/* === S Y N F I G ========================================================= */
/*! \file layer_shape.cpp
-** \brief Template Header
+** \brief Implementation of the "Shape" layer
**
** $Id$
**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
-** Copyright (c) 2007 Chris Moore
+** Copyright (c) 2007, 2008 Chris Moore
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
SYNFIG_LAYER_INIT(Layer_Shape);
SYNFIG_LAYER_SET_NAME(Layer_Shape,"shape");
-SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Shape,_("Shape"));
-SYNFIG_LAYER_SET_CATEGORY(Layer_Shape,_("Internal"));
+SYNFIG_LAYER_SET_LOCAL_NAME(Layer_Shape,N_("Shape"));
+SYNFIG_LAYER_SET_CATEGORY(Layer_Shape,N_("Internal"));
SYNFIG_LAYER_SET_VERSION(Layer_Shape,"0.1");
SYNFIG_LAYER_SET_CVS_ID(Layer_Shape,"$Id$");
//assumes that the rect culled away anything that would be beyond the edges
if(ydir > 0)
{
- while(y > (*++p)[1]);
+ while(y > (*++p)[1])
+ ;
}
else
{
- while(y < (*++p)[1]);
+ while(y < (*++p)[1])
+ ;
}
//for the loop to break there must have been a slope (straight line would do nothing)
if( (y > ymax && y > p[1][1]) || (y < ymin && y < p[1][1]) ) return 0;
//degenerate line max
- if(ymin == ymax == p[1][1])
+ if(ymin == ymax && ymax == p[1][1])
return 0;
//degenerate accept - to the right and crossing the base line
void setcover(Real c, Real a) { cover = c; area = a; }
void addcover(Real c, Real a) { cover += c; area += a; }
- bool operator < (const PenMark &rhs) const
+ bool operator<(const PenMark &rhs) const
{
return y == rhs.y ? x < rhs.x : y < rhs.y;
}
Layer_Composite (a,m),
edge_table (new Intersector),
color (Color::black()),
- offset (0,0),
+ origin (0,0),
invert (false),
antialias (true),
blurtype (Blur::FASTGAUSSIAN),
bool
Layer_Shape::set_param(const String & param, const ValueBase &value)
{
- IMPORT(color);
- IMPORT(offset);
+ IMPORT_PLUS(color, { if (color.get_a() == 0) { if (converted_blend_) {
+ set_blend_method(Color::BLEND_ALPHA_OVER);
+ color.set_a(1); } else transparent_color_ = true; } });
+ IMPORT(origin);
IMPORT(invert);
IMPORT(antialias);
- IMPORT(feather);
+ IMPORT_PLUS(feather, if(feather<0)feather=0;);
IMPORT(blurtype);
IMPORT(winding_style);
+ IMPORT_AS(origin,"offset");
+
return Layer_Composite::set_param(param,value);
}
Layer_Shape::get_param(const String ¶m)const
{
EXPORT(color);
- EXPORT(offset);
+ EXPORT(origin);
EXPORT(invert);
EXPORT(antialias);
EXPORT(feather);
.set_local_name(_("Color"))
.set_description(_("Layer_Shape Color"))
);
- ret.push_back(ParamDesc("offset")
- .set_local_name(_("Position"))
+ ret.push_back(ParamDesc("origin")
+ .set_local_name(_("Origin"))
);
ret.push_back(ParamDesc("invert")
.set_local_name(_("Invert"))
synfig::Layer::Handle
Layer_Shape::hit_check(synfig::Context context, const synfig::Point &p)const
{
- Point pos(p-offset);
+ Point pos(p-origin);
int intercepts = edge_table->intersect(pos[0],pos[1]);
if(feather)
pp = Blur(feather,feather,blurtype)(p);
- Point pos(pp-offset);
+ Point pos(pp-origin);
int intercepts = edge_table->intersect(pos[0],pos[1]);
bool intersect = ((!!intercepts) ^ invert);
if(!intersect)
- return context.get_color(pp);
+ return Color::blend(Color::alpha(),context.get_color(pp),get_amount(),get_blend_method());
//Ok, we're inside... bummmm ba bum buM...
if(get_blend_method() == Color::BLEND_STRAIGHT && get_amount() == 1)
//************** SCANLINE RENDERING *********************
void Layer_Shape::PolySpan::line_to(Real x, Real y)
{
- Real n[4];
+ Real n[4] = {0,0,0,0};
bool afterx = false;
const Real xin(x), yin(y);
if(is_solid_color() && invert)
{
Rect aabb = edge_table->aabb;
- Point tl = renddesc.get_tl() - offset;
+ Point tl = renddesc.get_tl() - origin;
Real pw = renddesc.get_pw(),
ph = renddesc.get_ph();
Rect nrect;
- Real pixelfeatherx = abs(feather/pw),
- pixelfeathery = abs(feather/ph);
+ Real pixelfeatherx = quality == 10 ? 0 : abs(feather/pw),
+ pixelfeathery = quality == 10 ? 0 : abs(feather/ph);
nrect.set_point((aabb.minx - tl[0])/pw,(aabb.miny - tl[1])/ph);
nrect.expand((aabb.maxx - tl[0])/pw,(aabb.maxy - tl[1])/ph);
if(cb && !cb->amount_complete(10000,10001+renddesc.get_h())) return false;
- if(feather)
+ if(feather && quality != 10)
{
//we have to blur rather than be crappy
PolySpan span;
+ // if the pixels are zero sized then we're too zoomed out to see anything
+ if (pw == 0 || ph == 0)
+ return true;
+
//optimization for tessellating only inside tiles
span.window.minx = 0;
span.window.miny = 0;
case Primitive::MOVE_TO:
{
x = data[curnum][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
if(curnum == 0)
{
case Primitive::LINE_TO:
{
x = data[curnum][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
tangent[0] = x - span.cur_x;
tangent[1] = y - span.cur_y;
case Primitive::CONIC_TO:
{
x = data[curnum+1][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum+1][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
x1 = data[curnum][0];
- x1 = (x1 - tl[0] + offset[0])*pw;
+ x1 = (x1 - tl[0] + origin[0])*pw;
y1 = data[curnum][1];
- y1 = (y1 - tl[1] + offset[1])*ph;
+ y1 = (y1 - tl[1] + origin[1])*ph;
tangent[0] = 2*(x - x1);
tangent[1] = 2*(y - y1);
case Primitive::CONIC_TO_SMOOTH:
{
x = data[curnum][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
x1 = span.cur_x + tangent[0]/2;
y1 = span.cur_y + tangent[1]/2;
case Primitive::CUBIC_TO:
{
x = data[curnum+2][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum+2][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
x2 = data[curnum+1][0];
- x2 = (x2 - tl[0] + offset[0])*pw;
+ x2 = (x2 - tl[0] + origin[0])*pw;
y2 = data[curnum+1][1];
- y2 = (y2 - tl[1] + offset[1])*ph;
+ y2 = (y2 - tl[1] + origin[1])*ph;
x1 = data[curnum][0];
- x1 = (x1 - tl[0] + offset[0])*pw;
+ x1 = (x1 - tl[0] + origin[0])*pw;
y1 = data[curnum][1];
- y1 = (y1 - tl[1] + offset[1])*ph;
+ y1 = (y1 - tl[1] + origin[1])*ph;
tangent[0] = 2*(x - x2);
tangent[1] = 2*(y - y2);
case Primitive::CUBIC_TO_SMOOTH:
{
x = data[curnum+1][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum+1][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
x2 = data[curnum][0];
- x2 = (x2 - tl[0] + offset[0])*pw;
+ x2 = (x2 - tl[0] + origin[0])*pw;
y2 = data[curnum][1];
- y2 = (y2 - tl[1] + offset[1])*ph;
+ y2 = (y2 - tl[1] + origin[1])*ph;
x1 = span.cur_x + tangent[0]/3.0;
y1 = span.cur_y + tangent[1]/3.0;
}
bool
-Layer_Shape::render_shape(surface<float> *surface,int /*quality*/,
+Layer_Shape::render_shape(etl::surface<float> *surface,int /*quality*/,
const RendDesc &renddesc, ProgressCallback */*cb*/)const
{
// If our amount is set to zero, no need to render anything
case Primitive::MOVE_TO:
{
x = data[curnum][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
if(curnum == 0)
{
case Primitive::LINE_TO:
{
x = data[curnum][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
tangent[0] = x - span.cur_x;
tangent[1] = y - span.cur_y;
case Primitive::CONIC_TO:
{
x = data[curnum+1][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum+1][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
x1 = data[curnum][0];
- x1 = (x1 - tl[0] + offset[0])*pw;
+ x1 = (x1 - tl[0] + origin[0])*pw;
y1 = data[curnum][1];
- y1 = (y1 - tl[1] + offset[1])*ph;
+ y1 = (y1 - tl[1] + origin[1])*ph;
tangent[0] = 2*(x - x1);
tangent[1] = 2*(y - y1);
case Primitive::CONIC_TO_SMOOTH:
{
x = data[curnum][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
x1 = span.cur_x + tangent[0]/2;
y1 = span.cur_y + tangent[1]/2;
case Primitive::CUBIC_TO:
{
x = data[curnum+2][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum+2][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
x2 = data[curnum+1][0];
- x2 = (x2 - tl[0] + offset[0])*pw;
+ x2 = (x2 - tl[0] + origin[0])*pw;
y2 = data[curnum+1][1];
- y2 = (y2 - tl[1] + offset[1])*ph;
+ y2 = (y2 - tl[1] + origin[1])*ph;
x1 = data[curnum][0];
- x1 = (x1 - tl[0] + offset[0])*pw;
+ x1 = (x1 - tl[0] + origin[0])*pw;
y1 = data[curnum][1];
- y1 = (y1 - tl[1] + offset[1])*ph;
+ y1 = (y1 - tl[1] + origin[1])*ph;
tangent[0] = 2*(x - x2);
tangent[1] = 2*(y - y2);
case Primitive::CUBIC_TO_SMOOTH:
{
x = data[curnum+1][0];
- x = (x - tl[0] + offset[0])*pw;
+ x = (x - tl[0] + origin[0])*pw;
y = data[curnum+1][1];
- y = (y - tl[1] + offset[1])*ph;
+ y = (y - tl[1] + origin[1])*ph;
x2 = data[curnum][0];
- x2 = (x2 - tl[0] + offset[0])*pw;
+ x2 = (x2 - tl[0] + origin[0])*pw;
y2 = data[curnum][1];
- y2 = (y2 - tl[1] + offset[1])*ph;
+ y2 = (y2 - tl[1] + origin[1])*ph;
x1 = span.cur_x + tangent[0]/3.0;
y1 = span.cur_y + tangent[1]/3.0;
if (edge_table->initaabb)
return Rect::zero();
- Rect bounds(edge_table->aabb+offset);
+ Rect bounds(edge_table->aabb+origin);
bounds.expand(max((bounds.get_min() - bounds.get_max()).mag()*0.01,
feather));