2021-12-26 21:19:38 +01:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2015-03-17 21:04:17 +01:00
|
|
|
*
|
2021-12-26 21:19:38 +01:00
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
2015-03-17 21:04:17 +01:00
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2015-03-17 21:04:17 +01:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-03-17 21:04:17 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/stark/ui/window.h"
|
|
|
|
#include "engines/stark/gfx/driver.h"
|
2015-04-06 12:23:12 +02:00
|
|
|
#include "engines/stark/services/services.h"
|
2015-12-25 09:35:50 +01:00
|
|
|
#include "engines/stark/ui/cursor.h"
|
2015-04-06 12:23:12 +02:00
|
|
|
|
2015-03-17 21:04:17 +01:00
|
|
|
namespace Stark {
|
2015-12-25 09:35:50 +01:00
|
|
|
|
2015-03-17 21:04:17 +01:00
|
|
|
Window::Window(Gfx::Driver *gfx, Cursor *cursor) :
|
|
|
|
_gfx(gfx),
|
|
|
|
_cursor(cursor),
|
2015-07-11 18:50:28 +02:00
|
|
|
_visible(false) {
|
2015-03-17 21:04:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window() {
|
|
|
|
}
|
|
|
|
|
2018-08-28 21:19:57 +02:00
|
|
|
void Window::handleGameLoop() {
|
|
|
|
if (!_visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
onGameLoop();
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:04:17 +01:00
|
|
|
void Window::render() {
|
|
|
|
if (!_visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-07 03:02:13 -04:00
|
|
|
_gfx->setViewport(_position);
|
2015-03-17 21:04:17 +01:00
|
|
|
|
|
|
|
onRender();
|
|
|
|
}
|
|
|
|
|
2017-06-14 21:41:53 +02:00
|
|
|
Graphics::Surface *Window::getScreenshot() const {
|
|
|
|
if (!_visible) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-08-07 03:02:13 -04:00
|
|
|
_gfx->setViewport(_position);
|
2017-06-14 21:41:53 +02:00
|
|
|
return _gfx->getViewportScreenshot();
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:04:17 +01:00
|
|
|
bool Window::isMouseInside() const {
|
|
|
|
if (!_visible) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-07 03:02:13 -04:00
|
|
|
Common::Point mousePos = _cursor->getMousePosition();
|
2015-03-17 21:04:17 +01:00
|
|
|
return _position.contains(mousePos);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::isVisible() const {
|
|
|
|
return _visible;
|
|
|
|
}
|
|
|
|
|
2015-07-14 13:17:54 +02:00
|
|
|
Common::Point Window::getRelativeMousePosition() const {
|
2018-08-07 03:02:13 -04:00
|
|
|
Common::Point mousePos = _cursor->getMousePosition();
|
2015-03-17 21:04:17 +01:00
|
|
|
return mousePos - Common::Point(_position.left, _position.top);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::handleMouseMove() {
|
|
|
|
if (!_visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMouseInside()) {
|
2015-07-14 13:17:54 +02:00
|
|
|
onMouseMove(getRelativeMousePosition());
|
2015-03-17 21:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::handleClick() {
|
|
|
|
if (!_visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMouseInside()) {
|
2015-07-14 13:17:54 +02:00
|
|
|
onClick(getRelativeMousePosition());
|
2015-03-17 21:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-11 16:35:54 +02:00
|
|
|
void Window::handleRightClick() {
|
|
|
|
if (!_visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMouseInside()) {
|
2015-07-14 13:17:54 +02:00
|
|
|
onRightClick(getRelativeMousePosition());
|
2015-07-11 16:35:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-15 13:55:00 +02:00
|
|
|
void Window::handleDoubleClick() {
|
|
|
|
if (!_visible) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isMouseInside()) {
|
|
|
|
onDoubleClick(getRelativeMousePosition());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 21:04:17 +01:00
|
|
|
} // End of namespace Stark
|