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