The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
debug.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
16 
17 #ifndef GUI_WIDGETS_DEBUG_HPP_INCLUDED
18 #define GUI_WIDGETS_DEBUG_HPP_INCLUDED
19 
20 #include "gui/widgets/grid.hpp"
21 
22 #include <iosfwd>
23 #include <string>
24 
25 namespace gui2
26 {
27 
28 class twidget;
29 class twindow;
30 
31 /**
32  * Helper class to output the layout to dot files.
33  *
34  * The class will generate .dot files in the location where wesnoth is running
35  * (so needs write access there). These files can be converted to images
36  * containing the graphs. This is used for debugging the widget library and its
37  * sizing algorithm.
38  *
39  * This class needs to be friends with a lot of classes so it can view the
40  * private data in the class. This design is chosen so the debug info can be
41  * put in a separate class instead of adding the info via virtual functions in
42  * the classes themselves. Also adding 'friend class foo' doesn't need to
43  * include the header declaring foo, so it avoids header cluttage.
44  *
45  */
46 class tdebug_layout_graph
47 {
48 public:
49  /**
50  * Constructor.
51  *
52  * @param window The window, whose information will be
53  * generated.
54  */
55  explicit tdebug_layout_graph(const twindow* window);
56 
57  /***** ***** ***** ***** FLAGS ***** ***** ***** *****/
58 
59  // domain flags
60  static const unsigned MANUAL = 0 << 0; /**<
61  * Shows the info when the F12 is
62  * pressed. The value 0 makes sure
63  * the domain is always valid.
64  */
65  static const unsigned SHOW = 1 << 0; /**<
66  * Shows the info when the dialog
67  * is shown.
68  */
69  static const unsigned LAYOUT = 1 << 1; /**<
70  * Shows the info in all layout
71  * phases.
72  */
73  /**
74  * Sets the level of wanted information.
75  *
76  * @param level A comma separated list of levels which are
77  * wanted. Possible values: child, size, state
78  * and all.
79  */
80  static void set_level(const std::string& level);
81 
82  /**
83  * Sets the domain when to show the information.
84  *
85  * @param domain A comma separated list for domains which are
86  * wanted. Possible values: show, layout and all.
87  */
88  static void set_domain(const std::string& domain);
89 
90  /**
91  * Generates a dot file.
92  *
93  * The file will have a fixed prefix filename but for every file a part of
94  * the name will contain where it was generated.
95  *
96  * @param generator The location where the name was generated.
97  */
98  void generate_dot_file(const std::string& generator, const unsigned domain);
99 
100 private:
101  /** The window whose info will be shown. */
102  const twindow* window_;
103 
104  /** The order in which the files are generated. */
105  unsigned sequence_number_;
106 
107  /** Basic part of the filename. */
108  std::string filename_base_;
109 
110  /***** ***** Widget ***** *****/
111 
112  /**
113  * Generates the info about a widget.
114  *
115  * @param out The stream to write the info to.
116  * @param widget The widget to write the info about.
117  * @param id The dof-file-id of the widget.
118  * @param embedded Is the grid embedded in a container eg parent
119  * inherits from tcontainer_.
120  */
121  void widget_generate_info(std::ostream& out,
122  const twidget* widget,
123  const std::string& id,
124  const bool embedded = false) const;
125 
126  /**
127  * Generates the basic info about a widget.
128  *
129  * @param out The stream to write the info to.
130  * @param widget The widget to write the info about.
131  */
132  void widget_generate_basic_info(std::ostream& out,
133  const twidget* widget) const;
134 
135  /**
136  * Generates the info about the state of the widget.
137  *
138  * @param out The stream to write the info to.
139  * @param widget The widget to write the info about.
140  */
141  void widget_generate_state_info(std::ostream& out,
142  const twidget* widget) const;
143 
144  /**
145  * Generates the info about the size and layout of the widget.
146  *
147  * @param out The stream to write the info to.
148  * @param widget The widget to write the info about.
149  */
150  void widget_generate_size_info(std::ostream& out,
151  const twidget* widget) const;
152 
153  /***** ***** Grid ***** *****/
154 
155  /**
156  * Generates the info about a grid.
157  *
158  * @param out The stream to write the info to.
159  * @param grid The grid to write the info about.
160  * @param parent_id The dot-file-id of the parent of the widget.
161  */
162  void grid_generate_info(std::ostream& out,
163  const tgrid* grid,
164  const std::string& parent_id) const;
165 
166  /**
167  * Generates the info about a grid cell.
168  *
169  * @param out The stream to write the info to.
170  * @param child The grid cell to write the info about.
171  * @param id The dof-file-id of the child.
172  */
173  void child_generate_info(std::ostream& out,
174  const tgrid::tchild& child,
175  const std::string& id) const;
176 
177  /***** ***** Helper ***** *****/
178 
179  /**
180  * Returns the control_type of a widget.
181  *
182  * This is a small wrapper around tcontrol::get_control_type() since a
183  * grid is no control and used rather frequently, so we want to give it a
184  * type.
185  *
186  * @param widget The widget to get the type of.
187  *
188  * @returns If the widget is a control it returns its
189  * type. If the widget is a grid it returns
190  * 'grid', otherwise 'unknown' will be returned.
191  */
192  std::string get_type(const twidget* widget) const;
193 };
194 
195 } // namespace gui2
196 
197 #endif
198 #endif
GLint level
Definition: glew.h:1220
rng * generator
This generator is automatically synced during synced context.
Definition: random_new.cpp:52
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void set_level(const std::string &value)
GLsizei const GLcharARB ** string
Definition: glew.h:4503