TextDocumentView: Selection polishing, I-Beam cursor
This commit is contained in:
@@ -6,7 +6,9 @@
|
|||||||
#include "TextDocumentView.h"
|
#include "TextDocumentView.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <Cursor.h>
|
||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
#include <Shape.h>
|
#include <Shape.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
@@ -63,11 +65,15 @@ TextDocumentView::Draw(BRect updateRect)
|
|||||||
BShape shape;
|
BShape shape;
|
||||||
_GetSelectionShape(shape, start, end);
|
_GetSelectionShape(shape, start, end);
|
||||||
|
|
||||||
SetHighColor(60, 40, 0);
|
|
||||||
SetDrawingMode(B_OP_SUBTRACT);
|
SetDrawingMode(B_OP_SUBTRACT);
|
||||||
|
SetLineMode(B_ROUND_CAP, B_ROUND_JOIN);
|
||||||
|
MovePenTo(fInsetLeft - 0.5f, fInsetTop - 0.5f);
|
||||||
|
|
||||||
MovePenTo(fInsetLeft, fInsetTop);
|
SetHighColor(30, 30, 30);
|
||||||
FillShape(&shape);
|
FillShape(&shape);
|
||||||
|
|
||||||
|
SetHighColor(40, 40, 40);
|
||||||
|
StrokeShape(&shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -112,6 +118,9 @@ void
|
|||||||
TextDocumentView::MouseMoved(BPoint where, uint32 transit,
|
TextDocumentView::MouseMoved(BPoint where, uint32 transit,
|
||||||
const BMessage* dragMessage)
|
const BMessage* dragMessage)
|
||||||
{
|
{
|
||||||
|
BCursor iBeamCursor(B_CURSOR_ID_I_BEAM);
|
||||||
|
SetViewCursor(&iBeamCursor);
|
||||||
|
|
||||||
if (fMouseDown)
|
if (fMouseDown)
|
||||||
SetCaret(where, true);
|
SetCaret(where, true);
|
||||||
}
|
}
|
||||||
@@ -314,8 +323,7 @@ TextDocumentView::_SetCaretOffset(int32 offset, bool updateAnchor,
|
|||||||
|
|
||||||
// _GetSelectionShape
|
// _GetSelectionShape
|
||||||
void
|
void
|
||||||
TextDocumentView::_GetSelectionShape(BShape& shape,
|
TextDocumentView::_GetSelectionShape(BShape& shape, int32 start, int32 end)
|
||||||
int32 start, int32 end)
|
|
||||||
{
|
{
|
||||||
float startX1;
|
float startX1;
|
||||||
float startY1;
|
float startY1;
|
||||||
@@ -324,12 +332,22 @@ TextDocumentView::_GetSelectionShape(BShape& shape,
|
|||||||
fTextDocumentLayout.GetTextBounds(start, startX1, startY1, startX2,
|
fTextDocumentLayout.GetTextBounds(start, startX1, startY1, startX2,
|
||||||
startY2);
|
startY2);
|
||||||
|
|
||||||
|
startX1 = floorf(startX1);
|
||||||
|
startY1 = floorf(startY1);
|
||||||
|
startX2 = ceilf(startX2);
|
||||||
|
startY2 = ceilf(startY2);
|
||||||
|
|
||||||
float endX1;
|
float endX1;
|
||||||
float endY1;
|
float endY1;
|
||||||
float endX2;
|
float endX2;
|
||||||
float endY2;
|
float endY2;
|
||||||
fTextDocumentLayout.GetTextBounds(end, endX1, endY1, endX2, endY2);
|
fTextDocumentLayout.GetTextBounds(end, endX1, endY1, endX2, endY2);
|
||||||
|
|
||||||
|
endX1 = floorf(endX1);
|
||||||
|
endY1 = floorf(endY1);
|
||||||
|
endX2 = ceilf(endX2);
|
||||||
|
endY2 = ceilf(endY2);
|
||||||
|
|
||||||
int32 startLineIndex = fTextDocumentLayout.LineIndexForOffset(start);
|
int32 startLineIndex = fTextDocumentLayout.LineIndexForOffset(start);
|
||||||
int32 endLineIndex = fTextDocumentLayout.LineIndexForOffset(end);
|
int32 endLineIndex = fTextDocumentLayout.LineIndexForOffset(end);
|
||||||
|
|
||||||
@@ -351,9 +369,11 @@ TextDocumentView::_GetSelectionShape(BShape& shape,
|
|||||||
// ------###
|
// ------###
|
||||||
// ##-------
|
// ##-------
|
||||||
// ---------
|
// ---------
|
||||||
|
float width = ceilf(fTextDocumentLayout.Width());
|
||||||
|
|
||||||
BPoint lt(startX1, startY1);
|
BPoint lt(startX1, startY1);
|
||||||
BPoint rt(fTextDocumentLayout.Width(), startY1);
|
BPoint rt(width, startY1);
|
||||||
BPoint rb(fTextDocumentLayout.Width(), startY2);
|
BPoint rb(width, startY2);
|
||||||
BPoint lb(startX1, startY2);
|
BPoint lb(startX1, startY2);
|
||||||
|
|
||||||
shape.MoveTo(lt);
|
shape.MoveTo(lt);
|
||||||
@@ -374,9 +394,11 @@ TextDocumentView::_GetSelectionShape(BShape& shape,
|
|||||||
shape.Close();
|
shape.Close();
|
||||||
} else {
|
} else {
|
||||||
// Selection over multiple lines
|
// Selection over multiple lines
|
||||||
|
float width = ceilf(fTextDocumentLayout.Width());
|
||||||
|
|
||||||
shape.MoveTo(BPoint(startX1, startY1));
|
shape.MoveTo(BPoint(startX1, startY1));
|
||||||
shape.LineTo(BPoint(fTextDocumentLayout.Width(), startY1));
|
shape.LineTo(BPoint(width, startY1));
|
||||||
shape.LineTo(BPoint(fTextDocumentLayout.Width(), endY1));
|
shape.LineTo(BPoint(width, endY1));
|
||||||
shape.LineTo(BPoint(endX1, endY1));
|
shape.LineTo(BPoint(endX1, endY1));
|
||||||
shape.LineTo(BPoint(endX1, endY2));
|
shape.LineTo(BPoint(endX1, endY2));
|
||||||
shape.LineTo(BPoint(0, endY2));
|
shape.LineTo(BPoint(0, endY2));
|
||||||
|
|||||||
Reference in New Issue
Block a user