-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo.cxx
146 lines (112 loc) · 4.51 KB
/
demo.cxx
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
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* Copyright(c) 2018, Markus Schmidt <[email protected]>
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 3.0 of the
* License, or (at your option) any later version.
*
* CTK is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with CTK; if not, see <http://www.gnu.org/licenses/>.
*/
#include "demo.hxx"
#include <algorithm>
int clicktest (CTK::Widget *widget, const void *event, void *data) {
CTK::EventButton *ev = (CTK::EventButton*)event;
printf("clicked id:%d x:%d y:%d button:%d\n", widget->id, (int)ev->x, (int)ev->y, (int)ev->button);
return 0;
};
int presstest (CTK::Widget *widget, const void *event, void *data) {
CTK::EventButton *ev = (CTK::EventButton*)event;
printf("pressed id:%d x:%d y:%d button:%d\n", widget->id, (int)ev->x, (int)ev->y, (int)ev->button);
return 0;
};
int releasetest (CTK::Widget *widget, const void *event, void *data) {
CTK::EventButton *ev = (CTK::EventButton*)event;
printf("released id:%d x:%d y:%d button:%d\n", widget->id, (int)ev->x, (int)ev->y, (int)ev->button);
return 0;
};
int dragstarttest (CTK::Widget *widget, const void *event, void *data) {
CTK::EventMotion *ev = (CTK::EventMotion*)event;
printf("dragstart id:%d x:%d y:%d\n", widget->id, (int)ev->x, (int)ev->y);
return 0;
};
int dragtest (CTK::Widget *widget, const void *event, void *data) {
CTK::EventMotion *ev = (CTK::EventMotion*)event;
printf("dragging id:%d x:%d y:%d\n", widget->id, (int)ev->x, (int)ev->y);
return 0;
};
int scrolltest (CTK::Widget *widget, const void *event, void *data) {
CTK::EventScroll *ev = (CTK::EventScroll*)event;
printf("scrolling id:%d x:%d y:%d dx:%d dy:%d\n", widget->id, (int)ev->x, (int)ev->y, (int)ev->dx, (int)ev->dy);
return 0;
};
int dragendtest (CTK::Widget *widget, const void *event, void *data) {
CTK::EventButton *ev = (CTK::EventButton*)event;
printf("dragend id:%d x:%d y:%d\n", widget->id, (int)ev->x, (int)ev->y);
return 0;
};
int hovertest (CTK::Widget *widget, const void *hover, void *data) {
bool *h = (bool*)hover;
printf("hover id:%d state:%d\n", widget->id, (int)*h);
return 0;
};
int toggletest (CTK::Widget *widget, void *data) {
printf("toggled id:%d\n", widget->id);
return 0;
};
DemoUI::DemoUI (PuglNativeWindow parent, const char* _title) : CTK::UI (parent, title)
{
title = _title;
/* test stacking and nesting */
// id 1
CTK::Widget* box3 = new CTK::Widget(this);
box3->resize(50, 10);
this->add(box3, 10, 40, 2);
// id 2
CTK::Container* con1 = new CTK::Container(this);
this->add(con1, 30, 30, 1);
// id 3
CTK::Widget* box1 = new CTK::Widget(this);
box1->resize(30, 40);
con1->add(box1, 30, 40, 1);
// id 4
CTK::Widget* box2 = new CTK::Widget(this);
box2->resize(40, 80);
con1->add(box2, 10, 20, 0);
/* test repositioning */
box3->repos(20,20);
/* test rescale */
rescale(2.5);
/* test generic events */
box2->addEvent(CTK::EVENT_BUTTON_PRESS, &presstest);
box2->addEvent(CTK::EVENT_BUTTON_RELEASE, &releasetest);
box2->addEvent(CTK::EVENT_SCROLL, &scrolltest);
/* test abstract events */
box2->addEvent(CTK::EVENT_CLICK, &clicktest);
box3->addEvent(CTK::EVENT_HOVER, &hovertest);
box2->addEvent(CTK::EVENT_DRAG_START, &dragstarttest);
box2->addEvent(CTK::EVENT_DRAG, &dragtest);
box2->addEvent(CTK::EVENT_DRAG_END, &dragendtest);
/* test events order of being fired */
box3->addEvent(CTK::EVENT_CLICK, &clicktest);
box1->addEvent(CTK::EVENT_CLICK, &clicktest);
/* test custom events */
box2->addEvent(CTK::EVENT_TOGGLED, &toggletest);
box2->fireEvent(CTK::EVENT_TOGGLED);
box2->removeEvent(CTK::EVENT_TOGGLED, &toggletest);
box2->fireEvent(CTK::EVENT_TOGGLED);
/* style */
//ui->loadStyle("../styles/default.style");
//CTK::UI *popup = new CTK::UI();
//popup->run();
//CTK::Widget* entry = new CTK::Widget(popup);
//entry->resize(50, 10);
//popup->add(entry, 10, 40, 2);
}