Add a debug background colour feature for widgets.
This feature allows a widget's background area to be coloured so it's directly visible which area a widget occupies. This feature is meant for debugging only and not available for LOW_MEM builds.
This commit is contained in:
parent
b7e508d616
commit
5dd0ff3299
6 changed files with 89 additions and 1 deletions
|
@ -41,6 +41,7 @@ Version 1.7.2+svn:
|
|||
* wmllint updated to accomodate new drake names. Gladiator changes must
|
||||
still be done by hand.
|
||||
* No longer "crash" upon invalid pango markup
|
||||
* It's now possible to display the area a widget uses, for debug purposes
|
||||
|
||||
Version 1.7.2:
|
||||
* Campaigns:
|
||||
|
|
|
@ -34,6 +34,10 @@ tbuilder_control::tbuilder_control(const config& cfg) :
|
|||
help(cfg["help"]),
|
||||
use_tooltip_on_label_overflow(
|
||||
utils::string_bool("use_tooltip_on_label_overflow", true))
|
||||
#ifndef LOW_MEM
|
||||
, debug_border_mode(lexical_cast_default<int>(cfg["debug_border_mode"]))
|
||||
, debug_border_colour(decode_colour(cfg["debug_border_colour"]))
|
||||
#endif
|
||||
{
|
||||
if(definition.empty()) {
|
||||
definition = "default";
|
||||
|
@ -55,6 +59,10 @@ void tbuilder_control::init_control(tcontrol* control) const
|
|||
control->set_tooltip(tooltip);
|
||||
control->set_help_message(help);
|
||||
control->set_use_tooltip_on_label_overflow(use_tooltip_on_label_overflow);
|
||||
#ifndef LOW_MEM
|
||||
control->set_debug_border_mode(debug_border_mode);
|
||||
control->set_debug_border_colour(debug_border_colour);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
|
@ -114,7 +122,18 @@ void tbuilder_control::init_control(tcontrol* control) const
|
|||
* set to true this will happen.
|
||||
*
|
||||
* linked_group (string = "") The linked group the widget belongs to.
|
||||
* @end_table
|
||||
*
|
||||
* debug_border_mode (unsigned = 0) The mode for showing the debug border.
|
||||
* This border shows the area reserved for
|
||||
* a widget. This function is only meant
|
||||
* for debugging and might not be
|
||||
* available in all wesnoth binaries.
|
||||
* Available modes:
|
||||
* @* 0 no border.
|
||||
* @* 1 1 pixel border.
|
||||
* @* 2 floodfill the widget area.
|
||||
*
|
||||
* debug_border_colour (colour = "") The colour of the debug border.
|
||||
* @end_table
|
||||
*/
|
||||
|
||||
|
|
|
@ -41,6 +41,10 @@ public:
|
|||
t_string tooltip;
|
||||
t_string help;
|
||||
bool use_tooltip_on_label_overflow;
|
||||
#ifndef LOW_MEM
|
||||
int debug_border_mode;
|
||||
unsigned debug_border_colour;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace implementation
|
||||
|
|
|
@ -43,6 +43,7 @@ tcontrol::tcontrol(const unsigned canvas_count)
|
|||
void tcontrol::set_members(const string_map& data)
|
||||
{
|
||||
/** @todo document this feature on the wiki. */
|
||||
/** @todo do we need to add the debug colours here as well? */
|
||||
string_map::const_iterator itor = data.find("id");
|
||||
if(itor != data.end()) {
|
||||
set_id(itor->second);
|
||||
|
|
|
@ -33,6 +33,10 @@ twidget::twidget()
|
|||
, clip_rect_()
|
||||
, layout_size_(tpoint(0,0))
|
||||
, linked_group_()
|
||||
#ifndef LOW_MEM
|
||||
, debug_border_mode_(0)
|
||||
, debug_border_colour_(0)
|
||||
#endif
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
, last_best_size_(tpoint(0,0))
|
||||
#endif
|
||||
|
@ -241,8 +245,10 @@ void twidget::draw_background(surface& frame_buffer)
|
|||
|
||||
if(drawing_action_ == PARTLY_DRAWN) {
|
||||
clip_rect_setter clip(frame_buffer, clip_rect_);
|
||||
draw_debug_border(frame_buffer);
|
||||
impl_draw_background(frame_buffer);
|
||||
} else {
|
||||
draw_debug_border(frame_buffer);
|
||||
impl_draw_background(frame_buffer);
|
||||
}
|
||||
}
|
||||
|
@ -271,4 +277,27 @@ void twidget::draw_foreground(surface& frame_buffer)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef LOW_MEM
|
||||
void twidget::draw_debug_border(surface& frame_buffer)
|
||||
{
|
||||
SDL_Rect r = drawing_action_ == PARTLY_DRAWN
|
||||
? clip_rect_
|
||||
: get_rect();
|
||||
switch(debug_border_mode_) {
|
||||
case 0:
|
||||
/* DO NOTHING */
|
||||
break;
|
||||
case 1:
|
||||
draw_rectangle(r.x, r.y, r.w, r.h
|
||||
, debug_border_colour_, frame_buffer);
|
||||
break;
|
||||
case 2:
|
||||
SDL_FillRect(frame_buffer, &r, debug_border_colour_);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace gui2
|
||||
|
|
|
@ -447,6 +447,18 @@ public:
|
|||
/** Returns the dirty state for a widget, final function. */
|
||||
bool get_dirty() const { return dirty_; }
|
||||
|
||||
#ifndef LOW_MEM
|
||||
void set_debug_border_mode(const unsigned debug_border_mode)
|
||||
{
|
||||
debug_border_mode_ = debug_border_mode;
|
||||
}
|
||||
|
||||
void set_debug_border_colour(const unsigned debug_border_colour)
|
||||
{
|
||||
debug_border_colour_ = debug_border_colour;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Draws the background of a widget.
|
||||
*
|
||||
|
@ -601,6 +613,28 @@ private:
|
|||
*/
|
||||
std::string linked_group_;
|
||||
|
||||
#ifndef LOW_MEM
|
||||
/**
|
||||
* Mode for drawing the debug border.
|
||||
*
|
||||
* The debug border is a helper border to determine where a widget is
|
||||
* placed. It's only intended for debugging purposes.
|
||||
*
|
||||
* Possible values:
|
||||
* - 0 no border
|
||||
* - 1 single pixel border
|
||||
* - 2 floodfilled rectangle
|
||||
*/
|
||||
unsigned debug_border_mode_;
|
||||
|
||||
/** The color for the debug border. */
|
||||
unsigned debug_border_colour_;
|
||||
|
||||
void draw_debug_border(surface& frame_buffer);
|
||||
#else
|
||||
void draw_debug_border(surface&) {}
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_WINDOW_LAYOUT_GRAPHS
|
||||
/**
|
||||
* Debug helper to store last value of get_best_size().
|
||||
|
|
Loading…
Add table
Reference in a new issue