(svn r19905) -Codechange: Use EventState for mouse handling routines.

This commit is contained in:
alberth 2010-05-30 12:15:28 +00:00
parent 113f3ef0eb
commit ce0e1cbb3f
2 changed files with 52 additions and 38 deletions

View File

@ -2640,23 +2640,23 @@ calc_heightdiff_single_direction:;
/**
* Handle the mouse while dragging for placement/resizing.
* @return Boolean whether search for a handler should continue
* @return State of handling the event.
*/
bool VpHandlePlaceSizingDrag()
EventState VpHandlePlaceSizingDrag()
{
if (_special_mouse_mode != WSM_SIZING) return true;
if (_special_mouse_mode != WSM_SIZING) return ES_NOT_HANDLED;
/* stop drag mode if the window has been closed */
Window *w = FindWindowById(_thd.window_class, _thd.window_number);
if (w == NULL) {
ResetObjectToPlace();
return false;
return ES_HANDLED;
}
/* while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() ) */
if (_left_button_down) {
w->OnPlaceDrag(_thd.select_method, _thd.select_proc, GetTileBelowCursor());
return false;
return ES_HANDLED;
}
/* mouse button released..
@ -2675,7 +2675,7 @@ bool VpHandlePlaceSizingDrag()
w->OnPlaceMouseUp(_thd.select_method, _thd.select_proc, _thd.selend, TileVirtXY(_thd.selstart.x, _thd.selstart.y), TileVirtXY(_thd.selend.x, _thd.selend.y));
return false;
return ES_HANDLED;
}
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)

View File

@ -1362,10 +1362,13 @@ static void HandlePlacePresize()
w->OnPlacePresize(pt, TileVirtXY(pt.x, pt.y));
}
static bool HandleDragDrop()
/** Handle drop in mouse dragging mode (#WSM_DRAGDROP).
* @return State of handling the event.
*/
static EventState HandleDragDrop()
{
if (_special_mouse_mode != WSM_DRAGDROP) return true;
if (_left_button_down) return false;
if (_special_mouse_mode != WSM_DRAGDROP) return ES_NOT_HANDLED;
if (_left_button_down) return ES_HANDLED;
Window *w = GetCallbackWnd();
@ -1379,13 +1382,16 @@ static bool HandleDragDrop()
ResetObjectToPlace();
return false;
return ES_HANDLED;
}
static bool HandleMouseDrag()
/** Handle dragging in mouse dragging mode (#WSM_DRAGDROP).
* @return State of handling the event.
*/
static EventState HandleMouseDrag()
{
if (_special_mouse_mode != WSM_DRAGDROP) return true;
if (!_left_button_down || (_cursor.delta.x == 0 && _cursor.delta.y == 0)) return true;
if (_special_mouse_mode != WSM_DRAGDROP) return ES_NOT_HANDLED;
if (!_left_button_down || (_cursor.delta.x == 0 && _cursor.delta.y == 0)) return ES_NOT_HANDLED;
Window *w = GetCallbackWnd();
@ -1397,7 +1403,7 @@ static bool HandleMouseDrag()
w->OnMouseDrag(pt, GetWidgetFromPos(w, pt.x, pt.y));
}
return false;
return ES_HANDLED;
}
static bool HandleMouseOver()
@ -1526,13 +1532,16 @@ static void PreventHiding(int *nx, int *ny, const Rect &rect, const Window *v, i
static bool _dragging_window; ///< A window is being dragged or resized.
static bool HandleWindowDragging()
/** Handle dragging/resizing of a window.
* @return State of handling the event.
*/
static EventState HandleWindowDragging()
{
/* Get out immediately if no window is being dragged at all. */
if (!_dragging_window) return true;
if (!_dragging_window) return ES_NOT_HANDLED;
/* If button still down, but cursor hasn't moved, there is nothing to do. */
if (_left_button_down && _cursor.delta.x == 0 && _cursor.delta.y == 0) return false;
if (_left_button_down && _cursor.delta.x == 0 && _cursor.delta.y == 0) return ES_HANDLED;
/* Otherwise find the window... */
Window *w;
@ -1652,7 +1661,7 @@ static bool HandleWindowDragging()
w->top = ny;
w->SetDirty();
return false;
return ES_HANDLED;
} else if (w->flags4 & WF_SIZING) {
/* Stop the sizing if the left mouse button was released */
if (!_left_button_down) {
@ -1690,7 +1699,7 @@ static bool HandleWindowDragging()
}
/* Window already on size */
if (x == 0 && y == 0) return false;
if (x == 0 && y == 0) return ES_HANDLED;
/* Now find the new cursor pos.. this is NOT _cursor, because we move in steps. */
_drag_delta.y += y;
@ -1705,12 +1714,12 @@ static bool HandleWindowDragging()
/* ResizeWindow sets both pre- and after-size to dirty for redrawal */
ResizeWindow(w, x, y);
return false;
return ES_HANDLED;
}
}
_dragging_window = false;
return false;
return ES_HANDLED;
}
/**
@ -1748,13 +1757,15 @@ static void StartWindowSizing(Window *w, bool to_left)
DeleteWindowById(WC_DROPDOWN_MENU, 0);
}
static bool HandleScrollbarScrolling()
/** handle scrollbar scrolling with the mouse.
* @return State of handling the event.
*/
static EventState HandleScrollbarScrolling()
{
Window *w;
/* Get out quickly if no item is being scrolled */
if (!_scrolling_scrollbar) return true;
if (!_scrolling_scrollbar) return ES_NOT_HANDLED;
/* Find the scrolling window */
FOR_ALL_WINDOWS_FROM_BACK(w) {
@ -1789,33 +1800,36 @@ static bool HandleScrollbarScrolling()
sb->SetPosition(pos);
w->SetDirty();
}
return false;
return ES_HANDLED;
}
}
_scrolling_scrollbar = false;
return false;
return ES_HANDLED;
}
static bool HandleViewportScroll()
/** Handle viewport scrolling with the mouse.
* @return State of handling the event.
*/
static EventState HandleViewportScroll()
{
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
if (!_scrolling_viewport) return true;
if (!_scrolling_viewport) return ES_NOT_HANDLED;
Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
if (!(_right_button_down || scrollwheel_scrolling || (_settings_client.gui.left_mouse_btn_scrolling && _left_button_down)) || w == NULL) {
_cursor.fix_at = false;
_scrolling_viewport = false;
return true;
return ES_NOT_HANDLED;
}
if (w == FindWindowById(WC_MAIN_WINDOW, 0) && w->viewport->follow_vehicle != INVALID_VEHICLE) {
/* If the main window is following a vehicle, then first let go of it! */
const Vehicle *veh = Vehicle::Get(w->viewport->follow_vehicle);
ScrollMainWindowTo(veh->x_pos, veh->y_pos, veh->z_pos, true); // This also resets follow_vehicle
return true;
return ES_NOT_HANDLED;
}
Point delta;
@ -1840,7 +1854,7 @@ static bool HandleViewportScroll()
_cursor.delta.x = 0;
_cursor.delta.y = 0;
return false;
return ES_HANDLED;
}
/** Check if a window can be made top-most window, and if so do
@ -2016,7 +2030,7 @@ enum MouseClick {
TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms
};
extern bool VpHandlePlaceSizingDrag();
extern EventState VpHandlePlaceSizingDrag();
static void ScrollMainViewport(int x, int y)
{
@ -2074,12 +2088,12 @@ static void MouseLoop(MouseClick click, int mousewheel)
HandlePlacePresize();
UpdateTileSelection();
if (!VpHandlePlaceSizingDrag()) return;
if (!HandleMouseDrag()) return;
if (!HandleDragDrop()) return;
if (!HandleWindowDragging()) return;
if (!HandleScrollbarScrolling()) return;
if (!HandleViewportScroll()) return;
if (VpHandlePlaceSizingDrag() == ES_HANDLED) return;
if (HandleMouseDrag() == ES_HANDLED) return;
if (HandleDragDrop() == ES_HANDLED) return;
if (HandleWindowDragging() == ES_HANDLED) return;
if (HandleScrollbarScrolling() == ES_HANDLED) return;
if (HandleViewportScroll() == ES_HANDLED) return;
if (!HandleMouseOver()) return;
bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);