diff --git a/test/GNUmakeinc.mk b/test/GNUmakeinc.mk index a037c435..e2b5ead8 100644 --- a/test/GNUmakeinc.mk +++ b/test/GNUmakeinc.mk @@ -10,6 +10,7 @@ testCFILES = \ test/page4.c \ test/page5.c \ test/page6.c \ + test/page7.c \ test/spaced.c testHFILES = \ diff --git a/test/drawtests.c b/test/drawtests.c index b4cca1ac..990b5de3 100644 --- a/test/drawtests.c +++ b/test/drawtests.c @@ -137,8 +137,6 @@ static void drawOriginal(uiAreaDrawParams *p) uiDrawFreePath(path); } -// TODO test quadrants 2 and 4 and the other axes -// TODO test negative start angles too static void drawArcs(uiAreaDrawParams *p) { uiDrawPath *path; @@ -1187,7 +1185,6 @@ static void drawCSArc(uiAreaDrawParams *p) double xc = 128.0; double yc = 128.0; double radius = 100.0; - // these are clockwise, not counterclockwise double angle1 = 45.0 * (M_PI / 180.0); double angle2 = 180.0 * (M_PI / 180.0); uiDrawBrush source; @@ -1248,7 +1245,6 @@ static void drawCSArcNegative(uiAreaDrawParams *p) double xc = 128.0; double yc = 128.0; double radius = 100.0; - // these are clockwise, not counterclockwise double angle1 = 45.0 * (M_PI / 180.0); double angle2 = 180.0 * (M_PI / 180.0); uiDrawBrush source; diff --git a/test/main.c b/test/main.c index e6f0c77b..4cee07a9 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; + uiBox *page2, *page3, *page4, *page5, *page6, *page7; int nomenus = 0; int startspaced = 0; @@ -110,6 +110,9 @@ int main(int argc, char *argv[]) page6 = makePage6(); uiTabAppend(mainTab, "Page 6", uiControl(page6)); + page7 = makePage7(); + uiTabAppend(mainTab, "Page 7", uiControl(page7)); + if (startspaced) setSpaced(1); diff --git a/test/page7.c b/test/page7.c new file mode 100644 index 00000000..ac15bef0 --- /dev/null +++ b/test/page7.c @@ -0,0 +1,152 @@ +// 13 october 2015 +#include "test.h" + +static uiArea *area; +static uiEntry *startAngle; +static uiEntry *sweep; +static uiCheckbox *negative; +static uiCheckbox *radians; + +struct handler { + uiAreaHandler ah; +}; + +static struct handler handler; + +// based on the cairo arc sample +static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p) +{ + double xc = 128.0; + double yc = 128.0; + double radius = 100.0; + uiDrawBrush source; + uiDrawStrokeParams sp; + uiDrawPath *path; + char *startText; + char *sweepText; + double factor; + + source.Type = uiDrawBrushTypeSolid; + source.R = 0; + source.G = 0; + source.B = 0; + source.A = 1; + sp.Cap = uiDrawLineCapFlat; + sp.Join = uiDrawLineJoinMiter; + sp.MiterLimit = uiDrawDefaultMiterLimit; + + startText = uiEntryText(startAngle); + sweepText = uiEntryText(sweep); + + factor = M_PI / 180; + if (uiCheckboxChecked(radians)) + factor = 1; + + sp.Thickness = 10.0; + path = uiDrawNewPath(uiDrawFillModeWinding); + uiDrawPathNewFigure(path, xc, yc); + uiDrawPathArcTo(path, + xc, yc, + radius, + atof(startText) * factor, + atof(sweepText) * factor, + uiCheckboxChecked(negative)); + uiDrawPathEnd(path); + uiDrawStroke(p->Context, path, &source, &sp); + uiDrawFreePath(path); + + uiFreeText(startText); + uiFreeText(sweepText); +} + +static uintmax_t handlerHScrollMax(uiAreaHandler *a, uiArea *area) +{ + return 0; +} + +static uintmax_t handlerVScrollMax(uiAreaHandler *a, uiArea *area) +{ + return 0; +} + +static int handlerRedrawOnResize(uiAreaHandler *a, uiArea *area) +{ + return 1; +} + +static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e) +{ + // do nothing +} + +static void handlerDragBroken(uiAreaHandler *ah, uiArea *a) +{ + // do nothing +} + +static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e) +{ + return 0; +} + +static void entryChanged(uiEntry *e, void *data) +{ + uiAreaQueueRedrawAll(area); +} + +static void checkboxToggled(uiCheckbox *c, void *data) +{ + uiAreaQueueRedrawAll(area); +} + +uiBox *makePage7(void) +{ + uiBox *page7; + uiGroup *group; + uiBox *box, *box2; + + handler.ah.Draw = handlerDraw; + handler.ah.HScrollMax = handlerHScrollMax; + handler.ah.VScrollMax = handlerVScrollMax; + handler.ah.RedrawOnResize = handlerRedrawOnResize; + handler.ah.MouseEvent = handlerMouseEvent; + handler.ah.DragBroken = handlerDragBroken; + handler.ah.KeyEvent = handlerKeyEvent; + + page7 = newHorizontalBox(); + + group = newGroup("Arc Test"); + uiBoxAppend(page7, uiControl(group), 1); + + box = newVerticalBox(); + uiGroupSetChild(group, uiControl(box)); + + area = uiNewArea((uiAreaHandler *) (&handler)); + uiBoxAppend(box, uiControl(area), 1); + + box2 = newHorizontalBox(); + uiBoxAppend(box, uiControl(box2), 0); + + uiBoxAppend(box2, uiControl(uiNewLabel("Start Angle")), 0); + startAngle = uiNewEntry(); + uiEntryOnChanged(startAngle, entryChanged, NULL); + uiBoxAppend(box2, uiControl(startAngle), 1); + + box2 = newHorizontalBox(); + uiBoxAppend(box, uiControl(box2), 0); + + uiBoxAppend(box2, uiControl(uiNewLabel("Sweep")), 0); + sweep = uiNewEntry(); + uiEntryOnChanged(sweep, entryChanged, NULL); + uiBoxAppend(box2, uiControl(sweep), 1); + + negative = uiNewCheckbox("Negative"); + uiCheckboxOnToggled(negative, checkboxToggled, NULL); + uiBoxAppend(box, uiControl(negative), 0); + + radians = uiNewCheckbox("Radians"); + uiCheckboxOnToggled(radians, checkboxToggled, NULL); + uiBoxAppend(box, uiControl(radians), 0); + + return page7; +} diff --git a/test/test.h b/test/test.h index 59436603..8a249b36 100644 --- a/test/test.h +++ b/test/test.h @@ -53,3 +53,6 @@ extern uiBox *makePage6(void); // drawtests.c extern void runDrawTest(intmax_t, uiAreaDrawParams *); extern void populateComboboxWithTests(uiCombobox *); + +// page7.c +extern uiBox *makePage7(void);