[DEV] Rework compleately EWOL to simplify and set it more user-frendly NO-MORE-COMPILE

This commit is contained in:
Edouard DUPIN 2012-11-21 21:56:37 +01:00
parent c3dde8d2ac
commit 15c71ebe1a
85 changed files with 537 additions and 3840 deletions

2
external/etk vendored

@ -1 +1 @@
Subproject commit 5145f629a8758ddd5025857e6333a5a0e21d68cc
Subproject commit a8cafb5969640bd14ed9ba0dd3dfa718124e2101

View File

@ -0,0 +1,37 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_COMMAND_LINE_H__
#define __EWOL_COMMAND_LINE_H__
namespace ewol
{
namespace commandLine {
/**
* @brief Remove all the element bufferised in the commandLine system
*/
void Clean(void);
/**
* @brief Get the number of element in the Command Line
* @return the number of element
*/
int32_t Size(void);
/**
* @brief Get an element with a specific ID
* @return The cmdLine Id element
*/
etk::UString Get(int32_t id);
/**
* @brief Add one element at the Command Line
* @param[in] newElement String in the input that might be added.
*/
void Add(etk::UString& newElement);
};
};
#endif

View File

@ -1,24 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_CURSOR_H__
#define __EWOL_CURSOR_H__
namespace ewol
{
class Cursor : public ewol::Compositing
{
protected:
public:
};
};
#endif

52
sources/ewol/config.cpp Normal file
View File

@ -0,0 +1,52 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/config.h>
#undef __class__
#define __class__ "ewol::config"
static etk::UString l_fontConfigFolder = "DATA::fonts";
static etk::UString l_fontConfigName = "Arial";
static int32_t l_fontConfigSize = 10;
void ewol::config_PRIVATE::Init(void)
{
// reset font properties
l_fontConfigFolder = "DATA::fonts";
l_fontConfigName = "Arial";
l_fontConfigSize = 10;
ewol::FreeTypeInit();
}
void ewol::config_PRIVATE::UnInit(void)
{
// UnInit FreeTypes
ewol::FreeTypeUnInit();
}
void ewol::config::FontFolder(etk::UString folder)
{
l_fontConfigFolder = folder;
}
void ewol::config::FontSetDefault(etk::UString fontName, int32_t size)
{
l_fontConfigName = fontName;
l_fontConfigSize = size;
}
etk::UString& ewol::config::FontGetDefaultName(void)
{
return l_fontConfigName;
}
int32_t ewol::config::FontGetDefaultSize(void)
{
return l_fontConfigSize;
}

52
sources/ewol/config.h Normal file
View File

@ -0,0 +1,52 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_CONFIG_H__
#define __EWOL_CONFIG_H__
namespace ewol
{
namespace config
{
/**
* @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)
*/
void FontFolder(etk::UString folder);
/**
* @brief Set the defaut font for all the widgets and basics display.
* @param[in] fontName The font name requested (not case sensitive) ex "Arial".
* @param[in] size The default size of the font default=10.
*/
void FontSetDefault(etk::UString fontName, int32_t size);
/**
* @brief Get the current default font name
* @raturn a reference on the font name string
*/
etk::UString& FontGetDefaultName(void);
/**
* @brief Get the default font size.
* @return the font size.
*/
int32_t FontGetDefaultSize(void);
};
namespace config_PRIVATE
{
/**
* Init the configuration
*/
void Init(void);
/**
* UnInit the configuration
*/
void UnInit(void);
};
};
#endif

View File

@ -15,6 +15,16 @@
#undef __class__
#define __class__ "ewol"
int32_t ewol::Run(int32_t argc, const char* argv[]);
{
// call standard RUN ...
}
void ewol::DisplayWindows(ewol::Windows * windows)
{
// Remove current Focus :
@ -197,3 +207,9 @@ int64_t ewol::GetTime(void)
{
return guiInterface::GetTime();
}

View File

@ -14,49 +14,74 @@
#include <ewol/widget/Widget.h>
#include <ewol/widget/Windows.h>
#if 1
namespace ewol {
namespace ewol
{
/**
* @brief This is the only one things the User might done in his main();
* @note To answare you before you ask the question, this is really simple:
* Due to the fect that the current system is multiple-platform, you "main"
* Does not exist in the android platform, then ewol call other start
* and stop function, to permit to have only one code
* @note The main can not be in the ewol, due to the fact thet is an librairy
* @param[in] argc Standard argc
* @param[in] argv Standard argv
* @return normal error int for the application error management
*/
int32_t Run(int32_t argc, const char* argv[]);
/**
* @brief Request the stop of the program (teminate all the process) no more call at hte application without APP_UnInit();
*/
void Stop(void);
void DisplayWindows(ewol::Windows * windows);
// only on computer
void ChangeSize(etk::Vector2D<int32_t> size);
void ChangePos(etk::Vector2D<int32_t> pos);
void GetAbsPos(etk::Vector2D<int32_t>& pos);
void KeyboardShow(void);
void KeyboardHide(void);
/**
* @brief Set a windows to diaplay
* @param[in] windows The requested windows that migt be use for the display
*/
void WindowsSet(ewol::Windows * windows);
/**
* @brief Add a PopUp at the current windows ==> this widget is display over the current element
* @param[in] tmpWidget A pointer on the pop-up widget that might be displayed
*/
void WindowsPopUpAdd(ewol::Widget * tmpWidget);
/**
* @brief Change the windows size
* @note work only on computer
* @param[in] size The new windows size
*/
void ChangeSize(etkVector2D<int32_t> size);
/**
* @brief Change the windows curent position
* @note work only on computer
* @param[in] pos The new windows position
*/
void ChangePos(etkVector2D<int32_t> pos);
/**
* @brief Generate the action of redrawing all the display.
*/
void ForceRedrawAll(void);
void PopUpWidgetPush(ewol::Widget * tmpWidget);
namespace CmdLine {
void Clean(void);
int32_t Nb(void);
etk::UString Get(int32_t id);
void Add(etk::UString& newElement);
};
// TODO : This might be deprecated ...
bool IsSetCapsLock(void);
bool IsSetShift(void);
bool IsSetCtrl(void);
bool IsSetMeta(void);
bool IsSetAlt(void);
bool IsSetAltGr(void);
bool IsSetVerNum(void);
bool IsSetInsert(void);
// basic shortcut setting (set default value, the configutration file will overloaded it automaticly
namespace shortCut {
void Add(bool shift, bool control, bool alt, bool meta, uniChar_t unicodeValue, const char * generateEventId, etk::UString data);
void Add(const char * descriptiveString, const char * generateEventId, etk::UString data);
};
// TODO : This is dangerous and might be deprecated ... Soon
int32_t GetCurrentWidth(void);
int32_t GetCurrentHeight(void);
void SetTitle(etk::UString title);
/**
* @brief Force the calculation of all the size of the widgets
*/
void RequestUpdateSize(void);
/**
* @brief Change the status of the Keyboard displat
* @note Specific for mobile platform
* @param[in] hide Status of the visibility of the keyboard
*/
void Keyboard(bool hide);
/**
* @brief Change the title display.
* @param[in] title the new title that might be displayed
*/
void SetTitle(etk::UString title);
/**
* @brief Get EWOL version
* @return The string that describe ewol version
*/
etk::UString GetVersion(void);
// get current time in ms...
/**
* @brief Get current time in us...
* @return The current time
*/
int64_t GetTime(void);
/**
* @brief This is to transfert the event from one widget to another one
@ -70,49 +95,12 @@ namespace ewol {
SCREEN_ORIENTATION_LANDSCAPE,
SCREEN_ORIENTATION_PORTRAIT,
} orientation_te;
/**
* @brief
* @param[in]
*/
void ForceOrientation(ewol::orientation_te orientation);
};
#else
namespace ewol {
// stop the program :
void Stop(void);
// display a specific windows
void WindowsSet(ewol::Windows * windows);
void WindowsPopUpAdd(ewol::Widget * tmpWidget);
// only on computer
// change the windows size
void ChangeSize(int32_t w, int32_t h);
// change the windows curent position
void ChangePos(int32_t x, int32_t y);
// force the redraw of all the widget (this was a bad case ...
void ForceRedrawAll(void);
// force the calculation of all the sizes
void RequestUpdateSize(void);
// get the cmd line for computer call
etk::Vector<etk::UString> CmdLineGet(void);
// get the special key properties
enum {
EWOL_KEY_LEFT = 1 << 0,
EWOL_KEY_RIGHT = 1 << 1,
EWOL_KEY_CAP_LOCK = 1 << 2,
EWOL_KEY_SHIFT = 1 << 3,
EWOL_KEY_CTRL = 1 << 4,
EWOL_KEY_META = 1 << 5,
EWOL_KEY_ALT = 1 << 6,
EWOL_KEY_ALT_GR = 1 << 7,
EWOL_KEY_VER_NUM = 1 << 8,
EWOL_KEY_INSERT = 1 << 9,
};
int32_t KeyboardGetStatus(void);
// set the vew title
void SetTitle(etk::UString title);
// get EWOL version
etk::UString GetVersion(void);
// get current time in ms...
int64_t GetTime(void);
};
#endif
#endif

View File

@ -1,464 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <etk/Types.h>
#include <ewol/font/Font.h>
#include <ewol/font/DistantFieldFont.h>
#include <ewol/font/FontManager.h>
#include <ewol/ResourceManager.h>
static int32_t nextP2(int32_t value)
{
int32_t val=1;
for (int32_t iii=1; iii<31; iii++) {
if (value <= val) {
return val;
}
val *=2;
}
EWOL_CRITICAL("impossible CASE....");
return val;
}
static int32_t simpleSQRT(int32_t value)
{
int32_t val=1;
for (int32_t iii=1; iii<1000; iii++) {
val =iii*iii;
if (value <= val) {
return iii;
}
}
EWOL_CRITICAL("impossible CASE....");
return val;
}
#define SPECIAL_BORDER (5)
#define SPECIAL_UPSCALER (8)
ewol::DistantFieldFont::DistantFieldFont(etk::UString fontName) :
ewol::Texture(fontName),
m_font(NULL),
m_lastGlyphPos(0,0),
m_lastRawHeigh(0)
{
int32_t tmpSize = 0;
// extarct name and size :
char * tmpData = fontName.c_str();
char * tmpPos = strchr(tmpData, ':');
if (tmpPos==NULL) {
m_size = 1;
EWOL_CRITICAL("Can not parse the font name : \"" << fontName << "\" ??? ':' " );
return;
} else {
if (sscanf(tmpPos+1, "%d", &tmpSize)!=1) {
m_size = 1;
EWOL_CRITICAL("Can not parse the font name : \"" << fontName << "\" ==> size ???");
return;
}
}
m_name = fontName.Extract(0, (tmpPos - tmpData));
m_size = tmpSize;
//EWOL_CRITICAL("Load FONT name : \"" << m_name << "\" ==> size=" << m_size);
ewol::resource::Keep(m_name, m_font);
if (NULL == m_font) {
return;
}
// set the bassic charset:
m_listElement.Clear();
freeTypeFontElement_ts tmpchar1;
tmpchar1.property.m_UVal = 0;
m_listElement.PushBack(tmpchar1);
for (int32_t iii=0x20/*'A'*/; iii</*'Z'*/0xFF; iii++) {
freeTypeFontElement_ts tmpchar;
tmpchar.property.m_UVal = iii;
m_listElement.PushBack(tmpchar);
if (0x7F == iii) {
iii = 0x9F;
}
}
/* this is a bad code for now ... */
// ==> determine the texture Size
GlyphProperty tmpproperty;
tmpproperty.m_UVal = 'A';
m_font->GetGlyphProperty(m_size, tmpproperty);
int32_t nbElement = 0xFF - 0x20 + 1;
int32_t coter = simpleSQRT(nbElement);
// note : +1 is for the overlapping of the glyph (Part 1)
int32_t glyphMaxWidth = tmpproperty.m_advance.x +1 + SPECIAL_BORDER*2;
int32_t glyphMaxHeight = tmpproperty.m_advance.y +1 + SPECIAL_BORDER*2;
int32_t textureWidth = nextP2(coter*glyphMaxWidth);
int32_t nbRaws = textureWidth / glyphMaxWidth;
if (nbRaws <= 0) {
EWOL_ERROR("devide by 0");
nbRaws = 1;
}
int32_t nbLine = (nbElement / nbRaws) + 1;
int32_t textureHeight = nextP2(nbLine*glyphMaxHeight);
// for android :
textureHeight = etk_max(textureHeight, textureWidth);
textureWidth = textureHeight;
EWOL_DEBUG("Generate a text texture for char(" << nbRaws << "," << nbLine << ") with size=(" << textureWidth << "," << textureHeight << ")");
// resize must be done on the texture ...
SetImageSize(etk::Vector2D<int32_t>(textureWidth,textureHeight));
// now we can acces directly on the image
m_data.SetFillColor(draw::Color(0xFFFFFF00));
m_data.Clear();
m_height = m_font->GetHeight(m_size);
draw::Image tmpUpScaledImage(etk::Vector2D<int32_t>(1024,1024));
int32_t CurrentLineHigh = 0;
etk::Vector2D<int32_t> glyphPosition(1,1);
for (int32_t iii=0; iii<m_listElement.Size(); iii++) {
if (true == m_font->GetGlyphProperty(m_size, m_listElement[iii].property)) {
EWOL_DEBUG("Generate Font Element : '" << m_listElement[iii].property.m_UVal << "'= '" << (char)m_listElement[iii].property.m_UVal << "'");
// clean the temporary image :
tmpUpScaledImage.SetFillColor(draw::Color(0xFFFFFF00));
tmpUpScaledImage.Clear();
/*
// check internal property:
// enought in the texture :
//if (m_data.GetWidth() < m_lastGlyphPos.x + m_listElement[iii].property.m_sizeTexture.x
// resize if needed ...
// line size :
// draw
// move the curent pointer of drawing:
*/
// change line if needed ...
if (glyphPosition.x+m_listElement[iii].property.m_sizeTexture.x > textureWidth) {
glyphPosition.x = 0;
glyphPosition.y += CurrentLineHigh;
CurrentLineHigh = 0;
}
// draw the glyph
m_font->DrawGlyph(tmpUpScaledImage, m_size*SPECIAL_UPSCALER, etk::Vector2D<int32_t>(SPECIAL_BORDER*SPECIAL_UPSCALER,SPECIAL_BORDER*SPECIAL_UPSCALER), m_listElement[iii].property, 0);
// set video position
m_listElement[iii].posStart.u = (float)(glyphPosition.x) / (float)textureWidth;
m_listElement[iii].posStart.v = (float)(glyphPosition.y) / (float)textureHeight;
m_listElement[iii].posStop.u = (float)(glyphPosition.x + m_listElement[iii].property.m_sizeTexture.x+2*SPECIAL_BORDER) / (float)textureWidth;
m_listElement[iii].posStop.v = (float)(glyphPosition.y + m_listElement[iii].property.m_sizeTexture.y+2*SPECIAL_BORDER) / (float)textureHeight;
/*
EWOL_DEBUG("generate '" << (char)m_listElement[iii].property.m_UVal << "'");
EWOL_DEBUG(" in tex : " << glyphPosition << " ==> " << m_listElement[iii].posStart.u<< "," << m_listElement[iii].posStart.v );
EWOL_DEBUG(" m_sizeTexture =" << m_listElement[iii].property.m_sizeTexture );
EWOL_DEBUG(" m_bearing =" << m_listElement[iii].property.m_bearing );
EWOL_DEBUG(" m_advance =" << m_listElement[iii].property.m_advance );
*/
// generate the distance field from this element ...
tmpUpScaledImage.DistanceField(etk::Vector2D<int32_t>(0,0), m_listElement[iii].property.m_sizeTexture*etk::Vector2D<int32_t>(SPECIAL_UPSCALER,SPECIAL_UPSCALER)+etk::Vector2D<int32_t>(2*SPECIAL_BORDER*SPECIAL_UPSCALER,2*SPECIAL_BORDER*SPECIAL_UPSCALER), SPECIAL_UPSCALER, SPECIAL_UPSCALER/2);
// copy data with downscaling : (subSampling)
etk::Vector2D<int32_t> tmpPos(0,0);
for (tmpPos.y = 0; tmpPos.y<m_listElement[iii].property.m_sizeTexture.y+2*SPECIAL_BORDER; tmpPos.y++) {
for (tmpPos.x = 0; tmpPos.x<m_listElement[iii].property.m_sizeTexture.x+2*SPECIAL_BORDER; tmpPos.x++) {
m_data.Set(glyphPosition + tmpPos, tmpUpScaledImage.Get(tmpPos*etk::Vector2D<int32_t>(SPECIAL_UPSCALER,SPECIAL_UPSCALER) + etk::Vector2D<int32_t>(SPECIAL_UPSCALER/2,SPECIAL_UPSCALER/2)) );
}
}
// update the maximum of the line hight :
if (CurrentLineHigh<m_listElement[iii].property.m_sizeTexture.y+1+2*SPECIAL_BORDER) {
// note : +1 is for the overlapping of the glyph (Part 2)
CurrentLineHigh = m_listElement[iii].property.m_sizeTexture.y+1 + 2*SPECIAL_BORDER;
}
// note : +1 is for the overlapping of the glyph (Part 3)
// update the Bitmap position drawing :
glyphPosition.x += m_listElement[iii].property.m_sizeTexture.x+1 + 2*SPECIAL_BORDER;
}
}
// For testing cheree the box are set)
#if 0
draw::Color tlpppp(0xFF,0xFF,0xFF,0x00);
for(int32_t jjj=0; jjj < textureHeight;jjj++) {
for(int32_t iii=0; iii < textureWidth; iii++){
tlpppp = m_data.Get(etk::Vector2D<int32_t>(iii, jjj) );
// set only alpha :
tlpppp.a = etk_min( tlpppp.a+0x60, 0xFF);
// real set of color
m_data.Set(etk::Vector2D<int32_t>(iii, jjj), tlpppp );
}
}
#endif
EWOL_DEBUG("End generation of the Fond bitmap, start adding texture");
Flush();
}
ewol::DistantFieldFont::~DistantFieldFont(void)
{
if (NULL!= m_font) {
ewol::resource::Release(m_font);
}
}
bool ewol::DistantFieldFont::HasName(etk::UString& fileName)
{
etk::UString tmpName = m_name;
tmpName += ":";
tmpName += m_size;
EWOL_VERBOSE("S : check : " << fileName << " ?= " << tmpName << " = " << (fileName==tmpName) );
return (fileName==tmpName);
}
int32_t ewol::DistantFieldFont::Draw(etk::Vector2D<float> textPos,
const etk::UString& unicodeString,
etk::Vector<etk::Vector2D<float> > & coord,
etk::Vector<texCoord_ts> & coordTex)
{
float totalSize = 0;
etk::Vector2D<float> tmpPos = textPos;
for(int32_t iii=0; iii<unicodeString.Size(); iii++) {
int32_t ret = Draw(tmpPos, unicodeString[iii], coord, coordTex);
tmpPos.x += ret;
totalSize += ret;
}
#if 0
// To display the texture ...
{
/* Bitmap position
* 0------1
* | |
* | |
* 3------2
*/
etk::Vector2D<float> bitmapDrawPos[4];
bitmapDrawPos[0].x = 10;
bitmapDrawPos[1].x = 400;
bitmapDrawPos[2].x = 400;
bitmapDrawPos[3].x = 10;
bitmapDrawPos[0].y = 400;
bitmapDrawPos[1].y = 400;
bitmapDrawPos[2].y = 10;
bitmapDrawPos[3].y = 10;
/* texture Position :
* 0------1
* | |
* | |
* 3------2
*/
texCoord_ts texturePos[4];
texturePos[0].u = 0;
texturePos[1].u = 1;
texturePos[2].u = 1;
texturePos[3].u = 0;
texturePos[0].v = 0;
texturePos[1].v = 0;
texturePos[2].v = 1;
texturePos[3].v = 1;
// NOTE : Android does not support the Quads elements ...
/* Step 1 :
* ********
* ******
* ****
* **
*
*/
// set texture coordonates :
coordTex.PushBack(texturePos[0]);
coordTex.PushBack(texturePos[1]);
coordTex.PushBack(texturePos[2]);
// set display positions :
coord.PushBack(bitmapDrawPos[0]);
coord.PushBack(bitmapDrawPos[1]);
coord.PushBack(bitmapDrawPos[2]);
/* Step 2 :
*
* **
* ****
* ******
* ********
*/
// set texture coordonates :
coordTex.PushBack(texturePos[0]);
coordTex.PushBack(texturePos[2]);
coordTex.PushBack(texturePos[3]);
// set display positions :
coord.PushBack(bitmapDrawPos[0]);
coord.PushBack(bitmapDrawPos[2]);
coord.PushBack(bitmapDrawPos[3]);
}
#endif
return totalSize;
}
int32_t ewol::DistantFieldFont::Draw(etk::Vector2D<float> textPos,
const uniChar_t unicodeChar,
etk::Vector<etk::Vector2D<float> > & coord,
etk::Vector<texCoord_ts> & coordTex)
{
float posDrawX = textPos.x;
int32_t charIndex;
if (unicodeChar < 0x20) {
charIndex = 0;
} else if (unicodeChar < 0x80) {
charIndex = unicodeChar - 0x1F;
} else {
charIndex = 0;
for (int32_t iii=0x80-0x20; iii < m_listElement.Size(); iii++) {
if (m_listElement[iii].property.m_UVal == unicodeChar) {
charIndex = iii;
break;
}
}
}
// 0x01 == 0x20 == ' ';
if (unicodeChar != 0x01) {
/* Bitmap position
* xA xB
* yC *------*
* | |
* | |
* yD *------*
*/
float dxA = -SPECIAL_BORDER + posDrawX + m_listElement[charIndex].property.m_bearing.x;
float dxB = +SPECIAL_BORDER + posDrawX + m_listElement[charIndex].property.m_bearing.x + m_listElement[charIndex].property.m_sizeTexture.x;
float dyC = +SPECIAL_BORDER + textPos.y + m_listElement[charIndex].property.m_bearing.y + m_height - m_size;
float dyD = -SPECIAL_BORDER + dyC - m_listElement[charIndex].property.m_sizeTexture.y;
float tuA = m_listElement[charIndex].posStart.u;
float tuB = m_listElement[charIndex].posStop.u;
float tvC = m_listElement[charIndex].posStart.v;
float tvD = m_listElement[charIndex].posStop.v;
// Clipping and drawing area
if( dxB <= dxA
|| dyD >= dyC) {
// nothing to do ...
} else {
/* Bitmap position
* 0------1
* | |
* | |
* 3------2
*/
etk::Vector2D<int32_t> bitmapDrawPos[4];
bitmapDrawPos[0].x = (int32_t)dxA;
bitmapDrawPos[1].x = (int32_t)dxB;
bitmapDrawPos[2].x = (int32_t)dxB;
bitmapDrawPos[3].x = (int32_t)dxA;
bitmapDrawPos[0].y = (int32_t)dyC;
bitmapDrawPos[1].y = (int32_t)dyC;
bitmapDrawPos[2].y = (int32_t)dyD;
bitmapDrawPos[3].y = (int32_t)dyD;
/* texture Position :
* 0------1
* | |
* | |
* 3------2
*/
texCoord_ts texturePos[4];
texturePos[0].u = tuA;
texturePos[1].u = tuB;
texturePos[2].u = tuB;
texturePos[3].u = tuA;
texturePos[0].v = tvC;
texturePos[1].v = tvC;
texturePos[2].v = tvD;
texturePos[3].v = tvD;
// NOTE : Android does not support the Quads elements ...
/* Step 1 :
* ********
* ******
* ****
* **
*
*/
// set texture coordonates :
coordTex.PushBack(texturePos[0]);
coordTex.PushBack(texturePos[1]);
coordTex.PushBack(texturePos[2]);
// set display positions :
coord.PushBack(bitmapDrawPos[0]);
coord.PushBack(bitmapDrawPos[1]);
coord.PushBack(bitmapDrawPos[2]);
/* Step 2 :
*
* **
* ****
* ******
* ********
*/
// set texture coordonates :
coordTex.PushBack(texturePos[0]);
coordTex.PushBack(texturePos[2]);
coordTex.PushBack(texturePos[3]);
// set display positions :
coord.PushBack(bitmapDrawPos[0]);
coord.PushBack(bitmapDrawPos[2]);
coord.PushBack(bitmapDrawPos[3]);
}
}
posDrawX += m_listElement[charIndex].property.m_advance.x;
int32_t sizeOut = posDrawX - textPos.x;
textPos.x = posDrawX;
return sizeOut;
}
etk::Vector2D<float> ewol::DistantFieldFont::GetSize(const etk::UString & unicodeString)
{
etk::Vector2D<float> outputSize(0,m_height);
for(int32_t iii=0; iii<unicodeString.Size(); iii++) {
etk::Vector2D<float> tmpp = GetSize(unicodeString[iii]);
outputSize.x += tmpp.x;
}
return outputSize;
}
etk::Vector2D<float> ewol::DistantFieldFont::GetSize(const uniChar_t unicodeChar)
{
etk::Vector2D<float> outputSize(0,m_height);
int32_t charIndex;
if (unicodeChar >= 0x80) {
charIndex = 0;
} else if (unicodeChar < 0x20) {
charIndex = 0;
} else if (unicodeChar < 0x80) {
charIndex = unicodeChar - 0x1F;
} else {
for (int32_t iii=0x80-0x20; iii < m_listElement.Size(); iii++) {
if (m_listElement[iii].property.m_UVal == unicodeChar) {
charIndex = iii;
break;
}
}
// TODO : Update if possible the mapping
charIndex = 0;
}
outputSize.x = m_listElement[charIndex].property.m_advance.x;
return outputSize;
}

View File

@ -1,58 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_DISTANT_FIELD_FONT_H__
#define __EWOL_DISTANT_FIELD_FONT_H__
#include <ewol/font/Font.h>
#include <ewol/texture/Texture.h>
#include <ewol/Resource.h>
namespace ewol
{
class DistantFieldFont : public ewol::Texture {
typedef struct {
GlyphProperty property;
texCoord_ts posStart;
texCoord_ts posStop;
}freeTypeFontElement_ts;
private:
int32_t m_size;
int32_t m_height;
ewol::Font* m_font;
etk::Vector<freeTypeFontElement_ts> m_listElement;
// for the texture generation :
etk::Vector2D<int32_t> m_lastGlyphPos;
int32_t m_lastRawHeigh;
public:
DistantFieldFont(etk::UString fontName);
~DistantFieldFont(void);
virtual bool HasName(etk::UString& fileName);
const char* GetType(void) { return "ewol::TexturedFont"; };
int32_t getFontSize(void) { return m_size; };
int32_t Draw(etk::Vector2D<float> textPos,
const etk::UString& unicodeString,
etk::Vector<etk::Vector2D<float> > & coord,
etk::Vector<texCoord_ts> & coordTex);
int32_t Draw(etk::Vector2D<float> textPos,
const uniChar_t unicodeChar,
etk::Vector<etk::Vector2D<float> > & coord,
etk::Vector<texCoord_ts> & coordTex);
etk::Vector2D<float> GetSize(const etk::UString & unicodeString);
etk::Vector2D<float> GetSize(const uniChar_t unicodeChar);
// TODO : Remove this element, it is stupid ...
int32_t GetHeight(void) { return m_height; };
int32_t GetFontSize(void) { return m_size; };
};
};
#endif

View File

@ -1,53 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <etk/Types.h>
#include <etk/Vector.h>
#include <ewol/Debug.h>
#include <ewol/font/FontManager.h>
#include <ewol/font/FontFreeType.h>
#include <ewol/font/TexturedFont.h>
static etk::UString l_defaultFontName = "";
static int32_t l_defaultFontSize = 10;
void ewol::font::Init(void)
{
l_defaultFontName = "";
l_defaultFontSize = 10;
// Specific for free Font
ewol::FreeTypeInit();
}
void ewol::font::UnInit(void)
{
// Specific for free Font
ewol::FreeTypeUnInit();
}
void ewol::font::SetDefaultFont(etk::UString fontName)
{
l_defaultFontName = fontName;
}
etk::UString& ewol::font::GetDefaultFont(void)
{
return l_defaultFontName;
}
void ewol::font::SetDefaultSize(int32_t newSize)
{
l_defaultFontSize = newSize;
}
int32_t ewol::font::GetDefaultSize(void)
{
return l_defaultFontSize;
}

View File

@ -1,29 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_FONT_MANAGER_H__
#define __EWOL_FONT_MANAGER_H__
#include <ewol/font/Font.h>
#include <ewol/font/TexturedFont.h>
#include <ewol/font/FontFreeType.h>
namespace ewol
{
namespace font {
void Init(void);
void UnInit(void);
void SetDefaultFont(etk::UString fontName);
etk::UString& GetDefaultFont(void);
void SetDefaultSize(int32_t newSize);
int32_t GetDefaultSize(void);
};
};
#endif

View File

@ -1,929 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/game/GameElementLua.h>
#include <etk/os/FSNode.h>
/*******************************************************************************
** Lua abstraction (START)
******************************************************************************* */
#include <lua/lua.hpp>
//For every acces :
static ewol::GameElementLua * tmpObj = NULL;
static etk::Vector<ewol::Sprite*> * tmpSprite = NULL;
static ewol::SceneElement * tmpScene = NULL;
template <typename T> int index(lua_State* L);
template <> int index<bool>(lua_State* L)
{
bool* ptr = (bool*)lua_touserdata(L, 1);
lua_pushboolean(L, *ptr ? 1 : 0);
return 1;
}
template <> int index<float>(lua_State* L)
{
float* ptr = (float*)lua_touserdata(L, 1);
lua_pushnumber(L, *ptr);
return 1;
}
template <typename T> int newindex(lua_State* L);
template <> int newindex<bool>(lua_State* L)
{
bool* ptr = (bool*)lua_touserdata(L, 1);
*ptr = lua_toboolean(L, 3)!=0;
return 0;
}
template <> int newindex<float>(lua_State* L)
{
float* ptr = (float*)lua_touserdata(L, 1);
if (!lua_isnumber(L, 3)) {
return luaL_error(L, "new value must be a number");
}
*ptr = (float)lua_tonumber(L, 3);
return 1;
}
template <typename T> class LuaValue
{
private:
lua_State* L;
etk::UString name;
T* ptr;
public:
LuaValue(lua_State* _L, etk::UString _name)
: L(_L), name(_name), ptr(0)
{
ptr = (T*)lua_newuserdata(L, sizeof(T));
*ptr = T();
lua_createtable(L, 0, 2);
lua_pushcfunction(L, index<T>);
lua_setfield(L, -2, "__index");
lua_pushcfunction(L, newindex<T>);
lua_setfield(L, -2, "__newindex");
lua_setmetatable(L, -2);
lua_setglobal(L, name.c_str());
}
virtual ~LuaValue(void)
{
lua_pushnil(L);
lua_setglobal(L, name.c_str());
ptr = 0;
L = 0;
}
LuaValue<T>& operator=(const T& value) { *ptr = value; return *this; }
operator T() { return *ptr; }
};
/*
template <> int lua_Set<float>(lua_State* L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
float value = luaL_checknumber(L, 1);
tmpObj->AngleSet(value);
// return number of parameters
return 1;
}
template <> int lua_Get<float>(lua_State* L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
float value = tmpObj->AngleGet();
lua_pushnumber(L, value );
// return number of parameters
return 1;
}
*/
LUAMOD_API int lua_GetPos(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, (lua_Number)0 );
lua_pushnumber(L, (lua_Number)0 );
return 2;
}
etk::Vector2D<float> tmpPos = tmpObj->PositionGet();
lua_pushnumber(L, (lua_Number)tmpPos.x );
lua_pushnumber(L, (lua_Number)tmpPos.y );
// return number of parameters
return 2;
}
LUAMOD_API int lua_SetPos(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
return 0;
}
float x = luaL_checknumber(L, 1);
float y = luaL_checknumber(L, 2);
etk::Vector2D<float> tmpPos;
tmpPos.x = x;
tmpPos.y = y;
tmpObj->PositionSet(tmpPos);
// return number of parameters
return 0;
}
LUAMOD_API int lua_GetSpeed(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, (lua_Number)0 );
return 1;
}
float tmpPos = tmpObj->SpeedGet();
lua_pushnumber(L, (lua_Number)tmpPos );
// return number of parameters
return 1;
}
LUAMOD_API int lua_SetSpeed(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
return 0;
}
float x = luaL_checknumber(L, 1);
tmpObj->SpeedSet(x);
// return number of parameters
return 0;
}
LUAMOD_API int lua_GetPower(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
float value = tmpObj->PowerGet();
lua_pushnumber(L, (lua_Number)value );
// return number of parameters
return 1;
}
LUAMOD_API int lua_SetPower(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
float value = luaL_checknumber(L, 1);
tmpObj->PowerSet(value);
// return number of parameters
return 1;
}
LUAMOD_API int lua_GetGroup(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
int32_t value = tmpObj->GroupGet();
lua_pushinteger(L, value );
// return number of parameters
return 1;
}
LUAMOD_API int lua_SetGroup(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
int32_t value = luaL_checkint(L, 1);
tmpObj->GroupSet(value);
// return number of parameters
return 1;
}
LUAMOD_API int lua_GetAngle(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
float value = tmpObj->AngleGet();
lua_pushnumber(L, value );
// return number of parameters
return 1;
}
LUAMOD_API int lua_SetAngle(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
float value = luaL_checknumber(L, 1);
tmpObj->AngleSet(value);
// return number of parameters
return 1;
}
LUAMOD_API int lua_GetSize(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 1;
}
float value = tmpObj->SizeGet();
lua_pushnumber(L, value );
// return number of parameters
return 1;
}
LUAMOD_API int lua_SetSize(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, 0 );
return 0;
}
float value = luaL_checknumber(L, 1);
tmpObj->SizeSet(value);
// return number of parameters
return 0;
}
LUAMOD_API int lua_GetCanBeCibled(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushboolean(L, false );
return 1;
}
float value = tmpObj->CanBeCibledGet();
lua_pushboolean(L, value );
// return number of parameters
return 1;
}
LUAMOD_API int lua_SetCanBeCibled(lua_State *L)
{
if (NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
return 0;
}
bool value = false;
if ( lua_isboolean( L, 1 ) ) {
value = lua_toboolean( L, 1 );
}
tmpObj->CanBeCibledSet(value);
// return number of parameters
return 0;
}
LUAMOD_API int lua_SpriteLoad(lua_State *L)
{
//LUA : int SpriteLoad("fileName", maxSize); => -1 in error ...
if (NULL==tmpScene || NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushnumber(L, (lua_Number)-1 );
return 1;
}
const char *filename = luaL_checkstring(L, 1);
int32_t maxSize = luaL_checkint(L, 2);
int32_t spriteID = tmpScene->LoadSprite( filename, maxSize);
if (spriteID < 0) {
EWOL_ERROR("Error to load the sprite : " << filename);
}
lua_pushnumber(L, (lua_Number)spriteID );
// return number of parameters
return 1;
}
LUAMOD_API int lua_SpriteUnLoad(lua_State *L)
{
// TODO : when supported ...
/*
//LUA : SpriteUnLoad(int);
if (NULL==tmpScene) {
return 1;
}
float a = luaL_checkint(L, 1);
etk::Vector2D<float> tmpPos = tmpObj->PositionGet();
tmpPos.y = a;
tmpObj->PositionSet(tmpPos);
*/
// return number of parameters
return 0;
}
LUAMOD_API int lua_SpriteDraw(lua_State *L)
{
//LUA : SpriteDraw(int id, posX, posY, angle, size)
if (NULL==tmpSprite) {
return 0;
}
float spriteID = luaL_checknumber(L, 1);
etk::Vector2D<float> tmpPos;
tmpPos.x = luaL_checknumber(L, 2);
tmpPos.y = luaL_checknumber(L, 3);
float angle = luaL_checknumber(L, 4);
float size = luaL_checknumber(L, 5);
if (spriteID < 0) {
EWOL_ERROR("Can not Draw the sprite : " << spriteID);
return 0;
}
//EWOL_INFO("Draw the sprite : " << spriteID << " pos=" << tmpPos << " angle=" << angle);
(*tmpSprite)[spriteID]->Element(tmpPos, size, angle);
// return number of parameters
return 0;
}
LUAMOD_API int lua_ElementAdd(lua_State *L)
{
//LUA : int ElementAdd("Bullet", group)
if (NULL==tmpScene) {
EWOL_ERROR("NULL obj...");
lua_pushinteger(L, 0 );
return 1;
}
etk::UString elementName = luaL_checkstring(L, 1);
int32_t group = luaL_checkint(L, 2);
// TODO : Remove this when find an other way do do it ...
ewol::GameElementLua * ttmpObj = tmpObj;
etk::Vector<ewol::Sprite*> * ttmpSprite = tmpSprite;
ewol::SceneElement * ttmpScene = tmpScene;
uint32_t elementId = tmpScene->AddElementNamed(group, elementName);
tmpObj = ttmpObj;
tmpSprite = ttmpSprite;
tmpScene = ttmpScene;
if (0==elementId) {
EWOL_ERROR("Error creating element : " << elementName);
}
lua_pushinteger(L, elementId );
// return number of parameters
return 1;
}
LUAMOD_API int lua_ElementSetPos(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene) {
EWOL_ERROR("ploppp ");
return 0;
}
int32_t idElement = luaL_checkint(L, 1);
ewol::GameElement* tmpElem = tmpScene->GetElement(idElement);
if (NULL != tmpElem) {
etk::Vector2D<float> tmpPos;
tmpPos.x = luaL_checknumber(L, 2);
tmpPos.y = luaL_checknumber(L, 3);
tmpElem->PositionSet(tmpPos);
} else {
EWOL_ERROR("Get element unique ID : " << idElement);
}
// return number of parameters
return 0;
}
LUAMOD_API int lua_ElementGetPos(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene) {
EWOL_ERROR("ploppp ");
lua_pushnumber(L, (lua_Number)0 );
lua_pushnumber(L, (lua_Number)0 );
return 2;
}
int32_t idElement = luaL_checkint(L, 1);
ewol::GameElement* tmpElem = tmpScene->GetElement(idElement);
if (NULL != tmpElem) {
etk::Vector2D<float> tmpPos = tmpElem->PositionGet();
lua_pushnumber(L, (lua_Number)tmpPos.x );
lua_pushnumber(L, (lua_Number)tmpPos.y );
} else {
lua_pushnumber(L, (lua_Number)0.0 );
lua_pushnumber(L, (lua_Number)0.0 );
EWOL_ERROR("Get element unique ID : " << idElement);
}
// return number of parameters
return 2;
}
LUAMOD_API int lua_ElementSetPower(lua_State *L)
{
//LUA : ElementSetPower(newElementId, 1);
if (NULL==tmpScene) {
return 0;
}
int32_t idElement = luaL_checkint(L, 1);
ewol::GameElement* tmpElem = tmpScene->GetElement(idElement);
if (NULL != tmpElem) {
int32_t power = luaL_checkint(L, 2);
tmpElem->PowerSet(power);
}
// return number of parameters
return 0;
}
LUAMOD_API int lua_ElementSetAngle(lua_State *L)
{
//LUA : ElementSetAngle(newElementId, m_angle);
if (NULL==tmpScene) {
return 0;
}
int32_t idElement = luaL_checkint(L, 1);
ewol::GameElement* tmpElem = tmpScene->GetElement(idElement);
if (NULL != tmpElem) {
float angle = luaL_checknumber(L, 2);
tmpElem->AngleSet(angle);
}
// return number of parameters
return 1;
}
LUAMOD_API int lua_GetNearestEnemy(lua_State *L)
{
//LUA : int GetNearestEnemy()
if (NULL==tmpScene || NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushinteger(L, 0 );
return 1;
}
uint32_t elementId = tmpScene->GetNearestEnemy(tmpObj->PositionGet(), tmpObj->GroupGet());
lua_pushinteger(L, elementId );
// return number of parameters
return 1;
}
LUAMOD_API int lua_ElmentExisted(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene) {
EWOL_ERROR("NULL obj...");
lua_pushboolean(L, false );
return 1;
}
int32_t idElement = luaL_checkint(L, 1);
if (0 != idElement) {
ewol::GameElement* tmpElem = tmpScene->GetElement(idElement);
if (NULL != tmpElem) {
lua_pushboolean(L, true );
} else {
lua_pushboolean(L, false );
}
} else {
lua_pushboolean(L, false );
}
// return number of parameters
return 1;
}
LUAMOD_API int lua_HaveImpact(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene || NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
lua_pushboolean(L, false );
return 1;
}
// TODO : Remove this when find an other way do do it ...
ewol::GameElementLua * ttmpObj = tmpObj;
etk::Vector<ewol::Sprite*> * ttmpSprite = tmpSprite;
ewol::SceneElement * ttmpScene = tmpScene;
bool result = tmpScene->HaveImpact(tmpObj->GroupGet(), tmpObj->TypeGet(), tmpObj->PositionGet(), tmpObj->SizeGet());
tmpObj = ttmpObj;
tmpSprite = ttmpSprite;
tmpScene = ttmpScene;
lua_pushboolean(L, result );
// return number of parameters
return 1;
}
LUAMOD_API int lua_Explosion(lua_State *L)
{
//LUA : ElementSetPos(newElementId, posX, posY);
if (NULL==tmpScene || NULL==tmpObj) {
EWOL_ERROR("NULL obj...");
return 0;
}
// TODO : Remove this when find an other way do do it ...
ewol::GameElementLua * ttmpObj = tmpObj;
etk::Vector<ewol::Sprite*> * ttmpSprite = tmpSprite;
ewol::SceneElement * ttmpScene = tmpScene;
tmpScene->Explosion(tmpObj->GroupGet(), tmpObj->TypeGet(), tmpObj->PositionGet(), 0.01, tmpObj->PowerGet());
tmpObj = ttmpObj;
tmpSprite = ttmpSprite;
tmpScene = ttmpScene;
// return number of parameters
return 0;
}
static const luaL_Reg functionsTable[] = {
// local element section
{ "GetPos", lua_GetPos },
{ "SetPos", lua_SetPos },
{ "GetSpeed", lua_GetSpeed },
{ "SetSpeed", lua_SetSpeed },
{ "GetAngle", lua_GetAngle },
{ "SetAngle", lua_SetAngle },
{ "GetSize", lua_GetSize },
{ "SetSize", lua_SetSize },
{ "GetPower", lua_GetPower },
{ "SetPower", lua_SetPower },
{ "GetGroup", lua_GetGroup },
{ "SetGroup", lua_SetGroup },
{ "GetCanBeCibled", lua_GetCanBeCibled },
{ "SetCanBeCibled", lua_SetCanBeCibled },
// other element section
{ "ElementAdd", lua_ElementAdd },
{ "ElementExisted", lua_ElmentExisted },
{ "ElementSetPos", lua_ElementSetPos },
{ "ElementGetPos", lua_ElementGetPos },
{ "ElementSetPower", lua_ElementSetPower },
{ "ElementSetAngle", lua_ElementSetAngle },
{ "GetNearestEnemy", lua_GetNearestEnemy },
{ "HaveImpact", lua_HaveImpact },
{ "Explosion", lua_Explosion },
// Sprite section
{ "SpriteLoad", lua_SpriteLoad },
{ "SpriteUnLoad", lua_SpriteUnLoad },
{ "SpriteDraw", lua_SpriteDraw },
{ NULL, NULL }
};
//http://www.swig.org/Doc1.3/Lua.html#Lua_nn13
//http://stackoverflow.com/questions/2521244/how-to-wrap-a-c-function-whose-parameters-are-pointer-to-structs-so-that-it-can
LUAMOD_API int luaopen_myLib(lua_State *L) {
luaL_register(L, "GameElement", functionsTable);
lua_pop(L, 1);
return 1;
}
/*******************************************************************************
** Lua abstraction (END)
******************************************************************************* */
#undef __class__
#define __class__ "GameElementLua"
ewol::GameElementLua::GameElementLua(ewol::SceneElement & sceneElement, etk::UString& tmpName) :
ewol::GameElement(sceneElement, tmpName),
m_luaState(NULL)
{
tmpObj = this;
tmpScene = &m_sceneElement;
etk::FSNode fileElement(etk::UString("DATA:") + tmpName);
etk::UString tmpCompleatName = fileElement.GetName();
// create state
m_luaState = luaL_newstate();
if (m_luaState == NULL) {
EWOL_ERROR("LUA: cannot create state: not enough memory");
return;
}
luaL_openlibs(m_luaState);
// open internal specific elements ...
luaopen_myLib(m_luaState);
/*
LuaValue<bool> *myBool = new LuaValue<bool>(m_luaState, "m_testBool");
LuaValue<float> *myValue = new LuaValue<float>(m_luaState, "m_testFloat");
*myBool = false;
*myValue = 18;
*/
int32_t fileSize = fileElement.FileSize();
if (0==fileSize) {
EWOL_ERROR("This file is empty : " << fileElement);
return;
}
if (false == fileElement.FileOpenRead()) {
EWOL_ERROR("Can not open the file : " << fileElement);
return;
}
// allocate data
char * fileBuffer = new char[fileSize+5];
if (NULL == fileBuffer) {
EWOL_ERROR("Error Memory allocation size=" << fileSize);
return;
}
memset(fileBuffer, 0, (fileSize+5)*sizeof(char));
// load data from the file :
fileElement.FileRead(fileBuffer, 1, fileSize);
// close the file:
fileElement.FileClose();
if (luaL_loadbuffer(m_luaState, fileBuffer, fileSize, tmpName.c_str())) {
//if (luaL_loadfile(m_luaState, "/home/heero/dev/perso/TethysDefender/assets/elementGame/Cube.lua" ) ) {
EWOL_ERROR("LUA: " << lua_tostring(m_luaState, -1));
return;
}
if (NULL != fileBuffer) {
delete[] fileBuffer;
}
// Call the basic for initialise all the element defined by the user...
if (lua_pcall(m_luaState, 0, 0, 0)) {
EWOL_ERROR("LUA: " << lua_tostring(m_luaState, -1));
return;
}
/*
EWOL_INFO("retreave element : " << *myValue << " and : " << *myBool);
*/
tmpObj = NULL;
tmpScene = NULL;
Init();
}
ewol::GameElementLua::~GameElementLua(void)
{
UnInit();
if (NULL != m_luaState) {
lua_close(m_luaState);
m_luaState = NULL;
}
}
void ewol::GameElementLua::Init(void)
{
tmpObj = this;
tmpScene = &m_sceneElement;
if (NULL != m_luaState) {
// call the init function
lua_getglobal(m_luaState, "Init");
if(!lua_isfunction(m_luaState,-1)) {
EWOL_WARNING("LUA: Not Find Init function ");
lua_pop(m_luaState,1);
} else {
// do the call (0 arguments, 0 result)
if (lua_pcall(m_luaState, 0, 0, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Init':" << lua_tostring(m_luaState, -1));
return;
}
}
}
tmpObj = NULL;
tmpScene = NULL;
}
void ewol::GameElementLua::UnInit(void)
{
tmpObj = this;
tmpScene = &m_sceneElement;
if (NULL != m_luaState) {
// call the init function
lua_getglobal(m_luaState, "UnInit");
if(!lua_isfunction(m_luaState,-1)) {
EWOL_WARNING("LUA: Not Find 'UnInit' function ");
lua_pop(m_luaState,1);
} else {
// do the call (0 arguments, 0 result)
if (lua_pcall(m_luaState, 0, 0, 0) != 0) {
EWOL_ERROR("LUA: error running function 'UnInit':" << lua_tostring(m_luaState, -1));
}
}
}
tmpObj = NULL;
tmpScene = NULL;
}
bool ewol::GameElementLua::Process(int64_t time, int32_t deltaTime)
{
tmpObj = this;
tmpScene = &m_sceneElement;
bool retVal = false;
if (NULL != m_luaState) {
// call the init function
lua_getglobal(m_luaState, "Process");
if(!lua_isfunction(m_luaState,-1)) {
EWOL_WARNING("LUA: Not Find 'Process' function ");
lua_pop(m_luaState,1);
} else {
lua_pushnumber(m_luaState, (int32_t)time); // push 1st argument
lua_pushnumber(m_luaState, (int32_t)deltaTime); // push 2nd argument
// do the call (2 arguments, 1 result)
if (lua_pcall(m_luaState, 2, 1, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Process':" << lua_tostring(m_luaState, -1));
} else {
// retrieve result
if (!lua_isboolean(m_luaState, -1)) {
EWOL_ERROR("LUA: function 'Process' must return a boolean");
} else {
retVal = lua_toboolean(m_luaState, -1);
lua_pop(m_luaState, 1);
}
}
}
}
tmpObj = NULL;
tmpScene = NULL;
return retVal;
}
void ewol::GameElementLua::Draw(void)
{
tmpObj = this;
tmpSprite = &m_sceneElement.animated;
if (NULL != m_luaState) {
// call the Draw function
lua_getglobal(m_luaState, "Draw");
if(!lua_isfunction(m_luaState,-1)) {
EWOL_WARNING("LUA: Not Find 'Draw' function ");
lua_pop(m_luaState,1);
} else {
// do the call (0 arguments, 0 result)
if (lua_pcall(m_luaState, 0, 0, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Draw':" << lua_tostring(m_luaState, -1));
}
}
}
tmpObj = NULL;
tmpSprite = NULL;
}
bool ewol::GameElementLua::HaveImpact(int32_t group, int32_t type, etk::Vector2D<float> position, float size)
{
// todo set a flag that permit lua to direct control of this ...
if (false == ewol::GameElement::HaveImpact(group, type, position, size) ) {
return false;
}
//HaveImpact(group, type, posX, posY, size, quadDistance)
tmpObj = this;
bool retVal = true;
if (NULL != m_luaState) {
// call the init function
lua_getglobal(m_luaState, "HaveImpact");
if(!lua_isfunction(m_luaState,-1)) {
EWOL_VERBOSE("LUA: Not Find 'HaveImpact' function ");
lua_pop(m_luaState,1);
} else {
lua_pushnumber(m_luaState, group);
lua_pushnumber(m_luaState, type);
lua_pushnumber(m_luaState, position.x);
lua_pushnumber(m_luaState, position.y);
lua_pushnumber(m_luaState, size);
float quadDistance = quadDist(m_position, position);
lua_pushnumber(m_luaState, quadDistance);
// do the call (6 arguments, 1 result)
if (lua_pcall(m_luaState, 6, 1, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Process':" << lua_tostring(m_luaState, -1));
} else {
// retrieve result
if (!lua_isboolean(m_luaState, -1)) {
EWOL_ERROR("LUA: function 'Process' must return a boolean");
} else {
retVal = lua_toboolean(m_luaState, -1);
lua_pop(m_luaState, 1);
}
}
}
}
tmpObj = NULL;
return retVal;
}
bool ewol::GameElementLua::Explosion(int32_t group, int32_t type, etk::Vector2D<float> position, float pxAtenuation, float power)
{
tmpObj = this;
bool retVal = false;
if (NULL != m_luaState) {
// call the init function
lua_getglobal(m_luaState, "Explosion");
if(!lua_isfunction(m_luaState,-1)) {
EWOL_VERBOSE("LUA: Not Find 'Explosion' function ");
lua_pop(m_luaState,1);
} else {
lua_pushnumber(m_luaState, group);
lua_pushnumber(m_luaState, type);
lua_pushnumber(m_luaState, position.x);
lua_pushnumber(m_luaState, position.y);
lua_pushnumber(m_luaState, pxAtenuation);
lua_pushnumber(m_luaState, power);
float quadDistance = quadDist(m_position, position);
lua_pushnumber(m_luaState, quadDistance);
// do the call (7 arguments, 1 result)
if (lua_pcall(m_luaState, 7, 1, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Explosion':" << lua_tostring(m_luaState, -1));
} else {
// retrieve result
if (!lua_isboolean(m_luaState, -1)) {
EWOL_ERROR("LUA: function 'Process' must return a boolean");
} else {
retVal = lua_toboolean(m_luaState, -1);
lua_pop(m_luaState, 1);
}
}
}
}
tmpObj = NULL;
return retVal;
}
etk::UString ewol::GameElementLua::Message(etk::UString control, etk::UString message)
{
tmpObj = this;
if (NULL != m_luaState) {
// call the init function
lua_getglobal(m_luaState, "Message");
if(!lua_isfunction(m_luaState,-1)) {
lua_pop(m_luaState,1);
} else {
lua_pushstring(m_luaState, control.c_str());
lua_pushstring(m_luaState, message.c_str());
// do the call (2 arguments, 0 result)
if (lua_pcall(m_luaState, 2, 0, 0) != 0) {
EWOL_ERROR("LUA: error running function 'Message':" << lua_tostring(m_luaState, -1));
}
}
}
tmpObj = NULL;
return "";
}
static ewol::GameElement* LoadSceneElement_lua(ewol::SceneElement & sceneElement, etk::UString& elementName, etk::UString& userString)
{
// try to find the file :
etk::UString tmpName = userString;
tmpName += elementName;
tmpName += ".lua";
// added a new element :
etk::FSNode fileElement(etk::UString("DATA:") + tmpName);
if (false == fileElement.Exist()) {
EWOL_ERROR("Can not find Game element : " << elementName << " ==> " << tmpName);
return NULL;
}
EWOL_VERBOSE("We find Game element : " << elementName << " ==> " << tmpName);
ewol::GameElementLua * tmpElement = new ewol::GameElementLua(sceneElement, tmpName);
if (NULL == tmpElement) {
EWOL_ERROR("Can not Allocat : " << elementName);
return NULL;
}
return tmpElement;
}
void ewol::RegisterLuaElementInFolder(ewol::SceneElement & sceneElement, etk::UString folder)
{
// TODO : parsing the folder ...
sceneElement.RegisterElementType("??????", &LoadSceneElement_lua, folder);
}
void ewol::RegisterLuaElementSpecify(ewol::SceneElement & sceneElement, etk::UString folder, etk::UString name)
{
sceneElement.RegisterElementType(name, &LoadSceneElement_lua, folder);
}

View File

@ -1,42 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_GAME_ELEMENT_LUA_H__
#define __EWOL_GAME_ELEMENT_LUA_H__
#include <etk/Types.h>
#include <ewol/Debug.h>
#include <ewol/oObject/Sprite.h>
#include <ewol/widget/Widget.h>
#include <ewol/game/SceneElement.h>
#include <ewol/game/GameElement.h>
#include <lua/lua.hpp>
namespace ewol {
class GameElementLua : public ewol::GameElement
{
private:
lua_State *m_luaState; // internal Lua state
public:
GameElementLua(ewol::SceneElement & sceneElement, etk::UString& tmpName);
~GameElementLua(void);
virtual void Init(void);
virtual void UnInit(void);
virtual bool Process(int64_t time, int32_t deltaTime);
virtual void Draw(void);
virtual bool HaveImpact(int32_t group, int32_t type, etk::Vector2D<float> position, float size);
virtual bool Explosion(int32_t group, int32_t type, etk::Vector2D<float> position, float pxAtenuation, float power);
virtual etk::UString Message(etk::UString control, etk::UString message);
};
void RegisterLuaElementInFolder(ewol::SceneElement & sceneElement, etk::UString folder);
void RegisterLuaElementSpecify(ewol::SceneElement & sceneElement, etk::UString folder, etk::UString name);
};
#endif

184
sources/ewol/key.cpp Normal file
View File

@ -0,0 +1,184 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
etk::CCout& ewol::keyEvent::operator <<(etk::CCout &os, const ewol::keyEvent::event_te obj)
{
switch(obj) {
default:
case ewol::keyEvent::None :
os << "None";
break;
case ewol::keyEvent::MouseDown :
os << "MouseDown";
break;
case ewol::keyEvent::MouseMove :
os << "MouseMove";
break;
case ewol::keyEvent::MouseSingle :
os << "MouseSingle";
break;
case ewol::keyEvent::MouseDouble :
os << "MouseDouble";
break;
case ewol::keyEvent::MouseTriple :
os << "MouseTriple";
break;
case ewol::keyEvent::MouseQuad :
os << "MouseQuad";
break;
case ewol::keyEvent::MouseQuinte :
os << "MouseQuinte";
break;
case ewol::keyEvent::MouseUp :
os << "MouseUp";
break;
case ewol::keyEvent::MouseEnter :
os << "MouseEnter";
break;
case ewol::keyEvent::MouseLeave :
os << "MouseLeave";
break;
case ewol::keyEvent::MouseAbort :
os << "MouseAbort";
break;
case ewol::keyEvent::MouseTransfer :
os << "MouseTransfer";
break;
case ewol::keyEvent::KeyboardLeft :
os << "KeyboardLeft";
break;
case ewol::keyEvent::KeyboardRight :
os << "KeyboardRight";
break;
case ewol::keyEvent::KeyboardUp :
os << "KeyboardUp";
break;
case ewol::keyEvent::KeyboardDown :
os << "KeyboardDown";
break;
case ewol::keyEvent::KeyboardPageUp :
os << "KeyboardPageUp";
break;
case ewol::keyEvent::KeyboardPageDown :
os << "KeyboardPageDown";
break;
case ewol::keyEvent::KeyboardStart :
os << "KeyboardStart";
break;
case ewol::keyEvent::KeyboardEnd :
os << "KeyboardEnd";
break;
case ewol::keyEvent::KeyboardCenter :
os << "KeyboardCenter";
break;
case ewol::keyEvent::KeyboardStopDefil :
os << "KeyboardStopDefil";
break;
case ewol::keyEvent::KeyboardWait :
os << "KeyboardWait";
break;
case ewol::keyEvent::KeyboardInsert :
os << "KeyboardInsert";
break;
case ewol::keyEvent::KeyboardF1 :
os << "KeyboardF1";
break;
case ewol::keyEvent::KeyboardF2 :
os << "KeyboardF2";
break;
case ewol::keyEvent::KeyboardF3 :
os << "KeyboardF3";
break;
case ewol::keyEvent::KeyboardF4 :
os << "KeyboardF4";
break;
case ewol::keyEvent::KeyboardF5 :
os << "KeyboardF5";
break;
case ewol::keyEvent::KeyboardF6 :
os << "KeyboardF6";
break;
case ewol::keyEvent::KeyboardF7 :
os << "KeyboardF7";
break;
case ewol::keyEvent::KeyboardF8 :
os << "KeyboardF8";
break;
case ewol::keyEvent::KeyboardF9 :
os << "KeyboardF9";
break;
case ewol::keyEvent::KeyboardF10 :
os << "KeyboardF10";
break;
case ewol::keyEvent::KeyboardF11 :
os << "KeyboardF11";
break;
case ewol::keyEvent::KeyboardF12 :
os << "KeyboardF12";
break;
case ewol::keyEvent::KeyboardCapLock :
os << "KeyboardCapLock";
break;
case ewol::keyEvent::KeyboardShiftLeft :
os << "KeyboardShiftLeft";
break;
case ewol::keyEvent::KeyboardShiftRight :
os << "KeyboardShiftRight";
break;
case ewol::keyEvent::KeyboardCtrlLeft :
os << "KeyboardCtrlLeft";
break;
case ewol::keyEvent::KeyboardCtrlRight :
os << "KeyboardCtrlRight";
break;
case ewol::keyEvent::KeyboardMetaLeft :
os << "KeyboardMetaLeft";
break;
case ewol::keyEvent::KeyboardMetaRight :
os << "KeyboardMetaRight";
break;
case ewol::keyEvent::KeyboardAlt :
os << "KeyboardAlt";
break;
case ewol::keyEvent::KeyboardAltGr :
os << "KeyboardAltGr";
break;
case ewol::keyEvent::KeyboardContextMenu :
os << "KeyboardContextMenu";
break;
case ewol::keyEvent::KeyboardVerNum :
os << "KeyboardVerNum";
break;
}
return os;
}
}
etk::CCout& ewol::keyEvent::operator <<(etk::CCout &os, const ewol::keyEvent::input_te obj)
{
switch(obj) {
default:
case ewol::keyEvent::NoUnknowne :
os << "Unknow";
break;
case ewol::keyEvent::Mouse :
os << "Mouse";
break;
case ewol::keyEvent::Finger :
os << "Finger";
break;
case ewol::keyEvent::Stylet :
os << "Stylet";
break;
}
return os;
}

93
sources/ewol/key.h Normal file
View File

@ -0,0 +1,93 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_KEY_H__
#define __EWOL_KEY_H__
#include <etk/Types.h>
#include <etk/Stream.h>
namespace ewol
{
namespace keyEvent
{
// event from all the type of input :
typedef enum {
None,
MouseDown,
MouseMove,
MouseSingle,
MouseDouble,
MouseTriple,
MouseQuad,
MouseQuinte,
MouseUp,
MouseEnter,
MouseLeave,
MouseAbort, // Appeare when an event is tranfert betwwen widgets (the widget which receive this has lost the events)
MouseTransfer, // Appeare when an event is tranfert betwwen widgets (the widget which receive this has receive the transfert of the event)
KeyboardLeft,
KeyboardRight,
KeyboardUp,
KeyboardDown,
KeyboardPageUp,
KeyboardPageDown,
KeyboardStart,
KeyboardEnd,
KeyboardCenter,
KeyboardStopDefil,
KeyboardWait,
KeyboardInsert,
KeyboardF1,
KeyboardF2,
KeyboardF3,
KeyboardF4,
KeyboardF5,
KeyboardF6,
KeyboardF7,
KeyboardF8,
KeyboardF9,
KeyboardF10,
KeyboardF11,
KeyboardF12,
KeyboardCapLock,
KeyboardShiftLeft,
KeyboardShiftRight,
KeyboardCtrlLeft,
KeyboardCtrlRight,
KeyboardMetaLeft,
KeyboardMetaRight,
KeyboardAlt,
KeyboardAltGr,
KeyboardContextMenu,
KeyboardVerNum,
} event_te;
/**
* @brief Debug operator To display the curent element in a Human redeable information
*/
etk::CCout& operator <<(etk::CCout &os, const ewol::keyEvent::event_te obj);
// type of input : Notye that the keyboard is not prevent due to the fact that data is too different
typedef enum {
Unknow,
Mouse,
Finger,
Stylet,
} input_te;
/**
* @brief Debug operator To display the curent element in a Human redeable information
*/
etk::CCout& operator <<(etk::CCout &os, const ewol::keyEvent::input_te obj);
};
};
#endif

View File

@ -1,601 +0,0 @@
/**
*******************************************************************************
* @file ewol/oObject/2DColored.cpp
* @brief ewol OpenGl Object system (Sources)
* @author Edouard DUPIN
* @date 09/11/2011
* @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/oObject/2DColored.h>
#include <ewol/openGL/openGL.h>
#include <math.h>
#undef __class__
#define __class__ "ewol::OObject2DColored"
ewol::OObject2DColored::OObject2DColored(void)
{
m_triElement = 0;
SetColor(1.0, 1.0, 1.0, 1.0);
etk::UString tmpString("DATA:color.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
}
}
ewol::OObject2DColored::~OObject2DColored(void)
{
m_coord.Clear();
m_coordColor.Clear();
ewol::resource::Release(m_GLprogram);
}
void ewol::OObject2DColored::Draw(void)
{
if (m_coord.Size()<=0) {
return;
}
if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ...");
return;
}
//glScalef(m_scaling.x, m_scaling.y, 1.0);
m_GLprogram->Use();
// set Matrix : translation/positionMatrix
etk::Matrix4 tmpMatrix = ewol::openGL::GetMatrix();
m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
// position :
m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, &m_coord[0]);
// color :
m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
// Request the draw of the elements :
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
m_GLprogram->UnUse();
}
void ewol::OObject2DColored::Clear(void)
{
m_coord.Clear();
m_coordColor.Clear();
}
void generatePolyGone(etk::Vector<etk::Vector2D<float> > & input, etk::Vector<etk::Vector2D<float> > & output )
{
if (input.Size()<3) {
return;
}
// TODO : Regenerate a linear poligone generation
for (int32_t iii=1; iii<input.Size()-1; iii++) {
output.PushBack(input[0]);
output.PushBack(input[iii]);
output.PushBack(input[iii+1]);
}
//EWOL_DEBUG("generate Plygone : " << input.Size() << " ==> " << output.Size() );
}
void SutherlandHodgman(etk::Vector<etk::Vector2D<float> > & input, etk::Vector<etk::Vector2D<float> > & output, float sx, float sy, float ex, float ey)
{
// with Sutherland-Hodgman-Algorithm
if (input.Size() <0) {
return;
}
//int32_t sizeInit=input.Size();
// last element :
etk::Vector2D<float> destPoint;
etk::Vector2D<float> lastElement = input[input.Size()-1];
bool inside = true;
if (lastElement.x < sx) {
inside = false;
}
//EWOL_DEBUG("generate an crop : ");
for(int32_t iii=0; iii<input.Size(); iii++) {
if(input[iii].x < sx) {
if(true == inside) {
//EWOL_DEBUG("element IN ==> OUT ");
//new point intersection ...
//y=aaax+bbb
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
float bbb = lastElement.y - (aaa*lastElement.x);
destPoint.y = aaa*sx + bbb;
destPoint.x = sx;
output.PushBack(destPoint);
} else {
//EWOL_DEBUG("element OUT ==> OUT ");
}
inside = false;
} else {
if(true == inside) {
//EWOL_DEBUG("element IN ==> IN ");
output.PushBack(input[iii]);
} else {
//EWOL_DEBUG("element OUT ==> IN ");
//new point intersection ...
//y=aaax+bbb
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
float bbb = lastElement.y - (aaa*lastElement.x);
destPoint.y = aaa*sx + bbb;
destPoint.x = sx;
output.PushBack(destPoint);
output.PushBack(input[iii]);
}
inside = true;
}
// update the last point position :
lastElement.x = input[iii].x;
lastElement.y = input[iii].y;
}
//EWOL_DEBUG("generate an crop on element : " << sizeInit << " ==> " << output.Size() << "intermediate (1)");
input = output;
output.Clear();
lastElement = input[input.Size()-1];
inside = true;
if (lastElement.y < sy) {
inside = false;
}
for(int32_t iii=0; iii<input.Size(); iii++) {
if(input[iii].y < sy) {
if(true == inside) {
//EWOL_DEBUG("element IN ==> OUT ");
//new point intersection ...
//x=aaay+bbb
float aaa = (lastElement.x-input[iii].x) / (lastElement.y-input[iii].y);
float bbb = lastElement.x - (aaa*lastElement.y);
destPoint.y = sy;
destPoint.x = sy*aaa + bbb;
output.PushBack(destPoint);
} else {
//EWOL_DEBUG("element OUT ==> OUT ");
}
inside = false;
} else {
if(true == inside) {
//EWOL_DEBUG("element IN ==> IN ");
output.PushBack(input[iii]);
} else {
//EWOL_DEBUG("element OUT ==> IN ");
//new point intersection ...
//y=aaax+bbb
float aaa = (lastElement.x-input[iii].x) / (lastElement.y-input[iii].y);
float bbb = lastElement.x - (aaa*lastElement.y);
destPoint.y = sy;
destPoint.x = sy*aaa + bbb;
output.PushBack(destPoint);
output.PushBack(input[iii]);
}
inside = true;
}
// update the last point position :
lastElement.x = input[iii].x;
lastElement.y = input[iii].y;
}
input = output;
output.Clear();
lastElement = input[input.Size()-1];
inside = true;
if (lastElement.x > ex) {
inside = false;
}
//EWOL_DEBUG("generate an crop : ");
for(int32_t iii=0; iii<input.Size(); iii++) {
if(input[iii].x > ex) {
if(true == inside) {
//EWOL_DEBUG("element IN ==> OUT ");
//new point intersection ...
//y=aaax+bbb
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
float bbb = lastElement.y - (aaa*lastElement.x);
destPoint.y = aaa*ex + bbb;
destPoint.x = ex;
output.PushBack(destPoint);
} else {
//EWOL_DEBUG("element OUT ==> OUT ");
}
inside = false;
} else {
if(true == inside) {
//EWOL_DEBUG("element IN ==> IN ");
output.PushBack(input[iii]);
} else {
//EWOL_DEBUG("element OUT ==> IN ");
//new point intersection ...
//y=aaax+bbb
float aaa = (lastElement.y-input[iii].y) / (lastElement.x-input[iii].x);
float bbb = lastElement.y - (aaa*lastElement.x);
destPoint.y = aaa*ex + bbb;
destPoint.x = ex;
output.PushBack(destPoint);
output.PushBack(input[iii]);
}
inside = true;
}
// update the last point position :
lastElement.x = input[iii].x;
lastElement.y = input[iii].y;
}
input = output;
output.Clear();
lastElement = input[input.Size()-1];
inside = true;
if (lastElement.y > ey) {
inside = false;
}
for(int32_t iii=0; iii<input.Size(); iii++) {
if(input[iii].y > ey) {
if(true == inside) {
//EWOL_DEBUG("element IN ==> OUT ");
//new point intersection ...
//x=aaay+bbb
float aaa = (lastElement.x-input[iii].x) / (lastElement.y-input[iii].y);
float bbb = lastElement.x - (aaa*lastElement.y);
destPoint.y = ey;
destPoint.x = ey*aaa + bbb;
output.PushBack(destPoint);
} else {
//EWOL_DEBUG("element OUT ==> OUT ");
}
inside = false;
} else {
if(true == inside) {
//EWOL_DEBUG("element IN ==> IN ");
output.PushBack(input[iii]);
} else {
//EWOL_DEBUG("element OUT ==> IN ");
//new point intersection ...
//y=aaax+bbb
float aaa = (lastElement.x-input[iii].x) / (lastElement.y-input[iii].y);
float bbb = lastElement.x - (aaa*lastElement.y);
destPoint.y = ey;
destPoint.x = ey*aaa + bbb;
output.PushBack(destPoint);
output.PushBack(input[iii]);
}
inside = true;
}
// update the last point position :
lastElement.x = input[iii].x;
lastElement.y = input[iii].y;
}
//EWOL_DEBUG("generate an crop on element : " << sizeInit << " ==> " << output.Size() );
}
void ewol::OObject2DColored::GenerateTriangle(void)
{
m_triElement = 0;
m_coord.PushBack(m_triangle[0]);
m_coordColor.PushBack(m_color[0]);
m_coord.PushBack(m_triangle[1]);
m_coordColor.PushBack(m_color[1]);
m_coord.PushBack(m_triangle[2]);
m_coordColor.PushBack(m_color[2]);
}
void ewol::OObject2DColored::SetColor(draw::Color color)
{
if (m_triElement < 1) {
m_color[0] = color;
}
if (m_triElement < 2) {
m_color[1] = color;
}
if (m_triElement < 3) {
m_color[2] = color;
}
}
void ewol::OObject2DColored::SetColor(float red, float green, float blue, float alpha)
{
if (m_triElement < 1) {
m_color[0] = draw::Color(red, green, blue, alpha);
}
if (m_triElement < 2) {
m_color[1] = draw::Color(red, green, blue, alpha);
}
if (m_triElement < 3) {
m_color[2] = draw::Color(red, green, blue, alpha);
}
}
void ewol::OObject2DColored::SetPoint(etk::Vector2D<float> point)
{
// TODO : Clean this :
etk::Vector2D<float> tmpElement;
tmpElement.x = point.x;
tmpElement.y = point.y;
m_triangle[m_triElement] = tmpElement;
m_triElement++;
if (m_triElement>=3) {
GenerateTriangle();
}
}
void ewol::OObject2DColored::SetPoint(float x, float y)
{
m_triangle[m_triElement].x = x;
m_triangle[m_triElement].y = y;
m_triElement++;
if (m_triElement>=3) {
GenerateTriangle();
}
}
void ewol::OObject2DColored::ResetCount(void)
{
m_triElement = 0;
m_color[1] = m_color[0];
m_color[2] = m_color[0];
}
void ewol::OObject2DColored::Line(float sx, float sy, float ex, float ey, float thickness)
{
ResetCount();
if (sx == ex && sy == ey) {
EWOL_WARNING("Try to draw an line width 0");
return;
}
//teta = tan-1(oposer/adjacent)
float teta = 0;
if (sx <= ex) {
teta = atan((ey-sy)/(ex-sx));
} else {
teta = M_PI + atan((ey-sy)/(ex-sx));
}
if (teta < 0) {
teta += 2*M_PI;
} else if (teta > 2*M_PI) {
teta -= 2*M_PI;
}
//EWOL_DEBUG("teta = " << (teta*180/(M_PI)) << " deg." );
float offsety = sin(teta-M_PI/2) * (thickness/2);
float offsetx = cos(teta-M_PI/2) * (thickness/2);
SetPoint(sx - offsetx, sy - offsety);
SetPoint(sx + offsetx, sy + offsety);
SetPoint(ex + offsetx, ey + offsety);
SetPoint(ex + offsetx, ey + offsety);
SetPoint(ex - offsetx, ey - offsety);
SetPoint(sx - offsetx, sy - offsety);
}
void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h)
{
ResetCount();
/*
x += 3;
y += 3;
w -= 6;
h -= 6;
*/
/* Bitmap position
* xA xB
* yC *------*
* | |
* | |
* yD *------*
*/
float dxA = x;
float dxB = x + w;
float dyC = y;
float dyD = y + h;
if (true == m_hasClipping) {
if (dxA < m_clipping.x) {
dxA = m_clipping.x;
}
if (dxB > m_clipping.x + m_clipping.w) {
dxB = m_clipping.x + m_clipping.w;
}
if (dyC < m_clipping.y) {
dyC = m_clipping.y;
}
if (dyD > m_clipping.y + m_clipping.h) {
dyD = m_clipping.y + m_clipping.h;
}
}
if( dyC >= dyD
|| dxA >= dxB) {
return;
}
SetPoint(dxA, dyD);
SetPoint(dxA, dyC);
SetPoint(dxB, dyC);
SetPoint(dxB, dyC);
SetPoint(dxB, dyD);
SetPoint(dxA, dyD);
}
void ewol::OObject2DColored::RectangleBorder(float x, float y, float w, float h, float thickness)
{
// TODO : This did not manage the thickness of the line ...
Line(x, y, x+w, y, thickness);
Line(x+w, y, x+w, y+h, thickness);
Line(x+w, y+h, x, y+h, thickness);
Line(x, y+h, x, y, thickness);
}
void ewol::OObject2DColored::Circle(float x, float y, float radius, float thickness)
{
ResetCount();
if (radius<0) {
radius *= -1;
}
if (radius < thickness/2) {
Disc(x, y, thickness/2 + radius);
}
int32_t nbOcurence = radius;
if (nbOcurence < 10)
{
nbOcurence = 10;
}
for (int32_t iii=0; iii<nbOcurence; iii++) {
float angleOne = 2*M_PI* iii / nbOcurence ;
float offsetExty = sin(angleOne) * (radius+thickness/2);
float offsetExtx = cos(angleOne) * (radius+thickness/2);
float offsetInty = sin(angleOne) * (radius-thickness/2);
float offsetIntx = cos(angleOne) * (radius-thickness/2);
float angleTwo = 2*M_PI* (iii+1) / nbOcurence ;
float offsetExt2y = sin(angleTwo) * (radius+thickness/2);
float offsetExt2x = cos(angleTwo) * (radius+thickness/2);
float offsetInt2y = sin(angleTwo) * (radius-thickness/2);
float offsetInt2x = cos(angleTwo) * (radius-thickness/2);
SetPoint(x + offsetIntx, y + offsetInty);
SetPoint(x + offsetExtx, y + offsetExty);
SetPoint(x + offsetExt2x, y + offsetExt2y);
SetPoint(x + offsetExt2x, y + offsetExt2y);
SetPoint(x + offsetInt2x, y + offsetInt2y);
SetPoint(x + offsetIntx, y + offsetInty);
}
}
void ewol::OObject2DColored::CirclePart(float x, float y, float radius, float thickness, float angleStart, float angleStop)
{
ResetCount();
if (radius<0) {
radius *= -1;
}
if (radius < thickness/2) {
Disc(x, y, thickness/2 + radius);
}
angleStart -= 90;
angleStop -= 90;
float AStart = angleStart * (M_PI)/180;
//float AStop = angleStop * (M_PI)/180;
float angleLinear = (angleStop-angleStart)* (M_PI)/180;
int32_t nbOcurence = radius;
if (nbOcurence < 10)
{
nbOcurence = 10;
}
for (int32_t iii=0; iii<nbOcurence; iii++) {
float angleOne = AStart + (angleLinear* iii / nbOcurence) ;
float offsetExty = sin(angleOne) * (radius+thickness/2);
float offsetExtx = cos(angleOne) * (radius+thickness/2);
float offsetInty = sin(angleOne) * (radius-thickness/2);
float offsetIntx = cos(angleOne) * (radius-thickness/2);
float angleTwo = AStart + (angleLinear* (iii+1) / nbOcurence );
float offsetExt2y = sin(angleTwo) * (radius+thickness/2);
float offsetExt2x = cos(angleTwo) * (radius+thickness/2);
float offsetInt2y = sin(angleTwo) * (radius-thickness/2);
float offsetInt2x = cos(angleTwo) * (radius-thickness/2);
SetPoint(x + offsetIntx, y + offsetInty);
SetPoint(x + offsetExtx, y + offsetExty);
SetPoint(x + offsetExt2x, y + offsetExt2y);
SetPoint(x + offsetExt2x, y + offsetExt2y);
SetPoint(x + offsetInt2x, y + offsetInt2y);
SetPoint(x + offsetIntx, y + offsetInty);
}
}
void ewol::OObject2DColored::Disc(float x, float y, float radius)
{
ResetCount();
if (radius<0) {
radius *= -1;
}
int32_t nbOcurence = radius*0.50;
if (nbOcurence < 15)
{
nbOcurence = 15;
}
// TODO : Generate a poligone instead if this ...
for (int32_t iii=0; iii<nbOcurence; iii++) {
SetPoint(x, y);
float angleOne = 2*M_PI* iii / nbOcurence ;
float offsety = sin(angleOne) * radius;
float offsetx = cos(angleOne) * radius;
SetPoint(x + offsetx, y + offsety);
float angleTwo = 2*M_PI* (iii+1) / nbOcurence ;
offsety = sin(angleTwo) * radius;
offsetx = cos(angleTwo) * radius;
SetPoint(x + offsetx, y + offsety);
}
}
void ewol::OObject2DColored::DiscPart(float x, float y, float radius, float angleStart, float angleStop)
{
ResetCount();
if (radius<0) {
radius *= -1;
}
angleStart -= 90;
angleStop -= 90;
float AStart = angleStart * (M_PI)/180;
//float AStop = angleStop * (M_PI)/180;
float angleLinear = (angleStop-angleStart)* (M_PI)/180;
//EWOL_DEBUG("Write a part of disk " << angleStart << " -> " << angleStop << " ocurence=" << (angleLinear*180/(M_PI)) );
int32_t nbOcurence = radius*0.50;
if (nbOcurence < 15)
{
nbOcurence = 15;
}
// TODO : Generate a poligone instead if this ...
for (int32_t iii=0; iii<nbOcurence; iii++) {
SetPoint(x, y);
float angleOne = AStart + (angleLinear* iii / nbOcurence) ;
float offsety = sin(angleOne) * radius;
float offsetx = cos(angleOne) * radius;
SetPoint(x + offsetx, y + offsety);
float angleTwo = AStart + (angleLinear* (iii+1) / nbOcurence) ;
offsety = sin(angleTwo) * radius;
offsetx = cos(angleTwo) * radius;
SetPoint(x + offsetx, y + offsety);
}
}

View File

@ -1,53 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_O_OBJECT_2D_COLORED_H__
#define __EWOL_O_OBJECT_2D_COLORED_H__
#include <ewol/oObject/OObject.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class OObject2DColored :public ewol::OObject
{
public:
OObject2DColored(void);
virtual ~OObject2DColored(void);
public:
virtual void Draw(void);
protected:
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLColor;
etk::Vector<etk::Vector2D<float> > m_coord; //!< internal coord of the object
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
draw::Colorf m_color[3];
int32_t m_triElement;
etk::Vector2D<float> m_triangle[3];
void GenerateTriangle(void);
void ResetCount(void);
public:
void Clear(void);
void SetColor(float red, float green, float blue, float alpha = 1.0);
void SetColor(draw::Color color);
void SetPoint(etk::Vector2D<float> point);
void SetPoint(float x, float y);
void Line(float sx, float sy, float ex, float ey, float thickness);
void Rectangle(float x, float y, float w, float h);
void RectangleBorder(float x, float y, float w, float h, float thickness);
void Circle(float x, float y, float radius, float thickness);
void CirclePart(float x, float y, float radius, float thickness, float angleStart, float angleStop);
void Disc(float x, float y, float radius);
void DiscPart(float x, float y, float radius, float angleStart, float angleStop);
};
};
#endif

View File

@ -1,201 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/oObject/2DTextColored.h>
#include <ewol/openGL/openGL.h>
#include <ewol/texture/Texture.h>
#include <ewol/font/FontManager.h>
#include <ewol/ResourceManager.h>
#undef __class__
#define __class__ "ewol::OObject2DTextColored"
void ewol::OObject2DTextColored::SetFontProperty(etk::UString fontName, int32_t fontSize)
{
// remove old one
if (NULL != m_font) {
ewol::resource::Release(m_font);
m_font = NULL;
}
etk::UString tmpName = fontName;
tmpName += ":";
tmpName += fontSize;
// link to new One
if (false == ewol::resource::Keep(tmpName, m_font)) {
EWOL_ERROR("Can not get font resource");
}
}
void ewol::OObject2DTextColored::SetFont(etk::UString fontName)
{
// get old size
int32_t fontSize = ewol::font::GetDefaultSize();
if (NULL != m_font) {
fontSize = m_font->GetFontSize();
}
SetFontProperty(fontName, fontSize);
}
void ewol::OObject2DTextColored::SetSize(int32_t fontSize)
{
// get old size
etk::UString fontName = ewol::font::GetDefaultFont();
if (NULL != m_font) {
fontName = m_font->GetName();
}
SetFontProperty(fontName, fontSize);
}
ewol::OObject2DTextColored::OObject2DTextColored(etk::UString fontName, int32_t size) :
m_font(NULL)
{
m_color = draw::color::black;
SetFontProperty(fontName, size);
etk::UString tmpString("DATA:text.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
}
}
// open with default font ...
ewol::OObject2DTextColored::OObject2DTextColored(void) :
m_font(NULL)
{
m_color = draw::color::black;
SetFontProperty(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize());
etk::UString tmpString("DATA:text.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
}
}
ewol::OObject2DTextColored::~OObject2DTextColored(void)
{
if (NULL != m_font) {
ewol::resource::Release(m_font);
m_font = NULL;
}
ewol::resource::Release(m_GLprogram);
}
void ewol::OObject2DTextColored::Draw(void)
{
if (m_coord.Size()<=0 || NULL == m_font) {
// TODO : a remètre ...
//EWOL_WARNING("Nothink to draw...");
return;
}
if (m_font == NULL) {
EWOL_WARNING("no font...");
return;
}
if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ...");
return;
}
m_GLprogram->Use();
// set Matrix : translation/positionMatrix
etk::Matrix4 tmpMatrix = ewol::openGL::GetMatrix();
m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
// TextureID
m_GLprogram->SetTexture0(m_GLtexID, m_font->GetId());
// position :
m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, &m_coord[0]);
// Texture :
m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]);
// color :
m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
// Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
m_GLprogram->UnUse();
}
void ewol::OObject2DTextColored::Clear(void)
{
m_coord.Clear();
m_coordTex.Clear();
m_coordColor.Clear();
m_displayMode.Clear();
}
int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const etk::UString& unicodeString, ewol::font::mode_te displayMode)
{
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return 0;
}
int32_t nbElementInTheArray = m_coord.Size();
int32_t size = 0;
size = m_font->Draw(textPos, unicodeString, m_coord, m_coordTex, m_displayMode, m_hasClipping, m_clipping, displayMode);
// set the color ...
for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) {
m_coordColor.PushBack(m_color);
}
return size;
}
int32_t ewol::OObject2DTextColored::Text(etk::Vector2D<float> textPos, const uniChar_t unicodeChar, ewol::font::mode_te displayMode)
{
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return 0;
}
int32_t nbElementInTheArray = m_coord.Size();
int32_t size = 0;
size = m_font->Draw(textPos, unicodeChar, m_coord, m_coordTex, m_displayMode, m_hasClipping, m_clipping, displayMode);
for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) {
m_coordColor.PushBack(m_color);
}
return size;
}
void ewol::OObject2DTextColored::SetColor(draw::Color color)
{
m_color = color;
}
void ewol::OObject2DTextColored::SetColor(float red, float green, float blue, float alpha)
{
m_color = draw::Color(red, green, blue, alpha);
}
etk::Vector2D<float> ewol::OObject2DTextColored::GetSize(const uniChar_t unicodeChar)
{
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return etk::Vector2D<float>(0,0);
}
return m_font->GetSize(unicodeChar);
}
etk::Vector2D<float> ewol::OObject2DTextColored::GetSize(const etk::UString& unicodeString)
{
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return etk::Vector2D<float>(0,0);
}
return m_font->GetSize(unicodeString);
}

View File

@ -1,57 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_O_OBJECT_2D_TEXT_COLORED_H__
#define __EWOL_O_OBJECT_2D_TEXT_COLORED_H__
#include <ewol/oObject/OObject.h>
#include <ewol/font/TexturedFont.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class OObject2DTextColored :public ewol::OObject
{
public:
OObject2DTextColored(etk::UString FontName, int32_t size);
OObject2DTextColored(void);
virtual ~OObject2DTextColored(void);
public:
virtual void Draw(void);
void SetColor(float red, float green, float blue, float alpha = 1.0);
void SetColor(draw::Color color);
// set a specific text
void Clear(void);
int32_t Text(etk::Vector2D<float> textPos, const etk::UString& unicodeString, ewol::font::mode_te displayMode = ewol::font::Regular);
int32_t Text(etk::Vector2D<float> textPos, const uniChar_t unicodeChar, ewol::font::mode_te displayMode = ewol::font::Regular);
protected:
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLColor;
int32_t m_GLtextMode;
int32_t m_GLtexture;
int32_t m_GLtexID;
ewol::TexturedFont* m_font; //!< ewol font system
draw::Color m_color; //!< tmp text color ...
etk::Vector<etk::Vector2D<float> > m_coord; //!< internal coord of the object
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
etk::Vector<int32_t> m_displayMode; //!< Display mode availlable (bold/...)
public:
void SetFont(etk::UString fontName);
void SetSize(int32_t fontSize);
void SetFontProperty(etk::UString fontName, int32_t fontSize);
int32_t GetHeight(void) { return (NULL!=m_font)?m_font->GetHeight():10; };
etk::Vector2D<float> GetSize(const uniChar_t unicodeChar);
etk::Vector2D<float> GetSize(const etk::UString& unicodeString);
};
};
#endif

View File

@ -1,224 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/oObject/2DTextShader.h>
#include <ewol/openGL/openGL.h>
#include <ewol/texture/Texture.h>
#include <ewol/font/FontManager.h>
#include <ewol/ResourceManager.h>
#undef __class__
#define __class__ "ewol::OObject2DTextShader"
float DF_SoftEdge_min = 0.45;
float DF_SoftEdge_max = 0.55;
int32_t DF_SoftEdge = 0;
void ewol::OObject2DTextShader::SetFontProperty(etk::UString fontName, int32_t fontSize)
{
// remove old one
if (NULL != m_font) {
ewol::resource::Release(m_font);
m_font = NULL;
}
etk::UString tmpName = fontName;
tmpName += ":";
tmpName += fontSize;
// link to new One
if (false == ewol::resource::Keep(tmpName, m_font)) {
EWOL_ERROR("Can not get font resource");
}
}
void ewol::OObject2DTextShader::SetFont(etk::UString fontName)
{
// get old size
int32_t fontSize = ewol::font::GetDefaultSize();
if (NULL != m_font) {
fontSize = m_font->GetFontSize();
}
SetFontProperty(fontName, fontSize);
}
void ewol::OObject2DTextShader::SetSize(int32_t fontSize)
{
// get old size
etk::UString fontName = ewol::font::GetDefaultFont();
if (NULL != m_font) {
fontName = m_font->GetName();
}
SetFontProperty(fontName, fontSize);
}
ewol::OObject2DTextShader::OObject2DTextShader(etk::UString fontName, int32_t size) :
m_font(NULL)
{
m_color = draw::color::black;
SetFontProperty(fontName, size);
etk::UString tmpString("DATA:fontDistanceField/font1.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
m_GLSoftEdgeMin = m_GLprogram->GetUniform("EW_SoftEdgeMin");
m_GLSoftEdgeMax = m_GLprogram->GetUniform("EW_SoftEdgeMax");
m_GLSoftEdge = m_GLprogram->GetUniform("EW_SoftEdge");
}
}
// open with default font ...
ewol::OObject2DTextShader::OObject2DTextShader(void) :
m_font(NULL)
{
m_color = draw::color::black;
SetFontProperty(ewol::font::GetDefaultFont(), ewol::font::GetDefaultSize());
etk::UString tmpString("DATA:fontDistanceField/font1.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
m_GLSoftEdgeMin = m_GLprogram->GetUniform("EW_SoftEdgeMin");
m_GLSoftEdgeMax = m_GLprogram->GetUniform("EW_SoftEdgeMax");
m_GLSoftEdge = m_GLprogram->GetUniform("EW_SoftEdge");
}
}
ewol::OObject2DTextShader::~OObject2DTextShader(void)
{
if (NULL != m_font) {
ewol::resource::Release(m_font);
m_font = NULL;
}
ewol::resource::Release(m_GLprogram);
}
void ewol::OObject2DTextShader::Draw(void)
{
if (m_coord.Size()<=0 || NULL == m_font) {
// TODO : a remètre ...
//EWOL_WARNING("Nothink to draw...");
return;
}
if (m_font == NULL) {
EWOL_WARNING("no font...");
return;
}
if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ...");
return;
}
m_GLprogram->Use();
// set Matrix : translation/positionMatrix
etk::Matrix4 tmpMatrix = ewol::openGL::GetMatrix();
m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
// TextureID
m_GLprogram->SetTexture0(m_GLtexID, m_font->GetId());
// position :
m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, &m_coord[0]);
// Texture :
m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]);
// color :
m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
// set some other specific properties :
m_GLprogram->Uniform1f(m_GLSoftEdgeMin, DF_SoftEdge_min);
m_GLprogram->Uniform1f(m_GLSoftEdgeMax, DF_SoftEdge_max);
m_GLprogram->Uniform1i(m_GLSoftEdge, DF_SoftEdge);
// Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
m_GLprogram->UnUse();
}
void ewol::OObject2DTextShader::Clear(void)
{
m_coord.Clear();
m_coordTex.Clear();
m_coordColor.Clear();
}
int32_t ewol::OObject2DTextShader::Text(etk::Vector2D<float> textPos, const etk::UString& unicodeString)
{
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return 0;
}
int32_t nbElementInTheArray = m_coord.Size();
int32_t size = 0;
if (true==m_hasClipping) {
size = m_font->Draw(textPos, unicodeString, m_coord, m_coordTex);
} else {
size = m_font->Draw(textPos, unicodeString, m_coord, m_coordTex);
}
// set the color ...
for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) {
m_coordColor.PushBack(m_color);
}
return size;
}
int32_t ewol::OObject2DTextShader::Text(etk::Vector2D<float> textPos, const uniChar_t unicodeChar)
{
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return 0;
}
int32_t nbElementInTheArray = m_coord.Size();
int32_t size = 0;
if (true==m_hasClipping) {
size = m_font->Draw(textPos, unicodeChar, m_coord, m_coordTex);
} else {
size = m_font->Draw(textPos, unicodeChar, m_coord, m_coordTex);
}
for (int32_t iii=nbElementInTheArray; iii<m_coord.Size(); iii++) {
m_coordColor.PushBack(m_color);
}
return size;
}
void ewol::OObject2DTextShader::SetColor(draw::Color color)
{
m_color = color;
}
void ewol::OObject2DTextShader::SetColor(float red, float green, float blue, float alpha)
{
m_color = draw::Color(red, green, blue, alpha);
}
etk::Vector2D<float> ewol::OObject2DTextShader::GetSize(const uniChar_t unicodeChar)
{
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return etk::Vector2D<float>(0,0);
}
return m_font->GetSize(unicodeChar);
}
etk::Vector2D<float> ewol::OObject2DTextShader::GetSize(const etk::UString& unicodeString)
{
if (m_font == NULL) {
EWOL_ERROR("Font Id is not corectly defined");
return etk::Vector2D<float>(0,0);
}
return m_font->GetSize(unicodeString);
}

View File

@ -1,61 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_O_OBJECT_2D_TEXT_SHADER_H__
#define __EWOL_O_OBJECT_2D_TEXT_SHADER_H__
#include <ewol/oObject/OObject.h>
#include <ewol/font/DistantFieldFont.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class OObject2DTextShader :public ewol::OObject
{
public:
OObject2DTextShader(etk::UString FontName, int32_t size);
OObject2DTextShader(void);
virtual ~OObject2DTextShader(void);
public:
virtual void Draw(void);
void SetColor(float red, float green, float blue, float alpha = 1.0);
void SetColor(draw::Color color);
// set a specific text
void Clear(void);
int32_t Text(etk::Vector2D<float> textPos, const etk::UString& unicodeString);
int32_t Text(etk::Vector2D<float> textPos, const uniChar_t unicodeChar);
protected:
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLColor;
int32_t m_GLtexture;
int32_t m_GLtexID;
int32_t m_GLSoftEdgeMin;
int32_t m_GLSoftEdgeMax;
int32_t m_GLSoftEdge;
ewol::DistantFieldFont* m_font; //!< ewol font system
draw::Color m_color; //!< tmp text color ...
etk::Vector<etk::Vector2D<float> > m_coord; //!< internal coord of the object
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
bool m_bold;
bool m_italic;
public:
void SetBold(bool newVal) { m_bold=newVal; };
void SetItalic(bool newVal) { m_italic=newVal; };
void SetFont(etk::UString fontName);
void SetSize(int32_t fontSize);
void SetFontProperty(etk::UString fontName, int32_t fontSize);
int32_t GetHeight(void) { return (NULL!=m_font)?m_font->GetHeight():10; };
etk::Vector2D<float> GetSize(const uniChar_t unicodeChar);
etk::Vector2D<float> GetSize(const etk::UString& unicodeString);
};
};
#endif

View File

@ -1,170 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/oObject/2DTextured.h>
#include <ewol/ResourceManager.h>
#include <ewol/openGL/openGL.h>
#undef __class__
#define __class__ "ewol::OObject2DTextured"
ewol::OObject2DTextured::OObject2DTextured(etk::UString textureName, float sizeX, float sizeY)
{
EWOL_VERBOSE("Create OObject textured : \"" << textureName << "\"");
ewol::TextureFile* resourceFile = NULL;
if (false == ewol::resource::Keep(textureName, resourceFile, etk::Vector2D<int32_t>(sizeX,sizeY)) ) {
EWOL_CRITICAL("can not get a resource Texture");
}
m_resource = resourceFile;
etk::UString tmpString("DATA:textured.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
}
}
ewol::OObject2DTextured::OObject2DTextured( float sizeX, float sizeY)
{
if (false == ewol::resource::Keep(m_resource) ) {
EWOL_CRITICAL("can not get a resource Texture");
}
if (NULL!=m_resource) {
m_resource->SetImageSize(etk::Vector2D<int32_t>(sizeX,sizeY));
draw::Image& tmpImage = m_resource->Get();
tmpImage.SetFillColor(draw::color::black);
tmpImage.Clear();
m_resource->Flush();
}
etk::UString tmpString("DATA:textured.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
}
}
ewol::OObject2DTextured::~OObject2DTextured(void)
{
if (NULL != m_resource) {
ewol::resource::Release(m_resource);
}
ewol::resource::Release(m_GLprogram);
}
void ewol::OObject2DTextured::Draw(void)
{
if (m_coord.Size()<=0) {
return;
}
if (NULL == m_resource) {
EWOL_WARNING("Texture does not exist ...");
return;
}
if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ...");
return;
}
m_GLprogram->Use();
// set Matrix : translation/positionMatrix
etk::Matrix4 tmpMatrix = ewol::openGL::GetMatrix();
m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
// TextureID
m_GLprogram->SetTexture0(m_GLtexID, m_resource->GetId());
// position :
m_GLprogram->SendAttribute(m_GLPosition, 2/*x,y*/, &m_coord[0]);
// Texture :
m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]);
// color :
m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
// Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
m_GLprogram->UnUse();
}
void ewol::OObject2DTextured::Clear(void)
{
m_coord.Clear();
m_coordTex.Clear();
m_coordColor.Clear();
}
void ewol::OObject2DTextured::Rectangle(float x, float y, float w, float h, draw::Color tmpColor)
{
Rectangle(x, y, w, h, 0.0, 0.0, 1.0, 1.0, tmpColor);
}
void ewol::OObject2DTextured::Rectangle(float x, float y, float w, float h, float texX, float texY, float texSX, float texSY, draw::Color tmpColor)
{
/*
x += 3;
y += 3;
w -= 6;
h -= 6;
*/
//EWOL_DEBUG("Add rectangle : ...");
etk::Vector2D<float> point;
texCoord_ts tex;
tex.u = texX;
tex.v = texSY;
point.x = x;
point.y = y;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
tex.u = texSX;
tex.v = texSY;
point.x = x + w;
point.y = y;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
tex.u = texSX;
tex.v = texY;
point.x = x + w;
point.y = y + h;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
tex.u = texX;
tex.v = texY;
point.x = x;
point.y = y + h;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
tex.u = texX;
tex.v = texSY;
point.x = x;
point.y = y;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
}

View File

@ -1,58 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_O_OBJECT_2D_TEXTURED_H__
#define __EWOL_O_OBJECT_2D_TEXTURED_H__
#include <ewol/oObject/OObject.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class OObject2DTextured :public ewol::OObject
{
public:
OObject2DTextured(etk::UString textureName, float sizeX=-1, float sizeY=-1);
OObject2DTextured(float sizeX=-1, float sizeY=-1);
virtual ~OObject2DTextured(void);
public:
virtual void Draw(void);
void Clear(void);
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);
protected:
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLColor;
int32_t m_GLtexture;
int32_t m_GLtexID;
ewol::Texture* m_resource; //!< texture resources
etk::Vector<etk::Vector2D<float> > m_coord; //!< internal coord of the object
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
public:
draw::Image* GetImage(void)
{
if (NULL == m_resource) {
return NULL;
}
draw::Image& tmpImage = m_resource->Get();
return &tmpImage;
};
void Flush(void)
{
if (NULL != m_resource) {
m_resource->Flush();
}
}
};
};
#endif

View File

@ -1,145 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/oObject/3DTextured.h>
#include <ewol/ResourceManager.h>
#include <ewol/openGL/openGL.h>
#undef __class__
#define __class__ "ewol::OObject3DTextured"
ewol::OObject3DTextured::OObject3DTextured(etk::UString textureName, float sizeX, float sizeY)
{
EWOL_VERBOSE("Create OObject textured : \"" << textureName << "\"");
if (false == ewol::resource::Keep(textureName, m_resource, etk::Vector2D<int32_t>(sizeX,sizeY)) ) {
EWOL_CRITICAL("can not get a resource Texture");
}
etk::UString tmpString("DATA:textured3D.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d");
m_GLColor = m_GLprogram->GetAttribute("EW_color");
m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLtexID = m_GLprogram->GetUniform("EW_texID");
}
}
ewol::OObject3DTextured::~OObject3DTextured(void)
{
if (NULL != m_resource) {
ewol::resource::Release(m_resource);
}
ewol::resource::Release(m_GLprogram);
}
void ewol::OObject3DTextured::Draw(void)
{
if (m_coord.Size()<=0) {
return;
}
if (NULL == m_resource) {
EWOL_WARNING("Texture does not exist ...");
return;
}
if (m_GLprogram==NULL) {
EWOL_ERROR("No shader ...");
return;
}
//EWOL_DEBUG(" Display " << m_coord.Size() << " elements" );
m_GLprogram->Use();
// set Matrix : translation/positionMatrix
etk::Matrix4 tmpMatrix = ewol::openGL::GetMatrix();
m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat);
// TextureID
m_GLprogram->SetTexture0(m_GLtexID, m_resource->GetId());
// position :
m_GLprogram->SendAttribute(m_GLPosition, 3/*x,y,z*/, &m_coord[0]);
// Texture :
m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]);
// color :
m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]);
// Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
m_GLprogram->UnUse();
}
void ewol::OObject3DTextured::Clear(void)
{
m_coord.Clear();
m_coordTex.Clear();
m_coordColor.Clear();
}
void ewol::OObject3DTextured::Rectangle(float x, float y, float w, float h, draw::Color tmpColor)
{
Rectangle(x, y, w, h, 0.0, 0.0, 1.0, 1.0, tmpColor);
}
void ewol::OObject3DTextured::Rectangle(float x, float y, float w, float h, float texX, float texY, float texSX, float texSY, draw::Color tmpColor)
{
/*
x += 3;
y += 3;
w -= 6;
h -= 6;
*/
//EWOL_DEBUG("Add rectangle : ...");
etk::Vector3D<float> point;
texCoord_ts tex;
point.z = 0;
tex.u = texX;
tex.v = texSY;
point.x = x;
point.y = y;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
tex.u = texSX;
tex.v = texSY;
point.x = x + w;
point.y = y;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
tex.u = texSX;
tex.v = texY;
point.x = x + w;
point.y = y + h;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
tex.u = texX;
tex.v = texY;
point.x = x;
point.y = y + h;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
tex.u = texX;
tex.v = texSY;
point.x = x;
point.y = y;
m_coord.PushBack(point);
m_coordTex.PushBack(tex);
m_coordColor.PushBack(tmpColor);
}

View File

@ -1,42 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_O_OBJECT_3D_TEXTURED_H__
#define __EWOL_O_OBJECT_3D_TEXTURED_H__
#include <ewol/oObject/OObject.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class OObject3DTextured :public ewol::OObject
{
public:
OObject3DTextured(etk::UString textureName, float sizeX=-1, float sizeY=-1);
virtual ~OObject3DTextured(void);
public:
virtual void Draw(void);
void Clear(void);
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);
protected:
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLColor;
int32_t m_GLtexture;
int32_t m_GLtexID;
ewol::TextureFile* m_resource; //!< texture resources
etk::Vector<etk::Vector3D<float> > m_coord; //!< internal coord of the object
etk::Vector<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
etk::Vector<draw::Colorf> m_coordColor; //!< internal color of the different point
};
};
#endif

View File

@ -1,35 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <etk/Types.h>
#include <etk/UString.h>
#include <ewol/oObject/OObject.h>
#undef __class__
#define __class__ "ewol::OObject"
ewol::OObject::OObject(void)
{
m_hasClipping = false;
m_scaling.x = 1.0;
m_scaling.y = 1.0;
m_clipping.x = 0;
m_clipping.y = 0;
m_clipping.w = 1024;
m_clipping.h = 1024;
m_nbLoadedTime = 1;
}
ewol::OObject::~OObject(void)
{
}

View File

@ -1,60 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_O_OBJECT_H__
#define __EWOL_O_OBJECT_H__
#include <etk/Types.h>
#include <draw/Color.h>
#include <ewol/Debug.h>
#include <ewol/font/Font.h>
#include <etk/Vector.h>
namespace ewol {
extern "C" {
typedef struct {
int32_t f;
int32_t s;
int32_t t;
}linkCoord_ts;
};
class OObject
{
protected:
int32_t m_nbLoadedTime; //!< specific in case of non multiple allocation
bool m_hasClipping;
clipping_ts m_clipping;
etk::Vector2D<float> m_scaling; //!< scaling ol the object
public:
OObject(void);
virtual ~OObject(void);
void clippingSet(clipping_ts clip) {m_clipping = clip; m_hasClipping = true;};
void clippingDisable(void) {m_hasClipping = false;};
void clippingEnable(void) {m_hasClipping = true;};
void scalingSet(etk::Vector2D<float> scale) {m_scaling = scale;};
virtual void Draw(void) = 0;
/**
* @brief Increase the number of element registered on this class ==> this is specific to decrese the memory usage in special case (scene)
*/
void IncreaseLoadedTime(void) { m_nbLoadedTime++;};
/**
* @brief Decrease the number of element registered on this class ==> this is specific to decrese the memory usage in special case (scene)
* @return true, if no more element registered on it ...
*/
bool DecreaseLoadedTime(void) { m_nbLoadedTime--; if (m_nbLoadedTime <= 0) { return true;} else { return false;} };
};
};
#endif
#include <ewol/oObject/2DTextured.h>
#include <ewol/oObject/2DColored.h>
#include <ewol/oObject/2DTextColored.h>
#include <ewol/oObject/2DTextShader.h>

View File

@ -1,109 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#include <ewol/oObject/Sprite.h>
#include <ewol/ResourceManager.h>
#include <ewol/openGL/openGL.h>
#include <math.h>
#undef __class__
#define __class__ "Sprite"
ewol::Sprite::Sprite(etk::UString spriteName, float sizeX, float sizeY) :
ewol::OObject3DTextured(spriteName, sizeX, sizeY)
{
m_name = spriteName;
}
ewol::Sprite::~Sprite(void)
{
}
void ewol::Sprite::Element(etk::Vector2D<float> pos, float size, float angle)
{
draw::Color tmpColor(0xFFFFFFFF);
etk::Vector3D<float> pos2;
pos2.x = pos.x;
pos2.y = pos.y;
pos2.z = 0.0;
Element(pos2, size, angle, tmpColor);
}
void ewol::Sprite::Element(etk::Vector3D<float> pos, float size, float angle)
{
draw::Color tmpColor(0xFFFFFFFF);
Element(pos, size, angle, tmpColor);
}
void ewol::Sprite::Element(etk::Vector2D<float> pos, float size, float angle, draw::Color tmpColor)
{
etk::Vector3D<float> pos2;
pos2.x = pos.x;
pos2.y = pos.y;
pos2.z = 0.0;
Element(pos2, size, angle, tmpColor);
}
void ewol::Sprite::Element(etk::Vector3D<float> pos, float size, float angle, draw::Color tmpColor)
{
angle -= M_PI/4;
size *= 0.7;
texCoord_ts texA, texB, texC, texD;
texA.u = 0.0;
texA.v = 0.0;
texB.u = 0.0;
texB.v = 1.0;
texC.u = 1.0;
texC.v = 1.0;
texD.u = 1.0;
texD.v = 0.0;
draw::Colorf localColor = tmpColor;
etk::Vector3D<float> point = pos;
float yyySin = sin(angle) * size;
float xxxCos = cos(angle) * size;
point.x = xxxCos + pos.x;
point.y = yyySin + pos.y;
m_coord.PushBack(point);
m_coordTex.PushBack(texB);
m_coordColor.PushBack(localColor);
point.x = yyySin + pos.x;
point.y = -xxxCos + pos.y;
m_coord.PushBack(point);
m_coordTex.PushBack(texC);
m_coordColor.PushBack(localColor);
point.x = -xxxCos + pos.x;
point.y = -yyySin + pos.y;
m_coord.PushBack(point);
m_coordTex.PushBack(texD);
m_coordColor.PushBack(localColor);
m_coord.PushBack(point);
m_coordTex.PushBack(texD);
m_coordColor.PushBack(localColor);
point.x = -yyySin + pos.x;
point.y = xxxCos + pos.y;
m_coord.PushBack(point);
m_coordTex.PushBack(texA);
m_coordColor.PushBack(localColor);
point.x = xxxCos + pos.x;
point.y = yyySin + pos.y;
m_coord.PushBack(point);
m_coordTex.PushBack(texB);
m_coordColor.PushBack(localColor);
}

View File

@ -1,32 +0,0 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD v3 (see license file)
*/
#ifndef __EWOL_O_OBJECT_SPRITE_H__
#define __EWOL_O_OBJECT_SPRITE_H__
#include <ewol/oObject/3DTextured.h>
#include <ewol/ResourceManager.h>
namespace ewol {
class Sprite :public ewol::OObject3DTextured
{
private:
etk::UString m_name;
public:
Sprite(etk::UString spriteName, float sizeX=-1, float sizeY=-1);
virtual ~Sprite(void);
void Element(etk::Vector2D<float> pos, float size, float angle);
void Element(etk::Vector3D<float> pos, float size, float angle);
void Element(etk::Vector2D<float> pos, float size, float angle, draw::Color tmpColor);
void Element(etk::Vector3D<float> pos, float size, float angle, draw::Color tmpColor);
bool HasName(etk::UString& name) { return name == m_name; };
};
};
#endif

View File

@ -365,6 +365,25 @@ void AddDecoration(void)
}
}
static void setVSync(bool sync)
{
// Function pointer for the wgl extention function we need to enable/disable
typedef int32_t (APIENTRY *PFNWGLSWAPINTERVALPROC)( int );
PFNWGLSWAPINTERVALPROC wglSwapIntervalEXT = 0;
const char *extensions = (char*)glGetString( GL_EXTENSIONS );
if( strstr( extensions, "WGL_EXT_swap_control" ) == 0 ) {
EWOL_ERROR("Can not set the vertical synchronisation status" << sync);
return;
} else {
wglSwapIntervalEXT = (PFNWGLSWAPINTERVALPROC)glXGetProcAddress( (const GLubyte *)"wglSwapIntervalEXT" );
if(wglSwapIntervalEXT) {
wglSwapIntervalEXT(sync);
} else {
EWOL_ERROR("Can not set the vertical synchronisation status" << sync);
}
}
}
bool CreateOGlContext(void)
{
#ifdef DEBUG_X11_EVENT
@ -379,6 +398,10 @@ bool CreateOGlContext(void)
} else {
EWOL_INFO("XF86 DRI NOT available\n");
}
// Enable vertical synchronisation : (some computer has synchronisation disable)
setVSync(true);
return true;
}

View File

@ -15,7 +15,7 @@ ewol::Mesh::Mesh(etk::UString genName) :
ewol::Resource(genName),
m_texture1(NULL)
{
etk::UString tmpString("textured3D.prog");
etk::UString tmpString("DATA:textured3D.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
@ -56,6 +56,7 @@ void ewol::Mesh::Draw(void)
EWOL_ERROR("No shader ...");
return;
}
glEnable(GL_DEPTH_TEST);
//EWOL_DEBUG(" Display " << m_coord.Size() << " elements" );
m_GLprogram->Use();
// set Matrix : translation/positionMatrix
@ -78,5 +79,6 @@ void ewol::Mesh::Draw(void)
// Request the draw od the elements :
glDrawArrays(GL_TRIANGLES, 0, m_vertices.Size());
m_GLprogram->UnUse();
glDisable(GL_DEPTH_TEST);
}

View File

@ -16,7 +16,7 @@
ewol::MeshObj::MeshObj(etk::UString _fileName) :
ewol::Mesh(_fileName)
{
etk::FSNode fileName(etk::UString("DATA:") + _fileName);
etk::FSNode fileName(_fileName);
// Get the fileSize ...
int32_t size = fileName.FileSize();
if (size == 0 ) {
@ -27,7 +27,7 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
EWOL_ERROR("Can not find the file name=\"" << fileName << "\"");
return;
}
char inputDataLine[2018];
char inputDataLine[2048];
etk::Vector<int32_t> indicesVertices;
@ -104,7 +104,8 @@ ewol::MeshObj::MeshObj(etk::UString _fileName) :
EWOL_INFO("Release previous loaded texture ... ");
ewol::resource::Release(m_texture1);
}
if (false == ewol::resource::Keep(tmpVal, m_texture1, tmpSize)) {
etk::UString tmpFilename = fileName.GetRelativeFolder() + tmpVal;
if (false == ewol::resource::Keep(tmpFilename, m_texture1, tmpSize)) {
EWOL_ERROR("Can not load specific texture : " << tmpVal);
}
} else if( inputDataLine[0]=='m'

View File

@ -404,56 +404,6 @@ void ewol::Program::Uniform4i(int32_t idElem, int32_t value1, int32_t value2, in
checkGlError("glUniform4i", __LINE__);
}
//////////////////////////////////////////////////////////////////////////////////////////////
void ewol::Program::Uniform1ui(int32_t idElem, uint32_t value1)
{
if (idElem<0 || idElem>m_elementList.Size()) {
EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]");
return;
}
if (false == m_elementList[idElem].m_isLinked) {
return;
}
glUniform1ui(m_elementList[idElem].m_elementId, value1);
checkGlError("glUniform1ui", __LINE__);
}
void ewol::Program::Uniform2ui(int32_t idElem, uint32_t value1, uint32_t value2)
{
if (idElem<0 || idElem>m_elementList.Size()) {
EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]");
return;
}
if (false == m_elementList[idElem].m_isLinked) {
return;
}
glUniform2ui(m_elementList[idElem].m_elementId, value1, value2);
checkGlError("glUniform2ui", __LINE__);
}
void ewol::Program::Uniform3ui(int32_t idElem, uint32_t value1, uint32_t value2, uint32_t value3)
{
if (idElem<0 || idElem>m_elementList.Size()) {
EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]");
return;
}
if (false == m_elementList[idElem].m_isLinked) {
return;
}
glUniform3ui(m_elementList[idElem].m_elementId, value1, value2, value3);
checkGlError("glUniform3ui", __LINE__);
}
void ewol::Program::Uniform4ui(int32_t idElem, uint32_t value1, uint32_t value2, uint32_t value3, uint32_t value4)
{
if (idElem<0 || idElem>m_elementList.Size()) {
EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]");
return;
}
if (false == m_elementList[idElem].m_isLinked) {
return;
}
glUniform4ui(m_elementList[idElem].m_elementId, value1, value2, value3, value4);
checkGlError("glUniform4ui", __LINE__);
}
//////////////////////////////////////////////////////////////////////////////////////////////
@ -621,88 +571,6 @@ void ewol::Program::Uniform4iv(int32_t idElem, int32_t nbElement, int32_t *value
checkGlError("glUniform4iv", __LINE__);
}
//////////////////////////////////////////////////////////////////////////////////////////////
void ewol::Program::Uniform1uiv(int32_t idElem, int32_t nbElement, uint32_t *value)
{
if (idElem<0 || idElem>m_elementList.Size()) {
EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]");
return;
}
if (false == m_elementList[idElem].m_isLinked) {
return;
}
if (0==nbElement) {
EWOL_ERROR("No element to send at open GL ...");
return;
}
if (NULL==value) {
EWOL_ERROR("NULL Input pointer to send at open GL ...");
return;
}
glUniform1uiv(m_elementList[idElem].m_elementId, nbElement, value);
checkGlError("glUniform1uiv", __LINE__);
}
void ewol::Program::Uniform2uiv(int32_t idElem, int32_t nbElement, uint32_t *value)
{
if (idElem<0 || idElem>m_elementList.Size()) {
EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]");
return;
}
if (false == m_elementList[idElem].m_isLinked) {
return;
}
if (0==nbElement) {
EWOL_ERROR("No element to send at open GL ...");
return;
}
if (NULL==value) {
EWOL_ERROR("NULL Input pointer to send at open GL ...");
return;
}
glUniform2uiv(m_elementList[idElem].m_elementId, nbElement, value);
checkGlError("glUniform2uiv", __LINE__);
}
void ewol::Program::Uniform3uiv(int32_t idElem, int32_t nbElement, uint32_t *value)
{
if (idElem<0 || idElem>m_elementList.Size()) {
EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]");
return;
}
if (false == m_elementList[idElem].m_isLinked) {
return;
}
if (0==nbElement) {
EWOL_ERROR("No element to send at open GL ...");
return;
}
if (NULL==value) {
EWOL_ERROR("NULL Input pointer to send at open GL ...");
return;
}
glUniform3uiv(m_elementList[idElem].m_elementId, nbElement, value);
checkGlError("glUniform3uiv", __LINE__);
}
void ewol::Program::Uniform4uiv(int32_t idElem, int32_t nbElement, uint32_t *value)
{
if (idElem<0 || idElem>m_elementList.Size()) {
EWOL_ERROR("idElem = " << idElem << " not in [0.." << (m_elementList.Size()-1) << "]");
return;
}
if (false == m_elementList[idElem].m_isLinked) {
return;
}
if (0==nbElement) {
EWOL_ERROR("No element to send at open GL ...");
return;
}
if (NULL==value) {
EWOL_ERROR("NULL Input pointer to send at open GL ...");
return;
}
glUniform4uiv(m_elementList[idElem].m_elementId, nbElement, value);
checkGlError("glUniform4uiv", __LINE__);
}
//////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -157,37 +157,6 @@ namespace ewol
*/
void Uniform4i(int32_t idElem, int32_t value1, int32_t value2, int32_t value3, int32_t value4);
/**
* @brief Send 1 unsigned integer uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] value1 Value to send at the Uniform
*/
void Uniform1ui(int32_t idElem, uint32_t value1);
/**
* @brief Send 2 unsigned integer uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] value1 Value to send at the Uniform
* @param[in] value2 Value to send at the Uniform
*/
void Uniform2ui(int32_t idElem, uint32_t value1, uint32_t value2);
/**
* @brief Send 3 unsigned integer uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] value1 Value to send at the Uniform
* @param[in] value2 Value to send at the Uniform
* @param[in] value3 Value to send at the Uniform
*/
void Uniform3ui(int32_t idElem, uint32_t value1, uint32_t value2, uint32_t value3);
/**
* @brief Send 4 unsigned integer uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] value1 Value to send at the Uniform
* @param[in] value2 Value to send at the Uniform
* @param[in] value3 Value to send at the Uniform
* @param[in] value4 Value to send at the Uniform
*/
void Uniform4ui(int32_t idElem, uint32_t value1, uint32_t value2, uint32_t value3, uint32_t value4);
/**
* @brief Send "vec1" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
@ -246,35 +215,6 @@ namespace ewol
*/
void Uniform4iv(int32_t idElem, int32_t nbElement, int32_t *value);
/**
* @brief Send "uvec1" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the Attribute that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform1uiv(int32_t idElem, int32_t nbElement, uint32_t *value);
/**
* @brief Send "uvec2" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform2uiv(int32_t idElem, int32_t nbElement, uint32_t *value);
/**
* @brief Send "uvec3" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform3uiv(int32_t idElem, int32_t nbElement, uint32_t *value);
/**
* @brief Send "uvec4" uniform element to the spefified ID (not send if does not really exist in the OpenGL program)
* @param[in] idElem Id of the uniform that might be sended.
* @param[in] nbElement Number of element sended
* @param[in] value Pointer on the data
*/
void Uniform4uiv(int32_t idElem, int32_t nbElement, uint32_t *value);
/**
* @brief Request the processing of this program
*/

View File

@ -24,7 +24,7 @@ static void local_ReadData(png_structp png_ptr, png_bytep data, png_size_t lengt
fileNode->FileRead(data, 1, length);
}
}
/*
static void LocalWriteData(png_structp png_ptr, png_bytep data, png_size_t length)
{
etk::FSNode* fileNode = static_cast<etk::FSNode*>(png_get_io_ptr(png_ptr));
@ -40,13 +40,10 @@ static void localFlushData(png_structp png_ptr)
fileNode->FileFlush();
}
}
*/
bool ewol::imagePNG::GenerateImage(etk::UString & inputFile, draw::Image & ouputImage)
{
int32_t m_width = 0;
int32_t m_height = 0;
etk::FSNode fileName(inputFile);
if (false==fileName.Exist()) {
@ -59,7 +56,7 @@ bool ewol::imagePNG::GenerateImage(etk::UString & inputFile, draw::Image & ouput
}
// Vars
int x, y, address = 0;
int x, y = 0;
int rowbytes;
unsigned char header[8];
png_infop info_ptr;

View File

@ -12,50 +12,6 @@
#include <ewol/ewol.h>
#include <ewol/openGL/openGL.h>
char* ewol::GetCharTypeMoveEvent(eventKbMoveType_te type)
{
char * returnValue = "?";
switch(type) {
case ewol::EVENT_KB_MOVE_TYPE_NONE: returnValue = "---"; break;
case ewol::EVENT_KB_MOVE_TYPE_LEFT: returnValue = "LEFT"; break;
case ewol::EVENT_KB_MOVE_TYPE_RIGHT: returnValue = "RIGHT"; break;
case ewol::EVENT_KB_MOVE_TYPE_UP: returnValue = "UP"; break;
case ewol::EVENT_KB_MOVE_TYPE_DOWN: returnValue = "DOWN"; break;
case ewol::EVENT_KB_MOVE_TYPE_PAGE_UP: returnValue = "PAGE_UP"; break;
case ewol::EVENT_KB_MOVE_TYPE_PAGE_DOWN: returnValue = "PAGE_DOWN"; break;
case ewol::EVENT_KB_MOVE_TYPE_START: returnValue = "START"; break;
case ewol::EVENT_KB_MOVE_TYPE_END: returnValue = "END"; break;
case ewol::EVENT_KB_MOVE_TYPE_CENTER: returnValue = "CENTER"; break;
case ewol::EVENT_KB_MOVE_TYPE_ARRET_DEFIL: returnValue = "ARRET_DEFIL"; break;
case ewol::EVENT_KB_MOVE_TYPE_WAIT: returnValue = "WAIT"; break;
case ewol::EVENT_KB_MOVE_TYPE_INSERT: returnValue = "INSERT"; break;
case ewol::EVENT_KB_MOVE_TYPE_F1: returnValue = "F1"; break;
case ewol::EVENT_KB_MOVE_TYPE_F2: returnValue = "F2"; break;
case ewol::EVENT_KB_MOVE_TYPE_F3: returnValue = "F3"; break;
case ewol::EVENT_KB_MOVE_TYPE_F4: returnValue = "F4"; break;
case ewol::EVENT_KB_MOVE_TYPE_F5: returnValue = "F5"; break;
case ewol::EVENT_KB_MOVE_TYPE_F6: returnValue = "F6"; break;
case ewol::EVENT_KB_MOVE_TYPE_F7: returnValue = "F7"; break;
case ewol::EVENT_KB_MOVE_TYPE_F8: returnValue = "F8"; break;
case ewol::EVENT_KB_MOVE_TYPE_F9: returnValue = "F9"; break;
case ewol::EVENT_KB_MOVE_TYPE_F10: returnValue = "F10"; break;
case ewol::EVENT_KB_MOVE_TYPE_F11: returnValue = "F11"; break;
case ewol::EVENT_KB_MOVE_TYPE_F12: returnValue = "F12"; break;
case ewol::EVENT_KB_MOVE_TYPE_CAPLOCK: returnValue = "CAPLOCK"; break;
case ewol::EVENT_KB_MOVE_TYPE_SHIFT_LEFT: returnValue = "SHIFT_LEFT"; break;
case ewol::EVENT_KB_MOVE_TYPE_SHIFT_RIGHT: returnValue = "SHIFT_RIGHT"; break;
case ewol::EVENT_KB_MOVE_TYPE_CTRL_LEFT: returnValue = "CTRL_LEFT"; break;
case ewol::EVENT_KB_MOVE_TYPE_CTRL_RIGHT: returnValue = "CTRL_RIGHT"; break;
case ewol::EVENT_KB_MOVE_TYPE_META_LEFT: returnValue = "META_LEFT"; break;
case ewol::EVENT_KB_MOVE_TYPE_META_RIGHT: returnValue = "META_RIGHT"; break;
case ewol::EVENT_KB_MOVE_TYPE_ALT: returnValue = "ALT"; break;
case ewol::EVENT_KB_MOVE_TYPE_ALT_GR: returnValue = "ALT_GR"; break;
case ewol::EVENT_KB_MOVE_TYPE_CONTEXT_MENU: returnValue = "CONTEXT_MENU"; break;
case ewol::EVENT_KB_MOVE_TYPE_VER_NUM: returnValue = "VER_NUM"; break;
}
return returnValue;
}
#undef __class__
#define __class__ "Widget"

View File

@ -21,71 +21,6 @@ namespace ewol {
#include <ewol/ClipBoard.h>
namespace ewol {
typedef enum {
EVENT_INPUT_TYPE_DOWN,
EVENT_INPUT_TYPE_MOVE,
EVENT_INPUT_TYPE_SINGLE,
EVENT_INPUT_TYPE_DOUBLE,
EVENT_INPUT_TYPE_TRIPLE,
EVENT_INPUT_TYPE_QUAD,
EVENT_INPUT_TYPE_QUINTE,
EVENT_INPUT_TYPE_UP,
EVENT_INPUT_TYPE_ENTER,
EVENT_INPUT_TYPE_LEAVE,
EVENT_INPUT_TYPE_ABORT, // Appeare when an event is tranfert betwwen widgets (the widget which receive this has lost the events)
EVENT_INPUT_TYPE_TRANSFERT, // Appeare when an event is tranfert betwwen widgets (the widget which receive this has receive the transfert of the event)
} eventInputType_te;
typedef enum {
EVENT_KB_TYPE_DOWN,
EVENT_KB_TYPE_UP,
} eventKbType_te;
typedef enum {
EVENT_KB_MOVE_TYPE_NONE,
EVENT_KB_MOVE_TYPE_LEFT,
EVENT_KB_MOVE_TYPE_RIGHT,
EVENT_KB_MOVE_TYPE_UP,
EVENT_KB_MOVE_TYPE_DOWN,
EVENT_KB_MOVE_TYPE_PAGE_UP,
EVENT_KB_MOVE_TYPE_PAGE_DOWN,
EVENT_KB_MOVE_TYPE_START,
EVENT_KB_MOVE_TYPE_END,
EVENT_KB_MOVE_TYPE_CENTER,
EVENT_KB_MOVE_TYPE_ARRET_DEFIL,
EVENT_KB_MOVE_TYPE_WAIT,
EVENT_KB_MOVE_TYPE_INSERT,
EVENT_KB_MOVE_TYPE_F1,
EVENT_KB_MOVE_TYPE_F2,
EVENT_KB_MOVE_TYPE_F3,
EVENT_KB_MOVE_TYPE_F4,
EVENT_KB_MOVE_TYPE_F5,
EVENT_KB_MOVE_TYPE_F6,
EVENT_KB_MOVE_TYPE_F7,
EVENT_KB_MOVE_TYPE_F8,
EVENT_KB_MOVE_TYPE_F9,
EVENT_KB_MOVE_TYPE_F10,
EVENT_KB_MOVE_TYPE_F11,
EVENT_KB_MOVE_TYPE_F12,
EVENT_KB_MOVE_TYPE_CAPLOCK,
EVENT_KB_MOVE_TYPE_SHIFT_LEFT,
EVENT_KB_MOVE_TYPE_SHIFT_RIGHT,
EVENT_KB_MOVE_TYPE_CTRL_LEFT,
EVENT_KB_MOVE_TYPE_CTRL_RIGHT,
EVENT_KB_MOVE_TYPE_META_LEFT,
EVENT_KB_MOVE_TYPE_META_RIGHT,
EVENT_KB_MOVE_TYPE_ALT,
EVENT_KB_MOVE_TYPE_ALT_GR,
EVENT_KB_MOVE_TYPE_CONTEXT_MENU,
EVENT_KB_MOVE_TYPE_VER_NUM,
} eventKbMoveType_te;
typedef enum {
INPUT_TYPE_UNKNOW,
INPUT_TYPE_MOUSE,
INPUT_TYPE_FINGER,
} inputType_te;
char* GetCharTypeMoveEvent(eventKbMoveType_te type);
class DrawProperty{