And finally migrated Area back.
This commit is contained in:
parent
246950deed
commit
2c275b76ae
|
@ -6,7 +6,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "ui.h"
|
// #include "pkgui.h"
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// Area is a Control that represents a blank canvas that a program
|
// Area is a Control that represents a blank canvas that a program
|
|
@ -6,30 +6,7 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include <stdlib.h>
|
// #include "pkgui.h"
|
||||||
// #include "ui.h"
|
|
||||||
// #include "util.h"
|
|
||||||
// extern void doAreaHandlerDraw(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
|
|
||||||
// extern void doAreaHandlerMouseEvent(uiAreaHandler *, uiArea *, uiAreaMouseEvent *);
|
|
||||||
// extern void doAreaHandlerMouseCrossed(uiAreaHandler *, uiArea *, int);
|
|
||||||
// extern void doAreaHandlerDragBroken(uiAreaHandler *, uiArea *);
|
|
||||||
// extern int doAreaHandlerKeyEvent(uiAreaHandler *, uiArea *, uiAreaKeyEvent *);
|
|
||||||
// static inline uiAreaHandler *allocAreaHandler(void)
|
|
||||||
// {
|
|
||||||
// uiAreaHandler *ah;
|
|
||||||
//
|
|
||||||
// ah = (uiAreaHandler *) pkguiAlloc(sizeof (uiAreaHandler));
|
|
||||||
// ah->Draw = doAreaHandlerDraw;
|
|
||||||
// ah->MouseEvent = doAreaHandlerMouseEvent;
|
|
||||||
// ah->MouseCrossed = doAreaHandlerMouseCrossed;
|
|
||||||
// ah->DragBroken = doAreaHandlerDragBroken;
|
|
||||||
// ah->KeyEvent = doAreaHandlerKeyEvent;
|
|
||||||
// return ah;
|
|
||||||
// }
|
|
||||||
// static inline void freeAreaHandler(uiAreaHandler *ah)
|
|
||||||
// {
|
|
||||||
// free(ah);
|
|
||||||
// }
|
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
// no need to lock this; only the GUI thread can access it
|
// no need to lock this; only the GUI thread can access it
|
||||||
|
@ -122,14 +99,14 @@ type AreaHandler interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerAreaHandler(ah AreaHandler) *C.uiAreaHandler {
|
func registerAreaHandler(ah AreaHandler) *C.uiAreaHandler {
|
||||||
uah := C.allocAreaHandler()
|
uah := C.pkguiAllocAreaHandler()
|
||||||
areahandlers[uah] = ah
|
areahandlers[uah] = ah
|
||||||
return uah
|
return uah
|
||||||
}
|
}
|
||||||
|
|
||||||
func unregisterAreaHandler(uah *C.uiAreaHandler) {
|
func unregisterAreaHandler(uah *C.uiAreaHandler) {
|
||||||
delete(areahandlers, uah)
|
delete(areahandlers, uah)
|
||||||
C.freeAreaHandler(uah)
|
C.pkguiFreeAreaHandler(uah)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AreaDrawParams provides a drawing context that can be used
|
// AreaDrawParams provides a drawing context that can be used
|
||||||
|
@ -159,8 +136,8 @@ type AreaDrawParams struct {
|
||||||
ClipHeight float64
|
ClipHeight float64
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doAreaHandlerDraw
|
//export pkguiDoAreaHandlerDraw
|
||||||
func doAreaHandlerDraw(uah *C.uiAreaHandler, ua *C.uiArea, udp *C.uiAreaDrawParams) {
|
func pkguiDoAreaHandlerDraw(uah *C.uiAreaHandler, ua *C.uiArea, udp *C.uiAreaDrawParams) {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
dp := &AreaDrawParams{
|
dp := &AreaDrawParams{
|
||||||
|
@ -210,8 +187,8 @@ func appendBits(out []uint, held C.uint64_t) []uint {
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doAreaHandlerMouseEvent
|
//export pkguiDoAreaHandlerMouseEvent
|
||||||
func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMouseEvent) {
|
func pkguiDoAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMouseEvent) {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
me := &AreaMouseEvent{
|
me := &AreaMouseEvent{
|
||||||
|
@ -229,15 +206,15 @@ func doAreaHandlerMouseEvent(uah *C.uiAreaHandler, ua *C.uiArea, ume *C.uiAreaMo
|
||||||
ah.MouseEvent(a, me)
|
ah.MouseEvent(a, me)
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doAreaHandlerMouseCrossed
|
//export pkguiDoAreaHandlerMouseCrossed
|
||||||
func doAreaHandlerMouseCrossed(uah *C.uiAreaHandler, ua *C.uiArea, left C.int) {
|
func pkguiDoAreaHandlerMouseCrossed(uah *C.uiAreaHandler, ua *C.uiArea, left C.int) {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
ah.MouseCrossed(a, tobool(left))
|
ah.MouseCrossed(a, tobool(left))
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doAreaHandlerDragBroken
|
//export pkguiDoAreaHandlerDragBroken
|
||||||
func doAreaHandlerDragBroken(uah *C.uiAreaHandler, ua *C.uiArea) {
|
func pkguiDoAreaHandlerDragBroken(uah *C.uiAreaHandler, ua *C.uiArea) {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
ah.DragBroken(a)
|
ah.DragBroken(a)
|
||||||
|
@ -252,8 +229,8 @@ type AreaKeyEvent struct {
|
||||||
Up bool
|
Up bool
|
||||||
}
|
}
|
||||||
|
|
||||||
//export doAreaHandlerKeyEvent
|
//export pkguiDoAreaHandlerKeyEvent
|
||||||
func doAreaHandlerKeyEvent(uah *C.uiAreaHandler, ua *C.uiArea, uke *C.uiAreaKeyEvent) C.int {
|
func pkguiDoAreaHandlerKeyEvent(uah *C.uiAreaHandler, ua *C.uiArea, uke *C.uiAreaKeyEvent) C.int {
|
||||||
ah := areahandlers[uah]
|
ah := areahandlers[uah]
|
||||||
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
a := ControlFromLibui(uintptr(unsafe.Pointer(ua))).(*Area)
|
||||||
ke := &AreaKeyEvent{
|
ke := &AreaKeyEvent{
|
18
pkgui.c
18
pkgui.c
|
@ -206,3 +206,21 @@ void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *p)
|
||||||
{
|
{
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uiAreaHandler *pkguiAllocAreaHandler(void)
|
||||||
|
{
|
||||||
|
uiAreaHandler *ah;
|
||||||
|
|
||||||
|
ah = (uiAreaHandler *) pkguiAlloc(sizeof (uiAreaHandler));
|
||||||
|
ah->Draw = pkguiDoAreaHandlerDraw;
|
||||||
|
ah->MouseEvent = pkguiDoAreaHandlerMouseEvent;
|
||||||
|
ah->MouseCrossed = pkguiDoAreaHandlerMouseCrossed;
|
||||||
|
ah->DragBroken = pkguiDoAreaHandlerDragBroken;
|
||||||
|
ah->KeyEvent = pkguiDoAreaHandlerKeyEvent;
|
||||||
|
return ah;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pkguiFreeAreaHandler(uiAreaHandler *ah)
|
||||||
|
{
|
||||||
|
free(ah);
|
||||||
|
}
|
||||||
|
|
4
pkgui.h
4
pkgui.h
|
@ -85,4 +85,8 @@ extern void pkguiFreeFontDescriptor(uiFontDescriptor *fd);
|
||||||
extern uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void);
|
extern uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void);
|
||||||
extern void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *p);
|
extern void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *p);
|
||||||
|
|
||||||
|
// area.go
|
||||||
|
extern uiAreaHandler *pkguiAllocAreaHandler(void);
|
||||||
|
extern void pkguiFreeAreaHandler(uiAreaHandler *ah);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue