mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-10-06 00:30:10 -06:00
CtrlLib: Common chameleon support routines
git-svn-id: svn://ultimatepp.org/upp/trunk@13783 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
a96849db67
commit
78224198e8
2 changed files with 65 additions and 0 deletions
|
|
@ -90,4 +90,58 @@ void ChSysInit()
|
|||
|
||||
#endif
|
||||
|
||||
void FillImage(Painter& p, const Rectf& r, const Image& m)
|
||||
{
|
||||
Xform2D xform = Xform2D::Translation(r.left, r.top);
|
||||
Size isz = m.GetSize();
|
||||
xform = Xform2D::Scale(r.GetWidth() / isz.cx, r.GetHeight() / isz.cy) * xform;
|
||||
p.Fill(m, xform);
|
||||
}
|
||||
|
||||
void RoundedRect(Painter& w, double x, double y, double cx, double cy, double rx, double ry, dword corners)
|
||||
{
|
||||
if(corners & CORNER_TOP_LEFT)
|
||||
w.Move(x + rx, y).Arc(x + rx, y + ry, rx, ry, -M_PI / 2, -M_PI / 2);
|
||||
else
|
||||
w.Move(x, y);
|
||||
|
||||
if(corners & CORNER_BOTTOM_LEFT)
|
||||
w.Line(x, y + cy - ry).Arc(x + rx, y + cy - ry, rx, ry, M_PI, -M_PI / 2);
|
||||
else
|
||||
w.Line(x, y + cy);
|
||||
|
||||
if(corners & CORNER_BOTTOM_RIGHT)
|
||||
w.Line(x + cx - rx, y + cy).Arc(x + cx - rx, y + cy - ry, rx, ry, M_PI / 2, -M_PI / 2);
|
||||
else
|
||||
w.Line(x + cx, y + cy);
|
||||
|
||||
if(corners & CORNER_TOP_RIGHT)
|
||||
w.Line(x + cx, y + ry).Arc(x + cx - rx, y + ry, rx, ry, 0, -M_PI / 2);
|
||||
else
|
||||
w.Line(x + cx, y);
|
||||
|
||||
w.Close();
|
||||
}
|
||||
|
||||
void RoundedRect(Painter& w, Rectf r, double rx, double ry, dword corner)
|
||||
{
|
||||
RoundedRect(w, r.left, r.top, r.GetWidth(), r.GetHeight(), rx, ry, corner);
|
||||
}
|
||||
|
||||
Image MakeButton(int radius, const Image& face, int border_width, Color border_color, dword corner)
|
||||
{
|
||||
int q = radius + border_width + 16;
|
||||
Rectf r(0, 0, q, q);
|
||||
ImagePainter w(r.GetSize());
|
||||
w.Clear(RGBAZero());
|
||||
RoundedRect(w, r.Deflated(border_width - 1), radius, radius, corner);
|
||||
FillImage(w, r.Deflated(border_width - 1), face);
|
||||
RoundedRect(w, r.Deflated(border_width / 2.0), radius, radius, corner);
|
||||
w.Stroke(border_width, border_color);
|
||||
Image m = w;
|
||||
Point p1(radius, radius);
|
||||
SetHotSpots(m, p1, (Point)r.BottomRight() - p1);
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue