aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/wage/gui.cpp237
-rw-r--r--engines/wage/gui.h9
2 files changed, 29 insertions, 217 deletions
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 05af5667e6..5aa4531388 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -342,150 +342,43 @@ void Gui::drawConsole() {
static void consoleWindowCallback(WindowClick click, Common::Event &event, void *g) {
Gui *gui = (Gui *)g;
- if (click == kBorderScrollUp || click == kBorderScrollDown) {
- int textFullSize = gui->getLinesSize() * gui->getConsoleLineHeight() + gui->getConsoleTextAreaHeight();
- float scrollPos = (float)gui->getScrollPos() / textFullSize;
- float scrollSize = (float)gui->getConsoleTextAreaHeight() / textFullSize;
-
- gui->_consoleWindow->setScroll(scrollPos, scrollSize);
-
- return;
- }
-}
-
-void Gui::drawBox(Graphics::ManagedSurface *g, int x, int y, int w, int h) {
- Common::Rect r(x, y, x + w + 1, y + h + 1);
-
- g->fillRect(r, kColorWhite);
- g->frameRect(r, kColorBlack);
-}
-
-void Gui::fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h, int color) {
- Common::Rect r(x, y, x + w, y + h);
-
- g->fillRect(r, color);
-}
-
-#define ARROW_W 12
-#define ARROW_H 6
-const int arrowPixels[ARROW_H][ARROW_W] = {
- {0,0,0,0,0,1,1,0,0,0,0,0},
- {0,0,0,0,1,1,1,1,0,0,0,0},
- {0,0,0,1,1,1,1,1,1,0,0,0},
- {0,0,1,1,1,1,1,1,1,1,0,0},
- {0,1,1,1,1,1,1,1,1,1,1,0},
- {1,1,1,1,1,1,1,1,1,1,1,1}};
-
-static void drawPixelInverted(int x, int y, int color, void *data) {
- Graphics::ManagedSurface *surface = (Graphics::ManagedSurface *)data;
+ gui->processConsoleEvents(click, event);
- if (x >= 0 && x < surface->w && y >= 0 && y < surface->h) {
- byte *p = (byte *)surface->getBasePtr(x, y);
-
- *p = *p == kColorWhite ? kColorBlack : kColorWhite;
- }
}
-void Gui::paintBorder(Graphics::ManagedSurface *g, Common::Rect &r, WindowType windowType, int highlightedPart, float scrollPos, float scrollSize) {
- bool active = false, scrollable = false, closeable = false, drawTitle = false;
- const int size = kBorderWidth;
- int x = r.left - size;
- int y = r.top - size;
- int width = r.width() + 2 * size;
- int height = r.height() + 2 * size;
-
- switch (windowType) {
- case kWindowScene:
- active = _sceneIsActive;
- scrollable = false;
- closeable = _sceneIsActive;
- drawTitle = true;
- break;
- case kWindowConsole:
- active = !_sceneIsActive;
- scrollable = true;
- closeable = !_sceneIsActive;
- drawTitle = false;
- break;
- }
-
- drawBox(g, x, y, size, size);
- drawBox(g, x + width - size - 1, y, size, size);
- drawBox(g, x + width - size - 1, y + height - size - 1, size, size);
- drawBox(g, x, y + height - size - 1, size, size);
- drawBox(g, x + size, y + 2, width - 2 * size - 1, size - 4);
- drawBox(g, x + size, y + height - size + 1, width - 2 * size - 1, size - 4);
- drawBox(g, x + 2, y + size, size - 4, height - 2 * size - 1);
- drawBox(g, x + width - size + 1, y + size, size - 4, height - 2 * size - 1);
-
- if (active) {
- fillRect(g, x + size, y + 5, width - 2 * size - 1, 8);
- fillRect(g, x + size, y + height - 13, width - 2 * size - 1, 8);
- fillRect(g, x + 5, y + size, 8, height - 2 * size - 1);
- if (!scrollable) {
- fillRect(g, x + width - 13, y + size, 8, height - 2 * size - 1);
- } else {
- int x1 = x + width - 15;
- int y1 = y + size + 1;
-
- for (int yy = 0; yy < ARROW_H; yy++) {
- for (int xx = 0; xx < ARROW_W; xx++)
- g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[yy][xx] != 0 ? kColorBlack : kColorWhite));
- }
-
- fillRect(g, x + width - 13, y + size + ARROW_H, 8, height - 2 * size - 1 - ARROW_H * 2);
-
- y1 += height - 2 * size - ARROW_H - 2;
- for (int yy = 0; yy < ARROW_H; yy++) {
- for (int xx = 0; xx < ARROW_W; xx++)
- g->hLine(x1 + xx, y1 + yy, x1 + xx, (arrowPixels[ARROW_H - yy - 1][xx] != 0 ? kColorBlack : kColorWhite));
- }
+void Gui::processConsoleEvents(WindowClick click, Common::Event &event) {
+ if (click == kBorderScrollUp || click == kBorderScrollDown) {
+ if (event.type == Common::EVENT_LBUTTONDOWN) {
+ int textFullSize = _lines.size() * _consoleLineHeight + _consoleTextArea.height();
+ float scrollPos = (float)_scrollPos / textFullSize;
+ float scrollSize = (float)_consoleTextArea.height() / textFullSize;
- if (highlightedPart == kBorderScrollUp || highlightedPart == kBorderScrollDown) {
- int rx1 = x + width - kBorderWidth + 2;
- int ry1 = y + size + r.height() * scrollPos;
- int rx2 = rx1 + size - 4;
- int ry2 = ry1 + r.height() * scrollSize;
- Common::Rect rr(rx1, ry1, rx2, ry2);
+ _consoleWindow->setScroll(scrollPos, scrollSize);
+ } else if (event.type == Common::EVENT_LBUTTONUP) {
+ int oldScrollPos = _scrollPos;
- Graphics::drawFilledRect(rr, kColorBlack, drawPixelInverted, g);
- }
- }
- if (closeable) {
- if (highlightedPart == kBorderCloseButton) {
- fillRect(g, x + 6, y + 6, 6, 6);
- } else {
- drawBox(g, x + 5, y + 5, 7, 7);
+ switch (click) {
+ case kBorderScrollUp:
+ _scrollPos = MAX<int>(0, _scrollPos - _consoleLineHeight);
+ undrawCursor();
+ _cursorY -= (_scrollPos - oldScrollPos);
+ _consoleDirty = true;
+ _consoleFullRedraw = true;
+ break;
+ case kBorderScrollDown:
+ _scrollPos = MIN<int>((_lines.size() - 2) * _consoleLineHeight, _scrollPos + _consoleLineHeight);
+ undrawCursor();
+ _cursorY -= (_scrollPos - oldScrollPos);
+ _consoleDirty = true;
+ _consoleFullRedraw = true;
+ break;
+ default:
+ break;
}
}
- }
- if (drawTitle) {
- const Graphics::Font *font = getTitleFont();
- int yOff = _builtInFonts ? 3 : 1;
-
- int w = font->getStringWidth(_scene->_name) + 10;
- int maxWidth = width - size * 2 - 7;
- if (w > maxWidth)
- w = maxWidth;
- drawBox(g, x + (width - w) / 2, y, w, size);
- font->drawString(g, _scene->_name, x + (width - w) / 2 + 5, y + yOff, w, kColorBlack);
- }
-
- if (x < 0) {
- width += x;
- x = 0;
- }
- if (y < 0) {
- height += y;
- y = 0;
+ return;
}
- if (x + width > _screen.w)
- width = _screen.w - x;
- if (y + height > _screen.h)
- height = _screen.h - y;
-
- g_system->copyRectToScreen(g->getBasePtr(x, y), g->pitch, x, y, width, height);
}
void Gui::loadFonts() {
@@ -602,26 +495,6 @@ bool Gui::processEvent(Common::Event &event) {
return true;
}
-static int isInBorder(Common::Rect &rect, int x, int y) {
- if (x >= rect.left - kBorderWidth && x < rect.left && y >= rect.top - kBorderWidth && y < rect.top)
- return kBorderCloseButton;
-
- if (x >= rect.right && x < rect.right + kBorderWidth) {
- if (y < rect.top - kBorderWidth)
- return kBorderNone;
-
- if (y >= rect.bottom + kBorderWidth)
- return kBorderNone;
-
- if (y >= rect.top + rect.height() / 2)
- return kBorderScrollDown;
-
- return kBorderScrollUp;
- }
-
- return kBorderNone;
-}
-
Designed *Gui::mouseUp(int x, int y) {
if (_menu->_menuActivated) {
if (_menu->mouseRelease(x, y)) {
@@ -655,68 +528,14 @@ Designed *Gui::mouseUp(int x, int y) {
}
}
- int borderClick;
-
- if (_sceneArea.contains(x, y)) {
- if (!_sceneIsActive) {
- _sceneIsActive = true;
- _bordersDirty = true;
- }
-
- for (ObjList::const_iterator it = _scene->_objs.end(); it != _scene->_objs.begin(); ) {
- it--;
- if ((*it)->_design->isPointOpaque(x - _sceneArea.left + kBorderWidth, y - _sceneArea.top + kBorderWidth))
- return *it;
- }
-
- for (ChrList::const_iterator it = _scene->_chrs.end(); it != _scene->_chrs.begin(); ) {
- it--;
- if ((*it)->_design->isPointOpaque(x - _sceneArea.left + kBorderWidth, y - _sceneArea.top + kBorderWidth))
- return *it;
- }
- } else if (_consoleTextArea.contains(x, y)) {
- if (_sceneIsActive) {
- _sceneIsActive = false;
- _bordersDirty = true;
- }
- } else if ((borderClick = isInBorder(_consoleTextArea, x, y)) != kBorderNone) {
- _bordersDirty = true;
- int _oldScrollPos = _scrollPos;
-
- switch (borderClick) {
- case kBorderScrollUp:
- _scrollPos = MAX<int>(0, _scrollPos - _consoleLineHeight);
- undrawCursor();
- _cursorY -= (_scrollPos - _oldScrollPos);
- _consoleDirty = true;
- _consoleFullRedraw = true;
- break;
- case kBorderScrollDown:
- _scrollPos = MIN<int>((_lines.size() - 2) * _consoleLineHeight, _scrollPos + _consoleLineHeight);
- undrawCursor();
- _cursorY -= (_scrollPos - _oldScrollPos);
- _consoleDirty = true;
- _consoleFullRedraw = true;
- break;
- }
- }
-
return NULL;
}
void Gui::mouseDown(int x, int y) {
- int borderClick;
-
if (_menu->mouseClick(x, y)) {
_menuDirty = true;
} else if (_consoleTextArea.contains(x, y)) {
startMarking(x, y);
- } else if ((borderClick = isInBorder(_consoleTextArea, x, y)) != kBorderNone) {
- int textFullSize = _lines.size() * _consoleLineHeight + _consoleTextArea.height();
- float scrollPos = (float)_scrollPos / textFullSize;
- float scrollSize = (float)_consoleTextArea.height() / textFullSize;
-
- paintBorder(&_screen, _consoleTextArea, kWindowConsole, borderClick, scrollPos, scrollSize);
}
}
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index baf167a370..aadb7ea3c8 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -114,21 +114,14 @@ public:
bool builtInFonts() { return _builtInFonts; }
- uint getScrollPos() { return _scrollPos; }
- uint getLinesSize() { return _lines.size(); }
- int getConsoleLineHeight() { return _consoleLineHeight; }
- int getConsoleTextAreaHeight() { return _consoleTextArea.height(); }
+ void processConsoleEvents(WindowClick click, Common::Event &event);
private:
void drawScene();
void drawConsole();
void undrawCursor();
void drawDesktop();
- void paintBorder(Graphics::ManagedSurface *g, Common::Rect &r, WindowType windowType, int highlightedPart = kBorderNone,
- float scrollPos = 0.0, float scrollSize = 0.0);
void renderConsole(Graphics::ManagedSurface *g, const Common::Rect &r);
- void drawBox(Graphics::ManagedSurface *g, int x, int y, int w, int h);
- void fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h, int color = kColorBlack);
void loadFonts();
void flowText(Common::String &str);
const Graphics::Font *getConsoleFont();