[DEV] Better button event
This commit is contained in:
parent
fbcb6148ad
commit
22e5c62c42
@ -25,7 +25,7 @@ varying vec2 v_position; // interpolated position ...
|
|||||||
|
|
||||||
// internal static define
|
// internal static define
|
||||||
vec4 S_colorBg = vec4(0.0);
|
vec4 S_colorBg = vec4(0.0);
|
||||||
vec4 S_colorFg[3];
|
vec4 S_colorFg[4];
|
||||||
vec4 S_colorBorder = vec4(0.0,0.0,0.0,1.0);
|
vec4 S_colorBorder = vec4(0.0,0.0,0.0,1.0);
|
||||||
float S_sizePadding = 3.0;
|
float S_sizePadding = 3.0;
|
||||||
float S_sizeBorder = 1.0;
|
float S_sizeBorder = 1.0;
|
||||||
@ -34,6 +34,7 @@ void main(void) {
|
|||||||
S_colorFg[0] = vec4(0.5,0.5,0.5,0.3);
|
S_colorFg[0] = vec4(0.5,0.5,0.5,0.3);
|
||||||
S_colorFg[1] = vec4(0.7,0.0,0.0,0.4);
|
S_colorFg[1] = vec4(0.7,0.0,0.0,0.4);
|
||||||
S_colorFg[2] = vec4(0.0,0.0,0.7,0.4);
|
S_colorFg[2] = vec4(0.0,0.0,0.7,0.4);
|
||||||
|
S_colorFg[3] = vec4(0.0,0.7,0.0,0.4);
|
||||||
// prevent origin moving ...
|
// prevent origin moving ...
|
||||||
vec2 position = v_position - EW_widgetProperty.origin;
|
vec2 position = v_position - EW_widgetProperty.origin;
|
||||||
|
|
||||||
|
@ -144,15 +144,22 @@ void ewol::Shaper::Clear(void)
|
|||||||
// nothing to do ...
|
// nothing to do ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool ewol::Shaper::ChangeStatusIn(int32_t newStatusId)
|
bool ewol::Shaper::ChangeStatusIn(int32_t newStatusId)
|
||||||
{
|
{
|
||||||
m_nextStatusRequested = newStatusId;
|
m_nextStatusRequested = newStatusId;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t ewol::Shaper::GetCurrentDisplayedStatus(void)
|
||||||
|
{
|
||||||
|
return m_stateNew;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ewol::Shaper::GetNextDisplayedStatus(void)
|
||||||
|
{
|
||||||
|
return m_nextStatusRequested;
|
||||||
|
}
|
||||||
|
|
||||||
bool ewol::Shaper::PeriodicCall(int64_t localTime)
|
bool ewol::Shaper::PeriodicCall(int64_t localTime)
|
||||||
{
|
{
|
||||||
// start :
|
// start :
|
||||||
|
@ -87,6 +87,16 @@ namespace ewol
|
|||||||
* @return false No need to request the periodic call.
|
* @return false No need to request the periodic call.
|
||||||
*/
|
*/
|
||||||
bool ChangeStatusIn(int32_t newStatusId);
|
bool ChangeStatusIn(int32_t newStatusId);
|
||||||
|
/**
|
||||||
|
* @brief Get the current displayed status of the shaper
|
||||||
|
* @return The Status Id
|
||||||
|
*/
|
||||||
|
int32_t GetCurrentDisplayedStatus(void);;
|
||||||
|
/**
|
||||||
|
* @brief Get the next displayed status of the shaper
|
||||||
|
* @return The next status Id (-1 if no status in next)
|
||||||
|
*/
|
||||||
|
int32_t GetNextDisplayedStatus(void);
|
||||||
/**
|
/**
|
||||||
* @brief Same as the widfget periodic call (this is for change display)
|
* @brief Same as the widfget periodic call (this is for change display)
|
||||||
* @param[in] localTime The current time of the call.
|
* @param[in] localTime The current time of the call.
|
||||||
|
@ -32,7 +32,9 @@ widget::Button::Button(etk::UString newLabel) :
|
|||||||
m_shaper("THEME:GUI:widgetButton.conf"),
|
m_shaper("THEME:GUI:widgetButton.conf"),
|
||||||
m_label(newLabel),
|
m_label(newLabel),
|
||||||
m_toggleMode(false),
|
m_toggleMode(false),
|
||||||
m_value(false)
|
m_value(false),
|
||||||
|
m_mouseHover(false),
|
||||||
|
m_buttonPressed(false)
|
||||||
{
|
{
|
||||||
AddEventId(ewolEventButtonPressed);
|
AddEventId(ewolEventButtonPressed);
|
||||||
AddEventId(ewolEventButtonDown);
|
AddEventId(ewolEventButtonDown);
|
||||||
@ -259,48 +261,68 @@ void widget::Button::OnRegenerateDisplay(void)
|
|||||||
|
|
||||||
bool widget::Button::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, etk::Vector2D<float> pos)
|
bool widget::Button::OnEventInput(ewol::keyEvent::type_te type, int32_t IdInput, ewol::keyEvent::status_te typeEvent, etk::Vector2D<float> pos)
|
||||||
{
|
{
|
||||||
|
bool previousHoverState = m_mouseHover;
|
||||||
if(ewol::keyEvent::statusLeave == typeEvent) {
|
if(ewol::keyEvent::statusLeave == typeEvent) {
|
||||||
ChangeStatusIn(STATUS_UP);
|
m_mouseHover = false;
|
||||||
}
|
m_buttonPressed = false;
|
||||||
|
} else {
|
||||||
etk::Vector2D<float> relativePos = RelativePosition(pos);
|
etk::Vector2D<float> relativePos = RelativePosition(pos);
|
||||||
// prevent error from ouside the button
|
// prevent error from ouside the button
|
||||||
if( relativePos.x < m_selectableAreaPos.x
|
if( relativePos.x < m_selectableAreaPos.x
|
||||||
|| relativePos.y < m_selectableAreaPos.y
|
|| relativePos.y < m_selectableAreaPos.y
|
||||||
|| relativePos.x > m_selectableAreaPos.x + m_selectableAreaSize.x
|
|| relativePos.x > m_selectableAreaPos.x + m_selectableAreaSize.x
|
||||||
|| relativePos.y > m_selectableAreaPos.y + m_selectableAreaSize.y ) {
|
|| relativePos.y > m_selectableAreaPos.y + m_selectableAreaSize.y ) {
|
||||||
return false;
|
m_mouseHover = false;
|
||||||
}
|
m_buttonPressed = false;
|
||||||
//EWOL_DEBUG("Event on BT ...");
|
} else {
|
||||||
if(ewol::keyEvent::statusEnter == typeEvent) {
|
m_mouseHover = true;
|
||||||
ChangeStatusIn(STATUS_HOVER);
|
|
||||||
}
|
|
||||||
if (1 == IdInput) {
|
|
||||||
if(ewol::keyEvent::statusDown == typeEvent) {
|
|
||||||
GenerateEventId(ewolEventButtonDown);
|
|
||||||
ChangeStatusIn(STATUS_PRESSED);
|
|
||||||
MarkToRedraw();
|
|
||||||
}
|
}
|
||||||
if(ewol::keyEvent::statusUp == typeEvent) {
|
}
|
||||||
GenerateEventId(ewolEventButtonUp);
|
bool previousPressed = m_buttonPressed;
|
||||||
ChangeStatusIn(STATUS_UP);
|
//EWOL_DEBUG("Event on BT ... mouse position : " << m_mouseHover);
|
||||||
MarkToRedraw();
|
if (true == m_mouseHover) {
|
||||||
}
|
if (1 == IdInput) {
|
||||||
if(ewol::keyEvent::statusSingle == typeEvent) {
|
if(ewol::keyEvent::statusDown == typeEvent) {
|
||||||
// inverse value :
|
GenerateEventId(ewolEventButtonDown);
|
||||||
m_value = (m_value)?false:true;
|
m_buttonPressed = true;
|
||||||
GenerateEventId(ewolEventButtonPressed);
|
MarkToRedraw();
|
||||||
GenerateEventId(ewolEventButtonValue, m_value);
|
}
|
||||||
if( false == m_toggleMode
|
if(ewol::keyEvent::statusUp == typeEvent) {
|
||||||
&& true == m_value) {
|
GenerateEventId(ewolEventButtonUp);
|
||||||
m_value = false;
|
m_buttonPressed = false;
|
||||||
GenerateEventId(ewolEventButtonValue, m_value);
|
MarkToRedraw();
|
||||||
|
}
|
||||||
|
if(ewol::keyEvent::statusSingle == typeEvent) {
|
||||||
|
// inverse value :
|
||||||
|
m_value = (m_value)?false:true;
|
||||||
|
GenerateEventId(ewolEventButtonPressed);
|
||||||
|
GenerateEventId(ewolEventButtonValue, m_value);
|
||||||
|
if( false == m_toggleMode
|
||||||
|
&& true == m_value) {
|
||||||
|
m_value = false;
|
||||||
|
GenerateEventId(ewolEventButtonValue, m_value);
|
||||||
|
}
|
||||||
|
MarkToRedraw();
|
||||||
}
|
}
|
||||||
MarkToRedraw();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
if( m_mouseHover != previousHoverState
|
||||||
|
|| m_buttonPressed != previousPressed) {
|
||||||
|
if (true==m_buttonPressed) {
|
||||||
|
ChangeStatusIn(STATUS_PRESSED);
|
||||||
|
} else {
|
||||||
|
if (true==m_mouseHover) {
|
||||||
|
ChangeStatusIn(STATUS_HOVER);
|
||||||
|
} else {
|
||||||
|
if (true == m_value) {
|
||||||
|
ChangeStatusIn(STATUS_DOWN);
|
||||||
|
} else {
|
||||||
|
ChangeStatusIn(STATUS_UP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@ namespace widget {
|
|||||||
etk::UString m_labelToggle; //!< Label to display when toggle mode is set ("" whenit is the same).
|
etk::UString m_labelToggle; //!< Label to display when toggle mode is set ("" whenit is the same).
|
||||||
bool m_toggleMode; //!< The button is able to toggle.
|
bool m_toggleMode; //!< The button is able to toggle.
|
||||||
bool m_value; //!< Current state of the button.
|
bool m_value; //!< Current state of the button.
|
||||||
|
bool m_mouseHover; //!< Flag to know where the mouse is (inside the displayed widget (if not fill)
|
||||||
|
bool m_buttonPressed; //!< Flag to know if the button is curently pressed
|
||||||
// hover area :
|
// hover area :
|
||||||
etk::Vector2D<float> m_selectableAreaPos; //!< Start position of the events
|
etk::Vector2D<float> m_selectableAreaPos; //!< Start position of the events
|
||||||
etk::Vector2D<float> m_selectableAreaSize; //!< Size of the event positions
|
etk::Vector2D<float> m_selectableAreaSize; //!< Size of the event positions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user