no longer need ffmpeg patch0 which was for Termux
[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 "edl.h"
25 #include "edlsession.h"
26 #include "keys.h"
27 #include "language.h"
28 #include "manualgoto.h"
29 #include "mwindow.h"
30 #include "mwindowgui.h"
31 #include "theme.h"
32
33 #define MGT_W xS(285)
34 #define MGT_H yS(80)
35
36 ManualGoto::ManualGoto(MWindow *mwindow, EditPanel *panel)
37  : BC_DialogThread()
38 {
39         this->mwindow = mwindow;
40         this->panel = panel;
41         window = 0;
42 }
43
44 ManualGoto::~ManualGoto()
45 {
46         close_window();
47 }
48
49 BC_Window *ManualGoto::new_gui()
50 {
51         BC_DisplayInfo dpy_info;
52         int x = dpy_info.get_abs_cursor_x() - MGT_W / 2;
53         int y = dpy_info.get_abs_cursor_y() - MGT_H / 2;
54         window = new ManualGotoWindow(this, x, y);
55         window->create_objects();
56         window->show_window();
57         return window;
58 }
59
60 void ManualGoto::handle_done_event(int result)
61 {
62         if( result ) return;
63         double current_position = panel->get_position();
64         const char *text = window->time_text->get_text();
65         double new_position = Units::text_to_seconds(text,
66                         mwindow->edl->session->sample_rate,
67                         window->time_format,
68                         mwindow->edl->session->frame_rate,
69                         mwindow->edl->session->frames_per_foot);
70         char modifier = window->direction->get_text()[0];
71         switch( modifier ) {
72         case '+':  new_position = current_position + new_position;  break;
73         case '-':  new_position = current_position - new_position;  break;
74         default: break;
75         }
76         panel->subwindow->lock_window("ManualGoto::handle_done_event");
77         panel->set_position(new_position);
78         panel->subwindow->unlock_window();
79 }
80
81 ManualGotoWindow::ManualGotoWindow(ManualGoto *mango, int x, int y)
82  : BC_Window(_(PROGRAM_NAME ": Goto position"), x, y,
83         MGT_W, MGT_H, MGT_W, MGT_H, 0, 0, 1)
84 {
85         this->mango = mango;
86 // *** CONTEXT_HELP ***
87         context_help_set_keyword("Transport and Buttons Bar");
88 }
89
90 ManualGotoWindow::~ManualGotoWindow()
91 {
92 }
93
94
95 ManualGotoText::ManualGotoText(ManualGotoWindow *window, int x, int y, int w)
96  : BC_TextBox(x, y, w, 1, "")
97 {
98         this->window = window;
99 }
100
101 int ManualGotoText::keypress_event()
102 {
103         int key = get_keypress();
104         if( key == '+' || key == '-' || key == '=' ) {
105                 char text[2];  text[0] = key;  text[1] = 0;
106                 window->direction->set_text(text);
107                 return 1;
108         }
109         if( key == RETURN ) {
110                 unlock_window();
111                 window->mango->handle_done_event(0);
112                 lock_window("ManualGotoText::handle_event");
113                 return 1;
114         }
115         return BC_TextBox::keypress_event();
116 }
117
118 void ManualGotoWindow::update(double position)
119 {
120         MWindow *mwindow = mango->mwindow;
121         format_text->update(Units::timetype_toformat(time_format));
122         char string[BCSTRLEN];
123         Units::totext(string, position, time_format,
124                 mwindow->edl->session->sample_rate,
125                 mwindow->edl->session->frame_rate,
126                 mwindow->edl->session->frames_per_foot,
127                 mwindow->get_timecode_offset());
128         time_text->update(string);
129 }
130
131 void ManualGotoWindow::update()
132 {
133         double position = mango->panel->get_position();
134         update(position);
135 }
136
137 ManualGotoKeyItem::ManualGotoKeyItem(ManualGotoDirection *popup,
138                 const char *text, const char *htxt)
139  : BC_MenuItem(text, htxt, htxt[0])
140 {
141         this->popup = popup;
142         this->htxt = htxt;
143 }
144
145 int ManualGotoKeyItem::handle_event()
146 {
147         popup->set_text(htxt);
148         return 1;
149 }
150
151 ManualGotoDirection::ManualGotoDirection(ManualGotoWindow *window,
152         int x, int y, int w)
153  : BC_PopupMenu(x, y, w, "=", -1, 0, 1)
154 {
155         this->window = window;
156 }
157
158 void ManualGotoDirection::create_objects()
159 {
160         add_item(new ManualGotoKeyItem(this, _("Forward"),  "+"));
161         add_item(new ManualGotoKeyItem(this, _("Position"), "="));
162         add_item(new ManualGotoKeyItem(this, _("Reverse"),  "-"));
163 }
164
165 ManualGotoUnitItem::ManualGotoUnitItem(ManualGotoUnits *popup, int type)
166  : BC_MenuItem(Units::timetype_toformat(type))
167 {
168         this->popup = popup;
169         this->type = type;
170 }
171
172 int ManualGotoUnitItem::handle_event()
173 {
174         popup->window->time_format = type;
175         popup->window->update();
176         return 1;
177 }
178
179 ManualGotoUnits::ManualGotoUnits(ManualGotoWindow *window, int x, int y, int w)
180  : BC_PopupMenu(x, y, w, "", 1, 0, 0)
181 {
182         this->window = window;
183 }
184
185 void ManualGotoUnits::create_objects()
186 {
187         add_item(new ManualGotoUnitItem(this, TIME_HMS));
188         add_item(new ManualGotoUnitItem(this, TIME_HMSF));
189         add_item(new ManualGotoUnitItem(this, TIME_TIMECODE));
190         add_item(new ManualGotoUnitItem(this, TIME_FRAMES));
191         add_item(new ManualGotoUnitItem(this, TIME_SAMPLES));
192         add_item(new ManualGotoUnitItem(this, TIME_SAMPLES_HEX));
193         add_item(new ManualGotoUnitItem(this, TIME_SECONDS));
194         add_item(new ManualGotoUnitItem(this, TIME_FEET_FRAMES));
195 }
196
197 void ManualGotoWindow::create_objects()
198 {
199         lock_window("ManualGotoWindow::create_objects");
200         MWindow *mwindow = mango->mwindow;
201         time_format = mwindow->edl->session->time_format;
202         int margin = mwindow->theme->widget_border;
203         int x = xS(10) + BC_OKButton::calculate_w() + margin, y = yS(10);
204         int pop_w = xS(24), x1 = x + pop_w + margin;
205         add_subwindow(format_text = new BC_Title(x1, y, ""));
206         y += format_text->get_h() + margin;
207         add_subwindow(direction = new ManualGotoDirection(this, x, y, pop_w));
208         direction->create_objects();
209         int tw = get_w() - x1 - xS(10) - BC_CancelButton::calculate_w() - margin - pop_w - margin;
210         add_subwindow(time_text = new ManualGotoText(this, x1, y, tw));
211         x1 += time_text->get_w() + margin;
212         add_subwindow(units = new ManualGotoUnits(this, x1, y, pop_w));
213         units->create_objects();
214         update();
215         add_subwindow(new BC_OKButton(this));
216         add_subwindow(new BC_CancelButton(this));
217         unlock_window();
218 }
219