Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-lib"
00017
00018 #include "global.hpp"
00019
00020 #include "widgets/combo.hpp"
00021 #include "display.hpp"
00022 #include "show_dialog.hpp"
00023
00024
00025 namespace gui {
00026
00027 const std::string combo::empty_combo_label = "";
00028
00029 const int combo::font_size = font::SIZE_SMALL;
00030 const int combo::horizontal_padding = 10;
00031 const int combo::vertical_padding = 10;
00032
00033 combo::combo(display& disp, const std::vector<std::string>& items)
00034 : button(disp.video(), items.empty() ? empty_combo_label : items[0]),
00035 items_(items), selected_(0), oldSelected_(0), disp_(&disp)
00036 {
00037 }
00038
00039 int combo::selected() const
00040 {
00041 return selected_;
00042 }
00043
00044 bool combo::changed()
00045 {
00046 if (oldSelected_ != selected_) {
00047 oldSelected_ = selected_;
00048 return true;
00049 } else
00050 return false;
00051 }
00052
00053 void combo::set_items(const std::vector<std::string>& items)
00054 {
00055 items_ = items;
00056 selected_ = -1;
00057 }
00058
00059 void combo::set_selected_internal(int val)
00060 {
00061 const size_t index = size_t(val);
00062 if (val == selected_ || index >= items_.size())
00063 return;
00064 set_label(items_[index]);
00065 oldSelected_ = selected_;
00066 selected_ = val;
00067 }
00068
00069 void combo::set_selected(int val)
00070 {
00071 set_selected_internal(val);
00072 oldSelected_ = selected_;
00073 }
00074
00075 void combo::make_drop_down_menu()
00076 {
00077 SDL_Rect const &loc = location();
00078 set_selected_internal(gui::show_dialog(*disp_, NULL, "", "", gui::MESSAGE, &items_,
00079 NULL, "", NULL, -1, NULL, loc.x, loc.y + loc.h));
00080 }
00081
00082 void combo::process_event()
00083 {
00084 if (!pressed())
00085 return;
00086 make_drop_down_menu();
00087 }
00088
00089 }