my log
[synfig.git] / synfig-studio / trunk / src / gtkmm / renderer_dragbox.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file template.cpp
3 **      \brief Template File
4 **
5 **      $Id: renderer_dragbox.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "renderer_dragbox.h"
32 #include "workarea.h"
33 #include <ETL/misc>
34
35 #endif
36
37 /* === U S I N G =========================================================== */
38
39 using namespace std;
40 using namespace etl;
41 using namespace synfig;
42 using namespace studio;
43
44 /* === M A C R O S ========================================================= */
45
46 /* === G L O B A L S ======================================================= */
47
48 /* === P R O C E D U R E S ================================================= */
49
50 /* === M E T H O D S ======================================================= */
51
52 Renderer_Dragbox::~Renderer_Dragbox()
53 {
54 }
55
56 const synfig::Point&
57 Renderer_Dragbox::get_drag_point()const
58 {
59         return get_work_area()->get_drag_point();
60 }
61
62 const synfig::Point&
63 Renderer_Dragbox::get_curr_point()const
64 {
65         return get_work_area()->get_cursor_pos();
66 }
67
68 bool
69 Renderer_Dragbox::get_enabled_vfunc()const
70 {
71         return get_work_area()->get_dragging_mode()==WorkArea::DRAG_BOX;
72 }
73
74
75 void
76 Renderer_Dragbox::render_vfunc(
77         const Glib::RefPtr<Gdk::Drawable>& drawable,
78         const Gdk::Rectangle& expose_area
79 )
80 {
81         assert(get_work_area());
82         if(!get_work_area())
83                 return;
84         
85         const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
86         
87         const synfig::Vector focus_point(get_work_area()->get_focus_point());
88
89 //      std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
90         
91         int drawable_w,drawable_h;
92         drawable->get_size(drawable_w,drawable_h);
93         
94         // Calculate the window coordinates of the top-left
95         // corner of the canvas.
96         const synfig::Vector::value_type
97                 x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
98                 y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
99
100         /*const synfig::Vector::value_type window_startx(window_tl[0]);
101         const synfig::Vector::value_type window_endx(window_br[0]);
102         const synfig::Vector::value_type window_starty(window_tl[1]);
103         const synfig::Vector::value_type window_endy(window_br[1]);
104         */
105         const int
106                 tile_w(get_work_area()->get_tile_w()),
107                 tile_h(get_work_area()->get_tile_h());
108
109         const int
110                 w(get_w()),
111                 h(get_h());
112         
113         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
114         
115         //const synfig::Vector grid_size(get_grid_size());
116
117         const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
118         const synfig::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
119         const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
120         const synfig::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
121         const float pw(get_pw()),ph(get_ph());
122         
123         const synfig::Point& curr_point(get_curr_point());
124         const synfig::Point& drag_point(get_drag_point());
125         
126         {
127                 gc->set_function(Gdk::COPY);
128                 gc->set_rgb_fg_color(Gdk::Color("#000000"));
129                 gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
130                 //gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
131
132                 Point tl(std::min(drag_point[0],curr_point[0]),std::min(drag_point[1],curr_point[1]));
133                 Point br(std::max(drag_point[0],curr_point[0]),std::max(drag_point[1],curr_point[1]));
134
135                 tl[0]=(tl[0]-window_startx)/pw;
136                 tl[1]=(tl[1]-window_starty)/ph;
137                 br[0]=(br[0]-window_startx)/pw;
138                 br[1]=(br[1]-window_starty)/ph;
139                 if(tl[0]>br[0])
140                         swap(tl[0],br[0]);
141                 if(tl[1]>br[1])
142                         swap(tl[1],br[1]);
143                 
144                 drawable->draw_rectangle(gc,false,
145                         round_to_int(tl[0]),
146                         round_to_int(tl[1]),
147                         round_to_int(br[0]-tl[0]),
148                         round_to_int(br[1]-tl[1])
149                 );
150         }
151 }