(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
authorsmatz
Sun, 17 Feb 2008 17:00:43 +0000
changeset 9082 8217cb013e23
parent 9081 4c47047836f3
child 9083 b242adf8191b
(svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
src/gfx_func.h
src/rail_gui.cpp
src/road_gui.cpp
src/video/cocoa/event.mm
src/video/sdl_v.cpp
src/video/win32_v.cpp
src/window.cpp
src/window_gui.h
--- a/src/gfx_func.h	Sun Feb 17 12:21:05 2008 +0000
+++ b/src/gfx_func.h	Sun Feb 17 17:00:43 2008 +0000
@@ -65,6 +65,7 @@
 extern Colour _cur_palette[256];
 
 void HandleKeypress(uint32 key);
+void HandleCtrlChanged();
 void HandleMouseEvents();
 void CSleep(int milliseconds);
 void UpdateWindows();
--- a/src/rail_gui.cpp	Sun Feb 17 12:21:05 2008 +0000
+++ b/src/rail_gui.cpp	Sun Feb 17 17:00:43 2008 +0000
@@ -76,7 +76,7 @@
 static void GenericPlaceRail(TileIndex tile, int cmd)
 {
 	DoCommandP(tile, _cur_railtype, cmd, CcPlaySound1E,
-		(_remove_button_clicked || _ctrl_pressed) ?
+		_remove_button_clicked ?
 		CMD_REMOVE_SINGLE_RAIL | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) | CMD_NO_WATER :
 		CMD_BUILD_SINGLE_RAIL | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK) | CMD_NO_WATER
 	);
@@ -277,6 +277,43 @@
 	RTW_CONVERT_RAIL,
 };
 
+
+/** Toogles state of the Remove button of Build rail toolbar
+ * @param w window the button belongs to
+ */
+static void ToggleRailButton_Remove(Window *w)
+{
+	w->ToggleWidgetLoweredState(RTW_REMOVE);
+	w->InvalidateWidget(RTW_REMOVE);
+	_remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
+	SetSelectionRed(_remove_button_clicked);
+
+	// handle station builder
+	if (_remove_button_clicked) {
+		SetTileSelectSize(1, 1);
+	}
+}
+
+/** Updates the Remove button because of Ctrl state change
+ * @param w window the button belongs to
+ * @return true iff the remove buton was changed
+ */
+static bool RailToolbar_CtrlChanged(Window *w)
+{
+	if (w->IsWidgetDisabled(RTW_REMOVE)) return false;
+
+	/* allow ctrl to switch remove mode only for these widgets */
+	for (uint i = RTW_BUILD_NS; i <= RTW_BUILD_WAYPOINT; i++) {
+		if ((i <= RTW_AUTORAIL || i == RTW_BUILD_WAYPOINT) && w->IsWidgetLowered(i)) {
+			ToggleRailButton_Remove(w);
+			return true;
+		}
+	}
+
+	return false;
+}
+
+
 static void BuildRailClick_N(Window *w)
 {
 	HandlePlacePushButton(w, RTW_BUILD_NS, GetRailTypeInfo(_cur_railtype)->cursor.rail_ns, VHM_RECT, PlaceRail_N);
@@ -351,17 +388,8 @@
 static void BuildRailClick_Remove(Window *w)
 {
 	if (w->IsWidgetDisabled(RTW_REMOVE)) return;
-	SetWindowDirty(w);
+	ToggleRailButton_Remove(w);
 	SndPlayFx(SND_15_BEEP);
-
-	w->ToggleWidgetLoweredState(RTW_REMOVE);
-	_remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
-	SetSelectionRed(_remove_button_clicked);
-
-	// handle station builder
-	if (_remove_button_clicked) {
-		SetTileSelectSize(1, 1);
-	}
 }
 
 static void BuildRailClick_Convert(Window *w)
@@ -373,7 +401,7 @@
 static void DoRailroadTrack(int mode)
 {
 	DoCommandP(TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y), _cur_railtype | (mode << 4), NULL,
-		(_remove_button_clicked || _ctrl_pressed) ?
+		_remove_button_clicked ?
 		CMD_REMOVE_RAILROAD_TRACK | CMD_NO_WATER | CMD_MSG(STR_1012_CAN_T_REMOVE_RAILROAD_TRACK) :
 		CMD_BUILD_RAILROAD_TRACK  | CMD_NO_WATER | CMD_MSG(STR_1011_CAN_T_BUILD_RAILROAD_TRACK)
 	);
@@ -514,6 +542,7 @@
 			_build_railroad_button_proc[e->we.click.widget - RTW_BUILD_NS](w);
 		}
 		UpdateRemoveWidgetStatus(w, e->we.click.widget);
+		if (_ctrl_pressed) RailToolbar_CtrlChanged(w);
 		break;
 
 	case WE_KEYPRESS:
@@ -523,6 +552,7 @@
 				_remove_button_clicked = false;
 				_build_railroad_button_proc[i](w);
 				UpdateRemoveWidgetStatus(w, i + RTW_BUILD_NS);
+				if (_ctrl_pressed) RailToolbar_CtrlChanged(w);
 				break;
 			}
 		}
@@ -607,6 +637,10 @@
 	case WE_DESTROY:
 		if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
 		break;
+
+	case WE_CTRL_CHANGED:
+		if (RailToolbar_CtrlChanged(w)) e->we.ctrl.cont = false;
+		break;
 	}
 }
 
--- a/src/road_gui.cpp	Sun Feb 17 12:21:05 2008 +0000
+++ b/src/road_gui.cpp	Sun Feb 17 17:00:43 2008 +0000
@@ -255,6 +255,38 @@
 
 typedef void OnButtonClick(Window *w);
 
+
+/** Toogles state of the Remove button of Build road toolbar
+ * @param w window the button belongs to
+ */
+static void ToggleRoadButton_Remove(Window *w)
+{
+	w->ToggleWidgetLoweredState(RTW_REMOVE);
+	w->InvalidateWidget(RTW_REMOVE);
+	_remove_button_clicked = w->IsWidgetLowered(RTW_REMOVE);
+	SetSelectionRed(_remove_button_clicked);
+}
+
+/** Updates the Remove button because of Ctrl state change
+ * @param w window the button belongs to
+ * @return true iff the remove buton was changed
+ */
+static bool RoadToolbar_CtrlChanged(Window *w)
+{
+	if (w->IsWidgetDisabled(RTW_REMOVE)) return false;
+
+	/* allow ctrl to switch remove mode only for these widgets */
+	for (uint i = RTW_ROAD_X; i <= RTW_AUTOROAD; i++) {
+		if (w->IsWidgetLowered(i)) {
+			ToggleRoadButton_Remove(w);
+			return true;
+		}
+	}
+
+	return false;
+}
+
+
 /**
  * Function that handles the click on the
  *  X road placement button.
@@ -338,10 +370,8 @@
 static void BuildRoadClick_Remove(Window *w)
 {
 	if (w->IsWidgetDisabled(RTW_REMOVE)) return;
-	SetWindowDirty(w);
+	ToggleRoadButton_Remove(w);
 	SndPlayFx(SND_15_BEEP);
-	w->ToggleWidgetLoweredState(RTW_REMOVE);
-	SetSelectionRed(w->IsWidgetLowered(RTW_REMOVE));
 }
 
 /** Array with the handlers of the button-clicks for the road-toolbar */
@@ -446,6 +476,7 @@
 			_build_road_button_proc[e->we.click.widget - RTW_ROAD_X](w);
 		}
 		UpdateOptionWidgetStatus(w, e->we.click.widget);
+		if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
 		break;
 
 	case WE_KEYPRESS:
@@ -456,6 +487,7 @@
 				_one_way_button_clicked = false;
 				_build_road_button_proc[i](w);
 				UpdateOptionWidgetStatus(w, i + RTW_ROAD_X);
+				if (_ctrl_pressed) RoadToolbar_CtrlChanged(w);
 				break;
 			}
 		}
@@ -568,6 +600,10 @@
 	case WE_DESTROY:
 		if (_patches.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0);
 		break;
+
+	case WE_CTRL_CHANGED:
+		if (RoadToolbar_CtrlChanged(w)) e->we.ctrl.cont = false;
+		break;
 	}
 }
 
--- a/src/video/cocoa/event.mm	Sun Feb 17 12:21:05 2008 +0000
+++ b/src/video/cocoa/event.mm	Sun Feb 17 17:00:43 2008 +0000
@@ -668,9 +668,13 @@
 			last_cur_ticks = cur_ticks;
 			next_tick = cur_ticks + 30;
 
+			bool old_ctrl_pressed = _ctrl_pressed;
+
 			_ctrl_pressed = !!(_current_mods & ( _patches.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask));
 			_shift_pressed = !!(_current_mods & NSShiftKeyMask);
 
+			if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
+
 			GameLoop();
 
 			_screen.dst_ptr = _cocoa_subdriver->GetPixelBuffer();
--- a/src/video/sdl_v.cpp	Sun Feb 17 12:21:05 2008 +0000
+++ b/src/video/sdl_v.cpp	Sun Feb 17 17:00:43 2008 +0000
@@ -490,6 +490,8 @@
 			last_cur_ticks = cur_ticks;
 			next_tick = cur_ticks + 30;
 
+			bool old_ctrl_pressed = _ctrl_pressed;
+
 			_ctrl_pressed  = !!(mod & KMOD_CTRL);
 			_shift_pressed = !!(mod & KMOD_SHIFT);
 
@@ -499,6 +501,9 @@
 				(keys[SDLK_UP]    ? 2 : 0) |
 				(keys[SDLK_RIGHT] ? 4 : 0) |
 				(keys[SDLK_DOWN]  ? 8 : 0);
+
+			if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
+
 			GameLoop();
 
 			_screen.dst_ptr = _sdl_screen->pixels;
--- a/src/video/win32_v.cpp	Sun Feb 17 12:21:05 2008 +0000
+++ b/src/video/win32_v.cpp	Sun Feb 17 17:00:43 2008 +0000
@@ -856,6 +856,9 @@
 			_realtime_tick += cur_ticks - last_cur_ticks;
 			last_cur_ticks = cur_ticks;
 			next_tick = cur_ticks + 30;
+
+			bool old_ctrl_pressed = _ctrl_pressed;
+
 			_ctrl_pressed = _wnd.has_focus && GetAsyncKeyState(VK_CONTROL)<0;
 			_shift_pressed = _wnd.has_focus && GetAsyncKeyState(VK_SHIFT)<0;
 
@@ -870,6 +873,8 @@
 				_dirkeys = 0;
 			}
 
+			if (old_ctrl_pressed != _ctrl_pressed) HandleCtrlChanged();
+
 			GameLoop();
 			_cursor.delta.x = _cursor.delta.y = 0;
 
--- a/src/window.cpp	Sun Feb 17 12:21:05 2008 +0000
+++ b/src/window.cpp	Sun Feb 17 17:00:43 2008 +0000
@@ -1709,6 +1709,21 @@
 	}
 }
 
+void HandleCtrlChanged()
+{
+	WindowEvent e;
+
+	e.event = WE_CTRL_CHANGED;
+	e.we.ctrl.cont = true;
+
+	/* Call the event, start with the uppermost window. */
+	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
+		Window *w = *--wz;
+		w->wndproc(w, &e);
+		if (!e.we.ctrl.cont) break;
+	}
+}
+
 extern void UpdateTileSelection();
 extern bool VpHandlePlaceSizingDrag();
 
--- a/src/window_gui.h	Sun Feb 17 12:21:05 2008 +0000
+++ b/src/window_gui.h	Sun Feb 17 17:00:43 2008 +0000
@@ -123,6 +123,7 @@
 	WE_MESSAGE,
 	WE_SCROLL,
 	WE_INVALIDATE_DATA,
+	WE_CTRL_CHANGED,
 };
 
 struct WindowEvent {
@@ -192,6 +193,10 @@
 		struct {
 			int wheel;     ///< how much was 'wheel'd'
 		} wheel;
+
+		struct {
+			bool cont;     ///< continue the search? (default true)
+		} ctrl;
 	} we;
 };