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

component_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/GUI/component_style.h"
00012 #include "component_generic.h"
00013 
00014 CL_Component_Generic::CL_Component_Generic(
00015         CL_Component *_self,
00016         const CL_Rect &pos,
00017         CL_Component *_parent,
00018         CL_StyleManager *style)
00019 :
00020         self(_self),
00021         parent(_parent),
00022         style_manager(style),
00023         position(pos),
00024         gui(NULL),
00025         captured(false),
00026         visible(true),
00027         enabled(true),
00028         popup(false),
00029         removeflag(false)
00030 {
00031         if(style_manager == NULL)
00032                 if(parent)
00033                         style_manager = parent->get_style_manager();
00034 
00035         init();
00036 }
00037 
00038 void CL_Component_Generic::init()
00039 {
00040         slot_begin_paint = sig_begin_paint.connect(CL_CreateSlot(this, &CL_Component_Generic::begin_paint));
00041         slot_end_paint = sig_end_paint.connect(CL_CreateSlot(this, &CL_Component_Generic::end_paint));
00042         slot_button_press = sig_key_down.connect(CL_CreateSlot(this, &CL_Component_Generic::on_button_press));
00043         slot_button_release = sig_key_up.connect(CL_CreateSlot(this, &CL_Component_Generic::on_button_release));
00044         slot_mouse_move = sig_mouse_moved.connect(CL_CreateSlot(this, &CL_Component_Generic::on_mouse_move));
00045 }
00046 
00047 CL_Component_Generic::~CL_Component_Generic()
00048 {
00049         for (
00050                 std::list<CL_ComponentStyle *>::iterator itStyle = styles.begin();
00051                 itStyle != styles.end();
00052                 itStyle++)
00053         {
00054                 delete (*itStyle);
00055         }
00056 
00057         for (
00058                 std::list<CL_Component *>::iterator it = delete_children.begin();
00059                 it != delete_children.end();
00060                 it++)
00061         {
00062                 delete (*it);
00063         }
00064 }
00065 
00066 void CL_Component_Generic::on_button_press(
00067         CL_Component *component,
00068         CL_InputDevice *device,
00069         CL_Key key)
00070 {
00071         bool found_child = false;
00072 
00073         std::list<CL_Component *>::iterator it;
00074         for (it = children.begin();it!=children.end();it++)
00075         {
00076                 if((*it)->is_enabled())
00077                 {
00078                         CL_Key k = key;
00079                         k.x -= (*it)->get_position().x1;
00080                         k.y -= (*it)->get_position().y1;
00081 
00082                         if (*it == component || (*it)->has_child(component))
00083                         {
00084                                 (*it)->sig_key_down()(component, device, k);
00085                                 break;
00086                         }
00087 
00088                         if (
00089                                 component == NULL &&
00090                                 k.x >= 0 && k.x < (*it)->get_width() &&
00091                                 k.y >= 0 && k.y < (*it)->get_height())
00092                         {
00093                                 found_child = true;
00094                                 // no routing information. Route it accordingly to mouse coords.
00095                         
00096                                 (*it)->sig_key_down()(component, device, k);
00097                         }
00098                 }
00099         }
00100 
00101         if (component == NULL && !found_child) self->set_focus();
00102 }
00103 
00104 void CL_Component_Generic::on_button_release(
00105         CL_Component *component,
00106         CL_InputDevice *device,
00107         CL_Key key)
00108 {
00109         std::list<CL_Component *>::iterator it;
00110         for (it = children.begin();it!=children.end();it++)
00111         {
00112                 if((*it)->is_enabled())
00113                 {
00114                         CL_Key k = key;
00115                         k.x -= (*it)->get_position().x1;
00116                         k.y -= (*it)->get_position().y1;
00117 
00118                         if (*it == component || (*it)->has_child(component))
00119                         {
00120                                 (*it)->sig_key_up()(component, device, k);
00121                                 break;
00122                         }
00123 
00124                         if (
00125                                 component == NULL &&
00126                                 k.x >= 0 && k.x < (*it)->get_width() &&
00127                                 k.y >= 0 && k.y < (*it)->get_height())
00128                         {
00129                                 // no routing information. Route it accordingly to mouse coords.
00130                         
00131                                 (*it)->sig_key_up()(component, device, k);
00132                         }
00133                 }
00134         }
00135 }
00136 
00137 void CL_Component_Generic::on_mouse_move(
00138         CL_Component *component,
00139         CL_InputDevice *device,
00140         int mouse_x,
00141         int mouse_y)
00142 {
00143         std::list<CL_Component *>::iterator it;
00144         for (it = children.begin();it!=children.end();it++)
00145         {
00146                 if((*it)->is_enabled())
00147                 {
00148                         int x = mouse_x - (*it)->get_position().x1;
00149                         int y = mouse_y - (*it)->get_position().y1;
00150         
00151                         if (*it == component || (*it)->has_child(component))
00152                         {
00153                                 (*it)->sig_mouse_moved()(component, device, x, y);
00154                                 break;
00155                         }
00156                 
00157                         if (
00158                                 component == NULL &&
00159                                 x >= 0 && x < (*it)->get_width() &&
00160                                 y >= 0 && y < (*it)->get_height())
00161                         {
00162                                 // no routing information. Route it accordingly to mouse coords.
00163                         
00164                                 (*it)->sig_mouse_moved()(component, device, x, y);
00165                         }
00166                 }
00167         }
00168 }
00169 
00170 void CL_Component_Generic::begin_paint()
00171 {
00172         CL_Display::push_translate_offset(position.x1, position.y1);
00173         CL_Rect r = self->get_screen_rect();
00174         CL_Display::push_clip_rect(CL_ClipRect(r.x1, r.y1, r.x2, r.y2));
00175 }
00176 
00177 void CL_Component_Generic::end_paint()
00178 {
00179         CL_Display::pop_clip_rect();
00180         CL_Display::pop_translate_offset();
00181 }

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