Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc3 / src / gtkmm / renderer_timecode.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file renderer_timecode.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 */
22 /* ========================================================================= */
23
24 /* === H E A D E R S ======================================================= */
25
26 #ifdef USING_PCH
27 #       include "pch.h"
28 #else
29 #ifdef HAVE_CONFIG_H
30 #       include <config.h>
31 #endif
32
33 #include "renderer_timecode.h"
34 #include "workarea.h"
35 #include <pangomm/layout.h>
36 #include <pangomm/context.h>
37 #include <pango/pango.h>
38 #include "app.h"
39 #include <cassert>
40
41 #endif
42
43 /* === U S I N G =========================================================== */
44
45 using namespace std;
46 using namespace etl;
47 using namespace synfig;
48 using namespace studio;
49
50 /* === M A C R O S ========================================================= */
51
52 /* === G L O B A L S ======================================================= */
53
54 /* === P R O C E D U R E S ================================================= */
55
56 /* === M E T H O D S ======================================================= */
57
58 Renderer_Timecode::~Renderer_Timecode()
59 {
60 }
61
62 bool
63 Renderer_Timecode::get_enabled_vfunc()const
64 {
65         Canvas::Handle canvas(get_work_area()->get_canvas());
66         return (canvas->rend_desc().get_time_start()!=canvas->rend_desc().get_time_end() ||
67                 canvas->get_time()!=canvas->rend_desc().get_time_start());
68 }
69
70 synfig::Vector
71 Renderer_Timecode::get_grid_size()const
72 {
73         return get_work_area()->get_grid_size();
74 }
75
76 void
77 Renderer_Timecode::render_vfunc(
78         const Glib::RefPtr<Gdk::Drawable>& drawable,
79         const Gdk::Rectangle& /*expose_area*/
80 )
81 {
82         assert(get_work_area());
83         if(!get_work_area())
84                 return;
85
86         //const synfig::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
87
88         const synfig::Vector focus_point(get_work_area()->get_focus_point());
89
90         //std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
91
92         int drawable_w,drawable_h;
93         drawable->get_size(drawable_w,drawable_h);
94
95         // Calculate the window coordinates of the top-left
96         // corner of the canvas.
97 //      const synfig::Vector::value_type
98 //              x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
99 //              y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
100
101         /*const synfig::Vector::value_type window_startx(window_tl[0]);
102         const synfig::Vector::value_type window_endx(window_br[0]);
103         const synfig::Vector::value_type window_starty(window_tl[1]);
104         const synfig::Vector::value_type window_endy(window_br[1]);
105         */
106 //      const int
107 //              tile_w(get_work_area()->get_tile_w()),
108 //              tile_h(get_work_area()->get_tile_h());
109
110 //      const int
111 //              w(get_w()),
112 //              h(get_h());
113
114         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
115
116         //const synfig::Vector grid_size(get_grid_size());
117
118 //      const synfig::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
119 //      const synfig::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
120 //      const synfig::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
121 //      const synfig::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
122 //      const float pw(get_pw()),ph(get_ph());
123
124         Canvas::Handle canvas(get_work_area()->get_canvas());
125         synfig::Time cur_time(canvas->get_time());
126
127         // Print out the timecode
128         {
129                 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_work_area()->get_pango_context()));
130
131 /*              Glib::ustring timecode(cur_time.get_string(rend_desc.get_frame_rate(),App::get_time_format()));
132
133                 try
134                 {
135                         timecode+="\n"+canvas->keyframe_list().find(cur_time)->get_description();
136                         gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
137                 }
138                 catch(synfig::Exception::NotFound)
139                 {
140                         return;
141                         gc->set_rgb_fg_color(Gdk::Color("#000000"));
142                 }
143
144                 layout->set_text(timecode);
145 */
146
147                 gc->set_rgb_fg_color(Gdk::Color("#5f0000"));
148                 try
149                 {
150                         int w, h;
151                         layout->set_text(canvas->keyframe_list().find(cur_time)->get_description());
152                         layout->get_size(w, h);
153                         get_work_area()->timecode_width = int(w*1.0/Pango::SCALE);
154                         get_work_area()->timecode_height = int(h*1.0/Pango::SCALE);
155                 }
156                 catch(synfig::Exception::NotFound)
157                 {
158                         get_work_area()->timecode_width = get_work_area()->timecode_height = 0;
159                         return;
160                 }
161                 catch(...) {
162                         assert(0);
163                 }
164
165                 drawable->draw_layout(gc, 4, 4, layout);
166         }
167 }