The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
combo.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "global.hpp"
18 
19 #include "construct_dialog.hpp"
20 #include "widgets/combo.hpp"
21 
22 class CVideo;
23 
24 namespace gui {
25 
27 
29 const int combo::horizontal_padding = 10;
30 const int combo::vertical_padding = 10;
31 
32 combo::combo(CVideo& video, const std::vector<std::string>& items)
33  : button(video, items.empty() ? empty_combo_label : items[0]),
34  items_(items), selected_(0), oldSelected_(0), video_(&video)
35 {
36 }
37 
38 int combo::selected() const
39 {
40  return selected_;
41 }
42 
44 {
45  if (oldSelected_ != selected_) {
47  return true;
48  } else
49  return false;
50 }
51 
52 void combo::set_items(const std::vector<std::string>& items)
53 {
54  items_ = items;
55  selected_ = -1;
56 }
57 
59 {
60  const size_t index = size_t(val);
61  if (val == selected_ || index >= items_.size())
62  return;
63  set_label(items_[index]);
65  selected_ = val;
66 }
67 
69 {
72 }
73 
75 {
76  SDL_Rect const &loc = location();
78  nullptr, "", nullptr, -1, nullptr, loc.x, loc.y + loc.h,
80 }
81 
83 {
84  if (!pressed())
85  return;
87 }
88 
89 }
CVideo * video_
Definition: combo.hpp:41
void set_label(const std::string &val)
Definition: button.cpp:604
virtual void process_event()
Definition: combo.cpp:82
Definition: video.hpp:58
General purpose widgets.
std::vector< std::string > items_
Definition: combo.hpp:39
GLuint const GLfloat * val
Definition: glew.h:2614
static const int horizontal_padding
Definition: combo.hpp:44
combo(CVideo &v, const std::vector< std::string > &items)
Definition: combo.cpp:32
const std::vector< std::string > items
int selected() const
Definition: combo.cpp:38
static const int font_size
Definition: combo.hpp:43
static const int vertical_padding
Definition: combo.hpp:45
bool changed()
Definition: combo.cpp:43
int show_dialog(CVideo &video, surface image, const std::string &caption, const std::string &message, DIALOG_TYPE type, const std::vector< std::string > *menu_items, const std::vector< preview_pane * > *preview_panes, const std::string &text_widget_label, std::string *text_widget_text, const int text_widget_max_chars, std::vector< check_item > *options, int xloc, int yloc, const dialog_frame::style *dialog_style, std::vector< dialog_button_info > *action_buttons, const menu::sorter *sorter, menu::style *menu_style)
static const style hotkeys_style
bool pressed()
Definition: button.cpp:770
void set_selected_internal(int val)
Definition: combo.cpp:58
void set_selected(int val)
Definition: combo.cpp:68
GLuint index
Definition: glew.h:1782
void set_items(const std::vector< std::string > &items)
Definition: combo.cpp:52
std::vector< expression_ptr > items_
Definition: formula.cpp:119
int selected_
Definition: combo.hpp:40
void make_drop_down_menu()
Definition: combo.cpp:74
static const std::string empty_combo_label
Definition: combo.hpp:42
SDL_Rect const & location() const
Definition: widget.cpp:144
int oldSelected_
Definition: combo.hpp:40
GLsizei const GLcharARB ** string
Definition: glew.h:4503
const int SIZE_SMALL
Definition: font.hpp:62