scummvm/engines/saga2/videobox.cpp

197 lines
4.9 KiB
C++
Raw Normal View History

2021-05-17 18:47:39 +00: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.
*
* 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 2
* of the License, or (at your option) any later version.
*
* 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
* aint32 with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*
* Based on the original sources
* Faery Tale II -- The Halls of the Dead
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
*/
2021-06-23 12:41:01 +00:00
#include "saga2/saga2.h"
2021-05-17 18:47:39 +00:00
#include "saga2/videobox.h"
namespace Saga2 {
// imports
extern BackWindow *mainWindow;
/* ===================================================================== *
CVideoBox: Methods
* ===================================================================== */
CVideoBox::CVideoBox(const Rect16 &box,
uint16 ident,
AppFunc *cmd) : ModalWindow(box, ident, cmd) {
// set the size of the window panes
2021-06-07 16:19:10 +00:00
vidPanRects[0] = Rect16(x, y, xBrushSize, yBrushSize);
vidPanRects[1] = Rect16(x, y + yBrushSize, xBrushSize, yBrushSize);
2021-05-17 18:47:39 +00:00
// options dialog window decorations
2021-06-07 16:19:10 +00:00
vidDec[0].set(vidPanRects[0], vidPan1ResID);
vidDec[1].set(vidPanRects[1], vidPan2ResID);
2021-05-17 18:47:39 +00:00
// null out the decRes pointer
decRes = NULL;
rInfo.result = -1;
rInfo.running = false;
2021-05-17 18:47:39 +00:00
}
CVideoBox::~CVideoBox(void) {
// remove the resource handle
if (decRes)
resFile->disposeContext(decRes);
2021-05-17 18:47:39 +00:00
decRes = NULL;
// stop video if not done
g_vm->abortVideo();
2021-05-17 18:47:39 +00:00
}
void CVideoBox::deactivate(void) {
selected = 0;
gPanel::deactivate();
}
bool CVideoBox::activate(gEventType why) {
if (why == gEventMouseDown) { // momentarily depress
selected = 1;
notify(why, 0); // notify App of successful hit
2021-06-13 14:56:52 +00:00
return true;
2021-05-17 18:47:39 +00:00
}
2021-06-13 14:56:52 +00:00
return false;
2021-05-17 18:47:39 +00:00
}
void CVideoBox::pointerMove(gPanelMessage &) {
notify(gEventMouseMove, 0);
}
bool CVideoBox::pointerHit(gPanelMessage &) {
// mouse hit detected, close video box
gWindow *win;
requestInfo *ri;
win = getWindow(); // get the window pointer
ri = win ? (requestInfo *)win->userData : NULL;
if (ri) {
ri->running = 0;
ri->result = id;
}
activate(gEventMouseDown);
2021-06-13 14:56:52 +00:00
return true;
2021-05-17 18:47:39 +00:00
}
void CVideoBox::pointerDrag(gPanelMessage &) {
if (selected) {
notify(gEventMouseDrag, 0);
}
}
void CVideoBox::pointerRelease(gPanelMessage &) {
if (selected) notify(gEventMouseUp, 0); // notify App of successful hit
deactivate();
}
void CVideoBox::drawClipped(
gPort &port,
const Point16 &offset,
const Rect16 &clipRect) {
2021-07-16 20:19:47 +00:00
g_vm->_pointer->hide();
2021-05-17 18:47:39 +00:00
ModalWindow::drawClipped(port, offset, clipRect);
2021-07-16 20:19:47 +00:00
g_vm->_pointer->show();
2021-05-17 18:47:39 +00:00
}
void CVideoBox::draw(void) { // redraw the window
// draw the decoration stuff
2021-06-30 18:26:57 +00:00
drawClipped(g_vm->_mainPort, Point16(0, 0), extent);
2021-05-17 18:47:39 +00:00
}
void CVideoBox::init(void) {
2021-05-27 18:05:08 +00:00
assert(resFile);
2021-05-17 18:47:39 +00:00
// set the result info to nominal startup values
rInfo.result = -1;
2021-06-13 14:56:52 +00:00
rInfo.running = true;
2021-05-17 18:47:39 +00:00
// init the resource context handle
2021-06-02 15:31:17 +00:00
decRes = resFile->newContext(MKTAG('V', 'I', 'D', 'O'),
2021-05-17 18:47:39 +00:00
"Video border resources");
// get the decorations for this window
setDecorations(vidDec,
ARRAYSIZE(vidDec),
2021-05-17 18:47:39 +00:00
decRes,
'V', 'B', 'D');
// attach the result info struct to this window
userData = &rInfo;
}
int16 CVideoBox::openVidBox(char *fileName) {
// initalize the graphics for this window
init();
// call the rest of the required functionality
ModalWindow::open();
// start the video playback
g_vm->startVideo(fileName, x + borderWidth, y + borderWidth);
2021-05-17 18:47:39 +00:00
// run this modal event loop
2021-06-13 14:56:52 +00:00
//EventLoop( rInfo.running, true );
rInfo.running = g_vm->checkVideo();
2021-05-17 18:47:39 +00:00
while (rInfo.running)
rInfo.running = g_vm->checkVideo();
2021-05-17 18:47:39 +00:00
// get the result
return rInfo.result;
}
void quickSavePalette(void);
void quickRestorePalette(void);
// this opens a video box for business
int16 openVidBox(char *fileName) {
// get the area of the vid box
Rect16 area = CVideoBox::getAreaRect();
quickSavePalette();
// create a video box
CVideoBox videoBox(area, 0, NULL);
// open this video box
int16 result = videoBox.openVidBox(fileName);
// get rid of the box when done
videoBox.~CVideoBox();
quickRestorePalette();
// replace the damaged area
2021-06-18 17:53:14 +00:00
mainWindow->invalidate(&area);
2021-05-17 18:47:39 +00:00
// return the result code
return result;
}
} // end of namespace Saga2