Migrated drawtext.go and fontbutton.go.

This commit is contained in:
Pietro Gagliardi 2018-08-26 17:17:03 -04:00
parent 247cdf8d6f
commit 246950deed
5 changed files with 58 additions and 75 deletions

View File

@ -33,7 +33,7 @@ func NewColorButton() *ColorButton {
// Colors are not alpha-premultiplied. // Colors are not alpha-premultiplied.
// TODO rename b or bl // TODO rename b or bl
func (b *ColorButton) Color() (r, g, bl, a float64) { func (b *ColorButton) Color() (r, g, bl, a float64) {
c := C.pkguiNewColorDoubles() c := C.pkguiAllocColorDoubles()
defer C.pkguiFreeColorDoubles(c) defer C.pkguiFreeColorDoubles(c)
C.uiColorButtonColor(b.b, c.r, c.g, c.b, c.a) 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)) return float64(*(c.r)), float64(*(c.g)), float64(*(c.b)), float64(*(c.a))

View File

@ -2,49 +2,7 @@
package ui package ui
// #include <stdlib.h> // #include "pkgui.h"
// #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);
// }
import "C" import "C"
// Attribute stores information about an attribute in an // Attribute stores information about an attribute in an
@ -317,8 +275,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute {
case C.uiAttributeTypeStretch: case C.uiAttributeTypeStretch:
return TextStretch(C.uiAttributeStretch(a)) return TextStretch(C.uiAttributeStretch(a))
case C.uiAttributeTypeColor: case C.uiAttributeTypeColor:
cc := C.pkguiNewCColor() cc := C.pkguiAllocColorDoubles()
defer C.pkguiFreeCColor(cc) defer C.pkguiFreeColorDoubles(cc)
C.uiAttributeColor(a, cc.r, cc.g, cc.b, cc.a) C.uiAttributeColor(a, cc.r, cc.g, cc.b, cc.a)
return TextColor{ return TextColor{
R: float64(*(cc.r)), R: float64(*(cc.r)),
@ -327,8 +285,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute {
A: float64(*(cc.a)), A: float64(*(cc.a)),
} }
case C.uiAttributeTypeBackground: case C.uiAttributeTypeBackground:
cc := C.pkguiNewCColor() cc := C.pkguiAllocColorDoubles()
defer C.pkguiFreeCColor(cc) defer C.pkguiFreeColorDoubles(cc)
C.uiAttributeColor(a, cc.r, cc.g, cc.b, cc.a) C.uiAttributeColor(a, cc.r, cc.g, cc.b, cc.a)
return TextBackground{ return TextBackground{
R: float64(*(cc.r)), R: float64(*(cc.r)),
@ -341,8 +299,8 @@ func attributeFromLibui(a *C.uiAttribute) Attribute {
case C.uiAttributeTypeUnderlineColor: case C.uiAttributeTypeUnderlineColor:
cu := C.pkguiNewUnderlineColor() cu := C.pkguiNewUnderlineColor()
defer C.pkguiFreeUnderlineColor(cu) defer C.pkguiFreeUnderlineColor(cu)
cc := C.pkguiNewCColor() cc := C.pkguiAllocColorDoubles()
defer C.pkguiFreeCColor(cc) defer C.pkguiFreeColorDoubles(cc)
C.uiAttributeUnderlineColor(a, cu, cc.r, cc.g, cc.b, cc.a) C.uiAttributeUnderlineColor(a, cu, cc.r, cc.g, cc.b, cc.a)
if *cu == C.uiUnderlineColorCustom { if *cu == C.uiUnderlineColorCustom {
return UnderlineColorCustom{ return UnderlineColorCustom{

View File

@ -6,20 +6,7 @@ import (
"unsafe" "unsafe"
) )
// #include <stdlib.h> // #include "pkgui.h"
// #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);
// }
import "C" import "C"
// FontButton is a Control that represents a button that the user can // FontButton is a Control that represents a button that the user can
@ -36,7 +23,7 @@ func NewFontButton() *FontButton {
b.b = C.uiNewFontButton() 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))) b.ControlBase = NewControlBase(b, uintptr(unsafe.Pointer(b.b)))
return b return b
@ -60,8 +47,8 @@ func (b *FontButton) OnChanged(f func(*FontButton)) {
b.onChanged = f b.onChanged = f
} }
//export doFontButtonOnChanged //export pkguiDoFontButtonOnChanged
func doFontButtonOnChanged(bb *C.uiFontButton, data unsafe.Pointer) { func pkguiDoFontButtonOnChanged(bb *C.uiFontButton, data unsafe.Pointer) {
b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*FontButton) b := ControlFromLibui(uintptr(unsafe.Pointer(bb))).(*FontButton)
if b.onChanged != nil { if b.onChanged != nil {
b.onChanged(b) b.onChanged(b)

43
pkgui.c
View File

@ -42,14 +42,6 @@ void pkguiColorButtonOnChanged(uiColorButton *c)
uiColorButtonOnChanged(c, pkguiDoColorButtonOnChanged, NULL); uiColorButtonOnChanged(c, pkguiDoColorButtonOnChanged, NULL);
} }
typedef struct pkguiColorDoubles pkguiColorDoubles;
struct pkguiColorDoubles {
double *r;
double *g;
double *b;
double *a;
};
pkguiColorDoubles pkguiAllocColorDoubles(void) pkguiColorDoubles pkguiAllocColorDoubles(void)
{ {
pkguiColorDoubles c; pkguiColorDoubles c;
@ -96,6 +88,11 @@ void pkguiEntryOnChanged(uiEntry *e)
uiEntryOnChanged(e, pkguiDoEntryOnChanged, NULL); uiEntryOnChanged(e, pkguiDoEntryOnChanged, NULL);
} }
void pkguiFontButtonOnChanged(uiFontButton *b)
{
uiFontButtonOnChanged(b, pkguiDoFontButtonOnChanged, NULL);
}
void pkguiMultilineEntryOnChanged(uiMultilineEntry *e) void pkguiMultilineEntryOnChanged(uiMultilineEntry *e)
{ {
uiMultilineEntryOnChanged(e, pkguiDoMultilineEntryOnChanged, NULL); uiMultilineEntryOnChanged(e, pkguiDoMultilineEntryOnChanged, NULL);
@ -179,3 +176,33 @@ void pkguiFreeMatrix(uiDrawMatrix *m)
{ {
free(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);
}

11
pkgui.h
View File

@ -48,6 +48,9 @@ extern void pkguiEditableComboboxOnChanged(uiEditableCombobox *c);
// entry.go // entry.go
extern void pkguiEntryOnChanged(uiEntry *e); extern void pkguiEntryOnChanged(uiEntry *e);
// fontbutton.go
extern void pkguiFontButtonOnChanged(uiFontButton *b);
// multilineentry.go // multilineentry.go
extern void pkguiMultilineEntryOnChanged(uiMultilineEntry *e); extern void pkguiMultilineEntryOnChanged(uiMultilineEntry *e);
@ -74,4 +77,12 @@ extern void pkguiSetDash(double *dashes, size_t i, double dash);
extern uiDrawMatrix *pkguiAllocMatrix(void); extern uiDrawMatrix *pkguiAllocMatrix(void);
extern void pkguiFreeMatrix(uiDrawMatrix *m); 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 #endif