From 4061dee480b55fa8ccc6a38d64f79c8a3ce989b0 Mon Sep 17 00:00:00 2001 From: thrust26 Date: Fri, 13 Nov 2020 08:58:19 +0100 Subject: [PATCH] fixed rendering, all dialogs are always re-rendered --- src/emucore/FrameBuffer.hxx | 7 +++++- src/gui/Dialog.cxx | 22 ++++++++-------- src/gui/Dialog.hxx | 5 ++++ src/gui/DialogContainer.cxx | 26 ++++++++----------- src/gui/ToolTip.cxx | 40 ++++++++++++++++++++++++++++++ src/gui/ToolTip.hxx | 39 +++++++++++++++++++++++++++++ src/gui/Widget.cxx | 21 +++++++++++----- src/gui/Widget.hxx | 4 +++ src/windows/Stella.vcxproj | 2 ++ src/windows/Stella.vcxproj.filters | 6 +++++ 10 files changed, 139 insertions(+), 33 deletions(-) create mode 100644 src/gui/ToolTip.cxx create mode 100644 src/gui/ToolTip.hxx diff --git a/src/emucore/FrameBuffer.hxx b/src/emucore/FrameBuffer.hxx index 8cda8d25c..9d6f3e930 100644 --- a/src/emucore/FrameBuffer.hxx +++ b/src/emucore/FrameBuffer.hxx @@ -88,9 +88,14 @@ class FrameBuffer /** There is a dedicated update method for emulation mode. - */ + */ void updateInEmulationMode(float framesPerSecond); + /** + Render backend to screen. + */ + void renderToScreen() { myBackend->renderToScreen(); } + /** Shows a text message onscreen. diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index e58920e89..b483d6e96 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -110,8 +110,6 @@ void Dialog::open() loadConfig(); // has to be done AFTER (re)building the focus list _visible = true; - - setDirty(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -227,12 +225,14 @@ void Dialog::redraw() // Draw this dialog setPosition(); drawDialog(); - render(); + // full rendering is caused in dialog container } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Dialog::render() { + cerr << " render " << typeid(*this).name() << endl; + // Update dialog surface; also render any extra surfaces // Extra surfaces must be rendered afterwards, so they are drawn on top if(_surface->render()) @@ -242,15 +242,17 @@ void Dialog::render() }); } - //cerr << "is ContextMenu " - // << (typeid(*parent().myDialogStack.top()) == typeid(ContextMenu)) << endl; + // Dialog is still on top if e.g a dialog without title is opened + // (e.g. ContextMenu) + bool onTop = parent().myDialogStack.top() == this + || (parent().myDialogStack.get(parent().myDialogStack.size() - 2) == this + && !parent().myDialogStack.top()->hasTitle()); + //&& typeid(*parent().myDialogStack.top()) == typeid(ContextMenu)) - // Dialog is still on top if e.g a ContextMenu is opened - if(!(parent().myDialogStack.top() == this) - && !((parent().myDialogStack.get(parent().myDialogStack.size() - 2) == this - //&& !(typeid(*parent().myDialogStack.top()) == typeid(ContextMenu))) - && !parent().myDialogStack.top()->hasTitle()))) + if(!onTop) { + cerr << " shade " << typeid(*this).name() << endl; + if(_shadeSurface == nullptr) { uInt32 data = 0xff000000; diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index c594d93cd..4fc48b7fc 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -119,6 +119,10 @@ class Dialog : public GuiObject */ bool shouldResize(uInt32& w, uInt32& h) const; + //bool enableToolTip(); + //void showToolTip(int x, int y); + //void hideToolTip(); + protected: void draw() override { } void releaseFocus() override; @@ -197,6 +201,7 @@ class Dialog : public GuiObject string _title; int _th{0}; int _layer{0}; + int _toolTipTimer{0}; Common::FixedStack> mySurfaceStack; diff --git a/src/gui/DialogContainer.cxx b/src/gui/DialogContainer.cxx index 1210e5d7c..50db35d3f 100644 --- a/src/gui/DialogContainer.cxx +++ b/src/gui/DialogContainer.cxx @@ -97,14 +97,16 @@ void DialogContainer::draw(bool full) cerr << "draw " << full << " " << typeid(*this).name() << endl; // Make the top dialog dirty if a full redraw is requested - if(full) - myDialogStack.top()->setDirty(); + //if(full) + // myDialogStack.top()->setDirty(); // Draw and render all dirty dialogs myDialogStack.applyAll([&](Dialog*& d) { if(d->needsRedraw()) d->redraw(); }); + // Always render all surfaces, bottom to top + render(); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -120,9 +122,9 @@ void DialogContainer::render() if(myDialogStack.empty()) return; - cerr << "render " << typeid(*this).name() << endl; + cerr << "full re-render " << typeid(*this).name() << endl; - // Render all dirty dialogs + // Render all dialogs myDialogStack.applyAll([&](Dialog*& d) { d->render(); }); @@ -153,10 +155,6 @@ int DialogContainer::addDialog(Dialog* d) "Unable to show dialog box; FIX THE CODE", MessagePosition::BottomCenter, true); else { - //// "shade" current top dialog - //if(!myDialogStack.empty()) - // myDialogStack.top()->setDirty(); - d->setDirty(); myDialogStack.push(d); } @@ -168,20 +166,16 @@ void DialogContainer::removeDialog() { if(!myDialogStack.empty()) { + cerr << "remove dialog" << endl; myDialogStack.pop(); if(!myDialogStack.empty()) { - //// this "unshades" the top dialog - //myDialogStack.top()->setDirty(); - - // Rerender all dialogs (TODO: top dialog is rendered twice) + // Rerender all dialogs myDialogStack.applyAll([&](Dialog*& d){ - //d->setDirty(); - d->render(); + d->render(); }); - // TODO: the screen is not updated until an event happens - // FrameBuffer::myBackend->renderToScreen() doesn't help + myOSystem.frameBuffer().renderToScreen(); } } } diff --git a/src/gui/ToolTip.cxx b/src/gui/ToolTip.cxx new file mode 100644 index 000000000..53cbea0c3 --- /dev/null +++ b/src/gui/ToolTip.cxx @@ -0,0 +1,40 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2020 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#include "OSystem.hxx" +#include "Font.hxx" +#include "Dialog.hxx" +#include "DialogContainer.hxx" + +#include "ToolTip.hxx" + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +ToolTip::ToolTip(OSystem& instance, DialogContainer& parent, + const GUI::Font& font) + : Dialog(instance, parent, font) +{ + const int lineHeight = font.getLineHeight(), + fontWidth = font.getMaxCharWidth(), + fontHeight = font.getFontHeight(), + buttonWidth = font.getStringWidth("Previous") + fontWidth * 2.5, + buttonHeight = font.getLineHeight() * 1.25; + const int VBORDER = fontHeight / 2; + const int HBORDER = fontWidth * 1.25; + const int VGAP = fontHeight / 4; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/gui/ToolTip.hxx b/src/gui/ToolTip.hxx new file mode 100644 index 000000000..2066bd3df --- /dev/null +++ b/src/gui/ToolTip.hxx @@ -0,0 +1,39 @@ +//============================================================================ +// +// SSSS tt lll lll +// SS SS tt ll ll +// SS tttttt eeee ll ll aaaa +// SSSS tt ee ee ll ll aa +// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator" +// SS SS tt ee ll ll aa aa +// SSSS ttt eeeee llll llll aaaaa +// +// Copyright (c) 1995-2020 by Bradford W. Mott, Stephen Anthony +// and the Stella Team +// +// See the file "License.txt" for information on usage and redistribution of +// this file, and for a DISCLAIMER OF ALL WARRANTIES. +//============================================================================ + +#ifndef TOOL_TIP_HXX +#define TOOL_TIP_HXX + +class OSystem; +class DialogContainer; + +/** + * Class for providing tooltip functionality + * + * @author Thomas Jentzsch + */ +class ToolTip : public Dialog +{ + public: + + public: + ToolTip(OSystem& instance, DialogContainer& parent, + const GUI::Font& font); + ~ToolTip() override = default; +}; + +#endif diff --git a/src/gui/Widget.cxx b/src/gui/Widget.cxx index 951a60282..1cacda9d6 100644 --- a/src/gui/Widget.cxx +++ b/src/gui/Widget.cxx @@ -71,13 +71,22 @@ bool Widget::isChainDirty() const // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Widget::tick() { - // Recursively tick widget and all child dialogs and widgets - Widget* w = _firstWidget; - - while(w) + if(isEnabled()) { - w->tick(); - w = w->_next; + //if(_hasFocus && hasToolTip()) + //{ + // if(dialog().enableToolTip()) + // dialog().showToolTip(10, 10); + //} + + // Recursively tick widget and all child dialogs and widgets + Widget* w = _firstWidget; + + while(w) + { + w->tick(); + w = w->_next; + } } } diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index 6a505e8df..13eefdbf7 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -99,6 +99,9 @@ class Widget : public GuiObject void setBGColorHi(ColorId color) { _bgcolorhi = color; setDirty(); } void setShadowColor(ColorId color) { _shadowcolor = color; setDirty(); } + void setToolTip(const string& text) { _toolTipText = text; } + bool hasToolTip() const { return !_toolTipText.empty(); } + virtual void loadConfig() { } protected: @@ -130,6 +133,7 @@ class Widget : public GuiObject ColorId _textcolorhi{kTextColorHi}; ColorId _textcolorlo{kBGColorLo}; ColorId _shadowcolor{kShadowColor}; + string _toolTipText; public: static Widget* findWidgetInChain(Widget* start, int x, int y); diff --git a/src/windows/Stella.vcxproj b/src/windows/Stella.vcxproj index 5f0bd9126..f9b5d3499 100644 --- a/src/windows/Stella.vcxproj +++ b/src/windows/Stella.vcxproj @@ -786,6 +786,7 @@ + @@ -1838,6 +1839,7 @@ + diff --git a/src/windows/Stella.vcxproj.filters b/src/windows/Stella.vcxproj.filters index 8dca2be2e..550419e9a 100644 --- a/src/windows/Stella.vcxproj.filters +++ b/src/windows/Stella.vcxproj.filters @@ -1032,6 +1032,9 @@ Source Files\gui + + Source Files\gui + @@ -2123,6 +2126,9 @@ Header Files\gui + + Header Files\gui +