GUI: RTL: Support stacked dialogs and fix mouse events for them

GUI: RTL: Add helpers for overlay dialogs
This commit is contained in:
aryanrawlani28 2020-05-12 03:37:40 +05:30 committed by Eugene Sandulenko
parent e4352391c2
commit e5fc39bb98
4 changed files with 58 additions and 15 deletions

View File

@ -217,7 +217,7 @@ void ThemeLayoutMain::reflowLayout(Widget *widgetChain) {
assert(_children.size() <= 1);
resetLayout();
if (_overlays == "screen") {
_x = 0;
_y = 0;
@ -242,13 +242,14 @@ void ThemeLayoutMain::reflowLayout(Widget *widgetChain) {
}
}
// Below: Not complete. Renders dialogs okay, but can I use this for tabs?
if (this->_name.contains("GameOptions") || this->_name.contains("GlobalOptions")) {
if (this->_name == "GameOptions" || this->_name == "GlobalOptions")
if (g_gui.useRTL()) {
if (this->_name == "GameOptions" || this->_name == "GlobalOptions") {
int oldX = _x;
_x = g_system->getOverlayWidth() - _w - _x;
else
; //_x -= 100; // GUI TODO: Can this flow be used for Tabs?
g_gui.setOverlayParas(oldX, _x);
}
}
if (_x >= 0) _x += _inset;
if (_y >= 0) _y += _inset;
if (_w >= 0) _w -= 2 * _inset;
@ -388,7 +389,7 @@ void ThemeLayoutStacked::reflowLayoutHorizontal(Widget *widgetChain) {
resize[rescount++] = i;
_children[i]->setWidth(0);
}
_children[i]->offsetX(curX);
// Advance the horizontal offset by the width of the newest item, plus

View File

@ -70,6 +70,10 @@ GuiManager::GuiManager() : _redrawStatus(kRedrawDisabled), _stateIsSaved(false),
_launched = false;
_useRTL = false;
_isAnotherWindowOverlayed = false;
_focusedWindowLeftSpacing = 0;
_focusedWindowRightSpacing = 0;
// Clear the cursor
memset(_cursor, 0xFF, sizeof(_cursor));
@ -581,8 +585,13 @@ void GuiManager::processEvent(const Common::Event &event, Dialog *const activeDi
uint32 time;
Common::Point mouse(event.mouse.x - activeDialog->_x, event.mouse.y - activeDialog->_y);
if (_useRTL)
mouse.x = _system->getOverlayWidth() - mouse.x;
if (g_gui.useRTL()) {
mouse.x = g_system->getOverlayWidth() - event.mouse.x - activeDialog->_x;
if (g_gui.getOverlayOffset() != 0) {
mouse.x = g_gui.getOverlayOffset() + mouse.x;
}
}
switch (event.type) {
case Common::EVENT_KEYDOWN:
@ -592,10 +601,12 @@ void GuiManager::processEvent(const Common::Event &event, Dialog *const activeDi
activeDialog->handleKeyUp(event.kbd);
break;
case Common::EVENT_MOUSEMOVE:
if (useRTL()) {
_globalMousePosition.x = _system->getOverlayWidth() - event.mouse.x;
}
else {
if (g_gui.useRTL()) {
_globalMousePosition.x = g_system->getOverlayWidth() - event.mouse.x;
if (g_gui.getOverlayOffset() != 0) {
_globalMousePosition.x = g_gui.getOverlayOffset() + _globalMousePosition.x;
}
} else {
_globalMousePosition.x = event.mouse.x;
}
_globalMousePosition.y = event.mouse.y;
@ -660,6 +671,15 @@ void GuiManager::setLastMousePos(int16 x, int16 y) {
_lastMousePosition.time = _system->getMillis(true);
}
void GuiManager::setOverlayParas(int l, int r) {
_focusedWindowLeftSpacing = l;
_focusedWindowRightSpacing = r;
}
void GuiManager::setWindowOverlayStatus(bool value) {
_isAnotherWindowOverlayed = value;
}
#ifdef USE_TTS
void GuiManager::initTextToSpeech() {
Common::TextToSpeechManager *ttsMan = g_system->getTextToSpeechManager();

View File

@ -90,6 +90,10 @@ public:
int getHeight() const { return _height; }
bool useRTL() const { return _useRTL; }
void setOverlayParas(int l, int r);
int getOverlayOffset() { return _focusedWindowRightSpacing - _focusedWindowLeftSpacing; }
void setWindowOverlayStatus(bool value);
bool isWindowOverlayed() const { return _isAnotherWindowOverlayed; }
const Graphics::Font &getFont(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return *(_theme->getFont(style)); }
int getFontHeight(ThemeEngine::FontStyle style = ThemeEngine::kFontStyleBold) const { return _theme->getFontHeight(style); }
@ -141,6 +145,10 @@ protected:
bool _useStdCursor;
bool _useRTL;
bool _isAnotherWindowOverlayed;
int _focusedWindowLeftSpacing;
int _focusedWindowRightSpacing;
// position and time of last mouse click (used to detect double clicks)
struct MousePos {

View File

@ -147,6 +147,8 @@ OptionsDialog::OptionsDialog(const Common::String &domain, const Common::String
OptionsDialog::~OptionsDialog() {
delete _subToggleGroup;
g_gui.setWindowOverlayStatus(false);
g_gui.setOverlayParas(0, 0); // GUI TODO: This does not seem necessary, but lets be safe for now.
}
void OptionsDialog::init() {
@ -215,6 +217,8 @@ void OptionsDialog::init() {
_subSpeedSlider = nullptr;
_subSpeedLabel = nullptr;
g_gui.setWindowOverlayStatus(true);
// Retrieve game GUI options
_guioptions.clear();
if (ConfMan.hasKey("guioptions", _domain)) {
@ -1826,8 +1830,14 @@ void GlobalOptionsDialog::build() {
addAccessibilityControls(tab, "GlobalOptions_Accessibility.");
#endif // USE_TTS
// Activate the first tab
tab->setActiveTab(0);
// GUI TODO: Incomplete implementation, currently just switches to last tab.
if (g_gui.useRTL()) {
tab->setActiveTab(tab->getActiveTab());
}
else {
// Activate the first tab
tab->setActiveTab(0);
}
_tabWidget = tab;
// Add OK & Cancel buttons
@ -2910,6 +2920,10 @@ void GlobalOptionsDialog::shiftWidget(Widget *widget, const char *widgetName, in
if (!g_gui.xmlEval()->getWidgetData(widgetName, x, y, w, h))
warning("%s's position is undefined", widgetName);
// GUI TODO: I'm not sure what's this being used for?
if (g_gui.useRTL())
x = g_system->getOverlayWidth() - x - w;
widget->setPos(x + xOffset, y + yOffset);
}
#endif // USE_LIBCURL