aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Frieger2009-03-01 04:07:04 +0000
committerGreg Frieger2009-03-01 04:07:04 +0000
commitce42d6e538e205fadda09fc426206a0e35bd2220 (patch)
treed9c97bbf2515695aa74fd0ab6eae34c80cde7e46
parent9ffd6a8768c0d65b36fb58eb2ad41bc652fd4e2c (diff)
downloadscummvm-rg350-ce42d6e538e205fadda09fc426206a0e35bd2220.tar.gz
scummvm-rg350-ce42d6e538e205fadda09fc426206a0e35bd2220.tar.bz2
scummvm-rg350-ce42d6e538e205fadda09fc426206a0e35bd2220.zip
Fixed windows and text drawing problem in SCI1
svn-id: r39000
-rw-r--r--engines/sci/engine/kgraphics.cpp1
-rw-r--r--engines/sci/gfx/operations.cpp33
2 files changed, 30 insertions, 4 deletions
diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp
index 522ca74d5b..2107b88ac7 100644
--- a/engines/sci/engine/kgraphics.cpp
+++ b/engines/sci/engine/kgraphics.cpp
@@ -1287,7 +1287,6 @@ reg_t kPalette(EngineState *s, int funct_nr, int argc, reg_t *argv) {
bestindex = i;
}
}
-
// Don't warn about inexact mappings -- it's actually the
// rule rather than the exception
return make_reg(0, bestindex);
diff --git a/engines/sci/gfx/operations.cpp b/engines/sci/gfx/operations.cpp
index 9c4f1cc4c4..3f90e2982a 100644
--- a/engines/sci/gfx/operations.cpp
+++ b/engines/sci/gfx/operations.cpp
@@ -1002,6 +1002,24 @@ int gfxop_draw_rectangle(gfx_state_t *state, rect_t rect, gfx_color_t color, gfx
#define COLOR_MIX(type, dist) ((color1.type * dist) + (color2.type * (1.0 - dist)))
+int _gfxop_matchColor(gfx_state_t *state, byte r, byte g, byte b) {
+ int i, delta, bestindex = -1, bestdelta = 200000;
+
+ for (i = 0; i < state->static_palette_entries; i++) {
+ int dr = abs(state->static_palette[i].r - r);
+ int dg = abs(state->static_palette[i].g - g);
+ int db = abs(state->static_palette[i].b - b);
+
+ delta = dr * dr + dg * dg + db * db;
+
+ if (delta < bestdelta) {
+ bestdelta = delta;
+ bestindex = i;
+ }
+ }
+ return bestindex;
+}
+
int gfxop_draw_box(gfx_state_t *state, rect_t box, gfx_color_t color1, gfx_color_t color2, gfx_box_shade_t shade_type) {
gfx_driver_t *drv = state->driver;
int reverse = 0; // switch color1 and color2
@@ -1072,9 +1090,12 @@ int gfxop_draw_box(gfx_state_t *state, rect_t box, gfx_color_t color1, gfx_color
mod_offset = (float)(1.0 - (mod_offset + mod_breadth));
// Reverse offset if we have to interpret colors inversely
- if (shade_type == GFX_BOX_SHADE_FLAT)
+ if (shade_type == GFX_BOX_SHADE_FLAT) {
+ if (color1.visual.global_index == -1)
+ color1.visual.global_index = _gfxop_matchColor(state, color1.visual.r, color1.visual.g,
+ color1.visual.b);
return drv->draw_filled_rect(drv, new_box, color1, color1, GFX_SHADE_FLAT);
- else {
+ } else {
if (PALETTE_MODE) {
GFXWARN("Attempting to draw shaded box in palette mode!\n");
return GFX_ERROR;
@@ -1920,6 +1941,13 @@ int gfxop_draw_text(gfx_state_t *state, gfx_text_handle_t *handle, rect_t zone)
gfx_pixmap_t *pxm = handle->text_pixmaps[i];
if (!pxm->data) {
+ // Matching pixmap's colors to current system palette if needed
+ for (int i = 0; i < pxm->colors_nr; i++) {
+ if (pxm->colors[i].global_index == -1)
+ pxm->colors[i].global_index = _gfxop_matchColor(state, pxm->colors[i].r, pxm->colors[i].g,
+ pxm->colors[i].b);
+ }
+
gfx_xlate_pixmap(pxm, state->driver->mode, state->options->text_xlate_filter);
gfxr_endianness_adjust(pxm, state->driver->mode); // FIXME: resmgr layer!
}
@@ -1952,7 +1980,6 @@ int gfxop_draw_text(gfx_state_t *state, gfx_text_handle_t *handle, rect_t zone)
pos.yl = pxm->yl;
_gfxop_add_dirty(state, pos);
-
_gfxop_draw_pixmap(state->driver, pxm, handle->priority, handle->control,
gfx_rect(0, 0, pxm->xl, pxm->yl), pos, state->clip_zone, 0, state->control_map, state->priority_map);