initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / tipwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 "clip.h"
25 #include "keys.h"
26 #include "language.h"
27 #include "mainsession.h"
28 #include "mwindow.h"
29 #include "preferences.h"
30 #include "theme.h"
31 #include "tipwindow.h"
32
33
34
35 // Table of tips of the day
36 static const char *tips[] = 
37 {
38         N_("Shift-click on a curve keyframe to snap it to the neighboring values."),
39
40         N_("When configuring slow effects, disable playback for the track.  After configuring it,\n"
41         "re-enable playback to process a single frame."),
42
43         N_("Ctrl + any transport command causes playback to only cover\n"
44         "the region defined by the in/out points."),
45
46         N_("Shift + clicking a patch causes all other patches except the\n"
47         "selected one to toggle."),
48
49         N_("Clicking on a patch and dragging across other tracks causes\n"
50         "the other patches to match the first one."),
51
52         N_("Shift + clicking on an effect boundary causes dragging to affect\n"
53         "just the one effect."),
54
55         N_("Load multiple files by clicking on one file and shift + clicking on\n"
56         "another file.  Ctrl + clicking toggles individual files."),
57
58         N_("Ctrl + left clicking on the time bar cycles forward a time format.\n"
59         "Ctrl + middle clicking on the time bar cycles backward a time format."),
60
61         N_("Use the +/- keys in the Compositor window to zoom in and out.\n"),
62
63         N_("Pressing Alt while clicking in the cropping window causes translation of\n"
64         "all 4 points.\n"),
65
66         N_("Pressing Tab over a track toggles the Record status.\n"
67         "Pressing Shift-Tab over a track toggles the Record status of all the other tracks.\n"),
68
69         N_("Audio->Map 1:1 maps each recordable audio track to a different channel.\n"
70         "Map 5.1:1 maps 6 recordable AC3 tracks to 2 channels.\n"),
71
72         N_("Alt + left moves to the previous edit handle.\n"
73         "Alt + right moves to the next edit handle.\n"),
74
75         N_("Settings->typeless keyframes allows keyframes from any track to be pasted on either\n"
76         "audio or video tracks.\n")
77 };
78
79 static int total_tips = sizeof(tips) / sizeof(char*);
80
81
82
83
84 TipWindow::TipWindow(MWindow *mwindow)
85  : BC_DialogThread()
86 {
87         this->mwindow = mwindow;
88 }
89
90 void TipWindow::handle_close_event(int result)
91 {
92         gui = 0;
93 }
94
95 BC_Window* TipWindow::new_gui()
96 {
97         BC_DisplayInfo display_info;
98         int x = display_info.get_abs_cursor_x();
99         int y = display_info.get_abs_cursor_y();
100         TipWindowGUI *gui = this->gui = new TipWindowGUI(mwindow, 
101                 this,
102                 x,
103                 y);
104         gui->create_objects();
105         return gui;
106 }
107
108 char* TipWindow::get_current_tip()
109 {
110         CLAMP(mwindow->session->current_tip, 0, total_tips - 1);
111         char *result = _(tips[mwindow->session->current_tip]);
112         mwindow->session->current_tip++;
113         if(mwindow->session->current_tip >= total_tips)
114                 mwindow->session->current_tip = 0;
115         mwindow->save_defaults();
116         return result;
117 }
118
119 void TipWindow::next_tip()
120 {
121         gui->tip_text->update(get_current_tip());
122 }
123
124 void TipWindow::prev_tip()
125 {
126         for(int i = 0; i < 2; i++)
127         {
128                 mwindow->session->current_tip--;
129                 if(mwindow->session->current_tip < 0)
130                         mwindow->session->current_tip = total_tips - 1;
131         }
132
133         gui->tip_text->update(get_current_tip());
134 }
135
136
137
138
139
140
141 TipWindowGUI::TipWindowGUI(MWindow *mwindow, 
142         TipWindow *thread,
143         int x,
144         int y)
145  : BC_Window(PROGRAM_NAME ": Tip of the day",
146         x,
147         y,
148         640,
149         100,
150         640,
151         100,
152         0,
153         0,
154         1)
155 {
156         this->mwindow = mwindow;
157         this->thread = thread;
158 }
159
160 void TipWindowGUI::create_objects()
161 {
162         int x = 10, y = 10;
163 SET_TRACE
164         add_subwindow(tip_text = new BC_Title(x, y, thread->get_current_tip()));
165         y = get_h() - 30;
166 SET_TRACE
167         BC_CheckBox *checkbox; 
168         add_subwindow(checkbox = new TipDisable(mwindow, this, x, y));
169 SET_TRACE
170         BC_Button *button;
171         y = get_h() - TipClose::calculate_h(mwindow) - 10;
172         x = get_w() - TipClose::calculate_w(mwindow) - 10;
173         add_subwindow(button = new TipClose(mwindow, this, x, y));
174 SET_TRACE
175         x -= TipNext::calculate_w(mwindow) + 10;
176         add_subwindow(button = new TipNext(mwindow, this, x, y));
177 SET_TRACE
178         x -= TipPrev::calculate_w(mwindow) + 10;
179         add_subwindow(button = new TipPrev(mwindow, this, x, y));
180 SET_TRACE
181         x += button->get_w() + 10;
182
183         show_window();
184         raise_window();
185 }
186
187 int TipWindowGUI::keypress_event()
188 {
189         switch(get_keypress())
190         {
191                 case RETURN:
192                 case ESC:
193                 case 'w':
194                         set_done(0);
195                         break;
196         }
197         return 0;
198 }
199
200
201
202
203
204
205
206 TipDisable::TipDisable(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
207  : BC_CheckBox(x, 
208         y, 
209         mwindow->preferences->use_tipwindow, 
210         _("Show tip of the day."))
211 {
212         this->mwindow = mwindow;
213         this->gui = gui;
214 }
215
216 int TipDisable::handle_event()
217 {
218         mwindow->preferences->use_tipwindow = get_value();
219         return 1;
220 }
221
222
223
224 TipNext::TipNext(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
225  : BC_Button(x, 
226         y, 
227         mwindow->theme->get_image_set("next_tip"))
228 {
229         this->mwindow = mwindow;
230         this->gui = gui;
231         set_tooltip(_("Next tip"));
232 }
233 int TipNext::handle_event()
234 {
235         gui->thread->next_tip();
236         return 1;
237 }
238
239 int TipNext::calculate_w(MWindow *mwindow)
240 {
241         return mwindow->theme->get_image_set("next_tip")[0]->get_w();
242 }
243
244
245
246
247
248
249 TipPrev::TipPrev(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
250  : BC_Button(x, y, mwindow->theme->get_image_set("prev_tip"))
251 {
252         this->mwindow = mwindow;
253         this->gui = gui;
254         set_tooltip(_("Previous tip"));
255 }
256
257 int TipPrev::handle_event()
258 {
259         gui->thread->prev_tip();
260         return 1;
261 }
262 int TipPrev::calculate_w(MWindow *mwindow)
263 {
264         return mwindow->theme->get_image_set("prev_tip")[0]->get_w();
265 }
266
267
268
269
270
271
272
273
274
275 TipClose::TipClose(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
276  : BC_Button(x, y, mwindow->theme->get_image_set("close_tip"))
277 {
278         this->mwindow = mwindow;
279         this->gui = gui;
280         set_tooltip(_("Close"));
281 }
282
283 int TipClose::handle_event()
284 {
285         gui->set_done(0);
286         return 1;
287 }
288
289 int TipClose::calculate_w(MWindow *mwindow)
290 {
291         return mwindow->theme->get_image_set("close_tip")[0]->get_w();
292 }
293 int TipClose::calculate_h(MWindow *mwindow)
294 {
295         return mwindow->theme->get_image_set("close_tip")[0]->get_h();
296 }
297
298
299