diff options
author | Jaromir Wysoglad | 2019-07-12 12:52:18 +0200 |
---|---|---|
committer | Filippos Karapetis | 2019-09-01 22:47:55 +0300 |
commit | b5cebcbeaed5b1b860f2686379fc288c137a4c2f (patch) | |
tree | 190f839f6c3d8c3176db62db36de12715d371431 /gui | |
parent | fa6faca76a35028e288753c3d74f2c81228ec5bb (diff) | |
download | scummvm-rg350-b5cebcbeaed5b1b860f2686379fc288c137a4c2f.tar.gz scummvm-rg350-b5cebcbeaed5b1b860f2686379fc288c137a4c2f.tar.bz2 scummvm-rg350-b5cebcbeaed5b1b860f2686379fc288c137a4c2f.zip |
TTS: Add text to speech to the GUI.
Diffstat (limited to 'gui')
-rw-r--r-- | gui/dialog.h | 1 | ||||
-rw-r--r-- | gui/options.cpp | 6 | ||||
-rw-r--r-- | gui/widget.cpp | 13 | ||||
-rw-r--r-- | gui/widget.h | 11 | ||||
-rw-r--r-- | gui/widgets/list.cpp | 25 | ||||
-rw-r--r-- | gui/widgets/list.h | 4 | ||||
-rw-r--r-- | gui/widgets/popup.cpp | 27 | ||||
-rw-r--r-- | gui/widgets/popup.h | 2 | ||||
-rw-r--r-- | gui/widgets/tab.cpp | 27 | ||||
-rw-r--r-- | gui/widgets/tab.h | 3 |
10 files changed, 110 insertions, 9 deletions
diff --git a/gui/dialog.h b/gui/dialog.h index 70b17910fa..1089434303 100644 --- a/gui/dialog.h +++ b/gui/dialog.h @@ -102,6 +102,7 @@ protected: virtual void handleKeyDown(Common::KeyState state); virtual void handleKeyUp(Common::KeyState state); virtual void handleMouseMoved(int x, int y, int button); + virtual void handleMouseLeft(int button) {}; virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); virtual void handleOtherEvent(Common::Event evt); diff --git a/gui/options.cpp b/gui/options.cpp index ebfa4009eb..1d4f6c7e99 100644 --- a/gui/options.cpp +++ b/gui/options.cpp @@ -1792,8 +1792,8 @@ void GlobalOptionsDialog::build() { tab->addTab(_c("Accessibility", "lowres")); _ttsCheckbox = new CheckboxWidget(tab, "GlobalOptions_Accessibility.TTSCheckbox", _("Use Text to speech"), _("Will read text in gui on mouse over.")); - if (ConfMan.hasKey("ttsEnabled")) - _ttsCheckbox->setState(ConfMan.getBool("ttsEnabled", _domain)); + if (ConfMan.hasKey("tts_enabled")) + _ttsCheckbox->setState(ConfMan.getBool("tts_enabled", _domain)); else _ttsCheckbox->setState(false); @@ -2135,7 +2135,7 @@ void GlobalOptionsDialog::apply() { error.runModal(); } #ifdef USE_TTS - ConfMan.setBool("ttsEnabled", _ttsCheckbox->getState(), _domain); + ConfMan.setBool("tts_enabled", _ttsCheckbox->getState(), _domain); #endif if (isRebuildNeeded) { diff --git a/gui/widget.cpp b/gui/widget.cpp index 2ac73dd4ca..d02d64fbeb 100644 --- a/gui/widget.cpp +++ b/gui/widget.cpp @@ -256,6 +256,19 @@ Common::String Widget::cleanupHotkey(const Common::String &label) { return res; } +void Widget::read(Common::String str) { +#ifdef USE_TTS + if (ConfMan.hasKey("tts_enabled", "scummvm") && + ConfMan.getBool("tts_enabled", "scummvm")) { + int volume = (ConfMan.getInt("speech_volume", "scummvm") * 100) / 256; + if (ConfMan.hasKey("mute", "scummvm") && ConfMan.getBool("mute", "scummvm")) + volume = 0; + g_system->getTextToSpeechManager()->setVolume(volume); + g_system->getTextToSpeechManager()->say(str); + } +#endif +} + #pragma mark - StaticTextWidget::StaticTextWidget(GuiObject *boss, int x, int y, int w, int h, const Common::String &text, Graphics::TextAlign align, const char *tooltip, ThemeEngine::FontStyle font) diff --git a/gui/widget.h b/gui/widget.h index bcab3b4fa6..06df49629d 100644 --- a/gui/widget.h +++ b/gui/widget.h @@ -33,6 +33,7 @@ #include "gui/ThemeEngine.h" #include "common/text-to-speech.h" #include "common/system.h" +#include "common/config-manager.h" namespace GUI { @@ -168,6 +169,8 @@ public: virtual bool containsWidget(Widget *) const { return false; } + void read(Common::String str); + protected: void updateState(int oldFlags, int newFlags); @@ -195,9 +198,11 @@ public: StaticTextWidget(GuiObject *boss, const Common::String &name, const Common::String &text, const char *tooltip = 0, ThemeEngine::FontStyle font = ThemeEngine::kFontStyleBold); void setValue(int value); void setLabel(const Common::String &label); + void handleMouseEntered(int button) { readLabel(); } const Common::String &getLabel() const { return _label; } void setAlign(Graphics::TextAlign align); Graphics::TextAlign getAlign() const { return _align; } + void readLabel() { read(_label); } protected: void drawWidget(); @@ -220,7 +225,7 @@ public: void handleMouseUp(int x, int y, int button, int clickCount); void handleMouseDown(int x, int y, int button, int clickCount); - void handleMouseEntered(int button) { g_system->getTextToSpeechManager()->say(_label); if (_duringPress) { setFlags(WIDGET_PRESSED); } else { setFlags(WIDGET_HILITED); } markAsDirty(); } + void handleMouseEntered(int button) { readLabel(); if (_duringPress) { setFlags(WIDGET_PRESSED); } else { setFlags(WIDGET_HILITED); } markAsDirty(); } void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED | WIDGET_PRESSED); markAsDirty(); } void setHighLighted(bool enable); @@ -265,7 +270,7 @@ public: CheckboxWidget(GuiObject *boss, const Common::String &name, const Common::String &label, const char *tooltip = 0, uint32 cmd = 0, uint8 hotkey = 0); void handleMouseUp(int x, int y, int button, int clickCount); - virtual void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); markAsDirty(); } + virtual void handleMouseEntered(int button) { readLabel(); setFlags(WIDGET_HILITED); markAsDirty(); } virtual void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); markAsDirty(); } void setState(bool state); @@ -311,7 +316,7 @@ public: RadiobuttonWidget(GuiObject *boss, const Common::String &name, RadiobuttonGroup *group, int value, const Common::String &label, const char *tooltip = 0, uint8 hotkey = 0); void handleMouseUp(int x, int y, int button, int clickCount); - virtual void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); markAsDirty(); } + virtual void handleMouseEntered(int button) { readLabel(); setFlags(WIDGET_HILITED); markAsDirty(); } virtual void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); markAsDirty(); } void setState(bool state, bool setGroup = true); diff --git a/gui/widgets/list.cpp b/gui/widgets/list.cpp index 74239f889d..26edd0a4ba 100644 --- a/gui/widgets/list.cpp +++ b/gui/widgets/list.cpp @@ -44,7 +44,7 @@ ListWidget::ListWidget(Dialog *boss, const String &name, const char *tooltip, ui _scrollBar = new ScrollBarWidget(this, _w - _scrollBarWidth, 0, _scrollBarWidth, _h); _scrollBar->setTarget(this); - setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE); + setFlags(WIDGET_ENABLED | WIDGET_CLEARBG | WIDGET_RETAIN_FOCUS | WIDGET_WANT_TICKLE | WIDGET_TRACK_MOUSE); _type = kListWidget; _editMode = false; _numberingMode = kListNumberingOne; @@ -93,6 +93,8 @@ ListWidget::ListWidget(Dialog *boss, int x, int y, int w, int h, const char *too _quickSelect = true; _editColor = ThemeEngine::kFontColorNormal; + + _lastRead = -1; } bool ListWidget::containsWidget(Widget *w) const { @@ -262,6 +264,27 @@ void ListWidget::handleMouseWheel(int x, int y, int direction) { _scrollBar->handleMouseWheel(x, y, direction); } +void ListWidget::handleMouseMoved(int x, int y, int button) { + if (!isEnabled()) + return; + + // First check whether the selection changed + int item = findItem(x, y); + + if (item != -1) { + if(_lastRead != item) { + read(_dataList[item]); + _lastRead = item; + } + } + else + _lastRead = -1; +} + +void ListWidget::handleMouseLeft(int button) { + _lastRead = -1; +} + int ListWidget::findItem(int x, int y) const { if (y < _topPadding) return -1; diff --git a/gui/widgets/list.h b/gui/widgets/list.h index 57e677e91e..eeaad3072c 100644 --- a/gui/widgets/list.h +++ b/gui/widgets/list.h @@ -84,6 +84,8 @@ protected: ThemeEngine::FontColor _editColor; + int _lastRead; + public: ListWidget(Dialog *boss, const String &name, const char *tooltip = 0, uint32 cmd = 0); ListWidget(Dialog *boss, int x, int y, int w, int h, const char *tooltip = 0, uint32 cmd = 0); @@ -125,6 +127,8 @@ public: virtual void handleMouseDown(int x, int y, int button, int clickCount); virtual void handleMouseUp(int x, int y, int button, int clickCount); virtual void handleMouseWheel(int x, int y, int direction); + virtual void handleMouseMoved(int x, int y, int button); + virtual void handleMouseLeft(int button); virtual bool handleKeyDown(Common::KeyState state); virtual bool handleKeyUp(Common::KeyState state); virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data); diff --git a/gui/widgets/popup.cpp b/gui/widgets/popup.cpp index a36a652e5b..fe51b39c10 100644 --- a/gui/widgets/popup.cpp +++ b/gui/widgets/popup.cpp @@ -45,6 +45,8 @@ protected: int _leftPadding; int _rightPadding; + int _lastRead; + public: PopUpDialog(PopUpWidget *boss, int clickX, int clickY); @@ -53,6 +55,7 @@ public: void handleMouseUp(int x, int y, int button, int clickCount) override; void handleMouseWheel(int x, int y, int direction) override; // Scroll through entries with scroll wheel void handleMouseMoved(int x, int y, int button) override; // Redraw selections depending on mouse position + void handleMouseLeft(int button) override; void handleKeyDown(Common::KeyState state) override; // Scroll through entries with arrow keys etc. protected: @@ -64,6 +67,7 @@ protected: void moveUp(); void moveDown(); + void read(Common::String); }; PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY) @@ -145,6 +149,8 @@ PopUpDialog::PopUpDialog(PopUpWidget *boss, int clickX, int clickY) // Remember original mouse position _clickX = clickX - _x; _clickY = clickY - _y; + + _lastRead = -1; } void PopUpDialog::drawDialog(DrawLayer layerToDraw) { @@ -207,6 +213,27 @@ void PopUpDialog::handleMouseMoved(int x, int y, int button) { // ...and update the selection accordingly setSelection(item); + if (_lastRead != item) { + read(_popUpBoss->_entries[item].name); + _lastRead = item; + } +} + +void PopUpDialog::handleMouseLeft(int button) { + _lastRead = -1; +} + +void PopUpDialog::read(Common::String str) { +#ifdef USE_TTS + if (ConfMan.hasKey("tts_enabled", "scummvm") && + ConfMan.getBool("tts_enabled", "scummvm")) { + int volume = (ConfMan.getInt("speech_volume", "scummvm") * 100) / 256; + if (ConfMan.hasKey("mute", "scummvm") && ConfMan.getBool("mute", "scummvm")) + volume = 0; + g_system->getTextToSpeechManager()->setVolume(volume); + g_system->getTextToSpeechManager()->say(str); + } +#endif } void PopUpDialog::handleKeyDown(Common::KeyState state) { diff --git a/gui/widgets/popup.h b/gui/widgets/popup.h index d2b1f1cb92..a898479410 100644 --- a/gui/widgets/popup.h +++ b/gui/widgets/popup.h @@ -77,7 +77,7 @@ public: uint32 getSelectedTag() const { return (_selectedItem >= 0) ? _entries[_selectedItem].tag : (uint32)-1; } // const String& getSelectedString() const { return (_selectedItem >= 0) ? _entries[_selectedItem].name : String::emptyString; } - void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); markAsDirty(); } + void handleMouseEntered(int button) { read(_entries[_selectedItem].name); setFlags(WIDGET_HILITED); markAsDirty(); } void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); markAsDirty(); } virtual void reflowLayout(); diff --git a/gui/widgets/tab.cpp b/gui/widgets/tab.cpp index d34214b0ea..103f57291a 100644 --- a/gui/widgets/tab.cpp +++ b/gui/widgets/tab.cpp @@ -46,7 +46,7 @@ TabWidget::TabWidget(GuiObject *boss, const String &name) } void TabWidget::init() { - setFlags(WIDGET_ENABLED); + setFlags(WIDGET_ENABLED | WIDGET_TRACK_MOUSE); _type = kTabWidget; _activeTab = -1; _firstVisibleTab = 0; @@ -71,6 +71,7 @@ void TabWidget::init() { int y = _butTP - _tabHeight; _navLeft = new ButtonWidget(this, x, y, _butW, _butH, "<", 0, kCmdLeft); _navRight = new ButtonWidget(this, x + _butW + 2, y, _butW, _butH, ">", 0, kCmdRight); + _lastRead = -1; } TabWidget::~TabWidget() { @@ -216,6 +217,30 @@ void TabWidget::handleMouseDown(int x, int y, int button, int clickCount) { setActiveTab(tabID); } +void TabWidget::handleMouseMoved(int x, int y, int button) { + assert(y < _tabHeight); + + if (x < 0) + return; + + // Determine which tab the mouse is on + int tabID; + for (tabID = _firstVisibleTab; tabID <= _lastVisibleTab; ++tabID) { + x -= _tabs[tabID]._tabWidth; + if (x < 0) + break; + } + + if (tabID <= _lastVisibleTab) { + if (tabID != _lastRead) { + read(_tabs[tabID].title); + _lastRead = tabID; + } + } + else + _lastRead = -1; +} + bool TabWidget::handleKeyDown(Common::KeyState state) { if (state.hasFlags(Common::KBD_SHIFT) && state.keycode == Common::KEYCODE_TAB) adjustTabs(kTabBackwards); diff --git a/gui/widgets/tab.h b/gui/widgets/tab.h index f85d30a9c6..8411509bd0 100644 --- a/gui/widgets/tab.h +++ b/gui/widgets/tab.h @@ -60,6 +60,7 @@ protected: ButtonWidget *_navLeft, *_navRight; bool _navButtonsVisible; + int _lastRead; public: TabWidget(GuiObject *boss, int x, int y, int w, int h); @@ -102,6 +103,8 @@ public: } virtual void handleMouseDown(int x, int y, int button, int clickCount) override; + virtual void handleMouseMoved(int x, int y, int button); + virtual void handleMouseLeft(int button) { _lastRead = -1; }; virtual bool handleKeyDown(Common::KeyState state) override; virtual void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override; virtual int getFirstVisible() const; |