91 lines
2.6 KiB
C++
91 lines
2.6 KiB
C++
/**
|
|
* @author Edouard DUPIN
|
|
*
|
|
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
*
|
|
* @license APACHE v2.0 (see license file)
|
|
*/
|
|
#pragma once
|
|
|
|
#include <etk/types.h>
|
|
#include <etk/Color.h>
|
|
#include <ewol/debug.h>
|
|
#include <ewol/widget/Widget.h>
|
|
#include <esignal/Signal.h>
|
|
|
|
// TODO : Rework ==> use property and shaper ...
|
|
|
|
namespace ewol {
|
|
namespace widget {
|
|
/**
|
|
* @ingroup ewolWidgetGroup
|
|
*/
|
|
class Joystick :public ewol::Widget {
|
|
public:
|
|
// Event list of properties
|
|
esignal::Signal<void> signalEnable;
|
|
esignal::Signal<void> signalDisable;
|
|
esignal::Signal<vec2> signalMove;
|
|
public:
|
|
enum joystickMode {
|
|
modeNormal,
|
|
modeArrow,
|
|
};
|
|
private:
|
|
etk::Color<> m_colorFg; //!< Forground color
|
|
etk::Color<> m_colorBg; //!< Background color
|
|
vec2 m_displayPos; //!< direction of the cursor ...
|
|
float m_distance; //!< dintance from the center
|
|
float m_angle; //!< angle of the arraw (if < 0 : No arraw...) 0 is the TOP ...
|
|
bool m_lock; //!< flag to mark the lock when the cursor is free when we are outside the circle
|
|
enum joystickMode m_displayMode; //!< Type of fonctionnal mode of the joystick
|
|
private:
|
|
// generic property of the joystick:
|
|
bool m_displayBackground;
|
|
std::string m_background;
|
|
std::string m_foreground;
|
|
float m_ratio;
|
|
protected:
|
|
Joystick();
|
|
void init();
|
|
public:
|
|
DECLARE_WIDGET_FACTORY(Joystick, "Joystick");
|
|
virtual ~Joystick();
|
|
public:
|
|
void setLockMode(bool _lockWhenOut) {
|
|
m_lock = _lockWhenOut;
|
|
};
|
|
void setDisplayMode(enum joystickMode _newMode) {
|
|
m_displayMode = _newMode;
|
|
};
|
|
/**
|
|
* @brief set the ratio of the widget joystick
|
|
* @param[in] _newRatio the new ratio that might be set
|
|
*/
|
|
void ratio(float _newRatio);
|
|
/**
|
|
* @brief set the Background of the widget joystick
|
|
* @param[in] _imageNameInData the new rbackground that might be set
|
|
* @param[in] _display
|
|
*/
|
|
void background(std::string _imageNameInData, bool _display=true);
|
|
/**
|
|
* @brief set the Foreground of the widget joystick
|
|
* @param[in] _imageNameInData the new Foreground that might be set
|
|
*/
|
|
void foreground(std::string _imageNameInData);
|
|
/**
|
|
* @brief get the property of the joystick
|
|
* @param[out] _distance distance to the center
|
|
* @param[out] _angle angle of the joy
|
|
*/
|
|
void getProperty(float& _distance, float& _angle);
|
|
|
|
public: // Derived function
|
|
virtual void onRegenerateDisplay();
|
|
virtual bool onEventInput(const ewol::event::Input& _event);
|
|
};
|
|
};
|
|
};
|
|
|