fix segv for plugin render_gui when plugin moved up/dn, opencv build fixes, opts...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / remotecontrol.C
1
2 #include "bccolors.h"
3 #include "mainsession.h"
4 #include "mwindow.h"
5 #include "mwindowgui.h"
6 #include "record.h"
7 #include "remotecontrol.h"
8
9
10 RemoteWindow::RemoteWindow(RemoteControl *remote_control)
11  : BC_Window(_(PROGRAM_NAME ": RemoteWindow"),
12                 0, 0, xS(16), yS(16), -1, -1, 1, 0, 1)
13 {
14         this->remote_control = remote_control;
15 }
16
17 RemoteWindow::~RemoteWindow()
18 {
19 }
20
21
22 RemoteControl::RemoteControl(MWindowGUI *mwindow_gui)
23  : Thread(1, 0, 0)
24 {
25         this->mwindow_gui = mwindow_gui;
26         this->handler = 0;
27         active_lock = new Mutex("RemoteControl::active_lock");
28
29         remote_window = new RemoteWindow(this);
30         Thread::start();
31         remote_window->init_wait();
32         gui = new RemoteGUI(remote_window, this);
33 }
34
35 void RemoteControl::run()
36 {
37         remote_window->run_window();
38 }
39
40 RemoteControl::~RemoteControl()
41 {
42         if( Thread::running() ) {
43                 remote_window->close(1);
44         }
45         Thread::join();
46         delete gui;
47         delete remote_window;
48         delete active_lock;
49 }
50
51
52
53 int RemoteControl::activate(RemoteHandler *handler)
54 {
55         int result = 0;
56         active_lock->lock("RemoteControl::activate");
57         if( !is_active() ) {
58                 if( !handler ) handler = !mwindow_gui->record->running() ?
59                         (RemoteHandler *)mwindow_gui->cwindow_remote_handler :
60                         (RemoteHandler *)mwindow_gui->record_remote_handler ;
61                 gui->lock_window("RemoteControl::activate");
62                 gui->set_active(handler);
63                 gui->set_color(handler->color);
64                 gui->fill_color(handler->color);
65                 gui->unlock_window();
66                 result = 1;
67         }
68         active_lock->unlock();
69         return result;
70 }
71
72 int RemoteControl::deactivate()
73 {
74         int result = 0;
75         active_lock->lock("RemoteControl::deactivate");
76         if( is_active() ) {
77                 gui->set_inactive();
78                 result = 1;
79         }
80         active_lock->unlock();
81         return result;
82 }
83
84 int RemoteControl::remote_key(int key)
85 {
86         if( !is_active() ) return 0;
87         return handler->remote_process_key(this, key);
88 }
89
90 void RemoteControl::set_color(int color)
91 {
92         gui->lock_window("RemoteControl::fill_color");
93         gui->set_color(color);
94         gui->unlock_window();
95 }
96
97 void RemoteControl::fill_color(int color)
98 {
99         gui->lock_window("RemoteControl::fill_color");
100         gui->fill_color(color);
101         gui->unlock_window();
102 }
103
104 RemoteGUI::RemoteGUI(BC_WindowBase *wdw, RemoteControl *remote_control)
105  : BC_Popup(wdw, remote_control->mwindow_gui->mwindow->session->mwindow_x,0,
106                 xS(16),yS(16), -1, 1)
107 {
108         this->remote_control = remote_control;
109 }
110
111 RemoteGUI::~RemoteGUI()
112 {
113 }
114
115 void RemoteGUI::set_active(RemoteHandler *handler)
116 {
117         remote_control->handler = handler;
118         show_window();
119         grab_keyboard();
120 }
121
122 void RemoteGUI::set_inactive()
123 {
124         remote_control->handler = 0;
125         ungrab_keyboard();
126         hide_window();
127 }
128
129 void RemoteGUI::
130 fill_color(int color)
131 {
132         set_color(color);
133         draw_box(0, 0, get_w(), get_h());
134         flash();
135 }
136
137 void RemoteGUI::tile_windows(int config)
138 {
139         MWindow *mwindow = remote_control->mwindow_gui->mwindow;
140         if( config == mwindow->session->window_config ) return;
141         lock_window("RemoteGUI::tile_windows");
142         ungrab_keyboard();  hide_window();
143         mwindow->gui->lock_window("RemoteGUI::tile_windows 1");
144         int need_reload = mwindow->tile_windows(config);
145         mwindow->gui->unlock_window();
146         if( !need_reload ) {
147                 show_window();  raise_window();  grab_keyboard();
148                 reposition_window(mwindow->session->mwindow_x,0);
149                 unlock_window();
150         }
151         else {
152                 unlock_window();
153                 mwindow->restart_status = 1;
154                 mwindow->quit();
155         }
156 }
157
158 int RemoteGUI::button_press_event()
159 {
160         remote_control->deactivate();
161         return 1;
162 }
163
164 int RemoteGUI::keypress_event()
165 {
166         int key = get_keypress();
167         int result = remote_control->remote_key(key);
168         if( result < 0 ) {
169                 remote_control->deactivate();
170                 result = 0;
171         }
172         return result;
173 }
174
175 RemoteHandler::
176 RemoteHandler(RemoteGUI *gui, int color)
177 {
178         this->gui = gui;
179         this->color = color;
180 }
181
182 RemoteHandler::~RemoteHandler()
183 {
184 }
185
186