colorpicker rework, cin.desktop+shortcuts+license updates, edit titlebar colors+auto...
[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, 16, 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->set_active(handler);
62                 gui->set_color(handler->color);
63                 gui->fill_color(handler->color);
64                 result = 1;
65         }
66         active_lock->unlock();
67         return result;
68 }
69
70 int RemoteControl::deactivate()
71 {
72         int result = 0;
73         active_lock->lock("RemoteControl::deactivate");
74         if( is_active() ) {
75                 gui->set_inactive();
76                 result = 1;
77         }
78         active_lock->unlock();
79         return result;
80 }
81
82 int RemoteControl::remote_key(int key)
83 {
84         if( !is_active() ) return 0;
85         return handler->remote_process_key(this, key);
86 }
87
88 void RemoteControl::set_color(int color)
89 {
90         gui->lock_window("RemoteControl::fill_color");
91         gui->set_color(color);
92         gui->unlock_window();
93 }
94
95 void RemoteControl::fill_color(int color)
96 {
97         gui->lock_window("RemoteControl::fill_color");
98         gui->fill_color(color);
99         gui->unlock_window();
100 }
101
102 RemoteGUI::RemoteGUI(BC_WindowBase *wdw, RemoteControl *remote_control)
103  : BC_Popup(wdw, remote_control->mwindow_gui->mwindow->session->mwindow_x,0,16,16, -1, 1)
104 {
105         this->remote_control = remote_control;
106 }
107
108 RemoteGUI::~RemoteGUI()
109 {
110 }
111
112 void RemoteGUI::set_active(RemoteHandler *handler)
113 {
114         remote_control->handler = handler;
115         show_window();
116         grab_keyboard();
117 }
118
119 void RemoteGUI::set_inactive()
120 {
121         remote_control->handler = 0;
122         ungrab_keyboard();
123         hide_window();
124 }
125
126 void RemoteGUI::
127 fill_color(int color)
128 {
129         set_color(color);
130         draw_box(0, 0, get_w(), get_h());
131         flash();
132 }
133
134 void RemoteGUI::tile_windows(int config)
135 {
136         MWindow *mwindow = remote_control->mwindow_gui->mwindow;
137         if( config == mwindow->session->window_config ) return;
138         lock_window("RemoteGUI::tile_windows");
139         ungrab_keyboard();  hide_window();
140         mwindow->gui->lock_window("RemoteGUI::tile_windows 1");
141         int need_reload = mwindow->tile_windows(config);
142         mwindow->gui->unlock_window();
143         if( !need_reload ) {
144                 show_window();  raise_window();  grab_keyboard();
145                 reposition_window(mwindow->session->mwindow_x,0);
146                 unlock_window();
147         }
148         else {
149                 unlock_window();
150                 mwindow->restart_status = 1;
151                 mwindow->quit();
152         }
153 }
154
155 int RemoteGUI::button_press_event()
156 {
157         remote_control->deactivate();
158         return 1;
159 }
160
161 int RemoteGUI::keypress_event()
162 {
163         int key = get_keypress();
164         int result = remote_control->remote_key(key);
165         if( result < 0 ) {
166                 remote_control->deactivate();
167                 result = 0;
168         }
169         return result;
170 }
171
172 RemoteHandler::
173 RemoteHandler(RemoteGUI *gui, int color)
174 {
175         this->gui = gui;
176         this->color = color;
177 }
178
179 RemoteHandler::~RemoteHandler()
180 {
181 }
182
183