2019-11-04 22:24:37 +01:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2021-12-26 15:54:17 -08: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.
|
2019-11-04 22:24:37 +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 15:54:17 -08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-11-04 22:24:37 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-10-13 21:08:54 -07:00
|
|
|
#include "chewy/cursor.h"
|
|
|
|
#include "chewy/events.h"
|
2022-02-09 20:38:12 -08:00
|
|
|
#include "chewy/global.h"
|
2019-11-04 22:24:37 +01:00
|
|
|
|
2021-09-12 15:41:09 -07:00
|
|
|
namespace Chewy {
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
Cursor::Cursor(McgaGraphics *iout, InputMgr *iin, cur_blk *curblkp) {
|
2022-02-10 20:27:40 -08:00
|
|
|
_out = iout;
|
|
|
|
_in = iin;
|
|
|
|
_scrWidth = _G(scr_w);
|
|
|
|
_curblk = curblkp;
|
|
|
|
_inzeig = _in->get_in_zeiger();
|
|
|
|
|
|
|
|
if (!_inzeig->minfo) {
|
|
|
|
_maus_da = false;
|
|
|
|
} else {
|
|
|
|
_maus_da = true;
|
|
|
|
_minfo = _inzeig->minfo;
|
|
|
|
_sichtbar = false;
|
|
|
|
_ani = nullptr;
|
|
|
|
_cur_aufruf = false;
|
|
|
|
_ani_count = false;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
Cursor::~Cursor() {
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
void Cursor::plot_cur() {
|
2022-02-10 20:27:40 -08:00
|
|
|
if (_maus_da && _sichtbar) {
|
2022-01-29 00:04:00 +01:00
|
|
|
if (cur_move) {
|
|
|
|
mouse_active = true;
|
|
|
|
cur_move = false;
|
2022-02-10 20:27:40 -08:00
|
|
|
if (!_curblk->no_back) {
|
2019-11-04 22:24:37 +01:00
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
_out->blockcopy(_curblk->cur_back, _cur_x_old, _cur_y_old, _scrWidth);
|
2019-11-04 22:24:37 +01:00
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
_out->sprite_save(_curblk->cur_back, (_minfo->x + _curblk->page_off_x),
|
|
|
|
(_minfo->y + _curblk->page_off_y), _curblk->xsize,
|
|
|
|
_curblk->ysize, _scrWidth);
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
_cur_x_old = (_minfo->x + _curblk->page_off_x);
|
|
|
|
_cur_y_old = (_minfo->y + _curblk->page_off_y);
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
_cur_aufruf -= 1;
|
|
|
|
if ((_cur_aufruf <= 0) && (_ani != nullptr)) {
|
|
|
|
_cur_aufruf = _ani->delay;
|
|
|
|
++_ani_count;
|
|
|
|
if (_ani_count > _ani->ani_end)
|
|
|
|
_ani_count = _ani->ani_anf;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
_out->sprite_set(_curblk->sprite[_ani_count], _cur_x_old, _cur_y_old,
|
|
|
|
_scrWidth);
|
2022-01-29 00:04:00 +01:00
|
|
|
mouse_active = false;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
void Cursor::show_cur() {
|
2022-02-10 20:27:40 -08:00
|
|
|
if ((_maus_da) && (!_sichtbar)) {
|
|
|
|
_sichtbar = true;
|
2022-01-29 00:04:00 +01:00
|
|
|
mouse_active = true;
|
2019-11-04 22:24:37 +01:00
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
_minfo->x = g_events->_mousePos.x;
|
|
|
|
_minfo->y = g_events->_mousePos.y;
|
2021-10-13 21:08:54 -07:00
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
if (!_curblk->no_back) {
|
|
|
|
_out->sprite_save(_curblk->cur_back, (_minfo->x + _curblk->page_off_x),
|
|
|
|
(_minfo->y + _curblk->page_off_y), _curblk->xsize,
|
|
|
|
_curblk->ysize, _scrWidth);
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
_cur_x_old = (_minfo->x + _curblk->page_off_x);
|
|
|
|
_cur_y_old = (_minfo->y + _curblk->page_off_y);
|
2022-01-29 00:04:00 +01:00
|
|
|
cur_move = true;
|
2019-11-04 22:24:37 +01:00
|
|
|
plot_cur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
void Cursor::hide_cur() {
|
2022-02-10 20:27:40 -08:00
|
|
|
if ((_maus_da) && (_sichtbar)) {
|
|
|
|
if (!_curblk->no_back) {
|
|
|
|
_out->blockcopy(_curblk->cur_back, _cur_x_old, _cur_y_old, _scrWidth);
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
2022-02-10 20:27:40 -08:00
|
|
|
_sichtbar = false;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
void Cursor::set_cur_ani(cur_ani *ani1) {
|
2022-02-10 20:27:40 -08:00
|
|
|
_ani = ani1;
|
|
|
|
_cur_aufruf = 0;
|
|
|
|
_ani_count = _ani->ani_anf;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
void Cursor::move(int16 x, int16 y) {
|
2022-02-10 20:27:40 -08:00
|
|
|
if (_maus_da) {
|
2022-01-29 00:04:00 +01:00
|
|
|
mouse_active = true;
|
2019-11-04 22:24:37 +01:00
|
|
|
|
2022-02-10 20:27:40 -08:00
|
|
|
_minfo->x = x;
|
|
|
|
_minfo->y = y;
|
|
|
|
_cur_x_old = (_minfo->x + _curblk->page_off_x);
|
|
|
|
_cur_y_old = (_minfo->y + _curblk->page_off_y);
|
|
|
|
_in->move_mouse(x, y);
|
|
|
|
if (_sichtbar)
|
2022-01-29 00:04:00 +01:00
|
|
|
cur_move = true;
|
2019-11-04 22:24:37 +01:00
|
|
|
else
|
2022-01-29 00:04:00 +01:00
|
|
|
cur_move = false;
|
|
|
|
mouse_active = false;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 19:23:13 -08:00
|
|
|
void Cursor::wait_taste_los(bool maus_plot) {
|
2022-01-29 17:33:14 +01:00
|
|
|
int16 is_mouse = 0;
|
2022-02-10 20:27:40 -08:00
|
|
|
if (_maus_da) {
|
2021-10-13 21:08:54 -07:00
|
|
|
g_events->update();
|
2022-02-10 20:27:40 -08:00
|
|
|
is_mouse = _minfo->button;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
2021-10-13 21:08:54 -07:00
|
|
|
|
2019-11-04 22:24:37 +01:00
|
|
|
if (!is_mouse)
|
2022-02-10 20:42:25 -08:00
|
|
|
_in->_hotkey = 0;
|
2022-02-10 20:27:40 -08:00
|
|
|
|
2022-01-29 17:33:14 +01:00
|
|
|
int16 stay = 1;
|
|
|
|
int16 switch_code = 1;
|
2021-10-13 21:08:54 -07:00
|
|
|
|
2019-11-04 22:24:37 +01:00
|
|
|
while ((switch_code != 0) && (stay)) {
|
2022-02-10 20:27:40 -08:00
|
|
|
switch_code = _in->get_switch_code();
|
2019-11-04 22:24:37 +01:00
|
|
|
if (is_mouse) {
|
|
|
|
switch_code = 2;
|
2021-10-13 21:08:54 -07:00
|
|
|
|
|
|
|
g_events->update();
|
2022-02-10 20:27:40 -08:00
|
|
|
stay = _minfo->button;
|
2019-11-04 22:24:37 +01:00
|
|
|
}
|
2021-10-13 21:08:54 -07:00
|
|
|
|
|
|
|
if (maus_plot)
|
2019-11-04 22:24:37 +01:00
|
|
|
plot_cur();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-12 15:41:09 -07:00
|
|
|
} // namespace Chewy
|