The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
progress_bar.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2010 - 2025
3 by Mark de Wever <koraq@xs4all.nl>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#define GETTEXT_DOMAIN "wesnoth-lib"
17
19
20#include "gui/core/log.hpp"
22#include "wml_exception.hpp"
23
24
25#define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
26#define LOG_HEADER LOG_SCOPE_HEADER + ':'
27
28namespace gui2
29{
30
31// ------------ WIDGET -----------{
32
33REGISTER_WIDGET(progress_bar)
34
35progress_bar::progress_bar(const implementation::builder_progress_bar& builder)
36 : styled_widget(builder, type())
37 , percentage_(static_cast<unsigned>(-1))
38{
39 // Force canvas update
40 set_percentage(0);
41}
42
43void progress_bar::set_active(const bool /*active*/)
44{
45 /* DO NOTHING */
46}
47
49{
50 return true;
51}
52
54{
55 return ENABLED;
56}
57
58void progress_bar::set_percentage(unsigned percentage)
59{
60 percentage = std::min<unsigned>(percentage, 100);
61
62 if(percentage_ != percentage) {
63 percentage_ = percentage;
64
65 for(auto & c : get_canvases())
66 {
67 c.set_variable("percentage", wfl::variant(percentage));
68 }
69
71 }
72}
73
75{
76 return false;
77}
78
79// }---------- DEFINITION ---------{
80
83{
84 DBG_GUI_P << "Parsing progress bar " << id;
85
86 load_resolutions<resolution>(cfg);
87}
88
91{
92 // Note the order should be the same as the enum state_t in progress_bar.hpp.
93 state.emplace_back(VALIDATE_WML_CHILD(cfg, "state_enabled", missing_mandatory_wml_tag("progress_bar_definition][resolution", "state_enabled")));
94}
95
96// }---------- BUILDER -----------{
97
98namespace implementation
99{
100
101builder_progress_bar::builder_progress_bar(const config& cfg)
103{
104}
105
106std::unique_ptr<widget> builder_progress_bar::build() const
107{
108 auto widget = std::make_unique<progress_bar>(*this);
109
110 DBG_GUI_G << "Window builder: placed progress bar '" << id
111 << "' with definition '" << definition << "'.";
112
113 return widget;
114}
115
116} // namespace implementation
117
118// }------------ END --------------
119
120} // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
unsigned percentage_
The percentage done.
virtual unsigned get_state() const override
See styled_widget::get_state.
bool disable_click_dismiss() const override
See widget::disable_click_dismiss.
void set_percentage(unsigned percentage)
virtual bool get_active() const override
See styled_widget::get_active.
virtual void set_active(const bool active) override
See styled_widget::set_active.
std::vector< canvas > & get_canvases()
Base class for all widgets.
Definition widget.hpp:55
void queue_redraw()
Indicates that this widget should be redrawn.
Definition widget.cpp:464
const config * cfg
Define the common log macros for the gui toolkit.
#define DBG_GUI_G
Definition log.hpp:41
#define DBG_GUI_P
Definition log.hpp:66
Generic file dialog.
Contains the implementation details for lexical_cast and shouldn't be used directly.
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
virtual std::unique_ptr< widget > build() const override
std::string definition
Parameters for the styled_widget.
progress_bar_definition(const config &cfg)
std::vector< state_definition > state
std::string missing_mandatory_wml_tag(const std::string &section, const std::string &tag)
Returns a standard message for a missing wml child (tag).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WML_CHILD(cfg, key, message)
#define c