Bug fixes:

* origin is given in "outer" coordinate system therefore if there is a
 previous state it has to be transformed. Please review if this is
 required in OffsetOrigin() too.
* in Transform() we have to scale relative to the view origin not (0 /
  0).

- optimized SetScale: saved one division


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21993 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2007-08-17 07:04:46 +00:00
parent 3f64fbd011
commit 1623ec9289
+26 -11
View File
@@ -7,6 +7,7 @@
* Adi Oanca <[email protected]> * Adi Oanca <[email protected]>
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
* Axel Dörfler, [email protected] * Axel Dörfler, [email protected]
* Michael Pfeiffer <[email protected]>
*/ */
/** Data classes for working with BView states and draw parameters */ /** Data classes for working with BView states and draw parameters */
@@ -281,14 +282,27 @@ DrawState::WriteToLink(BPrivate::LinkSender& link) const
void void
DrawState::SetOrigin(const BPoint& origin) DrawState::SetOrigin(const BPoint& origin)
{ {
fOrigin = fPreviousState ? fPreviousState->fOrigin + origin : origin; fOrigin = origin;
// origin is given as a point in the
// "outer" coordinate system, therefore
// it has to be transformed
if (PreviousState() != NULL)
PreviousState()->Transform(&fOrigin);
} }
void void
DrawState::OffsetOrigin(const BPoint& offset) DrawState::OffsetOrigin(const BPoint& offset)
{ {
if (PreviousState() == NULL)
fOrigin += offset; fOrigin += offset;
else {
// TODO this is necessary only if offset
// is in the "outer" coordinate system
float scale = PreviousState()->Scale();
fOrigin.x += offset.x * scale;
fOrigin.y += offset.y * scale;
}
} }
@@ -296,14 +310,12 @@ void
DrawState::SetScale(float scale) DrawState::SetScale(float scale)
{ {
// the scale is multiplied with the scale of the previous state if any // the scale is multiplied with the scale of the previous state if any
float localScale = fScale; float localScale = scale;
if (PreviousState() != NULL) if (PreviousState() != NULL)
localScale /= PreviousState()->Scale(); localScale *= PreviousState()->Scale();
if (localScale != scale) { if (fScale != localScale) {
fScale = scale; fScale = localScale;
if (PreviousState() != NULL)
fScale *= PreviousState()->Scale();
// update font size // update font size
// (pen size is currently calulated on the fly) // (pen size is currently calulated on the fly)
@@ -315,10 +327,13 @@ DrawState::SetScale(float scale)
void void
DrawState::Transform(float* x, float* y) const DrawState::Transform(float* x, float* y) const
{ {
*x += fOrigin.x; // scale relative to origin, therefore
*y += fOrigin.y; // scale first then translate to
// origin
*x *= fScale; *x *= fScale;
*y *= fScale; *y *= fScale;
*x += fOrigin.x;
*y += fOrigin.y;
} }
// InverseTransform // InverseTransform
@@ -326,10 +341,10 @@ void
DrawState::InverseTransform(float* x, float* y) const DrawState::InverseTransform(float* x, float* y) const
{ {
// TODO: watch out for fScale = 0? // TODO: watch out for fScale = 0?
*x /= fScale;
*y /= fScale;
*x -= fOrigin.x; *x -= fOrigin.x;
*y -= fOrigin.y; *y -= fOrigin.y;
*x /= fScale;
*y /= fScale;
} }
// Transform // Transform