aboutsummaryrefslogtreecommitdiff
path: root/engines/macventure
diff options
context:
space:
mode:
authorBorja Lorente2016-07-04 11:45:47 +0200
committerBorja Lorente2016-08-14 18:46:11 +0200
commit46a85f02d6086bb14a6635a6af77ba85520a7e39 (patch)
treeabb07d085e9d85c3862087da001dd3830ec05e5f /engines/macventure
parent541702206889519515f20c42dd10aaba70630db1 (diff)
downloadscummvm-rg350-46a85f02d6086bb14a6635a6af77ba85520a7e39.tar.gz
scummvm-rg350-46a85f02d6086bb14a6635a6af77ba85520a7e39.tar.bz2
scummvm-rg350-46a85f02d6086bb14a6635a6af77ba85520a7e39.zip
MACVENTURE: Add initial text rendering
Diffstat (limited to 'engines/macventure')
-rw-r--r--engines/macventure/gui.cpp80
-rw-r--r--engines/macventure/gui.h65
-rw-r--r--engines/macventure/macventure.cpp39
-rw-r--r--engines/macventure/macventure.h11
-rw-r--r--engines/macventure/script.cpp2
5 files changed, 135 insertions, 62 deletions
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp
index dc0c4afb09..7ad5eb0d41 100644
--- a/engines/macventure/gui.cpp
+++ b/engines/macventure/gui.cpp
@@ -51,6 +51,14 @@ enum {
kMenuSpecial = 3
};
+enum {
+ kCommandNum = 8
+};
+
+enum {
+ kDragThreshold = 5
+};
+
static const Graphics::MenuData menuSubItems[] = {
{ kMenuHighLevel, "File", 0, 0, false },
{ kMenuHighLevel, "Edit", 0, 0, false },
@@ -106,7 +114,9 @@ Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) {
_draggedObj.pos = Common::Point(0, 0);
_cursor = new Cursor(this);
- g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 1000000, this, "macVentureCursor");
+ g_system->getTimerManager()->installTimerProc(&cursorTimerHandler, 500000, this, "macVentureCursor");
+
+ _consoleText = new ConsoleText(this);
initGUI();
}
@@ -125,6 +135,9 @@ Gui::~Gui() {
if (_cursor)
delete _cursor;
+ if (_consoleText)
+ delete _consoleText;
+
Common::HashMap<ObjID, ImageAsset*>::const_iterator it = _assets.begin();
for (; it != _assets.end(); it++) {
delete it->_value;
@@ -297,8 +310,8 @@ void Gui::initWindows() {
_selfWindow->setDimensions(getWindowData(kSelfWindow).bounds);
_selfWindow->setActive(false);
_selfWindow->setCallback(selfWindowCallback, this);
- loadBorder(_selfWindow, "border_no_scroll_inac.bmp", false);
- loadBorder(_selfWindow, "border_no_scroll_inac.bmp", true);
+ loadBorder(_selfWindow, "border_none.bmp", false);
+ loadBorder(_selfWindow, "border_none.bmp", true);
// Exits Window
_exitsWindow = _wm.addWindow(false, false, false);
@@ -508,7 +521,7 @@ bool Gui::loadControls() {
data.scrollMax = res->readUint16BE();
data.scrollMin = res->readUint16BE();
data.cdef = res->readUint16BE();
- data.refcon = (ControlReference)id; id++;
+ data.refcon = (ControlType)id; id++;
res->readUint32BE();
data.titleLength = res->readByte();
if (data.titleLength) {
@@ -535,6 +548,7 @@ void Gui::drawWindows() {
drawSelfWindow();
drawInventories();
drawExitsWindow();
+ drawConsoleWindow();
}
@@ -579,7 +593,6 @@ void Gui::drawMainGameWindow() {
border.leftOffset,
border.topOffset,
kBlitDirect);
-
}
drawObjectsInWindow(kMainGameWindow, _mainGameWindow->getSurface());
@@ -638,6 +651,13 @@ void Gui::drawExitsWindow() {
//g_system->updateScreen();
}
+void Gui::drawConsoleWindow() {
+
+ Graphics::ManagedSurface *srf = _outConsoleWindow->getSurface();
+ BorderBounds bounds = borderBounds(getWindowData(kOutConsoleWindow).type);
+ _consoleText->renderInto(srf, bounds.leftOffset);
+}
+
void Gui::drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface * surface) {
WindowData &data = findWindowData(target);
BorderBounds border = borderBounds(data.type);
@@ -796,7 +816,7 @@ void Gui::updateExit(ObjID obj) {
{
ControlData data;
data.titleLength = 0;
- data.refcon = obj;
+ data.objref = obj;
Common::Point pos = _engine->getObjExitPosition(obj);
pos.x = border.leftOffset;
pos.y = border.topOffset;
@@ -807,6 +827,11 @@ void Gui::updateExit(ObjID obj) {
}
}
+void Gui::printText(const Common::String & text) {
+ debug("Print Text: %s", text);
+ _consoleText->printLine(text, _outConsoleWindow->getDimensions().width());
+}
+
WindowReference Gui::findWindowAtPoint(Common::Point point) {
Common::List<WindowData>::iterator it;
@@ -893,7 +918,7 @@ bool Gui::isRectInsideObject(Common::Rect target, ObjID obj) {
}
void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point startPos) {
- if (_engine->isObjClickable(child)) {
+ if (_engine->isObjClickable(child) && _draggedObj.id == 0) {
_draggedObj.hasMoved = false;
_draggedObj.id = child;
_draggedObj.mouseOffset = (_engine->getObjPosition(child) + getWindowSurfacePos(origin)) - startPos;
@@ -903,12 +928,14 @@ void Gui::selectDraggable(ObjID child, WindowReference origin, Common::Point sta
void Gui::handleDragRelease(Common::Point pos, bool shiftPressed, bool isDoubleClick) {
WindowReference destinationWindow = findWindowAtPoint(pos);
- if (_draggedObj.hasMoved) {
+ if (_draggedObj.id != 0 && _draggedObj.hasMoved) {
ObjID destObject = getWindowData(destinationWindow).objRef;
- _engine->handleObjectDrop(_draggedObj.id, pos, destObject); //change pos to validate
- } else {
- _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick);
+ debug("drop the object at obj %d", destObject);
+ _engine->handleObjectDrop(_draggedObj.id, pos, destObject);
}
+ _engine->handleObjectSelect(_draggedObj.id, destinationWindow, shiftPressed, isDoubleClick);
+
+
_draggedObj.id = 0;
}
@@ -1055,16 +1082,17 @@ bool Gui::processEvent(Common::Event &event) {
if (event.type == Common::EVENT_MOUSEMOVE) {
if (_draggedObj.id != 0) {
- _draggedObj.pos = event.mouse + _draggedObj.mouseOffset;
- _draggedObj.hasMoved = true;
+ Common::Point newPos = event.mouse + _draggedObj.mouseOffset;
+ _draggedObj.hasMoved = newPos.sqrDist(_draggedObj.pos) >= kDragThreshold;
+ _draggedObj.pos = newPos;
}
processed = true;
// TEST
- Common::Rect mr = calculateClickRect(event.mouse, _screen.getBounds());
- _screen.fillRect(mr, kColorGreen);
- g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h);
- g_system->updateScreen();
+ //Common::Rect mr = calculateClickRect(event.mouse, _screen.getBounds());
+ //_screen.fillRect(mr, kColorGreen);
+ //g_system->copyRectToScreen(_screen.getPixels(), _screen.pitch, 0, 0, _screen.w, _screen.h);
+ //g_system->updateScreen();
}
processed |= _wm.processEvent(event);
@@ -1098,8 +1126,8 @@ bool Gui::processCommandEvents(WindowClick click, Common::Event &event) {
}
- _engine->selectControl((ControlReference)data.getData().refcon);
- _engine->activateCommand((ControlReference)data.getData().refcon);
+ _engine->selectControl(_engine->referenceToAction(data.getData().refcon));
+ _engine->activateCommand(data.getData().refcon);
_engine->refreshReady();
_engine->preparedToRun();
}
@@ -1207,22 +1235,16 @@ bool Gui::processInventoryEvents(WindowClick click, Common::Event & event) {
void Gui::processCursorTick() {
_cursor->tick();
-
-
-
-
-
- handleDragRelease(_draggedObj.pos, false, true);
-
}
void Gui::handleSingleClick(Common::Point pos) {
- //handleDragRelease(_draggedObj.pos, false, false);
debug("Single Click");
+ handleDragRelease(_draggedObj.pos, false, false);
}
void Gui::handleDoubleClick(Common::Point pos) {
debug("Double Click");
+ handleDragRelease(_draggedObj.pos, false, true);
}
/* Ugly switches */
@@ -1236,7 +1258,7 @@ BorderBounds Gui::borderBounds(MVWindowType type) {
case MacVenture::kPlainDBox:
return BorderBounds(6, 6, 6, 6);
case MacVenture::kAltBox:
- return BorderBounds(8, 9, 11, 10);
+ return BorderBounds(4, 4, 4, 4); // Hand-tested
break;
case MacVenture::kNoGrowDoc:
return BorderBounds(1, 17, 1, 1);
@@ -1249,7 +1271,7 @@ BorderBounds Gui::borderBounds(MVWindowType type) {
case MacVenture::kRDoc16:
break;
case MacVenture::kRDoc4:
- return BorderBounds(1, 19, 1, 1);
+ return BorderBounds(0, 19, 1, 1);
case MacVenture::kRDoc6:
break;
case MacVenture::kRDoc10:
diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h
index 75bb1e64a5..6dd22f568c 100644
--- a/engines/macventure/gui.h
+++ b/engines/macventure/gui.h
@@ -40,6 +40,7 @@ class MacVentureEngine;
typedef uint32 ObjID;
class Cursor;
+class ConsoleText;
class CommandButton;
class ImageAsset;
@@ -110,7 +111,7 @@ struct WindowData {
bool updateScroll;
};
-enum ControlReference {
+enum ControlType {
kControlExitBox = 0,
kControlExamine = 1,
kControlOpen = 2,
@@ -130,7 +131,8 @@ struct ControlData {
uint16 scrollMax;
uint16 scrollMin;
uint16 cdef;
- uint32 refcon; // If exits window, then the obj id. Otherwise, the control type
+ ObjID objref;
+ ControlType refcon; // If exits window, then the obj id. Otherwise, the control type
uint8 titleLength;
char* title;
uint16 border;
@@ -215,6 +217,8 @@ public:
void unselectExits();
void updateExit(ObjID id);
+ void printText(const Common::String &text);
+
// Ugly switches
BorderBounds borderBounds(MVWindowType type);
@@ -244,9 +248,11 @@ private: // Attributes
Graphics::ManagedSurface _draggedSurface;
DraggedObj _draggedObj;
-
+
Cursor *_cursor;
+ ConsoleText *_consoleText;
+
private: // Methods
// Initializers
@@ -268,6 +274,7 @@ private: // Methods
void drawSelfWindow();
void drawInventories();
void drawExitsWindow();
+ void drawConsoleWindow();
void drawDraggedObject();
void drawObjectsInWindow(WindowReference target, Graphics::ManagedSurface *surface);
@@ -446,6 +453,58 @@ private:
Gui *_gui;
};
+class ConsoleText {
+
+public:
+
+ ConsoleText(Gui *gui) {
+ _gui = gui;
+ _lines.push_back("");
+ }
+
+ ~ConsoleText() {
+
+ }
+
+ void printLine(const Common::String &str, int maxW) {
+ Common::StringArray wrappedLines;
+ int textW = maxW;
+ const Graphics::Font *font = &_gui->getCurrentFont();
+
+ font->wordWrapText(str, textW, wrappedLines);
+
+ if (wrappedLines.empty()) // Sometimes we have empty lines
+ _lines.push_back("");
+
+ for (Common::StringArray::const_iterator j = wrappedLines.begin(); j != wrappedLines.end(); ++j)
+ _lines.push_back(*j);
+
+ updateScroll();
+ }
+
+ void renderInto(Graphics::ManagedSurface *target, uint leftOffset) {
+ target->fillRect(target->getBounds(), kColorWhite);
+ const Graphics::Font *font = &_gui->getCurrentFont();
+ // HACK print the last lines visible (no scroll)
+ uint y = target->h - font->getFontHeight();
+ for (uint i = _lines.size() - 1; i != 0; i--) {
+ font->drawString(target, _lines[i], leftOffset, y, font->getStringWidth(_lines[i]), kColorBlack);
+ y -= font->getFontHeight();
+ }
+ }
+
+ void updateScroll() {
+ // TODO implemebt
+ }
+
+private:
+
+ Gui *_gui;
+
+ Common::StringArray _lines;
+
+};
+
} // End of namespace MacVenture
#endif
diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp
index 1578c57011..6a9f82f468 100644
--- a/engines/macventure/macventure.cpp
+++ b/engines/macventure/macventure.cpp
@@ -172,13 +172,12 @@ void MacVentureEngine::requestUnpause() {
_gameState = kGameStatePlaying;
}
-void MacVentureEngine::selectControl(ControlReference id) {
- ControlAction action = referenceToAction(id);
- debug(2, "Select control %x", action);
- _selectedControl = action;
+void MacVentureEngine::selectControl(ControlAction id) {
+ debug(2, "Select control %x", id);
+ _selectedControl = id;
}
-void MacVentureEngine::activateCommand(ControlReference id) {
+void MacVentureEngine::activateCommand(ControlType id) {
if (id == kControlClickToContinue) {
_clickToContinue = false;
_paused = true;
@@ -264,15 +263,15 @@ bool MacVentureEngine::printTexts() {
_textQueue.remove_at(0);
switch (text.id) {
case kTextNumber:
- debug("Print Number: %d", text.asset);
+ _gui->printText(Common::String(text.asset));
gameChanged();
break;
case kTextNewLine:
- debug("Print Newline: ");
+ _gui->printText(Common::String("\n"));
gameChanged();
break;
case kTextPlain:
- debug("Print Plain Text: %s", _world->getText(text.asset, text.source, text.destination).c_str());
+ _gui->printText(_world->getText(text.asset, text.source, text.destination));
gameChanged();
break;
}
@@ -311,24 +310,19 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool
if (objID > 0) {
int i = findObjectInArray(objID, _currentSelection);
- if (isDoubleClick) { // no double click for now
+ if (isDoubleClick) {
if (i >= 0)
unselectAll();
selectObject(objID);
if (!_cmdReady)
{
- selectPrimaryObject(objID);
- if (_selectedControl == kNoCommand) {
- _selectedControl = kActivateObject;
- if (_activeControl)
- _activeControl = kNoCommand;
- _activeControl = kActivateObject;
- _cmdReady = true;
- }
+ selectObject(objID);
+
+ selectControl(kActivateObject);
+ _activeControl = kActivateObject;
+ _cmdReady = true;
}
preparedToRun();
- //doubleClickObject(objID, win, event, canDrag);
- debug("Double click");
} else {
if (i >= 0)
unselectAll();
@@ -336,7 +330,6 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool
if (getInvolvedObjects() == 1)
_cmdReady = true;
preparedToRun();
- //singleClickObject(objID, win, event, canDrag);
}
}
}
@@ -346,7 +339,7 @@ void MacVentureEngine::handleObjectSelect(ObjID objID, WindowReference win, bool
void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID newParent) {
_destObject = newParent;
updateDelta(delta);
- selectControl(kControlOperate);
+ selectControl(kOperate);
activateCommand(kControlOperate);
refreshReady();
preparedToRun();
@@ -354,7 +347,7 @@ void MacVentureEngine::handleObjectDrop(ObjID objID, Common::Point delta, ObjID
void MacVentureEngine::updateDelta(Common::Point newPos) {
Common::Point newDelta = newPos - _deltaPoint;
- debug(4, "Update delta: Old(%d, %d), New(%d, %d)",
+ debug("Update delta: Old(%d, %d), New(%d, %d)",
_deltaPoint.x, _deltaPoint.y,
newDelta.x, newDelta.y);
_deltaPoint = newDelta;
@@ -749,7 +742,7 @@ void MacVentureEngine::zoomObject(ObjID objID) {
warning("zoomObject: unimplemented");
}
-ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlReference id) {
+ControlAction MacVenture::MacVentureEngine::referenceToAction(ControlType id) {
switch (id) {
case MacVenture::kControlExitBox:
return kActivateObject;//??
diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h
index ad13d122f1..a1f570ed98 100644
--- a/engines/macventure/macventure.h
+++ b/engines/macventure/macventure.h
@@ -161,8 +161,8 @@ public:
void requestQuit();
void requestUnpause();
- void selectControl(ControlReference id);
- void activateCommand(ControlReference id);
+ void selectControl(ControlAction action);
+ void activateCommand(ControlType id);
void refreshReady();
void preparedToRun();
void gameChanged();
@@ -210,6 +210,8 @@ public:
Common::Point getObjExitPosition(ObjID objID);
ObjID getParent(ObjID objID);
+ // Utils
+ ControlAction referenceToAction(ControlType id);
// Encapsulation HACK
Common::Rect getObjBounds(ObjID objID);
@@ -250,10 +252,7 @@ private:
// Data loading
bool loadGlobalSettings();
bool loadTextHuffman();
-
- // Utils
- ControlAction referenceToAction(ControlReference id);
-
+
const char* getGameFileName() const;
private: // Attributes
diff --git a/engines/macventure/script.cpp b/engines/macventure/script.cpp
index cbc47a9148..230198bc6c 100644
--- a/engines/macventure/script.cpp
+++ b/engines/macventure/script.cpp
@@ -1071,7 +1071,7 @@ void ScriptEngine::opd5DLOG(EngineState * state, EngineFrame * frame) {
}
void ScriptEngine::opd6ACMD(EngineState * state, EngineFrame * frame) {
- _engine->activateCommand((ControlReference)state->pop());
+ _engine->activateCommand((ControlType)state->pop());
}
void ScriptEngine::opd7LOSE(EngineState * state, EngineFrame * frame) {