From 60f0882df94580cfc9453a093f70f28b1ef35f6b Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 12 Aug 2018 16:28:19 -0400 Subject: [PATCH] Migrated uiArea back. --- AAA_GOFILES/area.go => area.go | 59 +++----------------- AAA_GOFILES/areahandler.go => areahandler.go | 19 ++++--- 2 files changed, 18 insertions(+), 60 deletions(-) rename AAA_GOFILES/area.go => area.go (73%) rename AAA_GOFILES/areahandler.go => areahandler.go (96%) diff --git a/AAA_GOFILES/area.go b/area.go similarity index 73% rename from AAA_GOFILES/area.go rename to area.go index be267a4..f7ed41c 100644 --- a/AAA_GOFILES/area.go +++ b/area.go @@ -9,9 +9,6 @@ import ( // #include "ui.h" import "C" -// no need to lock this; only the GUI thread can access it -var areas = make(map[*C.uiArea]*Area) - // Area is a Control that represents a blank canvas that a program // can draw on as it wishes. Areas also receive keyboard and mouse // events, and programs can react to those as they see fit. Drawing @@ -45,11 +42,9 @@ var areas = make(map[*C.uiArea]*Area) // SetSize are ints. All other instances of points in parameters and // structures (including sizes of drawn objects) are float64s. type Area struct { - c *C.uiControl + ControlBase a *C.uiArea - ah *C.uiAreaHandler - scrolling bool } @@ -60,10 +55,8 @@ func NewArea(handler AreaHandler) *Area { a.ah = registerAreaHandler(handler) a.a = C.uiNewArea(a.ah) - a.c = (*C.uiControl)(unsafe.Pointer(a.a)) - - areas[a.a] = a + a.ControlBase = NewControlBase(a, uintptr(unsafe.Pointer(a.a))) return a } @@ -75,56 +68,15 @@ func NewScrollingArea(handler AreaHandler, width int, height int) *Area { a.ah = registerAreaHandler(handler) a.a = C.uiNewScrollingArea(a.ah, C.int(width), C.int(height)) - a.c = (*C.uiControl)(unsafe.Pointer(a.a)) - - areas[a.a] = a + a.ControlBase = NewControlBase(a, uintptr(unsafe.Pointer(a.a))) return a } // Destroy destroys the Area. func (a *Area) Destroy() { - delete(areas, a.a) - C.uiControlDestroy(a.c) unregisterAreaHandler(a.ah) -} - -// LibuiControl returns the libui uiControl pointer that backs -// the Area. This is only used by package ui itself and should -// not be called by programs. -func (a *Area) LibuiControl() uintptr { - return uintptr(unsafe.Pointer(a.c)) -} - -// Handle returns the OS-level handle associated with this Area. -// On Windows this is an HWND of a libui-internal class. -// On GTK+ this is a pointer to a GtkScrolledWindow with a -// GtkViewport as its child. The child of the viewport is the -// GtkDrawingArea that provides the Area itself. -// On OS X this is a pointer to a NSScrollView whose document view -// is the NSView that provides the Area itself. -func (a *Area) Handle() uintptr { - return uintptr(C.uiControlHandle(a.c)) -} - -// Show shows the Area. -func (a *Area) Show() { - C.uiControlShow(a.c) -} - -// Hide hides the Area. -func (a *Area) Hide() { - C.uiControlHide(a.c) -} - -// Enable enables the Area. -func (a *Area) Enable() { - C.uiControlEnable(a.c) -} - -// Disable disables the Area. -func (a *Area) Disable() { - C.uiControlDisable(a.c) + a.ControlBase.Destroy() } // SetSize sets the size of a scrolling Area to the given size, in points. @@ -154,3 +106,6 @@ func (a *Area) ScrollTo(x float64, y float64, width float64, height float64) { } C.uiAreaScrollTo(a.a, C.double(x), C.double(y), C.double(width), C.double(height)) } + +// TODO BeginUserWindowMove +// TODO BeginUserWindowResize diff --git a/AAA_GOFILES/areahandler.go b/areahandler.go similarity index 96% rename from AAA_GOFILES/areahandler.go rename to areahandler.go index 74cbe56..dbe739e 100644 --- a/AAA_GOFILES/areahandler.go +++ b/areahandler.go @@ -2,8 +2,13 @@ package ui +import ( + "unsafe" +) + // #include // #include "ui.h" +// #include "util.h" // extern void doAreaHandlerDraw(uiAreaHandler *, uiArea *, uiAreaDrawParams *); // extern void doAreaHandlerMouseEvent(uiAreaHandler *, uiArea *, uiAreaMouseEvent *); // extern void doAreaHandlerMouseCrossed(uiAreaHandler *, uiArea *, int); @@ -13,9 +18,7 @@ package ui // { // uiAreaHandler *ah; // -// ah = (uiAreaHandler *) malloc(sizeof (uiAreaHandler)); -// if (ah == NULL) // TODO -// return NULL; +// ah = (uiAreaHandler *) pkguiAlloc(sizeof (uiAreaHandler)); // ah->Draw = doAreaHandlerDraw; // ah->MouseEvent = doAreaHandlerMouseEvent; // ah->MouseCrossed = doAreaHandlerMouseCrossed; @@ -159,7 +162,7 @@ type AreaDrawParams struct { //export doAreaHandlerDraw func doAreaHandlerDraw(uah *C.uiAreaHandler, ua *C.uiArea, udp *C.uiAreaDrawParams) { ah := areahandlers[uah] - a := areas[ua] + a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area) dp := &AreaDrawParams{ Context: &DrawContext{udp.Context}, AreaWidth: float64(udp.AreaWidth), @@ -210,7 +213,7 @@ func appendBits(out []uint, held C.uint64_t) []uint { //export doAreaHandlerMouseEvent func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMouseEvent) { ah := areahandlers[uah] - a := areas[ua] + a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area) me := &AreaMouseEvent{ X: float64(ume.X), Y: float64(ume.Y), @@ -229,14 +232,14 @@ func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMo //export doAreaHandlerMouseCrossed func doAreaHandlerMouseCrossed(uah *C.uiAreaHandler, ua *C.uiArea, left C.int) { ah := areahandlers[uah] - a := areas[ua] + a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area) ah.MouseCrossed(a, tobool(left)) } //export doAreaHandlerDragBroken func doAreaHandlerDragBroken(uah *C.uiAreaHandler, ua *C.uiArea) { ah := areahandlers[uah] - a := areas[ua] + a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area) ah.DragBroken(a) } @@ -252,7 +255,7 @@ type AreaKeyEvent struct { //export doAreaHandlerKeyEvent func doAreaHandlerKeyEvent(uah *C.uiAreaHandler, ua *C.uiArea, uke *C.uiAreaKeyEvent) C.int { ah := areahandlers[uah] - a := areas[ua] + a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area) ke := &AreaKeyEvent{ Key: rune(uke.Key), ExtKey: ExtKey(uke.ExtKey),