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