input_device.h

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2011 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib may link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
00027 **    Harry Storbacka
00028 */
00029 
00032 
00033 #pragma once
00034 
00035 #include "../api_display.h"
00036 #include "../../Core/System/sharedptr.h"
00037 #include "../../Core/System/weakptr.h"
00038 #include "../../Core/Text/string_types.h"
00039 #include "../../Core/Signals/signal_v2.h"
00040 #include "../../Core/Math/point.h"
00041 
00042 class CL_InputEvent;
00043 class CL_InputState;
00044 class CL_InputDeviceProvider;
00045 class CL_InputDevice_Impl;
00046 
00050 class CL_API_DISPLAY CL_InputDevice
00051 {
00052 public:
00054         enum Type
00055         {
00056                 keyboard,
00057                 pointer,
00058                 joystick,
00059                 tablet,
00060                 unknown
00061         };
00062 
00065 
00066 public:
00068         CL_InputDevice();
00069 
00073         CL_InputDevice(CL_InputDeviceProvider *provider);
00074 
00078         CL_InputDevice(CL_WeakPtr<CL_InputDevice_Impl> impl);
00079 
00080         ~CL_InputDevice();
00081 
00085 
00086 public:
00088         bool is_null() const { return !impl; }
00089 
00091         void throw_if_null() const;
00092 
00094         CL_InputDeviceProvider *get_provider() const;
00095 
00097         CL_String get_name() const;
00098 
00100         CL_String get_device_name() const;
00101 
00103         Type get_type() const;
00104 
00106 
00108         CL_String get_key_name(int id) const;
00109 
00111         CL_String keyid_to_string(int keycode) const;
00112 
00114         int string_to_keyid(const CL_String &str) const;
00115 
00117 
00118         bool get_keycode(int keycode) const;
00119 
00121 
00122         CL_Point get_position() const;
00123 
00125 
00126         int get_x() const;
00127 
00129 
00130         int get_y() const;
00131 
00133         double get_axis(int index) const;
00134 
00136         int get_axis_count() const;
00137 
00139 
00140         int get_button_count() const;
00141 
00143 
00144         bool in_proximity() const;
00145 
00149 
00150 public:
00151         CL_InputDevice &operator =(const CL_InputDevice &copy);
00152 
00154 
00155         void set_position(int x, int y);
00156 
00162         bool poll(bool peek_only);
00163 
00167 
00168 public:
00170         CL_Signal_v2<const CL_InputEvent &, const CL_InputState &> &sig_key_down();
00171 
00173         CL_Signal_v2<const CL_InputEvent &, const CL_InputState &> &sig_key_up();
00174 
00176         CL_Signal_v2<const CL_InputEvent &, const CL_InputState &> &sig_pointer_move();
00177 
00179         CL_Signal_v2<const CL_InputEvent &, const CL_InputState &> &sig_axis_move();
00180 
00182         CL_Signal_v2<const CL_InputEvent &, const CL_InputState &> &sig_key_dblclk();
00183 
00185         CL_Signal_v2<const CL_InputEvent &, const CL_InputState &> &sig_proximity_change();
00186 
00190 
00191 private:
00192         CL_SharedPtr<CL_InputDevice_Impl> impl;
00193 
00194         friend class CL_InputContext_Impl;
00196 };
00197