Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

gui_manager_generic.cpp

Go to the documentation of this file.
00001 /*
00002         ClanGUI, copyrights by various people. Have a look in the CREDITS file.
00003         
00004         This sourcecode is distributed using the Library GNU Public Licence,
00005         version 2 or (at your option) any later version. Please read LICENSE
00006         for details.
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 // CL_GUIManager_Generic construction:
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 // CL_GUIManager_Generic attributes:
00066 
00067 CL_Component *CL_GUIManager_Generic::get_focus()
00068 {
00069         return comp_focus;
00070 }
00071 
00073 // CL_GUIManager_Generic operations:
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         // Remove all closed components
00112         bool new_focus = false;
00113         std::list<COMP_PAIR>::iterator it;
00114         for (it = components.begin(); it != components.end();)
00115         {
00116                 CL_Component *cur_component = (*it).first;
00117                 if(cur_component->is_removeflag_set())
00118                 {
00119                         it = components.erase(it);
00120                         new_focus = true;
00121                 }
00122                 else
00123                         it++;
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         // if in capture mode:
00166         if (comp_capture_mouse)
00167                 owner->sig_key_down()(comp_capture_mouse, device, k);
00168 
00169         // if it is the mouse pointer:
00170         else if (device == CL_Input::pointers[0])
00171                 owner->sig_key_down()(NULL, device, k);
00172 
00173         // keyboard, route using focused component.
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         // if in capture mode:
00196         if (comp_capture_mouse)
00197                 owner->sig_key_up()(comp_capture_mouse, device, k);
00198 
00199         // if it is the mouse pointer:
00200         else if (device == CL_Input::pointers[0])
00201                 owner->sig_key_up()(NULL, device, k);
00202 
00203         // keyboard, route using focused component.
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         // if in capture mode:
00218         if (comp_capture_mouse)
00219                 owner->sig_mouse_moved()(comp_capture_mouse, device, x, y);
00220 
00221         // if it is the mouse pointer:
00222         else if (device == CL_Input::pointers[0])
00223                 owner->sig_mouse_moved()(NULL, device, x, y);
00224 
00225         // keyboard, route using focused component.
00226         else
00227                 owner->sig_mouse_moved()(comp_focus, device, x, y);
00228 
00229 /*
00230         // Mouse enter/leave
00231         CL_Component *new_comp_mouse_over = NULL;
00232         std::list<COMP_PAIR>::iterator it;
00233         for (it = components.begin(); it != components.end(); it++)
00234         {
00235                 CL_Component *cur_component = (*it).first;
00236                 const CL_Rect &r = cur_component->get_position();
00237 
00238                 int pos_x = (int) x;
00239                 int pos_y = (int) y;
00240                 (*it).first->sig_transform_coords()(pos_x, pos_y);
00241 
00242                 if (pos_x >= r.x1 && pos_x < r.x2 &&
00243                         pos_y >= r.y1 && pos_y < r.y2)
00244                 {
00245                         int x = pos_x - r.x1;
00246                         int y = pos_y - r.y1;
00247                         new_comp_mouse_over = cur_component->get_component_at(x, y);
00248                         break;
00249                 }
00250         }
00251 
00252         if(new_comp_mouse_over != comp_mouse_over)
00253         {
00254                 if(comp_mouse_over)
00255                 {
00256                         comp_mouse_over->sig_mouse_left()();
00257                         comp_mouse_over = new_comp_mouse_over;
00258                 }
00259                 if(new_comp_mouse_over)
00260                 {
00261                         comp_mouse_over = new_comp_mouse_over;
00262                         comp_mouse_over->sig_mouse_entered()();
00263                 }
00264         }
00265 
00266         if(components.front().first->is_visible() == false ||
00267            components.front().first->is_enabled() == false)
00268                 return;
00269 
00270         int pos_x = (int) x;
00271         int pos_y = (int) y;
00272         components.front().first->sig_transform_coords()(pos_x, pos_y);
00273 
00274         if (comp_capture_mouse == NULL && device == CL_Input::pointers[0])
00275         {
00276                 const CL_Rect &r = components.front().first->get_position();
00277                 if (pos_x < r.x1 || pos_x >= r.x2 ||
00278                         pos_y < r.y1 || pos_y >= r.y2)
00279                 {
00280                         return;
00281                 }
00282         }
00283 
00284         pos_x -= components.front().first->get_position().x1;
00285         pos_y -= components.front().first->get_position().y1;
00286 
00287         if (comp_capture_mouse) std::cout << "mouse is captured!" << std::endl;
00288         components.front().first->sig_mouse_moved()(comp_capture_mouse, device, pos_x, pos_y);
00289 */
00290 }

Generated at Wed Apr 4 19:54:00 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001