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
 
@@ -221,24 +221,25 @@ STR_LIST_FILTER_TOOLTIP                 
 
STR_LIST_FILTER_TITLE                                           :{BLACK}Filter string:
 

	
 
STR_TOOLTIP_SORT_ORDER                                          :{BLACK}Select sorting order (descending/ascending)
 
STR_TOOLTIP_SORT_CRITERIA                                       :{BLACK}Select sorting criteria
 
STR_TOOLTIP_FILTER_CRITERIA                                     :{BLACK}Select filtering criteria
 
STR_BUTTON_SORT_BY                                              :{BLACK}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
 

	
 
# Query window
 
STR_BUTTON_DEFAULT                                              :{BLACK}Default
 
STR_BUTTON_CANCEL                                               :{BLACK}Cancel
 
STR_BUTTON_OK                                                   :{BLACK}OK
 

	
src/widget.cpp
Show inline comments
 
@@ -8,24 +8,25 @@
 
 */
 

	
 
/** @file widget.cpp Handling of the default/simple widgets. */
 

	
 
#include "stdafx.h"
 
#include "company_func.h"
 
#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.
 

	
 
/**
 
 * Compute the vertical position of the draggable part of scrollbar
 
 * @param sb     Scrollbar list data
 
 * @param top    Top position of the scrollbar (top position of the up-button)
 
 * @param bottom Bottom position of the scrollbar (bottom position of the down-button)
 
@@ -468,24 +469,36 @@ static inline void DrawShadeBox(const Re
 
 * Draw a sticky box.
 
 * @param r       Rectangle of the box.
 
 * @param colour  Colour of the sticky box.
 
 * @param clicked Box is lowered.
 
 */
 
static inline void DrawStickyBox(const Rect &r, Colours colour, bool clicked)
 
{
 
	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.
 
 */
 
static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bool clicked)
 
{
 
	DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
 
	if (at_left) {
 
		DrawSprite(SPR_WINDOW_RESIZE_LEFT, PAL_NONE, r.left + WD_RESIZEBOX_RIGHT + clicked, r.top + WD_RESIZEBOX_TOP + clicked);
 
	} else {
 
@@ -1681,45 +1694,47 @@ void NWidgetViewport::UpdateViewportCoor
 
		vp->width  = this->current_x;
 
		vp->height = this->current_y;
 

	
 
		vp->virtual_width  = ScaleByZoom(vp->width, vp->zoom);
 
		vp->virtual_height = ScaleByZoom(vp->height, vp->zoom);
 
	}
 
}
 

	
 
/** 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.
 
 * @param tp     Type of leaf widget.
 
 * @param colour Colour of the leaf widget.
 
 * @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:
 
			break;
 

	
 
		case WWT_PUSHBTN:
 
			this->SetFill(0, 0);
 
			break;
 

	
 
@@ -1766,24 +1781,30 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, 
 
		case WWT_STICKYBOX:
 
			this->SetFill(0, 0);
 
			this->SetMinimalSize(WD_STICKYBOX_WIDTH, 14);
 
			this->SetDataTip(STR_NULL, STR_TOOLTIP_STICKY);
 
			break;
 

	
 
		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;
 

	
 
		case WWT_CLOSEBOX:
 
			this->SetFill(0, 0);
 
			this->SetMinimalSize(WD_CLOSEBOX_WIDTH, 14);
 
			this->SetDataTip(STR_BLACK_CROSS, STR_TOOLTIP_CLOSE_WINDOW);
 
			break;
 

	
 
@@ -1825,24 +1846,42 @@ void NWidgetLeaf::SetupSmallestSize(Wind
 
		}
 
		case WWT_SHADEBOX: {
 
			static const Dimension extra = {WD_SHADEBOX_LEFT + WD_SHADEBOX_RIGHT, WD_SHADEBOX_TOP + WD_SHADEBOX_BOTTOM};
 
			padding = &extra;
 
			if (NWidgetLeaf::shadebox_dimension.width == 0) {
 
				NWidgetLeaf::shadebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_SHADE), GetSpriteSize(SPR_WINDOW_UNSHADE));
 
				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;
 
				NWidgetLeaf::stickybox_dimension.height += extra.height;
 
			}
 
			size = maxdim(size, NWidgetLeaf::stickybox_dimension);
 
			break;
 
		}
 
		case WWT_RESIZEBOX: {
 
@@ -2041,24 +2080,28 @@ void NWidgetLeaf::Draw(const Window *w)
 
		case WWT_HSCROLLBAR:
 
			assert(this->widget_data == 0);
 
			DrawHorizontalScrollbar(r, this->colour, (w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL),
 
								(w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL),
 
								(w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL), &w->hscroll);
 
			break;
 

	
 
		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:
 
			assert(this->widget_data == 0);
 
			DrawResizeBox(r, this->colour, this->pos_x < (uint)(w->width / 2), !!(w->flags4 & WF_SIZING));
 
			break;
 

	
 
		case WWT_CLOSEBOX:
 
			DrawCloseBox(r, this->colour, this->widget_data);
src/widget_type.h
Show inline comments
 
@@ -56,24 +56,25 @@ enum WidgetType {
 
	WWT_TEXTBTN,    ///< Button with text
 
	WWT_TEXTBTN_2,  ///< Button with diff text when clicked
 
	WWT_LABEL,      ///< Centered label
 
	WWT_TEXT,       ///< Pure simple text
 
	WWT_MATRIX,     ///< Grid of rows and columns. @see MatrixWidgetValues
 
	WWT_SCROLLBAR,  ///< Vertical scrollbar
 
	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!!
 

	
 
	/* Nested widget types. */
 
	NWID_HORIZONTAL,      ///< Horizontal container.
 
	NWID_HORIZONTAL_LTR,  ///< Horizontal container that doesn't change the order of the widgets for RTL languages.
 
	NWID_VERTICAL,        ///< Vertical container.
 
	NWID_SPACER,          ///< Invisible widget that takes some space.
 
@@ -471,24 +472,25 @@ class NWidgetLeaf : public NWidgetCore {
 
public:
 
	NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, StringID tip);
 

	
 
	/* virtual */ void SetupSmallestSize(Window *w, bool init_array);
 
	/* virtual */ void Draw(const Window *w);
 
	/* virtual */ Scrollbar *FindScrollbar(Window *w, bool allow_next = true) const;
 

	
 
	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.
 
};
 

	
 
/**
 
 * @defgroup NestedWidgetParts Hierarchical widget parts
 
 * To make nested widgets easier to enter, nested widget parts have been created. They allow the tree to be defined in a flat array of parts.
 
 *
 
 * - Leaf widgets start with a #NWidget(WidgetType tp, Colours col, int16 idx) part.
 
 *   Next, specify its properties with one or more of
 
 *   - #SetMinimalSize Define the minimal size of the widget.
src/window.cpp
Show inline comments
 
@@ -337,24 +337,28 @@ static void DispatchLeftClickEvent(Windo
 

	
 
		case WWT_CAPTION: // 'Title bar'
 
			StartWindowDrag(w);
 
			return;
 

	
 
		case WWT_RESIZEBOX:
 
			/* 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:
 
			w->flags4 ^= WF_STICKY;
 
			nw->SetDirty(w);
 
			return;
 

	
 
		default:
 
			break;
src/window_gui.h
Show inline comments
 
@@ -76,24 +76,31 @@ enum WidgetDrawDistances {
 
	WD_SHADEBOX_LEFT   = 2,     ///< Left offset of shade sprite.
 
	WD_SHADEBOX_RIGHT  = 2,     ///< Right offset of shade sprite.
 
	WD_SHADEBOX_TOP    = 3,     ///< Top offset of shade sprite.
 
	WD_SHADEBOX_BOTTOM = 3,     ///< Bottom offset of shade sprite.
 

	
 
	/* WWT_STICKYBOX */
 
	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.
 

	
 
	/* WWT_CLOSEBOX */
 
	WD_CLOSEBOX_WIDTH  = 11,    ///< Width of a close box widget.
 
	WD_CLOSEBOX_LEFT   = 2,     ///< Left offset of closebox string.
 
	WD_CLOSEBOX_RIGHT  = 1,     ///< Right offset of closebox string.
 
	WD_CLOSEBOX_TOP    = 2,     ///< Top offset of closebox string.
 
@@ -761,24 +768,38 @@ public:
 
	virtual void OnPlaceMouseUp(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile) {}
 

	
 
	/**
 
	 * The user moves over the map when a tile highlight mode has been set
 
	 * when the special mouse mode has been set to 'PRESIZE' mode. An
 
	 * example of this is the tile highlight for dock building.
 
	 * @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.
 
 */
 
template <class NWID>
 
inline NWID *Window::GetWidget(uint widnum)
 
{
 
	if (widnum >= this->nested_array_size || this->nested_array[widnum] == NULL) return NULL;
 
	NWID *nwid = dynamic_cast<NWID *>(this->nested_array[widnum]);
0 comments (0 inline, 0 general)