initial version
[synfig.git] / synfig-studio / trunk / src / gtkmm / renderer_bbox.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file template.cpp
3 **      \brief Template File
4 **
5 **      $Id: renderer_bbox.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_bbox.h"
32 #include "workarea.h"
33 #include "canvasview.h"
34 #endif
35
36 /* === U S I N G =========================================================== */
37
38 using namespace std;
39 using namespace etl;
40 using namespace sinfg;
41 using namespace studio;
42
43 /* === M A C R O S ========================================================= */
44
45 /* === G L O B A L S ======================================================= */
46
47 /* === P R O C E D U R E S ================================================= */
48
49 /* === M E T H O D S ======================================================= */
50
51 Renderer_BBox::Renderer_BBox()
52 {
53 }
54
55 Renderer_BBox::~Renderer_BBox()
56 {
57 }
58
59 const sinfg::Rect&
60 Renderer_BBox::get_bbox()
61 {
62         return get_work_area()->get_canvas_view()->get_bbox();
63 }
64
65 void
66 Renderer_BBox::render_vfunc(
67         const Glib::RefPtr<Gdk::Drawable>& drawable,
68         const Gdk::Rectangle& expose_area
69 )
70 {
71         assert(get_work_area());
72         if(!get_work_area())
73                 return;
74         
75 //      const sinfg::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
76         
77         const sinfg::Vector focus_point(get_work_area()->get_focus_point());
78
79 //      std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
80         
81         int drawable_w,drawable_h;
82         drawable->get_size(drawable_w,drawable_h);
83         
84         // Calculate the window coordinates of the top-left
85         // corner of the canvas.
86 //      const sinfg::Vector::value_type
87 //              x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
88 //              y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
89
90         /*const sinfg::Vector::value_type window_startx(window_tl[0]);
91         const sinfg::Vector::value_type window_endx(window_br[0]);
92         const sinfg::Vector::value_type window_starty(window_tl[1]);
93         const sinfg::Vector::value_type window_endy(window_br[1]);
94         */
95 //      const int
96 //              tile_w(get_work_area()->get_tile_w()),
97 //              tile_h(get_work_area()->get_tile_h());
98
99 //      const int
100 //              w(get_w()),
101 //              h(get_h());
102         
103         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
104         
105         //const sinfg::Vector grid_size(get_grid_size());
106
107         const sinfg::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
108 //      const sinfg::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
109         const sinfg::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
110 //      const sinfg::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
111         const float pw(get_pw()),ph(get_ph());
112         
113         const sinfg::Point curr_point(get_bbox().get_min());
114         const sinfg::Point drag_point(get_bbox().get_max());
115         if(get_bbox().area()<10000000000000000.0)
116         {
117                 gc->set_function(Gdk::INVERT);
118                 gc->set_rgb_fg_color(Gdk::Color("#FFFFFF"));
119                 //gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
120                 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
121
122                 Point tl(std::min(drag_point[0],curr_point[0]),std::min(drag_point[1],curr_point[1]));
123                 Point br(std::max(drag_point[0],curr_point[0]),std::max(drag_point[1],curr_point[1]));
124
125                 tl[0]=(tl[0]-window_startx)/pw;
126                 tl[1]=(tl[1]-window_starty)/ph;
127                 br[0]=(br[0]-window_startx)/pw;
128                 br[1]=(br[1]-window_starty)/ph;
129                 if(tl[0]>br[0])
130                         swap(tl[0],br[0]);
131                 if(tl[1]>br[1])
132                         swap(tl[1],br[1]);
133                 
134                 drawable->draw_rectangle(gc,false,
135                         round_to_int(tl[0]),
136                         round_to_int(tl[1]),
137                         round_to_int(br[0]-tl[0]),
138                         round_to_int(br[1]-tl[1])
139                 );
140         }
141 }