/**
 *
 *  rct2: 0x006852F4
 */
static void window_editor_inventions_list_drag_open(rct_research_item* researchItem)
{
    char buffer[256], *ptr;
    int32_t stringWidth;
    rct_window* w;

    window_close_by_class(WC_EDITOR_INVENTION_LIST_DRAG);
    _editorInventionsListDraggedItem = researchItem;
    rct_string_id stringId = research_item_get_name(researchItem);

    ptr = buffer;
    if (researchItem->type == RESEARCH_ENTRY_TYPE_RIDE && !RideGroupManager::RideTypeIsIndependent(researchItem->baseRideType))
    {
        const auto rideEntry = get_ride_entry(researchItem->entryIndex);
        const rct_string_id rideGroupName = get_ride_naming(researchItem->baseRideType, rideEntry).name;
        rct_string_id args[] = {
            rideGroupName,
            stringId,
        };
        format_string(ptr, 256, STR_INVENTIONS_LIST_RIDE_AND_VEHICLE_NAME, &args);
    }
    else
    {
        format_string(ptr, 256, stringId, nullptr);
    }

    stringWidth = gfx_get_string_width(buffer);
    window_editor_inventions_list_drag_widgets[0].right = stringWidth;

    w = window_create(
        gTooltipCursorX - (stringWidth / 2), gTooltipCursorY - 7, stringWidth, 14, &window_editor_inventions_list_drag_events,
        WC_EDITOR_INVENTION_LIST_DRAG, WF_STICK_TO_FRONT | WF_TRANSPARENT | WF_NO_SNAPPING);
    w->widgets = window_editor_inventions_list_drag_widgets;
    w->colours[1] = COLOUR_WHITE;
    input_window_position_begin(w, 0, gTooltipCursorX, gTooltipCursorY);
}
Exemple #2
0
/**
 *
 *  rct2: 0x006E95F9
 */
static void input_widget_left(sint32 x, sint32 y, rct_window *w, rct_widgetindex widgetIndex)
{
	rct_windowclass windowClass = 255;
	rct_windownumber windowNumber = 0;
	rct_widget *widget;

	if (w != NULL) {
		windowClass = w->classification;
		windowNumber = w->number;
	}

	window_close_by_class(WC_ERROR);
	window_close_by_class(WC_TOOLTIP);

	// Window might have changed position in the list, therefore find it again
	w = window_find_by_number(windowClass, windowNumber);
	if (w == NULL)
		return;

	w = window_bring_to_front(w);
	if (widgetIndex == -1)
		return;

	if (windowClass != gCurrentTextBox.window.classification ||
		windowNumber != gCurrentTextBox.window.number ||
		widgetIndex != gCurrentTextBox.widget_index) {
		window_cancel_textbox();
	}

	widget = &w->widgets[widgetIndex];

	switch (widget->type) {
	case WWT_FRAME:
	case WWT_RESIZE:
		if (window_can_resize(w) && (x >= w->x + w->width - 19 && y >= w->y + w->height - 19))
			input_window_resize_begin(w, widgetIndex, x, y);
		break;
	case WWT_VIEWPORT:
		_inputState = INPUT_STATE_VIEWPORT_LEFT;
		gInputDragLastX = x;
		gInputDragLastY = y;
		_dragWidget.window_classification = windowClass;
		_dragWidget.window_number = windowNumber;
		if (_inputFlags & INPUT_FLAG_TOOL_ACTIVE) {
			w = window_find_by_number(
				gCurrentToolWidget.window_classification,
				gCurrentToolWidget.window_number
				);
			if (w != NULL) {
				window_event_tool_down_call(w, gCurrentToolWidget.widget_index, x, y);
				_inputFlags |= INPUT_FLAG_4;
			}
		}
		break;
	case WWT_CAPTION:
		input_window_position_begin(w, widgetIndex, x, y);
		break;
	case WWT_SCROLL:
		input_scroll_begin(w, widgetIndex, x, y);
		break;
	default:
		if (widget_is_enabled(w, widgetIndex) && !widget_is_disabled(w, widgetIndex)) {
			audio_play_sound_panned(SOUND_CLICK_1, w->x + (widget->left + widget->right) / 2, 0, 0, 0);

			// Set new cursor down widget
			gPressedWidget.window_classification = windowClass;
			gPressedWidget.window_number = windowNumber;
			gPressedWidget.widget_index = widgetIndex;
			_inputFlags |= INPUT_FLAG_WIDGET_PRESSED;
			_inputState = INPUT_STATE_WIDGET_PRESSED;
			_clickRepeatTicks = 1;

			widget_invalidate_by_number(windowClass, windowNumber, widgetIndex);
			window_event_mouse_down_call(w, widgetIndex);
		}
		break;
	}
}