ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

fmvmenu.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/ui/menu/fmvmenu.h"
00024 
00025 #include "engines/stark/services/services.h"
00026 #include "engines/stark/services/userinterface.h"
00027 #include "engines/stark/services/diary.h"
00028 #include "engines/stark/services/staticprovider.h"
00029 
00030 #include "engines/stark/resources/location.h"
00031 
00032 #include "engines/stark/visual/text.h"
00033 
00034 namespace Stark {
00035 
00036 const Color FMVWidget::_textColorHovered = Color(0x1E, 0x1E, 0x96);
00037 const Color FMVWidget::_textColorDefault = Color(0x00, 0x00, 0x00);
00038 
00039 // Hard-coded parameters in case cannot retrieve the format rectangle
00040 Common::Point FMVMenuScreen::_formatRectPos(202, 61);
00041 int FMVMenuScreen::_fontHeight(16);
00042 uint FMVMenuScreen::_fmvPerPage(18);
00043 
00044 FMVMenuScreen::FMVMenuScreen(Gfx::Driver *gfx, Cursor *cursor) :
00045         StaticLocationScreen(gfx, cursor, "DiaryFMV", Screen::kScreenFMVMenu),
00046         _fmvWidgets() {
00047 }
00048 
00049 FMVMenuScreen::~FMVMenuScreen() {
00050     freeFMVWidgets();
00051 }
00052 
00053 void FMVMenuScreen::open() {
00054     StaticLocationScreen::open();
00055 
00056     _widgets.push_back(new StaticLocationWidget(
00057             "BGImage",
00058             nullptr,
00059             nullptr));
00060 
00061     _widgets.push_back(new StaticLocationWidget(
00062             "Return",
00063             CLICK_HANDLER(FMVMenuScreen, backHandler),
00064             nullptr));
00065     _widgets.back()->setupSounds(0, 1);
00066 
00067     _widgets.push_back(new StaticLocationWidget(
00068             "Back",
00069             CLICK_HANDLER(FMVMenuScreen, backHandler),
00070             nullptr));
00071     _widgets.back()->setupSounds(0, 1);
00072 
00073     _widgets.push_back(new StaticLocationWidget(
00074             "PreviousPage",
00075             CLICK_HANDLER(FMVMenuScreen, prevPageHandler),
00076             nullptr));
00077     _widgets.back()->setupSounds(0, 1);
00078 
00079     _widgets.push_back(new StaticLocationWidget(
00080             "NextPage",
00081             CLICK_HANDLER(FMVMenuScreen, nextPageHandler),
00082             nullptr));
00083     _widgets.back()->setupSounds(0, 1);
00084 
00085     // Acquire data for FMVWidget from the format rectangle
00086 
00087     int formatRectHeight = 379;
00088 
00089     Resources::Location *location = StarkStaticProvider->getLocation();
00090     Gfx::RenderEntry *formatRect = location->getRenderEntryByName("FormatRectangle");
00091 
00092     if (formatRect) {
00093         _formatRectPos = formatRect->getPosition();
00094         formatRectHeight = formatRect->getText()->getTargetHeight();
00095 
00096         // The format rectangle contains one line,
00097         // which can be used to retrieve the font's height
00098         Common::Rect textRect = formatRect->getText()->getRect();
00099         _fontHeight = textRect.bottom - textRect.top;
00100 
00101         _fmvPerPage = formatRectHeight / (_fontHeight + 4);
00102     }
00103 
00104     _maxPage = StarkDiary->countFMV() / _fmvPerPage;
00105     changePage(0);
00106 }
00107 
00108 void FMVMenuScreen::close() {
00109     freeFMVWidgets();
00110     StaticLocationScreen::close();
00111 }
00112 
00113 void FMVMenuScreen::onScreenChanged() {
00114     StaticLocationScreen::onScreenChanged();
00115     for (uint i = 0; i < _fmvWidgets.size(); ++i) {
00116         _fmvWidgets[i]->onScreenChanged();
00117     }
00118 }
00119 
00120 void FMVMenuScreen::onMouseMove(const Common::Point &pos) {
00121     StaticLocationScreen::onMouseMove(pos);
00122     for (uint i = 0; i < _fmvWidgets.size(); ++i) {
00123         _fmvWidgets[i]->onMouseMove(pos);
00124     }
00125 }
00126 
00127 void FMVMenuScreen::onClick(const Common::Point &pos) {
00128     StaticLocationScreen::onClick(pos);
00129     for (uint i = 0; i < _fmvWidgets.size(); ++i) {
00130         if (_fmvWidgets[i]->isMouseInside(pos)) {
00131             _fmvWidgets[i]->onClick();
00132             return;
00133         }
00134     }
00135 }
00136 
00137 void FMVMenuScreen::onRender() {
00138     StaticLocationScreen::onRender();
00139     for (uint i = 0; i < _fmvWidgets.size(); ++i) {
00140         _fmvWidgets[i]->render();
00141     }
00142 }
00143 
00144 void FMVMenuScreen::backHandler() {
00145     StarkUserInterface->backPrevScreen();
00146 }
00147 
00148 void FMVMenuScreen::freeFMVWidgets() {
00149     for (uint i = 0; i < _fmvWidgets.size(); ++i) {
00150         delete _fmvWidgets[i];
00151     }
00152     _fmvWidgets.clear();
00153 }
00154 
00155 void FMVMenuScreen::loadFMVWidgets(uint page) {
00156     uint start = page * _fmvPerPage;
00157     uint end = start + _fmvPerPage;
00158     end = end < StarkDiary->countFMV() ? end : StarkDiary->countFMV();
00159 
00160     for (uint i = start; i < end; ++i) {
00161         _fmvWidgets.push_back(new FMVWidget(_gfx, i));
00162     }
00163 }
00164 
00165 void FMVMenuScreen::changePage(uint page) {
00166     assert(page <= _maxPage);
00167 
00168     freeFMVWidgets();
00169     loadFMVWidgets(page);
00170 
00171     _widgets[kWidgetPrevious]->setVisible(page > 0);
00172     _widgets[kWidgetNext]->setVisible(page < _maxPage);
00173 
00174     _page = page;
00175 }
00176 
00177 FMVWidget::FMVWidget(Gfx::Driver *gfx, uint fmvIndex) :
00178         _filename(StarkDiary->getFMVFilename(fmvIndex)),
00179         _title(gfx) {
00180     _title.setText(StarkDiary->getFMVTitle(fmvIndex));
00181     _title.setColor(_textColorDefault);
00182     _title.setFont(FontProvider::kCustomFont, 3);
00183 
00184     Common::Rect rect = _title.getRect();
00185     _width = rect.right - rect.left;
00186 
00187     _position.x = FMVMenuScreen::_formatRectPos.x;
00188     _position.y = FMVMenuScreen::_formatRectPos.y + 
00189                   (fmvIndex % FMVMenuScreen::_fmvPerPage) * (FMVMenuScreen::_fontHeight + 4);
00190 }
00191 
00192 void FMVWidget::onClick() {
00193     StarkUserInterface->requestFMVPlayback(_filename);
00194 }
00195 
00196 bool FMVWidget::isMouseInside(const Common::Point &mousePos) const {
00197     return mousePos.x >= _position.x && mousePos.x <= _position.x + _width &&
00198            mousePos.y >= _position.y && mousePos.y <= _position.y + FMVMenuScreen::_fontHeight;
00199 }
00200 
00201 } // End of namespace Stark


Generated on Sat May 18 2019 05:01:02 for ResidualVM by doxygen 1.7.1
curved edge   curved edge