From ced40b2266976d0129294a1c5925b7d88024b2de Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sun, 8 Mar 2009 20:17:01 +0000 Subject: Use new Palette class to manager pixmap palettes. There are some remaining regressions with text colour in SCI1 games, but overall it should fix more than it breaks. svn-id: r39242 --- engines/sci/engine/game.cpp | 36 +++++++++++------------------ engines/sci/engine/kgraphics.cpp | 49 +++++++++++++++++++++------------------- engines/sci/engine/kmenu.cpp | 4 ++-- engines/sci/engine/kpathing.cpp | 10 ++------ engines/sci/engine/state.h | 2 +- 5 files changed, 44 insertions(+), 57 deletions(-) (limited to 'engines/sci/engine') diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index 572fe9dc90..c84637b2bc 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -101,28 +101,14 @@ static int _init_graphics_input(EngineState *s) { } static void _sci1_alloc_system_colors(EngineState *s) { - gfx_color_t white; - gfx_color_t black; - - white.visual.global_index = 255; - white.visual.r = white.visual.g = white.visual.b = 255; - white.alpha = 0; - white.priority = white.control = 0; - white.mask = GFX_MASK_VISUAL; - gfxop_set_system_color(s->gfx_state, &white); - - black.visual.global_index = 0; - black.visual.r = black.visual.g = black.visual.b = 0; - black.alpha = 0; - black.priority = black.control = 0; - black.mask = GFX_MASK_VISUAL; - gfxop_set_system_color(s->gfx_state, &black); + gfx_color_t black = { PaletteEntry(0, 0, 0), 0, 0, 0, GFX_MASK_VISUAL }; + gfxop_set_system_color(s->gfx_state, 0, &black); } int _reset_graphics_input(EngineState *s) { Resource *resource; int font_nr; - gfx_color_t transparent = { { -1, 0, 0, 0 }, 0, -1, -1, 0 }; + gfx_color_t transparent = { PaletteEntry(), 0, -1, -1, 0 }; sciprintf("Initializing graphics\n"); if (s->resmgr->_sciVersion <= SCI_VERSION_01) { @@ -133,24 +119,28 @@ int _reset_graphics_input(EngineState *s) { gfx_sci0_image_colors[sci0_palette][i].g, gfx_sci0_image_colors[sci0_palette][i].b, 0, -1, -1)) { return 1; } - gfxop_set_system_color(s->gfx_state, &(s->ega_colors[i])); + gfxop_set_system_color(s->gfx_state, i, &(s->ega_colors[i])); } } else { // Check for Amiga palette file. Common::File file; if (file.open("spal")) { - s->gfx_state->resstate->static_palette = gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, file); + if (s->gfx_state->resstate->static_palette) + s->gfx_state->resstate->static_palette->free(); + s->gfx_state->resstate->static_palette = gfxr_read_pal1_amiga(file); + s->gfx_state->resstate->static_palette->name = "static palette"; file.close(); _sci1_alloc_system_colors(s); } else { resource = s->resmgr->findResource(kResourceTypePalette, 999, 1); if (resource) { + if (s->gfx_state->resstate->static_palette) + s->gfx_state->resstate->static_palette->free(); if (s->version < SCI_VERSION(1, 001, 000)) - s->gfx_state->resstate->static_palette = gfxr_read_pal1(999, &s->gfx_state->resstate->static_palette_entries, - resource->data, resource->size); + s->gfx_state->resstate->static_palette = gfxr_read_pal1(999, resource->data, resource->size); else - s->gfx_state->resstate->static_palette = gfxr_read_pal11(999, &s->gfx_state->resstate->static_palette_entries, - resource->data, resource->size); + s->gfx_state->resstate->static_palette = gfxr_read_pal11(999, resource->data, resource->size); + s->gfx_state->resstate->static_palette->name = "static palette"; _sci1_alloc_system_colors(s); s->resmgr->unlockResource(resource, 999, kResourceTypePalette); } else { diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index ff615e688e..b9a7d0036c 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -264,24 +264,26 @@ void graph_restore_box(EngineState *s, reg_t handle) { #define KERNEL_COLOR_PALETTE s->gfx_state->pic->visual_map->colors #define KERNEL_COLORS_NR s->gfx_state->pic->visual_map->colors_nr #else -#define KERNEL_COLOR_PALETTE s->gfx_state->resstate->static_palette -#define KERNEL_COLORS_NR s->gfx_state->resstate->static_palette_entries +#define KERNEL_COLOR_PALETTE (s->gfx_state->resstate->static_palette) +#define KERNEL_COLORS_NR (s->gfx_state->resstate->static_palette ? s->gfx_state->resstate->static_palette->size() : 0) #endif -static gfx_pixmap_color_t white = {GFX_COLOR_INDEX_UNMAPPED, 255, 255, 255}; +//static gfx_pixmap_color_t white = {GFX_COLOR_INDEX_UNMAPPED, 255, 255, 255}; -gfx_pixmap_color_t *get_pic_color(EngineState *s, int color) { +//PaletteEntry white(255, 255, 255); + +PaletteEntry get_pic_color(EngineState *s, int color) { if (s->resmgr->_sciVersion < SCI_VERSION_01_VGA) - return &(s->ega_colors[color].visual); + return s->ega_colors[color].visual; if (color == 255) - return &white; - else if (color < KERNEL_COLORS_NR) - return &(KERNEL_COLOR_PALETTE[color]); + return PaletteEntry(255,255,255); + else if (color < (int)KERNEL_COLORS_NR) + return KERNEL_COLOR_PALETTE->getColor(color); else { SCIkwarn(SCIkERROR, "Color index %d out of bounds for pic %d (%d max)", color, s->gfx_state->pic_nr, KERNEL_COLORS_NR); BREAKPOINT(); - return NULL; + return PaletteEntry(0,0,0); } } @@ -293,7 +295,7 @@ static gfx_color_t graph_map_color(EngineState *s, int color, int priority, int gfxop_set_color(s->gfx_state, &retval, (color < 0) ? -1 : retval.visual.r, retval.visual.g, retval.visual.b, (color == -1) ? 255 : 0, priority, control); } else { - retval.visual = *(get_pic_color(s, color)); + retval.visual = get_pic_color(s, color); retval.alpha = 0; retval.priority = priority; retval.control = control; @@ -1276,10 +1278,10 @@ reg_t kPalette(EngineState *s, int funct_nr, int argc, reg_t *argv) { int i, delta, bestindex = -1, bestdelta = 200000; - for (i = 0; i < KERNEL_COLORS_NR; i++) { - int dr = abs(KERNEL_COLOR_PALETTE[i].r - r); - int dg = abs(KERNEL_COLOR_PALETTE[i].g - g); - int db = abs(KERNEL_COLOR_PALETTE[i].b - b); + for (i = 0; i < (int)KERNEL_COLORS_NR; i++) { + int dr = abs(KERNEL_COLOR_PALETTE->getColor(i).r - r); + int dg = abs(KERNEL_COLOR_PALETTE->getColor(i).g - g); + int db = abs(KERNEL_COLOR_PALETTE->getColor(i).b - b); delta = dr * dr + dg * dg + db * db; @@ -2464,9 +2466,9 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) { if (SKPV_OR_ALT(8 + argextra, 255) >= 0) { if (s->resmgr->_sciVersion < SCI_VERSION_01_VGA) - bgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(8 + argextra, 15))); + bgcolor.visual = get_pic_color(s, SKPV_OR_ALT(8 + argextra, 15)); else - bgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(8 + argextra, 255))); + bgcolor.visual = get_pic_color(s, SKPV_OR_ALT(8 + argextra, 255)); bgcolor.mask = GFX_MASK_VISUAL; } @@ -2475,13 +2477,14 @@ reg_t kNewWindow(EngineState *s, int funct_nr, int argc, reg_t *argv) { bgcolor.alpha = 0; SCIkdebug(SCIkGRAPHICS, "New window with params %d, %d, %d, %d\n", SKPV(0), SKPV(1), SKPV(2), SKPV(3)); - fgcolor.visual = *(get_pic_color(s, SKPV_OR_ALT(7 + argextra, 0))); + fgcolor.visual = get_pic_color(s, SKPV_OR_ALT(7 + argextra, 0)); fgcolor.mask = GFX_MASK_VISUAL; fgcolor.alpha = 0; - black.visual = *(get_pic_color(s, 0)); + black.visual = get_pic_color(s, 0); black.mask = GFX_MASK_VISUAL; black.alpha = 0; - lWhite.visual = *(get_pic_color(s, s->resmgr->_sciVersion < SCI_VERSION_01_VGA ? 15 : 255)), lWhite.mask = GFX_MASK_VISUAL; + lWhite.visual = get_pic_color(s, s->resmgr->_sciVersion < SCI_VERSION_01_VGA ? 15 : 255); + lWhite.mask = GFX_MASK_VISUAL; lWhite.alpha = 0; window = sciw_new_window(s, gfx_rect(x, y, xl, yl), s->titlebar_port->font_nr, fgcolor, bgcolor, @@ -3083,7 +3086,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { int index = UKPV_OR_ALT(1, 0); int temp; bool save_under = false; - gfx_color_t transparent = { { -1, 0, 0, 0 }, 0, -1, -1, 0 }; + gfx_color_t transparent = { PaletteEntry(), 0, -1, -1, 0 }; char *text; gfxw_port_t *port = (s->port) ? s->port : s->picture_port; bool update_immediately = true; @@ -3100,7 +3103,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { // TODO: in SCI1VGA the default colors for text and background are #0 (black) // SCI0 case should be checked if (s->resmgr->_sciVersion >= SCI_VERSION_01_VGA) { - color0.visual = bg_color.visual = *get_pic_color(s, 0); + color0.visual = bg_color.visual = get_pic_color(s, 0); } if (textp.segment) { @@ -3140,7 +3143,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { color0 = (s->ega_colors[temp]); else if ((s->resmgr->_sciVersion >= SCI_VERSION_01_VGA) && temp >= 0 && temp < 256) { - color0.visual = *(get_pic_color(s, temp)); + color0.visual = get_pic_color(s, temp); color0.mask = GFX_MASK_VISUAL; } else if (temp == -1) @@ -3157,7 +3160,7 @@ reg_t kDisplay(EngineState *s, int funct_nr, int argc, reg_t *argv) { bg_color = s->ega_colors[temp]; else if ((s->resmgr->_sciVersion >= SCI_VERSION_01_VGA) && temp >= 0 && temp <= 256) { - bg_color.visual = *get_pic_color(s, temp); + bg_color.visual = get_pic_color(s, temp); bg_color.mask = GFX_MASK_VISUAL; } else if (temp == -1) diff --git a/engines/sci/engine/kmenu.cpp b/engines/sci/engine/kmenu.cpp index d58582c97e..f08e0d3180 100644 --- a/engines/sci/engine/kmenu.cpp +++ b/engines/sci/engine/kmenu.cpp @@ -68,9 +68,9 @@ reg_t kDrawStatus(EngineState *s, int funct_nr, int argc, reg_t *argv) { int fgcolor = SKPV_OR_ALT(1, s->status_bar_foreground); int bgcolor = SKPV_OR_ALT(2, s->status_bar_background); - s->titlebar_port->color.visual = *(get_pic_color(s, fgcolor)); + s->titlebar_port->color.visual = get_pic_color(s, fgcolor); s->titlebar_port->color.mask = GFX_MASK_VISUAL; - s->titlebar_port->bgcolor.visual = *(get_pic_color(s, bgcolor)); + s->titlebar_port->bgcolor.visual = get_pic_color(s, bgcolor); s->titlebar_port->bgcolor.mask = GFX_MASK_VISUAL; s->status_bar_foreground = fgcolor; diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp index c7c5b00858..b5f34d3f07 100644 --- a/engines/sci/engine/kpathing.cpp +++ b/engines/sci/engine/kpathing.cpp @@ -293,10 +293,7 @@ static void draw_line(EngineState *s, Common::Point p1, Common::Point p2, int ty gfxw_list_t *decorations = s->picture_port->decorations; gfxw_primitive_t *line; - col.visual.global_index = GFX_COLOR_INDEX_UNMAPPED; - col.visual.r = poly_colors[type][0]; - col.visual.g = poly_colors[type][1]; - col.visual.b = poly_colors[type][2]; + col.visual = PaletteEntry(poly_colors[type][0], poly_colors[type][1], poly_colors[type][2]); col.alpha = 0; col.priority = -1; col.control = 0; @@ -318,10 +315,7 @@ static void draw_point(EngineState *s, Common::Point p, int start) { gfxw_list_t *decorations = s->picture_port->decorations; gfxw_box_t *box; - col.visual.global_index = GFX_COLOR_INDEX_UNMAPPED; - col.visual.r = point_colors[start][0]; - col.visual.g = point_colors[start][1]; - col.visual.b = point_colors[start][2]; + col.visual = PaletteEntry(point_colors[start][0], point_colors[start][1], point_colors[start][2]); col.alpha = 0; col.priority = -1; col.control = 0; diff --git a/engines/sci/engine/state.h b/engines/sci/engine/state.h index bc33f6de92..a8c1e08d24 100644 --- a/engines/sci/engine/state.h +++ b/engines/sci/engine/state.h @@ -310,7 +310,7 @@ bool get_savegame_metadata(Common::SeekableReadStream* stream, SavegameMetadata* /* Read the header from a savegame */ -gfx_pixmap_color_t *get_pic_color(EngineState *s, int color); +PaletteEntry get_pic_color(EngineState *s, int color); /* Retrieves the gfx_pixmap_color_t associated with a game color index ** Parameters: (EngineState *) s: The game state ** (int) color: The color to look up -- cgit v1.2.3