minor changes; mostly for new Context Help feature
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / timeblur / timeblurwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
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 "bcsignals.h"
24 #include "cursors.h"
25 #include "edl.h"
26 #include "timeblur.h"
27 #include "timeblurwindow.h"
28 #include "language.h"
29 #include "localsession.h"
30 #include "mwindow.h"
31 #include "pluginserver.h"
32 #include "theme.h"
33
34 #include <unistd.h>
35
36
37 TimeBlurWindow::TimeBlurWindow(TimeBlurMain *plugin)
38  : PluginClientWindow(plugin, xS(250), yS(50), xS(250), yS(50), 0)
39 {
40         this->plugin = plugin;
41 }
42
43 TimeBlurWindow::~TimeBlurWindow()
44 {
45 }
46
47 void TimeBlurWindow::create_objects()
48 {
49         int margin = plugin->get_theme()->widget_border;
50         int x = margin, y = margin;
51         int x1 = x;
52         add_subwindow(select = new TimeBlurSelect(plugin, this, x1, y));
53         x1 += select->get_w() + margin;
54         frames = new TimeBlurFrames(plugin, this, x1, y);
55         frames->create_objects();
56         x1 += frames->get_w() + 3*margin;
57         add_subwindow(clear_frames = new TimeBlurClearFrames(plugin, this, x1, y));
58         show_window();
59 }
60
61
62 TimeBlurSelect::TimeBlurSelect(TimeBlurMain *plugin, TimeBlurWindow *gui,
63                 int x, int y)
64  : BC_GenericButton(x, y, xS(100), _("Frames"))
65 {
66         this->plugin = plugin;
67         this->gui = gui;
68         set_tooltip(_("Set frames to selection duration"));
69 }
70 int TimeBlurSelect::handle_event()
71 {
72         MWindow *mwindow = plugin->server->mwindow;
73         if( mwindow ) {
74                 EDL *edl = mwindow->edl;
75                 double start = edl->local_session->get_selectionstart();
76                 int64_t start_pos = edl->get_frame_rate() * start;
77                 double end = edl->local_session->get_selectionend();
78                 int64_t end_pos = edl->get_frame_rate() * end;
79                 int64_t frames = end_pos - start_pos;
80                 gui->frames->update(frames);
81                 plugin->config.frames = frames;
82                 plugin->send_configure_change();
83         }
84         return 1;
85 }
86
87 TimeBlurClearFrames::TimeBlurClearFrames(TimeBlurMain *plugin, TimeBlurWindow *gui,
88                 int x, int y)
89  : BC_Button(x, y, plugin->get_theme()->get_image_set("reset_button"))
90 {
91         this->plugin = plugin;
92         this->gui = gui;
93         set_tooltip(_("Clear frames"));
94 }
95
96 int TimeBlurClearFrames::handle_event()
97 {
98         plugin->config.frames = 0;
99         gui->frames->update(0);
100         plugin->send_configure_change();
101         return 1;
102 }
103
104 TimeBlurFrames::TimeBlurFrames(TimeBlurMain *plugin, TimeBlurWindow *gui,
105                 int x, int y)
106  : BC_TumbleTextBox(gui, 0, 0, 65535, x, y, xS(80))
107 {
108         this->plugin = plugin;
109         this->gui = gui;
110 }
111
112 int TimeBlurFrames::handle_event()
113 {
114         plugin->config.frames = atoi(get_text());
115         plugin->send_configure_change();
116         return 1;
117 }
118
119 void TimeBlurFrames::update(int frames)
120 {
121         BC_TumbleTextBox::update((int64_t)frames);
122 }
123