#include "IconDes.h" #define IMAGECLASS IconDesImg #define IMAGEFILE #include void IconShow::Paint(Draw& w) { Size sz = GetSize(); static Color color[] = { White(), Black(), WhiteGray(), LtGray(), Gray(), Yellow(), Brown(), Red(), Green(), Blue(), Cyan(), Magenta() }; int image_scale = ImlFlagsToDPIScale(flags); auto GetSize = [&](int scale) { return scale * image.GetSize() / image_scale; }; auto GetScaled = [&](int scale) { if(image_scale == DPI_600) { if(scale == DPI_100) return Downscale6x(image); if(scale == DPI_150) return Downscale2x(DownSample2x(image)); if(scale == DPI_200) return DownSample3x(image); if(scale == DPI_300) return DownSample2x(image); } return DPISmartRescale(image, scale * image.GetSize() / image_scale); }; Size sz300 = GetSize(DPI_300); if(sz300.cx * sz300.cy > 20000) { w.DrawRect(sz, SColorPaper); w.DrawImage(DPI(5), DPI(5), image); return; } int n = min(__countof(color), sz.cx / (2 * sz300.cx + DPI(20))); int cx = sz.cx / n; int y = DPI(5); for(int i = 0; i < n; i++) w.DrawRect(i * cx, 0, cx + n, sz.cy, color[i]); for(int sc : { DPI_100, DPI_150, DPI_200, DPI_300 }) { Size isz = GetSize(sc); Image m1 = GetScaled(sc); Image m2 = DarkTheme(m1); for(int i = 0; i < n; i++) { int x = i * cx; if(image_scale == sc) w.DrawRect(x + DPI(1), y, DPI(2), isz.cy, SLtBlue); w.DrawImage(x + DPI(5), y, m1); w.DrawImage(x + sz300.cx + DPI(10), y, m2); } y += isz.cy + DPI(5); } } void sDrawChRect(Draw& w, int x0, int y, int cx, int cy, bool start = false) { w.DrawRect(x0, y, cx, cy, Color(255, 150, 200)); } void IconDes::Paint(Draw& w) { Size sz = GetSize(); if(!IsCurrent()) { w.DrawRect(sz, SColorPaper()); PaintBasicHintsTopic(this, w, "ide/app/ImlBeginnerInfo_en-us"); return; } const Image& image = Current().image; const Image& selection = Current().selection; Point spos = sb; Size isz = image.GetSize(); bool pastepaint = HasCapture() && IsPasting(); magnify = max(magnify, 1); if(magnify == 1) { w.DrawRect(sz, SColorPaper()); ImageBuffer pb(isz); RGBA c1 = GrayColor(102); RGBA c2 = GrayColor(153); int xn = isz.cx / DPI(4); for(int y = 0; y < isz.cy; y++) { RGBA *b = pb[y]; RGBA cc1 = c1; RGBA cc2 = c2; if(y & DPI(4)) Swap(cc1, cc2); for(int q = xn; q--;) { Fill(b, cc1, DPI(4)); Swap(cc1, cc2); b += DPI(4); } while(b < pb[y] + isz.cx) *b++ = cc1; } AlphaBlend(pb, image, (int)image.GetLength()); if(!pastepaint) for(int y = 0; y < isz.cy; y++) { const RGBA *m = selection[y]; RGBA *t = pb[y]; const RGBA *e = m + isz.cx; while(m < e) { if(!m->r) t->r = t->g = t->b = ((t->r + t->g + t->b) >> 2); m++; t++; } } w.DrawImage(-spos.x, -spos.y, pb); Rect r = pb.GetSize(); r.Offset(-spos); if(show_grid2) { w.DrawRect(r.right, 0, 1, r.bottom + 1, LtRed()); w.DrawRect(0, r.bottom, r.right, 1, LtRed()); } m1refresh = Null; if(IsPasting()) DrawFrame(w, Rect(Current().pastepos - spos, Current().paste_image.GetSize()), LtRed); return; } Rect src = Rect((sz + magnify) / magnify).Offseted(spos) & isz; Size ssz = src.GetSize(); ImageBuffer b(src.GetSize() * magnify); int m2 = magnify / 2; CoFor(src.GetHeight(), [&](int y) { // create chequered background RGBA *q = b[y * magnify]; int i = 0; Color c1 = GrayColor(102); Color c2 = GrayColor(153); int m = magnify - m2; for(int pass = 0; pass < 2; pass++) { RGBA *t = q; for(int i = 0; i < src.GetWidth(); i++) { Fill(q, c1, magnify); Fill(q + 1, c2, m2); q += magnify; } i++; while(i < m) { memcpy_t(q, t, b.GetWidth()); q += b.GetWidth(); i++; } m = magnify; Swap(c1, c2); } }); w.DrawImage(0, 0, b); // paint chequered background w.DrawImage(0, 0, Magnify(image, src, magnify, magnify, true)); // paint actual image if(!pastepaint && !IsNull(selection)) { // paint selection RGBA c1 = 170 * Black(); RGBA c2 = 80 * LtGray(); int ncx = ssz.cx * magnify; ImageBuffer b(ncx, ssz.cy * magnify); CoFor(ssz.cy, [&](int y) { const RGBA *s = selection[src.top + y] + src.left; const RGBA *e = s + ssz.cx; RGBA *t = ~b + y * ncx * magnify; RGBA *q = t; while(s < e) { RGBA c = s->r ? RGBAZero() : c1; Fill(q, c, magnify); Fill(q + ncx, c, magnify); if(!s->r) for(int i = 0; i < magnify - 1; i += 2) q[i] = c2; q += magnify; s++; } for(int i = 2; i < magnify; i++) { q += ncx; memcpy_t(q, t, ncx); t += ncx; } }); w.DrawImage(0, 0, b); } if(magnify > 6) { int grid2 = 0; if(max(isz.cx, isz.cy) > 16 && show_grid2) { if(isz.cx % 3 == 0 && isz.cy % 3 == 0) grid2 = 3; else if(isz.cx % 4 == 0 && isz.cy % 4 == 0) grid2 = 4; } auto GridColor = [&](int x, int sz) -> Color { if(grid2) { if(x == sz / 2) return LtMagenta(); if(x % grid2 == 0) return LtRed(); } return Black(); }; int m = ssz.cx * magnify + 1; for(int y = 0; y <= src.GetHeight(); y++) w.DrawRect(0, magnify * y, m, 1, GridColor(y + src.top, isz.cy)); m = ssz.cy * magnify + 1; for(int x = 0; x <= src.GetWidth(); x++) w.DrawRect(magnify * x, 0, 1, m, GridColor(x + src.left, isz.cx)); } if(IsPasting() && !pastepaint) DrawFatFrame(w, Rect(magnify * (Current().pastepos - spos), magnify * Current().paste_image.GetSize() + Size(1, 1)), Color(200, 200, 255), 3); if(magnify > 8 || IsHotSpot()) { auto PaintHotSpot = [&](Point h, Color c, bool tl, bool br) { if(h.x > 0 || h.y > 0 || tool == &IconDes::HotSpotTool) { h = (h - spos) * magnify; int d = magnify + 1; int n = 1 + magnify / 8; if(br) { w.DrawRect(h.x + d - n, h.y + n, n, d - n, c); w.DrawRect(h.x + n, h.y + d - n, d - 2 * n, n, c); } if(tl) { w.DrawRect(h.x, h.y, d, n, c); w.DrawRect(h.x, h.y + n, n, d - n, c); } } }; bool ns = image.GetHotSpot() != image.Get2ndSpot(); PaintHotSpot(image.GetHotSpot(), LtRed(), true, ns); PaintHotSpot(image.Get2ndSpot(), LtBlue(), ns, true); } PaintBasicHintsTopic(this, w, "ide/app/ImlBeginnerInfo_en-us"); }