Migrated uiArea back.
This commit is contained in:
parent
3a6de2e65a
commit
60f0882df9
|
@ -9,9 +9,6 @@ import (
|
||||||
// #include "ui.h"
|
// #include "ui.h"
|
||||||
import "C"
|
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
|
// Area is a Control that represents a blank canvas that a program
|
||||||
// can draw on as it wishes. Areas also receive keyboard and mouse
|
// can draw on as it wishes. Areas also receive keyboard and mouse
|
||||||
// events, and programs can react to those as they see fit. Drawing
|
// 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
|
// SetSize are ints. All other instances of points in parameters and
|
||||||
// structures (including sizes of drawn objects) are float64s.
|
// structures (including sizes of drawn objects) are float64s.
|
||||||
type Area struct {
|
type Area struct {
|
||||||
c *C.uiControl
|
ControlBase
|
||||||
a *C.uiArea
|
a *C.uiArea
|
||||||
|
|
||||||
ah *C.uiAreaHandler
|
ah *C.uiAreaHandler
|
||||||
|
|
||||||
scrolling bool
|
scrolling bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +55,8 @@ func NewArea(handler AreaHandler) *Area {
|
||||||
a.ah = registerAreaHandler(handler)
|
a.ah = registerAreaHandler(handler)
|
||||||
|
|
||||||
a.a = C.uiNewArea(a.ah)
|
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
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,56 +68,15 @@ func NewScrollingArea(handler AreaHandler, width int, height int) *Area {
|
||||||
a.ah = registerAreaHandler(handler)
|
a.ah = registerAreaHandler(handler)
|
||||||
|
|
||||||
a.a = C.uiNewScrollingArea(a.ah, C.int(width), C.int(height))
|
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
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy destroys the Area.
|
// Destroy destroys the Area.
|
||||||
func (a *Area) Destroy() {
|
func (a *Area) Destroy() {
|
||||||
delete(areas, a.a)
|
|
||||||
C.uiControlDestroy(a.c)
|
|
||||||
unregisterAreaHandler(a.ah)
|
unregisterAreaHandler(a.ah)
|
||||||
}
|
a.ControlBase.Destroy()
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSize sets the size of a scrolling Area to the given size, in points.
|
// 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))
|
C.uiAreaScrollTo(a.a, C.double(x), C.double(y), C.double(width), C.double(height))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO BeginUserWindowMove
|
||||||
|
// TODO BeginUserWindowResize
|
|
@ -2,8 +2,13 @@
|
||||||
|
|
||||||
package ui
|
package ui
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
// #include <stdlib.h>
|
// #include <stdlib.h>
|
||||||
// #include "ui.h"
|
// #include "ui.h"
|
||||||
|
// #include "util.h"
|
||||||
// extern void doAreaHandlerDraw(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
|
// extern void doAreaHandlerDraw(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
|
||||||
// extern void doAreaHandlerMouseEvent(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
// extern void doAreaHandlerMouseEvent(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
||||||
// extern void doAreaHandlerMouseCrossed(uiAreaHandler *, uiArea *, int);
|
// extern void doAreaHandlerMouseCrossed(uiAreaHandler *, uiArea *, int);
|
||||||
|
@ -13,9 +18,7 @@ package ui
|
||||||
// {
|
// {
|
||||||
// uiAreaHandler *ah;
|
// uiAreaHandler *ah;
|
||||||
//
|
//
|
||||||
// ah = (uiAreaHandler *) malloc(sizeof (uiAreaHandler));
|
// ah = (uiAreaHandler *) pkguiAlloc(sizeof (uiAreaHandler));
|
||||||
// if (ah == NULL) // TODO
|
|
||||||
// return NULL;
|
|
||||||
// ah->Draw = doAreaHandlerDraw;
|
// ah->Draw = doAreaHandlerDraw;
|
||||||
// ah->MouseEvent = doAreaHandlerMouseEvent;
|
// ah->MouseEvent = doAreaHandlerMouseEvent;
|
||||||
// ah->MouseCrossed = doAreaHandlerMouseCrossed;
|
// ah->MouseCrossed = doAreaHandlerMouseCrossed;
|
||||||
|
@ -159,7 +162,7 @@ type AreaDrawParams struct {
|
||||||
//export doAreaHandlerDraw
|
//export doAreaHandlerDraw
|
||||||
func doAreaHandlerDraw(uah *C.uiAreaHandler, ua *C.uiArea, udp *C.uiAreaDrawParams) {
|
func doAreaHandlerDraw(uah *C.uiAreaHandler, ua *C.uiArea, udp *C.uiAreaDrawParams) {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := areas[ua]
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
dp := &AreaDrawParams{
|
dp := &AreaDrawParams{
|
||||||
Context: &DrawContext{udp.Context},
|
Context: &DrawContext{udp.Context},
|
||||||
AreaWidth: float64(udp.AreaWidth),
|
AreaWidth: float64(udp.AreaWidth),
|
||||||
|
@ -210,7 +213,7 @@ func appendBits(out []uint, held C.uint64_t) []uint {
|
||||||
//export doAreaHandlerMouseEvent
|
//export doAreaHandlerMouseEvent
|
||||||
func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMouseEvent) {
|
func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMouseEvent) {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := areas[ua]
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
me := &AreaMouseEvent{
|
me := &AreaMouseEvent{
|
||||||
X: float64(ume.X),
|
X: float64(ume.X),
|
||||||
Y: float64(ume.Y),
|
Y: float64(ume.Y),
|
||||||
|
@ -229,14 +232,14 @@ func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMo
|
||||||
//export doAreaHandlerMouseCrossed
|
//export doAreaHandlerMouseCrossed
|
||||||
func doAreaHandlerMouseCrossed(uah *C.uiAreaHandler, ua *C.uiArea, left C.int) {
|
func doAreaHandlerMouseCrossed(uah *C.uiAreaHandler, ua *C.uiArea, left C.int) {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := areas[ua]
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
ah.MouseCrossed(a, tobool(left))
|
ah.MouseCrossed(a, tobool(left))
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doAreaHandlerDragBroken
|
//export doAreaHandlerDragBroken
|
||||||
func doAreaHandlerDragBroken(uah *C.uiAreaHandler, ua *C.uiArea) {
|
func doAreaHandlerDragBroken(uah *C.uiAreaHandler, ua *C.uiArea) {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := areas[ua]
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
ah.DragBroken(a)
|
ah.DragBroken(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +255,7 @@ type AreaKeyEvent struct {
|
||||||
//export doAreaHandlerKeyEvent
|
//export doAreaHandlerKeyEvent
|
||||||
func doAreaHandlerKeyEvent(uah *C.uiAreaHandler, ua *C.uiArea, uke *C.uiAreaKeyEvent) C.int {
|
func doAreaHandlerKeyEvent(uah *C.uiAreaHandler, ua *C.uiArea, uke *C.uiAreaKeyEvent) C.int {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := areas[ua]
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
ke := &AreaKeyEvent{
|
ke := &AreaKeyEvent{
|
||||||
Key: rune(uke.Key),
|
Key: rune(uke.Key),
|
||||||
ExtKey: ExtKey(uke.ExtKey),
|
ExtKey: ExtKey(uke.ExtKey),
|
Loading…
Reference in New Issue