RafaMar + programmer friend Help button in Batch Render addition
[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         deactivate();
57         if( !handler )
58                 handler = !mwindow_gui->record->running() ?
59                         (RemoteHandler *)mwindow_gui->cwindow_remote_handler :
60                         (RemoteHandler *)mwindow_gui->record_remote_handler ;
61         active_lock->lock("RemoteControl::activate");
62         if( handler ) {
63                 gui->lock_window("RemoteControl::activate");
64                 gui->set_active(handler);
65                 gui->set_color(handler->color);
66                 gui->fill_color(handler->color);
67                 gui->unlock_window();
68                 result = 1;
69         }
70         active_lock->unlock();
71         return result;
72 }
73
74 int RemoteControl::deactivate()
75 {
76         int result = 0;
77         if( is_active() ) {
78                 active_lock->lock("RemoteControl::deactivate");
79                 if( is_active() ) {
80                         gui->set_inactive();
81                         result = 1;
82                 }
83                 active_lock->unlock();
84         }
85         return result;
86 }
87
88 int RemoteControl::remote_key(int key)
89 {
90         if( !is_active() ) return 0;
91         return handler->remote_key(key);
92 }
93
94 void RemoteControl::set_color(int color)
95 {
96         gui->lock_window("RemoteControl::fill_color");
97         gui->set_color(color);
98         gui->unlock_window();
99 }
100
101 void RemoteControl::fill_color(int color)
102 {
103         gui->lock_window("RemoteControl::fill_color");
104         gui->fill_color(color);
105         gui->unlock_window();
106 }
107
108 RemoteGUI::RemoteGUI(BC_WindowBase *wdw, RemoteControl *remote_control)
109  : BC_Popup(wdw, remote_control->mwindow_gui->mwindow->session->mwindow_x,0,
110                 xS(16),yS(16), -1, 1)
111 {
112         this->remote_control = remote_control;
113 }
114
115 RemoteGUI::~RemoteGUI()
116 {
117 }
118
119 void RemoteGUI::set_active(RemoteHandler *handler)
120 {
121         remote_control->handler = handler;
122         show_window();
123         grab_keyboard();
124 }
125
126 void RemoteGUI::set_inactive()
127 {
128         remote_control->handler = 0;
129         ungrab_keyboard();
130         hide_window();
131 }
132
133 void RemoteGUI::
134 fill_color(int color)
135 {
136         set_color(color);
137         draw_box(0, 0, get_w(), get_h());
138         flash();
139 }
140
141 void RemoteGUI::tile_windows(int config)
142 {
143         MWindow *mwindow = remote_control->mwindow_gui->mwindow;
144         if( config == mwindow->session->window_config ) return;
145         lock_window("RemoteGUI::tile_windows");
146         ungrab_keyboard();  hide_window();
147         mwindow->gui->lock_window("RemoteGUI::tile_windows 1");
148         int need_reload = mwindow->tile_windows(config);
149         mwindow->gui->unlock_window();
150         if( !need_reload ) {
151                 show_window();  raise_window();  grab_keyboard();
152                 reposition_window(mwindow->session->mwindow_x,0);
153                 unlock_window();
154         }
155         else {
156                 unlock_window();
157                 mwindow->restart_status = 1;
158                 mwindow->quit();
159         }
160 }
161
162 int RemoteGUI::button_press_event()
163 {
164         remote_control->deactivate();
165         return 1;
166 }
167
168 int RemoteGUI::keypress_event()
169 {
170         int key = get_keypress();
171         int result = remote_control->remote_key(key);
172         if( result < 0 ) {
173                 remote_control->deactivate();
174                 result = 0;
175         }
176         return result;
177 }
178
179 RemoteHandler::RemoteHandler(RemoteGUI *gui, int color)
180 {
181         this->gui = gui;
182         this->color = color;
183 }
184
185 RemoteHandler::~RemoteHandler()
186 {
187 }
188
189 int RemoteHandler::remote_key(int key)
190 {
191         gui->set_inactive();
192         return -1;
193 }
194
195 int RemoteHandler::process_key(int key)
196 {
197         return -1;
198 }
199