Fixed LineWidth(): now it calls StyledWidth(). It's not an issue, since charachter widths are cached by _BWidthBuffer_.
Marc Flerackers lend me a hand and now alignments should work much better (if not perfectly) Some cleanups. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9119 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Copyright (c) 2001-2003, OpenBeOS
|
// Copyright (c) 2001-2004, Haiku, Inc.
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
// copy of this software and associated documentation files (the "Software"),
|
// copy of this software and associated documentation files (the "Software"),
|
||||||
@@ -24,25 +24,15 @@
|
|||||||
// Description: Line storage used by BTextView
|
// Description: Line storage used by BTextView
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
|
||||||
|
|
||||||
// System Includes -------------------------------------------------------------
|
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include "TextViewSupportBuffer.h"
|
#include "TextViewSupportBuffer.h"
|
||||||
|
|
||||||
// Project Includes ------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Includes --------------------------------------------------------------
|
|
||||||
|
|
||||||
// Local Defines ---------------------------------------------------------------
|
|
||||||
typedef struct STELine {
|
typedef struct STELine {
|
||||||
long offset; // offset of first character of line
|
long offset; // offset of first character of line
|
||||||
float origin; // pixel position of top of line
|
float origin; // pixel position of top of line
|
||||||
float ascent; // maximum ascent for line
|
float ascent; // maximum ascent for line
|
||||||
float width; // width of line
|
|
||||||
} STELine, *STELinePtr;
|
} STELine, *STELinePtr;
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
|
||||||
|
|
||||||
// _BLineBuffer_ class ---------------------------------------------------------
|
// _BLineBuffer_ class ---------------------------------------------------------
|
||||||
class _BLineBuffer_ : public _BTextViewSupportBuffer_<STELine> {
|
class _BLineBuffer_ : public _BTextViewSupportBuffer_<STELine> {
|
||||||
@@ -64,19 +54,21 @@ virtual ~_BLineBuffer_();
|
|||||||
long NumLines() const;
|
long NumLines() const;
|
||||||
const STELinePtr operator[](int32 index) const;
|
const STELinePtr operator[](int32 index) const;
|
||||||
};
|
};
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
inline int32
|
inline int32
|
||||||
_BLineBuffer_::NumLines() const
|
_BLineBuffer_::NumLines() const
|
||||||
{
|
{
|
||||||
return fItemCount - 1;
|
return fItemCount - 1;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
inline const STELinePtr
|
inline const STELinePtr
|
||||||
_BLineBuffer_::operator[](int32 index) const
|
_BLineBuffer_::operator[](int32 index) const
|
||||||
{
|
{
|
||||||
return &fBuffer[index];
|
return &fBuffer[index];
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* $Log $
|
* $Log $
|
||||||
|
|||||||
@@ -35,8 +35,7 @@
|
|||||||
// to refresh only changed parts of text (currently we often redraw the whole text)
|
// to refresh only changed parts of text (currently we often redraw the whole text)
|
||||||
|
|
||||||
// Known Bugs:
|
// Known Bugs:
|
||||||
// - PointAt(), OffsetAt(), and possibly some other functions don't work right yet
|
// - some issues when alignment is different than B_ALIGN_LEFT.
|
||||||
// when alignment is different than B_ALIGN_LEFT.
|
|
||||||
// - visual artifacts appears when you highlight some text which spans between
|
// - visual artifacts appears when you highlight some text which spans between
|
||||||
// multiple lines and with mixed sizes/styles (could be something in GetTextRegion())
|
// multiple lines and with mixed sizes/styles (could be something in GetTextRegion())
|
||||||
|
|
||||||
@@ -1845,8 +1844,7 @@ BTextView::PointAt(int32 inOffset, float *outHeight) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fAlignment != B_ALIGN_LEFT) {
|
if (fAlignment != B_ALIGN_LEFT) {
|
||||||
float modifier = fTextRect.right - StyledWidth(line->offset,
|
float modifier = fTextRect.right - LineWidth(lineNum);
|
||||||
(line + 1)->offset - line->offset);
|
|
||||||
if (fAlignment == B_ALIGN_CENTER)
|
if (fAlignment == B_ALIGN_CENTER)
|
||||||
modifier /= 2;
|
modifier /= 2;
|
||||||
result.x += modifier;
|
result.x += modifier;
|
||||||
@@ -1894,6 +1892,13 @@ BTextView::OffsetAt(BPoint point) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// convert to text rect coordinates
|
// convert to text rect coordinates
|
||||||
|
if (fAlignment != B_ALIGN_LEFT) {
|
||||||
|
float lineWidth = fTextRect.right - LineWidth(lineNum);
|
||||||
|
if (fAlignment == B_ALIGN_CENTER)
|
||||||
|
lineWidth /= 2;
|
||||||
|
point.x -= lineWidth;
|
||||||
|
}
|
||||||
|
|
||||||
point.x -= fTextRect.left;
|
point.x -= fTextRect.left;
|
||||||
point.x = max_c(point.x, 0.0);
|
point.x = max_c(point.x, 0.0);
|
||||||
|
|
||||||
@@ -2055,8 +2060,10 @@ BTextView::LineWidth(int32 lineNum) const
|
|||||||
CALLED();
|
CALLED();
|
||||||
if (lineNum < 0 || lineNum >= fLines->NumLines())
|
if (lineNum < 0 || lineNum >= fLines->NumLines())
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else {
|
||||||
return (*fLines)[lineNum]->width;
|
STELinePtr line = (*fLines)[lineNum];
|
||||||
|
return StyledWidth(line->offset, (line + 1)->offset - line->offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2734,7 +2741,6 @@ BTextView::InsertText(const char *inText, int32 inLength, int32 inOffset,
|
|||||||
fStyles->BumpOffset(inLength, fStyles->OffsetToRun(inOffset - 1) + 1);
|
fStyles->BumpOffset(inLength, fStyles->OffsetToRun(inOffset - 1) + 1);
|
||||||
|
|
||||||
if (inRuns != NULL)
|
if (inRuns != NULL)
|
||||||
//SetStyleRange(inOffset, inOffset + inLength, inStyles, false);
|
|
||||||
SetRunArray(inOffset, inOffset + inLength, inRuns);
|
SetRunArray(inOffset, inOffset + inLength, inRuns);
|
||||||
else {
|
else {
|
||||||
// apply nullStyle to inserted text
|
// apply nullStyle to inserted text
|
||||||
@@ -3572,9 +3578,13 @@ BTextView::StyledWidth(int32 fromOffset, int32 length, float *outAscent,
|
|||||||
maxAscent = max_c(ascent, maxAscent);
|
maxAscent = max_c(ascent, maxAscent);
|
||||||
maxDescent = max_c(descent, maxDescent);
|
maxDescent = max_c(descent, maxDescent);
|
||||||
|
|
||||||
// TODO: Change this with a call to _BWidthBuffer_::StringWidth()
|
// Use _BWidthBuffer_ if possible
|
||||||
// as soon as everything else work
|
if (sWidths != NULL) {
|
||||||
result += font->StringWidth(fText->Text() + fromOffset, numChars);
|
LockWidthBuffer();
|
||||||
|
result += sWidths->StringWidth(fText->Text(), fromOffset, numChars, font);
|
||||||
|
UnlockWidthBuffer();
|
||||||
|
} else
|
||||||
|
result += font->StringWidth(fText->Text() + fromOffset, numChars);
|
||||||
|
|
||||||
fromOffset += numChars;
|
fromOffset += numChars;
|
||||||
length -= numChars;
|
length -= numChars;
|
||||||
@@ -3673,9 +3683,10 @@ BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
|
|||||||
|
|
||||||
if (fAlignment != B_ALIGN_LEFT) {
|
if (fAlignment != B_ALIGN_LEFT) {
|
||||||
// B_ALIGN_RIGHT
|
// B_ALIGN_RIGHT
|
||||||
startLeft = (fTextRect.right - StyledWidth(line->offset, length));
|
startLeft = (fTextRect.right - LineWidth(i));
|
||||||
if (fAlignment == B_ALIGN_CENTER)
|
if (fAlignment == B_ALIGN_CENTER)
|
||||||
startLeft /= 2;
|
startLeft /= 2;
|
||||||
|
startLeft += fTextRect.left;
|
||||||
}
|
}
|
||||||
|
|
||||||
MovePenTo(startLeft, line->origin + line->ascent + fTextRect.top);
|
MovePenTo(startLeft, line->origin + line->ascent + fTextRect.top);
|
||||||
|
|||||||
Reference in New Issue
Block a user