The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
progress_bar.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2016 by Mark de Wever <[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 
18 
19 #include "gui/core/log.hpp"
21 #include "gui/widgets/settings.hpp"
22 
23 #include "utils/functional.hpp"
24 
25 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
26 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
27 
28 namespace gui2
29 {
30 
31 // ------------ WIDGET -----------{
32 
33 REGISTER_WIDGET(progress_bar)
34 
35 void tprogress_bar::set_active(const bool /*active*/)
36 {
37  /* DO NOTHING */
38 }
39 
41 {
42  return true;
43 }
44 
45 unsigned tprogress_bar::get_state() const
46 {
47  return ENABLED;
48 }
49 
50 void tprogress_bar::set_percentage(unsigned percentage)
51 {
52  percentage = std::min<unsigned>(percentage, 100);
53 
54  if(percentage_ != percentage) {
55  percentage_ = percentage;
56 
57  for(auto & c : canvas())
58  {
59  c.set_variable("percentage", variant(percentage));
60  }
61 
62  set_is_dirty(true);
63  }
64 }
65 
67 {
68  return false;
69 }
70 
72 {
73  static const std::string type = "progress_bar";
74  return type;
75 }
76 
77 // }---------- DEFINITION ---------{
78 
80  : tcontrol_definition(cfg)
81 {
82  DBG_GUI_P << "Parsing progress bar " << id << '\n';
83 
84  load_resolutions<tresolution>(cfg);
85 }
86 
87 /*WIKI
88  * @page = GUIWidgetDefinitionWML
89  * @order = 1_progress_bar
90  *
91  * == Progress bar ==
92  *
93  * @macro = progress_bar_description
94  *
95  * The definition of a progress bar. This object shows the progress of a certain
96  * action, or the value state of a certain item.
97  *
98  * The following states exist:
99  * * state_enabled, the progress bar is enabled.
100  * @begin{parent}{name="gui/"}
101  * @begin{tag}{name="progress_bar_definition"}{min=0}{max=-1}{super="generic/widget_definition"}
102  * @begin{tag}{name="resolution"}{min=0}{max=-1}{super="generic/widget_definition/resolution"}
103  * @begin{tag}{name="state_enabled"}{min=0}{max=1}{super="generic/state"}
104  * @end{tag}{name="state_enabled"}
105  * @end{tag}{name="resolution"}
106  * @end{tag}{name="progress_bar_definition"}
107  * @end{parent}{name="gui/"}
108  */
111 {
112  // Note the order should be the same as the enum tstate in progress_bar.hpp.
113  state.push_back(tstate_definition(cfg.child("state_enabled")));
114 }
115 
116 // }---------- BUILDER -----------{
117 
118 /*WIKI_MACRO
119  * @begin{macro}{progress_bar_description}
120  * A progress bar shows the progress of a certain object.
121  * @end{macro}
122  */
123 
124 /*WIKI
125  * @page = GUIWidgetInstanceWML
126  * @order = 2_progress_bar
127  *
128  * == Image ==
129  *
130  * @macro = progress_bar_description
131  *
132  * A progress bar has no extra fields.
133  * @begin{parent}{name="gui/window/resolution/grid/row/column/"}
134  * @begin{tag}{name="progress_bar"}{min=0}{max=-1}{super="generic/widget_instance"}
135  * @end{tag}{name="progress_bar"}
136  * @end{parent}{name="gui/window/resolution/grid/row/column/"}
137  */
138 
139 namespace implementation
140 {
141 
142 tbuilder_progress_bar::tbuilder_progress_bar(const config& cfg)
143  : tbuilder_control(cfg)
144 {
145 }
146 
148 {
149  tprogress_bar* widget = new tprogress_bar();
150 
151  init_control(widget);
152 
153  DBG_GUI_G << "Window builder: placed progress bar '" << id
154  << "' with definition '" << definition << "'.\n";
155 
156  return widget;
157 }
158 
159 } // namespace implementation
160 
161 // }------------ END --------------
162 
163 } // namespace gui2
Define the common log macros for the gui toolkit.
#define DBG_GUI_P
Definition: log.hpp:69
bool disable_click_dismiss() const override
See twidget::disable_click_dismiss.
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
const GLfloat * c
Definition: glew.h:12741
void set_percentage(unsigned percentage)
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
virtual unsigned get_state() const override
See tcontrol::get_state.
void set_is_dirty(const bool is_dirty)
Definition: widget.cpp:435
Base class of a resolution, contains the common keys for a resolution.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void init_control(tcontrol *control) const
Definition: control.cpp:675
std::string definition
Parameters for the control.
Definition: control.hpp:530
This file contains the settings handling of the widget library.
unsigned percentage_
The percentage done.
Contains the state info for a resolution.
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
std::vector< tcanvas > & canvas()
Definition: control.hpp:282
tprogress_bar_definition(const config &cfg)
virtual const std::string & get_control_type() const override
See tcontrol::get_control_type.
virtual bool get_active() const override
See tcontrol::get_active.
std::vector< tstate_definition > state
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:658
Base class for all widgets.
Definition: widget.hpp:49
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
#define DBG_GUI_G
Definition: log.hpp:41
GLsizei const GLcharARB ** string
Definition: glew.h:4503
Contains the implementation details for lexical_cast and shouldn't be used directly.