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

onscreendialog.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
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 "common/system.h"
00024 
00025 #include "gui/gui-manager.h"
00026 
00027 #include "gui/EventRecorder.h"
00028 
00029 #include "common/events.h"
00030 #include "common/rect.h"
00031 #include "common/translation.h"
00032 
00033 #include "graphics/cursorman.h"
00034 
00035 #include "gui/editrecorddialog.h"
00036 #include "gui/ThemeEval.h"
00037 
00038 #include "gui/onscreendialog.h"
00039 
00040 namespace GUI {
00041 
00042 bool OnScreenDialog::isVisible() const {
00043     return true;
00044 }
00045 
00046 enum {
00047     kStopCmd = 'STOP',
00048     kEditCmd = 'EDIT',
00049     kSwitchModeCmd = 'MODE',
00050     kFastModeCmd = 'FAST'
00051 };
00052 
00053 void OnScreenDialog::reflowLayout() {
00054     GuiObject::reflowLayout();
00055 }
00056 
00057 void OnScreenDialog::releaseFocus() {
00058 }
00059 
00060 OnScreenDialog::OnScreenDialog(bool isRecord) : Dialog("OnScreenDialog") {
00061     _x = _y = 0;
00062 
00063 #ifndef DISABLE_FANCY_THEMES
00064     if (g_gui.xmlEval()->getVar("Globals.OnScreenDialog.ShowPics") == 1 && g_gui.theme()->supportsImages()) {
00065         GUI::PicButtonWidget *button;
00066         button = new PicButtonWidget(this, "OnScreenDialog.StopButton", 0, kStopCmd, 0);
00067         button->useThemeTransparency(true);
00068 
00069         if (g_system->getOverlayWidth() > 320)
00070             button->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageStopButton));
00071         else
00072             button->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageStopSmallButton));
00073 
00074         if (isRecord) {
00075             button = new PicButtonWidget(this, "OnScreenDialog.EditButton", 0, kEditCmd, 0);
00076             button->useThemeTransparency(true);
00077 
00078             if (g_system->getOverlayWidth() > 320)
00079                 button->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageEditButton));
00080             else
00081                 button->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageEditSmallButton));
00082         } else {
00083             button = new PicButtonWidget(this, "OnScreenDialog.SwitchModeButton", 0, kSwitchModeCmd, 0);
00084             button->useThemeTransparency(true);
00085             if (g_system->getOverlayWidth() > 320)
00086                 button->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageSwitchModeButton));
00087             else
00088                 button->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageSwitchModeSmallButton));
00089 
00090             button = new PicButtonWidget(this, "OnScreenDialog.FastReplayButton", 0, kFastModeCmd, 0);
00091             button->useThemeTransparency(true);
00092             if (g_system->getOverlayWidth() > 320)
00093                 button->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageFastReplayButton));
00094             else
00095                 button->setGfx(g_gui.theme()->getImageSurface(ThemeEngine::kImageFastReplaySmallButton));
00096         }
00097     } else
00098 #endif
00099     {
00100         if (g_system->getOverlayWidth() > 320)
00101             new ButtonWidget(this, "OnScreenDialog.StopButton", "[ ]", _("Stop"), kStopCmd);
00102         else
00103             new ButtonWidget(this, "OnScreenDialog.StopButton", "[]", _("Stop"), kStopCmd);
00104 
00105         if (isRecord) {
00106             new ButtonWidget(this, "OnScreenDialog.EditButton", "E", _("Edit record description"), kEditCmd);
00107         } else {
00108             new ButtonWidget(this, "OnScreenDialog.SwitchModeButton", "G", _("Switch to Game"), kSwitchModeCmd);
00109 
00110             new ButtonWidget(this, "OnScreenDialog.FastReplayButton", ">>", _("Fast replay"), kFastModeCmd);
00111         }
00112     }
00113 
00114 
00115     _text = new GUI::StaticTextWidget(this, "OnScreenDialog.TimeLabel", "00:00:00");
00116     _enableDrag = false;
00117     _mouseOver = false;
00118     _editDlgShown = false;
00119 
00120     _lastTime = 0;
00121     _dlg = 0;
00122 }
00123 
00124 void OnScreenDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00125     Common::Event eventRTL;
00126     switch (cmd) {
00127     case kStopCmd:
00128         eventRTL.type = Common::EVENT_RTL;
00129         g_system->getEventManager()->pushEvent(eventRTL);
00130         close();
00131         break;
00132     case kEditCmd:
00133         _dlg = new EditRecordDialog(g_eventRec.getAuthor(), g_eventRec.getName(), g_eventRec.getNotes());
00134         CursorMan.lock(false);
00135         g_eventRec.setRedraw(false);
00136         g_system->showOverlay();
00137         _editDlgShown = true;
00138         _dlg->runModal();
00139         _editDlgShown = false;
00140         g_system->hideOverlay();
00141         g_eventRec.setRedraw(true);
00142         CursorMan.lock(true);
00143         g_eventRec.setAuthor(((EditRecordDialog *)_dlg)->getAuthor());
00144         g_eventRec.setName(((EditRecordDialog *)_dlg)->getName());
00145         g_eventRec.setNotes(((EditRecordDialog *)_dlg)->getNotes());
00146         delete _dlg;
00147         break;
00148     case kSwitchModeCmd:
00149         if (g_eventRec.switchMode()) {
00150             close();
00151         }
00152         break;
00153     case kFastModeCmd:
00154         g_eventRec.switchFastMode();
00155         break;
00156     }
00157 }
00158 
00159 void OnScreenDialog::setReplayedTime(uint32 newTime) {
00160     if (newTime - _lastTime > 1000) {
00161         uint32 seconds = newTime / 1000;
00162         _text->setLabel(Common::String::format("%.2d:%.2d:%.2d", seconds / 3600 % 24, seconds / 60 % 60, seconds % 60));
00163         _lastTime = newTime;
00164     }
00165 }
00166 
00167 OnScreenDialog::~OnScreenDialog() {
00168 }
00169 
00170 void OnScreenDialog::handleMouseMoved(int x, int y, int button) {
00171     if (_enableDrag) {
00172         _x = _x + x - _dragPoint.x;
00173         _y = _y + y - _dragPoint.y;
00174     }
00175     Dialog::handleMouseMoved(x, y, button);
00176     if (isMouseOver(x, y)) {
00177         if (_mouseOver == false) {
00178             g_gui.theme()->showCursor();
00179             CursorMan.lock(true);
00180         }
00181         _mouseOver = true;
00182     } else {
00183         if (_mouseOver == true) {
00184             CursorMan.lock(false);
00185             g_gui.theme()->hideCursor();
00186         }
00187         _mouseOver = false;
00188     }
00189 }
00190 
00191 void OnScreenDialog::handleMouseDown(int x, int y, int button, int clickCount) {
00192     if (isMouseOver(x, y)) {
00193         _dragPoint.x = x;
00194         _dragPoint.y = y;
00195         _enableDrag = true;
00196     }
00197     Dialog::handleMouseDown(x, y, button, clickCount);
00198 }
00199 
00200 void OnScreenDialog::handleMouseUp(int x, int y, int button, int clickCount) {
00201     if (isMouseOver(x, y)) {
00202 
00203     }
00204     _enableDrag = false;
00205     Dialog::handleMouseUp(x, y, button, clickCount);
00206 }
00207 
00208 bool OnScreenDialog::isMouseOver(int x, int y) {
00209     return (x >= 0 && x < _w && y >= 0 && y < _h);
00210 }
00211 
00212 bool OnScreenDialog::isMouseOver() {
00213     return _mouseOver;
00214 }
00215 
00216 void OnScreenDialog::close() {
00217     CursorMan.lock(false);
00218     Dialog::close();
00219 }
00220 
00221 Dialog *OnScreenDialog::getActiveDlg() {
00222     if (_editDlgShown) {
00223         return _dlg;
00224     } else {
00225         return this;
00226     }
00227 }
00228 
00229 bool OnScreenDialog::isEditDlgVisible() {
00230     return _editDlgShown;
00231 }
00232 
00233 }


Generated on Sat Mar 23 2019 05:01:53 for ResidualVM by doxygen 1.7.1
curved edge   curved edge