[DEV] remove dependency with scenarium

This commit is contained in:
Edouard DUPIN 2022-10-03 23:44:48 +02:00
parent 757b5c78e7
commit 760fd95b60
21 changed files with 456 additions and 249 deletions

View File

@ -9,7 +9,8 @@ list_elem = [
"Entry",
"Tick",
"ScrollBar",
"Button"
"Button",
"Slider"
]
for elem in list_elem:

View File

@ -1,134 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <ewol/widget/Slider.hpp>
#include <ewol/widget/Manager.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ewol::widget::Slider);
int dotRadius = 6;
ewol::widget::Slider::Slider() :
signalChange(this, "change", ""),
propertyValue(this, "value",
0.0f,
"Value of the Slider",
ewol::widget::Slider::onChangePropertyValue),
propertyMinimum(this, "min",
0.0f,
"Minium value",
ewol::widget::Slider::onChangePropertyMinimum),
propertyMaximum(this, "max",
10.0f,
"Maximum value",
ewol::widget::Slider::onChangePropertyMaximum),
propertyStep(this, "step",
1.0f,
"Step size",
ewol::widget::Slider::onChangePropertyStep) {
addObjectType("ewol::widget::Slider");
this.textColorFg = etk::color::black;
this.textColorBg = etk::color::black;
this.textColorBg.setA(0x3F);
propertyCanFocus.setDirectCheck(true);
// Limit event at 1:
setMouseLimit(1);
}
ewol::widget::Slider::~Slider() {
}
void ewol::widget::Slider::calculateMinMaxSize() {
Vector2f minTmp = propertyMinSize.getPixel();
this.minSize.setValue(etk::max(minTmp.x(), 40.0f),
etk::max(minTmp.y(), dotRadius*2.0f) );
markToRedraw();
}
void ewol::widget::Slider::onDraw() {
this.draw.draw();
}
void ewol::widget::Slider::onRegenerateDisplay() {
if (needRedraw() == false) {
return;
}
// clean the object list ...
this.draw.clear();
this.draw.setColor(this.textColorFg);
// draw a line :
this.draw.setThickness(1);
this.draw.setPos(Vector3f(dotRadius, this.size.y()/2, 0) );
this.draw.lineTo(Vector3f(this.size.x()-dotRadius, this.size.y()/2, 0) );
this.draw.setThickness(0);
etk::Color<> borderDot = this.textColorFg;
borderDot.setA(borderDot.a()/2);
this.draw.setPos(Vector3f(4+((propertyValue-propertyMinimum)/(propertyMaximum-propertyMinimum))*(this.size.x()-2*dotRadius), this.size.y()/2, 0) );
this.draw.setColorBg(borderDot);
this.draw.circle(dotRadius);
this.draw.setColorBg(this.textColorFg);
this.draw.circle(dotRadius/1.6);
}
boolean ewol::widget::Slider::onEventInput( ewol::event::Input _event) {
Vector2f relativePos = relativePosition(_event.getPos());
//Log.debug("Event on Slider ..." + _event);
if (1 == _event.getId()) {
if( KeyStatus::pressSingle == _event.getStatus()
|| KeyStatus::move == _event.getStatus()) {
// get the new position :
Log.verbose("Event on Slider (" + relativePos.x() + "," + relativePos.y() + ")");
float oldValue = *propertyValue;
updateValue(*propertyMinimum + (float)(relativePos.x() - dotRadius) / (this.size.x()-2*dotRadius) * (*propertyMaximum-*propertyMinimum));
if (oldValue != *propertyValue) {
Log.verbose(" new value : " + *propertyValue + " in [" + *propertyMinimum + ".." + *propertyMaximum + "]");
signalChange.emit(*propertyValue);
}
return true;
}
}
return false;
}
void ewol::widget::Slider::updateValue(float _newValue) {
_newValue = etk::max(etk::min(_newValue, *propertyMaximum), *propertyMinimum);
if (*propertyStep == 0.0f) {
propertyValue.setDirect(_newValue);
} else {
float basicVal = (long)(_newValue / *propertyStep);
propertyValue.setDirect(basicVal * *propertyStep);
}
markToRedraw();
}
void ewol::widget::Slider::onChangePropertyValue() {
updateValue(*propertyValue);
return;
}
void ewol::widget::Slider::onChangePropertyMinimum() {
updateValue(*propertyValue);
return;
}
void ewol::widget::Slider::onChangePropertyMaximum() {
updateValue(*propertyValue);
return;
}
void ewol::widget::Slider::onChangePropertyStep() {
updateValue(*propertyValue);
return;
}

View File

@ -1,5 +1,5 @@
EMF(STRING)
# Blender v3.1.2 EMF File: 'Button.blend'
# Blender v3.2.2 EMF File: 'Button.blend'
Mesh:CheckBox_Cube
Vertex:16
12.043998 11.983889 -5.389912|12.043998 -12.104107 -5.391196|12.043998 11.983492 2.052411|12.043998 -12.104505 2.051126|-12.043998 11.983889 -5.389912|-12.043998 -12.104107 -5.391196|-12.043998 11.983492 2.052411|-12.043998 -12.104505 2.051126|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.199120 -10.192897 3.116539|-10.199120 10.181330 3.117619|10.199120 10.181330 3.117619|10.199120 -10.192897 3.116539|

View File

@ -1,5 +1,5 @@
EMF(STRING)
# Blender v3.1.2 EMF File: 'Entry.blend'
# Blender v3.2.2 EMF File: 'Entry.blend'
Mesh:CheckBox_Cube
Vertex:16
13.004523 12.944430 -5.686628|13.004523 -13.064616 -5.688015|13.004523 12.944001 2.349230|13.004523 -13.065046 2.347842|-13.004523 12.944430 -5.686628|-13.004523 -13.064616 -5.688015|-13.004523 12.944001 2.349230|-13.004523 -13.065046 2.347842|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.199120 -10.192897 3.116539|-10.199120 10.181330 3.117619|10.199120 10.181330 3.117619|10.199120 -10.192897 3.116539|

View File

@ -1,6 +1,6 @@
EMF(STRING)
# Blender v3.1.2 EMF File: 'ScrollBar.blend'
Mesh:ScrollBar_Cube
# Blender v3.2.2 EMF File: 'ScrollBar.blend'
Mesh:CheckBox_Cube
Vertex:24
0.999633 0.939126 0.692412|0.999633 -1.060139 0.692306|-0.999632 0.939126 0.692412|-0.999633 -1.060139 0.692306|0.612843 1.917809 -0.016061|1.978234 0.460425 -0.016089|1.978234 -0.581316 -0.016244|0.612843 -2.038658 -0.016272|1.978234 0.460402 0.387109|0.612843 1.917744 0.387137|1.490144 1.429646 0.539397|0.612843 -2.038723 0.386926|1.978234 -0.581340 0.386954|1.490132 -1.550629 0.539242|-1.978234 0.460425 -0.016089|-0.612843 1.917809 -0.016061|-0.612843 -2.038658 -0.016272|-1.978234 -0.581316 -0.016244|-0.612843 1.917744 0.387137|-1.978234 0.460402 0.387109|-1.490144 1.429646 0.539397|-1.978234 -0.581340 0.386954|-0.612843 -2.038723 0.386926|-1.490132 -1.550629 0.539242|
UV-mapping:

View File

@ -1,5 +1,5 @@
EMF(STRING)
# Blender v3.1.2 EMF File: 'CheckBox.blend'
# Blender v3.2.2 EMF File: 'Tick.blend'
Mesh:CheckBox_Cube
Vertex:16
12.043998 11.983889 -5.389912|12.043998 -12.104107 -5.391196|12.043998 11.983492 2.052411|12.043998 -12.104505 2.051126|-12.043998 11.983889 -5.389912|-12.043998 -12.104107 -5.391196|-12.043998 11.983492 2.052411|-12.043998 -12.104505 2.051126|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.199120 -10.192897 3.116539|-10.199120 10.181330 3.117619|10.199120 10.181330 3.117619|10.199120 -10.192897 3.116539|

View File

@ -31,6 +31,9 @@
"gui_checked":{
"Kd":"0.0 0.0 0.0"
},
"gui_slider":{
"Kd":"0.0 1.0 0.0"
},
"gui_border_inside":{
"Kd":"0.5 0.5 0.5"
}

View File

@ -1,7 +1,7 @@
package sample.atriasoft.ewol;
import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
import org.atriasoft.reggol.LogLevel;
import org.atriasoft.reggol.Logger;
public class Log {
private static final boolean FORCE_ALL = false;

View File

@ -5,8 +5,8 @@
*/
package sample.atriasoft.ewol.validationWidget;
import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
import org.atriasoft.reggol.LogLevel;
import org.atriasoft.reggol.Logger;
public class Log {
private static final String LIB_NAME = "ejson-test";

View File

@ -17,6 +17,10 @@ public class MainWindows extends BasicWindows {
public MainWindows() {
setPropertyTitle("Test all compositing");
this.titles.add("test Slider");
this.values.add("""
<Slider name='My name is Bob' fill='true,false,false' expand='true'/>
""");
this.titles.add("test Entry");
this.values.add("""
<Entry name='My name is Bob' fill='true,false,false' expand='true'/>

View File

@ -22,7 +22,7 @@ open module org.atriasoft.ewol {
requires transitive org.atriasoft.esvg;
requires transitive org.atriasoft.exml;
requires transitive org.atriasoft.ejson;
requires transitive io.scenarium.logger;
requires transitive org.atriasoft.reggol;
requires org.atriasoft.loader3d;
requires org.atriasoft.egami;
requires java.base;

View File

@ -28,6 +28,13 @@ import org.atriasoft.loader3d.resources.ResourcePaletteFile;
// TODO : load image
// TODO : Abstaraction between states (call by name and the system greate IDs
public class GuiShape extends Compositing {
private class SpecificValues {
public Matrix4f transform = Matrix4f.IDENTITY;
public Vector3f offsetScaleInside = Vector3f.ZERO;
public Vector3f offsetScaleOutside = Vector3f.ZERO;
public ResourceMesh mesh = null;
}
private static final int SHAPER_POS_BOTTOM = 3;
private static final int SHAPER_POS_LEFT = 0;
private static final int SHAPER_POS_RIGHT = 2;
@ -36,9 +43,9 @@ public class GuiShape extends Compositing {
private int confIdPaletteFile = -1; //!< Palette of the display
private final int[] confIdPaddingIn = new int[4]; //!< Padding in property : X-left X-right Y-top Y-buttom
private final int[] confIdPaddingOut = new int[4]; //!< Padding out property : X-left X-right Y-top Y-buttom
// External theme config:
private ResourceConfigFile config = null; //!< pointer on the config file resources
// External theme configuration:
private ResourceConfigFile config = null; //!< pointer on the config file resources
private int confObjectFile = -1; //!< Config Id of the object file to display
private int confObjectFile2 = -1; //!< Config Id of the object file to display
private int confProgramFileFrag = -1; //!< ConfigFile opengGl program Name
@ -52,22 +59,19 @@ public class GuiShape extends Compositing {
private int oGLPaletteOffset = -1; //!< openGL id on the element (offset for the palet rendering)
private int oGLOffsetScaleInside = -1;
private int oGLOffsetScaleOutside = -1;
// openGL shaders programs:
private ResourceProgram oGLprogram = null; //!< pointer on the opengl display program
// For the Image :
private ResourcePaletteFile palette;
private ResourceTexture2 texture;
private final ResourceMesh[] mesh = new ResourceMesh[2];
private Padding sizeObject = Padding.ZERO;
private int stateActivate = -1; //!< Activate state of the element
private GuiShapeMode stateNew = GuiShapeMode.NORMAL; //!< destination state
private GuiShapeMode stateOld = GuiShapeMode.NORMAL; //!< previous state
private Matrix4f transform = Matrix4f.IDENTITY;
private Uri uri; //!< Name of the configuration of the shaper.
private Vector3f offsetScaleInside = Vector3f.ZERO;
private Vector3f offsetScaleOutside = Vector3f.ZERO;
private Uri uri; //!< Name of the configuration of the shaper.
private final SpecificValues[] valueSpecific = new SpecificValues[2];
// dynamic change:
private float stateTransition = 0; //!< working state between 2 states
@ -133,10 +137,10 @@ public class GuiShape extends Compositing {
// this is a normal case ... the user can choice to have no config basic file ...
return;
}
if (idMesh == 0 && this.mesh[0] == null) {
if (idMesh == 0 && this.valueSpecific[0] == null) {
Log.error("No Object (0) to display ...");
return;
} else if (idMesh == 1 && this.mesh[1] == null) {
} else if (idMesh == 1 && this.valueSpecific[1] == null) {
Log.error("No Object (1) to display ...");
return;
} else if (idMesh < 0 && idMesh > 1) {
@ -151,14 +155,14 @@ public class GuiShape extends Compositing {
// set Matrix : translation/positionMatrix
final Matrix4f projMatrix = OpenGL.getMatrix();
final Matrix4f camMatrix = OpenGL.getCameraMatrix();
final Matrix4f tmpMatrix = this.matrixApply.multiply(this.transform);
final Matrix4f tmpMatrix = this.matrixApply.multiply(this.valueSpecific[idMesh].transform);
this.oGLprogram.use();
this.mesh[idMesh].bindForRendering();
this.valueSpecific[idMesh].mesh.bindForRendering();
this.oGLprogram.uniformMatrix(this.oGLMatrixProjection, projMatrix);
this.oGLprogram.uniformMatrix(this.oGLMatrixTransformation, tmpMatrix);
this.oGLprogram.uniformMatrix(this.oGLMatrixView, camMatrix);
final Set<String> layers = this.mesh[idMesh].getLayers();
final Set<String> layers = this.valueSpecific[idMesh].mesh.getLayers();
Log.verbose("get layers:" + layers);
// Texture:
final float imageDelta = (float) 1 / ResourcePaletteFile.getHeight();
@ -190,21 +194,21 @@ public class GuiShape extends Compositing {
//Log.verbose("plop: " + this.offsetScaleOutside);
//Log.verbose("plop: " + this.offsetScaleInside);
this.oGLprogram.uniformVector(this.oGLOffsetScaleInside, this.offsetScaleInside);
this.oGLprogram.uniformVector(this.oGLOffsetScaleOutside, this.offsetScaleOutside);
this.oGLprogram.uniformVector(this.oGLOffsetScaleInside, this.valueSpecific[idMesh].offsetScaleInside);
this.oGLprogram.uniformVector(this.oGLOffsetScaleOutside, this.valueSpecific[idMesh].offsetScaleOutside);
this.texture.bindForRendering(0);
this.mesh[idMesh].render("palette");
this.valueSpecific[idMesh].mesh.render("palette");
if (secondaryTexture != null) {
this.oGLprogram.uniformFloat(this.oGLPaletteOffset, 0);
secondaryTexture.bindForRendering(0);
this.mesh[idMesh].render("gui_dynamic_1");
this.valueSpecific[idMesh].mesh.render("gui_dynamic_1");
}
// Request the draw of the elements:
this.mesh[idMesh].render();
this.valueSpecific[idMesh].mesh.render();
this.mesh[idMesh].unBindForRendering();
this.valueSpecific[idMesh].mesh.unBindForRendering();
this.oGLprogram.unUse();
OpenGL.disable(Flag.flag_depthTest);
}
@ -369,8 +373,10 @@ public class GuiShape extends Compositing {
}
final String objectFile = this.config.getString(this.confObjectFile);
if (!objectFile.isEmpty()) {
this.mesh[0] = ResourceMesh.create(Uri.valueOf(objectFile));
final List<Vector3f> verticesToModify = this.mesh[0].getGeneratedPosition();
final int idMesh = 0;
this.valueSpecific[idMesh] = new SpecificValues();
this.valueSpecific[idMesh].mesh = ResourceMesh.create(Uri.valueOf(objectFile));
final List<Vector3f> verticesToModify = this.valueSpecific[idMesh].mesh.getGeneratedPosition();
float top = 0;
float bottom = 0;
float left = 0;
@ -379,7 +385,7 @@ public class GuiShape extends Compositing {
float font = 0;
// estimate size of border:
if (verticesToModify == null) {
Log.critical("Element is null : verticesToModify");
Log.critical("Element is null : verticesToModify 1");
return;
}
for (int iii = 0; iii < verticesToModify.size(); iii++) {
@ -391,11 +397,16 @@ public class GuiShape extends Compositing {
font = Math.max(font, verticesToModify.get(iii).z());
}
this.sizeObject = new Padding(Math.abs(left), Math.abs(top), Math.abs(right), Math.abs(bottom));
} else {
final int idMesh = 0;
this.valueSpecific[idMesh] = null;
}
final String objectFile2 = this.config.getString(this.confObjectFile2);
if (!objectFile2.isEmpty()) {
this.mesh[1] = ResourceMesh.create(Uri.valueOf(objectFile2));
final List<Vector3f> verticesToModify = this.mesh[1].getGeneratedPosition();
final int idMesh = 1;
this.valueSpecific[idMesh] = new SpecificValues();
this.valueSpecific[idMesh].mesh = ResourceMesh.create(Uri.valueOf(objectFile2));
final List<Vector3f> verticesToModify = this.valueSpecific[idMesh].mesh.getGeneratedPosition();
float top = 0;
float bottom = 0;
float left = 0;
@ -415,6 +426,9 @@ public class GuiShape extends Compositing {
back = Math.min(back, verticesToModify.get(iii).z());
font = Math.max(font, verticesToModify.get(iii).z());
}
} else {
final int idMesh = 1;
this.valueSpecific[idMesh] = null;
}
}
@ -472,6 +486,36 @@ public class GuiShape extends Compositing {
this.stateActivate = status;
}
public void setShape(final int idMesh, final Vector3f origin, final Vector3f size) {
final Padding tmp = getPadding();
setShape(idMesh, origin, size, origin.add(tmp.left(), tmp.bottom(), 0), size.less(tmp.x(), tmp.y(), 0));
}
public void setShape(final int idMesh, final Vector3f origin, final Vector3f size, final Vector3f insidePos, final Vector3f insideSize) {
final Vector3f halfSize = insideSize.multiply(0.5f);
this.valueSpecific[idMesh].offsetScaleOutside = halfSize;
this.valueSpecific[idMesh].offsetScaleInside = halfSize.add(this.sizeObject.x() * 0.25f, this.sizeObject.y() * 0.25f, 0);
/*
List<Vector3f> verticesToModify = this.mesh.getGeneratedPosition();
float[] newVertices = new float[verticesToModify.size()*3];
for (int iii=0; iii<newVertices.length; ++iii) {
Vector3f tmp = verticesToModify.get(iii);
newVertices[iii*3+0] = getUpdatedPos(tmp.x(), halfSize.x());
newVertices[iii*3+1] = getUpdatedPos(tmp.y(), halfSize.y());
newVertices[iii*3+2] = getUpdatedPos(tmp.z(), halfSize.z());
}
this.mesh.setModifiedPosition(newVertices);
*/
this.valueSpecific[idMesh].transform = Matrix4f.createMatrixTranslate(new Vector3f(origin.x() + size.x() * 0.5f, origin.y() + size.y() * 0.5f, origin.z() + size.z() * 0.5f));
}
// private float getUpdatedPos(final float value, final float halfsize) {
// if (value <= 0.0f) {
// return value - halfsize;
// }
// return value + halfsize;
// }
// @previous
public void setShape(final Vector2f origin, final Vector2f size) {
final Padding tmp = getPadding();
@ -523,8 +567,8 @@ public class GuiShape extends Compositing {
public void setShape(final Vector2f origin, final Vector2f size, final Vector2f insidePos, final Vector2f insideSize) {
//Log.error("Set shape property : origin=" + origin + " size=" + size + " in-pos=" + insidePos + " in-size=" + insideSize);
final Vector2f halfSize = insideSize.multiply(0.5f);
this.offsetScaleOutside = new Vector3f(halfSize.x(), halfSize.y(), 1.0f);
this.offsetScaleInside = new Vector3f(halfSize.x() + this.sizeObject.x() * 0.25f, halfSize.y() + this.sizeObject.y() * 0.25f, 1.0f);
final Vector3f offsetScaleOutside = new Vector3f(halfSize.x(), halfSize.y(), 1.0f);
final Vector3f offsetScaleInside = new Vector3f(halfSize.x() + this.sizeObject.x() * 0.25f, halfSize.y() + this.sizeObject.y() * 0.25f, 1.0f);
/*
List<Vector3f> verticesToModify = this.mesh.getGeneratedPosition();
float[] newVertices = new float[verticesToModify.size()*3];
@ -538,16 +582,17 @@ public class GuiShape extends Compositing {
//this.transform = this.transform.multiply(Matrix4f.createMatrixTranslate(new Vector3f(origin.x() + size.x() * 0.5f, origin.y() + size.y() * 0.5f, 0.0f)));
this.mesh.setModifiedPosition(newVertices);
*/
this.transform = Matrix4f.createMatrixTranslate(new Vector3f(origin.x() + size.x() * 0.5f, origin.y() + size.y() * 0.5f, 0.0f));
final Matrix4f transform = Matrix4f.createMatrixTranslate(new Vector3f(origin.x() + size.x() * 0.5f, origin.y() + size.y() * 0.5f, 0.0f));
for (int iii = 0; iii < 2; iii++) {
if (this.valueSpecific[iii] == null) {
continue;
}
this.valueSpecific[iii].offsetScaleOutside = offsetScaleOutside;
this.valueSpecific[iii].offsetScaleInside = offsetScaleInside;
this.valueSpecific[iii].transform = transform;
}
}
// private float getUpdatedPos(final float value, final float halfsize) {
// if (value <= 0.0f) {
// return value - halfsize;
// }
// return value + halfsize;
// }
public void setShape(final Vector3f origin, final Vector3f size) {
final Padding tmp = getPadding();
setShape(origin, size, origin.add(tmp.left(), tmp.bottom(), 0), size.less(tmp.x(), tmp.y(), 0));
@ -555,8 +600,8 @@ public class GuiShape extends Compositing {
public void setShape(final Vector3f origin, final Vector3f size, final Vector3f insidePos, final Vector3f insideSize) {
final Vector3f halfSize = insideSize.multiply(0.5f);
this.offsetScaleOutside = halfSize;
this.offsetScaleInside = halfSize.add(this.sizeObject.x() * 0.25f, this.sizeObject.y() * 0.25f, 0);
final Vector3f offsetScaleOutside = halfSize;
final Vector3f offsetScaleInside = halfSize.add(this.sizeObject.x() * 0.25f, this.sizeObject.y() * 0.25f, 0);
/*
List<Vector3f> verticesToModify = this.mesh.getGeneratedPosition();
float[] newVertices = new float[verticesToModify.size()*3];
@ -568,7 +613,15 @@ public class GuiShape extends Compositing {
}
this.mesh.setModifiedPosition(newVertices);
*/
this.transform = Matrix4f.createMatrixTranslate(new Vector3f(origin.x() + size.x() * 0.5f, origin.y() + size.y() * 0.5f, origin.z() + size.z() * 0.5f));
final Matrix4f transform = Matrix4f.createMatrixTranslate(new Vector3f(origin.x() + size.x() * 0.5f, origin.y() + size.y() * 0.5f, origin.z() + size.z() * 0.5f));
for (int iii = 0; iii < 2; iii++) {
if (this.valueSpecific[iii] == null) {
continue;
}
this.valueSpecific[iii].offsetScaleOutside = offsetScaleOutside;
this.valueSpecific[iii].offsetScaleInside = offsetScaleInside;
this.valueSpecific[iii].transform = transform;
}
}
/**

View File

@ -1,7 +1,7 @@
package org.atriasoft.ewol.internal;
import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
import org.atriasoft.reggol.LogLevel;
import org.atriasoft.reggol.Logger;
public class Log {
private static final boolean FORCE_ALL = false;

View File

@ -37,13 +37,13 @@ public class Composer extends Container {
public static Widget composerGenerateFile(final Uri uri, final long id) {
final byte[] elemData = Uri.getAllData(uri);
if (elemData == null) {
Log.error("Can not read the Stream : " + uri);
Log.error("Can not read the Stream : {}", uri);
return null;
}
final String dataToParse = new String(elemData);
final Widget tmp = composerGenerateString(dataToParse, id);
if (tmp == null) {
Log.error("Faiul to Load data: {}", uri);
Log.error("Fail to Load data: {}", uri);
}
return tmp;
}

View File

@ -79,7 +79,7 @@ public class ImageDisplay extends Widget {
@AknotManaged
@AknotAttribute
@AknotName(value = "border")
@AknotName(value = "image-border")
@AknotDescription(value = "Border of the image")
public Dimension2f getPropertyBorder() {
return this.propertyBorder;
@ -87,7 +87,7 @@ public class ImageDisplay extends Widget {
@AknotManaged
@AknotAttribute
@AknotName(value = "size")
@AknotName(value = "image-size")
@AknotDescription(value = "Basic display size of the image")
public Dimension2f getPropertyImageSize() {
return this.propertyImageSize;

View File

@ -1,60 +1,340 @@
package org.atriasoft.ewol.widget;
import org.atriasoft.aknot.annotation.AknotAttribute;
import org.atriasoft.aknot.annotation.AknotDescription;
import org.atriasoft.aknot.annotation.AknotManaged;
import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.aknot.annotation.AknotSignal;
import org.atriasoft.esignal.Signal;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.FMath;
import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.etk.math.Vector3i;
import org.atriasoft.ewol.Padding;
import org.atriasoft.ewol.compositing.CompositingDrawing;
import org.atriasoft.ewol.compositing.GuiShape;
import org.atriasoft.ewol.event.EventInput;
import org.atriasoft.ewol.internal.Log;
import org.atriasoft.gale.key.KeyStatus;
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Color.hpp>
#include <ewol/debug.hpp>
#include <ewol/widget/Widget.hpp>
#include <ewol/compositing/Drawing.hpp>
#include <esignal/Signal.hpp>
/**
* @ingroup ewolWidgetGroup
*/
public class Slider extends Widget {
namespace ewol {
namespace widget {
class Slider;
using Slider = ememory::Ptr<ewol::widget::Slider>;
using SliderWeak = ememory::WeakPtr<ewol::widget::Slider>;
/**
* @ingroup ewolWidgetGroup
*/
class Slider : public Widget {
public: // signals
esignal::Signal<float> signalChange;
public:
//eproperty::Value<String> propertyShape; //!< name of the shape used
eproperty::Value<float> propertyValue; //!< current value of the Slider
eproperty::Value<float> propertyMinimum; //!< minimum value of the slider
eproperty::Value<float> propertyMaximum; //!< maximum value of the slider
eproperty::Value<float> propertyStep; //!< step of every iteration of the slider (increment/precision)
protected:
Slider();
public:
DECLARE_WIDGET_FACTORY(Slider, "Slider");
~Slider();
public:
// TODO : Rework the color in the theme ...
void setColor(etk::Color<> _newColor) {
this.textColorFg = _newColor;
};
protected:
ewol::compositing::Drawing this.draw; //!< drawing tool.
etk::Color<> this.textColorFg; //!< Text color
etk::Color<> this.textColorBg; //!< Background color
void updateValue(float _newValue);
public: // Derived function
void onDraw() ;
void calculateMinMaxSize() ;
void onRegenerateDisplay() ;
boolean onEventInput( ewol::event::Input _event) ;
protected:
void onChangePropertyValue();
void onChangePropertyMinimum();
void onChangePropertyMaximum();
void onChangePropertyStep();
};
private Uri propertyConfig = new Uri("THEME", "shape/Slider.json", "ewol");
private Float propertyValue = 0.0f; //!< string that must be displayed
private GuiShape shape = null;
private final GuiShape shapeTop = null;
@AknotSignal
@AknotName("value")
@AknotDescription("Tick value change")
public Signal<Float> signalValue = new Signal<>();
// element over:
Vector3f overPositionStart = Vector3f.ZERO;
Vector3f overPositionStop = Vector3f.ZERO;
Vector3f overCursorPositionStart = Vector3f.ZERO;
Vector3f overCursorPositionStop = Vector3f.ZERO;
//@AknotAutoGenerateProperty("minimum", "configuration of the widget")
private Float propertyMinimum = 0.0f;
private Float propertyMaximum = 10.0f;
private Float propertyStep = 0.1f;
private final Color textColorFg = Color.BLACK; //!< Text color
private final Color textColorBg = Color.BLACK.withA(0x3F); //!< Background color
CompositingDrawing draw = new CompositingDrawing(); //!< drawing tool.
public Slider() {
this.propertyCanFocus = true;
onChangePropertyShaper();
markToRedraw();
// Limit event at 1:
setMouseLimit(1);
}
@Override
public void calculateMinMaxSize() {
// call main class
super.calculateMinMaxSize();
// get generic padding
Padding padding = Padding.ZERO;
if (this.shape != null) {
padding = this.shape.getPadding();
}
final Vector3i minHeight = Vector3i.VALUE_16;
Vector3f minimumSizeBase = new Vector3f(minHeight.x(), minHeight.y(), minHeight.z());
// add padding :
minimumSizeBase = minimumSizeBase.add(padding.x(), padding.y(), padding.z());
this.minSize = Vector3f.max(this.minSize, minimumSizeBase);
// verify the min max of the min size ...
checkMinSize();
Log.error("min size = " + this.minSize);
}
private boolean checkIfOver(final Vector3f relPos) {
return relPos.x() > this.overPositionStart.x() && relPos.y() > this.overPositionStart.y() && relPos.x() < this.overPositionStop.x() && relPos.y() < this.overPositionStop.y();
}
@AknotManaged
@AknotAttribute
@AknotName("config")
@AknotDescription("configuration of the widget")
public Uri getPropertyConfig() {
return this.propertyConfig;
}
@AknotManaged
@AknotAttribute
@AknotName("maximum")
@AknotDescription("Maximum value of the slider")
public Float getPropertyMaximum() {
return this.propertyMaximum;
}
@AknotManaged
@AknotAttribute
@AknotName("minimum")
@AknotDescription("Minimum value of the slider")
public Float getPropertyMinimum() {
return this.propertyMinimum;
}
@AknotManaged
@AknotAttribute
@AknotName("step")
@AknotDescription("Step value of the slider")
public Float getPropertyStep() {
return this.propertyStep;
}
@AknotManaged
@AknotAttribute
@AknotName("value")
@AknotDescription("Value of the slider")
public Float getPropertyValue() {
return this.propertyValue;
}
protected void onChangePropertyShaper() {
if (this.shape == null) {
this.shape = new GuiShape(this.propertyConfig);
} else {
this.shape.setSource(this.propertyConfig);
}
}
@Override
public void onDraw() {
if (this.shape != null) {
// draw background
this.shape.draw(true, 0);
// draw slider
this.shape.draw(true, 1);
}
}
@Override
public boolean onEventInput(final EventInput event) {
final Vector3f positionAbsolute = new Vector3f(event.pos().x(), event.pos().y(), 0);
final Vector3f relPos = relativePosition(positionAbsolute);
Log.warning("Event on Input ... " + event + " relPos = " + relPos);
final boolean over = checkIfOver(relPos);
if (event.inputId() != 1) {
return false;
}
if (KeyStatus.pressSingle == event.status() && over) {
keepFocus();
// get percent value
final float pourcent = (relPos.x() - this.overPositionStart.x()) / (this.overPositionStop.x() - this.overPositionStart.x());
float value = (this.propertyMaximum - this.propertyMinimum) * pourcent + this.propertyMinimum;
if (this.propertyStep != 0.0f) {
value += this.propertyStep * 0.5f;
}
setPropertyValue(value);
return true;
}
if (KeyStatus.down == event.status() && over) {
keepFocus();
// get percent value
final float pourcent = (relPos.x() - this.overPositionStart.x()) / (this.overPositionStop.x() - this.overPositionStart.x());
float value = (this.propertyMaximum - this.propertyMinimum) * pourcent + this.propertyMinimum;
if (this.propertyStep != 0.0f) {
value += this.propertyStep * 0.5f;
}
setPropertyValue(value);
return true;
}
if (KeyStatus.move == event.status() && over) {
keepFocus();
// get percent value
final float pourcent = (relPos.x() - this.overPositionStart.x()) / (this.overPositionStop.x() - this.overPositionStart.x());
float value = (this.propertyMaximum - this.propertyMinimum) * pourcent + this.propertyMinimum;
if (this.propertyStep != 0.0f) {
value += this.propertyStep * 0.5f;
}
setPropertyValue(value);
return true;
}
if (KeyStatus.up == event.status() && over) {
keepFocus();
// get percent value
final float pourcent = (relPos.x() - this.overPositionStart.x()) / (this.overPositionStop.x() - this.overPositionStart.x());
float value = (this.propertyMaximum - this.propertyMinimum) * pourcent + this.propertyMinimum;
if (this.propertyStep != 0.0f) {
value += this.propertyStep * 0.5f;
}
setPropertyValue(value);
return true;
}
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));
}
*/
final Padding padding = this.shape.getPadding();
{
// Manage external shape:
Vector3f tmpSizeShaper = this.minSize;
Vector3f delta = this.propertyGravity.gravityGenerateDelta(this.size.less(this.minSize));
if (this.propertyFill.x()) {
tmpSizeShaper = tmpSizeShaper.withX(this.size.x());
delta = delta.withX(0.0f);
}
if (this.propertyFill.y()) {
tmpSizeShaper = tmpSizeShaper.withY(this.size.y());
delta = delta.withY(0.0f);
}
Vector3f tmpOriginShaper = delta;
Vector3f tmpSizeInside = tmpSizeShaper.less(padding.x(), padding.y(), padding.z());
//Vector3f tmpOriginText = this.size.less(tmpSizeText).multiply(0.5f);
Vector3f tmpOriginInside = Vector3f.ZERO;
// sometimes, the user define an height bigger than the real size needed == > in this case we need to center the text in the shaper ...
// fix all the position in the int class:
tmpSizeShaper = Vector3f.clipInt(tmpSizeShaper);
tmpOriginShaper = Vector3f.clipInt(tmpOriginShaper);
tmpSizeInside = Vector3f.clipInt(tmpSizeInside);
tmpOriginInside = Vector3f.clipInt(tmpOriginInside);
this.overPositionStart = tmpOriginShaper;
this.overPositionStop = tmpOriginShaper.add(tmpSizeShaper);
this.shape.setShape(0, tmpOriginShaper, tmpSizeShaper, tmpOriginInside, tmpSizeInside);
}
{
// Manage cursor:
Vector3f tmpSizeShaper = this.minSize;
Vector3f delta = this.propertyGravity.gravityGenerateDelta(this.size.less(this.minSize));
if (this.propertyFill.y()) {
tmpSizeShaper = tmpSizeShaper.withY(this.size.y());
delta = delta.withY(0.0f);
}
Vector3f tmpOriginShaper = delta;
Vector3f tmpSizeInside = tmpSizeShaper.less(padding.x(), padding.y(), padding.z());
//Vector3f tmpOriginText = this.size.less(tmpSizeText).multiply(0.5f);
Vector3f tmpOriginInside = Vector3f.ZERO;
final float xxx = tmpOriginShaper.x() * 2.0f;
tmpOriginShaper = tmpOriginShaper.withX(xxx * (this.propertyValue - this.propertyMinimum) / (this.propertyMaximum - this.propertyMinimum));
// sometimes, the user define an height bigger than the real size needed == > in this case we need to center the text in the shaper ...
// fix all the position in the int class:
tmpSizeShaper = Vector3f.clipInt(tmpSizeShaper);
tmpOriginShaper = Vector3f.clipInt(tmpOriginShaper);
tmpSizeInside = Vector3f.clipInt(tmpSizeInside);
tmpOriginInside = Vector3f.clipInt(tmpOriginInside);
this.overCursorPositionStart = tmpOriginShaper;
this.overCursorPositionStop = tmpOriginShaper.add(tmpSizeShaper);
this.shape.setShape(1, tmpOriginShaper, tmpSizeShaper, tmpOriginInside, tmpSizeInside);
}
//this.gc.flush();
this.shape.flush();
}
public void setPropertyConfig(final Uri propertyConfig) {
if (this.propertyConfig.equals(propertyConfig)) {
return;
}
this.propertyConfig = propertyConfig;
onChangePropertyShaper();
}
public void setPropertyMaximum(final Float propertyMaximum) {
if (this.propertyMaximum == propertyMaximum) {
return;
}
this.propertyMaximum = propertyMaximum;
updateValue(this.propertyValue);
this.signalValue.emit(this.propertyValue);
}
public void setPropertyMinimum(final Float propertyMinimum) {
if (this.propertyMinimum == propertyMinimum) {
return;
}
this.propertyMinimum = propertyMinimum;
updateValue(this.propertyValue);
this.signalValue.emit(this.propertyValue);
}
public void setPropertyStep(final Float propertyStep) {
if (this.propertyStep == propertyStep) {
return;
}
this.propertyStep = propertyStep;
updateValue(this.propertyValue);
this.signalValue.emit(this.propertyValue);
}
public void setPropertyValue(final Float propertyValue) {
if (this.propertyValue == propertyValue) {
return;
}
this.propertyValue = propertyValue;
updateValue(this.propertyValue);
this.signalValue.emit(this.propertyValue);
}
protected void updateValue(float newValue) {
newValue = FMath.max(FMath.min(newValue, this.propertyMaximum), this.propertyMinimum);
if (this.propertyStep == 0.0f) {
this.propertyValue = newValue;
} else {
final float basicVal = (long) (newValue / this.propertyStep);
this.propertyValue = basicVal * this.propertyStep;
}
markToRedraw();
}
}

View File

@ -95,7 +95,6 @@ public class Tick extends Widget {
markToRedraw();
// can not support multiple click...
setMouseLimit(1);
this.shape = new GuiShape(this.propertyConfig);
}
@Override

View File

@ -21,6 +21,7 @@ public class WidgetXmlFactory implements InterfaceFactoryAccess {
listWidgetAvaillable.put("PopUp", PopUp.class);
listWidgetAvaillable.put("FileChooser", FileChooser.class);
listWidgetAvaillable.put("Spin", Spin.class);
listWidgetAvaillable.put("Slider", Slider.class);
}
@Override

View File

@ -1,7 +1,7 @@
package test.atriasoft.ewol;
import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
import org.atriasoft.reggol.LogLevel;
import org.atriasoft.reggol.Logger;
public class Log {
private static final String LIB_NAME = "etk-test";

View File

@ -1,7 +1,7 @@
package test.atriasoft.ewol;
import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger;
import org.atriasoft.reggol.LogLevel;
import org.atriasoft.reggol.Logger;
public class Log2 {
private static final String LIB_NAME = "etk-test-2";

View File

@ -11,7 +11,7 @@ package test.atriasoft.ewol;
import java.util.ArrayList;
import java.util.List;
import io.scenarium.logger.Logger;
import org.atriasoft.reggol.Logger;
import org.junit.Test;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;