summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gfx.cpp3
-rw-r--r--src/widget.cpp75
-rw-r--r--src/widget_type.h6
-rw-r--r--src/window.cpp5
-rw-r--r--src/window_gui.h66
5 files changed, 115 insertions, 40 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 482427a72..58373d898 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -20,6 +20,7 @@
#include "network/network_func.h"
#include "core/smallvec_type.hpp"
#include "thread.h"
+#include "window_func.h"
#include "table/palettes.h"
#include "table/sprites.h"
@@ -1227,6 +1228,8 @@ void LoadStringWidthTable()
for (i = 0; i != 224; i++) {
_stringwidth_table[FS_LARGE][i] = GetGlyphWidth(FS_LARGE, i + 32);
}
+
+ ReInitAllWindows();
}
/**
diff --git a/src/widget.cpp b/src/widget.cpp
index 4f27a331c..027319e43 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -276,9 +276,16 @@ static inline void DrawImageButtons(const Rect &r, WidgetType type, Colours colo
assert(img != 0);
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
- /* show different image when clicked for WWT_IMGBTN_2 */
- if ((type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++;
- DrawSprite(img, PAL_NONE, r.left + WD_IMGBTN_LEFT + clicked, r.top + WD_IMGBTN_TOP + clicked);
+ int left, top;
+ if ((type & WWT_MASK) == WWT_IMGBTN_2) {
+ if (clicked) img++; // Show different image when clicked for #WWT_IMGBTN_2.
+ left = WD_IMGBTN2_LEFT;
+ top = WD_IMGBTN2_TOP;
+ } else {
+ left = WD_IMGBTN_LEFT;
+ top = WD_IMGBTN_TOP;
+ }
+ DrawSprite(img, PAL_NONE, r.left + left + clicked, r.top + top + clicked);
}
/**
@@ -488,7 +495,7 @@ static inline void DrawFrame(const Rect &r, Colours colour, StringID str)
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_STICKY_LEFT + clicked, r.top + WD_STICKY_TOP + clicked);
+ DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + WD_STICKYBOX_LEFT + clicked, r.top + WD_STICKYBOX_TOP + clicked);
}
/**
@@ -502,9 +509,9 @@ static inline void DrawResizeBox(const Rect &r, Colours colour, bool at_left, bo
{
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 + 2 + clicked, r.top + 3 + clicked);
+ DrawSprite(SPR_WINDOW_RESIZE_LEFT, PAL_NONE, r.left + WD_RESIZEBOX_RIGHT + clicked, r.top + WD_RESIZEBOX_TOP + clicked);
} else {
- DrawSprite(SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.left + 3 + clicked, r.top + WD_RESIZE_TOP + clicked);
+ DrawSprite(SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.left + WD_RESIZEBOX_LEFT + clicked, r.top + WD_RESIZEBOX_TOP + clicked);
}
}
@@ -518,7 +525,7 @@ static inline void DrawCloseBox(const Rect &r, Colours colour, StringID str)
{
assert(str == STR_BLACK_CROSS || str == STR_SILVER_CROSS); // black or silver cross
DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, FR_NONE);
- DrawString(r.left, r.right, r.top + WD_CLOSEBOX_TOP, str, TC_FROMSTRING, SA_CENTER);
+ DrawString(r.left + WD_CLOSEBOX_LEFT, r.right - WD_CLOSEBOX_RIGHT, r.top + WD_CLOSEBOX_TOP, str, TC_FROMSTRING, SA_CENTER);
}
/**
@@ -1819,6 +1826,18 @@ NWidgetBase *NWidgetBackground::GetWidgetOfType(WidgetType tp)
return nwid;
}
+/** Reset the cached dimensions. */
+/* static */ void NWidgetLeaf::InvalidateDimensionCache()
+{
+ stickybox_dimension.width = stickybox_dimension.height = 0;
+ resizebox_dimension.width = resizebox_dimension.height = 0;
+ closebox_dimension.width = closebox_dimension.height = 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.
@@ -1881,13 +1900,13 @@ NWidgetLeaf::NWidgetLeaf(WidgetType tp, Colours colour, int index, uint16 data,
case WWT_STICKYBOX:
this->SetFill(false, false);
- this->SetMinimalSize(WD_STICKY_WIDTH, 14);
+ this->SetMinimalSize(WD_STICKYBOX_WIDTH, 14);
this->SetDataTip(STR_NULL, STR_STICKY_BUTTON);
break;
case WWT_RESIZEBOX:
this->SetFill(false, false);
- this->SetMinimalSize(WD_RESIZE_WIDTH, 12);
+ this->SetMinimalSize(WD_RESIZEBOX_WIDTH, 12);
this->SetDataTip(STR_NULL, STR_RESIZE_BUTTON);
break;
@@ -1924,8 +1943,24 @@ int NWidgetLeaf::SetupSmallestSize(Window *w)
case WWT_SCROLLBAR:
case WWT_SCROLL2BAR:
case WWT_HSCROLLBAR:
+ break;
+
case WWT_STICKYBOX:
+ if (NWidgetLeaf::stickybox_dimension.width == 0) {
+ NWidgetLeaf::stickybox_dimension = maxdim(GetSpriteSize(SPR_PIN_UP), GetSpriteSize(SPR_PIN_DOWN));
+ NWidgetLeaf::stickybox_dimension.width += WD_STICKYBOX_LEFT + WD_STICKYBOX_RIGHT;
+ NWidgetLeaf::stickybox_dimension.height += WD_STICKYBOX_TOP + WD_STICKYBOX_BOTTOM;
+ }
+ d2 = maxdim(d2, NWidgetLeaf::stickybox_dimension);
+ break;
+
case WWT_RESIZEBOX:
+ if (NWidgetLeaf::resizebox_dimension.width == 0) {
+ NWidgetLeaf::resizebox_dimension = maxdim(GetSpriteSize(SPR_WINDOW_RESIZE_LEFT), GetSpriteSize(SPR_WINDOW_RESIZE_RIGHT));
+ NWidgetLeaf::resizebox_dimension.width += WD_RESIZEBOX_LEFT + WD_RESIZEBOX_RIGHT;
+ NWidgetLeaf::resizebox_dimension.height += WD_RESIZEBOX_TOP + WD_RESIZEBOX_BOTTOM;
+ }
+ d2 = maxdim(d2, NWidgetLeaf::resizebox_dimension);
break;
case WWT_PUSHBTN:
@@ -1936,15 +1971,25 @@ int NWidgetLeaf::SetupSmallestSize(Window *w)
case WWT_IMGBTN:
case WWT_PUSHIMGBTN:
+ d2 = maxdim(d2, GetSpriteSize(this->widget_data));
+ d2.height += WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM;
+ d2.width += WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
+ break;
+
case WWT_IMGBTN_2:
d2 = maxdim(d2, GetSpriteSize(this->widget_data));
- d2.height += WD_IMGBTN_TOP;
- d2.width += WD_IMGBTN_LEFT;
+ d2 = maxdim(d2, GetSpriteSize(this->widget_data + 1));
+ d2.height += WD_IMGBTN2_TOP + WD_IMGBTN2_BOTTOM;
+ d2.width += WD_IMGBTN2_LEFT + WD_IMGBTN2_RIGHT;
break;
case WWT_CLOSEBOX:
- d2 = maxdim(d2, GetStringBoundingBox(this->widget_data));
- d2.height += WD_CLOSEBOX_TOP;
+ if (NWidgetLeaf::closebox_dimension.width == 0) {
+ NWidgetLeaf::closebox_dimension = maxdim(GetStringBoundingBox(STR_BLACK_CROSS), GetStringBoundingBox(STR_SILVER_CROSS));
+ NWidgetLeaf::closebox_dimension.width += WD_CLOSEBOX_LEFT + WD_CLOSEBOX_RIGHT;
+ NWidgetLeaf::closebox_dimension.height += WD_CLOSEBOX_TOP + WD_CLOSEBOX_BOTTOM;
+ }
+ d2 = maxdim(d2, NWidgetLeaf::closebox_dimension);
break;
case WWT_TEXTBTN:
@@ -1963,13 +2008,13 @@ int NWidgetLeaf::SetupSmallestSize(Window *w)
case WWT_CAPTION:
d2 = maxdim(d2, GetStringBoundingBox(this->widget_data));
d2.width += WD_CAPTIONTEXT_LEFT + WD_CAPTIONTEXT_RIGHT;
- d2.height += WD_CAPTIONTEXT_TOP;
+ d2.height += WD_CAPTIONTEXT_TOP + WD_CAPTIONTEXT_BOTTOM;
break;
case WWT_DROPDOWN:
d2 = maxdim(d2, GetStringBoundingBox(this->widget_data));
d2.width += WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT;
- d2.height += WD_DROPDOWNTEXT_TOP;
+ d2.height += WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
break;
default:
diff --git a/src/widget_type.h b/src/widget_type.h
index 0e5fd42c4..3106dc8ae 100644
--- a/src/widget_type.h
+++ b/src/widget_type.h
@@ -477,6 +477,12 @@ public:
/* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
/* virtual */ NWidgetBase *GetWidgetOfType(WidgetType tp);
/* virtual */ Scrollbar *FindScrollbar(Window *w, bool allow_next = true);
+
+ static void InvalidateDimensionCache();
+private:
+ 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.
};
Widget *InitializeNWidgets(NWidgetBase *nwid, bool rtl = false);
diff --git a/src/window.cpp b/src/window.cpp
index 13bc7be1b..f46bf08da 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1337,6 +1337,8 @@ void InitWindowSystem()
_focused_window = NULL;
_mouseover_last_w = NULL;
_scrolling_viewport = 0;
+
+ NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
}
/**
@@ -2546,8 +2548,9 @@ void HideVitalWindows()
/** Re-initialize all windows. */
void ReInitAllWindows()
{
- Window *w;
+ NWidgetLeaf::InvalidateDimensionCache(); // Reset cached sizes of several widgets.
+ Window *w;
FOR_ALL_WINDOWS_FROM_BACK(w) {
w->ReInit();
}
diff --git a/src/window_gui.h b/src/window_gui.h
index 5962e8f79..522f366d9 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -29,57 +29,75 @@ DECLARE_ENUM_AS_BIT_SET(FrameFlags);
/** Distances used in drawing widgets. */
enum WidgetDrawDistances {
- /* WWT_IMGBTN, WWT_IMGBTN_2 */
- WD_IMGBTN_LEFT = 1, ///< Left offset of the image in the button.
- WD_IMGBTN_TOP = 1, ///< Top offset of image in the button.
+ /* WWT_IMGBTN */
+ WD_IMGBTN_LEFT = 1, ///< Left offset of the image in the button.
+ WD_IMGBTN_RIGHT = 2, ///< Right offset of the image in the button.
+ WD_IMGBTN_TOP = 1, ///< Top offset of image in the button.
+ WD_IMGBTN_BOTTOM = 2, ///< Bottom offset of image in the button.
+
+ /* WWT_IMGBTN_2 */
+ WD_IMGBTN2_LEFT = 1, ///< Left offset of the images in the button.
+ WD_IMGBTN2_RIGHT = 3, ///< Right offset of the images in the button.
+ WD_IMGBTN2_TOP = 1, ///< Top offset of images in the button.
+ WD_IMGBTN2_BOTTOM = 3, ///< Bottom offset of images in the button.
/* WWT_INSET */
WD_INSET_LEFT = 2, ///< Left offset of string.
WD_INSET_RIGHT = 2, ///< Right offset of string.
WD_INSET_TOP = 1, ///< Top offset of string.
- WD_VSCROLLBAR_WIDTH = 12, ///< Width of a vertical scrollbar.
+ WD_VSCROLLBAR_WIDTH = 12, ///< Width of a vertical scrollbar.
WD_HSCROLLBAR_HEIGHT = 12, ///< Height of a horizontal scrollbar.
/* FrameRect widgets, all text buttons, panel, editbox */
- WD_FRAMERECT_LEFT = 2, ///< Offset at left to draw the frame rectangular area
- WD_FRAMERECT_RIGHT = 2, ///< Offset at right to draw the frame rectangular area
- WD_FRAMERECT_TOP = 1, ///< Offset at top to draw the frame rectangular area
+ WD_FRAMERECT_LEFT = 2, ///< Offset at left to draw the frame rectangular area
+ WD_FRAMERECT_RIGHT = 2, ///< Offset at right to draw the frame rectangular area
+ WD_FRAMERECT_TOP = 1, ///< Offset at top to draw the frame rectangular area
WD_FRAMERECT_BOTTOM = 1, ///< Offset at bottom to draw the frame rectangular area
/* WWT_FRAME */
- WD_FRAMETEXT_LEFT = 6, ///< Left offset of the text of the frame.
+ WD_FRAMETEXT_LEFT = 6, ///< Left offset of the text of the frame.
WD_FRAMETEXT_RIGHT = 6, ///< Right offset of the text of the frame.
/* WWT_STICKYBOX */
- WD_STICKY_WIDTH = 12, ///< Width of a sticky box widget.
- WD_STICKY_LEFT = 2, ///< Left offset of sticky sprite.
- WD_STICKY_TOP = 3, ///< Top offset of sticky sprite.
+ 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 = 1, ///< Bottom offset of sticky sprite.
/* WWT_RESIZEBOX */
- WD_RESIZE_WIDTH = 12, ///< Width of a resize box widget.
- WD_RESIZE_TOP = 3, ///< Top offset of resize sprite.
+ 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 = 4, ///< Bottom offset of resize sprite.
/* WWT_CLOSEBOX */
- WD_CLOSEBOX_WIDTH = 11, ///< Width of a close box widget.
- WD_CLOSEBOX_TOP = 2, ///< Distance between the top of the close box widget, and the string.
+ 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.
+ WD_CLOSEBOX_BOTTOM = 2, ///< Bottom offset of closebox string.
/* WWT_CAPTION */
- WD_CAPTION_HEIGHT = 14, ///< Height of a title bar.
- WD_CAPTIONTEXT_LEFT = 2, ///< Offset of the caption text at the left.
- WD_CAPTIONTEXT_RIGHT = 2, ///< Offset of the caption text at the right.
- WD_CAPTIONTEXT_TOP = 2, ///< Offset of the caption text at the top.
+ WD_CAPTION_HEIGHT = 14, ///< Height of a title bar.
+ WD_CAPTIONTEXT_LEFT = 2, ///< Offset of the caption text at the left.
+ WD_CAPTIONTEXT_RIGHT = 2, ///< Offset of the caption text at the right.
+ WD_CAPTIONTEXT_TOP = 2, ///< Offset of the caption text at the top.
+ WD_CAPTIONTEXT_BOTTOM = 2, ///< Offset of the caption text at the bottom.
/* Dropdown widget. */
- WD_DROPDOWN_HEIGHT = 12, ///< Height of a drop down widget.
- WD_DROPDOWNTEXT_LEFT = 2, ///< Left offset of the dropdown widget string.
- WD_DROPDOWNTEXT_RIGHT = 14, ///< Right offset of the dropdown widget string.
- WD_DROPDOWNTEXT_TOP = 1, ///< Top offset of the dropdown widget string.
+ WD_DROPDOWN_HEIGHT = 12, ///< Height of a drop down widget.
+ WD_DROPDOWNTEXT_LEFT = 2, ///< Left offset of the dropdown widget string.
+ WD_DROPDOWNTEXT_RIGHT = 14, ///< Right offset of the dropdown widget string.
+ WD_DROPDOWNTEXT_TOP = 1, ///< Top offset of the dropdown widget string.
+ WD_DROPDOWNTEXT_BOTTOM = 1, ///< Bottom offset of the dropdown widget string.
WD_SORTBUTTON_ARROW_WIDTH = 11, ///< Width of up/down arrow of sort button state.
- WD_PAR_VSEP_NORMAL = 2, ///< Amount of vertical space between two paragraphs of text.
+ WD_PAR_VSEP_NORMAL = 2, ///< Amount of vertical space between two paragraphs of text.
};
/* wiget.cpp */