add libdav1d codec, add remap_a/v_codec option keywords
[goodguy/cinelerra.git] / cinelerra-5.1 / 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 "bcbutton.h"
23 #include "bcdialog.h"
24 #include "bcdisplayinfo.h"
25 #include "bcresources.h"
26 #include "bcsignals.h"
27 #include "bctoggle.h"
28 #include "cstrdup.h"
29 #include "file.h"
30 #include "keys.h"
31 #include "language.h"
32 #include "mainsession.h"
33 #include "mwindow.h"
34 #include "preferences.h"
35 #include "theme.h"
36 #include "tipwindow.h"
37
38
39 // Table of tips of the day
40 static Tips tips;
41
42
43 TipWindow::TipWindow(MWindow *mwindow)
44  : BC_DialogThread()
45 {
46         this->mwindow = mwindow;
47 }
48
49 TipWindow::~TipWindow()
50 {
51         close_window();
52 }
53
54 void TipWindow::load_tips(const char *lang)
55 {
56         tips.remove_all_objects();
57         char tip[0x10000];  tip[0] = 0;
58         char string[BCTEXTLEN];
59         sprintf(string, "%s/%s.%s", File::get_cindat_path(), TIPS_FILE, lang);
60         FILE *fp = fopen(string, "r");
61         if( !fp ) {
62                 sprintf(tip, _("tip file missing:\n %s"), string);
63                 tips.add(tip);
64                 return;
65         }
66
67         while( fgets(string, sizeof(string), fp) ) {
68                 if( string[0] == '\n' && string[1] == 0 && strlen(tip) > 0 ) {
69                         tips.add(tip);
70                         tip[0] = 0;
71                         continue;
72                 }
73                 strcat(tip, string);
74         }
75
76         fclose(fp);
77 }
78
79 void TipWindow::handle_close_event(int result)
80 {
81         gui = 0;
82 }
83
84 BC_Window* TipWindow::new_gui()
85 {
86         BC_DisplayInfo display_info;
87         int x = display_info.get_abs_cursor_x();
88         int y = display_info.get_abs_cursor_y();
89         TipWindowGUI *gui = this->gui = new TipWindowGUI(mwindow, this, x, y);
90         gui->create_objects();
91         return gui;
92 }
93
94 const char* TipWindow::get_current_tip(int n)
95 {
96         mwindow->session->current_tip += n;
97         if( mwindow->session->current_tip < 0 )
98                 mwindow->session->current_tip = tips.size()-1;
99         else if( mwindow->session->current_tip >= tips.size() )
100                 mwindow->session->current_tip = 0;
101         const char *result = tips[mwindow->session->current_tip];
102         mwindow->save_defaults();
103         return result;
104 }
105
106 void TipWindow::next_tip()
107 {
108         gui->tip_text->update(get_current_tip(1));
109 }
110
111 void TipWindow::prev_tip()
112 {
113         gui->tip_text->update(get_current_tip(-1));
114 }
115
116
117
118 TipWindowGUI::TipWindowGUI(MWindow *mwindow, TipWindow *thread, int x, int y)
119  : BC_Window(_(PROGRAM_NAME ": Tip of the day"), x, y,
120                 640, 100, 640, 100, 0, 0, 1)
121 {
122         this->mwindow = mwindow;
123         this->thread = thread;
124 }
125
126 void TipWindowGUI::create_objects()
127 {
128         lock_window("TipWindowGUI::create_objects");
129         int x = 10, y = 10;
130         add_subwindow(tip_text = new BC_Title(x, y, thread->get_current_tip(1)));
131         y = get_h() - 30;
132         BC_CheckBox *checkbox;
133         add_subwindow(checkbox = new TipDisable(mwindow, this, x, y));
134         BC_Button *button;
135         y = get_h() - TipClose::calculate_h(mwindow) - 10;
136         x = get_w() - TipClose::calculate_w(mwindow) - 10;
137         add_subwindow(button = new TipClose(mwindow, this, x, y));
138         x -= TipNext::calculate_w(mwindow) + 10;
139         add_subwindow(button = new TipNext(mwindow, this, x, y));
140         x -= TipPrev::calculate_w(mwindow) + 10;
141         add_subwindow(button = new TipPrev(mwindow, this, x, y));
142         x += button->get_w() + 10;
143
144         show_window();
145         raise_window();
146         unlock_window();
147 }
148
149 int TipWindowGUI::keypress_event()
150 {
151         switch(get_keypress()) {
152         case RETURN:
153         case ESC:
154         case 'w':
155                 set_done(0);
156                 break;
157         }
158         return 0;
159 }
160
161
162
163 TipDisable::TipDisable(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
164  : BC_CheckBox(x, y, mwindow->preferences->use_tipwindow,
165         _("Show tip of the day."))
166 {
167         this->mwindow = mwindow;
168         this->gui = gui;
169 }
170
171 int TipDisable::handle_event()
172 {
173         mwindow->preferences->use_tipwindow = get_value();
174         return 1;
175 }
176
177
178
179 TipNext::TipNext(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
180  : BC_Button(x, y, mwindow->theme->get_image_set("next_tip"))
181 {
182         this->mwindow = mwindow;
183         this->gui = gui;
184         set_tooltip(_("Next tip"));
185 }
186 int TipNext::handle_event()
187 {
188         gui->thread->next_tip();
189         return 1;
190 }
191
192 int TipNext::calculate_w(MWindow *mwindow)
193 {
194         return mwindow->theme->get_image_set("next_tip")[0]->get_w();
195 }
196
197
198
199 TipPrev::TipPrev(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
200  : BC_Button(x, y, mwindow->theme->get_image_set("prev_tip"))
201 {
202         this->mwindow = mwindow;
203         this->gui = gui;
204         set_tooltip(_("Previous tip"));
205 }
206
207 int TipPrev::handle_event()
208 {
209         gui->thread->prev_tip();
210         return 1;
211 }
212 int TipPrev::calculate_w(MWindow *mwindow)
213 {
214         return mwindow->theme->get_image_set("prev_tip")[0]->get_w();
215 }
216
217
218 TipClose::TipClose(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
219  : BC_Button(x, y, mwindow->theme->get_image_set("close_tip"))
220 {
221         this->mwindow = mwindow;
222         this->gui = gui;
223         set_tooltip(_("Close"));
224 }
225
226 int TipClose::handle_event()
227 {
228         gui->set_done(0);
229         return 1;
230 }
231
232 int TipClose::calculate_w(MWindow *mwindow)
233 {
234         return mwindow->theme->get_image_set("close_tip")[0]->get_w();
235 }
236 int TipClose::calculate_h(MWindow *mwindow)
237 {
238         return mwindow->theme->get_image_set("close_tip")[0]->get_h();
239 }
240
241
242