aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJoseph-Eugene Winzer2018-02-23 19:32:21 +0100
committerJoseph-Eugene Winzer2018-03-11 23:25:00 +0100
commitbb9bfcba4a1cf83eb4c29142760785c38587c0bb (patch)
treecf44560c69ba17725626fa655152a28584579715 /engines
parent7f5cea54e3b31370f8630503bf163e622ce93718 (diff)
downloadscummvm-rg350-bb9bfcba4a1cf83eb4c29142760785c38587c0bb.tar.gz
scummvm-rg350-bb9bfcba4a1cf83eb4c29142760785c38587c0bb.tar.bz2
scummvm-rg350-bb9bfcba4a1cf83eb4c29142760785c38587c0bb.zip
SUPERNOVA: Encapsulates GuiElement
It simplifies the overloaded functions for renderBox/Text and saveScreen
Diffstat (limited to 'engines')
-rw-r--r--engines/supernova/state.cpp57
-rw-r--r--engines/supernova/state.h17
-rw-r--r--engines/supernova/supernova.cpp27
-rw-r--r--engines/supernova/supernova.h4
4 files changed, 56 insertions, 49 deletions
diff --git a/engines/supernova/state.cpp b/engines/supernova/state.cpp
index e3e341e11f..798bfe1f13 100644
--- a/engines/supernova/state.cpp
+++ b/engines/supernova/state.cpp
@@ -1464,56 +1464,31 @@ void GameManager::takeObject(Object &obj) {
void GameManager::drawCommandBox() {
for (int i = 0; i < ARRAYSIZE(_guiCommandButton); ++i) {
- _vm->renderBox(_guiCommandButton[i].left,
- _guiCommandButton[i].top,
- _guiCommandButton[i].width(),
- _guiCommandButton[i].height(),
- _guiCommandButton[i]._bgColor);
- int space = (_guiCommandButton[i].width() - _vm->textWidth(_guiCommandButton[i]._text)) / 2;
- _vm->renderText(_guiCommandButton[i]._text,
- _guiCommandButton[i]._textPosition.x + space,
- _guiCommandButton[i]._textPosition.y,
- _guiCommandButton[i]._textColor);
+ _vm->renderBox(_guiCommandButton[i]);
+ int space = (_guiCommandButton[i].width() - _vm->textWidth(_guiCommandButton[i].getText())) / 2;
+ _vm->renderText(_guiCommandButton[i].getText(),
+ _guiCommandButton[i].getTextPos().x + space,
+ _guiCommandButton[i].getTextPos().y,
+ _guiCommandButton[i].getTextColor());
}
}
void GameManager::drawInventory() {
for (int i = 0; i < ARRAYSIZE(_guiInventory); ++i) {
- _vm->renderBox(_guiInventory[i].left,
- _guiInventory[i].top,
- _guiInventory[i].width(),
- _guiInventory[i].height(),
- _guiInventory[i]._bgColor);
-
+ _vm->renderBox(_guiInventory[i]);
_vm->renderText(_inventory.get(i + _inventoryScroll)->_name,
- _guiInventory[i]._textPosition.x,
- _guiInventory[i]._textPosition.y,
- _guiInventory[i]._textColor);
+ _guiInventory[i].getTextPos().x,
+ _guiInventory[i].getTextPos().y,
+ _guiInventory[i].getTextColor());
}
- _vm->renderBox(_guiInventoryArrow[0].left,
- _guiInventoryArrow[0].top,
- _guiInventoryArrow[0].width(),
- _guiInventoryArrow[0].height(),
- _guiInventoryArrow[0]._bgColor);
- _vm->renderBox(_guiInventoryArrow[1].left,
- _guiInventoryArrow[1].top,
- _guiInventoryArrow[1].width(),
- _guiInventoryArrow[1].height(),
- _guiInventoryArrow[1]._bgColor);
+ _vm->renderBox(_guiInventoryArrow[0]);
+ _vm->renderBox(_guiInventoryArrow[1]);
if (_inventory.getSize() > ARRAYSIZE(_guiInventory)) {
- if (_inventoryScroll != 0) {
- _vm->renderText(_guiInventoryArrow[0]._text,
- _guiInventoryArrow[0]._textPosition.x,
- _guiInventoryArrow[0]._textPosition.y,
- _guiInventoryArrow[0]._textColor);
- }
- if (_inventoryScroll + ARRAYSIZE(_guiInventory) < _inventory.getSize()) {
- _vm->renderText(_guiInventoryArrow[1]._text,
- _guiInventoryArrow[1]._textPosition.x,
- _guiInventoryArrow[1]._textPosition.y,
- _guiInventoryArrow[1]._textColor);
- }
+ if (_inventoryScroll != 0)
+ _vm->renderText(_guiInventoryArrow[0]);
+ if (_inventoryScroll + ARRAYSIZE(_guiInventory) < _inventory.getSize())
+ _vm->renderText(_guiInventoryArrow[1]);
}
}
diff --git a/engines/supernova/state.h b/engines/supernova/state.h
index 9072aa26f1..e361cb7057 100644
--- a/engines/supernova/state.h
+++ b/engines/supernova/state.h
@@ -91,6 +91,23 @@ public:
void setColor(int bgColor, int textColor, int bgColorHighlighted, int textColorHightlighted);
void setHighlight(bool isHighlighted);
+ const char *getText() const {
+ return _text;
+ }
+ int getBackgroundColor() const {
+ return _bgColor;
+ }
+ int getTextColor() const {
+ return _textColor;
+ }
+ const Common::Point &getTextPos() const {
+ return _textPosition;
+ }
+ bool isHighlighted() const {
+ return _isHighlighted;
+ }
+
+private:
Common::Point _textPosition;
char _text[128];
int _bgColor;
diff --git a/engines/supernova/supernova.cpp b/engines/supernova/supernova.cpp
index 54e87e2aab..170a081dc5 100644
--- a/engines/supernova/supernova.cpp
+++ b/engines/supernova/supernova.cpp
@@ -506,6 +506,9 @@ bool SupernovaEngine::setCurrentImage(int filenumber) {
void SupernovaEngine::saveScreen(int x, int y, int width, int height) {
_screenBuffer.push(x, y, width, height);
}
+void SupernovaEngine::saveScreen(const GuiElement &guiElement) {
+ saveScreen(guiElement.left, guiElement.top, guiElement.width(), guiElement.height());
+}
void SupernovaEngine::restoreScreen() {
_screenBuffer.restore();
@@ -692,6 +695,10 @@ void SupernovaEngine::renderText(const uint16 character) {
text[1] = 0;
renderText(text, _textCursorX, _textCursorY, _textColor);
}
+void SupernovaEngine::renderText(const GuiElement &guiElement) {
+ renderText(guiElement.getText(), guiElement.getTextPos().x,
+ guiElement.getTextPos().y, guiElement.getTextColor());
+}
void SupernovaEngine::renderBox(int x, int y, int width, int height, byte color) {
Graphics::Surface *screen = _system->lockScreen();
@@ -699,6 +706,10 @@ void SupernovaEngine::renderBox(int x, int y, int width, int height, byte color)
_system->unlockScreen();
}
+void SupernovaEngine::renderBox(const GuiElement &guiElement) {
+ renderBox(guiElement.left, guiElement.top, guiElement.width(),
+ guiElement.height(), guiElement.getBackgroundColor());
+}
void SupernovaEngine::paletteBrightness() {
byte palette[768];
@@ -831,14 +842,14 @@ bool SupernovaEngine::quitGameDialog() {
_gm->animationOff();
_gm->saveTime();
- saveScreen(guiQuitBox.left, guiQuitBox.top, guiQuitBox.width(), guiQuitBox.height());
-
- renderBox(guiQuitBox.left, guiQuitBox.top, guiQuitBox.width(), guiQuitBox.height(), guiQuitBox._bgColorNormal);
- renderText(guiQuitBox._text, guiQuitBox._textPosition.x, guiQuitBox._textPosition.y, guiQuitBox._textColorNormal);
- renderBox(guiQuitYes.left, guiQuitYes.top, guiQuitYes.width(), guiQuitYes.height(), guiQuitYes._bgColorNormal);
- renderText(guiQuitYes._text, guiQuitYes._textPosition.x, guiQuitYes._textPosition.y, guiQuitYes._textColorNormal);
- renderBox(guiQuitNo.left, guiQuitNo.top, guiQuitNo.width(), guiQuitNo.height(), guiQuitNo._bgColorNormal);
- renderText(guiQuitNo._text, guiQuitNo._textPosition.x, guiQuitNo._textPosition.y, guiQuitNo._textColorNormal);
+ saveScreen(guiQuitBox);
+
+ renderBox(guiQuitBox);
+ renderText(guiQuitBox);
+ renderBox(guiQuitYes);
+ renderText(guiQuitYes);
+ renderBox(guiQuitNo);
+ renderText(guiQuitNo);
do {
_gm->getInput();
diff --git a/engines/supernova/supernova.h b/engines/supernova/supernova.h
index 7aa6c139c6..e01fb778a5 100644
--- a/engines/supernova/supernova.h
+++ b/engines/supernova/supernova.h
@@ -90,6 +90,7 @@ struct SoundSample {
int _length;
};
+class GuiElement;
class SupernovaEngine : public Engine {
public:
explicit SupernovaEngine(OSystem *syst);
@@ -140,6 +141,7 @@ public:
void renderImage(int section);
bool setCurrentImage(int filenumber);
void saveScreen(int x, int y, int width, int height);
+ void saveScreen(const GuiElement &guiElement);
void restoreScreen();
void renderRoom(Room &room);
void renderMessage(const char *text, MessagePosition position = kMessageNormal);
@@ -148,7 +150,9 @@ public:
void renderText(const uint16 character, int x, int y, byte color);
void renderText(const char *text);
void renderText(const uint16 character);
+ void renderText(const GuiElement &guiElement);
void renderBox(int x, int y, int width, int height, byte color);
+ void renderBox(const GuiElement &guiElement);
void setColor63(byte value);
bool loadGame(int slot);
bool saveGame(int slot, const Common::String &description);