ide: IconDes improvements

git-svn-id: svn://ultimatepp.org/upp/trunk@11924 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-05-01 10:22:33 +00:00
parent 3c976aac57
commit f936338a91
7 changed files with 57 additions and 12 deletions

View file

@ -11,6 +11,19 @@ Image WithHotSpots(const Image& m, int x1, int y1, int x2, int y2)
return b;
}
Image WithResolution(const Image& m, int res)
{
Image h = m;
ImageBuffer b(h);
b.SetResolution(res);
return b;
}
Image WithResolution(const Image& m, const Image& res)
{
return WithResolution(m, res.GetResolution());
}
Image WithHotSpot(const Image& m, int x1, int y1)
{
Image h = m;
@ -51,6 +64,7 @@ force_inline Size DstSrc(ImageBuffer& dest, Point& p, const Image& src, Rect& sr
void DstSrcOp(ImageBuffer& dest, Point p, const Image& src, const Rect& srect,
void (*op)(RGBA *t, const RGBA *s, int n))
{
dest.SetResolution(src.GetResolution());
Rect sr = srect;
Size sz = DstSrc(dest, p, src, sr);
if(sz.cx > 0)
@ -149,7 +163,7 @@ Image Crop(const Image& img, const Rect& rc)
ImageRaster src(img);
ImageEncoder tgt;
Crop(tgt, src, rc);
return tgt;
return WithResolution(tgt, img);
}
Image Crop(const Image& img, int x, int y, int cx, int cy)
@ -191,6 +205,7 @@ Image AutoCrop(const Image& m, RGBA c)
Image ColorMask(const Image& src, Color key)
{
ImageBuffer ib(src.GetSize());
ib.SetResolution(src.GetResolution());
const RGBA *s = src;
const RGBA *e = src + src.GetLength();
RGBA *t = ~ib;
@ -229,7 +244,7 @@ Image CanvasSize(const Image& img, int cx, int cy)
ImageRaster src(img);
ImageEncoder tgt;
CanvasSize(tgt, src, cx, cy);
return tgt;
return WithResolution(tgt, img);
}
Image AssignAlpha(const Image& img, const Image& alpha)
@ -250,6 +265,7 @@ Image AssignAlpha(const Image& img, const Image& alpha)
}
}
ib.SetHotSpots(img);
ib.SetResolution(img.GetResolution());
return ib;
}
@ -293,6 +309,7 @@ Image Equalight(const Image& img, int thold)
t++;
}
w.SetHotSpots(img);
w.SetResolution(img.GetResolution());
return w;
}
@ -312,6 +329,7 @@ Image Grayscale(const Image& img)
s++;
}
w.SetHotSpots(img);
w.SetResolution(img.GetResolution());
return w;
}
@ -332,6 +350,7 @@ Image Grayscale(const Image& img, int amount)
s++;
}
w.SetHotSpots(img);
w.SetResolution(img.GetResolution());
return w;
}
@ -358,6 +377,7 @@ Image Colorize(const Image& img, Color color, int alpha)
}
Premultiply(w);
w.SetHotSpots(img);
w.SetResolution(img.GetResolution());
return w;
}
@ -397,6 +417,7 @@ Image AdjustForDarkBk(const Image& img)
}
Premultiply(w);
w.SetHotSpots(img);
w.SetResolution(img.GetResolution());
return w;
}
@ -423,6 +444,7 @@ Image Contrast(const Image& img, int amount)
}
Premultiply(w);
w.SetHotSpots(img);
w.SetResolution(img.GetResolution());
return w;
}
@ -497,7 +519,7 @@ Image Filter(const Image& img, ImageFilter9& filter)
ImageEncoder tgt;
ImageRaster src(img);
Filter(tgt, src, filter);
return tgt;
return WithResolution(tgt, img);
}
struct RGBAI {
@ -555,7 +577,7 @@ Image Sharpen(const Image& img, int amount)
ImageEncoder tgt;
ImageRaster src(img);
Sharpen(tgt, src, amount);
return tgt;
return WithResolution(tgt, img);
}
struct sEtchFilter : ImageFilter9 {
@ -600,6 +622,7 @@ Image SetColorKeepAlpha(const Image& img, Color c)
}
Premultiply(w);
w.SetHotSpots(img);
w.SetResolution(img.GetResolution());
return w;
}
@ -666,6 +689,7 @@ Image RotateClockwise(const Image& img)
Point p1 = img.GetHotSpot();
Point p2 = img.Get2ndSpot();
SetNormalizedHotSpots(ib, sz.cy - p1.y - 1, p1.x, sz.cy - p2.y - 1, p2.x);
ib.SetResolution(img.GetResolution());
return ib;
}
@ -680,6 +704,7 @@ Image RotateAntiClockwise(const Image& img)
Point p1 = img.GetHotSpot();
Point p2 = img.Get2ndSpot();
SetNormalizedHotSpots(ib, p1.y, sz.cx - p1.x - 1, p2.y, sz.cx - p2.x - 1);
ib.SetResolution(img.GetResolution());
return ib;
}
@ -693,6 +718,7 @@ Image Rotate180(const Image& orig)
Point p1 = orig.GetHotSpot();
Point p2 = orig.Get2ndSpot();
SetNormalizedHotSpots(dest, sz.cy - p1.y - 1, sz.cx - p1.x - 1, sz.cy - p2.y - 1, sz.cx - p2.x - 1);
dest.SetResolution(dest.GetResolution());
return dest;
}
@ -713,6 +739,7 @@ Image MirrorHorz(const Image& img)
Point p1 = img.GetHotSpot();
Point p2 = img.Get2ndSpot();
SetNormalizedHotSpots(ib, sz.cx - p1.x - 1, p1.y, sz.cx - p2.x - 1, p2.y);
ib.SetResolution(img.GetResolution());
return ib;
}
@ -734,6 +761,7 @@ Image MirrorVert(const Image& img)
Point p1 = img.GetHotSpot();
Point p2 = img.Get2ndSpot();
SetNormalizedHotSpots(ib, p1.x, sz.cy - p1.y - 1, p2.x, sz.cy - p2.y - 1);
ib.SetResolution(img.GetResolution());
return ib;
}
@ -765,6 +793,7 @@ Image Magnify(const Image& img, int nx, int ny)
}
t = q;
}
b.SetResolution(img.GetResolution());
return b;
}
@ -806,6 +835,7 @@ Image Rotate(const Image& m, int angle)
*t++ = xs >= 0 && xs < isz.cx && ys >= 0 && ys < isz.cy ? m[ys][xs] : RGBAZero();
}
}
ib.SetResolution(m.GetResolution());
return ib;
}
@ -831,6 +861,7 @@ Image Dither(const Image& m, int dival)
int g = Grayscale(*s++) * 100 / dival;
*t++ = g > dither[y & 7][x & 7] ? White() : Black();
}
ib.SetResolution(m.GetResolution());
return ib;
}

View file

@ -230,6 +230,7 @@ void IconDes::SetBar()
{
toolbar.Set(THISBACK(MainToolBar));
SetSb();
SyncStatus();
}
struct CachedIconImage : public Display {
@ -300,10 +301,12 @@ void IconDes::SerializeSettings(Stream& s)
void IconDes::SyncStatus()
{
Point p = GetPos(GetMousePos() - GetScreenView().TopLeft());
Size sz = Current().image.GetSize();
Size sz = IsCurrent() ? Current().image.GetSize() : Size(0, 0);
String s;
if(Rect(sz).Contains(p))
s << "x: " << p.x << ':' << sz.cx - p.x - 1 << ", y: " << p.y << ':' << sz.cy - p.y - 1;
s << "(" << p.x << ", " << p.y << ") : (" << sz.cx - p.x - 1 << ", " << sz.cy - p.y - 1 << ")";
if(!IsNull(rect) && (doselection || IsPasting()))
MergeWith(s, ", ", AsString(rect));
status.SetLabel(s);
}

View file

@ -127,7 +127,7 @@ void IconDes::MakePaste()
if(paste_mode == PASTE_BACK) {
Image h = c.image;
UPP::Copy(c.image, c.pastepos, c.paste_image, c.paste_image.GetSize());
UPP::Over(c.image, c.pastepos, h, c.paste_image.GetSize());
UPP::Over(c.image, Point(0, 0), h, c.image.GetSize());
}
else
UPP::Over(c.image, c.pastepos, Premultiply(c.paste_image), c.paste_image.GetSize());
@ -178,10 +178,10 @@ void IconDes::RectTool0(Point p, dword flags, bool empty)
Size isz = GetImageSize();
IconDraw iw(isz);
iw.DrawRect(isz, GrayColor(0));
Rect r = Rect(startpoint, p + 1).Normalized();
rect = Rect(startpoint, p + 1).Normalized();
if(empty)
iw.DrawRect(r.Deflated(pen, pen), GrayColor(128));
DrawFatFrame(iw, r, GrayColor(255), pen);
iw.DrawRect(rect.Deflated(pen, pen), GrayColor(128));
DrawFatFrame(iw, rect, GrayColor(255), pen);
ApplyDraw(iw, flags);
}
@ -297,6 +297,7 @@ void IconDes::Paste(const Image& img)
FinishPaste();
if(!IsCurrent())
return;
SaveUndo();
Slot& c = Current();
c.base_image = c.image;
c.paste_image = img;
@ -435,6 +436,7 @@ void IconDes::SelectRect()
doselection = false;
Select();
selectrect = true;
rect = Null;
SetBar();
}
@ -504,6 +506,7 @@ void IconDes::SyncImage()
info.SetLabel(Format("%d x %d", c.image.GetWidth(), c.image.GetHeight()));
}
selectrect = false;
SyncList();
SetBar();
Refresh();
}

View file

@ -5,7 +5,6 @@
#include <Painter/Painter.h>
#include <RichEdit/RichEdit.h>
namespace Upp {
#define IMAGECLASS IconDesImg
@ -196,6 +195,9 @@ private:
FrameRight<Label> status;
int syncinglist = 0;
Rect rect;
struct TextDlg : WithIconDesTextLayout<TopWindow> {
typedef TextDlg CLASSNAME;

View file

@ -211,6 +211,7 @@ Image DownSample3x(const Image& src)
s += 3;
}
}
ib.SetResolution(src.GetResolution());
return ib;
}
@ -239,6 +240,7 @@ Image DownSample2x(const Image& src)
s += 2;
}
}
ib.SetResolution(src.GetResolution());
return ib;
}

View file

@ -16,6 +16,9 @@ static String sFormatImageName(const String& name, const Image& img, bool exp)
void IconDes::SyncList()
{
if(syncinglist)
return;
syncinglist++;
int sc = ilist.GetScroll();
int q = ilist.GetKey();
ilist.Clear();
@ -27,6 +30,7 @@ void IconDes::SyncList()
}
ilist.ScrollTo(sc);
ilist.FindSetCursor(q);
syncinglist--;
}
void IconDes::Search()

View file

@ -92,7 +92,7 @@ void IconDes::Paint(Draw& w)
w.DrawRect(r.right, 0, 1, r.bottom + 1, LtRed());
w.DrawRect(0, r.bottom, r.right, 1, LtRed());
m1refresh = Null;
if(IsPasting() && IsPasting())
if(IsPasting())
DrawFrame(w, Rect(Current().pastepos - spos, Current().paste_image.GetSize()), LtRed);
return;
}