Skip to content

Commit 246950d

Browse files
committed
Migrated drawtext.go and fontbutton.go.
1 parent 247cdf8 commit 246950d

File tree

5 files changed

+58
-75
lines changed

5 files changed

+58
-75
lines changed

colorbutton.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func NewColorButton() *ColorButton {
3333
// Colors are not alpha-premultiplied.
3434
// TODO rename b or bl
3535
func (b *ColorButton) Color() (r, g, bl, a float64) {
36-
c := C.pkguiNewColorDoubles()
36+
c := C.pkguiAllocColorDoubles()
3737
defer C.pkguiFreeColorDoubles(c)
3838
C.uiColorButtonColor(b.b, c.r, c.g, c.b, c.a)
3939
return float64(*(c.r)), float64(*(c.g)), float64(*(c.b)), float64(*(c.a))

BBB_GOFILES/drawtext.go renamed to drawtext.go

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,7 @@
22

33
package ui
44

5-
// #include <stdlib.h>
6-
// #include "ui.h"
7-
// #include "util.h"
8-
// typedef struct pkguiCColor pkguiCColor;
9-
// struct pkguiCColor { double *r; double *g; double *b; double *a; };
10-
// static inline pkguiCColor pkguiNewCColor(void)
11-
// {
12-
// pkguiCColor c;
13-
//
14-
// c.r = (double *) pkguiAlloc(4 * sizeof (double));
15-
// c.g = c.r + 1;
16-
// c.b = c.g + 1;
17-
// c.a = c.b + 1;
18-
// return c;
19-
// }
20-
// static inline void pkguiFreeCColor(pkguiCColor c)
21-
// {
22-
// free(c.r);
23-
// }
24-
// static inline uiUnderlineColor *pkguiNewUnderlineColor(void)
25-
// {
26-
// return (uiUnderlineColor *) pkguiAlloc(sizeof (uiUnderlineColor));
27-
// }
28-
// static inline void pkguiFreeUnderlineColor(uiUnderlineColor *c)
29-
// {
30-
// free(c);
31-
// }
32-
// static inline uiFontDescriptor *pkguiNewFontDescriptor(void)
33-
// {
34-
// return (uiFontDescriptor *) pkguiAlloc(sizeof (uiFontDescriptor));
35-
// }
36-
// static inline void pkguiFreeFontDescriptor(uiFontDescriptor *fd)
37-
// {
38-
// free(fd);
39-
// }
40-
// static inline uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void)
41-
// {
42-
// return (uiDrawTextLayoutParams *) pkguiAlloc(sizeof (uiDrawTextLayoutParams));
43-
// }
44-
// static inline void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *fd)
45-
// {
46-
// free(fd);
47-
// }
5+
// #include "pkgui.h"
486
import "C"
497

508
// Attribute stores information about an attribute in an
@@ -317,8 +275,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute {
317275
case C.uiAttributeTypeStretch:
318276
return TextStretch(C.uiAttributeStretch(a))
319277
case C.uiAttributeTypeColor:
320-
cc := C.pkguiNewCColor()
321-
defer C.pkguiFreeCColor(cc)
278+
cc := C.pkguiAllocColorDoubles()
279+
defer C.pkguiFreeColorDoubles(cc)
322280
C.uiAttributeColor(a, cc.r, cc.g, cc.b, cc.a)
323281
return TextColor{
324282
R: float64(*(cc.r)),
@@ -327,8 +285,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute {
327285
A: float64(*(cc.a)),
328286
}
329287
case C.uiAttributeTypeBackground:
330-
cc := C.pkguiNewCColor()
331-
defer C.pkguiFreeCColor(cc)
288+
cc := C.pkguiAllocColorDoubles()
289+
defer C.pkguiFreeColorDoubles(cc)
332290
C.uiAttributeColor(a, cc.r, cc.g, cc.b, cc.a)
333291
return TextBackground{
334292
R: float64(*(cc.r)),
@@ -341,8 +299,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute {
341299
case C.uiAttributeTypeUnderlineColor:
342300
cu := C.pkguiNewUnderlineColor()
343301
defer C.pkguiFreeUnderlineColor(cu)
344-
cc := C.pkguiNewCColor()
345-
defer C.pkguiFreeCColor(cc)
302+
cc := C.pkguiAllocColorDoubles()
303+
defer C.pkguiFreeColorDoubles(cc)
346304
C.uiAttributeUnderlineColor(a, cu, cc.r, cc.g, cc.b, cc.a)
347305
if *cu == C.uiUnderlineColorCustom {
348306
return UnderlineColorCustom{

BBB_GOFILES/fontbutton.go renamed to fontbutton.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,7 @@ import (
66
"unsafe"
77
)
88

9-
// #include <stdlib.h>
10-
// #include "ui.h"
11-
// #include "util.h"
12-
// extern void doFontButtonOnChanged(uiFontButton *, void *);
13-
// // see golang/go#19835
14-
// typedef void (*fontButtonCallback)(uiFontButton *, void *);
15-
// static inline uiFontDescriptor *pkguiNewFontDescriptor(void)
16-
// {
17-
// return (uiFontDescriptor *) pkguiAlloc(sizeof (uiFontDescriptor));
18-
// }
19-
// static inline void pkguiFreeFontDescriptor(uiFontDescriptor *fd)
20-
// {
21-
// free(fd);
22-
// }
9+
// #include "pkgui.h"
2310
import "C"
2411

2512
// FontButton is a Control that represents a button that the user can
@@ -36,7 +23,7 @@ func NewFontButton() *FontButton {
3623

3724
b.b = C.uiNewFontButton()
3825

39-
C.uiFontButtonOnChanged(b.b, C.fontButtonCallback(C.doFontButtonOnChanged), nil)
26+
C.pkguiFontButtonOnChanged(b.b)
4027

4128
b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
4229
return b
@@ -60,8 +47,8 @@ func (b *FontButton) OnChanged(f func(*FontButton)) {
6047
b.onChanged = f
6148
}
6249

63-
//export doFontButtonOnChanged
64-
func doFontButtonOnChanged(bb *C.uiFontButton, data unsafe.Pointer) {
50+
//export pkguiDoFontButtonOnChanged
51+
func pkguiDoFontButtonOnChanged(bb *C.uiFontButton, data unsafe.Pointer) {
6552
b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*FontButton)
6653
if b.onChanged != nil {
6754
b.onChanged(b)

pkgui.c

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ void pkguiColorButtonOnChanged(uiColorButton *c)
4242
uiColorButtonOnChanged(c, pkguiDoColorButtonOnChanged, NULL);
4343
}
4444

45-
typedef struct pkguiColorDoubles pkguiColorDoubles;
46-
struct pkguiColorDoubles {
47-
double *r;
48-
double *g;
49-
double *b;
50-
double *a;
51-
};
52-
5345
pkguiColorDoubles pkguiAllocColorDoubles(void)
5446
{
5547
pkguiColorDoubles c;
@@ -96,6 +88,11 @@ void pkguiEntryOnChanged(uiEntry *e)
9688
uiEntryOnChanged(e, pkguiDoEntryOnChanged, NULL);
9789
}
9890

91+
void pkguiFontButtonOnChanged(uiFontButton *b)
92+
{
93+
uiFontButtonOnChanged(b, pkguiDoFontButtonOnChanged, NULL);
94+
}
95+
9996
void pkguiMultilineEntryOnChanged(uiMultilineEntry *e)
10097
{
10198
uiMultilineEntryOnChanged(e, pkguiDoMultilineEntryOnChanged, NULL);
@@ -179,3 +176,33 @@ void pkguiFreeMatrix(uiDrawMatrix *m)
179176
{
180177
free(m);
181178
}
179+
180+
uiUnderlineColor *pkguiNewUnderlineColor(void)
181+
{
182+
return (uiUnderlineColor *) pkguiAlloc(sizeof (uiUnderlineColor));
183+
}
184+
185+
void pkguiFreeUnderlineColor(uiUnderlineColor *c)
186+
{
187+
free(c);
188+
}
189+
190+
uiFontDescriptor *pkguiNewFontDescriptor(void)
191+
{
192+
return (uiFontDescriptor *) pkguiAlloc(sizeof (uiFontDescriptor));
193+
}
194+
195+
void pkguiFreeFontDescriptor(uiFontDescriptor *fd)
196+
{
197+
free(fd);
198+
}
199+
200+
uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void)
201+
{
202+
return (uiDrawTextLayoutParams *) pkguiAlloc(sizeof (uiDrawTextLayoutParams));
203+
}
204+
205+
void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *p)
206+
{
207+
free(p);
208+
}

pkgui.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ extern void pkguiEditableComboboxOnChanged(uiEditableCombobox *c);
4848
// entry.go
4949
extern void pkguiEntryOnChanged(uiEntry *e);
5050

51+
// fontbutton.go
52+
extern void pkguiFontButtonOnChanged(uiFontButton *b);
53+
5154
// multilineentry.go
5255
extern void pkguiMultilineEntryOnChanged(uiMultilineEntry *e);
5356

@@ -74,4 +77,12 @@ extern void pkguiSetDash(double *dashes, size_t i, double dash);
7477
extern uiDrawMatrix *pkguiAllocMatrix(void);
7578
extern void pkguiFreeMatrix(uiDrawMatrix *m);
7679

80+
// drawtext.go
81+
extern uiUnderlineColor *pkguiNewUnderlineColor(void);
82+
extern void pkguiFreeUnderlineColor(uiUnderlineColor *c);
83+
extern uiFontDescriptor *pkguiNewFontDescriptor(void);
84+
extern void pkguiFreeFontDescriptor(uiFontDescriptor *fd);
85+
extern uiDrawTextLayoutParams *pkguiNewDrawTextLayoutParams(void);
86+
extern void pkguiFreeDrawTextLayoutParams(uiDrawTextLayoutParams *p);
87+
7788
#endif

0 commit comments

Comments
 (0)