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