diff --git a/colorbutton.go b/colorbutton.go index 6b1f525..f10c5c8 100644 --- a/colorbutton.go +++ b/colorbutton.go @@ -33,7 +33,7 @@ func NewColorButton() *ColorButton { // Colors are not alpha-premultiplied. // TODO rename b or bl func (b *ColorButton) Color() (r, g, bl, a float64) { - c := C.pkguiNewColorDoubles() + c := C.pkguiAllocColorDoubles() defer C.pkguiFreeColorDoubles(c) C.uiColorButtonColor(b.b, c.r, c.g, c.b, c.a) return float64(*(c.r)), float64(*(c.g)), float64(*(c.b)), float64(*(c.a)) diff --git a/BBB_GOFILES/drawtext.go b/drawtext.go similarity index 92% rename from BBB_GOFILES/drawtext.go rename to drawtext.go index 1cd438c..930416f 100644 --- a/BBB_GOFILES/drawtext.go +++ b/drawtext.go @@ -2,49 +2,7 @@ package ui -// #include -// #include "ui.h" -// #include "util.h" -// typedef struct pkguiCColor pkguiCColor; -// struct pkguiCColor { double *r; double *g; double *b; double *a; }; -// static inline pkguiCColor pkguiNewCColor(void) -// { -// pkguiCColor c; -// -// c.r = (double *) pkguiAlloc(4 * sizeof (double)); -// c.g = c.r + 1; -// c.b = c.g + 1; -// c.a = c.b + 1; -// return c; -// } -// static inline void pkguiFreeCColor(pkguiCColor c) -// { -// free(c.r); -// } -// static inline uiUnderlineColor *pkguiNewUnderlineColor(void) -// { -// return (uiUnderlineColor *) pkguiAlloc(sizeof (uiUnderlineColor)); -// } -// static inline void pkguiFreeUnderlineColor(uiUnderlineColor *c) -// { -// free(c); -// } -// static inline uiFontDescriptor *pkguiNewFontDescriptor(void) -// { -// return (uiFontDescriptor *) pkguiAlloc(sizeof (uiFontDescriptor)); -// } -// static inline void pkguiFreeFontDescriptor(uiFontDescriptor *fd) -// { -// free(fd); -// } -// static inline uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void) -// { -// return (uiDrawTextLayoutParams *) pkguiAlloc(sizeof (uiDrawTextLayoutParams)); -// } -// static inline void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *fd) -// { -// free(fd); -// } +// #include "pkgui.h" import "C" // Attribute stores information about an attribute in an @@ -317,8 +275,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute { case C.uiAttributeTypeStretch: return TextStretch(C.uiAttributeStretch(a)) case C.uiAttributeTypeColor: - cc := C.pkguiNewCColor() - defer C.pkguiFreeCColor(cc) + cc := C.pkguiAllocColorDoubles() + defer C.pkguiFreeColorDoubles(cc) C.uiAttributeColor(a, cc.r, cc.g, cc.b, cc.a) return TextColor{ R: float64(*(cc.r)), @@ -327,8 +285,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute { A: float64(*(cc.a)), } case C.uiAttributeTypeBackground: - cc := C.pkguiNewCColor() - defer C.pkguiFreeCColor(cc) + cc := C.pkguiAllocColorDoubles() + defer C.pkguiFreeColorDoubles(cc) C.uiAttributeColor(a, cc.r, cc.g, cc.b, cc.a) return TextBackground{ R: float64(*(cc.r)), @@ -341,8 +299,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute { case C.uiAttributeTypeUnderlineColor: cu := C.pkguiNewUnderlineColor() defer C.pkguiFreeUnderlineColor(cu) - cc := C.pkguiNewCColor() - defer C.pkguiFreeCColor(cc) + cc := C.pkguiAllocColorDoubles() + defer C.pkguiFreeColorDoubles(cc) C.uiAttributeUnderlineColor(a, cu, cc.r, cc.g, cc.b, cc.a) if *cu == C.uiUnderlineColorCustom { return UnderlineColorCustom{ diff --git a/BBB_GOFILES/fontbutton.go b/fontbutton.go similarity index 63% rename from BBB_GOFILES/fontbutton.go rename to fontbutton.go index c228151..d465411 100644 --- a/BBB_GOFILES/fontbutton.go +++ b/fontbutton.go @@ -6,20 +6,7 @@ import ( "unsafe" ) -// #include -// #include "ui.h" -// #include "util.h" -// extern void doFontButtonOnChanged(uiFontButton *, void *); -// // see golang/go#19835 -// typedef void (*fontButtonCallback)(uiFontButton *, void *); -// static inline uiFontDescriptor *pkguiNewFontDescriptor(void) -// { -// return (uiFontDescriptor *) pkguiAlloc(sizeof (uiFontDescriptor)); -// } -// static inline void pkguiFreeFontDescriptor(uiFontDescriptor *fd) -// { -// free(fd); -// } +// #include "pkgui.h" import "C" // FontButton is a Control that represents a button that the user can @@ -36,7 +23,7 @@ func NewFontButton() *FontButton { b.b = C.uiNewFontButton() - C.uiFontButtonOnChanged(b.b, C.fontButtonCallback(C.doFontButtonOnChanged), nil) + C.pkguiFontButtonOnChanged(b.b) b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b))) return b @@ -60,8 +47,8 @@ func (b *FontButton) OnChanged(f func(*FontButton)) { b.onChanged = f } -//export doFontButtonOnChanged -func doFontButtonOnChanged(bb *C.uiFontButton, data unsafe.Pointer) { +//export pkguiDoFontButtonOnChanged +func pkguiDoFontButtonOnChanged(bb *C.uiFontButton, data unsafe.Pointer) { b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*FontButton) if b.onChanged != nil { b.onChanged(b) diff --git a/pkgui.c b/pkgui.c index 5d0d55d..081c956 100644 --- a/pkgui.c +++ b/pkgui.c @@ -42,14 +42,6 @@ void pkguiColorButtonOnChanged(uiColorButton *c) uiColorButtonOnChanged(c, pkguiDoColorButtonOnChanged, NULL); } -typedef struct pkguiColorDoubles pkguiColorDoubles; -struct pkguiColorDoubles { - double *r; - double *g; - double *b; - double *a; -}; - pkguiColorDoubles pkguiAllocColorDoubles(void) { pkguiColorDoubles c; @@ -96,6 +88,11 @@ void pkguiEntryOnChanged(uiEntry *e) uiEntryOnChanged(e, pkguiDoEntryOnChanged, NULL); } +void pkguiFontButtonOnChanged(uiFontButton *b) +{ + uiFontButtonOnChanged(b, pkguiDoFontButtonOnChanged, NULL); +} + void pkguiMultilineEntryOnChanged(uiMultilineEntry *e) { uiMultilineEntryOnChanged(e, pkguiDoMultilineEntryOnChanged, NULL); @@ -179,3 +176,33 @@ void pkguiFreeMatrix(uiDrawMatrix *m) { free(m); } + +uiUnderlineColor *pkguiNewUnderlineColor(void) +{ + return (uiUnderlineColor *) pkguiAlloc(sizeof (uiUnderlineColor)); +} + +void pkguiFreeUnderlineColor(uiUnderlineColor *c) +{ + free(c); +} + +uiFontDescriptor *pkguiNewFontDescriptor(void) +{ + return (uiFontDescriptor *) pkguiAlloc(sizeof (uiFontDescriptor)); +} + +void pkguiFreeFontDescriptor(uiFontDescriptor *fd) +{ + free(fd); +} + +uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void) +{ + return (uiDrawTextLayoutParams *) pkguiAlloc(sizeof (uiDrawTextLayoutParams)); +} + +void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *p) +{ + free(p); +} diff --git a/pkgui.h b/pkgui.h index d421965..44cd6b3 100644 --- a/pkgui.h +++ b/pkgui.h @@ -48,6 +48,9 @@ extern void pkguiEditableComboboxOnChanged(uiEditableCombobox *c); // entry.go extern void pkguiEntryOnChanged(uiEntry *e); +// fontbutton.go +extern void pkguiFontButtonOnChanged(uiFontButton *b); + // multilineentry.go extern void pkguiMultilineEntryOnChanged(uiMultilineEntry *e); @@ -74,4 +77,12 @@ extern void pkguiSetDash(double *dashes, size_t i, double dash); extern uiDrawMatrix *pkguiAllocMatrix(void); extern void pkguiFreeMatrix(uiDrawMatrix *m); +// drawtext.go +extern uiUnderlineColor *pkguiNewUnderlineColor(void); +extern void pkguiFreeUnderlineColor(uiUnderlineColor *c); +extern uiFontDescriptor *pkguiNewFontDescriptor(void); +extern void pkguiFreeFontDescriptor(uiFontDescriptor *fd); +extern uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void); +extern void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *p); + #endif