map media vicon popup
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / vicon.h
1 #ifndef __VICON_H__
2 #define __VICON_H__
3
4 #include "arraylist.h"
5 #include "bccmodels.h"
6 #include "bcpopup.h"
7 #include "bcwindowbase.h"
8 #include "thread.h"
9 #include "vicon.inc"
10 #include "vframe.h"
11
12 typedef void VIconDrawVFrame(BC_WindowBase *wdw, VFrame *frame);
13
14 class ViewPopup : public BC_Popup {
15 public:
16         VIconThread *vt;
17         int keypress_event();
18         int button_press_event();
19         int cursor_motion_event();
20
21         ViewPopup(VIconThread *vt, VFrame *frame, int x, int y, int w, int h);
22         ~ViewPopup();
23 };
24
25 class VIFrame {
26         unsigned char *img_data;
27         VFrame *vfrm;
28 public:
29         VIFrame(int ww, int hh, int vcmdl) {
30                 int size = BC_CModels::calculate_datasize(ww, hh, -1, vcmdl);
31                 img_data = new unsigned char[size];
32                 vfrm = new VFrame(img_data, -1, ww, hh, vcmdl, -1);
33         }
34         ~VIFrame() { delete vfrm;  delete [] img_data; }
35
36         operator VFrame *() { return vfrm; }
37 };
38
39 class VIcon
40 {
41 public:
42         int vw, vh, in_use, hidden;
43         ArrayList<VIFrame *> images;
44         int64_t seq_no;
45         double cycle_start, age, frame_rate;
46         int audio_size, playing_audio;
47         uint8_t *audio_data;
48
49         int64_t vframes() { return images.size(); }
50         void reset() { seq_no = 0; cycle_start = 0; age = 0; }
51         void reset(double rate) { reset(); frame_rate = rate; }
52         void clear_images() { images.remove_all_objects(); }
53         void init_audio(int audio_size);
54
55         virtual int64_t set_seq_no(int64_t no) { return seq_no = no; }
56         virtual VFrame *frame() { return *images[seq_no]; }
57         virtual int get_vx() { return 0; }
58         virtual int get_vy() { return 0; }
59         virtual void load_audio() {}
60         virtual void start_audio() {}
61         virtual void stop_audio() {}
62         virtual int popup_button_press(int x, int y) { return 0; }
63         virtual int popup_cursor_motion(int x, int y) { return 0; }
64
65         void add_image(VFrame *frm, int ww, int hh, int vcmdl);
66         void draw_vframe(VIconThread *vt, BC_WindowBase *wdw, int x, int y);
67         void dump(const char *dir);
68
69         VIcon(int vw=VICON_WIDTH, int vh=VICON_HEIGHT, double rate=VICON_RATE);
70         virtual ~VIcon();
71 };
72
73 class VIconThread : public Thread
74 {
75 public:
76         int done, interrupted;
77         BC_WindowBase *wdw;
78         Timer *timer;
79         Condition *draw_lock;
80         ViewPopup *view_win;
81         VIcon *viewing, *vicon;
82         int view_w, view_h;
83         int draw_x0, draw_y0;
84         int draw_x1, draw_y1;
85         int img_dirty, win_dirty;
86         double refresh_rate;
87         int64_t stop_age;
88
89         ArrayList<VIcon *>t_heap;
90         VIcon *low_vicon();
91         void add_vicon(VIcon *vicon);
92         int del_vicon(VIcon *vicon);
93         void run();
94         void flash();
95         int draw(VIcon *vicon);
96         int update_view();
97         void draw_images();
98         void start_drawing();
99         void stop_drawing();
100         void reset_images();
101         void remove_vicon(int i);
102         int keypress_event(int key);
103         void set_drawing_area(int x0, int y0, int x1, int y1);
104         void set_view_popup(VIcon *vicon, VIconDrawVFrame *draw_vfrm=0);
105         void close_view_popup();
106         void hide_vicons(int v=1);
107         ViewPopup *new_view_window(VFrame *frame);
108
109         virtual bool visible(VIcon *vicon, int x, int y);
110         virtual void drawing_started() {}
111         virtual void drawing_stopped() {}
112         static VIconDrawVFrame draw_vframe;
113         VIconDrawVFrame *draw_vfrm;
114
115         VIconThread(BC_WindowBase *wdw, int vw=4*VICON_WIDTH, int vh=4*VICON_HEIGHT);
116         ~VIconThread();
117 };
118
119 #endif