Allow scrolling when selecting destination station or building single-tile objects

This commit is contained in:
pelya
2014-11-16 03:38:40 +02:00
parent 3b50884ffc
commit 334856619a
8 changed files with 18 additions and 9 deletions

View File

@@ -86,7 +86,7 @@ struct BuildAirToolbarWindow : Window {
{
switch (widget) {
case WID_AT_AIRPORT:
if (HandlePlacePushButton(this, WID_AT_AIRPORT, SPR_CURSOR_AIRPORT, HT_RECT)) {
if (HandlePlacePushButton(this, WID_AT_AIRPORT, SPR_CURSOR_AIRPORT, HT_RECT | HT_SCROLL_VIEWPORT)) {
ShowBuildAirportPicker(this);
this->last_user_action = widget;
}

View File

@@ -139,7 +139,7 @@ struct BuildDocksToolbarWindow : Window {
case WID_DT_DEPOT: // Build depot button
if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT)) ShowBuildDocksDepotPicker(this);
if (HandlePlacePushButton(this, WID_DT_DEPOT, SPR_CURSOR_SHIP_DEPOT, HT_RECT | HT_SCROLL_VIEWPORT)) ShowBuildDocksDepotPicker(this);
break;
case WID_DT_STATION: // Build station button
@@ -149,7 +149,7 @@ struct BuildDocksToolbarWindow : Window {
case WID_DT_BUOY: // Build buoy button
if (!CanBuildVehicleInfrastructure(VEH_SHIP)) return;
HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT);
HandlePlacePushButton(this, WID_DT_BUOY, SPR_CURSOR_BUOY, HT_RECT | HT_SCROLL_VIEWPORT);
break;
case WID_DT_RIVER: // Build river button (in scenario editor)

View File

@@ -580,9 +580,9 @@ private:
assert(type > OPOS_NONE && type < OPOS_END);
static const HighLightStyle goto_place_style[OPOS_END - 1] = {
HT_RECT | HT_VEHICLE, // OPOS_GOTO
HT_RECT | HT_VEHICLE | HT_SCROLL_VIEWPORT, // OPOS_GOTO
HT_NONE, // OPOS_CONDITIONAL
HT_VEHICLE, // OPOS_SHARE
HT_VEHICLE | HT_SCROLL_VIEWPORT, // OPOS_SHARE
};
SetObjectToPlaceWnd(ANIMCURSOR_PICKSTATION, PAL_NONE, goto_place_style[type - 1], this);
this->goto_type = type;

View File

@@ -520,7 +520,7 @@ struct BuildRailToolbarWindow : Window {
break;
case WID_RAT_BUILD_DEPOT:
if (HandlePlacePushButton(this, WID_RAT_BUILD_DEPOT, GetRailTypeInfo(_cur_railtype)->cursor.depot, HT_RECT)) {
if (HandlePlacePushButton(this, WID_RAT_BUILD_DEPOT, GetRailTypeInfo(_cur_railtype)->cursor.depot, HT_RECT | HT_SCROLL_VIEWPORT)) {
ShowBuildTrainDepotPicker(this);
this->last_user_action = widget;
}
@@ -529,7 +529,7 @@ struct BuildRailToolbarWindow : Window {
case WID_RAT_BUILD_WAYPOINT:
this->last_user_action = widget;
_waypoint_count = StationClass::Get(STAT_CLASS_WAYP)->GetSpecCount();
if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT) && _waypoint_count > 1) {
if (HandlePlacePushButton(this, WID_RAT_BUILD_WAYPOINT, SPR_CURSOR_WAYPOINT, HT_RECT | HT_SCROLL_VIEWPORT) && _waypoint_count > 1) {
ShowBuildWaypointPicker(this);
}
break;

View File

@@ -406,7 +406,7 @@ struct BuildRoadToolbarWindow : Window {
case WID_ROT_DEPOT:
if (_game_mode == GM_EDITOR || !CanBuildVehicleInfrastructure(VEH_ROAD)) return;
if (HandlePlacePushButton(this, WID_ROT_DEPOT, SPR_CURSOR_ROAD_DEPOT, HT_RECT)) {
if (HandlePlacePushButton(this, WID_ROT_DEPOT, SPR_CURSOR_ROAD_DEPOT, HT_RECT | HT_SCROLL_VIEWPORT)) {
ShowRoadDepotPicker(this);
this->last_started_action = widget;
}

View File

@@ -28,6 +28,7 @@ enum HighLightStyle {
HT_RAIL = 0x080, ///< autorail (one piece), lower bits: direction
HT_VEHICLE = 0x100, ///< vehicle is accepted as target as well (bitmask)
HT_DIAGONAL = 0x200, ///< Also allow 'diagonal rectangles'. Only usable in combination with #HT_RECT or #HT_POINT.
HT_SCROLL_VIEWPORT = 0x400, ///< Allow scrolling viewport with left mouse button, this disables drag&drop, use only when selection cannot grow.
HT_DRAG_MASK = 0x0F8, ///< Mask for the tile drag-type modes.
/* lower bits (used with HT_LINE and HT_RAIL):

View File

@@ -1953,7 +1953,9 @@ bool HandleViewportClicked(const ViewPort *vp, int x, int y)
{
if (_move_pressed) return false;
if ((_thd.place_mode & HT_DRAG_MASK) != HT_NONE) {
// Allow scrolling viewport with mouse even in selection mode,
// unless we select line or area, or perform drag&drop
if ((_thd.place_mode & HT_DRAG_MASK) != HT_NONE && !(_thd.place_mode & HT_SCROLL_VIEWPORT)) {
PlaceObject();
return true;
}
@@ -1971,6 +1973,11 @@ bool HandleViewportMouseUp(const ViewPort *vp, int x, int y)
if (v != NULL && VehicleClicked(v)) return true;
}
if ((_thd.place_mode & HT_DRAG_MASK) != HT_NONE) {
PlaceObject();
return true;
}
if (CheckClickOnTown(vp, x, y)) return true;
if (CheckClickOnStation(vp, x, y)) return true;
if (CheckClickOnSign(vp, x, y)) return true;

View File

@@ -2913,6 +2913,7 @@ static void MouseLoop(MouseClick click, int mousewheel)
_scrolling_viewport = true;
_cursor.fix_at = false;
} else {
// Viewport already clicked, prevent sending same event on mouse-up
_left_button_dragged = true;
}
mouse_down_on_viewport = true;