summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/table/sprites.h5
-rw-r--r--src/widget.cpp6
-rw-r--r--src/window.cpp46
-rw-r--r--src/window_gui.h16
4 files changed, 48 insertions, 25 deletions
diff --git a/src/table/sprites.h b/src/table/sprites.h
index 5c14d88ba..c9ca6c98d 100644
--- a/src/table/sprites.h
+++ b/src/table/sprites.h
@@ -49,7 +49,7 @@ enum Sprites {
/* Extra graphic spritenumbers */
SPR_OPENTTD_BASE = 4896,
- OPENTTD_SPRITE_COUNT = 149,
+ OPENTTD_SPRITE_COUNT = 150,
/* Halftile-selection sprites */
SPR_HALFTILE_SELECTION_FLAT = SPR_OPENTTD_BASE,
@@ -62,7 +62,8 @@ enum Sprites {
SPR_BOX_EMPTY = SPR_OPENTTD_BASE + 41,
SPR_BOX_CHECKED = SPR_OPENTTD_BASE + 42,
SPR_WARNING_SIGN = SPR_OPENTTD_BASE + 43, // warning sign (shown if there are any newgrf errors)
- SPR_WINDOW_RESIZE = SPR_OPENTTD_BASE + 44, // resize icon
+ SPR_WINDOW_RESIZE_RIGHT= SPR_OPENTTD_BASE + 44, // resize icon to the right
+ SPR_WINDOW_RESIZE_LEFT = SPR_OPENTTD_BASE + 149, // resize icon to the left
/* Arrow icons pointing in all 4 directions */
SPR_ARROW_DOWN = SPR_OPENTTD_BASE + 45,
SPR_ARROW_UP = SPR_OPENTTD_BASE + 46,
diff --git a/src/widget.cpp b/src/widget.cpp
index ce4f4f160..2643eb9e3 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -451,7 +451,11 @@ void Window::DrawWidgets() const
clicked = !!(this->flags4 & WF_SIZING);
DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE);
- DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked);
+ if (wi->left < (this->width / 2)) {
+ DrawSprite(SPR_WINDOW_RESIZE_LEFT, PAL_NONE, r.left + 2, r.top + 3 + clicked);
+ } else {
+ DrawSprite(SPR_WINDOW_RESIZE_RIGHT, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked);
+ }
break;
case WWT_CLOSEBOX: {
diff --git a/src/window.cpp b/src/window.cpp
index b73c4a6ba..ad8bbc889 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -228,7 +228,7 @@ bool Window::HasWidgetOfType(WidgetType widget_type) const
}
static void StartWindowDrag(Window *w);
-static void StartWindowSizing(Window *w);
+static void StartWindowSizing(Window *w, bool to_left);
/**
* Dispatch left mouse-button (possibly double) click in window.
@@ -322,7 +322,9 @@ static void DispatchLeftClickEvent(Window *w, int x, int y, bool double_click)
}
if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) {
- StartWindowSizing(w);
+ /* 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, wi->left < (w->width / 2));
w->InvalidateWidget(widget);
return;
}
@@ -1511,8 +1513,6 @@ static bool HandleWindowDragging()
w->SetDirty();
return false;
} else if (w->flags4 & WF_SIZING) {
- int x, y;
-
/* Stop the sizing if the left mouse button was released */
if (!_left_button_down) {
w->flags4 &= ~WF_SIZING;
@@ -1520,8 +1520,15 @@ static bool HandleWindowDragging()
break;
}
- x = _cursor.pos.x - _drag_delta.x;
- y = _cursor.pos.y - _drag_delta.y;
+ /* Compute difference in pixels between cursor position and reference point in the window.
+ * If resizing the left edge of the window, moving to the left makes the window bigger not smaller.
+ */
+ int x, y = _cursor.pos.y - _drag_delta.y;
+ if (w->flags4 & WF_SIZING_LEFT) {
+ x = _drag_delta.x - _cursor.pos.x;
+ } else {
+ x = _cursor.pos.x - _drag_delta.x;
+ }
/* X and Y has to go by step.. calculate it.
* The cast to int is necessary else x/y are implicitly casted to
@@ -1531,18 +1538,26 @@ static bool HandleWindowDragging()
if (w->resize.step_height > 1) y -= y % (int)w->resize.step_height;
/* Check if we don't go below the minimum set size */
- if ((int)w->width + x < (int)w->resize.width)
+ if ((int)w->width + x < (int)w->resize.width) {
x = w->resize.width - w->width;
- if ((int)w->height + y < (int)w->resize.height)
+ }
+ if ((int)w->height + y < (int)w->resize.height) {
y = w->resize.height - w->height;
+ }
/* Window already on size */
if (x == 0 && y == 0) return false;
- /* Now find the new cursor pos.. this is NOT _cursor, because
- we move in steps. */
- _drag_delta.x += x;
+ /* Now find the new cursor pos.. this is NOT _cursor, because we move in steps. */
_drag_delta.y += y;
+ if (w->flags4 & WF_SIZING_LEFT && x != 0) {
+ _drag_delta.x -= x; // x > 0 -> window gets longer -> left-edge moves to left -> subtract x to get new position.
+ w->SetDirty();
+ w->left -= x; // If dragging left edge, move left window edge in opposite direction by the same amount.
+ /* ResizeWindow() below ensures marking new position as dirty. */
+ } else {
+ _drag_delta.x += x;
+ }
/* ResizeWindow sets both pre- and after-size to dirty for redrawal */
ResizeWindow(w, x, y);
@@ -1579,12 +1594,13 @@ static void StartWindowDrag(Window *w)
}
/**
- * Start resizing a window
- * @param w Window to start resizing
+ * Start resizing a window.
+ * @param w Window to start resizing.
+ * @param to_left Whether to drag towards the left or not
*/
-static void StartWindowSizing(Window *w)
+static void StartWindowSizing(Window *w, bool to_left)
{
- w->flags4 |= WF_SIZING;
+ w->flags4 |= to_left ? WF_SIZING_LEFT : WF_SIZING_RIGHT;
_dragging_window = true;
_drag_delta.x = _cursor.pos.x;
diff --git a/src/window_gui.h b/src/window_gui.h
index bfcb33cba..f873eb94a 100644
--- a/src/window_gui.h
+++ b/src/window_gui.h
@@ -587,15 +587,17 @@ enum WindowFlags {
WF_SCROLL_UP = 1 << 4, ///< Upper scroll button has been pressed, @see ScrollbarClickHandler()
WF_SCROLL_DOWN = 1 << 5, ///< Lower scroll button has been pressed, @see ScrollbarClickHandler()
WF_SCROLL_MIDDLE = 1 << 6, ///< Scrollbar scrolling, @see ScrollbarClickHandler()
- WF_HSCROLL = 1 << 7,
- WF_SIZING = 1 << 8, ///< Window is being resized.
- WF_STICKY = 1 << 9, ///< Window is made sticky by user
+ WF_SCROLL2 = 1 << 7,
+ WF_HSCROLL = 1 << 8,
+ WF_SIZING_RIGHT = 1 << 9, ///< Window is being resized towards the right.
+ WF_SIZING_LEFT = 1 << 10, ///< Window is being resized towards the left.
+ WF_SIZING = WF_SIZING_RIGHT | WF_SIZING_LEFT, ///< Window is being resized.
+ WF_STICKY = 1 << 11, ///< Window is made sticky by user
- WF_DISABLE_VP_SCROLL = 1 << 10, ///< Window does not do autoscroll, @see HandleAutoscroll()
+ WF_DISABLE_VP_SCROLL = 1 << 12, ///< Window does not do autoscroll, @see HandleAutoscroll()
- WF_WHITE_BORDER_ONE = 1 << 11,
- WF_WHITE_BORDER_MASK = 1 << 12 | WF_WHITE_BORDER_ONE,
- WF_SCROLL2 = 1 << 13,
+ WF_WHITE_BORDER_ONE = 1 << 13,
+ WF_WHITE_BORDER_MASK = 1 << 14 | WF_WHITE_BORDER_ONE,
};
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number);