-
Notifications
You must be signed in to change notification settings - Fork 27
/
choicegrid.h
78 lines (66 loc) · 2.45 KB
/
choicegrid.h
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
//////////////////////////////////////////////////////////////////////
// Yet Another Tibia Client
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//////////////////////////////////////////////////////////////////////
#ifndef __CHOICES_H
#define __CHOICES_H
#include <string>
#include <GLICT/panel.h>
#include <GLICT/button.h>
class ChoiceGrid
{
public:
struct Item;
typedef void (*ItemCallback_t)(Item *parent, Item *olditem);
typedef void (*Callback_t)(ChoiceGrid* parent, Item* item, Item* olditem);
struct Item {
std::string txt;
glictButton btn;
ItemCallback_t cb;
void* data;
class ChoiceGrid* parent;
};
ChoiceGrid();
~ChoiceGrid();
ChoiceGrid::Item* addItem(const std::string &txt, ItemCallback_t cb, void* data=NULL, bool enabled=true);
void setRows(int rows);
void setPadding(int w, int h);
void setItemSize(int w, int h);
void rebuildGrid();
void setOnClick(Callback_t func) { cb=func; }
void setSelected(ChoiceGrid::Item* newitem);
void setData(void* data) { this->data = data; }
void setFont(const std::string& font) { this->font = font; }
glictPanel* getGrid() { return &grid; }
ChoiceGrid::Item* getSelected() { return selected; }
const ChoiceGrid::Item* getSelected() const { return selected; }
void* getData() { return data; }
int getCount() const { return items.size(); }
private:
glictPanel grid;
std::vector<Item*> items;
int paddingw, paddingh;
int rows;
int w, h;
Callback_t cb;
Item* selected;
void* data;
std::string font;
static void onClick(glictPos* relmousepos, glictContainer* caller);
};
#endif