-
Notifications
You must be signed in to change notification settings - Fork 1
/
GCP_Form.cpp
612 lines (512 loc) · 20.2 KB
/
GCP_Form.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
#include "GCP_ContextMenu.h"
#include "GCP_Edit.h"
#include "GCP_Label.h"
#include "GCP_CheckBox.h"
#include "GCP_Form.h"
#include "GCP_MessageBox.h"
using namespace gcp;
GCP_Form::GCP_Form(int _width, int _height)
{
_componentThatWasLeftClicked = 0; //êîä óêàçàòåëÿ íà êîìïîíåíò ïî êîòîðîìó ìû êëèêíóëè
_isLocked = false; //çàáëîêèðîâàíà ôîðìà?
_isDragStarted = false; //íà÷àëè ïåðåòàñêèâàòü êîìïîíåíò?
isLocalEventsLocked = false; //çàáëîêèðîâàòü îáðàáîòêó ëîêàëüíûõ ñîáûòèé íà ôîðìå?
isDraggingSomeComponent = false; //ïåðåòàñêèâàåòñÿ ëè êîìïîíåíò â äàííûé ìîìåíò?
isTransparent = false; //Ðèñîâàòü ôîðìó ïðîçðà÷íî ïîâåðõ äðóãèõ?
_isDragable = true; //Ìîæíî ëè òàñêàòü ôîðìó ïî áóôåðó èëè äðóãîé ôîðìå?
iPosition = 0;
isParentLocking = false; //Áëîêèðîâàòü ðîäèòåëüñêóþ ôîðìó åñëè ðàáîòàåò ýòà ôîðìà
_isVisible = true; //Ìîæíî âîîáùå ôîðìó íå ðèñîâàòü
isShowTopRightButtons = true; //Ïîêàçûâàòü êðåñòèêè íîëèêè â ïðàâîì âåðõíåì óãëó
setPosition(0, 0, _width, _height);
_swidth = _width; //Øèðèíà áóôåðà íà êîòîðîì ðèñóåì
_sheight = _height; //Âûñîòà áóôåðà íà êîòîðîì ðèñóåì
//_sdlPixelFormat = screen->format;
_isContextMenuOpened = false; //Îòêðûòî ëè êîíòåêñòíîå ìåíþ íà ôîðìå?
isLocked = false; //Ìîæíî çàáëîêèðîâàòü îáðàáîòêó êîìïîíåíò íà ôîðìå
setStyle(GCP_DefaultStyle);
//cBackColor = c_white; //Öâåò çàäíèêà
//colorHeadMenuBackground = c_black; //Ôîí âåðõíåé ïîëîñêè
//colorHeadMenuFade = c_grey; //Ôîí âåðõíåé ïîëîñêè åñëè ôîðìà íå àêòèâíà
//colorButtonBackground = c_white; //Ôîí êíîïîê????
//Êðåñòèêè íîëèêè
formTopRightButtons = GCP_SPointer<GCP_ContextMenu>(new GCP_ContextMenu());
formTopRightButtons->setPosition(_position.x() + _position.width() - 20, _position.y() + 5);
formTopRightButtons->setMenuType(GCP_MENU_MHORIZONTAL);
formTopRightButtons->isContextMenuBlocking = false; //Ìåíþ íå áëîêèðóåò äðóãèå êîìïîíåíòû íà ôîðìå
formTopRightButtons->setStyle(GCP_ButtonWhiteStyle);
formTopRightButtons->setVisible(true);
xbutton = GCP_SPointer<GCP_Button>(new GCP_Button());
xbutton->setCaption("X");
xbutton->setWidthHeight(15, 20);
xbutton->setStyle(GCP_ButtonWhiteStyle);
xbutton->setOnMouseLeftClick(this, &GCP_Form::toggleVisibility);
xbutton->options.draw_order = -1000;
formTopRightButtons->addButton(xbutton);
addComponent(formTopRightButtons);
//Âåðõíÿÿ ïîëîñêà íà ôîðìå (äëÿ îáðàáîòêè äðàãåíäðîï)
xpanel = GCP_SPointer<GCP_Button>(new GCP_Button());
xpanel->setWidthHeight(_position.width(), 30);
xpanel->setPosition(_position.x(), _position.y());
xpanel->options.draw_order = -999;
xpanel->setStyle(GCP_PanelBlackStyle);
addComponent((GCP_SPointer<GCP_FormComponent>)xpanel);
//Ñîîáùåíèå ñ àëàðìîì
messagebox = GCP_SPointer<GCP_Form>(new GCP_MessageBox(450, 150));
messagebox->isParentLocking = true;
messagebox->setVisible(false);
messagebox->setDragable(false);
messagebox->options.draw_order = -100;
messagebox->setPosition(_position.width() / 2 - messagebox->_position.width() / 2, _position.height() / 2 - messagebox->_position.height() / 2);
const char *caprion = "ÓÂÅÄÎÌËÅÍÈÅ";
messagebox->setCaption(GCP_Math::RUSCP1251_TO_WCHAR(caprion));
addSubForm(messagebox);
}
void GCP_Form::showmessage(const string &text, const string &caption, bool block)
{
_messages.push_back(text);
_messages_caption.push_back(caption);
}
void GCP_Form::showmessage(int text, const string &captionbool, bool block)
{
showmessage(GCP_Math::intToString(text), captionbool, block);
}
void GCP_Form::setBufferSize(int screenw, int screenh)
{
_swidth = screenw;
_sheight = screenh;
//if(width > screenw || width < 0 || height > screenh || height < 0 )
// throw "Form size doesn't match screen size";
}
void GCP_Form::setFont(string dir) {
//!!! ïåðåäàåì øðèôò ñâîèì êîìïîíåíòàì
/*getStyle()->sFontDir = dir;
xbutton->setFont(getStyle()->sFontDir);
xpanel->setFont(getStyle()->sFontDir);
messagebox->setFont(getStyle()->sFontDir);*/
}
GCP_Form::~GCP_Form() {
//!!!Óäàëÿåì óêàçàòåëè èç ïàìÿòè ïî óíè÷òîæåíèþ ôîðìû!!!!!
/*for(int i=0; i<_subForms.size(); i++)
delete _subForms.at(i);
for(int i=0; i<_components.size(); i++)
delete _components.at(i);
for(int i=0; i<_contextmenus.size(); i++)
delete _contextmenus.at(i);*/
}
void GCP_Form::addToNameMap(const gcp_spFormComponent& component, const string& name)
{
childNameMap namemap;
for (size_t i = 0; i < _childNames.size(); i++)
{
childNameMap map = _childNames.at(i);
if (map.first == name)
throw;
}
namemap.first = name;
namemap.second = component->ID();
_childNames.push_back(namemap);
}
void GCP_Form::removeFromNameMap(const gcp_spFormComponent& component)
{
for (size_t i = 0; i < _childNames.size(); i++)
{
childNameMap map = _childNames.at(i);
if (map.second == component->ID())
{
_childNames.erase(i);
break;
}
}
}
const GCP_FormComponent* GCP_Form::getComponent(const string& name) const
{
for (size_t i = 0; i < _childNames.size(); i++)
{
childNameMap map = _childNames.at(i);
if (map.first == name)
{
for (size_t j = 0; j < _components.size(); j++)
if (_contextmenus.at(j)->ID() == map.second)
return ((gcp_spFormComponent)(_contextmenus.at(j))).getPointer();
for (size_t j = 0; j < _components.size(); j++)
if (_components.at(j)->ID() == map.second)
return ((gcp_spFormComponent)_components.at(j)).getPointer();
for (size_t j = 0; j < _subForms.size(); j++)
if (_subForms.at(j)->ID() == map.second)
return ((gcp_spFormComponent)_subForms.at(j)).getPointer();
}
}
return NULL;
}
void GCP_Form::addComponent(GCP_SPointer<GCP_ContextMenu> const &component, std::string name)
{
if (name != "default")
addToNameMap((GCP_SPointer<GCP_FormComponent>)component.getPointer(), name);
_contextmenus.push_back(component);
}
void GCP_Form::addComponent(GCP_SPointer<GCP_FormComponent> const &component, std::string name)
{
if (name != "default")
addToNameMap((GCP_SPointer<GCP_FormComponent>)component.getPointer(), name);
for (unsigned int i = 0; i < _components.size(); i++)
if (component == _components.at(i)) //Äâà ðàçà îäíî è òîæå íå ïðèíèìàåì
return;
//Êîîðäèíàòû êîìïîíåíòà èäóò îíîñèòåëüíî ëåâîãî âåðõíåãî óãëà ôîðìû
const GCP_Rect<int> formPos = _position;
const GCP_Rect<int> compPos = component->getPosition();
component->setPosition(formPos.x() + compPos.x(), formPos.y() + compPos.y());
//component->setFont(getFont());
_components.push_back(component);
GCP_Math::quickSortComponent<gcp_spFormComponent>(&_components, 0, _components.size() - 1, GCP_SORTBY_DRAWORDER);
}
void GCP_Form::removeComponent(GCP_SPointer<GCP_FormComponent> const &component)
{
for (unsigned int i = 0; i < _components.size(); i++)
if (_components.at(i) == component)
{
removeFromNameMap(component);
_components.erase(i);
break;
}
}
void GCP_Form::removeComponent(string const& name)
{
const GCP_FormComponent* component = getComponent(name);
for (unsigned int i = 0; i < _components.size(); i++)
if (_components.at(i) == component)
{
removeFromNameMap(_components.at(i));
_components.erase(i);
break;
}
}
void GCP_Form::toggleVisibility(void* obj)
{
setVisible(!isVisible());
}
void GCP_Form::addSubForm(GCP_SPointer<GCP_Form> const &form, std::string name)
{
if (name != "default")
addToNameMap((GCP_SPointer<GCP_FormComponent>)form.getPointer(), name);
//!!! Øðèôò ïåðåäàåì!!!
//form->setFont(getFont());
form->setBufferSize(_swidth, _sheight);
_subForms.push_back(form);
GCP_Math::quickSortComponent<gcp_spForm>(&_subForms, 0, _subForms.size() - 1, GCP_SORTBY_DRAWORDER);
}
void GCP_Form::setPosition(const GCP_Rect<int> &position)
{
_position.setWidthHeight(position.width(), position.height());
setPosition(position.x(), position.y());
}
void GCP_Form::setPosition(int x, int y, int width, int height)
{
_position.setWidthHeight(width, height);
setPosition(x, y);
}
void GCP_Form::setPosition(int x, int y)
{
int deltaX = x - _position.x();
int deltaY = y - _position.y();
_position.setTopLeft(x, y);
for (unsigned int i = 0; i < _components.size(); i++)
_components.at(i)->setPosition(_components.at(i)->getPosition().x() + deltaX, _components.at(i)->getPosition().y() + deltaY);
for (unsigned int i = 0; i < _contextmenus.size(); i++)
_contextmenus.at(i)->setPosition(_contextmenus.at(i)->getPosition().x() + deltaX, _contextmenus.at(i)->getPosition().y() + deltaY);
}
void GCP_Form::setCaption(const std::string& str)
{
xpanel->setCaption(str);
xpanel->setWidthHeight(getPosition().width(), 30);
}
void GCP_Form::OnDraw(const GCP_Event &event)
{
if (!isVisible())
return;
if (!isShowTopRightButtons)
xbutton->setVisible(false);
GCP_Event drawEvent = event;
drawEvent.drawRect = _position;
if (isTransparent)
{
if (getStyle()->backgroundColor.a != 255)
{
gcpUint8 alphaOrig = GCP_Draw::Render()->GetAlpha();
GCP_Draw::Render()->SetAlpha(getStyle()->backgroundColor.a);
GCP_Draw::Render()->SetBlendMode(E_BLEND_ADD);
GCP_Draw::Render()->Draw_FillRound(_position, 1, getStyle()->backgroundColor);
GCP_Draw::Render()->SetBlendMode(E_BLEND_NONE);
GCP_Draw::Render()->SetAlpha(alphaOrig);
}
}
else
{
GCP_Draw::Render()->Draw_FillRound(_position, 1, getStyle()->backgroundColor);
}
GCP_Draw::Render()->Draw_Round(_position, 1, getStyle()->headBackground);
//!!! Ñîðòèðîâêó òîæå íàäî îäèí ðàç ñîîáðàçèòü
//GCP_Math::quickSort<GCP_FormComponent*>(&_components,0,_components.size()-1, GCP_SORTBY_DRAWORDER);
for (unsigned int i = 0; i < _components.size(); i++)
_components.at(i)->OnDraw(drawEvent);
//Âñïëûâàþùèå ïîäñêàçêè ðèñóþòñÿ ïîâåðõ êîìïîíåíò
for (unsigned int i = 0; i < _components.size(); i++)
_components.at(i)->OnDrawInfo(drawEvent);
//Çàãàëîâîê ôîðìû
//GCP_Draw::Render()->Draw_Text(_sCaption, xPos + width / 2 - 65, yPos + xpanel->height / 5, getStyle(), &drawdata);
//Ðèñóåì Êîíòåêñòíûå ìåíþ
_isContextMenuOpened = false;
for (unsigned int i = 0; i < _contextmenus.size(); i++){
_contextmenus.at(i)->setLock(_isContextMenuOpened);
_contextmenus.at(i)->OnDraw(drawEvent);
if (_contextmenus.at(i)->isVisible() && _contextmenus.at(i)->isContextMenuBlocking)
_isContextMenuOpened = true; //áóäåì áëîêèðîâàòü êîìïîíåíòû ïîêà îòêðûòî ýòî ìåíþ
}
basicOnDraw(drawEvent);
//Ñîîáùåíèÿ ìîæíî ñäåëàòü ñ ïîòîêàìè. òîãäà îíè ìîãóò áëîêèðîâàòü âñþ ïðîãðàììó ïîêà íå íàæìåøü êíîïêó ÎÊ
//Íî òîãäà íàäî îòäåëÿòü èíòåðôåéñ îò ãëàâíîãî ïîòîêà îáðàáîòêè ñîáûòèé SDL
if (_messages.size())
if (messagebox->isVisible() == false){
messagebox->messagelabel->text = _messages.pop_first();
messagebox->setCaption(_messages_caption.pop_first());
messagebox->setVisible(true);
}
//!!! Ñîðòèðîâêó òîæå íàäî îäèí ðàç ñîîáðàçèòü
GCP_Math::quickSortComponent<gcp_spForm>(&_subForms, 0, _subForms.size() - 1, GCP_SORTBY_DRAWORDER);
unsigned int blockingFormIndex = -1;
_pBlockingForm = NULL;
onParentFormEndBlocking();
bool isHavingSubformsThatLocking = false;
for (unsigned int i = 0; i < _subForms.size(); i++){
gcp_spForm ptrSubForm = _subForms.at(i);
ptrSubForm->OnDraw(drawEvent);
ptrSubForm->onParentFormEndBlocking();
if (ptrSubForm->isParentLocking && ptrSubForm->isVisible())
{
isHavingSubformsThatLocking = true;
blockingFormIndex = i;
_pBlockingForm = ptrSubForm;
}
}
if (isHavingSubformsThatLocking)
{
onParentFormStartBlocking();
for (unsigned int i = 0; i < _subForms.size(); i++)
_subForms.at(i)->onParentFormStartBlocking();
_subForms.at(blockingFormIndex)->onParentFormEndBlocking();
}
//Ïî õîðîøåìó ìåñàäæ áîêñ äîëæåí áëîêèðîâàòü äðóãèå ôîðìû ñ
//ñëåäîâàòåëüíî ðèñîâàòüñÿ è îáðàáàòûâàòüñÿ îí äîëæåí îòäåëüíî
//messagebox->OnDraw(screen, width, height);
_isLocked = false;
if (isHavingSubformsThatLocking || isLocked)
_isLocked = true;
return;
}
///OnEvent
gcp_formEvent GCP_Form::OnEvent(const GCP_Event &cevent)
{
//Áóäåì âîçâðàùàòü ãäå íàõîäèëñÿ êóðñîð êîãäà ïðîèçîøëî ñîáûòèå
gcp_formEvent evt, other_evt;
evt.isEventInsideForm = cevent.isPassingOnlyGlobalEvent;
evt.isEventOnFormHead = false;
GCP_Event event = cevent; //Áóäåì ðåäàêòèðîâàòü ñîáûòèå.
if (!_isVisible)
return evt;
GCP_Math::quickSortComponent<gcp_spForm>(&_subForms, 0, _subForms.size() - 1, GCP_SORTBY_EVENTORDER); //WHY? EVENTORDER = DRAWORDER^-1
if (_pBlockingForm)
event.isPassingOnlyGlobalEvent = true;
//Ïåðåäàåì âñåì äî÷åðíèì ôîðìàì ãëîáàëüíîå ñîáûòèå
for (unsigned int i = 0; i < _subForms.size(); i++)
{
if (_subForms.at(i) == _pBlockingForm)
continue;
other_evt = _subForms.at(i)->OnEvent(event);
evt.isEventInsideForm = evt.isEventInsideForm || other_evt.isEventInsideForm; //Çàïîìèíàåì åñëè ýòî ñîáûòèå ïðîèçîøëî âíóòðè õîòü îäíîé èç àêòèâíûõ ôîðì
event.isPassingOnlyGlobalEvent = event.isPassingOnlyGlobalEvent || evt.isEventInsideForm; //Âñå îñòàëüíûå ôîðìû ïîëó÷àò òîëüêî ãëîáàëüíûå ñîáûòèÿ åñëè õîòü íà îäíîé ìû îáðàáîòàåì ëîêàëüíûå
}
//Ñîáûòèå äîëæíî áûòü ïåðåäàíî áëîêèðóåùåé ôîðìå è êàê ãëîáàëüíîå è êàê ëîêàëüíîå
if (_pBlockingForm)
{
event.isPassingOnlyGlobalEvent = false;
_pBlockingForm->OnEvent(event);
event.isPassingOnlyGlobalEvent = true;
}
if (_isLocked){
evt.isEventInsideForm = false;
evt.isEventOnFormHead = false;
return evt;
}
if (event.eventType == GCP_ON_MOUSE_GUP){
_isDragStarted = false;
isDraggingSomeComponent = false;
}
//ÎÏÒÈÌÈÇÈÐÎÂÀÒÜ ÊÀÊ ÒÎ ÎÁÐÀÁÎÒÊÓ ÁÎËÜØÎÃÎ ×ÈÑËÀ ÊÎÌÏÎÍÅÍÒ? ÂÐÎÄÅ ÄÎ 1000-2000 ðàáîòàåò íîðìàëüíî
//ÐÀÑ×ÅÒ ÍÀ ÒÎ ×ÒÎ ÊÎÌÏÎÍÅÍÒ ÁÓÄÅÒ ÌÍÎÃÎ > 400
//Ïðåäïîëîæèì ìû íå îáðàáàòûâàåì íèêàêîå ëîêàëüíîå ñîáûòèå ó êîìïîíåíò
bool isMouseOverSomeComponent = false;
if (!_isContextMenuOpened && !isDraggingSomeComponent)
{
for (unsigned int i = 0; i < _components.size(); i++)
{
gcp_spFormComponent component = _components.at(i);
component->OnEvent(event); //Âûçûâàåì ãëîáàëüíîå ñîáûòèå ó íàøèõ êîìïîíåíò
//Åñëè ãëîáàëüíîå ñîáûòèå ïðîèçîøëî íàä äî÷åðíåé ôîðìîé, ëîêàëüíûå ñîáûòèÿ äëÿ íàøèõ êîìïîíåíò íå îáðàáàòûâàåì
if (!isLocalEventsLocked && component->isEnabled())
if (!isMouseOverSomeComponent && !evt.isEventInsideForm)
{
if (component->checkCollisionBox(event.mousex, event.mousey))
{
component->OnEvent(MakeEventLocal(event));
if (event.eventType == GCP_ON_MOUSE_GLDOWN)
_componentThatWasLeftClicked = component;
if (component->isEventUnderneathBlocking())
isMouseOverSomeComponent = true;
//Ïåðåäàëè ëîêàëüíîå ñîáûòèå êîìïîíåíòó ïî ýòèì êîîðäèíàòàì.
//Äàëåå ëîêàëüíûå ñîáûòèÿ áîëåå íå ïåðåäàåì
}
}
}
}
event.isPassingOnlyGlobalEvent = evt.isEventInsideForm;
if (!isLocalEventsLocked)
for (unsigned int i = 0; i < _contextmenus.size(); i++)
_contextmenus.at(i)->OnEvent(event);
if (event.eventType == GCP_ON_MOUSE_GUP)
_componentThatWasLeftClicked = 0;
if (event.eventType == GCP_ON_MOUSE_GLDOWN)
_isClickedOnTopHeader = false;
//Îáðàáàòûâàåì ãëîáàëüíîå è ëîêàëüíûå ñîáûòèÿ äëÿ ôîðìû
basicOnEvent(event);
if (!event.isPassingOnlyGlobalEvent)
if (checkCollisionBox(event.mousex, event.mousey)){
mouse_x = event.mousex;
mouse_y = event.mousey;
evt.isEventInsideForm = true;
if (event.mousey < _position.y() + xpanel->getPosition().height())
{
if (event.eventType == GCP_ON_MOUSE_GLDOWN)
_isClickedOnTopHeader = true;
evt.isEventOnFormHead = true;
}
//íå ïåðåäàåì GCP_ON_GRIGHT_CLICK êàê ëîêàëüíîå ñîáûòèå åñëè êëèê áûë ïî çàãîëîâêó
if (!evt.isEventOnFormHead || event.eventType != GCP_ON_GRIGHT_CLICK)
basicOnEvent(MakeEventLocal(event));
}
return evt;
}
////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////OnMouseGlobalLeftHoldMotion
////////////////////////////////////////////////////////////////////////////////////////////
gcp_formEvent GCP_Form::OnMouseGlobalLeftHoldMotion(const GCP_Event& cevent)
{
//A special one event. Forms could check wether it is their local event only if they get this as a global event
gcp_formEvent evt;
evt.isEventInsideForm = false;
evt.isFormDragged = false;
if (!_isVisible || _pBlockingForm.getRefCount() > 0)
{
if (_pBlockingForm.getRefCount() > 0)
_pBlockingForm->OnMouseGlobalLeftHoldMotion(cevent);
return evt;
}
GCP_Event event = cevent;
event.drawRect = GCP_Rect<int>(_position.x(), _position.y(), _position.width(), _position.height());
//WHY? EVENTORDER = DRAWORDER^-1
GCP_Math::quickSortComponent<gcp_spForm>(&_subForms, 0, _subForms.size() - 1, GCP_SORTBY_EVENTORDER);
bool isDragged = false;
bool isEventInsideChildForm = false;
if (!_isDragStarted || _isLocked)
{
for (unsigned int i = 0; i < _subForms.size(); i++)
{
evt = _subForms.at(i)->OnMouseGlobalLeftHoldMotion(event);
isDragged = evt.isFormDragged; //If child form is dragged
isEventInsideChildForm = evt.isEventInsideForm;
if (isDragged) {
isDraggingSomeComponent = true; //Consider sub form as dragging component
break;
}
}
}
if (_isLocked){
evt.isEventInsideForm = false;
evt.isFormDragged = false;
return evt;
}
if (!_isContextMenuOpened){
if (!isDragged && isDragable()){
if (_isClickedOnTopHeader || _isDragStarted)
{
int xPosStart = _position.x(), yPosStart = _position.y();
_position.setTopLeft(_position.x() + event.iMouseXRel,
_position.y() + event.iMouseYRel);
_position.setTopLeft((int)GCP_Math::Max(0, GCP_Math::Min(_swidth - _position.width(), _position.x())),
(int)GCP_Math::Max(0, GCP_Math::Min(_sheight - _position.height(), _position.y())));
int deltaX = _position.x() - xPosStart;
int deltaY = _position.y() - yPosStart;
for (unsigned int i = 0; i < _components.size(); i++)
{
GCP_Rect<int> previousPos = _components.at(i)->getPosition();
_components.at(i)->setPosition(previousPos.x() + deltaX, previousPos.y() + deltaY);
}
for (unsigned int i = 0; i < _contextmenus.size(); i++)
{
if (!_contextmenus.at(i)->isContextMenuBlocking)
{
GCP_Rect<int> previousPos = _contextmenus.at(i)->getPosition();
_contextmenus.at(i)->setPosition(previousPos.x() + deltaX, previousPos.y() + deltaY);
}
}
_isDragStarted = true;
evt.isEventInsideForm = false;
evt.isFormDragged = _isDragStarted;
return evt;
}
}
bool isComponentClicked = false;
if (!_isDragStarted){
for (unsigned int i = 0; i < _components.size(); i++){
_components.at(i)->OnMouseGlobalLeftHoldMotion(event);
/*if(!isComponentClicked && !isDraggingSomeComponent)
if(_components.at(i)==_componentThatWasLeftClicked){
_components.at(i)->OnMouseLeftHoldMotion(motion,_position.x() yPos+xpanel->height,width,height-xpanel->height);
isComponentClicked = true;
isDraggingSomeComponent = true;
}*/
}
///REFACTOR THIS!!!!
if (_componentThatWasLeftClicked)
if (_componentThatWasLeftClicked->isDragable() && !isComponentClicked && !isDraggingSomeComponent)
{
event.drawRect = GCP_Rect<int>(_position.x(), _position.y() + xpanel->getPosition().height(), _position.width(), _position.height() - xpanel->getPosition().height());
_componentThatWasLeftClicked->OnMouseLeftHoldMotion(event);
isComponentClicked = true;
isDraggingSomeComponent = true;
}
}
}
if (checkCollisionBox(event.drawRect.x(), event.drawRect.y()) && !isEventInsideChildForm){
evt.isEventInsideForm = true;
basicOnMouseLeftHoldMotion(event);
}
basicOnMouseGlobalLeftHoldMotion(event);
evt.isFormDragged = _isDragStarted;
return evt;
}
void GCP_Form::onParentFormStartBlocking()
{
xpanel->setEnabled(false);
for (unsigned int i = 0; i < _subForms.size(); i++)
_subForms.at(i)->setEnabled(false);
}
void GCP_Form::onParentFormEndBlocking()
{
xpanel->setEnabled(true);
for (unsigned int i = 0; i < _subForms.size(); i++)
_subForms.at(i)->setEnabled(true); //!!!!
}
void GCP_Form::toogleTopRightButtons(bool enabled)
{
formTopRightButtons->setVisible(enabled);
}