From 6fd945b6024610f4215217191f68bea6e6491341 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 24 Dec 2015 22:59:00 -0500 Subject: [PATCH] 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);