2017-01-17 12:30:00 -06:00
|
|
|
// 17 january 2017
|
2017-01-20 12:25:21 -06:00
|
|
|
#include "drawtext.h"
|
|
|
|
|
|
|
|
static uiWindow *mainwin;
|
|
|
|
static uiBox *box;
|
|
|
|
static uiCombobox *exampleList;
|
|
|
|
static uiArea *area;
|
|
|
|
static uiAreaHandler handler;
|
|
|
|
|
|
|
|
#define nExamples 20
|
|
|
|
static struct example *examples[nExamples];
|
|
|
|
static int curExample = 0;
|
|
|
|
|
|
|
|
static void onExampleChanged(uiCombobox *c, void *data)
|
|
|
|
{
|
|
|
|
uiControlHide(examples[curExample]->panel);
|
|
|
|
curExample = uiComboboxSelected(exampleList);
|
|
|
|
uiControlShow(examples[curExample]->panel);
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void redraw(void)
|
|
|
|
{
|
|
|
|
uiAreaQueueRedrawAll(area);
|
|
|
|
}
|
2017-01-17 12:30:00 -06:00
|
|
|
|
|
|
|
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
|
|
|
|
{
|
2017-01-20 12:25:21 -06:00
|
|
|
examples[curExample]->draw(p);
|
2017-01-17 12:30:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e)
|
|
|
|
{
|
2017-02-05 23:26:22 -06:00
|
|
|
if (examples[curExample]->mouse != NULL)
|
|
|
|
examples[curExample]->mouse(e);
|
2017-01-17 12:30:00 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2017-02-10 18:22:25 -06:00
|
|
|
if (examples[curExample]->key != NULL)
|
|
|
|
return examples[curExample]->key(e);
|
2017-01-17 12:30:00 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int onClosing(uiWindow *w, void *data)
|
|
|
|
{
|
|
|
|
uiControlDestroy(uiControl(mainwin));
|
|
|
|
uiQuit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int shouldQuit(void *data)
|
|
|
|
{
|
|
|
|
uiControlDestroy(uiControl(mainwin));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
uiInitOptions o;
|
|
|
|
const char *err;
|
2017-01-20 12:25:21 -06:00
|
|
|
int n;
|
2017-01-17 12:30:00 -06:00
|
|
|
|
|
|
|
handler.Draw = handlerDraw;
|
|
|
|
handler.MouseEvent = handlerMouseEvent;
|
|
|
|
handler.MouseCrossed = handlerMouseCrossed;
|
|
|
|
handler.DragBroken = handlerDragBroken;
|
|
|
|
handler.KeyEvent = handlerKeyEvent;
|
|
|
|
|
|
|
|
memset(&o, 0, sizeof (uiInitOptions));
|
|
|
|
err = uiInit(&o);
|
|
|
|
if (err != NULL) {
|
|
|
|
fprintf(stderr, "error initializing ui: %s\n", err);
|
|
|
|
uiFreeInitError(err);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uiOnShouldQuit(shouldQuit, NULL);
|
|
|
|
|
2017-01-17 12:54:23 -06:00
|
|
|
mainwin = uiNewWindow("libui Text-Drawing Example", 640, 480, 1);
|
2017-01-17 12:30:00 -06:00
|
|
|
uiWindowOnClosing(mainwin, onClosing, NULL);
|
|
|
|
|
2017-01-20 12:25:21 -06:00
|
|
|
box = uiNewVerticalBox();
|
|
|
|
uiWindowSetChild(mainwin, uiControl(box));
|
|
|
|
|
|
|
|
exampleList = uiNewCombobox();
|
|
|
|
uiBoxAppend(box, uiControl(exampleList), 0);
|
|
|
|
|
2017-01-17 12:30:00 -06:00
|
|
|
area = uiNewArea(&handler);
|
2017-01-20 12:25:21 -06:00
|
|
|
uiBoxAppend(box, uiControl(area), 1);
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
examples[n] = mkBasicExample();
|
|
|
|
uiComboboxAppend(exampleList, examples[n]->name);
|
2017-01-20 19:38:18 -06:00
|
|
|
uiControlHide(examples[n]->panel);
|
|
|
|
uiBoxAppend(box, examples[n]->panel, 0);
|
|
|
|
n++;
|
|
|
|
examples[n] = mkHitTestExample();
|
|
|
|
uiComboboxAppend(exampleList, examples[n]->name);
|
|
|
|
uiControlHide(examples[n]->panel);
|
2017-01-20 12:25:21 -06:00
|
|
|
uiBoxAppend(box, examples[n]->panel, 0);
|
|
|
|
n++;
|
2017-02-11 22:19:30 -06:00
|
|
|
examples[n] = mkAttributesExample();
|
|
|
|
uiComboboxAppend(exampleList, examples[n]->name);
|
|
|
|
uiControlHide(examples[n]->panel);
|
|
|
|
uiBoxAppend(box, examples[n]->panel, 0);
|
|
|
|
n++;
|
2017-02-24 17:54:35 -06:00
|
|
|
examples[n] = mkEmptyStringExample();
|
|
|
|
uiComboboxAppend(exampleList, examples[n]->name);
|
|
|
|
uiControlHide(examples[n]->panel);
|
|
|
|
uiBoxAppend(box, examples[n]->panel, 0);
|
|
|
|
n++;
|
2017-01-20 12:25:21 -06:00
|
|
|
// and set things up for the initial state
|
|
|
|
uiComboboxSetSelected(exampleList, 0);
|
|
|
|
uiComboboxOnSelected(exampleList, onExampleChanged, NULL);
|
|
|
|
// and set up the first one
|
|
|
|
onExampleChanged(NULL, NULL);
|
2017-01-17 12:30:00 -06:00
|
|
|
|
|
|
|
uiControlShow(uiControl(mainwin));
|
|
|
|
uiMain();
|
2017-01-20 12:25:21 -06:00
|
|
|
|
|
|
|
// TODO free examples
|
|
|
|
|
2017-01-17 12:30:00 -06:00
|
|
|
uiUninit();
|
|
|
|
return 0;
|
|
|
|
}
|