/
GUIlistPopup.cpp
80 lines (67 loc) · 2.12 KB
/
GUIlistPopup.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
#include "GUI_Common.h"
#include "GUI_Surface_Base.h"
#include "GUI_Surface.h"
#include "GUI_elements.h"
#include "GUI_Looks.h"
#include "GUIentity.h"
#include "GUImanager.h"
#include "GUIplugin.h"
#include "GUIpopup.h"
#include "GUIlistPopup.h"
GUIlistPopup::GUIlistPopup(string title, vector<string> items, GUI_BaseElement *parent, RECT rect, bool(*callback)(int, void*), void *usrdata, string styleid, string styleset)
: GUIpopup(parent, rect, styleid, styleset)
{
CreateLabel(title, _R(10, 10, width - 10, 35), POPUP);
//calculate the height of the listbox
int listheight = min(height - 80, GUI_ListBox::GetNeededListBoxHeight((int)items.size(), STYLE_LISTBOX));
list = CreateListBox(_R(10, 40, width - 10, 40 + listheight), POPUP, LISTPOPUPLIST);
//add elements to the list
for (UINT i = 0; i < items.size(); ++i)
{
list->AddElement(items[i]);
}
list->SetSelected(0);
//create ok and cancel buttons
okbtn = CreateDynamicButton("Ok", _R(width - 140, height - 35, width - 80, height - 10), POPUP, LISTPOPUPOK);
cancelbtn = CreateDynamicButton("Cancel", _R(width - 70, height - 35, width - 10, height - 10), POPUP, LISTPOPUPCANCEL);
clbk = callback;
this->usrdata = usrdata;
}
GUIlistPopup::~GUIlistPopup()
{
}
bool GUIlistPopup::ProcessChildren(GUI_MOUSE_EVENT _event, int _x, int _y)
{
if (isvisible)
{
//see if any children have been clicked
int eventid = -1;
for (UINT i = rootelements.size(); i > 0; --i)
{
eventid = rootelements[i - 1]->ProcessMouse(_event, _x, _y);
if (eventid != -1) break;
}
if (eventid != -1)
{
if (eventid == LISTPOPUPOK)
{
//invoke the callback function and tell it what item was selected
if (clbk(list->GetSelected(), usrdata))
{
//if the callback returns true, close the popup
close();
}
}
else if (eventid == LISTPOPUPCANCEL)
{
//invoke the callback function and tell it no item was selected
clbk(-1, usrdata);
//close the popup regardless of what the callback returned
close();
}
}
//something has processed an event, and even if we don't care about it here, we still need a redraw
return true;
}
return false;
}