From dfd78ec359318439bf927932eb42bfd8bf42dd21 Mon Sep 17 00:00:00 2001 From: Daniel Trujillo Date: Mon, 27 Jun 2016 23:03:41 +0200 Subject: [PATCH] Perform a refactor for compliance with conding style. --- src/interface/window.h | 2 +- src/windows/custom_currency.c | 409 ++++++++++++++++++---------------- src/windows/options.c | 2 +- 3 files changed, 213 insertions(+), 200 deletions(-) diff --git a/src/interface/window.h b/src/interface/window.h index 649da6219b..caf981dc91 100644 --- a/src/interface/window.h +++ b/src/interface/window.h @@ -630,7 +630,7 @@ void ride_construction_toolupdate_entrance_exit(int screenX, int screenY); void ride_construction_toolupdate_construct(int screenX, int screenY); void ride_construction_tooldown_construct(int screenX, int screenY); -void window_custom_currency_open(); +void custom_currency_window_open(); void window_maze_construction_update_pressed_widgets(); void window_track_place_open(const track_design_file_ref *tdFileRef); diff --git a/src/windows/custom_currency.c b/src/windows/custom_currency.c index 0fc8bc9666..dfd3409a0f 100644 --- a/src/windows/custom_currency.c +++ b/src/windows/custom_currency.c @@ -14,108 +14,113 @@ *****************************************************************************/ #pragma endregion +/** + * 'Custom currency configuration' window definition and logic. + */ + +#include "../config.h" +#include "dropdown.h" #include "../localisation/localisation.h" #include "../interface/widget.h" #include "../interface/window.h" -#include "../config.h" -#include "dropdown.h" enum WINDOW_CUSTOM_CURRENCY_WIDGET_IDX { - WIDX_BACKGROUND, - WIDX_TITLE, - WIDX_CLOSE, - WIDX_RATE, - WIDX_RATE_UP, - WIDX_RATE_DOWN, - WIDX_SYMBOL_TEXT, - WIDX_AFFIX_DROPDOWN, - WIDX_AFFIX_DROPDOWN_BUTTON, + WIDX_BACKGROUND, + WIDX_TITLE, + WIDX_CLOSE, + WIDX_RATE, + WIDX_RATE_UP, + WIDX_RATE_DOWN, + WIDX_SYMBOL_TEXT, + WIDX_AFFIX_DROPDOWN, + WIDX_AFFIX_DROPDOWN_BUTTON, }; rct_widget window_custom_currency_widgets[] = { - { WWT_FRAME, 0, 0, 399, 0, 99, 0x0FFFFFFFF, STR_NONE }, - { WWT_CAPTION, 0, 1, 398, 1, 14, STR_CUSTOM_CURRENCY_WINDOW_TITLE, STR_WINDOW_TITLE_TIP }, - { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, - { WWT_SPINNER, 1, 100, 200, 30, 40, 5462, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 189, 199, 31, 35, STR_NUMERIC_UP, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 189, 199, 36, 40, STR_NUMERIC_DOWN, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 120, 200, 50, 60, 0, STR_NONE }, - { WWT_DROPDOWN, 1, 220, 350, 50, 60, 865, STR_NONE }, - { WWT_DROPDOWN_BUTTON, 1, 339, 349, 51, 59, STR_DROPDOWN_GLYPH, STR_NONE }, - { WIDGETS_END }, + { WWT_FRAME, 0, 0, 399, 0, 99, 0x0FFFFFFFF, STR_NONE }, + { WWT_CAPTION, 0, 1, 398, 1, 14, STR_CUSTOM_CURRENCY_WINDOW_TITLE, STR_WINDOW_TITLE_TIP }, + { WWT_CLOSEBOX, 0, 387, 397, 2, 13, STR_CLOSE_X, STR_CLOSE_WINDOW_TIP }, + { WWT_SPINNER, 1, 100, 200, 30, 40, 5462, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 189, 199, 31, 35, STR_NUMERIC_UP, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 189, 199, 36, 40, STR_NUMERIC_DOWN, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 120, 200, 50, 60, 0, STR_NONE }, + { WWT_DROPDOWN, 1, 220, 350, 50, 60, 865, STR_NONE }, + { WWT_DROPDOWN_BUTTON, 1, 339, 349, 51, 59, STR_DROPDOWN_GLYPH, STR_NONE }, + { WIDGETS_END }, }; -static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget); -static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int dropdownIndex); -static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text); -static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi); - -static void invalidate_money_widgets(); - -static rct_window_event_list window_custom_currency_events = { - NULL, - NULL, - NULL, - window_custom_currency_mousedown, - window_custom_currency_dropdown, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - window_custom_currency_text_input, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - window_custom_currency_paint, - NULL +static rct_window_event_list _windowCustomCurrencyEvents = { + NULL, + NULL, + NULL, + custom_currency_window_mousedown, + custom_currency_window_dropdown, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + custom_currency_window_text_input, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + custom_currency_window_paint, + NULL }; +static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct_widget *widget); +static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int dropdownIndex); +static void custom_currency_window_text_input(struct rct_window *w, int windgetIndex, char *text); +static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi); + +static void custom_currency_invalidate_money_widgets(); + /** * - * rct2: 0x0066D2AC + * rct2: 0x0066D2AC */ -void window_custom_currency_open() +void custom_currency_window_open() { - rct_window* window; + rct_window* window; - // Check if window is already open - window = window_bring_to_front_by_class(WC_CUSTOM_CURRENCY_CONFIG); - if (window != NULL) - return; + // Check if window is already open + window = window_bring_to_front_by_class(WC_CUSTOM_CURRENCY_CONFIG); + if(window != NULL) + return; - window = window_create_centred( - 400, - 100, - &window_custom_currency_events, - WC_CUSTOM_CURRENCY_CONFIG, - 0 - ); - window->widgets = window_custom_currency_widgets; - window->enabled_widgets = (1 << WIDX_CLOSE) | - (1 << WIDX_RATE) | - (1 << WIDX_RATE_UP) | - (1 << WIDX_RATE_DOWN) | - (1 << WIDX_SYMBOL_TEXT) | - (1 << WIDX_AFFIX_DROPDOWN) | - (1 << WIDX_AFFIX_DROPDOWN_BUTTON); + window = window_create_centred( + 400, + 100, + &_windowCustomCurrencyEvents, + WC_CUSTOM_CURRENCY_CONFIG, + 0 + ); + window->widgets = window_custom_currency_widgets; + window->enabled_widgets = + (1 << WIDX_CLOSE) | + (1 << WIDX_RATE) | + (1 << WIDX_RATE_UP) | + (1 << WIDX_RATE_DOWN) | + (1 << WIDX_SYMBOL_TEXT) | + (1 << WIDX_AFFIX_DROPDOWN) | + (1 << WIDX_AFFIX_DROPDOWN_BUTTON); - window_init_scroll_widgets(window); - window->colours[0] = 22; - window->colours[1] = 22; - window->colours[2] = 22; + window_init_scroll_widgets(window); + window->colours[0] = 22; + window->colours[1] = 22; + window->colours[2] = 22; } @@ -124,164 +129,172 @@ void window_custom_currency_open() * * rct2: 0x006BB01B */ -static void window_custom_currency_mousedown(int widgetIndex, rct_window*w, rct_widget* widget) +static void custom_currency_window_mousedown(int widgetIndex, rct_window *w, rct_widget *widget) { - widget = &w->widgets[widgetIndex - 1]; + widget = &w->widgets[widgetIndex - 1]; - switch (widgetIndex) { + switch(widgetIndex) { - case WIDX_CLOSE: - window_close(w); - break; + case WIDX_CLOSE: + window_close(w); + break; - case WIDX_RATE_UP: - CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; - gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; - config_save_default(); - invalidate_money_widgets(); - break; + case WIDX_RATE_UP: + CurrencyDescriptors[CURRENCY_CUSTOM].rate += 1; + gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; + config_save_default(); + custom_currency_invalidate_money_widgets(); + break; - case WIDX_RATE_DOWN: - if(CurrencyDescriptors[CURRENCY_CUSTOM].rate > 1) { - CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; - gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; - config_save_default(); - invalidate_money_widgets(); - } - break; + case WIDX_RATE_DOWN: + if(CurrencyDescriptors[CURRENCY_CUSTOM].rate > 1) { + CurrencyDescriptors[CURRENCY_CUSTOM].rate -= 1; + gConfigGeneral.custom_currency_rate = CurrencyDescriptors[CURRENCY_CUSTOM].rate; + config_save_default(); + custom_currency_invalidate_money_widgets(); + } + break; - case WIDX_AFFIX_DROPDOWN_BUTTON: - gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL; - gDropdownItemsArgs[0] = STR_PREFIX; + case WIDX_AFFIX_DROPDOWN_BUTTON: + gDropdownItemsFormat[0] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[0] = STR_PREFIX; - gDropdownItemsFormat[1] = STR_DROPDOWN_MENU_LABEL; - gDropdownItemsArgs[1] = STR_SUFFIX; + gDropdownItemsFormat[1] = STR_DROPDOWN_MENU_LABEL; + gDropdownItemsArgs[1] = STR_SUFFIX; - window_dropdown_show_text_custom_width( - w->x + widget->left, - w->y + widget->top, - widget->bottom - widget->top + 1, - w->colours[1], - DROPDOWN_FLAG_STAY_OPEN, - 2, - widget->right - widget->left - 3 - ); + window_dropdown_show_text_custom_width( + w->x + widget->left, + w->y + widget->top, + widget->bottom - widget->top + 1, + w->colours[1], + DROPDOWN_FLAG_STAY_OPEN, + 2, + widget->right - widget->left - 3 + ); - if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { - dropdown_set_checked(0, true); - } else { - dropdown_set_checked(1, true); - } + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { + dropdown_set_checked(0, true); + } else { + dropdown_set_checked(1, true); + } - break; + break; - case WIDX_SYMBOL_TEXT: - window_text_input_raw_open( w, - WIDX_SYMBOL_TEXT, - STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE, - STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC, - CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - CURRENCY_SYMBOL_MAX_SIZE); - break; + case WIDX_SYMBOL_TEXT: + window_text_input_raw_open( + w, + WIDX_SYMBOL_TEXT, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_TITLE, + STR_CUSTOM_CURRENCY_SYMBOL_INPUT_DESC, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + CURRENCY_SYMBOL_MAX_SIZE + ); + break; - } + } } /** * * rct2: 0x006BB076 */ -static void window_custom_currency_dropdown(rct_window *w, int widgetIndex, int dropdownIndex) +static void custom_currency_window_dropdown(rct_window *w, int widgetIndex, int dropdownIndex) { - if (dropdownIndex == -1) - return; + if(dropdownIndex == -1) + return; - if(widgetIndex == WIDX_AFFIX_DROPDOWN_BUTTON) { + if(widgetIndex == WIDX_AFFIX_DROPDOWN_BUTTON) { - if(dropdownIndex == 0) { - CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_PREFIX; - CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_PREFIX; - } else if(dropdownIndex == 1) { - CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_SUFFIX; - CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_SUFFIX; - } + if(dropdownIndex == 0) { + CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_PREFIX; + CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_PREFIX; + } else if(dropdownIndex == 1) { + CurrencyDescriptors[CURRENCY_CUSTOM].affix_ascii = CURRENCY_SUFFIX; + CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode = CURRENCY_SUFFIX; + } - gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode; - config_save_default(); + gConfigGeneral.custom_currency_affix = CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode; + config_save_default(); - invalidate_money_widgets(); + custom_currency_invalidate_money_widgets(); - } + } } -static void window_custom_currency_text_input(struct rct_window *w, int windgetIndex, char *text) +static void custom_currency_window_text_input(struct rct_window *w, int windgetIndex, char *text) { - if(text != NULL) { - strncpy(CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - text, - CURRENCY_SYMBOL_MAX_SIZE); + if(text != NULL) { + strncpy( + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + text, + CURRENCY_SYMBOL_MAX_SIZE + ); - strncpy(gConfigGeneral.custom_currency_symbol, - CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - CURRENCY_SYMBOL_MAX_SIZE); + strncpy( + gConfigGeneral.custom_currency_symbol, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + CURRENCY_SYMBOL_MAX_SIZE + ); - config_save_default(); - invalidate_money_widgets(); - } + config_save_default(); + custom_currency_invalidate_money_widgets(); + } } -static void invalidate_money_widgets() +static void custom_currency_invalidate_money_widgets() { - widget_invalidate_by_class(WC_BOTTOM_TOOLBAR, 2 /*WIDX_MONEY (not accesible)*/); - widget_invalidate_by_class(WC_CUSTOM_CURRENCY_CONFIG, WIDX_RATE); +// widget_invalidate_by_class(WC_BOTTOM_TOOLBAR, 2 /*WIDX_MONEY (not accesible)*/); + widget_invalidate_by_class(WC_CUSTOM_CURRENCY_CONFIG, WIDX_RATE); + } -/** - * - * rct2: 0x0066D321 - */ -static void window_custom_currency_paint(rct_window *w, rct_drawpixelinfo *dpi) + +static void custom_currency_window_paint(rct_window *w, rct_drawpixelinfo *dpi) { - int x, y; + int x, y; - set_format_arg(0, sint32, 100); + set_format_arg(0, sint32, 100); - window_draw_widgets(w, dpi); + window_draw_widgets(w, dpi); - x = w->x + 10; - y = w->y + 30; + x = w->x + 10; + y = w->y + 30; - gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); + gfx_draw_string_left(dpi, STR_RATE, NULL, w->colours[1], x, y); - sint32 baseExchange = CurrencyDescriptors[CURRENCY_POUNDS].rate; - set_format_arg(0, sint32, baseExchange); - gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x+200, y); + sint32 baseExchange = CurrencyDescriptors[CURRENCY_POUNDS].rate; + set_format_arg(0, sint32, baseExchange); + gfx_draw_string_left(dpi, STR_CUSTOM_CURRENCY_EQUIVALENCY, gCommonFormatArgs, w->colours[1], x + 200, y); - y += 20; + y += 20; - gfx_draw_string_left(dpi, STR_CURRENCY_SYMBOL_TEXT, NULL, w->colours[1], x, y); + gfx_draw_string_left(dpi, STR_CURRENCY_SYMBOL_TEXT, NULL, w->colours[1], x, y); - gfx_draw_string(dpi, - CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, - w->colours[1], - w->x + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1, - w->y + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top); - - if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX){ - gfx_draw_string_left(dpi, - STR_PREFIX, - w, - w->colours[1], - w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, - w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); - } else { - gfx_draw_string_left(dpi, - STR_SUFFIX, - w, - w->colours[1], - w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, - w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top); - } + gfx_draw_string( + dpi, + CurrencyDescriptors[CURRENCY_CUSTOM].symbol_unicode, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].left + 1, + w->y + window_custom_currency_widgets[WIDX_SYMBOL_TEXT].top); + if(CurrencyDescriptors[CURRENCY_CUSTOM].affix_unicode == CURRENCY_PREFIX) { + gfx_draw_string_left( + dpi, + STR_PREFIX, + w, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, + w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top + ); + } else { + gfx_draw_string_left( + dpi, + STR_SUFFIX, + w, + w->colours[1], + w->x + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].left + 1, + w->y + window_custom_currency_widgets[WIDX_AFFIX_DROPDOWN].top + ); + } } diff --git a/src/windows/options.c b/src/windows/options.c index 7754c5e87a..7fbf42a769 100644 --- a/src/windows/options.c +++ b/src/windows/options.c @@ -1194,7 +1194,7 @@ static void window_options_dropdown(rct_window *w, int widgetIndex, int dropdown case WIDX_CURRENCY_DROPDOWN: if(dropdownIndex == CURRENCY_CUSTOM+1) { // Add 1 because the separator occupies a position gConfigGeneral.currency_format = (sint8)dropdownIndex-1; - window_custom_currency_open(); + custom_currency_window_open(); } else { gConfigGeneral.currency_format = (sint8)dropdownIndex; }