Changeset - r15070:eb6f0a8e1d86
[Not reviewed]
master
0 5 0
rubidium - 14 years ago 2010-04-24 13:27:22
rubidium@openttd.org
(svn r19706) -Add: support for the (NewGRF) debug box
5 files changed with 72 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -227,12 +227,13 @@ STR_BUTTON_SORT_BY                      
 
STR_BUTTON_LOCATION                                             :{BLACK}Location
 
STR_BUTTON_RENAME                                               :{BLACK}Rename
 

	
 
STR_TOOLTIP_CLOSE_WINDOW                                        :{BLACK}Close window
 
STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS                              :{BLACK}Window title - drag this to move window
 
STR_TOOLTIP_SHADE                                               :{BLACK}Shade window - only show the title bar
 
STR_TOOLTIP_DEBUG                                               :{BLACK}Show NewGRF debug information
 
STR_TOOLTIP_STICKY                                              :{BLACK}Mark this window as uncloseable by the 'Close All Windows' key
 
STR_TOOLTIP_RESIZE                                              :{BLACK}Click and drag to resize this window
 
STR_TOOLTIP_TOGGLE_LARGE_SMALL_WINDOW                           :{BLACK}Toggle large/small window size
 
STR_TOOLTIP_VSCROLL_BAR_SCROLLS_LIST                            :{BLACK}Scroll bar - scrolls list up/down
 
STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST                            :{BLACK}Scroll bar - scrolls list left/right
 
STR_TOOLTIP_DEMOLISH_BUILDINGS_ETC                              :{BLACK}Demolish buildings etc. on a square of land
src/widget.cpp
Show inline comments
 
@@ -14,12 +14,13 @@
 
#include "window_gui.h"
 
#include "viewport_func.h"
 
#include "zoom_func.h"
 
#include "strings_func.h"
 
#include "transparency.h"
 
#include "core/geometry_func.hpp"
 
#include "settings_type.h"
 

	
 
#include "table/sprites.h"
 
#include "table/strings.h"
 

	
 
static const char *UPARROW   = "\xEE\x8A\xA0"; ///< String containing an upwards pointing arrow.
 
static const char *DOWNARROW = "\xEE\x8A\xAA"; ///< String containing a downwards pointing arrow.
 
@@ -474,12 +475,24 @@ static inline void DrawStickyBox(const R
 
{
 
	DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
 
	DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + WD_STICKYBOX_LEFT + clicked, r.top + WD_STICKYBOX_TOP + clicked);
 
}
 

	
 
/**
 
 * Draw a NewGRF debug box.
 
 * @param r       Rectangle of the box.
 
 * @param colour  Colour of the debug box.
 
 * @param clicked Box is lowered.
 
 */
 
static inline void DrawDebugBox(const Rect &r, Colours colour, bool clicked)
 
{
 
	DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
 
	DrawSprite(SPR_WINDOW_DEBUG, PAL_NONE, r.left + WD_DEBUGBOX_LEFT + clicked, r.top + WD_DEBUGBOX_TOP + clicked);
 
}
 

	
 
/**
 
 * Draw a resize box.
 
 * @param r       Rectangle of the box.
 
 * @param colour  Colour of the resize box.
 
 * @param at_left Resize box is at left-side of the window,
 
 * @param clicked Box is lowered.
 
 */
 
@@ -1687,18 +1700,20 @@ void NWidgetViewport::UpdateViewportCoor
 
}
 

	
 
/** Reset the cached dimensions. */
 
/* static */ void NWidgetLeaf::InvalidateDimensionCache()
 
{
 
	shadebox_dimension.width  = shadebox_dimension.height  = 0;
 
	debugbox_dimension.width  = debugbox_dimension.height  = 0;
 
	stickybox_dimension.width = stickybox_dimension.height = 0;
 
	resizebox_dimension.width = resizebox_dimension.height = 0;
 
	closebox_dimension.width  = closebox_dimension.height  = 0;
 
}
 

	
 
Dimension NWidgetLeaf::shadebox_dimension  = {0, 0};
 
Dimension NWidgetLeaf::debugbox_dimension  = {0, 0};
 
Dimension NWidgetLeaf::stickybox_dimension = {0, 0};
 
Dimension NWidgetLeaf::resizebox_dimension = {0, 0};
 
Dimension NWidgetLeaf::closebox_dimension  = {0, 0};
 

	
 
/**
 
 * Nested leaf widget.
 
@@ -1707,13 +1722,13 @@ Dimension NWidgetLeaf::closebox_dimensio
 
 * @param index  Index in the widget array used by the window system.
 
 * @param data   Data of the widget.
 
 * @param tip    Tooltip of the widget.
 
 */
 
NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip) : NWidgetCore(tp, colour, 1, 1, data, tip)
 
{
 
	assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX);
 
	assert(index >= 0 || tp == WWT_LABEL || tp == WWT_TEXT || tp == WWT_CAPTION || tp == WWT_RESIZEBOX || tp == WWT_SHADEBOX || tp == WWT_DEBUGBOX || tp == WWT_STICKYBOX || tp == WWT_CLOSEBOX);
 
	if (index >= 0) this->SetIndex(index);
 
	this->SetMinimalSize(0, 0);
 
	this->SetResize(0, 0);
 

	
 
	switch (tp) {
 
		case WWT_EMPTY:
 
@@ -1772,12 +1787,18 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, 
 
		case WWT_SHADEBOX:
 
			this->SetFill(0, 0);
 
			this->SetMinimalSize(WD_SHADEBOX_TOP, 14);
 
			this->SetDataTip(STR_NULL, STR_TOOLTIP_SHADE);
 
			break;
 

	
 
		case WWT_DEBUGBOX:
 
			this->SetFill(0, 0);
 
			this->SetMinimalSize(WD_DEBUGBOX_TOP, 14);
 
			this->SetDataTip(STR_NULL, STR_TOOLTIP_DEBUG);
 
			break;
 

	
 
		case WWT_RESIZEBOX:
 
			this->SetFill(0, 0);
 
			this->SetMinimalSize(WD_RESIZEBOX_WIDTH, 12);
 
			this->SetDataTip(STR_NULL, STR_TOOLTIP_RESIZE);
 
			break;
 

	
 
@@ -1831,12 +1852,30 @@ void NWidgetLeaf::SetupSmallestSize(Wind
 
				NWidgetLeaf::shadebox_dimension.width += extra.width;
 
				NWidgetLeaf::shadebox_dimension.height += extra.height;
 
			}
 
			size = maxdim(size, NWidgetLeaf::shadebox_dimension);
 
			break;
 
		}
 
		case WWT_DEBUGBOX:
 
			if (_settings_client.gui.newgrf_developer_tools && w->IsNewGRFInspectable()) {
 
				static const Dimension extra = {WD_DEBUGBOX_LEFT + WD_DEBUGBOX_RIGHT, WD_DEBUGBOX_TOP + WD_DEBUGBOX_BOTTOM};
 
				padding = &extra;
 
				if (NWidgetLeaf::debugbox_dimension.width == 0) {
 
					NWidgetLeaf::debugbox_dimension = GetSpriteSize(SPR_WINDOW_DEBUG);
 
					NWidgetLeaf::debugbox_dimension.width += extra.width;
 
					NWidgetLeaf::debugbox_dimension.height += extra.height;
 
				}
 
				size = maxdim(size, NWidgetLeaf::debugbox_dimension);
 
			} else {
 
				/* If the setting is disabled we don't want to see it! */
 
				size.width = 0;
 
				fill.width = 0;
 
				resize.width = 0;
 
			}
 
			break;
 

	
 
		case WWT_STICKYBOX: {
 
			static const Dimension extra = {WD_STICKYBOX_LEFT + WD_STICKYBOX_RIGHT, WD_STICKYBOX_TOP + WD_STICKYBOX_BOTTOM};
 
			padding = &extra;
 
			if (NWidgetLeaf::stickybox_dimension.width == 0) {
 
				NWidgetLeaf::stickybox_dimension = maxdim(GetSpriteSize(SPR_PIN_UP), GetSpriteSize(SPR_PIN_DOWN));
 
				NWidgetLeaf::stickybox_dimension.width += extra.width;
 
@@ -2047,12 +2086,16 @@ void NWidgetLeaf::Draw(const Window *w)
 

	
 
		case WWT_SHADEBOX:
 
			assert(this->widget_data == 0);
 
			DrawShadeBox(r, this->colour, w->IsShaded());
 
			break;
 

	
 
		case WWT_DEBUGBOX:
 
			DrawDebugBox(r, this->colour, clicked);
 
			break;
 

	
 
		case WWT_STICKYBOX:
 
			assert(this->widget_data == 0);
 
			DrawStickyBox(r, this->colour, !!(w->flags4 & WF_STICKY));
 
			break;
 

	
 
		case WWT_RESIZEBOX:
src/widget_type.h
Show inline comments
 
@@ -62,12 +62,13 @@ enum WidgetType {
 
	WWT_FRAME,      ///< Frame
 
	WWT_CAPTION,    ///< Window caption (window title between closebox and stickybox)
 

	
 
	WWT_HSCROLLBAR, ///< Horizontal scrollbar
 
	WWT_SHADEBOX,   ///< Shade box (at top-right of a window, between caption and stickybox)
 
	WWT_STICKYBOX,  ///< Sticky box (normally at top-right of a window)
 
	WWT_DEBUGBOX,   ///< NewGRF debug box (between shade box and caption)
 
	WWT_SCROLL2BAR, ///< 2nd vertical scrollbar
 
	WWT_RESIZEBOX,  ///< Resize box (normally at bottom-right of a window)
 
	WWT_CLOSEBOX,   ///< Close box (at top-left of a window)
 
	WWT_DROPDOWN,   ///< Drop down list
 
	WWT_EDITBOX,    ///< a textbox for typing
 
	WWT_LAST,       ///< Last Item. use WIDGETS_END to fill up padding!!
 
@@ -477,12 +478,13 @@ public:
 

	
 
	bool ButtonHit(const Point &pt);
 

	
 
	static void InvalidateDimensionCache();
 
private:
 
	static Dimension shadebox_dimension;  ///< Cached size of a shadebox widget.
 
	static Dimension debugbox_dimension;  ///< Cached size of a debugbox widget.
 
	static Dimension stickybox_dimension; ///< Cached size of a stickybox widget.
 
	static Dimension resizebox_dimension; ///< Cached size of a resizebox widget.
 
	static Dimension closebox_dimension;  ///< Cached size of a closebox widget.
 
};
 

	
 
/**
src/window.cpp
Show inline comments
 
@@ -343,12 +343,16 @@ static void DispatchLeftClickEvent(Windo
 
			/* When the resize widget is on the left size of the window
 
			 * we assume that that button is used to resize to the left. */
 
			StartWindowSizing(w, (int)nw->pos_x < (w->width / 2));
 
			nw->SetDirty(w);
 
			return;
 

	
 
		case WWT_DEBUGBOX:
 
			w->ShowNewGRFInspectWindow();
 
			break;
 

	
 
		case WWT_SHADEBOX:
 
			nw->SetDirty(w);
 
			w->SetShaded(!w->IsShaded());
 
			return;
 

	
 
		case WWT_STICKYBOX:
src/window_gui.h
Show inline comments
 
@@ -82,12 +82,19 @@ enum WidgetDrawDistances {
 
	WD_STICKYBOX_WIDTH  = 12,   ///< Width of a standard sticky box widget.
 
	WD_STICKYBOX_LEFT   = 2,    ///< Left offset of sticky sprite.
 
	WD_STICKYBOX_RIGHT  = 2,    ///< Right offset of sticky sprite.
 
	WD_STICKYBOX_TOP    = 3,    ///< Top offset of sticky sprite.
 
	WD_STICKYBOX_BOTTOM = 3,    ///< Bottom offset of sticky sprite.
 

	
 
	/* WWT_DEBUGBOX */
 
	WD_DEBUGBOX_WIDTH  = 12,    ///< Width of a standard debug box widget.
 
	WD_DEBUGBOX_LEFT   = 2,     ///< Left offset of debug sprite.
 
	WD_DEBUGBOX_RIGHT  = 2,     ///< Right offset of debug sprite.
 
	WD_DEBUGBOX_TOP    = 3,     ///< Top offset of debug sprite.
 
	WD_DEBUGBOX_BOTTOM = 3,     ///< Bottom offset of debug sprite.
 

	
 
	/* WWT_RESIZEBOX */
 
	WD_RESIZEBOX_WIDTH  = 12,   ///< Width of a resize box widget.
 
	WD_RESIZEBOX_LEFT   = 3,    ///< Left offset of resize sprite.
 
	WD_RESIZEBOX_RIGHT  = 2,    ///< Right offset of resize sprite.
 
	WD_RESIZEBOX_TOP    = 3,    ///< Top offset of resize sprite.
 
	WD_RESIZEBOX_BOTTOM = 2,    ///< Bottom offset of resize sprite.
 
@@ -767,12 +774,26 @@ public:
 
	 * @param pt   the exact point on the map where the mouse is.
 
	 * @param tile the tile on the map where the mouse is.
 
	 */
 
	virtual void OnPlacePresize(Point pt, TileIndex tile) {}
 

	
 
	/*** End of the event handling ***/
 

	
 
	/**
 
	 * Is the data related to this window NewGRF inspectable?
 
	 * @return true iff it is inspectable.
 
	 */
 
	virtual bool IsNewGRFInspectable() const { return false; }
 

	
 
	/**
 
	 * Show the NewGRF inspection window. When this function is called it is
 
	 * up to the window to call and pass the right parameters to the
 
	 * ShowInspectWindow function.
 
	 * @pre this->IsNewGRFInspectable()
 
	 */
 
	virtual void ShowNewGRFInspectWindow() const { NOT_REACHED(); }
 
};
 

	
 
/** Get the nested widget with number \a widnum from the nested widget tree.
 
 * @tparam NWID Type of the nested widget.
 
 * @param widnum Widget number of the widget to retrieve.
 
 * @return The requested widget if it is instantiated, \c NULL otherwise.
0 comments (0 inline, 0 general)