From b556ccca12c91a16499cc254ef8aef172e47ca81 Mon Sep 17 00:00:00 2001 From: cxl Date: Sun, 15 Feb 2009 22:34:47 +0000 Subject: [PATCH] New painter examples git-svn-id: svn://ultimatepp.org/upp/trunk@869 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- examples/PainterExamples/Arc.cpp | 11 ++++ examples/PainterExamples/Big.cpp | 51 +++++++++++++++++++ examples/PainterExamples/Clipping.cpp | 24 +++++++++ examples/PainterExamples/Dash.cpp | 18 +++++++ examples/PainterExamples/Div.cpp | 17 +++++++ examples/PainterExamples/Examples.h | 2 +- examples/PainterExamples/Image.cpp | 27 ++++++++-- examples/PainterExamples/Lion.cpp | 16 +++++- examples/PainterExamples/MaskBlending.cpp | 1 - examples/PainterExamples/PainterExamples.upp | 6 ++- examples/PainterExamples/Path.cpp | 2 +- examples/PainterExamples/Pythagoras.cpp | 6 +-- examples/PainterExamples/RadialFocus.cpp | 4 +- examples/PainterExamples/Stroke.cpp | 2 +- examples/PainterExamples/TextFillGradient.cpp | 1 + examples/PainterExamples/ThinLine.cpp | 1 - examples/PainterExamples/main.cpp | 3 +- 17 files changed, 176 insertions(+), 16 deletions(-) create mode 100644 examples/PainterExamples/Arc.cpp create mode 100644 examples/PainterExamples/Big.cpp create mode 100644 examples/PainterExamples/Dash.cpp create mode 100644 examples/PainterExamples/Div.cpp diff --git a/examples/PainterExamples/Arc.cpp b/examples/PainterExamples/Arc.cpp new file mode 100644 index 000000000..337278696 --- /dev/null +++ b/examples/PainterExamples/Arc.cpp @@ -0,0 +1,11 @@ +#include "Examples.h" + +void Arc(Painter& sw) +{ + sw.Move(400, 200).Arc(400, 200, 200, 100, 0.0, M_PI).Stroke(4, Blue()); + sw.Move(400, 400).Arc(400, 400, 100, 100, 0.0, M_PI / 3).Fill(LtCyan()).Stroke(2, Black()); +} + +INITBLOCK { + RegisterExample("Arc example", Arc); +} diff --git a/examples/PainterExamples/Big.cpp b/examples/PainterExamples/Big.cpp new file mode 100644 index 000000000..06cd3dd01 --- /dev/null +++ b/examples/PainterExamples/Big.cpp @@ -0,0 +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) * 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 \ No newline at end of file diff --git a/examples/PainterExamples/Clipping.cpp b/examples/PainterExamples/Clipping.cpp index e6cc85020..70c35cf13 100644 --- a/examples/PainterExamples/Clipping.cpp +++ b/examples/PainterExamples/Clipping.cpp @@ -10,8 +10,32 @@ 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) +{ + Font fnt = Roman(150).Bold(); + String txt = "CLIPPED!"; + Size tsz = GetTextSize(txt, fnt); + sw.Text(0, 0, txt, fnt).Fill(Green()); + sw.Text(0, 0, txt, fnt).Stroke(0.5, Black()); +} + +void ClippingExample2(Painter& sw) +{ + sw.Begin(); + sw.Ellipse(200, 200, 200, 200).Stroke(2, Red()).Clip(); + sw.Begin(); + sw.Ellipse(200, 200, 100, 300).Clip().Stroke(2, Red()); + sw.Text(0, 0, "CL", Arial(360).Bold()).Fill(Blue()); + sw.End(); + sw.Text(0, 0, "CL", Arial(360).Bold()).Opacity(0.4).Fill(Black()); + sw.End(); } INITBLOCK { RegisterExample("Clipping", ClippingExample); + RegisterExample("Clipping removed (to benchmark) ", NoClippingExample); + RegisterExample("Clipping 2", ClippingExample2); } diff --git a/examples/PainterExamples/Dash.cpp b/examples/PainterExamples/Dash.cpp new file mode 100644 index 000000000..9a490dcce --- /dev/null +++ b/examples/PainterExamples/Dash.cpp @@ -0,0 +1,18 @@ +#include "Examples.h" + +void Dash(Painter& sw) +{ + sw.Move(50, 50).Line(400, 200).Dash("2").Stroke(5, Blue()); + sw.Translate(0, 10); + sw.Move(50, 50).Line(400, 200).Dash("10 5").Stroke(5, Blue()); + sw.Translate(0, 10); + sw.Move(50, 50).Line(400, 200).Dash("10 5 5 5").Stroke(5, Blue()); + sw.Translate(0, 10); + sw.Move(50, 50).Line(400, 200).Dash("1").Stroke(5, Blue()); + sw.Translate(0, 10); + sw.Move(50, 50).Line(400, 200).Dash("1 2 3 4 5").Stroke(5, Blue()); +} + +INITBLOCK { + RegisterExample("Dash test", Dash); +} diff --git a/examples/PainterExamples/Div.cpp b/examples/PainterExamples/Div.cpp new file mode 100644 index 000000000..12d5d6abb --- /dev/null +++ b/examples/PainterExamples/Div.cpp @@ -0,0 +1,17 @@ +#include "Examples.h" + +void Div(Painter& sw) +{ + sw.Character(100, 100, 'O', Arial(100)) + .Character(100, 150, 'O', Arial(100)) + .Fill(Black()); + sw.Translate(200, 0); + sw.Character(100, 100, 'O', Arial(100)) + .Div() + .Character(100, 150, 'O', Arial(100)) + .Fill(Black()); +} + +INITBLOCK { + RegisterExample("Div", Div); +} diff --git a/examples/PainterExamples/Examples.h b/examples/PainterExamples/Examples.h index e2cfe9c42..10f1688d3 100644 --- a/examples/PainterExamples/Examples.h +++ b/examples/PainterExamples/Examples.h @@ -23,7 +23,7 @@ struct App : TopWindow { FrameBottom< WithCtrlLayout > ctrl; typedef App CLASSNAME; - + void DoPaint0(Painter& sw); void DoPaint(Painter& sw); void Print(); diff --git a/examples/PainterExamples/Image.cpp b/examples/PainterExamples/Image.cpp index 1b65205ad..24b99e4f6 100644 --- a/examples/PainterExamples/Image.cpp +++ b/examples/PainterExamples/Image.cpp @@ -1,18 +1,30 @@ #include "Examples.h" - void ImageExact(Painter& sw) { sw.Rectangle(10, 10, 1000, 600) -// .Fill(TestImg::test(), 200, 100, 300, 300) _DBG_ .Fill(TestImg::test(), 100, 100, 500, 100) .Stroke(2, Black()); } +void ImageExactFast(Painter& sw) +{ + sw.Rectangle(10, 10, 1000, 600) + .Fill(TestImg::test(), 100, 100, 500, 100, FILL_FAST) + .Stroke(2, Black()); +/* + int cx = 400; + for(int l = 0; l < 5; l++) { + sw.Translate(cx, 0); + cx /= 2; + sw.Rectangle(10, 10, 1000, 600) + .Fill(MakeMipMap(TestImg::test(), l), 100, 100, 100 + cx, 100, FILL_FAST); + }*/ +} + void ImageReflect(Painter& sw) { sw.Rectangle(10, 10, 1000, 600) -// .Fill(TestImg::test(), 200, 100, 300, 300, GRADIENT_REFLECT) _DBG_ .Fill(TestImg::test(), 100, 100, 500, 100, FILL_REFLECT) .Stroke(2, Black()); } @@ -31,6 +43,13 @@ void ImagePad(Painter& sw) .Stroke(2, Black()); } +void ImagePadFast(Painter& sw) +{ + sw.Rectangle(10, 10, 1000, 600) + .Fill(TestImg::test(), 100, 100, 500, 100, FILL_PAD|FILL_FAST) + .Stroke(2, Black()); +} + void ImageRepeat(Painter& sw) { sw.Rectangle(10, 10, 1000, 600) @@ -40,8 +59,10 @@ void ImageRepeat(Painter& sw) INITBLOCK { RegisterExample("Image fill exact", ImageExact); + RegisterExample("Image fill exact fast", ImageExactFast); RegisterExample("Image fill reflect", ImageReflect); RegisterExample("Image fill pad", ImagePad); + RegisterExample("Image fill pad fast", ImagePadFast); RegisterExample("Image fill repeat", ImageRepeat); RegisterExample("Image vpad&hreflect", ImageVPadHReflect); } diff --git a/examples/PainterExamples/Lion.cpp b/examples/PainterExamples/Lion.cpp index 5cf83000b..99eb2f5ed 100644 --- a/examples/PainterExamples/Lion.cpp +++ b/examples/PainterExamples/Lion.cpp @@ -188,7 +188,19 @@ void PaintLion(Painter& sw) sw.Fill(l[i].color); } } - + +void PaintLionNoAA(Painter& sw) +{ + static Vector l = Lion(); + for(int i = 0; i < l.GetCount(); i++) { + Vector& 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); @@ -199,7 +211,6 @@ void Demo(Painter& sw) .Fill(TestImg::test(), 0, 400, 500, 400, FILL_REFLECT) .Stroke(5, 0, 500, Blue(), tsz.cx, 500, LtRed()) .Stroke(1, White()); - for(int i = 0; i < 10; i++) { sw.Begin(); sw.Opacity(0.5); @@ -213,5 +224,6 @@ void Demo(Painter& sw) INITBLOCK { RegisterExample("Lion", PaintLion); + RegisterExample("Lion NoAA", PaintLionNoAA); RegisterExample("U++ Painter", Demo); } diff --git a/examples/PainterExamples/MaskBlending.cpp b/examples/PainterExamples/MaskBlending.cpp index 74d8d73ae..1d5ccd1e8 100644 --- a/examples/PainterExamples/MaskBlending.cpp +++ b/examples/PainterExamples/MaskBlending.cpp @@ -23,4 +23,3 @@ void MaskBlending(Painter& sw) INITBLOCK { RegisterExample("Blending using alpha mask", MaskBlending); } - diff --git a/examples/PainterExamples/PainterExamples.upp b/examples/PainterExamples/PainterExamples.upp index ea45bb7d7..0320a9ffa 100644 --- a/examples/PainterExamples/PainterExamples.upp +++ b/examples/PainterExamples/PainterExamples.upp @@ -1,4 +1,4 @@ -description "Antialiased renderer class, Painter, examples"; +description "Antialiased renderer class, Painter, examples, version 2.0"; uses CtrlLib, @@ -20,12 +20,16 @@ file TextFillSolid.cpp, TextFillGradient.cpp, TextStrokeGradient.cpp, + Div.cpp, MaskBlending.cpp, RadialMaskBlending.cpp, RichText.cpp, Stroke.cpp, + Dash.cpp, Path.cpp, + Arc.cpp, ThinLine.cpp, + Big.cpp, Examples.lay, Test.iml; diff --git a/examples/PainterExamples/Path.cpp b/examples/PainterExamples/Path.cpp index f3c23f1ab..3d5f7ab2d 100644 --- a/examples/PainterExamples/Path.cpp +++ b/examples/PainterExamples/Path.cpp @@ -1,5 +1,5 @@ #include "Examples.h" - + void Path(Painter& sw) { sw.Translate(52, 52); diff --git a/examples/PainterExamples/Pythagoras.cpp b/examples/PainterExamples/Pythagoras.cpp index f45079d78..5052e5865 100644 --- a/examples/PainterExamples/Pythagoras.cpp +++ b/examples/PainterExamples/Pythagoras.cpp @@ -4,7 +4,7 @@ void DoRect(Painter &sw, double size, bool image) { if(size < 1) return; - + sw.Move(0, 0); sw.Line(0, size); sw.Line(size, size); @@ -16,13 +16,13 @@ void DoRect(Painter &sw, double size, bool image) sw.Begin(); sw.Translate(0, size); - sw.Rotate(M_PI/4.); + sw.Rotate(M_PI/4.0); DoRect(sw, size / M_SQRT2, image); sw.End(); sw.Begin(); sw.Translate(size / 2, 1.5 * size); - sw.Rotate(-M_PI/4.); + sw.Rotate(-M_PI/4.0); DoRect(sw, size / M_SQRT2, image); sw.End(); } diff --git a/examples/PainterExamples/RadialFocus.cpp b/examples/PainterExamples/RadialFocus.cpp index a75a2ff44..ea83da850 100644 --- a/examples/PainterExamples/RadialFocus.cpp +++ b/examples/PainterExamples/RadialFocus.cpp @@ -1,11 +1,13 @@ #include "Examples.h" +#if 0 void RadialFocus(Painter& sw) { sw.Circle(400.5, 400.5, 200) .Fill(300, 300, White(), 400.5, 400.5, 200, LtBlue()) ; } +#endif void RadialFocusPad(Painter& sw) { @@ -32,7 +34,7 @@ void RadialFocusRepeat(Painter& sw) } INITBLOCK { - RegisterExample("Radial gradient - focus", RadialFocus); +// RegisterExample("Radial gradient - focus", RadialFocus); RegisterExample("Radial gradient - focus - PAD", RadialFocusPad); RegisterExample("Radial gradient - focus - REFLECT", RadialFocusReflect); RegisterExample("Radial gradient - focus - REPEAT", RadialFocusRepeat); diff --git a/examples/PainterExamples/Stroke.cpp b/examples/PainterExamples/Stroke.cpp index b9ac595ed..fbcf502aa 100644 --- a/examples/PainterExamples/Stroke.cpp +++ b/examples/PainterExamples/Stroke.cpp @@ -2,7 +2,7 @@ void Stroke(Painter& sw) { - const char *txt = "GRM";//ADIENT TEXT"; + const char *txt = "GRM"; Font fnt = Arial(100).Bold(); Size tsz = GetTextSize(txt, fnt); sw.Scale(3, 3); diff --git a/examples/PainterExamples/TextFillGradient.cpp b/examples/PainterExamples/TextFillGradient.cpp index 19975d37e..04fe29b7c 100644 --- a/examples/PainterExamples/TextFillGradient.cpp +++ b/examples/PainterExamples/TextFillGradient.cpp @@ -7,6 +7,7 @@ void TextFillGradient(Painter& sw) Size tsz = GetTextSize(txt, fnt); sw.Text(100, 100, txt, fnt) .Fill(100, 100, Blue(), 100 + tsz.cx, 100 + tsz.cy, LtRed()); + sw.Translate(0, 200); } INITBLOCK { diff --git a/examples/PainterExamples/ThinLine.cpp b/examples/PainterExamples/ThinLine.cpp index f7795344d..3af25d24f 100644 --- a/examples/PainterExamples/ThinLine.cpp +++ b/examples/PainterExamples/ThinLine.cpp @@ -1,5 +1,4 @@ #include "Examples.h" - void ThinPolygon(Painter& sw) { diff --git a/examples/PainterExamples/main.cpp b/examples/PainterExamples/main.cpp index 58e5a9eb8..1f3551856 100644 --- a/examples/PainterExamples/main.cpp +++ b/examples/PainterExamples/main.cpp @@ -31,7 +31,7 @@ void App::DoPaint0(Painter& sw) sw.LineCap(~ctrl.linecap); sw.LineJoin(~ctrl.linejoin); { PAINTER_TIMING("FILL"); - sw.Clear(White()); + sw.Clear(White()); } PAINTER_TIMING("Paint"); if(list.IsCursor()) @@ -173,6 +173,7 @@ App::App() { ctrl.print <<= THISBACK(Print); Reset(); LoadFromFile(*this); + Title("Painter 2.0"); } App::~App()