[DEV] add button widget
This commit is contained in:
parent
ea7c800947
commit
47bc71af75
71
resources/resources/ewol/theme/shape/Button.emf
Normal file
71
resources/resources/ewol/theme/shape/Button.emf
Normal file
@ -0,0 +1,71 @@
|
||||
EMF(STRING)
|
||||
# Blender v2.92.0 EMF File: 'Entry.blend'
|
||||
Mesh:EntryBox_Cube
|
||||
Vertex:16
|
||||
20.042355 19.982376 -7.860689|20.042355 -20.102333 -7.862826|20.042355 19.981716 4.524041|20.042355 -20.102993 4.521903|-20.042355 19.982376 -7.860689|-20.042355 -20.102333 -7.862826|-20.042355 19.981716 4.524041|-20.042355 -20.102993 4.521903|10.127714 10.066911 7.616918|10.127714 -10.188519 7.615837|-10.127714 10.066911 7.616918|-10.127714 -10.188519 7.615837|-10.127714 -10.188596 7.897926|-10.127714 10.066834 7.899007|10.127714 10.066834 7.899007|10.127714 -10.188596 7.897926|
|
||||
UV-mapping:
|
||||
1.000000 1.000000|-0.000001 -0.000000|0.999976 0.000023|0.000001 1.000001|0.074219 0.995849|0.120606 0.943115|0.121582 0.993408|0.112927 0.992387|0.078245 0.948093|0.073324 0.991157|0.101769 0.970961|0.080974 0.959440|0.102023 0.957458|0.111927 0.985005|0.078476 0.953015|0.082167 0.983774|0.074219 0.944092|0.111696 0.944402|0.080720 0.975385|0.113157 0.949323|0.174907 0.947863|0.131613 0.991157|0.132843 0.945402|0.178368 0.944941|0.137534 0.984544|0.142456 0.948632|0.171985 0.949093|0.136074 0.991157|0.137304 0.950323|0.174677 0.949093|0.135074 0.992387|0.136304 0.949093|0.178598 0.993618|0.178368 0.988235|0.173216 0.991157|0.175907 0.989926|0.013265 0.951784|0.051868 0.992387|0.013034 0.993618|0.054098 0.951784|0.137534 0.988235|0.177138 0.947863|0.135074 0.947862|0.172446 0.988465|
|
||||
Normal(face):22
|
||||
0.000000 -0.000053 1.000000|-0.297843 -0.000051 0.954615|0.000000 -0.297894 0.954599|0.000000 0.297792 0.954631|0.297843 -0.000051 0.954615|0.000000 1.000000 0.000053|-1.000000 0.000000 0.000000|0.000000 -1.000000 -0.000053|1.000000 -0.000000 -0.000000|0.000000 0.000053 -1.000000|
|
||||
Face:22
|
||||
gui_dynamic_1
|
||||
14/0/0 12/1/0 15/2/0| 14/0/0 13/3/0 12/1/0|
|
||||
palette:gui_border_1
|
||||
7/4/1 10/5/1 6/6/1| 3/7/2 11/8/2 7/9/2| 6/10/3 8/11/3 2/12/3| 2/13/4 9/14/4 3/15/4| 7/4/1 11/16/1 10/5/1| 3/7/2 9/17/2 11/8/2| 6/10/3 10/18/3 8/11/3| 2/13/4 8/19/4 9/14/4|
|
||||
palette:gui_border_2
|
||||
4/20/5 2/21/5 0/22/5| 6/23/6 5/24/6 7/25/6| 1/26/7 7/27/7 5/28/7| 0/29/8 3/30/8 1/31/8| 4/20/5 6/32/5 2/21/5| 6/23/6 4/33/6 5/24/6| 1/26/7 3/34/7 7/27/7| 0/29/8 2/35/8 3/30/8|
|
||||
palette:gui_center
|
||||
9/36/0 10/37/0 11/38/0| 9/36/0 8/39/0 10/37/0|
|
||||
palette:gui_back
|
||||
5/40/9 0/41/9 1/42/9| 5/40/9 4/43/9 0/41/9|
|
||||
|
||||
Materials:gui_dynamic_1
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.800000 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
vNi 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
map_Kd empty_area.png
|
||||
# Just for information:
|
||||
Palettes:gui_back
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.800000 0.000000 0.005632
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
vNi 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
# Just for information:
|
||||
Palettes:gui_border_1
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.000000 0.002615 0.800000
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
vNi 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
# Just for information:
|
||||
Palettes:gui_border_2
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.000000 0.800000 0.170495
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
vNi 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
||||
# Just for information:
|
||||
Palettes:gui_center
|
||||
Ns 225.000000
|
||||
Ka 1.000000 1.000000 1.000000
|
||||
Kd 0.438544 0.438544 0.438544
|
||||
Ks 0.500000 0.500000 0.500000
|
||||
Ke 0.000000 0.000000 0.000000
|
||||
vNi 1.450000
|
||||
d 1.000000
|
||||
illum 2
|
@ -1,26 +0,0 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
// transmit from the vertex shader
|
||||
varying vec2 v_propPos;
|
||||
varying vec4 v_colorTansition;
|
||||
uniform vec4 EW_border;
|
||||
uniform vec4 EW_background;
|
||||
|
||||
|
||||
void main(void) {
|
||||
// prevent origin moving ...
|
||||
gl_FragColor = vec4(v_propPos.y, v_propPos.x, 1.0, 1.0);
|
||||
if( v_propPos.x == 1.0
|
||||
&& v_propPos.y == 1.0) {
|
||||
gl_FragColor = v_colorTansition;
|
||||
} else if ( v_propPos.x == 0.0
|
||||
|| v_propPos.y == 0.0) {
|
||||
gl_FragColor = EW_background;
|
||||
} else {
|
||||
gl_FragColor = EW_border;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,24 @@
|
||||
{
|
||||
padding-out-left:1,
|
||||
padding-out-right:1,
|
||||
padding-out-top:1,
|
||||
padding-out-buttom:1,
|
||||
# padding "outside" the object in pixel ==> prevent bad display
|
||||
"padding-out-left":2,
|
||||
"padding-out-right":2,
|
||||
"padding-out-top":2,
|
||||
"padding-out-buttom":2,
|
||||
|
||||
border-left:1,
|
||||
border-right:1,
|
||||
border-top:1,
|
||||
border-buttom:1,
|
||||
# padding "inside" the object in pixel ==> prevent bad display
|
||||
"padding-in-left":2,
|
||||
"padding-in-right":2,
|
||||
"padding-in-top":2,
|
||||
"padding-in-buttom":2,
|
||||
|
||||
padding-in-left:1,
|
||||
padding-in-right:1,
|
||||
padding-in-top:1,
|
||||
padding-in-buttom:1,
|
||||
# render program:
|
||||
"program-vert":"THEME:shape/aaRenderShape.vert?lib=ewol",
|
||||
"program-frag":"THEME:shape/aaRenderShape.frag?lib=ewol",
|
||||
|
||||
object-file:"THEME:///Button.obj?lib=ewol",
|
||||
object-size:"1,1,1"
|
||||
# Object to render (with modification)
|
||||
"object-file":"THEME:shape/Button.emf?lib=ewol",
|
||||
|
||||
"palette":"THEME:shape/palette_gui.json?lib=ewol",
|
||||
|
||||
"change-time":200
|
||||
}
|
||||
|
@ -1,52 +0,0 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
struct widgetStateProperty {
|
||||
int stateOld;
|
||||
int stateNew;
|
||||
float transition;
|
||||
};
|
||||
|
||||
uniform widgetStateProperty EW_status;
|
||||
|
||||
// Input :
|
||||
attribute vec2 EW_coord2d;
|
||||
attribute vec2 EW_widgetPropertyPos;
|
||||
uniform mat4 EW_MatrixTransformation;
|
||||
uniform vec4 EW_foreground;
|
||||
uniform vec4 EW_foregroundHover;
|
||||
uniform vec4 EW_foregroundSelected;
|
||||
uniform vec4 EW_foregroundPressed;
|
||||
|
||||
// output :
|
||||
varying vec2 v_propPos;
|
||||
varying vec4 v_colorTansition;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = EW_MatrixTransformation * vec4(EW_coord2d, 0.0, 1.0);
|
||||
// transmit position of the curent element (intermolated ...)
|
||||
v_propPos = EW_widgetPropertyPos;
|
||||
|
||||
vec4 colorOld = EW_foreground;
|
||||
if(EW_status.stateOld == 1) {
|
||||
colorOld = EW_foregroundPressed;
|
||||
} else if(EW_status.stateOld == 2) {
|
||||
colorOld = EW_foregroundHover;
|
||||
} else if(EW_status.stateOld == 3) {
|
||||
colorOld = EW_foregroundSelected;
|
||||
}
|
||||
vec4 colorNew = EW_foreground;
|
||||
if(EW_status.stateNew == 1) {
|
||||
colorNew = EW_foregroundPressed;
|
||||
} else if(EW_status.stateNew == 2) {
|
||||
colorNew = EW_foregroundHover;
|
||||
} else if(EW_status.stateNew == 3) {
|
||||
colorNew = EW_foregroundSelected;
|
||||
}
|
||||
|
||||
// note : int() is needed for the OpenGL ES platform
|
||||
v_colorTansition = colorOld * (1.0 - EW_status.transition)
|
||||
+ colorNew * EW_status.transition;
|
||||
}
|
80
samples/src/sample/atriasoft/ewol/sampleButton/Appl.java
Normal file
80
samples/src/sample/atriasoft/ewol/sampleButton/Appl.java
Normal file
@ -0,0 +1,80 @@
|
||||
package sample.atriasoft.ewol.sampleButton;
|
||||
|
||||
import org.atriasoft.etk.Configs;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.ewol.context.EwolApplication;
|
||||
import org.atriasoft.ewol.context.EwolContext;
|
||||
|
||||
public class Appl implements EwolApplication {
|
||||
|
||||
//! [ewol_sample_HW_main_application]
|
||||
private void localCreate(final EwolContext context) {
|
||||
//! [ewol_sample_HW_main_parse_arguments]
|
||||
// parse all the argument of the application
|
||||
for (int iii = 0; iii < context.getCmd().size(); iii++) {
|
||||
String tmpppp = context.getCmd().get(iii);
|
||||
if (tmpppp == "-h" || tmpppp == "--help") {
|
||||
Log.print(" -h/--help display this help");
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
//! [ewol_sample_HW_main_parse_arguments]
|
||||
//! [ewol_sample_HW_main_set_windows_size]
|
||||
// TODO : Remove this: Move if in the windows properties
|
||||
context.setSize(new Vector2f(800, 600));
|
||||
//! [ewol_sample_HW_main_set_windows_size]
|
||||
//! [ewol_sample_HW_main_set_font_property]
|
||||
// select font preference of der with a basic application size
|
||||
Configs.getConfigFonts().set("FreeSherif", 48);
|
||||
//! [ewol_sample_HW_main_set_font_property]
|
||||
//! [ewol_sample_HW_main_set_windows]
|
||||
// Create the windows
|
||||
MainWindows basicWindows = new MainWindows();
|
||||
// configure the ewol context to use the new windows
|
||||
context.setWindows(basicWindows);
|
||||
//! [ewol_sample_HW_main_set_windows]
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final EwolContext context) {
|
||||
Log.info("Application onCreate: [BEGIN]");
|
||||
localCreate(context);
|
||||
Log.info("Application onCreate: [ END ]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy(final EwolContext context) {
|
||||
Log.info("Application onDestroy: [BEGIN]");
|
||||
|
||||
Log.info("Application onDestroy: [ END ]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(final EwolContext context) {
|
||||
Log.info("Application onPause: [BEGIN]");
|
||||
|
||||
Log.info("Application onPause: [ END ]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(final EwolContext context) {
|
||||
Log.info("Application onResume: [BEGIN]");
|
||||
|
||||
Log.info("Application onResume: [ END ]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(final EwolContext context) {
|
||||
Log.info("Application onStart: [BEGIN]");
|
||||
|
||||
Log.info("Application onStart: [ END ]");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(final EwolContext context) {
|
||||
Log.info("Application onStop: [BEGIN]");
|
||||
|
||||
Log.info("Application onStop: [ END ]");
|
||||
}
|
||||
|
||||
}
|
39
samples/src/sample/atriasoft/ewol/sampleButton/Log.java
Normal file
39
samples/src/sample/atriasoft/ewol/sampleButton/Log.java
Normal file
@ -0,0 +1,39 @@
|
||||
package sample.atriasoft.ewol.sampleButton;
|
||||
|
||||
public class Log {
|
||||
private static final String LIBNAME = "sampleEntry";
|
||||
|
||||
public static void critical(final String data) {
|
||||
System.out.println("[C] " + Log.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void debug(final String data) {
|
||||
System.out.println("[D] " + Log.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void error(final String data) {
|
||||
System.out.println("[E] " + Log.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void info(final String data) {
|
||||
System.out.println("[I] " + Log.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void print(final String data) {
|
||||
System.out.println(data);
|
||||
}
|
||||
|
||||
public static void todo(final String data) {
|
||||
System.out.println("[TODO] " + Log.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void verbose(final String data) {
|
||||
System.out.println("[V] " + Log.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
public static void warning(final String data) {
|
||||
System.out.println("[W] " + Log.LIBNAME + " | " + data);
|
||||
}
|
||||
|
||||
private Log() {}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package sample.atriasoft.ewol.sampleButton;
|
||||
|
||||
import org.atriasoft.etk.math.Vector2b;
|
||||
import org.atriasoft.ewol.widget.Button;
|
||||
import org.atriasoft.ewol.widget.Sizer;
|
||||
import org.atriasoft.ewol.widget.Sizer.DisplayMode;
|
||||
import org.atriasoft.ewol.widget.Windows;
|
||||
|
||||
public class MainWindows extends Windows {
|
||||
|
||||
public MainWindows() {
|
||||
setPropertyTitle("Simple Button test");
|
||||
//EwolObject.getContext().getFontDefault().setName("FreeSans");
|
||||
|
||||
Sizer sizerMain = new Sizer(DisplayMode.modeVert);
|
||||
sizerMain.setPropertyExpand(new Vector2b(true, true));
|
||||
sizerMain.setPropertyFill(new Vector2b(true, true));
|
||||
setSubWidget(sizerMain);
|
||||
|
||||
Button simpleButton = new Button();
|
||||
simpleButton.setPropertyValue("Top Button");
|
||||
simpleButton.setPropertyExpand(new Vector2b(true, true));
|
||||
simpleButton.setPropertyFill(new Vector2b(true, false));
|
||||
sizerMain.subWidgetAdd(simpleButton);
|
||||
|
||||
Button simpleButton2 = new Button();
|
||||
simpleButton2.setPropertyValue("Botom Button");
|
||||
simpleButton2.setPropertyExpand(new Vector2b(true, true));
|
||||
simpleButton2.setPropertyFill(new Vector2b(false, true));
|
||||
sizerMain.subWidgetAdd(simpleButton2);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package sample.atriasoft.ewol.sampleButton;
|
||||
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.ewol.Ewol;
|
||||
|
||||
public class SampleButtonMain {
|
||||
public static void main(final String[] args) {
|
||||
Ewol.init();
|
||||
//Uri.addLibrary("ne", MainCollisionTest.class, "testDataLoxelEngine/");
|
||||
Uri.setApplication(MainWindows.class);
|
||||
Ewol.run(new Appl(), args);
|
||||
}
|
||||
|
||||
private SampleButtonMain() {}
|
||||
}
|
@ -9,7 +9,7 @@ import org.atriasoft.ewol.widget.Windows;
|
||||
public class MainWindows extends Windows {
|
||||
|
||||
public MainWindows() {
|
||||
setPropertyTitle("Simple sample test");
|
||||
setPropertyTitle("Simple Entry test");
|
||||
//EwolObject.getContext().getFontDefault().setName("FreeSans");
|
||||
|
||||
Sizer sizerMain = new Sizer(DisplayMode.modeVert);
|
||||
|
@ -1,107 +1,296 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
package org.atriasoft.ewol.widget;
|
||||
|
||||
import org.atriasoft.esignal.Connection;
|
||||
import org.atriasoft.esignal.SignalEmpty;
|
||||
import org.atriasoft.etk.Color;
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector2i;
|
||||
import org.atriasoft.ewol.Padding;
|
||||
import org.atriasoft.ewol.annotation.EwolDescription;
|
||||
import org.atriasoft.ewol.annotation.EwolSignal;
|
||||
import org.atriasoft.ewol.compositing.CompositingGraphicContext;
|
||||
import org.atriasoft.ewol.compositing.GuiShape;
|
||||
import org.atriasoft.ewol.compositing.GuiShapeMode;
|
||||
import org.atriasoft.ewol.event.EventInput;
|
||||
import org.atriasoft.ewol.event.EventTime;
|
||||
import org.atriasoft.ewol.internal.Log;
|
||||
import org.atriasoft.ewol.object.EwolObject;
|
||||
import org.atriasoft.exml.annotation.XmlManaged;
|
||||
import org.atriasoft.exml.annotation.XmlName;
|
||||
import org.atriasoft.exml.annotation.XmlProperty;
|
||||
import org.atriasoft.gale.key.KeyStatus;
|
||||
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
* Entry box display :
|
||||
*
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~
|
||||
* ----------------------------------------------
|
||||
* | Text Label |
|
||||
* ----------------------------------------------
|
||||
* ~~~~~~~~~~~~~~~~~~~~~~
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/debug.hpp>
|
||||
#include <ewol/compositing/Text.hpp>
|
||||
#include <ewol/compositing/Image.hpp>
|
||||
#include <ewol/compositing/Shaper.hpp>
|
||||
#include <ewol/widget/Container2.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
#include <esignal/Signal.hpp>
|
||||
|
||||
|
||||
|
||||
namespace ewol {
|
||||
namespace widget {
|
||||
class Button;
|
||||
using Button = ememory::Ptr<ewol::widget::Button>;
|
||||
using ButtonWeak = ememory::WeakPtr<ewol::widget::Button>;
|
||||
/**
|
||||
* a composed button is a button with an inside composed with the specify XML element
|
||||
* ==> this permit to generate standard element simple
|
||||
*/
|
||||
class Button : public ewol::widget::Container2 {
|
||||
public:
|
||||
enum buttonLock{
|
||||
lockNone, //!< normal status of the button
|
||||
lockWhenPressed, //!< When the state is set in pressed, the status stay in this one
|
||||
lockWhenReleased, //!< When the state is set in not pressed, the status stay in this one
|
||||
lockAccess, //!< all event are trashed == > acctivity of the button is disable
|
||||
};
|
||||
public: // Event list
|
||||
esignal::Signal<> signalPressed;
|
||||
esignal::Signal<> signalDown;
|
||||
esignal::Signal<> signalUp;
|
||||
esignal::Signal<> signalEnter;
|
||||
esignal::Signal<> signalLeave;
|
||||
esignal::Signal<bool> signalValue;
|
||||
public: // propertie list
|
||||
eproperty::Value<etk::Uri> propertyShape; //!< shaper name property
|
||||
eproperty::Value<bool> propertyValue; //!< Current state of the button.
|
||||
eproperty::List<enum buttonLock> propertyLock; //!< Current lock state of the button.
|
||||
eproperty::Value<bool> propertyToggleMode; //!< The button is able to toggle.
|
||||
eproperty::Value<bool> propertyEnableSingle; //!< When a single subwidget is set display all time it.
|
||||
private:
|
||||
ewol::compositing::Shaper this.shaper; //!< Compositing theme.
|
||||
protected:
|
||||
/**
|
||||
* Constructor
|
||||
* @param _shaperName Shaper file properties
|
||||
*/
|
||||
Button();
|
||||
void init() ;
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(Button, "Button");
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
~Button();
|
||||
private:
|
||||
boolean this.mouseHover; //!< Flag to know where the mouse is (inside the displayed widget (if not fill)).
|
||||
boolean this.buttonPressed; //!< Flag to know if the button is curently pressed.
|
||||
// hover area :
|
||||
Vector2f this.selectableAreaPos; //!< Start position of the events
|
||||
Vector2f this.selectableAreaSize; //!< size of the event positions
|
||||
private:
|
||||
/**
|
||||
* internal system to change the property of the current status
|
||||
* @param _newStatusId new state
|
||||
*/
|
||||
void changeStatusIn(int _newStatusId);
|
||||
/**
|
||||
* update the status with the internal satte of the button ...
|
||||
*/
|
||||
void CheckStatus();
|
||||
protected: // Derived function
|
||||
void onDraw() ;
|
||||
public:
|
||||
void calculateMinMaxSize() ;
|
||||
void onChangeSize() ;
|
||||
void onRegenerateDisplay() ;
|
||||
boolean onEventInput( ewol::event::Input _event) ;
|
||||
boolean onEventEntry( ewol::event::Entry _event) ;
|
||||
void onDetectPresenceToggleWidget() {
|
||||
propertyToggleMode.set(true);
|
||||
public class Button extends Widget {
|
||||
/// color property of the text foreground
|
||||
private int colorIdTextFg;
|
||||
/// text display this.text
|
||||
private final CompositingGraphicContext gc = new CompositingGraphicContext();
|
||||
/// Periodic call handle to remove it when needed
|
||||
protected Connection periodicConnectionHanble = new Connection();
|
||||
@XmlManaged
|
||||
@XmlProperty
|
||||
@XmlName(value = "config")
|
||||
@EwolDescription(value = "configuration of the widget")
|
||||
private Uri propertyConfig = new Uri("THEME", "shape/Button.json", "ewol");
|
||||
|
||||
@XmlManaged
|
||||
@XmlProperty
|
||||
@XmlName(value = "value")
|
||||
@EwolDescription(value = "Value display in the entry (decorated text)")
|
||||
private String propertyValue = "Test Text..."; //!< string that must be displayed
|
||||
|
||||
private GuiShape shape;
|
||||
@EwolSignal(name = "down", description = "Button is Down")
|
||||
public SignalEmpty signalDown = new SignalEmpty();
|
||||
@EwolSignal(name = "up", description = "Button is Up")
|
||||
public SignalEmpty signalUp = new SignalEmpty();
|
||||
@EwolSignal(name = "click", description = "Button is Clicked")
|
||||
public SignalEmpty signalClick = new SignalEmpty();
|
||||
|
||||
// element over:
|
||||
Vector2f overPositionStart = Vector2f.ZERO;
|
||||
Vector2f overPositionStop = Vector2f.ZERO;
|
||||
private boolean isDown;
|
||||
|
||||
/**
|
||||
* Constuctor
|
||||
*/
|
||||
public Button() {
|
||||
this.propertyCanFocus = true;
|
||||
onChangePropertyShaper();
|
||||
markToRedraw();
|
||||
this.shape = new GuiShape(this.propertyConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateMinMaxSize() {
|
||||
// call main class
|
||||
super.calculateMinMaxSize();
|
||||
// get generic padding
|
||||
Padding padding = Padding.ZERO;
|
||||
if (this.shape != null) {
|
||||
padding = this.shape.getPadding();
|
||||
}
|
||||
Vector2i minHeight = this.gc.calculateTextSize(this.propertyValue);
|
||||
|
||||
Vector2f minimumSizeBase = new Vector2f(minHeight.x(), minHeight.y());
|
||||
// add padding :
|
||||
minimumSizeBase = minimumSizeBase.add(padding.x(), padding.y());
|
||||
this.minSize = Vector2f.max(this.minSize, minimumSizeBase);
|
||||
// verify the min max of the min size ...
|
||||
checkMinSize();
|
||||
Log.error("min size = " + this.minSize);
|
||||
}
|
||||
|
||||
protected void changeStatusIn(final GuiShapeMode newStatusId) {
|
||||
if (this.shape.changeStatusIn(newStatusId)) {
|
||||
if (!this.periodicConnectionHanble.isConnected()) {
|
||||
Log.error("REQUEST: connection on operiodic call");
|
||||
this.periodicConnectionHanble = EwolObject.getObjectManager().periodicCall.connect(this, Button::periodicCall);
|
||||
}
|
||||
markToRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
public Uri getPropertyConfig() {
|
||||
return this.propertyConfig;
|
||||
}
|
||||
|
||||
public String getPropertyValue() {
|
||||
return this.propertyValue;
|
||||
}
|
||||
|
||||
|
||||
protected void onChangePropertyShaper() {
|
||||
if (this.shape == null) {
|
||||
this.shape = new GuiShape(this.propertyConfig);
|
||||
} else {
|
||||
this.shape.setSource(this.propertyConfig);
|
||||
}
|
||||
}
|
||||
|
||||
protected void onChangePropertyTextWhenNothing() {
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
protected void onChangePropertyValue() {
|
||||
String newData = this.propertyValue;
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw() {
|
||||
if (this.shape != null) {
|
||||
this.shape.draw(this.gc.getResourceTexture(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onEventInput(final EventInput event) {
|
||||
Vector2f relPos = relativePosition(event.pos());
|
||||
Log.verbose("Event on Input ... " + event + " relPos = "+ relPos);
|
||||
if (event.inputId() == 0) {
|
||||
if (!this.isDown) {
|
||||
if (KeyStatus.leave == event.status()) {
|
||||
changeStatusIn(GuiShapeMode.NORMAL);
|
||||
} else {
|
||||
Log.verbose("Detect Over : " + this.overPositionStart + " -> " + this.overPositionStop);
|
||||
if (relPos.x() > this.overPositionStart.x() && relPos.y() > this.overPositionStart.y() && relPos.x() < this.overPositionStop.x() && relPos.y() < this.overPositionStop.y()) {
|
||||
changeStatusIn(GuiShapeMode.OVER);
|
||||
} else {
|
||||
changeStatusIn(GuiShapeMode.NORMAL);
|
||||
}
|
||||
}
|
||||
protected:
|
||||
esignal::Connection this.PCH; //!< Periodic Call Handle to remove it when needed
|
||||
/**
|
||||
* Periodic call to update grapgic display
|
||||
* @param _event Time generic event
|
||||
*/
|
||||
void periodicCall( ewol::event::Time _event);
|
||||
void onLostFocus() ;
|
||||
protected:
|
||||
void onChangePropertyShape();
|
||||
void onChangePropertyValue();
|
||||
void onChangePropertyLock();
|
||||
void onChangePropertyToggleMode();
|
||||
void onChangePropertyEnableSingle();
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
if (event.inputId() == 1) {
|
||||
if (KeyStatus.pressSingle == event.status()) {
|
||||
keepFocus();
|
||||
this.signalClick.emit();
|
||||
//nothing to do ...
|
||||
return true;
|
||||
}
|
||||
if (KeyStatus.down == event.status()) {
|
||||
keepFocus();
|
||||
this.isDown = true;
|
||||
changeStatusIn(GuiShapeMode.SELECT);
|
||||
markToRedraw();
|
||||
this.signalDown.emit();
|
||||
} else if (KeyStatus.move == event.status()) {
|
||||
keepFocus();
|
||||
markToRedraw();
|
||||
} else if (KeyStatus.up == event.status()) {
|
||||
keepFocus();
|
||||
this.isDown = false;
|
||||
this.signalUp.emit();
|
||||
changeStatusIn(GuiShapeMode.OVER);
|
||||
markToRedraw();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegenerateDisplay() {
|
||||
if (!needRedraw()) {
|
||||
//return;
|
||||
}
|
||||
//Log.verbose("Regenerate Display ==> is needed: '" + this.propertyValue + "'");
|
||||
this.shape.clear();
|
||||
this.gc.clear();
|
||||
if (this.colorIdTextFg >= 0) {
|
||||
//this.text.setDefaultColorFg(this.shape.getColor(this.colorIdTextFg));
|
||||
//this.text.setDefaultColorBg(this.shape.getColor(this.colorIdTextBg));
|
||||
//this.text.setCursorColor(this.shape.getColor(this.colorIdCursor));
|
||||
//this.text.setSelectionColor(this.shape.getColor(this.colorIdSelection));
|
||||
}
|
||||
Padding padding = this.shape.getPadding();
|
||||
|
||||
Vector2f tmpSizeShaper = this.minSize;
|
||||
if (this.propertyFill.x()) {
|
||||
tmpSizeShaper = tmpSizeShaper.withX(this.size.x());
|
||||
}
|
||||
if (this.propertyFill.y()) {
|
||||
tmpSizeShaper = tmpSizeShaper.withY(this.size.y());
|
||||
}
|
||||
|
||||
Vector2f tmpOriginShaper = this.size.less(tmpSizeShaper).multiply(0.5f);
|
||||
Vector2f tmpSizeText = tmpSizeShaper.less(padding.x(), padding.y());
|
||||
//Vector2f tmpOriginText = this.size.less(tmpSizeText).multiply(0.5f);
|
||||
Vector2f tmpOriginText = new Vector2f(0, this.gc.getTextSize());
|
||||
// sometimes, the user define an height bigger than the real size needed == > in this case we need to center the text in the shaper ...
|
||||
/*
|
||||
int minHeight = this.gc.getTextHeight();
|
||||
if (tmpSizeText.y() > minHeight) {
|
||||
tmpOriginText = tmpOriginText.add(0, (tmpSizeText.y() - minHeight) * 0.5f);
|
||||
}
|
||||
*/
|
||||
// fix all the position in the int class:
|
||||
tmpSizeShaper = Vector2f.clipInt(tmpSizeShaper);
|
||||
tmpOriginShaper = Vector2f.clipInt(tmpOriginShaper);
|
||||
tmpSizeText = Vector2f.clipInt(tmpSizeText);
|
||||
tmpOriginText = Vector2f.clipInt(tmpOriginText);
|
||||
|
||||
this.gc.clear();
|
||||
this.gc.setSize((int)tmpSizeText.x(), (int)tmpSizeText.y());
|
||||
|
||||
this.gc.setColorFill(Color.BLACK);
|
||||
this.gc.setColorStroke(Color.NONE);
|
||||
this.gc.setStrokeWidth(1);
|
||||
this.gc.text(tmpOriginText, this.propertyValue);
|
||||
this.overPositionStart = tmpOriginShaper;
|
||||
this.overPositionStop = tmpOriginShaper.add(tmpSizeShaper);
|
||||
this.shape.setShape(tmpOriginShaper, tmpSizeShaper, tmpOriginText, tmpSizeText);
|
||||
this.gc.flush();
|
||||
this.shape.flush();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Periodic call to update grapgic display
|
||||
* @param _event Time generic event
|
||||
*/
|
||||
protected static void periodicCall(final Button self, final EventTime event) {
|
||||
Log.verbose("Periodic call on Entry(" + event + ")");
|
||||
if (!self.shape.periodicCall(event)) {
|
||||
self.periodicConnectionHanble.close();
|
||||
}
|
||||
self.markToRedraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* internal check the value with RegExp checking
|
||||
* @param newData The new string to display
|
||||
*/
|
||||
protected void setInternalValue(final String newData) {
|
||||
String previous = this.propertyValue;
|
||||
// check the RegExp :
|
||||
if (newData.length() > 0) {
|
||||
/*
|
||||
if (this.regex.parse(_newData, 0, _newData.size()) == false) {
|
||||
Log.info("The input data does not match with the regExp '" + _newData + "' Regex='" + propertyRegex + "'" );
|
||||
return;
|
||||
}
|
||||
if (this.regex.start() != 0) {
|
||||
Log.info("The input data does not match with the regExp '" + _newData + "' Regex='" + propertyRegex + "' (start position error)" );
|
||||
return;
|
||||
}
|
||||
if (this.regex.stop() != _newData.size()) {
|
||||
Log.info("The input data does not match with the regExp '" + _newData + "' Regex='" + propertyRegex + "' (stop position error)" );
|
||||
return;
|
||||
}
|
||||
*/
|
||||
}
|
||||
this.propertyValue = newData;
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
public void setPropertyConfig(final Uri propertyConfig) {
|
||||
if (this.propertyConfig.equals(propertyConfig)) {
|
||||
return;
|
||||
}
|
||||
this.propertyConfig = propertyConfig;
|
||||
onChangePropertyShaper();
|
||||
}
|
||||
|
||||
|
||||
public void setPropertyValue(final String propertyValue) {
|
||||
if (this.propertyValue.equals(propertyValue)) {
|
||||
return;
|
||||
}
|
||||
this.propertyValue = propertyValue;
|
||||
onChangePropertyValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user