* improvements to saving/loading, biggest flaw was that appending an icon

changed the save entry_ref to the appended file, instead of keeping it
* added cleaning up styles (removing duplicates) after importing from SVG
* compile fixes for rgb_color ==/!= rgb_color
* added Style::operator==(const Style& other)
* improved debug output when listeners are still attached
  to a VectorPath upon destruction



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19188 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2006-11-03 09:40:22 +00:00
parent 64dfde6fb0
commit 6e3b3b09d3
7 changed files with 76 additions and 17 deletions
+17 -7
View File
@@ -137,10 +137,16 @@ IconEditorApp::MessageReceived(BMessage* message)
}
_SyncPanels(fSavePanel, fOpenPanel);
} else {
const char* saveText = NULL;
if (fDocument->Ref())
saveText = fDocument->Ref()->name;
switch (message->what) {
case MSG_EXPORT_AS:
case MSG_EXPORT:
exportMode = EXPORT_MODE_FLAT_ICON;
if (fDocument->ExportRef())
saveText = fDocument->ExportRef()->name;
break;
case MSG_EXPORT_BITMAP:
exportMode = EXPORT_MODE_BITMAP;
@@ -171,6 +177,8 @@ IconEditorApp::MessageReceived(BMessage* message)
fSavePanel->SetMessage(&fpMessage);
// fSavePanel->Refresh();
if (saveText)
fSavePanel->SetSaveText(saveText);
fSavePanel->Show();
}
break;
@@ -325,13 +333,15 @@ IconEditorApp::_Open(const entry_ref& ref, bool append)
fDocument->SetIcon(icon);
switch (refMode) {
case REF_MESSAGE:
fDocument->SetRef(ref);
break;
case REF_FLAT:
fDocument->SetExportRef(ref);
break;
if (!append) {
switch (refMode) {
case REF_MESSAGE:
fDocument->SetRef(ref);
break;
case REF_FLAT:
fDocument->SetExportRef(ref);
break;
}
}
locker.Unlock();
@@ -454,6 +454,8 @@ DocumentBuilder::parse_path(PathTokenizer& tok)
}
}
// #pragma mark -
// GetIcon
status_t
DocumentBuilder::GetIcon(Icon* icon, SVGImporter* importer,
@@ -519,6 +521,25 @@ printf("scale: %f\n", scale);
_AddShape(attributes, true, transform, icon);
}
// clean up styles and paths (remove duplicates)
int32 count = icon->Shapes()->CountShapes();
for (int32 i = 1; i < count; i++) {
Shape* shape = icon->Shapes()->ShapeAtFast(i);
Style* style = shape->Style();
if (!style)
continue;
int32 styleIndex = icon->Styles()->IndexOf(style);
for (int32 j = 0; j < styleIndex; j++) {
Style* earlierStyle = icon->Styles()->StyleAtFast(j);
if (*style == *earlierStyle) {
shape->SetStyle(earlierStyle);
icon->Styles()->RemoveStyle(style);
style->Release();
break;
}
}
}
return B_OK;
}
@@ -528,7 +549,8 @@ DocumentBuilder::StartGradient(bool radial)
{
if (fCurrentGradient) {
fprintf(stderr, "DocumentBuilder::StartGradient() - ERROR: "
"previous gradient (%s) not finished!\n", fCurrentGradient->ID());
"previous gradient (%s) not finished!\n",
fCurrentGradient->ID());
}
if (radial)
@@ -546,7 +568,8 @@ DocumentBuilder::EndGradient()
if (fCurrentGradient) {
// fCurrentGradient->PrintToStream();
} else {
fprintf(stderr, "DocumentBuilder::EndGradient() - ERROR: no gradient started!\n");
fprintf(stderr, "DocumentBuilder::EndGradient() - "
"ERROR: no gradient started!\n");
}
fCurrentGradient = NULL;
}
@@ -34,11 +34,11 @@ SetColorCommand::~SetColorCommand()
status_t
SetColorCommand::InitCheck()
{
#ifdef HAIKU_TARGET_PLATFORM_BEOS
#ifdef __HAIKU__
return fStyle && fStyle->Color() != fColor ? B_OK : B_NO_INIT;
#else
return fStyle && *(uint32*)&fStyle->Color() != *(uint32*)&fColor ?
B_OK : B_NO_INIT;
#else
return fStyle && fStyle->Color() != fColor ? B_OK : B_NO_INIT;
#endif
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2006, Haiku.
* Copyright 2006, Haiku. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
+9 -3
View File
@@ -20,6 +20,7 @@
#ifdef ICON_O_MATIC
#include <debugger.h>
#include <typeinfo>
#include <Message.h>
#include <TypeConstants.h>
@@ -169,9 +170,14 @@ VectorPath::~VectorPath()
obj_free(fPath);
#ifdef ICON_O_MATIC
if (fListeners.CountItems() > 0)
debugger("VectorPath::~VectorPath() - "
"there are still listeners attached!");
if (fListeners.CountItems() > 0) {
PathListener* listener = (PathListener*)fListeners.ItemAt(0);
char message[512];
sprintf(message, "VectorPath::~VectorPath() - "
"there are still listeners attached! %p/%s",
listener, typeid(*listener).name());
debugger(message);
}
#endif
}
+19 -1
View File
@@ -142,13 +142,31 @@ Style::Archive(BMessage* into, bool deep) const
return ret;
}
// operator ==
bool
Style::operator==(const Style& other) const
{
if (fGradient) {
if (other.fGradient)
return *fGradient == *other.fGradient;
else
return false;
} else {
if (!other.fGradient)
return *(uint32*)&fColor == *(uint32*)&other.fColor;
else
return false;
}
}
#endif // ICON_O_MATIC
// SetColor
void
Style::SetColor(const rgb_color& color)
{
if ((uint32&)fColor == (uint32&)color)
if (*(uint32*)&fColor == *(uint32*)&color)
return;
fColor = color;
+2
View File
@@ -45,6 +45,8 @@ class Style {
// Style
status_t Archive(BMessage* into,
bool deep = true) const;
bool operator==(const Style& other) const;
#else
inline void Notify() {}
#endif // ICON_O_MATIC