From 0d3f2573c6ab40c0e8cdd82de1e9f321611d36f1 Mon Sep 17 00:00:00 2001 From: Paweł Kołodziejski Date: Sat, 21 Feb 2009 09:10:14 +0000 Subject: formating svn-id: r38671 --- engines/sci/gfx/sbtree.cpp | 96 +++++---------- engines/sci/gfx/sci_widgets.cpp | 259 ++++++++++++++-------------------------- 2 files changed, 124 insertions(+), 231 deletions(-) (limited to 'engines/sci/gfx') diff --git a/engines/sci/gfx/sbtree.cpp b/engines/sci/gfx/sbtree.cpp index 5158feefad..03f5de365f 100644 --- a/engines/sci/gfx/sbtree.cpp +++ b/engines/sci/gfx/sbtree.cpp @@ -23,7 +23,7 @@ * */ -/* Static binary lookup tree lookup */ +// Static binary lookup tree lookup #include "common/util.h" #include "sci/include/sci_memory.h" @@ -38,14 +38,11 @@ typedef struct { void *value; } sbcell_t; -int -int_compar(const void *a, const void *b) { +int int_compar(const void *a, const void *b) { return (*((int *)a)) - (*((int *)b)); } - -void -insert_interval(sbcell_t *data, int start, int stop, int *keys, int plus) { +void insert_interval(sbcell_t *data, int start, int stop, int *keys, int plus) { int center = start + ((stop - start) >> 1); data->key = keys[center]; @@ -60,8 +57,7 @@ insert_interval(sbcell_t *data, int start, int stop, int *keys, int plus) { insert_interval(data + plus + 1, center + 1, stop, keys, ((plus << 1) + 1)); } -sbtree_t * -sbtree_new(int size, int *keys) { +sbtree_t *sbtree_new(int size, int *keys) { int table_size = 2; int levels = 0; sbcell_t *table; @@ -79,7 +75,7 @@ sbtree_new(int size, int *keys) { if (table_size > 1) --table_size; - table = (sbcell_t*)sci_calloc(sizeof(sbcell_t), table_size); + table = (sbcell_t *)sci_calloc(sizeof(sbcell_t), table_size); for (i = 0; i < table_size; i++) table[i].key = NOT_A_KEY; @@ -88,7 +84,7 @@ sbtree_new(int size, int *keys) { return NULL; } - tree = (sbtree_t*)sci_malloc(sizeof(sbtree_t)); + tree = (sbtree_t *)sci_malloc(sizeof(sbtree_t)); if (!tree) { error("SBTree: Could not allocate tree structure\n"); @@ -114,9 +110,7 @@ sbtree_new(int size, int *keys) { return tree; } - -void -sbtree_free(sbtree_t *tree) { +void sbtree_free(sbtree_t *tree) { if (!tree) { error("SBTree: Attempt to free NULL sbtree\n"); return; @@ -126,10 +120,7 @@ sbtree_free(sbtree_t *tree) { free(tree); } - -void -sbtree_foreach(sbtree_t *tree, void *args, void *(*operation)(sbtree_t *, const int, - const void *, void *)) { +void sbtree_foreach(sbtree_t *tree, void *args, void *(*operation)(sbtree_t *, const int, const void *, void *)) { int i; sbcell_t *cell = (sbcell_t *) tree->data; @@ -140,14 +131,12 @@ sbtree_foreach(sbtree_t *tree, void *args, void *(*operation)(sbtree_t *, const } } -sbcell_t * -locate(sbcell_t *start, int key, int level, int levels, int plus) { +sbcell_t *locate(sbcell_t *start, int key, int level, int levels, int plus) { int comparison; if (level >= levels && (level != levels || start->key == NOT_A_KEY)) - /* For large tables, the speed improvement caused by this comparison - ** scheme is almost (cough) measurable... - */ + // For large tables, the speed improvement caused by this comparison + // scheme is almost (cough) measurable... return NULL; comparison = key - start->key; @@ -158,9 +147,7 @@ locate(sbcell_t *start, int key, int level, int levels, int plus) { return locate(start + plus + (comparison > 0), key, level + 1, levels, (plus << 1) + (comparison > 0)); } - -int -sbtree_set(sbtree_t *tree, int key, void *value) { +int sbtree_set(sbtree_t *tree, int key, void *value) { sbcell_t *cell = locate((sbcell_t *) tree->data, key, 0, tree->levels, 1); if (cell) @@ -171,9 +158,7 @@ sbtree_set(sbtree_t *tree, int key, void *value) { return 0; } - -void * -sbtree_get(sbtree_t *tree, int key) { +void *sbtree_get(sbtree_t *tree, int key) { sbcell_t *cell = locate((sbcell_t *) tree->data, key, 0, tree->levels, 1); if (cell) @@ -183,10 +168,9 @@ sbtree_get(sbtree_t *tree, int key) { } #if 0 -static void -sbtree_print(sbtree_t *tree) { +static void sbtree_print(sbtree_t *tree) { int l, i; - sbcell_t *cells = (sbcell_t *) tree->data; + sbcell_t *cells = (sbcell_t *)tree->data; error("\tTree:\n"); for (l = 0; l <= tree->levels; l++) { @@ -209,48 +193,45 @@ sbtree_print(sbtree_t *tree) { } #endif - -/***************************** TEST CODE ********************************/ +//**************************** TEST CODE ******************************* #ifdef SBTREE_DEBUG static int any_error; - -void * -foreach_double_func(sbtree_t *tree, const int key, const void *value, void *args) { +void *foreach_double_func(sbtree_t *tree, const int key, const void *value, void *args) { int *real_value = (int *) value; if (!real_value) error("foreach_double_func(): key %d mapped to non-value", key); - else *real_value *= 2; + else + *real_value *= 2; return real_value; } -int * -generate_linear_forward(int numbers) { +int *generate_linear_forward(int numbers) { int i; int *data = sci_malloc(sizeof(int) * numbers); + for (i = 0; i < numbers; i++) data[i] = i + 1; return data; } -int * -generate_linear_backward(int numbers) { +int *generate_linear_backward(int numbers) { int i; int *data = sci_malloc(sizeof(int) * numbers); + for (i = 0; i < numbers; i++) data[i] = numbers - i; return data; } -int * -generate_random(int numbers, int max) { +int *generate_random(int numbers, int max) { int i; int *data = sci_malloc(sizeof(int) * numbers); @@ -260,9 +241,7 @@ generate_random(int numbers, int max) { return data; } - -void -insert_values(sbtree_t *tree, int nr, int *data) { +void insert_values(sbtree_t *tree, int nr, int *data) { int i; for (i = 0; i < nr; i++) @@ -272,14 +251,12 @@ insert_values(sbtree_t *tree, int nr, int *data) { } } - #define MODE_LINEAR 0 #define MODE_LINEAR_MAP 1 #define MODE_RANDOM 2 #define MODE_LINEAR_DOUBLE 3 -void -test_value(sbtree_t *tree, int times, int max, int numbers, int *data, int mode) { +void test_value(sbtree_t *tree, int times, int max, int numbers, int *data, int mode) { int i; int failed = 0; @@ -310,9 +287,7 @@ test_value(sbtree_t *tree, int times, int max, int numbers, int *data, int mode) error("OK\n"); } - -void -test_boundary(sbtree_t *tree, int max, int random) { +void test_boundary(sbtree_t *tree, int max, int random) { int *value_too_low = sbtree_get(tree, 0); int *value_too_high = sbtree_get(tree, max + 1); int *value_low = sbtree_get(tree, 1); @@ -340,9 +315,7 @@ test_boundary(sbtree_t *tree, int max, int random) { } } - -void -test_empty(sbtree_t *tree, int count, int max) { +void test_empty(sbtree_t *tree, int count, int max) { int i; int errors = 0; @@ -362,8 +335,7 @@ test_empty(sbtree_t *tree, int count, int max) { error("OK\n"); } -void -run_test(sbtree_t *tree, int entries, int *data, int random, int max_value) { +void run_test(sbtree_t *tree, int entries, int *data, int random, int max_value) { char *tests[] = {"\tLinear reference test: \t\t", "\tKey map reference test: \t", "\tRandom access test: \t\t"}; int i; @@ -398,20 +370,19 @@ run_test(sbtree_t *tree, int entries, int *data, int random, int max_value) { sbtree_free(tree); } - #define TESTS_NR 11 -int -main(int argc, char **argv) { +int main(int argc, char **argv) { int tests_nr = TESTS_NR; int test_sizes[TESTS_NR] = {1, 2, 3, 7, 8, 9, 1000, 16383, 16384, 16385, 1000000}; int i; + error("sbtree.c Copyright (C) 2000 Christoph Reichenbach \n" "This program is provided WITHOUT WARRANTY of any kind\n" "Please refer to the file COPYING that should have come with this program\n"); error("Static Binary Tree testing facility\n"); - free(malloc(42)); /* Make sure libefence's Copyright message is print here if we're using it */ + free(malloc(42)); // Make sure libefence's Copyright message is print here if we're using it error("\nsbtree.c: Running %d tests.\n", tests_nr); @@ -449,5 +420,4 @@ main(int argc, char **argv) { return 0; } - -#endif /* SBTREE_DEBUG */ +#endif // SBTREE_DEBUG diff --git a/engines/sci/gfx/sci_widgets.cpp b/engines/sci/gfx/sci_widgets.cpp index e39c9a37c8..8d5b48da5a 100644 --- a/engines/sci/gfx/sci_widgets.cpp +++ b/engines/sci/gfx/sci_widgets.cpp @@ -32,9 +32,7 @@ #define SCI_SPECIAL_CHAR_ARROW_UP 0x18 #define SCI_SPECIAL_CHAR_ARROW_DOWN 0x19 - -static void -clear_titlebar(gfxw_port_t *titlebar) { +static void clear_titlebar(gfxw_port_t *titlebar) { if (titlebar->contents) { titlebar->contents->widfree(titlebar->contents); titlebar->contents = NULL; @@ -42,8 +40,7 @@ clear_titlebar(gfxw_port_t *titlebar) { } } -static gfxw_list_t * -make_titlebar_list(state_t *s, rect_t bounds, gfxw_port_t *status_bar) { +static gfxw_list_t *make_titlebar_list(state_t *s, rect_t bounds, gfxw_port_t *status_bar) { gfx_color_t color = status_bar->bgcolor; gfxw_list_t *list; gfxw_box_t *bgbox; @@ -58,21 +55,18 @@ make_titlebar_list(state_t *s, rect_t bounds, gfxw_port_t *status_bar) { return list; } -static gfxw_list_t * -finish_titlebar_list(state_t *s, gfxw_list_t *list, gfxw_port_t *status_bar) { +static gfxw_list_t *finish_titlebar_list(state_t *s, gfxw_list_t *list, gfxw_port_t *status_bar) { gfx_color_t black = s->ega_colors[0]; gfxw_primitive_t *line; - line = gfxw_new_line(Common::Point(0, status_bar->bounds.yl - 1), - Common::Point(status_bar->bounds.xl, status_bar->bounds.yl - 1), + line = gfxw_new_line(Common::Point(0, status_bar->bounds.yl - 1), Common::Point(status_bar->bounds.xl, status_bar->bounds.yl - 1), black, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL); - list->add((gfxw_container_t *) list, (gfxw_widget_t *) line); + list->add((gfxw_container_t *)list, (gfxw_widget_t *)line); return list; } -void -sciw_set_status_bar(state_t *s, gfxw_port_t *status_bar, char *text, int fgcolor, int bgcolor) { +void sciw_set_status_bar(state_t *s, gfxw_port_t *status_bar, char *text, int fgcolor, int bgcolor) { gfx_state_t *state; gfxw_list_t *list; gfx_color_t bg = status_bar->bgcolor; @@ -100,7 +94,7 @@ sciw_set_status_bar(state_t *s, gfxw_port_t *status_bar, char *text, int fgcolor list = make_titlebar_list(s, status_bar->bounds, status_bar); - list->add((gfxw_container_t *) list, (gfxw_widget_t *) textw); + list->add((gfxw_container_t *)list, (gfxw_widget_t *)textw); } else { gfxw_box_t *bgbox = gfxw_new_box(state, gfx_rect(0, 0, status_bar->bounds.xl, status_bar->bounds.yl - 1), @@ -108,7 +102,7 @@ sciw_set_status_bar(state_t *s, gfxw_port_t *status_bar, char *text, int fgcolor list = gfxw_new_list(status_bar->bounds, 0); - list->add((gfxw_container_t *) list, (gfxw_widget_t *) bgbox); + list->add((gfxw_container_t *)list, (gfxw_widget_t *)bgbox); } list->add(GFXWC(status_bar), GFXW(list)); @@ -118,9 +112,8 @@ sciw_set_status_bar(state_t *s, gfxw_port_t *status_bar, char *text, int fgcolor gfxop_update(state); } -static void -sciw_make_window_fit(rect_t *rect, gfxw_port_t *parent) { - /* This window is meant to cover the whole screen, so we allow it to go through. */ +static void sciw_make_window_fit(rect_t *rect, gfxw_port_t *parent) { + // This window is meant to cover the whole screen, so we allow it to go through. if (rect->xl == 319 && rect->yl == 189) return; if (rect->x + rect->xl > parent->bounds.x + parent->bounds.xl) @@ -130,10 +123,8 @@ sciw_make_window_fit(rect_t *rect, gfxw_port_t *parent) { rect->y -= (rect->y + rect->yl) - (parent->bounds.y + parent->bounds.yl) + 2; } -gfxw_port_t * -sciw_new_window(state_t *s, rect_t area, int font, gfx_color_t color, gfx_color_t bgcolor, - int title_font, gfx_color_t title_color, gfx_color_t title_bgcolor, - const char *title, int flags) { +gfxw_port_t *sciw_new_window(state_t *s, rect_t area, int font, gfx_color_t color, gfx_color_t bgcolor, + int title_font, gfx_color_t title_color, gfx_color_t title_bgcolor, const char *title, int flags) { gfxw_visual_t *visual = s->visual; gfx_state_t *state = s->gfx_state; int shadow_offset = 2; @@ -146,20 +137,18 @@ sciw_new_window(state_t *s, rect_t area, int font, gfx_color_t color, gfx_color_ if (area.xl == 319 && area.yl == 189) { flags |= WINDOW_FLAG_NOFRAME; - /* The below line makes the points bar in QfG2 work, but breaks - the one in QfG1. Hm. */ + // The below line makes the points bar in QfG2 work, but breaks + // the one in QfG1. Hm. if ((byte)bgcolor.priority == 255) /* Yep, QfG2 */ area.y += 3; } /* - if (area.y + area.yl > visual->bounds.y + visual->bounds.yl) - { + if (area.y + area.yl > visual->bounds.y + visual->bounds.yl) { area.y -= (area.y + area.yl) - (visual->bounds.y + visual->bounds.yl) + yextra; } - if (area.x + area.xl > visual->bounds.x + visual->bounds.xl) - { + if (area.x + area.xl > visual->bounds.x + visual->bounds.xl) { area.x -= (area.x + area.xl) - (visual->bounds.x + visual->bounds.xl) + xextra; } */ @@ -168,7 +157,7 @@ sciw_new_window(state_t *s, rect_t area, int font, gfx_color_t color, gfx_color_ area. y += 10; if (!(flags & (WINDOW_FLAG_TITLE | WINDOW_FLAG_NOFRAME))) - area.yl -= 1; /* Normal windows are drawn one pixel too small. */ + area.yl -= 1; // Normal windows are drawn one pixel too small. sciw_make_window_fit(&area, s->wm_port); win = gfxw_new_port(visual, s->wm_port, area, color, bgcolor); @@ -183,44 +172,40 @@ sciw_new_window(state_t *s, rect_t area, int font, gfx_color_t color, gfx_color_ flags = WINDOW_FLAG_TRANSPARENT | WINDOW_FLAG_NOFRAME; if (flags == (WINDOW_FLAG_TRANSPARENT | WINDOW_FLAG_NOFRAME)) - return win; /* Fully transparent window */ + return win; // Fully transparent window if (flags & WINDOW_FLAG_TITLE) frame = gfx_rect(area.x - 1, area.y - 10, area.xl + 2, area.yl + 11); else frame = gfx_rect(area.x - 1, area.y - 1, area.xl + 2, area.yl + 2); - /* Set visible window boundaries */ + // Set visible window boundaries win->bounds = gfx_rect(frame.x, frame.y, frame.xl + shadow_offset, frame.yl + shadow_offset); - decorations = gfxw_new_list(gfx_rect(frame.x, frame.y, - frame.xl + 1 + shadow_offset, frame.yl + 1 + shadow_offset), 0); + decorations = gfxw_new_list(gfx_rect(frame.x, frame.y, frame.xl + 1 + shadow_offset, frame.yl + 1 + shadow_offset), 0); if (!(flags & WINDOW_FLAG_TRANSPARENT)) { - /* Draw window background */ - win->port_bg = (gfxw_widget_t *) gfxw_new_box(state, - gfx_rect(1, (flags & WINDOW_FLAG_TITLE) ? 10 : 1, - area.xl, area.yl), - bgcolor, bgcolor, GFX_BOX_SHADE_FLAT); + // Draw window background + win->port_bg = (gfxw_widget_t *)gfxw_new_box(state, gfx_rect(1, (flags & WINDOW_FLAG_TITLE) ? 10 : 1, + area.xl, area.yl), bgcolor, bgcolor, GFX_BOX_SHADE_FLAT); decorations->add((gfxw_container_t *) decorations, win->port_bg); win->flags |= GFXW_FLAG_OPAQUE; } if (flags & WINDOW_FLAG_TITLE) { - /* Add window title */ + // Add window title rect_t title_rect = gfx_rect(1, 1, area.xl, 8); - decorations->add((gfxw_container_t *) decorations, (gfxw_widget_t *) - gfxw_new_box(state, title_rect, title_bgcolor, title_bgcolor, GFX_BOX_SHADE_FLAT)); + decorations->add((gfxw_container_t *)decorations, (gfxw_widget_t *) + gfxw_new_box(state, title_rect, title_bgcolor, title_bgcolor, GFX_BOX_SHADE_FLAT)); - decorations->add((gfxw_container_t *) decorations, (gfxw_widget_t *) - gfxw_new_text(state, title_rect, title_font, title, - ALIGN_CENTER, ALIGN_CENTER, title_color, title_color, - title_bgcolor, GFXR_FONT_FLAG_NO_NEWLINES)); + decorations->add((gfxw_container_t *)decorations, (gfxw_widget_t *) + gfxw_new_text(state, title_rect, title_font, title, ALIGN_CENTER, ALIGN_CENTER, title_color, title_color, + title_bgcolor, GFXR_FONT_FLAG_NO_NEWLINES)); } if (!(flags & WINDOW_FLAG_NOFRAME)) { - /* Draw backdrop shadow */ + // Draw backdrop shadow if (!(flags & WINDOW_FLAG_NO_DROP_SHADOW)) { if (gfxop_set_color(state, &black, 0, 0, 0, 0x80, bgcolor.priority, -1)) { @@ -228,18 +213,16 @@ sciw_new_window(state_t *s, rect_t area, int font, gfx_color_t color, gfx_color_ return NULL; } - decorations->add((gfxw_container_t *) decorations, (gfxw_widget_t *) + decorations->add((gfxw_container_t *)decorations, (gfxw_widget_t *) gfxw_new_box(state, gfx_rect(shadow_offset + 1, frame.yl - 1, - frame.xl - 4, shadow_offset), - black, black, GFX_BOX_SHADE_FLAT)); + frame.xl - 4, shadow_offset), black, black, GFX_BOX_SHADE_FLAT)); - decorations->add((gfxw_container_t *) decorations, (gfxw_widget_t *) + decorations->add((gfxw_container_t *)decorations, (gfxw_widget_t *) gfxw_new_box(state, gfx_rect(frame.xl - 1, shadow_offset + 1, - shadow_offset, frame.yl - 2), - black, black, GFX_BOX_SHADE_FLAT)); + shadow_offset, frame.yl - 2), black, black, GFX_BOX_SHADE_FLAT)); } - /* Draw frame */ + // Draw frame if (gfxop_set_color(state, &black, 0, 0, 0, 0, bgcolor.priority, -1)) { GFXERROR("Could not get black color entry"); @@ -248,21 +231,16 @@ sciw_new_window(state_t *s, rect_t area, int font, gfx_color_t color, gfx_color_ if (!(flags & WINDOW_FLAG_NO_DROP_SHADOW)) { - decorations->add((gfxw_container_t *) decorations, (gfxw_widget_t *) - gfxw_new_rect(gfx_rect(0, 0, frame.xl - 1, frame.yl - 1), - black, GFX_LINE_MODE_FINE, GFX_LINE_STYLE_NORMAL)); + decorations->add((gfxw_container_t *)decorations, (gfxw_widget_t *) + gfxw_new_rect(gfx_rect(0, 0, frame.xl - 1, frame.yl - 1), black, GFX_LINE_MODE_FINE, GFX_LINE_STYLE_NORMAL)); if (flags & WINDOW_FLAG_TITLE) - decorations->add((gfxw_container_t *) decorations, (gfxw_widget_t *) - gfxw_new_line(Common::Point(1, 9), - Common::Point(frame.xl - 2, 9), - black, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL)); + decorations->add((gfxw_container_t *)decorations, (gfxw_widget_t *)gfxw_new_line(Common::Point(1, 9), + Common::Point(frame.xl - 2, 9), black, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL)); } else { - decorations->add((gfxw_container_t *) decorations, (gfxw_widget_t *) - gfxw_new_rect(gfx_rect(0, 0, frame.xl, frame.yl), - black, GFX_LINE_MODE_FINE, GFX_LINE_STYLE_NORMAL)); + decorations->add((gfxw_container_t *)decorations, (gfxw_widget_t *) + gfxw_new_rect(gfx_rect(0, 0, frame.xl, frame.yl), black, GFX_LINE_MODE_FINE, GFX_LINE_STYLE_NORMAL)); } - } win->decorations = decorations; @@ -271,21 +249,14 @@ sciw_new_window(state_t *s, rect_t area, int font, gfx_color_t color, gfx_color_ return win; } +//*** Controls *** - -/*----------------*/ -/**** Controls ****/ -/*----------------*/ -static inline rect_t -_move_and_extend_rect(rect_t rect, Common::Point point, int yplus) { +static inline rect_t _move_and_extend_rect(rect_t rect, Common::Point point, int yplus) { return gfx_rect(rect.x + point.x, rect.y + point.y, rect.xl + 1, rect.yl + yplus); } - -gfxw_list_t * -_sciw_add_text_to_list(gfxw_list_t *list, gfxw_port_t *port, rect_t zone, char *text, - int font, gfx_alignment_t align, char framed, char inverse, int flags, - char gray_text) { +gfxw_list_t *_sciw_add_text_to_list(gfxw_list_t *list, gfxw_port_t *port, rect_t zone, char *text, + int font, gfx_alignment_t align, char framed, char inverse, int flags, char gray_text) { gfx_color_t *color1, *color2, *bgcolor; if (inverse) { @@ -299,25 +270,20 @@ _sciw_add_text_to_list(gfxw_list_t *list, gfxw_port_t *port, rect_t zone, char * bgcolor = &(port->bgcolor); } - list->add(GFXWC(list), GFXW(gfxw_new_text(port->visual->gfx_state, zone, - font, text, align, ALIGN_TOP, + list->add(GFXWC(list), GFXW(gfxw_new_text(port->visual->gfx_state, zone, font, text, align, ALIGN_TOP, *color1, *color2, *bgcolor, flags))); - zone.xl--; zone.yl -= 2; if (framed) { - list->add(GFXWC(list), - GFXW(gfxw_new_rect(zone, *color2, GFX_LINE_MODE_CORRECT, - GFX_LINE_STYLE_STIPPLED))); + list->add(GFXWC(list), GFXW(gfxw_new_rect(zone, *color2, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_STIPPLED))); } return list; } -gfxw_list_t * -sciw_new_button_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int font, char selected, char inverse, char grayed_out) { +gfxw_list_t *sciw_new_button_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int font, char selected, char inverse, char grayed_out) { gfx_color_t *frame_col = (inverse) ? &(port->bgcolor) : &(port->color); gfxw_list_t *list; @@ -357,10 +323,8 @@ sciw_new_button_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, in return list; } - -gfxw_list_t * -sciw_new_text_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int font, - gfx_alignment_t align, char framed, char inverse) { +gfxw_list_t *sciw_new_text_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int font, + gfx_alignment_t align, char framed, char inverse) { gfxw_list_t *list = gfxw_new_list(_move_and_extend_rect(zone, Common::Point(port->zone.x, port->zone.y), 2), 0); gfxw_set_id(GFXW(list), ID.segment, ID.offset); @@ -371,10 +335,8 @@ sciw_new_text_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int return _sciw_add_text_to_list(list, port, zone, text, font, align, framed, inverse, 0, port->gray_text); } - -gfxw_list_t * -sciw_new_edit_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int font, unsigned int cursor, - char inverse) { +gfxw_list_t *sciw_new_edit_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int font, unsigned int cursor, + char inverse) { gfxw_text_t *text_handle; long draw_cursor; long foo; @@ -396,22 +358,20 @@ sciw_new_edit_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int draw_cursor = draw_cursor > 500000; if (!draw_cursor) { - text_handle = gfxw_new_text(port->visual->gfx_state, zone, - font, text, ALIGN_LEFT, ALIGN_TOP, + text_handle = gfxw_new_text(port->visual->gfx_state, zone, font, text, ALIGN_LEFT, ALIGN_TOP, port->color, port->color, port->bgcolor, GFXR_FONT_FLAG_NO_NEWLINES); list->add(GFXWC(list), GFXW(text_handle)); } else { - char *textdup = (char*)sci_malloc(strlen(text) + 1); + char *textdup = (char *)sci_malloc(strlen(text) + 1); strncpy(textdup, text, cursor); if (cursor <= strlen(text)) - textdup[cursor] = 0; /* terminate */ + textdup[cursor] = 0; // terminate if (cursor > 0) { - text_handle = gfxw_new_text(port->visual->gfx_state, zone, - font, textdup, ALIGN_LEFT, ALIGN_TOP, + text_handle = gfxw_new_text(port->visual->gfx_state, zone, font, textdup, ALIGN_LEFT, ALIGN_TOP, port->color, port->color, port->bgcolor, GFXR_FONT_FLAG_NO_NEWLINES); list->add(GFXWC(list), GFXW(text_handle)); @@ -421,40 +381,33 @@ sciw_new_edit_control(gfxw_port_t *port, reg_t ID, rect_t zone, char *text, int if (cursor < strlen(text)) { textdup[0] = text[cursor]; textdup[1] = 0; - text_handle = gfxw_new_text(port->visual->gfx_state, zone, - font, textdup, ALIGN_LEFT, ALIGN_TOP, + text_handle = gfxw_new_text(port->visual->gfx_state, zone, font, textdup, ALIGN_LEFT, ALIGN_TOP, port->bgcolor, port->bgcolor, port->color, GFXR_FONT_FLAG_NO_NEWLINES); list->add(GFXWC(list), GFXW(text_handle)); zone.x += text_handle->width; }; if (cursor + 1 < strlen(text)) { - text_handle = gfxw_new_text(port->visual->gfx_state, zone, - font, text + cursor + 1, ALIGN_LEFT, ALIGN_TOP, + text_handle = gfxw_new_text(port->visual->gfx_state, zone, font, text + cursor + 1, ALIGN_LEFT, ALIGN_TOP, port->color, port->color, port->bgcolor, GFXR_FONT_FLAG_NO_NEWLINES); list->add(GFXWC(list), GFXW(text_handle)); zone.x += text_handle->width; }; if (cursor == strlen(text)) - list->add(GFXWC(list), GFXW(gfxw_new_line(Common::Point(zone.x, zone.y), - Common::Point(zone.x, zone.y + cursor_height - 1), + list->add(GFXWC(list), GFXW(gfxw_new_line(Common::Point(zone.x, zone.y), Common::Point(zone.x, zone.y + cursor_height - 1), port->color, GFX_LINE_MODE_FAST, GFX_LINE_STYLE_NORMAL))); free(textdup); } - zone.x = zone.y = 0; - list->add(GFXWC(list), - GFXW(gfxw_new_rect(zone, port->color, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL))); + list->add(GFXWC(list), GFXW(gfxw_new_rect(zone, port->color, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL))); return list; } - -gfxw_list_t * -sciw_new_icon_control(gfxw_port_t *port, reg_t ID, rect_t zone, int view, int loop, int cel, +gfxw_list_t *sciw_new_icon_control(gfxw_port_t *port, reg_t ID, rect_t zone, int view, int loop, int cel, char frame, char inverse) { gfxw_list_t *list = gfxw_new_list(_move_and_extend_rect(zone, Common::Point(port->zone.x, port->zone.y), 1), 0); gfxw_widget_t *icon; @@ -483,9 +436,7 @@ sciw_new_icon_control(gfxw_port_t *port, reg_t ID, rect_t zone, int view, int lo return list; } - -gfxw_list_t * -sciw_new_list_control(gfxw_port_t *port, reg_t ID, rect_t zone, int font_nr, char **entries_list, +gfxw_list_t *sciw_new_list_control(gfxw_port_t *port, reg_t ID, rect_t zone, int font_nr, char **entries_list, int entries_nr, int list_top, int selection, char inverse) { gfxw_list_t *list; @@ -522,10 +473,9 @@ sciw_new_list_control(gfxw_port_t *port, reg_t ID, rect_t zone, int font_nr, cha zone.x = 1; zone.y = 11; - /* Draw text */ + // Draw text for (i = list_top; columns-- && i < entries_nr; i++) { - if (i != selection) list->add(GFXWC(list), GFXW(gfxw_new_text(port->visual->gfx_state, gfx_rect(zone.x, zone.y, zone.xl - 2, font_height), @@ -534,8 +484,7 @@ sciw_new_list_control(gfxw_port_t *port, reg_t ID, rect_t zone, int font_nr, cha else { list->add(GFXWC(list), GFXW(gfxw_new_box(port->visual->gfx_state, gfx_rect(zone.x, zone.y, zone.xl - 1, font_height), port->color, port->color, GFX_BOX_SHADE_FLAT))); - list->add(GFXWC(list), - GFXW(gfxw_new_text(port->visual->gfx_state, gfx_rect(zone.x, zone.y, zone.xl - 2, font_height), + list->add(GFXWC(list), GFXW(gfxw_new_text(port->visual->gfx_state, gfx_rect(zone.x, zone.y, zone.xl - 2, font_height), font_nr, entries_list[i], ALIGN_LEFT, ALIGN_TOP, port->bgcolor, port->bgcolor, port->color, GFXR_FONT_FLAG_NO_NEWLINES))); } @@ -543,37 +492,29 @@ sciw_new_list_control(gfxw_port_t *port, reg_t ID, rect_t zone, int font_nr, cha zone.y += font_height; } - /* Draw frames */ + // Draw frames zone.x = 0; zone.y = 0; - /* Add up arrow */ - list->add(GFXWC(list), - GFXW(gfxw_new_text(port->visual->gfx_state, gfx_rect(1, 0, zone.xl - 2, 8), + // Add up arrow + list->add(GFXWC(list), GFXW(gfxw_new_text(port->visual->gfx_state, gfx_rect(1, 0, zone.xl - 2, 8), port->font_nr, arr_up, ALIGN_CENTER, ALIGN_CENTER, port->color, port->color, port->bgcolor, 0))); - /* Add down arrow */ - list->add(GFXWC(list), - GFXW(gfxw_new_text(port->visual->gfx_state, gfx_rect(1, zone.yl - 9, zone.xl - 2, 8), + // Add down arrow + list->add(GFXWC(list), GFXW(gfxw_new_text(port->visual->gfx_state, gfx_rect(1, zone.yl - 9, zone.xl - 2, 8), port->font_nr, arr_down, ALIGN_CENTER, ALIGN_CENTER, port->color, port->color, port->bgcolor, 0))); - if (list_top & 1) { /* Hack to work around aggressive caching */ - - list->add(GFXWC(list), - GFXW(gfxw_new_rect(zone, port->color, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL))); - - list->add(GFXWC(list), - GFXW(gfxw_new_rect(gfx_rect(zone.x, zone.y + 10, zone.xl, zone.yl - 20), + if (list_top & 1) { // Hack to work around aggressive caching + list->add(GFXWC(list), GFXW(gfxw_new_rect(zone, port->color, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL))); + list->add(GFXWC(list), GFXW(gfxw_new_rect(gfx_rect(zone.x, zone.y + 10, zone.xl, zone.yl - 20), port->color, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL))); } else { - list->add(GFXWC(list), GFXW(gfxw_new_rect(gfx_rect(zone.x, zone.y, zone.xl, zone.yl - 10), port->color, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL))); - list->add(GFXWC(list), GFXW(gfxw_new_rect(gfx_rect(zone.x, zone.y + 10, zone.xl, zone.yl - 10), port->color, GFX_LINE_MODE_CORRECT, GFX_LINE_STYLE_NORMAL))); @@ -582,9 +523,7 @@ sciw_new_list_control(gfxw_port_t *port, reg_t ID, rect_t zone, int font_nr, cha return list; } - -void -sciw_set_menubar(state_t *s, gfxw_port_t *status_bar, menubar_t *menubar, int selection) { +void sciw_set_menubar(state_t *s, gfxw_port_t *status_bar, menubar_t *menubar, int selection) { gfxw_list_t *list = make_titlebar_list(s, status_bar->bounds, status_bar); int offset = MENU_LEFT_BORDER; int i; @@ -598,16 +537,13 @@ sciw_set_menubar(state_t *s, gfxw_port_t *status_bar, menubar_t *menubar, int se if (i == selection) { list->add(GFXWC(list), GFXW(gfxw_new_box(status_bar->visual->gfx_state, gfx_rect(offset, 0, width, MENU_BAR_HEIGHT), status_bar->color, status_bar->color, GFX_BOX_SHADE_FLAT))); - list->add(GFXWC(list), - GFXW(gfxw_new_text(s->gfx_state, gfx_rect(offset, 0, width, MENU_BAR_HEIGHT), + list->add(GFXWC(list), GFXW(gfxw_new_text(s->gfx_state, gfx_rect(offset, 0, width, MENU_BAR_HEIGHT), status_bar->font_nr, menu->title, ALIGN_CENTER, ALIGN_CENTER, status_bar->bgcolor, status_bar->bgcolor, status_bar->color, GFXR_FONT_FLAG_NO_NEWLINES))); } else - list->add(GFXWC(list), - GFXW(gfxw_new_text(s->gfx_state, gfx_rect(offset, 0, width, MENU_BAR_HEIGHT), + list->add(GFXWC(list), GFXW(gfxw_new_text(s->gfx_state, gfx_rect(offset, 0, width, MENU_BAR_HEIGHT), status_bar->font_nr, menu->title, ALIGN_CENTER, ALIGN_CENTER, status_bar->color, status_bar->color, status_bar->bgcolor, GFXR_FONT_FLAG_NO_NEWLINES))); - offset += width; } @@ -615,8 +551,7 @@ sciw_set_menubar(state_t *s, gfxw_port_t *status_bar, menubar_t *menubar, int se finish_titlebar_list(s, list, status_bar); } -gfxw_port_t * -sciw_new_menu(state_t *s, gfxw_port_t *status_bar, menubar_t *menubar, int selection) { +gfxw_port_t *sciw_new_menu(state_t *s, gfxw_port_t *status_bar, menubar_t *menubar, int selection) { gfxw_port_t *retval; menu_t *menu = menubar->menus + selection; rect_t area = gfx_rect(MENU_LEFT_BORDER, 10, 0, 0); @@ -637,8 +572,7 @@ sciw_new_menu(state_t *s, gfxw_port_t *status_bar, menubar_t *menubar, int selec area.yl = menu->items_nr * 10; retval = sciw_new_window(s, area, status_bar->font_nr, status_bar->color, status_bar->bgcolor, - 0, status_bar->color, status_bar->bgcolor, - NULL, WINDOW_FLAG_NO_DROP_SHADOW | WINDOW_FLAG_TRANSPARENT); + 0, status_bar->color, status_bar->bgcolor, NULL, WINDOW_FLAG_NO_DROP_SHADOW | WINDOW_FLAG_TRANSPARENT); retval->set_visual(GFXW(retval), s->visual); @@ -650,20 +584,18 @@ sciw_new_menu(state_t *s, gfxw_port_t *status_bar, menubar_t *menubar, int selec #define MAGIC_ID_OFFSET 0x2000 -static inline gfx_color_t -un_prioritize(gfx_color_t col) { +static inline gfx_color_t un_prioritize(gfx_color_t col) { col.priority = -1; col.mask &= ~GFX_MASK_PRIORITY; return col; } -gfxw_widget_t * -_make_menu_entry(menu_item_t *item, int offset, int width, gfxw_port_t *port, gfx_color_t color, gfx_color_t bgcolor, int ID, int gray) { - rect_t area = gfx_rect(MENU_BOX_LEFT_PADDING, 0, width - MENU_BOX_LEFT_PADDING, 10); - rect_t list_area = gfx_rect(port->zone.x, area.y + offset + port->zone.y, width, area.yl); - gfxw_list_t *list = (gfxw_list_t *) gfxw_set_id(GFXW(gfxw_new_list(list_area, 0)), ID, GFXW_NO_ID); - gfx_color_t xcolor = {{0, 0, 0, 0}, 0, 0, 0, 0}; +gfxw_widget_t *_make_menu_entry(menu_item_t *item, int offset, int width, gfxw_port_t *port, gfx_color_t color, gfx_color_t bgcolor, int ID, int gray) { + rect_t area = gfx_rect(MENU_BOX_LEFT_PADDING, 0, width - MENU_BOX_LEFT_PADDING, 10); + rect_t list_area = gfx_rect(port->zone.x, area.y + offset + port->zone.y, width, area.yl); + gfxw_list_t *list = (gfxw_list_t *) gfxw_set_id(GFXW(gfxw_new_list(list_area, 0)), ID, GFXW_NO_ID); + gfx_color_t xcolor = {{0, 0, 0, 0}, 0, 0, 0, 0}; color = un_prioritize(color); bgcolor = un_prioritize(bgcolor); @@ -683,8 +615,7 @@ _make_menu_entry(menu_item_t *item, int offset, int width, gfxw_port_t *port, gf return GFXW(list); } -gfxw_widget_t * -_make_menu_hbar(int offset, int width, gfxw_port_t *port, gfx_color_t color, gfx_color_t bgcolor, int ID) { +gfxw_widget_t *_make_menu_hbar(int offset, int width, gfxw_port_t *port, gfx_color_t color, gfx_color_t bgcolor, int ID) { rect_t area = gfx_rect(0, 0, width, 10); rect_t list_area = gfx_rect(area.x + port->zone.x, area.y + offset + port->zone.y, area.xl, area.yl); gfxw_list_t *list = (gfxw_list_t *) gfxw_set_id(GFXW(gfxw_new_list(list_area, 0)), ID, GFXW_NO_ID); @@ -693,16 +624,13 @@ _make_menu_hbar(int offset, int width, gfxw_port_t *port, gfx_color_t color, gfx bgcolor = un_prioritize(bgcolor); list->add(GFXWC(list), GFXW(gfxw_new_box(port->visual->gfx_state, area, bgcolor, bgcolor, GFX_BOX_SHADE_FLAT))); - list->add(GFXWC(list), GFXW(gfxw_new_line(Common::Point(0, 5), - Common::Point(width, 5), - color, + list->add(GFXWC(list), GFXW(gfxw_new_line(Common::Point(0, 5), Common::Point(width, 5), color, GFX_LINE_MODE_FAST, GFX_LINE_STYLE_STIPPLED))); return GFXW(list); } -gfxw_port_t * -sciw_unselect_item(state_t *s, gfxw_port_t *menu_port, menu_t *menu, int selection) { +gfxw_port_t *sciw_unselect_item(state_t *s, gfxw_port_t *menu_port, menu_t *menu, int selection) { menu_item_t *item = menu->items + selection; if (selection < 0 || selection >= menu->items_nr) @@ -710,19 +638,16 @@ sciw_unselect_item(state_t *s, gfxw_port_t *menu_port, menu_t *menu, int selecti if (item->type == MENU_TYPE_NORMAL) menu_port->add(GFXWC(menu_port), GFXW(_make_menu_entry(item, selection * 10, menu_port->zone.xl + 1, - menu_port, menu_port->color, - menu_port->bgcolor, selection + MAGIC_ID_OFFSET, + menu_port, menu_port->color, menu_port->bgcolor, selection + MAGIC_ID_OFFSET, item->enabled))); else menu_port->add(GFXWC(menu_port), GFXW(_make_menu_hbar(selection * 10, menu_port->zone.xl + 1, - menu_port, menu_port->color, - menu_port->bgcolor, selection + MAGIC_ID_OFFSET))); + menu_port, menu_port->color, menu_port->bgcolor, selection + MAGIC_ID_OFFSET))); return menu_port; } -gfxw_port_t * -sciw_select_item(state_t *s, gfxw_port_t *menu_port, menu_t *menu, int selection) { +gfxw_port_t *sciw_select_item(state_t *s, gfxw_port_t *menu_port, menu_t *menu, int selection) { menu_item_t *item = menu->items + selection; if (selection < 0 || selection >= menu->items_nr) @@ -730,13 +655,11 @@ sciw_select_item(state_t *s, gfxw_port_t *menu_port, menu_t *menu, int selection if (item->type == MENU_TYPE_NORMAL) menu_port->add(GFXWC(menu_port), GFXW(_make_menu_entry(item, selection * 10, menu_port->zone.xl + 1, - menu_port, menu_port->bgcolor, - menu_port->color, selection + MAGIC_ID_OFFSET, + menu_port, menu_port->bgcolor, menu_port->color, selection + MAGIC_ID_OFFSET, item->enabled))); else menu_port->add(GFXWC(menu_port), GFXW(_make_menu_hbar(selection * 10, menu_port->zone.xl + 1, - menu_port, menu_port->bgcolor, - menu_port->color, selection + MAGIC_ID_OFFSET))); + menu_port, menu_port->bgcolor, menu_port->color, selection + MAGIC_ID_OFFSET))); return menu_port; } -- cgit v1.2.3