GRAPHICS: MACGUI: Event processing code for text selection in MacTextWindow
This commit is contained in:
parent
20734108e3
commit
c25a26d11c
4 changed files with 73 additions and 0 deletions
|
@ -445,4 +445,8 @@ void MacText::removeLastLine() {
|
||||||
_textMaxHeight -= h;
|
_textMaxHeight -= h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MacText::getRowCol(int x, int y, int *col, int *row) {
|
||||||
|
warning("getRowCol(%d, %d, ...)", x, y);
|
||||||
|
}
|
||||||
|
|
||||||
} // End of namespace Graphics
|
} // End of namespace Graphics
|
||||||
|
|
|
@ -113,6 +113,8 @@ public:
|
||||||
void render();
|
void render();
|
||||||
Graphics::ManagedSurface *getSurface() { return _surface; }
|
Graphics::ManagedSurface *getSurface() { return _surface; }
|
||||||
|
|
||||||
|
void getRowCol(int x, int y, int *col, int *row);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void splitString(Common::String &s);
|
void splitString(Common::String &s);
|
||||||
void render(int from, int to);
|
void render(int from, int to);
|
||||||
|
|
|
@ -54,6 +54,7 @@ MacTextWindow::MacTextWindow(MacWindowManager *wm, const MacFont *font, int fgco
|
||||||
_maxWidth = maxWidth;
|
_maxWidth = maxWidth;
|
||||||
|
|
||||||
_inputIsDirty = true;
|
_inputIsDirty = true;
|
||||||
|
_inTextSelection = false;
|
||||||
|
|
||||||
_scrollPos = 0;
|
_scrollPos = 0;
|
||||||
|
|
||||||
|
@ -225,9 +226,71 @@ bool MacTextWindow::processEvent(Common::Event &event) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (click == kBorderInner) {
|
||||||
|
if (event.type == Common::EVENT_LBUTTONDOWN) {
|
||||||
|
startMarking(event.mouse.x, event.mouse.y);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if (event.type == Common::EVENT_LBUTTONUP) {
|
||||||
|
if (_inTextSelection) {
|
||||||
|
_inTextSelection = false;
|
||||||
|
|
||||||
|
if (_selectedText.endY == -1 ||
|
||||||
|
(_selectedText.endX == _selectedText.startX && _selectedText.endY == _selectedText.startY)) {
|
||||||
|
_selectedText.startY = _selectedText.endY = -1;
|
||||||
|
_contentIsDirty = true;
|
||||||
|
//_menu->enableCommand(kMenuEdit, kMenuActionCopy, false);
|
||||||
|
} else {
|
||||||
|
//_menu->enableCommand(kMenuEdit, kMenuActionCopy, true);
|
||||||
|
|
||||||
|
bool cutAllowed = false;
|
||||||
|
|
||||||
|
if (_selectedText.startY == _selectedText.endY && _selectedText.startY == _mactext->getLineCount() - 1)
|
||||||
|
cutAllowed = true;
|
||||||
|
|
||||||
|
//_menu->enableCommand(kMenuEdit, kMenuActionCut, cutAllowed);
|
||||||
|
//_menu->enableCommand(kMenuEdit, kMenuActionClear, cutAllowed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else if (event.type == Common::EVENT_MOUSEMOVE) {
|
||||||
|
if (_inTextSelection) {
|
||||||
|
updateTextSelection(event.mouse.x, event.mouse.y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return MacWindow::processEvent(event);
|
return MacWindow::processEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MacTextWindow::startMarking(int x, int y) {
|
||||||
|
x -= getInnerDimensions().left;
|
||||||
|
y -= getInnerDimensions().top;
|
||||||
|
|
||||||
|
y += _scrollPos;
|
||||||
|
|
||||||
|
_mactext->getRowCol(x, y, &_selectedText.startX, &_selectedText.startY);
|
||||||
|
|
||||||
|
_selectedText.endY = -1;
|
||||||
|
|
||||||
|
_inTextSelection = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MacTextWindow::updateTextSelection(int x, int y) {
|
||||||
|
x -= getInnerDimensions().left;
|
||||||
|
y -= getInnerDimensions().top;
|
||||||
|
|
||||||
|
y += _scrollPos;
|
||||||
|
|
||||||
|
_mactext->getRowCol(x, y, &_selectedText.endX, &_selectedText.endY);
|
||||||
|
|
||||||
|
_contentIsDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
void MacTextWindow::undrawInput() {
|
void MacTextWindow::undrawInput() {
|
||||||
for (uint i = 0; i < _inputTextHeight; i++)
|
for (uint i = 0; i < _inputTextHeight; i++)
|
||||||
_mactext->removeLastLine();
|
_mactext->removeLastLine();
|
||||||
|
|
|
@ -71,6 +71,9 @@ private:
|
||||||
void drawInput();
|
void drawInput();
|
||||||
void updateCursorPos();
|
void updateCursorPos();
|
||||||
|
|
||||||
|
void startMarking(int x, int y);
|
||||||
|
void updateTextSelection(int x, int y);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int _cursorX, _cursorY;
|
int _cursorX, _cursorY;
|
||||||
bool _cursorState;
|
bool _cursorState;
|
||||||
|
@ -88,6 +91,7 @@ private:
|
||||||
|
|
||||||
ManagedSurface *_cursorSurface;
|
ManagedSurface *_cursorSurface;
|
||||||
|
|
||||||
|
bool _inTextSelection;
|
||||||
SelectedText _selectedText;
|
SelectedText _selectedText;
|
||||||
|
|
||||||
int _maxWidth;
|
int _maxWidth;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue