prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / canvas.h
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 #ifndef CANVAS_H
23 #define CANVAS_H
24
25 #include "edl.inc"
26 #include "guicast.h"
27 #include "mwindow.inc"
28
29 // Output for all X11 video
30
31 class CanvasOutput;
32 class CanvasFullScreen;
33 class CanvasXScroll;
34 class CanvasYScroll;
35 class CanvasPopup;
36 class CanvasFullScreenPopup;
37 class CanvasToggleControls;
38
39 // The EDL arguments can be set to 0 if the canvas_w and canvas_h are used
40 class Canvas
41 {
42 public:
43         Canvas(MWindow *mwindow,
44                 BC_WindowBase *subwindow, 
45                 int x, 
46                 int y, 
47                 int w, 
48                 int h,
49                 int output_w,
50                 int output_h,
51                 int use_scrollbars);
52         virtual ~Canvas();
53
54         void reset();
55 // Get dimensions given a zoom
56         void calculate_sizes(float aspect_ratio, 
57                 int output_w, 
58                 int output_h, 
59                 float zoom, 
60                 int &w, 
61                 int &h);
62 // Lock access to the canvas pointer.
63 // Must be called before get_canvas or locking the canvas.
64         void lock_canvas(const char *location);
65         void unlock_canvas();
66         int is_locked();
67
68         void create_objects(EDL *edl);
69         void set_cursor(int cursor);
70 // Start video playback
71         void start_video();
72         void stop_video();
73
74 // Start single frame processing.  Causes the status indicator to update
75         void start_single();
76         void stop_single();
77
78         void start_fullscreen();
79         void stop_fullscreen();
80
81 // Don't call from inside the canvas
82         void create_canvas();
83
84
85
86 // Processing or video playback changed.
87         virtual void status_event() {};
88
89
90         virtual void reset_camera() {};
91         virtual void reset_projector() {};
92         virtual void zoom_resize_window(float percentage) {};
93         virtual void zoom_auto() {};
94         virtual int cursor_leave_event() { return 0; };
95         virtual int cursor_enter_event() { return 0; };
96         virtual int button_release_event() { return 0; };
97         virtual int button_press_event();
98         virtual int cursor_motion_event() { return 0; };
99         virtual void draw_overlays() { };
100         virtual void toggle_controls() { } ;
101         virtual int get_cwindow_controls() { return 0; };
102         virtual int get_fullscreen() { return 0; }
103         virtual void set_fullscreen(int value) { };
104
105         int cursor_leave_event_base(BC_WindowBase *caller);
106         int cursor_enter_event_base(BC_WindowBase *caller);
107         int button_press_event_base(BC_WindowBase *caller);
108         int keypress_event(BC_WindowBase *caller);
109 // Use menu different options for different windows
110         void use_cwindow();
111         void use_rwindow();
112         void use_vwindow();
113         void use_auxwindow(BC_WindowBase *aux);
114
115 // Provide canvas dimensions since a BC_Bitmap containing obsolete dimensions
116 // is often the output being transferred to.
117 // This gets the input coordinates on the device output_frame
118 // and the corresponding output coordinates on the canvas.
119 // Must be floating point to support OpenGL.
120         void get_transfers(EDL *edl, 
121                 float &output_x1, 
122                 float &output_y1, 
123                 float &output_x2, 
124                 float &output_y2,
125                 float &canvas_x1, 
126                 float &canvas_y1, 
127                 float &canvas_x2, 
128                 float &canvas_y2,
129 // passing -1 causes automatic size detection
130                 int canvas_w = -1,
131                 int canvas_h = -1);
132         void reposition_window(EDL *edl, int x, int y, int w, int h);
133         virtual void reset_translation() {};
134         virtual void close_source() {};
135 // Updates the stores
136         virtual void update_zoom(int x, int y, float zoom) {};
137         void check_boundaries(EDL *edl, int &x, int &y, float &zoom);
138         void update_scrollbars(int flush);
139 // Get scrollbar positions relative to output.
140 // No correction is done if output is smaller than canvas
141         virtual int get_xscroll() { return 0; };
142         virtual int get_yscroll() { return 0; };
143         virtual float get_zoom() { return 0; };
144 // Redraws the image
145         virtual void draw_refresh(int flush = 1) {};
146
147 // Get top left offset of canvas relative to output.
148 // Normally negative.  Can be positive if output is smaller than canvas.
149         float get_x_offset(EDL *edl, 
150                 int single_channel, 
151                 float zoom_x, 
152                 float conformed_w,
153                 float conformed_h);
154         float get_y_offset(EDL *edl, 
155                 int single_channel, 
156                 float zoom_y, 
157                 float conformed_w,
158                 float conformed_h);
159         void get_zooms(EDL *edl, 
160                 int single_channel, 
161                 float &zoom_x, 
162                 float &zoom_y,
163                 float &conformed_w,
164                 float &conformed_h);
165         
166         
167 // Convert coord from output to canvas position, including
168 // x and y scroll offsets
169         void output_to_canvas(EDL *edl, int single_channel, float &x, float &y);
170 // Convert coord from canvas to output position
171         void canvas_to_output(EDL *edl, int single_channel, float &x, float &y);
172
173 // Get dimensions of frame being sent to canvas
174         virtual int get_output_w(EDL *edl);
175         virtual int get_output_h(EDL *edl);
176 // Get if scrollbars exist
177         int scrollbars_exist();
178 // Get cursor locations relative to canvas and not offset by scrollbars
179         int get_cursor_x();
180         int get_cursor_y();
181         int get_buttonpress();
182 // Gets whatever video surface is enabled
183         BC_WindowBase* get_canvas();
184
185 // The owner of the canvas
186         BC_WindowBase *subwindow;
187 // Video surface if a subwindow
188         CanvasOutput *canvas_subwindow;
189 // Video surface if fullscreen
190         CanvasFullScreen *canvas_fullscreen;
191         CanvasXScroll *xscroll;
192         CanvasYScroll *yscroll;
193         CanvasPopup *canvas_menu;
194         CanvasFullScreenPopup *fullscreen_menu;
195         int x, y, w, h;
196         int use_scrollbars;
197         BC_WindowBase *canvas_auxwindow;
198 // Used in record monitor
199         int output_w, output_h;
200 // Last frame played is stored here in driver format for 
201 // refreshes.
202         VFrame *refresh_frame;
203 // Results from last get_scrollbars
204         int w_needed;
205         int h_needed;
206         int w_visible;
207         int h_visible;
208 // For cases where video is not enabled on the canvas but processing is 
209 // occurring for a single frame, this causes the status to update.
210         int is_processing;
211 // Cursor is inside video surface
212         int cursor_inside;
213         int view_x;
214         int view_y;
215         int view_w;
216         int view_h;
217         int scr_w0;
218         int root_w, root_h;
219
220         MWindow *mwindow;
221
222 private:
223         void get_scrollbars(EDL *edl, 
224                 int &canvas_x, 
225                 int &canvas_y, 
226                 int &canvas_w, 
227                 int &canvas_h);
228         Mutex *canvas_lock;
229 };
230
231
232 class CanvasOutput : public BC_SubWindow
233 {
234 public:
235         CanvasOutput(Canvas *canvas,
236         int x,
237         int y,
238         int w,
239         int h);
240         ~CanvasOutput();
241
242         int cursor_leave_event();
243         int cursor_enter_event();
244         int button_press_event();
245         int button_release_event();
246         int cursor_motion_event();
247         int keypress_event();
248
249         Canvas *canvas;
250 };
251
252
253
254
255 class CanvasFullScreen : public BC_FullScreen
256 {
257 public:
258         CanvasFullScreen(Canvas *canvas,
259         int w,
260         int h);
261         ~CanvasFullScreen();
262
263         Canvas *canvas;
264 };
265
266
267
268
269 class CanvasXScroll : public BC_ScrollBar
270 {
271 public:
272         CanvasXScroll(EDL *edl, 
273                 Canvas *canvas, 
274                 int x, 
275                 int y, 
276                 int length, 
277                 int position, 
278                 int handle_length, 
279                 int pixels);
280         ~CanvasXScroll();
281
282         int handle_event();
283         Canvas *canvas;
284         EDL *edl;
285 };
286
287 class CanvasYScroll : public BC_ScrollBar
288 {
289 public:
290         CanvasYScroll(EDL *edl, 
291                 Canvas *canvas, 
292                 int x, 
293                 int y, 
294                 int length, 
295                 int position, 
296                 int handle_length, 
297                 int pixels);
298         ~CanvasYScroll();
299
300         int handle_event();
301
302         Canvas *canvas;
303         EDL *edl;
304 };
305
306 class CanvasFullScreenPopup : public BC_PopupMenu
307 {
308 public:
309         CanvasFullScreenPopup(Canvas *canvas);
310
311         void create_objects();
312         void use_cwindow();
313
314         Canvas *canvas;
315 };
316
317 class CanvasSubWindowItem : public BC_MenuItem
318 {
319 public:
320         CanvasSubWindowItem(Canvas *canvas);
321         int handle_event();
322         Canvas *canvas;
323 };
324
325 class CanvasPopup : public BC_PopupMenu
326 {
327 public:
328         CanvasPopup(Canvas *canvas);
329         ~CanvasPopup();
330
331         void create_objects();
332         void use_cwindow();
333         void use_rwindow();
334         void use_vwindow();
335
336         Canvas *canvas;
337         CanvasToggleControls *toggle_controls;
338 };
339
340 class CanvasPopupSize : public BC_MenuItem
341 {
342 public:
343         CanvasPopupSize(Canvas *canvas, char *text, float percentage);
344         ~CanvasPopupSize();
345         int handle_event();
346         Canvas *canvas;
347         float percentage;
348 };
349
350 class CanvasPopupAuto : public BC_MenuItem
351 {
352 public:
353         CanvasPopupAuto(Canvas *canvas);
354         int handle_event();
355         Canvas *canvas;
356 };
357
358 class CanvasPopupResetCamera : public BC_MenuItem
359 {
360 public:
361         CanvasPopupResetCamera(Canvas *canvas);
362         int handle_event();
363         Canvas *canvas;
364 };
365
366 class CanvasPopupResetProjector : public BC_MenuItem
367 {
368 public:
369         CanvasPopupResetProjector(Canvas *canvas);
370         int handle_event();
371         Canvas *canvas;
372 };
373
374 class CanvasToggleControls : public BC_MenuItem
375 {
376 public:
377         CanvasToggleControls(Canvas *canvas);
378         int handle_event();
379         static char* calculate_text(int cwindow_controls);
380         Canvas *canvas;
381 };
382
383 class CanvasFullScreenItem : public BC_MenuItem
384 {
385 public:
386         CanvasFullScreenItem(Canvas *canvas);
387         int handle_event();
388         Canvas *canvas;
389 };
390
391 class CanvasPopupResetTranslation : public BC_MenuItem
392 {
393 public:
394         CanvasPopupResetTranslation(Canvas *canvas);
395         int handle_event();
396         Canvas *canvas;
397 };
398
399
400 class CanvasPopupRemoveSource : public BC_MenuItem
401 {
402 public:
403         CanvasPopupRemoveSource(Canvas *canvas);
404         int handle_event();
405         Canvas *canvas;
406 };
407
408
409
410
411
412 #endif