added blinking cursor

This commit is contained in:
thrust26 2020-11-11 17:26:40 +01:00
parent e5daa770ed
commit 7433e14cec
7 changed files with 58 additions and 20 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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<UndoHandler> myUndoHandler;
int _caretPos{0};
int _caretTimer{0};
bool _caretEnabled{true};
// Size of current selected text
// 0 = no selection

View File

@ -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(); }

View File

@ -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;

View File

@ -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();