* Style is now responsible for generating and caching

the gradient color array, it observs the gradient for
  this purpose
* introduced IconObject class that combines Observable,
  Referenceable and Selectable interfaces and adds an
  interface for retrieving a PropertyObject that represents
  the object in question
* Shape and Style inherit from IconObject now


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18037 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2006-07-05 11:14:08 +00:00
parent 64d80db621
commit a744b2c60e
10 changed files with 176 additions and 60 deletions
+2 -2
View File
@@ -41,6 +41,7 @@ Application Icon-O-Matic :
# document # document
Document.cpp Document.cpp
Icon.cpp Icon.cpp
IconObject.cpp
IconRenderer.cpp IconRenderer.cpp
# generic/command # generic/command
Command.cpp Command.cpp
@@ -110,8 +111,6 @@ Application Icon-O-Matic :
ShapeListView.cpp ShapeListView.cpp
SwatchGroup.cpp SwatchGroup.cpp
TransformerListView.cpp TransformerListView.cpp
# gradient
Gradient.cpp
# shape # shape
PathContainer.cpp PathContainer.cpp
PathManipulator.cpp PathManipulator.cpp
@@ -127,6 +126,7 @@ Application Icon-O-Matic :
RemovePointsCommand.cpp RemovePointsCommand.cpp
RemoveShapesCommand.cpp RemoveShapesCommand.cpp
# style # style
Gradient.cpp
Style.cpp Style.cpp
StyleManager.cpp StyleManager.cpp
# transformer # transformer
@@ -0,0 +1,47 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/
#include "IconObject.h"
// constructor
IconObject::IconObject()
: Observable(),
Referenceable(),
Selectable()
{
}
// destructor
IconObject::~IconObject()
{
}
// SelectedChanged
void
IconObject::SelectedChanged()
{
// simply pass on the event for now
Notify();
}
// #pragma mark -
// MakePropertyObject
PropertyObject*
IconObject::MakePropertyObject() const
{
return NULL;
}
// SetToPropertyObject
bool
IconObject::SetToPropertyObject(const PropertyObject* object)
{
return false;
}
@@ -0,0 +1,36 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/
#ifndef ICON_OBJECT_H
#define ICON_OBJECT_H
#include "Observable.h"
#include "Referenceable.h"
#include "Selectable.h"
class PropertyObject;
class IconObject : public Observable,
public Referenceable,
public Selectable {
public:
IconObject();
virtual ~IconObject();
// Selectable interface
virtual void SelectedChanged();
// IconObject
virtual PropertyObject* MakePropertyObject() const;
virtual bool SetToPropertyObject(
const PropertyObject* object);
private:
};
#endif // ICON_OBJECT_H
@@ -99,11 +99,7 @@ StyleHandler::generate_span(agg::rgba8* span, int x, int y,
} }
Gradient* gradient = style->Gradient(); Gradient* gradient = style->Gradient();
const agg::rgba8* colors = style->Colors();
// TODO: move filling of color array elsewhere and cache result
// maybe in Style?
agg::rgba8 colors[256];
gradient->MakeGradient((uint32*)colors, 256);
agg::trans_affine transformation; agg::trans_affine transformation;
// TODO: construct the gradient transformation here // TODO: construct the gradient transformation here
+29 -34
View File
@@ -25,12 +25,12 @@ ShapeListener::~ShapeListener()
// constructor // constructor
Shape::Shape(::Style* style) Shape::Shape(::Style* style)
: Observable(), : IconObject(),
Referenceable(), Observer(),
PathContainerListener(), PathContainerListener(),
fPaths(new (nothrow) PathContainer(false)), fPaths(new (nothrow) PathContainer(false)),
fStyle(style), fStyle(NULL),
fPathSource(fPaths), fPathSource(fPaths),
fTransformers(4), fTransformers(4),
@@ -42,18 +42,17 @@ Shape::Shape(::Style* style)
if (fPaths) if (fPaths)
fPaths->AddListener(this); fPaths->AddListener(this);
if (fStyle) SetStyle(style);
fStyle->Acquire();
} }
// constructor // constructor
Shape::Shape(const Shape& other) Shape::Shape(const Shape& other)
: Observable(), : IconObject(),
Referenceable(), Observer(),
PathContainerListener(), PathContainerListener(),
fPaths(new (nothrow) PathContainer(false)), fPaths(new (nothrow) PathContainer(false)),
fStyle(other.fStyle), fStyle(NULL),
fPathSource(fPaths), fPathSource(fPaths),
fTransformers(4), fTransformers(4),
@@ -76,8 +75,7 @@ Shape::Shape(const Shape& other)
} }
// TODO: clone vertex transformers // TODO: clone vertex transformers
if (fStyle) SetStyle(other.fStyle);
fStyle->Acquire();
} }
// destructor // destructor
@@ -91,10 +89,23 @@ Shape::~Shape()
fPaths->RemoveListener(this); fPaths->RemoveListener(this);
delete fPaths; delete fPaths;
if (fStyle) SetStyle(NULL);
fStyle->Release();
} }
// #pragma mark -
// ObjectChanged
void
Shape::ObjectChanged(const Observable* object)
{
// simply pass on the event for now
// (a path or the style changed,
// the shape needs to be re-rendered)
Notify();
}
// #pragma mark -
// PathAdded // PathAdded
void void
Shape::PathAdded(VectorPath* path) Shape::PathAdded(VectorPath* path)
@@ -115,26 +126,6 @@ Shape::PathRemoved(VectorPath* path)
// #pragma mark - // #pragma mark -
// ObjectChanged
void
Shape::ObjectChanged(const Observable* object)
{
// simply pass on the event for now
Notify();
}
// #pragma mark -
// SelectedChanged
void
Shape::SelectedChanged()
{
// simply pass on the event for now
Notify();
}
// #pragma mark -
// InitCheck // InitCheck
status_t status_t
Shape::InitCheck() const Shape::InitCheck() const
@@ -149,13 +140,17 @@ Shape::SetStyle(::Style* style)
if (fStyle == style) if (fStyle == style)
return; return;
if (fStyle) if (fStyle) {
fStyle->RemoveObserver(this);
fStyle->Release(); fStyle->Release();
}
fStyle = style; fStyle = style;
if (fStyle) if (fStyle) {
fStyle->Acquire(); fStyle->Acquire();
fStyle->AddObserver(this);
}
Notify(); Notify();
} }
+6 -13
View File
@@ -5,12 +5,10 @@
#include <Rect.h> #include <Rect.h>
#include <String.h> #include <String.h>
#include "Observable.h" #include "IconObject.h"
#include "Observer.h" #include "Observer.h"
#include "PathContainer.h" #include "PathContainer.h"
#include "PathSource.h" #include "PathSource.h"
#include "Referenceable.h"
#include "Selectable.h"
class Style; class Style;
@@ -25,25 +23,20 @@ class ShapeListener {
virtual void TransformerRemoved(Transformer* t) = 0; virtual void TransformerRemoved(Transformer* t) = 0;
}; };
class Shape : public Observable, class Shape : public IconObject,
public Observer, // observing all the paths public Observer, // observing all the paths and the style
public Referenceable,
public Selectable,
public PathContainerListener { public PathContainerListener {
public: public:
Shape(::Style* style); Shape(::Style* style);
Shape(const Shape& other); Shape(const Shape& other);
virtual ~Shape(); virtual ~Shape();
// PathContainerListener interface
virtual void PathAdded(VectorPath* path);
virtual void PathRemoved(VectorPath* path);
// Observer interface // Observer interface
virtual void ObjectChanged(const Observable* object); virtual void ObjectChanged(const Observable* object);
// Selectable interface // PathContainerListener interface
virtual void SelectedChanged(); virtual void PathAdded(VectorPath* path);
virtual void PathRemoved(VectorPath* path);
// Shape // Shape
status_t InitCheck() const; status_t InitCheck() const;
+38 -4
View File
@@ -12,29 +12,63 @@
// constructor // constructor
Style::Style() Style::Style()
: Referenceable(), : IconObject(),
Observer(),
fColor(), fColor(),
fGradient(NULL) fGradient(NULL),
fColors(NULL)
{ {
} }
// destructor // destructor
Style::~Style() Style::~Style()
{ {
delete fGradient; SetGradient(NULL);
} }
// ObjectChanged
void
Style::ObjectChanged(const Observable* object)
{
if (object == fGradient && fColors) {
fGradient->MakeGradient((uint32*)fColors, 256);
Notify();
}
}
// #pragma mark -
// SetColor // SetColor
void void
Style::SetColor(const rgb_color& color) Style::SetColor(const rgb_color& color)
{ {
if ((uint32&)fColor == (uint32&)color)
return;
fColor = color; fColor = color;
Notify();
} }
// SetGradient // SetGradient
void void
Style::SetGradient(::Gradient* gradient) Style::SetGradient(::Gradient* gradient)
{ {
delete fGradient; if (fGradient) {
fGradient->RemoveObserver(this);
delete fGradient;
}
fGradient = gradient; fGradient = gradient;
if (fGradient) {
fGradient->AddObserver(this);
// generate gradient
if (!fColors)
fColors = new agg::rgba8[256];
fGradient->MakeGradient((uint32*)fColors, 256);
} else {
delete[] fColors;
fColors = NULL;
}
} }
+17 -2
View File
@@ -11,15 +11,24 @@
#include <GraphicsDefs.h> #include <GraphicsDefs.h>
#include "Referenceable.h" #include <agg_color_rgba.h>
#include "IconObject.h"
#include "Observer.h"
class Gradient; class Gradient;
class Style : public Referenceable { class Style : public IconObject,
public Observer {
public: public:
Style(); Style();
virtual ~Style(); virtual ~Style();
// Observer interface
virtual void ObjectChanged(const Observable* object);
// Style
void SetColor(const rgb_color& color); void SetColor(const rgb_color& color);
inline rgb_color Color() const inline rgb_color Color() const
{ return fColor; } { return fColor; }
@@ -28,9 +37,15 @@ class Style : public Referenceable {
::Gradient* Gradient() const ::Gradient* Gradient() const
{ return fGradient; } { return fGradient; }
const agg::rgba8* Colors() const
{ return fColors; }
private: private:
rgb_color fColor; rgb_color fColor;
::Gradient* fGradient; ::Gradient* fGradient;
// hold gradient color array
agg::rgba8* fColors;
}; };
#endif // STYLE_H #endif // STYLE_H