From 280ef464f6241bb37e1a2cb2f61eb0968785cadc Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 24 Dec 2015 18:05:16 -0500 Subject: [PATCH 01/16] Started work on text rendering. Right now, features match Pango; they will be stripped as needed. Also I never committed test/page8.c; whoops. --- test/page8.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++ ui.h | 69 ++++++++++++++++++++ 2 files changed, 244 insertions(+) create mode 100644 test/page8.c diff --git a/test/page8.c b/test/page8.c new file mode 100644 index 00000000..e5d565cf --- /dev/null +++ b/test/page8.c @@ -0,0 +1,175 @@ +// 22 december 2015 +#include "test.h" + +static void onListFonts(uiButton *b, void *data) +{ + uiDrawFontFamilies *ff; + char *this; + uintmax_t i, n; + + uiMultilineEntrySetText(uiMultilineEntry(data), ""); + ff = uiDrawListFontFamilies(); + n = uiDrawFontFamiliesNumFamilies(ff); + for (i = 0; i < n; i++) { + this = uiDrawFontFamiliesFamily(ff, i); + uiMultilineEntryAppend(uiMultilineEntry(data), this); + uiMultilineEntryAppend(uiMultilineEntry(data), "\n"); + uiFreeText(this); + } + uiDrawFreeFontFamilies(ff); +} + +static uiEntry *textString; +static uiEntry *textFont; +static uiEntry *textSize; +static uiCombobox *textWeight; +static uiCombobox *textItalic; +static uiCheckbox *textSmallCaps; +static uiCombobox *textStretch; +static uiEntry *textR, *textG, *textB, *textA; +static uiCheckbox *textHasBackground; +static uiEntry *textBR, *textBG, *textBB, *textBA; +static uiCheckbox *textHasStrikethrough; +static uiEntry *textSR, *textSG, *textSB, *textSA; +static uiCheckbox *textHasUnderline; +static uiEntry *textUR, *textUG, *textUB, *textUA; +static uiButton *textApply; +static uiArea *textArea; + +static void onTextApply(uiButton *b, void *data) +{ + uiAreaQueueRedrawAll(textArea); +} + +static void mkRGBA(uiBox *parent, uiCheckbox **has, const char *hasText, uiEntry **r, uiEntry **g, uiEntry **b, uiEntry **a, const char *field) +{ + uiBox *hbox; + uiBox *vbox; + + hbox = newHorizontalBox(); + uiBoxAppend(parent, uiControl(hbox), 0); + + if (has != NULL) { + *has = uiNewCheckbox(hasText); + uiBoxAppend(hbox, uiControl(*has), 0); + } + + vbox = newVerticalBox(); + uiBoxAppend(hbox, uiControl(vbox), 1); + + hbox = newHorizontalBox(); + uiBoxAppend(vbox, uiControl(hbox), 0); + + *r = uiNewEntry(); + uiEntrySetText(*r, field); + uiBoxAppend(hbox, uiControl(*r), 1); + + *g = uiNewEntry(); + uiEntrySetText(*g, field); + uiBoxAppend(hbox, uiControl(*g), 1); + + hbox = newHorizontalBox(); + uiBoxAppend(vbox, uiControl(hbox), 0); + + *b = uiNewEntry(); + uiEntrySetText(*b, field); + uiBoxAppend(hbox, uiControl(*b), 1); + + *a = uiNewEntry(); + uiEntrySetText(*a, "1.0"); + uiBoxAppend(hbox, uiControl(*a), 1); +} + +uiBox *makePage8(void) +{ + uiBox *page8; + uiGroup *group; + uiBox *vbox; + uiMultilineEntry *me; + uiButton *button; + + page8 = newHorizontalBox(); + + group = newGroup("Font Families"); + uiBoxAppend(page8, uiControl(group), 1); + + vbox = newVerticalBox(); + uiGroupSetChild(group, uiControl(vbox)); + + me = uiNewMultilineEntry(); + uiBoxAppend(vbox, uiControl(me), 1); + + button = uiNewButton("List Font Families"); + uiButtonOnClicked(button, onListFonts, me); + uiBoxAppend(vbox, uiControl(button), 0); + + group = newGroup("Text Rendering"); + uiBoxAppend(page8, uiControl(group), 1); + + vbox = newVerticalBox(); + uiGroupSetChild(group, uiControl(vbox)); + + textString = uiNewEntry(); + // TODO make it placeholder + uiEntrySetText(textString, "Enter text here"); + uiBoxAppend(vbox, uiControl(textString), 0); + + textFont = uiNewEntry(); + uiEntrySetText(textFont, "Arial"); + uiBoxAppend(vbox, uiControl(textFont), 0); + + textSize = uiNewEntry(); + uiEntrySetText(textSize, "10"); + uiBoxAppend(vbox, uiControl(textSize), 0); + + textWeight = uiNewCombobox(); + uiComboboxAppend(textWeight, "Thin"); + uiComboboxAppend(textWeight, "Ultra Light"); + uiComboboxAppend(textWeight, "Light"); + uiComboboxAppend(textWeight, "Book"); + uiComboboxAppend(textWeight, "Normal"); + uiComboboxAppend(textWeight, "Medium"); + uiComboboxAppend(textWeight, "Semi Bold"); + uiComboboxAppend(textWeight, "Bold"); + uiComboboxAppend(textWeight, "Utra Bold"); + uiComboboxAppend(textWeight, "Heavy"); + uiComboboxAppend(textWeight, "Ultra Heavy"); + uiComboboxSetSelected(textWeight, uiDrawTextWeightNormal); + uiBoxAppend(vbox, uiControl(textWeight), 0); + + textItalic = uiNewCombobox(); + uiComboboxAppend(textItalic, "Normal"); + uiComboboxAppend(textItalic, "Oblique"); + uiComboboxAppend(textItalic, "Italic"); + uiComboboxSetSelected(textItalic, uiDrawTextItalicNormal); + uiBoxAppend(vbox, uiControl(textItalic), 0); + + textSmallCaps = uiNewCheckbox("Small Caps"); + uiBoxAppend(vbox, uiControl(textSmallCaps), 0); + + textStretch = uiNewCombobox(); + uiComboboxAppend(textStretch, "Ultra Condensed"); + uiComboboxAppend(textStretch, "Extra Condensed"); + uiComboboxAppend(textStretch, "Condensed"); + uiComboboxAppend(textStretch, "Semi Condensed"); + uiComboboxAppend(textStretch, "Normal"); + uiComboboxAppend(textStretch, "Semi Expanded"); + uiComboboxAppend(textStretch, "Expanded"); + uiComboboxAppend(textStretch, "Extra Expanded"); + uiComboboxAppend(textStretch, "Ultra Expanded"); + uiComboboxSetSelected(textStretch, uiDrawTextStretchNormal); + uiBoxAppend(vbox, uiControl(textStretch), 0); + + mkRGBA(vbox, NULL, NULL, &textR, &textG, &textB, &textA, "0.0"); + mkRGBA(vbox, &textHasBackground, "Background", &textBR, &textBG, &textBB, &textBA, "1.0"); + mkRGBA(vbox, &textHasStrikethrough, "Strikethrough", &textSR, &textSG, &textSB, &textSA, "0.0"); + mkRGBA(vbox, &textHasUnderline, "Underline", &textUR, &textUG, &textUB, &textUA, "0.0"); + + textApply = uiNewButton("Apply"); + uiButtonOnClicked(textApply, onTextApply, NULL); + uiBoxAppend(vbox, uiControl(textApply), 0); + + // TODO + + return page8; +} diff --git a/ui.h b/ui.h index 2227389c..322315a5 100644 --- a/ui.h +++ b/ui.h @@ -460,6 +460,75 @@ _UI_EXTERN uintmax_t uiDrawFontFamiliesNumFamilies(uiDrawFontFamilies *ff); _UI_EXTERN char *uiDrawFontFamiliesFamily(uiDrawFontFamilies *ff, uintmax_t n); _UI_EXTERN void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff); +typedef struct uiDrawTextStyle uiDrawTextStyle; + +typedef enum uiDrawTextWeight { + uiDrawTextWeightThin, + uiDrawTextWeightUltraLight, + uiDrawTextWeightLight, + uiDrawTextWeightBook, + uiDrawTextWeightNormal, + uiDrawTextWeightMedium, + uiDrawTextWeightSemiBold, + uiDrawTextWeightBold, + uiDrawTextWeightUtraBold, + uiDrawTextWeightHeavy, + uiDrawTextWeightUltraHeavy, +} uiDrawTextWeight; + +// TODO drop Oblique? +typedef enum uiDrawTextItalic { + uiDrawTextItalicNormal, + uiDrawTextItalicOblique, + uiDrawTextItalicItalic, +} uiDrawTextItalic; + +typedef enum uiDrawTextStretch { + uiDrawTextStretchUltraCondensed, + uiDrawTextStretchExtraCondensed, + uiDrawTextStretchCondensed, + uiDrawTextStretchSemiCondensed, + uiDrawTextStretchNormal, + uiDrawTextStretchSemiExpanded, + uiDrawTextStretchExpanded, + uiDrawTextStretchExtraExpanded, + uiDrawTextStretchUltraExpanded, +} uiDrawTextStretch; + +struct uiDrawTextStyle { + const char *Family; + double Size; + uiDrawTextWeight Weight; + uiDrawTextItalic Italic; + int SmallCaps; + uiDrawTextStretch Stretch; + double TextR; + double TextG; + double TextB; + double TextA; + int HasBackgroundColor; + double BackgroundR; + double BackgroundG; + double BakcgroundB; + double BackgroundA; // TODO Pango + int HasStrikethrough; + double StrikethroughR; + double StrikethroughG; + double StrikethroughB; + double StrikethroughA; // TODO Pango + int HasUnderline; + double UnderlineR; + double UnderlineG; + double UnderlineB; + double UnderlineA; // TODO Pango +}; + +_UI_EXTERN double uiDrawTextSizeToPoints(double textSize); +_UI_EXTERN double uiDrawPointsToTextSize(double points); + +// TODO make this more robust. +_UI_EXTERN void uiDrawText(uiDrawContext *context, double x, double y, const char *text, uiDrawTextStyle *style); + typedef enum uiModifiers { uiModifierCtrl = 1 << 0, uiModifierAlt = 1 << 1, From 6ef404c2dd2b9f9f43c9195702f34d91af682540 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 24 Dec 2015 19:48:57 -0500 Subject: [PATCH 02/16] Implemented the basic uiDrawText() function on GTK+. It looks like I missed some PangoAttributes; I'll add those in next. --- test/page8.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++- ui.h | 8 +++-- unix/draw.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 4 deletions(-) diff --git a/test/page8.c b/test/page8.c index e5d565cf..42c72daf 100644 --- a/test/page8.c +++ b/test/page8.c @@ -35,6 +35,78 @@ static uiCheckbox *textHasUnderline; static uiEntry *textUR, *textUG, *textUB, *textUA; static uiButton *textApply; static uiArea *textArea; +static uiAreaHandler textAreaHandler; + +static double entryDouble(uiEntry *e) +{ + char *s; + double d; + + s = uiEntryText(e); + d = atof(s); + uiFreeText(s); + return d; +} + +static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp) +{ + uiDrawTextStyle style; + char *s; + char *family; // make compiler happy + + memset(&style, 0, sizeof (uiDrawTextStyle)); + family = uiEntryText(textFont); + style.Family = family; + style.Size = entryDouble(textSize); + style.Weight = uiComboboxSelected(textWeight); + style.Italic = uiComboboxSelected(textItalic); + style.SmallCaps = uiCheckboxChecked(textSmallCaps); + style.Stretch = uiComboboxSelected(textStretch); + style.TextR = entryDouble(textR); + style.TextG = entryDouble(textG); + style.TextB = entryDouble(textB); + style.TextA = entryDouble(textA); + style.HasBackground = uiCheckboxChecked(textHasBackground); + style.BackgroundR = entryDouble(textBR); + style.BackgroundG = entryDouble(textBG); + style.BackgroundB = entryDouble(textBB); + style.BackgroundA = entryDouble(textBA); + style.HasStrikethrough = uiCheckboxChecked(textHasStrikethrough); + style.StrikethroughR = entryDouble(textSR); + style.StrikethroughG = entryDouble(textSG); + style.StrikethroughB = entryDouble(textSB); + style.StrikethroughA = entryDouble(textSA); + style.HasUnderline = uiCheckboxChecked(textHasUnderline); + style.UnderlineR = entryDouble(textUR); + style.UnderlineG = entryDouble(textUG); + style.UnderlineB = entryDouble(textUB); + style.UnderlineA = entryDouble(textUA); + s = uiEntryText(textString); + uiDrawText(dp->Context, 10, 10, s, &style); + uiFreeText(s); + uiFreeText(family); +} + +static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) +{ + // do nothing +} + +static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) +{ + // do nothing +} + +static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) +{ + // do nothing +} + +static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) +{ + // do nothing + return 0; +} static void onTextApply(uiButton *b, void *data) { @@ -169,7 +241,13 @@ uiBox *makePage8(void) uiButtonOnClicked(textApply, onTextApply, NULL); uiBoxAppend(vbox, uiControl(textApply), 0); - // TODO + textAreaHandler.Draw = handlerDraw; + textAreaHandler.MouseEvent = handlerMouseEvent; + textAreaHandler.MouseCrossed = handlerMouseCrossed; + textAreaHandler.DragBroken = handlerDragBroken; + textAreaHandler.KeyEvent = handlerKeyEvent; + textArea = uiNewArea(&textAreaHandler); + uiBoxAppend(vbox, uiControl(textArea), 1); return page8; } diff --git a/ui.h b/ui.h index 322315a5..b9943160 100644 --- a/ui.h +++ b/ui.h @@ -496,6 +496,7 @@ typedef enum uiDrawTextStretch { } uiDrawTextStretch; struct uiDrawTextStyle { + // TODO Language attribute const char *Family; double Size; uiDrawTextWeight Weight; @@ -506,10 +507,10 @@ struct uiDrawTextStyle { double TextG; double TextB; double TextA; - int HasBackgroundColor; + int HasBackground; double BackgroundR; double BackgroundG; - double BakcgroundB; + double BackgroundB; double BackgroundA; // TODO Pango int HasStrikethrough; double StrikethroughR; @@ -521,13 +522,14 @@ struct uiDrawTextStyle { double UnderlineG; double UnderlineB; double UnderlineA; // TODO Pango + // TODO other Pango attributes }; _UI_EXTERN double uiDrawTextSizeToPoints(double textSize); _UI_EXTERN double uiDrawPointsToTextSize(double points); // TODO make this more robust. -_UI_EXTERN void uiDrawText(uiDrawContext *context, double x, double y, const char *text, uiDrawTextStyle *style); +_UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, const char *text, uiDrawTextStyle *style); typedef enum uiModifiers { uiModifierCtrl = 1 << 0, diff --git a/unix/draw.c b/unix/draw.c index 83827694..5d2490b2 100644 --- a/unix/draw.c +++ b/unix/draw.c @@ -482,3 +482,91 @@ void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff) g_free(ff->f); uiFree(ff); } + +double uiDrawTextSizeToPoints(double textSize) +{ + gint pangoSize; + + pangoSize = (gint) (textSize * PANGO_SCALE); + return ((double) pangoSize) / PANGO_SCALE; +} + +double uiDrawPointsToTextSize(double points) +{ + // yeah, as far as I can tell the two functions are equivalent + // TODO verify + // TODO make sure they aren't just equivalent + return uiDrawTextSizeToPoints(points); +} + +static const PangoWeight pangoWeights[] = { + [uiDrawTextWeightThin] = PANGO_WEIGHT_THIN, + [uiDrawTextWeightUltraLight] = PANGO_WEIGHT_ULTRALIGHT, + [uiDrawTextWeightLight] = PANGO_WEIGHT_LIGHT, + [uiDrawTextWeightBook] = PANGO_WEIGHT_BOOK, + [uiDrawTextWeightNormal] = PANGO_WEIGHT_NORMAL, + [uiDrawTextWeightMedium] = PANGO_WEIGHT_MEDIUM, + [uiDrawTextWeightSemiBold] = PANGO_WEIGHT_SEMIBOLD, + [uiDrawTextWeightBold] = PANGO_WEIGHT_BOLD, + [uiDrawTextWeightUtraBold] = PANGO_WEIGHT_ULTRABOLD, + [uiDrawTextWeightHeavy] = PANGO_WEIGHT_HEAVY, + [uiDrawTextWeightUltraHeavy] = PANGO_WEIGHT_ULTRAHEAVY, +}; + +static const PangoStyle pangoItalics[] = { + [uiDrawTextItalicNormal] = PANGO_STYLE_NORMAL, + [uiDrawTextItalicOblique] = PANGO_STYLE_OBLIQUE, + [uiDrawTextItalicItalic] = PANGO_STYLE_ITALIC, +}; + +static const PangoStretch pangoStretches[] = { + [uiDrawTextStretchUltraCondensed] = PANGO_STRETCH_ULTRA_CONDENSED, + [uiDrawTextStretchExtraCondensed] = PANGO_STRETCH_EXTRA_CONDENSED, + [uiDrawTextStretchCondensed] = PANGO_STRETCH_CONDENSED, + [uiDrawTextStretchSemiCondensed] = PANGO_STRETCH_SEMI_CONDENSED, + [uiDrawTextStretchNormal] = PANGO_STRETCH_NORMAL, + [uiDrawTextStretchSemiExpanded] = PANGO_STRETCH_SEMI_EXPANDED, + [uiDrawTextStretchExpanded] = PANGO_STRETCH_EXPANDED, + [uiDrawTextStretchExtraExpanded] = PANGO_STRETCH_EXTRA_EXPANDED, + [uiDrawTextStretchUltraExpanded] = PANGO_STRETCH_ULTRA_EXPANDED, +}; + +void uiDrawText(uiDrawContext *c, double x, double y, const char *text, uiDrawTextStyle *style) +{ + PangoAttrList *attrs; + PangoLayout *layout; + + attrs = pango_attr_list_new(); + pango_attr_list_insert(attrs, + pango_attr_family_new(style->Family)); + pango_attr_list_insert(attrs, + pango_attr_size_new((gint) (style->Size * PANGO_SCALE))); + pango_attr_list_insert(attrs, + pango_attr_weight_new(pangoWeights[style->Weight])); + pango_attr_list_insert(attrs, + pango_attr_style_new(pangoItalics[style->Italic])); + if (style->SmallCaps) + pango_attr_list_insert(attrs, + pango_attr_variant_new(PANGO_VARIANT_SMALL_CAPS)); + pango_attr_list_insert(attrs, + pango_attr_stretch_new(pangoStretches[style->Stretch])); + cairo_set_source_rgba(c->cr, style->TextR, style->TextG, style->TextB, style->TextA); + if (style->HasBackground) { + // TODO + } + if (style->HasStrikethrough) { + // TODO + } + if (style->HasUnderline) { + // TODO + } + + layout = pango_cairo_create_layout(c->cr); + pango_layout_set_text(layout, text, -1); + pango_layout_set_attributes(layout, attrs); + cairo_move_to(c->cr, x, y); + pango_cairo_show_layout(c->cr, layout); + + g_object_unref(layout); + pango_attr_list_unref(attrs); +} From 353afcd464dd3200d7f9899ef97bc4ed5b8ccffa Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 24 Dec 2015 22:31:32 -0500 Subject: [PATCH 03/16] Added the Language field to the text styles list. --- ui.h | 2 +- unix/draw.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ui.h b/ui.h index b9943160..e4463119 100644 --- a/ui.h +++ b/ui.h @@ -496,7 +496,6 @@ typedef enum uiDrawTextStretch { } uiDrawTextStretch; struct uiDrawTextStyle { - // TODO Language attribute const char *Family; double Size; uiDrawTextWeight Weight; @@ -522,6 +521,7 @@ struct uiDrawTextStyle { double UnderlineG; double UnderlineB; double UnderlineA; // TODO Pango + const char *Language; // RFC 3066; NULL for default // TODO other Pango attributes }; diff --git a/unix/draw.c b/unix/draw.c index 5d2490b2..006431b0 100644 --- a/unix/draw.c +++ b/unix/draw.c @@ -560,6 +560,9 @@ void uiDrawText(uiDrawContext *c, double x, double y, const char *text, uiDrawTe if (style->HasUnderline) { // TODO } + if (style->Language != NULL) + pango_attr_list_insert(attrs, + pango_attr_language_new(pango_language_from_string(style->Language))); layout = pango_cairo_create_layout(c->cr); pango_layout_set_text(layout, text, -1); From 6fd945b6024610f4215217191f68bea6e6491341 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 24 Dec 2015 22:59:00 -0500 Subject: [PATCH 04/16] Split the text test onto a separate page, Page 9. --- test/GNUfiles.mk | 1 + test/main.c | 7 +- test/page8.c | 207 --------------------------------------------- test/page9.c | 214 +++++++++++++++++++++++++++++++++++++++++++++++ test/test.h | 3 + 5 files changed, 223 insertions(+), 209 deletions(-) create mode 100644 test/page9.c diff --git a/test/GNUfiles.mk b/test/GNUfiles.mk index 6b6feffe..e1bc8f9d 100644 --- a/test/GNUfiles.mk +++ b/test/GNUfiles.mk @@ -15,6 +15,7 @@ CFILES += \ test/page7b.c \ test/page7c.c \ test/page8.c \ + test/page9.c \ test/spaced.c HFILES += \ diff --git a/test/main.c b/test/main.c index 7e41189e..675d1f4c 100644 --- a/test/main.c +++ b/test/main.c @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) int i; const char *err; uiWindow *w; - uiBox *page2, *page3, *page4, *page5, *page6, *page7, *page8; + uiBox *page2, *page3, *page4, *page5, *page6, *page7, *page8, *page9; uiTab *outerTab; uiTab *innerTab; int nomenus = 0; @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) uiTabAppend(mainTab, "Page 5", uiControl(page5)); innerTab = newTab(); - uiTabAppend(outerTab, "Pages 6-8", uiControl(innerTab)); + uiTabAppend(outerTab, "Pages 6-9", uiControl(innerTab)); page6 = makePage6(); uiTabAppend(innerTab, "Page 6", uiControl(page6)); @@ -124,6 +124,9 @@ int main(int argc, char *argv[]) page8 = makePage8(); uiTabAppend(innerTab, "Page 8", uiControl(page8)); + page9 = makePage9(); + uiTabAppend(innerTab, "Page 9", uiControl(page9)); + if (startspaced) setSpaced(1); diff --git a/test/page8.c b/test/page8.c index 42c72daf..3819257d 100644 --- a/test/page8.c +++ b/test/page8.c @@ -19,139 +19,6 @@ static void onListFonts(uiButton *b, void *data) uiDrawFreeFontFamilies(ff); } -static uiEntry *textString; -static uiEntry *textFont; -static uiEntry *textSize; -static uiCombobox *textWeight; -static uiCombobox *textItalic; -static uiCheckbox *textSmallCaps; -static uiCombobox *textStretch; -static uiEntry *textR, *textG, *textB, *textA; -static uiCheckbox *textHasBackground; -static uiEntry *textBR, *textBG, *textBB, *textBA; -static uiCheckbox *textHasStrikethrough; -static uiEntry *textSR, *textSG, *textSB, *textSA; -static uiCheckbox *textHasUnderline; -static uiEntry *textUR, *textUG, *textUB, *textUA; -static uiButton *textApply; -static uiArea *textArea; -static uiAreaHandler textAreaHandler; - -static double entryDouble(uiEntry *e) -{ - char *s; - double d; - - s = uiEntryText(e); - d = atof(s); - uiFreeText(s); - return d; -} - -static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp) -{ - uiDrawTextStyle style; - char *s; - char *family; // make compiler happy - - memset(&style, 0, sizeof (uiDrawTextStyle)); - family = uiEntryText(textFont); - style.Family = family; - style.Size = entryDouble(textSize); - style.Weight = uiComboboxSelected(textWeight); - style.Italic = uiComboboxSelected(textItalic); - style.SmallCaps = uiCheckboxChecked(textSmallCaps); - style.Stretch = uiComboboxSelected(textStretch); - style.TextR = entryDouble(textR); - style.TextG = entryDouble(textG); - style.TextB = entryDouble(textB); - style.TextA = entryDouble(textA); - style.HasBackground = uiCheckboxChecked(textHasBackground); - style.BackgroundR = entryDouble(textBR); - style.BackgroundG = entryDouble(textBG); - style.BackgroundB = entryDouble(textBB); - style.BackgroundA = entryDouble(textBA); - style.HasStrikethrough = uiCheckboxChecked(textHasStrikethrough); - style.StrikethroughR = entryDouble(textSR); - style.StrikethroughG = entryDouble(textSG); - style.StrikethroughB = entryDouble(textSB); - style.StrikethroughA = entryDouble(textSA); - style.HasUnderline = uiCheckboxChecked(textHasUnderline); - style.UnderlineR = entryDouble(textUR); - style.UnderlineG = entryDouble(textUG); - style.UnderlineB = entryDouble(textUB); - style.UnderlineA = entryDouble(textUA); - s = uiEntryText(textString); - uiDrawText(dp->Context, 10, 10, s, &style); - uiFreeText(s); - uiFreeText(family); -} - -static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) -{ - // do nothing -} - -static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) -{ - // do nothing -} - -static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) -{ - // do nothing -} - -static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) -{ - // do nothing - return 0; -} - -static void onTextApply(uiButton *b, void *data) -{ - uiAreaQueueRedrawAll(textArea); -} - -static void mkRGBA(uiBox *parent, uiCheckbox **has, const char *hasText, uiEntry **r, uiEntry **g, uiEntry **b, uiEntry **a, const char *field) -{ - uiBox *hbox; - uiBox *vbox; - - hbox = newHorizontalBox(); - uiBoxAppend(parent, uiControl(hbox), 0); - - if (has != NULL) { - *has = uiNewCheckbox(hasText); - uiBoxAppend(hbox, uiControl(*has), 0); - } - - vbox = newVerticalBox(); - uiBoxAppend(hbox, uiControl(vbox), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - *r = uiNewEntry(); - uiEntrySetText(*r, field); - uiBoxAppend(hbox, uiControl(*r), 1); - - *g = uiNewEntry(); - uiEntrySetText(*g, field); - uiBoxAppend(hbox, uiControl(*g), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - - *b = uiNewEntry(); - uiEntrySetText(*b, field); - uiBoxAppend(hbox, uiControl(*b), 1); - - *a = uiNewEntry(); - uiEntrySetText(*a, "1.0"); - uiBoxAppend(hbox, uiControl(*a), 1); -} - uiBox *makePage8(void) { uiBox *page8; @@ -175,79 +42,5 @@ uiBox *makePage8(void) uiButtonOnClicked(button, onListFonts, me); uiBoxAppend(vbox, uiControl(button), 0); - group = newGroup("Text Rendering"); - uiBoxAppend(page8, uiControl(group), 1); - - vbox = newVerticalBox(); - uiGroupSetChild(group, uiControl(vbox)); - - textString = uiNewEntry(); - // TODO make it placeholder - uiEntrySetText(textString, "Enter text here"); - uiBoxAppend(vbox, uiControl(textString), 0); - - textFont = uiNewEntry(); - uiEntrySetText(textFont, "Arial"); - uiBoxAppend(vbox, uiControl(textFont), 0); - - textSize = uiNewEntry(); - uiEntrySetText(textSize, "10"); - uiBoxAppend(vbox, uiControl(textSize), 0); - - textWeight = uiNewCombobox(); - uiComboboxAppend(textWeight, "Thin"); - uiComboboxAppend(textWeight, "Ultra Light"); - uiComboboxAppend(textWeight, "Light"); - uiComboboxAppend(textWeight, "Book"); - uiComboboxAppend(textWeight, "Normal"); - uiComboboxAppend(textWeight, "Medium"); - uiComboboxAppend(textWeight, "Semi Bold"); - uiComboboxAppend(textWeight, "Bold"); - uiComboboxAppend(textWeight, "Utra Bold"); - uiComboboxAppend(textWeight, "Heavy"); - uiComboboxAppend(textWeight, "Ultra Heavy"); - uiComboboxSetSelected(textWeight, uiDrawTextWeightNormal); - uiBoxAppend(vbox, uiControl(textWeight), 0); - - textItalic = uiNewCombobox(); - uiComboboxAppend(textItalic, "Normal"); - uiComboboxAppend(textItalic, "Oblique"); - uiComboboxAppend(textItalic, "Italic"); - uiComboboxSetSelected(textItalic, uiDrawTextItalicNormal); - uiBoxAppend(vbox, uiControl(textItalic), 0); - - textSmallCaps = uiNewCheckbox("Small Caps"); - uiBoxAppend(vbox, uiControl(textSmallCaps), 0); - - textStretch = uiNewCombobox(); - uiComboboxAppend(textStretch, "Ultra Condensed"); - uiComboboxAppend(textStretch, "Extra Condensed"); - uiComboboxAppend(textStretch, "Condensed"); - uiComboboxAppend(textStretch, "Semi Condensed"); - uiComboboxAppend(textStretch, "Normal"); - uiComboboxAppend(textStretch, "Semi Expanded"); - uiComboboxAppend(textStretch, "Expanded"); - uiComboboxAppend(textStretch, "Extra Expanded"); - uiComboboxAppend(textStretch, "Ultra Expanded"); - uiComboboxSetSelected(textStretch, uiDrawTextStretchNormal); - uiBoxAppend(vbox, uiControl(textStretch), 0); - - mkRGBA(vbox, NULL, NULL, &textR, &textG, &textB, &textA, "0.0"); - mkRGBA(vbox, &textHasBackground, "Background", &textBR, &textBG, &textBB, &textBA, "1.0"); - mkRGBA(vbox, &textHasStrikethrough, "Strikethrough", &textSR, &textSG, &textSB, &textSA, "0.0"); - mkRGBA(vbox, &textHasUnderline, "Underline", &textUR, &textUG, &textUB, &textUA, "0.0"); - - textApply = uiNewButton("Apply"); - uiButtonOnClicked(textApply, onTextApply, NULL); - uiBoxAppend(vbox, uiControl(textApply), 0); - - textAreaHandler.Draw = handlerDraw; - textAreaHandler.MouseEvent = handlerMouseEvent; - textAreaHandler.MouseCrossed = handlerMouseCrossed; - textAreaHandler.DragBroken = handlerDragBroken; - textAreaHandler.KeyEvent = handlerKeyEvent; - textArea = uiNewArea(&textAreaHandler); - uiBoxAppend(vbox, uiControl(textArea), 1); - return page8; } diff --git a/test/page9.c b/test/page9.c new file mode 100644 index 00000000..e724966a --- /dev/null +++ b/test/page9.c @@ -0,0 +1,214 @@ +// 22 december 2015 +#include "test.h" + +static uiEntry *textString; +static uiEntry *textFont; +static uiEntry *textSize; +static uiCombobox *textWeight; +static uiCombobox *textItalic; +static uiCheckbox *textSmallCaps; +static uiCombobox *textStretch; +static uiEntry *textR, *textG, *textB, *textA; +static uiCheckbox *textHasBackground; +static uiEntry *textBR, *textBG, *textBB, *textBA; +static uiCheckbox *textHasStrikethrough; +static uiEntry *textSR, *textSG, *textSB, *textSA; +static uiCheckbox *textHasUnderline; +static uiEntry *textUR, *textUG, *textUB, *textUA; +static uiButton *textApply; +static uiArea *textArea; +static uiAreaHandler textAreaHandler; + +static double entryDouble(uiEntry *e) +{ + char *s; + double d; + + s = uiEntryText(e); + d = atof(s); + uiFreeText(s); + return d; +} + +static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp) +{ + uiDrawTextStyle style; + char *s; + char *family; // make compiler happy + + memset(&style, 0, sizeof (uiDrawTextStyle)); + family = uiEntryText(textFont); + style.Family = family; + style.Size = entryDouble(textSize); + style.Weight = uiComboboxSelected(textWeight); + style.Italic = uiComboboxSelected(textItalic); + style.SmallCaps = uiCheckboxChecked(textSmallCaps); + style.Stretch = uiComboboxSelected(textStretch); + style.TextR = entryDouble(textR); + style.TextG = entryDouble(textG); + style.TextB = entryDouble(textB); + style.TextA = entryDouble(textA); + style.HasBackground = uiCheckboxChecked(textHasBackground); + style.BackgroundR = entryDouble(textBR); + style.BackgroundG = entryDouble(textBG); + style.BackgroundB = entryDouble(textBB); + style.BackgroundA = entryDouble(textBA); + style.HasStrikethrough = uiCheckboxChecked(textHasStrikethrough); + style.StrikethroughR = entryDouble(textSR); + style.StrikethroughG = entryDouble(textSG); + style.StrikethroughB = entryDouble(textSB); + style.StrikethroughA = entryDouble(textSA); + style.HasUnderline = uiCheckboxChecked(textHasUnderline); + style.UnderlineR = entryDouble(textUR); + style.UnderlineG = entryDouble(textUG); + style.UnderlineB = entryDouble(textUB); + style.UnderlineA = entryDouble(textUA); + s = uiEntryText(textString); + uiDrawText(dp->Context, 10, 10, s, &style); + uiFreeText(s); + uiFreeText(family); +} + +static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) +{ + // do nothing +} + +static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) +{ + // do nothing +} + +static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) +{ + // do nothing +} + +static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) +{ + // do nothing + return 0; +} + +static void onTextApply(uiButton *b, void *data) +{ + uiAreaQueueRedrawAll(textArea); +} + +static void mkRGBA(uiBox *parent, uiCheckbox **has, const char *hasText, uiEntry **r, uiEntry **g, uiEntry **b, uiEntry **a, const char *field) +{ + uiBox *hbox; + uiBox *vbox; + + hbox = newHorizontalBox(); + uiBoxAppend(parent, uiControl(hbox), 0); + + if (has != NULL) { + *has = uiNewCheckbox(hasText); + uiBoxAppend(hbox, uiControl(*has), 0); + } + + vbox = newVerticalBox(); + uiBoxAppend(hbox, uiControl(vbox), 1); + + hbox = newHorizontalBox(); + uiBoxAppend(vbox, uiControl(hbox), 0); + + *r = uiNewEntry(); + uiEntrySetText(*r, field); + uiBoxAppend(hbox, uiControl(*r), 1); + + *g = uiNewEntry(); + uiEntrySetText(*g, field); + uiBoxAppend(hbox, uiControl(*g), 1); + + hbox = newHorizontalBox(); + uiBoxAppend(vbox, uiControl(hbox), 0); + + *b = uiNewEntry(); + uiEntrySetText(*b, field); + uiBoxAppend(hbox, uiControl(*b), 1); + + *a = uiNewEntry(); + uiEntrySetText(*a, "1.0"); + uiBoxAppend(hbox, uiControl(*a), 1); +} + +uiBox *makePage9(void) +{ + uiBox *page9; + uiBox *vbox; + + page9 = newVerticalBox(); + vbox = page9; + + textString = uiNewEntry(); + // TODO make it placeholder + uiEntrySetText(textString, "Enter text here"); + uiBoxAppend(vbox, uiControl(textString), 0); + + textFont = uiNewEntry(); + uiEntrySetText(textFont, "Arial"); + uiBoxAppend(vbox, uiControl(textFont), 0); + + textSize = uiNewEntry(); + uiEntrySetText(textSize, "10"); + uiBoxAppend(vbox, uiControl(textSize), 0); + + textWeight = uiNewCombobox(); + uiComboboxAppend(textWeight, "Thin"); + uiComboboxAppend(textWeight, "Ultra Light"); + uiComboboxAppend(textWeight, "Light"); + uiComboboxAppend(textWeight, "Book"); + uiComboboxAppend(textWeight, "Normal"); + uiComboboxAppend(textWeight, "Medium"); + uiComboboxAppend(textWeight, "Semi Bold"); + uiComboboxAppend(textWeight, "Bold"); + uiComboboxAppend(textWeight, "Utra Bold"); + uiComboboxAppend(textWeight, "Heavy"); + uiComboboxAppend(textWeight, "Ultra Heavy"); + uiComboboxSetSelected(textWeight, uiDrawTextWeightNormal); + uiBoxAppend(vbox, uiControl(textWeight), 0); + + textItalic = uiNewCombobox(); + uiComboboxAppend(textItalic, "Normal"); + uiComboboxAppend(textItalic, "Oblique"); + uiComboboxAppend(textItalic, "Italic"); + uiComboboxSetSelected(textItalic, uiDrawTextItalicNormal); + uiBoxAppend(vbox, uiControl(textItalic), 0); + + textSmallCaps = uiNewCheckbox("Small Caps"); + uiBoxAppend(vbox, uiControl(textSmallCaps), 0); + + textStretch = uiNewCombobox(); + uiComboboxAppend(textStretch, "Ultra Condensed"); + uiComboboxAppend(textStretch, "Extra Condensed"); + uiComboboxAppend(textStretch, "Condensed"); + uiComboboxAppend(textStretch, "Semi Condensed"); + uiComboboxAppend(textStretch, "Normal"); + uiComboboxAppend(textStretch, "Semi Expanded"); + uiComboboxAppend(textStretch, "Expanded"); + uiComboboxAppend(textStretch, "Extra Expanded"); + uiComboboxAppend(textStretch, "Ultra Expanded"); + uiComboboxSetSelected(textStretch, uiDrawTextStretchNormal); + uiBoxAppend(vbox, uiControl(textStretch), 0); + + mkRGBA(vbox, NULL, NULL, &textR, &textG, &textB, &textA, "0.0"); + mkRGBA(vbox, &textHasBackground, "Background", &textBR, &textBG, &textBB, &textBA, "1.0"); + mkRGBA(vbox, &textHasStrikethrough, "Strikethrough", &textSR, &textSG, &textSB, &textSA, "0.0"); + mkRGBA(vbox, &textHasUnderline, "Underline", &textUR, &textUG, &textUB, &textUA, "0.0"); + + textApply = uiNewButton("Apply"); + uiButtonOnClicked(textApply, onTextApply, NULL); + uiBoxAppend(vbox, uiControl(textApply), 0); + + textAreaHandler.Draw = handlerDraw; + textAreaHandler.MouseEvent = handlerMouseEvent; + textAreaHandler.MouseCrossed = handlerMouseCrossed; + textAreaHandler.DragBroken = handlerDragBroken; + textAreaHandler.KeyEvent = handlerKeyEvent; + textArea = uiNewArea(&textAreaHandler); + uiBoxAppend(vbox, uiControl(textArea), 1); + + return page9; +} diff --git a/test/test.h b/test/test.h index c277c62b..2d47c2b8 100644 --- a/test/test.h +++ b/test/test.h @@ -68,3 +68,6 @@ extern uiGroup *makePage7c(void); // page8.c extern uiBox *makePage8(void); + +// page9.c +extern uiBox *makePage9(void); From 15bb89977003d1124b94b35f4233c2107428fa39 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 24 Dec 2015 23:04:07 -0500 Subject: [PATCH 05/16] Vertically condensed Page 9 a bit. --- test/page9.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/test/page9.c b/test/page9.c index e724966a..a073788d 100644 --- a/test/page9.c +++ b/test/page9.c @@ -98,7 +98,6 @@ static void onTextApply(uiButton *b, void *data) static void mkRGBA(uiBox *parent, uiCheckbox **has, const char *hasText, uiEntry **r, uiEntry **g, uiEntry **b, uiEntry **a, const char *field) { uiBox *hbox; - uiBox *vbox; hbox = newHorizontalBox(); uiBoxAppend(parent, uiControl(hbox), 0); @@ -108,12 +107,6 @@ static void mkRGBA(uiBox *parent, uiCheckbox **has, const char *hasText, uiEntry uiBoxAppend(hbox, uiControl(*has), 0); } - vbox = newVerticalBox(); - uiBoxAppend(hbox, uiControl(vbox), 1); - - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - *r = uiNewEntry(); uiEntrySetText(*r, field); uiBoxAppend(hbox, uiControl(*r), 1); @@ -122,9 +115,6 @@ static void mkRGBA(uiBox *parent, uiCheckbox **has, const char *hasText, uiEntry uiEntrySetText(*g, field); uiBoxAppend(hbox, uiControl(*g), 1); - hbox = newHorizontalBox(); - uiBoxAppend(vbox, uiControl(hbox), 0); - *b = uiNewEntry(); uiEntrySetText(*b, field); uiBoxAppend(hbox, uiControl(*b), 1); @@ -138,22 +128,29 @@ uiBox *makePage9(void) { uiBox *page9; uiBox *vbox; + uiBox *hbox; page9 = newVerticalBox(); vbox = page9; + hbox = newHorizontalBox(); + uiBoxAppend(vbox, uiControl(hbox), 0); + textString = uiNewEntry(); // TODO make it placeholder uiEntrySetText(textString, "Enter text here"); - uiBoxAppend(vbox, uiControl(textString), 0); + uiBoxAppend(hbox, uiControl(textString), 1); textFont = uiNewEntry(); uiEntrySetText(textFont, "Arial"); - uiBoxAppend(vbox, uiControl(textFont), 0); + uiBoxAppend(hbox, uiControl(textFont), 1); textSize = uiNewEntry(); uiEntrySetText(textSize, "10"); - uiBoxAppend(vbox, uiControl(textSize), 0); + uiBoxAppend(hbox, uiControl(textSize), 1); + + hbox = newHorizontalBox(); + uiBoxAppend(vbox, uiControl(hbox), 0); textWeight = uiNewCombobox(); uiComboboxAppend(textWeight, "Thin"); @@ -168,17 +165,20 @@ uiBox *makePage9(void) uiComboboxAppend(textWeight, "Heavy"); uiComboboxAppend(textWeight, "Ultra Heavy"); uiComboboxSetSelected(textWeight, uiDrawTextWeightNormal); - uiBoxAppend(vbox, uiControl(textWeight), 0); + uiBoxAppend(hbox, uiControl(textWeight), 1); textItalic = uiNewCombobox(); uiComboboxAppend(textItalic, "Normal"); uiComboboxAppend(textItalic, "Oblique"); uiComboboxAppend(textItalic, "Italic"); uiComboboxSetSelected(textItalic, uiDrawTextItalicNormal); - uiBoxAppend(vbox, uiControl(textItalic), 0); + uiBoxAppend(hbox, uiControl(textItalic), 1); textSmallCaps = uiNewCheckbox("Small Caps"); - uiBoxAppend(vbox, uiControl(textSmallCaps), 0); + uiBoxAppend(hbox, uiControl(textSmallCaps), 1); + + hbox = newHorizontalBox(); + uiBoxAppend(vbox, uiControl(hbox), 0); textStretch = uiNewCombobox(); uiComboboxAppend(textStretch, "Ultra Condensed"); @@ -191,7 +191,7 @@ uiBox *makePage9(void) uiComboboxAppend(textStretch, "Extra Expanded"); uiComboboxAppend(textStretch, "Ultra Expanded"); uiComboboxSetSelected(textStretch, uiDrawTextStretchNormal); - uiBoxAppend(vbox, uiControl(textStretch), 0); + uiBoxAppend(hbox, uiControl(textStretch), 1); mkRGBA(vbox, NULL, NULL, &textR, &textG, &textB, &textA, "0.0"); mkRGBA(vbox, &textHasBackground, "Background", &textBR, &textBG, &textBB, &textBA, "1.0"); From 3b916fa74930e8f95e727b2ddbca9d2c9cf1507f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 27 Dec 2015 11:32:47 -0500 Subject: [PATCH 06/16] Stubbed out the text drawing functions on OS X. --- darwin/draw.m | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/darwin/draw.m b/darwin/draw.m index e14c5d2d..268108e5 100644 --- a/darwin/draw.m +++ b/darwin/draw.m @@ -488,3 +488,20 @@ void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff) CFRelease(ff->fonts); uiFree(ff); } + +double uiDrawTextSizeToPoints(double textSize) +{ + // TODO + return 0; +} + +double uiDrawPointsToTextSize(double points) +{ + // TODO + return 0; +} + +void uiDrawText(uiDrawContext *c, double x, double y, const char *text, uiDrawTextStyle *style) +{ + // TODO +} From c31d06c2543240f6e288cdb4b2dd573d51fe4e65 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 27 Dec 2015 15:19:14 -0500 Subject: [PATCH 07/16] Quick change for now: added libgmalloc to the OS X build so I can debug potential memory allocation issues. I think something is wrong in the mouseExited logic... --- darwin/GNUfiles.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/darwin/GNUfiles.mk b/darwin/GNUfiles.mk index 02c533eb..4db7f861 100644 --- a/darwin/GNUfiles.mk +++ b/darwin/GNUfiles.mk @@ -64,3 +64,6 @@ LDFLAGS += \ # TODO -current_version, -compatibility_version LDFLAGS += \ -Wl,-install_name,@rpath/$(NAME).$(SOVERSION)$(SUFFIX) + +# TODO make this an option +LDFLAGS += -lgmalloc From 0ec70f911149613d6ca117c162abdb65aec034d4 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 27 Dec 2015 15:54:53 -0500 Subject: [PATCH 08/16] Removed libgmalloc. That was a mistake; it slows down callbacks tremendously on DEFAULT SETTINGS. --- darwin/GNUfiles.mk | 3 --- 1 file changed, 3 deletions(-) diff --git a/darwin/GNUfiles.mk b/darwin/GNUfiles.mk index 4db7f861..02c533eb 100644 --- a/darwin/GNUfiles.mk +++ b/darwin/GNUfiles.mk @@ -64,6 +64,3 @@ LDFLAGS += \ # TODO -current_version, -compatibility_version LDFLAGS += \ -Wl,-install_name,@rpath/$(NAME).$(SOVERSION)$(SUFFIX) - -# TODO make this an option -LDFLAGS += -lgmalloc From 93a9847b5929d0b48f98e8f05cfb36c86b1c3dc7 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 27 Dec 2015 16:15:18 -0500 Subject: [PATCH 09/16] Added debugging code for mouseExited:. In El Capitan it's not working in scrolled views... --- darwin/area.m | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/darwin/area.m b/darwin/area.m index d7f34433..34e981ad 100644 --- a/darwin/area.m +++ b/darwin/area.m @@ -223,6 +223,10 @@ mouseEvent(otherMouseUp) { uiArea *a = self->libui_a; +NSLog(@"entered"); +NSLog(@"a %p", a); +NSLog(@"ah %p", a->ah); +NSLog(@"crossed %p", a->ah->MouseCrossed); (*(a->ah->MouseCrossed))(a->ah, a, 0); } @@ -230,6 +234,10 @@ mouseEvent(otherMouseUp) { uiArea *a = self->libui_a; +NSLog(@"exited"); +NSLog(@"a %p", a); +NSLog(@"ah %p", a->ah); +NSLog(@"crossed %p", a->ah->MouseCrossed); (*(a->ah->MouseCrossed))(a->ah, a, 1); } From 66ad8066ea4a23c0f0f6406c64c1ecffc17283c5 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 27 Dec 2015 17:13:57 -0500 Subject: [PATCH 10/16] Improved the exited debugging. --- darwin/area.m | 6 ++++-- test/page7b.c | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/darwin/area.m b/darwin/area.m index 34e981ad..736db34f 100644 --- a/darwin/area.m +++ b/darwin/area.m @@ -223,22 +223,24 @@ mouseEvent(otherMouseUp) { uiArea *a = self->libui_a; -NSLog(@"entered"); +NSLog(@"entered %p", self); NSLog(@"a %p", a); NSLog(@"ah %p", a->ah); NSLog(@"crossed %p", a->ah->MouseCrossed); (*(a->ah->MouseCrossed))(a->ah, a, 0); +NSLog(@"after entered call"); } - (void)mouseExited:(NSEvent *)e { uiArea *a = self->libui_a; -NSLog(@"exited"); +NSLog(@"exited %p", self); NSLog(@"a %p", a); NSLog(@"ah %p", a->ah); NSLog(@"crossed %p", a->ah->MouseCrossed); (*(a->ah->MouseCrossed))(a->ah, a, 1); +NSLog(@"after exited call"); } // note: there is no equivalent to WM_CAPTURECHANGED on Mac OS X; there literally is no way to break a grab like that diff --git a/test/page7b.c b/test/page7b.c index 420155c8..d1f98a74 100644 --- a/test/page7b.c +++ b/test/page7b.c @@ -27,6 +27,7 @@ static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent * static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left) { +printf("%d %d\n", left, !left); uiCheckboxSetChecked(label, !left); } From a1beccd63da1a96fcb567d5ff2cc7e0d640c1a8a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 27 Dec 2015 22:19:59 -0500 Subject: [PATCH 11/16] Pinpointed the issues with mouseExited:. A TODO for now; this is gonna be murder to figure out :) --- darwin/area.m | 10 ---------- darwin/checkbox.m | 2 ++ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/darwin/area.m b/darwin/area.m index 736db34f..d7f34433 100644 --- a/darwin/area.m +++ b/darwin/area.m @@ -223,24 +223,14 @@ mouseEvent(otherMouseUp) { uiArea *a = self->libui_a; -NSLog(@"entered %p", self); -NSLog(@"a %p", a); -NSLog(@"ah %p", a->ah); -NSLog(@"crossed %p", a->ah->MouseCrossed); (*(a->ah->MouseCrossed))(a->ah, a, 0); -NSLog(@"after entered call"); } - (void)mouseExited:(NSEvent *)e { uiArea *a = self->libui_a; -NSLog(@"exited %p", self); -NSLog(@"a %p", a); -NSLog(@"ah %p", a->ah); -NSLog(@"crossed %p", a->ah->MouseCrossed); (*(a->ah->MouseCrossed))(a->ah, a, 1); -NSLog(@"after exited call"); } // note: there is no equivalent to WM_CAPTURECHANGED on Mac OS X; there literally is no way to break a grab like that diff --git a/darwin/checkbox.m b/darwin/checkbox.m index 28f789d8..09af33a7 100644 --- a/darwin/checkbox.m +++ b/darwin/checkbox.m @@ -75,6 +75,8 @@ void uiCheckboxSetText(uiCheckbox *c, const char *text) { [c->button setTitle:toNSString(text)]; // this may result in the size of the checkbox changing + // TODO something somewhere is causing this to corrupt some memory so that, for instance, page7b's mouseExited: never triggers on 10.11; figure out what + // TODO is this related to map-related crashes? uiDarwinControlTriggerRelayout(uiDarwinControl(c)); } From 1b3d303cbe4c86cfdea2ab6d7410d46f0f20729b Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 27 Dec 2015 22:55:41 -0500 Subject: [PATCH 12/16] More TODOs. --- darwin/tab.m | 1 + 1 file changed, 1 insertion(+) diff --git a/darwin/tab.m b/darwin/tab.m index 14cf44c0..b711168a 100644 --- a/darwin/tab.m +++ b/darwin/tab.m @@ -86,6 +86,7 @@ void uiTabInsertAt(uiTab *t, const char *name, uintmax_t n, uiControl *child) childView = (NSView *) uiControlHandle(child); view = [[NSView alloc] initWithFrame:NSZeroRect]; + // TODO if we turn off the autoresizing mask, nothing shows up; didn't this get documented somewhere? [view addSubview:childView]; [t->pages insertObject:[NSValue valueWithPointer:child] atIndex:n]; From c5d4813dec0220458ed9ee7e01e2504722464173 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 31 Dec 2015 12:30:53 -0500 Subject: [PATCH 13/16] Stubbed out the text drawing functions on Windows too. --- windows/drawtext.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/windows/drawtext.cpp b/windows/drawtext.cpp index a644ca38..a3b01edd 100644 --- a/windows/drawtext.cpp +++ b/windows/drawtext.cpp @@ -107,3 +107,20 @@ void uiDrawFreeFontFamilies(uiDrawFontFamilies *ff) ff->fonts->Release(); uiFree(ff); } + +double uiDrawTextSizeToPoints(double textSize) +{ + // TODO + return 0; +} + +double uiDrawPointsToTextSize(double points) +{ + // TODO + return 0; +} + +void uiDrawText(uiDrawContext *c, double x, double y, const char *text, uiDrawTextStyle *style) +{ + // TODO +} From 5d40eff32a9d7eaee31ef32b269330aab0f30e01 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 31 Dec 2015 19:58:03 -0500 Subject: [PATCH 14/16] Added Windows 7 compatibility to the manifest. --- windows/libui.manifest | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/windows/libui.manifest b/windows/libui.manifest index 903c5359..8beb6cfc 100644 --- a/windows/libui.manifest +++ b/windows/libui.manifest @@ -19,5 +19,13 @@ /> + + + + + + + + From 46aadf62c1ead5659c717c2f7d8ea567e3646297 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 31 Dec 2015 20:09:20 -0500 Subject: [PATCH 15/16] Added a manifest to the test program. --- test/GNUfiles.mk | 5 +++++ test/resources.rc | 9 +++++++++ test/test.manifest | 20 ++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/resources.rc create mode 100644 test/test.manifest diff --git a/test/GNUfiles.mk b/test/GNUfiles.mk index e1bc8f9d..4de5e9b7 100644 --- a/test/GNUfiles.mk +++ b/test/GNUfiles.mk @@ -20,3 +20,8 @@ CFILES += \ HFILES += \ test/test.h + +ifeq ($(OS),windows) +RCFILES += \ + test/resources.rc +endif diff --git a/test/resources.rc b/test/resources.rc new file mode 100644 index 00000000..11c78a76 --- /dev/null +++ b/test/resources.rc @@ -0,0 +1,9 @@ +// 30 may 2015 + +// this is a UTF-8 file +#pragma code_page(65001) + +// this is the Common Controls 6 manifest +// TODO set up the string values here +// 1 is the value of CREATEPROCESS_MANIFEST_RESOURCE_ID and 24 is the value of RT_MANIFEST; we use it directly to avoid needing to share winapi.h with the tests and examples +1 24 "test.manifest" diff --git a/test/test.manifest b/test/test.manifest new file mode 100644 index 00000000..41e7c9c5 --- /dev/null +++ b/test/test.manifest @@ -0,0 +1,20 @@ + + + +Your application description here. + + + + + + + + + + + From 05ab8d07db2b64279251e6a502cc54454fc6bb9f Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 31 Dec 2015 20:12:14 -0500 Subject: [PATCH 16/16] And added compatibility manifests to the examples too. --- build/GNUmakefile.example | 5 +++++ examples/example.manifest | 20 ++++++++++++++++++++ examples/resources.rc | 9 +++++++++ 3 files changed, 34 insertions(+) create mode 100644 examples/example.manifest create mode 100644 examples/resources.rc diff --git a/build/GNUmakefile.example b/build/GNUmakefile.example index 34268a97..fab16e2b 100644 --- a/build/GNUmakefile.example +++ b/build/GNUmakefile.example @@ -15,6 +15,11 @@ CFILES += \ HFILES += \ ui.h +ifeq ($(OS),windows) +RCFILES += \ + examples/resources.rc +endif + NAME = $(EXAMPLE) SUFFIX = $(EXESUFFIX) diff --git a/examples/example.manifest b/examples/example.manifest new file mode 100644 index 00000000..41e7c9c5 --- /dev/null +++ b/examples/example.manifest @@ -0,0 +1,20 @@ + + + +Your application description here. + + + + + + + + + + + diff --git a/examples/resources.rc b/examples/resources.rc new file mode 100644 index 00000000..b55e24ec --- /dev/null +++ b/examples/resources.rc @@ -0,0 +1,9 @@ +// 30 may 2015 + +// this is a UTF-8 file +#pragma code_page(65001) + +// this is the Common Controls 6 manifest +// TODO set up the string values here +// 1 is the value of CREATEPROCESS_MANIFEST_RESOURCE_ID and 24 is the value of RT_MANIFEST; we use it directly to avoid needing to share winapi.h with the tests and examples +1 24 "example.manifest"