/* === S Y N F I G ========================================================= */
-/*! \file template.cpp
+/*! \file renderer_ducks.cpp
** \brief Template File
**
-** $Id: renderer_ducks.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
+** $Id$
**
** \legal
-** Copyright (c) 2002 Robert B. Quattlebaum Jr.
+** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+** Copyright (c) 2007, 2008 Chris Moore
**
-** This software and associated documentation
-** are CONFIDENTIAL and PROPRIETARY property of
-** the above-mentioned copyright holder.
+** This package is free software; you can redistribute it and/or
+** modify it under the terms of the GNU General Public License as
+** published by the Free Software Foundation; either version 2 of
+** the License, or (at your option) any later version.
**
-** You may not copy, print, publish, or in any
-** other way distribute this software without
-** a prior written agreement with
-** the copyright holder.
+** This package is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+** General Public License for more details.
** \endlegal
*/
/* ========================================================================= */
#include <ETL/misc>
#include "widget_color.h"
#include <synfig/distance.h>
+#include <synfig/valuenode_blinecalcvertex.h>
+#include <synfig/valuenode_bline.h>
#include "app.h"
+#include "general.h"
+
#endif
/* === U S I N G =========================================================== */
/* === M E T H O D S ======================================================= */
+bool
+restrict_blinevertex_duck(etl::handle<Duck> duck, WorkArea& w_area, synfig::Point *point)
+{
+ synfig::Point sub_trans_origin(duck->get_sub_trans_origin());
+ etl::handle<Duck> origin_duck = duck->get_origin_duck();
+ bool origin_changed = false;
+ if(origin_duck)
+ origin_changed = restrict_blinevertex_duck(origin_duck, w_area, &sub_trans_origin);
+
+ if( ValueNode_BLineCalcVertex::Handle bline_vertex =
+ ValueNode_BLineCalcVertex::Handle::cast_dynamic(duck->get_value_desc().get_value_node())
+ )
+ {
+ synfig::Point closest_point = duck->get_point();
+ synfig::Real radius = 0.0;
+ ValueNode_BLine::Handle bline = ValueNode_BLine::Handle::cast_dynamic(bline_vertex->get_link(bline_vertex->get_link_index_from_name("bline")));
+ synfig::find_closest_point(
+ (*bline)(w_area.get_time()),
+ duck->get_point(),
+ radius,
+ bline->get_loop(),
+ &closest_point
+ );
+
+ if(closest_point != duck->get_point())
+ {
+ *point = closest_point * duck->get_scalar() + sub_trans_origin;
+ return true;
+ }
+ }
+
+ if(origin_changed)
+ {
+ *point = duck->get_point() * duck->get_scalar() + sub_trans_origin;
+ return true;
+ }
+
+ return false;
+}
+
Renderer_Ducks::~Renderer_Ducks()
{
}
void
Renderer_Ducks::render_vfunc(
const Glib::RefPtr<Gdk::Drawable>& drawable,
- const Gdk::Rectangle& expose_area
+ const Gdk::Rectangle& /*expose_area*/
)
{
assert(get_work_area());
if(!get_work_area())
return;
-
+
const synfig::Vector focus_point(get_work_area()->get_focus_point());
-
+
int drawable_w,drawable_h;
drawable->get_size(drawable_w,drawable_h);
-
+
Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
-
+
const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
vector<Gdk::Point> points;
std::list<synfig::Point>::iterator iter2;
Point holder;
-
+
for(iter2=(*iter)->stroke_data->begin();iter2!=(*iter)->stroke_data->end();++iter2)
{
holder=*iter2-window_start;
holder[0]/=pw;holder[1]/=ph;
points.push_back(Gdk::Point(round_to_int(holder[0]),round_to_int(holder[1])));
}
-
+
gc->set_rgb_fg_color(colorconv_synfig2gdk((*iter)->color));
gc->set_function(Gdk::COPY);
gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
// Draw the stroke
- drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
+ drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
}
// Render the beziers
for(std::list<handle<Duckmatic::Bezier> >::const_iterator iter=bezier_list.begin();iter!=bezier_list.end();++iter)
{
+ Point sub_trans_p1((*iter)->p1->get_sub_trans_point());
+ Point sub_trans_p2((*iter)->p2->get_sub_trans_point());
+ Point sub_trans_c1((*iter)->c1->get_sub_trans_point());
+ Point sub_trans_c2((*iter)->c2->get_sub_trans_point());
+
+ WorkArea* w_area = get_work_area();
+ restrict_blinevertex_duck((*iter)->p1, *w_area, &sub_trans_p1);
+ restrict_blinevertex_duck((*iter)->p2, *w_area, &sub_trans_p2);
+ restrict_blinevertex_duck((*iter)->c1, *w_area, &sub_trans_c1);
+ restrict_blinevertex_duck((*iter)->c2, *w_area, &sub_trans_c2);
+
Point window_start(window_startx,window_starty);
- Point p1((*iter)->p1->get_trans_point()-window_start);
- Point p2((*iter)->p2->get_trans_point()-window_start);
- Point c1((*iter)->c1->get_trans_point()-window_start);
- Point c2((*iter)->c2->get_trans_point()-window_start);
+ Point p1((*iter)->p1->get_transform_stack().perform(sub_trans_p1)-window_start);
+ Point p2((*iter)->p2->get_transform_stack().perform(sub_trans_p2)-window_start);
+ Point c1((*iter)->c1->get_transform_stack().perform(sub_trans_c1)-window_start);
+ Point c2((*iter)->c2->get_transform_stack().perform(sub_trans_c2)-window_start);
p1[0]/=pw;p1[1]/=ph;
p2[0]/=pw;p2[1]/=ph;
c1[0]/=pw;c1[1]/=ph;
c2[0]/=pw;c2[1]/=ph;
bezier<Point> curve(p1,c1,c2,p2);
vector<Gdk::Point> points;
-
+
float f;
Point pt;
for(f=0;f<1.0;f+=1.0/17.0)
points.push_back(Gdk::Point(round_to_int(pt[0]),round_to_int(pt[1])));
}
points.push_back(Gdk::Point(round_to_int(p2[0]),round_to_int(p2[1])));
-
+
// Draw the curve
/* if(solid_lines)
{
- gc->set_rgb_fg_color(Gdk::Color("#000000"));
+ gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_1);
gc->set_function(Gdk::COPY);
gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
- gc->set_rgb_fg_color(Gdk::Color("#afafaf"));
+ drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
+ gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_2);
gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
+ drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
}
else
*/
// gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
// gc->set_function(Gdk::INVERT);
// gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
-// drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
- gc->set_rgb_fg_color(Gdk::Color("#000000"));
+// drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
+ gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_1);
gc->set_function(Gdk::COPY);
gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
- gc->set_rgb_fg_color(Gdk::Color("#afafaf"));
+ drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
+ gc->set_rgb_fg_color(DUCK_COLOR_BEZIER_2);
gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
+ drawable->draw_lines(gc, Glib::ArrayHandle<Gdk::Point>(points));
}
}
// Render the ducks
for(std::list<handle<Duck> >::const_iterator iter=duck_list.begin();iter!=duck_list.end();++iter)
{
-
+
// If this type of duck has been masked, then skip it
if((*iter)->get_type() && (!(get_work_area()->get_type_mask() & (*iter)->get_type())))
continue;
-
+
// Real x,y;
// Gdk::Rectangle area;
- Point point((*iter)->get_trans_point());
- Point origin((*iter)->get_trans_origin());
-
- point[0]=(point[0]-window_startx)/pw;
- point[1]=(point[1]-window_starty)/ph;
+ Point sub_trans_point((*iter)->get_sub_trans_point());
+ Point sub_trans_origin((*iter)->get_sub_trans_origin());
+ etl::handle<Duck> origin_duck = (*iter)->get_origin_duck();
bool has_connect(false);
if((*iter)->get_tangent() || (*iter)->get_type()&Duck::TYPE_ANGLE)
if((*iter)->get_connect_duck())
{
has_connect=true;
- origin=(*iter)->get_connect_duck()->get_trans_point();
+ sub_trans_origin = (*iter)->get_connect_duck()->get_sub_trans_point();
+ origin_duck = (*iter)->get_connect_duck();
+ }
+
+
+ if (App::restrict_radius_ducks &&
+ (*iter)->is_radius())
+ {
+ if (sub_trans_point[0] < sub_trans_origin[0])
+ sub_trans_point[0] = sub_trans_origin[0];
+ if (sub_trans_point[1] < sub_trans_origin[1])
+ sub_trans_point[1] = sub_trans_origin[1];
}
+ WorkArea* w_area = get_work_area();
+ restrict_blinevertex_duck((*iter), *w_area, &sub_trans_point);
+ if(origin_duck)
+ restrict_blinevertex_duck(origin_duck, *w_area, &sub_trans_origin);
+
+ Point point((*iter)->get_transform_stack().perform(sub_trans_point));
+ Point origin((*iter)->get_transform_stack().perform(sub_trans_origin));
+
+ point[0]=(point[0]-window_startx)/pw;
+ point[1]=(point[1]-window_starty)/ph;
+
origin[0]=(origin[0]-window_startx)/pw;
origin[1]=(origin[1]-window_starty)/ph;
-
bool selected(get_work_area()->duck_is_selected(*iter));
- bool hover(*iter==hover_duck);
-
+ bool hover(*iter==hover_duck || (*iter)->get_hover());
+
shadow = selected?Gtk::SHADOW_IN:Gtk::SHADOW_OUT;
-
+
if(get_work_area()->get_selected_value_node())
{
synfigapp::ValueDesc value_desc((*iter)->get_value_desc());
- if(value_desc.is_valid() && value_desc.is_value_node() && get_work_area()->get_selected_value_node()==value_desc.get_value_node())
+ if (value_desc.is_valid() &&
+ ((value_desc.is_value_node() && get_work_area()->get_selected_value_node() == value_desc.get_value_node()) ||
+ (value_desc.parent_is_value_node() && get_work_area()->get_selected_value_node() == value_desc.get_parent_value_node())))
{
gc->set_function(Gdk::COPY);
- gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
+ gc->set_rgb_fg_color(DUCK_COLOR_SELECTED);
//gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
gc->set_line_attributes(2,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
-
+
drawable->draw_rectangle(gc,false,
round_to_int(point[0]-5),
round_to_int(point[1]-5),
10
);
}
-
+
}
if((*iter)->get_box_duck())
Point tl(min(point[0],boxpoint[0]),min(point[1],boxpoint[1]));
gc->set_function(Gdk::COPY);
- gc->set_rgb_fg_color(Gdk::Color("#FFFFFF"));
+ gc->set_rgb_fg_color(DUCK_COLOR_BOX_1);
gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
drawable->draw_rectangle(gc,false,
round_to_int(tl[0]),
round_to_int(tl[1]),
round_to_int(abs(boxpoint[0]-point[0])),
round_to_int(abs(boxpoint[1]-point[1]))
- );
+ );
gc->set_function(Gdk::COPY);
- gc->set_rgb_fg_color(Gdk::Color("#000000"));
+ gc->set_rgb_fg_color(DUCK_COLOR_BOX_2);
gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
drawable->draw_rectangle(gc,false,
round_to_int(tl[0]),
round_to_int(tl[1]),
round_to_int(abs(boxpoint[0]-point[0])),
round_to_int(abs(boxpoint[1]-point[1]))
- );
+ );
}
ScreenDuck screen_duck;
screen_duck.hover=hover;
if(!(*iter)->get_editable())
- screen_duck.color=(Gdk::Color("#cfcfcf"));
+ screen_duck.color=(DUCK_COLOR_NOT_EDITABLE);
else if((*iter)->get_tangent())
- screen_duck.color=((*iter)->get_scalar()<0?Gdk::Color("#ffff00"):Gdk::Color("#ff0000"));
+ screen_duck.color=((*iter)->get_scalar()<0 ? DUCK_COLOR_TANGENT_1 : DUCK_COLOR_TANGENT_2);
else if((*iter)->get_type()&Duck::TYPE_VERTEX)
- screen_duck.color=Gdk::Color("#ff7f00");
+ screen_duck.color=DUCK_COLOR_VERTEX;
else if((*iter)->get_type()&Duck::TYPE_RADIUS)
- screen_duck.color=Gdk::Color("#00ffff");
+ screen_duck.color=DUCK_COLOR_RADIUS;
else if((*iter)->get_type()&Duck::TYPE_WIDTH)
- screen_duck.color=Gdk::Color("#ff00ff");
+ screen_duck.color=DUCK_COLOR_WIDTH;
else if((*iter)->get_type()&Duck::TYPE_ANGLE)
- screen_duck.color=(Gdk::Color("#0000ff"));
+ screen_duck.color=(DUCK_COLOR_ANGLE);
else
- screen_duck.color=Gdk::Color("#00ff00");
-
+ screen_duck.color=DUCK_COLOR_OTHER;
+
screen_duck_list.push_front(screen_duck);
if(has_connect)
if(solid_lines)
{
gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- gc->set_rgb_fg_color(Gdk::Color("#000000"));
+ gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_OUTSIDE);
gc->set_function(Gdk::COPY);
- drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
+ drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- gc->set_rgb_fg_color(Gdk::Color("#9fefef"));
- drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
+ gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_INSIDE);
+ drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
}
else
{
// gc->set_rgb_fg_color(Gdk::Color("#ffffff"));
// gc->set_function(Gdk::INVERT);
-// drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
+// drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- gc->set_rgb_fg_color(Gdk::Color("#000000"));
+ gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_OUTSIDE);
gc->set_function(Gdk::COPY);
- drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
+ drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- gc->set_rgb_fg_color(Gdk::Color("#9fefef"));
- drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
+ gc->set_rgb_fg_color(DUCK_COLOR_CONNECT_INSIDE);
+ drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
}
}
d,
0,
360*64
- );
+ );
gc->set_rgb_fg_color(Gdk::Color("#afafaf"));
}
else
gc->set_function(Gdk::INVERT);
}
gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
-
+
drawable->draw_arc(
gc,
false,
d,
0,
360*64
- );
+ );
if(hover)
{
- Distance real_mag(((*iter)->get_trans_point()-(*iter)->get_trans_origin()).mag(),Distance::SYSTEM_UNITS);
+ Real mag;
+ if (App::restrict_radius_ducks)
+ {
+ Point sub_trans_point((*iter)->get_sub_trans_point());
+ Point sub_trans_origin((*iter)->get_sub_trans_origin());
+
+ if (sub_trans_point[0] < sub_trans_origin[0])
+ sub_trans_point[0] = sub_trans_origin[0];
+ if (sub_trans_point[1] < sub_trans_origin[1])
+ sub_trans_point[1] = sub_trans_origin[1];
+
+ Point point((*iter)->get_transform_stack().perform(sub_trans_point));
+ Point origin((*iter)->get_transform_stack().perform(sub_trans_origin));
+
+ mag = (point-origin).mag();
+ }
+ else
+ mag = ((*iter)->get_trans_point()-(*iter)->get_trans_origin()).mag();
+
+ Distance real_mag(mag, Distance::SYSTEM_UNITS);
real_mag.convert(App::distance_system,get_work_area()->get_rend_desc());
- layout->set_text(real_mag.get_string());
+ layout->set_text(real_mag.get_string());
- gc->set_rgb_fg_color(Gdk::Color("#000000"));
+ gc->set_rgb_fg_color(DUCK_COLOR_WIDTH_TEXT_1);
drawable->draw_layout(
gc,
round_to_int(point[0])+1+6,
round_to_int(point[1])+1-8,
layout
);
- gc->set_rgb_fg_color(Gdk::Color("#FF00FF"));
+ gc->set_rgb_fg_color(DUCK_COLOR_WIDTH_TEXT_2);
drawable->draw_layout(
gc,
round_to_int(point[0])+6,
}
}
-
+
for(;screen_duck_list.size();screen_duck_list.pop_front())
{
int radius=4;
int outline=1;
Gdk::Color color(screen_duck_list.front().color);
-
+
if(!screen_duck_list.front().selected)
{
color.set_red(color.get_red()*2/3);
color.set_green(color.get_green()*2/3);
color.set_blue(color.get_blue()*2/3);
}
-
+
if(screen_duck_list.front().hover && !screen_duck_list.back().hover && screen_duck_list.size()>1)
{
screen_duck_list.push_back(screen_duck_list.front());
continue;
}
-
+
if(screen_duck_list.front().hover)
{
radius+=2;
outline++;
}
-
+
gc->set_function(Gdk::COPY);
gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
- gc->set_rgb_fg_color(Gdk::Color("#000000"));
+ gc->set_rgb_fg_color(DUCK_COLOR_OUTLINE);
drawable->draw_arc(
gc,
true,
radius*2,
0,
360*64
- );
+ );
gc->set_rgb_fg_color(color);
radius*2-outline*2,
0,
360*64
- );
+ );
}
}