The Battle for Wesnoth  1.19.0-dev
debug_clock.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2024
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:
52  debug_clock();
53 
54 private:
55  /** Progress bar for displaying the hours as a percentage. */
57 
58  /** Progress bar for displaying the minutes as a percentage. */
60 
61  /** Progress bar for displaying the seconds as a percentage. */
63 
64  /** An integer selector to display the total seconds. */
66 
67  /** An integer selector to display the total seconds this hour. */
69 
70  /** An integer selector to display the seconds this minute. */
72 
74 
75  /** A widget that can display the time. */
77 
78  /** The signal patched in the drawing routine. */
80 
81  /** Helper struct to keep track of the time. */
82  struct time
83  {
84  time();
85 
86  /**
87  * Sets the fields to the current time.
88  *
89  * @note The milliseconds aren't queried and set to zero.
90  */
91  void set_current_time();
92 
93  /**
94  * Moves the clock x milliseconds forward.
95  *
96  * @note The default value of @p milliseconds is the same as the
97  * interval for the drawing routine.
98  *
99  * @pre @p milliseconds < 1000.
100  *
101  * @param milliseconds The number of milliseconds to move ahead.
102  *
103  * @returns Did the number of seconds alter?
104  */
105  bool step(const unsigned milliseconds = 30);
106 
107  /** The number of hours. */
108  unsigned hour;
109 
110  /** The number of minutes. */
111  unsigned minute;
112 
113  /** The number of seconds. */
114  unsigned second;
115 
116  /** The number of milliseconds. */
117  unsigned millisecond;
118  };
119 
120  /**
121  * The `current' time.
122  *
123  * @note Since the dialog is used to test the drawing routine by keeping
124  * track of the calls to the drawing routine, the clock might be off.
125  */
127 
128  /** The type of window this is. */
129  virtual const std::string& window_id() const override;
130 
131  /**
132  * The callback for the drawing routine.
133  *
134  * It updates the `time' in the various controls.
135  *
136  * @param force Force an update even it the time didn't
137  * change? (This is used to set the clock
138  * initially.)
139  */
140  void update_time(const bool force);
141 
142  /* top_level_drawable interface */
143  virtual void update() override;
144 };
145 
146 } // namespace dialogs
147 } // namespace gui2
Clock to test the draw events.
Definition: debug_clock.hpp:50
virtual void update() override
Update state and any parameters that may effect layout, or any of the later stages.
Definition: debug_clock.cpp:68
progress_bar * second_percentage_
Progress bar for displaying the seconds as a percentage.
Definition: debug_clock.hpp:62
progress_bar * minute_percentage_
Progress bar for displaying the minutes as a percentage.
Definition: debug_clock.hpp:59
integer_selector * minute_
An integer selector to display the total seconds this hour.
Definition: debug_clock.hpp:68
integer_selector * second_
An integer selector to display the seconds this minute.
Definition: debug_clock.hpp:71
virtual const std::string & window_id() const override
The type of window this is.
void update_time(const bool force)
The callback for the drawing routine.
Definition: debug_clock.cpp:74
event::signal signal_
The signal patched in the drawing routine.
Definition: debug_clock.hpp:79
time time_
The ‘current’ time.
progress_bar * hour_percentage_
Progress bar for displaying the hours as a percentage.
Definition: debug_clock.hpp:56
integer_selector * hour_
An integer selector to display the total seconds.
Definition: debug_clock.hpp:65
styled_widget * clock_
A widget that can display the time.
Definition: debug_clock.hpp:76
The popup class shows windows that are shown non-modal.
Small abstract helper class.
A pane is a container where new members can be added and removed during run-time.
Definition: pane.hpp:43
This object shows the progress of a certain action, or the value state of a certain item.
Base class for all visible items.
Various uncategorised dialogs.
dispatcher_callback<> signal
Used for events in event_category::general.
Definition: dispatcher.hpp:56
Generic file dialog.
Helper struct to keep track of the time.
Definition: debug_clock.hpp:83
unsigned minute
The number of minutes.
unsigned second
The number of seconds.
unsigned hour
The number of hours.
void set_current_time()
Sets the fields to the current time.
bool step(const unsigned milliseconds=30)
Moves the clock x milliseconds forward.
unsigned millisecond
The number of milliseconds.