The Battle for Wesnoth  1.17.0-dev
debug_clock.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2021
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 #pragma once
17 
19 
21 
22 namespace gui2
23 {
24 
25 class styled_widget;
26 class pane;
27 class progress_bar;
28 class integer_selector;
29 
30 namespace dialogs
31 {
32 
33 /**
34  * @ingroup GUIWindowDefinitionWML
35  *
36  * Clock to test the draw events.
37  *
38  * This shows the dialog for keeping track of the drawing events related to the current time. (This window is used for debug purposes only.)
39  * Key |Type |Mandatory|Description
40  * ------------------|------------------|---------|-----------
41  * hour_percentage | progress_bar |no |This shows the hours as a percentage, where 24 hours is 100%.
42  * minute_percentage | progress_bar |no |This shows the minutes as a percentage, where 60 minutes is 100%.
43  * second_percentage | progress_bar |no |This shows the seconds as a percentage, where 60 seconds is 100%.
44  * hour | integer_selector |no |This shows the seconds since the beginning of the day. The control should have a minimum_value of 0 and a maximum_value of 86399 (246060 - 1).
45  * minute | integer_selector |no |This shows the seconds since the beginning of the current hour. The control should have a minimum_value of 0 and a maximum_value of 3599 (6060 - 1).
46  * second | integer_selector |no |This shows the seconds since the beginning of the current minute. The control should have a minimum_value of 0 and a maximum_value of 59.
47  * clock | control |no |A control which will have set three variables in its canvas:<ul><li>hour - the same value as the hour integer_selector.</li><li>minute - the same value as the minute integer_selector.</li><li>second - the same value as the second integer_selector.</li></ul>The control can then show the time in its own preferred format(s).
48  */
50 {
51 public:
53  : modeless_dialog()
54  , hour_percentage_(nullptr)
55  , minute_percentage_(nullptr)
56  , second_percentage_(nullptr)
57  , hour_(nullptr)
58  , minute_(nullptr)
59  , second_(nullptr)
60  , pane_(nullptr)
61  , clock_(nullptr)
62  , signal_()
63  , time_()
64  {
65  }
66 
67 private:
68  /** Progress bar for displaying the hours as a percentage. */
70 
71  /** Progress bar for displaying the minutes as a percentage. */
73 
74  /** Progress bar for displaying the seconds as a percentage. */
76 
77  /** An integer selector to display the total seconds. */
79 
80  /** An integer selector to display the total seconds this hour. */
82 
83  /** An integer selector to display the seconds this minute. */
85 
87 
88  /** A widget that can display the time. */
90 
91  /** The signal patched in the drawing routine. */
93 
94  /** Helper struct to keep track of the time. */
95  struct time
96  {
97  time();
98 
99  /**
100  * Sets the fields to the current time.
101  *
102  * @note The milliseconds aren't queried and set to zero.
103  */
104  void set_current_time();
105 
106  /**
107  * Moves the clock x milliseconds forward.
108  *
109  * @note The default value of @p milliseconds is the same as the
110  * interval for the drawing routine.
111  *
112  * @pre @p milliseconds < 1000.
113  *
114  * @param milliseconds The number of milliseconds to move ahead.
115  *
116  * @returns Did the number of seconds alter?
117  */
118  bool step(const unsigned milliseconds = 30);
119 
120  /** The number of hours. */
121  unsigned hour;
122 
123  /** The number of minutes. */
124  unsigned minute;
125 
126  /** The number of seconds. */
127  unsigned second;
128 
129  /** The number of milliseconds. */
130  unsigned millisecond;
131  };
132 
133  /**
134  * The `current' time.
135  *
136  * @note Since the dialog is used to test the drawing routine by keeping
137  * track of the calls to the drawing routine, the clock might be off.
138  */
140 
141  virtual const std::string& window_id() const override;
142 
143  virtual void pre_show(window& window) override;
144 
145  virtual void post_show(CVideo& video);
146 
147  /**
148  * The callback for the drawing routine.
149  *
150  * It updates the `time' in the various controls.
151  *
152  * @param force Force an update even it the time didn't
153  * change? (This is used to set the clock
154  * initially.)
155  */
156  void update_time(const bool force);
157 };
158 
159 } // namespace dialogs
160 } // namespace gui2
integer_selector * minute_
An integer selector to display the total seconds this hour.
Definition: debug_clock.hpp:81
progress_bar * second_percentage_
Progress bar for displaying the seconds as a percentage.
Definition: debug_clock.hpp:75
integer_selector * hour_
An integer selector to display the total seconds.
Definition: debug_clock.hpp:78
progress_bar * minute_percentage_
Progress bar for displaying the minutes as a percentage.
Definition: debug_clock.hpp:72
Definition: video.hpp:32
This object shows the progress of a certain action, or the value state of a certain item...
integer_selector * second_
An integer selector to display the seconds this minute.
Definition: debug_clock.hpp:84
unsigned second
The number of seconds.
event::signal_function signal_
The signal patched in the drawing routine.
Definition: debug_clock.hpp:92
dispatcher_callback_func<> signal_function
Callback function signature.
Definition: dispatcher.hpp:198
Small abstract helper class.
Generic file dialog.
Definition: field-fwd.hpp:23
void update_time(const bool force)
The callback for the drawing routine.
Definition: debug_clock.cpp:75
Helper struct to keep track of the time.
Definition: debug_clock.hpp:95
A pane is a container where new members can be added and removed during run-time. ...
Definition: pane.hpp:43
Various uncategorised dialogs.
progress_bar * hour_percentage_
Progress bar for displaying the hours as a percentage.
Definition: debug_clock.hpp:69
unsigned minute
The number of minutes.
time time_
The `current&#39; time.
void set_current_time()
Sets the fields to the current time.
Clock to test the draw events.
Definition: debug_clock.hpp:49
virtual const std::string & window_id() const override
The id of the window to build.
Base class for all visible items.
virtual void post_show(CVideo &video)
Definition: debug_clock.cpp:70
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: debug_clock.cpp:37
The popup class shows windows that are shown non-modal.
unsigned hour
The number of hours.
unsigned millisecond
The number of milliseconds.
bool step(const unsigned milliseconds=30)
Moves the clock x milliseconds forward.
styled_widget * clock_
A widget that can display the time.
Definition: debug_clock.hpp:89
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65