diff --git a/include/lgi/common/Point.h b/include/lgi/common/Point.h --- a/include/lgi/common/Point.h +++ b/include/lgi/common/Point.h @@ -1,205 +1,218 @@ /// 2d Point classes #pragma once #include class LgiClass LPoint { public: int x, y; LPoint(int Ix = 0, int Iy = 0) { x = Ix; y = Iy; } LPoint(const LPoint &p) { x = p.x; y = p.y; } bool Inside(class LRect &r); LPoint operator +(const LPoint &p) { LPoint r; r.x = x + p.x; r.y = y + p.y; return r; } LPoint &operator +=(const LPoint &p) { x += p.x; y += p.y; return *this; } LPoint operator -(const LPoint &p) { LPoint r; r.x = x - p.x; r.y = y - p.y; return r; } LPoint &operator -=(const LPoint &p) { x -= p.x; y -= p.y; return *this; } LPoint &operator *=(int factor) { x *= factor; y *= factor; return *this; } LPoint &operator /=(int factor) { x /= factor; y /= factor; return *this; } bool operator ==(const LPoint &p) { return x == p.x && y == p.y; } bool operator !=(const LPoint &p) { return !(*this == p); } void Set(int X, int Y) { x = X; y = Y; } void Zero() { x = 0; y = 0; } LString GetStr() { LString s; s.Printf("%i,%i", x, y); return s; } bool SetStr(LString s) { auto p = s.SplitDelimit(" ,"); if (p.Length() != 2) return false; x = (int)p[0].Int(); y = (int)p[1].Int(); return true; } }; /// 3d Point class LgiClass LPoint3 { public: int x, y, z; }; class LgiClass LPointF { public: static double Threshold; double x, y; LPointF() { x = y = 0; } LPointF(double X, double Y) { x = X; y = Y; } LPointF(const LPointF &p) { x = p.x; y = p.y; } LPointF(const LPoint &p) { x = p.x; y = p.y; } LPointF &operator =(const LPointF &p) { x = p.x; y = p.y; return *this; } LPointF &operator -(const LPointF &p) { static LPointF Result; Result.x = x - p.x; Result.y = y - p.y; return Result; } LPointF &operator +(const LPointF &p) { static LPointF Result; Result.x = x + p.x; Result.y = y + p.y; return Result; } bool operator ==(const LPointF &p) { double dx = x - p.x; if (dx < 0) dx = -dx; double dy = y - p.y; if (dy < 0) dy = -dy; return dx #include "lgi/common/Lgi.h" #include "lgi/common/Panel.h" #include "lgi/common/DisplayString.h" #include "lgi/common/LgiRes.h" #include "lgi/common/CssTools.h" ////////////////////////////////////////////////////////////////////////////// LPanel::LPanel(const char *name, int size, bool open) { Ds = 0; if (name) Name(name); IsOpen = open; _IsToolBar = !IsOpen; ClosedSize = LSysFont->GetHeight() + 3; OpenSize = size; Align = GV_EDGE_TOP; _BorderSize = 1; Raised(true); LResources::StyleElement(this); } LPanel::~LPanel() { DeleteObj(Ds); } int LPanel::CalcWidth() { if (!Ds) Ds = new LDisplayString(GetFont(), Name()); return 30 + (Ds ? Ds->X() : 0); } bool LPanel::Open() { return IsOpen; } void LPanel::Open(bool i) { if (i != IsOpen) { IsOpen = i; _IsToolBar = !IsOpen; SetChildrenVisibility(IsOpen); RePour(); /* int ExStyle = GetWindowLong(Handle(), GWL_EXSTYLE); SetWindowLong( Handle(), GWL_EXSTYLE, (ExStyle & ~WS_EX_CONTROLPARENT) | (IsOpen ? WS_EX_CONTROLPARENT : 0)); */ } } int LPanel::Alignment() { return Align; } void LPanel::Alignment(int i) { Align = i; } int LPanel::GetClosedSize() { return ClosedSize; } void LPanel::SetClosedSize(int i) { ClosedSize = i; } int LPanel::GetOpenSize() { return OpenSize; } void LPanel::SetOpenSize(int i) { OpenSize = i; } bool LPanel::Attach(LViewI *Wnd) { bool Status = LLayout::Attach(Wnd); SetChildrenVisibility(IsOpen); if (Status) AttachChildren(); return Status; } bool LPanel::Pour(LRegion &r) { int Sx = CalcWidth(); LRect *Best = 0; if (Open()) { Best = FindLargest(r); } else { Best = FindSmallestFit(r, Sx, ClosedSize); if (!Best) { Best = FindLargest(r); } } if (Best) { LRect r = *Best; if (OpenSize > 0) { int Size = ((Open()) ? OpenSize : ClosedSize); int Limit = 30; if (TestFlag(Align, GV_EDGE_RIGHT) || TestFlag(Align, GV_EDGE_LEFT)) { Limit = MIN(Size, r.X()-1); } else /* if (TestFlag(Align, GV_EDGE_BOTTOM) || TextFlag(Align, GV_EDGE_TOP)) */ { Limit = MIN(Size, r.Y()-1); } if (Align & GV_EDGE_RIGHT) { r.x1 = r.x2 - Limit; } else if (Align & GV_EDGE_BOTTOM) { r.y1 = r.y2 - Limit; } else if (Align & GV_EDGE_LEFT) { r.x2 = r.x1 + Limit; } else // if (Align & GV_EDGE_TOP) { r.y2 = r.y1 + Limit; } if (!Open()) { r.x2 = r.x1 + Sx - 1; } } else { r.y2 = r.y1 - OpenSize; } SetPos(r, true); if (IsOpen) { for (auto v: Children) { auto css = v->GetCss(); if (css && css->Width() == LCss::LenAuto && css->Height() == LCss::LenAuto) { LRect c = GetClient(); LCssTools tools(css, v->GetFont()); c = tools.ApplyMargin(c); v->SetPos(c); break; } } } return true; } return false; } int LPanel::OnNotify(LViewI *Ctrl, LNotification n) { if (GetParent()) { return GetParent()->OnNotify(Ctrl, n); } return 0; } void LPanel::OnPaint(LSurface *pDC) { - LRect r = GetClient(); + auto r = GetClient(); LCssTools Tools(this); LColour cFore = Tools.GetFore(); LColour cBack = Tools.GetBack(); Tools.PaintContent(pDC, r); auto BackImg = Tools.GetBackImage(); auto Fnt = GetFont(); Fnt->Transparent(BackImg ? true : false); Fnt->Fore(cFore); Fnt->Back(cBack); if (!Open()) { // title if (!Ds) Ds = new LDisplayString(Fnt, Name()); if (Ds) Ds->Draw(pDC, r.x1 + 20, r.y1 + 1); } if (OpenSize > 0) { // Draw thumb - ThumbPos.ZOff(8, 8); + auto scale = GetWindow()->GetDpiScale(); + scale *= 1.2; + int gapPx = (int)(scale.x * 2); + ThumbPos.ZOff(8 * scale.x, 8 * scale.y); ThumbPos.Offset(r.x1 + 3, r.y1 + 3); pDC->Colour(L_LOW); pDC->Box(&ThumbPos); pDC->Colour(L_WHITE); pDC->Rectangle(ThumbPos.x1+1, ThumbPos.y1+1, ThumbPos.x2-1, ThumbPos.y2-1); pDC->Colour(L_SHADOW); - pDC->Line( ThumbPos.x1+2, - ThumbPos.y1+4, - ThumbPos.x1+6, - ThumbPos.y1+4); + + auto center = ThumbPos.Center(); + pDC->Line( ThumbPos.x1+gapPx, + center.y, + ThumbPos.x2-gapPx, + center.y); if (!Open()) { - pDC->Line( ThumbPos.x1+4, - ThumbPos.y1+2, - ThumbPos.x1+4, - ThumbPos.y1+6); + pDC->Line( center.x, + ThumbPos.y1+gapPx, + center.x, + ThumbPos.y2-gapPx); } } } void LPanel::OnMouseClick(LMouse &m) { if (OpenSize > 0 && m.Left() && - m.Down() && - ThumbPos.Overlap(m.x, m.y)) + m.Down()) { - Open(!IsOpen); - if (GetParent()) - OnNotify(this, LNotifyItemClick); + if (ThumbPos.Overlap(m.x, m.y)) + { + Open(!IsOpen); + if (GetParent()) + OnNotify(this, LNotifyItemClick); + } + else LgiTrace("%s:%i - Not over %i,%i - %s\n", _FL, m.x, m.y, ThumbPos.GetStr()); } } void LPanel::RePour() { - LWindow *Top = dynamic_cast(GetWindow()); - if (Top) - { + if (auto Top = GetWindow()) Top->PourAll(); - } } void LPanel::SetChildrenVisibility(bool i) { for (auto w: Children) { if (i && !w->IsAttached()) { w->Attach(this); } w->Visible(i); } }