WAGE: Stub for object clicking

This commit is contained in:
Eugene Sandulenko 2016-01-01 18:48:16 +01:00
parent 559e486034
commit 1ef7beb8e8
5 changed files with 68 additions and 7 deletions

View file

@ -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;

View file

@ -68,6 +68,7 @@ public:
}
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);

View file

@ -119,6 +119,7 @@ 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;
@ -126,6 +127,7 @@ Gui::Gui() {
_scrollPos = 0;
_builtInFonts = false;
_sceneIsActive = false;
g_system->getPaletteManager()->setPalette(palette, 0, 4);
@ -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;
}
@ -191,8 +196,16 @@ void Gui::draw() {
int consoleY = kMenuHeight + kComponentsPadding;
renderConsole(&_screen, consoleX + kBorderWidth , consoleY + kBorderWidth, consoleW - 2 * kBorderWidth, consoleH - 2 * kBorderWidth);
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();
// Blit to screen
@ -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;
@ -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

View file

@ -68,6 +68,7 @@ public:
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);
@ -82,6 +83,7 @@ private:
Graphics::Surface _console;
Scene *_scene;
bool _sceneDirty;
bool _bordersDirty;
Common::StringArray _out;
Common::StringArray _lines;
@ -90,6 +92,8 @@ private:
bool _builtInFonts;
Common::Rect _consoleTextArea;
Common::Rect _sceneArea;
bool _sceneIsActive;
bool _cursorIsArrow;
};

View file

@ -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;
}