From 16676278947035069f71c6cee3fbf35724ea8db1 Mon Sep 17 00:00:00 2001 From: Nathan Woods Date: Fri, 31 Jan 2014 03:11:57 +0000 Subject: [PATCH] Minor refactorings --- src/emu/ui/ui.c | 96 ++++++++++++++++++++++++++++++++++++------------- src/emu/ui/ui.h | 4 +++ 2 files changed, 75 insertions(+), 25 deletions(-) diff --git a/src/emu/ui/ui.c b/src/emu/ui/ui.c index dbc5ba9a91c..b7a54718e22 100644 --- a/src/emu/ui/ui.c +++ b/src/emu/ui/ui.c @@ -540,11 +540,23 @@ float ui_manager::get_string_width(const char *s) void ui_manager::draw_outlined_box(render_container *container, float x0, float y0, float x1, float y1, rgb_t backcolor) { - container->add_rect(x0, y0, x1, y1, backcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - container->add_line(x0, y0, x1, y0, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - container->add_line(x1, y0, x1, y1, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - container->add_line(x1, y1, x0, y1, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); - container->add_line(x0, y1, x0, y0, UI_LINE_WIDTH, UI_BORDER_COLOR, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + draw_outlined_box(container, x0, y0, x1, y1, UI_BORDER_COLOR, backcolor); +} + + +//------------------------------------------------- +// draw_outlined_box - add primitives to draw +// an outlined box with the given background +// color +//------------------------------------------------- + +void ui_manager::draw_outlined_box(render_container *container, float x0, float y0, float x1, float y1, rgb_t fgcolor, rgb_t bgcolor) +{ + container->add_rect(x0, y0, x1, y1, bgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + container->add_line(x0, y0, x1, y0, UI_LINE_WIDTH, fgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + container->add_line(x1, y0, x1, y1, UI_LINE_WIDTH, fgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + container->add_line(x1, y1, x0, y1, UI_LINE_WIDTH, fgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); + container->add_line(x0, y1, x0, y0, UI_LINE_WIDTH, fgcolor, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); } @@ -1339,6 +1351,58 @@ void ui_manager::process_natural_keyboard() } +//------------------------------------------------- +// increase_frameskip +//------------------------------------------------- + +void ui_manager::increase_frameskip() +{ + // get the current value and increment it + int newframeskip = machine().video().frameskip() + 1; + if (newframeskip > MAX_FRAMESKIP) + newframeskip = -1; + machine().video().set_frameskip(newframeskip); + + // display the FPS counter for 2 seconds + machine().ui().show_fps_temp(2.0); +} + + +//------------------------------------------------- +// decrease_frameskip +//------------------------------------------------- + +void ui_manager::decrease_frameskip() +{ + // get the current value and decrement it + int newframeskip = machine().video().frameskip() - 1; + if (newframeskip < -1) + newframeskip = MAX_FRAMESKIP; + machine().video().set_frameskip(newframeskip); + + // display the FPS counter for 2 seconds + machine().ui().show_fps_temp(2.0); +} + + +//------------------------------------------------- +// can_paste +//------------------------------------------------- + +bool ui_manager::can_paste() +{ + // retrieve the clipboard text + char *text = osd_get_clipboard_text(); + + // free the string if allocated + if (text != NULL) + osd_free(text); + + // did we have text? + return text != NULL; +} + + //------------------------------------------------- // paste - does a paste from the keyboard //------------------------------------------------- @@ -1549,29 +1613,11 @@ UINT32 ui_manager::handler_ingame(running_machine &machine, render_container *co // increment frameskip? if (ui_input_pressed(machine, IPT_UI_FRAMESKIP_INC)) - { - // get the current value and increment it - int newframeskip = machine.video().frameskip() + 1; - if (newframeskip > MAX_FRAMESKIP) - newframeskip = -1; - machine.video().set_frameskip(newframeskip); - - // display the FPS counter for 2 seconds - machine.ui().show_fps_temp(2.0); - } + machine.ui().increase_frameskip(); // decrement frameskip? if (ui_input_pressed(machine, IPT_UI_FRAMESKIP_DEC)) - { - // get the current value and decrement it - int newframeskip = machine.video().frameskip() - 1; - if (newframeskip < -1) - newframeskip = MAX_FRAMESKIP; - machine.video().set_frameskip(newframeskip); - - // display the FPS counter for 2 seconds - machine.ui().show_fps_temp(2.0); - } + machine.ui().decrease_frameskip(); // toggle throttle? if (ui_input_pressed(machine, IPT_UI_THROTTLE)) diff --git a/src/emu/ui/ui.h b/src/emu/ui/ui.h index 875f42bd6fe..6d4e299a3bf 100644 --- a/src/emu/ui/ui.h +++ b/src/emu/ui/ui.h @@ -134,6 +134,7 @@ public: float get_char_width(unicode_char ch); float get_string_width(const char *s); void draw_outlined_box(render_container *container, float x0, float y0, float x1, float y1, rgb_t backcolor); + void draw_outlined_box(render_container *container, float x0, float y0, float x1, float y1, rgb_t fgcolor, rgb_t bgcolor); void draw_text(render_container *container, const char *buf, float x, float y); void draw_text_full(render_container *container, const char *origs, float x, float y, float origwrapwidth, int justify, int wrap, int draw, rgb_t fgcolor, rgb_t bgcolor, float *totalwidth = NULL, float *totalheight = NULL); void draw_text_box(render_container *container, const char *text, int justify, float xpos, float ypos, rgb_t backcolor); @@ -149,10 +150,13 @@ public: void show_menu(); void show_mouse(bool status); bool is_menu_active(); + bool can_paste(); void paste(); bool use_natural_keyboard() const; void set_use_natural_keyboard(bool use_natural_keyboard); void image_handler_ingame(); + void increase_frameskip(); + void decrease_frameskip(); // print the game info string into a buffer astring &game_info_astring(astring &string);