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