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 
22 
23 namespace gui2
24 {
25 
26 class styled_widget;
27 class pane;
28 class progress_bar;
29 class integer_selector;
30 
31 namespace dialogs
32 {
33 
34 /**
35  * @ingroup GUIWindowDefinitionWML
36  *
37  * Clock to test the draw events.
38  *
39  * This shows the dialog for keeping track of the drawing events related to the current time. (This window is used for debug purposes only.)
40  * Key |Type |Mandatory|Description
41  * ------------------|------------------|---------|-----------
42  * hour_percentage | progress_bar |no |This shows the hours as a percentage, where 24 hours is 100%.
43  * minute_percentage | progress_bar |no |This shows the minutes as a percentage, where 60 minutes is 100%.
44  * second_percentage | progress_bar |no |This shows the seconds as a percentage, where 60 seconds is 100%.
45  * 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).
46  * 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).
47  * 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.
48  * 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).
49  */
51 {
52 public:
53  debug_clock();
54 
55 private:
56  /** Progress bar for displaying the hours as a percentage. */
58 
59  /** Progress bar for displaying the minutes as a percentage. */
61 
62  /** Progress bar for displaying the seconds as a percentage. */
64 
65  /** An integer selector to display the total seconds. */
67 
68  /** An integer selector to display the total seconds this hour. */
70 
71  /** An integer selector to display the seconds this minute. */
73 
75 
76  /** A widget that can display the time. */
78 
79  /** The signal patched in the drawing routine. */
81 
82  /** Helper struct to keep track of the time. */
83  struct time
84  {
85  time();
86 
87  /**
88  * Sets the fields to the current time.
89  *
90  * @note The milliseconds aren't queried and set to zero.
91  */
92  void set_current_time();
93 
94  /**
95  * Moves the clock x milliseconds forward.
96  *
97  * @note The default value of @p milliseconds is the same as the
98  * interval for the drawing routine.
99  *
100  * @pre @p milliseconds < 1000.
101  *
102  * @param milliseconds The number of milliseconds to move ahead.
103  *
104  * @returns Did the number of seconds alter?
105  */
106  bool step(const unsigned milliseconds = 30);
107 
108  /** The number of hours. */
109  unsigned hour;
110 
111  /** The number of minutes. */
112  unsigned minute;
113 
114  /** The number of seconds. */
115  unsigned second;
116 
117  /** The number of milliseconds. */
118  unsigned millisecond;
119  };
120 
121  /**
122  * The `current' time.
123  *
124  * @note Since the dialog is used to test the drawing routine by keeping
125  * track of the calls to the drawing routine, the clock might be off.
126  */
128 
129  /** The type of window this is. */
130  virtual const std::string& window_id() const override;
131 
132  /**
133  * The callback for the drawing routine.
134  *
135  * It updates the `time' in the various controls.
136  *
137  * @param force Force an update even it the time didn't
138  * change? (This is used to set the clock
139  * initially.)
140  */
141  void update_time(const bool force);
142 
143  /* top_level_drawable interface */
144  virtual void update() override;
145 };
146 
147 } // namespace dialogs
148 } // namespace gui2
Clock to test the draw events.
Definition: debug_clock.hpp:51
virtual void update() override
Update state and any parameters that may effect layout, or any of the later stages.
Definition: debug_clock.cpp:70
progress_bar * second_percentage_
Progress bar for displaying the seconds as a percentage.
Definition: debug_clock.hpp:63
progress_bar * minute_percentage_
Progress bar for displaying the minutes as a percentage.
Definition: debug_clock.hpp:60
integer_selector * minute_
An integer selector to display the total seconds this hour.
Definition: debug_clock.hpp:69
integer_selector * second_
An integer selector to display the seconds this minute.
Definition: debug_clock.hpp:72
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:76
event::signal signal_
The signal patched in the drawing routine.
Definition: debug_clock.hpp:80
time time_
The ‘current’ time.
progress_bar * hour_percentage_
Progress bar for displaying the hours as a percentage.
Definition: debug_clock.hpp:57
integer_selector * hour_
An integer selector to display the total seconds.
Definition: debug_clock.hpp:66
styled_widget * clock_
A widget that can display the time.
Definition: debug_clock.hpp:77
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:44
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:58
Generic file dialog.
Helper struct to keep track of the time.
Definition: debug_clock.hpp:84
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.