diff --git a/src/gui/Dialog.cxx b/src/gui/Dialog.cxx index f519cdadc..669d7341c 100644 --- a/src/gui/Dialog.cxx +++ b/src/gui/Dialog.cxx @@ -156,7 +156,7 @@ void Dialog::setDirty() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Dialog::isDirty() const +bool Dialog::isDirty() { return _dirty; } @@ -221,8 +221,6 @@ void Dialog::positionAt(uInt32 pos) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool Dialog::render() { - //assert(_dirty); - if(!isVisible() || !needsRedraw()) return false; @@ -404,7 +402,7 @@ void Dialog::drawDialog() if(isDirty()) { - cerr << "*** draw dialog " << typeid(*this).name() << " ***" << endl; + //cerr << "*** draw dialog " << typeid(*this).name() << " ***" << endl; // Dialog is still on top if e.g a ContextMenu is opened _onTop = parent().myDialogStack.top() == this @@ -446,6 +444,7 @@ void Dialog::drawDialog() w = _firstWidget; while(w) { + // only redraw changed widgets if(w->needsRedraw()) w->draw(); diff --git a/src/gui/Dialog.hxx b/src/gui/Dialog.hxx index d9b750ab6..68a71608c 100644 --- a/src/gui/Dialog.hxx +++ b/src/gui/Dialog.hxx @@ -65,7 +65,7 @@ class Dialog : public GuiObject // A dialog being dirty indicates that its underlying surface needs to be // redrawn and then re-rendered; this is taken care of in ::render() void setDirty() override; - bool isDirty() const override; + bool isDirty() override; // TODO: remove bool isChainDirty() const override; bool render(); diff --git a/src/gui/EditableWidget.cxx b/src/gui/EditableWidget.cxx index 16b371813..b1783c10c 100644 --- a/src/gui/EditableWidget.cxx +++ b/src/gui/EditableWidget.cxx @@ -62,6 +62,23 @@ void EditableWidget::setText(const string& str, bool) setDirty(); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool EditableWidget::isDirty() +{ + if(_hasFocus && _editable && isVisible() && _boss->isVisible()) + { + _caretTimer++; + if(_caretTimer > 40) // switch every 2/3rd seconds + { + _caretTimer = 0; + _caretEnabled = !_caretEnabled; + _dirty = true; + } + cerr << "."; + } + + return _dirty; +} // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EditableWidget::setEditable(bool editable, bool hiliteBG) @@ -79,6 +96,15 @@ void EditableWidget::setEditable(bool editable, bool hiliteBG) } } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void EditableWidget::receivedFocusWidget() +{ + _caretTimer = 0; + _caretEnabled = true; + + Widget::receivedFocusWidget(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void EditableWidget::lostFocusWidget() { @@ -316,22 +342,31 @@ void EditableWidget::drawCaretSelection() if (!_editable || !isVisible() || !_boss->isVisible() || !_hasFocus) return; - const Common::Rect& editRect = getEditRect(); - int x = editRect.x(); - int y = editRect.y(); + if(_caretEnabled) + { + FBSurface& s = _boss->dialog().surface(); + const Common::Rect& editRect = getEditRect(); + int x = editRect.x(); + int y = editRect.y(); + x += getCaretOffset(); - x += getCaretOffset(); + x += _x; + y += _y; - x += _x; - y += _y; - - FBSurface& s = _boss->dialog().surface(); - s.vLine(x, y + 2, y + editRect.h() - 2, kTextColorHi); - s.vLine(x-1, y + 2, y + editRect.h() - 2, kTextColorHi); + s.vLine(x, y + 2, y + editRect.h() - 2, kTextColorHi); + s.vLine(x-1, y + 2, y + editRect.h() - 2, kTextColorHi); + clearDirty(); + } if(_selectSize) { + FBSurface& s = _boss->dialog().surface(); + const Common::Rect& editRect = getEditRect(); + int x = editRect.x(); + int y = editRect.y(); + string text = selectString(); + x = editRect.x(); y = editRect.y(); int w = editRect.w(); diff --git a/src/gui/EditableWidget.hxx b/src/gui/EditableWidget.hxx index fda92ccdf..e4dfbc2f7 100644 --- a/src/gui/EditableWidget.hxx +++ b/src/gui/EditableWidget.hxx @@ -65,7 +65,9 @@ class EditableWidget : public Widget, public CommandSender void setTextFilter(const TextFilter& filter) { _filter = filter; } protected: + void receivedFocusWidget() override; void lostFocusWidget() override; + bool isDirty() override; virtual void startEditMode() { setFlags(Widget::FLAG_WANTS_RAWDATA); } virtual void endEditMode() { clearFlags(Widget::FLAG_WANTS_RAWDATA); } @@ -110,6 +112,8 @@ class EditableWidget : public Widget, public CommandSender unique_ptr myUndoHandler; int _caretPos{0}; + int _caretTimer{0}; + bool _caretEnabled{true}; // Size of current selected text // 0 = no selection diff --git a/src/gui/GuiObject.hxx b/src/gui/GuiObject.hxx index 3bb510a6b..a6cf4e5ca 100644 --- a/src/gui/GuiObject.hxx +++ b/src/gui/GuiObject.hxx @@ -93,9 +93,9 @@ class GuiObject : public CommandReceiver virtual bool isVisible() const = 0; virtual void setDirty() = 0; virtual void clearDirty() { _dirty = false; } - virtual bool isDirty() const { return _dirty; } + virtual bool isDirty() { return _dirty; } virtual bool isChainDirty() const = 0; - virtual bool needsRedraw() const { return isDirty() || isChainDirty(); }; + virtual bool needsRedraw() { return isDirty() || isChainDirty(); }; void setFlags(uInt32 flags) { _flags |= flags; setDirty(); } void clearFlags(uInt32 flags) { _flags &= ~flags; setDirty(); } diff --git a/src/gui/Widget.cxx b/src/gui/Widget.cxx index 6358808e7..c9e0441e7 100644 --- a/src/gui/Widget.cxx +++ b/src/gui/Widget.cxx @@ -63,7 +63,7 @@ void Widget::setDirty() } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -bool Widget::isDirty() const +bool Widget::isDirty() { //string name = typeid(*this).name(); //if(_dirty && name == "class TabWidget") @@ -353,7 +353,7 @@ StaticTextWidget::StaticTextWidget(GuiObject* boss, const GUI::Font& font, _label(text), _align(align) { - _flags = Widget::FLAG_ENABLED; + _flags = Widget::FLAG_ENABLED | FLAG_CLEARBG; _bgcolor = kDlgColor; _bgcolorhi = kDlgColor; diff --git a/src/gui/Widget.hxx b/src/gui/Widget.hxx index 270f1eb32..3e70523c0 100644 --- a/src/gui/Widget.hxx +++ b/src/gui/Widget.hxx @@ -70,7 +70,7 @@ class Widget : public GuiObject virtual bool handleEvent(Event::Type event) { return false; } void setDirty() override; - bool isDirty() const override; + bool isDirty() override; // TODO: remove bool isChainDirty() const override; void draw() override; void receivedFocus();