[DEV] new button shader system ==> must be reworked

This commit is contained in:
Edouard DUPIN 2012-11-04 19:04:12 +01:00
parent d3eed67f00
commit b0b619da82
5 changed files with 141 additions and 72 deletions

View File

@ -74,6 +74,20 @@ void ewol::Button::Init(void)
m_textColorBg = draw::color::black;
m_textColorBg.a = 0x3F;
SetCanHaveFocus(true);
#ifdef __VIDEO__OPENGL_ES_2
etk::UString tmpString("THEME:rounded:widgetButton.prog");
// get the shader resource :
m_GLPosition = 0;
if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) {
m_GLPosition = m_GLprogram->GetAttribute("EW_coord2d");
m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation");
m_GLsizeBorder = m_GLprogram->GetUniform("EW_sizeBorder");
m_GLsizePadding = m_GLprogram->GetUniform("EW_sizePadding");
m_GLsize = m_GLprogram->GetUniform("EW_size");
m_GLposText = m_GLprogram->GetUniform("EW_posText");
m_GLstate = m_GLprogram->GetUniform("EW_state");
}
#endif
}
ewol::Button::Button(void)
@ -151,8 +165,63 @@ bool ewol::Button::GetValue(void)
return false;
}
#ifdef __VIDEO__OPENGL_ES_2
void ewol::Button::SetPoint(float x, float y)
{
etk::Vector2D<float> triangle(x, y);
m_coord.PushBack(triangle);
}
void ewol::Button::Rectangle(float x, float y, float w, float h)
{
m_coord.Clear();
/* Bitmap position
* xA xB
* yC *------*
* | |
* | |
* yD *------*
*/
float dxA = x;
float dxB = x + w;
float dyC = y;
float dyD = y + h;
SetPoint(dxA, dyD);
SetPoint(dxA, dyC);
SetPoint(dxB, dyC);
SetPoint(dxB, dyC);
SetPoint(dxB, dyD);
SetPoint(dxA, dyD);
}
#endif
void ewol::Button::OnDraw(DrawProperty& displayProp)
{
#ifdef __VIDEO__OPENGL_ES_2
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]);
// all entry parameters :
m_GLprogram->Uniform1f(m_GLsizeBorder, 3);
m_GLprogram->Uniform1f(m_GLsizePadding, m_padding.x);
m_GLprogram->Uniform2fv(m_GLsize, 1, &m_size.x);
m_GLprogram->Uniform4fv(m_GLposText, 1, m_pos);
m_GLprogram->Uniform1i(m_GLstate, 0);
// Request the draw of the elements :
glDrawArrays(GL_TRIANGLES, 0, m_coord.Size());
m_GLprogram->UnUse();
#endif
m_oObjectDecoration.Draw();
if (NULL != m_oObjectImage) {
m_oObjectImage->Draw();
@ -212,12 +281,16 @@ void ewol::Button::OnRegenerateDisplay(void)
//EWOL_DEBUG("draw tex at pos : " <<textPos << "in element size:" << m_size);
m_oObjectText.Text(textPos/*, drawClipping*/, m_label);
m_oObjectDecoration.SetColor(m_textColorBg);
tmpOriginX -= m_padding.x/2;
tmpOriginY -= m_padding.y/2;
tmpSizeX += m_padding.x/1;
tmpSizeY += m_padding.y/1;
m_oObjectDecoration.Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY);
#ifndef __VIDEO__OPENGL_ES_2
m_oObjectDecoration.SetColor(m_textColorBg);
tmpOriginX -= m_padding.x/2;
tmpOriginY -= m_padding.y/2;
tmpSizeX += m_padding.x/1;
tmpSizeY += m_padding.y/1;
m_oObjectDecoration.Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY);
#else
Rectangle(0, 0, m_size.x, m_size.y);
#endif
}
}

View File

@ -43,6 +43,33 @@ namespace ewol {
} textAlignement_te;
class Button : public ewol::Widget
{
private:
#ifdef __VIDEO__OPENGL_ES_2
ewol::Program* m_GLprogram;
int32_t m_GLPosition;
int32_t m_GLMatrix;
int32_t m_GLsizeBorder;
int32_t m_GLsizePadding;
int32_t m_GLsize;
float m_pos[4];
int32_t m_GLposText;
int32_t m_GLstate;
etk::Vector<etk::Vector2D<float> > m_coord; //!< internal coord of the object
draw::Colorf m_color[3];
void SetPoint(float x, float y);
void Rectangle(float x, float y, float w, float h);
#endif
private:
ewol::OObject2DTextColored m_oObjectText;
ewol::OObject2DColored m_oObjectDecoration;
ewol::OObject2DTextured* m_oObjectImage;
bool m_hasAnImage;
etk::UString m_imageSelected;
textAlignement_te m_alignement;
etk::Vector2D<float> m_padding;
etk::UString m_label;
draw::Color m_textColorFg; //!< Text color
draw::Color m_textColorBg; //!< Background color
public:
Button(void);
Button(etk::UString newLabel);
@ -65,17 +92,6 @@ namespace ewol {
void SetPadding(etk::Vector2D<float> newPadding);
void SetColorBg(draw::Color newColor) { m_textColorBg = newColor; };
void SetColorFg(draw::Color newColor) { m_textColorFg = newColor; };
private:
ewol::OObject2DTextColored m_oObjectText;
ewol::OObject2DColored m_oObjectDecoration;
ewol::OObject2DTextured* m_oObjectImage;
bool m_hasAnImage;
etk::UString m_imageSelected;
textAlignement_te m_alignement;
etk::Vector2D<float> m_padding;
etk::UString m_label;
draw::Color m_textColorFg; //!< Text color
draw::Color m_textColorBg; //!< Background color
public:
virtual void OnRegenerateDisplay(void);
virtual void OnDraw(DrawProperty& displayProp);

View File

@ -134,61 +134,37 @@ etk::UString ewol::Entry::GetValue(void)
#ifdef __VIDEO__OPENGL_ES_2
void ewol::Entry::SetPoint(float x, float y)
{
etk::Vector2D<float> triangle(x, y);
m_coord.PushBack(triangle);
}
void ewol::Entry::Rectangle(float x, float y, float w, float h)
{
m_coord.Clear();
/*
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;
}
void ewol::Entry::SetPoint(float x, float y)
{
etk::Vector2D<float> triangle(x, y);
m_coord.PushBack(triangle);
}
if( dyC >= dyD
|| dxA >= dxB) {
return;
void ewol::Entry::Rectangle(float x, float y, float w, float h)
{
m_coord.Clear();
/* Bitmap position
* xA xB
* yC *------*
* | |
* | |
* yD *------*
*/
float dxA = x;
float dxB = x + w;
float dyC = y;
float dyD = y + h;
SetPoint(dxA, dyD);
SetPoint(dxA, dyC);
SetPoint(dxB, dyC);
SetPoint(dxB, dyC);
SetPoint(dxB, dyD);
SetPoint(dxA, dyD);
}
*/
SetPoint(dxA, dyD);
SetPoint(dxA, dyC);
SetPoint(dxB, dyC);
SetPoint(dxB, dyC);
SetPoint(dxB, dyD);
SetPoint(dxA, dyD);
}
#endif
/**
* @brief Common widget drawing function (called by the drawing thread [Android, X11, ...])

View File

@ -60,8 +60,8 @@ namespace ewol {
int32_t m_GLstate;
etk::Vector<etk::Vector2D<float> > m_coord; //!< internal coord of the object
draw::Colorf m_color[3];
void SetPoint(float x, float y);
void Rectangle(float x, float y, float w, float h);
void SetPoint(float x, float y);
void Rectangle(float x, float y, float w, float h);
#endif
private:
ewol::OObject2DTextColored m_oObjectText; //!< text display

View File

@ -108,5 +108,9 @@ LOCAL_COPY_FILES := ../../share/textured3D.prog:textured3D.prog \
\
../../share/theme/rounded/widgetEntry.prog:theme/rounded/widgetEntry.prog \
../../share/theme/rounded/widgetEntry.frag:theme/rounded/widgetEntry.frag \
../../share/theme/rounded/widgetEntry.vert:theme/rounded/widgetEntry.vert
../../share/theme/rounded/widgetEntry.vert:theme/rounded/widgetEntry.vert \
\
../../share/theme/default/widgetButton.prog:theme/default/widgetButton.prog \
../../share/theme/default/widgetButton.frag:theme/default/widgetButton.frag \
../../share/theme/default/widgetButton.vert:theme/default/widgetButton.vert