2015-12-24 21:59:00 -06:00
|
|
|
// 22 december 2015
|
|
|
|
#include "test.h"
|
|
|
|
|
2016-01-12 23:56:03 -06:00
|
|
|
// TODO draw a rectangle pointing out where (10,10) is both to test initial colors and to figure out what the *real* ascent is
|
|
|
|
|
2015-12-24 21:59:00 -06:00
|
|
|
static uiEntry *textString;
|
|
|
|
static uiEntry *textFont;
|
|
|
|
static uiEntry *textSize;
|
|
|
|
static uiCombobox *textWeight;
|
|
|
|
static uiCombobox *textItalic;
|
|
|
|
static uiCheckbox *textSmallCaps;
|
|
|
|
static uiCombobox *textStretch;
|
2016-01-14 19:02:01 -06:00
|
|
|
static uiEntry *textWidth;
|
2015-12-24 21:59:00 -06:00
|
|
|
static uiButton *textApply;
|
2016-01-12 21:07:24 -06:00
|
|
|
static uiCheckbox *addLeading;
|
2015-12-24 21:59:00 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-01-13 18:35:31 -06:00
|
|
|
// TODO this should be altered not to restore all state on exit so default text attributes can be checked
|
2016-01-13 03:02:30 -06:00
|
|
|
static void drawGuides(uiDrawContext *c, uiDrawTextFontMetrics *m)
|
|
|
|
{
|
|
|
|
uiDrawPath *p;
|
|
|
|
uiDrawBrush b;
|
|
|
|
uiDrawStrokeParams sp;
|
|
|
|
|
|
|
|
memset(&b, 0, sizeof (uiDrawBrush));
|
|
|
|
b.Type = uiDrawBrushTypeSolid;
|
|
|
|
memset(&sp, 0, sizeof (uiDrawStrokeParams));
|
|
|
|
sp.Cap = uiDrawLineCapFlat;
|
|
|
|
sp.Join = uiDrawLineJoinMiter;
|
|
|
|
sp.MiterLimit = uiDrawDefaultMiterLimit;
|
|
|
|
sp.Thickness = 2;
|
|
|
|
|
|
|
|
uiDrawSave(c);
|
|
|
|
|
|
|
|
p = uiDrawNewPath(uiDrawFillModeWinding);
|
|
|
|
uiDrawPathNewFigure(p, 8, 10);
|
|
|
|
uiDrawPathLineTo(p, 8, 10 + m->Ascent);
|
|
|
|
uiDrawPathEnd(p);
|
|
|
|
b.R = 0.94;
|
|
|
|
b.G = 0.5;
|
|
|
|
b.B = 0.5;
|
|
|
|
b.A = 1.0;
|
|
|
|
uiDrawStroke(c, p, &b, &sp);
|
|
|
|
uiDrawFreePath(p);
|
|
|
|
|
|
|
|
p = uiDrawNewPath(uiDrawFillModeWinding);
|
|
|
|
uiDrawPathNewFigure(p, 8, 10 + m->Ascent);
|
|
|
|
uiDrawPathLineTo(p, 8, 10 + m->Ascent + m->Descent);
|
|
|
|
uiDrawPathEnd(p);
|
|
|
|
b.R = 0.12;
|
|
|
|
b.G = 0.56;
|
|
|
|
b.B = 1.0;
|
|
|
|
b.A = 1.0;
|
|
|
|
uiDrawStroke(c, p, &b, &sp);
|
|
|
|
uiDrawFreePath(p);
|
|
|
|
|
|
|
|
p = uiDrawNewPath(uiDrawFillModeWinding);
|
|
|
|
uiDrawPathAddRectangle(p, 0, 0, 10, 10);
|
|
|
|
uiDrawPathEnd(p);
|
|
|
|
uiDrawClip(c, p);
|
|
|
|
b.R = 0.85;
|
|
|
|
b.G = 0.65;
|
|
|
|
b.B = 0.13;
|
|
|
|
b.A = 1.0;
|
|
|
|
uiDrawStroke(c, p, &b, &sp);
|
|
|
|
uiDrawFreePath(p);
|
|
|
|
|
|
|
|
uiDrawRestore(c);
|
|
|
|
}
|
|
|
|
|
2015-12-24 21:59:00 -06:00
|
|
|
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
|
|
|
{
|
2016-01-12 00:58:45 -06:00
|
|
|
uiDrawTextFontDescriptor desc;
|
|
|
|
uiDrawTextFont *font;
|
2015-12-24 21:59:00 -06:00
|
|
|
char *s;
|
|
|
|
char *family; // make compiler happy
|
2016-01-07 17:37:43 -06:00
|
|
|
uiDrawTextLayout *layout;
|
2016-01-12 20:52:45 -06:00
|
|
|
uiDrawTextFontMetrics metrics;
|
2016-01-12 21:07:24 -06:00
|
|
|
double ypos;
|
2016-01-14 19:02:01 -06:00
|
|
|
double width;
|
|
|
|
double height;
|
2015-12-24 21:59:00 -06:00
|
|
|
|
2016-01-12 00:58:45 -06:00
|
|
|
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
|
2015-12-24 21:59:00 -06:00
|
|
|
family = uiEntryText(textFont);
|
2016-01-12 00:58:45 -06:00
|
|
|
desc.Family = family;
|
|
|
|
desc.Size = entryDouble(textSize);
|
|
|
|
desc.Weight = uiComboboxSelected(textWeight);
|
|
|
|
desc.Italic = uiComboboxSelected(textItalic);
|
|
|
|
desc.Stretch = uiComboboxSelected(textStretch);
|
|
|
|
font = uiDrawLoadClosestFont(&desc);
|
2016-01-12 20:52:45 -06:00
|
|
|
uiFreeText(family);
|
|
|
|
uiDrawTextFontGetMetrics(font, &metrics);
|
2016-01-12 00:58:45 -06:00
|
|
|
|
2016-01-14 19:02:01 -06:00
|
|
|
width = entryDouble(textWidth);
|
|
|
|
|
2016-01-13 03:02:30 -06:00
|
|
|
drawGuides(dp->Context, &metrics);
|
|
|
|
|
2015-12-24 21:59:00 -06:00
|
|
|
s = uiEntryText(textString);
|
2016-01-14 19:02:01 -06:00
|
|
|
layout = uiDrawNewTextLayout(s, font, width);
|
2016-01-12 20:52:45 -06:00
|
|
|
uiFreeText(s);
|
2016-04-15 13:09:14 -05:00
|
|
|
if (uiCheckboxChecked(textSmallCaps))
|
|
|
|
; // TODO
|
2016-01-12 21:07:24 -06:00
|
|
|
ypos = 10;
|
|
|
|
uiDrawText(dp->Context, 10, ypos, layout);
|
2016-01-14 19:02:01 -06:00
|
|
|
// TODO make these optional?
|
2016-01-15 19:18:53 -06:00
|
|
|
uiDrawTextLayoutExtents(layout, &width, &height);
|
2016-01-12 20:52:45 -06:00
|
|
|
uiDrawFreeTextLayout(layout);
|
2016-01-12 00:58:45 -06:00
|
|
|
|
2016-01-14 19:02:01 -06:00
|
|
|
layout = uiDrawNewTextLayout("This is a second line", font, -1);
|
2016-01-16 12:34:22 -06:00
|
|
|
if (/*TODO reuse width*/entryDouble(textWidth) < 0) {
|
2016-01-14 19:02:01 -06:00
|
|
|
double ad;
|
|
|
|
|
|
|
|
ad = metrics.Ascent + metrics.Descent;
|
2016-01-16 12:34:22 -06:00
|
|
|
printf("ad:%g extent:%g\n", ad, height);
|
2016-01-14 19:02:01 -06:00
|
|
|
}
|
|
|
|
ypos += height;
|
2016-01-12 21:07:24 -06:00
|
|
|
if (uiCheckboxChecked(addLeading))
|
|
|
|
ypos += metrics.Leading;
|
|
|
|
uiDrawText(dp->Context, 10, ypos, layout);
|
2016-01-07 17:37:43 -06:00
|
|
|
uiDrawFreeTextLayout(layout);
|
2016-01-12 20:52:45 -06:00
|
|
|
|
2016-01-12 00:58:45 -06:00
|
|
|
uiDrawFreeTextFont(font);
|
2015-12-24 21:59:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiBox *makePage9(void)
|
|
|
|
{
|
|
|
|
uiBox *page9;
|
|
|
|
uiBox *vbox;
|
2015-12-24 22:04:07 -06:00
|
|
|
uiBox *hbox;
|
2015-12-24 21:59:00 -06:00
|
|
|
|
|
|
|
page9 = newVerticalBox();
|
|
|
|
vbox = page9;
|
|
|
|
|
2015-12-24 22:04:07 -06:00
|
|
|
hbox = newHorizontalBox();
|
|
|
|
uiBoxAppend(vbox, uiControl(hbox), 0);
|
|
|
|
|
2015-12-24 21:59:00 -06:00
|
|
|
textString = uiNewEntry();
|
|
|
|
// TODO make it placeholder
|
|
|
|
uiEntrySetText(textString, "Enter text here");
|
2015-12-24 22:04:07 -06:00
|
|
|
uiBoxAppend(hbox, uiControl(textString), 1);
|
2015-12-24 21:59:00 -06:00
|
|
|
|
|
|
|
textFont = uiNewEntry();
|
|
|
|
uiEntrySetText(textFont, "Arial");
|
2015-12-24 22:04:07 -06:00
|
|
|
uiBoxAppend(hbox, uiControl(textFont), 1);
|
2015-12-24 21:59:00 -06:00
|
|
|
|
|
|
|
textSize = uiNewEntry();
|
|
|
|
uiEntrySetText(textSize, "10");
|
2015-12-24 22:04:07 -06:00
|
|
|
uiBoxAppend(hbox, uiControl(textSize), 1);
|
|
|
|
|
|
|
|
hbox = newHorizontalBox();
|
|
|
|
uiBoxAppend(vbox, uiControl(hbox), 0);
|
2015-12-24 21:59:00 -06:00
|
|
|
|
|
|
|
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);
|
2015-12-24 22:04:07 -06:00
|
|
|
uiBoxAppend(hbox, uiControl(textWeight), 1);
|
2015-12-24 21:59:00 -06:00
|
|
|
|
|
|
|
textItalic = uiNewCombobox();
|
|
|
|
uiComboboxAppend(textItalic, "Normal");
|
|
|
|
uiComboboxAppend(textItalic, "Oblique");
|
|
|
|
uiComboboxAppend(textItalic, "Italic");
|
|
|
|
uiComboboxSetSelected(textItalic, uiDrawTextItalicNormal);
|
2015-12-24 22:04:07 -06:00
|
|
|
uiBoxAppend(hbox, uiControl(textItalic), 1);
|
2015-12-24 21:59:00 -06:00
|
|
|
|
|
|
|
textSmallCaps = uiNewCheckbox("Small Caps");
|
2015-12-24 22:04:07 -06:00
|
|
|
uiBoxAppend(hbox, uiControl(textSmallCaps), 1);
|
|
|
|
|
|
|
|
hbox = newHorizontalBox();
|
|
|
|
uiBoxAppend(vbox, uiControl(hbox), 0);
|
2015-12-24 21:59:00 -06:00
|
|
|
|
|
|
|
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);
|
2015-12-24 22:04:07 -06:00
|
|
|
uiBoxAppend(hbox, uiControl(textStretch), 1);
|
2015-12-24 21:59:00 -06:00
|
|
|
|
2016-01-15 19:18:53 -06:00
|
|
|
textWidth = uiNewEntry();
|
|
|
|
uiEntrySetText(textWidth, "-1");
|
|
|
|
uiBoxAppend(hbox, uiControl(textWidth), 1);
|
|
|
|
|
2016-01-12 21:07:24 -06:00
|
|
|
hbox = newHorizontalBox();
|
|
|
|
uiBoxAppend(vbox, uiControl(hbox), 0);
|
|
|
|
|
2015-12-24 21:59:00 -06:00
|
|
|
textApply = uiNewButton("Apply");
|
|
|
|
uiButtonOnClicked(textApply, onTextApply, NULL);
|
2016-01-12 21:07:24 -06:00
|
|
|
uiBoxAppend(hbox, uiControl(textApply), 1);
|
|
|
|
|
|
|
|
addLeading = uiNewCheckbox("Add Leading");
|
|
|
|
uiCheckboxSetChecked(addLeading, 1);
|
|
|
|
uiBoxAppend(hbox, uiControl(addLeading), 0);
|
2015-12-24 21:59:00 -06:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|