diff options
author | Max Horn | 2002-09-19 16:06:51 +0000 |
---|---|---|
committer | Max Horn | 2002-09-19 16:06:51 +0000 |
commit | bb57506d48e783027dbf09ab44c88b40ed7d2fa4 (patch) | |
tree | ed90efab26e7287627b2a5ce6c8c6d6909a5cf5d | |
parent | b46b35b54470180a882d2732b75d64243857cb54 (diff) | |
download | scummvm-rg350-bb57506d48e783027dbf09ab44c88b40ed7d2fa4.tar.gz scummvm-rg350-bb57506d48e783027dbf09ab44c88b40ed7d2fa4.tar.bz2 scummvm-rg350-bb57506d48e783027dbf09ab44c88b40ed7d2fa4.zip |
Added overlay to OSystem interface; implemented overlay in SDL backend (all other backends, including SDL_gl, still need to implement this!); changed NewGUI to make use of the overlay; added Cmd-Q as a shortcut for Quit on MacOS X
svn-id: r4971
-rw-r--r-- | backends/sdl/sdl-common.cpp | 40 | ||||
-rw-r--r-- | backends/sdl/sdl-common.h | 10 | ||||
-rw-r--r-- | backends/sdl/sdl.cpp | 428 | ||||
-rw-r--r-- | backends/sdl/sdl_gl.cpp | 31 | ||||
-rw-r--r-- | common/scaler.cpp | 50 | ||||
-rw-r--r-- | common/system.h | 7 | ||||
-rw-r--r-- | gui/dialog.cpp | 80 | ||||
-rw-r--r-- | gui/dialog.h | 24 | ||||
-rw-r--r-- | gui/newgui.cpp | 205 | ||||
-rw-r--r-- | gui/newgui.h | 34 | ||||
-rw-r--r-- | gui/widget.cpp | 7 |
11 files changed, 522 insertions, 394 deletions
diff --git a/backends/sdl/sdl-common.cpp b/backends/sdl/sdl-common.cpp index bdedb8ed1a..3c1fd3a151 100644 --- a/backends/sdl/sdl-common.cpp +++ b/backends/sdl/sdl-common.cpp @@ -81,7 +81,7 @@ void OSystem_SDL_Common::init_size(uint w, uint h) { _cur_pal = (SDL_Color*)calloc(sizeof(SDL_Color), 256); dirty_rect_list = (SDL_Rect*)calloc(NUM_DIRTY_RECT, sizeof(SDL_Rect)); - _mouse_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING); + _mouse_backup = (byte*)malloc(MAX_MOUSE_W * MAX_MOUSE_H * MAX_SCALING * 2); dirty_checksums = (uint32*)calloc(CKSUM_NUM*2, sizeof(uint32)); load_gfx_mode(); @@ -424,12 +424,15 @@ bool OSystem_SDL_Common::poll_event(Event *event) { switch(ev.type) { case SDL_KEYDOWN: { byte b = 0; - if (ev.key.keysym.mod & KMOD_SHIFT) b |= KBD_SHIFT; - if (ev.key.keysym.mod & KMOD_CTRL) b |= KBD_CTRL; - if (ev.key.keysym.mod & KMOD_ALT) b |= KBD_ALT; + if (ev.key.keysym.mod & KMOD_SHIFT) + b |= KBD_SHIFT; + if (ev.key.keysym.mod & KMOD_CTRL) + b |= KBD_CTRL; + if (ev.key.keysym.mod & KMOD_ALT) + b |= KBD_ALT; event->kbd.flags = b; - /* internal keypress? */ + // Alt-Return toggles full screen mode if (b == KBD_ALT && ev.key.keysym.sym==SDLK_RETURN) { property(PROP_TOGGLE_FULLSCREEN, NULL); break; @@ -439,6 +442,7 @@ bool OSystem_SDL_Common::poll_event(Event *event) { quit(); break; } + // Ctr-Alt-1 till Ctrl-Alt-7 will change the GFX mode if (b == (KBD_CTRL|KBD_ALT) && (ev.key.keysym.sym>='1') && (ev.key.keysym.sym<='7')) { Property prop; @@ -446,20 +450,28 @@ bool OSystem_SDL_Common::poll_event(Event *event) { property(PROP_SET_GFX_MODE, &prop); break; } - #ifdef QTOPIA +#ifdef MACOSX + // quit on Cmd-Q on Mac + if ((ev.key.keysym.mod & KMOD_META) && ev.key.keysym.sym=='q') { + quit(); + break; + } +#endif + +#ifdef QTOPIA // quit on fn+backspace on zaurus - if (ev.key.keysym.sym==127) { + if (ev.key.keysym.sym == 127) { quit(); break; } // map menu key (f11) to f5 (scumm menu) - if (ev.key.keysym.sym==292) { + if (ev.key.keysym.sym == 292) { event->event_code = EVENT_KEYDOWN; event->kbd.keycode = 286; event->kbd.ascii = mapKey(286, ev.key.keysym.mod); } // map center (space) to tab (default action ) - // i wanted to map the calendar button but the calendar comes up + // I wanted to map the calendar button but the calendar comes up // else if (ev.key.keysym.sym==32) { event->event_code = EVENT_KEYDOWN; @@ -480,12 +492,11 @@ bool OSystem_SDL_Common::poll_event(Event *event) { event->kbd.keycode = ev.key.keysym.sym; event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod); } - #endif - #ifndef QTOPIA +#else event->event_code = EVENT_KEYDOWN; event->kbd.keycode = ev.key.keysym.sym; event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod); - #endif +#endif switch(ev.key.keysym.sym) { case SDLK_LEFT: @@ -718,8 +729,6 @@ void OSystem_SDL_Common::draw_mouse() { if (SDL_LockSurface(sdl_screen) == -1) error("SDL_LockSurface failed: %s.\n", SDL_GetError()); - add_dirty_rect(x, y, w, h); - dst = (byte *)sdl_screen->pixels + y * SCREEN_WIDTH + x; while (h > 0) { int width = w; @@ -739,6 +748,9 @@ void OSystem_SDL_Common::draw_mouse() { SDL_UnlockSurface(sdl_screen); + // Mark as dirty + add_dirty_rect(x, y, w, h); + // Finally, set the flag to indicate the mouse has been drawn _mouse_drawn = true; } diff --git a/backends/sdl/sdl-common.h b/backends/sdl/sdl-common.h index bd2410ab2a..3da878a6e6 100644 --- a/backends/sdl/sdl-common.h +++ b/backends/sdl/sdl-common.h @@ -106,17 +106,12 @@ public: static OSystem *create(int gfx_mode, bool full_screen); protected: - typedef void TwoXSaiProc(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, - uint8 *dstPtr, uint32 dstPitch, int width, int height); SDL_Surface *sdl_screen; // unseen game screen - SDL_Surface *sdl_tmpscreen; // temporary screen (for 2xsai) SDL_CD *cdrom; enum { DF_WANT_RECT_OPTIM = 1 << 0, - DF_REAL_8BIT = 1 << 1, - DF_SEPARATE_TEMPSCREEN = 1 << 2, DF_UPDATE_EXPAND_1_PIXEL = 1 << 3 }; @@ -166,7 +161,6 @@ protected: int16 _mouse_hotspot_y; int _current_shake_pos; int _new_shake_pos; - TwoXSaiProc *_sai_func; SDL_Color *_cur_pal; uint _palette_changed_first, _palette_changed_last; @@ -180,8 +174,8 @@ protected: void add_dirty_rect(int x, int y, int w, int h); - void draw_mouse(); - void undraw_mouse(); + virtual void draw_mouse(); + virtual void undraw_mouse(); virtual void load_gfx_mode() = 0; virtual void unload_gfx_mode() = 0; diff --git a/backends/sdl/sdl.cpp b/backends/sdl/sdl.cpp index eeea78fbee..ef8633bea4 100644 --- a/backends/sdl/sdl.cpp +++ b/backends/sdl/sdl.cpp @@ -24,6 +24,10 @@ #include "common/scaler.h" #include "common/engine.h" // Only #included for error() and warning() +// FIXME - this macro assumes that we use 565 mode. But what if we are in 555 mode? +#define RGB_TO_16(r,g,b) ((((r>>3)&0x1F) << 11) | (((g>>2)&0x3F) << 5) | ((b>>3)&0x1F)) +//#define RGB_TO_16(r,g,b) ((((r>>3)&0x1F) << 10) | (((g>>3)&0x1F) << 5) | ((b>>3)&0x1F)) + class OSystem_SDL_Normal : public OSystem_SDL_Common { public: @@ -36,12 +40,31 @@ public: // Set a parameter uint32 property(int param, Property *value); + // Overlay + virtual void show_overlay(); + virtual void hide_overlay(); + virtual void clear_overlay(); + virtual void grab_overlay(int16 *buf, int pitch); + virtual void copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h); + protected: + typedef void ScalerProc(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, + uint8 *dstPtr, uint32 dstPitch, int width, int height); + + SDL_Surface *sdl_tmpscreen; // temporary screen (for scalers/overlay) SDL_Surface *sdl_hwscreen; // hardware screen + bool _overlay_visible; - void load_gfx_mode(); - void unload_gfx_mode(); + ScalerProc *_scaler_proc; + + virtual void draw_mouse(); + virtual void undraw_mouse(); + + virtual void load_gfx_mode(); + virtual void unload_gfx_mode(); void hotswap_gfx_mode(); + + int TMP_SCREEN_WIDTH; }; OSystem_SDL_Common *OSystem_SDL_Common::create() { @@ -52,7 +75,7 @@ void OSystem_SDL_Normal::set_palette(const byte *colors, uint start, uint num) { const byte *b = colors; uint i; SDL_Color *base = _cur_pal + start; - for(i=0;i!=num;i++) { + for(i = 0; i < num; i++) { base[i].r = b[0]; base[i].g = b[1]; base[i].b = b[2]; @@ -66,34 +89,151 @@ void OSystem_SDL_Normal::set_palette(const byte *colors, uint start, uint num) { _palette_changed_last = start + num; } +void OSystem_SDL_Normal::draw_mouse() { + if (!_overlay_visible) { + OSystem_SDL_Common::draw_mouse(); + } + + + if (_mouse_drawn || !_mouse_visible) + return; + + int x = _mouse_cur_state.x - _mouse_hotspot_x; + int y = _mouse_cur_state.y - _mouse_hotspot_y; + int w = _mouse_cur_state.w; + int h = _mouse_cur_state.h; + byte color; + byte *src = _mouse_data; // Image representing the mouse + uint16 *bak = (uint16*)_mouse_backup; // Surface used to backup the area obscured by the mouse + uint16 *dst; // Surface we are drawing into + + // clip the mouse rect, and addjust the src pointer accordingly + if (x < 0) { + w += x; + src -= x; + x = 0; + } + if (y < 0) { + h += y; + src -= y * _mouse_cur_state.w; + y = 0; + } + if (w > SCREEN_WIDTH - x) + w = SCREEN_WIDTH - x; + if (h > SCREEN_HEIGHT - y) + h = SCREEN_HEIGHT - y; + + // Adjust for tmp_screen offset + x++; + y++; + + // Store the bounding box so that undraw mouse can restore the area the + // mouse currently covers to its original content. + _mouse_old_state.x = x; + _mouse_old_state.y = y; + _mouse_old_state.w = w; + _mouse_old_state.h = h; + + // Quick check to see if anything has to be drawn at all + if (w <= 0 || h <= 0) + return; + + // Draw the mouse cursor; backup the covered area in "bak" + + if (SDL_LockSurface(sdl_tmpscreen) == -1) + error("SDL_LockSurface failed: %s.\n", SDL_GetError()); + + dst = (uint16 *)sdl_tmpscreen->pixels + y * TMP_SCREEN_WIDTH + x; + while (h > 0) { + int width = w; + while (width > 0) { + *bak++ = *dst; + color = *src++; + if (color != 0xFF) // 0xFF = transparent, don't draw + *dst = RGB_TO_16(_cur_pal[color].r, _cur_pal[color].g, _cur_pal[color].b); + dst++; + width--; + } + src += _mouse_cur_state.w - w; + bak += MAX_MOUSE_W - w; + dst += TMP_SCREEN_WIDTH - w; + h--; + } + + SDL_UnlockSurface(sdl_tmpscreen); + + // Mark as dirty + add_dirty_rect(x, y, w, h); + + // Finally, set the flag to indicate the mouse has been drawn + _mouse_drawn = true; +} + +void OSystem_SDL_Normal::undraw_mouse() { + if (!_overlay_visible) { + OSystem_SDL_Common::undraw_mouse(); + } + + + if (!_mouse_drawn) + return; + _mouse_drawn = false; + + uint16 *dst, *bak = (uint16 *)_mouse_backup; + const int old_mouse_x = _mouse_old_state.x; + const int old_mouse_y = _mouse_old_state.y; + const int old_mouse_w = _mouse_old_state.w; + const int old_mouse_h = _mouse_old_state.h; + int x,y; + + if (SDL_LockSurface(sdl_tmpscreen) == -1) + error("SDL_LockSurface failed: %s.\n", SDL_GetError()); + + // No need to do clipping here, since draw_mouse() did that already + + dst = (uint16 *)sdl_tmpscreen->pixels + old_mouse_y * TMP_SCREEN_WIDTH + old_mouse_x; + for (y = 0; y < old_mouse_h; ++y, bak += MAX_MOUSE_W, dst += TMP_SCREEN_WIDTH) { + for (x = 0; x < old_mouse_w; ++x) { + dst[x] = bak[x]; + } + } + + add_dirty_rect(old_mouse_x, old_mouse_y, old_mouse_w, old_mouse_h); + + SDL_UnlockSurface(sdl_tmpscreen); +} + void OSystem_SDL_Normal::load_gfx_mode() { force_full = true; scaling = 1; _mode_flags = 0; + _overlay_visible = false; - _sai_func = NULL; + _scaler_proc = NULL; sdl_tmpscreen = NULL; + TMP_SCREEN_WIDTH = (SCREEN_WIDTH + 3); switch(_mode) { case GFX_2XSAI: scaling = 2; - _sai_func = _2xSaI; + _scaler_proc = _2xSaI; break; case GFX_SUPER2XSAI: scaling = 2; - _sai_func = Super2xSaI; + _scaler_proc = Super2xSaI; break; case GFX_SUPEREAGLE: scaling = 2; - _sai_func = SuperEagle; + _scaler_proc = SuperEagle; break; case GFX_ADVMAME2X: scaling = 2; - _sai_func = AdvMame2x; + _scaler_proc = AdvMame2x; break; case GFX_DOUBLESIZE: scaling = 2; + _scaler_proc = Normal2x; break; case GFX_TRIPLESIZE: @@ -102,11 +242,13 @@ void OSystem_SDL_Normal::load_gfx_mode() { goto normal_mode; } scaling = 3; + _scaler_proc = Normal3x; break; case GFX_NORMAL: normal_mode:; scaling = 1; + _scaler_proc = Normal1x; break; } @@ -114,55 +256,30 @@ normal_mode:; if (sdl_screen == NULL) error("sdl_screen failed failed"); - if (_sai_func) { - uint16 *tmp_screen = (uint16*)calloc((SCREEN_WIDTH+3)*(SCREEN_HEIGHT+3),sizeof(uint16)); - _mode_flags = DF_WANT_RECT_OPTIM | DF_SEPARATE_TEMPSCREEN | DF_UPDATE_EXPAND_1_PIXEL; - - sdl_hwscreen = SDL_SetVideoMode(SCREEN_WIDTH * scaling, SCREEN_HEIGHT * scaling, 16, - _full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE - ); - if (sdl_hwscreen == NULL) - error("sdl_hwscreen failed"); - - /* Need some extra bytes around when using 2XSAI */ - if (sdl_hwscreen->format->Rmask == 0x7C00) // HACK HACK HACK - Init_2xSaI(555); - else - Init_2xSaI(565); - sdl_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen, - SCREEN_WIDTH + 3, SCREEN_HEIGHT + 3, 16, (SCREEN_WIDTH + 3)*2, - sdl_hwscreen->format->Rmask, - sdl_hwscreen->format->Gmask, - sdl_hwscreen->format->Bmask, - sdl_hwscreen->format->Amask); - - if (sdl_tmpscreen == NULL) - error("sdl_tmpscreen failed"); - - } else { - switch(scaling) { - case 3: - _sai_func = Normal3x; - break; - case 2: - _sai_func = Normal2x; - break; - case 1: - _sai_func = Normal1x; - break; - } - - _mode_flags = DF_WANT_RECT_OPTIM | DF_REAL_8BIT; - - sdl_hwscreen = SDL_SetVideoMode(SCREEN_WIDTH * scaling, SCREEN_HEIGHT * scaling, 8, - _full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE - ); - if (sdl_hwscreen == NULL) - error("sdl_hwscreen failed"); - - sdl_tmpscreen = sdl_screen; - } + uint16 *tmp_screen = (uint16*)calloc(TMP_SCREEN_WIDTH*(SCREEN_HEIGHT+3),sizeof(uint16)); + _mode_flags = DF_WANT_RECT_OPTIM | DF_UPDATE_EXPAND_1_PIXEL; + sdl_hwscreen = SDL_SetVideoMode(SCREEN_WIDTH * scaling, SCREEN_HEIGHT * scaling, 16, + _full_screen ? (SDL_FULLSCREEN|SDL_SWSURFACE) : SDL_SWSURFACE + ); + if (sdl_hwscreen == NULL) + error("sdl_hwscreen failed"); + + /* Need some extra bytes around when using 2XSAI */ + if (sdl_hwscreen->format->Rmask == 0x7C00) // HACK HACK HACK + Init_2xSaI(555); + else + Init_2xSaI(565); + sdl_tmpscreen = SDL_CreateRGBSurfaceFrom(tmp_screen, + TMP_SCREEN_WIDTH, SCREEN_HEIGHT + 3, 16, TMP_SCREEN_WIDTH*2, + sdl_hwscreen->format->Rmask, + sdl_hwscreen->format->Gmask, + sdl_hwscreen->format->Bmask, + sdl_hwscreen->format->Amask); + + if (sdl_tmpscreen == NULL) + error("sdl_tmpscreen failed"); + // keyboard cursor control, some other better place for it? km.x_max = SCREEN_WIDTH * scaling - 1; km.y_max = SCREEN_HEIGHT * scaling - 1; @@ -182,11 +299,11 @@ void OSystem_SDL_Normal::unload_gfx_mode() { sdl_hwscreen = NULL; } - if (_mode_flags & DF_SEPARATE_TEMPSCREEN) { + if (sdl_tmpscreen) { free((uint16*)sdl_tmpscreen->pixels); SDL_FreeSurface(sdl_tmpscreen); + sdl_tmpscreen = NULL; } - sdl_tmpscreen = NULL; } void OSystem_SDL_Normal::update_screen() { @@ -194,14 +311,12 @@ void OSystem_SDL_Normal::update_screen() { if (sdl_hwscreen == NULL) return; // Can this really happen? - /* First make sure the mouse is drawn, if it should be drawn. */ + // First make sure the mouse is drawn, if it should be drawn. draw_mouse(); - /* Palette update in case we are NOT in "real" 8 bit color mode. - * Must take place before updating the screen, since the palette must - * be set up for conversion from 8bit to 16bit. - */ - if (((_mode_flags & DF_REAL_8BIT) == 0) && _palette_changed_last != 0) { + // Check whether the palette was changed in the meantime and update the + // screen surface accordingly. + if (_palette_changed_last != 0) { SDL_SetColors(sdl_screen, _cur_pal + _palette_changed_first, _palette_changed_first, _palette_changed_last - _palette_changed_first); @@ -222,7 +337,7 @@ void OSystem_SDL_Normal::update_screen() { force_full = true; } - /* force a full redraw if requested */ + // Force a full redraw if requested if (force_full) { num_dirty_rects = 1; @@ -232,20 +347,20 @@ void OSystem_SDL_Normal::update_screen() { dirty_rect_list[0].h = SCREEN_HEIGHT; } - /* Only draw anything if necessary */ + // Only draw anything if necessary if (num_dirty_rects > 0) { SDL_Rect *r; uint32 srcPitch, dstPitch; SDL_Rect *last_rect = dirty_rect_list + num_dirty_rects; - /* Convert appropriate parts of the image into 16bpp */ - if ((_mode_flags & DF_REAL_8BIT) == 0) { + // Convert appropriate parts of the 8bpp image into 16bpp + if (!_overlay_visible) { SDL_Rect dst; for(r=dirty_rect_list; r!=last_rect; ++r) { dst = *r; - dst.x++; - dst.y++; + dst.x++; // Shift rect by one since 2xSai needs to acces the data around + dst.y++; // any pixel to scale it, and we want to avoid mem access crashes. if (SDL_BlitSurface(sdl_screen, r, sdl_tmpscreen, &dst) != 0) error("SDL_BlitSurface failed: %s", SDL_GetError()); } @@ -257,46 +372,24 @@ void OSystem_SDL_Normal::update_screen() { srcPitch = sdl_tmpscreen->pitch; dstPitch = sdl_hwscreen->pitch; - if ((_mode_flags & DF_REAL_8BIT) == 0) { - for(r=dirty_rect_list; r!=last_rect; ++r) { - register int dst_y = r->y + _current_shake_pos; - register int dst_h = 0; - if (dst_y < SCREEN_HEIGHT) { - dst_h = r->h; - if (dst_h > SCREEN_HEIGHT - dst_y) - dst_h = SCREEN_HEIGHT - dst_y; - - r->x <<= 1; - dst_y <<= 1; - - _sai_func((byte*)sdl_tmpscreen->pixels + (r->x+2) + (r->y+1)*srcPitch, srcPitch, NULL, - (byte*)sdl_hwscreen->pixels + r->x*scaling + dst_y*dstPitch, dstPitch, r->w, dst_h); - } + for(r=dirty_rect_list; r!=last_rect; ++r) { + register int dst_y = r->y + _current_shake_pos; + register int dst_h = 0; + if (dst_y < SCREEN_HEIGHT) { + dst_h = r->h; + if (dst_h > SCREEN_HEIGHT - dst_y) + dst_h = SCREEN_HEIGHT - dst_y; - r->y = dst_y; - r->w <<= 1; - r->h = dst_h << 1; - } - } else { - for(r=dirty_rect_list; r!=last_rect; ++r) { - register int dst_y = r->y + _current_shake_pos; - register int dst_h = 0; - if (dst_y < SCREEN_HEIGHT) { - dst_h = r->h; - if (dst_h > SCREEN_HEIGHT - dst_y) - dst_h = SCREEN_HEIGHT - dst_y; - - dst_y *= scaling; - - _sai_func((byte*)sdl_tmpscreen->pixels + r->x + r->y*srcPitch, srcPitch, NULL, - (byte*)sdl_hwscreen->pixels + r->x*scaling + dst_y*dstPitch, dstPitch, r->w, dst_h); - } + dst_y *= scaling; - r->x *= scaling; - r->y = dst_y; - r->w *= scaling; - r->h = dst_h * scaling; + _scaler_proc((byte*)sdl_tmpscreen->pixels + (r->x*2+2) + (r->y+1)*srcPitch, srcPitch, NULL, + (byte*)sdl_hwscreen->pixels + r->x*2*scaling + dst_y*dstPitch, dstPitch, r->w, dst_h); } + + r->x *= scaling; + r->y = dst_y; + r->w *= scaling; + r->h = dst_h * scaling; } if (force_full) { @@ -308,19 +401,6 @@ void OSystem_SDL_Normal::update_screen() { SDL_UnlockSurface(sdl_hwscreen); } - /* Palette update in case we are in "real" 8 bit color mode. - * Must take place after the screen data was updated, since with - * "real" 8bit mode, palatte changes may be visible immediatly, - * and we want to avoid any ugly effects. - */ - if (_mode_flags & DF_REAL_8BIT && _palette_changed_last != 0) { - SDL_SetColors(sdl_hwscreen, _cur_pal + _palette_changed_first, - _palette_changed_first, - _palette_changed_last - _palette_changed_first); - - _palette_changed_last = 0; - } - if (num_dirty_rects > 0) { /* Finally, blit all our changes to the screen */ SDL_UpdateRects(sdl_hwscreen, num_dirty_rects, dirty_rect_list); @@ -345,13 +425,10 @@ void OSystem_SDL_Normal::hotswap_gfx_mode() { force_full = true; - /* reset palette */ - if (_mode_flags & DF_REAL_8BIT) - SDL_SetColors(sdl_hwscreen, _cur_pal, 0, 256); - else - SDL_SetColors(sdl_screen, _cur_pal, 0, 256); + // reset palette + SDL_SetColors(sdl_screen, _cur_pal, 0, 256); - /* blit image */ + // blit image OSystem_SDL_Normal::copy_rect(bak_mem, SCREEN_WIDTH, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); free(bak_mem); @@ -372,3 +449,102 @@ uint32 OSystem_SDL_Normal::property(int param, Property *value) { return OSystem_SDL_Common::property(param, value); } + + +void OSystem_SDL_Normal::show_overlay() +{ + // hide the mouse + undraw_mouse(); + + _overlay_visible = true; + clear_overlay(); +} + +void OSystem_SDL_Normal::hide_overlay() +{ + _overlay_visible = false; + force_full = true; +} + +void OSystem_SDL_Normal::clear_overlay() +{ + if (!_overlay_visible) + return; + + // hide the mouse + undraw_mouse(); + + // Clear the overlay by making the game screen "look through" everywhere. + SDL_Rect src, dst; + src.x = src.y = 0; + dst.x = dst.y = 1; + src.w = dst.w = SCREEN_WIDTH; + src.h = dst.h = SCREEN_HEIGHT; + if (SDL_BlitSurface(sdl_screen, &src, sdl_tmpscreen, &dst) != 0) + error("SDL_BlitSurface failed: %s", SDL_GetError()); + + force_full = true; +} + +void OSystem_SDL_Normal::grab_overlay(int16 *buf, int pitch) +{ + if (!_overlay_visible) + return; + + if (sdl_tmpscreen == NULL) + return; + + // hide the mouse + undraw_mouse(); + + if (SDL_LockSurface(sdl_tmpscreen) == -1) + error("SDL_LockSurface failed: %s.\n", SDL_GetError()); + + int16 *src = (int16 *)sdl_tmpscreen->pixels + TMP_SCREEN_WIDTH + 1; + int h = SCREEN_HEIGHT; + do { + memcpy(buf, src, SCREEN_WIDTH*2); + src += TMP_SCREEN_WIDTH; + buf += pitch; + } while (--h); + + SDL_UnlockSurface(sdl_tmpscreen); +} + +void OSystem_SDL_Normal::copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h) +{ + if (!_overlay_visible) + return; + + if (sdl_tmpscreen == NULL) + return; + + // Clip the coordinates + if (x < 0) { w+=x; buf-=x; x = 0; } + if (y < 0) { h+=y; buf-=y*pitch; y = 0; } + if (w > SCREEN_WIDTH-x) { w = SCREEN_WIDTH - x; } + if (h > SCREEN_HEIGHT-y) { h = SCREEN_HEIGHT - y; } + if (w <= 0 || h <= 0) + return; + + // Mark the modified region as dirty + cksum_valid = false; + add_dirty_rect(x, y, w, h); + + /* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */ + undraw_mouse(); + + if (SDL_LockSurface(sdl_tmpscreen) == -1) + error("SDL_LockSurface failed: %s.\n", SDL_GetError()); + + int16 *dst = (int16 *)sdl_tmpscreen->pixels + (y+1) * TMP_SCREEN_WIDTH + (x+1); + do { + memcpy(dst, buf, w*2); + dst += TMP_SCREEN_WIDTH; + buf += pitch; + } while (--h); + + SDL_UnlockSurface(sdl_tmpscreen); +} + + diff --git a/backends/sdl/sdl_gl.cpp b/backends/sdl/sdl_gl.cpp index b62a757d84..00d0947f32 100644 --- a/backends/sdl/sdl_gl.cpp +++ b/backends/sdl/sdl_gl.cpp @@ -47,6 +47,13 @@ public: // Set a parameter uint32 property(int param, Property *value); + // Overlay + virtual void show_overlay(); + virtual void hide_overlay(); + virtual void clear_overlay(); + virtual void grab_overlay(int16 *buf, int pitch); + virtual void copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h); + protected: FB2GL fb2gl; @@ -78,22 +85,14 @@ void OSystem_SDL_GL::set_palette(const byte *colors, uint start, uint num) { void OSystem_SDL_GL::load_gfx_mode() { int gl_flags = FB2GL_320 | FB2GL_PITCH; force_full = true; - scaling = 1; + scaling = 2; _mode_flags = 0; - - _sai_func = NULL; - sdl_tmpscreen = NULL; - - /* It's easier to work with 8 bit (256 colors) */ - _mode_flags |= DF_REAL_8BIT; sdl_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, 8, 0, 0, 0, 0); if (sdl_screen == NULL) error("sdl_screen failed failed"); - _sai_func = Normal1x; - - _mode_flags = DF_WANT_RECT_OPTIM | DF_REAL_8BIT; + _mode_flags = DF_WANT_RECT_OPTIM; if (_full_screen) gl_flags |= (FB2GL_FS); @@ -109,8 +108,6 @@ void OSystem_SDL_GL::load_gfx_mode() { } SDL_SetGamma(1.25,1.25,1.25); - - sdl_tmpscreen = sdl_screen; } void OSystem_SDL_GL::unload_gfx_mode() { @@ -118,12 +115,6 @@ void OSystem_SDL_GL::unload_gfx_mode() { SDL_FreeSurface(sdl_screen); sdl_screen = NULL; } - - if (_mode_flags & DF_SEPARATE_TEMPSCREEN) { - free((uint16*)sdl_tmpscreen->pixels); - SDL_FreeSurface(sdl_tmpscreen); - } - sdl_tmpscreen = NULL; } void OSystem_SDL_GL::update_screen() { @@ -150,7 +141,7 @@ void OSystem_SDL_GL::update_screen() { _palette_changed_last = 0; } - fb2gl.update(sdl_tmpscreen->pixels,320,200,320,0,_current_shake_pos); + fb2gl.update(sdl_screen->pixels,320,200,320,0,_current_shake_pos); } @@ -168,7 +159,7 @@ void OSystem_SDL_GL::hotswap_gfx_mode() { load_gfx_mode(); fb2gl.setPalette(0,256); - fb2gl.update(sdl_tmpscreen->pixels,320,200,320,0,_current_shake_pos); + fb2gl.update(sdl_screen->pixels,320,200,320,0,_current_shake_pos); /* blit image */ copy_rect(bak_mem, SCREEN_WIDTH, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); diff --git a/common/scaler.cpp b/common/scaler.cpp index 9a98d1e8ef..c0a2e30ef4 100644 --- a/common/scaler.cpp +++ b/common/scaler.cpp @@ -747,16 +747,15 @@ void AdvMame2x(uint8 *srcPtr, uint32 srcPitch, uint8 *null, uint8 *dstPtr, uint3 } -/* Beware! Contrary to the other functions in this file, this blits from 8 to 8 bit! */ void Normal1x(uint8 *srcPtr, uint32 srcPitch, uint8 *null, uint8 *dstPtr, uint32 dstPitch, int width, int height) { - uint8 *r; + uint16 *r; while (height--) { - r = dstPtr; + r = (uint16 *)dstPtr; for (int i = 0; i < width; ++i, ++r) { - uint8 color = *(srcPtr + i); + uint16 color = *(((uint16 *)srcPtr) + i); *r = color; } @@ -765,7 +764,6 @@ void Normal1x(uint8 *srcPtr, uint32 srcPitch, uint8 *null, uint8 *dstPtr, uint32 } } -/* Beware! Contrary to the other functions in this file, this blits from 8 to 8 bit! */ void Normal2x(uint8 *srcPtr, uint32 srcPitch, uint8 *null, uint8 *dstPtr, uint32 dstPitch, int width, int height) { @@ -773,42 +771,42 @@ void Normal2x(uint8 *srcPtr, uint32 srcPitch, uint8 *null, uint8 *dstPtr, uint32 while (height--) { r = dstPtr; - for (int i = 0; i < width; ++i, r += 2) { - uint8 color = *(srcPtr + i); + for (int i = 0; i < width; ++i, r += 4) { + uint16 color = *(((uint16 *)srcPtr) + i); - *(r) = color; - *(r + 1) = color; - *(r + dstPitch) = color; - *(r + dstPitch + 1) = color; + *(uint16 *)(r + 0) = color; + *(uint16 *)(r + 2) = color; + *(uint16 *)(r + 0 + dstPitch) = color; + *(uint16 *)(r + 2 + dstPitch) = color; } srcPtr += srcPitch; dstPtr += dstPitch << 1; } } -/* Beware! Contrary to the other functions in this file, this blits from 8 to 8 bit! */ void Normal3x(uint8 *srcPtr, uint32 srcPitch, uint8 *null, uint8 *dstPtr, uint32 dstPitch, int width, int height) { uint8 *r; - uint32 dstPitch2 = dstPitch << 1; + uint32 dstPitch2 = dstPitch * 2; + uint32 dstPitch3 = dstPitch * 3; while (height--) { r = dstPtr; - for (int i = 0; i < width; ++i, r += 3) { - uint8 color = *(srcPtr + i); - - *(r + 0) = color; - *(r + 1) = color; - *(r + 2) = color; - *(r + 0 + dstPitch) = color; - *(r + 1 + dstPitch) = color; - *(r + 2 + dstPitch) = color; - *(r + 0 + dstPitch2) = color; - *(r + 1 + dstPitch2) = color; - *(r + 2 + dstPitch2) = color; + for (int i = 0; i < width; ++i, r += 6) { + uint16 color = *(((uint16 *)srcPtr) + i); + + *(uint16 *)(r + 0) = color; + *(uint16 *)(r + 2) = color; + *(uint16 *)(r + 4) = color; + *(uint16 *)(r + 0 + dstPitch) = color; + *(uint16 *)(r + 2 + dstPitch) = color; + *(uint16 *)(r + 4 + dstPitch) = color; + *(uint16 *)(r + 0 + dstPitch2) = color; + *(uint16 *)(r + 2 + dstPitch2) = color; + *(uint16 *)(r + 4 + dstPitch2) = color; } srcPtr += srcPitch; - dstPtr += dstPitch * 3; + dstPtr += dstPitch3; } } diff --git a/common/system.h b/common/system.h index 97e7ebcca2..f3fcea129a 100644 --- a/common/system.h +++ b/common/system.h @@ -158,6 +158,13 @@ public: // Quit virtual void quit() = 0; + + // Overlay + virtual void show_overlay() = 0; + virtual void hide_overlay() = 0; + virtual void clear_overlay() = 0; + virtual void grab_overlay(int16 *buf, int pitch) = 0; + virtual void copy_rect_overlay(const int16 *buf, int pitch, int x, int y, int w, int h) = 0; }; diff --git a/gui/dialog.cpp b/gui/dialog.cpp index 54b50e8958..e1886af83d 100644 --- a/gui/dialog.cpp +++ b/gui/dialog.cpp @@ -45,33 +45,6 @@ * ... */ -Dialog::~Dialog() -{ - teardownScreenBuf(); -} - -void Dialog::setupScreenBuf() -{ - // Create _screenBuf if it doesn't already exist - if (!_screenBuf) - _screenBuf = new byte[g_scumm->_realWidth * g_scumm->_realHeight]; - - // Draw the fixed parts of the dialog: background and border. - _gui->blendRect(_x, _y, _w, _h, _gui->_bgcolor); - _gui->box(_x, _y, _w, _h); - - // Finally blit this to _screenBuf - _gui->blitTo(_screenBuf, _x, _y, _w, _h); -} - -void Dialog::teardownScreenBuf() -{ - if (_screenBuf) { - delete [] _screenBuf; - _screenBuf = 0; - } -} - void Dialog::open() { Widget *w = _firstWidget; @@ -112,18 +85,15 @@ void Dialog::draw() if (!isVisible()) return; - if (_screenBuf) { - _gui->blitFrom(_screenBuf, _x, _y, _w, _h); - } else { - _gui->fillRect(_x, _y, _w, _h, _gui->_bgcolor); - _gui->box(_x, _y, _w, _h); - } - _gui->addDirtyRect(_x, _y, _w, _h); + _gui->blendRect(_x, _y, _w, _h, _gui->_bgcolor); + _gui->box(_x, _y, _w, _h); while (w) { w->draw(); w = w->_next; } + + _gui->addDirtyRect(_x, _y, _w, _h); } void Dialog::handleMouseDown(int x, int y, int button, int clickCount) @@ -314,8 +284,8 @@ enum { * method to Dialog for that. */ -SaveLoadDialog::SaveLoadDialog(NewGui *gui) - : Dialog (gui, 30, 20, 260, 124) +SaveLoadDialog::SaveLoadDialog(NewGui *gui, Scumm *scumm) + : Dialog (gui, 30, 20, 260, 124), _scumm(scumm) { addResText(10, 7, 240, 16, 1); // addResText(10, 7, 240, 16, 2); @@ -333,10 +303,9 @@ SaveLoadDialog::SaveLoadDialog(NewGui *gui) // Get savegame names ScummVM::StringList l; char name[32]; - Scumm *s = _gui->getScumm(); for (int i = 0; i <= 80; i++) { // 80 - got this value from the old GUI - s->getSavegameName(i, name); + _scumm->getSavegameName(i, name); l.push_back(name); } @@ -349,7 +318,7 @@ void SaveLoadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat case kListItemChangedCmd: case kSaveCmd: if (_savegameList->getSelected() >= 1 && !_savegameList->getSelectedString().isEmpty()) { - Scumm *s = _gui->getScumm(); + Scumm *s = _scumm; s->_saveLoadSlot = _savegameList->getSelected(); s->_saveLoadCompatible = false; s->_saveLoadFlag = 1; // 1 for save, I assume (Painelf) @@ -360,7 +329,7 @@ void SaveLoadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat case kListItemDoubleClickedCmd: case kLoadCmd: if (_savegameList->getSelected() >= 0 && !_savegameList->getSelectedString().isEmpty()) { - Scumm *s = _gui->getScumm(); + Scumm *s = _scumm; s->_saveLoadSlot = _savegameList->getSelected(); s->_saveLoadCompatible = false; s->_saveLoadFlag = 2; // 2 for load. Magic number anyone? @@ -374,8 +343,7 @@ void SaveLoadDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 dat _gui->optionsDialog(); break; case kQuitCmd: { - Scumm *s = _gui->getScumm(); - s->_system->quit(); + _scumm->_system->quit(); } break; default: @@ -441,8 +409,8 @@ PauseDialog::PauseDialog(NewGui *gui) addResText(4, 4, 220, 16, 10); } -SoundDialog::SoundDialog(NewGui *gui) - : Dialog (gui, 30, 20, 260, 110) +SoundDialog::SoundDialog(NewGui *gui, Scumm *scumm) + : Dialog (gui, 30, 20, 260, 110), _scumm(scumm) { // set up dialog @@ -471,14 +439,12 @@ SoundDialog::SoundDialog(NewGui *gui) void SoundDialog::open() { - Scumm *scumm = _gui->getScumm(); - Dialog::open(); // get current variables - _soundVolumeMaster = scumm->_sound->_sound_volume_master; - _soundVolumeMusic = scumm->_sound->_sound_volume_music; - _soundVolumeSfx = scumm->_sound->_sound_volume_sfx; + _soundVolumeMaster = _scumm->_sound->_sound_volume_master; + _soundVolumeMusic = _scumm->_sound->_sound_volume_music; + _soundVolumeSfx = _scumm->_sound->_sound_volume_sfx; masterVolumeSlider->setValue(_soundVolumeMaster); musicVolumeSlider->setValue(_soundVolumeMusic); @@ -509,17 +475,15 @@ void SoundDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) sfxVolumeLabel->draw(); break; case kOKCmd: { - Scumm *scumm = _gui->getScumm(); - // FIXME: Look at Fingolfins comments in Gui::handleSoundDialogCommand(), gui.cpp - scumm->_sound->_sound_volume_master = _soundVolumeMaster; // Master - scumm->_sound->_sound_volume_music = _soundVolumeMusic; // Music - scumm->_sound->_sound_volume_sfx = _soundVolumeSfx; // SFX + _scumm->_sound->_sound_volume_master = _soundVolumeMaster; // Master + _scumm->_sound->_sound_volume_music = _soundVolumeMusic; // Music + _scumm->_sound->_sound_volume_sfx = _soundVolumeSfx; // SFX - scumm->_imuse->set_music_volume(_soundVolumeMusic); - scumm->_imuse->set_master_volume(_soundVolumeMaster); - scumm->_mixer->setVolume(_soundVolumeSfx); - scumm->_mixer->setMusicVolume(_soundVolumeMusic); + _scumm->_imuse->set_music_volume(_soundVolumeMusic); + _scumm->_imuse->set_master_volume(_soundVolumeMaster); + _scumm->_mixer->setVolume(_soundVolumeSfx); + _scumm->_mixer->setMusicVolume(_soundVolumeMusic); scummcfg->setInt("master_volume", _soundVolumeMaster); scummcfg->setInt("music_volume", _soundVolumeMusic); diff --git a/gui/dialog.h b/gui/dialog.h index 4d5dd82d0b..3d1577b9e3 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -26,6 +26,7 @@ #include "ListWidget.h" class NewGui; +class Scumm; #define RES_STRING(id) _gui->queryResString(id) #define CUSTOM_STRING(id) _gui->queryCustomString(id) @@ -45,15 +46,14 @@ protected: Widget *_firstWidget; Widget *_mouseWidget; Widget *_focusedWidget; - byte *_screenBuf; bool _visible; public: Dialog(NewGui *gui, int x, int y, int w, int h) : _gui(gui), _x(x), _y(y), _w(w), _h(h), _firstWidget(0), - _mouseWidget(0), _focusedWidget(0), _screenBuf(0), _visible(false) + _mouseWidget(0), _focusedWidget(0), _visible(false) {} - virtual ~Dialog(); + virtual ~Dialog() {}; virtual void open(); virtual void close(); @@ -70,9 +70,6 @@ public: NewGui *getGui() { return _gui; } - virtual void setupScreenBuf(); - virtual void teardownScreenBuf(); - bool isVisible() const { return _visible; } protected: @@ -85,24 +82,25 @@ protected: class SaveLoadDialog : public Dialog { public: - SaveLoadDialog(NewGui *gui); + SaveLoadDialog(NewGui *gui, Scumm *scumm); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); protected: + Scumm *_scumm; ListWidget *_savegameList; }; -class SoundDialog; -class KeysDialog; -class MiscDialog; - class AboutDialog : public Dialog { public: AboutDialog(NewGui *gui); }; +class SoundDialog; +class KeysDialog; +class MiscDialog; + class OptionsDialog : public Dialog { protected: SoundDialog *_soundDialog; @@ -138,7 +136,7 @@ public: class SoundDialog : public Dialog { public: - SoundDialog(NewGui *gui); + SoundDialog(NewGui *gui, Scumm *scumm); enum { kMasterVolumeChanged = 'mavc', @@ -153,6 +151,8 @@ public: virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); protected: + Scumm *_scumm; + int _soundVolumeMaster; int _soundVolumeMusic; int _soundVolumeSfx; diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 9da918525e..89a9cd49bb 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -37,11 +37,24 @@ * - ... */ -NewGui::NewGui(Scumm *s) : _s(s), _use_alpha_blending(false), - _need_redraw(false),_prepare_for_gui(true), +// FIXME - this macro assumes that we use 565 mode. But what if we are in 555 mode? +#define RGB_TO_16(r,g,b) (((((r)>>3)&0x1F) << 11) | ((((g)>>2)&0x3F) << 5) | (((b)>>3)&0x1F)) +//#define RGB_TO_16(r,g,b) (((((r)>>3)&0x1F) << 10) | ((((g)>>3)&0x1F) << 5) | (((b)>>3)&0x1F)) + +#define RED_FROM_16(x) ((((x)>>11)&0x1F) << 3) +#define GREEN_FROM_16(x) ((((x)>>5)&0x3F) << 2) +#define BLUE_FROM_16(x) (((x)&0x1F) << 3) + +//#define RED_FROM_16(x) ((((x)>>10)&0x1F) << 3) +//#define GREEN_FROM_16(x) ((((x)>>5)&0x1F) << 3) +//#define BLUE_FROM_16(x) (((x)&0x1F) << 3) + + +NewGui::NewGui(Scumm *s) : _s(s), _system(s->_system), _screen(0), + _use_alpha_blending(true), _need_redraw(false),_prepare_for_gui(true), _pauseDialog(0), _saveLoadDialog(0), _aboutDialog(0), _optionsDialog(0), _currentKeyDown(0) -{ +{ } void NewGui::pauseDialog() @@ -54,7 +67,7 @@ void NewGui::pauseDialog() void NewGui::saveloadDialog() { if (!_saveLoadDialog) - _saveLoadDialog = new SaveLoadDialog(this); + _saveLoadDialog = new SaveLoadDialog(this, _s); _saveLoadDialog->open(); } @@ -75,7 +88,7 @@ void NewGui::optionsDialog() void NewGui::soundDialog() { if (!_soundDialog) - _soundDialog = new SoundDialog(this); + _soundDialog = new SoundDialog(this, _s); _soundDialog->open(); } @@ -85,22 +98,14 @@ void NewGui::loop() int i; if (_prepare_for_gui) { - ClearBlendCache(_s->_currentPalette, 128); saveState(); - if (_use_alpha_blending) - activeDialog->setupScreenBuf(); -#if 1 - // FIXME - hack to encode our own custom GUI colors. Since we have to live - // with a given 8 bit palette, the result is not always as nice as one - // would wish, but this is just an experiment after all. - _bgcolor = RGBMatch(_s->_currentPalette, 0, 0, 0); - - _color = RGBMatch(_s->_currentPalette, 80, 80, 80); - _shadowcolor = RGBMatch(_s->_currentPalette, 64, 64, 64); - - _textcolor = RGBMatch(_s->_currentPalette, 32, 192, 32); - _textcolorhi = RGBMatch(_s->_currentPalette, 0, 256, 0); -#endif + + // Setup some default GUI colors + _bgcolor = RGB_TO_16(0, 0, 0); + _color = RGB_TO_16(80, 80, 80); + _shadowcolor = RGB_TO_16(64, 64, 64); + _textcolor = RGB_TO_16(32, 192, 32); + _textcolorhi = RGB_TO_16(0, 255, 0); _eventList.clear(); _currentKeyDown = 0; @@ -115,6 +120,10 @@ void NewGui::loop() activeDialog->handleTickle(); if (_need_redraw) { + // Restore the overlay to its initial state, then draw all dialogs. + // This is necessary to get the blending right. + _system->clear_overlay(); + _system->grab_overlay(_screen, _screen_pitch); for (i = 0; i < _dialogStack.size(); i++) _dialogStack[i]->draw(); _need_redraw = false; @@ -152,7 +161,7 @@ void NewGui::loop() // We don't distinguish between mousebuttons (for now at least) case OSystem::EVENT_LBUTTONDOWN: case OSystem::EVENT_RBUTTONDOWN: { - uint32 time = _s->_system->get_msecs(); + uint32 time = _system->get_msecs(); if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay) && ABS(_lastClick.x - t.mouse.x) < 3 && ABS(_lastClick.y - t.mouse.y) < 3) { @@ -208,10 +217,16 @@ void NewGui::saveState() _old_cursorHeight = _s->_cursorHeight; _old_cursorHotspotX = _s->_cursorHotspotX; _old_cursorHotspotY = _s->_cursorHotspotY; - _old_cursor_mode = _s->_system->show_mouse(true); + _old_cursor_mode = _system->show_mouse(true); _s->_cursorAnimate++; _s->gdi._cursorActive = 1; + + // TODO - add getHeight & getWidth methods to OSystem + _system->show_overlay(); + _screen = new int16[_s->_realWidth * _s->_realHeight]; + _screen_pitch = _s->_realWidth; + _system->grab_overlay(_screen, _screen_pitch); } void NewGui::restoreState() @@ -228,17 +243,21 @@ void NewGui::restoreState() _s->_cursorHotspotY = _old_cursorHotspotY; _s->updateCursor(); - _s->_system->show_mouse(_old_cursor_mode); + _system->show_mouse(_old_cursor_mode); _s->_sound->pauseSounds(_old_soundsPaused); + + _system->hide_overlay(); + if (_screen) { + delete _screen; + _screen = 0; + } } void NewGui::openDialog(Dialog *dialog) { if (_dialogStack.empty()) _prepare_for_gui = true; - else if (_use_alpha_blending) - dialog->setupScreenBuf(); _dialogStack.push(dialog); _need_redraw = true; @@ -250,10 +269,6 @@ void NewGui::closeTopDialog() if (_dialogStack.empty()) return; - // Tear down its screenBuf - if (_use_alpha_blending) - _dialogStack.top()->teardownScreenBuf(); - // Remove the dialog from the stack _dialogStack.pop(); if (_dialogStack.empty()) @@ -304,15 +319,9 @@ const char *NewGui::queryCustomString(int stringno) #pragma mark - -byte *NewGui::getBasePtr(int x, int y) +int16 *NewGui::getBasePtr(int x, int y) { - VirtScreen *vs = _s->findVirtScreen(y); - - if (vs == NULL) - return NULL; - - return vs->screenPtr + x + (y - vs->topline) * _s->_realWidth + - _s->_screenStartStrip * 8 + (_s->camera._cur.y - (_s->_realHeight / 2)) * _s->_realWidth; + return _screen + x + y * _screen_pitch; } void NewGui::box(int x, int y, int width, int height) @@ -328,9 +337,9 @@ void NewGui::box(int x, int y, int width, int height) vline(x + width - 2, y + 1, y + height - 1, _shadowcolor); } -void NewGui::line(int x, int y, int x2, int y2, byte color) +void NewGui::line(int x, int y, int x2, int y2, int16 color) { - byte *ptr; + int16 *ptr; if (x2 < x) x2 ^= x ^= x2 ^= x; // Swap x2 and x @@ -347,7 +356,7 @@ void NewGui::line(int x, int y, int x2, int y2, byte color) /* vertical line */ while (y++ <= y2) { *ptr = color; - ptr += _s->_realWidth; + ptr += _screen_pitch; } } else if (y == y2) { /* horizontal line */ @@ -357,53 +366,61 @@ void NewGui::line(int x, int y, int x2, int y2, byte color) } } -void NewGui::blendRect(int x, int y, int w, int h, byte color) +void NewGui::blendRect(int x, int y, int w, int h, int16 color) { - byte *ptr = getBasePtr(x, y); + int r = RED_FROM_16(color); + int g = GREEN_FROM_16(color); + int b = BLUE_FROM_16(color); + int16 *ptr = getBasePtr(x, y); if (ptr == NULL) return; while (h--) { for (int i = 0; i < w; i++) { - ptr[i] = Blend(ptr[i], color, _s->_currentPalette); + ptr[i] = RGB_TO_16((RED_FROM_16(ptr[i])+r)/2, + (GREEN_FROM_16(ptr[i])+g)/2, + (BLUE_FROM_16(ptr[i])+b)/2); +// ptr[i] = color; } - ptr += _s->_realWidth; + ptr += _screen_pitch; } } -void NewGui::fillRect(int x, int y, int w, int h, byte color) +void NewGui::fillRect(int x, int y, int w, int h, int16 color) { - byte *ptr = getBasePtr(x, y); + int i; + int16 *ptr = getBasePtr(x, y); if (ptr == NULL) return; while (h--) { - for (int i = 0; i < w; i++) { + for (i = 0; i < w; i++) { ptr[i] = color; } - ptr += _s->_realWidth; + ptr += _screen_pitch; } } -void NewGui::checkerRect(int x, int y, int w, int h, byte color) +void NewGui::checkerRect(int x, int y, int w, int h, int16 color) { - byte *ptr = getBasePtr(x, y); + int i; + int16 *ptr = getBasePtr(x, y); if (ptr == NULL) return; while (h--) { - for (int i = 0; i < w; i++) { + for (i = 0; i < w; i++) { if ((h ^ i) & 1) ptr[i] = color; } - ptr += _s->_realWidth; + ptr += _screen_pitch; } } -void NewGui::frameRect(int x, int y, int w, int h, byte color) +void NewGui::frameRect(int x, int y, int w, int h, int16 color) { int i; - byte *ptr, *basePtr = getBasePtr(x, y); + int16 *ptr, *basePtr = getBasePtr(x, y); if (basePtr == NULL) return; @@ -411,57 +428,57 @@ void NewGui::frameRect(int x, int y, int w, int h, byte color) for (i = 0; i < w; i++, ptr++) *ptr = color; ptr--; - for (i = 0; i < h; i++, ptr += _s->_realWidth) + for (i = 0; i < h; i++, ptr += _screen_pitch) *ptr = color; ptr = basePtr; - for (i = 0; i < h; i++, ptr += _s->_realWidth) + for (i = 0; i < h; i++, ptr += _screen_pitch) *ptr = color; - ptr -= _s->_realWidth; + ptr -= _screen_pitch; for (i = 0; i < w; i++, ptr++) *ptr = color; } void NewGui::addDirtyRect(int x, int y, int w, int h) { - VirtScreen *vs = _s->findVirtScreen(y); - - if (vs != NULL) - _s->setVirtscreenDirty(vs, x, y, x + w, y + h); + // For now we don't keep yet another list of dirty rects but simply + // blit the affected area directly to the overlay. At least for our current + // GUI/widget/dialog code that is just fine. + int16 *buf = getBasePtr(x, y); + _system->copy_rect_overlay(buf, _screen_pitch, x, y, w, h); } -void NewGui::drawChar(const char str, int xx, int yy) +void NewGui::drawChar(const char str, int xx, int yy, int16 color) { unsigned int buffer = 0, mask = 0, x, y; byte *tmp; - int tempc = _color; - _color = _textcolor; tmp = &guifont[0]; tmp += 224 + (str + 1) * 8; - byte *ptr = getBasePtr(xx, yy); + int16 *ptr = getBasePtr(xx, yy); if (ptr == NULL) return; for (y = 0; y < 8; y++) { for (x = 0; x < 8; x++) { - unsigned char color; + unsigned char c; if ((mask >>= 1) == 0) { buffer = *tmp++; mask = 0x80; } - color = ((buffer & mask) != 0); - if (color) - ptr[x] = _color; + c = ((buffer & mask) != 0); + if (c) + ptr[x] = color; } - ptr += _s->_realWidth; + ptr += _screen_pitch; } - _color = tempc; - } -void NewGui::drawString(const char *str, int x, int y, int w, byte color, int align) +void NewGui::drawString(const char *str, int x, int y, int w, int16 color, int align) { +#if 1 + if (0) { +#else if (_s->_gameId) { /* If a game is active.. */ StringTab *st = &_s->string[5]; st->charset = 1; @@ -480,22 +497,23 @@ void NewGui::drawString(const char *str, int x, int y, int w, byte color, int al _s->_messagePtr = (byte *)str; _s->drawString(5); +#endif } else { // FIXME - support center/right align, use nicer custom font. // Ultimately, we might want to *always* draw our messages this way, // but only if we have a nice font. uint len = strlen(str); for (uint letter = 0; letter < len; letter++) - drawChar(str[letter], x + (letter * 8), y); + drawChar(str[letter], x + (letter * 8), y, color); } } /* * Draw an 8x8 bitmap at location (x,y) */ -void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, byte color) +void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, int16 color) { - byte *ptr = getBasePtr(x, y); + int16 *ptr = getBasePtr(x, y); if (ptr == NULL) return; @@ -506,39 +524,6 @@ void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, byte color) ptr[x2] = color; mask >>= 4; } - ptr += _s->_realWidth; - } -} - -void NewGui::blitTo(byte buffer[320*200], int x, int y, int w, int h) -{ - byte *dstPtr = buffer + x + y * _s->_realWidth; - byte *srcPtr = getBasePtr(x, y); - if (srcPtr == NULL) - return; - - while (h--) { - for (int i = 0; i < w; i++) { - *dstPtr++ = *srcPtr++; - } - dstPtr += _s->_realWidth - w; - srcPtr += _s->_realWidth - w; + ptr += _screen_pitch; } } - -void NewGui::blitFrom(byte buffer[320*200], int x, int y, int w, int h) -{ - byte *srcPtr = buffer + x + y * _s->_realWidth; - byte *dstPtr = getBasePtr(x, y); - if (dstPtr == NULL) - return; - - while (h--) { - for (int i = 0; i < w; i++) { - *dstPtr++ = *srcPtr++; - } - dstPtr += _s->_realWidth - w; - srcPtr += _s->_realWidth - w; - } -} - diff --git a/gui/newgui.h b/gui/newgui.h index 0b0aef913a..0df581d31b 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -63,10 +63,10 @@ typedef ScummVM::List<OSystem::Event> EventList; class NewGui { friend class Dialog; public: - byte _color, _shadowcolor; - byte _bgcolor; - byte _textcolor; - byte _textcolorhi; + int16 _color, _shadowcolor; + int16 _bgcolor; + int16 _textcolor; + int16 _textcolorhi; // Dialogs void pauseDialog(); @@ -82,11 +82,13 @@ public: NewGui(Scumm *s); void handleEvent(const OSystem::Event &event) { _eventList.push_back(event); } - - Scumm *getScumm() { return _s; } protected: Scumm *_s; + OSystem *_system; + int16 *_screen; + int _screen_pitch; + bool _use_alpha_blending; bool _need_redraw; bool _prepare_for_gui; @@ -129,20 +131,18 @@ protected: public: // Drawing - byte *getBasePtr(int x, int y); + int16 *getBasePtr(int x, int y); void box(int x, int y, int width, int height); - void line(int x, int y, int x2, int y2, byte color); - void blendRect(int x, int y, int w, int h, byte color); - void fillRect(int x, int y, int w, int h, byte color); - void checkerRect(int x, int y, int w, int h, byte color); - void frameRect(int x, int y, int w, int h, byte color); + void line(int x, int y, int x2, int y2, int16 color); + void blendRect(int x, int y, int w, int h, int16 color); + void fillRect(int x, int y, int w, int h, int16 color); + void checkerRect(int x, int y, int w, int h, int16 color); + void frameRect(int x, int y, int w, int h, int16 color); void addDirtyRect(int x, int y, int w, int h); - void drawChar(const char c, int x, int y); - void drawString(const char *str, int x, int y, int w, byte color, int align = kTextAlignLeft); + void drawChar(const char c, int x, int y, int16 color); + void drawString(const char *str, int x, int y, int w, int16 color, int align = kTextAlignLeft); - void drawBitmap(uint32 bitmap[8], int x, int y, byte color); - void blitTo(byte buffer[320*200], int x, int y, int w, int h); - void blitFrom(byte buffer[320*200], int x, int y, int w, int h); + void drawBitmap(uint32 bitmap[8], int x, int y, int16 color); // Query a string from the resources const char *queryResString(int stringno); diff --git a/gui/widget.cpp b/gui/widget.cpp index e822617460..f6aedbad76 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -58,9 +58,6 @@ void Widget::draw() // Now perform the actual widget draw drawWidget(_flags & WIDGET_HILITED); - - // Flag the draw area as dirty - gui->addDirtyRect(_x, _y, _w, _h); // Restore x/y if (_flags & WIDGET_BORDER) { @@ -68,6 +65,10 @@ void Widget::draw() _y -= 4; _w += 8; } + + // Flag the draw area as dirty + gui->addDirtyRect(_x, _y, _w, _h); + _x -= _boss->_x; _y -= _boss->_y; } |