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

button.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/world/button.h"
00024 
00025 #include "engines/stark/services/services.h"
00026 #include "engines/stark/gfx/driver.h"
00027 #include "engines/stark/gfx/texture.h"
00028 
00029 #include "engines/stark/visual/explodingimage.h"
00030 #include "engines/stark/visual/flashingimage.h"
00031 #include "engines/stark/visual/image.h"
00032 #include "engines/stark/visual/text.h"
00033 
00034 namespace Stark {
00035 
00036 Button::Button(const Common::String &text, StaticProvider::UIElement stockElement, const Common::Point &pos, HintAlign align, const Common::Point &hintPos) :
00037         _position(pos),
00038         _stockElement(stockElement),
00039         _text(text),
00040         _hintPosition(hintPos),
00041         _align(align),
00042         _mouseText(nullptr),
00043         _renderHint(false),
00044         _explodingImageAnimation(nullptr),
00045         _flashingImageAnimation(nullptr) {
00046 }
00047 
00048 Button::~Button() {
00049     delete _explodingImageAnimation;
00050     delete _flashingImageAnimation;
00051     delete _mouseText;
00052 }
00053 
00054 void Button::render() {
00055     VisualImageXMG *image = StarkStaticProvider->getUIElement(_stockElement);
00056     image->render(_position, false);
00057 
00058     if (_explodingImageAnimation) {
00059         _explodingImageAnimation->render(_position);
00060     }
00061 
00062     if (_flashingImageAnimation) {
00063         _flashingImageAnimation->render(_position);
00064     }
00065 
00066     if (_renderHint) {
00067         Common::Point pos(_hintPosition);
00068         if (_align == kAlignRight) {
00069             pos.x -= _mouseText->getRect().width();
00070         }
00071         _mouseText->render(pos);
00072         _renderHint = false;
00073     }
00074 }
00075 
00076 bool Button::containsPoint(const Common::Point &point) {
00077     VisualImageXMG *image = StarkStaticProvider->getUIElement(_stockElement);
00078 
00079     Common::Rect r;
00080     r.left = _position.x;
00081     r.top = _position.y;
00082     r.setWidth(image->getWidth());
00083     r.setHeight(image->getHeight());
00084     return r.contains(point);
00085 }
00086 
00087 void Button::showButtonHint() {
00088     if (!_mouseText) {
00089         _mouseText = new VisualText(StarkGfx);
00090         _mouseText->setText(_text);
00091         _mouseText->setColor(Color(0xFF, 0xFF, 0xFF));
00092         _mouseText->setFont(FontProvider::kSmallFont);
00093         _mouseText->setTargetWidth(96);
00094     }
00095     _renderHint = true;
00096 }
00097 
00098 void Button::resetHintVisual() {
00099     delete _mouseText;
00100     _mouseText = nullptr;
00101 }
00102 
00103 void Button::goToAnimStatement(int animScriptItemIndex) {
00104     StarkStaticProvider->goToAnimScriptStatement(_stockElement, animScriptItemIndex);
00105 }
00106 
00107 void Button::startImageExplosion(VisualImageXMG *image) {
00108     assert(image);
00109 
00110     stopImageExplosion();
00111     _explodingImageAnimation = new VisualExplodingImage(StarkGfx);
00112     _explodingImageAnimation->initFromSurface(image->getSurface());
00113 }
00114 
00115 void Button::stopImageExplosion() {
00116     delete _explodingImageAnimation;
00117     _explodingImageAnimation = nullptr;
00118 }
00119 
00120 void Button::startImageFlashing(VisualImageXMG *image) {
00121     assert(image);
00122 
00123     stopImageFlashing();
00124     _flashingImageAnimation = new VisualFlashingImage(StarkGfx);
00125     _flashingImageAnimation->initFromSurface(image->getSurface());
00126 }
00127 
00128 void Button::stopImageFlashing() {
00129     delete _flashingImageAnimation;
00130     _flashingImageAnimation = nullptr;
00131 }
00132 
00133 } // End of namespace Stark


Generated on Sat Feb 16 2019 05:00:46 for ResidualVM by doxygen 1.7.1
curved edge   curved edge