From 247cdf8d6ff13697dcead9908d97146e0d5171c4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 26 Aug 2018 17:08:41 -0400 Subject: [PATCH] Migrated colorbutton.go back. --- BBB_GOFILES/colorbutton.go => colorbutton.go | 33 ++++---------------- pkgui.c | 29 +++++++++++++++++ pkgui.h | 12 +++++++ 3 files changed, 47 insertions(+), 27 deletions(-) rename BBB_GOFILES/colorbutton.go => colorbutton.go (61%) diff --git a/BBB_GOFILES/colorbutton.go b/colorbutton.go similarity index 61% rename from BBB_GOFILES/colorbutton.go rename to colorbutton.go index 0129a55..6b1f525 100644 --- a/BBB_GOFILES/colorbutton.go +++ b/colorbutton.go @@ -6,28 +6,7 @@ import ( "unsafe" ) -// #include -// #include "ui.h" -// #include "util.h" -// extern void doColorButtonOnChanged(uiColorButton *, void *); -// // see golang/go#19835 -// typedef void (*colorButtonCallback)(uiColorButton *, void *); -// 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); -// } +// #include "pkgui.h" import "C" // ColorButton is a Control that represents a button that the user can @@ -44,7 +23,7 @@ func NewColorButton() *ColorButton { b.b = C.uiNewColorButton() - C.uiColorButtonOnChanged(b.b, C.colorButtonCallback(C.doColorButtonOnChanged), nil) + C.pkguiColorButtonOnChanged(b.b) b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b))) return b @@ -54,8 +33,8 @@ func NewColorButton() *ColorButton { // Colors are not alpha-premultiplied. // TODO rename b or bl func (b *ColorButton) Color() (r, g, bl, a float64) { - c := C.pkguiNewCColor() - defer C.pkguiFreeCColor(c) + c := C.pkguiNewColorDoubles() + 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)) } @@ -74,8 +53,8 @@ func (b *ColorButton) OnChanged(f func(*ColorButton)) { b.onChanged = f } -//export doColorButtonOnChanged -func doColorButtonOnChanged(bb *C.uiColorButton, data unsafe.Pointer) { +//export pkguiDoColorButtonOnChanged +func pkguiDoColorButtonOnChanged(bb *C.uiColorButton, data unsafe.Pointer) { b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*ColorButton) if b.onChanged != nil { b.onChanged(b) diff --git a/pkgui.c b/pkgui.c index f0d19be..5d0d55d 100644 --- a/pkgui.c +++ b/pkgui.c @@ -37,6 +37,35 @@ void pkguiCheckboxOnToggled(uiCheckbox *c) uiCheckboxOnToggled(c, pkguiDoCheckboxOnToggled, NULL); } +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; + + c.r = (double *) pkguiAlloc(4 * sizeof (double)); + c.g = c.r + 1; + c.b = c.g + 1; + c.a = c.b + 1; + return c; +} + +void pkguiFreeColorDoubles(pkguiColorDoubles c) +{ + free(c.r); +} + void pkguiComboboxOnSelected(uiCombobox *c) { uiComboboxOnSelected(c, pkguiDoComboboxOnSelected, NULL); diff --git a/pkgui.h b/pkgui.h index d7cd5b2..d421965 100644 --- a/pkgui.h +++ b/pkgui.h @@ -22,6 +22,18 @@ extern void pkguiButtonOnClicked(uiButton *b); // checkbox.go extern void pkguiCheckboxOnToggled(uiCheckbox *c); +// colorbutton.go +extern void pkguiColorButtonOnChanged(uiColorButton *c); +typedef struct pkguiColorDoubles pkguiColorDoubles; +struct pkguiColorDoubles { + double *r; + double *g; + double *b; + double *a; +}; +extern pkguiColorDoubles pkguiAllocColorDoubles(void); +extern void pkguiFreeColorDoubles(pkguiColorDoubles c); + // combobox.go extern void pkguiComboboxOnSelected(uiCombobox *c);