aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/test/page7c.c
blob: ac6a316cb08fa680763ed5ed848cdb589f7d92ae (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// 13 october 2015
#include "test.h"

static uiArea *area;

struct handler {
	uiAreaHandler ah;
};

static struct handler handler;

#define areaSize 250
#define borderThickness 1
#define padding 30
#define circleRadius ((areaSize - padding) / 2)

static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *dp)
{
	uiDrawPath *path;
	uiDrawBrush brush;
	uiDrawStrokeParams sp;
	uiDrawBrushGradientStop stops[2];

	memset(&brush, 0, sizeof (uiDrawBrush));
	memset(&sp, 0, sizeof (uiDrawStrokeParams));

	// add some buffering to detect scrolls that aren't on the dot and draws that are outside the scroll area on Windows
	path = uiDrawNewPath(uiDrawFillModeWinding);
	uiDrawPathAddRectangle(path,
		-50, -50,
		areaSize + 100, areaSize + 100);
	uiDrawPathEnd(path);
	brush.Type = uiDrawBrushTypeSolid;
	brush.R = 0;
	brush.G = 1;
	brush.B = 0;
	brush.A = 1;
	uiDrawFill(dp->Context, path, &brush);
	uiDrawFreePath(path);

	path = uiDrawNewPath(uiDrawFillModeWinding);
	uiDrawPathAddRectangle(path,
		0, 0,
		areaSize, areaSize);
	uiDrawPathEnd(path);
	brush.Type = uiDrawBrushTypeSolid;
	brush.R = 1;
	brush.G = 1;
	brush.B = 1;
	brush.A = 1;
	uiDrawFill(dp->Context, path, &brush);
	brush.Type = uiDrawBrushTypeSolid;
	brush.R = 1;
	brush.G = 0;
	brush.B = 0;
	brush.A = 1;
	sp.Cap = uiDrawLineCapFlat;
	sp.Join = uiDrawLineJoinMiter;
	sp.Thickness = 1;
	sp.MiterLimit = uiDrawDefaultMiterLimit;
	uiDrawStroke(dp->Context, path, &brush, &sp);
	uiDrawFreePath(path);

	path = uiDrawNewPath(uiDrawFillModeWinding);
	uiDrawPathNewFigureWithArc(path,
		areaSize / 2, areaSize / 2,
		circleRadius,
		0, 2 * uiPi,
		0);
	uiDrawPathEnd(path);
	stops[0].Pos =0.0;
	stops[0].R = 0.0;
	stops[0].G = 1.0;
	stops[0].B = 1.0;
	stops[0].A = 1.0;
	stops[1].Pos = 1.0;
	stops[1].R = 0.0;
	stops[1].G = 0.0;
	stops[1].B = 1.0;
	stops[1].A = 1.0;
	brush.Type = uiDrawBrushTypeLinearGradient;
	brush.X0 = areaSize / 2;
	brush.Y0 = padding;
	brush.X1 = areaSize / 2;
	brush.Y1 = areaSize - padding;
	brush.Stops = stops;
	brush.NumStops = 2;
	uiDrawFill(dp->Context, path, &brush);
	uiDrawFreePath(path);
}

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)
{
	if (e->Key == 'h' && !e->Up) {
		// TODO hide the widget momentarily on the h key
		return 1;
	}
	return 0;
}

uiGroup *makePage7c(void)
{
	uiGroup *group;

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

	group = newGroup("Scrolling Drawing Test");

	area = uiNewScrollingArea((uiAreaHandler *) (&handler),
		areaSize, areaSize);
	uiGroupSetChild(group, uiControl(area));

	return group;
}