ide: png. editor

git-svn-id: svn://ultimatepp.org/upp/trunk@5072 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2012-06-21 19:25:59 +00:00
parent d768e2a5b0
commit 57a0162305
5 changed files with 212 additions and 209 deletions

View file

@ -0,0 +1,96 @@
#include "IconDes.h"
#include <plugin/bmp/bmp.h>
#include <plugin/png/png.h>
bool IdeIconDes::Load(const char *_filename)
{
Clear();
filename = _filename;
filetime = FileGetTime(filename);
Array<ImlImage> m;
int f;
if(!LoadIml(LoadFile(filename), m, f))
return false;
format = f;
for(int i = 0; i < m.GetCount(); i++)
AddImage(m[i].name, m[i].image, m[i].exp);
return true;
}
void IdeIconDes::Save()
{
if(format == 1) {
for(int i = 0; i < GetCount(); i++) {
Image m = GetImage(i);
Point p = m.Get2ndSpot();
if(m.GetKind() == IMAGE_ALPHA || p.x || p.y) {
if(PromptYesNo("Legacy file format does not support images "
"with full alpha channel or 2nd hotspot - "
"the information would be lost.&"
"Do you wish to convert the file to the new format?")) {
format = 0;
}
break;
}
}
}
StoreToGlobal(*this, "icondes-ctrl");
Array<ImlImage> m;
VectorMap<Size, Image> exp;
String folder = GetFileFolder(filename);
for(int i = 0; i < GetCount(); i++) {
ImlImage& c = m.Add();
c.name = GetName(i);
c.image = GetImage(i);
c.exp = GetExport(i);
if(c.exp) {
Size sz = c.image.GetSize();
exp.GetAdd(sz) = c.image;
PNGEncoder png;
png.SaveFile(AppendFileName(folder, String().Cat() << "icon" << sz.cx << 'x' << sz.cy << ".png"), c.image);
}
}
String d = SaveIml(m, format);
if(!SaveChangedFileFinish(filename, d))
return;
filetime = FileGetTime(filename);
if(exp.GetCount())
SaveFile(AppendFileName(folder, "icon.ico"), WriteIcon(exp.GetValues()));
}
void IdeIconDes::ToolEx(Bar& bar)
{
bar.Separator();
bar.Add("File properties..", IconDesImg::FileProperties(), THISBACK(FileProperties));
}
void IdeIconDes::FileProperties()
{
WithFilePropertiesLayout<TopWindow> dlg;
CtrlLayoutOKCancel(dlg, "File properties");
dlg.format <<= format;
if(dlg.Run() == IDOK)
format = ~dlg.format;
}
void IdeIconDes::Serialize(Stream& s)
{
SerializeSettings(s);
}
String IdeIconDes::GetFileName() const
{
return filename;
}
void IdeIconDes::EditMenu(Bar& bar)
{
EditBar(bar);
ToolEx(bar);
bar.Add("List", THISBACK(ListMenu));
bar.Add("Selection", THISBACK(SelectBar));
bar.Add("Image", THISBACK(ImageBar));
bar.Add("Draw", THISBACK(DrawBar));
bar.Add("Settings", THISBACK(SettingBar));
}

View file

@ -29,4 +29,10 @@ struct IdeIconDes : IdeDesigner, IconDes {
IdeIconDes() { format = 0; } IdeIconDes() { format = 0; }
}; };
struct IdeIconEditPos : IconDes::EditPos, Moveable<IdeIconEditPos> {
Time filetime;
IdeIconEditPos() { filetime = Null; }
};
#endif #endif

View file

@ -6,6 +6,7 @@ uses
file file
IconDes.h, IconDes.h,
IconDes.cpp,
IdeDes.icpp, IdeDes.icpp,
Info readonly separator, Info readonly separator,
Copying; Copying;

View file

@ -1,209 +1,107 @@
#include "IconDes.h" #include "IconDes.h"
#include <plugin/bmp/bmp.h> static VectorMap<String, IdeIconEditPos>& sEP()
#include <plugin/png/png.h> {
static VectorMap<String, IdeIconEditPos> x;
bool IdeIconDes::Load(const char *_filename) return x;
{ }
Clear();
filename = _filename; void IdeIconDes::SaveEditPos()
filetime = FileGetTime(filename); {
Array<ImlImage> m; IdeIconEditPos& ep = sEP().GetAdd(filename);
int f; ep.filetime = filetime;
if(!LoadIml(LoadFile(filename), m, f)) (EditPos&)ep = GetEditPos();
return false; }
format = f;
for(int i = 0; i < m.GetCount(); i++) void SerializeIconDesPos(Stream& s)
AddImage(m[i].name, m[i].image, m[i].exp); {
return true; VectorMap<String, IdeIconEditPos>& filedata = sEP();
} if(s.IsStoring()) {
for(int i = 0; i < filedata.GetCount(); i++) {
String fn = filedata.GetKey(i);
void IdeIconDes::Save() if(!fn.IsEmpty()) {
{ FindFile ff(fn);
if(format == 1) { IdeIconEditPos& ep = filedata[i];
for(int i = 0; i < GetCount(); i++) { if(ff && ff.GetLastWriteTime() == ep.filetime) {
Image m = GetImage(i); s % fn;
Point p = m.Get2ndSpot(); s % ep.filetime;
if(m.GetKind() == IMAGE_ALPHA || p.x || p.y) { s % ep.cursor;
if(PromptYesNo("Legacy file format does not support images " s % ep.sc;
"with full alpha channel or 2nd hotspot - " }
"the information would be lost.&" }
"Do you wish to convert the file to the new format?")) { }
format = 0; String end;
} s % end;
break; }
} else {
} String fn;
} filedata.Clear();
StoreToGlobal(*this, "icondes-ctrl"); for(;;) {
Array<ImlImage> m; s % fn;
VectorMap<Size, Image> exp; if(fn.IsEmpty()) break;
String folder = GetFileFolder(filename); IdeIconEditPos& ep = filedata.GetAdd(fn);
for(int i = 0; i < GetCount(); i++) { s % ep.filetime;
ImlImage& c = m.Add(); s % ep.cursor;
c.name = GetName(i); s % ep.sc;
c.image = GetImage(i); }
c.exp = GetExport(i); }
if(c.exp) { }
Size sz = c.image.GetSize();
exp.GetAdd(sz) = c.image; bool IsImlFile(const char *path)
PNGEncoder png; {
png.SaveFile(AppendFileName(folder, String().Cat() << "icon" << sz.cx << 'x' << sz.cy << ".png"), c.image); return ToLower(GetFileExt(path)) == ".iml";
} }
}
String d = SaveIml(m, format); struct IconDesModule : public IdeModule {
if(!SaveChangedFileFinish(filename, d)) virtual void CleanUsc() {}
return; virtual bool ParseUsc(CParser& p) { return false; }
filetime = FileGetTime(filename); virtual Image FileIcon(const char *path) {
if(exp.GetCount()) return IsImlFile(path) ? IconDesImg::FileIcon() : Null;
SaveFile(AppendFileName(folder, "icon.ico"), WriteIcon(exp.GetValues())); }
} virtual IdeDesigner *CreateDesigner(const char *path, byte) {
if(IsImlFile(path)) {
void IdeIconDes::ToolEx(Bar& bar) IdeIconDes *d = new IdeIconDes;
{ LoadFromGlobal(*d, "icondes-ctrl");
bar.Separator(); if(d->Load(path)) {
bar.Add("File properties..", IconDesImg::FileProperties(), THISBACK(FileProperties)); IdeIconEditPos& ep = sEP().GetAdd(path);
} if(ep.filetime == d->filetime)
d->SetEditPos(ep);
void IdeIconDes::FileProperties() return d;
{ }
WithFilePropertiesLayout<TopWindow> dlg; delete d;
CtrlLayoutOKCancel(dlg, "File properties"); return NULL;
dlg.format <<= format; }
if(dlg.Run() == IDOK) return false;
format = ~dlg.format; }
} virtual void Serialize(Stream& s) {
int version = 0;
void IdeIconDes::Serialize(Stream& s) s / version;
{ SerializeIconDesPos(s);
SerializeSettings(s); }
} };
struct IdeIconEditPos : IconDes::EditPos, Moveable<IdeIconEditPos> { void RegisterIconDes()
Time filetime; {
RegisterIdeModule(Single<IconDesModule>());
IdeIconEditPos() { filetime = Null; } }
};
void IdeIconDes::CopyId(const String& n)
static VectorMap<String, IdeIconEditPos>& sEP() {
{ ClearClipboard();
static VectorMap<String, IdeIconEditPos> x; AppendClipboardText(n);
return x; }
}
void IdeIconDes::ListMenuEx(Bar& bar)
void IdeIconDes::SaveEditPos() {
{ String n = GetCurrentName();
IdeIconEditPos& ep = sEP().GetAdd(filename); String c = GetFileTitle(filename);
ep.filetime = filetime; c.Set(0, ToUpper(c[0]));
(EditPos&)ep = GetEditPos(); c = c.EndsWith("Img") ? c : c + "Img";
} c << "::" << n << "()";
bar.Separator();
void SerializeIconDesPos(Stream& s) bar.Add(n.GetCount(), "Copy '" + c + '\'', CtrlImg::copy(), THISBACK1(CopyId, c));
{ }
VectorMap<String, IdeIconEditPos>& filedata = sEP();
if(s.IsStoring()) { INITBLOCK {
for(int i = 0; i < filedata.GetCount(); i++) { RegisterGlobalConfig("icondes-ctrl");
String fn = filedata.GetKey(i); }
if(!fn.IsEmpty()) {
FindFile ff(fn);
IdeIconEditPos& ep = filedata[i];
if(ff && ff.GetLastWriteTime() == ep.filetime) {
s % fn;
s % ep.filetime;
s % ep.cursor;
s % ep.sc;
}
}
}
String end;
s % end;
}
else {
String fn;
filedata.Clear();
for(;;) {
s % fn;
if(fn.IsEmpty()) break;
IdeIconEditPos& ep = filedata.GetAdd(fn);
s % ep.filetime;
s % ep.cursor;
s % ep.sc;
}
}
}
String IdeIconDes::GetFileName() const
{
return filename;
}
bool IsImlFile(const char *path)
{
return ToLower(GetFileExt(path)) == ".iml";
}
void IdeIconDes::EditMenu(Bar& bar)
{
EditBar(bar);
ToolEx(bar);
bar.Add("List", THISBACK(ListMenu));
bar.Add("Selection", THISBACK(SelectBar));
bar.Add("Image", THISBACK(ImageBar));
bar.Add("Draw", THISBACK(DrawBar));
bar.Add("Settings", THISBACK(SettingBar));
}
struct IconDesModule : public IdeModule {
virtual void CleanUsc() {}
virtual bool ParseUsc(CParser& p) { return false; }
virtual Image FileIcon(const char *path) {
return IsImlFile(path) ? IconDesImg::FileIcon() : Null;
}
virtual IdeDesigner *CreateDesigner(const char *path, byte) {
if(IsImlFile(path)) {
IdeIconDes *d = new IdeIconDes;
LoadFromGlobal(*d, "icondes-ctrl");
if(d->Load(path)) {
IdeIconEditPos& ep = sEP().GetAdd(path);
if(ep.filetime == d->filetime)
d->SetEditPos(ep);
return d;
}
delete d;
return NULL;
}
return false;
}
virtual void Serialize(Stream& s) {
int version = 0;
s / version;
SerializeIconDesPos(s);
}
};
void RegisterIconDes()
{
RegisterIdeModule(Single<IconDesModule>());
}
void IdeIconDes::CopyId(const String& n)
{
ClearClipboard();
AppendClipboardText(n);
}
void IdeIconDes::ListMenuEx(Bar& bar)
{
String n = GetCurrentName();
String c = GetFileTitle(filename);
c.Set(0, ToUpper(c[0]));
c = c.EndsWith("Img") ? c : c + "Img";
c << "::" << n << "()";
bar.Separator();
bar.Add(n.GetCount(), "Copy '" + c + '\'', CtrlImg::copy(), THISBACK1(CopyId, c));
}
INITBLOCK {
RegisterGlobalConfig("icondes-ctrl");
}

View file

@ -2,6 +2,8 @@
void IdePngDes::Save() void IdePngDes::Save()
{ {
if(GetCount())
SaveChangedFile(filename, PNGEncoder().SaveString(GetImage(0)), true);
} }
void IdePngDes::Load(const char *_filename) void IdePngDes::Load(const char *_filename)