From 5232fc378bd7ecfdc1e34d24feb2b058fcea1800 Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Wed, 9 Jul 2014 18:05:34 +0100 Subject: [PATCH 1/2] Trying to use the gfx wrap functions. --- src/gfx.h | 1 + src/window_game_bottom_toolbar.c | 6 ++++++ src/window_tooltip.c | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gfx.h b/src/gfx.h index f82ae27d02..a259a76bbf 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -64,6 +64,7 @@ extern int gLastDrawStringY; int gfx_load_g1(); void gfx_load_character_widths(); +int gfx_wrap_string(char* buffer, int width, int* num_lines, int* font_height); void gfx_clear(rct_drawpixelinfo *dpi, int colour); void gfx_draw_pixel(rct_drawpixelinfo *dpi, int x, int y, int colour); void gfx_draw_line(rct_drawpixelinfo *dpi, int x1, int y1, int x2, int y2, int colour); diff --git a/src/window_game_bottom_toolbar.c b/src/window_game_bottom_toolbar.c index 73ad07b02c..79d2a2f83d 100644 --- a/src/window_game_bottom_toolbar.c +++ b/src/window_game_bottom_toolbar.c @@ -250,6 +250,12 @@ static void window_game_bottom_toolbar_tooltip() tool_tip_index = 0; break; } + +#ifdef _MSC_VER + __asm mov ax, tool_tip_index +#else + __asm__("mov ax, %[tool_tip_index] " :[tool_tip_index] "+m" (tool_tip_index)); +#endif } /** diff --git a/src/window_tooltip.c b/src/window_tooltip.c index fc8ebbb22f..a84c03e407 100644 --- a/src/window_tooltip.c +++ b/src/window_tooltip.c @@ -24,6 +24,7 @@ #include "string_ids.h" #include "widget.h" #include "window.h" +#include "gfx.h" enum { WIDX_BACKGROUND @@ -127,7 +128,8 @@ void window_tooltip_open(rct_window *widgetWindow, int widgetIndex, int x, int y esi = 0x0141ED68; edi = ecx + 1; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224; - RCT2_CALLFUNC_X(0x006C21E2, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); + ecx = gfx_wrap_string((char*) 0x0141ED68, ecx + 1, &edi, &ebx); + //RCT2_CALLFUNC_X(0x006C21E2, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); ecx &= 0xFFFF; edi &= 0xFFFF; From 0d144540cc27eaee4d7062d3a69c51597da63c0a Mon Sep 17 00:00:00 2001 From: Duncan Frost Date: Sun, 13 Jul 2014 13:10:14 +0100 Subject: [PATCH 2/2] Fixed gfx_wrap_string error. Cleanedup tooltip --- src/gfx.c | 8 +++----- src/window_tooltip.c | 30 ++++++++++++++---------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/gfx.c b/src/gfx.c index 5d4336432d..3b9e330fe2 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -1585,10 +1585,8 @@ int gfx_wrap_string(char* buffer, int width, int* num_lines, int* font_height) unsigned int max_width = 0; rct_g1_element g1_element; - uint16* current_font_sprite_base = RCT2_ADDRESS(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); - *num_lines = 0; - *font_height = 0; + *font_height = RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16); // Pointer to the start of the current word unsigned char* curr_word = NULL; @@ -1650,7 +1648,7 @@ int gfx_wrap_string(char* buffer, int width, int* num_lines, int* font_height) } } - line_width += RCT2_ADDRESS(RCT2_ADDRESS_FONT_CHAR_WIDTH, uint8)[*current_font_sprite_base + (*curr_char - 0x20)]; + line_width += RCT2_ADDRESS(RCT2_ADDRESS_FONT_CHAR_WIDTH, uint8)[*font_height + (*curr_char - 0x20)]; if ((int)line_width <= width) { continue; @@ -1694,7 +1692,7 @@ int gfx_wrap_string(char* buffer, int width, int* num_lines, int* font_height) line_width = 0; curr_word = 0; } - + if (max_width == 0)return line_width; return max_width; } diff --git a/src/window_tooltip.c b/src/window_tooltip.c index a84c03e407..ee5183b9a0 100644 --- a/src/window_tooltip.c +++ b/src/window_tooltip.c @@ -115,31 +115,29 @@ void window_tooltip_open(rct_window *widgetWindow, int widgetIndex, int x, int y return; RCT2_GLOBAL(0x0142006C, sint32) = -1; + char* buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); - format_string((char*)0x0141ED68, widget->tooltip, (void*)0x013CE952); + format_string(buffer, widget->tooltip, (void*)0x013CE952); RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224; - esi = 0x0141ED68; - RCT2_CALLFUNC_X(0x006C23B1, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - ecx &= 0xFFFF; - if (ecx > 196) - ecx = 196; + int tooltip_text_width = ecx, tooltip_text_height = 0; + //gfx_get_string_width_new_lined + RCT2_CALLFUNC_X(0x006C23B1, &eax, &ebx, &tooltip_text_width, &edx, &buffer, &edi, &ebp); + buffer = RCT2_ADDRESS(RCT2_ADDRESS_COMMON_STRING_FORMAT_BUFFER, char); + tooltip_text_width &= 0xFFFF; + if (tooltip_text_width > 196) + tooltip_text_width = 196; - esi = 0x0141ED68; - edi = ecx + 1; RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_FONT_SPRITE_BASE, uint16) = 224; - ecx = gfx_wrap_string((char*) 0x0141ED68, ecx + 1, &edi, &ebx); - //RCT2_CALLFUNC_X(0x006C21E2, &eax, &ebx, &ecx, &edx, &esi, &edi, &ebp); - ecx &= 0xFFFF; - edi &= 0xFFFF; + tooltip_text_width = gfx_wrap_string(buffer, tooltip_text_width + 1, &tooltip_text_height, &ebx); - RCT2_GLOBAL(0x01420044, sint16) = edi; - width = ecx + 3; - height = ((edi + 1) * 10) + 4; + RCT2_GLOBAL(0x01420044, sint16) = tooltip_text_height; + width = tooltip_text_width + 3; + height = ((tooltip_text_height + 1) * 10) + 4; window_tooltip_widgets[WIDX_BACKGROUND].right = width; window_tooltip_widgets[WIDX_BACKGROUND].bottom = height; - memcpy((void*)0x0141FE44, (void*)0x0141ED68, 512); + memcpy((void*)0x0141FE44, (void*)buffer, 512); x = clamp(0, x - (width / 2), RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_WIDTH, uint16) - width); y = clamp(22, y + 26, RCT2_GLOBAL(RCT2_ADDRESS_SCREEN_HEIGHT, uint16) - height - 40);