[DEV] integrate the new interface of URI and file

This commit is contained in:
Edouard DUPIN 2018-09-24 23:26:07 +02:00
parent 63ac2d7e07
commit 532b64a1f0
24 changed files with 255 additions and 232 deletions

View File

@ -4,7 +4,7 @@
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
#include <etk/os/FSNode.hpp> #include <etk/uri/uri.hpp>
#include <ewol/debug.hpp> #include <ewol/debug.hpp>
#include <ewol/compositing/Shaper.hpp> #include <ewol/compositing/Shaper.hpp>
#include <etk/typeInfo.hpp> #include <etk/typeInfo.hpp>
@ -15,8 +15,8 @@ const int32_t ewol::compositing::Shaper::m_vboIdCoord(0);
const int32_t ewol::compositing::Shaper::m_vboIdPos(1); const int32_t ewol::compositing::Shaper::m_vboIdPos(1);
#define NB_VBO (2) #define NB_VBO (2)
ewol::compositing::Shaper::Shaper(const etk::String& _shaperName) : ewol::compositing::Shaper::Shaper(const etk::Uri& _uri) :
m_name(_shaperName), m_uri(_uri),
m_config(null), m_config(null),
m_confIdMode(-1), m_confIdMode(-1),
m_confIdDisplayOutside(-1), m_confIdDisplayOutside(-1),
@ -83,11 +83,11 @@ void ewol::compositing::Shaper::unLoadProgram() {
} }
void ewol::compositing::Shaper::loadProgram() { void ewol::compositing::Shaper::loadProgram() {
if (m_name == "") { if (m_uri.isEmpty() == true) {
EWOL_DEBUG("no Shaper set for loading resources ..."); EWOL_DEBUG("no Shaper set for loading resources ...");
return; return;
} }
m_config = ewol::resource::ConfigFile::create(m_name); m_config = ewol::resource::ConfigFile::create(m_uri.get());
if (m_config != null) { if (m_config != null) {
m_confIdMode = m_config->request("mode"); m_confIdMode = m_config->request("mode");
m_confIdDisplayOutside = m_config->request("display-outside"); m_confIdDisplayOutside = m_config->request("display-outside");
@ -113,8 +113,9 @@ void ewol::compositing::Shaper::loadProgram() {
etk::String tmpFilename(basicShaderFile); etk::String tmpFilename(basicShaderFile);
if (tmpFilename.find(':') == etk::String::npos) { if (tmpFilename.find(':') == etk::String::npos) {
// get the relative position of the current file ... // get the relative position of the current file ...
etk::FSNode file(m_name); etk::Uri tmpUri = m_uri;
tmpFilename = file.getRelativeFolder() + basicShaderFile; tmpUri.setPath(m_uri.getPath().getParent() / basicShaderFile);
tmpFilename = tmpUri.get();
EWOL_DEBUG("Shaper try load shader : '" << tmpFilename << "' with base : '" << basicShaderFile << "'"); EWOL_DEBUG("Shaper try load shader : '" << tmpFilename << "' with base : '" << basicShaderFile << "'");
} else { } else {
EWOL_DEBUG("Shaper try load shader : '" << tmpFilename << "'"); EWOL_DEBUG("Shaper try load shader : '" << tmpFilename << "'");
@ -140,8 +141,9 @@ void ewol::compositing::Shaper::loadProgram() {
etk::String tmpFilename(basicImageFile); etk::String tmpFilename(basicImageFile);
if (tmpFilename.find(':') == etk::String::npos) { if (tmpFilename.find(':') == etk::String::npos) {
// get the relative position of the current file ... // get the relative position of the current file ...
etk::FSNode file(m_name); etk::Uri tmpUri = m_uri;
tmpFilename = file.getRelativeFolder() + basicImageFile; tmpUri.setPath(m_uri.getPath().getParent() / basicImageFile);
tmpFilename = tmpUri.get();
EWOL_DEBUG("Shaper try load shaper image : '" << tmpFilename << "' with base : '" << basicImageFile << "'"); EWOL_DEBUG("Shaper try load shaper image : '" << tmpFilename << "' with base : '" << basicImageFile << "'");
} else { } else {
EWOL_DEBUG("Shaper try load shaper image : '" << tmpFilename << "'"); EWOL_DEBUG("Shaper try load shaper image : '" << tmpFilename << "'");
@ -155,8 +157,9 @@ void ewol::compositing::Shaper::loadProgram() {
etk::String tmpFilename(basicColorFile); etk::String tmpFilename(basicColorFile);
if (tmpFilename.find(':') == etk::String::npos) { if (tmpFilename.find(':') == etk::String::npos) {
// get the relative position of the current file ... // get the relative position of the current file ...
etk::FSNode file(m_name); etk::Uri tmpUri = m_uri;
tmpFilename = file.getRelativeFolder() + basicColorFile; tmpUri.setPath(m_uri.getPath().getParent() / basicColorFile);
tmpFilename = tmpUri.get();
EWOL_DEBUG("Shaper try load colorFile : '" << tmpFilename << "' with base : '" << basicColorFile << "'"); EWOL_DEBUG("Shaper try load colorFile : '" << tmpFilename << "' with base : '" << basicColorFile << "'");
} else { } else {
EWOL_DEBUG("Shaper try load colorFile : '" << tmpFilename << "'"); EWOL_DEBUG("Shaper try load colorFile : '" << tmpFilename << "'");
@ -626,15 +629,15 @@ ewol::Padding ewol::compositing::Shaper::getBorder() {
return padding; return padding;
} }
void ewol::compositing::Shaper::setSource(const etk::String& _newFile) { void ewol::compositing::Shaper::setSource(const etk::Uri& _uri) {
clear(); clear();
unLoadProgram(); unLoadProgram();
m_name = _newFile; m_uri = _uri;
loadProgram(); loadProgram();
} }
bool ewol::compositing::Shaper::hasSources() { bool ewol::compositing::Shaper::hasSources() {
return m_GLprogram!=null; return m_GLprogram != null;
} }
@ -675,7 +678,7 @@ double ewol::compositing::Shaper::getConfigNumber(int32_t _id) {
namespace etk { namespace etk {
template<> etk::String toString<ewol::compositing::Shaper>(const ewol::compositing::Shaper& _obj) { template<> etk::String toString<ewol::compositing::Shaper>(const ewol::compositing::Shaper& _obj) {
return _obj.getSource(); return _obj.getSource().get();
} }
template<> etk::UString toUString<ewol::compositing::Shaper>(const ewol::compositing::Shaper& _obj) { template<> etk::UString toUString<ewol::compositing::Shaper>(const ewol::compositing::Shaper& _obj) {
return etk::toUString(etk::toString(_obj)); return etk::toUString(etk::toString(_obj));

View File

@ -38,7 +38,7 @@ namespace ewol {
// TODO : Abstaraction between states (call by name and the system greate IDs // TODO : Abstaraction between states (call by name and the system greate IDs
class Shaper : public ewol::Compositing { class Shaper : public ewol::Compositing {
private: private:
etk::String m_name; //!< Name of the configuration of the shaper. etk::Uri m_uri; //!< Name of the configuration of the shaper.
// External theme config: // External theme config:
ememory::SharedPtr<ewol::resource::ConfigFile> m_config; //!< pointer on the config file resources ememory::SharedPtr<ewol::resource::ConfigFile> m_config; //!< pointer on the config file resources
int32_t m_confIdPaddingOut[shaperPosCount]; //!< Padding out property : X-left X-right Y-top Y-buttom int32_t m_confIdPaddingOut[shaperPosCount]; //!< Padding out property : X-left X-right Y-top Y-buttom
@ -92,9 +92,9 @@ namespace ewol {
public: public:
/** /**
* @brief generic constructor * @brief generic constructor
* @param[in] _shaperName Name of the file that might be loaded * @param[in] _uri URI of the file that might be loaded
*/ */
Shaper(const etk::String& _shaperName=""); Shaper(const etk::Uri& _uri="");
/** /**
* @brief generic destructor * @brief generic destructor
*/ */
@ -164,15 +164,15 @@ namespace ewol {
ewol::Padding getBorder(); ewol::Padding getBorder();
/** /**
* @brief change the shaper Source * @brief change the shaper Source
* @param[in] _newFile New file of the shaper * @param[in] _uri New file of the shaper
*/ */
void setSource(const etk::String& _newFile); void setSource(const etk::Uri& _uri);
/** /**
* @brief get the shaper file Source * @brief get the shaper file Source
* @return the shapper file name * @return the shapper file name
*/ */
const etk::String& getSource() const { const etk::Uri& getSource() const {
return m_name; return m_uri;
}; };
/** /**
* @brief Sometimes the user declare an image but not allocate the ressources all the time, this is to know it .. * @brief Sometimes the user declare an image but not allocate the ressources all the time, this is to know it ..
@ -284,10 +284,10 @@ namespace ewol {
* == operator * == operator
*****************************************************/ *****************************************************/
bool operator== (const Shaper& _obj) const { bool operator== (const Shaper& _obj) const {
return _obj.m_name == m_name; return _obj.m_uri == m_uri;
} }
bool operator!= (const Shaper& _obj) const { bool operator!= (const Shaper& _obj) const {
return _obj.m_name != m_name; return _obj.m_uri != m_uri;
} }
}; };
} }

View File

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <ewol/debug.hpp> #include <ewol/debug.hpp>
#include <etk/uri/uri.hpp>
namespace ewol { namespace ewol {
namespace context { namespace context {
@ -17,20 +18,20 @@ namespace ewol {
ConfigFont(); ConfigFont();
virtual ~ConfigFont(); virtual ~ConfigFont();
private: private:
etk::String m_folder; etk::Uri m_folder;
public: public:
/** /**
* @brief Specify the default font folder for the Ewol search system (only needed when embended font) * @brief Specify the default font folder for the Ewol search system (only needed when embended font)
* @param[in] _folder basic folder of the font (ex: DATA:fonts) * @param[in] _folder basic folder of the font (ex: DATA:fonts)
*/ */
void setFolder(const etk::String& _folder) { void setFolder(const etk::Uri& _folder) {
m_folder = _folder; m_folder = _folder;
}; };
/** /**
* @brief get the default font folder. * @brief get the default font folder.
* @return The default font folder. * @return The default font folder.
*/ */
const etk::String& getFolder() { const etk::Uri& getFolder() {
return m_folder; return m_folder;
}; };
private: private:

View File

@ -8,9 +8,9 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/etk.hpp> #include <etk/etk.hpp>
#include <etk/tool.hpp> #include <etk/tool.hpp>
#include <etk/os/FSNode.hpp> #include <etk/theme/theme.hpp>
#include <ethread/tools.hpp> #include <ethread/tools.hpp>
#include <ethread/Mutex.hpp> #include <ethread/Mutex.hpp>

View File

@ -11,7 +11,6 @@
#include <etranslate/etranslate.hpp> #include <etranslate/etranslate.hpp>
#include <gale/context/commandLine.hpp> #include <gale/context/commandLine.hpp>
#include <etk/os/FSNode.hpp>
#include <gale/Dimension.hpp> #include <gale/Dimension.hpp>
#ifndef EWOL_VERSION #ifndef EWOL_VERSION

View File

@ -4,7 +4,7 @@
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
#include <etk/os/FSNode.hpp> #include <etk/uri/uri.hpp>
#include <ewol/debug.hpp> #include <ewol/debug.hpp>
#include <ewol/resource/ColorFile.hpp> #include <ewol/resource/ColorFile.hpp>
#include <ejson/ejson.hpp> #include <ejson/ejson.hpp>
@ -19,10 +19,10 @@ ewol::resource::ColorFile::ColorFile() :
addResourceType("ewol::ColorFile"); addResourceType("ewol::ColorFile");
} }
void ewol::resource::ColorFile::init(const etk::String& _filename) { void ewol::resource::ColorFile::init(const etk::Uri& _uri) {
ethread::RecursiveLock lock(m_mutex); ethread::RecursiveLock lock(m_mutex);
gale::Resource::init(_filename); gale::Resource::init(_uri.get());
EWOL_DEBUG("CF : load \"" << _filename << "\""); EWOL_DEBUG("CF : load \"" << _uri << "\"");
reload(); reload();
EWOL_DEBUG("List of all color : " << m_list.getKeys()); EWOL_DEBUG("List of all color : " << m_list.getKeys());
} }
@ -41,8 +41,8 @@ void ewol::resource::ColorFile::reload() {
} }
// open and read all json elements: // open and read all json elements:
ejson::Document doc; ejson::Document doc;
if (doc.load(m_name) == false) { if (doc.load(etk::Uri(m_name)) == false) {
EWOL_ERROR("Can not load file : '" << m_name << "' = " << etk::FSNode(m_name).getFileSystemName()); EWOL_ERROR("Can not load file : '" << m_name << "'");
return; return;
} }
ejson::Array baseArray = doc["color"].toArray(); ejson::Array baseArray = doc["color"].toArray();

View File

@ -23,10 +23,10 @@ namespace ewol {
protected: protected:
/** /**
* @brief Constructor of the color property file * @brief Constructor of the color property file
* @param[in] _filename Name of the file needed * @param[in] _uri Name of the file needed
*/ */
ColorFile(); ColorFile();
void init(const etk::String& _filename); void init(const etk::Uri& _uri);
public: public:
DECLARE_RESOURCE_NAMED_FACTORY(ColorFile); DECLARE_RESOURCE_NAMED_FACTORY(ColorFile);
/** /**

View File

@ -4,7 +4,7 @@
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
#include <etk/os/FSNode.hpp> #include <etk/uri/uri.hpp>
#include <ewol/debug.hpp> #include <ewol/debug.hpp>
#include <ewol/resource/ConfigFile.hpp> #include <ewol/resource/ConfigFile.hpp>
#include <gale/resource/Manager.hpp> #include <gale/resource/Manager.hpp>
@ -21,10 +21,10 @@ ewol::resource::ConfigFile::ConfigFile() :
addResourceType("ewol::ConfigFile"); addResourceType("ewol::ConfigFile");
} }
void ewol::resource::ConfigFile::init(const etk::String& _filename) { void ewol::resource::ConfigFile::init(const etk::Uri& _uri) {
ethread::RecursiveLock lock(m_mutex); ethread::RecursiveLock lock(m_mutex);
gale::Resource::init(_filename); gale::Resource::init(_uri.get());
EWOL_DEBUG("SFP : load \"" << _filename << "\""); EWOL_DEBUG("SFP : load \"" << _uri << "\"");
reload(); reload();
} }
@ -41,7 +41,7 @@ void ewol::resource::ConfigFile::reload() {
m_list.getValue(iii) = ejson::empty(); m_list.getValue(iii) = ejson::empty();
} }
} }
m_doc.load(m_name); m_doc.load(etk::Uri(m_name));
for (auto elementName : m_list.getKeys()) { for (auto elementName : m_list.getKeys()) {
if (m_doc[elementName].exist() == true) { if (m_doc[elementName].exist() == true) {

View File

@ -19,7 +19,7 @@ namespace ewol {
etk::Map<etk::String, ejson::Value> m_list; etk::Map<etk::String, ejson::Value> m_list;
protected: protected:
ConfigFile(); ConfigFile();
void init(const etk::String& _filename); void init(const etk::Uri& _filename);
public: public:
virtual ~ConfigFile(); virtual ~ConfigFile();
DECLARE_RESOURCE_NAMED_FACTORY(ConfigFile); DECLARE_RESOURCE_NAMED_FACTORY(ConfigFile);

View File

@ -5,7 +5,7 @@
*/ */
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/os/FSNode.hpp> #include <etk/uri/uri.hpp>
#include <egami/egami.hpp> #include <egami/egami.hpp>
#include <gale/resource/Manager.hpp> #include <gale/resource/Manager.hpp>
@ -34,41 +34,59 @@ ewol::resource::DistanceFieldFont::DistanceFieldFont() :
m_sizeRatio = 1.0f; m_sizeRatio = 1.0f;
} }
/**
* @brief Get all the Path contain in the specidy path:
* @param[in] _path Generic path to parse ...
* @return The list of path found
* @example[start]
* auto out = explodeMultiplePath("DATA:///font?lib=ewol");
* // out contain: {"DATA:///font", "DATA:///font?lib=ewol"}
* @example[stop]
*/
static etk::Vector<etk::Uri> explodeMultiplePath(const etk::Uri& _uri) {
etk::Vector<etk::Uri> out;
out.pushBack(_uri);
if (_uri.getQuery().exist("lib") == true) {
etk::Uri tmp = _uri;
tmp.getQuery().erase("lib");
out.pushBack(tmp);
}
return out;
}
void ewol::resource::DistanceFieldFont::init(const etk::String& _fontName) { void ewol::resource::DistanceFieldFont::init(const etk::String& _fontName) {
ethread::RecursiveLock lock(m_mutex); ethread::RecursiveLock lock(m_mutex);
ewol::resource::Texture::init(_fontName); ewol::resource::Texture::init(_fontName);
etk::String localName = _fontName; etk::String localName = _fontName;
etk::Vector<etk::String> folderList; etk::Vector<etk::Uri> folderList;
if (true == ewol::getContext().getFontDefault().getUseExternal()) { if (ewol::getContext().getFontDefault().getUseExternal() == true) {
#if defined(__TARGET_OS__Android) #if defined(__TARGET_OS__Android)
folderList.pushBack("ROOT:system/fonts"); folderList.pushBack(etk::Path("/system/fonts"));
#elif defined(__TARGET_OS__Linux) #elif defined(__TARGET_OS__Linux)
folderList.pushBack("ROOT:usr/share/fonts/truetype"); folderList.pushBack(etk::Path("/usr/share/fonts/truetype"));
#endif #endif
} }
etk::String applicationBaseFont = ewol::getContext().getFontDefault().getFolder(); etk::Uri applicationBaseFont = ewol::getContext().getFontDefault().getFolder();
etk::Vector<etk::String> applicationBaseFontList = etk::FSNodeExplodeMultiplePath(applicationBaseFont); for (auto &it : explodeMultiplePath(applicationBaseFont)) {
for (auto &it : applicationBaseFontList) {
folderList.pushBack(it); folderList.pushBack(it);
} }
for (size_t folderID = 0; folderID < folderList.size() ; folderID++) { for (size_t folderID = 0; folderID < folderList.size() ; folderID++) {
etk::FSNode myFolder(folderList[folderID]); etk::Vector<etk::Uri> output = etk::uri::listRecursive(folderList[folderID]);
// find the real Font name :
etk::Vector<etk::String> output;
myFolder.folderGetRecursiveFiles(output);
etk::Vector<etk::String> split = etk::split(localName, ';'); etk::Vector<etk::String> split = etk::split(localName, ';');
EWOL_INFO("try to find font named : " << split << " in: " << myFolder); EWOL_INFO("try to find font named : " << split << " in: " << output);
//EWOL_CRITICAL("parse string : " << split); //EWOL_CRITICAL("parse string : " << split);
bool hasFindAFont = false; bool hasFindAFont = false;
for (size_t jjj=0; jjj<split.size(); jjj++) { for (size_t jjj=0; jjj<split.size(); jjj++) {
EWOL_INFO(" try with : '" << split[jjj] << "'"); EWOL_INFO(" try with : '" << split[jjj] << "'");
for (size_t iii=0; iii<output.size(); iii++) { for (size_t iii=0; iii<output.size(); iii++) {
etk::String nameFolder = output[iii].getPath().getString();
//EWOL_DEBUG(" file : " << output[iii]); //EWOL_DEBUG(" file : " << output[iii]);
if( true == etk::end_with(output[iii], split[jjj]+"-"+"regular"+".ttf", false) if( true == etk::end_with(nameFolder, split[jjj]+"-"+"regular"+".ttf", false)
|| true == etk::end_with(output[iii], split[jjj]+"-"+"r"+".ttf", false) || true == etk::end_with(nameFolder, split[jjj]+"-"+"r"+".ttf", false)
|| true == etk::end_with(output[iii], split[jjj]+"regular"+".ttf", false) || true == etk::end_with(nameFolder, split[jjj]+"regular"+".ttf", false)
|| true == etk::end_with(output[iii], split[jjj]+"r"+".ttf", false) || true == etk::end_with(nameFolder, split[jjj]+"r"+".ttf", false)
|| true == etk::end_with(output[iii], split[jjj]+".ttf", false)) { || true == etk::end_with(nameFolder, split[jjj]+".ttf", false)) {
EWOL_INFO(" find Font [Regular] : " << output[iii]); EWOL_INFO(" find Font [Regular] : " << output[iii]);
m_fileName = output[iii]; m_fileName = output[iii];
hasFindAFont=true; hasFindAFont=true;
@ -90,8 +108,8 @@ void ewol::resource::DistanceFieldFont::init(const etk::String& _fontName) {
} }
} }
if (m_fileName.size() == 0) { if (m_fileName.isEmpty() == true) {
EWOL_ERROR("can not load FONT name : '" << m_fileName << "'" ); EWOL_ERROR("can not load FONT name : '" << _fontName << "'" );
m_font = null; m_font = null;
return; return;
} }
@ -370,24 +388,30 @@ void ewol::resource::DistanceFieldFont::exportOnFile() {
doc.add("m_lastRawHeigh", ejson::Number(m_lastRawHeigh)); doc.add("m_lastRawHeigh", ejson::Number(m_lastRawHeigh));
doc.add("m_borderSize", ejson::Number(m_borderSize)); doc.add("m_borderSize", ejson::Number(m_borderSize));
doc.add("m_textureBorderSize", ejson::String(m_textureBorderSize)); doc.add("m_textureBorderSize", ejson::String(m_textureBorderSize));
doc.store(m_fileName + ".json"); etk::Uri tmpUri = m_fileName;
egami::store(m_data, m_fileName + ".bmp"); tmpUri.setPath(m_fileName.getPath() + ".json");
egami::store(m_data, m_fileName + ".png"); doc.store(tmpUri);
tmpUri.setPath(m_fileName.getPath() + ".bmp");
egami::store(m_data, tmpUri);
tmpUri.setPath(m_fileName.getPath() + ".png");
egami::store(m_data, tmpUri);
} }
bool ewol::resource::DistanceFieldFont::importFromFile() { bool ewol::resource::DistanceFieldFont::importFromFile() {
ethread::RecursiveLock lock(m_mutex); ethread::RecursiveLock lock(m_mutex);
EWOL_DEBUG("IMPORT: DistanceFieldFont : file : '" << m_fileName << ".json'"); etk::Uri tmpUriJson = m_fileName;
tmpUriJson.setPath(m_fileName.getPath() + ".json");
etk::Uri tmpUriBmp = m_fileName;
tmpUriBmp.setPath(m_fileName.getPath() + ".bmp");
EWOL_DEBUG("IMPORT: DistanceFieldFont : file : '" << tmpUriJson << "'");
// test file existance: // test file existance:
etk::FSNode fileJSON(m_fileName + ".json"); if ( etk::uri::exist(tmpUriJson) == false
etk::FSNode fileBMP(m_fileName + ".bmp"); || etk::uri::exist(tmpUriBmp) == false) {
if ( fileJSON.exist() == false
|| fileBMP.exist() == false) {
EWOL_DEBUG("Does not import file for distance field system"); EWOL_DEBUG("Does not import file for distance field system");
return false; return false;
} }
ejson::Document doc; ejson::Document doc;
doc.load(m_fileName + ".json"); doc.load(tmpUriJson);
m_sizeRatio = doc["m_sizeRatio"].toNumber().get(0); m_sizeRatio = doc["m_sizeRatio"].toNumber().get(0);
m_lastGlyphPos = doc["m_lastGlyphPos"].toString().get("0,0"); m_lastGlyphPos = doc["m_lastGlyphPos"].toString().get("0,0");
@ -416,6 +440,6 @@ bool ewol::resource::DistanceFieldFont::importFromFile() {
prop.m_exist = tmpObj["m_exist"].toBoolean().get(false); prop.m_exist = tmpObj["m_exist"].toBoolean().get(false);
m_listElement.pushBack(prop); m_listElement.pushBack(prop);
} }
m_data = egami::load(m_fileName + ".bmp"); m_data = egami::load(tmpUriBmp);
return m_data.exist(); return m_data.exist();
} }

View File

@ -13,7 +13,7 @@ namespace ewol {
namespace resource { namespace resource {
class DistanceFieldFont : public ewol::resource::Texture { class DistanceFieldFont : public ewol::resource::Texture {
private: private:
etk::String m_fileName; etk::Uri m_fileName;
float m_sizeRatio; float m_sizeRatio;
// specific element to have the the know if the specify element is known... // specific element to have the the know if the specify element is known...
// == > otherwise I can just generate italic ... // == > otherwise I can just generate italic ...

View File

@ -6,7 +6,6 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/Vector.hpp> #include <etk/Vector.hpp>
#include <etk/os/FSNode.hpp>
#include <gale/renderer/openGL/openGL.hpp> #include <gale/renderer/openGL/openGL.hpp>
@ -56,42 +55,30 @@ ewol::resource::FontFreeType::FontFreeType() {
m_FileSize = 0; m_FileSize = 0;
} }
void ewol::resource::FontFreeType::init(const etk::String& _fontName) { void ewol::resource::FontFreeType::init(const etk::Uri& _uri) {
ethread::RecursiveLock lock(m_mutex); ethread::RecursiveLock lock(m_mutex);
ewol::resource::FontBase::init(_fontName); ewol::resource::FontBase::init(_uri);
etk::FSNode myfile(_fontName); auto fileIO = etk::uri::get(_uri);
if (myfile.exist() == false) { if (fileIO == null) {
EWOL_ERROR("File Does not exist : " << myfile); EWOL_ERROR("File Does not exist : " << _uri);
return; return;
} }
m_FileSize = myfile.fileSize(); if (fileIO->open(etk::io::OpenMode::Read) == false) {
if (m_FileSize == 0) { EWOL_ERROR("Can not open the file : " << _uri);
EWOL_ERROR("This file is empty : " << myfile);
return; return;
} }
if (myfile.fileOpenRead() == false) { m_FileBuffer = fileIO->readAll<FT_Byte>();
EWOL_ERROR("Can not open the file : " << myfile);
return;
}
// allocate data
m_FileBuffer.resize(m_FileSize, 0);
if (m_FileBuffer.size() != m_FileSize) {
EWOL_ERROR("Error Memory allocation size=" << _fontName);
return;
}
// load data from the file :
myfile.fileRead(&m_FileBuffer[0], 1, m_FileSize);
// close the file: // close the file:
myfile.fileClose(); fileIO->close();
// load Face ... // load Face ...
int32_t error = FT_New_Memory_Face(library, &m_FileBuffer[0], m_FileSize, 0, &m_fftFace ); int32_t error = FT_New_Memory_Face(library, &m_FileBuffer[0], m_FileBuffer.size(), 0, &m_fftFace );
if( FT_Err_Unknown_File_Format == error) { if( FT_Err_Unknown_File_Format == error) {
EWOL_ERROR("... the font file could be opened and read, but it appears ... that its font format is unsupported"); EWOL_ERROR("... the font file could be opened and read, but it appears ... that its font format is unsupported");
} else if (0 != error) { } else if (0 != error) {
EWOL_ERROR("... another error code means that the font file could not ... be opened or read, or simply that it is broken..."); EWOL_ERROR("... another error code means that the font file could not ... be opened or read, or simply that it is broken...");
} else { } else {
// all OK // all OK
EWOL_INFO("load font : \"" << _fontName << "\" glyph count = " << (int)m_fftFace->num_glyphs); EWOL_INFO("load font : \"" << _uri << "\" glyph count = " << (int)m_fftFace->num_glyphs);
m_init = true; m_init = true;
//display(); //display();
} }

View File

@ -7,6 +7,7 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <ewol/resource/font/FontBase.hpp> #include <ewol/resource/font/FontBase.hpp>
#include <etk/uri/uri.hpp>
#include <egami/egami.hpp> #include <egami/egami.hpp>
extern "C" { extern "C" {
@ -26,9 +27,9 @@ namespace ewol {
void display(); void display();
protected: protected:
FontFreeType(); FontFreeType();
void init(const etk::String& _fontName); void init(const etk::Uri& _uri);
public: public:
DECLARE_RESOURCE_NAMED_FACTORY(FontFreeType); DECLARE_RESOURCE_URI_FACTORY(FontFreeType);
virtual ~FontFreeType(); virtual ~FontFreeType();
public: public:

View File

@ -25,13 +25,13 @@ void ewol::resource::ImageDF::init() {
ewol::resource::Texture::init(); ewol::resource::Texture::init();
} }
void ewol::resource::ImageDF::init(etk::String _genName, const etk::String& _tmpfileName, const ivec2& _size) { void ewol::resource::ImageDF::init(etk::String _genName, const etk::Uri& _uri, const ivec2& _size) {
ethread::RecursiveLock lock(m_mutex); ethread::RecursiveLock lock(m_mutex);
ewol::resource::Texture::init(_genName); ewol::resource::Texture::init(_genName);
EWOL_DEBUG("create a new resource::Image : _genName=" << _genName << " _tmpfileName=" << _tmpfileName << " size=" << _size); EWOL_DEBUG("create a new resource::Image : _genName=" << _genName << " _uri=" << _uri << " size=" << _size);
m_data = egami::load(_tmpfileName, _size); m_data = egami::load(_uri, _size);
if (m_data.exist() == false) { if (m_data.exist() == false) {
EWOL_ERROR("ERROR when loading the image : " << _tmpfileName); EWOL_ERROR("ERROR when loading the image : " << _uri);
} }
ivec2 tmp = m_data.getSize(); ivec2 tmp = m_data.getSize();
m_realImageSize = vec2(tmp.x(), tmp.y()); m_realImageSize = vec2(tmp.x(), tmp.y());

View File

@ -18,7 +18,7 @@ namespace ewol {
protected: protected:
ImageDF(); ImageDF();
void init(); void init();
void init(etk::String _genName, const etk::String& _fileName, const ivec2& _size); void init(etk::String _genName, const etk::Uri& _uri, const ivec2& _size);
public: public:
virtual ~ImageDF() { }; virtual ~ImageDF() { };
protected: protected:

View File

@ -45,16 +45,16 @@ void ewol::resource::TextureFile::init() {
ewol::resource::Texture::init(); ewol::resource::Texture::init();
} }
void ewol::resource::TextureFile::init(etk::String _genName, const etk::String& _tmpFilename, const ivec2& _size) { void ewol::resource::TextureFile::init(etk::String _genName, const etk::Uri& _uri, const ivec2& _size) {
ethread::RecursiveLock lock(m_mutex); ethread::RecursiveLock lock(m_mutex);
ewol::resource::Texture::init(_genName); ewol::resource::Texture::init(_genName);
EWOL_DEBUG("create a new resource::Image : _genName=" << _genName << " _tmpFilename=" << _tmpFilename << " size=" << _size); EWOL_DEBUG("create a new resource::Image : _genName=" << _genName << " _uri=" << _uri << " size=" << _size);
egami::Image tmp = egami::load(_tmpFilename, _size); egami::Image tmp = egami::load(_uri, _size);
set(etk::move(tmp)); set(etk::move(tmp));
//m_lastSize = m_realImageSize; //m_lastSize = m_realImageSize;
#ifdef GENERATE_DISTANCE_FIELD_MODE #ifdef GENERATE_DISTANCE_FIELD_MODE
//egami::generateDistanceFieldFile(_tmpFilename, etk::String(_tmpFilename, 0, _tmpFilename.size()-4) + ".bmp"); //egami::generateDistanceFieldFile(_uri, etk::String(_uri, 0, _uri.size()-4) + ".bmp");
egami::generateDistanceFieldFile(_tmpFilename, etk::String(_tmpFilename, 0, _tmpFilename.size()-4) + ".edf"); egami::generateDistanceFieldFile(_uri, etk::String(_uri, 0, _uri.size()-4) + ".edf");
#endif #endif
} }

View File

@ -22,7 +22,7 @@ namespace ewol {
protected: protected:
TextureFile(); TextureFile();
void init(); void init();
void init(etk::String _genName, const etk::String& _fileName, const ivec2& _size); void init(etk::String _genName, const etk::Uri& _uri, const ivec2& _size);
public: public:
virtual ~TextureFile() { }; virtual ~TextureFile() { };
public: public:

View File

@ -5,7 +5,6 @@
*/ */
#include <etk/types.hpp> #include <etk/types.hpp>
#include <etk/os/FSNode.hpp>
#include <egami/egami.hpp> #include <egami/egami.hpp>
#include <gale/resource/Manager.hpp> #include <gale/resource/Manager.hpp>
@ -44,6 +43,26 @@ ewol::resource::TexturedFont::TexturedFont():
addResourceType("ewol::resource::TexturedFont"); addResourceType("ewol::resource::TexturedFont");
} }
/**
* @brief Get all the Path contain in the specidy path:
* @param[in] _path Generic path to parse ...
* @return The list of path found
* @example[start]
* auto out = explodeMultiplePath("DATA:///font?lib=ewol");
* // out contain: {"DATA:///font", "DATA:///font?lib=ewol"}
* @example[stop]
*/
static etk::Vector<etk::Uri> explodeMultiplePath(const etk::Uri& _uri) {
etk::Vector<etk::Uri> out;
out.pushBack(_uri);
if (_uri.getQuery().exist("lib") == true) {
etk::Uri tmp = _uri;
tmp.getQuery().erase("lib");
out.pushBack(tmp);
}
return out;
}
void ewol::resource::TexturedFont::init(const etk::String& _fontName) { void ewol::resource::TexturedFont::init(const etk::String& _fontName) {
ethread::RecursiveLock lock(m_mutex); ethread::RecursiveLock lock(m_mutex);
ewol::resource::Texture::init(_fontName); ewol::resource::Texture::init(_fontName);
@ -76,84 +95,82 @@ void ewol::resource::TexturedFont::init(const etk::String& _fontName) {
if (tmpPos == null) { if (tmpPos == null) {
m_size = 1; m_size = 1;
EWOL_CRITICAL("Can not parse the font name : '" << _fontName << "' ??? ':' " ); EWOL_CRITICAL("Can not parse the font name: '" << _fontName << "' ??? ':' " );
return; return;
} else { } else {
if (sscanf(tmpPos+1, "%d", &tmpSize)!=1) { if (sscanf(tmpPos+1, "%d", &tmpSize)!=1) {
m_size = 1; m_size = 1;
EWOL_CRITICAL("Can not parse the font name : '" << _fontName << "' == > size ???"); EWOL_CRITICAL("Can not parse the font name: '" << _fontName << "' == > size ???");
return; return;
} }
} }
etk::String localName(_fontName, 0, (tmpPos - tmpData)); etk::String localName(_fontName, 0, (tmpPos - tmpData));
if (tmpSize>400) { if (tmpSize>400) {
EWOL_ERROR("Font size too big ==> limit at 400 when exxeed ==> error : " << tmpSize << "==>30"); EWOL_ERROR("Font size too big ==> limit at 400 when exxeed ==> error: " << tmpSize << "==>30");
tmpSize = 30; tmpSize = 30;
} }
m_size = tmpSize; m_size = tmpSize;
etk::Vector<etk::String> folderList; etk::Vector<etk::Uri> folderList;
if (ewol::getContext().getFontDefault().getUseExternal() == true) { if (ewol::getContext().getFontDefault().getUseExternal() == true) {
#if defined(__TARGET_OS__Android) #if defined(__TARGET_OS__Android)
folderList.pushBack("ROOT:system/fonts"); folderList.pushBack(etk::Path("/system/fonts"));
#elif defined(__TARGET_OS__Linux) #elif defined(__TARGET_OS__Linux)
folderList.pushBack("ROOT:usr/share/fonts"); folderList.pushBack(etk::Path("/usr/share/fonts/truetype"));
#endif #endif
} }
etk::String applicationBaseFont = ewol::getContext().getFontDefault().getFolder(); etk::Uri applicationBaseFont = ewol::getContext().getFontDefault().getFolder();
etk::Vector<etk::String> applicationBaseFontList = etk::FSNodeExplodeMultiplePath(applicationBaseFont); for (auto &it : explodeMultiplePath(applicationBaseFont)) {
for (auto &it : applicationBaseFontList) {
folderList.pushBack(it); folderList.pushBack(it);
} }
for (size_t folderID=0; folderID<folderList.size() ; folderID++) { for (size_t folderID = 0; folderID < folderList.size() ; folderID++) {
etk::FSNode myFolder(folderList[folderID]); etk::Vector<etk::Uri> output = etk::uri::listRecursive(folderList[folderID]);
// find the real Font name :
etk::Vector<etk::String> output;
myFolder.folderGetRecursiveFiles(output);
etk::Vector<etk::String> split = etk::split(localName, ';'); etk::Vector<etk::String> split = etk::split(localName, ';');
EWOL_INFO("try to find font named : " << split << " in: " << myFolder); EWOL_INFO("try to find font named : " << split << " in: " << output);
//EWOL_CRITICAL("parse string : " << split); //EWOL_CRITICAL("parse string : " << split);
bool hasFindAFont = false; bool hasFindAFont = false;
for (size_t jjj=0; jjj<split.size(); jjj++) { for (size_t jjj=0; jjj<split.size(); jjj++) {
EWOL_INFO(" try with : '" << split[jjj] << "'"); EWOL_INFO(" try with : '" << split[jjj] << "'");
for (size_t iii=0; iii<output.size(); iii++) { for (size_t iii=0; iii<output.size(); iii++) {
etk::String nameFolder = output[iii].getPath().getString();
//EWOL_DEBUG(" file : " << output[iii]); //EWOL_DEBUG(" file : " << output[iii]);
if( etk::end_with(output[iii], split[jjj]+"-"+"bold"+".ttf", false) == true if( etk::end_with(nameFolder, split[jjj]+"-"+"bold"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"b"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"b"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"bd"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"bd"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"bold"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"bold"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"bd"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"bd"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"b"+".ttf", false) == true) { || etk::end_with(nameFolder, split[jjj]+"b"+".ttf", false) == true) {
EWOL_INFO(" find Font [Bold] : " << output[iii]); EWOL_INFO(" find Font [Bold] : " << output[iii]);
m_fileName[ewol::font::Bold] = output[iii]; m_fileName[ewol::font::Bold] = output[iii];
hasFindAFont = true; hasFindAFont = true;
} else if( etk::end_with(output[iii], split[jjj]+"-"+"oblique"+".ttf", false) == true } else if( etk::end_with(nameFolder, split[jjj]+"-"+"oblique"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"italic"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"italic"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"Light"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"Light"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"i"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"i"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"oblique"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"oblique"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"italic"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"italic"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"light"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"light"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"i"+".ttf", false) == true) { || etk::end_with(nameFolder, split[jjj]+"i"+".ttf", false) == true) {
EWOL_INFO(" find Font [Italic] : " << output[iii]); EWOL_INFO(" find Font [Italic] : " << output[iii]);
m_fileName[ewol::font::Italic] = output[iii]; m_fileName[ewol::font::Italic] = output[iii];
hasFindAFont = true; hasFindAFont = true;
} else if( etk::end_with(output[iii], split[jjj]+"-"+"bolditalic"+".ttf", false) == true } else if( etk::end_with(nameFolder, split[jjj]+"-"+"bolditalic"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"boldoblique"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"boldoblique"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"bi"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"bi"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"z"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"z"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"bolditalic"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"bolditalic"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"boldoblique"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"boldoblique"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"bi"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"bi"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"z"+".ttf", false) == true) { || etk::end_with(nameFolder, split[jjj]+"z"+".ttf", false) == true) {
EWOL_INFO(" find Font [Bold-Italic] : " << output[iii]); EWOL_INFO(" find Font [Bold-Italic] : " << output[iii]);
m_fileName[ewol::font::BoldItalic] = output[iii]; m_fileName[ewol::font::BoldItalic] = output[iii];
hasFindAFont = true; hasFindAFont = true;
} else if( etk::end_with(output[iii], split[jjj]+"-"+"regular"+".ttf", false) == true } else if( etk::end_with(nameFolder, split[jjj]+"-"+"regular"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"-"+"r"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"-"+"r"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"regular"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"regular"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+"r"+".ttf", false) == true || etk::end_with(nameFolder, split[jjj]+"r"+".ttf", false) == true
|| etk::end_with(output[iii], split[jjj]+".ttf", false) == true) { || etk::end_with(nameFolder, split[jjj]+".ttf", false) == true) {
EWOL_INFO(" find Font [Regular] : " << output[iii]); EWOL_INFO(" find Font [Regular] : " << output[iii]);
m_fileName[ewol::font::Regular] = output[iii]; m_fileName[ewol::font::Regular] = output[iii];
hasFindAFont = true; hasFindAFont = true;
@ -176,7 +193,7 @@ void ewol::resource::TexturedFont::init(const etk::String& _fontName) {
// try to find the reference mode : // try to find the reference mode :
enum ewol::font::mode refMode = ewol::font::Regular; enum ewol::font::mode refMode = ewol::font::Regular;
for(int32_t iii=3; iii >= 0; iii--) { for(int32_t iii=3; iii >= 0; iii--) {
if (m_fileName[iii].size() != 0) { if (m_fileName[iii].isEmpty() == false) {
refMode = (enum ewol::font::mode)iii; refMode = (enum ewol::font::mode)iii;
} }
} }
@ -184,7 +201,7 @@ void ewol::resource::TexturedFont::init(const etk::String& _fontName) {
EWOL_DEBUG(" set reference mode : " << refMode); EWOL_DEBUG(" set reference mode : " << refMode);
// generate the wrapping on the preventing error // generate the wrapping on the preventing error
for(int32_t iii=3; iii >= 0; iii--) { for(int32_t iii=3; iii >= 0; iii--) {
if (m_fileName[iii].size() != 0) { if (m_fileName[iii].isEmpty() == false) {
m_modeWraping[iii] = (enum ewol::font::mode)iii; m_modeWraping[iii] = (enum ewol::font::mode)iii;
} else { } else {
m_modeWraping[iii] = refMode; m_modeWraping[iii] = refMode;
@ -192,7 +209,7 @@ void ewol::resource::TexturedFont::init(const etk::String& _fontName) {
} }
for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) { for (int32_t iiiFontId=0; iiiFontId<4 ; iiiFontId++) {
if (m_fileName[iiiFontId].size() == 0) { if (m_fileName[iiiFontId].isEmpty() == true) {
EWOL_DEBUG("can not load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size ); EWOL_DEBUG("can not load FONT [" << iiiFontId << "] name : \"" << m_fileName[iiiFontId] << "\" == > size=" << m_size );
m_font[iiiFontId] = null; m_font[iiiFontId] = null;
continue; continue;

View File

@ -25,7 +25,7 @@ namespace ewol {
namespace resource { namespace resource {
class TexturedFont : public ewol::resource::Texture { class TexturedFont : public ewol::resource::Texture {
private: private:
etk::String m_fileName[4]; etk::Uri m_fileName[4];
int32_t m_size; int32_t m_size;
int32_t m_height[4]; int32_t m_height[4];
// specific element to have the the know if the specify element is known... // specific element to have the the know if the specify element is known...

View File

@ -21,8 +21,8 @@ namespace ewol {
FontBase() { FontBase() {
addResourceType("ewol::FontFreeType"); addResourceType("ewol::FontFreeType");
} }
void init(const etk::String& _fontName) { void init(const etk::Uri& _uri) {
gale::Resource::init(_fontName); gale::Resource::init(_uri);
}; };
virtual ~FontBase() { }; virtual ~FontBase() { };

View File

@ -7,7 +7,7 @@
#include <ewol/ewol.hpp> #include <ewol/ewol.hpp>
#include <ewol/widget/Composer.hpp> #include <ewol/widget/Composer.hpp>
#include <etk/os/FSNode.hpp> #include <etk/uri/uri.hpp>
#include <ewol/widget/Manager.hpp> #include <ewol/widget/Manager.hpp>
#include <ewol/context/Context.hpp> #include <ewol/context/Context.hpp>
#include <etk/typeInfo.hpp> #include <etk/typeInfo.hpp>
@ -20,8 +20,12 @@ ewol::widget::Composer::Composer() :
// nothing to do ... // nothing to do ...
} }
ewol::WidgetShared ewol::widget::composerGenerateFile(const etk::String& _fileName, uint64_t _id) { ewol::WidgetShared ewol::widget::composerGenerateFile(const etk::Uri& _uri, uint64_t _id) {
etk::String tmpData = etk::FSNodeReadAllData(_fileName); etk::String tmpData;
if (etk::uri::readAll(_uri, tmpData) == false) {
EWOL_ERROR("Can not read the file: " << _uri);
return null;
}
return ewol::widget::composerGenerateString(tmpData, _id); return ewol::widget::composerGenerateString(tmpData, _id);
} }
@ -74,8 +78,12 @@ ewol::widget::Composer::~Composer() {
} }
bool ewol::widget::Composer::loadFromFile(const etk::String& _fileName, uint64_t _id) { bool ewol::widget::Composer::loadFromFile(const etk::Uri& _uri, uint64_t _id) {
etk::String tmpData = etk::FSNodeReadAllData(_fileName); etk::String tmpData;
if (etk::uri::readAll(_uri, tmpData) == false) {
EWOL_ERROR("Can not read the file: " << _uri);
return false;
}
return loadFromString(tmpData, _id); return loadFromString(tmpData, _id);
} }

View File

@ -8,6 +8,7 @@
#include <etk/types.hpp> #include <etk/types.hpp>
#include <ewol/debug.hpp> #include <ewol/debug.hpp>
#include <ewol/widget/Container.hpp> #include <ewol/widget/Container.hpp>
#include <etk/uri/uri.hpp>
namespace ewol { namespace ewol {
namespace widget { namespace widget {
@ -21,7 +22,7 @@ namespace ewol {
class Composer : public ewol::widget::Container { class Composer : public ewol::widget::Container {
public: public:
eproperty::Value<bool> propertyRemoveIfUnderRemove; //!< Remove the composer if sub element request a remove eproperty::Value<bool> propertyRemoveIfUnderRemove; //!< Remove the composer if sub element request a remove
eproperty::Value<etk::String> propertySubFile; //!< If loading a sub-file, we must do it here ==> permit to con,figure it in the xml and not have wrong display eproperty::Value<etk::Uri> propertySubFile; //!< If loading a sub-file, we must do it here ==> permit to configure it in the xml and not have wrong display
protected: protected:
/** /**
* @brief Constructor * @brief Constructor
@ -35,12 +36,12 @@ namespace ewol {
virtual ~Composer(); virtual ~Composer();
/** /**
* @brief load a composition with a file * @brief load a composition with a file
* @param[in] _fileName Name of the file * @param[in] _uri Name of the file
* @param[in] _id Unique ID that is used in replacing the balise "{ID}" inside the File (do nothing if == 0) * @param[in] _id Unique ID that is used in replacing the balise "{ID}" inside the File (do nothing if == 0)
* @return true == > all done OK * @return true == > all done OK
* @return false == > some error occured * @return false == > some error occured
*/ */
bool loadFromFile(const etk::String& _fileName, uint64_t _id=0); bool loadFromFile(const etk::Uri& _uri, uint64_t _id=0);
/** /**
* @brief load a composition with a file * @brief load a composition with a file
* @param[in] _composerXmlString xml to parse directly * @param[in] _composerXmlString xml to parse directly
@ -57,6 +58,6 @@ namespace ewol {
virtual void onChangePropertySubFile(); virtual void onChangePropertySubFile();
}; };
ewol::WidgetShared composerGenerateString(const etk::String& _data = "", uint64_t _id=0); ewol::WidgetShared composerGenerateString(const etk::String& _data = "", uint64_t _id=0);
ewol::WidgetShared composerGenerateFile(const etk::String& _data = "", uint64_t _id=0); ewol::WidgetShared composerGenerateFile(const etk::Uri& _uri = "", uint64_t _id=0);
}; };
}; };

View File

@ -6,7 +6,7 @@
#include <ewol/widget/ListFileSystem.hpp> #include <ewol/widget/ListFileSystem.hpp>
#include <etk/tool.hpp> #include <etk/tool.hpp>
#include <etk/os/FSNode.hpp> #include <etk/path/fileSystem.hpp>
#include <etk/typeInfo.hpp> #include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ewol::widget::ListFileSystem); ETK_DECLARE_TYPE(ewol::widget::ListFileSystem);
@ -17,11 +17,11 @@ ewol::widget::ListFileSystem::ListFileSystem() :
signalFolderSelect(this, "folder-select", ""), signalFolderSelect(this, "folder-select", ""),
signalFolderValidate(this, "folder-validate", ""), signalFolderValidate(this, "folder-validate", ""),
propertyPath(this, "path", propertyPath(this, "path",
"/", etk::Path("/"),
"Path to display", "Path to display",
&ewol::widget::ListFileSystem::onChangePropertyPath), &ewol::widget::ListFileSystem::onChangePropertyPath),
propertyFile(this, "select", propertyFile(this, "select",
"", etk::Path(),
"selection af a specific file", "selection af a specific file",
&ewol::widget::ListFileSystem::onChangePropertyFile), &ewol::widget::ListFileSystem::onChangePropertyFile),
propertyShowFile(this, "show-file", propertyShowFile(this, "show-file",
@ -60,12 +60,7 @@ ewol::widget::ListFileSystem::~ListFileSystem() {
} }
void ewol::widget::ListFileSystem::clearList() { void ewol::widget::ListFileSystem::clearList() {
for (auto &it : m_list) { m_list.clear();
if (it != null) {
ETK_DELETE(etk::FSNode, it);
it = null;
}
}
} }
etk::Color<> ewol::widget::ListFileSystem::getBasicBG() { etk::Color<> ewol::widget::ListFileSystem::getBasicBG() {
@ -78,35 +73,39 @@ void ewol::widget::ListFileSystem::regenerateView() {
m_selectedLine = -1; m_selectedLine = -1;
m_list.clear(); m_list.clear();
m_originScrooled.setValue(0,0); m_originScrooled.setValue(0,0);
etk::FSNode tmpFolder(*propertyPath); uint32_t flags = 0;
// get the list: if (*propertyShowHidden == true) {
m_list = tmpFolder.folderGetSubList(*propertyShowHidden, *propertyShowFolder, *propertyShowFile, *propertyFilter); flags |= etk::path::LIST_HIDDEN;
}
if (*propertyShowFolder == true) {
flags |= etk::path::LIST_FOLDER;
}
if (*propertyShowFile == true) {
flags |= etk::path::LIST_FILE;
}
m_list = etk::path::list(*propertyPath, flags);
// request a redraw ... // request a redraw ...
markToRedraw(); markToRedraw();
} }
etk::String ewol::widget::ListFileSystem::getSelect() const { etk::Path ewol::widget::ListFileSystem::getSelect() const {
etk::String tmpVal = ""; etk::String tmpVal = "";
if (m_selectedLine >= 0) { if (m_selectedLine >= 0) {
if (m_list[m_selectedLine] != null) { tmpVal = m_list[m_selectedLine].getFileName();
tmpVal = m_list[m_selectedLine]->getNameFile();
}
} }
return tmpVal; return tmpVal;
} }
// select the specific file // select the specific file
void ewol::widget::ListFileSystem::setSelect(const etk::String& _data) { void ewol::widget::ListFileSystem::setSelect(const etk::Path& _data) {
// remove selected line // remove selected line
m_selectedLine = -1; m_selectedLine = -1;
// search the coresponding file : // search the coresponding file :
for (size_t iii=0; iii<m_list.size(); ++iii) { for (size_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii] != null) { if (m_list[iii] == _data) {
if (m_list[iii]->getNameFile() == _data) { // we find the line :
// we find the line : m_selectedLine = iii;
m_selectedLine = iii; break;
break;
}
} }
} }
markToRedraw(); markToRedraw();
@ -143,10 +142,9 @@ fluorine::Variant ewol::widget::ListFileSystem::getData(int32_t _role, const ive
} }
} }
if( _pos.y()-offset >= 0 if( _pos.y()-offset >= 0
&& _pos.y()-offset < (int32_t)m_list.size() && _pos.y()-offset < (int32_t)m_list.size()) {
&& m_list[_pos.y()-offset] != null) { EWOL_VERBOSE("get filename for : '" << m_list[_pos.y()-offset] << ":'" << m_list[_pos.y()-offset].getFileName() << "'");
EWOL_VERBOSE("get filename for : '" << *m_list[_pos.y()-offset] << ":'" << m_list[_pos.y()-offset]->getNameFile() << "'"); return m_list[_pos.y()-offset].getFileName();
return m_list[_pos.y()-offset]->getNameFile();
} }
} }
return "<<<ERROR>>>"; return "<<<ERROR>>>";
@ -194,19 +192,12 @@ bool ewol::widget::ListFileSystem::onItemEvent(const ewol::event::Input& _event,
// ".." folder // ".." folder
signalFolderSelect.emit(".."); signalFolderSelect.emit("..");
} else if( m_selectedLine-offset >= 0 } else if( m_selectedLine-offset >= 0
&& m_selectedLine-offset < (int32_t)m_list.size() && m_selectedLine-offset < (int32_t)m_list.size() ) {
&& null != m_list[m_selectedLine-offset] ) {
// generate event extern : // generate event extern :
switch(m_list[m_selectedLine-offset]->getNodeType()) { if(etk::path::isDirectory(m_list[m_selectedLine-offset])) {
case etk::typeNode_file : signalFolderSelect.emit(m_list[m_selectedLine-offset].getFileName());
signalFileSelect.emit(m_list[m_selectedLine-offset]->getNameFile()); } else {
break; signalFileSelect.emit(m_list[m_selectedLine-offset].getFileName());
case etk::typeNode_folder :
signalFolderSelect.emit(m_list[m_selectedLine-offset]->getNameFile());
break;
default:
EWOL_ERROR("Can not generate event on an unknow type");
break;
} }
} }
} else { } else {
@ -219,18 +210,11 @@ bool ewol::widget::ListFileSystem::onItemEvent(const ewol::event::Input& _event,
// ".." folder // ".." folder
signalFolderValidate.emit(".."); signalFolderValidate.emit("..");
} else if( m_selectedLine-offset >= 0 } else if( m_selectedLine-offset >= 0
&& m_selectedLine-offset < (int32_t)m_list.size() && m_selectedLine-offset < (int32_t)m_list.size()) {
&& null != m_list[m_selectedLine-offset] ) { if(etk::path::isDirectory(m_list[m_selectedLine-offset])) {
switch(m_list[m_selectedLine-offset]->getNodeType()) { signalFolderSelect.emit(m_list[m_selectedLine-offset].getFileName());
case etk::typeNode_file : } else {
signalFileValidate.emit(m_list[m_selectedLine-offset]->getNameFile()); signalFileSelect.emit(m_list[m_selectedLine-offset].getFileName());
break;
case etk::typeNode_folder :
signalFolderValidate.emit(m_list[m_selectedLine-offset]->getNameFile());
break;
default:
EWOL_ERROR("Can not generate event on an unknow type");
break;
} }
} }
} }

View File

@ -6,7 +6,6 @@
#pragma once #pragma once
#include <ewol/widget/List.hpp> #include <ewol/widget/List.hpp>
#include <etk/os/FSNode.hpp>
#include <ewol/resource/ColorFile.hpp> #include <ewol/resource/ColorFile.hpp>
#include <esignal/Signal.hpp> #include <esignal/Signal.hpp>
@ -20,13 +19,13 @@ namespace ewol {
*/ */
class ListFileSystem : public ewol::widget::List { class ListFileSystem : public ewol::widget::List {
public: // signals public: // signals
esignal::Signal<etk::String> signalFileSelect; //!< @event "file-select" Generated when a file is selected. esignal::Signal<etk::Path> signalFileSelect; //!< @event "file-select" Generated when a file is selected.
esignal::Signal<etk::String> signalFileValidate; //!< @event "file-validate" Generate when the user validate (return) or double click on the element esignal::Signal<etk::Path> signalFileValidate; //!< @event "file-validate" Generate when the user validate (return) or double click on the element
esignal::Signal<etk::String> signalFolderSelect; esignal::Signal<etk::Path> signalFolderSelect;
esignal::Signal<etk::String> signalFolderValidate; esignal::Signal<etk::Path> signalFolderValidate;
public: // properties public: // properties
eproperty::Value<etk::String> propertyPath; //!< Current folder that display point on. eproperty::Value<etk::Path> propertyPath; //!< Current folder that display point on.
eproperty::Value<etk::String> propertyFile; //!< current selected file eproperty::Value<etk::Path> propertyFile; //!< current selected file
eproperty::Value<bool> propertyShowFile; //!< Show files elements eproperty::Value<bool> propertyShowFile; //!< Show files elements
eproperty::Value<bool> propertyShowFolder; //!< Display the folders elements eproperty::Value<bool> propertyShowFolder; //!< Display the folders elements
eproperty::Value<bool> propertyShowHidden; //!< Display hidden elements eproperty::Value<bool> propertyShowHidden; //!< Display hidden elements
@ -48,8 +47,7 @@ namespace ewol {
fluorine::Variant getData(int32_t _role, const ivec2& _pos) override; fluorine::Variant getData(int32_t _role, const ivec2& _pos) override;
bool onItemEvent(const ewol::event::Input& _event, const ivec2& _pos, const vec2& _mousePosition) override; bool onItemEvent(const ewol::event::Input& _event, const ivec2& _pos, const vec2& _mousePosition) override;
protected: protected:
// TODO: use shred_ptr etk::Vector<etk::Path> m_list; //!< List of all element in the path. (they are filtered)
etk::Vector<etk::FSNode *> m_list; //!< List of all element in the path. (they are filtered)
/** /**
* @brief Clean the list of element. * @brief Clean the list of element.
*/ */
@ -65,12 +63,12 @@ namespace ewol {
* @brief Select a specific file in the path * @brief Select a specific file in the path
* @param[in] _data File to selested. * @param[in] _data File to selested.
*/ */
virtual void setSelect(const etk::String& _data); virtual void setSelect(const etk::Path& _data);
/** /**
* @brief Get the current selected file/folder/... in the list * @brief Get the current selected file/folder/... in the list
* @return the String of the element selected. * @return the String of the element selected.
*/ */
etk::String getSelect() const ; etk::Path getSelect() const ;
protected: protected:
virtual void onChangePropertyPath(); virtual void onChangePropertyPath();
virtual void onChangePropertyFile(); virtual void onChangePropertyFile();