Add back 2 patches for histogram and overlayframe that are working correctly and...
[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                 xS(640), yS(110), xS(640), yS(110), 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 xs10 = xS(10), ys10 = yS(10), ys30 = yS(30);
130         int x = xs10, y = ys10;
131         add_subwindow(tip_text = new BC_Title(x, y, thread->get_current_tip(1)));
132         y = get_h() - ys30;
133         BC_CheckBox *checkbox;
134         add_subwindow(checkbox = new TipDisable(mwindow, this, x, y));
135         BC_Button *button;
136         y = get_h() - TipClose::calculate_h(mwindow) - ys10;
137         x = get_w() - TipClose::calculate_w(mwindow) - xs10;
138         add_subwindow(button = new TipClose(mwindow, this, x, y));
139         x -= TipNext::calculate_w(mwindow) + xs10;
140         add_subwindow(button = new TipNext(mwindow, this, x, y));
141         x -= TipPrev::calculate_w(mwindow) + xs10;
142         add_subwindow(button = new TipPrev(mwindow, this, x, y));
143         x += button->get_w() + xs10;
144
145         show_window();
146         raise_window();
147         unlock_window();
148 }
149
150 int TipWindowGUI::keypress_event()
151 {
152         switch(get_keypress()) {
153         case RETURN:
154         case ESC:
155         case 'w':
156                 set_done(0);
157                 break;
158         }
159         return context_help_check_and_show();
160 }
161
162
163
164 TipDisable::TipDisable(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
165  : BC_CheckBox(x, y, mwindow->preferences->use_tipwindow,
166         _("Show tip of the day."))
167 {
168         this->mwindow = mwindow;
169         this->gui = gui;
170 }
171
172 int TipDisable::handle_event()
173 {
174         mwindow->preferences->use_tipwindow = get_value();
175         return 1;
176 }
177
178
179
180 TipNext::TipNext(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
181  : BC_Button(x, y, mwindow->theme->get_image_set("next_tip"))
182 {
183         this->mwindow = mwindow;
184         this->gui = gui;
185         set_tooltip(_("Next tip"));
186 }
187 int TipNext::handle_event()
188 {
189         gui->thread->next_tip();
190         return 1;
191 }
192
193 int TipNext::calculate_w(MWindow *mwindow)
194 {
195         return mwindow->theme->get_image_set("next_tip")[0]->get_w();
196 }
197
198
199
200 TipPrev::TipPrev(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
201  : BC_Button(x, y, mwindow->theme->get_image_set("prev_tip"))
202 {
203         this->mwindow = mwindow;
204         this->gui = gui;
205         set_tooltip(_("Previous tip"));
206 }
207
208 int TipPrev::handle_event()
209 {
210         gui->thread->prev_tip();
211         return 1;
212 }
213 int TipPrev::calculate_w(MWindow *mwindow)
214 {
215         return mwindow->theme->get_image_set("prev_tip")[0]->get_w();
216 }
217
218
219 TipClose::TipClose(MWindow *mwindow, TipWindowGUI *gui, int x, int y)
220  : BC_Button(x, y, mwindow->theme->get_image_set("close_tip"))
221 {
222         this->mwindow = mwindow;
223         this->gui = gui;
224         set_tooltip(_("Close"));
225 }
226
227 int TipClose::handle_event()
228 {
229         gui->set_done(0);
230         return 1;
231 }
232
233 int TipClose::calculate_w(MWindow *mwindow)
234 {
235         return mwindow->theme->get_image_set("close_tip")[0]->get_w();
236 }
237 int TipClose::calculate_h(MWindow *mwindow)
238 {
239         return mwindow->theme->get_image_set("close_tip")[0]->get_h();
240 }
241
242
243