aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/test/page7b.c
blob: d1f98a744100d4946c23cc105264fd48367e0240 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 13 october 2015
#include "test.h"

static uiArea *area;
static uiCheckbox *label;

struct handler {
	uiAreaHandler ah;
};

static struct handler handler;

static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *p)
{
	// do nothing
}

static void handlerMouseEvent(uiAreaHandler *a, uiArea *area, uiAreaMouseEvent *e)
{
	char pos[128];

	// wonderful, vanilla snprintf() isn't in visual studio 2013 - http://blogs.msdn.com/b/vcblog/archive/2013/07/19/c99-library-support-in-visual-studio-2013.aspx
	// we can't use _snprintf() in the test suite because that's msvc-only, so oops. sprintf() it is.
	sprintf(pos, "X %g Y %g", e->X, e->Y);
	uiCheckboxSetText(label, pos);
}

static void handlerMouseCrossed(uiAreaHandler *ah, uiArea *a, int left)
{
printf("%d %d\n", left, !left);
	uiCheckboxSetChecked(label, !left);
}

static void handlerDragBroken(uiAreaHandler *ah, uiArea *a)
{
	// do nothing
}

static int handlerKeyEvent(uiAreaHandler *ah, uiArea *a, uiAreaKeyEvent *e)
{
	if (e->Key == 'h' && !e->Up) {
		// TODO hide the widget momentarily on the h key
		return 1;
	}
	return 0;
}

uiGroup *makePage7b(void)
{
	uiGroup *group;
	uiBox *box;

	handler.ah.Draw = handlerDraw;
	handler.ah.MouseEvent = handlerMouseEvent;
	handler.ah.MouseCrossed = handlerMouseCrossed;
	handler.ah.DragBroken = handlerDragBroken;
	handler.ah.KeyEvent = handlerKeyEvent;

	group = newGroup("Scrolling Mouse Test");

	box = newVerticalBox();
	uiGroupSetChild(group, uiControl(box));

	area = uiNewScrollingArea((uiAreaHandler *) (&handler), 5000, 5000);
	uiBoxAppend(box, uiControl(area), 1);

	label = uiNewCheckbox("");
	uiBoxAppend(box, uiControl(label), 0);

	return group;
}