From 4a50fc36653580f5079c8893225331a3bd423678 Mon Sep 17 00:00:00 2001 From: cxl Date: Fri, 17 Jan 2020 08:57:42 +0000 Subject: [PATCH] CtrlLib, Draw: Gtk3 ch improvements git-svn-id: svn://ultimatepp.org/upp/trunk@13905 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlCore/gtk3-todo.txt | 3 +- uppsrc/CtrlLib/Ch.cpp | 8 +- uppsrc/Draw/Cham.cpp | 234 ++++++++------------- uppsrc/Draw/Cham.h | 7 +- uppsrc/Draw/Draw.upp | 2 +- uppsrc/Draw/{SSettings.cpp => SColors.cpp} | 0 6 files changed, 102 insertions(+), 152 deletions(-) rename uppsrc/Draw/{SSettings.cpp => SColors.cpp} (100%) diff --git a/uppsrc/CtrlCore/gtk3-todo.txt b/uppsrc/CtrlCore/gtk3-todo.txt index a32a05209..2b7e8ef3a 100644 --- a/uppsrc/CtrlCore/gtk3-todo.txt +++ b/uppsrc/CtrlCore/gtk3-todo.txt @@ -1,11 +1,11 @@ - Possible issue with Capture (e.g. ide about box) - Issue with editfield text clipping in the right -- LeftRoundness with DropChoice (DropChoiceRdO) - DnD crash? - GUILock docs CH: +- EditDate / EditTime problems - Redmond scrollbars width - Improve progress? @@ -78,3 +78,4 @@ DONE: - spinbutton cosmetics - ide missing vertical line - DropChoice STDSIZE (.TopPosZ(10)) +- LeftRoundness with DropChoice (DropChoiceRdO) diff --git a/uppsrc/CtrlLib/Ch.cpp b/uppsrc/CtrlLib/Ch.cpp index 9a4ffee0f..944857f82 100644 --- a/uppsrc/CtrlLib/Ch.cpp +++ b/uppsrc/CtrlLib/Ch.cpp @@ -282,10 +282,11 @@ void ChSynthetic(Image button100x100[4], Color text[4]) Color ink = SColorText(); for(int i = 0; i < 4; i++) { Image m = button100x100[i]; + auto Espots = [](const Image& m) { return WithHotSpots(m, DPI(3), DPI(1), CH_EDITFIELD_IMAGE, DPI(3)); }; if(i == 0) { ink = GetInk(m); roundness = GetRoundness(m) ? DPI(3) : 0; - CtrlsImg::Set(CtrlsImg::I_EFE, WithHotSpots(MakeButton(roundness, SColorPaper(), DPI(1), ink), DPI(3), DPI(1), 0, 0)); + CtrlsImg::Set(CtrlsImg::I_EFE, Espots(MakeButton(roundness, SColorPaper(), DPI(1), ink))); CtrlsImg::Set(CtrlsImg::I_VE, WithHotSpots(MakeButton(DPI(0), SColorPaper(), DPI(1), ink), DPI(2), DPI(2), 0, 0)); LabelBox::SetLook(WithHotSpots(MakeButton(2 * roundness / 3, Image(), DPI(1), ink), DPI(3), DPI(3), 0, 0)); } @@ -294,10 +295,9 @@ void ChSynthetic(Image button100x100[4], Color text[4]) { EditField::Style& s = EditField::StyleDefault().Write(); s.activeedge = true; - s.edge[i] = WithHotSpots(MakeButton(roundness, i == CTRL_DISABLED ? SColorFace() : SColorPaper(), DPI(1), ink), - DPI(3), DPI(1), 0, 0); + s.edge[i] = Espots(MakeButton(roundness, i == CTRL_DISABLED ? SColorFace() : SColorPaper(), DPI(1), ink)); if(i == 0) - s.coloredge = WithHotSpots(MakeButton(roundness, Black(), DPI(2), Null), DPI(3), DPI(1), 0, 0); + s.coloredge = Espots(MakeButton(roundness, Black(), DPI(2), Null)); } { auto Set = [&](Button::Style& s, const Image& arrow = Null, Color ink = Null, Color border = Null) { diff --git a/uppsrc/Draw/Cham.cpp b/uppsrc/Draw/Cham.cpp index e73e8175a..5afababd9 100644 --- a/uppsrc/Draw/Cham.cpp +++ b/uppsrc/Draw/Cham.cpp @@ -184,9 +184,6 @@ Value StdChLookFn(Draw& w, const Rect& r, const Value& v, int op, Color ink) return 0; case LOOK_MARGINS: return Rect(n, n, n, n); - case LOOK_ISBODYOPAQUE: - case LOOK_ISOPAQUE: - return false; } } if(IsType(v)) { @@ -200,9 +197,6 @@ Value StdChLookFn(Draw& w, const Rect& r, const Value& v, int op, Color ink) return 0; case LOOK_MARGINS: return Rect(1, 1, 1, 1); - case LOOK_ISBODYOPAQUE: - case LOOK_ISOPAQUE: - return !IsNull(c); } } if(IsType(v)) { @@ -219,6 +213,11 @@ Value StdChLookFn(Draw& w, const Rect& r, const Value& v, int op, Color ink) } Point p2 = img.Get2ndSpot(); int tile = 0; + if(p2.x == CH_EDITFIELD_IMAGE) { + if(op != LOOK_MARGINS) + p.x = p.y = p2.y; + p2.x = p2.y = 0; + } if(p2.x || p2.y) { if(p2.x < p.x) { Swap(p2.x, p.x); @@ -247,138 +246,103 @@ Value StdChLookFn(Draw& w, const Rect& r, const Value& v, int op, Color ink) } if(op == LOOK_MARGINS) return Rect(p.x, p.y, isz.cx - p2.x, isz.cy - p2.y); - if(op == LOOK_ISOPAQUE) - return img.GetKind() == IMAGE_OPAQUE; if(IsNull(img)) return 1; - if(op == LOOK_ISBODYOPAQUE) { - static VectorMap btc; - int64 key = img.GetSerialId(); - int q = btc.Find(key); - if(q < 0) { - bool opaque = true; - Rect m = ChMargins(img); - Rect r = img.GetSize(); - r.left += max(m.left, 0); - r.right -= max(m.right, 0); - r.top += m.top; - r.bottom -= m.bottom; - int cx = r.right - r.left; - if(cx >= 0) - for(int y = r.top; y < r.bottom && opaque; y++) { - const RGBA *s = img[y] + r.left; - const RGBA *e = s + cx; - while(s < e) { - if(s->a != 255) { - opaque = false; + LTIMING("ChPaint Image"); + w.Clipoff(r); + Rect sr(p, p2); + Size sz2(isz.cx - sr.right, isz.cy - sr.bottom); + Rect r = RectC(p.x, p.y, sz.cx - sr.left - sz2.cx, sz.cy - sr.top - sz2.cy); + int top = minmax(sz.cy / 2, 0, isz.cy); + int bottom = minmax(sz.cy - top, 0, isz.cy); + int yy = isz.cy - bottom; + int left = minmax(sz.cx / 2, 0, isz.cx); + int right = minmax(sz.cx - left, 0, isz.cx); + int xx = isz.cx - right; + if(!r.IsEmpty()) { + ChDraw(w, 0, 0, img, RectC(0, 0, p.x, p.y), ink); + ChDraw(w, 0, r.bottom, img, RectC(0, sr.bottom, p.x, sz2.cy), ink); + ChDraw(w, r.right, 0, img, RectC(sr.right, 0, sz2.cx, p.y), ink); + ChDraw(w, r.right, r.bottom, img, RectC(sr.right, sr.bottom, sz2.cx, sz2.cy), ink); + ChDraw(w, p.x, 0, r.Width(), p.y, img, RectC(p.x, 0, sr.Width(), p.y), ink); + ChDraw(w, p.x, r.bottom, r.Width(), sz2.cy, img, RectC(p.x, sr.bottom, sr.Width(), sz2.cy), ink); + ChDraw(w, 0, p.y, p.x, r.Height(), img, RectC(0, p.y, p.x, sr.Height()), ink); + ChDraw(w, r.right, p.y, sz2.cx, r.Height(), img, RectC(sr.right, p.y, sz2.cx, sr.Height()), ink); + if(op == LOOK_PAINT) { + if(IsNull(r) || IsNull(sr)) { + w.End(); + return 1; + } + if(tile) { + LTIMING("Ch-Tiles"); + LTIMING("Ch-Tiles"); + Size sz; + sz.cx = (tile & 1 ? sr : r).GetWidth(); + sz.cy = (tile & 2 ? sr : r).GetHeight(); + img = Rescale(img, sz, sr); + DrawTiles(w, r, img); + } + else { + static VectorMap btc; + int64 key = img.GetSerialId(); + int q; + { + LTIMING("Find"); + q = btc.Find(key); + } + if(q < 0) { + LTIMING("ClassifyContent"); + q = ClassifyContent(img, sr); + if(btc.GetCount() > 100) + btc.Clear(); + btc.Add(key, q); + } + else + q = btc[q]; + switch(q) { + case IMAGECONTENT_VERTDUP|IMAGECONTENT_HORZDUP: + { + LTIMING("Ch-singlecolor"); + RGBA c = img[sr.top][sr.left]; + if(c.a == 255) { + w.DrawRect(r, c); break; } } - } - if(btc.GetCount() > 100) - btc.Clear(); - btc.Add(key, q); - return opaque; - } - return btc[q]; - } - if(op == LOOK_PAINT || op == LOOK_PAINTEDGE) { - LTIMING("ChPaint Image"); - w.Clipoff(r); - Rect sr(p, p2); - Size sz2(isz.cx - sr.right, isz.cy - sr.bottom); - Rect r = RectC(p.x, p.y, sz.cx - sr.left - sz2.cx, sz.cy - sr.top - sz2.cy); - int top = minmax(sz.cy / 2, 0, isz.cy); - int bottom = minmax(sz.cy - top, 0, isz.cy); - int yy = isz.cy - bottom; - int left = minmax(sz.cx / 2, 0, isz.cx); - int right = minmax(sz.cx - left, 0, isz.cx); - int xx = isz.cx - right; - if(!r.IsEmpty()) { - ChDraw(w, 0, 0, img, RectC(0, 0, p.x, p.y), ink); - ChDraw(w, 0, r.bottom, img, RectC(0, sr.bottom, p.x, sz2.cy), ink); - ChDraw(w, r.right, 0, img, RectC(sr.right, 0, sz2.cx, p.y), ink); - ChDraw(w, r.right, r.bottom, img, RectC(sr.right, sr.bottom, sz2.cx, sz2.cy), ink); - ChDraw(w, p.x, 0, r.Width(), p.y, img, RectC(p.x, 0, sr.Width(), p.y), ink); - ChDraw(w, p.x, r.bottom, r.Width(), sz2.cy, img, RectC(p.x, sr.bottom, sr.Width(), sz2.cy), ink); - ChDraw(w, 0, p.y, p.x, r.Height(), img, RectC(0, p.y, p.x, sr.Height()), ink); - ChDraw(w, r.right, p.y, sz2.cx, r.Height(), img, RectC(sr.right, p.y, sz2.cx, sr.Height()), ink); - if(op == LOOK_PAINT) { - if(IsNull(r) || IsNull(sr)) { - w.End(); - return 1; - } - if(tile) { - LTIMING("Ch-Tiles"); - LTIMING("Ch-Tiles"); - Size sz; - sz.cx = (tile & 1 ? sr : r).GetWidth(); - sz.cy = (tile & 2 ? sr : r).GetHeight(); - img = Rescale(img, sz, sr); - DrawTiles(w, r, img); - } - else { - static VectorMap btc; - int64 key = img.GetSerialId(); - int q; - { - LTIMING("Find"); - q = btc.Find(key); - } - if(q < 0) { - LTIMING("ClassifyContent"); - q = ClassifyContent(img, sr); - if(btc.GetCount() > 100) - btc.Clear(); - btc.Add(key, q); - } - else - q = btc[q]; - switch(q) { - case IMAGECONTENT_VERTDUP|IMAGECONTENT_HORZDUP: - { - LTIMING("Ch-singlecolor"); - RGBA c = img[sr.top][sr.left]; - if(c.a == 255) { - w.DrawRect(r, c); - break; - } - } - case 0: - default: - ChDraw(w, r, img, sr, ink); - break; - } + case 0: + default: + ChDraw(w, r, img, sr, ink); + break; } } } - else - if(r.left < r.right) { - ChDraw(w, 0, 0, img, RectC(0, 0, p.x, top), ink); - ChDraw(w, 0, sz.cy - bottom, img, RectC(0, yy, p.x, bottom), ink); - ChDraw(w, r.right, 0, img, RectC(sr.right, 0, sz2.cx, top), ink); - ChDraw(w, r.right, sz.cy - bottom, img, RectC(sr.right, yy, sz2.cx, bottom), ink); - ChDraw(w, p.x, 0, r.Width(), top, img, RectC(p.x, 0, sr.Width(), top), ink); - ChDraw(w, p.x, sz.cy - bottom, r.Width(), bottom, img, RectC(p.x, yy, sr.Width(), bottom), ink); - } - else - if(r.top < r.bottom) { - ChDraw(w, 0, 0, img, RectC(0, 0, left, p.y), ink); - ChDraw(w, 0, r.bottom, img, RectC(0, sr.bottom, left, sz2.cy), ink); - ChDraw(w, sz.cx - right, 0, img, RectC(xx, 0, right, p.y), ink); - ChDraw(w, sz.cx - right, r.bottom, img, RectC(xx, sr.bottom, right, sz2.cy), ink); - ChDraw(w, 0, p.y, left, r.Height(), img, RectC(0, p.y, left, sr.Height()), ink); - ChDraw(w, sz.cx - right, p.y, right, r.Height(), img, RectC(xx, p.y, right, sr.Height()), ink); - } - else { - ChDraw(w, 0, 0, img, RectC(0, 0, left, top), ink); - ChDraw(w, 0, sz.cy - bottom, img, RectC(0, yy, left, top), ink); - ChDraw(w, sz.cx - right, 0, img, RectC(xx, 0, right, top), ink); - ChDraw(w, sz.cx - right, sz.cy - bottom, img, RectC(xx, yy, right, bottom), ink); - } - w.End(); - return 1; } + else + if(r.left < r.right) { + ChDraw(w, 0, 0, img, RectC(0, 0, p.x, top), ink); + ChDraw(w, 0, sz.cy - bottom, img, RectC(0, yy, p.x, bottom), ink); + ChDraw(w, r.right, 0, img, RectC(sr.right, 0, sz2.cx, top), ink); + ChDraw(w, r.right, sz.cy - bottom, img, RectC(sr.right, yy, sz2.cx, bottom), ink); + ChDraw(w, p.x, 0, r.Width(), top, img, RectC(p.x, 0, sr.Width(), top), ink); + ChDraw(w, p.x, sz.cy - bottom, r.Width(), bottom, img, RectC(p.x, yy, sr.Width(), bottom), ink); + } + else + if(r.top < r.bottom) { + ChDraw(w, 0, 0, img, RectC(0, 0, left, p.y), ink); + ChDraw(w, 0, r.bottom, img, RectC(0, sr.bottom, left, sz2.cy), ink); + ChDraw(w, sz.cx - right, 0, img, RectC(xx, 0, right, p.y), ink); + ChDraw(w, sz.cx - right, r.bottom, img, RectC(xx, sr.bottom, right, sz2.cy), ink); + ChDraw(w, 0, p.y, left, r.Height(), img, RectC(0, p.y, left, sr.Height()), ink); + ChDraw(w, sz.cx - right, p.y, right, r.Height(), img, RectC(xx, p.y, right, sr.Height()), ink); + } + else { + ChDraw(w, 0, 0, img, RectC(0, 0, left, top), ink); + ChDraw(w, 0, sz.cy - bottom, img, RectC(0, yy, left, top), ink); + ChDraw(w, sz.cx - right, 0, img, RectC(xx, 0, right, top), ink); + ChDraw(w, sz.cx - right, sz.cy - bottom, img, RectC(xx, yy, right, bottom), ink); + } + w.End(); + return 1; } return Null; } @@ -512,18 +476,6 @@ Rect ChMargins(const Value& look) return sChOp(w, Null, look, LOOK_MARGINS); } -bool ChIsOpaque(const Value& look) -{ - NilDraw w; - return sChOp(w, Null, look, LOOK_ISOPAQUE); -} - -bool ChIsBodyOpaque(const Value& look) -{ - NilDraw w; - return sChOp(w, Null, look, LOOK_ISBODYOPAQUE); -} - void DeflateMargins(Rect& r, const Rect& m) { r = Rect(r.left + m.left, r.top + m.top, r.right - m.right, r.bottom - m.bottom); diff --git a/uppsrc/Draw/Cham.h b/uppsrc/Draw/Cham.h index 0352b3c9a..7c238bf42 100644 --- a/uppsrc/Draw/Cham.h +++ b/uppsrc/Draw/Cham.h @@ -2,12 +2,11 @@ enum LookOp { LOOK_PAINT, LOOK_MARGINS, LOOK_PAINTEDGE, - LOOK_ISOPAQUE, - LOOK_ISBODYOPAQUE, }; enum { - CH_SCROLLBAR_IMAGE = -1000 // special Image hotspot x value for ChPaint of scrollbar + CH_SCROLLBAR_IMAGE = -1000, // special Image hotspot x value for ChPaint of scrollbar + CH_EDITFIELD_IMAGE = -1001, // special Image hotspot x2 value, y2 is then x and y for the purposes of painting }; void ChLookFn(Value (*fn)(Draw& w, const Rect& r, const Value& look, int lookop, Color ink)); @@ -27,8 +26,6 @@ void ChPaintEdge(Draw& w, int x, int y, int cx, int cy, const Value& look, Col void ChPaintBody(Draw& w, const Rect& r, const Value& look, Color ink = Null); void ChPaintBody(Draw& w, int x, int y, int cx, int cy, const Value& look, Color ink = Null); Rect ChMargins(const Value& look); -bool ChIsOpaque(const Value& look); -bool ChIsBodyOpaque(const Value& look); void DeflateMargins(Rect& r, const Rect& margin); void ChDeflateMargins(Rect& r, const Value& look); diff --git a/uppsrc/Draw/Draw.upp b/uppsrc/Draw/Draw.upp index 56fc0754b..c263a0f00 100644 --- a/uppsrc/Draw/Draw.upp +++ b/uppsrc/Draw/Draw.upp @@ -73,7 +73,7 @@ file Chameleon readonly separator, Cham.h, Cham.cpp, - SSettings.cpp, + SColors.cpp, GTK-dli readonly separator, gobj.dli, gdk.dli, diff --git a/uppsrc/Draw/SSettings.cpp b/uppsrc/Draw/SColors.cpp similarity index 100% rename from uppsrc/Draw/SSettings.cpp rename to uppsrc/Draw/SColors.cpp