1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
/* 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 3 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "engines/stark/ui/menu/fmvmenu.h"
#include "engines/stark/services/services.h"
#include "engines/stark/services/userinterface.h"
#include "engines/stark/services/diary.h"
#include "engines/stark/services/staticprovider.h"
#include "engines/stark/resources/location.h"
#include "engines/stark/visual/text.h"
namespace Stark {
FMVMenuScreen::FMVMenuScreen(Gfx::Driver *gfx, Cursor *cursor) :
StaticLocationScreen(gfx, cursor, "DiaryFMV", Screen::kScreenFMVMenu),
_fmvWidgets(),
_page(0),
_maxPage(0) {
_formatRectPos = Common::Point(202, 61);
_fontHeight = 16;
_fmvPerPage = 18;
}
FMVMenuScreen::~FMVMenuScreen() {
freeFMVWidgets();
}
void FMVMenuScreen::open() {
StaticLocationScreen::open();
_widgets.push_back(new StaticLocationWidget(
"BGImage",
nullptr,
nullptr));
_widgets.push_back(new StaticLocationWidget(
"Return",
CLICK_HANDLER(FMVMenuScreen, backHandler),
nullptr));
_widgets.back()->setupSounds(0, 1);
_widgets.push_back(new StaticLocationWidget(
"Back",
CLICK_HANDLER(FMVMenuScreen, backHandler),
nullptr));
_widgets.back()->setupSounds(0, 1);
_widgets.push_back(new StaticLocationWidget(
"PreviousPage",
CLICK_HANDLER(FMVMenuScreen, prevPageHandler),
nullptr));
_widgets.back()->setupSounds(0, 1);
_widgets.push_back(new StaticLocationWidget(
"NextPage",
CLICK_HANDLER(FMVMenuScreen, nextPageHandler),
nullptr));
_widgets.back()->setupSounds(0, 1);
// Acquire data for FMVWidget from the format rectangle
int formatRectHeight = 379;
Resources::Location *location = StarkStaticProvider->getLocation();
Gfx::RenderEntry *formatRect = location->getRenderEntryByName("FormatRectangle");
if (formatRect) {
_formatRectPos = formatRect->getPosition();
formatRectHeight = formatRect->getText()->getTargetHeight();
// The format rectangle contains one line,
// which can be used to retrieve the font's height
Common::Rect textRect = formatRect->getText()->getRect();
_fontHeight = textRect.bottom - textRect.top;
_fmvPerPage = formatRectHeight / (_fontHeight + 4);
}
_maxPage = StarkDiary->countFMV() / _fmvPerPage;
changePage(0);
}
void FMVMenuScreen::close() {
freeFMVWidgets();
StaticLocationScreen::close();
}
void FMVMenuScreen::onScreenChanged() {
StaticLocationScreen::onScreenChanged();
for (uint i = 0; i < _fmvWidgets.size(); ++i) {
_fmvWidgets[i]->onScreenChanged();
}
}
void FMVMenuScreen::onMouseMove(const Common::Point &pos) {
StaticLocationScreen::onMouseMove(pos);
for (uint i = 0; i < _fmvWidgets.size(); ++i) {
_fmvWidgets[i]->onMouseMove(pos);
}
}
void FMVMenuScreen::onClick(const Common::Point &pos) {
StaticLocationScreen::onClick(pos);
for (uint i = 0; i < _fmvWidgets.size(); ++i) {
if (_fmvWidgets[i]->isMouseInside(pos)) {
_fmvWidgets[i]->onClick();
return;
}
}
}
void FMVMenuScreen::onRender() {
StaticLocationScreen::onRender();
for (uint i = 0; i < _fmvWidgets.size(); ++i) {
_fmvWidgets[i]->render();
}
}
void FMVMenuScreen::backHandler() {
StarkUserInterface->backPrevScreen();
}
void FMVMenuScreen::freeFMVWidgets() {
for (uint i = 0; i < _fmvWidgets.size(); ++i) {
delete _fmvWidgets[i];
}
_fmvWidgets.clear();
}
void FMVMenuScreen::loadFMVWidgets(uint page) {
uint start = page * _fmvPerPage;
uint end = start + _fmvPerPage;
end = end < StarkDiary->countFMV() ? end : StarkDiary->countFMV();
for (uint i = start; i < end; ++i) {
_fmvWidgets.push_back(new FMVWidget(_gfx, i));
}
}
void FMVMenuScreen::changePage(uint page) {
assert(page <= _maxPage);
freeFMVWidgets();
loadFMVWidgets(page);
_widgets[kWidgetPrevious]->setVisible(page > 0);
_widgets[kWidgetNext]->setVisible(page < _maxPage);
_page = page;
}
FMVWidget::FMVWidget(Gfx::Driver *gfx, uint fmvIndex) :
_filename(StarkDiary->getFMVFilename(fmvIndex)),
_title(gfx) {
_title.setText(StarkDiary->getFMVTitle(fmvIndex));
_title.setColor(_textColorDefault);
_title.setFont(FontProvider::kCustomFont, 3);
Common::Rect rect = _title.getRect();
_width = rect.right - rect.left;
_formatRectPos = Common::Point(202, 61);
_fontHeight = 16;
_fmvPerPage = 18;
_position.x = _formatRectPos.x;
_position.y = _formatRectPos.y + (fmvIndex % _fmvPerPage) * (_fontHeight + 4);
}
void FMVWidget::onClick() {
StarkUserInterface->requestFMVPlayback(_filename);
}
bool FMVWidget::isMouseInside(const Common::Point &mousePos) const {
return mousePos.x >= _position.x && mousePos.x <= _position.x + _width &&
mousePos.y >= _position.y && mousePos.y <= _position.y + _fontHeight;
}
} // End of namespace Stark
|