* small cleanup in VectorPath

* cache the agg converted path in Shape on multiple
  calls to VertexSource (rendering multiple icons after
  a single change)
* added VertexSource::ApproximationScale() which is used
  to retrieve a suitable approximation scale for the
  whole Transformer pipeline
* added a couple more properties to Contour and Stroke


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18070 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2006-07-08 09:29:25 +00:00
parent 9b224ec82e
commit d4d2597fef
17 changed files with 183 additions and 43 deletions
@@ -66,6 +66,10 @@ name_for_id(int32 id)
name = "Scale Y"; name = "Scale Y";
break; break;
case PROPERTY_DETECT_ORIENTATION:
name = "Detect Orient.";
break;
default: default:
name = "<unkown property>"; name = "<unkown property>";
break; break;
@@ -31,6 +31,8 @@ enum {
PROPERTY_ROTATION = 'rotn', PROPERTY_ROTATION = 'rotn',
PROPERTY_SCALE_X = 'sclx', PROPERTY_SCALE_X = 'sclx',
PROPERTY_SCALE_Y = 'scly', PROPERTY_SCALE_Y = 'scly',
PROPERTY_DETECT_ORIENTATION = 'ador',
}; };
+26 -12
View File
@@ -33,6 +33,7 @@ Shape::Shape(::Style* style)
fPathSource(fPaths), fPathSource(fPaths),
fTransformers(4), fTransformers(4),
fNeedsUpdate(true),
fLastBounds(0, 0, -1, -1) fLastBounds(0, 0, -1, -1)
{ {
@@ -53,6 +54,7 @@ Shape::Shape(const Shape& other)
fPathSource(fPaths), fPathSource(fPaths),
fTransformers(4), fTransformers(4),
fNeedsUpdate(true),
fLastBounds(0, 0, -1, -1) fLastBounds(0, 0, -1, -1)
{ {
@@ -99,7 +101,7 @@ Shape::ObjectChanged(const Observable* object)
// simply pass on the event for now // simply pass on the event for now
// (a path, transformer or the style changed, // (a path, transformer or the style changed,
// the shape needs to be re-rendered) // the shape needs to be re-rendered)
Notify(); _NotifyRerender();
} }
// #pragma mark - // #pragma mark -
@@ -110,7 +112,7 @@ Shape::PathAdded(VectorPath* path)
{ {
path->Acquire(); path->Acquire();
path->AddListener(this); path->AddListener(this);
Notify(); _NotifyRerender();
} }
// PathRemoved // PathRemoved
@@ -118,7 +120,7 @@ void
Shape::PathRemoved(VectorPath* path) Shape::PathRemoved(VectorPath* path)
{ {
path->RemoveListener(this); path->RemoveListener(this);
Notify(); _NotifyRerender();
path->Release(); path->Release();
} }
@@ -128,42 +130,42 @@ Shape::PathRemoved(VectorPath* path)
void void
Shape::PointAdded(int32 index) Shape::PointAdded(int32 index)
{ {
Notify(); _NotifyRerender();
} }
// PointRemoved // PointRemoved
void void
Shape::PointRemoved(int32 index) Shape::PointRemoved(int32 index)
{ {
Notify(); _NotifyRerender();
} }
// PointChanged // PointChanged
void void
Shape::PointChanged(int32 index) Shape::PointChanged(int32 index)
{ {
Notify(); _NotifyRerender();
} }
// PathChanged // PathChanged
void void
Shape::PathChanged() Shape::PathChanged()
{ {
Notify(); _NotifyRerender();
} }
// PathClosedChanged // PathClosedChanged
void void
Shape::PathClosedChanged() Shape::PathClosedChanged()
{ {
Notify(); _NotifyRerender();
} }
// PathReversed // PathReversed
void void
Shape::PathReversed() Shape::PathReversed()
{ {
Notify(); _NotifyRerender();
} }
// #pragma mark - // #pragma mark -
@@ -194,7 +196,7 @@ Shape::SetStyle(::Style* style)
fStyle->AddObserver(this); fStyle->AddObserver(this);
} }
Notify(); _NotifyRerender();
} }
// #pragma mark - // #pragma mark -
@@ -238,7 +240,11 @@ Shape::VertexSource()
source = t; source = t;
} }
fPathSource.Update(source->WantsOpenPaths()); if (fNeedsUpdate) {
fPathSource.Update(source->WantsOpenPaths(),
source->ApproximationScale());
fNeedsUpdate = false;
}
return *source; return *source;
} }
@@ -349,7 +355,7 @@ Shape::_NotifyTransformerAdded(Transformer* transformer, int32 index) const
listener->TransformerAdded(transformer, index); listener->TransformerAdded(transformer, index);
} }
// TODO: merge Observable and ShapeListener interface // TODO: merge Observable and ShapeListener interface
Notify(); _NotifyRerender();
} }
// _NotifyTransformerRemoved // _NotifyTransformerRemoved
@@ -364,5 +370,13 @@ Shape::_NotifyTransformerRemoved(Transformer* transformer) const
listener->TransformerRemoved(transformer); listener->TransformerRemoved(transformer);
} }
// TODO: merge Observable and ShapeListener interface // TODO: merge Observable and ShapeListener interface
_NotifyRerender();
}
// _NotifyRerender
void
Shape::_NotifyRerender() const
{
fNeedsUpdate = true;
Notify(); Notify();
} }
+3
View File
@@ -84,11 +84,14 @@ class Shape : public IconObject,
int32 index) const; int32 index) const;
void _NotifyTransformerRemoved(Transformer* t) const; void _NotifyTransformerRemoved(Transformer* t) const;
void _NotifyRerender() const;
PathContainer* fPaths; PathContainer* fPaths;
::Style* fStyle; ::Style* fStyle;
PathSource fPathSource; PathSource fPathSource;
BList fTransformers; BList fTransformers;
mutable bool fNeedsUpdate;
BList fListeners; BList fListeners;
+28 -23
View File
@@ -95,6 +95,7 @@ VectorPath::VectorPath(const VectorPath& from)
IconObject(from), IconObject(from),
fListeners(20), fListeners(20),
fPath(NULL), fPath(NULL),
fClosed(false),
fPointCount(0), fPointCount(0),
fAllocCount(0), fAllocCount(0),
fCachedBounds(0.0, 0.0, -1.0, -1.0) fCachedBounds(0.0, 0.0, -1.0, -1.0)
@@ -113,31 +114,35 @@ VectorPath::VectorPath(const BMessage* archive)
fAllocCount(0), fAllocCount(0),
fCachedBounds(0.0, 0.0, -1.0, -1.0) fCachedBounds(0.0, 0.0, -1.0, -1.0)
{ {
if (archive) { if (!archive)
type_code typeFound; return;
int32 countFound;
if (archive->GetInfo("point", &typeFound, &countFound) >= B_OK type_code typeFound;
&& typeFound == B_POINT_TYPE && _SetPointCount(countFound)) { int32 countFound;
memset(fPath, 0, fAllocCount * sizeof(control_point)); if (archive->GetInfo("point", &typeFound, &countFound) >= B_OK
BPoint point; && typeFound == B_POINT_TYPE
BPoint pointIn; && _SetPointCount(countFound)) {
BPoint pointOut;
bool connected; memset(fPath, 0, fAllocCount * sizeof(control_point));
for (int32 i = 0; i < fPointCount
&& archive->FindPoint("point", i, &point) >= B_OK BPoint point;
&& archive->FindPoint("point in", i, &pointIn) >= B_OK BPoint pointIn;
&& archive->FindPoint("point out", i, &pointOut) >= B_OK BPoint pointOut;
&& archive->FindBool("connected", i, &connected) >= B_OK; i++) { bool connected;
fPath[i].point = point; for (int32 i = 0; i < fPointCount
fPath[i].point_in = pointIn; && archive->FindPoint("point", i, &point) >= B_OK
fPath[i].point_out = pointOut; && archive->FindPoint("point in", i, &pointIn) >= B_OK
fPath[i].connected = connected; && archive->FindPoint("point out", i, &pointOut) >= B_OK
} && archive->FindBool("connected", i, &connected) >= B_OK; i++) {
} fPath[i].point = point;
if (archive->FindBool("path closed", &fClosed) < B_OK) { fPath[i].point_in = pointIn;
fClosed = false; fPath[i].point_out = pointOut;
fPath[i].connected = connected;
} }
} }
if (archive->FindBool("path closed", &fClosed) < B_OK)
fClosed = false;
} }
// destructor // destructor
@@ -46,6 +46,13 @@ AffineTransformer::SetSource(VertexSource& source)
Affine::attach(source); Affine::attach(source);
} }
// ApproximationScale
double
AffineTransformer::ApproximationScale() const
{
return fSource.ApproximationScale() * scale();
}
// #pragma mark - // #pragma mark -
// MakePropertyObject // MakePropertyObject
@@ -30,6 +30,8 @@ class AffineTransformer : public Transformer,
virtual void SetSource(VertexSource& source); virtual void SetSource(VertexSource& source);
virtual double ApproximationScale() const;
// IconObject interface // IconObject interface
virtual PropertyObject* MakePropertyObject() const; virtual PropertyObject* MakePropertyObject() const;
virtual bool SetToPropertyObject( virtual bool SetToPropertyObject(
@@ -9,6 +9,7 @@
#include "ContourTransformer.h" #include "ContourTransformer.h"
#include "CommonPropertyIDs.h" #include "CommonPropertyIDs.h"
#include "OptionProperty.h"
#include "Property.h" #include "Property.h"
#include "PropertyObject.h" #include "PropertyObject.h"
@@ -17,6 +18,7 @@ ContourTransformer::ContourTransformer(VertexSource& source)
: Transformer(source, "Contour"), : Transformer(source, "Contour"),
Contour(source) Contour(source)
{ {
auto_detect_orientation(true);
} }
// destructor // destructor
@@ -46,6 +48,13 @@ ContourTransformer::SetSource(VertexSource& source)
Contour::attach(source); Contour::attach(source);
} }
// ApproximationScale
double
ContourTransformer::ApproximationScale() const
{
return fSource.ApproximationScale() * width();
}
// #pragma mark - // #pragma mark -
// MakePropertyObject // MakePropertyObject
@@ -59,6 +68,23 @@ ContourTransformer::MakePropertyObject() const
// width // width
object->AddProperty(new FloatProperty(PROPERTY_WIDTH, width())); object->AddProperty(new FloatProperty(PROPERTY_WIDTH, width()));
// auto detect orientation
object->AddProperty(new BoolProperty(PROPERTY_DETECT_ORIENTATION,
auto_detect_orientation()));
// join mode
OptionProperty* property = new OptionProperty(PROPERTY_JOIN_MODE);
property->AddOption(agg::miter_join, "Miter");
property->AddOption(agg::round_join, "Round");
property->AddOption(agg::bevel_join, "Bevel");
property->SetCurrentOptionID(line_join());
object->AddProperty(property);
// miter limit
object->AddProperty(new FloatProperty(PROPERTY_MITER_LIMIT,
miter_limit()));
return object; return object;
} }
@@ -76,6 +102,29 @@ ContourTransformer::SetToPropertyObject(const PropertyObject* object)
Notify(); Notify();
} }
// auto detect orientation
bool ado = object->Value(PROPERTY_DETECT_ORIENTATION,
auto_detect_orientation());
if (ado != auto_detect_orientation()) {
auto_detect_orientation(ado);
Notify();
}
// join mode
OptionProperty* property = dynamic_cast<OptionProperty*>(
object->FindProperty(PROPERTY_JOIN_MODE));
if (property && line_join() != property->CurrentOptionID()) {
line_join((agg::line_join_e)property->CurrentOptionID());
Notify();
}
// miter limit
float l = object->Value(PROPERTY_MITER_LIMIT, (float)miter_limit());
if (l != miter_limit()) {
miter_limit(l);
Notify();
}
return HasPendingNotifications(); return HasPendingNotifications();
} }
@@ -27,6 +27,8 @@ class ContourTransformer : public Transformer,
virtual void SetSource(VertexSource& source); virtual void SetSource(VertexSource& source);
virtual double ApproximationScale() const;
// IconObject interface // IconObject interface
virtual PropertyObject* MakePropertyObject() const; virtual PropertyObject* MakePropertyObject() const;
virtual bool SetToPropertyObject( virtual bool SetToPropertyObject(
@@ -39,9 +39,25 @@ PathSource::vertex(double* x, double* y)
return fAGGCurvedPath.vertex(x, y); return fAGGCurvedPath.vertex(x, y);
} }
// WantsOpenPaths
bool
PathSource::WantsOpenPaths() const
{
return false;
}
// ApproximationScale
double
PathSource::ApproximationScale() const
{
return 1.0;
}
// #pragma mark -
// Update // Update
void void
PathSource::Update(bool leavePathsOpen) PathSource::Update(bool leavePathsOpen, double approximationScale)
{ {
fAGGPath.remove_all(); fAGGPath.remove_all();
@@ -51,11 +67,7 @@ PathSource::Update(bool leavePathsOpen)
if (!leavePathsOpen) if (!leavePathsOpen)
fAGGPath.close_polygon(); fAGGPath.close_polygon();
} }
fAGGCurvedPath.approximation_scale(approximationScale);
} }
// WantsOpenPaths
bool
PathSource::WantsOpenPaths() const
{
return false;
}
@@ -29,9 +29,11 @@ class PathSource : public VertexSource {
virtual unsigned vertex(double* x, double* y); virtual unsigned vertex(double* x, double* y);
virtual bool WantsOpenPaths() const; virtual bool WantsOpenPaths() const;
virtual double ApproximationScale() const;
// PathSource // PathSource
void Update(bool leavePathsOpen); void Update(bool leavePathsOpen,
double approximationScale);
private: private:
PathContainer* fPaths; PathContainer* fPaths;
@@ -42,6 +42,14 @@ PerspectiveTransformer::SetSource(VertexSource& source)
Perspective::attach(source); Perspective::attach(source);
} }
// ApproximationScale
double
PerspectiveTransformer::ApproximationScale() const
{
// TODO: upgrade AGG
return fSource.ApproximationScale();// * scale();
}
@@ -29,6 +29,8 @@ class PerspectiveTransformer : public Transformer,
virtual unsigned vertex(double* x, double* y); virtual unsigned vertex(double* x, double* y);
virtual void SetSource(VertexSource& source); virtual void SetSource(VertexSource& source);
virtual double ApproximationScale() const;
}; };
#endif // PERSPECTIVE_TRANSFORMER_H #endif // PERSPECTIVE_TRANSFORMER_H
@@ -54,6 +54,13 @@ StrokeTransformer::WantsOpenPaths() const
return true; return true;
} }
// ApproximationScale
double
StrokeTransformer::ApproximationScale() const
{
return fSource.ApproximationScale() * width();
}
// #pragma mark - // #pragma mark -
// MakePropertyObject // MakePropertyObject
@@ -85,6 +92,10 @@ StrokeTransformer::MakePropertyObject() const
object->AddProperty(property); object->AddProperty(property);
// miter limit
object->AddProperty(new FloatProperty(PROPERTY_MITER_LIMIT,
miter_limit()));
return object; return object;
} }
@@ -117,6 +128,12 @@ StrokeTransformer::SetToPropertyObject(const PropertyObject* object)
Notify(); Notify();
} }
// miter limit
float l = object->Value(PROPERTY_MITER_LIMIT, (float)miter_limit());
if (l != miter_limit()) {
miter_limit(l);
Notify();
}
return HasPendingNotifications(); return HasPendingNotifications();
} }
@@ -26,7 +26,9 @@ class StrokeTransformer : public Transformer,
virtual unsigned vertex(double* x, double* y); virtual unsigned vertex(double* x, double* y);
virtual void SetSource(VertexSource& source); virtual void SetSource(VertexSource& source);
virtual bool WantsOpenPaths() const; virtual bool WantsOpenPaths() const;
virtual double ApproximationScale() const;
// IconObject interface // IconObject interface
virtual PropertyObject* MakePropertyObject() const; virtual PropertyObject* MakePropertyObject() const;
@@ -60,3 +60,10 @@ Transformer::WantsOpenPaths() const
return fSource.WantsOpenPaths(); return fSource.WantsOpenPaths();
} }
// ApproximationScale
double
Transformer::ApproximationScale() const
{
return fSource.ApproximationScale();
}
@@ -20,6 +20,7 @@ class VertexSource {
virtual unsigned vertex(double* x, double* y) = 0; virtual unsigned vertex(double* x, double* y) = 0;
virtual bool WantsOpenPaths() const = 0; virtual bool WantsOpenPaths() const = 0;
virtual double ApproximationScale() const = 0;
}; };
@@ -36,6 +37,7 @@ class Transformer : public VertexSource,
virtual void SetSource(VertexSource& source); virtual void SetSource(VertexSource& source);
virtual bool WantsOpenPaths() const; virtual bool WantsOpenPaths() const;
virtual double ApproximationScale() const;
protected: protected:
VertexSource& fSource; VertexSource& fSource;