Skip to content

Commit

Permalink
WAGE: Stub for object clicking
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 1, 2016
1 parent 559e486 commit 1ef7beb
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
9 changes: 9 additions & 0 deletions engines/wage/design.cpp
Expand Up @@ -169,6 +169,15 @@ void Design::paint(Graphics::Surface *surface, Patterns &patterns, bool mask, in
}
}

bool Design::isPointOpaque(int x, int y) {
if (_surface == NULL)
error("Surface is null");

byte pixel = ((byte *)_surface->getBasePtr(x, y))[0];

return pixel != kColorGreen;
}

void drawPixel(int x, int y, int color, void *data) {
plotData *p = (plotData *)data;

Expand Down
1 change: 1 addition & 0 deletions engines/wage/design.h
Expand Up @@ -68,6 +68,7 @@ class Design {
}

void paint(Graphics::Surface *canvas, Patterns &patterns, bool mask, int x, int y);
bool isPointOpaque(int x, int y);
static void drawFilledRect(Graphics::Surface *surface, Common::Rect &rect, int color, Patterns &patterns, byte fillType);
static void drawFilledRoundRect(Graphics::Surface *surface, Common::Rect &rect, int arc, int color, Patterns &patterns, byte fillType);

Expand Down
53 changes: 46 additions & 7 deletions engines/wage/gui.cpp
Expand Up @@ -119,13 +119,15 @@ static const byte macCursorBeam[] = {
Gui::Gui() {
_scene = NULL;
_sceneDirty = true;
_bordersDirty = true;
_screen.create(g_system->getWidth(), g_system->getHeight(), Graphics::PixelFormat::createFormatCLUT8());

Patterns p;
p.push_back(checkersPattern);

_scrollPos = 0;
_builtInFonts = false;
_sceneIsActive = false;

g_system->getPaletteManager()->setPalette(palette, 0, 4);

Expand Down Expand Up @@ -177,8 +179,11 @@ void Gui::appendText(String &str) {
void Gui::draw() {
if (_scene != NULL && _sceneDirty) {
_scene->paint(&_screen, 0 + kComponentsPadding, kMenuHeight + kComponentsPadding);
paintBorder(&_screen, 0 + kComponentsPadding, kMenuHeight + kComponentsPadding, _scene->_design->getBounds()->width(), _scene->_design->getBounds()->height(),
kWindowScene);

_sceneArea.left = 0 + kComponentsPadding + kBorderWidth;
_sceneArea.top = kMenuHeight + kComponentsPadding + kBorderWidth;
_sceneArea.setWidth(_scene->_design->getBounds()->width() - 2 * kBorderWidth);
_sceneArea.setHeight(_scene->_design->getBounds()->height() - 2 * kBorderWidth);

_sceneDirty = false;
}
Expand All @@ -191,7 +196,15 @@ void Gui::draw() {
int consoleY = kMenuHeight + kComponentsPadding;

renderConsole(&_screen, consoleX + kBorderWidth , consoleY + kBorderWidth, consoleW - 2 * kBorderWidth, consoleH - 2 * kBorderWidth);
paintBorder(&_screen, consoleX, consoleY, consoleW, consoleH, kWindowConsole);

if (_bordersDirty) {
if (_scene)
paintBorder(&_screen, 0 + kComponentsPadding, kMenuHeight + kComponentsPadding, _scene->_design->getBounds()->width(), _scene->_design->getBounds()->height(),
kWindowScene);
paintBorder(&_screen, consoleX, consoleY, consoleW, consoleH, kWindowConsole);

_bordersDirty = false;
}

renderMenu();

Expand Down Expand Up @@ -227,16 +240,16 @@ void Gui::paintBorder(Graphics::Surface *g, int x, int y, int width, int height,

switch (windowType) {
case kWindowScene:
active = false;
active = _sceneIsActive;
scrollable = false;
closeable = false;
closeable = _sceneIsActive;
closeBoxPressed = false;
drawTitle = true;
break;
case kWindowConsole:
active = true;
active = !_sceneIsActive;
scrollable = true;
closeable = true;
closeable = !_sceneIsActive;
closeBoxPressed = false;
drawTitle = false;
break;
Expand Down Expand Up @@ -506,4 +519,30 @@ void Gui::renderMenu() {
}
}

Designed *Gui::getClickTarget(int x, int y) {
if (_sceneArea.contains(x, y)) {
if (!_sceneIsActive) {
_sceneIsActive = true;
_bordersDirty = true;
}

for (Common::List<Obj *>::const_iterator it = _scene->_objs.begin(); it != _scene->_objs.end(); ++it) {
if ((*it)->_design->isPointOpaque(x - _sceneArea.left + kBorderWidth, y - _sceneArea.top + kBorderWidth))
return *it;
}

for (Common::List<Chr *>::const_iterator it = _scene->_chrs.begin(); it != _scene->_chrs.end(); ++it) {
if ((*it)->_design->isPointOpaque(x - _sceneArea.left + kBorderWidth, y - _sceneArea.top + kBorderWidth))
return *it;
}
} else if (_consoleTextArea.contains(x, y)) {
if (_sceneIsActive) {
_sceneIsActive = false;
_bordersDirty = true;
}
}

return NULL;
}

} // End of namespace Wage
4 changes: 4 additions & 0 deletions engines/wage/gui.h
Expand Up @@ -68,6 +68,7 @@ class Gui {
void setScene(Scene *scene);
void appendText(Common::String &str);
void mouseMove(int x, int y);
Designed *getClickTarget(int x, int y);

private:
void paintBorder(Graphics::Surface *g, int x, int y, int width, int height, WindowType windowType);
Expand All @@ -82,6 +83,7 @@ class Gui {
Graphics::Surface _console;
Scene *_scene;
bool _sceneDirty;
bool _bordersDirty;

Common::StringArray _out;
Common::StringArray _lines;
Expand All @@ -90,6 +92,8 @@ class Gui {
bool _builtInFonts;

Common::Rect _consoleTextArea;
Common::Rect _sceneArea;
bool _sceneIsActive;
bool _cursorIsArrow;
};

Expand Down
8 changes: 8 additions & 0 deletions engines/wage/wage.cpp
Expand Up @@ -144,6 +144,14 @@ void WageEngine::processEvents() {
case Common::EVENT_MOUSEMOVE:
_gui->mouseMove(event.mouse.x, event.mouse.y);
break;
case Common::EVENT_LBUTTONDOWN:
break;
case Common::EVENT_LBUTTONUP:
{
Designed *obj = _gui->getClickTarget(event.mouse.x, event.mouse.y);
if (obj != NULL)
debug(0, "Clicked: %s", obj->_name.c_str());
}
default:
break;
}
Expand Down

0 comments on commit 1ef7beb

Please sign in to comment.