-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathstackpanel.cpp
257 lines (215 loc) · 7.67 KB
/
stackpanel.cpp
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// Note: No matter what other statements in this file may say,
// this file is released under the same license as the latest
// version of GLICT (currently, GNU Lesser General Public License v2)
// It is not (currently) distributed as part of GLICT because UI
// element it produces is YATC-specific.
#include "stackpanel.h"
#include "util.h"
#include "gm_gameworld.h"
#include <GLICT/globals.h>
#include <string.h>
#ifndef MIN
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)>(y)?(x):(y))
#endif
yatcStackPanel::yatcStackPanel()
{
strcpy(this->objtype, "yatcStackPanel");
#if (GLICT_APIREV>=95)
SetForcedHeight(0);
defocusabilize_element = false;
#else
#warning yatcStackPanel needs GLICT APIREV 95+ to function properly.
#endif
}
yatcStackPanel::~yatcStackPanel()
{
}
/**
* @brief Overrides the default implementation for a glictList allowing dragging
* of children along the Y axis.
*
* The children are expected to be special yatcStackPanelWindow objects.
*
* @param evt event being dispatched to the stack panel
* @param wparam mouse position
* @param lparam unused
* @param returnvalue unused for handled events; passed to glictList::CastEvent
* as-is
*
* @return whether the event was handled
*/
bool yatcStackPanel::CastEvent(glictEvents evt, void* wparam, long lparam, void* returnvalue)
{
#if (GLICT_APIREV>=95)
if (evt == GLICT_MOUSEMOVE) {
if (draggedchild) {
_updateDraggedChildPos((*(glictPos*)wparam));
return true;
}
} else
if (evt == GLICT_MOUSEUP) {
if (draggedchild) {
_updateDraggedChildPos((*(glictPos*)wparam));
StopDraggingChild(*(glictPos*)wparam);
return true;
}
}
#endif
return glictList::CastEvent(evt,wparam,lparam,returnvalue);
}
void yatcStackPanel::StartDraggingChild(glictContainer* draggedChild, const glictPos &relmousepos) {
#if (GLICT_APIREV>=95)
glictList::StartDraggingChild(draggedChild, relmousepos);
#endif
}
void yatcStackPanel::StopDraggingChild(const glictPos &eventmousepos) {
#if (GLICT_APIREV>=95)
glictList::StopDraggingChild(eventmousepos);
RebuildList();
#endif
}
void yatcStackPanel::ForceHeight(int height)
{
// TODO (nfries88): close windows if needed, resize bottom remaining window appropriately.
SetHeight(GetTotalHeight());
}
void yatcStackPanel::_updateDraggedChildPos(const glictPos &eventmousepos)
{
#if (GLICT_APIREV>=95)
int totaldcheight = draggedchild->GetHeight() +draggedchild->GetTopSize()+draggedchild->GetBottomSize();
//int oldy = draggedchild->GetY();
int newy = MIN(MAX(eventmousepos.y - draggedchild->_GetDragRelMouse().y, 0), totalheight-totaldcheight);
draggedchild->Focus(NULL);
int currentheight=0;
bool met = false;
for (std::list<glictContainer*>::iterator it = listlist.begin() ; it != listlist.end() ; it++) {
if (!(*it)->GetVisible()) continue;
if (*it == draggedchild) {
std::list<glictContainer*>::iterator oldit = it;
it++;
listlist.erase(oldit);
if (it == listlist.end()) break;
}
if (*it != draggedchild) {
int totalitheight = (*it)->GetHeight() +(*it)->GetTopSize()+(*it)->GetBottomSize();
if (currentheight + totalitheight /2 > newy && !met) {
currentheight += totaldcheight;
met = true;
listlist.insert(it, draggedchild);// inserts dragged child before "it"
}
(*it)->SetPos(0, currentheight);
if (forcedheight)
(*it)->SetHeight(forcedheight);
(*it)->SetWidth(width - GetCurrentVScrollbarWidth() - (*it)->GetLeftSize() - (*it)->GetRightSize());
currentheight += totalitheight;
}
}
if (!met)
listlist.push_back(draggedchild);
draggedchild->SetPos(
draggedchild->GetX(),
newy
);
#endif
}
void yatcStackPanel::Paint()
{
#if (GLICT_APIREV>=95)
glictGlobals.PaintRect(clipleft, clipright, cliptop, MIN(clipbottom, cliptop + totalheight), glictColor(0,0,0,1));
#endif
glictList::Paint();
}
yatcStackPanelWindow::yatcStackPanelWindow()
{
// wide enough to display 4 items per row, tall enough to display all rows or three rows, whichever is smalle
window.SetWidth(150 + 10); // 10 == for scrollbar
window.SetHeight(0);
// close button on titlebar
// support added to glict svn 76+
// this button needs to be relocated manually
#if (GLICT_APIREV >= 76)
window.AddTitlebarObject(&closebtn);
closebtn.SetSkin(&g_skin.graphicbtn[BUTTON_CLOSE_WINDOW]);
closebtn.SetHighlightSkin(&g_skin.graphicbth[BUTTON_CLOSE_WINDOW]);
closebtn.SetCaption("");
closebtn.SetWidth(12);
closebtn.SetHeight(12);
closebtn.SetPos(150 + 10 - 12, 2);
closebtn.SetCustomData(this);
closebtn.SetOnClick(OnClose);
window.AddTitlebarObject(&btnCollapse);
btnCollapse.SetSkin(&g_skin.graphicbtn[BUTTON_COLLAPSE_WINDOW]);
btnCollapse.SetHighlightSkin(&g_skin.graphicbth[BUTTON_COLLAPSE_WINDOW]);
btnCollapse.SetCaption("");
btnCollapse.SetWidth(12);
btnCollapse.SetHeight(12);
btnCollapse.SetPos(150 + 10 - 24, 2);
btnCollapse.SetCustomData(this);
btnCollapse.SetOnClick(OnCollapse);
#else
#warning For titlebar objects (such as close buttons) to work properly, you need GLICT APIREV 76+
#endif
}
void yatcStackPanelWindow::Collapse()
{
window.SetHeight(0);
btnCollapse.SetSkin(&g_skin.graphicbtn[BUTTON_EXPAND_WINDOW]);
btnCollapse.SetHighlightSkin(&g_skin.graphicbth[BUTTON_EXPAND_WINDOW]);
btnCollapse.SetOnClick(OnExpand);
glictList* parentlist = dynamic_cast<glictList*>(window.GetParent());
if (parentlist)
parentlist->RebuildList();
GM_Gameworld* gameclass = dynamic_cast<GM_Gameworld*>(g_game);
if(gameclass)
gameclass->updateRightSide();
}
void yatcStackPanelWindow::Expand()
{
window.SetHeight(GetDefaultHeight());
btnCollapse.SetSkin(&g_skin.graphicbtn[BUTTON_COLLAPSE_WINDOW]);
btnCollapse.SetHighlightSkin(&g_skin.graphicbth[BUTTON_COLLAPSE_WINDOW]);
btnCollapse.SetOnClick(OnCollapse);
glictList* parentlist = dynamic_cast<glictList*>(window.GetParent());
if (parentlist)
parentlist->RebuildList();
GM_Gameworld* gameclass = dynamic_cast<GM_Gameworld*>(g_game);
if(gameclass)
gameclass->updateRightSide();
}
void yatcStackPanelWindow::Close()
{
OnClose();
glictList* parentlist = dynamic_cast<glictList*>(window.GetParent());
if (parentlist)
parentlist->RebuildList();
GM_Gameworld* gameclass = dynamic_cast<GM_Gameworld*>(g_game);
if(gameclass)
gameclass->updateRightSide();
}
void yatcStackPanelWindow::OnClose(glictPos* pos, glictContainer *caller) {
yatcStackPanelWindow* window = (yatcStackPanelWindow*)caller->GetCustomData();
window->Close();
}
void yatcStackPanelWindow::OnCollapse(glictPos* pos, glictContainer *caller) {
yatcStackPanelWindow* window = (yatcStackPanelWindow*)caller->GetCustomData();
window->Collapse();
}
void yatcStackPanelWindow::OnExpand(glictPos* pos, glictContainer *caller) {
yatcStackPanelWindow* window = (yatcStackPanelWindow*)caller->GetCustomData();
window->Expand();
}
void yatcStackPanelWindow::OnResized(glictSize* size, glictContainer* caller)
{
yatcStackPanelWindow* window = (yatcStackPanelWindow*)caller->GetCustomData();
//NativeGUIError("Holy Crap", "This works");
// in case of horizontal resize
window->window.SetWidth(150+10);
window->OnResize(size->h);
glictList* parentlist = dynamic_cast<glictList*>(window->window.GetParent());
if (parentlist)
parentlist->RebuildList();
GM_Gameworld* gameclass = dynamic_cast<GM_Gameworld*>(g_game);
if(gameclass)
gameclass->updateRightSide();
}