Skip to content

Commit

Permalink
WAGE: Implement object clicking as part of callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Apr 19, 2016
1 parent 9a4a8ac commit fd7b312
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
16 changes: 16 additions & 0 deletions engines/wage/entities.cpp
Expand Up @@ -202,6 +202,22 @@ const char *Scene::getFontName() {
return "Unknown";
}

Designed *Scene::lookUpEntity(int x, int y) {
for (ObjList::const_iterator it = _objs.end(); it != _objs.begin(); ) {
it--;
if ((*it)->_design->isPointOpaque(x, y))
return *it;
}

for (ChrList::const_iterator it = _chrs.end(); it != _chrs.begin(); ) {
it--;
if ((*it)->_design->isPointOpaque(x, y))
return *it;
}

return nullptr;
}

Obj::Obj() : _currentOwner(NULL), _currentScene(NULL) {
_index = 0;
_namePlural = false;
Expand Down
2 changes: 2 additions & 0 deletions engines/wage/entities.h
Expand Up @@ -322,6 +322,8 @@ class Scene : public Designed {
Scene(Common::String name, Common::SeekableReadStream *data);
~Scene();

Designed *lookUpEntity(int x, int y);

Common::Rect *getTextBounds() {
return _textBounds == NULL ? NULL : new Common::Rect(*_textBounds);
}
Expand Down
13 changes: 12 additions & 1 deletion engines/wage/gui.cpp
Expand Up @@ -315,7 +315,18 @@ void Gui::drawScene() {
_consoleTextArea.setHeight(_scene->_textBounds->height() - 2 * kBorderWidth);
}

static void sceneWindowCallback(WindowClick click, Common::Event &event, void *gui) {
static void sceneWindowCallback(WindowClick click, Common::Event &event, void *g) {
Gui *gui = (Gui *)g;

if (click == kBorderInner && event.type == Common::EVENT_LBUTTONUP) {
Designed *obj = gui->_scene->lookUpEntity(event.mouse.x - gui->_sceneWindow->getDimensions().left,
event.mouse.y - gui->_sceneWindow->getDimensions().top);

if (obj != nullptr)
gui->_engine->processTurn(NULL, obj);

return;
}
}

// Render console
Expand Down
2 changes: 1 addition & 1 deletion engines/wage/gui.h
Expand Up @@ -155,13 +155,13 @@ class Gui {

bool _menuDirty;

Scene *_scene;
MacWindow *_sceneWindow;
MacWindow *_consoleWindow;

private:
Graphics::ManagedSurface _console;
Menu *_menu;
Scene *_scene;
bool _sceneDirty;
bool _consoleDirty;
bool _bordersDirty;
Expand Down
26 changes: 9 additions & 17 deletions engines/wage/macwindow.cpp
Expand Up @@ -267,6 +267,9 @@ void MacWindow::fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h
}

static WindowClick isInBorder(Common::Rect &rect, int x, int y) {
if (rect.contains(x, y))
return kBorderInner;

if (x >= rect.left - kBorderWidth && x < rect.left && y >= rect.top - kBorderWidth && y < rect.top)
return kBorderCloseButton;

Expand Down Expand Up @@ -294,15 +297,12 @@ bool MacWindow::processEvent(Common::Event &event) {
case Common::EVENT_LBUTTONDOWN:
mouseDown(event);
break;
case Common::EVENT_LBUTTONUP:
setHighlight(kBorderNone);
#if 0
{
Designed *obj = mouseUp(event.mouse.x, event.mouse.y);
if (obj != NULL)
_engine->processTurn(NULL, obj);
case Common::EVENT_LBUTTONUP: {
setHighlight(kBorderNone);

WindowClick click = isInBorder(_innerDims, event.mouse.x, event.mouse.y);
(*_callback)(click, event, _dataPtr);
}
#endif
break;

default:
Expand All @@ -313,22 +313,14 @@ bool MacWindow::processEvent(Common::Event &event) {
}

void MacWindow::mouseDown(Common::Event &event) {
if (_innerDims.contains(event.mouse.x, event.mouse.y)) {
if (!_callback)
return;

(*_callback)(kBorderInner, event, _dataPtr);
return;
}

WindowClick click = isInBorder(_innerDims, event.mouse.x, event.mouse.y);

if (click == kBorderNone)
return;

setHighlight(click);

if (click == kBorderScrollUp || click == kBorderScrollDown) {
if (click == kBorderScrollUp || click == kBorderScrollDown || click == kBorderInner) {
if (!_callback)
return;

Expand Down

0 comments on commit fd7b312

Please sign in to comment.