mirror of https://github.com/stella-emu/stella.git
finalized EditableWidget
enabled selection drawing on all derived widgets
This commit is contained in:
parent
ac47d855e1
commit
2ec1f463ad
|
@ -646,7 +646,7 @@ void DataGridWidget::drawWidget(bool hilite)
|
||||||
|
|
||||||
// Only draw the caret while editing, and if it's in the current viewport
|
// Only draw the caret while editing, and if it's in the current viewport
|
||||||
if(_editMode)
|
if(_editMode)
|
||||||
drawCaret();
|
drawCaretSelection();
|
||||||
|
|
||||||
// Draw the scrollbar
|
// Draw the scrollbar
|
||||||
if(_scrollBar)
|
if(_scrollBar)
|
||||||
|
|
|
@ -547,7 +547,7 @@ void RomListWidget::drawWidget(bool hilite)
|
||||||
s.drawString(_font, editString(), _x + r.x(), ypos, r.w(), textColor,
|
s.drawString(_font, editString(), _x + r.x(), ypos, r.w(), textColor,
|
||||||
TextAlign::Left, -_editScrollOffset, false);
|
TextAlign::Left, -_editScrollOffset, false);
|
||||||
|
|
||||||
drawCaret();
|
drawCaretSelection();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -145,7 +145,7 @@ void CheckListWidget::drawWidget(bool hilite)
|
||||||
(!_useScrollbar ||
|
(!_useScrollbar ||
|
||||||
((_selectedItem >= _scrollBar->_currentPos) &&
|
((_selectedItem >= _scrollBar->_currentPos) &&
|
||||||
(_selectedItem < _scrollBar->_currentPos + _rows))))
|
(_selectedItem < _scrollBar->_currentPos + _rows))))
|
||||||
drawCaret();
|
drawCaretSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -108,10 +108,8 @@ void EditTextWidget::drawWidget(bool hilite)
|
||||||
: onTop && isEnabled() ? _textcolor : kColor,
|
: onTop && isEnabled() ? _textcolor : kColor,
|
||||||
TextAlign::Left, scrollOffset(), !isEditable());
|
TextAlign::Left, scrollOffset(), !isEditable());
|
||||||
|
|
||||||
// Draw selected text
|
// Draw the caret and selection
|
||||||
drawSelection();
|
drawCaretSelection();
|
||||||
// Draw the caret
|
|
||||||
drawCaret();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -159,12 +159,12 @@ bool EditableWidget::handleControlKeys(StellaKey key, StellaMod mod)
|
||||||
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_K: // TODO
|
case KBDK_K:
|
||||||
handled = killLine(+1);
|
handled = killLine(+1);
|
||||||
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_U: // TODO
|
case KBDK_U:
|
||||||
handled = killLine(-1);
|
handled = killLine(-1);
|
||||||
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
@ -284,12 +284,16 @@ bool EditableWidget::handleNormalKeys(StellaKey key)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_BACKSPACE:
|
case KBDK_BACKSPACE:
|
||||||
|
handled = killSelectedText();
|
||||||
|
if(!handled)
|
||||||
handled = killChar(-1);
|
handled = killChar(-1);
|
||||||
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBDK_DELETE:
|
case KBDK_DELETE:
|
||||||
case KBDK_KP_PERIOD:
|
case KBDK_KP_PERIOD:
|
||||||
|
handled = killSelectedText();
|
||||||
|
if(!handled)
|
||||||
handled = killChar(+1);
|
handled = killChar(+1);
|
||||||
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
if(handled) sendCommand(EditableWidget::kChangedCmd, key, _id);
|
||||||
break;
|
break;
|
||||||
|
@ -342,7 +346,7 @@ int EditableWidget::getCaretOffset() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void EditableWidget::drawCaret()
|
void EditableWidget::drawCaretSelection()
|
||||||
{
|
{
|
||||||
// Only draw if item is visible
|
// Only draw if item is visible
|
||||||
if (!_editable || !isVisible() || !_boss->isVisible() || !_hasFocus)
|
if (!_editable || !isVisible() || !_boss->isVisible() || !_hasFocus)
|
||||||
|
@ -360,21 +364,12 @@ void EditableWidget::drawCaret()
|
||||||
FBSurface& s = _boss->dialog().surface();
|
FBSurface& s = _boss->dialog().surface();
|
||||||
s.vLine(x, 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);
|
s.vLine(x-1, y + 2, y + editRect.h() - 2, kTextColorHi);
|
||||||
}
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
if(_selectSize)
|
||||||
void EditableWidget::drawSelection()
|
{
|
||||||
{
|
|
||||||
// Only draw if item is visible
|
|
||||||
if(!_editable || !isVisible() || !_boss->isVisible() || !_hasFocus
|
|
||||||
|| !_selectSize)
|
|
||||||
return;
|
|
||||||
|
|
||||||
FBSurface& s = _boss->dialog().surface();
|
|
||||||
string text = selectString();
|
string text = selectString();
|
||||||
const Common::Rect& editRect = getEditRect();
|
x = editRect.x();
|
||||||
int x = editRect.x();
|
y = editRect.y();
|
||||||
int y = editRect.y();
|
|
||||||
int w = editRect.w();
|
int w = editRect.w();
|
||||||
int h = editRect.h();
|
int h = editRect.h();
|
||||||
int wt = int(text.length()) * _font.getMaxCharWidth() + 1;
|
int wt = int(text.length()) * _font.getMaxCharWidth() + 1;
|
||||||
|
@ -398,6 +393,7 @@ void EditableWidget::drawSelection()
|
||||||
s.fillRect(x - 1, y + 1, w + 1, h - 3, kTextColorHi);
|
s.fillRect(x - 1, y + 1, w + 1, h - 3, kTextColorHi);
|
||||||
s.drawString(_font, text, x, y + 1, w, h,
|
s.drawString(_font, text, x, y + 1, w, h,
|
||||||
kTextColorInv, TextAlign::Left, 0, false);
|
kTextColorInv, TextAlign::Left, 0, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
@ -466,10 +462,8 @@ int EditableWidget::scrollOffset()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
bool EditableWidget::killChar(int direction)
|
bool EditableWidget::killChar(int direction)
|
||||||
{
|
{
|
||||||
bool handled = killSelectedText();
|
bool handled = false;
|
||||||
|
|
||||||
if(!handled)
|
|
||||||
{
|
|
||||||
if(direction == -1) // Delete previous character (backspace)
|
if(direction == -1) // Delete previous character (backspace)
|
||||||
{
|
{
|
||||||
if(_caretPos > 0)
|
if(_caretPos > 0)
|
||||||
|
@ -484,7 +478,6 @@ bool EditableWidget::killChar(int direction)
|
||||||
_editString.erase(_caretPos, 1);
|
_editString.erase(_caretPos, 1);
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
@ -503,6 +496,9 @@ bool EditableWidget::killLine(int direction)
|
||||||
killChar(-1);
|
killChar(-1);
|
||||||
|
|
||||||
handled = true;
|
handled = true;
|
||||||
|
// remove selection for removed text
|
||||||
|
if(_selectSize < 0)
|
||||||
|
_selectSize = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(direction == 1) // erase from current position to end of line
|
else if(direction == 1) // erase from current position to end of line
|
||||||
|
@ -514,6 +510,9 @@ bool EditableWidget::killLine(int direction)
|
||||||
killChar(+1);
|
killChar(+1);
|
||||||
|
|
||||||
handled = true;
|
handled = true;
|
||||||
|
// remove selection for removed text
|
||||||
|
if(_selectSize > 0)
|
||||||
|
_selectSize = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,6 +545,9 @@ bool EditableWidget::killLastWord()
|
||||||
killChar(-1);
|
killChar(-1);
|
||||||
|
|
||||||
handled = true;
|
handled = true;
|
||||||
|
// remove selection for removed word
|
||||||
|
if(_selectSize < 0)
|
||||||
|
_selectSize = std::min(_selectSize + count, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return handled;
|
return handled;
|
||||||
|
|
|
@ -72,7 +72,7 @@ class EditableWidget : public Widget, public CommandSender
|
||||||
|
|
||||||
virtual Common::Rect getEditRect() const = 0;
|
virtual Common::Rect getEditRect() const = 0;
|
||||||
virtual int getCaretOffset() const;
|
virtual int getCaretOffset() const;
|
||||||
void drawCaret();
|
void drawCaretSelection();
|
||||||
bool setCaretPos(int newPos);
|
bool setCaretPos(int newPos);
|
||||||
bool moveCaretPos(int direction);
|
bool moveCaretPos(int direction);
|
||||||
bool adjustOffset();
|
bool adjustOffset();
|
||||||
|
@ -82,7 +82,6 @@ class EditableWidget : public Widget, public CommandSender
|
||||||
string& editString() { return _editString; }
|
string& editString() { return _editString; }
|
||||||
const string selectString() const;
|
const string selectString() const;
|
||||||
void resetSelection() { _selectSize = 0; }
|
void resetSelection() { _selectSize = 0; }
|
||||||
void drawSelection();
|
|
||||||
int scrollOffset();
|
int scrollOffset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -297,7 +297,7 @@ void PopUpWidget::drawWidget(bool hilite)
|
||||||
align, editable ? -_editScrollOffset : 0, !editable);
|
align, editable ? -_editScrollOffset : 0, !editable);
|
||||||
|
|
||||||
if(editable)
|
if(editable)
|
||||||
drawCaret();
|
drawCaretSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -112,7 +112,7 @@ void StringListWidget::drawWidget(bool hilite)
|
||||||
(!_useScrollbar ||
|
(!_useScrollbar ||
|
||||||
((_selectedItem >= _scrollBar->_currentPos) &&
|
((_selectedItem >= _scrollBar->_currentPos) &&
|
||||||
(_selectedItem < _scrollBar->_currentPos + _rows))))
|
(_selectedItem < _scrollBar->_currentPos + _rows))))
|
||||||
drawCaret();
|
drawCaretSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
Loading…
Reference in New Issue