Lumiera  0.pre.03
»edit your freedom«
timecode-widget.hpp
Go to the documentation of this file.
1 /*
2  TIMECODE-WIDGET.hpp - widget for timecode display / input
3 
4  Copyright (C) Ardour.org
5  1999, Paul Davis
6 
7  Copyright (C) Lumiera.org
8  2010, Stefan Kangas <skangas@skangas.se
9 
10  This program 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 the
13  License, or (at your option) any later version.
14 
15  This program 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
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 
24 */
25 
26 
35 #ifndef STAGE_WIDGET_TIMECODE_WIDGET_H
36 #define STAGE_WIDGET_TIMECODE_WIDGET_H
37 
38 #include "stage/gtk-base.hpp"
39 #include "lib/time/timevalue.hpp"
40 
41 #include <gtkmm/box.h>
42 #include <gtkmm/menu.h>
43 #include <gtkmm/eventbox.h>
44 #include <gtkmm/label.h>
45 #include <gtkmm/frame.h>
46 
47 #include <string>
48 
49 
50 namespace stage {
51 namespace widget {
52 
53  using lib::time::Time;
54  using lib::time::TimeVar;
56 
57  using std::string;
58 
59 
64  class TimeCode
65  : public Gtk::HBox
66  {
67  public:
68  enum Mode {
69  SMPTE,
70  MinSec,
71  Frames,
72  Off
73  };
74 
75 
76  TimeCode (string clock_name
77  ,string widget_name
78  ,bool editable
79 // , bool is_duration = false
80  );
81 
82 
83  Mode mode() const { return _mode; }
84 
85  void focus();
86 
87  void set(Time when, bool force = false);
88  void set_mode(Mode);
89 
90  void set_widget_name(string);
91 
92  string name() const { return _name; }
93 
94  Time current_time (Time position = Time::ZERO) const;
95  Time current_duration (Time position = Time::ZERO) const;
96 
97  sigc::signal<void> ValueChanged;
98  sigc::signal<void> ChangeAborted;
99 
100  static sigc::signal<void> ModeChanged;
101  // static std::vector<TimeCode*> clocks;
102 
103  static bool has_focus() { return _has_focus; }
104 
105 
106  private:
107  uint key_entry_state;
108  Mode _mode;
109  string _name;
110  // bool is_duration;
111  bool editable;
112 
113  Gtk::Menu *ops_menu;
114 
115  Gtk::HBox smpte_packer_hbox;
116  Gtk::HBox smpte_packer;
117 
118  Gtk::HBox minsec_packer_hbox;
119  Gtk::HBox minsec_packer;
120 
121  Gtk::HBox frames_packer_hbox;
122  Gtk::HBox frames_packer;
123 
124  enum Field {
125  SMPTE_Hours,
126  SMPTE_Minutes,
127  SMPTE_Seconds,
128  SMPTE_Frames,
129  MS_Hours,
130  MS_Minutes,
131  MS_Seconds,
132  VFrames
133  };
134 
135  Gtk::EventBox audio_frames_ebox;
136  Gtk::Label audio_frames_label;
137 
138  Gtk::HBox off_hbox;
139 
140  Gtk::EventBox hours_ebox;
141  Gtk::EventBox minutes_ebox;
142  Gtk::EventBox seconds_ebox;
143  Gtk::EventBox frames_ebox;
144 
145  Gtk::EventBox ms_hours_ebox;
146  Gtk::EventBox ms_minutes_ebox;
147  Gtk::EventBox ms_seconds_ebox;
148 
149  Gtk::Label hours_label;
150  Gtk::Label minutes_label;
151  Gtk::Label seconds_label;
152  Gtk::Label frames_label;
153  Gtk::Label colon1, colon2, colon3;
154 
155  Gtk::Label ms_hours_label;
156  Gtk::Label ms_minutes_label;
157  Gtk::Label ms_seconds_label;
158  Gtk::Label colon4, colon5;
159 
160  Gtk::EventBox clock_base;
161  Gtk::Frame clock_frame;
162 
163  TimeVar last_when;
164  bool last_pdelta;
165  bool last_sdelta;
166 
167  int last_hrs;
168  int last_mins;
169  int last_secs;
170  int last_frames;
171  bool last_negative;
172 
173  int ms_last_hrs;
174  int ms_last_mins;
175  float ms_last_secs;
176 
177  bool dragging;
178  double drag_start_y;
179  double drag_y;
180  double drag_accum;
181 
182  void on_realize();
183 
184  bool field_motion_notify_event (GdkEventMotion *ev, Field);
185  bool field_button_press_event (GdkEventButton *ev, Field);
186  bool field_button_release_event (GdkEventButton *ev, Field);
187  bool field_button_scroll_event (GdkEventScroll *ev, Field);
188  bool field_key_press_event (GdkEventKey *ev, Field);
189  bool field_key_release_event (GdkEventKey *ev, Field);
190  bool field_focus_gain_event (GdkEventFocus*, Field);
191  bool field_focus_loss_event (GdkEventFocus*, Field);
192  bool drop_focus_handler (GdkEventFocus *ev);
193 
194  void set_smpte (Time, bool);
195  void set_minsec (Time, bool);
196  void set_frames (Time, bool);
197 
198  int get_frames (Field, Time pos = Time::ZERO, int dir=1);
199 
200  void smpte_sanitize_display();
201  Time smpte_time_from_display() const;
202  Time minsec_time_from_display() const;
203  Time audio_time_from_display() const;
204 
205  void build_ops_menu();
206  void setup_events();
207 
208  void smpte_offset_changed();
209  void set_size_requests();
210 
211  static const uint field_length[(int)VFrames+1];
212  static bool _has_focus;
213 
214  void set_size_request_to_display_given_text (Gtk::Widget &w, const gchar *text, gint hpadding, gint vpadding);
215  void get_ink_pixel_size (Glib::RefPtr<Pango::Layout> layout, int& width, int& height);
216  };
217 
218 
219 
220 }}// stage::widget
221 #endif /*STAGE_WIDGET_TIMECODE_WIDGET_H*/
Widget for timecode input and display.
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
Definition: timevalue.hpp:241
bool field_focus_gain_event(GdkEventFocus *, Field)
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:142
A set of basic GTK includes for the UI.