aboutsummaryrefslogtreecommitdiff
path: root/gui/newgui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/newgui.cpp')
-rw-r--r--gui/newgui.cpp205
1 files changed, 95 insertions, 110 deletions
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;
- }
-}
-