Added copyright lines for files I've edited this year.
[synfig.git] / synfig-studio / trunk / src / gtkmm / renderer_ducks.cpp
index 2304a3b..fb5a609 100644 (file)
@@ -1,20 +1,22 @@
 /* === 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
 */
 /* ========================================================================= */
@@ -37,6 +39,8 @@
 #include <synfig/distance.h>
 #include "app.h"
 
+#include "general.h"
+
 #endif
 
 /* === U S I N G =========================================================== */
@@ -80,21 +84,21 @@ struct ScreenDuck
 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]);
@@ -115,20 +119,20 @@ Renderer_Ducks::render_vfunc(
                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));
        }
 
 
@@ -147,7 +151,7 @@ Renderer_Ducks::render_vfunc(
                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)
@@ -156,17 +160,17 @@ Renderer_Ducks::render_vfunc(
                        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
 */
@@ -174,14 +178,14 @@ Renderer_Ducks::render_vfunc(
 //                     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));
 
                }
        }
@@ -198,11 +202,11 @@ Renderer_Ducks::render_vfunc(
        // 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());
@@ -219,28 +223,34 @@ Renderer_Ducks::render_vfunc(
                if((*iter)->get_connect_duck())
                {
                        has_connect=true;
-                       origin=(*iter)->get_connect_duck()->get_trans_point();                  
+                       origin=(*iter)->get_connect_duck()->get_trans_point();
                }
 
                origin[0]=(origin[0]-window_startx)/pw;
                origin[1]=(origin[1]-window_starty)/ph;
 
-               
+               if (App::restrict_radius_ducks &&
+                       (*iter)->is_radius())
+               {
+                       if (point[0] < origin[0]) point[0] = origin[0];
+                       if (point[1] > origin[1]) point[1] = origin[1];
+               }
+
                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())
                        {
                                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),
@@ -248,7 +258,7 @@ Renderer_Ducks::render_vfunc(
                                        10
                                );
                        }
-                               
+
                }
 
                if((*iter)->get_box_duck())
@@ -259,23 +269,23 @@ Renderer_Ducks::render_vfunc(
                        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;
@@ -284,20 +294,20 @@ Renderer_Ducks::render_vfunc(
                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)
@@ -307,23 +317,23 @@ Renderer_Ducks::render_vfunc(
                                gc->set_line_attributes(3,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
                                gc->set_rgb_fg_color(Gdk::Color("#000000"));
                                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]));                                         
+                               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_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]));                                         
+                               drawable->draw_line(gc, (int)origin[0],(int)origin[1],(int)(point[0]),(int)(point[1]));
                        }
                }
 
@@ -348,7 +358,7 @@ Renderer_Ducks::render_vfunc(
                                        d,
                                        0,
                                        360*64
-                               );  
+                               );
                                gc->set_rgb_fg_color(Gdk::Color("#afafaf"));
                        }
                        else
@@ -357,7 +367,7 @@ Renderer_Ducks::render_vfunc(
                                gc->set_function(Gdk::INVERT);
                        }
                        gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
-                       
+
                        drawable->draw_arc(
                                gc,
                                false,
@@ -367,13 +377,27 @@ Renderer_Ducks::render_vfunc(
                                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 point((*iter)->get_trans_point());
+                                       Point origin((*iter)->get_trans_origin());
+
+                                       if ((point[0] - origin[0]) * pw < 0) point[0] = origin[0];
+                                       if ((point[1] - origin[1]) * ph > 0) point[1] = origin[1];
+
+                                       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"));
                                drawable->draw_layout(
@@ -394,36 +418,36 @@ Renderer_Ducks::render_vfunc(
                }
 
        }
-       
+
 
        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,
@@ -433,7 +457,7 @@ Renderer_Ducks::render_vfunc(
                        radius*2,
                        0,
                        360*64
-               );  
+               );
 
 
                gc->set_rgb_fg_color(color);
@@ -447,6 +471,6 @@ Renderer_Ducks::render_vfunc(
                        radius*2-outline*2,
                        0,
                        360*64
-               );  
+               );
        }
 }