basic property of the joystick

This commit is contained in:
Edouard Dupin 2012-04-01 13:39:07 +02:00
parent 6cd8f3fa2a
commit 2315b6f11f
9 changed files with 170 additions and 32 deletions

View File

@ -31,21 +31,23 @@
ewol::OObject2DTextured::OObject2DTextured(etk::File textureName)
ewol::OObject2DTextured::OObject2DTextured(etk::UString textureName)
{
EWOL_DEBUG("Create OObject textured : \"" << textureName << "\"");
EWOL_VERBOSE("Create OObject textured : \"" << textureName << "\"");
m_textureId = ewol::texture::Load(textureName);
}
ewol::OObject2DTextured::OObject2DTextured(etk::File textureName, etkFloat_t sizeX, etkFloat_t sizeY)
ewol::OObject2DTextured::OObject2DTextured(etk::UString textureName, etkFloat_t sizeX, etkFloat_t sizeY)
{
EWOL_DEBUG("Create OObject textured : \"" << textureName << "\"");
EWOL_VERBOSE("Create OObject textured : \"" << textureName << "\"");
m_textureId = ewol::texture::Load(textureName, sizeX);
}
ewol::OObject2DTextured::~OObject2DTextured(void)
{
ewol::texture::UnLoad(m_textureId);
if (-1 != m_textureId) {
ewol::texture::UnLoad(m_textureId);
}
}
void ewol::OObject2DTextured::Draw(void)

View File

@ -31,8 +31,8 @@ namespace ewol {
class OObject2DTextured :public ewol::OObject
{
public:
OObject2DTextured(etk::File textureName);
OObject2DTextured(etk::File textureName, etkFloat_t sizeX, etkFloat_t sizeY);
OObject2DTextured(etk::UString textureName);
OObject2DTextured(etk::UString textureName, etkFloat_t sizeX, etkFloat_t sizeY);
virtual ~OObject2DTextured(void);
public:
virtual void Draw(void);

View File

@ -276,19 +276,20 @@ static int32_t nextP2(int32_t value)
*/
// TODO : Load non square texture ...
// TODO : Check the size to regenerate the texture if the size change
int32_t ewol::texture::Load(etk::File fileName, int32_t requestedWidth)
int32_t ewol::texture::Load(etk::UString tmpfileName, int32_t requestedWidth)
{
int32_t outTextureID = -1;
if (l_listLoadedTexture.Size()!=0) {
for (int32_t iii=0; iii<l_listLoadedTexture.Size(); iii++) {
if (NULL != l_listLoadedTexture[iii]) {
if (l_listLoadedTexture[iii]->m_filename == fileName.GetCompleateName()) {
if (l_listLoadedTexture[iii]->m_filename == tmpfileName) {
l_listLoadedTexture[iii]->m_nbTimeLoaded++;
return iii;
}
}
}
}
etk::File fileName(tmpfileName, etk::FILE_TYPE_DATA);
if (false == fileName.Exist()) {
EWOL_ERROR("File does not Exist ... " << fileName);
} else {
@ -297,7 +298,7 @@ int32_t ewol::texture::Load(etk::File fileName, int32_t requestedWidth)
// create the bitmap texture
ewol::texture::TextureBMP * myBitmap = new ewol::texture::TextureBMP(fileName);
// draw bitmap properties
myBitmap->Display();
//myBitmap->Display();
// check if all is OK
if (myBitmap->LoadOK() == true) {
if (myBitmap->Width() != nextP2(myBitmap->Width()) ) {
@ -307,7 +308,7 @@ int32_t ewol::texture::Load(etk::File fileName, int32_t requestedWidth)
EWOL_ERROR("Texture can not have Width=" << myBitmap->Width() << "px different of height=" << myBitmap->Height() << "px in file:" << fileName);
return -1;
}
outTextureID = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_RGBA, myBitmap->Width(), myBitmap->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, myBitmap->Data(), myBitmap->DataSize(), fileName.GetCompleateName());
outTextureID = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_RGBA, myBitmap->Width(), myBitmap->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, myBitmap->Data(), myBitmap->DataSize(), tmpfileName);
}
// removet the bitmap handle
delete (myBitmap);
@ -320,14 +321,14 @@ int32_t ewol::texture::Load(etk::File fileName, int32_t requestedWidth)
// create the bitmap texture
ewol::texture::TextureSVG * mySvg = new ewol::texture::TextureSVG(fileName, requestedWidth, requestedWidth);
// draw bitmap properties
mySvg->Display();
//mySvg->Display();
// check if all is OK
if (mySvg->LoadOK() == true) {
if (mySvg->Width() != mySvg->Height()) {
EWOL_ERROR("Texture can not have Width=" << mySvg->Width() << "px different of height=" << mySvg->Height() << "px in file:" << fileName);
return -1;
}
outTextureID = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_RGBA, mySvg->Width(), mySvg->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, mySvg->Data(), mySvg->DataSize(), fileName.GetCompleateName());
outTextureID = ewol::texture::Load(GL_TEXTURE_2D, 0, GL_RGBA, mySvg->Width(), mySvg->Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, mySvg->Data(), mySvg->DataSize(), tmpfileName);
}
// removet the bitmap handle
delete (mySvg);
@ -349,7 +350,7 @@ int32_t ewol::texture::Load(etk::File fileName, int32_t requestedWidth)
*/
void ewol::texture::UnLoad(uint32_t textureID)
{
EWOL_INFO("Unload a specific tecture ID=" << textureID);
//EWOL_INFO("Unload a specific tecture ID=" << textureID);
if (textureID>=0 && (int32_t)textureID<l_listLoadedTexture.Size()) {
if (NULL == l_listLoadedTexture[textureID]) {
EWOL_ERROR("Texture : " << textureID << " does not existe anymore...");

View File

@ -34,7 +34,7 @@ namespace ewol
namespace texture {
void Init(void);
void UnInit(void);
int32_t Load(etk::File fileName, int32_t requestedWidth=-1);
int32_t Load(etk::UString fileName, int32_t requestedWidth=-1);
int32_t Load(int32_t target, int32_t level, int32_t internalFormat, int32_t width, int32_t height, int32_t border, int32_t format, int32_t type, const void* data, int32_t nbBytes, etk::UString filename);
void UnLoad(uint32_t textureID);
int32_t GetSize(uint32_t textureID);

View File

@ -89,7 +89,7 @@ void ewol::Button::SetImage(etk::UString imageName)
if (imageName == "") {
m_hasAnImage = false;
} else {
m_imageSelected.SetCompleateName(imageName, etk::FILE_TYPE_DATA);
m_imageSelected = imageName;
m_hasAnImage = true;
}
}

View File

@ -70,7 +70,7 @@ namespace ewol {
void SetPadding(coord2D_ts newPadding);
private:
bool m_hasAnImage;
etk::File m_imageSelected;
etk::UString m_imageSelected;
textAlignement_te m_alignement;
coord2D_ts m_padding;
etk::UString m_label;

View File

@ -32,6 +32,65 @@ extern const char * const ewolEventJoystickEnable = "ewol-joystick-enable";
extern const char * const ewolEventJoystickDisable = "ewol-joystick-disable";
extern const char * const ewolEventJoystickMove = "ewol-joystick-move";
static bool l_displayBackground(true);
static etk::UString l_background("");
static etk::UString l_foreground("");
static etkFloat_t l_ratio(1.0/7.0);
/**
* @brief Initilise the basic widget property ==> due to the android system
* @note all widget that have template might have this initializer ...
* @param ---
* @return ---
*/
void WIDGET_JoystickInit(void)
{
l_displayBackground = true;
l_background = "";
l_foreground = "";
l_ratio = 1.0/7.0;
}
/**
* @brief Set the default ratio of the widget joystick
* @param[in] newRatio the new ratio that might be set
* @return ---
*/
void WIDGET_JoystickDefaultRatio(etkFloat_t newRatio)
{
if (newRatio > 1) {
newRatio = 1;
}
l_ratio = newRatio;
EWOL_INFO("Set default Joystick ratio at " << l_ratio);
}
/**
* @brief Set the default Background of the widget joystick
* @param[in] imageNameInData the new rbackground that might be set
* @return ---
*/
void WIDGET_JoystickDefaultBackground(etk::UString imageNameInData, bool display)
{
// TODO : check if it existed
l_background = imageNameInData;
l_displayBackground = display;
EWOL_INFO("Set default Joystick background at " << l_background << " Display it=" << l_displayBackground);
}
/**
* @brief Set the default Foreground of the widget joystick
* @param[in] imageNameInData the new Foreground that might be set
* @return ---
*/
void WIDGET_JoystickDefaultForeground(etk::UString imageNameInData)
{
// TODO : check if it existed
l_foreground = imageNameInData;
EWOL_INFO("Set default Joystick Foreground at " << l_foreground);
}
#undef __class__
#define __class__ "Joystick"
@ -59,6 +118,11 @@ ewol::Joystick::Joystick(void)
m_distance = 0.0;
m_angle = -0.1;
// set the generic parameters:
m_displayBackground = l_displayBackground;
m_background = l_background;
m_foreground = l_foreground;
m_ratio = l_ratio;
SetCanHaveFocus(true);
}
@ -121,7 +185,7 @@ bool ewol::Joystick::CalculateSize(etkFloat_t availlableX, etkFloat_t availlable
MarkToReedraw();
return true;
}
#define INTERNAL_ELEMENT_RATIO (7)
void ewol::Joystick::OnRegenerateDisplay(void)
{
if (true == NeedRedraw()) {
@ -130,19 +194,22 @@ void ewol::Joystick::OnRegenerateDisplay(void)
ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored;
// set background
tmpOObjects->SetColor(m_colorBg);
if (true) { //(ewol::JOYSTICK_CIRCLE_MODE==m_displayMode) {
tmpOObjects->Disc( m_size.x/2, m_size.y/2, m_size.x/2-1);
} else {
tmpOObjects->Rectangle( 2, 2, m_size.x-4, m_size.y-4);
if (true == m_displayBackground) {
if (m_background == "") {
tmpOObjects->SetColor(m_colorBg);
tmpOObjects->Disc( m_size.x/2, m_size.y/2, m_size.x/2-1);
} else {
}
}
// set cursor point
tmpOObjects->SetColor(m_colorFg);
etkFloat_t sizeElement = m_size.x/INTERNAL_ELEMENT_RATIO;
if (true) { //(ewol::JOYSTICK_CIRCLE_MODE==m_displayMode) {
tmpOObjects->Disc( ((m_displayPos.x+1.0)/2.0)*m_size.x, ((m_displayPos.y+1.0)/2.0)*m_size.y, sizeElement);
etkFloat_t sizeElement = m_size.x*m_ratio;
if (m_foreground == "") {
tmpOObjects->SetColor(m_colorFg);
tmpOObjects->Disc( ((m_displayPos.x+1.0)/2.0)*(m_size.x-2*sizeElement) + sizeElement, ((m_displayPos.y+1.0)/2.0)*(m_size.y-2*sizeElement) + sizeElement, sizeElement);
EWOL_INFO("kjhkjh sdfs " << m_colorFg << " plop" << m_displayPos << " ratio:" << m_ratio);
} else {
tmpOObjects->Rectangle( ((m_displayPos.x+1.0)/2.0)*m_size.x-sizeElement/2.0, ((m_displayPos.y+1.0)/2.0)*m_size.y-sizeElement/2.0, sizeElement, sizeElement);
EWOL_INFO("kjhkjh " << m_foreground);
}
// add all needed objects ...
if (NULL != tmpOObjects) {
@ -172,9 +239,10 @@ bool ewol::Joystick::OnEventInput(int32_t IdInput, eventInputType_te typeEvent,
|| ewol::EVENT_INPUT_TYPE_MOVE == typeEvent) {
// get local relative position
coord2D_ts relativePos = RelativePosition(pos);
etkFloat_t sizeElement = m_size.x*m_ratio;
// Calculate the position of the cursor...
m_displayPos.x = relativePos.x/m_size.x*2.0 - 1.0;
m_displayPos.y = relativePos.y/m_size.y*2.0 - 1.0;
m_displayPos.x = (relativePos.x-sizeElement)/(m_size.x-sizeElement*2)*2.0 - 1.0;
m_displayPos.y = (relativePos.y-sizeElement)/(m_size.y-sizeElement*2)*2.0 - 1.0;
// distance :
m_distance = m_displayPos.y*m_displayPos.y + m_displayPos.x * m_displayPos.x;
@ -220,3 +288,43 @@ bool ewol::Joystick::OnEventInput(int32_t IdInput, eventInputType_te typeEvent,
return false;
}
/**
* @brief Set the ratio of the widget joystick
* @param[in] newRatio the new ratio that might be set
* @return ---
*/
void ewol::Joystick::Ratio(etkFloat_t newRatio)
{
if (newRatio > 1) {
newRatio = 1;
}
m_ratio = newRatio;
EWOL_INFO("Set default Joystick ratio at " << m_ratio);
}
/**
* @brief Set the Background of the widget joystick
* @param[in] imageNameInData the new rbackground that might be set
* @return ---
*/
void ewol::Joystick::Background(etk::UString imageNameInData, bool display)
{
// TODO : check if it existed
m_background = imageNameInData;
m_displayBackground = display;
EWOL_INFO("Set default Joystick background at " << m_background << " Display it=" << m_displayBackground);
}
/**
* @brief Set the Foreground of the widget joystick
* @param[in] imageNameInData the new Foreground that might be set
* @return ---
*/
void ewol::Joystick::Foreground(etk::UString imageNameInData)
{
// TODO : check if it existed
m_foreground = imageNameInData;
EWOL_INFO("Set default Joystick Foreground at " << m_foreground);
}

View File

@ -48,6 +48,12 @@ namespace ewol {
etkFloat_t 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
joystickMode_te m_displayMode; //!< Type of fonctionnal mode of the joystick
private:
// generic property of the joystick:
bool m_displayBackground;
etk::UString m_background;
etk::UString m_foreground;
etkFloat_t m_ratio;
public:
Joystick(void);
virtual ~Joystick(void);
@ -74,7 +80,7 @@ namespace ewol {
* @return ---
*/
virtual bool CalculateSize(etkFloat_t availlableX, etkFloat_t availlableY);
virtual void OnRegenerateDisplay(void);
virtual void OnRegenerateDisplay(void);
/**
* @brief Event on an input of this Widget
* @param[in] IdInput Id of the current Input (PC : left=1, right=2, middle=3, none=0 / Tactil : first finger=1 , second=2 (only on this widget, no knowledge at ouside finger))
@ -86,6 +92,26 @@ namespace ewol {
virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, coord2D_ts pos);
void SetLockMode(bool lockWhenOut) { m_lock = lockWhenOut; };
void SetDisplayMode(joystickMode_te newMode) { m_displayMode = newMode; };
/**
* @brief Set the ratio of the widget joystick
* @param[in] newRatio the new ratio that might be set
* @return ---
*/
void Ratio(etkFloat_t newRatio);
/**
* @brief Set the Background of the widget joystick
* @param[in] imageNameInData the new rbackground that might be set
* @return ---
*/
void Background(etk::UString imageNameInData, bool display=true);
/**
* @brief Set the Foreground of the widget joystick
* @param[in] imageNameInData the new Foreground that might be set
* @return ---
*/
void Foreground(etk::UString imageNameInData);
};
extern const char * const TYPE_EOBJECT_WIDGET_JOYSTICK;

View File

@ -292,9 +292,10 @@ void svg::Parser::GenerateAnImage(int32_t sizeX, int32_t sizeY)
//basicTrans *= agg::trans_affine_translation(width/3, height/3);
AggDraw(*m_renderedElement, basicTrans);
/*
etk::UString tmpFileOut = "zzz_out_test.ppm";
m_renderedElement->WritePpm(tmpFileOut);
*/
}
uint8_t* svg::Parser::GetPointerOnData(void)