00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "precomp.h"
00010 #include "API/Display/Display/display.h"
00011 #include "API/Display/Input/input.h"
00012 #include "API/Display/Input/inputdevice.h"
00013 #include "API/Display/Input/inputcursor.h"
00014 #include "API/Core/System/system.h"
00015 #include "API/GUI/component.h"
00016 #include "gui_manager_generic.h"
00017 #include "component_manager_generic.h"
00018
00020
00021
00022 CL_GUIManager_Generic::CL_GUIManager_Generic(CL_GUIManager *_owner, CL_Component *parent_component)
00023 :
00024 owner(_owner),
00025 parent(NULL),
00026 input_enabled(true),
00027 comp_focus(_owner),
00028 comp_capture_mouse(NULL),
00029 comp_mouse_over(NULL)
00030 {
00031 owner->set_gui_manager(owner);
00032
00033 if(parent_component)
00034 {
00035 parent = parent_component->get_gui_manager();
00036 if(parent)
00037 parent->disable_input();
00038 }
00039
00040 slot_button_press = CL_Input::sig_button_press.connect(
00041 CL_CreateSlot(
00042 this,
00043 &CL_GUIManager_Generic::on_button_press));
00044
00045 slot_button_release = CL_Input::sig_button_release.connect(
00046 CL_CreateSlot(
00047 this,
00048 &CL_GUIManager_Generic::on_button_release));
00049
00050 slot_mouse_move = CL_Input::sig_mouse_move.connect(
00051 CL_CreateSlot(
00052 this,
00053 &CL_GUIManager_Generic::on_mouse_move));
00054 }
00055
00056 CL_GUIManager_Generic::~CL_GUIManager_Generic()
00057 {
00058 if (parent)
00059 parent->enable_input();
00060
00061 disable_input();
00062 }
00063
00065
00066
00067 CL_Component *CL_GUIManager_Generic::get_focus()
00068 {
00069 return comp_focus;
00070 }
00071
00073
00074
00075 void CL_GUIManager_Generic::set_focus(CL_Component *component)
00076 {
00077 if (comp_focus == component) return;
00078
00079 comp_focus->sig_lost_focus()();
00080 comp_focus = component;
00081 comp_focus->sig_got_focus()();
00082 }
00083
00084 void CL_GUIManager_Generic::quit()
00085 {
00086 quit_run = true;
00087 }
00088
00089 void CL_GUIManager_Generic::run()
00090 {
00091 quit_run = false;
00092 while (!quit_run)
00093 {
00094 if (parent)
00095 parent->show();
00096 show();
00097
00098 CL_Display::flip_display();
00099 CL_System::keep_alive();
00100 }
00101 }
00102
00103 void CL_GUIManager_Generic::show()
00104 {
00105 if (parent)
00106 parent->show();
00107
00108 owner->update();
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 }
00127
00128 void CL_GUIManager_Generic::enable_input()
00129 {
00130 input_enabled = true;
00131 }
00132
00133 void CL_GUIManager_Generic::disable_input()
00134 {
00135 input_enabled = false;
00136 }
00137
00138 void CL_GUIManager_Generic::gui_capture_mouse(CL_Component *component)
00139 {
00140 comp_capture_mouse = component;
00141 }
00142
00143 void CL_GUIManager_Generic::gui_release_mouse()
00144 {
00145 comp_capture_mouse = NULL;
00146 }
00147
00148 void CL_GUIManager_Generic::on_button_press(
00149 CL_InputDevice *device,
00150 const CL_Key &key)
00151 {
00152 if (!input_enabled) return;
00153
00154 CL_Key k = key;
00155 int _x = k.x;
00156 int _y = k.y;
00157
00158 owner->sig_transform_coords()(_x, _y);
00159
00160 k.x = _x;
00161 k.y = _y;
00162 k.x -= owner->get_position().x1;
00163 k.y -= owner->get_position().y1;
00164
00165
00166 if (comp_capture_mouse)
00167 owner->sig_key_down()(comp_capture_mouse, device, k);
00168
00169
00170 else if (device == CL_Input::pointers[0])
00171 owner->sig_key_down()(NULL, device, k);
00172
00173
00174 else
00175 owner->sig_key_down()(comp_focus, device, k);
00176 }
00177
00178 void CL_GUIManager_Generic::on_button_release(
00179 CL_InputDevice *device,
00180 const CL_Key &key)
00181 {
00182 if (!input_enabled) return;
00183
00184 CL_Key k = key;
00185 int _x = k.x;
00186 int _y = k.y;
00187
00188 owner->sig_transform_coords()(_x, _y);
00189
00190 k.x = _x;
00191 k.y = _y;
00192 k.x -= owner->get_position().x1;
00193 k.y -= owner->get_position().y1;
00194
00195
00196 if (comp_capture_mouse)
00197 owner->sig_key_up()(comp_capture_mouse, device, k);
00198
00199
00200 else if (device == CL_Input::pointers[0])
00201 owner->sig_key_up()(NULL, device, k);
00202
00203
00204 else
00205 owner->sig_key_up()(comp_focus, device, k);
00206 }
00207
00208 void CL_GUIManager_Generic::on_mouse_move(
00209 CL_InputDevice *device,
00210 int x,
00211 int y)
00212 {
00213 if (!input_enabled) return;
00214
00215 owner->sig_transform_coords()(x, y);
00216
00217
00218 if (comp_capture_mouse)
00219 owner->sig_mouse_moved()(comp_capture_mouse, device, x, y);
00220
00221
00222 else if (device == CL_Input::pointers[0])
00223 owner->sig_mouse_moved()(NULL, device, x, y);
00224
00225
00226 else
00227 owner->sig_mouse_moved()(comp_focus, device, x, y);
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 }