static rct_peep *viewport_interaction_get_closest_peep(sint32 x, sint32 y, sint32 maxDistance) { sint32 distance, closestDistance; uint16 spriteIndex; rct_window *w; rct_viewport *viewport; rct_peep *peep, *closestPeep; w = window_find_from_point(x, y); if (w == nullptr) return nullptr; viewport = w->viewport; if (viewport == nullptr || viewport->zoom >= 2) return nullptr; x = ((x - viewport->x) << viewport->zoom) + viewport->view_x; y = ((y - viewport->y) << viewport->zoom) + viewport->view_y; closestPeep = nullptr; closestDistance = 0xFFFF; FOR_ALL_PEEPS(spriteIndex, peep) { if (peep->sprite_left == LOCATION_NULL) continue; distance = abs(((peep->sprite_left + peep->sprite_right) / 2) - x) + abs(((peep->sprite_top + peep->sprite_bottom) / 2) - y); if (distance > maxDistance) continue; if (distance < closestDistance) { closestPeep = peep; closestDistance = distance; } } return closestPeep; }
/** * * rct2: 0x006E8655 */ static void game_handle_input_mouse(int x, int y, int state) { rct_window *w, *w2; rct_widget *widget; int widgetIndex; rct_windowclass windowClass; rct_windownumber windowNumber; // Get window and widget under cursor position w = window_find_from_point(x, y); widgetIndex = w == NULL ? -1 : window_find_widget_from_point(w, x, y); widget = widgetIndex == -1 ? 0 : &w->widgets[widgetIndex]; switch (RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8)) { case INPUT_STATE_RESET: window_tooltip_reset(x, y); // fall-through case INPUT_STATE_NORMAL: switch (state) { case 0: input_mouseover(x, y, w, widgetIndex); break; case 1: input_leftmousedown(x, y, w, widgetIndex); break; case 3: // Close tooltip window_close_by_id(5, 0); if (w != NULL) window_bring_to_front(w); if (widgetIndex == -1) break; if (widget->type == WWT_VIEWPORT) { if (RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_FLAGS, uint8) & 9) break; w->flags &= ~(1 << 3); RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_VIEWPORT_DRAG; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) = y; RCT2_GLOBAL(0x009DE530, rct_windowclass) = w->classification; RCT2_GLOBAL(0x009DE52E, rct_windownumber) = w->number; RCT2_GLOBAL(0x009DE540, sint16) = 0; // hide cursor // RCT2_CALLPROC_X(0x00407045, 0, 0, 0, 0, 0, 0, 0); // RCT2_GLOBAL(0x009DE518, uint32) |= (1 << 5); GetCursorPos(&_dragPosition); ShowCursor(FALSE); } else if (widget->type == WWT_SCROLL) { } break; } break; case INPUT_STATE_WIDGET_PRESSED: RCT2_CALLPROC_X(0x006E8DA7, x, y, state, widgetIndex, w, widget, 0); break; case INPUT_STATE_DRAGGING: // RCT2_CALLPROC_X(0x006E8C5C, x, y, state, widgetIndex, w, widget, 0); w = window_find_by_id(RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWCLASS, rct_windowclass), RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWNUMBER, rct_windownumber)); if (w == NULL) { RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; break; } if (state == 0) { y = clamp(29, y, RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 34); window_move_position( w, x - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16), y - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) ); RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) = y; } else if (state == 2) { RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_NORMAL; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint8) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WIDGET_INDEX, uint8) = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, sint16); RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_CLASS, rct_windowclass) = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, rct_windowclass); RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_NUMBER, rct_windownumber) = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, rct_windownumber); y = clamp(29, y, RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 34); window_move_position( w, x - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16), y - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) ); RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) = y; RCT2_CALLPROC_X(w->event_handlers[WE_UNKNOWN_18], 0, 0, x, y, w, 0, 0); } break; case INPUT_STATE_VIEWPORT_DRAG: { int dx, dy; dx = x - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16); dy = y - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16); w = window_find_by_id(RCT2_GLOBAL(0x009DE530, rct_windowclass), RCT2_GLOBAL(0x009DE52E, rct_windownumber)); if (state == 0) { rct_viewport *viewport = w->viewport; RCT2_GLOBAL(0x009DE540, sint16) += RCT2_GLOBAL(0x009DE588, sint16); if (viewport == NULL) { ShowCursor(TRUE); RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; } else if (dx != 0 || dy != 0) { if (!(w->flags & (1 << 2))) { RCT2_GLOBAL(0x009DE540, sint16) = 1000; dx <<= viewport->zoom + 1; dy <<= viewport->zoom + 1; w->var_4B2 += dx; w->var_4B4 += dy; } } } else if (state == 4) { ShowCursor(TRUE); RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; if (RCT2_GLOBAL(0x009DE540, sint16) < 500) { // Right click { int eax, ebx, ecx, edx, esi, edi, ebp; eax = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16); ebx = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16); RCT2_CALLFUNC_X(0x006EDE88, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); switch (ebx & 0xFF) { case 2: if (*((uint8*)edx) == 0) RCT2_CALLPROC_X(0x006B4857, eax, 0, ecx, 0, 0, 0, 0); break; case 3: RCT2_CALLPROC_X(0x006CC056, eax, 0, ecx, edx, 0, 0, 0); break; case 5: RCT2_CALLPROC_X(0x006E08D2, eax, 0, ecx, edx, 0, 0, 0); break; case 6: RCT2_CALLPROC_X(0x006A614A, eax, 0, ecx, edx, 0, 0, 0); break; case 7: RCT2_CALLPROC_X(0x006A61AB, eax, 0, ecx, edx, 0, 0, 0); break; case 8: RCT2_CALLPROC_X(0x00666C0E, eax, 0, ecx, edx, 0, 0, 0); break; case 9: RCT2_CALLPROC_X(0x006E57A9, eax, 0, ecx, edx, 0, 0, 0); break; case 10: RCT2_CALLPROC_X(0x006B88DC, eax, 0, ecx, edx, 0, 0, 0); break; case 12: RCT2_CALLPROC_X(0x006BA233, eax, 0, ecx, edx, 0, 0, 0); break; default: break; } } } } // // SetCursorPos(_dragPosition.x, _dragPosition.y); // RCT2_CALLPROC_X(0x006E89C6, x - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16), y - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16), state, widgetIndex, w, widget, 0); break; } case INPUT_STATE_DROPDOWN_ACTIVE: RCT2_CALLPROC_X(0x006E8DA7, x, y, state, widgetIndex, w, widget, 0); break; case INPUT_STATE_VIEWPORT_LEFT: RCT2_CALLPROC_X(0x006E87B4, x, y, state, widgetIndex, w, widget, 0); break; case INPUT_STATE_SCROLL_LEFT: RCT2_CALLPROC_X(0x006E8676, x, y, state, widgetIndex, w, widget, 0); break; case INPUT_STATE_RESIZING: // RCT2_CALLPROC_X(0x006E8B46, x, y, state, widgetIndex, w, widget, 0); w = window_find_by_id(RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWCLASS, rct_windowclass), RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_WINDOWNUMBER, rct_windownumber)); if (w == NULL) { RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_RESET; break; } if (state != 0 && state != 2) break; if (state == 2) { RCT2_GLOBAL(RCT2_ADDRESS_INPUT_STATE, uint8) = INPUT_STATE_NORMAL; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TIMEOUT, uint8) = 0; RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WIDGET_INDEX, uint8) = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WIDGETINDEX, sint16); RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_CLASS, rct_windowclass) = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWCLASS, rct_windowclass); RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_WINDOW_NUMBER, rct_windownumber) = RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DOWN_WINDOWNUMBER, rct_windownumber); } if (y < RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - 2) { window_resize( w, x - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16), y - RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) ); } RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_X, sint16) = x; RCT2_GLOBAL(RCT2_ADDRESS_CURSOR_DRAG_LAST_Y, sint16) = y; break; case 9: RCT2_CALLPROC_X(0x006E8ACB, x, y, state, widgetIndex, w, widget, 0); break; } }
/** * * rct2: 0x006E8655 */ static void game_handle_input_mouse(sint32 x, sint32 y, sint32 state) { rct_window *w; rct_widget *widget; rct_widgetindex widgetIndex; // Get window and widget under cursor position w = window_find_from_point(x, y); widgetIndex = w == NULL ? -1 : window_find_widget_from_point(w, x, y); widget = widgetIndex == -1 ? 0 : &w->widgets[widgetIndex]; switch (_inputState) { case INPUT_STATE_RESET: window_tooltip_reset(x, y); // fall-through case INPUT_STATE_NORMAL: switch (state) { case MOUSE_STATE_RELEASED: input_widget_over(x, y, w, widgetIndex); break; case MOUSE_STATE_LEFT_PRESS: input_widget_left(x, y, w, widgetIndex); break; case MOUSE_STATE_RIGHT_PRESS: window_close_by_class(WC_TOOLTIP); if (w != NULL) { w = window_bring_to_front(w); } if (widgetIndex != -1) { switch (widget->type) { case WWT_VIEWPORT: if (!(gScreenFlags & (SCREEN_FLAGS_TRACK_MANAGER | SCREEN_FLAGS_TITLE_DEMO))) { input_viewport_drag_begin(w, x, y); } break; case WWT_SCROLL: input_scroll_drag_begin(x, y, w, widget, widgetIndex); break; } } break; } break; case INPUT_STATE_WIDGET_PRESSED: input_state_widget_pressed(x, y, state, widgetIndex, w, widget); break; case INPUT_STATE_POSITIONING_WINDOW: w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number); if (w == NULL) { _inputState = INPUT_STATE_RESET; } else { input_window_position_continue(w, gInputDragLastX, gInputDragLastY, x, y); if (state == MOUSE_STATE_LEFT_RELEASE) { input_window_position_end(w, x, y); } } break; case INPUT_STATE_VIEWPORT_RIGHT: if (state == MOUSE_STATE_RELEASED) { input_viewport_drag_continue(); } else if (state == MOUSE_STATE_RIGHT_RELEASE) { input_viewport_drag_end(); if (_ticksSinceDragStart < 500) { // If the user pressed the right mouse button for less than 500 ticks, interpret as right click viewport_interaction_right_click(x, y); } } break; case INPUT_STATE_DROPDOWN_ACTIVE: input_state_widget_pressed(x, y, state, widgetIndex, w, widget); break; case INPUT_STATE_VIEWPORT_LEFT: w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number); if (w == NULL) { _inputState = INPUT_STATE_RESET; break; } switch (state) { case MOUSE_STATE_RELEASED: if (w->viewport == NULL) { _inputState = INPUT_STATE_RESET; break; } if (w->classification != _dragWidget.window_classification || w->number != _dragWidget.window_number || !(_inputFlags & INPUT_FLAG_TOOL_ACTIVE) ) { break; } w = window_find_by_number( gCurrentToolWidget.window_classification, gCurrentToolWidget.window_number ); if (w == NULL) { break; } window_event_tool_drag_call(w, gCurrentToolWidget.widget_index, x, y); break; case MOUSE_STATE_LEFT_RELEASE: _inputState = INPUT_STATE_RESET; if (_dragWidget.window_number == w->number) { if ((_inputFlags & INPUT_FLAG_TOOL_ACTIVE)) { w = window_find_by_number( gCurrentToolWidget.window_classification, gCurrentToolWidget.window_number ); if (w != NULL) { window_event_tool_up_call(w, gCurrentToolWidget.widget_index, x, y); } } else if (!(_inputFlags & INPUT_FLAG_4)) { viewport_interaction_left_click(x, y); } } break; } break; case INPUT_STATE_SCROLL_LEFT: switch (state) { case MOUSE_STATE_RELEASED: input_scroll_continue(w, widgetIndex, state, x, y); break; case MOUSE_STATE_LEFT_RELEASE: input_scroll_end(); break; } break; case INPUT_STATE_RESIZING: w = window_find_by_number(_dragWidget.window_classification, _dragWidget.window_number); if (w == NULL) { _inputState = INPUT_STATE_RESET; } else { if (state == MOUSE_STATE_LEFT_RELEASE) { input_window_resize_end(); } if (state == MOUSE_STATE_RELEASED || state == MOUSE_STATE_LEFT_RELEASE) { input_window_resize_continue(w, x, y); } } break; case INPUT_STATE_SCROLL_RIGHT: input_scroll_right(x, y, state); break; } }
/** * * rct2: 0x006ED833 */ void process_mouse_over(sint32 x, sint32 y) { rct_window* window; sint32 cursorId; cursorId = CURSOR_ARROW; set_map_tooltip_format_arg(0, rct_string_id, STR_NONE); window = window_find_from_point(x, y); if (window != NULL) { sint32 ebx, edi; rct_window* subWindow; rct_widgetindex widgetId = window_find_widget_from_point(window, x, y); if (widgetId != -1) { switch (window->widgets[widgetId].type){ case WWT_VIEWPORT: if (!(_inputFlags & INPUT_FLAG_TOOL_ACTIVE)) { if (viewport_interaction_left_over(x, y)) { sub_6ED990(CURSOR_HAND_POINT); return; } break; } cursorId = gCurrentToolId; subWindow = window_find_by_number( gCurrentToolWidget.window_classification, gCurrentToolWidget.window_number ); if (subWindow == NULL) break; ebx = 0; edi = cursorId; // Window event WE_UNKNOWN_0E was called here, but no windows actually implemented a handler and // its not known what it was for cursorId = edi; if ((ebx & 0xFF) != 0) { sub_6ED990(cursorId); return; } break; case WWT_FRAME: case WWT_RESIZE: if (!(window->flags & WF_RESIZABLE)) break; if (window->min_width == window->max_width && window->min_height == window->max_height) break; if (x < window->x + window->width - 0x13) break; if (y < window->y + window->height - 0x13) break; cursorId = CURSOR_DIAGONAL_ARROWS; break; case WWT_SCROLL: { sint32 output_scroll_area, scroll_id; sint32 scroll_x, scroll_y; widget_scroll_get_part(window, &window->widgets[widgetId], x, y, &scroll_x, &scroll_y, &output_scroll_area, &scroll_id); cursorId = scroll_id; if (output_scroll_area != SCROLL_PART_VIEW) { cursorId = CURSOR_ARROW; break; } // Same as default but with scroll_x/y cursorId = window_event_cursor_call(window, widgetId, scroll_x, scroll_y); if (cursorId == -1) cursorId = CURSOR_ARROW; break; } default: cursorId = window_event_cursor_call(window, widgetId, x, y); if (cursorId == -1) cursorId = CURSOR_ARROW; break; } } } viewport_interaction_right_over(x, y); sub_6ED990(cursorId); }
/** * * rct2: 0x006E7868 */ static void window_all_wheel_input() { int raw, wheel, widgetIndex; rct_window *w; rct_widget *widget; rct_scroll *scroll; // Get wheel value raw = gCursorState.wheel; wheel = 0; while (1) { raw -= 120; if (raw < 0) break; wheel -= 17; } raw += 120; while (1) { raw += 120; if (raw > 0) break; wheel += 17; } raw -= 120; gCursorState.wheel = raw; if (wheel == 0) return; // Check window cursor is over if (!(RCT2_GLOBAL(0x009DE518, uint32) & (1 << 5))) { w = window_find_from_point(gCursorState.x, gCursorState.y); if (w != NULL) { // Check if main window if (w->classification == WC_MAIN_WINDOW) { window_viewport_wheel_input(w, wheel); return; } // Check scroll view, cursor is over widgetIndex = window_find_widget_from_point(w, gCursorState.x, gCursorState.y); if (widgetIndex != -1) { widget = &w->widgets[widgetIndex]; if (widget->type == WWT_SCROLL) { scroll = &w->scrolls[RCT2_GLOBAL(0x01420075, uint8) * sizeof(rct_scroll)]; if (scroll->flags & (HSCROLLBAR_VISIBLE | VSCROLLBAR_VISIBLE)) { window_scroll_wheel_input(w, window_get_scroll_index(w, widgetIndex), wheel); return; } } // Check other scroll views on window if (window_wheel_input(w, wheel)) return; } } } // Check windows, front to back for (w = RCT2_LAST_WINDOW; w >= g_window_list; w--) if (window_wheel_input(w, wheel)) return; }
/** * * rct2: 0x006ED833 */ void process_mouse_over(int x, int y) { rct_window* window; rct_window* subWindow; int widgetId; int cursorId; int ebx, esi, edi, ebp; cursorId = CURSOR_ARROW; RCT2_GLOBAL(RCT2_ADDRESS_MAP_TOOLTIP_ARGS, sint16) = -1; window = window_find_from_point(x, y); if (window != NULL) { widgetId = window_find_widget_from_point(window, x, y); RCT2_GLOBAL(0x1420046, sint16) = (widgetId & 0xFFFF); if (widgetId != -1) { switch (window->widgets[widgetId].type){ case WWT_VIEWPORT: if (!(gInputFlags & INPUT_FLAG_TOOL_ACTIVE)) { if (viewport_interaction_left_over(x, y)) { sub_6ED990(CURSOR_HAND_POINT); return; } break; } cursorId = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_TOOL, uint8); subWindow = window_find_by_number( RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWCLASS, rct_windowclass), RCT2_GLOBAL(RCT2_ADDRESS_TOOL_WINDOWNUMBER, rct_windownumber) ); ebp = (int)subWindow; if (subWindow == NULL) break; ebx = 0; edi = cursorId; esi = (int)subWindow; // Window event WE_UNKNOWN_0E was called here, but no windows actually implemented a handler and // its not known what it was for cursorId = edi; if ((ebx & 0xFF) != 0) { sub_6ED990(cursorId); return; } break; case WWT_FRAME: case WWT_RESIZE: if (!(window->flags & 0x100)) break; if (window->min_width == window->max_width && window->min_height == window->max_height) break; if (x < window->x + window->width - 0x13) break; if (y < window->y + window->height - 0x13) break; cursorId = CURSOR_DIAGONAL_ARROWS; break; case WWT_SCROLL: RCT2_GLOBAL(0x9DE558, uint16) = x; RCT2_GLOBAL(0x9DE55A, uint16) = y; int output_scroll_area, scroll_id; int scroll_x, scroll_y; widget_scroll_get_part(window, &window->widgets[widgetId], x, y, &scroll_x, &scroll_y, &output_scroll_area, &scroll_id); cursorId = scroll_id; if (output_scroll_area != SCROLL_PART_VIEW) { cursorId = CURSOR_ARROW; break; } // Same as default but with scroll_x/y cursorId = window_event_cursor_call(window, widgetId, scroll_x, scroll_y); if (cursorId == -1) cursorId = CURSOR_ARROW; break; default: cursorId = window_event_cursor_call(window, widgetId, x, y); if (cursorId == -1) cursorId = CURSOR_ARROW; break; } } } viewport_interaction_right_over(x, y); sub_6ED990(cursorId); }