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     Dialog::reflowLayout();
00055 
00056     _x = _y = 0;
00057 }
00058 
00059 void OnScreenDialog::releaseFocus() {
00060 }
00061 
00062 OnScreenDialog::OnScreenDialog(bool isRecord) : Dialog("OnScreenDialog") {
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", nullptr, 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", nullptr, 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", nullptr, 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", nullptr, 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 = nullptr;
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     default:
00157         break;
00158     }
00159 }
00160 
00161 void OnScreenDialog::setReplayedTime(uint32 newTime) {
00162     if (newTime - _lastTime > 1000) {
00163         uint32 seconds = newTime / 1000;
00164         _text->setLabel(Common::String::format("%.2d:%.2d:%.2d", seconds / 3600 % 24, seconds / 60 % 60, seconds % 60));
00165         _lastTime = newTime;
00166     }
00167 }
00168 
00169 OnScreenDialog::~OnScreenDialog() {
00170 }
00171 
00172 void OnScreenDialog::handleMouseMoved(int x, int y, int button) {
00173     if (_enableDrag) {
00174         _x = _x + x - _dragPoint.x;
00175         _y = _y + y - _dragPoint.y;
00176     }
00177     Dialog::handleMouseMoved(x, y, button);
00178     if (isMouseOver(x, y)) {
00179         if (_mouseOver == false) {
00180             g_gui.theme()->showCursor();
00181             CursorMan.lock(true);
00182         }
00183         _mouseOver = true;
00184     } else {
00185         if (_mouseOver == true) {
00186             CursorMan.lock(false);
00187             g_gui.theme()->hideCursor();
00188         }
00189         _mouseOver = false;
00190     }
00191 }
00192 
00193 void OnScreenDialog::handleMouseDown(int x, int y, int button, int clickCount) {
00194     if (isMouseOver(x, y)) {
00195         _dragPoint.x = x;
00196         _dragPoint.y = y;
00197         _enableDrag = true;
00198     }
00199     Dialog::handleMouseDown(x, y, button, clickCount);
00200 }
00201 
00202 void OnScreenDialog::handleMouseUp(int x, int y, int button, int clickCount) {
00203     if (isMouseOver(x, y)) {
00204 
00205     }
00206     _enableDrag = false;
00207     Dialog::handleMouseUp(x, y, button, clickCount);
00208 }
00209 
00210 bool OnScreenDialog::isMouseOver(int x, int y) {
00211     return (x >= 0 && x < _w && y >= 0 && y < _h);
00212 }
00213 
00214 bool OnScreenDialog::isMouseOver() {
00215     return _mouseOver;
00216 }
00217 
00218 void OnScreenDialog::close() {
00219     CursorMan.lock(false);
00220     Dialog::close();
00221 }
00222 
00223 Dialog *OnScreenDialog::getActiveDlg() {
00224     if (_editDlgShown) {
00225         return _dlg;
00226     } else {
00227         return this;
00228     }
00229 }
00230 
00231 bool OnScreenDialog::isEditDlgVisible() {
00232     return _editDlgShown;
00233 }
00234 
00235 }


Generated on Sat May 30 2020 05:01:05 for ResidualVM by doxygen 1.7.1
curved edge   curved edge