HaikuDepot: Implement support for a blinking cursor.
However, since the selection is actually maintained in TextEditor, the cursor can't be navigated. The code needs to shuffle around a bit.
This commit is contained in:
@@ -67,34 +67,29 @@ TextDocumentView::Draw(BRect updateRect)
|
|||||||
fTextDocumentLayout.SetWidth(_TextLayoutWidth(Bounds().Width()));
|
fTextDocumentLayout.SetWidth(_TextLayoutWidth(Bounds().Width()));
|
||||||
fTextDocumentLayout.Draw(this, BPoint(fInsetLeft, fInsetTop), updateRect);
|
fTextDocumentLayout.Draw(this, BPoint(fInsetLeft, fInsetTop), updateRect);
|
||||||
|
|
||||||
if (fSelectionAnchorOffset == fCaretOffset)
|
bool isCaret = fSelectionAnchorOffset == fCaretOffset;
|
||||||
return;
|
|
||||||
|
|
||||||
int32 start;
|
if (isCaret) {
|
||||||
int32 end;
|
if (fShowCaret && fTextEditor.Get() != NULL)
|
||||||
GetSelection(start, end);
|
_DrawCaret(fCaretOffset);
|
||||||
|
} else {
|
||||||
BShape shape;
|
_DrawSelection();
|
||||||
_GetSelectionShape(shape, start, end);
|
|
||||||
|
|
||||||
SetDrawingMode(B_OP_SUBTRACT);
|
|
||||||
SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
|
|
||||||
MovePenTo(fInsetLeft - 0.5f, fInsetTop - 0.5f);
|
|
||||||
|
|
||||||
if (IsFocus() && Window() != NULL && Window()->IsActive()) {
|
|
||||||
SetHighColor(30, 30, 30);
|
|
||||||
FillShape(&shape);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetHighColor(40, 40, 40);
|
|
||||||
StrokeShape(&shape);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextDocumentView::Pulse()
|
TextDocumentView::Pulse()
|
||||||
{
|
{
|
||||||
// TODO: Blink cursor
|
if (fTextEditor.Get() == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Blink cursor
|
||||||
|
fShowCaret = !fShowCaret;
|
||||||
|
if (fCaretBounds.IsValid())
|
||||||
|
Invalidate(fCaretBounds);
|
||||||
|
else
|
||||||
|
Invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -465,7 +460,50 @@ TextDocumentView::_SetCaretOffset(int32 offset, bool updateAnchor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// _GetSelectionShape
|
void
|
||||||
|
TextDocumentView::_DrawCaret(int32 textOffset)
|
||||||
|
{
|
||||||
|
float x1;
|
||||||
|
float y1;
|
||||||
|
float x2;
|
||||||
|
float y2;
|
||||||
|
|
||||||
|
fTextDocumentLayout.GetTextBounds(textOffset, x1, y1, x2, y2);
|
||||||
|
x2 = x1 + 1;
|
||||||
|
|
||||||
|
fCaretBounds = BRect(x1, y1, x2, y2);
|
||||||
|
fCaretBounds.OffsetBy(fInsetLeft, fInsetTop);
|
||||||
|
|
||||||
|
SetDrawingMode(B_OP_INVERT);
|
||||||
|
FillRect(fCaretBounds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TextDocumentView::_DrawSelection()
|
||||||
|
{
|
||||||
|
int32 start;
|
||||||
|
int32 end;
|
||||||
|
GetSelection(start, end);
|
||||||
|
|
||||||
|
BShape shape;
|
||||||
|
_GetSelectionShape(shape, start, end);
|
||||||
|
|
||||||
|
SetDrawingMode(B_OP_SUBTRACT);
|
||||||
|
|
||||||
|
SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
|
||||||
|
MovePenTo(fInsetLeft - 0.5f, fInsetTop - 0.5f);
|
||||||
|
|
||||||
|
if (IsFocus() && Window() != NULL && Window()->IsActive()) {
|
||||||
|
SetHighColor(30, 30, 30);
|
||||||
|
FillShape(&shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetHighColor(40, 40, 40);
|
||||||
|
StrokeShape(&shape);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextDocumentView::_GetSelectionShape(BShape& shape, int32 start, int32 end)
|
TextDocumentView::_GetSelectionShape(BShape& shape, int32 start, int32 end)
|
||||||
{
|
{
|
||||||
@@ -551,3 +589,5 @@ TextDocumentView::_GetSelectionShape(BShape& shape, int32 start, int32 end)
|
|||||||
shape.Close();
|
shape.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ private:
|
|||||||
void _SetCaretOffset(int32 offset, bool updateAnchor,
|
void _SetCaretOffset(int32 offset, bool updateAnchor,
|
||||||
bool lockSelectionAnchor);
|
bool lockSelectionAnchor);
|
||||||
|
|
||||||
|
void _DrawCaret(int32 textOffset);
|
||||||
|
void _DrawSelection();
|
||||||
void _GetSelectionShape(BShape& shape,
|
void _GetSelectionShape(BShape& shape,
|
||||||
int32 start, int32 end);
|
int32 start, int32 end);
|
||||||
|
|
||||||
@@ -93,6 +95,7 @@ private:
|
|||||||
int32 fCaretOffset;
|
int32 fCaretOffset;
|
||||||
float fCaretAnchorX;
|
float fCaretAnchorX;
|
||||||
bool fShowCaret;
|
bool fShowCaret;
|
||||||
|
BRect fCaretBounds;
|
||||||
|
|
||||||
bool fMouseDown;
|
bool fMouseDown;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user