grab stable branch
[synfig.git] / synfig-studio / tags / stable / src / gtkmm / renderer_timecode.cpp
1 /* === S I N F G =========================================================== */
2 /*!     \file template.cpp
3 **      \brief Template File
4 **
5 **      $Id: renderer_timecode.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_timecode.h"
32 #include "workarea.h"
33 #include <pangomm/layout.h>
34 #include <pangomm/context.h>
35 #include <pango/pango.h>
36 #include "app.h"
37
38 #endif
39
40 /* === U S I N G =========================================================== */
41
42 using namespace std;
43 using namespace etl;
44 using namespace sinfg;
45 using namespace studio;
46
47 /* === M A C R O S ========================================================= */
48
49 /* === G L O B A L S ======================================================= */
50
51 /* === P R O C E D U R E S ================================================= */
52
53 /* === M E T H O D S ======================================================= */
54
55 Renderer_Timecode::~Renderer_Timecode()
56 {
57 }
58
59 bool
60 Renderer_Timecode::get_enabled_vfunc()const
61 {
62         Canvas::Handle canvas(get_work_area()->get_canvas());
63         return (canvas->rend_desc().get_time_start()!=canvas->rend_desc().get_time_end() ||
64                 canvas->get_time()!=canvas->rend_desc().get_time_start());
65 }
66
67 sinfg::Vector
68 Renderer_Timecode::get_grid_size()const
69 {
70         return get_work_area()->get_grid_size();
71 }
72
73 void
74 Renderer_Timecode::render_vfunc(
75         const Glib::RefPtr<Gdk::Drawable>& drawable,
76         const Gdk::Rectangle& expose_area
77 )
78 {
79         assert(get_work_area());
80         if(!get_work_area())
81                 return;
82         
83         //const sinfg::RendDesc &rend_desc(get_work_area()->get_canvas()->rend_desc());
84         
85         const sinfg::Vector focus_point(get_work_area()->get_focus_point());
86
87         //std::vector< std::pair<Glib::RefPtr<Gdk::Pixbuf>,int> >& tile_book(get_tile_book());
88         
89         int drawable_w,drawable_h;
90         drawable->get_size(drawable_w,drawable_h);
91         
92         // Calculate the window coordinates of the top-left
93         // corner of the canvas.
94 //      const sinfg::Vector::value_type
95 //              x(focus_point[0]/get_pw()+drawable_w/2-get_w()/2),
96 //              y(focus_point[1]/get_ph()+drawable_h/2-get_h()/2);
97
98         /*const sinfg::Vector::value_type window_startx(window_tl[0]);
99         const sinfg::Vector::value_type window_endx(window_br[0]);
100         const sinfg::Vector::value_type window_starty(window_tl[1]);
101         const sinfg::Vector::value_type window_endy(window_br[1]);
102         */
103 //      const int
104 //              tile_w(get_work_area()->get_tile_w()),
105 //              tile_h(get_work_area()->get_tile_h());
106
107 //      const int
108 //              w(get_w()),
109 //              h(get_h());
110         
111         Glib::RefPtr<Gdk::GC> gc(Gdk::GC::create(drawable));
112         
113         //const sinfg::Vector grid_size(get_grid_size());
114
115 //      const sinfg::Vector::value_type window_startx(get_work_area()->get_window_tl()[0]);
116 //      const sinfg::Vector::value_type window_endx(get_work_area()->get_window_br()[0]);
117 //      const sinfg::Vector::value_type window_starty(get_work_area()->get_window_tl()[1]);
118 //      const sinfg::Vector::value_type window_endy(get_work_area()->get_window_br()[1]);
119 //      const float pw(get_pw()),ph(get_ph());
120
121         Canvas::Handle canvas(get_work_area()->get_canvas());
122         sinfg::Time cur_time(canvas->get_time());
123         
124         // Print out the timecode
125         {
126                 Glib::RefPtr<Pango::Layout> layout(Pango::Layout::create(get_work_area()->get_pango_context()));
127                 
128 /*              Glib::ustring timecode(cur_time.get_string(rend_desc.get_frame_rate(),App::get_time_format()));
129
130                 try
131                 {
132                         timecode+="\n"+canvas->keyframe_list().find(cur_time)->get_description();
133                         gc->set_rgb_fg_color(Gdk::Color("#FF0000"));
134                 }
135                 catch(sinfg::Exception::NotFound)
136                 {
137                         return;
138                         gc->set_rgb_fg_color(Gdk::Color("#000000"));
139                 }
140                 
141                 layout->set_text(timecode);             
142 */
143
144                 gc->set_rgb_fg_color(Gdk::Color("#5f0000"));
145                 try
146                 {
147                         layout->set_text(canvas->keyframe_list().find(cur_time)->get_description());            
148                 }
149                 catch(sinfg::Exception::NotFound)
150                 {
151                         return;
152                 }
153                 
154                 drawable->draw_layout(gc, 4, 4, layout);
155         }       
156 }