ripple edge drag_handle tweaks, sync_parameter fix, shuttlerc, shortcuts
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / manualgoto.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2004 Andraz Tori
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "editpanel.h"
24 #include "language.h"
25 #include "manualgoto.h"
26 #include "mwindow.h"
27 #include "mwindowgui.h"
28 #include "keys.h"
29
30 ManualGoto::ManualGoto(MWindow *mwindow, EditPanel *panel)
31  : BC_DialogThread()
32 {
33         this->mwindow = mwindow;
34         this->panel = panel;
35         gotowindow = 0;
36 }
37
38 ManualGoto::~ManualGoto()
39 {
40         close_window();
41 }
42
43 BC_Window *ManualGoto::new_gui()
44 {
45         BC_DisplayInfo dpy_info;
46         int x = dpy_info.get_abs_cursor_x() - 250 / 2;
47         int y = dpy_info.get_abs_cursor_y() - 80 / 2;
48         gotowindow = new ManualGotoWindow(this, x, y);
49         gotowindow->create_objects();
50         double position = panel->get_position();
51         gotowindow->reset_data(position);
52         gotowindow->show_window();
53         return gotowindow;
54 }
55
56 void ManualGoto::handle_done_event(int result)
57 {
58         if( result ) return;
59         double current_position = panel->get_position();
60         double new_position = gotowindow->get_new_position();
61         char modifier = gotowindow->signtitle->get_text()[0];
62         switch( modifier ) {
63         case '+':  new_position = current_position + new_position;  break;
64         case '-':  new_position = current_position - new_position;  break;
65         default: break;
66         }
67         panel->subwindow->lock_window("ManualGoto::handle_done_event");
68         panel->set_position(new_position);
69         panel->subwindow->unlock_window();
70 }
71
72
73 ManualGotoWindow::ManualGotoWindow(ManualGoto *mango, int x, int y)
74  : BC_Window(_(PROGRAM_NAME ": Goto position"), x, y,
75         250, 80, 250, 80, 0, 0, 1)
76 {
77         this->mango = mango;
78 }
79
80 ManualGotoWindow::~ManualGotoWindow()
81 {
82 }
83
84 void ManualGotoWindow::reset_data(double position)
85 {
86         lock_window("ManualGotoWindow::reset_data");
87         update_position(position);
88         signtitle->update("=");
89         unlock_window();
90 }
91
92 double ManualGotoWindow::get_new_position()
93 {
94         int64_t hh = atoi(hours->get_text());
95         int mm = atoi(minutes->get_text());
96         int ss = atoi(seconds->get_text());
97         int ms = atoi(msecs->get_text());
98
99         double seconds = ((((hh * 60) + mm) * 60) + ss) + (1.0 * ms) / 1000;
100         return seconds;
101 }
102
103 void ManualGotoWindow::update_position(double position)
104 {
105         if( position < 0 ) position = 0;
106         int64_t pos = position;
107         int64_t hour = (pos / 3600);
108         int minute = (pos / 60 - hour * 60);
109         int second = pos - hour * 3600 - minute * 60;
110         int thousandths = ((int64_t)(position * 1000)) % 1000;
111
112         hours->update((int)hour);
113         minutes->update(minute);
114         seconds->update(second);
115         msecs->update(thousandths);
116 }
117
118 void ManualGotoWindow::create_objects()
119 {
120         lock_window("ManualGotoWindow::create_objects");
121         int x = 76, y = 5;
122
123         BC_Title *title = new BC_Title(x - 2, y, _("hour  min     sec     msec"), SMALLFONT);
124         add_subwindow(title);  y += title->get_h() + 3;
125
126         signtitle = new BC_Title(x - 17, y, "=", LARGEFONT);
127         add_subwindow(signtitle);
128         hours = new ManualGotoNumber(this, x, y, 16, 9, "%i");
129         add_subwindow(hours);    x += hours->get_w() + 4;
130         minutes = new ManualGotoNumber(this, x, y, 26, 59, "%02i");
131         add_subwindow(minutes);  x += minutes->get_w() + 4;
132         seconds = new ManualGotoNumber(this, x, y, 26, 59, "%02i");
133         add_subwindow(seconds);  x += seconds->get_w() + 4;
134         msecs = new ManualGotoNumber(this, x, y, 34, 999, "%03i");
135         add_subwindow(msecs);
136         y += hours->get_h() + 10;
137
138         add_subwindow(new BC_OKButton(this));
139         add_subwindow(new BC_CancelButton(this));
140         unlock_window();
141 }
142
143
144 ManualGotoNumber::ManualGotoNumber(ManualGotoWindow *window, int x, int y, int w,
145         int max, const char *format)
146  : BC_TextBox(x, y, w, 1, "")
147 {
148         this->window = window;
149         this->max = max;
150         this->format = format;
151 }
152
153 int ManualGotoNumber::handle_event()
154 {
155         return 1;
156 }
157
158 void ManualGotoNumber::update(int64_t v)
159 {
160         char text[BCTEXTLEN];
161         if( v < 0 ) v = atoll(get_text());
162         if( v > max ) v = max;
163         sprintf(text, format, v);
164         BC_TextBox::update(text);
165 }
166
167 int ManualGotoNumber::keypress_event()
168 {
169         int key = get_keypress();
170         if( key == '+' || key == '-' || key == '=' ) {
171                 window->signtitle->update(key);
172                 return 1;
173         }
174         if( key == '.' || key == TAB ) {
175                 window->cycle_textboxes(1);
176                 return 1;
177         }
178
179         int chars = 1, m = max;
180         while( (m /= 10) > 0 ) ++chars;
181         int in_textlen = strlen(get_text());
182         if( in_textlen >= chars )
183                 BC_TextBox::update("");
184         int result = BC_TextBox::keypress_event();
185         int out_textlen = strlen(get_text());
186         if( out_textlen >= chars && get_ibeam_letter() >= chars )
187                 window->cycle_textboxes(1);
188         return result;
189 }
190
191