More PainterExamples

git-svn-id: svn://ultimatepp.org/upp/trunk@898 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2009-02-23 17:49:43 +00:00
parent aa13fdbe63
commit daf2cece0d
9 changed files with 142 additions and 83 deletions

View file

@ -6,6 +6,20 @@ void Arc(Painter& sw)
sw.Move(400, 400).Arc(400, 400, 100, 100, 0.0, M_PI / 3).Fill(LtCyan()).Stroke(2, Black());
}
void SvgArc(Painter& sw)
{
sw.Path("M300,200 h-150 a150,150 0 1,0 150,-150 z").Fill(Red()).Stroke(5, Blue());
sw.Path("M275,175 v-150 a150,150 0 0,0 -150,150 z").Fill(Yellow()).Stroke(5, Blue());
sw.Path(
"M600,350 l 50,-25 "
"a25,25 -30 0,1 50,-25 l 50,-25 "
"a25,50 -30 0,1 50,-25 l 50,-25 "
"a25,75 -30 0,1 50,-25 l 50,-25 "
"a25,100 -30 0,1 50,-25 l 50,-25"
).Stroke(5, Red());
}
INITBLOCK {
RegisterExample("Arc example", Arc);
RegisterExample("SvgArc example", SvgArc);
}

View file

@ -1,51 +1,51 @@
#include "Examples.h"
#ifndef _DEBUG
void Big(Painter& sw)
{
int n = 0;
double sgn = 1;
for(int r = 400; r > 5; r -= 3) {
for(int i = 0; i < 400; i++) {
Pointf p = Polar(sgn * i * M_2PI / 400) * (double)r + Pointf(400, 400);
if(i)
sw.Line(p);
else
sw.Move(p);
sw.Line(Polar(sgn * (i * M_2PI / 400 + M_2PI / 800)) * ((double)r - 6) + Pointf(400, 400));
n += 2;
}
sw.Close();
sgn = -sgn;
}
sw.Fill(Black());
sw.Text(0, 0, "Elements: " + AsString(n), Arial(20)).Fill(Blue());
}
void BigStroke(Painter& sw)
{
int n = 0;
double r = 400;
int i = 0;
while(r > 5) {
Pointf p = Polar(i * M_2PI / 400) * r + Pointf(400, 400);
if(i)
sw.Line(p);
else
sw.Move(p);
sw.Line(Polar((i * M_2PI / 400 + M_2PI / 800)) * (r - 3) + Pointf(400, 400));
n += 2;
r = r - 0.01;
i++;
}
sw.Stroke(1, Black());
sw.Text(0, 0, "Elements: " + AsString(n), Arial(20)).Fill(Blue());
}
INITBLOCK {
RegisterExample("Really Big Polygon", Big);
RegisterExample("Really Big Stroke", BigStroke);
}
#endif
#include "Examples.h"
#ifndef _DEBUG
void Big(Painter& sw)
{
int n = 0;
double sgn = 1;
for(int r = 400; r > 5; r -= 3) {
for(int i = 0; i < 400; i++) {
Pointf p = Polar(sgn * i * M_2PI / 400) * r + Pointf(400, 400);
if(i)
sw.Line(p);
else
sw.Move(p);
sw.Line(Polar(sgn * (i * M_2PI / 400 + M_2PI / 800)) * (r - 6) + Pointf(400, 400));
n += 2;
}
sw.Close();
sgn = -sgn;
}
sw.Fill(Black());
sw.Text(0, 0, "Elements: " + AsString(n), Arial(20)).Fill(Blue());
}
void BigStroke(Painter& sw)
{
int n = 0;
double r = 400;
int i = 0;
while(r > 5) {
Pointf p = Polar(i * M_2PI / 400) * r + Pointf(400, 400);
if(i)
sw.Line(p);
else
sw.Move(p);
sw.Line(Polar((i * M_2PI / 400 + M_2PI / 800)) * (r - 3) + Pointf(400, 400));
n += 2;
r = r - 0.01;
i++;
}
sw.Stroke(1, Black());
sw.Text(0, 0, "Elements: " + AsString(n), Arial(20)).Fill(Blue());
}
INITBLOCK {
RegisterExample("Really Big Polygon", Big);
RegisterExample("Really Big Stroke", BigStroke);
}
#endif

View file

@ -10,7 +10,6 @@ void ClippingExample(Painter& sw)
sw.Text(0, 0, txt, fnt).Fill(Green());
sw.End();
sw.Text(0, 0, txt, fnt).Stroke(0.5, Black());
}
void NoClippingExample(Painter& sw)

View file

@ -1,9 +1,9 @@
LAYOUT(CtrlLayout, 196, 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(EditDoubleSpin, translate_x, Min(0).Max(2000).LeftPosZ(4, 64).TopPosZ(24, 19))
ITEM(SliderCtrl, translate_x_slider, HSizePosZ(72, 4).TopPosZ(22, 24))
ITEM(Label, dv___3, SetLabel(t_("Translate Y")).LeftPosZ(4, 72).TopPosZ(48, 19))
ITEM(EditDoubleSpin, translate_y, SetInc(1).Min(0).Max(2000).LeftPosZ(4, 64).TopPosZ(68, 19))
ITEM(EditDoubleSpin, translate_y, Min(0).Max(2000).LeftPosZ(4, 64).TopPosZ(68, 19))
ITEM(SliderCtrl, translate_y_slider, HSizePosZ(72, 4).TopPosZ(66, 24))
ITEM(Label, dv___6, SetLabel(t_("Rotate")).LeftPosZ(4, 52).TopPosZ(92, 19))
ITEM(EditDoubleSpin, rotate, Min(0).Max(6.29).LeftPosZ(4, 64).TopPosZ(112, 19))
@ -15,13 +15,15 @@ LAYOUT(CtrlLayout, 196, 344)
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).HSizePosZ(4, 128).TopPosZ(244, 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, 188).TopPosZ(268, 16))
ITEM(DropList, linejoin, LeftPosZ(4, 92).TopPosZ(288, 19))
ITEM(DropList, linecap, LeftPosZ(104, 88).TopPosZ(288, 19))
ITEM(Button, reset, SetLabel(t_("Reset")).HSizePosZ(4, 132).TopPosZ(316, 24))
ITEM(Button, print, SetLabel(t_("Print")).HSizePosZ(68, 68).TopPosZ(316, 24))
ITEM(Button, benchmark, SetLabel(t_("Benchmark")).HSizePosZ(132, 4).TopPosZ(316, 24))
ITEM(Option, painting, SetLabel(t_("Paint through Painting")).LeftPosZ(4, 128).TopPosZ(268, 20))
ITEM(DropList, linejoin, LeftPosZ(4, 100).BottomPosZ(33, 19))
ITEM(DropList, linecap, RightPosZ(4, 100).BottomPosZ(33, 19))
ITEM(Button, reset, SetLabel(t_("Reset")).LeftPosZ(4, 64).BottomPosZ(4, 24))
ITEM(Button, print, SetLabel(t_("Print")).HSizePosZ(72, 80).BottomPosZ(4, 24))
ITEM(Button, benchmark, SetLabel(t_("Benchmark")).RightPosZ(4, 72).BottomPosZ(4, 24))
ITEM(Switch, quality, SetLabel(t_("Antialiased\nNoAA\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

@ -34,5 +34,6 @@ file
Test.iml;
mainconfig
"" = "GUI";
"" = "GUI",
"" = "GUI SSE2";

View file

@ -7,6 +7,14 @@ void Radial(Painter& sw)
.Stroke(1, Black());
}
void FocusRadial(Painter& sw)
{
sw.Circle(400.5, 400.5, 200)
.Fill(300, 300, Blue(), 400.5, 400.5, 200, LtRed())
.Stroke(1, Black());
}
INITBLOCK {
RegisterExample("Radial gradient", Radial);
RegisterExample("Radial focus gradient", FocusRadial);
}

View file

@ -6,6 +6,44 @@ void TextFillSolid(Painter& sw)
.Fill(LtBlue());
}
const char *text = "Quick Brown Fox Jumps Over The Lazy Dog!";
void SomeTexts(Painter& sw)
{
int face[] = {
Font::ARIAL, Font::ROMAN, Font::COURIER
};
int height[] = {
10, 16, 20
};
sw.Rectangle(600, 0, 1000, 1000).Fill(Blue());
for(int x = 20; x < 1000; x += 600) {
double y = 20;
for(int h = 0; h < __countof(height); h++)
for(int italic = 0; italic < 2; italic++)
for(int bold = 0; bold < 2; bold++)
for(int c = 0; c < __countof(face); c++) {
sw.Text(x, y, text, Font().Face(face[c]).Height(height[h]).Italic(italic).Bold(bold))
.Fill(x == 20 ? Black() : White());
y += height[h] + 2;
}
}
}
void ZBug(Painter& sw)
{
sw.Text(100, 100, "z", Roman(25).Italic()).Fill(Black());
sw.Text(130, 100, "z", Roman(70).Italic()).Fill(Black());
}
void WBug(Painter& sw)
{
sw.Text(100, 100, "w", Roman(20).Bold()).Fill(Black());
}
INITBLOCK {
RegisterExample("Filling text with solid color", TextFillSolid);
RegisterExample("Various fonts", SomeTexts);
RegisterExample("ZBug", ZBug);
RegisterExample("WBug", WBug);
}

View file

@ -31,9 +31,11 @@ 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())
Examples()[list.GetCursor()].example(sw);
}
@ -67,7 +69,8 @@ void App::Benchmark()
time = GetTickCount();
if(time - time0 > 1000) break;
ImageBuffer ib(800, 600);
BufferPainter sw(ib);
BufferPainter sw(ib, ctrl.quality);
PAINTER_TIMING("Paint");
DoPaint(sw);
n++;
}
@ -76,8 +79,14 @@ void App::Benchmark()
void App::Paint(Draw& w)
{
ImageBuffer ib(GetSize());
BufferPainter sw(ib);
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,6 +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.quality = MODE_ANTIALIASED;
ctrl.linejoin <<= LINEJOIN_MITER;
ctrl.linecap <<= LINECAP_BUTT;
ToSlider();
@ -137,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.painting % ctrl.quality % ctrl.transparent
;
}
@ -167,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 <<= 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);