From f838473c25cba44a858a341558c34367fe1a44ea Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 19 Sep 2002 23:06:54 +0000 Subject: NewGui now has its own mouse cursor code -> again one less dependency on Scumm; moved makeCursorColorTransparent to gfx.cpp where it belongs svn-id: r4977 --- gui/newgui.cpp | 58 +++++++++++++++++++++++++++++++++++----------------------- gui/newgui.h | 13 ++++++++----- 2 files changed, 43 insertions(+), 28 deletions(-) (limited to 'gui') diff --git a/gui/newgui.cpp b/gui/newgui.cpp index d110c474c9..e2c3dfb639 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -70,7 +70,7 @@ static byte guifont[] = { // Constructor NewGui::NewGui(Scumm *s) : _s(s), _system(s->_system), _screen(0), _use_alpha_blending(true), _need_redraw(false), _prepare_for_gui(true), - _currentKeyDown(0) + _currentKeyDown(0), _cursorAnimateCounter(0) { // Setup some default GUI colors. // TODO - either use nicer values, or maybe make this configurable? @@ -79,6 +79,9 @@ NewGui::NewGui(Scumm *s) : _s(s), _system(s->_system), _screen(0), _shadowcolor = RGB_TO_16(64, 64, 64); _textcolor = RGB_TO_16(32, 160, 32); _textcolorhi = RGB_TO_16(0, 255, 0); + + // Clear the cursor + memset(_cursor, 0xFF, sizeof(_cursor)); } void NewGui::loop() @@ -111,7 +114,7 @@ void NewGui::loop() _need_redraw = false; } - _s->animateCursor(); + animateCursor(); if (_eventList.size() > 0) { @@ -188,19 +191,12 @@ void NewGui::loop() void NewGui::saveState() { + // Pause sound put _old_soundsPaused = _s->_sound->_soundsPaused; _s->_sound->pauseSounds(true); // Backup old cursor - memcpy(_old_grabbedCursor, _s->_grabbedCursor, sizeof(_old_grabbedCursor)); - _old_cursorWidth = _s->_cursorWidth; - _old_cursorHeight = _s->_cursorHeight; - _old_cursorHotspotX = _s->_cursorHotspotX; - _old_cursorHotspotY = _s->_cursorHotspotY; - _old_cursor_mode = _system->show_mouse(true); - - _s->_cursorAnimate++; - _s->gdi._cursorActive = 1; + _oldCursorMode = _system->show_mouse(true); // TODO - add getHeight & getWidth methods to OSystem _system->show_overlay(); @@ -211,18 +207,11 @@ void NewGui::saveState() void NewGui::restoreState() { - _s->_cursorAnimate--; - // Restore old cursor - memcpy(_s->_grabbedCursor, _old_grabbedCursor, sizeof(_old_grabbedCursor)); - _s->_cursorWidth = _old_cursorWidth; - _s->_cursorHeight = _old_cursorHeight; - _s->_cursorHotspotX = _old_cursorHotspotX; - _s->_cursorHotspotY = _old_cursorHotspotY; _s->updateCursor(); + _system->show_mouse(_oldCursorMode); - _system->show_mouse(_old_cursor_mode); - + // Resume sound output _s->_sound->pauseSounds(_old_soundsPaused); _system->hide_overlay(); @@ -439,9 +428,9 @@ void NewGui::drawString(const char *str, int x, int y, int w, int16 color, int a } } -/* - * Draw an 8x8 bitmap at location (x,y) - */ +// +// Draw an 8x8 bitmap at location (x,y) +// void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, int16 color) { int16 *ptr = getBasePtr(x, y); @@ -458,3 +447,26 @@ void NewGui::drawBitmap(uint32 bitmap[8], int x, int y, int16 color) ptr += _screen_pitch; } } + +// +// Draw the mouse cursor (animated). This is mostly ripped from the cursor code in gfx.cpp +// We could plug in a different cursor here if we like to. +// +void NewGui::animateCursor() +{ + if (0 == (_cursorAnimateCounter & 0x3)) { + const byte colors[4] = { 15, 15, 7, 8 }; + const byte color = colors[(_cursorAnimateCounter >> 2) & 3]; + int i; + + for (i = 0; i < 16; i++) { + if ((i < 7) || (i > 9)) { + _cursor[16 * 8 + i] = color; + _cursor[16 * i + 8] = color; + } + } + + _system->set_mouse_cursor(_cursor, 16, 16, 8, 8); + } + _cursorAnimateCounter++; +} diff --git a/gui/newgui.h b/gui/newgui.h index 583a7d6c1c..1f38558097 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -94,11 +94,6 @@ protected: // sound state bool _old_soundsPaused; - - // mouse cursor state - bool _old_cursor_mode; - int _old_cursorHotspotX, _old_cursorHotspotY, _old_cursorWidth, _old_cursorHeight; - byte _old_grabbedCursor[2048]; // position and time of last mouse click (used to detect double clicks) struct { @@ -109,12 +104,20 @@ protected: // List of events to be handled EventList _eventList; + + + // mouse cursor state + bool _oldCursorMode; + int _cursorAnimateCounter; + byte _cursor[2048]; void saveState(); void restoreState(); void openDialog(Dialog *dialog); void closeTopDialog(); + + void animateCursor(); public: // Drawing -- cgit v1.2.3