add basic think of resources
This commit is contained in:
parent
a89f8c09f5
commit
b780f22d2c
@ -26,6 +26,7 @@
|
|||||||
#define __EWOL_O_OBJECT_2D_TEXTURED_H__
|
#define __EWOL_O_OBJECT_2D_TEXTURED_H__
|
||||||
|
|
||||||
#include <ewol/oObject/OObject.h>
|
#include <ewol/oObject/OObject.h>
|
||||||
|
#include <ewol/Texture/Texture.h>
|
||||||
|
|
||||||
namespace ewol {
|
namespace ewol {
|
||||||
class OObject2DTextured :public ewol::OObject
|
class OObject2DTextured :public ewol::OObject
|
||||||
@ -40,10 +41,10 @@ namespace ewol {
|
|||||||
void Rectangle(float x, float y, float w, float h, float texX=0.0, float texY=0.0, float texSX=1.0, float texSY=1.0, draw::Color tmpColor=draw::color::white);
|
void Rectangle(float x, float y, float w, float h, float texX=0.0, float texY=0.0, float texSX=1.0, float texSY=1.0, draw::Color tmpColor=draw::color::white);
|
||||||
void Rectangle(float x, float y, float w, float h, draw::Color tmpColor);
|
void Rectangle(float x, float y, float w, float h, draw::Color tmpColor);
|
||||||
protected:
|
protected:
|
||||||
int32_t m_textureId; //!< texture internal ID
|
ewol::Texture
|
||||||
etk::Vector<Vector2D<float> > m_coord; //!< internal coord of the object
|
etk::Vector<Vector2D<float> > m_coord; //!< internal coord of the object
|
||||||
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
|
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
|
||||||
etk::Vector<draw::Color> m_coordColor; //!< internal color of the different point
|
etk::Vector<draw::Color> m_coordColor; //!< internal color of the different point
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
39
Sources/libewol/ewol/resources/ResourcesImage.cpp
Normal file
39
Sources/libewol/ewol/resources/ResourcesImage.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
*******************************************************************************
|
||||||
|
* @file ewol/resources/ResourcesImage.cpp
|
||||||
|
* @brief ewol Resources image system (sources)
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @date 21/08/2012
|
||||||
|
* @par Project
|
||||||
|
* ewol
|
||||||
|
*
|
||||||
|
* @par Copyright
|
||||||
|
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY.
|
||||||
|
*
|
||||||
|
* Licence summary :
|
||||||
|
* You can modify and redistribute the sources code and binaries.
|
||||||
|
* You can send me the bug-fix
|
||||||
|
*
|
||||||
|
* Term of the licence in in the file licence.txt.
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ewol/resources/ResourcesManager.h>
|
||||||
|
|
||||||
|
ewol::ResourcesImage::ResourcesImage(etk::UString fileName, Vector2D<int32_t> size) :
|
||||||
|
m_resourceID(0),
|
||||||
|
m_counter(1),
|
||||||
|
m_image(size)
|
||||||
|
{
|
||||||
|
m_resourceID = ewol::resourcesManager::Add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ewol::ResourcesImage::~ResourcesImage(void)
|
||||||
|
{
|
||||||
|
ewol::resourcesManager::Rm(this);
|
||||||
|
}
|
52
Sources/libewol/ewol/resources/ResourcesImage.h
Normal file
52
Sources/libewol/ewol/resources/ResourcesImage.h
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
*******************************************************************************
|
||||||
|
* @file ewol/resources/ResourcesImage.h
|
||||||
|
* @brief ewol Resources image system (header)
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @date 21/08/2012
|
||||||
|
* @par Project
|
||||||
|
* ewol
|
||||||
|
*
|
||||||
|
* @par Copyright
|
||||||
|
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY.
|
||||||
|
*
|
||||||
|
* Licence summary :
|
||||||
|
* You can modify and redistribute the sources code and binaries.
|
||||||
|
* You can send me the bug-fix
|
||||||
|
*
|
||||||
|
* Term of the licence in in the file licence.txt.
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __EWOL_RESOURCES_IMAGE_H__
|
||||||
|
#define __EWOL_RESOURCES_IMAGE_H__
|
||||||
|
|
||||||
|
#include <etk/UString.h>
|
||||||
|
#include <draw/Image.h>
|
||||||
|
|
||||||
|
namespace ewol
|
||||||
|
{
|
||||||
|
class ResourcesImage
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
uint32_t m_resourceID;
|
||||||
|
uint32_t m_counter;
|
||||||
|
draw::Image m_image;
|
||||||
|
etk::UString m_fileName;
|
||||||
|
public:
|
||||||
|
ResourcesImage(etk::UString fileName, Vector2D<int32_t> size);
|
||||||
|
~ResourcesImage(void);
|
||||||
|
bool HasName(etk::UString& fileName) { return fileName==m_fileName; };
|
||||||
|
void Increment(void) { m_counter++; };
|
||||||
|
bool Decrement(void) { m_counter--; return (m_counter==0)?true:false; };
|
||||||
|
draw::Image& Get(void) { return m_image; };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
128
Sources/libewol/ewol/resources/ResourcesManager.cpp
Normal file
128
Sources/libewol/ewol/resources/ResourcesManager.cpp
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/**
|
||||||
|
*******************************************************************************
|
||||||
|
* @file ewol/resources/ResourcesManager.cpp
|
||||||
|
* @brief ewol Resources manager system (Sources)
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @date 21/08/2012
|
||||||
|
* @par Project
|
||||||
|
* ewol
|
||||||
|
*
|
||||||
|
* @par Copyright
|
||||||
|
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY.
|
||||||
|
*
|
||||||
|
* Licence summary :
|
||||||
|
* You can modify and redistribute the sources code and binaries.
|
||||||
|
* You can send me the bug-fix
|
||||||
|
*
|
||||||
|
* Term of the licence in in the file licence.txt.
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <etk/Types.h>
|
||||||
|
#include <ewol/Debug.h>
|
||||||
|
#include <etk/File.h>
|
||||||
|
#include <etk/Vector.h>
|
||||||
|
#include <ewol/resources/ResourcesManager.h>
|
||||||
|
|
||||||
|
static etk::Vector<ewol::ResourcesImage *> l_imageList;
|
||||||
|
|
||||||
|
static uint32_t l_uniqueIdResources = 0;
|
||||||
|
|
||||||
|
void ewol::resourcesManager::Init(void)
|
||||||
|
{
|
||||||
|
// nothing to do in théory then, we clean the buffers :
|
||||||
|
// NOTE : If we do domething here, then the system does not work corectly
|
||||||
|
l_imageList.Clear();
|
||||||
|
l_uniqueIdResources = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::resourcesManager::UnInit(void)
|
||||||
|
{
|
||||||
|
for (int32_t iii=0; iii<l_imageList.Size(); iii++) {
|
||||||
|
if (l_imageList[iii] != NULL) {
|
||||||
|
delete(l_imageList[iii]);
|
||||||
|
l_imageList[iii] = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l_imageList.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// note : Return the UniqueID ...
|
||||||
|
uint32_t ewol::resourcesManager::Add(ewol::ResourcesImage *object)
|
||||||
|
{
|
||||||
|
if (object==NULL) {
|
||||||
|
EWOL_CRITICAL("try to add an Image Resources with NULL pointer ...");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
for (int32_t iii=0; iii<l_imageList.Size(); iii++) {
|
||||||
|
if (l_imageList[iii] != NULL) {
|
||||||
|
if (l_imageList[iii] == object) {
|
||||||
|
EWOL_CRITICAL("try to add a Image resources a second time ...");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
l_uniqueIdResources ++;
|
||||||
|
// add it in the list
|
||||||
|
l_imageList.PushBack(object);
|
||||||
|
// return his ID ...
|
||||||
|
return l_uniqueIdResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::resourcesManager::Rm(ewol::ResourcesImage *object)
|
||||||
|
{
|
||||||
|
if (object==NULL) {
|
||||||
|
EWOL_CRITICAL("try to remove a texture with NULL pointer ...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) {
|
||||||
|
if (l_imageList[iii] != NULL) {
|
||||||
|
if (l_imageList[iii] == object) {
|
||||||
|
// we find the texture :
|
||||||
|
l_imageList.Erase(iii);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EWOL_CRITICAL("Try to remove an Image resources that is not present in the resources pool");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ewol::ResourcesImage* ewol::resourcesManager::ImageKeep(etk::UString fileName, Vector2D<int32_t> size)
|
||||||
|
{
|
||||||
|
for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) {
|
||||||
|
if (l_imageList[iii] != NULL) {
|
||||||
|
if( l_imageList[iii]->HasName(fileName)
|
||||||
|
&& l_imageList[iii]->Get().GetSize() == size) {
|
||||||
|
l_imageList[iii]->Increment();
|
||||||
|
return l_imageList[iii];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ewol::ResourcesImage* tmpResources = new ewol::ResourcesImage(fileName, size);
|
||||||
|
if (NULL == tmpResources) {
|
||||||
|
EWOL_ERROR("allocation error of a resource Image : " << fileName);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
l_imageList.PushBack(tmpResources);
|
||||||
|
return tmpResources;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ewol::resourcesManager::ImageRelease(ewol::ResourcesImage* object)
|
||||||
|
{
|
||||||
|
for (int32_t iii=l_imageList.Size()-1; iii>=0; iii--) {
|
||||||
|
if (l_imageList[iii] != NULL) {
|
||||||
|
if(l_imageList[iii] == object) {
|
||||||
|
if (true == l_imageList[iii]->Decrement()) {
|
||||||
|
delete(l_imageList[iii]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
50
Sources/libewol/ewol/resources/ResourcesManager.h
Normal file
50
Sources/libewol/ewol/resources/ResourcesManager.h
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
*******************************************************************************
|
||||||
|
* @file ewol/resources/ResourcesManager.h
|
||||||
|
* @brief ewol Resources manager system (header)
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @date 21/08/2012
|
||||||
|
* @par Project
|
||||||
|
* ewol
|
||||||
|
*
|
||||||
|
* @par Copyright
|
||||||
|
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY.
|
||||||
|
*
|
||||||
|
* Licence summary :
|
||||||
|
* You can modify and redistribute the sources code and binaries.
|
||||||
|
* You can send me the bug-fix
|
||||||
|
*
|
||||||
|
* Term of the licence in in the file licence.txt.
|
||||||
|
*
|
||||||
|
*******************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __EWOL_RESOURCES_MANAGER_H__
|
||||||
|
#define __EWOL_RESOURCES_MANAGER_H__
|
||||||
|
|
||||||
|
#include <etk/Types.h>
|
||||||
|
#include <ewol/Debug.h>
|
||||||
|
#include <etk/File.h>
|
||||||
|
#include <ewol/resources/ResourcesImage.h>
|
||||||
|
|
||||||
|
namespace ewol
|
||||||
|
{
|
||||||
|
namespace resourcesManager {
|
||||||
|
void Init(void);
|
||||||
|
void UnInit(void);
|
||||||
|
uint32_t Add(ewol::ResourcesImage* object);
|
||||||
|
void Rm(ewol::ResourcesImage* object);
|
||||||
|
//uint32_t Add(audio::Track* object);
|
||||||
|
//void Rm(audio::Track* object);
|
||||||
|
|
||||||
|
ewol::ResourcesImage* ImageKeep(etk::UString fileName, Vector2D<int32_t> size);
|
||||||
|
void ImageRelease(ewol::ResourcesImage* object);
|
||||||
|
//audio::Track* AudioKeep(etk::UString fileName, Vector2D<int32_t> size);
|
||||||
|
//void AudioRelease(audio::Track* object);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -31,6 +31,10 @@
|
|||||||
#include <ewol/openGl.h>
|
#include <ewol/openGl.h>
|
||||||
|
|
||||||
namespace ewol {
|
namespace ewol {
|
||||||
|
// TODO : remove this deprecated element
|
||||||
|
namespace texture {
|
||||||
|
inline int32_t GetGLID(int32_t m_FontTextureId) { return 0; };
|
||||||
|
};
|
||||||
class Texture {
|
class Texture {
|
||||||
private:
|
private:
|
||||||
uint32_t m_uniqueId;
|
uint32_t m_uniqueId;
|
||||||
|
@ -22,9 +22,6 @@
|
|||||||
*******************************************************************************
|
*******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __EWOL_TEXTURE_MANAGER_H__
|
|
||||||
#define __EWOL_TEXTURE_MANAGER_H__
|
|
||||||
|
|
||||||
#include <etk/Types.h>
|
#include <etk/Types.h>
|
||||||
#include <ewol/Debug.h>
|
#include <ewol/Debug.h>
|
||||||
#include <etk/File.h>
|
#include <etk/File.h>
|
||||||
|
@ -6,6 +6,10 @@ FILE_LIST = ewol/ewol.cpp \
|
|||||||
ewol/Debug.cpp \
|
ewol/Debug.cpp \
|
||||||
ewol/ShortCutManager.cpp
|
ewol/ShortCutManager.cpp
|
||||||
|
|
||||||
|
# Resources manager
|
||||||
|
FILE_LIST+= ewol/resources/ResourcesManager.cpp \
|
||||||
|
ewol/resources/ResourcesImage.cpp
|
||||||
|
|
||||||
# Gui interface
|
# Gui interface
|
||||||
FILE_LIST+= ewol/os/eSystem.cpp \
|
FILE_LIST+= ewol/os/eSystem.cpp \
|
||||||
ewol/os/eSystemInput.cpp
|
ewol/os/eSystemInput.cpp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user