Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07 / src / gtkmm / renderer_bbox.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file renderer_bbox.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "renderer_bbox.h"
33 #include "workarea.h"
34 #include "canvasview.h"
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_BBox::Renderer_BBox()
53 {
54 }
55
56 Renderer_BBox::~Renderer_BBox()
57 {
58 }
59
60 const synfig::Rect&
61 Renderer_BBox::get_bbox()
62 {
63         return get_work_area()->get_canvas_view()->get_bbox();
64 }
65
66 void
67 Renderer_BBox::render_vfunc(
68         const Glib::RefPtr<Gdk::Drawable>& drawable,
69         const Gdk::Rectangle& /*expose_area*/
70 )
71 {
72         assert(get_work_area());
73         if(!get_work_area())
74                 return;
75
76 //      const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
77
78         const synfig::Vector focus_point(get_work_area()->get_focus_point());
79
80 //      std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
81
82         int drawable_w,drawable_h;
83         drawable->get_size(drawable_w,drawable_h);
84
85         // Calculate the window coordinates of the top-left
86         // corner of the canvas.
87 //      const synfig::Vector::value_type
88 //              x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
89 //              y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
90
91         /*const synfig::Vector::value_type window_startx(window_tl[0]);
92         const synfig::Vector::value_type window_endx(window_br[0]);
93         const synfig::Vector::value_type window_starty(window_tl[1]);
94         const synfig::Vector::value_type window_endy(window_br[1]);
95         */
96 //      const int
97 //              tile_w(get_work_area()->get_tile_w()),
98 //              tile_h(get_work_area()->get_tile_h());
99
100 //      const int
101 //              w(get_w()),
102 //              h(get_h());
103
104         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
105
106         //const synfig::Vector grid_size(get_grid_size());
107
108         const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
109 //      const synfig::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
110         const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
111 //      const synfig::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
112         const float pw(get_pw()),ph(get_ph());
113
114         const synfig::Point curr_point(get_bbox().get_min());
115         const synfig::Point drag_point(get_bbox().get_max());
116         if(get_bbox().area()<10000000000000000.0)
117         {
118                 gc->set_function(Gdk::INVERT);
119                 gc->set_rgb_fg_color(Gdk::Color("#FFFFFF"));
120                 //gc->set_line_attributes(1,Gdk::LINE_ON_OFF_DASH,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
121                 gc->set_line_attributes(1,Gdk::LINE_SOLID,Gdk::CAP_BUTT,Gdk::JOIN_MITER);
122
123                 Point tl(std::min(drag_point[0],curr_point[0]),std::min(drag_point[1],curr_point[1]));
124                 Point br(std::max(drag_point[0],curr_point[0]),std::max(drag_point[1],curr_point[1]));
125
126                 tl[0]=(tl[0]-window_startx)/pw;
127                 tl[1]=(tl[1]-window_starty)/ph;
128                 br[0]=(br[0]-window_startx)/pw;
129                 br[1]=(br[1]-window_starty)/ph;
130                 if(tl[0]>br[0])
131                         swap(tl[0],br[0]);
132                 if(tl[1]>br[1])
133                         swap(tl[1],br[1]);
134
135                 drawable->draw_rectangle(gc,false,
136                         round_to_int(tl[0]),
137                         round_to_int(tl[1]),
138                         round_to_int(br[0]-tl[0]),
139                         round_to_int(br[1]-tl[1])
140                 );
141         }
142 }