From 760fd95b606a5b86f9a807b22474e5d8e5dd25f8 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 3 Oct 2022 23:44:48 +0200 Subject: [PATCH] [DEV] remove dependency with scenarium --- blender_files/exportEmf.py | 3 +- old_widget/Slider.cpp | 134 ------ .../resources/ewol/theme/shape/Button.emf | 2 +- .../resources/ewol/theme/shape/Entry.emf | 2 +- .../resources/ewol/theme/shape/ScrollBar.emf | 4 +- resources/resources/ewol/theme/shape/Tick.emf | 2 +- .../ewol/theme/shape/palette_gui.json | 5 +- samples/src/sample/atriasoft/ewol/Log.java | 4 +- .../atriasoft/ewol/validationWidget/Log.java | 4 +- .../ewol/validationWidget/MainWindows.java | 6 +- src/module-info.java | 2 +- .../atriasoft/ewol/compositing/GuiShape.java | 127 ++++-- src/org/atriasoft/ewol/internal/Log.java | 4 +- src/org/atriasoft/ewol/widget/Composer.java | 4 +- .../atriasoft/ewol/widget/ImageDisplay.java | 4 +- src/org/atriasoft/ewol/widget/Slider.java | 386 +++++++++++++++--- src/org/atriasoft/ewol/widget/Tick.java | 1 - .../ewol/widget/WidgetXmlFactory.java | 1 + test/src/test/atriasoft/ewol/Log.java | 4 +- test/src/test/atriasoft/ewol/Log2.java | 4 +- .../src/test/atriasoft/ewol/TestBasicLog.java | 2 +- 21 files changed, 456 insertions(+), 249 deletions(-) delete mode 100644 old_widget/Slider.cpp diff --git a/blender_files/exportEmf.py b/blender_files/exportEmf.py index 616c751..7e35529 100644 --- a/blender_files/exportEmf.py +++ b/blender_files/exportEmf.py @@ -9,7 +9,8 @@ list_elem = [ "Entry", "Tick", "ScrollBar", - "Button" + "Button", + "Slider" ] for elem in list_elem: diff --git a/old_widget/Slider.cpp b/old_widget/Slider.cpp deleted file mode 100644 index 936d946..0000000 --- a/old_widget/Slider.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include - -#include -#include -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; -} - - diff --git a/resources/resources/ewol/theme/shape/Button.emf b/resources/resources/ewol/theme/shape/Button.emf index fa505da..13a498f 100644 --- a/resources/resources/ewol/theme/shape/Button.emf +++ b/resources/resources/ewol/theme/shape/Button.emf @@ -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| diff --git a/resources/resources/ewol/theme/shape/Entry.emf b/resources/resources/ewol/theme/shape/Entry.emf index 95d3d02..c1523c9 100644 --- a/resources/resources/ewol/theme/shape/Entry.emf +++ b/resources/resources/ewol/theme/shape/Entry.emf @@ -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| diff --git a/resources/resources/ewol/theme/shape/ScrollBar.emf b/resources/resources/ewol/theme/shape/ScrollBar.emf index 3a1df32..557f34b 100644 --- a/resources/resources/ewol/theme/shape/ScrollBar.emf +++ b/resources/resources/ewol/theme/shape/ScrollBar.emf @@ -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: diff --git a/resources/resources/ewol/theme/shape/Tick.emf b/resources/resources/ewol/theme/shape/Tick.emf index 3398b98..28a4c4f 100644 --- a/resources/resources/ewol/theme/shape/Tick.emf +++ b/resources/resources/ewol/theme/shape/Tick.emf @@ -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| diff --git a/resources/resources/ewol/theme/shape/palette_gui.json b/resources/resources/ewol/theme/shape/palette_gui.json index 739e89f..db4b7f3 100644 --- a/resources/resources/ewol/theme/shape/palette_gui.json +++ b/resources/resources/ewol/theme/shape/palette_gui.json @@ -31,8 +31,11 @@ "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" } } -} \ No newline at end of file +} diff --git a/samples/src/sample/atriasoft/ewol/Log.java b/samples/src/sample/atriasoft/ewol/Log.java index 19154ea..25dd7dd 100644 --- a/samples/src/sample/atriasoft/ewol/Log.java +++ b/samples/src/sample/atriasoft/ewol/Log.java @@ -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; diff --git a/samples/src/sample/atriasoft/ewol/validationWidget/Log.java b/samples/src/sample/atriasoft/ewol/validationWidget/Log.java index eec27f1..9877e0a 100644 --- a/samples/src/sample/atriasoft/ewol/validationWidget/Log.java +++ b/samples/src/sample/atriasoft/ewol/validationWidget/Log.java @@ -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"; diff --git a/samples/src/sample/atriasoft/ewol/validationWidget/MainWindows.java b/samples/src/sample/atriasoft/ewol/validationWidget/MainWindows.java index 6a01d3f..db33935 100644 --- a/samples/src/sample/atriasoft/ewol/validationWidget/MainWindows.java +++ b/samples/src/sample/atriasoft/ewol/validationWidget/MainWindows.java @@ -16,7 +16,11 @@ public class MainWindows extends BasicWindows { public MainWindows() { setPropertyTitle("Test all compositing"); - + + this.titles.add("test Slider"); + this.values.add(""" + + """); this.titles.add("test Entry"); this.values.add(""" diff --git a/src/module-info.java b/src/module-info.java index b940efd..09d3cac 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -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; diff --git a/src/org/atriasoft/ewol/compositing/GuiShape.java b/src/org/atriasoft/ewol/compositing/GuiShape.java index 64ac014..b8b3afc 100644 --- a/src/org/atriasoft/ewol/compositing/GuiShape.java +++ b/src/org/atriasoft/ewol/compositing/GuiShape.java @@ -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 layers = this.mesh[idMesh].getLayers(); + final Set 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 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 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 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 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 verticesToModify = this.mesh.getGeneratedPosition(); + float[] newVertices = new float[verticesToModify.size()*3]; + for (int iii=0; iii -#include -#include -#include -#include -#include - -namespace ewol { - namespace widget { - class Slider; - using Slider = ememory::Ptr; - using SliderWeak = ememory::WeakPtr; - /** - * @ingroup ewolWidgetGroup - */ - class Slider : public Widget { - public: // signals - esignal::Signal signalChange; - public: - //eproperty::Value propertyShape; //!< name of the shape used - eproperty::Value propertyValue; //!< current value of the Slider - eproperty::Value propertyMinimum; //!< minimum value of the slider - eproperty::Value propertyMaximum; //!< maximum value of the slider - eproperty::Value 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(); - }; +/** + * @ingroup ewolWidgetGroup + */ +public class Slider extends Widget { + + 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 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(); + } +} \ No newline at end of file diff --git a/src/org/atriasoft/ewol/widget/Tick.java b/src/org/atriasoft/ewol/widget/Tick.java index 03b0010..0d19daa 100644 --- a/src/org/atriasoft/ewol/widget/Tick.java +++ b/src/org/atriasoft/ewol/widget/Tick.java @@ -95,7 +95,6 @@ public class Tick extends Widget { markToRedraw(); // can not support multiple click... setMouseLimit(1); - this.shape = new GuiShape(this.propertyConfig); } @Override diff --git a/src/org/atriasoft/ewol/widget/WidgetXmlFactory.java b/src/org/atriasoft/ewol/widget/WidgetXmlFactory.java index 5b69682..7239149 100644 --- a/src/org/atriasoft/ewol/widget/WidgetXmlFactory.java +++ b/src/org/atriasoft/ewol/widget/WidgetXmlFactory.java @@ -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 diff --git a/test/src/test/atriasoft/ewol/Log.java b/test/src/test/atriasoft/ewol/Log.java index eb452e1..8ddd4f6 100644 --- a/test/src/test/atriasoft/ewol/Log.java +++ b/test/src/test/atriasoft/ewol/Log.java @@ -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"; diff --git a/test/src/test/atriasoft/ewol/Log2.java b/test/src/test/atriasoft/ewol/Log2.java index 4f762c8..a8eeca9 100644 --- a/test/src/test/atriasoft/ewol/Log2.java +++ b/test/src/test/atriasoft/ewol/Log2.java @@ -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"; diff --git a/test/src/test/atriasoft/ewol/TestBasicLog.java b/test/src/test/atriasoft/ewol/TestBasicLog.java index 7ddceef..a442c6f 100644 --- a/test/src/test/atriasoft/ewol/TestBasicLog.java +++ b/test/src/test/atriasoft/ewol/TestBasicLog.java @@ -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;