Skip to content

Commit 247cdf8

Browse files
committed
Migrated colorbutton.go back.
1 parent ba8f53f commit 247cdf8

File tree

3 files changed

+47
-27
lines changed

3 files changed

+47
-27
lines changed
Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,7 @@ import (
66
"unsafe"
77
)
88

9-
// #include <stdlib.h>
10-
// #include "ui.h"
11-
// #include "util.h"
12-
// extern void doColorButtonOnChanged(uiColorButton *, void *);
13-
// // see golang/go#19835
14-
// typedef void (*colorButtonCallback)(uiColorButton *, void *);
15-
// typedef struct pkguiCColor pkguiCColor;
16-
// struct pkguiCColor { double *r; double *g; double *b; double *a; };
17-
// static inline pkguiCColor pkguiNewCColor(void)
18-
// {
19-
// pkguiCColor c;
20-
//
21-
// c.r = (double *) pkguiAlloc(4 * sizeof (double));
22-
// c.g = c.r + 1;
23-
// c.b = c.g + 1;
24-
// c.a = c.b + 1;
25-
// return c;
26-
// }
27-
// static inline void pkguiFreeCColor(pkguiCColor c)
28-
// {
29-
// free(c.r);
30-
// }
9+
// #include "pkgui.h"
3110
import "C"
3211

3312
// ColorButton is a Control that represents a button that the user can
@@ -44,7 +23,7 @@ func NewColorButton() *ColorButton {
4423

4524
b.b = C.uiNewColorButton()
4625

47-
C.uiColorButtonOnChanged(b.b, C.colorButtonCallback(C.doColorButtonOnChanged), nil)
26+
C.pkguiColorButtonOnChanged(b.b)
4827

4928
b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
5029
return b
@@ -54,8 +33,8 @@ func NewColorButton() *ColorButton {
5433
// Colors are not alpha-premultiplied.
5534
// TODO rename b or bl
5635
func (b *ColorButton) Color() (r, g, bl, a float64) {
57-
c := C.pkguiNewCColor()
58-
defer C.pkguiFreeCColor(c)
36+
c := C.pkguiNewColorDoubles()
37+
defer C.pkguiFreeColorDoubles(c)
5938
C.uiColorButtonColor(b.b, c.r, c.g, c.b, c.a)
6039
return float64(*(c.r)), float64(*(c.g)), float64(*(c.b)), float64(*(c.a))
6140
}
@@ -74,8 +53,8 @@ func (b *ColorButton) OnChanged(f func(*ColorButton)) {
7453
b.onChanged = f
7554
}
7655

77-
//export doColorButtonOnChanged
78-
func doColorButtonOnChanged(bb *C.uiColorButton, data unsafe.Pointer) {
56+
//export pkguiDoColorButtonOnChanged
57+
func pkguiDoColorButtonOnChanged(bb *C.uiColorButton, data unsafe.Pointer) {
7958
b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*ColorButton)
8059
if b.onChanged != nil {
8160
b.onChanged(b)

pkgui.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,35 @@ void pkguiCheckboxOnToggled(uiCheckbox *c)
3737
uiCheckboxOnToggled(c, pkguiDoCheckboxOnToggled, NULL);
3838
}
3939

40+
void pkguiColorButtonOnChanged(uiColorButton *c)
41+
{
42+
uiColorButtonOnChanged(c, pkguiDoColorButtonOnChanged, NULL);
43+
}
44+
45+
typedef struct pkguiColorDoubles pkguiColorDoubles;
46+
struct pkguiColorDoubles {
47+
double *r;
48+
double *g;
49+
double *b;
50+
double *a;
51+
};
52+
53+
pkguiColorDoubles pkguiAllocColorDoubles(void)
54+
{
55+
pkguiColorDoubles c;
56+
57+
c.r = (double *) pkguiAlloc(4 * sizeof (double));
58+
c.g = c.r + 1;
59+
c.b = c.g + 1;
60+
c.a = c.b + 1;
61+
return c;
62+
}
63+
64+
void pkguiFreeColorDoubles(pkguiColorDoubles c)
65+
{
66+
free(c.r);
67+
}
68+
4069
void pkguiComboboxOnSelected(uiCombobox *c)
4170
{
4271
uiComboboxOnSelected(c, pkguiDoComboboxOnSelected, NULL);

pkgui.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ extern void pkguiButtonOnClicked(uiButton *b);
2222
// checkbox.go
2323
extern void pkguiCheckboxOnToggled(uiCheckbox *c);
2424

25+
// colorbutton.go
26+
extern void pkguiColorButtonOnChanged(uiColorButton *c);
27+
typedef struct pkguiColorDoubles pkguiColorDoubles;
28+
struct pkguiColorDoubles {
29+
double *r;
30+
double *g;
31+
double *b;
32+
double *a;
33+
};
34+
extern pkguiColorDoubles pkguiAllocColorDoubles(void);
35+
extern void pkguiFreeColorDoubles(pkguiColorDoubles c);
36+
2537
// combobox.go
2638
extern void pkguiComboboxOnSelected(uiCombobox *c);
2739

0 commit comments

Comments
 (0)