Make the debug layout domains working.

This commit is contained in:
Mark de Wever 2008-12-28 13:10:56 +00:00
parent 46280d9df0
commit e14a3b8fb7
4 changed files with 63 additions and 36 deletions

View File

@ -79,33 +79,23 @@ std::string get_base_filename()
return (formatter() << buf << '_' << counter << '_').c_str();
}
/***** ***** ***** ***** FLAGS ***** ***** ***** *****/
const unsigned ALL = UINT_MAX; /**< All levels/domains */
// level flags
const unsigned CHILD = 1 << 0; /**<
* Shows the child records of a cell.
*/
* Shows the child records of a cell.
*/
const unsigned SIZE_INFO = 1 << 1; /**<
* Shows the size info of
* children/widgets.
*/
const unsigned STATE_INFO = 1 << 2; /**< Shows the state info of widgets. */
// domain flags
const unsigned SHOW = 1 << 0; /**<
* Shows the info when the dialog is
* shown.
*/
const unsigned LAYOUT = 1 << 1; /**<
* Shows the info in all layout
* phases.
*/
unsigned level_ = ALL; /** @todo Should default to 0. */
unsigned domain_ = ALL; /** @todo Should default to 0. */
* Shows the size info of
* children/widgets.
*/
const unsigned STATE_INFO = 1 << 2; /**<
* Shows the state info of widgets.
*/
unsigned level_ = 0;
unsigned domain_ = 0;
} //namespace
tdebug_layout_graph::tdebug_layout_graph(const twindow* window)
@ -170,8 +160,14 @@ void tdebug_layout_graph::set_domain(const std::string& domain)
}
}
void tdebug_layout_graph::generate_dot_file(const std::string& generator)
void tdebug_layout_graph::generate_dot_file(
const std::string& generator, const unsigned domain)
{
// domain == 0 must also evaluate to true.
if((domain_ & domain) != domain) {
return;
}
const std::string filename = filename_base_ +
lexical_cast<std::string>(++sequence_number_) + "-" + generator + ".dot";
std::ofstream file(filename.c_str());

View File

@ -54,6 +54,22 @@ public:
*/
tdebug_layout_graph(const twindow* window);
/***** ***** ***** ***** FLAGS ***** ***** ***** *****/
// domain flags
static const unsigned MANUAL = 0 << 0; /**<
* Shows the info when the F12 is
* pressed. The value 0 makes sure
* the domain is always valid.
*/
static const unsigned SHOW = 1 << 0; /**<
* Shows the info when the dialog
* is shown.
*/
static const unsigned LAYOUT = 1 << 1; /**<
* Shows the info in all layout
* phases.
*/
/**
* Sets the level of wanted information.
*
@ -79,7 +95,8 @@ public:
*
* @param generator The location where the name was generated.
*/
void generate_dot_file(const std::string& generator);
void generate_dot_file(
const std::string& generator, const unsigned domain);
private:

View File

@ -33,6 +33,16 @@
namespace gui2{
namespace {
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
const unsigned MANUAL = tdebug_layout_graph::MANUAL;
const unsigned SHOW = tdebug_layout_graph::SHOW;
const unsigned LAYOUT = tdebug_layout_graph::LAYOUT;
#else
// values are irrelavant when DEBUG_WINDOW_LAYOUT_GRAPHS is not defined.
const unsigned MANUAL = 0;
const unsigned SHOW = 0;
const unsigned LAYOUT = 0;
#endif
/**
* The interval between draw events.
@ -199,7 +209,7 @@ int twindow::show(const bool restore, void* /*flip_function*/)
{
log_scope2(gui_draw, "Window: show.");
generate_dot_file("show");
generate_dot_file("show", SHOW);
assert(status_ == NEW);
@ -477,7 +487,8 @@ void twindow::key_press(tevent_handler& /*event_handler*/, bool& handled,
}
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
if(key == SDLK_F12) {
debug_layout_->generate_dot_file("manual");
debug_layout_->generate_dot_file(
"manual", tdebug_layout_graph::MANUAL);
handled = true;
}
#endif
@ -527,7 +538,7 @@ void twindow::layout()
log_scope2(gui_layout, "Window: Recalculate size");
layout_init();
generate_dot_file("layout_init");
generate_dot_file("layout_init", LAYOUT);
const game_logic::map_formula_callable variables =
get_screen_size_variables();
@ -539,7 +550,7 @@ void twindow::layout()
settings::screen_height : h_(variables);
tpoint size = get_best_size();
generate_dot_file("get_initial_best_size");
generate_dot_file("get_initial_best_size", LAYOUT);
DBG_G_L << "twindow " << __func__ << ": " << size << " maximum size "
<< maximum_width << ',' << maximum_height << ".\n";
@ -550,21 +561,21 @@ void twindow::layout()
if(size.x > maximum_width && can_wrap()) {
layout_wrap(maximum_width);
size = get_best_size();
generate_dot_file("wrapped");
generate_dot_file("wrapped", LAYOUT);
}
// *** scrollbar (leaves height untouched)
if(size.x > maximum_width && has_horizontal_scrollbar()) {
layout_use_horizontal_scrollbar(maximum_width);
size = get_best_size();
generate_dot_file("horizontal_scrollbar");
generate_dot_file("horizontal_scrollbar", LAYOUT);
}
// *** shrink (can change height)
if(size.x > maximum_width) {
layout_shrink_width(maximum_width);
size = get_best_size();
generate_dot_file("shrink_width");
generate_dot_file("shrink_width", LAYOUT);
}
// *** failed?
@ -581,14 +592,14 @@ void twindow::layout()
if(size.y > maximum_height && has_vertical_scrollbar()) {
layout_use_vertical_scrollbar(maximum_height);
size = get_best_size();
generate_dot_file("vertical_scrollbar");
generate_dot_file("vertical_scrollbar", LAYOUT);
}
// *** shrink (can change width)
if(size.y > maximum_height) {
layout_shrink_height(maximum_height);
size = get_best_size();
generate_dot_file("shrink_height");
generate_dot_file("shrink_height", LAYOUT);
}
// *** failed?
@ -642,7 +653,7 @@ void twindow::layout()
/***** Set the window size *****/
set_size(origin, size);
generate_dot_file("layout_finished");
generate_dot_file("layout_finished", LAYOUT);
need_layout_ = false;
}
@ -747,9 +758,10 @@ twindow::~twindow()
delete debug_layout_;
}
void twindow::generate_dot_file(const std::string& generator)
void twindow::generate_dot_file(const std::string& generator,
const unsigned domain)
{
debug_layout_->generate_dot_file(generator);
debug_layout_->generate_dot_file(generator, domain);
}
#endif
} // namespace gui2

View File

@ -422,9 +422,11 @@ public:
~twindow();
/** wrapper for tdebug_layout_graph::generate_dot_file. */
void generate_dot_file(const std::string& generator);
void generate_dot_file(
const std::string& generator, const unsigned domain);
#else
void generate_dot_file(const std::string&) {}
void generate_dot_file(const std::string&,
const unsigned) {}
#endif
};