add button color (not ended)
This commit is contained in:
parent
8326ac2dfc
commit
81075dff9c
213
Sources/libewol/ewol/widget/ButtonColor.cpp
Normal file
213
Sources/libewol/ewol/widget/ButtonColor.cpp
Normal file
@ -0,0 +1,213 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/widget/ButtonColor.cpp
|
||||
* @brief ewol Button select color widget system (Sources)
|
||||
* @author Edouard DUPIN
|
||||
* @date 04/03/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#include <ewol/widget/ButtonColor.h>
|
||||
|
||||
#include <ewol/OObject.h>
|
||||
#include <ewol/WidgetManager.h>
|
||||
|
||||
|
||||
extern const char * const ewolEventButtonColorChange = "ewol-Button-Color-Change";
|
||||
|
||||
|
||||
|
||||
#undef __class__
|
||||
#define __class__ "ButtonColor"
|
||||
|
||||
|
||||
void ewol::ButtonColor::Init(void)
|
||||
{
|
||||
AddEventId(ewolEventButtonColorChange);
|
||||
|
||||
m_alignement = ewol::TEXT_ALIGN_CENTER;
|
||||
|
||||
#ifdef __PLATFORM__Android
|
||||
m_padding.y = 12;
|
||||
m_padding.x = 12;
|
||||
#else
|
||||
m_padding.y = 4;
|
||||
m_padding.x = 4;
|
||||
#endif
|
||||
|
||||
m_textColorFg.red = 0.0;
|
||||
m_textColorFg.green = 0.0;
|
||||
m_textColorFg.blue = 0.0;
|
||||
m_textColorFg.alpha = 1.0;
|
||||
|
||||
m_textColorBg.red = 0.0;
|
||||
m_textColorBg.green = 0.0;
|
||||
m_textColorBg.blue = 0.0;
|
||||
m_textColorBg.alpha = 0.25;
|
||||
SetCanHaveFocus(true);
|
||||
}
|
||||
|
||||
ewol::ButtonColor::ButtonColor(void)
|
||||
{
|
||||
m_label = "No Label";
|
||||
Init();
|
||||
}
|
||||
|
||||
ewol::ButtonColor::ButtonColor(etk::UString newLabel)
|
||||
{
|
||||
m_label = newLabel;
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
ewol::ButtonColor::~ButtonColor(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ewol::ButtonColor::SetPadding(coord2D_ts newPadding)
|
||||
{
|
||||
m_padding = newPadding;
|
||||
}
|
||||
|
||||
bool ewol::ButtonColor::CalculateMinSize(void)
|
||||
{
|
||||
int32_t fontId = GetDefaultFontId();
|
||||
int32_t minWidth = ewol::GetWidth(fontId, m_label);
|
||||
int32_t minHeight = ewol::GetHeight(fontId);
|
||||
m_minSize.x = m_padding.x*2 + minWidth;
|
||||
m_minSize.y = m_padding.y*2 + minHeight;
|
||||
MarkToReedraw();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ewol::ButtonColor::SetLabel(etk::UString newLabel)
|
||||
{
|
||||
m_label = newLabel;
|
||||
MarkToReedraw();
|
||||
}
|
||||
|
||||
void ewol::ButtonColor::SetValue(bool val)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ewol::ButtonColor::SetAlignement(textAlignement_te typeAlign)
|
||||
{
|
||||
m_alignement = typeAlign;
|
||||
MarkToReedraw();
|
||||
}
|
||||
|
||||
|
||||
bool ewol::ButtonColor::GetValue(void)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ewol::ButtonColor::OnRegenerateDisplay(void)
|
||||
{
|
||||
if (true == NeedRedraw()) {
|
||||
// clean the object list ...
|
||||
ClearOObjectList();
|
||||
|
||||
int32_t tmpSizeX = m_minSize.x;
|
||||
int32_t tmpSizeY = m_minSize.y;
|
||||
int32_t tmpOriginX = (m_size.x - m_minSize.x) / 2;
|
||||
int32_t tmpOriginY = (m_size.y - m_minSize.y) / 2;
|
||||
// no change for the text orogin :
|
||||
int32_t tmpTextOriginX = (m_size.x - m_minSize.x) / 2 + m_padding.x;
|
||||
int32_t tmpTextOriginY = (m_size.y - m_minSize.y) / 2 + m_padding.y;
|
||||
|
||||
if (true==m_userFillX) {
|
||||
tmpSizeX = m_size.x;
|
||||
tmpOriginX = 0;
|
||||
if (m_alignement == ewol::TEXT_ALIGN_LEFT) {
|
||||
tmpTextOriginX = m_padding.x;
|
||||
}
|
||||
}
|
||||
if (true==m_userFillY) {
|
||||
tmpSizeY = m_size.y;
|
||||
tmpOriginY = 0;
|
||||
}
|
||||
tmpOriginX += m_padding.x;
|
||||
tmpOriginY += m_padding.y;
|
||||
tmpSizeX -= 2*m_padding.x;
|
||||
tmpSizeY -= 2*m_padding.y;
|
||||
|
||||
ewol::OObject2DText * tmpText = new ewol::OObject2DText("", -1, m_textColorFg);
|
||||
/*
|
||||
int32_t fontId = GetDefaultFontId();
|
||||
int32_t fontHeight = ewol::GetHeight(fontId);
|
||||
int32_t fontWidth = ewol::GetWidth(fontId, m_label.c_str());
|
||||
*/
|
||||
coord2D_ts textPos;
|
||||
textPos.x = tmpTextOriginX;
|
||||
textPos.y = tmpTextOriginY;
|
||||
clipping_ts drawClipping;
|
||||
drawClipping.x = m_padding.x;
|
||||
drawClipping.y = m_padding.y;
|
||||
drawClipping.w = m_size.x - 2*m_padding.x;
|
||||
drawClipping.h = m_size.y - 2*m_padding.y;
|
||||
tmpText->Text(textPos, drawClipping, m_label);
|
||||
|
||||
ewol::OObject2DColored * tmpOObjects = new ewol::OObject2DColored;
|
||||
tmpOObjects->SetColor(m_textColorBg);
|
||||
tmpOriginX -= m_padding.x/2;
|
||||
tmpOriginY -= m_padding.y/2;
|
||||
tmpSizeX += m_padding.x/1;
|
||||
tmpSizeY += m_padding.y/1;
|
||||
tmpOObjects->Rectangle( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY);
|
||||
AddOObject(tmpOObjects);
|
||||
|
||||
AddOObject(tmpText);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ewol::ButtonColor::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, eventPosition_ts pos)
|
||||
{
|
||||
//EWOL_DEBUG("Event on BT ...");
|
||||
if (1 == IdInput) {
|
||||
if( ewol::EVENT_INPUT_TYPE_SINGLE == typeEvent
|
||||
|| ewol::EVENT_INPUT_TYPE_DOUBLE == typeEvent
|
||||
|| ewol::EVENT_INPUT_TYPE_TRIPLE == typeEvent) {
|
||||
// nothing to do ...
|
||||
GenerateEventId(ewolEventButtonPressed);
|
||||
MarkToReedraw();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ewol::ButtonColor::SetCurrentColor(color_ts color)
|
||||
{
|
||||
m_selectedColor = color;
|
||||
m_textColorBg = m_selectedColor;
|
||||
char colorText[256];
|
||||
sprintf(colorText, "#%02X%02X%02X%02X",
|
||||
(uint8_t)(color.red * 0xFF),
|
||||
(uint8_t)(color.green * 0xFF),
|
||||
(uint8_t)(color.blue * 0xFF),
|
||||
(uint8_t)(color.alpha * 0xFF));
|
||||
//set the new label ...
|
||||
SetLabel(colorText);
|
||||
}
|
66
Sources/libewol/ewol/widget/ButtonColor.h
Normal file
66
Sources/libewol/ewol/widget/ButtonColor.h
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* @file ewol/widget/ButtonColor.h
|
||||
* @brief ewol Button select color widget system (header)
|
||||
* @author Edouard DUPIN
|
||||
* @date 04/03/2012
|
||||
* @par Project
|
||||
* ewol
|
||||
*
|
||||
* @par Copyright
|
||||
* Copyright 2011 Edouard DUPIN, all right reserved
|
||||
*
|
||||
* This software is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY.
|
||||
*
|
||||
* Licence summary :
|
||||
* You can modify and redistribute the sources code and binaries.
|
||||
* You can send me the bug-fix
|
||||
*
|
||||
* Term of the licence in in the file licence.txt.
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __EWOL_BUTTON_COLOR_H__
|
||||
#define __EWOL_BUTTON_COLOR_H__
|
||||
|
||||
#include <etk/Types.h>
|
||||
#include <ewol/Debug.h>
|
||||
#include <ewol/widget/Drawable.h>
|
||||
#include <ewol/widget/Button.h>
|
||||
|
||||
extern const char * const ewolEventButtonColorChange;
|
||||
|
||||
namespace ewol {
|
||||
class ButtonColor :public ewol::Drawable
|
||||
{
|
||||
public:
|
||||
ButtonColor(void);
|
||||
ButtonColor(etk::UString newLabel);
|
||||
void Init(void);
|
||||
virtual ~ButtonColor(void);
|
||||
virtual bool CalculateMinSize(void);
|
||||
void SetLabel(etk::UString newLabel);
|
||||
etk::UString GetLabel(void) {return m_label;};
|
||||
void SetValue(bool val);
|
||||
bool GetValue(void);
|
||||
void SetAlignement(textAlignement_te typeAlign);
|
||||
void SetPadding(coord2D_ts newPadding);
|
||||
private:
|
||||
textAlignement_te m_alignement;
|
||||
coord2D_ts m_padding;
|
||||
etk::UString m_label;
|
||||
color_ts m_textColorFg; //!< Text color
|
||||
color_ts m_textColorBg; //!< Background color
|
||||
color_ts m_selectedColor; //!< user current selected Color
|
||||
public:
|
||||
virtual void OnRegenerateDisplay(void);
|
||||
public:
|
||||
virtual bool OnEventInput(int32_t IdInput, eventInputType_te typeEvent, eventPosition_ts pos);
|
||||
color_ts GetCurrentColor(void) { return m_selectedColor; };
|
||||
void SetCurrentColor(color_ts color);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
@ -22,6 +22,7 @@ FILE_LIST = ewol/ewol.cpp \
|
||||
ewol/widget/WidgetScrolled.cpp \
|
||||
ewol/widget/Drawable.cpp \
|
||||
ewol/widget/Button.cpp \
|
||||
ewol/widget/ButtonColor.cpp \
|
||||
ewol/widget/Label.cpp \
|
||||
ewol/widget/CheckBox.cpp \
|
||||
ewol/widget/Entry.cpp \
|
||||
|
13
exemple/2DObject.e2d
Normal file
13
exemple/2DObject.e2d
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<e2d ratio="1.000" designed size="256">
|
||||
<element name="hjhj">
|
||||
<dot id=1 x="0.2352" y="0.435634" />
|
||||
<dot id=2 x="0.6746" y="0.323467" />
|
||||
<dot id=3 x="0.4657" y="0.234131" />
|
||||
<dot id=3 x="0.00000" y="1.000000" />
|
||||
<link id1="1" color1="#45F645FF"
|
||||
id2="2" color2="#345635FF"
|
||||
id3="4" color3="#867757FF"/>
|
||||
</element>
|
||||
</e2d>
|
||||
|
Loading…
x
Reference in New Issue
Block a user