hegyi@112
|
1 |
#include "mapselector.h"
|
hegyi@112
|
2 |
|
hegyi@114
|
3 |
MapSelector::MapSelector(std::vector<std::string> ml, std::string act, std::string labeltext, bool edge, bool d):def(d),itisedge(edge),set_new_map(false)
|
hegyi@112
|
4 |
{
|
hegyi@112
|
5 |
update_list(ml);
|
hegyi@112
|
6 |
|
hegyi@112
|
7 |
if(act=="")
|
hegyi@112
|
8 |
{
|
hegyi@112
|
9 |
cbt.set_active(0);
|
hegyi@112
|
10 |
default_state=true;
|
hegyi@112
|
11 |
}
|
hegyi@112
|
12 |
else
|
hegyi@112
|
13 |
{
|
hegyi@112
|
14 |
cbt.set_active_text((Glib::ustring)act);
|
hegyi@112
|
15 |
default_state=false;
|
hegyi@112
|
16 |
}
|
hegyi@112
|
17 |
|
hegyi@112
|
18 |
//binding signal to the actual entry
|
hegyi@112
|
19 |
cbt.signal_changed().connect
|
hegyi@112
|
20 |
(
|
hegyi@112
|
21 |
sigc::mem_fun((*this), &MapSelector::comboChanged),
|
hegyi@112
|
22 |
false
|
hegyi@112
|
23 |
);
|
hegyi@112
|
24 |
|
hegyi@114
|
25 |
label=new Gtk::Label(labeltext);
|
hegyi@112
|
26 |
|
hegyi@112
|
27 |
label->set_width_chars(longest_property_string_length);
|
hegyi@112
|
28 |
|
hegyi@112
|
29 |
defbut=new Gtk::Button();
|
hegyi@112
|
30 |
defbut->set_label("Reset");
|
hegyi@112
|
31 |
|
hegyi@112
|
32 |
defbut->signal_pressed().connect
|
hegyi@112
|
33 |
(
|
hegyi@112
|
34 |
sigc::mem_fun(*this, &MapSelector::reset)
|
hegyi@112
|
35 |
);
|
hegyi@112
|
36 |
|
hegyi@112
|
37 |
newbut=new Gtk::Button(Gtk::Stock::NEW);
|
hegyi@112
|
38 |
|
hegyi@112
|
39 |
newbut->signal_pressed().connect
|
hegyi@112
|
40 |
(
|
hegyi@112
|
41 |
sigc::mem_fun(*this, &MapSelector::new_but_pressed)
|
hegyi@112
|
42 |
);
|
hegyi@112
|
43 |
|
hegyi@112
|
44 |
add(*label);
|
hegyi@112
|
45 |
|
hegyi@112
|
46 |
add(cbt);
|
hegyi@112
|
47 |
|
hegyi@112
|
48 |
add(*defbut);
|
hegyi@112
|
49 |
add(*newbut);
|
hegyi@112
|
50 |
}
|
hegyi@112
|
51 |
|
hegyi@112
|
52 |
void MapSelector::new_but_pressed()
|
hegyi@112
|
53 |
{
|
hegyi@112
|
54 |
set_new_map=true;
|
hegyi@112
|
55 |
signal_newmapwin.emit(itisedge);
|
hegyi@112
|
56 |
}
|
hegyi@112
|
57 |
|
hegyi@112
|
58 |
void MapSelector::update_list( std::vector< std::string > ml )
|
hegyi@112
|
59 |
{
|
hegyi@112
|
60 |
int prev_act=cbt.get_active_row_number();
|
hegyi@112
|
61 |
cbt.clear();
|
hegyi@112
|
62 |
std::vector< std::string >::iterator emsi=ml.begin();
|
hegyi@112
|
63 |
for(;emsi!=ml.end();emsi++)
|
hegyi@112
|
64 |
{
|
hegyi@112
|
65 |
cbt.append_text(*emsi);
|
hegyi@112
|
66 |
}
|
hegyi@114
|
67 |
if(def)
|
hegyi@114
|
68 |
{
|
hegyi@114
|
69 |
cbt.prepend_text("Default values");
|
hegyi@114
|
70 |
}
|
hegyi@112
|
71 |
if(prev_act!=-1)
|
hegyi@112
|
72 |
{
|
hegyi@112
|
73 |
cbt.set_active(prev_act);
|
hegyi@112
|
74 |
}
|
hegyi@112
|
75 |
}
|
hegyi@112
|
76 |
|
hegyi@112
|
77 |
void MapSelector::comboChanged()
|
hegyi@112
|
78 |
{
|
hegyi@112
|
79 |
if(cbt.get_active_row_number()!=0)
|
hegyi@112
|
80 |
{
|
hegyi@112
|
81 |
default_state=false;
|
hegyi@112
|
82 |
Glib::ustring mapname = cbt.get_active_text();
|
hegyi@112
|
83 |
if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
|
hegyi@112
|
84 |
{
|
hegyi@112
|
85 |
signal_cbt.emit(mapname);
|
hegyi@112
|
86 |
}
|
hegyi@112
|
87 |
}
|
hegyi@112
|
88 |
else if((!default_state)&&(cbt.get_active_row_number()==0))
|
hegyi@112
|
89 |
{
|
hegyi@112
|
90 |
reset();
|
hegyi@112
|
91 |
}
|
hegyi@112
|
92 |
}
|
hegyi@112
|
93 |
|
hegyi@112
|
94 |
void MapSelector::reset()
|
hegyi@112
|
95 |
{
|
hegyi@112
|
96 |
default_state=true;
|
hegyi@112
|
97 |
|
hegyi@112
|
98 |
cbt.set_active(0);
|
hegyi@112
|
99 |
|
hegyi@112
|
100 |
signal_cbt.emit("");
|
hegyi@112
|
101 |
}
|
hegyi@112
|
102 |
|
hegyi@112
|
103 |
|
hegyi@112
|
104 |
Glib::ustring MapSelector::get_active_text()
|
hegyi@112
|
105 |
{
|
hegyi@112
|
106 |
return cbt.get_active_text();
|
hegyi@112
|
107 |
}
|
hegyi@112
|
108 |
|
hegyi@112
|
109 |
void MapSelector::set_active_text(Glib::ustring text)
|
hegyi@112
|
110 |
{
|
hegyi@112
|
111 |
cbt.set_active_text(text);
|
hegyi@112
|
112 |
}
|
hegyi@112
|
113 |
|
hegyi@112
|
114 |
void MapSelector::append_text(Glib::ustring text)
|
hegyi@112
|
115 |
{
|
hegyi@112
|
116 |
cbt.append_text(text);
|
hegyi@112
|
117 |
if(set_new_map)
|
hegyi@112
|
118 |
{
|
hegyi@112
|
119 |
set_active_text(text);
|
hegyi@112
|
120 |
set_new_map=false;
|
hegyi@112
|
121 |
}
|
hegyi@112
|
122 |
}
|
hegyi@112
|
123 |
|
hegyi@112
|
124 |
sigc::signal<void, std::string> MapSelector::signal_cbt_ch()
|
hegyi@112
|
125 |
{
|
hegyi@112
|
126 |
return signal_cbt;
|
hegyi@112
|
127 |
}
|
hegyi@112
|
128 |
|
hegyi@112
|
129 |
sigc::signal<void, bool> MapSelector::signal_newmapwin_needed()
|
hegyi@112
|
130 |
{
|
hegyi@112
|
131 |
return signal_newmapwin;
|
hegyi@112
|
132 |
}
|