2016-05-04 19:24:41 +02:00
|
|
|
#pragma region Copyright (c) 2014-2016 OpenRCT2 Developers
|
2014-04-24 19:53:42 +02:00
|
|
|
/*****************************************************************************
|
2014-04-25 19:25:34 +02:00
|
|
|
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
|
|
|
|
*
|
2016-05-04 19:24:41 +02:00
|
|
|
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
|
|
|
|
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
|
2014-04-25 19:25:34 +02:00
|
|
|
*
|
|
|
|
* OpenRCT2 is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2016-05-04 19:24:41 +02:00
|
|
|
*
|
|
|
|
* A full copy of the GNU General Public License can be found in licence.txt
|
2014-04-25 19:25:34 +02:00
|
|
|
*****************************************************************************/
|
2016-05-04 19:24:41 +02:00
|
|
|
#pragma endregion
|
2014-04-24 19:53:42 +02:00
|
|
|
|
2014-10-06 18:36:58 +02:00
|
|
|
#include "../addresses.h"
|
|
|
|
#include "../drawing/drawing.h"
|
|
|
|
#include "../localisation/localisation.h"
|
2016-01-04 23:45:51 +01:00
|
|
|
#include "../input.h"
|
2014-10-06 18:36:58 +02:00
|
|
|
#include "../interface/widget.h"
|
|
|
|
#include "../interface/window.h"
|
2014-04-24 19:53:42 +02:00
|
|
|
|
|
|
|
enum {
|
|
|
|
WIDX_BACKGROUND
|
|
|
|
};
|
|
|
|
|
|
|
|
static rct_widget window_tooltip_widgets[] = {
|
|
|
|
{ WWT_IMGBTN, 0, 0, 199, 0, 31, 0x0FFFFFFFF, STR_NONE },
|
|
|
|
{ WIDGETS_END },
|
|
|
|
};
|
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_tooltip_onclose(rct_window *w);
|
2014-05-19 19:47:14 +02:00
|
|
|
static void window_tooltip_update(rct_window *w);
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_tooltip_paint(rct_window *w, rct_drawpixelinfo *dpi);
|
2014-04-24 19:53:42 +02:00
|
|
|
|
2015-07-10 02:39:16 +02:00
|
|
|
static rct_window_event_list window_tooltip_events = {
|
2014-04-24 19:53:42 +02:00
|
|
|
window_tooltip_onclose,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-04-24 19:53:42 +02:00
|
|
|
window_tooltip_update,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2014-04-24 19:53:42 +02:00
|
|
|
window_tooltip_paint,
|
2015-07-10 02:39:16 +02:00
|
|
|
NULL
|
2014-04-24 19:53:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void window_tooltip_reset(int x, int y)
|
|
|
|
{
|
2016-01-05 01:02:23 +01:00
|
|
|
gTooltipCursorX = x;
|
|
|
|
gTooltipCursorY = y;
|
|
|
|
gTooltipTimeout = 0;
|
|
|
|
gTooltipWidget.window_classification = 255;
|
2016-01-04 23:45:51 +01:00
|
|
|
gInputState = INPUT_STATE_NORMAL;
|
2016-01-04 23:53:03 +01:00
|
|
|
gInputFlags &= ~INPUT_FLAG_4;
|
2014-04-24 19:53:42 +02:00
|
|
|
}
|
|
|
|
|
2015-04-12 23:26:15 +02:00
|
|
|
uint8* gTooltip_text_buffer = RCT2_ADDRESS(RCT2_ADDRESS_TOOLTIP_TEXT_BUFFER, uint8);
|
2015-09-01 08:08:28 +02:00
|
|
|
|
|
|
|
void window_tooltip_show(rct_string_id id, int x, int y)
|
2014-04-24 19:53:42 +02:00
|
|
|
{
|
|
|
|
rct_window *w;
|
|
|
|
int width, height;
|
|
|
|
|
2014-10-16 03:02:43 +02:00
|
|
|
w = window_find_by_class(WC_ERROR);
|
2014-04-24 19:53:42 +02:00
|
|
|
if (w != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RCT2_GLOBAL(0x0142006C, sint32) = -1;
|
2014-07-13 14:10:14 +02:00
|
|
|
char* buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char);
|
2014-04-24 19:53:42 +02:00
|
|
|
|
2016-05-15 23:03:53 +02:00
|
|
|
format_string(buffer, id, gCommonFormatArgs);
|
2016-04-26 00:00:58 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
2014-11-01 14:10:14 +01:00
|
|
|
|
2015-08-01 17:40:15 +02:00
|
|
|
int tooltip_text_width;
|
2014-11-01 14:10:14 +01:00
|
|
|
tooltip_text_width = gfx_get_string_width_new_lined(buffer);
|
2014-07-13 14:10:14 +02:00
|
|
|
buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char);
|
2015-08-01 17:40:15 +02:00
|
|
|
tooltip_text_width = min(tooltip_text_width, 196);
|
2014-04-24 19:53:42 +02:00
|
|
|
|
2016-04-26 00:00:58 +02:00
|
|
|
gCurrentFontSpriteBase = FONT_SPRITE_BASE_MEDIUM;
|
2015-06-09 19:29:02 +02:00
|
|
|
|
2015-08-01 17:40:15 +02:00
|
|
|
int numLines, fontSpriteBase;
|
|
|
|
tooltip_text_width = gfx_wrap_string(buffer, tooltip_text_width + 1, &numLines, &fontSpriteBase);
|
2014-07-13 14:10:14 +02:00
|
|
|
|
2015-08-01 17:40:15 +02:00
|
|
|
RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TEXT_HEIGHT, sint16) = numLines;
|
2014-07-13 14:10:14 +02:00
|
|
|
width = tooltip_text_width + 3;
|
2016-04-26 00:00:58 +02:00
|
|
|
height = ((numLines + 1) * font_get_line_height(gCurrentFontSpriteBase)) + 4;
|
2014-04-24 19:53:42 +02:00
|
|
|
window_tooltip_widgets[WIDX_BACKGROUND].right = width;
|
|
|
|
window_tooltip_widgets[WIDX_BACKGROUND].bottom = height;
|
|
|
|
|
2014-11-01 14:10:14 +01:00
|
|
|
memcpy(gTooltip_text_buffer, buffer, 512);
|
2015-09-01 08:08:28 +02:00
|
|
|
|
2016-04-24 01:36:39 +02:00
|
|
|
x = clamp(0, x - (width / 2), gScreenWidth - width);
|
2015-02-21 03:01:32 +01:00
|
|
|
|
2016-04-24 01:36:39 +02:00
|
|
|
int max_y = gScreenHeight - height;
|
2015-02-21 03:01:32 +01:00
|
|
|
y += 26; // Normally, we'd display the tooltip 26 lower
|
|
|
|
if (y > max_y)
|
|
|
|
// If y is too large, the tooltip could be forced below the cursor if we'd just clamped y,
|
|
|
|
// so we'll subtract a bit more
|
|
|
|
y -= height + 40;
|
|
|
|
y = clamp(22, y, max_y);
|
2014-04-24 19:53:42 +02:00
|
|
|
|
2015-06-13 23:16:14 +02:00
|
|
|
w = window_create(
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
width,
|
|
|
|
height,
|
2015-07-10 02:39:16 +02:00
|
|
|
&window_tooltip_events,
|
2015-06-13 23:16:14 +02:00
|
|
|
WC_TOOLTIP,
|
|
|
|
WF_TRANSPARENT | WF_STICK_TO_FRONT
|
2015-09-01 08:08:28 +02:00
|
|
|
);
|
2014-04-24 19:53:42 +02:00
|
|
|
w->widgets = window_tooltip_widgets;
|
|
|
|
|
2016-01-05 01:02:23 +01:00
|
|
|
gTooltipNotShownTicks = 0;
|
2014-04-24 19:53:42 +02:00
|
|
|
}
|
|
|
|
|
2015-09-01 08:08:28 +02:00
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2015-09-01 08:08:28 +02:00
|
|
|
* rct2: 0x006EA10D
|
|
|
|
*/
|
|
|
|
void window_tooltip_open(rct_window *widgetWindow, int widgetIndex, int x, int y)
|
|
|
|
{
|
|
|
|
rct_widget *widget;
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2015-09-01 08:08:28 +02:00
|
|
|
if (widgetWindow == NULL || widgetIndex == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
widget = &widgetWindow->widgets[widgetIndex];
|
|
|
|
window_event_invalidate_call(widgetWindow);
|
|
|
|
if (widget->tooltip == 0xFFFF)
|
|
|
|
return;
|
|
|
|
|
2016-01-05 01:02:23 +01:00
|
|
|
gTooltipWidget.window_classification = widgetWindow->classification;
|
|
|
|
gTooltipWidget.window_number = widgetWindow->number;
|
|
|
|
gTooltipWidget.widget_index = widgetIndex;
|
2015-09-01 08:08:28 +02:00
|
|
|
|
2016-01-07 23:14:53 +01:00
|
|
|
if (window_event_tooltip_call(widgetWindow, widgetIndex) == STR_NONE)
|
2015-09-01 08:08:28 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
window_tooltip_show(widget->tooltip, x, y);
|
|
|
|
}
|
|
|
|
|
2014-04-24 19:53:42 +02:00
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-04-24 19:53:42 +02:00
|
|
|
* rct2: 0x006E98C6
|
|
|
|
*/
|
|
|
|
void window_tooltip_close()
|
|
|
|
{
|
2014-10-16 03:02:43 +02:00
|
|
|
window_close_by_class(WC_TOOLTIP);
|
2016-01-05 01:02:23 +01:00
|
|
|
gTooltipTimeout = 0;
|
|
|
|
gTooltipWidget.window_classification = 255;
|
2014-04-24 19:53:42 +02:00
|
|
|
RCT2_GLOBAL(0x0142006C, sint32) = -1;
|
|
|
|
RCT2_GLOBAL(0x009DE51E, uint8) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-04-24 19:53:42 +02:00
|
|
|
* rct2: 0x006EA578
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_tooltip_onclose(rct_window *w)
|
2014-04-24 19:53:42 +02:00
|
|
|
{
|
|
|
|
RCT2_GLOBAL(0x009BC3B0, uint8) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-04-24 19:53:42 +02:00
|
|
|
* rct2: 0x006EA580
|
|
|
|
*/
|
2014-05-19 19:47:14 +02:00
|
|
|
static void window_tooltip_update(rct_window *w)
|
2014-04-24 19:53:42 +02:00
|
|
|
{
|
|
|
|
if (RCT2_GLOBAL(0x009DE51E, uint8) == 0)
|
2016-01-05 01:02:23 +01:00
|
|
|
gTooltipNotShownTicks = 0;
|
2014-04-24 19:53:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-10-20 20:16:30 +02:00
|
|
|
*
|
2014-04-24 19:53:42 +02:00
|
|
|
* rct2: 0x006EA41D
|
|
|
|
*/
|
2015-07-10 02:39:16 +02:00
|
|
|
static void window_tooltip_paint(rct_window *w, rct_drawpixelinfo *dpi)
|
2014-04-24 19:53:42 +02:00
|
|
|
{
|
|
|
|
int left = w->x;
|
|
|
|
int top = w->y;
|
|
|
|
int right = w->x + w->width - 1;
|
|
|
|
int bottom = w->y + w->height - 1;
|
|
|
|
|
|
|
|
// Background
|
|
|
|
gfx_fill_rect(dpi, left + 1, top + 1, right - 1, bottom - 1, 0x0200002D);
|
|
|
|
gfx_fill_rect(dpi, left + 1, top + 1, right - 1, bottom - 1, 0x02000084);
|
|
|
|
|
|
|
|
// Sides
|
|
|
|
gfx_fill_rect(dpi, left + 0, top + 2, left + 0, bottom - 2, 0x0200002F);
|
|
|
|
gfx_fill_rect(dpi, right + 0, top + 2, right + 0, bottom - 2, 0x0200002F);
|
|
|
|
gfx_fill_rect(dpi, left + 2, bottom + 0, right - 2, bottom + 0, 0x0200002F);
|
|
|
|
gfx_fill_rect(dpi, left + 2, top + 0, right - 2, top + 0, 0x0200002F);
|
|
|
|
|
|
|
|
// Corners
|
|
|
|
gfx_draw_pixel(dpi, left + 1, top + 1, 0x0200002F);
|
|
|
|
gfx_draw_pixel(dpi, right - 1, top + 1, 0x0200002F);
|
|
|
|
gfx_draw_pixel(dpi, left + 1, bottom - 1, 0x0200002F);
|
|
|
|
gfx_draw_pixel(dpi, right - 1, bottom - 1, 0x0200002F);
|
2015-10-20 20:16:30 +02:00
|
|
|
|
2014-04-24 19:53:42 +02:00
|
|
|
// Text
|
2014-10-05 03:51:17 +02:00
|
|
|
left = w->x + ((w->width + 1) / 2) - 1;
|
2015-08-03 19:40:16 +02:00
|
|
|
top = w->y + 1;
|
2015-10-30 15:18:29 +01:00
|
|
|
draw_string_centred_raw(dpi, left, top, RCT2_GLOBAL(RCT2_ADDRESS_TOOLTIP_TEXT_HEIGHT, uint16), (char *)gTooltip_text_buffer);
|
|
|
|
}
|