mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-15 06:05:58 -06:00
PainterExamles: OnPath
git-svn-id: svn://ultimatepp.org/upp/trunk@928 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
acf40cf6c3
commit
37b9997f7b
6 changed files with 133 additions and 66 deletions
|
|
@ -1,51 +1,51 @@
|
|||
#include "Examples.h"
|
||||
|
||||
#ifndef _DEBUG
|
||||
|
||||
void Big(Painter& sw)
|
||||
{
|
||||
int n = 0;
|
||||
double sgn = 1;
|
||||
for(double 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
|
||||
#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
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
LAYOUT(CtrlLayout, 212, 384)
|
||||
ITEM(Label, dv___0, SetLabel(t_("Translate X")).LeftPosZ(4, 72).TopPosZ(4, 19))
|
||||
ITEM(EditDoubleSpin, translate_x, Min(0).Max(2000).LeftPosZ(4, 64).TopPosZ(24, 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))
|
||||
ITEM(Label, dv___3, SetLabel(t_("Translate Y")).LeftPosZ(4, 72).TopPosZ(48, 19))
|
||||
ITEM(EditDoubleSpin, translate_y, Min(0).Max(2000).LeftPosZ(4, 64).TopPosZ(68, 19))
|
||||
ITEM(EditDoubleSpin, translate_y, SetInc(1).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))
|
||||
|
|
|
|||
58
examples/PainterExamples/OnPath.cpp
Normal file
58
examples/PainterExamples/OnPath.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#include "Examples.h"
|
||||
|
||||
void OnPath(Painter& sw)
|
||||
{
|
||||
sw.Move(200, 300).Quadratic(400, 50, 600, 300).Quadratic(1000, 300).Stroke(1, Blue());
|
||||
for(int i = -1; i <= 16; i++) {
|
||||
sw.BeginOnPath(i / 15.0);
|
||||
sw.Move(0, -6).Line(6, 0).Line(0, 6).Close().Stroke(1, Black());
|
||||
sw.End();
|
||||
}
|
||||
}
|
||||
|
||||
void OnTextPath(Painter& sw)
|
||||
{
|
||||
sw.Text(50, 50, "Hello!", Roman(350)).Stroke(1, Black());
|
||||
for(int i = 0; i <= 100; i++) {
|
||||
sw.BeginOnPath(i / 100.0);
|
||||
sw.Move(0, -6).Line(6, 0).Line(0, 6).Fill(Red());
|
||||
sw.End();
|
||||
}
|
||||
}
|
||||
|
||||
void OnPathBee(Painter& sw)
|
||||
{
|
||||
sw.Move(200, 300).Quadratic(400, 50, 600, 300).Quadratic(1000, 300).Stroke(1, Blue());
|
||||
for(int i = -1; i <= 16; i++) {
|
||||
sw.BeginOnPath(i / 15.0);
|
||||
sw.DrawImage(0, -TestImg::Bee().GetHeight() / 2, TestImg::Bee());
|
||||
sw.End();
|
||||
}
|
||||
}
|
||||
|
||||
void TextOnPath(Painter& sw)
|
||||
{
|
||||
Font fnt = Roman(100);
|
||||
FontInfo fi = fnt.Info();
|
||||
double pos = 0;
|
||||
const char *s = "Hello world, this is text on path!";
|
||||
int l = GetTextSize(s, fnt).cx;
|
||||
double r = l / (2 * M_PI);
|
||||
sw.Circle(300, 300, r).Stroke(1, Red());
|
||||
while(*s) {
|
||||
double w = fi[*s];
|
||||
sw.BeginOnPath(pos + w / 2, true);
|
||||
sw.Character(-w / 2, -fi.GetAscent(), *s++, fnt)
|
||||
.Fill(0, -fi.GetAscent(), Yellow(), 0, fi.GetDescent(), Blue())
|
||||
.Stroke(1, Black());
|
||||
sw.End();
|
||||
pos += w;
|
||||
}
|
||||
}
|
||||
|
||||
INITBLOCK {
|
||||
RegisterExample("OnPath", OnPath);
|
||||
RegisterExample("OnTextPath", OnTextPath);
|
||||
RegisterExample("OnPathBee", OnPathBee);
|
||||
RegisterExample("TextOnPath", TextOnPath);
|
||||
}
|
||||
|
|
@ -25,6 +25,7 @@ file
|
|||
RadialMaskBlending.cpp,
|
||||
RichText.cpp,
|
||||
Stroke.cpp,
|
||||
OnPath.cpp,
|
||||
Dash.cpp,
|
||||
Path.cpp,
|
||||
Arc.cpp,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
PREMULTIPLIED
|
||||
IMAGE_ID(test)
|
||||
IMAGE_ID(Arrow)
|
||||
IMAGE_ID(Bee)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,172,189,7,119,20,89,210,181,251,125,191,250,254,129,251,206,116,3,13,13,52,86,222,33,36,156,64,32,16,242)
|
||||
|
|
@ -13911,3 +13913,22 @@ IMAGE_DATA(140,59,196,235,151,13,213,239,116,182,212,128,96,93,25,149,211,155,15
|
|||
IMAGE_DATA(225,124,154,248,57,110,121,53,102,178,206,114,14,6,242,121,81,243,57,231,67,206,220,237,229,215,70,25,156,147,188,252)
|
||||
IMAGE_DATA(255,213,165,31,190,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
|
||||
IMAGE_END_DATA(445056, 1)
|
||||
|
||||
IMAGE_BEGIN_DATA
|
||||
IMAGE_DATA(120,156,237,212,223,75,147,81,28,199,241,231,47,8,137,34,232,135,20,51,218,180,109,68,65,37,78,246,76,45,98,83)
|
||||
IMAGE_DATA(123,44,93,225,42,182,199,49,165,229,30,199,126,20,209,99,133,142,32,43,83,204,209,212,98,185,48,218,114,153,209,69)
|
||||
IMAGE_DATA(221,246,15,8,253,3,221,116,217,159,240,110,12,26,38,27,107,103,221,4,158,155,3,7,94,231,123,126,126,164,6,169)
|
||||
IMAGE_DATA(65,218,212,144,234,107,212,57,7,91,122,81,47,58,199,191,216,255,182,223,246,255,167,223,33,53,214,90,172,214,130,248)
|
||||
IMAGE_DATA(79,31,36,214,118,168,22,139,210,99,166,95,105,70,239,216,91,147,115,187,173,104,193,14,52,215,17,230,6,90,254,198)
|
||||
IMAGE_DATA(50,60,210,74,95,191,133,160,106,39,161,117,242,176,107,103,53,199,244,147,0,87,125,50,90,180,155,165,69,149,27,222)
|
||||
IMAGE_DATA(54,210,174,93,85,221,248,248,121,162,113,133,17,255,69,194,163,54,30,220,83,120,123,97,119,85,119,247,118,193,12,119)
|
||||
IMAGE_DATA(18,47,212,155,184,239,32,161,187,121,55,184,175,146,43,142,191,120,25,98,45,31,43,152,62,50,153,201,130,235,101,97)
|
||||
IMAGE_DATA(214,71,86,45,235,248,242,41,196,106,246,58,239,243,26,249,85,141,204,114,132,212,98,136,185,25,55,159,179,81,210,234)
|
||||
IMAGE_DATA(129,178,238,67,78,231,227,155,8,107,175,194,172,164,34,188,94,138,49,51,27,32,189,224,97,121,74,97,94,61,90,113)
|
||||
IMAGE_DATA(157,211,99,14,230,67,237,248,100,3,99,189,38,166,18,97,82,207,188,60,141,59,42,154,160,243,20,223,116,27,57,213)
|
||||
IMAGE_DATA(74,206,127,152,141,91,102,46,181,218,25,116,25,25,56,99,36,218,109,249,185,197,146,185,115,133,201,115,199,216,184,105)
|
||||
IMAGE_DATA(102,212,222,204,247,9,3,235,67,38,116,167,204,99,143,17,135,117,15,73,239,73,2,114,211,230,186,36,175,157,32,235)
|
||||
IMAGE_DATA(179,145,244,152,8,186,100,126,60,50,243,252,178,133,149,161,179,124,13,26,232,178,238,167,221,216,136,124,188,133,30,167)
|
||||
IMAGE_DATA(243,183,21,118,130,235,20,61,151,186,238,65,240,222,69,223,153,36,137,189,235,63,124,141,255,168,228,68,255,173,96,78)
|
||||
IMAGE_DATA(20,173,64,46,149,172,64,14,22,157,96,238,22,173,64,206,151,108,57,243,11,122,3,253,103,0,0,0,0,0,0,0)
|
||||
IMAGE_END_DATA(512, 2)
|
||||
|
|
|
|||
|
|
@ -30,20 +30,7 @@ void SomeTexts(Painter& sw)
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue