scummvm/engines/chewy/cursor.cpp

160 lines
3.6 KiB
C++
Raw Normal View History

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"
2019-11-04 22:24:37 +01:00
2021-09-12 15:41:09 -07:00
namespace Chewy {
2022-02-09 22:03:05 +01:00
cursor::cursor(McgaGraphic *iout, InputMgr *iin, cur_blk *curblkp) {
2019-11-04 22:24:37 +01:00
out = iout;
in = iin;
scr_width = scr_w;
curblk = curblkp;
inzeig = in->get_in_zeiger();
if (!inzeig->minfo)
maus_da = false;
else {
maus_da = true;
minfo = inzeig->minfo;
sichtbar = false;
2021-12-09 19:58:37 -08:00
ani = nullptr;
2019-11-04 22:24:37 +01:00
cur_aufruf = false;
ani_count = false;
}
}
cursor::~cursor() {
}
void cursor::plot_cur() {
if (maus_da && sichtbar) {
if (cur_move) {
mouse_active = true;
cur_move = false;
2019-11-04 22:24:37 +01:00
if (!curblk->no_back) {
out->blockcopy(curblk->cur_back, cur_x_old, cur_y_old, scr_width);
out->sprite_save(curblk->cur_back, (minfo->x + curblk->page_off_x),
(minfo->y + curblk->page_off_y), curblk->xsize,
curblk->ysize, scr_width);
}
cur_x_old = (minfo->x + curblk->page_off_x);
cur_y_old = (minfo->y + curblk->page_off_y);
}
cur_aufruf -= 1;
if ((cur_aufruf <= 0) && (ani != nullptr)) {
2019-11-04 22:24:37 +01:00
cur_aufruf = ani->delay;
++ani_count;
if (ani_count > ani->ani_end)
ani_count = ani->ani_anf;
}
out->sprite_set(curblk->sprite[ani_count], cur_x_old, cur_y_old,
scr_width);
mouse_active = false;
2019-11-04 22:24:37 +01:00
}
}
void cursor::show_cur() {
if ((maus_da) && (!sichtbar)) {
2021-10-13 21:08:54 -07:00
sichtbar = true;
mouse_active = true;
2019-11-04 22:24:37 +01:00
2021-10-13 21:08:54 -07:00
minfo->x = g_events->_mousePos.x;
minfo->y = g_events->_mousePos.y;
if (!curblk->no_back) {
2019-11-04 22:24:37 +01:00
out->sprite_save(curblk->cur_back, (minfo->x + curblk->page_off_x),
2021-10-13 21:08:54 -07:00
(minfo->y + curblk->page_off_y), curblk->xsize,
curblk->ysize, scr_width);
2019-11-04 22:24:37 +01:00
}
cur_x_old = (minfo->x + curblk->page_off_x);
cur_y_old = (minfo->y + curblk->page_off_y);
cur_move = true;
2019-11-04 22:24:37 +01:00
plot_cur();
}
}
void cursor::hide_cur() {
if ((maus_da) && (sichtbar)) {
if (!curblk->no_back) {
out->blockcopy(curblk->cur_back, cur_x_old, cur_y_old, scr_width);
}
sichtbar = false;
}
}
void cursor::set_cur_ani(cur_ani *ani1) {
ani = ani1;
cur_aufruf = 0;
ani_count = ani->ani_anf;
}
void cursor::move(int16 x, int16 y) {
if (maus_da) {
mouse_active = true;
2019-11-04 22:24:37 +01: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)
cur_move = true;
2019-11-04 22:24:37 +01:00
else
cur_move = false;
mouse_active = false;
2019-11-04 22:24:37 +01:00
}
}
void cursor::wait_taste_los(bool maus_plot) {
int16 is_mouse = 0;
2019-11-04 22:24:37 +01:00
if (maus_da) {
2021-10-13 21:08:54 -07:00
g_events->update();
2021-10-13 22:09:05 -07: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)
in->hot_key = 0;
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)) {
switch_code = in->get_switch_code();
if (is_mouse) {
switch_code = 2;
2021-10-13 21:08:54 -07:00
g_events->update();
2021-10-13 22:09:05 -07: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