Skip to content

Commit

Permalink
WAGE: Implement callback calling in MacWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Apr 19, 2016
1 parent fd7bf64 commit b8ec681
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 15 additions & 7 deletions engines/wage/macwindow.cpp
Expand Up @@ -61,6 +61,9 @@ MacWindow::MacWindow(int id, bool scrollable) : _scrollable(scrollable), _id(id)
_highlightedPart = kBorderNone;

_scrollPos = _scrollSize = 0.0;

_callback = 0;
_dataPtr = 0;
}

MacWindow::~MacWindow() {
Expand Down Expand Up @@ -271,7 +274,7 @@ bool MacWindow::processEvent(Common::Event &event) {
//mouseMove(event.mouse.x, event.mouse.y);
break;
case Common::EVENT_LBUTTONDOWN:
mouseDown(event.mouse.x, event.mouse.y);
mouseDown(event);
break;
case Common::EVENT_LBUTTONUP:
#if 0
Expand All @@ -290,23 +293,28 @@ bool MacWindow::processEvent(Common::Event &event) {
return true;
}

void MacWindow::mouseDown(int x, int y) {
if (_innerDims.contains(x, y)) {
// (*callback)(x - _dims.left, y - dims.top);
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, x, y);
WindowClick click = isInBorder(_innerDims, event.mouse.x, event.mouse.y);

if (click == kBorderNone)
return;

setHighlight(click);

if (click == kBorderScrollUp || click == kBorderScrollDown) {
// TODO
}
if (!_callback)
return;

(*_callback)(click, event, _dataPtr);
}
}

} // End of namespace Wage
6 changes: 5 additions & 1 deletion engines/wage/macwindow.h
Expand Up @@ -86,6 +86,7 @@ class MacWindow {
void setDirty(bool dirty) { _contentIsDirty = dirty; }
int getId() { return _id; }
bool processEvent(Common::Event &event);
void setCallback(void (*callback)(WindowClick, Common::Event &, void *), void *data) { _callback = callback; _dataPtr = data; }

private:
void drawBorder();
Expand All @@ -94,7 +95,7 @@ class MacWindow {
const Graphics::Font *getTitleFont();
bool builtInFonts();

void mouseDown(int x, int y);
void mouseDown(Common::Event &event);

private:
Graphics::ManagedSurface _surface;
Expand All @@ -113,6 +114,9 @@ class MacWindow {
Common::Rect _innerDims;

Common::String _title;

void (*_callback)(WindowClick, Common::Event &, void *);
void *_dataPtr;
};

} // End of namespace Wage
Expand Down

0 comments on commit b8ec681

Please sign in to comment.