The Battle for Wesnoth  1.15.1+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 /** Clock to test the draw events. */
34 {
35 public:
37  : modeless_dialog()
38  , hour_percentage_(nullptr)
39  , minute_percentage_(nullptr)
40  , second_percentage_(nullptr)
41  , hour_(nullptr)
42  , minute_(nullptr)
43  , second_(nullptr)
44  , pane_(nullptr)
45  , clock_(nullptr)
46  , signal_()
47  , time_()
48  {
49  }
50 
51 private:
52  /** Progress bar for displaying the hours as a percentage. */
54 
55  /** Progress bar for displaying the minutes as a percentage. */
57 
58  /** Progress bar for displaying the seconds as a percentage. */
60 
61  /** An integer selector to display the total seconds. */
63 
64  /** An integer selector to display the total seconds this hour. */
66 
67  /** An integer selector to display the seconds this minute. */
69 
71 
72  /** A widget that can display the time. */
74 
75  /** The signal patched in the drawing routine. */
77 
78  /** Helper struct to keep track of the time. */
79  struct time
80  {
81  time();
82 
83  /**
84  * Sets the fields to the current time.
85  *
86  * @note The milliseconds aren't queried and set to zero.
87  */
88  void set_current_time();
89 
90  /**
91  * Moves the clock x milliseconds forward.
92  *
93  * @note The default value of @p milliseconds is the same as the
94  * interval for the drawing routine.
95  *
96  * @pre @p milliseconds < 1000.
97  *
98  * @param milliseconds The number of milliseconds to move ahead.
99  *
100  * @returns Did the number of seconds alter?
101  */
102  bool step(const unsigned milliseconds = 30);
103 
104  /** The number of hours. */
105  unsigned hour;
106 
107  /** The number of minutes. */
108  unsigned minute;
109 
110  /** The number of seconds. */
111  unsigned second;
112 
113  /** The number of milliseconds. */
114  unsigned millisecond;
115  };
116 
117  /**
118  * The `current' time.
119  *
120  * @note Since the dialog is used to test the drawing routine by keeping
121  * track of the calls to the drawing routine, the clock might be off.
122  */
124 
125  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
126  virtual const std::string& window_id() const override;
127 
128  /** Inherited from modal_dialog. */
129  virtual void pre_show(window& window) override;
130 
131  /** Inherited from modal_dialog. */
132  virtual void post_show(CVideo& video);
133 
134  /**
135  * The callback for the drawing routine.
136  *
137  * It updates the `time' in the various controls.
138  *
139  * @param force Force an update even it the time didn't
140  * change? (This is used to set the clock
141  * initially.)
142  */
143  void update_time(const bool force);
144 };
145 
146 } // namespace dialogs
147 } // namespace gui2
integer_selector * minute_
An integer selector to display the total seconds this hour.
Definition: debug_clock.hpp:65
progress_bar * second_percentage_
Progress bar for displaying the seconds as a percentage.
Definition: debug_clock.hpp:59
integer_selector * hour_
An integer selector to display the total seconds.
Definition: debug_clock.hpp:62
progress_bar * minute_percentage_
Progress bar for displaying the minutes as a percentage.
Definition: debug_clock.hpp:56
Definition: video.hpp:31
integer_selector * second_
An integer selector to display the seconds this minute.
Definition: debug_clock.hpp:68
unsigned second
The number of seconds.
event::signal_function signal_
The signal patched in the drawing routine.
Definition: debug_clock.hpp:76
Small abstract helper class.
Generic file dialog.
Definition: field-fwd.hpp:22
void update_time(const bool force)
The callback for the drawing routine.
Helper struct to keep track of the time.
Definition: debug_clock.hpp:79
Various uncategorised dialogs.
progress_bar * hour_percentage_
Progress bar for displaying the hours as a percentage.
Definition: debug_clock.hpp:53
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:33
virtual const std::string & window_id() const override
Inherited from modal_dialog, implemented by REGISTER_DIALOG.
Base class for all visible items.
std::function< void(widget &dispatcher, const ui_event event, bool &handled, bool &halt)> signal_function
Callback function signature.
Definition: dispatcher.hpp:42
virtual void post_show(CVideo &video)
Inherited from modal_dialog.
virtual void pre_show(window &window) override
Inherited from modal_dialog.
Definition: debug_clock.cpp:80
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:73
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63