mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-28 06:12:37 -06:00
Painter20 dasher
git-svn-id: svn://ultimatepp.org/upp/trunk@840 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
68c2a1caaa
commit
068030de69
13 changed files with 231 additions and 505 deletions
62
uppdev/ScanLine/Dasher.cpp
Normal file
62
uppdev/ScanLine/Dasher.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#include "ScanLine.h"
|
||||
|
||||
void Dasher::Put(const Pointf& p)
|
||||
{
|
||||
if(flag)
|
||||
PutLine(p);
|
||||
else
|
||||
PutMove(p);
|
||||
}
|
||||
|
||||
void Dasher::Move(const Pointf& p)
|
||||
{
|
||||
PutMove(p);
|
||||
p0 = p;
|
||||
}
|
||||
|
||||
void Dasher::Line(const Pointf& p)
|
||||
{
|
||||
if(pattern.GetCount() == 0) {
|
||||
PutLine(p);
|
||||
return;
|
||||
}
|
||||
Pointf v = p - p0;
|
||||
double len = Length(v);
|
||||
double pos = 0;
|
||||
while(pos + rem < len) {
|
||||
pos += rem;
|
||||
Put(pos / len * v + p0);
|
||||
flag = !flag;
|
||||
rem = pattern[patterni];
|
||||
patterni = (patterni + 1) % pattern.GetCount();
|
||||
}
|
||||
rem -= len - pos;
|
||||
Put(p);
|
||||
p0 = p;
|
||||
}
|
||||
|
||||
Dasher::Dasher(double width, const Vector<double>& p, double distance)
|
||||
{
|
||||
pattern.SetCount(p.GetCount());
|
||||
double sum = 0;
|
||||
for(int i = 0; i < p.GetCount(); i++)
|
||||
sum += (pattern[i] = p[i] * width);
|
||||
if(sum == 0) {
|
||||
pattern.Clear();
|
||||
return;
|
||||
}
|
||||
distance -= int(distance / sum) * sum;
|
||||
patterni = 0;
|
||||
flag = false;
|
||||
for(;;) {
|
||||
rem = pattern[patterni];
|
||||
patterni = (patterni + 1) % pattern.GetCount();
|
||||
flag = !flag;
|
||||
if(rem > distance) {
|
||||
rem -= distance;
|
||||
break;
|
||||
}
|
||||
distance -= rem;
|
||||
}
|
||||
p0 = Pointf(0, 0);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue