many improvements and bug fixes:

* added VertexSource::SetLast() used by PathSource
  to call agg::path_storage::close_polygon(). The
  StrokeTransformer avoids this of course. Affine
  and PerspectiveTransformer forward this to their source.
* TransformerItems watch their transformers for notifications
* made VectorPath an IconObject
* VectorPath no longer uses close_polygon() when converting
  to agg::path_storage to allow open strokes
* added IconObjectListView which inherits from
  PropertyListView and allows to edit the properties of the
  last selected object from one of the other list views
* fixed a couple bugs when adopting properties:
  - removed the Property* in the PropertyEditorView base
  class, and made GetProperty() virtual, as the base class
  pointer was not maintained and superfluous
  - delete the old PropertyObject in PropertyListView::SetTo
  when adopting the properties instead of the object whose
  properties were adopted...
* added SetPropertiesCommand to allow Undo/Redo on changes
  of properties
* Style is also an IconObject now (TODO: yet another list view
  for styles... :-)
* Style watches its Gradient for notifications and builds and
  caches the color array now
* removed generating the color array for each scanline in
  IconRenderer, so the performance is improved a lot
* Shape watches its Transformers for notifications in order
  to trigger rerendering
* StrokeTransformers adds a bunch of properties like stroke
  width, cap and join mode
* StateView keyboard filter no longer steals keydown events
  from BTextViews
* PropertyItemViews resize with the parent
* refined the interface for PropertyListView for easier
  tracking of the changed properties in derived classes
* added HasPendingNotifications() to Observable, so that
  IconObjects can track changes more easily when adopting
  a PropertyObject
* the name is now part of any IconObject


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18045 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2006-07-05 23:51:34 +00:00
parent b92418a82c
commit e2a31283dd
55 changed files with 787 additions and 229 deletions
+2
View File
@@ -43,6 +43,7 @@ Application Icon-O-Matic :
Icon.cpp Icon.cpp
IconObject.cpp IconObject.cpp
IconRenderer.cpp IconRenderer.cpp
SetPropertiesCommand.cpp
# generic/command # generic/command
Command.cpp Command.cpp
CommandStack.cpp CommandStack.cpp
@@ -107,6 +108,7 @@ Application Icon-O-Matic :
support.cpp support.cpp
support_ui.cpp support_ui.cpp
# gui # gui
IconObjectListView.cpp
PathListView.cpp PathListView.cpp
ShapeListView.cpp ShapeListView.cpp
SwatchGroup.cpp SwatchGroup.cpp
+22 -3
View File
@@ -19,9 +19,11 @@
#include "Document.h" #include "Document.h"
#include "CanvasView.h" #include "CanvasView.h"
#include "CommandStack.h" #include "CommandStack.h"
#include "IconObjectListView.h"
#include "IconEditorApp.h" #include "IconEditorApp.h"
#include "IconView.h" #include "IconView.h"
#include "PathListView.h" #include "PathListView.h"
#include "ScrollView.h"
#include "ShapeListView.h" #include "ShapeListView.h"
#include "SwatchGroup.h" #include "SwatchGroup.h"
#include "TransformerFactory.h" #include "TransformerFactory.h"
@@ -54,7 +56,7 @@ enum {
// constructor // constructor
MainWindow::MainWindow(IconEditorApp* app, Document* document) MainWindow::MainWindow(IconEditorApp* app, Document* document)
: BWindow(BRect(50, 50, 781, 781), "Icon-O-Matic", : BWindow(BRect(50, 50, 891, 781), "Icon-O-Matic",
B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS), B_ASYNCHRONOUS_CONTROLS),
fApp(app), fApp(app),
@@ -205,6 +207,11 @@ MainWindow::_Init()
fShapeListView->SetCommandStack(fDocument->CommandStack()); fShapeListView->SetCommandStack(fDocument->CommandStack());
fShapeListView->SetSelection(fDocument->Selection()); fShapeListView->SetSelection(fDocument->Selection());
fTransformerListView->SetSelection(fDocument->Selection());
fPropertyListView->SetCommandStack(fDocument->CommandStack());
fPropertyListView->SetSelection(fDocument->Selection());
fIconPreview16->SetIcon(fDocument->Icon()); fIconPreview16->SetIcon(fDocument->Icon());
fIconPreview32->SetIcon(fDocument->Icon()); fIconPreview32->SetIcon(fDocument->Icon());
// fIconPreview48->SetIcon(fDocument->Icon()); // fIconPreview48->SetIcon(fDocument->Icon());
@@ -332,6 +339,9 @@ MainWindow::_CreateGUI(BRect bounds)
fTransformerListView = new TransformerListView(bounds, fTransformerListView = new TransformerListView(bounds,
"transformer list view"); "transformer list view");
// property list view
fPropertyListView = new IconObjectListView();
bg->AddChild(fSwatchGroup); bg->AddChild(fSwatchGroup);
bg->AddChild(fIconPreview16); bg->AddChild(fIconPreview16);
@@ -346,15 +356,24 @@ MainWindow::_CreateGUI(BRect bounds)
B_NO_BORDER)); B_NO_BORDER));
bg->AddChild(new BScrollView("shape list scroll view", bg->AddChild(new BScrollView("shape list scroll view",
fShapeListView, fShapeListView,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_FOLLOW_LEFT | B_FOLLOW_TOP,
0, false, true, 0, false, true,
B_NO_BORDER)); B_NO_BORDER));
bg->AddChild(new BScrollView("transformer list scroll view", bg->AddChild(new BScrollView("transformer list scroll view",
fTransformerListView, fTransformerListView,
B_FOLLOW_RIGHT | B_FOLLOW_TOP, B_FOLLOW_LEFT | B_FOLLOW_TOP,
0, false, true, 0, false, true,
B_NO_BORDER)); B_NO_BORDER));
// scroll view around property list view
bounds.OffsetBy(bounds.Width() + 6 + B_V_SCROLL_BAR_WIDTH, 0);
bg->AddChild(new ScrollView(fPropertyListView,
SCROLL_VERTICAL | SCROLL_NO_FRAME,
bounds, "property scroll view",
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
B_WILL_DRAW | B_FRAME_EVENTS));
bg->AddChild(fCanvasView); bg->AddChild(fCanvasView);
return bg; return bg;
+2
View File
@@ -17,6 +17,7 @@ class BMenuBar;
class BMenuItem; class BMenuItem;
class CanvasView; class CanvasView;
class Document; class Document;
class IconObjectListView;
class IconEditorApp; class IconEditorApp;
class IconView; class IconView;
class PathListView; class PathListView;
@@ -62,6 +63,7 @@ class MainWindow : public BWindow,
PathListView* fPathListView; PathListView* fPathListView;
ShapeListView* fShapeListView; ShapeListView* fShapeListView;
TransformerListView* fTransformerListView; TransformerListView* fTransformerListView;
IconObjectListView* fPropertyListView;
// TODO: for testing only... // TODO: for testing only...
MultipleManipulatorState* fState; MultipleManipulatorState* fState;
+41 -5
View File
@@ -8,11 +8,27 @@
#include "IconObject.h" #include "IconObject.h"
#include "CommonPropertyIDs.h"
#include "Property.h"
#include "PropertyObject.h"
// constructor // constructor
IconObject::IconObject() IconObject::IconObject(const char* name)
: Observable(), : Observable(),
Referenceable(), Referenceable(),
Selectable() Selectable(),
fName(name)
{
}
// copy constructor
IconObject::IconObject(const IconObject& other)
: Observable(),
Referenceable(),
Selectable(),
fName(other.fName)
{ {
} }
@@ -26,7 +42,7 @@ void
IconObject::SelectedChanged() IconObject::SelectedChanged()
{ {
// simply pass on the event for now // simply pass on the event for now
Notify(); // Notify();
} }
// #pragma mark - // #pragma mark -
@@ -35,13 +51,33 @@ IconObject::SelectedChanged()
PropertyObject* PropertyObject*
IconObject::MakePropertyObject() const IconObject::MakePropertyObject() const
{ {
return NULL; PropertyObject* object = new PropertyObject();
object->AddProperty(new StringProperty(PROPERTY_NAME, fName.String()));
return object;
} }
// SetToPropertyObject // SetToPropertyObject
bool bool
IconObject::SetToPropertyObject(const PropertyObject* object) IconObject::SetToPropertyObject(const PropertyObject* object)
{ {
return false; AutoNotificationSuspender _(this);
BString name;
if (object->GetValue(PROPERTY_NAME, name))
SetName(name.String());
return HasPendingNotifications();
} }
// SetName
void
IconObject::SetName(const char* name)
{
if (fName == name)
return;
fName = name;
Notify();
}
+9 -1
View File
@@ -9,6 +9,8 @@
#ifndef ICON_OBJECT_H #ifndef ICON_OBJECT_H
#define ICON_OBJECT_H #define ICON_OBJECT_H
#include <String.h>
#include "Observable.h" #include "Observable.h"
#include "Referenceable.h" #include "Referenceable.h"
#include "Selectable.h" #include "Selectable.h"
@@ -19,7 +21,8 @@ class IconObject : public Observable,
public Referenceable, public Referenceable,
public Selectable { public Selectable {
public: public:
IconObject(); IconObject(const char* name);
IconObject(const IconObject& other);
virtual ~IconObject(); virtual ~IconObject();
// Selectable interface // Selectable interface
@@ -30,7 +33,12 @@ class IconObject : public Observable,
virtual bool SetToPropertyObject( virtual bool SetToPropertyObject(
const PropertyObject* object); const PropertyObject* object);
void SetName(const char* name);
const char* Name() const
{ return fName.String(); }
private: private:
BString fName;
}; };
#endif // ICON_OBJECT_H #endif // ICON_OBJECT_H
@@ -0,0 +1,89 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/
#include "SetPropertiesCommand.h"
#include <stdio.h>
#include "CommonPropertyIDs.h"
#include "IconObject.h"
#include "Property.h"
#include "PropertyObject.h"
// constructor
SetPropertiesCommand::SetPropertiesCommand(IconObject** objects,
int32 objectCount,
PropertyObject* previous,
PropertyObject* current)
: Command(),
fObjects(objects),
fObjectCount(objectCount),
fOldProperties(previous),
fNewProperties(current)
{
}
// destructor
SetPropertiesCommand::~SetPropertiesCommand()
{
delete[] fObjects;
delete fOldProperties;
delete fNewProperties;
}
// InitCheck
status_t
SetPropertiesCommand::InitCheck()
{
return fObjects && fOldProperties && fNewProperties
&& fObjectCount > 0 && fOldProperties->CountProperties() > 0
&& fOldProperties->ContainsSameProperties(*fNewProperties) ?
B_OK : B_NO_INIT;
}
// Perform
status_t
SetPropertiesCommand::Perform()
{
for (int32 i = 0; i < fObjectCount; i++) {
if (fObjects[i])
fObjects[i]->SetToPropertyObject(fNewProperties);
}
return B_OK;
}
// Undo
status_t
SetPropertiesCommand::Undo()
{
for (int32 i = 0; i < fObjectCount; i++) {
if (fObjects[i])
fObjects[i]->SetToPropertyObject(fOldProperties);
}
return B_OK;
}
// GetName
void
SetPropertiesCommand::GetName(BString& name)
{
if (fOldProperties->CountProperties() > 1) {
if (fObjectCount > 1)
name << "Multi Paste Properties";
else
name << "Paste Properties";
} else {
BString property = name_for_id(
fOldProperties->PropertyAt(0)->Identifier());
if (fObjectCount > 1)
name << "Multi Set " << property;
else
name << "Set " << property;
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <[email protected]>
*/
#ifndef SET_PROPERTIES_COMMAND_H
#define SET_PROPERTIES_COMMAND_H
#include "Command.h"
class IconObject;
class PropertyObject;
class SetPropertiesCommand : public Command {
public:
SetPropertiesCommand(IconObject** objects,
int32 objectCount,
PropertyObject* previous,
PropertyObject* current);
virtual ~SetPropertiesCommand();
virtual status_t InitCheck();
virtual status_t Perform();
virtual status_t Undo();
virtual void GetName(BString& name);
private:
IconObject** fObjects;
int32 fObjectCount;
PropertyObject* fOldProperties;
PropertyObject* fNewProperties;
};
#endif // SET_PROPERTIES_COMMAND_H
@@ -10,6 +10,7 @@
#include <Message.h> #include <Message.h>
#include <MessageFilter.h> #include <MessageFilter.h>
#include <TextView.h>
#include <Window.h> #include <Window.h>
#include "Command.h" #include "Command.h"
@@ -32,6 +33,8 @@ class EventFilter : public BMessageFilter {
filter_result result = B_DISPATCH_MESSAGE; filter_result result = B_DISPATCH_MESSAGE;
switch (message->what) { switch (message->what) {
case B_KEY_DOWN: { case B_KEY_DOWN: {
if (dynamic_cast<BTextView*>(*target))
break;
uint32 key; uint32 key;
uint32 modifiers; uint32 modifiers;
if (message->FindInt32("raw_char", (int32*)&key) >= B_OK if (message->FindInt32("raw_char", (int32*)&key) >= B_OK
@@ -41,6 +44,8 @@ class EventFilter : public BMessageFilter {
break; break;
} }
case B_KEY_UP: { case B_KEY_UP: {
if (dynamic_cast<BTextView*>(*target))
break;
uint32 key; uint32 key;
uint32 modifiers; uint32 modifiers;
if (message->FindInt32("raw_char", (int32*)&key) >= B_OK if (message->FindInt32("raw_char", (int32*)&key) >= B_OK
@@ -25,6 +25,8 @@ class Observable {
void SuspendNotifications(bool suspend); void SuspendNotifications(bool suspend);
bool HasPendingNotifications() const
{ return fPendingNotifications; }
private: private:
BList fObservers; BList fObservers;
@@ -8,6 +8,10 @@
#include "CommonPropertyIDs.h" #include "CommonPropertyIDs.h"
#include <stdio.h>
#include <debugger.h>
// name_for_id // name_for_id
const char* const char*
name_for_id(int32 id) name_for_id(int32 id)
@@ -42,6 +46,10 @@ name_for_id(int32 id)
name = "Miter Limit"; name = "Miter Limit";
break; break;
case PROPERTY_CLOSED:
name = "Closed";
break;
default: default:
name = "<unkown property>"; name = "<unkown property>";
break; break;
@@ -23,6 +23,8 @@ enum {
PROPERTY_CAP_MODE = 'cpmd', PROPERTY_CAP_MODE = 'cpmd',
PROPERTY_JOIN_MODE = 'jnmd', PROPERTY_JOIN_MODE = 'jnmd',
PROPERTY_MITER_LIMIT = 'mtlm', PROPERTY_MITER_LIMIT = 'mtlm',
PROPERTY_CLOSED = 'clsd',
}; };
@@ -14,12 +14,11 @@
#include "PropertyItemView.h" #include "PropertyItemView.h"
// constructor // constructor
PropertyEditorView::PropertyEditorView(Property* property) PropertyEditorView::PropertyEditorView()
: BView(BRect(0.0, 0.0, 10.0, 10.0), "property item", : BView(BRect(0.0, 0.0, 10.0, 10.0), "property item",
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE),
fParent(NULL), fParent(NULL),
fProperty(property),
fSelected(false) fSelected(false)
{ {
} }
@@ -107,4 +106,3 @@ PropertyEditorView::ValueChanged()
fParent->UpdateObject(); fParent->UpdateObject();
} }
@@ -16,7 +16,7 @@ class PropertyItemView;
class PropertyEditorView : public BView { class PropertyEditorView : public BView {
public: public:
PropertyEditorView(Property* property); PropertyEditorView();
virtual ~PropertyEditorView(); virtual ~PropertyEditorView();
// BView // BView
@@ -30,9 +30,6 @@ class PropertyEditorView : public BView {
// PropertyEditorView // PropertyEditorView
virtual float PreferredHeight() const; virtual float PreferredHeight() const;
Property* GetProperty() const
{ return fProperty; }
void SetSelected(bool selected); void SetSelected(bool selected);
bool IsSelected() const bool IsSelected() const
{ return fSelected; } { return fSelected; }
@@ -47,12 +44,12 @@ class PropertyEditorView : public BView {
virtual void ValueChanged(); virtual void ValueChanged();
virtual bool AdoptProperty(Property* property) = 0; virtual bool AdoptProperty(Property* property) = 0;
virtual Property* GetProperty() const = 0;
protected: protected:
PropertyItemView* fParent; PropertyItemView* fParent;
private: private:
Property* fProperty;
bool fSelected; bool fSelected;
}; };
@@ -25,7 +25,7 @@
// constructor // constructor
PropertyItemView::PropertyItemView(Property* property) PropertyItemView::PropertyItemView(Property* property)
: BView(BRect(0.0, 0.0, 10.0, 10.0), "property item", : BView(BRect(0.0, 0.0, 10.0, 10.0), "property item",
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE),
fParent(NULL), fParent(NULL),
fEditorView(/*factory->*/EditorFor(property)), fEditorView(/*factory->*/EditorFor(property)),
@@ -85,6 +85,7 @@ PropertyListView::PropertyListView()
fPropertyM(NULL), fPropertyM(NULL),
fPropertyObject(NULL), fPropertyObject(NULL),
fSavedProperties(new PropertyObject()),
fLastClickedItem(NULL), fLastClickedItem(NULL),
fSuspendUpdates(false), fSuspendUpdates(false),
@@ -103,6 +104,7 @@ PropertyListView::~PropertyListView()
delete fClipboard; delete fClipboard;
delete fPropertyObject; delete fPropertyObject;
delete fSavedProperties;
delete fMouseWheelFilter; delete fMouseWheelFilter;
delete fTabFilter; delete fTabFilter;
@@ -346,6 +348,7 @@ PropertyListView::SetTo(PropertyObject* object)
if (fPropertyObject && object && if (fPropertyObject && object &&
fPropertyObject->ContainsSameProperties(*object)) { fPropertyObject->ContainsSameProperties(*object)) {
// iterate over view items and update their value views // iterate over view items and update their value views
bool error = false;
for (int32 i = 0; PropertyItemView* item = _ItemAt(i); i++) { for (int32 i = 0; PropertyItemView* item = _ItemAt(i); i++) {
Property* property = object->PropertyAt(i); Property* property = object->PropertyAt(i);
if (!item->AdoptProperty(property)) { if (!item->AdoptProperty(property)) {
@@ -354,13 +357,24 @@ PropertyListView::SetTo(PropertyObject* object)
// there is no editor view at this item // there is no editor view at this item
fprintf(stderr, "PropertyListView::_SetTo() - " fprintf(stderr, "PropertyListView::_SetTo() - "
"property mismatch at %ld\n", i); "property mismatch at %ld\n", i);
error = true;
break; break;
} }
if (property) if (property)
item->SetEnabled(property->IsEditable()); item->SetEnabled(property->IsEditable());
} }
// we didn't take on ownership, but kept our old object // we didn't need to make empty, but transfer ownership
delete object; // of the object
if (!error) {
// if the "adopt" process went only halfway,
// some properties of the original object
// are still referenced, so we can only
// delete the original object if the process
// was successful and leak Properties otherwise,
// but this case is only theoretical anyways...
delete fPropertyObject;
}
fPropertyObject = object;
} else { } else {
// remember scroll pos, selection and focused item // remember scroll pos, selection and focused item
BPoint scrollOffset = ScrollOffset(); BPoint scrollOffset = ScrollOffset();
@@ -406,14 +420,17 @@ PropertyListView::SetTo(PropertyObject* object)
SetDataRect(_ItemsRect()); SetDataRect(_ItemsRect());
} }
_UpdateSavedProperties();
_CheckMenuStatus(); _CheckMenuStatus();
} }
// UpdateObject // PropertyChanged
void void
PropertyListView::UpdateObject(uint32 propertyID) PropertyListView::PropertyChanged(const Property* previous,
const Property* current)
{ {
printf("PropertyListView::UpdateObject(%s)\n", name_for_id(propertyID)); printf("PropertyListView::PropertyChanged(%s)\n",
name_for_id(current->Identifier()));
} }
// PasteProperties // PasteProperties
@@ -442,6 +459,20 @@ PropertyListView::IsEditingMultipleObjects()
// #pragma mark - // #pragma mark -
// UpdateObject
void
PropertyListView::UpdateObject(uint32 propertyID)
{
Property* previous = fSavedProperties->FindProperty(propertyID);
Property* current = fPropertyObject->FindProperty(propertyID);
if (previous && current) {
// call hook function
PropertyChanged(previous, current);
// update saved property
previous->SetValue(current);
}
}
// ScrollOffsetChanged // ScrollOffsetChanged
void void
PropertyListView::ScrollOffsetChanged(BPoint oldOffset, BPoint newOffset) PropertyListView::ScrollOffsetChanged(BPoint oldOffset, BPoint newOffset)
@@ -508,13 +539,28 @@ PropertyListView::DoubleClicked(PropertyItemView* item)
{ {
if (fLastClickedItem == item) { if (fLastClickedItem == item) {
printf("implement PropertyListView::DoubleClicked()\n"); printf("implement PropertyListView::DoubleClicked()\n");
// ...->EditObject(item->GetProperty());
} }
fLastClickedItem = NULL; fLastClickedItem = NULL;
} }
// #pragma mark - // #pragma mark -
// _UpdateSavedProperties
void
PropertyListView::_UpdateSavedProperties()
{
fSavedProperties->DeleteProperties();
if (!fPropertyObject)
return;
int32 count = fPropertyObject->CountProperties();
for (int32 i = 0; i < count; i++) {
const Property* p = fPropertyObject->PropertyAtFast(i);
fSavedProperties->AddProperty(p->Clone());
}
}
// _AddItem // _AddItem
bool bool
PropertyListView::_AddItem(PropertyItemView* item) PropertyListView::_AddItem(PropertyItemView* item)
@@ -52,7 +52,8 @@ class PropertyListView : public BView,
// PropertyListView // PropertyListView
void SetTo(PropertyObject* object); void SetTo(PropertyObject* object);
// takes ownership of the object // takes ownership of the object
virtual void UpdateObject(uint32 propertyID); virtual void PropertyChanged(const Property* previous,
const Property* current);
// implement to know when a property changed // implement to know when a property changed
virtual void PasteProperties(const PropertyObject* object); virtual void PasteProperties(const PropertyObject* object);
// implement to know when a property changed // implement to know when a property changed
@@ -63,6 +64,8 @@ class PropertyListView : public BView,
void UpdateStrings(); void UpdateStrings();
// interface for Property framework // interface for Property framework
void UpdateObject(uint32 propertyID);
bool TabFocus(bool shift); bool TabFocus(bool shift);
void Select(PropertyItemView* item); void Select(PropertyItemView* item);
@@ -72,6 +75,8 @@ class PropertyListView : public BView,
void DoubleClicked(PropertyItemView* item); void DoubleClicked(PropertyItemView* item);
private: private:
void _UpdateSavedProperties();
bool _AddItem(PropertyItemView* item); bool _AddItem(PropertyItemView* item);
PropertyItemView* _RemoveItem(int32 index); PropertyItemView* _RemoveItem(int32 index);
PropertyItemView* _ItemAt(int32 index) const; PropertyItemView* _ItemAt(int32 index) const;
@@ -96,6 +101,7 @@ class PropertyListView : public BView,
BMenuItem* fPasteMI; BMenuItem* fPasteMI;
PropertyObject* fPropertyObject; PropertyObject* fPropertyObject;
PropertyObject* fSavedProperties;
PropertyItemView* fLastClickedItem; PropertyItemView* fLastClickedItem;
@@ -10,13 +10,11 @@
#include <stdio.h> #include <stdio.h>
#include "Property.h"
#include "ui_defines.h" #include "ui_defines.h"
// constructor // constructor
BoolValueView::BoolValueView(BoolProperty* property) BoolValueView::BoolValueView(BoolProperty* property)
: PropertyEditorView(property), : PropertyEditorView(),
fProperty(property), fProperty(property),
fCheckBoxRect(0.0, 0.0, -1.0, -1.0), fCheckBoxRect(0.0, 0.0, -1.0, -1.0),
fEnabled(true) fEnabled(true)
@@ -9,10 +9,9 @@
#ifndef BOOL_VALUE_VIEW_H #ifndef BOOL_VALUE_VIEW_H
#define BOOL_VALUE_VIEW_H #define BOOL_VALUE_VIEW_H
#include "Property.h"
#include "PropertyEditorView.h" #include "PropertyEditorView.h"
class BoolProperty;
class BoolValueView : public PropertyEditorView { class BoolValueView : public PropertyEditorView {
public: public:
BoolValueView(BoolProperty* property); BoolValueView(BoolProperty* property);
@@ -31,6 +30,8 @@ class BoolValueView : public PropertyEditorView {
virtual void SetEnabled(bool enabled); virtual void SetEnabled(bool enabled);
virtual bool AdoptProperty(Property* property); virtual bool AdoptProperty(Property* property);
virtual Property* GetProperty() const
{ return fProperty; }
private: private:
void _ToggleValue(); void _ToggleValue();
@@ -16,7 +16,6 @@
#include "support_ui.h" #include "support_ui.h"
#include "ColorProperty.h"
#include "PropertyItemView.h" #include "PropertyItemView.h"
#include "SwatchValueView.h" #include "SwatchValueView.h"
@@ -26,7 +25,7 @@ enum {
// constructor // constructor
ColorValueView::ColorValueView(ColorProperty* property) ColorValueView::ColorValueView(ColorProperty* property)
: PropertyEditorView(property), : PropertyEditorView(),
fProperty(property) fProperty(property)
{ {
fSwatchView = new SwatchValueView("swatch property view", fSwatchView = new SwatchValueView("swatch property view",
@@ -9,9 +9,9 @@
#ifndef COLOR_VALUE_VIEW_H #ifndef COLOR_VALUE_VIEW_H
#define COLOR_VALUE_VIEW_H #define COLOR_VALUE_VIEW_H
#include "ColorProperty.h"
#include "PropertyEditorView.h" #include "PropertyEditorView.h"
class ColorProperty;
class SwatchValueView; class SwatchValueView;
class ColorValueView : public PropertyEditorView { class ColorValueView : public PropertyEditorView {
@@ -32,6 +32,8 @@ class ColorValueView : public PropertyEditorView {
virtual bool IsFocused() const; virtual bool IsFocused() const;
virtual bool AdoptProperty(Property* property); virtual bool AdoptProperty(Property* property);
virtual Property* GetProperty() const
{ return fProperty; }
protected: protected:
ColorProperty* fProperty; ColorProperty* fProperty;
@@ -10,12 +10,11 @@
#include <stdio.h> #include <stdio.h>
#include "Property.h"
#include "NummericalTextView.h" #include "NummericalTextView.h"
// constructor // constructor
FloatValueView::FloatValueView(FloatProperty* property) FloatValueView::FloatValueView(FloatProperty* property)
: TextInputValueView(property), : TextInputValueView(),
fProperty(property) fProperty(property)
{ {
BRect b = Bounds(); BRect b = Bounds();
@@ -9,9 +9,9 @@
#ifndef FLOAT_VALUE_VIEW_H #ifndef FLOAT_VALUE_VIEW_H
#define FLOAT_VALUE_VIEW_H #define FLOAT_VALUE_VIEW_H
#include "Property.h"
#include "TextInputValueView.h" #include "TextInputValueView.h"
class FloatProperty;
class NummericalTextView; class NummericalTextView;
class FloatValueView : public TextInputValueView { class FloatValueView : public TextInputValueView {
@@ -26,6 +26,8 @@ class FloatValueView : public TextInputValueView {
virtual void ValueChanged(); virtual void ValueChanged();
virtual bool AdoptProperty(Property* property); virtual bool AdoptProperty(Property* property);
virtual Property* GetProperty() const
{ return fProperty; }
private: private:
FloatProperty* fProperty; FloatProperty* fProperty;
@@ -6,20 +6,19 @@
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
*/ */
#include "IconValueView.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Region.h> #include <Region.h>
#include "IconProperty.h"
#include "PropertyItemView.h" #include "PropertyItemView.h"
#include "IconValueView.h"
// constructor // constructor
IconValueView::IconValueView(IconProperty* property) IconValueView::IconValueView(IconProperty* property)
: PropertyEditorView(property), : PropertyEditorView(),
fProperty(property), fProperty(property),
fIcon(NULL) fIcon(NULL)
{ {
@@ -9,9 +9,9 @@
#ifndef ICON_VALUE_VIEW_H #ifndef ICON_VALUE_VIEW_H
#define ICON_VALUE_VIEW_H #define ICON_VALUE_VIEW_H
#include "IconProperty.h"
#include "PropertyEditorView.h" #include "PropertyEditorView.h"
class IconProperty;
class NummericalTextView; class NummericalTextView;
class IconValueView : public PropertyEditorView { class IconValueView : public PropertyEditorView {
@@ -26,6 +26,8 @@ class IconValueView : public PropertyEditorView {
virtual void SetEnabled(bool enabled); virtual void SetEnabled(bool enabled);
virtual bool AdoptProperty(Property* property); virtual bool AdoptProperty(Property* property);
virtual Property* GetProperty() const
{ return fProperty; }
// IconValueView // IconValueView
status_t SetIcon(const unsigned char* bitsFromQuickRes, status_t SetIcon(const unsigned char* bitsFromQuickRes,
@@ -10,12 +10,11 @@
#include <stdio.h> #include <stdio.h>
#include "Int64Property.h"
#include "NummericalTextView.h" #include "NummericalTextView.h"
// constructor // constructor
Int64ValueView::Int64ValueView(Int64Property* property) Int64ValueView::Int64ValueView(Int64Property* property)
: TextInputValueView(property), : TextInputValueView(),
fProperty(property) fProperty(property)
{ {
BRect b = Bounds(); BRect b = Bounds();
@@ -9,9 +9,9 @@
#ifndef INT64_VALUE_VIEW_H #ifndef INT64_VALUE_VIEW_H
#define INT64_VALUE_VIEW_H #define INT64_VALUE_VIEW_H
#include "Int64Property.h"
#include "TextInputValueView.h" #include "TextInputValueView.h"
class Int64Property;
class NummericalTextView; class NummericalTextView;
class Int64ValueView : public TextInputValueView { class Int64ValueView : public TextInputValueView {
@@ -26,6 +26,8 @@ class Int64ValueView : public TextInputValueView {
virtual void ValueChanged(); virtual void ValueChanged();
virtual bool AdoptProperty(Property* property); virtual bool AdoptProperty(Property* property);
virtual Property* GetProperty() const
{ return fProperty; }
private: private:
Int64Property* fProperty; Int64Property* fProperty;
@@ -10,12 +10,11 @@
#include <stdio.h> #include <stdio.h>
#include "Property.h"
#include "NummericalTextView.h" #include "NummericalTextView.h"
// constructor // constructor
IntValueView::IntValueView(IntProperty* property) IntValueView::IntValueView(IntProperty* property)
: TextInputValueView(property), : TextInputValueView(),
fProperty(property) fProperty(property)
{ {
BRect b = Bounds(); BRect b = Bounds();
@@ -9,9 +9,9 @@
#ifndef INT_VALUE_VIEW_H #ifndef INT_VALUE_VIEW_H
#define INT_VALUE_VIEW_H #define INT_VALUE_VIEW_H
#include "Property.h"
#include "TextInputValueView.h" #include "TextInputValueView.h"
class IntProperty;
class NummericalTextView; class NummericalTextView;
class IntValueView : public TextInputValueView { class IntValueView : public TextInputValueView {
@@ -26,6 +26,8 @@ class IntValueView : public TextInputValueView {
virtual void ValueChanged(); virtual void ValueChanged();
virtual bool AdoptProperty(Property* property); virtual bool AdoptProperty(Property* property);
virtual Property* GetProperty() const
{ return fProperty; }
private: private:
IntProperty* fProperty; IntProperty* fProperty;
@@ -6,6 +6,8 @@
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
*/ */
#include "OptionValueView.h"
#include <stdio.h> #include <stdio.h>
#include <Font.h> #include <Font.h>
@@ -14,17 +16,13 @@
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Region.h> #include <Region.h>
#include "OptionProperty.h"
#include "OptionValueView.h"
enum { enum {
MSG_OPTION_CHANGED = 'opch', MSG_OPTION_CHANGED = 'opch',
}; };
// constructor // constructor
OptionValueView::OptionValueView(OptionProperty* property) OptionValueView::OptionValueView(OptionProperty* property)
: PropertyEditorView(property), : PropertyEditorView(),
fProperty(property), fProperty(property),
fCurrentOption(""), fCurrentOption(""),
fEnabled(true) fEnabled(true)
@@ -11,10 +11,9 @@
#include <String.h> #include <String.h>
#include "OptionProperty.h"
#include "PropertyEditorView.h" #include "PropertyEditorView.h"
class OptionProperty;
class OptionValueView : public PropertyEditorView { class OptionValueView : public PropertyEditorView {
public: public:
OptionValueView(OptionProperty* property); OptionValueView(OptionProperty* property);
@@ -35,6 +34,8 @@ class OptionValueView : public PropertyEditorView {
virtual void ValueChanged(); virtual void ValueChanged();
virtual bool AdoptProperty(Property* property); virtual bool AdoptProperty(Property* property);
virtual Property* GetProperty() const
{ return fProperty; }
private: private:
OptionProperty* fProperty; OptionProperty* fProperty;
@@ -11,12 +11,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "Property.h"
#include "StringTextView.h" #include "StringTextView.h"
// constructor // constructor
StringValueView::StringValueView(StringProperty* property) StringValueView::StringValueView(StringProperty* property)
: TextInputValueView(property), : TextInputValueView(),
fProperty(property) fProperty(property)
{ {
BRect b = Bounds(); BRect b = Bounds();
@@ -9,9 +9,10 @@
#ifndef STRING_VALUE_VIEW_H #ifndef STRING_VALUE_VIEW_H
#define STRING_VALUE_VIEW_H #define STRING_VALUE_VIEW_H
#include "OptionProperty.h"
#include "Property.h"
#include "TextInputValueView.h" #include "TextInputValueView.h"
class StringProperty;
class StringTextView; class StringTextView;
class StringValueView : public TextInputValueView { class StringValueView : public TextInputValueView {
@@ -26,6 +27,8 @@ class StringValueView : public TextInputValueView {
virtual void ValueChanged(); virtual void ValueChanged();
virtual bool AdoptProperty(Property* property); virtual bool AdoptProperty(Property* property);
virtual Property* GetProperty() const
{ return fProperty; }
private: private:
StringProperty* fProperty; StringProperty* fProperty;
@@ -21,8 +21,8 @@ enum {
}; };
// constructor // constructor
TextInputValueView::TextInputValueView(Property* property) TextInputValueView::TextInputValueView()
: PropertyEditorView(property) : PropertyEditorView()
{ {
} }
@@ -21,7 +21,7 @@ class InputTextView;
class TextInputValueView : public PropertyEditorView { class TextInputValueView : public PropertyEditorView {
public: public:
TextInputValueView(Property* property); TextInputValueView();
virtual ~TextInputValueView(); virtual ~TextInputValueView();
// BView interface // BView interface
@@ -0,0 +1,153 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "IconObjectListView.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include "CommandStack.h"
#include "IconObject.h"
#include "Property.h"
#include "PropertyObject.h"
#include "Selection.h"
#include "SetPropertiesCommand.h"
using std::nothrow;
// constructor
IconObjectListView::IconObjectListView()
: PropertyListView(),
fSelection(NULL),
fCommandStack(NULL),
fObject(NULL),
fIgnoreObjectChange(false)
{
}
// destructor
IconObjectListView::~IconObjectListView()
{
SetSelection(NULL);
_SetObject(NULL);
}
// PropertyChanged
void
IconObjectListView::PropertyChanged(const Property* previous,
const Property* current)
{
if (!fCommandStack || !fObject)
return;
PropertyObject* oldObject = new (nothrow) PropertyObject();
if (oldObject)
oldObject->AddProperty(previous->Clone());
PropertyObject* newObject = new (nothrow) PropertyObject();
if (newObject)
newObject->AddProperty(current->Clone());
IconObject** objects = new (nothrow) IconObject*[1];
if (objects)
objects[0] = fObject;
Command* command = new (nothrow) SetPropertiesCommand(objects, 1,
oldObject,
newObject);
fIgnoreObjectChange = true;
fCommandStack->Perform(command);
fIgnoreObjectChange = false;
}
// PasteProperties
void
IconObjectListView::PasteProperties(const PropertyObject* object)
{
printf("IconObjectListView::PasteProperties()\n");
PropertyListView::PasteProperties(object);
}
// IsEditingMultipleObjects
bool
IconObjectListView::IsEditingMultipleObjects()
{
return false;
}
// #pragma mark -
// ObjectChanged
void
IconObjectListView::ObjectChanged(const Observable* object)
{
if (object == fSelection) {
Selectable* selected = fSelection->SelectableAt(0);
_SetObject(dynamic_cast<IconObject*>(selected));
}
if (object == fObject && !fIgnoreObjectChange) {
printf("IconObjectListView::ObjectChanged(fObject)\n");
SetTo(fObject->MakePropertyObject());
}
}
// #pragma mark -
// SetSelection
void
IconObjectListView::SetSelection(Selection* selection)
{
if (fSelection == selection)
return;
if (fSelection)
fSelection->RemoveObserver(this);
fSelection = selection;
if (fSelection)
fSelection->AddObserver(this);
}
// SetCommandStack
void
IconObjectListView::SetCommandStack(CommandStack* stack)
{
fCommandStack = stack;
}
// #pragma mark -
// _SetObject
void
IconObjectListView::_SetObject(IconObject* object)
{
if (fObject == object)
return;
if (fObject) {
fObject->RemoveObserver(this);
fObject->Release();
}
fObject = object;
PropertyObject* propertyObject = NULL;
if (fObject) {
fObject->Acquire();
fObject->AddObserver(this);
propertyObject = fObject->MakePropertyObject();
}
SetTo(propertyObject);
}
@@ -0,0 +1,48 @@
/*
* Copyright 2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#ifndef ICON_OBJECT_LIST_VIEW_H
#define ICON_OBJECT_LIST_VIEW_H
#include "Observer.h"
#include "PropertyListView.h"
class CommandStack;
class IconObject;
class Selection;
class IconObjectListView : public PropertyListView,
public Observer {
public:
IconObjectListView();
virtual ~IconObjectListView();
// PropertyListView interface
virtual void PropertyChanged(const Property* previous,
const Property* current);
virtual void PasteProperties(const PropertyObject* object);
virtual bool IsEditingMultipleObjects();
// Observer interface
virtual void ObjectChanged(const Observable* object);
// IconObjectListView
void SetSelection(Selection* selection);
void SetCommandStack(CommandStack* stack);
private:
void _SetObject(IconObject* object);
Selection* fSelection;
CommandStack* fCommandStack;
IconObject* fObject;
bool fIgnoreObjectChange;
};
#endif // ICON_OBJECT_LIST_VIEW_H
+24 -24
View File
@@ -128,29 +128,29 @@ class PathListItem : public SimpleItem,
} }
void SetMarkEnabled(bool enabled) void SetMarkEnabled(bool enabled)
{ {
if (fMarkEnabled == enabled) if (fMarkEnabled == enabled)
return; return;
fMarkEnabled = enabled; fMarkEnabled = enabled;
Invalidate(); Invalidate();
} }
void SetMarked(bool marked) void SetMarked(bool marked)
{ {
if (fMarked == marked) if (fMarked == marked)
return; return;
fMarked = marked; fMarked = marked;
Invalidate(); Invalidate();
} }
void Invalidate() void Invalidate()
{ {
// :-/ // :-/
if (fListView->LockLooper()) { if (fListView->LockLooper()) {
fListView->InvalidateItem( fListView->InvalidateItem(
fListView->IndexOf(this)); fListView->IndexOf(this));
fListView->UnlockLooper(); fListView->UnlockLooper();
} }
} }
VectorPath* path; VectorPath* path;
private: private:
@@ -265,10 +265,10 @@ PathListView::SelectionChanged()
if (!fSelection) if (!fSelection)
return; return;
// if (item) if (item)
// fSelection->Select(item->path); fSelection->Select(item->path);
// else else
// fSelection->DeselectAll(); fSelection->DeselectAll();
} }
// MouseDown // MouseDown
@@ -26,19 +26,62 @@
using std::nothrow; using std::nothrow;
class TransformerItem : public SimpleItem { class TransformerItem : public SimpleItem,
public Observer {
public: public:
TransformerItem(Transformer* t) TransformerItem(Transformer* t,
TransformerListView* listView)
: SimpleItem(t->Name()), : SimpleItem(t->Name()),
transformer(t) transformer(NULL),
fListView(listView)
{ {
SetTransformer(t);
} }
virtual ~TransformerItem() virtual ~TransformerItem()
{ {
SetTransformer(NULL);
}
// Observer interface
virtual void ObjectChanged(const Observable* object)
{
UpdateText();
}
// TransformerItem
void SetTransformer(Transformer* t)
{
if (t == transformer)
return;
if (transformer) {
transformer->RemoveObserver(this);
transformer->Release();
}
transformer = t;
if (transformer) {
transformer->Acquire();
transformer->AddObserver(this);
UpdateText();
}
}
void UpdateText()
{
SetText(transformer->Name());
// :-/
if (fListView->LockLooper()) {
fListView->InvalidateItem(
fListView->IndexOf(this));
fListView->UnlockLooper();
}
} }
Transformer* transformer; Transformer* transformer;
private:
TransformerListView* fListView;
}; };
// #pragma mark - // #pragma mark -
@@ -171,7 +214,8 @@ BListItem*
TransformerListView::CloneItem(int32 index) const TransformerListView::CloneItem(int32 index) const
{ {
if (TransformerItem* item = dynamic_cast<TransformerItem*>(ItemAt(index))) { if (TransformerItem* item = dynamic_cast<TransformerItem*>(ItemAt(index))) {
return new TransformerItem(item->transformer); return new TransformerItem(item->transformer,
const_cast<TransformerListView*>(this));
} }
return NULL; return NULL;
} }
@@ -258,7 +302,7 @@ bool
TransformerListView::_AddTransformer(Transformer* transformer, int32 index) TransformerListView::_AddTransformer(Transformer* transformer, int32 index)
{ {
if (transformer) if (transformer)
return AddItem(new TransformerItem(transformer), index); return AddItem(new TransformerItem(transformer, this), index);
return false; return false;
} }
+16 -31
View File
@@ -25,7 +25,7 @@ ShapeListener::~ShapeListener()
// constructor // constructor
Shape::Shape(::Style* style) Shape::Shape(::Style* style)
: IconObject(), : IconObject("<shape>"),
Observer(), Observer(),
PathContainerListener(), PathContainerListener(),
@@ -35,9 +35,7 @@ Shape::Shape(::Style* style)
fPathSource(fPaths), fPathSource(fPaths),
fTransformers(4), fTransformers(4),
fLastBounds(0, 0, -1, -1), fLastBounds(0, 0, -1, -1)
fName("<shape>")
{ {
if (fPaths) if (fPaths)
fPaths->AddListener(this); fPaths->AddListener(this);
@@ -47,7 +45,7 @@ Shape::Shape(::Style* style)
// constructor // constructor
Shape::Shape(const Shape& other) Shape::Shape(const Shape& other)
: IconObject(), : IconObject(other),
Observer(), Observer(),
PathContainerListener(), PathContainerListener(),
@@ -57,9 +55,7 @@ Shape::Shape(const Shape& other)
fPathSource(fPaths), fPathSource(fPaths),
fTransformers(4), fTransformers(4),
fLastBounds(0, 0, -1, -1), fLastBounds(0, 0, -1, -1)
fName(other.fName)
{ {
if (fPaths) { if (fPaths) {
fPaths->AddListener(this); fPaths->AddListener(this);
@@ -82,8 +78,11 @@ Shape::Shape(const Shape& other)
Shape::~Shape() Shape::~Shape()
{ {
int32 count = fTransformers.CountItems(); int32 count = fTransformers.CountItems();
for (int32 i = 0; i < count; i++) for (int32 i = 0; i < count; i++) {
delete (Transformer*)fTransformers.ItemAtFast(i); Transformer* t = (Transformer*)fTransformers.ItemAtFast(i);
t->RemoveObserver(this);
delete t;
}
fPaths->MakeEmpty(); fPaths->MakeEmpty();
fPaths->RemoveListener(this); fPaths->RemoveListener(this);
@@ -99,7 +98,7 @@ void
Shape::ObjectChanged(const Observable* object) Shape::ObjectChanged(const Observable* object)
{ {
// simply pass on the event for now // simply pass on the event for now
// (a path 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(); Notify();
} }
@@ -157,26 +156,6 @@ Shape::SetStyle(::Style* style)
// #pragma mark - // #pragma mark -
// SetName
void
Shape::SetName(const char* name)
{
if (fName == name)
return;
fName = name;
Notify();
}
// Name
const char*
Shape::Name() const
{
return fName.String();
}
// #pragma mark -
// Bounds // Bounds
BRect BRect
Shape::Bounds(bool updateLast) const Shape::Bounds(bool updateLast) const
@@ -217,6 +196,8 @@ Shape::VertexSource()
source = t; source = t;
} }
source->SetLast();
return *source; return *source;
} }
@@ -237,6 +218,8 @@ Shape::AddTransformer(Transformer* transformer, int32 index)
if (!fTransformers.AddItem((void*)transformer, index)) if (!fTransformers.AddItem((void*)transformer, index))
return false; return false;
transformer->AddObserver(this);
_NotifyTransformerAdded(transformer, index); _NotifyTransformerAdded(transformer, index);
return true; return true;
} }
@@ -246,6 +229,8 @@ bool
Shape::RemoveTransformer(Transformer* transformer) Shape::RemoveTransformer(Transformer* transformer)
{ {
if (fTransformers.RemoveItem((void*)transformer)) { if (fTransformers.RemoveItem((void*)transformer)) {
transformer->RemoveObserver(this);
_NotifyTransformerRemoved(transformer); _NotifyTransformerRemoved(transformer);
return true; return true;
} }
-6
View File
@@ -3,7 +3,6 @@
#include <List.h> #include <List.h>
#include <Rect.h> #include <Rect.h>
#include <String.h>
#include "IconObject.h" #include "IconObject.h"
#include "Observer.h" #include "Observer.h"
@@ -48,9 +47,6 @@ class Shape : public IconObject,
inline ::Style* Style() const inline ::Style* Style() const
{ return fStyle; } { return fStyle; }
void SetName(const char* name);
const char* Name() const;
inline BRect LastBounds() const inline BRect LastBounds() const
{ return fLastBounds; } { return fLastBounds; }
BRect Bounds(bool updateLast = false) const; BRect Bounds(bool updateLast = false) const;
@@ -87,8 +83,6 @@ class Shape : public IconObject,
BList fListeners; BList fListeners;
mutable BRect fLastBounds; mutable BRect fLastBounds;
BString fName;
}; };
#endif // SHAPE_H #endif // SHAPE_H
+45 -46
View File
@@ -24,6 +24,10 @@
#include "support.h" #include "support.h"
#include "CommonPropertyIDs.h"
#include "Property.h"
#include "PropertyObject.h"
#define obj_new(type, n) ((type *)malloc ((n) * sizeof(type))) #define obj_new(type, n) ((type *)malloc ((n) * sizeof(type)))
#define obj_renew(p, type, n) ((type *)realloc (p, (n) * sizeof(type))) #define obj_renew(p, type, n) ((type *)realloc (p, (n) * sizeof(type)))
#define obj_free free #define obj_free free
@@ -56,11 +60,6 @@ get_path_storage(agg::path_storage& path,
points[0].point.x, points[0].point.x,
points[0].point.y); points[0].point.y);
path.close_polygon(); path.close_polygon();
} else {
// straight line from last to first control point
path.line_to(points[0].point.x,
points[0].point.y);
path.close_polygon();
} }
return true; return true;
@@ -72,27 +71,23 @@ get_path_storage(agg::path_storage& path,
// constructor // constructor
VectorPath::VectorPath() VectorPath::VectorPath()
: BArchivable(), : BArchivable(),
Observable(), IconObject("<path>"),
Referenceable(),
fPath(NULL), fPath(NULL),
fClosed(false), 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)
fName("<path>")
{ {
} }
// constructor // constructor
VectorPath::VectorPath(const VectorPath& from) VectorPath::VectorPath(const VectorPath& from)
: BArchivable(), : BArchivable(),
Observable(), IconObject(from),
Referenceable(),
fPath(NULL), fPath(NULL),
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)
fName()
{ {
*this = from; *this = from;
} }
@@ -100,14 +95,12 @@ VectorPath::VectorPath(const VectorPath& from)
// constructor // constructor
VectorPath::VectorPath(const BMessage* archive) VectorPath::VectorPath(const BMessage* archive)
: BArchivable(), : BArchivable(),
Observable(), IconObject("<path>"/*archive*/),
Referenceable(),
fPath(NULL), fPath(NULL),
fClosed(false), 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)
fName()
{ {
if (archive) { if (archive) {
type_code typeFound; type_code typeFound;
@@ -133,9 +126,6 @@ VectorPath::VectorPath(const BMessage* archive)
if (archive->FindBool("path closed", &fClosed) < B_OK) { if (archive->FindBool("path closed", &fClosed) < B_OK) {
fClosed = false; fClosed = false;
} }
if (archive->FindString("name", &fName) < B_OK) {
fName = "<path>";
}
} }
} }
@@ -146,6 +136,35 @@ VectorPath::~VectorPath()
obj_free(fPath); obj_free(fPath);
} }
// #pragma mark -
// MakePropertyObject
PropertyObject*
VectorPath::MakePropertyObject() const
{
PropertyObject* object = IconObject::MakePropertyObject();
if (!object)
return NULL;
object->AddProperty(new BoolProperty(PROPERTY_CLOSED, fClosed));
return object;
}
// SetToPropertyObject
bool
VectorPath::SetToPropertyObject(const PropertyObject* object)
{
AutoNotificationSuspender _(this);
IconObject::SetToPropertyObject(object);
SetClosed(object->Value(PROPERTY_CLOSED, fClosed));
return HasPendingNotifications();
}
// #pragma mark -
// operator= // operator=
VectorPath& VectorPath&
VectorPath::operator=(const VectorPath& from) VectorPath::operator=(const VectorPath& from)
@@ -161,7 +180,6 @@ VectorPath::operator=(const VectorPath& from)
fPointCount = 0; fPointCount = 0;
fCachedBounds.Set(0.0, 0.0, -1.0, -1.0); fCachedBounds.Set(0.0, 0.0, -1.0, -1.0);
} }
fName = from.fName;
return *this; return *this;
} }
@@ -213,13 +231,8 @@ VectorPath::Archive(BMessage* into, bool deep) const
fprintf(stderr, "failed adding points!\n"); fprintf(stderr, "failed adding points!\n");
} }
if (ret >= B_OK) { if (ret >= B_OK) {
ret = into->AddString("name", fName.String());
} else {
fprintf(stderr, "failed adding close!\n"); fprintf(stderr, "failed adding close!\n");
} }
if (ret < B_OK) {
fprintf(stderr, "failed adding name!\n");
}
// finish off // finish off
if (ret < B_OK) { if (ret < B_OK) {
ret = into->AddString("class", "VectorPath"); ret = into->AddString("class", "VectorPath");
@@ -228,6 +241,8 @@ VectorPath::Archive(BMessage* into, bool deep) const
return ret; return ret;
} }
// #pragma mark -
// AddPoint // AddPoint
bool bool
VectorPath::AddPoint(BPoint point) VectorPath::AddPoint(BPoint point)
@@ -414,6 +429,8 @@ VectorPath::SetInOutConnected(int32 index, bool connected)
return false; return false;
} }
// #pragma mark -
// GetPointAt // GetPointAt
bool bool
VectorPath::GetPointAt(int32 index, BPoint& point) const VectorPath::GetPointAt(int32 index, BPoint& point) const
@@ -478,6 +495,8 @@ VectorPath::CountPoints() const
return fPointCount; return fPointCount;
} }
// #pragma mark -
// distance_to_curve // distance_to_curve
static float static float
distance_to_curve(const BPoint& p, const BPoint& a, const BPoint& aOut, const BPoint& bIn, const BPoint& b) distance_to_curve(const BPoint& p, const BPoint& a, const BPoint& aOut, const BPoint& bIn, const BPoint& b)
@@ -845,26 +864,6 @@ VectorPath::_SetPoint(int32 index, BPoint point)
// #pragma mark - // #pragma mark -
// SetName
void
VectorPath::SetName(const char* name)
{
if (fName == name)
return;
fName = name;
Notify();
}
// Name
const char*
VectorPath::Name() const
{
return fName.String();
}
// #pragma mark -
// _SetPointCount // _SetPointCount
bool bool
VectorPath::_SetPointCount(int32 count) VectorPath::_SetPointCount(int32 count)
+8 -10
View File
@@ -15,8 +15,7 @@
#include <agg_path_storage.h> #include <agg_path_storage.h>
#include "Observable.h" #include "IconObject.h"
#include "Referenceable.h"
class BBitmap; class BBitmap;
class BMessage; class BMessage;
@@ -30,8 +29,7 @@ struct control_point {
}; };
class VectorPath : public BArchivable, class VectorPath : public BArchivable,
public Observable, public IconObject {
public Referenceable {
public: public:
class Iterator { class Iterator {
@@ -48,6 +46,12 @@ class VectorPath : public BArchivable,
VectorPath(const BMessage* archive); VectorPath(const BMessage* archive);
virtual ~VectorPath(); virtual ~VectorPath();
// IconObject
virtual PropertyObject* MakePropertyObject() const;
virtual bool SetToPropertyObject(
const PropertyObject* object);
// VectorPath
VectorPath& operator=(const VectorPath& from); VectorPath& operator=(const VectorPath& from);
// bool operator==(const VectorPath& frrom) const; // bool operator==(const VectorPath& frrom) const;
@@ -122,9 +126,6 @@ class VectorPath : public BArchivable,
bool GetAGGPathStorage(agg::path_storage& path) const; bool GetAGGPathStorage(agg::path_storage& path) const;
void SetName(const char* name);
const char* Name() const;
private: private:
BRect _Bounds() const; BRect _Bounds() const;
void _SetPoint(int32 index, BPoint point); void _SetPoint(int32 index, BPoint point);
@@ -138,9 +139,6 @@ class VectorPath : public BArchivable,
int32 fAllocCount; int32 fAllocCount;
mutable BRect fCachedBounds; mutable BRect fCachedBounds;
// TODO: should this really be part of VectorPath?
BString fName;
}; };
#endif // VECTOR_PATH_H #endif // VECTOR_PATH_H
+1 -1
View File
@@ -12,7 +12,7 @@
// constructor // constructor
Style::Style() Style::Style()
: IconObject(), : IconObject("<style>"),
Observer(), Observer(),
fColor(), fColor(),
@@ -10,7 +10,7 @@
// constructor // constructor
AffineTransformer::AffineTransformer(VertexSource& source) AffineTransformer::AffineTransformer(VertexSource& source)
: Transformer(source), : Transformer(source, "Transformation"),
Affine(source, *this) Affine(source, *this)
{ {
} }
@@ -42,11 +42,10 @@ AffineTransformer::SetSource(VertexSource& source)
Affine::attach(source); Affine::attach(source);
} }
// Name // SetLast
const char* void
AffineTransformer::Name() const AffineTransformer::SetLast()
{ {
return "Transformation"; fSource.SetLast();
} }
@@ -29,8 +29,7 @@ class AffineTransformer : 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 void SetLast();
virtual const char* Name() const;
}; };
#endif // AFFINE_TRANSFORMER_H #endif // AFFINE_TRANSFORMER_H
@@ -10,7 +10,7 @@
// constructor // constructor
ContourTransformer::ContourTransformer(VertexSource& source) ContourTransformer::ContourTransformer(VertexSource& source)
: Transformer(source), : Transformer(source, "Contour"),
Contour(source) Contour(source)
{ {
} }
@@ -42,10 +42,10 @@ ContourTransformer::SetSource(VertexSource& source)
Contour::attach(source); Contour::attach(source);
} }
// Name // SetLast
const char* void
ContourTransformer::Name() const ContourTransformer::SetLast()
{ {
return "Contour"; fSource.SetLast();
} }
@@ -26,8 +26,7 @@ class ContourTransformer : 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 void SetLast();
virtual const char* Name() const;
}; };
#endif // CONTOUR_TRANSFORMER_H #endif // CONTOUR_TRANSFORMER_H
@@ -39,6 +39,13 @@ PathSource::vertex(double* x, double* y)
return fAGGCurvedPath.vertex(x, y); return fAGGCurvedPath.vertex(x, y);
} }
// SetLast
void
PathSource::SetLast()
{
fAGGPath.close_polygon();
}
// Update // Update
void void
PathSource::Update() PathSource::Update()
@@ -28,6 +28,8 @@ class PathSource : public VertexSource {
virtual void rewind(unsigned path_id); virtual void rewind(unsigned path_id);
virtual unsigned vertex(double* x, double* y); virtual unsigned vertex(double* x, double* y);
virtual void SetLast();
void Update(); void Update();
private: private:
@@ -10,7 +10,7 @@
// constructor // constructor
PerspectiveTransformer::PerspectiveTransformer(VertexSource& source) PerspectiveTransformer::PerspectiveTransformer(VertexSource& source)
: Transformer(source), : Transformer(source, "Perspective"),
Perspective(source, *this) Perspective(source, *this)
{ {
} }
@@ -42,11 +42,12 @@ PerspectiveTransformer::SetSource(VertexSource& source)
Perspective::attach(source); Perspective::attach(source);
} }
// Name // SetLast
const char* void
PerspectiveTransformer::Name() const PerspectiveTransformer::SetLast()
{ {
return "Perspective"; fSource.SetLast();
} }
@@ -29,8 +29,7 @@ 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 void SetLast();
virtual const char* Name() const;
}; };
#endif // PERSPECTIVE_TRANSFORMER_H #endif // PERSPECTIVE_TRANSFORMER_H
@@ -8,9 +8,14 @@
#include "StrokeTransformer.h" #include "StrokeTransformer.h"
#include "CommonPropertyIDs.h"
#include "OptionProperty.h"
#include "Property.h"
#include "PropertyObject.h"
// constructor // constructor
StrokeTransformer::StrokeTransformer(VertexSource& source) StrokeTransformer::StrokeTransformer(VertexSource& source)
: Transformer(source), : Transformer(source, "Stroke"),
Stroke(source) Stroke(source)
{ {
} }
@@ -42,11 +47,71 @@ StrokeTransformer::SetSource(VertexSource& source)
Stroke::attach(source); Stroke::attach(source);
} }
// Name // #pragma mark -
const char*
StrokeTransformer::Name() const // MakePropertyObject
PropertyObject*
StrokeTransformer::MakePropertyObject() const
{ {
return "Stroke"; PropertyObject* object = Transformer::MakePropertyObject();
if (!object)
return NULL;
// width
object->AddProperty(new FloatProperty(PROPERTY_WIDTH, width()));
// cap mode
OptionProperty* property = new OptionProperty(PROPERTY_CAP_MODE);
property->AddOption(agg::butt_cap, "Butt");
property->AddOption(agg::square_cap, "Square");
property->AddOption(agg::round_cap, "Round");
property->SetCurrentOptionID(line_cap());
object->AddProperty(property);
// join mode
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);
return object;
}
// SetToPropertyObject
bool
StrokeTransformer::SetToPropertyObject(const PropertyObject* object)
{
AutoNotificationSuspender _(this);
Transformer::SetToPropertyObject(object);
// width
float w = object->Value(PROPERTY_WIDTH, (float)width());
if (w != width()) {
width(w);
Notify();
}
// cap mode
OptionProperty* property = dynamic_cast<OptionProperty*>(
object->FindProperty(PROPERTY_CAP_MODE));
if (property && line_cap() != property->CurrentOptionID()) {
line_cap((agg::line_cap_e)property->CurrentOptionID());
Notify();
}
// join mode
property = dynamic_cast<OptionProperty*>(
object->FindProperty(PROPERTY_JOIN_MODE));
if (property && line_join() != property->CurrentOptionID()) {
line_join((agg::line_join_e)property->CurrentOptionID());
Notify();
}
return HasPendingNotifications();
} }
@@ -27,7 +27,10 @@ class StrokeTransformer : public Transformer,
virtual void SetSource(VertexSource& source); virtual void SetSource(VertexSource& source);
virtual const char* Name() const; // IconObject interface
virtual PropertyObject* MakePropertyObject() const;
virtual bool SetToPropertyObject(
const PropertyObject* object);
}; };
#endif // STROKE_TRANSFORMER_H #endif // STROKE_TRANSFORMER_H
@@ -18,11 +18,18 @@ VertexSource::~VertexSource()
{ {
} }
// Finish
void
VertexSource::SetLast()
{
}
// #pragma mark - // #pragma mark -
// constructor // constructor
Transformer::Transformer(VertexSource& source) Transformer::Transformer(VertexSource& source, const char* name)
: fSource(source) : IconObject(name),
fSource(source)
{ {
} }
@@ -52,11 +59,4 @@ Transformer::SetSource(VertexSource& source)
fSource = source; fSource = source;
} }
// #pragma mark -
// SelectedChanged
void
Transformer::SelectedChanged()
{
}
@@ -9,7 +9,7 @@
#ifndef TRANSFORMER_H #ifndef TRANSFORMER_H
#define TRANSFORMER_H #define TRANSFORMER_H
#include "Selectable.h" #include "IconObject.h"
class VertexSource { class VertexSource {
public: public:
@@ -18,13 +18,16 @@ class VertexSource {
virtual void rewind(unsigned path_id) = 0; virtual void rewind(unsigned path_id) = 0;
virtual unsigned vertex(double* x, double* y) = 0; virtual unsigned vertex(double* x, double* y) = 0;
virtual void SetLast();
}; };
class Transformer : public VertexSource, class Transformer : public VertexSource,
public Selectable { public IconObject {
public: public:
Transformer(VertexSource& source); Transformer(VertexSource& source,
const char* name);
virtual ~Transformer(); virtual ~Transformer();
virtual void rewind(unsigned path_id); virtual void rewind(unsigned path_id);
@@ -32,12 +35,7 @@ class Transformer : public VertexSource,
virtual void SetSource(VertexSource& source); virtual void SetSource(VertexSource& source);
virtual const char* Name() const = 0; protected:
// Selectable interface
virtual void SelectedChanged();
private:
VertexSource& fSource; VertexSource& fSource;
}; };