aboutsummaryrefslogtreecommitdiff
path: root/gui/widgets
diff options
context:
space:
mode:
authorJaromir Wysoglad2019-07-12 12:52:18 +0200
committerFilippos Karapetis2019-09-01 22:47:55 +0300
commitb5cebcbeaed5b1b860f2686379fc288c137a4c2f (patch)
tree190f839f6c3d8c3176db62db36de12715d371431 /gui/widgets
parentfa6faca76a35028e288753c3d74f2c81228ec5bb (diff)
downloadscummvm-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/widgets')
-rw-r--r--gui/widgets/list.cpp25
-rw-r--r--gui/widgets/list.h4
-rw-r--r--gui/widgets/popup.cpp27
-rw-r--r--gui/widgets/popup.h2
-rw-r--r--gui/widgets/tab.cpp27
-rw-r--r--gui/widgets/tab.h3
6 files changed, 85 insertions, 3 deletions
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;