PainterExamples: New tests

git-svn-id: svn://ultimatepp.org/upp/trunk@884 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-02-22 09:31:23 +00:00
parent 7db4871131
commit 6189510565
4 changed files with 54 additions and 36 deletions

View file

@ -1,4 +1,4 @@
LAYOUT(CtrlLayout, 212, 344)
LAYOUT(CtrlLayout, 212, 384)
ITEM(Label, dv___0, SetLabel(t_("Translate X")).LeftPosZ(4, 72).TopPosZ(4, 19))
ITEM(EditDoubleSpin, translate_x, SetInc(1).Min(0).Max(2000).LeftPosZ(4, 64).TopPosZ(24, 19))
ITEM(SliderCtrl, translate_x_slider, HSizePosZ(72, 4).TopPosZ(22, 24))
@ -9,20 +9,21 @@ LAYOUT(CtrlLayout, 212, 344)
ITEM(EditDoubleSpin, rotate, Min(0).Max(6.29).LeftPosZ(4, 64).TopPosZ(112, 19))
ITEM(SliderCtrl, rotate_slider, HSizePosZ(72, 4).TopPosZ(110, 24))
ITEM(Label, dv___9, SetLabel(t_("Scale")).LeftPosZ(4, 52).TopPosZ(136, 19))
ITEM(EditDoubleSpin, scale, Min(0).Max(3).LeftPosZ(4, 64).VSizePosZ(156, 169))
ITEM(SliderCtrl, scale_slider, HSizePosZ(72, 4).VSizePosZ(154, 166))
ITEM(Label, dv___12, SetLabel(t_("Scale X")).LeftPosZ(4, 52).BottomPosZ(145, 19))
ITEM(EditDoubleSpin, scale_x, Min(0).Max(2).LeftPosZ(4, 64).BottomPosZ(125, 19))
ITEM(SliderCtrl, scale_x_slider, HSizePosZ(72, 4).BottomPosZ(122, 24))
ITEM(Label, dv___15, SetLabel(t_("Opacity")).LeftPosZ(4, 52).BottomPosZ(101, 19))
ITEM(EditDoubleSpin, opacity, SetInc(0.05).Min(0).Max(1).LeftPosZ(4, 80).BottomPosZ(81, 19))
ITEM(SliderCtrl, opacity_slider, HSizePosZ(72, 4).BottomPosZ(78, 24))
ITEM(Option, painting, SetLabel(t_("Paint through Painting")).HSizePosZ(4, 80).BottomPosZ(60, 16))
ITEM(DropList, linejoin, LeftPosZ(4, 92).BottomPosZ(37, 19))
ITEM(DropList, linecap, HSizePosZ(104, 20).BottomPosZ(37, 19))
ITEM(Button, reset, SetLabel(t_("Reset")).LeftPosZ(4, 52).BottomPosZ(4, 24))
ITEM(Button, print, SetLabel(t_("Print")).HSizePosZ(60, 92).BottomPosZ(4, 24))
ITEM(Button, benchmark, SetLabel(t_("Benchmark")).RightPosZ(4, 60).BottomPosZ(4, 24))
ITEM(Option, subpixel, SetLabel(t_("Subpixel")).LeftPosZ(144, 64).TopPosZ(268, 16))
ITEM(EditDoubleSpin, scale, Min(0).Max(3).LeftPosZ(4, 64).TopPosZ(156, 19))
ITEM(SliderCtrl, scale_slider, HSizePosZ(72, 4).TopPosZ(154, 24))
ITEM(Label, dv___12, SetLabel(t_("Scale X")).LeftPosZ(4, 52).TopPosZ(180, 19))
ITEM(EditDoubleSpin, scale_x, Min(0).Max(2).LeftPosZ(4, 64).TopPosZ(200, 19))
ITEM(SliderCtrl, scale_x_slider, HSizePosZ(72, 4).TopPosZ(198, 24))
ITEM(Label, dv___15, SetLabel(t_("Opacity")).LeftPosZ(4, 52).TopPosZ(224, 19))
ITEM(EditDoubleSpin, opacity, SetInc(0.05).Min(0).Max(1).LeftPosZ(4, 64).TopPosZ(244, 19))
ITEM(SliderCtrl, opacity_slider, HSizePosZ(72, 4).TopPosZ(242, 24))
ITEM(Option, painting, SetLabel(t_("Paint through Painting")).LeftPosZ(4, 128).TopPosZ(268, 20))
ITEM(DropList, linejoin, LeftPosZ(4, 100).TopPosZ(332, 19))
ITEM(DropList, linecap, LeftPosZ(108, 100).TopPosZ(332, 19))
ITEM(Button, reset, SetLabel(t_("Reset")).LeftPosZ(4, 64).TopPosZ(356, 24))
ITEM(Button, print, SetLabel(t_("Print")).LeftPosZ(72, 60).TopPosZ(356, 24))
ITEM(Button, benchmark, SetLabel(t_("Benchmark")).LeftPosZ(136, 72).TopPosZ(356, 24))
ITEM(Switch, quality, SetLabel(t_("NoAA\nAntialiased\nSubpixel")).LeftPosZ(4, 204).TopPosZ(312, 16))
ITEM(Option, transparent, SetLabel(t_("Transparent background")).LeftPosZ(4, 204).TopPosZ(288, 20))
END_LAYOUT

View file

@ -189,18 +189,6 @@ void PaintLion(Painter& sw)
}
}
void PaintLionNoAA(Painter& sw)
{
static Vector<ColorPolygon> l = Lion();
for(int i = 0; i < l.GetCount(); i++) {
Vector<Pointf>& p = l[i].point;
sw.Move(p[0].x, p[0].y);
for(int j = 1; j < p.GetCount(); j++)
sw.Line(p[j].x, p[j].y);
sw.NoAA().Fill(l[i].color);
}
}
void Demo(Painter& sw)
{
PaintLion(sw);
@ -224,6 +212,5 @@ void Demo(Painter& sw)
INITBLOCK {
RegisterExample("Lion", PaintLion);
RegisterExample("Lion NoAA", PaintLionNoAA);
RegisterExample("U++ Painter", Demo);
}

View file

@ -6,6 +6,27 @@ void TextFillSolid(Painter& sw)
.Fill(LtBlue());
}
const char *text = "Quick Brown Fox Jumps Over The Lazy Dog!";
void SomeTexts(Painter& sw)
{
double y = 20;
Font fnt[] = {
Arial(10), Arial(16), Arial(24),
Arial(10).Italic(), Arial(16).Italic(), Arial(24).Italic(),
Roman(10), Roman(16), Roman(24),
Roman(10).Italic(), Roman(16).Italic(), Roman(24).Italic(),
Courier(10), Courier(16), Courier(24),
Courier(10).Italic(), Courier(16).Italic(), Courier(24).Italic(),
};
for(int i = 0; i < __countof(fnt); i++) {
Font f = fnt[i];
sw.Text(20, y, text, f).Fill(Black());
y += f.GetHeight();
}
}
INITBLOCK {
RegisterExample("Filling text with solid color", TextFillSolid);
RegisterExample("Various fonts", SomeTexts);
}

View file

@ -31,7 +31,10 @@ void App::DoPaint0(Painter& sw)
sw.LineCap(~ctrl.linecap);
sw.LineJoin(~ctrl.linejoin);
{ PAINTER_TIMING("FILL");
sw.Clear(White());
if(ctrl.transparent)
sw.Clear(RGBAZero());
else
sw.Clear(White());
}
PAINTER_TIMING("Paint");
if(list.IsCursor())
@ -67,7 +70,7 @@ void App::Benchmark()
time = GetTickCount();
if(time - time0 > 1000) break;
ImageBuffer ib(800, 600);
BufferPainter sw(ib, ctrl.subpixel);
BufferPainter sw(ib, ctrl.quality);
DoPaint(sw);
n++;
}
@ -76,8 +79,14 @@ void App::Benchmark()
void App::Paint(Draw& w)
{
ImageBuffer ib(GetSize());
BufferPainter sw(ib, ctrl.subpixel);
Size sz = GetSize();
if(ctrl.transparent) {
for(int y = 0; y + 32 < sz.cy; y += 32)
for(int x = 0; x + 32 < sz.cx; x += 32)
w.DrawRect(x, y, 32, 32, (x ^ y) & 32 ? Color(254, 172, 120) : Color(124, 135, 253));
}
ImageBuffer ib(sz);
BufferPainter sw(ib, ctrl.quality);
DoPaint(sw);
w.DrawImage(0, 0, ib);
}
@ -123,7 +132,7 @@ void App::Reset()
ctrl.rotate <<= ctrl.translate_x <<= ctrl.translate_y <<= 0;
ctrl.scale <<= ctrl.scale_x <<= ctrl.opacity <<= 1.0;
ctrl.painting = false;
ctrl.subpixel = false;
ctrl.quality = QUALITY_ANTIALIASED;
ctrl.linejoin <<= LINEJOIN_MITER;
ctrl.linecap <<= LINECAP_BUTT;
ToSlider();
@ -138,7 +147,7 @@ void App::Serialize(Stream& s)
% ctrl.translate_x % ctrl.translate_x_slider
% ctrl.translate_y % ctrl.translate_y_slider
% ctrl.opacity % ctrl.opacity_slider
% ctrl.painting % ctrl.subpixel
% ctrl.painting % ctrl.quality % ctrl.transparent
;
}
@ -168,7 +177,7 @@ App::App() {
ctrl.linejoin.Add(LINEJOIN_MITER, "Miter joins");
ctrl.linejoin.Add(LINEJOIN_ROUND, "Round joins");
ctrl.linejoin.Add(LINEJOIN_BEVEL, "Bevel joins");
ctrl.linecap <<= ctrl.linejoin <<= ctrl.painting <<= ctrl.subpixel <<= THISBACK(Sync);
ctrl.linecap <<= ctrl.linejoin <<= ctrl.painting <<= ctrl.quality <<= ctrl.transparent <<= THISBACK(Sync);
ctrl.reset <<= THISBACK(Reset);
ctrl.benchmark <<= THISBACK(Benchmark);
ctrl.print <<= THISBACK(Print);