Skip to content

Commit

Permalink
WAGE: Further work on WindowManager
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Apr 19, 2016
1 parent 7373359 commit 609dd56
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
46 changes: 45 additions & 1 deletion engines/wage/macwindow.cpp
Expand Up @@ -90,11 +90,15 @@ void MacWindow::resize(int w, int h) {

void MacWindow::move(int x, int y) {
_dims.moveTo(x, y);

_innerDims.setWidth(0); // Invalidate rect
}

void MacWindow::setDimensions(const Common::Rect &r) {
resize(r.width(), r.height());
_dims.moveTo(r.left, r.top);

_innerDims.setWidth(0); // Invalidate rect
}

bool MacWindow::draw(Graphics::ManagedSurface *g, bool forceRedraw) {
Expand Down Expand Up @@ -144,6 +148,11 @@ static void drawPixelInverted(int x, int y, int color, void *data) {
void MacWindow::drawBorder() {
_borderIsDirty = false;

if (_innerDims.isEmpty()) {
_innerDims = _dims;
_innerDims.grow(-kBorderWidth);
}

bool active = _active, scrollable = _scrollable, closeable = _active, drawTitle = !_title.empty();
const int size = kBorderWidth;
int x = 0;
Expand Down Expand Up @@ -235,8 +244,43 @@ void MacWindow::fillRect(Graphics::ManagedSurface *g, int x, int y, int w, int h
g->fillRect(r, color);
}

WindowClick MacWindow::mouseDown(int x, int y) {
static WindowClick 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;
}

void MacWindow::mouseDown(int x, int y) {
if (_innerDims.contains(x, y)) {
// (*callback)(x - _dims.left, y - dims.top);
return;
}

WindowClick click = isInBorder(_innerDims, x, y);

if (click == kBorderNone)
return;

setHighlight(click);

if (click == kBorderScrollUp || click == kBorderScrollDown) {
// TODO
}

}

} // End of namespace Wage
3 changes: 2 additions & 1 deletion engines/wage/macwindow.h
Expand Up @@ -85,7 +85,7 @@ class MacWindow {
void setScroll(float scrollPos, float scrollSize) { _scrollPos = scrollPos; _scrollSize = scrollSize; }
void setDirty(bool dirty) { _contentIsDirty = dirty; }
int getId() { return _id; }
WindowClick mouseDown(int x, int y);
void mouseDown(int x, int y);

private:
void drawBorder();
Expand All @@ -108,6 +108,7 @@ class MacWindow {
float _scrollPos, _scrollSize;

Common::Rect _dims;
Common::Rect _innerDims;

Common::String _title;
};
Expand Down
9 changes: 1 addition & 8 deletions engines/wage/macwindowmanager.cpp
Expand Up @@ -122,14 +122,7 @@ bool MacWindowManager::mouseDown(int x, int y) {

if (w->getDimensions().contains(x, y)) {
setActive(w->getId());

WindowClick click = w->mouseDown(x, y);

if (click == kBorderInner) {

} else {
w->setHighlight(click);
}
w->mouseDown(x, y);

return true;
}
Expand Down

0 comments on commit 609dd56

Please sign in to comment.