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