From a744b2c60e3043bce47784a091a16e59aaf5a218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 5 Jul 2006 11:14:08 +0000 Subject: [PATCH] * 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 --- src/apps/icon-o-matic/Jamfile | 4 +- src/apps/icon-o-matic/document/IconObject.cpp | 47 ++++++++++++++ src/apps/icon-o-matic/document/IconObject.h | 36 +++++++++++ .../icon-o-matic/document/IconRenderer.cpp | 6 +- src/apps/icon-o-matic/shape/Shape.cpp | 63 +++++++++---------- src/apps/icon-o-matic/shape/Shape.h | 19 ++---- .../{gradient => style}/Gradient.cpp | 0 .../{gradient => style}/Gradient.h | 0 src/apps/icon-o-matic/style/Style.cpp | 42 +++++++++++-- src/apps/icon-o-matic/style/Style.h | 19 +++++- 10 files changed, 176 insertions(+), 60 deletions(-) create mode 100644 src/apps/icon-o-matic/document/IconObject.cpp create mode 100644 src/apps/icon-o-matic/document/IconObject.h rename src/apps/icon-o-matic/{gradient => style}/Gradient.cpp (100%) rename src/apps/icon-o-matic/{gradient => style}/Gradient.h (100%) diff --git a/src/apps/icon-o-matic/Jamfile b/src/apps/icon-o-matic/Jamfile index c988a45eaf..4dc03bf997 100644 --- a/src/apps/icon-o-matic/Jamfile +++ b/src/apps/icon-o-matic/Jamfile @@ -41,6 +41,7 @@ Application Icon-O-Matic : # document Document.cpp Icon.cpp + IconObject.cpp IconRenderer.cpp # generic/command Command.cpp @@ -110,8 +111,6 @@ Application Icon-O-Matic : ShapeListView.cpp SwatchGroup.cpp TransformerListView.cpp - # gradient - Gradient.cpp # shape PathContainer.cpp PathManipulator.cpp @@ -127,6 +126,7 @@ Application Icon-O-Matic : RemovePointsCommand.cpp RemoveShapesCommand.cpp # style + Gradient.cpp Style.cpp StyleManager.cpp # transformer diff --git a/src/apps/icon-o-matic/document/IconObject.cpp b/src/apps/icon-o-matic/document/IconObject.cpp new file mode 100644 index 0000000000..1b933e986e --- /dev/null +++ b/src/apps/icon-o-matic/document/IconObject.cpp @@ -0,0 +1,47 @@ +/* + * Copyright 2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus + */ + +#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; +} + diff --git a/src/apps/icon-o-matic/document/IconObject.h b/src/apps/icon-o-matic/document/IconObject.h new file mode 100644 index 0000000000..2c7afe991c --- /dev/null +++ b/src/apps/icon-o-matic/document/IconObject.h @@ -0,0 +1,36 @@ +/* + * Copyright 2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus + */ + +#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 diff --git a/src/apps/icon-o-matic/document/IconRenderer.cpp b/src/apps/icon-o-matic/document/IconRenderer.cpp index 82c856915a..fda009238e 100644 --- a/src/apps/icon-o-matic/document/IconRenderer.cpp +++ b/src/apps/icon-o-matic/document/IconRenderer.cpp @@ -99,11 +99,7 @@ StyleHandler::generate_span(agg::rgba8* span, int x, int y, } Gradient* gradient = style->Gradient(); - - // TODO: move filling of color array elsewhere and cache result - // maybe in Style? - agg::rgba8 colors[256]; - gradient->MakeGradient((uint32*)colors, 256); + const agg::rgba8* colors = style->Colors(); agg::trans_affine transformation; // TODO: construct the gradient transformation here diff --git a/src/apps/icon-o-matic/shape/Shape.cpp b/src/apps/icon-o-matic/shape/Shape.cpp index 6d992693f0..e37221da40 100644 --- a/src/apps/icon-o-matic/shape/Shape.cpp +++ b/src/apps/icon-o-matic/shape/Shape.cpp @@ -25,12 +25,12 @@ ShapeListener::~ShapeListener() // constructor Shape::Shape(::Style* style) - : Observable(), - Referenceable(), + : IconObject(), + Observer(), PathContainerListener(), fPaths(new (nothrow) PathContainer(false)), - fStyle(style), + fStyle(NULL), fPathSource(fPaths), fTransformers(4), @@ -42,18 +42,17 @@ Shape::Shape(::Style* style) if (fPaths) fPaths->AddListener(this); - if (fStyle) - fStyle->Acquire(); + SetStyle(style); } // constructor Shape::Shape(const Shape& other) - : Observable(), - Referenceable(), + : IconObject(), + Observer(), PathContainerListener(), fPaths(new (nothrow) PathContainer(false)), - fStyle(other.fStyle), + fStyle(NULL), fPathSource(fPaths), fTransformers(4), @@ -76,8 +75,7 @@ Shape::Shape(const Shape& other) } // TODO: clone vertex transformers - if (fStyle) - fStyle->Acquire(); + SetStyle(other.fStyle); } // destructor @@ -91,10 +89,23 @@ Shape::~Shape() fPaths->RemoveListener(this); delete fPaths; - if (fStyle) - fStyle->Release(); + SetStyle(NULL); } +// #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 void Shape::PathAdded(VectorPath* path) @@ -115,26 +126,6 @@ Shape::PathRemoved(VectorPath* path) // #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 status_t Shape::InitCheck() const @@ -149,13 +140,17 @@ Shape::SetStyle(::Style* style) if (fStyle == style) return; - if (fStyle) + if (fStyle) { + fStyle->RemoveObserver(this); fStyle->Release(); + } fStyle = style; - if (fStyle) + if (fStyle) { fStyle->Acquire(); + fStyle->AddObserver(this); + } Notify(); } diff --git a/src/apps/icon-o-matic/shape/Shape.h b/src/apps/icon-o-matic/shape/Shape.h index fec382d61e..faee727470 100644 --- a/src/apps/icon-o-matic/shape/Shape.h +++ b/src/apps/icon-o-matic/shape/Shape.h @@ -5,12 +5,10 @@ #include #include -#include "Observable.h" +#include "IconObject.h" #include "Observer.h" #include "PathContainer.h" #include "PathSource.h" -#include "Referenceable.h" -#include "Selectable.h" class Style; @@ -25,25 +23,20 @@ class ShapeListener { virtual void TransformerRemoved(Transformer* t) = 0; }; -class Shape : public Observable, - public Observer, // observing all the paths - public Referenceable, - public Selectable, +class Shape : public IconObject, + public Observer, // observing all the paths and the style public PathContainerListener { public: Shape(::Style* style); Shape(const Shape& other); virtual ~Shape(); - // PathContainerListener interface - virtual void PathAdded(VectorPath* path); - virtual void PathRemoved(VectorPath* path); - // Observer interface virtual void ObjectChanged(const Observable* object); - // Selectable interface - virtual void SelectedChanged(); + // PathContainerListener interface + virtual void PathAdded(VectorPath* path); + virtual void PathRemoved(VectorPath* path); // Shape status_t InitCheck() const; diff --git a/src/apps/icon-o-matic/gradient/Gradient.cpp b/src/apps/icon-o-matic/style/Gradient.cpp similarity index 100% rename from src/apps/icon-o-matic/gradient/Gradient.cpp rename to src/apps/icon-o-matic/style/Gradient.cpp diff --git a/src/apps/icon-o-matic/gradient/Gradient.h b/src/apps/icon-o-matic/style/Gradient.h similarity index 100% rename from src/apps/icon-o-matic/gradient/Gradient.h rename to src/apps/icon-o-matic/style/Gradient.h diff --git a/src/apps/icon-o-matic/style/Style.cpp b/src/apps/icon-o-matic/style/Style.cpp index 900d714507..3699e520a4 100644 --- a/src/apps/icon-o-matic/style/Style.cpp +++ b/src/apps/icon-o-matic/style/Style.cpp @@ -12,29 +12,63 @@ // constructor Style::Style() - : Referenceable(), + : IconObject(), + Observer(), + fColor(), - fGradient(NULL) + fGradient(NULL), + fColors(NULL) { } // destructor 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 void Style::SetColor(const rgb_color& color) { + if ((uint32&)fColor == (uint32&)color) + return; + fColor = color; + Notify(); } // SetGradient void Style::SetGradient(::Gradient* gradient) { - delete fGradient; + if (fGradient) { + fGradient->RemoveObserver(this); + delete fGradient; + } + 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; + } } diff --git a/src/apps/icon-o-matic/style/Style.h b/src/apps/icon-o-matic/style/Style.h index f04b1d5e99..a274edebcb 100644 --- a/src/apps/icon-o-matic/style/Style.h +++ b/src/apps/icon-o-matic/style/Style.h @@ -11,15 +11,24 @@ #include -#include "Referenceable.h" +#include + +#include "IconObject.h" +#include "Observer.h" class Gradient; -class Style : public Referenceable { +class Style : public IconObject, + public Observer { public: Style(); virtual ~Style(); + + // Observer interface + virtual void ObjectChanged(const Observable* object); + + // Style void SetColor(const rgb_color& color); inline rgb_color Color() const { return fColor; } @@ -28,9 +37,15 @@ class Style : public Referenceable { ::Gradient* Gradient() const { return fGradient; } + const agg::rgba8* Colors() const + { return fColors; } + private: rgb_color fColor; ::Gradient* fGradient; + + // hold gradient color array + agg::rgba8* fColors; }; #endif // STYLE_H