* 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:
parent
64d80db621
commit
a744b2c60e
@ -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
|
||||
|
47
src/apps/icon-o-matic/document/IconObject.cpp
Normal file
47
src/apps/icon-o-matic/document/IconObject.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
*/
|
||||
|
||||
#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;
|
||||
}
|
||||
|
36
src/apps/icon-o-matic/document/IconObject.h
Normal file
36
src/apps/icon-o-matic/document/IconObject.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
*/
|
||||
|
||||
#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();
|
||||
|
||||
// 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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -5,12 +5,10 @@
|
||||
#include <Rect.h>
|
||||
#include <String.h>
|
||||
|
||||
#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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -11,15 +11,24 @@
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
|
||||
#include "Referenceable.h"
|
||||
#include <agg_color_rgba.h>
|
||||
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user