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)
8  2010, Stefan Kangas <skangas@skangas.se
9 
10   **Lumiera** is free software; you can redistribute it and/or modify it
11   under the terms of the GNU General Public License as published by the
12   Free Software Foundation; either version 2 of the License, or (at your
13   option) any later version. See the file COPYING for further details.
14 
15 */
16 
17 
26 #ifndef STAGE_WIDGET_TIMECODE_WIDGET_H
27 #define STAGE_WIDGET_TIMECODE_WIDGET_H
28 
29 #include "stage/gtk-base.hpp"
30 #include "lib/time/timevalue.hpp"
31 
32 #include <gtkmm/box.h>
33 #include <gtkmm/menu.h>
34 #include <gtkmm/eventbox.h>
35 #include <gtkmm/label.h>
36 #include <gtkmm/frame.h>
37 
38 #include <string>
39 
40 
41 namespace stage {
42 namespace widget {
43 
44  using lib::time::Time;
45  using lib::time::TimeVar;
47 
48  using std::string;
49 
50 
55  class TimeCode
56  : public Gtk::HBox
57  {
58  public:
59  enum Mode {
60  SMPTE,
61  MinSec,
62  Frames,
63  Off
64  };
65 
66 
67  TimeCode (string clock_name
68  ,string widget_name
69  ,bool editable
70 // , bool is_duration = false
71  );
72 
73 
74  Mode mode() const { return _mode; }
75 
76  void focus();
77 
78  void set(Time when, bool force = false);
79  void set_mode(Mode);
80 
81  void set_widget_name(string);
82 
83  string name() const { return _name; }
84 
85  Time current_time (Time position = Time::ZERO) const;
86  Time current_duration (Time position = Time::ZERO) const;
87 
88  sigc::signal<void> ValueChanged;
89  sigc::signal<void> ChangeAborted;
90 
91  static sigc::signal<void> ModeChanged;
92  // static std::vector<TimeCode*> clocks;
93 
94  static bool has_focus() { return _has_focus; }
95 
96 
97  private:
98  uint key_entry_state;
99  Mode _mode;
100  string _name;
101  // bool is_duration;
102  bool editable;
103 
104  Gtk::Menu *ops_menu;
105 
106  Gtk::HBox smpte_packer_hbox;
107  Gtk::HBox smpte_packer;
108 
109  Gtk::HBox minsec_packer_hbox;
110  Gtk::HBox minsec_packer;
111 
112  Gtk::HBox frames_packer_hbox;
113  Gtk::HBox frames_packer;
114 
115  enum Field {
116  SMPTE_Hours,
117  SMPTE_Minutes,
118  SMPTE_Seconds,
119  SMPTE_Frames,
120  MS_Hours,
121  MS_Minutes,
122  MS_Seconds,
123  VFrames
124  };
125 
126  Gtk::EventBox audio_frames_ebox;
127  Gtk::Label audio_frames_label;
128 
129  Gtk::HBox off_hbox;
130 
131  Gtk::EventBox hours_ebox;
132  Gtk::EventBox minutes_ebox;
133  Gtk::EventBox seconds_ebox;
134  Gtk::EventBox frames_ebox;
135 
136  Gtk::EventBox ms_hours_ebox;
137  Gtk::EventBox ms_minutes_ebox;
138  Gtk::EventBox ms_seconds_ebox;
139 
140  Gtk::Label hours_label;
141  Gtk::Label minutes_label;
142  Gtk::Label seconds_label;
143  Gtk::Label frames_label;
144  Gtk::Label colon1, colon2, colon3;
145 
146  Gtk::Label ms_hours_label;
147  Gtk::Label ms_minutes_label;
148  Gtk::Label ms_seconds_label;
149  Gtk::Label colon4, colon5;
150 
151  Gtk::EventBox clock_base;
152  Gtk::Frame clock_frame;
153 
154  TimeVar last_when;
155  bool last_pdelta;
156  bool last_sdelta;
157 
158  int last_hrs;
159  int last_mins;
160  int last_secs;
161  int last_frames;
162  bool last_negative;
163 
164  int ms_last_hrs;
165  int ms_last_mins;
166  float ms_last_secs;
167 
168  bool dragging;
169  double drag_start_y;
170  double drag_y;
171  double drag_accum;
172 
173  void on_realize();
174 
175  bool field_motion_notify_event (GdkEventMotion *ev, Field);
176  bool field_button_press_event (GdkEventButton *ev, Field);
177  bool field_button_release_event (GdkEventButton *ev, Field);
178  bool field_button_scroll_event (GdkEventScroll *ev, Field);
179  bool field_key_press_event (GdkEventKey *ev, Field);
180  bool field_key_release_event (GdkEventKey *ev, Field);
181  bool field_focus_gain_event (GdkEventFocus*, Field);
182  bool field_focus_loss_event (GdkEventFocus*, Field);
183  bool drop_focus_handler (GdkEventFocus *ev);
184 
185  void set_smpte (Time, bool);
186  void set_minsec (Time, bool);
187  void set_frames (Time, bool);
188 
189  int get_frames (Field, Time pos = Time::ZERO, int dir=1);
190 
191  void smpte_sanitize_display();
192  Time smpte_time_from_display() const;
193  Time minsec_time_from_display() const;
194  Time audio_time_from_display() const;
195 
196  void build_ops_menu();
197  void setup_events();
198 
199  void smpte_offset_changed();
200  void set_size_requests();
201 
202  static const uint field_length[(int)VFrames+1];
203  static bool _has_focus;
204 
205  void set_size_request_to_display_given_text (Gtk::Widget &w, const gchar *text, gint hpadding, gint vpadding);
206  void get_ink_pixel_size (Glib::RefPtr<Pango::Layout> layout, int& width, int& height);
207  };
208 
209 
210 
211 }}// stage::widget
212 #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:232
bool field_focus_gain_event(GdkEventFocus *, Field)
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
a family of time value like entities and their relationships.
basic constant internal time value.
Definition: timevalue.hpp:133
A set of basic GTK includes for the UI.