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

component_move_handler.cpp

Go to the documentation of this file.
00001 
00002 #include "precomp.h"
00003 #include "API/GUI/component_move_handler.h"
00004 #include "API/GUI/component.h"
00005 #include "API/GUI/component_options.h"
00006 #include "API/Display/Input/input.h"
00007 
00008 class CL_ComponentMoveHandler_Generic
00009 {
00010 public:
00011         CL_ComponentMoveHandler_Generic()
00012         : owner(NULL), move_comp(NULL)
00013         {
00014         }
00015 
00016         void on_key_down(CL_Component *comp, CL_InputDevice *device, CL_Key key);
00017         void on_key_up(CL_Component *comp, CL_InputDevice *device, CL_Key key);
00018         void on_mouse_moved(CL_Component *comp, CL_InputDevice *device, int x, int y);
00019 
00020         CL_Slot slot_key_down;
00021         CL_Slot slot_key_up;
00022         CL_Slot slot_mouse_moved;
00023 
00024         CL_Rect move_area;
00025         CL_Component *owner;
00026         CL_Component *move_comp;
00027         int down_x, down_y;
00028 };
00029 
00030 CL_ComponentMoveHandler::CL_ComponentMoveHandler(
00031         const CL_Rect &move_area,
00032         CL_Component *owner,
00033         CL_StyleManager *style)
00034 :
00035         impl(new CL_ComponentMoveHandler_Generic)
00036 {
00037         impl->move_area = move_area;
00038         impl->owner = owner;
00039 
00040         CL_Rect rect(0, 0, 0, 0);
00041         impl->move_comp = new CL_Component(rect, impl->owner, style);
00042         impl->move_comp->show(false);
00043 
00044         impl->slot_key_down = owner->sig_key_down().connect(
00045                 CL_CreateSlot(
00046                         impl,
00047                         &CL_ComponentMoveHandler_Generic::on_key_down));
00048 
00049         impl->slot_key_up = impl->move_comp->sig_key_up().connect(
00050                 CL_CreateSlot(
00051                         impl,
00052                         &CL_ComponentMoveHandler_Generic::on_key_up));
00053 
00054         impl->slot_mouse_moved = impl->move_comp->sig_mouse_moved().connect(
00055                 CL_CreateSlot(
00056                         impl,
00057                         &CL_ComponentMoveHandler_Generic::on_mouse_moved));
00058 }
00059 
00060 CL_ComponentMoveHandler::~CL_ComponentMoveHandler()
00061 {
00062         if (impl->move_comp != NULL)
00063         {
00064                 impl->owner->remove_child(impl->move_comp);
00065                 delete impl->move_comp;
00066         }
00067         delete impl;
00068 }
00069 
00070 void CL_ComponentMoveHandler::set_move_area(const CL_Rect &move_area)
00071 {
00072         impl->move_area = move_area;
00073 }
00074 
00075 void CL_ComponentMoveHandler_Generic::on_key_down(
00076         CL_Component *comp,
00077         CL_InputDevice *device,
00078         CL_Key key)
00079 {
00080         if (device != CL_Input::pointers[0]) return;
00081         if (key.x < move_area.x1 || key.x >= move_area.x2) return;
00082         if (key.y < move_area.y1 || key.y >= move_area.y2) return;
00083 
00084         move_comp->set_position(key.x, key.y);
00085         move_comp->capture_mouse();
00086 }
00087 
00088 void CL_ComponentMoveHandler_Generic::on_key_up(
00089         CL_Component *comp,
00090         CL_InputDevice *device,
00091         CL_Key key)
00092 {
00093         if (device != CL_Input::pointers[0]) return;
00094 
00095         move_comp->release_mouse();
00096 }
00097 
00098 void CL_ComponentMoveHandler_Generic::on_mouse_moved(
00099         CL_Component *comp,
00100         CL_InputDevice *device,
00101         int x,
00102         int y)
00103 {
00104         if (device != CL_Input::pointers[0]) return;
00105 
00106         const CL_Rect &pos = owner->get_position();
00107         owner->set_position(pos.x1 + x, pos.y1 + y);
00108 }

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