diff options
author | rubidium <rubidium@openttd.org> | 2010-04-24 13:27:22 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2010-04-24 13:27:22 +0000 |
commit | e75e2648fc5a9c741629ef1efc8a097c655ed035 (patch) | |
tree | 37af684212bbdd39ab92860c5e0adb3e68f9fb87 /src | |
parent | fef77ca53e2d3a381889aecc6739053f1582143b (diff) | |
download | openttd-e75e2648fc5a9c741629ef1efc8a097c655ed035.tar.xz |
(svn r19706) -Add: support for the (NewGRF) debug box
Diffstat (limited to 'src')
-rw-r--r-- | src/lang/english.txt | 1 | ||||
-rw-r--r-- | src/widget.cpp | 45 | ||||
-rw-r--r-- | src/widget_type.h | 2 | ||||
-rw-r--r-- | src/window.cpp | 4 | ||||
-rw-r--r-- | src/window_gui.h | 21 |
5 files changed, 72 insertions, 1 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt index fe1848229..09acfe907 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -230,6 +230,7 @@ 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 diff --git a/src/widget.cpp b/src/widget.cpp index de89bf263..377ef0667 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -17,6 +17,7 @@ #include "strings_func.h" #include "transparency.h" #include "core/geometry_func.hpp" +#include "settings_type.h" #include "table/sprites.h" #include "table/strings.h" @@ -477,6 +478,18 @@ static inline void DrawStickyBox(const Rect &r, Colours colour, bool 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. @@ -1690,12 +1703,14 @@ void NWidgetViewport::UpdateViewportCoordinates(Window *w) /* 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}; @@ -1710,7 +1725,7 @@ Dimension NWidgetLeaf::closebox_dimension = {0, 0}; */ 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); @@ -1775,6 +1790,12 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data, 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); @@ -1834,6 +1855,24 @@ void NWidgetLeaf::SetupSmallestSize(Window *w, bool init_array) 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; @@ -2050,6 +2089,10 @@ void NWidgetLeaf::Draw(const Window *w) 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)); diff --git a/src/widget_type.h b/src/widget_type.h index d73f2d428..4c9585eb2 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -65,6 +65,7 @@ enum WidgetType { 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) @@ -480,6 +481,7 @@ public: 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. diff --git a/src/window.cpp b/src/window.cpp index 78fbd1ac5..db8505ba1 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -346,6 +346,10 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, int click_count) nw->SetDirty(w); return; + case WWT_DEBUGBOX: + w->ShowNewGRFInspectWindow(); + break; + case WWT_SHADEBOX: nw->SetDirty(w); w->SetShaded(!w->IsShaded()); diff --git a/src/window_gui.h b/src/window_gui.h index 1a3bb217b..147811271 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -85,6 +85,13 @@ enum WidgetDrawDistances { 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. @@ -770,6 +777,20 @@ public: 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. |