Added the first text layout attribute: foreground color. Now to implement.
This commit is contained in:
parent
6fdbd8d68f
commit
7a568f6bf4
107
test/page10.c
107
test/page10.c
|
@ -22,112 +22,33 @@ static double entryDouble(uiEntry *e)
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO this should be altered not to restore all state on exit so default text attributes can be checked
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
uiDrawTextFontDescriptor desc;
|
uiDrawTextFontDescriptor desc;
|
||||||
uiDrawTextFont *font;
|
uiDrawTextFont *font;
|
||||||
char *s;
|
|
||||||
char *family; // make compiler happy
|
|
||||||
uiDrawTextLayout *layout;
|
uiDrawTextLayout *layout;
|
||||||
uiDrawTextFontMetrics metrics;
|
|
||||||
double ypos;
|
|
||||||
double width;
|
|
||||||
double height;
|
|
||||||
|
|
||||||
|
// TODO
|
||||||
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
|
memset(&desc, 0, sizeof (uiDrawTextFontDescriptor));
|
||||||
family = uiEntryText(textFont);
|
family = uiEntryText(textFont);
|
||||||
desc.Family = family;
|
desc.Family = "Arial";
|
||||||
desc.Size = entryDouble(textSize);
|
desc.Size = 36;
|
||||||
desc.Weight = uiComboboxSelected(textWeight);
|
desc.Weight = uiDrawTextWeightNormal;
|
||||||
desc.Italic = uiComboboxSelected(textItalic);
|
desc.Italic = uiDrawTextItalicNormal;
|
||||||
desc.SmallCaps = uiCheckboxChecked(textSmallCaps);
|
desc.Stretch = uiDrawTextStretchNormal;
|
||||||
desc.Stretch = uiComboboxSelected(textStretch);
|
|
||||||
font = uiDrawLoadClosestFont(&desc);
|
font = uiDrawLoadClosestFont(&desc);
|
||||||
uiFreeText(family);
|
|
||||||
uiDrawTextFontGetMetrics(font, &metrics);
|
|
||||||
|
|
||||||
width = entryDouble(textWidth);
|
layout = uiDrawNewTextLayout(s, "One two three four", -1);
|
||||||
|
uiDrawTextLayoutSetForegroundColor(layout,
|
||||||
drawGuides(dp->Context, &metrics);
|
4, 7,
|
||||||
|
1, 0, 0, 1);
|
||||||
s = uiEntryText(textString);
|
uiDrawTextLayoutSetForegroundColor(layout,
|
||||||
layout = uiDrawNewTextLayout(s, font, width);
|
8, 14,
|
||||||
uiFreeText(s);
|
1, 0, 0.5, 0.5);
|
||||||
ypos = 10;
|
uiDrawText(dp->Context, 10, 10, layout);
|
||||||
uiDrawText(dp->Context, 10, ypos, layout);
|
|
||||||
// TODO make these optional?
|
|
||||||
uiDrawTextLayoutExtents(layout, &width, &height);
|
|
||||||
uiDrawFreeTextLayout(layout);
|
|
||||||
|
|
||||||
layout = uiDrawNewTextLayout("This is a second line", font, -1);
|
|
||||||
if (/*TODO reuse width*/entryDouble(textWidth) < 0) {
|
|
||||||
double ad;
|
|
||||||
|
|
||||||
ad = metrics.Ascent + metrics.Descent;
|
|
||||||
printf("ad:%g extent:%g\n", ad, height);
|
|
||||||
}
|
|
||||||
ypos += height;
|
|
||||||
if (uiCheckboxChecked(addLeading))
|
|
||||||
ypos += metrics.Leading;
|
|
||||||
uiDrawText(dp->Context, 10, ypos, layout);
|
|
||||||
uiDrawFreeTextLayout(layout);
|
uiDrawFreeTextLayout(layout);
|
||||||
|
|
||||||
uiDrawFreeTextFont(font);
|
uiDrawFreeTextFont(font);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e)
|
static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e)
|
||||||
|
|
3
ui.h
3
ui.h
|
@ -522,6 +522,9 @@ _UI_EXTERN void uiDrawFreeTextLayout(uiDrawTextLayout *layout);
|
||||||
_UI_EXTERN void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width);
|
_UI_EXTERN void uiDrawTextLayoutSetWidth(uiDrawTextLayout *layout, double width);
|
||||||
_UI_EXTERN void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height);
|
_UI_EXTERN void uiDrawTextLayoutExtents(uiDrawTextLayout *layout, double *width, double *height);
|
||||||
|
|
||||||
|
// and the attributes that you can set on a text layout
|
||||||
|
_UI_EXTERN void uiDrawTextLayoutSetColor(uiDrawTextLayout *layout, intmax_t startChar, intmax_t endChar, double r, double g, double b, double a);
|
||||||
|
|
||||||
_UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout);
|
_UI_EXTERN void uiDrawText(uiDrawContext *c, double x, double y, uiDrawTextLayout *layout);
|
||||||
|
|
||||||
typedef enum uiModifiers {
|
typedef enum uiModifiers {
|
||||||
|
|
Loading…
Reference in New Issue