Force power 2 texture, and update the scene system

This commit is contained in:
Edouard Dupin 2012-04-11 18:51:46 +02:00
parent 59b78d1c00
commit 17974d4c98
10 changed files with 215 additions and 111 deletions

View File

@ -33,6 +33,8 @@
*/
ewol::GameElement::GameElement(void)
{
m_group = -1;
m_type = -1;
m_visible = true;
m_position.x = 0.0;
m_position.y = 0.0;
@ -44,56 +46,6 @@ ewol::GameElement::GameElement(void)
}
/**
* @brief Destructor : This does not remove the sprite requested, they will be supressed when the scene is removed ...
* @param ---
* @return ---
*/
ewol::GameElement::~GameElement(void)
{
}
/**
* @brief Periodicly this fuction will be call tu change property of all the dynamic obbjects
* @param[in] time Current game time (start at 0)
* @param[in] deltaTime delta time before the previous call
* @param[in,out] listOfSprite Reference on the list where the display must be done for every sprite
* @param[in,out] listOfEffects Reference on the list where the display must be done for every effects
* @return true if the object must be remove
* @return false if the object must be keep
*/
bool ewol::GameElement::Process(int64_t time, int32_t deltaTime, etk::VectorType<ewol::GameElement*> & listOfElement)
{
// nothing to do here ...
return false;
}
/**
* @brief Requuest the draw of the current element, it will be done on the current Sprite list
* @param[in,out] listOfSprite Reference on the list where the display must be done for every sprite
* @param[in,out] listOfEffects Reference on the list where the display must be done for every effects
* @return ---
*/
void ewol::GameElement::Draw(etk::VectorType<ewol::Sprite*> & listOfSprite, etk::VectorType<ewol::Sprite*> & listOfEffects)
{
// nothing to do here ...
}
/**
* @brief an element has been remove, just remove reference on it or ID on IT, it can be replace whith an other that have no link
* @param[in] idOfElement Id of the element that has been removed
* @return ---
*/
void ewol::GameElement::RemoveElement(int32_t idOfElement)
{
// nothing to do here ...
}
/**
* @brief Requuest the draw of the current element, it will be done on the current Sprite list
* @param[in,out] listOfElement Reference on the list of sprite that we need to find if it exist or added a new one
@ -124,3 +76,11 @@ int32_t ewol::GameElement::LoadSprite(etk::VectorType<ewol::Sprite*> listOfEleme
return listOfElement[0].Size() -1;
}
etkFloat_t quadDist(coord2D_ts pos1, coord2D_ts pos2)
{
etkFloat_t tmpVal1 = pos1.x - pos2.x;
etkFloat_t tmpVal2 = pos1.y - pos2.y;
return tmpVal1*tmpVal1 + tmpVal2*tmpVal2;
}

View File

@ -30,11 +30,15 @@
#include <ewol/OObject/Sprite.h>
#include <ewol/Widget.h>
namespace ewol {
// declare the scene element before ...
class SceneElement;
class GameElement
{
protected:
int32_t m_group;
int32_t m_type;
bool m_visible;
coord2D_ts m_position;
coord2D_ts m_speed;
@ -42,30 +46,78 @@ namespace ewol {
etkFloat_t m_angle;
etkFloat_t m_gravity;
public:
GameElement(void);
virtual ~GameElement(void);
bool IsVisible(void) { return m_visible; };
void SetVisible(bool state) { m_visible = state; };
coord2D_ts PositionGet(void) { return m_position; };
void PositionSet(coord2D_ts state) { m_position = state; };
void PositionSet(etkFloat_t xxx, etkFloat_t yyy) { m_position.x = xxx; m_position.y = yyy; };
coord2D_ts SpeedGet(void) { return m_speed; };
void SpeedSet(coord2D_ts state) { m_speed = state; };
void SpeedSet(etkFloat_t xxx, etkFloat_t yyy) { m_speed.x = xxx; m_speed.y = yyy; };
etkFloat_t SizeGet(void) { return m_size; };
void SizeSet(etkFloat_t state) { m_size = state; };
etkFloat_t AngleGet(void) { return m_angle; };
void AngleSet(etkFloat_t state) { m_angle = state; };
etkFloat_t GravityGet(void) { return m_gravity; };
void GravitySet(etkFloat_t state) { m_gravity = state; };
virtual bool Process(int64_t time, int32_t deltaTime, etk::VectorType<ewol::GameElement*> & listOfElement);
virtual void Draw(etk::VectorType<ewol::Sprite*> & listOfSprite, etk::VectorType<ewol::Sprite*> & listOfEffects);
virtual void RemoveElement(int32_t idOfElement);
virtual bool HaveImpact(int32_t type, coord2D_ts position, etkFloat_t size) {return false;};
virtual void Explosion(int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power) { } ;
int32_t LoadSprite(etk::VectorType<ewol::Sprite*> listOfElement[NB_BOUBLE_BUFFER], etk::UString fileName, coord2D_ts maxSize);
/**
* @brief Constructor : here are requested all the needed sprite and effect that can be used in the game
* @param ---
* @return ---
*/
GameElement(void);
/**
* @brief Destructor : This does not remove the sprite requested, they will be supressed when the scene is removed ...
* @param ---
* @return ---
*/
virtual ~GameElement(void) { };
bool IsVisible(void) { return m_visible; };
void SetVisible(bool state) { m_visible = state; };
coord2D_ts PositionGet(void) { return m_position; };
void PositionSet(coord2D_ts state) { m_position = state; };
void PositionSet(etkFloat_t xxx, etkFloat_t yyy) { m_position.x = xxx; m_position.y = yyy; };
coord2D_ts SpeedGet(void) { return m_speed; };
void SpeedSet(coord2D_ts state) { m_speed = state; };
void SpeedSet(etkFloat_t xxx, etkFloat_t yyy) { m_speed.x = xxx; m_speed.y = yyy; };
etkFloat_t SizeGet(void) { return m_size; };
void SizeSet(etkFloat_t state) { m_size = state; };
etkFloat_t AngleGet(void) { return m_angle; };
void AngleSet(etkFloat_t state) { m_angle = state; };
etkFloat_t GravityGet(void) { return m_gravity; };
void GravitySet(etkFloat_t state) { m_gravity = state; };
int32_t GetType(void) { return m_type; };
int32_t GroupGet(void) { return m_group; };
void GroupSet(int32_t state) { m_group = state; };
/**
* @brief Periodicly this fuction will be call tu change property of all the dynamic obbjects
* @param[in] time Current game time (start at 0)
* @param[in] deltaTime delta time before the previous call
* @param[in,out] listOfSprite Reference on the list where the display must be done for every sprite
* @param[in,out] listOfEffects Reference on the list where the display must be done for every effects
* @return true if the object must be remove
* @return false if the object must be keep
*/
virtual bool Process(int64_t time, int32_t deltaTime, ewol::SceneElement & sceneElement) { return false; };
/**
* @brief Requuest the draw of the current element, it will be done on the current Sprite list
* @param[in,out] listOfSprite Reference on the list where the display must be done for every sprite
* @param[in,out] listOfEffects Reference on the list where the display must be done for every effects
* @return ---
*/
virtual void Draw(etk::VectorType<ewol::Sprite*> & listOfSprite, etk::VectorType<ewol::Sprite*> & listOfEffects) { };
/**
* @brief an element has been remove, just remove reference on it or ID on IT, it can be replace whith an other that have no link
* @param[in] idOfElement Id of the element that has been removed
* @return ---
*/
virtual void RemoveElement(int32_t idOfElement) { };
virtual bool HaveImpact(int32_t group, int32_t type, coord2D_ts position, etkFloat_t size) {return false;};
virtual void Explosion(int32_t group, int32_t type, coord2D_ts position, etkFloat_t pxAtenuation, etkFloat_t power) { } ;
/**
* @brief Requuest the draw of the current element, it will be done on the current Sprite list
* @param[in,out] listOfElement Reference on the list of sprite that we need to find if it exist or added a new one
* @param[in] fileName Sprite name
* @param[in] maxSize maximum size of the sprite
* @return the id of the sprite requested or -1 if it does not existed
*/
int32_t LoadSprite(etk::VectorType<ewol::Sprite*> listOfElement[NB_BOUBLE_BUFFER], etk::UString fileName, coord2D_ts maxSize);
};
};
#include <ewol/widget/Scene.h>
etkFloat_t quadDist(coord2D_ts pos1, coord2D_ts pos2);
#endif

View File

@ -293,6 +293,9 @@ int32_t ewol::texture::Load(etk::UString tmpfileName, int32_t requestedWidth)
if (false == fileName.Exist()) {
EWOL_ERROR("File does not Exist ... " << fileName);
} else {
// get the upper paw2 ot the size requested...
requestedWidth = nextP2(requestedWidth);
etk::UString fileExtention = fileName.GetExtention();
if (fileExtention == "bmp") {
// create the bitmap texture
@ -313,8 +316,6 @@ int32_t ewol::texture::Load(etk::UString tmpfileName, int32_t requestedWidth)
// removet the bitmap handle
delete (myBitmap);
} else if (fileExtention == "svg") {
// get the upper paw2 ot the size requested...
//requestedWidth = nextP2(requestedWidth);
/*if (requestedWidth < 32) {
requestedWidth = 32;
}*/

View File

@ -252,6 +252,7 @@ void ewol::Widget::KeepFocus(void)
/**
* @brief extern interface to request a draw ... (called by the drawing thread [Android, X11, ...])
* This function generate a clipping with the viewport openGL system. Like this a widget draw can not draw over an other widget
* @note This function is virtual for the scrolled widget, and the more complicated OpenGl widget
* @param ---
* @return ---
*/

View File

@ -407,10 +407,11 @@ namespace ewol {
/**
* @brief extern interface to request a draw ... (called by the drawing thread [Android, X11, ...])
* This function generate a clipping with the viewport openGL system. Like this a widget draw can not draw over an other widget
* @note This function is virtual for the scrolled widget, and the more complicated OpenGl widget
* @param ---
* @return ---
*/
void GenDraw(void);
virtual void GenDraw(void);
protected:
/**
* @brief Common widget drawing function (called by the drawing thread [Android, X11, ...])

View File

@ -120,9 +120,10 @@ static void* BaseAppEntry(void* param)
EWOL_DEBUG("==> Init BThread (END)");
while(false == requestEndProcessing) {
ewol::threadMsg::threadMsgContent_ts data;
data.type = THREAD_JUST_DISPLAY;
ewol::threadMsg::WaitMessage(androidJniMsg, data);
countNbEvent++;
if (data.type != THREAD_JUST_DISPLAY) {
countNbEvent++;
//EWOL_DEBUG("EVENT");
switch (data.type) {
case THREAD_INIT:

View File

@ -97,21 +97,21 @@ void ewol::Scene::OnRegenerateDisplay(void)
{
if (true == NeedRedraw()) {
// clean elements
for (int32_t iii=0; iii<m_animated[m_currentCreateId].Size(); iii++) {
if (NULL != m_animated[m_currentCreateId][iii]) {
m_animated[m_currentCreateId][iii]->Clear();
for (int32_t iii=0; iii<m_sceneElement.animated[m_currentCreateId].Size(); iii++) {
if (NULL != m_sceneElement.animated[m_currentCreateId][iii]) {
m_sceneElement.animated[m_currentCreateId][iii]->Clear();
}
}
// clean effects
for (int32_t iii=0; iii<m_effects[m_currentCreateId].Size(); iii++) {
if (NULL != m_effects[m_currentCreateId][iii]) {
m_effects[m_currentCreateId][iii]->Clear();
for (int32_t iii=0; iii<m_sceneElement.effects[m_currentCreateId].Size(); iii++) {
if (NULL != m_sceneElement.effects[m_currentCreateId][iii]) {
m_sceneElement.effects[m_currentCreateId][iii]->Clear();
}
}
for (int32_t iii=0; iii<m_listAnimatedElements.Size(); iii++) {
if (NULL != m_listAnimatedElements[iii]) {
for (int32_t iii=0; iii<m_sceneElement.listAnimatedElements.Size(); iii++) {
if (NULL != m_sceneElement.listAnimatedElements[iii]) {
// find an empty slot ...
m_listAnimatedElements[iii]->Draw(m_animated[m_currentCreateId], m_effects[m_currentCreateId]);
m_sceneElement.listAnimatedElements[iii]->Draw(m_sceneElement.animated[m_currentCreateId], m_sceneElement.effects[m_currentCreateId]);
}
}
}
@ -128,35 +128,36 @@ void ewol::Scene::OnDraw(void)
// draw background
// TODO : ...
// draw elements
for (int32_t iii=0; iii<m_animated[m_currentDrawId].Size(); iii++) {
if (NULL != m_animated[m_currentDrawId][iii]) {
m_animated[m_currentDrawId][iii]->Draw();
for (int32_t iii=0; iii<m_sceneElement.animated[m_currentDrawId].Size(); iii++) {
if (NULL != m_sceneElement.animated[m_currentDrawId][iii]) {
m_sceneElement.animated[m_currentDrawId][iii]->Draw();
}
}
// draw effects
for (int32_t iii=0; iii<m_effects[m_currentDrawId].Size(); iii++) {
if (NULL != m_effects[m_currentDrawId][iii]) {
m_effects[m_currentDrawId][iii]->Draw();
for (int32_t iii=0; iii<m_sceneElement.effects[m_currentDrawId].Size(); iii++) {
if (NULL != m_sceneElement.effects[m_currentDrawId][iii]) {
m_sceneElement.effects[m_currentDrawId][iii]->Draw();
}
}
m_needFlipFlop = true;
}
void ewol::Scene::AddElement(ewol::GameElement* newElement)
int32_t ewol::SceneElement::AddElement(ewol::GameElement* newElement)
{
if (NULL == newElement) {
return;
return -1;
}
for (int32_t iii=0; iii<m_listAnimatedElements.Size(); iii++) {
if (NULL == m_listAnimatedElements[iii]) {
for (int32_t iii=0; iii<listAnimatedElements.Size(); iii++) {
if (NULL == listAnimatedElements[iii]) {
// find an empty slot ...
m_listAnimatedElements[iii] = newElement;
return;
listAnimatedElements[iii] = newElement;
return iii;
}
}
//did not find empty slot :
m_listAnimatedElements.PushBack(newElement);
listAnimatedElements.PushBack(newElement);
return listAnimatedElements.Size()-1;
}
@ -169,12 +170,12 @@ void ewol::Scene::PeriodicCall(int64_t localTime)
{
//EWOL_ERROR("Periodic Call ... " << localTime);
for (int32_t iii=0; iii<m_listAnimatedElements.Size(); iii++) {
if (NULL != m_listAnimatedElements[iii]) {
for (int32_t iii=0; iii<m_sceneElement.listAnimatedElements.Size(); iii++) {
if (NULL != m_sceneElement.listAnimatedElements[iii]) {
// check if the element request an auto Kill ...
if (true == m_listAnimatedElements[iii]->Process(localTime, 20000, m_listAnimatedElements) ) {
delete(m_listAnimatedElements[iii]);
m_listAnimatedElements[iii] = NULL;
if (true == m_sceneElement.listAnimatedElements[iii]->Process(localTime, 20000, m_sceneElement) ) {
delete(m_sceneElement.listAnimatedElements[iii]);
m_sceneElement.listAnimatedElements[iii] = NULL;
}
}
}

View File

@ -33,14 +33,21 @@
namespace ewol {
class SceneElement {
public:
etk::VectorType<ewol::OObject*> backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first
etk::VectorType<ewol::Sprite*> animated[NB_BOUBLE_BUFFER]; //!< element that must be display the first
etk::VectorType<ewol::Sprite*> effects[NB_BOUBLE_BUFFER]; //!< element that must be display the first
etk::VectorType<ewol::GameElement*> listAnimatedElements; //!< generic element to display...
int32_t AddElement(ewol::GameElement* newElement);
};
class Scene :public ewol::WidgetScrooled
{
// TODO : Set it in private ...
protected:
etk::VectorType<ewol::OObject*> m_backgroundElements[NB_BOUBLE_BUFFER]; //!< element that must be display the first
etk::VectorType<ewol::Sprite*> m_animated[NB_BOUBLE_BUFFER]; //!< element that must be display the first
etk::VectorType<ewol::Sprite*> m_effects[NB_BOUBLE_BUFFER]; //!< element that must be display the first
etk::VectorType<ewol::GameElement*> m_listAnimatedElements; //!< generic element to display...
SceneElement m_sceneElement; //!< all element neede in the scene
public:
Scene(void);
virtual ~Scene(void);
@ -73,7 +80,6 @@ namespace ewol {
* @return ---
*/
virtual void OnDraw(void);
void AddElement(ewol::GameElement* newElement);
};
/**

View File

@ -26,6 +26,8 @@
#include <ewol/OObject.h>
#include <ewol/WidgetManager.h>
#include <ewol/importgl.h>
#include <ewol/ewol.h>
@ -35,6 +37,8 @@ ewol::WidgetScrooled::WidgetScrooled(void)
m_originScrooled.y = 0;
m_pixelScrolling = 20;
m_highSpeedMode = SCROLL_DISABLE;
m_scroollingMode = SCROLL_MODE_NORMAL;
m_zoom = 1.0;
}
ewol::WidgetScrooled::~WidgetScrooled(void)
@ -115,6 +119,7 @@ void ewol::WidgetScrooled::OnRegenerateDisplay(void)
bool ewol::WidgetScrooled::OnEventInput(int32_t IdInput, ewol::eventInputType_te typeEvent, coord2D_ts pos)
{
coord2D_ts relativePos = RelativePosition(pos);
if (SCROLL_MODE_NORMAL == m_scroollingMode) {
#ifdef __MODE__Touch
if (1 == IdInput) {
EWOL_VERBOSE("event 1 << " << (int32_t)typeEvent << "(" << x << "," << y << ")");
@ -162,7 +167,6 @@ bool ewol::WidgetScrooled::OnEventInput(int32_t IdInput, ewol::eventInputType_te
}
#else
if (4 == IdInput && ewol::EVENT_INPUT_TYPE_UP == typeEvent) {
//EWOL_INFO("mouse-event GDK_SCROLL_UP");
m_originScrooled.y -= m_pixelScrolling;
if (m_originScrooled.y < 0) {
m_originScrooled.y = 0;
@ -170,7 +174,6 @@ bool ewol::WidgetScrooled::OnEventInput(int32_t IdInput, ewol::eventInputType_te
MarkToReedraw();
return true;
} else if (5 == IdInput && ewol::EVENT_INPUT_TYPE_UP == typeEvent) {
//EWOL_INFO("mouse-event GDK_SCROLL_DOWN");
m_originScrooled.y += m_pixelScrolling;
if (m_maxSize.y < m_originScrooled.y) {
m_originScrooled.y = m_maxSize.y;
@ -228,6 +231,69 @@ bool ewol::WidgetScrooled::OnEventInput(int32_t IdInput, ewol::eventInputType_te
return true;
}
#endif
} else if (SCROLL_MODE_CENTER == m_scroollingMode) {
#ifdef __MODE__Touch
// TODO ...
#else
etkFloat_t tmp1=ewol::GetCurrentHeight() / m_maxSize.y;
etkFloat_t tmp2=ewol::GetCurrentWidth() / m_maxSize.x;
//EWOL_INFO(" elements Zoom : " << tmp1 << " " << tmp2);
tmp1 = etk_min(tmp1, tmp2);
if (4 == IdInput && ewol::EVENT_INPUT_TYPE_UP == typeEvent) {
m_zoom -= 0.1;
if (tmp1 < 1.0) {
m_zoom = etk_max(tmp1, m_zoom);
} else {
m_zoom = etk_max(1.0, m_zoom);
}
MarkToReedraw();
return true;
} else if (5 == IdInput && ewol::EVENT_INPUT_TYPE_UP == typeEvent) {
m_zoom += 0.1;
if (tmp1 > 1.0) {
m_zoom = etk_min(tmp1, m_zoom);
} else {
m_zoom = etk_min(1.0, m_zoom);
}
MarkToReedraw();
return true;
}
#endif
} else {
EWOL_ERROR("Scrolling mode unknow ... " << m_scroollingMode );
}
return false;
}
/**
* @brief extern interface to request a draw ... (called by the drawing thread [Android, X11, ...])
* This function generate a clipping with the viewport openGL system. Like this a widget draw can not draw over an other widget
* @note This function is virtual for the scrolled widget, and the more complicated OpenGl widget
* @param ---
* @return ---
*/
void ewol::WidgetScrooled::GenDraw(void)
{
if (SCROLL_MODE_CENTER == m_scroollingMode) {
glPushMatrix();
// here we invert the reference of the standard OpenGl view because the reference in the common display is Top left and not buttom left
glViewport( m_origin.x,
ewol::GetCurrentHeight() - m_size.y - m_origin.y,
m_size.x,
m_size.y);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthoEwol(-m_size.x/2, m_size.x/2, m_size.y/2, -m_size.y/2, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(m_zoom, m_zoom, 1.0);
glTranslatef(-m_maxSize.x/2, -m_maxSize.y/2, -1.0);
// Call the widget drawing methode
OnDraw();
glPopMatrix();
} else {
ewol::Widget::GenDraw();
}
}

View File

@ -41,12 +41,18 @@ namespace ewol {
#endif
}highSpeedMode_te;
typedef enum {
SCROLL_MODE_NORMAL, //!< No Zoom , can UP and down, left and right
SCROLL_MODE_CENTER, //!< Zoom enable, no move left and right
} scrollingMode_te;
class WidgetScrooled : public ewol::Widget
{
protected:
coord2D_ts m_originScrooled;
coord2D_ts m_maxSize;
etkFloat_t m_zoom; //!< current zoom on the display
private:
scrollingMode_te m_scroollingMode; //!< mode of management of the scrooling
etkFloat_t m_pixelScrolling;
coord2D_ts m_highSpeedStartPos;
highSpeedMode_te m_highSpeedMode;
@ -78,8 +84,17 @@ namespace ewol {
* @return false the event is not used
*/
virtual bool OnEventInput(int32_t IdInput, ewol::eventInputType_te typeEvent, coord2D_ts pos);
/**
* @brief extern interface to request a draw ... (called by the drawing thread [Android, X11, ...])
* This function generate a clipping with the viewport openGL system. Like this a widget draw can not draw over an other widget
* @note This function is virtual for the scrolled widget, and the more complicated OpenGl widget
* @param ---
* @return ---
*/
virtual void GenDraw(void);
protected:
void SetScrollingSize(etkFloat_t nbPixel) { m_pixelScrolling = nbPixel; };
void ScroolingMode(scrollingMode_te newMode) { m_scroollingMode = newMode; };
};
extern const char * const TYPE_EOBJECT_WIDGET_SCROOLED;