no more fOrigin and fScale in Painter, everything is now expected in absolute (screen) coordinates
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@12402 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -76,9 +76,7 @@ class Painter {
|
|||||||
inline void SetLowColor(const RGBColor& color)
|
inline void SetLowColor(const RGBColor& color)
|
||||||
{ SetLowColor(color.GetColor32()); }
|
{ SetLowColor(color.GetColor32()); }
|
||||||
|
|
||||||
void SetScale(float scale);
|
|
||||||
void SetPenSize(float size);
|
void SetPenSize(float size);
|
||||||
void SetOrigin(const BPoint& origin);
|
|
||||||
void SetDrawingMode(drawing_mode mode);
|
void SetDrawingMode(drawing_mode mode);
|
||||||
void SetBlendingMode(source_alpha alphaSrcMode,
|
void SetBlendingMode(source_alpha alphaSrcMode,
|
||||||
alpha_function alphaFncMode);
|
alpha_function alphaFncMode);
|
||||||
@@ -249,10 +247,6 @@ class Painter {
|
|||||||
bool centerOffset = true) const;
|
bool centerOffset = true) const;
|
||||||
BPoint _Transform(const BPoint& point,
|
BPoint _Transform(const BPoint& point,
|
||||||
bool centerOffset = true) const;
|
bool centerOffset = true) const;
|
||||||
void _Transform(float* width) const;
|
|
||||||
float _Transform(const float& width) const;
|
|
||||||
void _Transform(BRect* rect) const;
|
|
||||||
BRect _Transform(const BRect& rect) const;
|
|
||||||
BRect _Clipped(const BRect& rect) const;
|
BRect _Clipped(const BRect& rect) const;
|
||||||
|
|
||||||
// void _RebuildClipping();
|
// void _RebuildClipping();
|
||||||
@@ -329,9 +323,7 @@ class Painter {
|
|||||||
// does not concern rendering
|
// does not concern rendering
|
||||||
bool fSubpixelPrecise;
|
bool fSubpixelPrecise;
|
||||||
|
|
||||||
float fScale;
|
|
||||||
float fPenSize;
|
float fPenSize;
|
||||||
BPoint fOrigin;
|
|
||||||
BRegion* fClippingRegion; // NULL indicates no clipping at all
|
BRegion* fClippingRegion; // NULL indicates no clipping at all
|
||||||
drawing_mode fDrawingMode;
|
drawing_mode fDrawingMode;
|
||||||
source_alpha fAlphaSrcMode;
|
source_alpha fAlphaSrcMode;
|
||||||
|
|||||||
@@ -54,9 +54,7 @@ Painter::Painter()
|
|||||||
fFontRendererBin(NULL),
|
fFontRendererBin(NULL),
|
||||||
fLineProfile(),
|
fLineProfile(),
|
||||||
fSubpixelPrecise(false),
|
fSubpixelPrecise(false),
|
||||||
fScale(1.0),
|
|
||||||
fPenSize(1.0),
|
fPenSize(1.0),
|
||||||
fOrigin(0.0, 0.0),
|
|
||||||
fClippingRegion(NULL),
|
fClippingRegion(NULL),
|
||||||
fDrawingMode(B_OP_COPY),
|
fDrawingMode(B_OP_COPY),
|
||||||
fAlphaSrcMode(B_PIXEL_ALPHA),
|
fAlphaSrcMode(B_PIXEL_ALPHA),
|
||||||
@@ -154,9 +152,7 @@ Painter::SetDrawData(const DrawData* data)
|
|||||||
// for now...
|
// for now...
|
||||||
SetHighColor(data->highcolor.GetColor32());
|
SetHighColor(data->highcolor.GetColor32());
|
||||||
SetLowColor(data->lowcolor.GetColor32());
|
SetLowColor(data->lowcolor.GetColor32());
|
||||||
SetScale(data->scale);
|
|
||||||
SetPenSize(data->pensize);
|
SetPenSize(data->pensize);
|
||||||
// fOrigin = data->coordOrigin;
|
|
||||||
SetDrawingMode(data->draw_mode);
|
SetDrawingMode(data->draw_mode);
|
||||||
SetBlendingMode(data->alphaSrcMode, data->alphaFncMode);
|
SetBlendingMode(data->alphaSrcMode, data->alphaFncMode);
|
||||||
SetPenLocation(data->penlocation);
|
SetPenLocation(data->penlocation);
|
||||||
@@ -201,17 +197,6 @@ Painter::SetLowColor(const rgb_color& color)
|
|||||||
fPatternHandler->SetLowColor(color);;
|
fPatternHandler->SetLowColor(color);;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetScale
|
|
||||||
void
|
|
||||||
Painter::SetScale(float scale)
|
|
||||||
{
|
|
||||||
if (fScale != scale) {
|
|
||||||
fScale = scale;
|
|
||||||
// _RebuildClipping();
|
|
||||||
_UpdateLineWidth();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPenSize
|
// SetPenSize
|
||||||
void
|
void
|
||||||
Painter::SetPenSize(float size)
|
Painter::SetPenSize(float size)
|
||||||
@@ -222,20 +207,6 @@ Painter::SetPenSize(float size)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOrigin
|
|
||||||
void
|
|
||||||
Painter::SetOrigin(const BPoint& origin)
|
|
||||||
{
|
|
||||||
// NOTE: The BeBook says that the coordinate system
|
|
||||||
// of a view cannot be changed during an update, because
|
|
||||||
// it would mess up the clipping, and this is indeed
|
|
||||||
// what would happen in this implementation as well.
|
|
||||||
// I don't know yet what actually happens if you still
|
|
||||||
// try to call SetOrigin() from within BView::Draw()
|
|
||||||
fOrigin = origin;
|
|
||||||
// _RebuildClipping();
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetDrawingMode
|
// SetDrawingMode
|
||||||
void
|
void
|
||||||
Painter::SetDrawingMode(drawing_mode mode)
|
Painter::SetDrawingMode(drawing_mode mode)
|
||||||
@@ -312,7 +283,6 @@ Painter::StrokeLine(BPoint a, BPoint b, DrawData* context)
|
|||||||
_Transform(&b);
|
_Transform(&b);
|
||||||
|
|
||||||
SetPenSize(context->pensize);
|
SetPenSize(context->pensize);
|
||||||
float penSize = _Transform(fPenSize);
|
|
||||||
|
|
||||||
BRect touched(min_c(a.x, b.x), min_c(a.y, b.y),
|
BRect touched(min_c(a.x, b.x), min_c(a.y, b.y),
|
||||||
max_c(a.x, b.x), max_c(a.y, b.y));
|
max_c(a.x, b.x), max_c(a.y, b.y));
|
||||||
@@ -322,7 +292,7 @@ Painter::StrokeLine(BPoint a, BPoint b, DrawData* context)
|
|||||||
// Extending by penSize like that is not really correct,
|
// Extending by penSize like that is not really correct,
|
||||||
// but fast and only triggers unnecessary calculation
|
// but fast and only triggers unnecessary calculation
|
||||||
// in a few edge cases
|
// in a few edge cases
|
||||||
touched.InsetBy(-(penSize - 1), -(penSize - 1));
|
touched.InsetBy(-(fPenSize - 1), -(fPenSize - 1));
|
||||||
if (!touched.Intersects(fClippingRegion->Frame())) {
|
if (!touched.Intersects(fClippingRegion->Frame())) {
|
||||||
touched.Set(0.0, 0.0, -1.0, -1.0);
|
touched.Set(0.0, 0.0, -1.0, -1.0);
|
||||||
return touched;
|
return touched;
|
||||||
@@ -335,7 +305,7 @@ Painter::StrokeLine(BPoint a, BPoint b, DrawData* context)
|
|||||||
fPatternHandler->SetPattern(context->patt);
|
fPatternHandler->SetPattern(context->patt);
|
||||||
|
|
||||||
// first, try an optimized version
|
// first, try an optimized version
|
||||||
if (penSize == 1.0 &&
|
if (fPenSize == 1.0 &&
|
||||||
(fDrawingMode == B_OP_COPY || fDrawingMode == B_OP_OVER)) {
|
(fDrawingMode == B_OP_COPY || fDrawingMode == B_OP_OVER)) {
|
||||||
pattern pat = *fPatternHandler->GetR5Pattern();
|
pattern pat = *fPatternHandler->GetR5Pattern();
|
||||||
if (pat == B_SOLID_HIGH &&
|
if (pat == B_SOLID_HIGH &&
|
||||||
@@ -361,7 +331,7 @@ BRect
|
|||||||
Painter::StrokeLine(BPoint b, DrawData* context)
|
Painter::StrokeLine(BPoint b, DrawData* context)
|
||||||
{
|
{
|
||||||
// TODO: move this function elsewhere
|
// TODO: move this function elsewhere
|
||||||
return StrokeLine(context->penlocation, context);
|
return StrokeLine(context->penlocation, b, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// StraightLine
|
// StraightLine
|
||||||
@@ -535,8 +505,7 @@ Painter::StrokeRect(const BRect& r, const pattern& p) const
|
|||||||
_Transform(&b);
|
_Transform(&b);
|
||||||
|
|
||||||
// first, try an optimized version
|
// first, try an optimized version
|
||||||
float penSize = _Transform(fPenSize);
|
if (fPenSize == 1.0 &&
|
||||||
if (penSize == 1.0 &&
|
|
||||||
(fDrawingMode == B_OP_COPY || fDrawingMode == B_OP_OVER)) {
|
(fDrawingMode == B_OP_COPY || fDrawingMode == B_OP_OVER)) {
|
||||||
// TODO: fix me
|
// TODO: fix me
|
||||||
// pattern p = *fPatternHandler->GetR5Pattern();
|
// pattern p = *fPatternHandler->GetR5Pattern();
|
||||||
@@ -660,9 +629,6 @@ Painter::StrokeRoundRect(const BRect& r, float xRadius, float yRadius,
|
|||||||
_Transform(<);
|
_Transform(<);
|
||||||
_Transform(&rb);
|
_Transform(&rb);
|
||||||
|
|
||||||
_Transform(&xRadius);
|
|
||||||
_Transform(&yRadius);
|
|
||||||
|
|
||||||
agg::rounded_rect rect;
|
agg::rounded_rect rect;
|
||||||
rect.rect(lt.x, lt.y, rb.x, rb.y);
|
rect.rect(lt.x, lt.y, rb.x, rb.y);
|
||||||
rect.radius(xRadius, yRadius);
|
rect.radius(xRadius, yRadius);
|
||||||
@@ -686,9 +652,6 @@ Painter::FillRoundRect(const BRect& r, float xRadius, float yRadius,
|
|||||||
rb.x += 1.0;
|
rb.x += 1.0;
|
||||||
rb.y += 1.0;
|
rb.y += 1.0;
|
||||||
|
|
||||||
_Transform(&xRadius);
|
|
||||||
_Transform(&yRadius);
|
|
||||||
|
|
||||||
agg::rounded_rect rect;
|
agg::rounded_rect rect;
|
||||||
rect.rect(lt.x, lt.y, rb.x, rb.y);
|
rect.rect(lt.x, lt.y, rb.x, rb.y);
|
||||||
rect.radius(xRadius, yRadius);
|
rect.radius(xRadius, yRadius);
|
||||||
@@ -718,8 +681,6 @@ Painter::StrokeArc(BPoint center, float xRadius, float yRadius,
|
|||||||
float angle, float span, const pattern& p) const
|
float angle, float span, const pattern& p) const
|
||||||
{
|
{
|
||||||
_Transform(¢er);
|
_Transform(¢er);
|
||||||
_Transform(&xRadius);
|
|
||||||
_Transform(&yRadius);
|
|
||||||
|
|
||||||
double angleRad = (angle * PI) / 180.0;
|
double angleRad = (angle * PI) / 180.0;
|
||||||
double spanRad = (span * PI) / 180.0;
|
double spanRad = (span * PI) / 180.0;
|
||||||
@@ -737,8 +698,6 @@ Painter::FillArc(BPoint center, float xRadius, float yRadius,
|
|||||||
float angle, float span, const pattern& p) const
|
float angle, float span, const pattern& p) const
|
||||||
{
|
{
|
||||||
_Transform(¢er);
|
_Transform(¢er);
|
||||||
_Transform(&xRadius);
|
|
||||||
_Transform(&yRadius);
|
|
||||||
|
|
||||||
double angleRad = (angle * PI) / 180.0;
|
double angleRad = (angle * PI) / 180.0;
|
||||||
double spanRad = (span * PI) / 180.0;
|
double spanRad = (span * PI) / 180.0;
|
||||||
@@ -812,12 +771,10 @@ Painter::DrawString(const char* utf8String, uint32 length,
|
|||||||
// transform.ShearBy(B_ORIGIN, fFont.Shear(), 0.0);
|
// transform.ShearBy(B_ORIGIN, fFont.Shear(), 0.0);
|
||||||
transform.RotateBy(B_ORIGIN, -fFont.Rotation());
|
transform.RotateBy(B_ORIGIN, -fFont.Rotation());
|
||||||
transform.TranslateBy(baseLine);
|
transform.TranslateBy(baseLine);
|
||||||
transform.ScaleBy(B_ORIGIN, fScale, fScale);
|
|
||||||
transform.TranslateBy(fOrigin);
|
|
||||||
|
|
||||||
BRect clippingFrame;
|
BRect clippingFrame;
|
||||||
if (fClippingRegion)
|
if (fClippingRegion)
|
||||||
clippingFrame = _Transform(fClippingRegion->Frame());
|
clippingFrame = fClippingRegion->Frame();
|
||||||
|
|
||||||
bounds = fTextRenderer->RenderString(utf8String,
|
bounds = fTextRenderer->RenderString(utf8String,
|
||||||
length,
|
length,
|
||||||
@@ -827,11 +784,6 @@ Painter::DrawString(const char* utf8String, uint32 length,
|
|||||||
clippingFrame,
|
clippingFrame,
|
||||||
false,
|
false,
|
||||||
&fPenLocation);
|
&fPenLocation);
|
||||||
// pen location is not transformed in quite the same way,
|
|
||||||
// or transformations would add up
|
|
||||||
transform.Reset();
|
|
||||||
transform.RotateBy(B_ORIGIN, -fFont.Rotation());
|
|
||||||
transform.TranslateBy(baseLine);
|
|
||||||
transform.Transform(&fPenLocation);
|
transform.Transform(&fPenLocation);
|
||||||
}
|
}
|
||||||
return _Clipped(bounds);
|
return _Clipped(bounds);
|
||||||
@@ -919,9 +871,7 @@ Painter::InvertRect(const BRect& r) const
|
|||||||
// implementation only for B_RGB32 at the moment
|
// implementation only for B_RGB32 at the moment
|
||||||
int32 count = region.CountRects();
|
int32 count = region.CountRects();
|
||||||
for (int32 i = 0; i < count; i++) {
|
for (int32 i = 0; i < count; i++) {
|
||||||
BRect r = region.RectAt(i);
|
_InvertRect32(region.RectAt(i));
|
||||||
_Transform(&r);
|
|
||||||
_InvertRect32(r);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -982,16 +932,12 @@ Painter::_MakeEmpty()
|
|||||||
void
|
void
|
||||||
Painter::_Transform(BPoint* point, bool centerOffset) const
|
Painter::_Transform(BPoint* point, bool centerOffset) const
|
||||||
{
|
{
|
||||||
*point += fOrigin;
|
|
||||||
// rounding
|
// rounding
|
||||||
if (!fSubpixelPrecise) {
|
if (!fSubpixelPrecise) {
|
||||||
// TODO: validate usage of floor() for values < 0
|
// TODO: validate usage of floor() for values < 0
|
||||||
point->x = floorf(point->x);
|
point->x = floorf(point->x);
|
||||||
point->y = floorf(point->y);
|
point->y = floorf(point->y);
|
||||||
}
|
}
|
||||||
// apply the scale
|
|
||||||
point->x *= fScale;
|
|
||||||
point->y *= fScale;
|
|
||||||
// this code is supposed to move coordinates to the center of pixels,
|
// this code is supposed to move coordinates to the center of pixels,
|
||||||
// as AGG considers (0,0) to be the "upper left corner" of a pixel,
|
// as AGG considers (0,0) to be the "upper left corner" of a pixel,
|
||||||
// but BViews are less strict on those details
|
// but BViews are less strict on those details
|
||||||
@@ -1010,59 +956,12 @@ Painter::_Transform(const BPoint& point, bool centerOffset) const
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
// _Transform
|
|
||||||
void
|
|
||||||
Painter::_Transform(float* width) const
|
|
||||||
{
|
|
||||||
*width *= fScale;
|
|
||||||
if (*width < 1)
|
|
||||||
*width = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// _Transform
|
|
||||||
float
|
|
||||||
Painter::_Transform(const float& width) const
|
|
||||||
{
|
|
||||||
float w = width * fScale;
|
|
||||||
if (w < 1)
|
|
||||||
w = 1;
|
|
||||||
return w;
|
|
||||||
}
|
|
||||||
|
|
||||||
// _Transform
|
|
||||||
void
|
|
||||||
Painter::_Transform(BRect* rect) const
|
|
||||||
{
|
|
||||||
// TODO integrate this function more
|
|
||||||
rect->right++;
|
|
||||||
rect->bottom++;
|
|
||||||
rect->left += fOrigin.x;
|
|
||||||
rect->top += fOrigin.y;
|
|
||||||
rect->right += fOrigin.x;
|
|
||||||
rect->bottom += fOrigin.y;
|
|
||||||
rect->left *= fScale;
|
|
||||||
rect->top *= fScale;
|
|
||||||
rect->right *= fScale;
|
|
||||||
rect->bottom *= fScale;
|
|
||||||
rect->right--;
|
|
||||||
rect->bottom--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// _Transform
|
|
||||||
BRect
|
|
||||||
Painter::_Transform(const BRect& rect) const
|
|
||||||
{
|
|
||||||
BRect ret = rect;
|
|
||||||
_Transform(&ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// _Clipped
|
// _Clipped
|
||||||
BRect
|
BRect
|
||||||
Painter::_Clipped(const BRect& rect) const
|
Painter::_Clipped(const BRect& rect) const
|
||||||
{
|
{
|
||||||
if (rect.IsValid() && fClippingRegion)
|
if (rect.IsValid() && fClippingRegion)
|
||||||
return rect & _Transform(fClippingRegion->Frame());
|
return rect & fClippingRegion->Frame();
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1132,10 +1031,7 @@ Painter::_UpdateFont()
|
|||||||
void
|
void
|
||||||
Painter::_UpdateLineWidth()
|
Painter::_UpdateLineWidth()
|
||||||
{
|
{
|
||||||
float width = fPenSize;
|
fLineProfile.width(fPenSize);
|
||||||
_Transform(&width);
|
|
||||||
|
|
||||||
fLineProfile.width(width);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
@@ -1173,13 +1069,8 @@ Painter::_DrawEllipse(BPoint center, float xRadius, float yRadius,
|
|||||||
// might even be necessary to treat Fill and Stroke
|
// might even be necessary to treat Fill and Stroke
|
||||||
// differently, as with Fill-/StrokeRect().
|
// differently, as with Fill-/StrokeRect().
|
||||||
_Transform(¢er);
|
_Transform(¢er);
|
||||||
_Transform(&xRadius);
|
|
||||||
_Transform(&yRadius);
|
|
||||||
|
|
||||||
float width = fPenSize;
|
int32 divisions = (int32)max_c(12, ((xRadius + yRadius) * PI) / 2 * (int32)fPenSize);
|
||||||
_Transform(&width);
|
|
||||||
|
|
||||||
int32 divisions = (int32)max_c(12, ((xRadius + yRadius) * PI) / 2 * (int32)width);
|
|
||||||
|
|
||||||
agg::ellipse path(center.x, center.y, xRadius, yRadius, divisions);
|
agg::ellipse path(center.x, center.y, xRadius, yRadius, divisions);
|
||||||
|
|
||||||
@@ -1197,9 +1088,6 @@ Painter::_DrawShape(/*const */BShape* shape, const pattern& p, bool fill) const
|
|||||||
agg::path_storage path;
|
agg::path_storage path;
|
||||||
ShapeConverter converter(&path);
|
ShapeConverter converter(&path);
|
||||||
|
|
||||||
// account for our view coordinate system
|
|
||||||
converter.ScaleBy(B_ORIGIN, fScale, fScale);
|
|
||||||
converter.TranslateBy(fOrigin);
|
|
||||||
// offset locations to center of pixels
|
// offset locations to center of pixels
|
||||||
converter.TranslateBy(BPoint(0.5, 0.5));
|
converter.TranslateBy(BPoint(0.5, 0.5));
|
||||||
|
|
||||||
@@ -1329,14 +1217,10 @@ typedef agg::renderer_scanline_aa<renderer_base, span_gen_type> image_renderer_t
|
|||||||
|
|
||||||
agg::trans_affine srcMatrix;
|
agg::trans_affine srcMatrix;
|
||||||
// srcMatrix *= agg::trans_affine_translation(-actualBitmapRect.left, -actualBitmapRect.top);
|
// srcMatrix *= agg::trans_affine_translation(-actualBitmapRect.left, -actualBitmapRect.top);
|
||||||
srcMatrix *= agg::trans_affine_scaling(fScale, fScale);
|
|
||||||
srcMatrix *= agg::trans_affine_translation(fOrigin.x, fOrigin.y);
|
|
||||||
|
|
||||||
agg::trans_affine imgMatrix;
|
agg::trans_affine imgMatrix;
|
||||||
imgMatrix *= agg::trans_affine_scaling(xScale, yScale);
|
imgMatrix *= agg::trans_affine_scaling(xScale, yScale);
|
||||||
imgMatrix *= agg::trans_affine_translation(xOffset, yOffset);
|
imgMatrix *= agg::trans_affine_translation(xOffset, yOffset);
|
||||||
imgMatrix *= agg::trans_affine_scaling(fScale, fScale);
|
|
||||||
imgMatrix *= agg::trans_affine_translation(fOrigin.x, fOrigin.y);
|
|
||||||
imgMatrix.invert();
|
imgMatrix.invert();
|
||||||
|
|
||||||
span_alloc_type sa;
|
span_alloc_type sa;
|
||||||
@@ -1411,11 +1295,9 @@ Painter::_StrokePath(VertexSource& path, const pattern& p) const
|
|||||||
// _SetPattern(p);
|
// _SetPattern(p);
|
||||||
|
|
||||||
#if ALIASED_DRAWING
|
#if ALIASED_DRAWING
|
||||||
float width = fPenSize;
|
if (fPenSize > 1.0) {
|
||||||
_Transform(&width);
|
|
||||||
if (width > 1.0) {
|
|
||||||
agg::conv_stroke<VertexSource> stroke(path);
|
agg::conv_stroke<VertexSource> stroke(path);
|
||||||
stroke.width(width);
|
stroke.width(fPenSize);
|
||||||
|
|
||||||
fRasterizer->add_path(stroke);
|
fRasterizer->add_path(stroke);
|
||||||
agg::render_scanlines(*fRasterizer, *fScanline, *fRenderer);
|
agg::render_scanlines(*fRasterizer, *fScanline, *fRenderer);
|
||||||
|
|||||||
Reference in New Issue
Block a user