[FEAT] basic rework of generic Graphic context in full openGl

This commit is contained in:
Edouard DUPIN 2025-07-14 16:31:46 +02:00
parent 0fe0fa6629
commit ec4b1a1875
21 changed files with 1252 additions and 857 deletions

View File

@ -44,17 +44,17 @@
<artifactId>ewol</artifactId>
<version>0.1.0</version>
</dependency>
<!-- Loopback of logger JDK logging API to SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>2.0.9</version>
</dependency>
<!-- generic logger of SLF4J to console (in color) -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.18</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.18</version>
<scope>test</scope>
<version>1.4.11</version>
</dependency>
<dependency>
<groupId>xerces</groupId>

View File

@ -18,20 +18,20 @@ import org.slf4j.LoggerFactory;
public class BasicWindows extends Windows {
private static final Logger LOGGER = LoggerFactory.getLogger(BasicWindows.class);
private int index = -1;
private final List<TestWidgetInterface> testedElement = new ArrayList<>();
private Container container = null;
private Label title = null;
public static void staticRequestNext(final BasicWindows self) {
self.requestNext();
}
public static void staticRequestPrevious(final BasicWindows self) {
self.requestPrevious();
}
public void requestNext() {
LOGGER.info("Request Next");
this.index++;
@ -40,7 +40,7 @@ public class BasicWindows extends Windows {
}
updateDisplay();
}
public void requestPrevious() {
LOGGER.info("Request Previous");
this.index--;
@ -49,7 +49,7 @@ public class BasicWindows extends Windows {
}
updateDisplay();
}
public void updateDisplay() {
final var test = this.testedElement.get(this.index);
final var titlegenerated = "<b>[" + (this.index + 1) + "/" + this.testedElement.size() + "] " + test.getTitle()
@ -58,14 +58,14 @@ public class BasicWindows extends Windows {
setPropertyTitle(titlegenerated);
this.container.setSubWidget(new ModelWidget(test));
}
public BasicWindows() {
final var sizerMain = new Sizer(DisplayMode.VERTICAL);
sizerMain.setPropertyExpand(Vector2b.TRUE);
sizerMain.setPropertyFill(Vector2b.TRUE);
setSubWidget(sizerMain);
final var menu = new Sizer(DisplayMode.HORIZONTAL);
menu.setPropertyExpand(Vector2b.TRUE_FALSE);
menu.setPropertyExpandIfFree(Vector2b.TRUE_FALSE);
@ -73,40 +73,40 @@ public class BasicWindows extends Windows {
menu.setPropertyLockExpand(Vector2b.TRUE);
menu.setPropertyMaxSize(new Dimension2f(new Vector2f(9999, 3), Distance.CENTIMETER));
sizerMain.subWidgetAdd(menu);
this.container = new Container();
this.container.setPropertyExpand(Vector2b.TRUE);
this.container.setPropertyFill(Vector2b.TRUE);
sizerMain.subWidgetAdd(this.container);
final var next = Button.createLabelButton("&lt;&lt; Previous");
next.setPropertyMaxSize(new Dimension2f(new Vector2f(9999, 2), Distance.CENTIMETER));
menu.subWidgetAdd(next);
next.signalClick.connectAuto(this, BasicWindows::staticRequestNext);
this.title = new Label("unknown");
this.title.setPropertyFill(Vector2b.FALSE);
this.title.setPropertyExpand(Vector2b.TRUE);
menu.subWidgetAdd(this.title);
final var previous = Button.createLabelButton("Next &gt;&gt;");
previous.setPropertyMaxSize(new Dimension2f(new Vector2f(9999, 2), Distance.CENTIMETER));
menu.subWidgetAdd(previous);
previous.signalClick.connectAuto(this, BasicWindows::staticRequestPrevious);
this.container.setPropertyExpand(Vector2b.TRUE);
this.container.setPropertyFill(Vector2b.TRUE);
this.container.setPropertyExpandIfFree(Vector2b.TRUE);
this.testedElement.add(new TestWidgetBox());
this.testedElement.add(new TestWidgetSlider());
this.testedElement.add(new TestWidgetEntry());
this.testedElement.add(new TestWidgetBox());
this.testedElement.add(new TestWidgetButton());
this.testedElement.add(new TestWidgetButtonToggle());
this.testedElement.add(new TestWidgetCheckBox());
this.testedElement.add(new TestWidgetImage());
this.testedElement.add(new TestWidgetLabel());
requestNext();
}
}

View File

@ -1,15 +1,20 @@
package sample.atriasoft.ewol;
import java.util.logging.LogManager;
import org.atriasoft.etk.Uri;
import org.atriasoft.ewol.Ewol;
import org.slf4j.bridge.SLF4JBridgeHandler;
public class MainApplicaitionStarter {
public static void main(final String[] args) {
// Loop-back of logger JDK logging API to SLF4J
LogManager.getLogManager().reset();
SLF4JBridgeHandler.install();
Ewol.init();
Uri.setApplication(MainApplicaitionStarter.class, "test-ewol/");
Ewol.run(new Appl(), args);
}
private MainApplicaitionStarter() {
}
private MainApplicaitionStarter() {}
}

View File

@ -0,0 +1,15 @@
package org.atriasoft.ewol.compositing;
/** @file
* @author Edouard DUPIN
* @copyright 2025, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
public abstract class CompositingDraw extends Compositing implements CompositingDrawInterface {
public static final CompositingDraw createGC() {
return new CompositingGC();
}
}

View File

@ -0,0 +1,32 @@
/** @file
* @author Edouard DUPIN
* @copyright 2025, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.ewol.compositing;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector2f;
public interface CompositingDrawInterface {
void clear();
void flush();
void setPaintFillColor(final Color color);
void setPaintStrokeColor(final Color color);
void setPaintStrokeWidth(final float width);
void addLine(final Vector2f startPos, final Vector2f stopPos);
void addRectangle(final Vector2f position, final Vector2f size);
void addRectangle(final Vector2f position, final Vector2f size, final Vector2f roundedCorner);
void addCircle(final Vector2f position, final float radius);
void addEllipse(final Vector2f center, final Vector2f radius);
}

View File

@ -20,9 +20,9 @@ import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CompositingDrawing extends Compositing {
public abstract class CompositingDrawing extends CompositingDraw {
private static final Logger LOGGER = LoggerFactory.getLogger(CompositingDrawing.class);
protected static int vboIdColor = 1;
protected static int vboIdCoord = 0;
private boolean clippingEnable = false; // !< true if the clipping must be activated
@ -38,19 +38,19 @@ public class CompositingDrawing extends Compositing {
private ResourceProgram oGLprogram; // !< pointer on the opengl display program
private final List<Color> outColors = new ArrayList<>();
private final List<Vector3f> outTriangles = new ArrayList<>();
private Vector3f position = new Vector3f(0, 0, 0); // !< The current position to draw
private float thickness = 0; // !< when drawing line and other things
private final Vector3f[] triangle = new Vector3f[3]; // !< Register every system with a combinaison of tiangle
private final Color[] tricolor = new Color[3]; // !< Register every the associated color foreground
private int triElement = 0; // !< special counter of the single dot generated
//protected ResourceVirtualBufferObject vbo;
protected ResourceVirtualArrayObject vbo;
// internal API for the generation abstraction of triangles
/**
* Basic ructor
@ -66,7 +66,7 @@ public class CompositingDrawing extends Compositing {
// TO facilitate some debugs we add a name of the VBO:
this.vbo.setName("[VBO] of ewol::compositing::Area");
}
/**
* add a point reference at the current position (this is a vertex
* reference at the current position
@ -75,7 +75,7 @@ public class CompositingDrawing extends Compositing {
internalSetColor(this.color);
setPoint(this.position);
}
/**
* draw a 2D circle with the specify rafdius parameter.
* @param radius Distence to the dorder
@ -85,75 +85,90 @@ public class CompositingDrawing extends Compositing {
public void circle(final float radius) {
circle(radius, 0);
}
public void circle(final float radius, final float angleStart) {
circle(radius, angleStart, 2.0f * FMath.PI);
}
public void circle(float radius, final float angleStart, float angleStop) {
public void circleBorderRaw(
final Vector3f centerPos,
final float radius,
final float thickness,
final float angleStart,
final float angleStop) {
resetCount();
if (radius < 0) {
radius *= -1;
}
angleStop = angleStop - angleStart;
int nbOcurence = (int) radius;
if (nbOcurence < 10) {
nbOcurence = 10;
}
for (int iii = 0; iii < nbOcurence; iii++) {
final float angleOne = angleStart + (angleStop * iii / nbOcurence);
final float offsetExty = FMath.sin(angleOne) * (radius + thickness / 2);
final float offsetExtx = FMath.cos(angleOne) * (radius + thickness / 2);
final float offsetInty = FMath.sin(angleOne) * (radius - thickness / 2);
final float offsetIntx = FMath.cos(angleOne) * (radius - thickness / 2);
final float angleTwo = angleStart + (angleStop * (iii + 1) / nbOcurence);
final float offsetExt2y = FMath.sin(angleTwo) * (radius + thickness / 2);
final float offsetExt2x = FMath.cos(angleTwo) * (radius + thickness / 2);
final float offsetInt2y = FMath.sin(angleTwo) * (radius - thickness / 2);
final float offsetInt2x = FMath.cos(angleTwo) * (radius - thickness / 2);
setPoint(new Vector3f(centerPos.x() + offsetIntx, centerPos.y() + offsetInty, 0));
setPoint(new Vector3f(centerPos.x() + offsetExtx, centerPos.y() + offsetExty, 0));
setPoint(new Vector3f(centerPos.x() + offsetExt2x, centerPos.y() + offsetExt2y, 0));
setPoint(new Vector3f(centerPos.x() + offsetExt2x, centerPos.y() + offsetExt2y, 0));
setPoint(new Vector3f(centerPos.x() + offsetInt2x, centerPos.y() + offsetInt2y, 0));
setPoint(new Vector3f(centerPos.x() + offsetIntx, centerPos.y() + offsetInty, 0));
}
}
public void circleRaw(final Vector3f centerPos, final float radius, final float angleStart, final float angleStop) {
resetCount();
int nbOcurence = (int) radius;
if (nbOcurence < 10) {
nbOcurence = 10;
}
for (int iii = 0; iii < nbOcurence; iii++) {
setPoint(new Vector3f(centerPos.x(), centerPos.y(), 0));
final float angleOne = angleStart + (angleStop * iii / nbOcurence);
float offsety = FMath.sin(angleOne) * radius;
float offsetx = FMath.cos(angleOne) * radius;
setPoint(new Vector3f(centerPos.x() + offsetx, centerPos.y() + offsety, 0));
final float angleTwo = angleStart + (angleStop * (iii + 1) / nbOcurence);
offsety = FMath.sin(angleTwo) * radius;
offsetx = FMath.cos(angleTwo) * radius;
setPoint(new Vector3f(centerPos.x() + offsetx, centerPos.y() + offsety, 0));
}
}
public void circle(float radius, final float angleStart, float angleStop) {
resetCount();
if (radius < 0) {
radius *= -1;
}
angleStop = angleStop - angleStart;
// display background :
if (this.colorBg.a() != 0) {
internalSetColor(this.colorBg);
for (int iii = 0; iii < nbOcurence; iii++) {
setPoint(new Vector3f(this.position.x(), this.position.y(), 0));
final float angleOne = angleStart + (angleStop * iii / nbOcurence);
float offsety = FMath.sin(angleOne) * radius;
float offsetx = FMath.cos(angleOne) * radius;
setPoint(new Vector3f(this.position.x() + offsetx, this.position.y() + offsety, 0));
final float angleTwo = angleStart + (angleStop * (iii + 1) / nbOcurence);
offsety = FMath.sin(angleTwo) * radius;
offsetx = FMath.cos(angleTwo) * radius;
setPoint(new Vector3f(this.position.x() + offsetx, this.position.y() + offsety, 0));
}
circleRaw(this.position, radius, angleStart, angleStop);
}
// show if we have a border :
if (this.thickness == 0 || this.color.a() == 0) {
return;
}
internalSetColor(this.color);
for (int iii = 0; iii < nbOcurence; iii++) {
final float angleOne = angleStart + (angleStop * iii / nbOcurence);
final float offsetExty = FMath.sin(angleOne) * (radius + this.thickness / 2);
final float offsetExtx = FMath.cos(angleOne) * (radius + this.thickness / 2);
final float offsetInty = FMath.sin(angleOne) * (radius - this.thickness / 2);
final float offsetIntx = FMath.cos(angleOne) * (radius - this.thickness / 2);
final float angleTwo = angleStart + (angleStop * (iii + 1) / nbOcurence);
final float offsetExt2y = FMath.sin(angleTwo) * (radius + this.thickness / 2);
final float offsetExt2x = FMath.cos(angleTwo) * (radius + this.thickness / 2);
final float offsetInt2y = FMath.sin(angleTwo) * (radius - this.thickness / 2);
final float offsetInt2x = FMath.cos(angleTwo) * (radius - this.thickness / 2);
setPoint(new Vector3f(this.position.x() + offsetIntx, this.position.y() + offsetInty, 0));
setPoint(new Vector3f(this.position.x() + offsetExtx, this.position.y() + offsetExty, 0));
setPoint(new Vector3f(this.position.x() + offsetExt2x, this.position.y() + offsetExt2y, 0));
setPoint(new Vector3f(this.position.x() + offsetExt2x, this.position.y() + offsetExt2y, 0));
setPoint(new Vector3f(this.position.x() + offsetInt2x, this.position.y() + offsetInt2y, 0));
setPoint(new Vector3f(this.position.x() + offsetIntx, this.position.y() + offsetInty, 0));
}
circleBorderRaw(this.position, radius, this.thickness, angleStart, angleStop);
}
/**
* clear alll tre registered element in the current element
* clear all the registered element in the current element
*/
@Override
public void clear() {
@ -163,23 +178,23 @@ public class CompositingDrawing extends Compositing {
this.vbo.clear();
this.outTriangles.clear();
this.outColors.clear();
// reset temporal variables :
this.position = Vector3f.ZERO;
this.clippingPosStart = Vector3f.ZERO;
this.clippingPosStop = Vector3f.ZERO;
this.clippingEnable = false;
this.color = Color.BLACK;
this.colorBg = Color.NONE;
for (int iii = 0; iii < 3; iii++) {
this.triangle[iii] = this.position;
this.tricolor[iii] = this.color;
}
}
/**
* draw All the refistered text in the current element on openGL
*/
@ -202,7 +217,7 @@ public class CompositingDrawing extends Compositing {
this.vbo.unBindForRendering();
this.oGLprogram.unUse();
}
@Override
public void flush() {
// push data on the VBO
@ -210,7 +225,7 @@ public class CompositingDrawing extends Compositing {
this.vbo.setColors(this.outColors.toArray(Color[]::new));
this.vbo.setVertexCount(this.outTriangles.size());
}
/**
* Lunch the generation of triangle
*/
@ -223,7 +238,7 @@ public class CompositingDrawing extends Compositing {
this.outColors.add(this.tricolor[1]);
this.outColors.add(this.tricolor[2]);
}
/**
* Get the foreground color of the font.
* @return Foreground color.
@ -231,7 +246,7 @@ public class CompositingDrawing extends Compositing {
public Color getColor() {
return this.color;
}
/**
* Get the background color of the font.
* @return Background color.
@ -239,7 +254,7 @@ public class CompositingDrawing extends Compositing {
public Color getColorBg() {
return this.colorBg;
}
/**
* get the current display position (sometime needed in the gui control)
* @return the current position.
@ -247,7 +262,7 @@ public class CompositingDrawing extends Compositing {
public Vector3f getPos() {
return this.position;
}
/**
* set the Color of the current triangle drawing
* @param color Color to current dots generated
@ -263,7 +278,7 @@ public class CompositingDrawing extends Compositing {
this.tricolor[2] = color;
}
}
/**
* Relative drawing a line (special vector)
* @param vect Vector of the current line.
@ -271,31 +286,31 @@ public class CompositingDrawing extends Compositing {
public void lineRel(final float xxx, final float yyy) {
lineTo(this.position.add(new Vector3f(xxx, yyy, 0)));
}
public void lineRel(final float xxx, final float yyy, final float zzz) {
lineTo(this.position.add(new Vector3f(xxx, yyy, zzz)));
}
public void lineRel(final Vector2f vect) {
lineRel(new Vector3f(vect.x(), vect.y(), 0));
}
public void lineRel(final Vector3f vect) {
lineTo(this.position.add(vect));
}
public void lineTo(final float xxx, final float yyy) {
lineTo(new Vector3f(xxx, yyy, 0));
}
public void lineTo(final float xxx, final float yyy, final float zzz) {
lineTo(new Vector3f(xxx, yyy, zzz));
}
public void lineTo(final Vector2f dest) {
lineTo(new Vector3f(dest.x(), dest.y(), 0));
}
/**
* draw a line to a specific position
* @param dest Position of the end of the line.
@ -326,14 +341,14 @@ public class CompositingDrawing extends Compositing {
setPoint(new Vector3f(this.position.x() - offsetx, this.position.y() - offsety, this.position.z()));
setPoint(new Vector3f(this.position.x() + offsetx, this.position.y() + offsety, this.position.z()));
setPoint(new Vector3f(dest.x() + offsetx, dest.y() + offsety, this.position.z()));
setPoint(new Vector3f(dest.x() + offsetx, dest.y() + offsety, dest.z()));
setPoint(new Vector3f(dest.x() - offsetx, dest.y() - offsety, dest.z()));
setPoint(new Vector3f(this.position.x() - offsetx, this.position.y() - offsety, dest.z()));
// update the system position :
this.position = dest;
}
/**
* load the openGL program and get all the ID needed
*/
@ -352,39 +367,47 @@ public class CompositingDrawing extends Compositing {
this.oGLMatrixView = this.oGLprogram.getUniform("in_matrixView");
}
}
public void rectangle(final float xxx, final float yyy) {
rectangle(new Vector3f(xxx, yyy, 0));
}
public void rectangle(final float xxx, final float yyy, final float zzz) {
rectangle(new Vector3f(xxx, yyy, zzz));
}
public void rectangle(final Vector2f dest) {
rectangle(new Vector3f(dest.x(), dest.y(), 0));
rectangle(dest.toVector3f());
}
/**
* draw a 2D rectangle to the position requested.
* @param dest Position the the end of the rectangle
*/
public void rectangle(final Vector3f dest) {
resetCount();
internalSetColor(this.color);
rectangleRaw(this.position, dest);
}
public void rectangleRaw(final Vector3f startPos, final Vector3f endPos) {
resetCount();
/*
* Bitmap position xA xB yC *------* | | | | yD *------*
* Bitmap position xA xB
* yC *------*
* | |
* | |
* yD *------*
*/
float dxA = this.position.x();
float dxB = dest.x();
float dxA = startPos.x();
float dxB = endPos.x();
if (dxA > dxB) {
// inverse order :
final float tmp = dxA;
dxA = dxB;
dxB = tmp;
}
float dyC = this.position.y();
float dyD = dest.y();
float dyC = startPos.y();
float dyD = endPos.y();
if (dyC > dyD) {
// inverse order :
final float tmp = dyC;
@ -411,24 +434,219 @@ public class CompositingDrawing extends Compositing {
setPoint(new Vector3f(dxA, dyD, 0));
setPoint(new Vector3f(dxA, dyC, 0));
setPoint(new Vector3f(dxB, dyC, 0));
setPoint(new Vector3f(dxB, dyC, 0));
setPoint(new Vector3f(dxB, dyD, 0));
setPoint(new Vector3f(dxA, dyD, 0));
}
public void rectangleBorder(final Vector2f dest, final float borderWidth) {
rectangleBorder(dest.toVector3f(), borderWidth);
}
public void rectangleBorder(final Vector3f dest, final float borderWidth) {
/*
* Bitmap position xA xB
* yC *--------------* buttom
* | |
* | xpA xpB |
* ypC | *------* |
* | | | |
* | | | |
* Left | | | |
* | | | |
* ypD | *------* |
* | |
* | |
* yD *--------------* Top
*/
resetCount();
internalSetColor(this.colorBg);
float dxA = this.position.x();
float dxB = dest.x();
if (dxA > dxB) {
// inverse order :
final float tmp = dxA;
dxA = dxB;
dxB = tmp;
}
float dyC = this.position.y();
float dyD = dest.y();
if (dyC > dyD) {
// inverse order :
final float tmp = dyC;
dyC = dyD;
dyD = tmp;
}
float dxpA = dxA + borderWidth * 0.5f;
float dxpB = dxB - borderWidth * 0.5f;
float dypC = dyC + borderWidth * 0.5f;
float dypD = dyD - borderWidth * 0.5f;
dxA = dxA - borderWidth * 0.5f;
dxB = dxB + borderWidth * 0.5f;
dyC = dyC - borderWidth * 0.5f;
dyD = dyD + borderWidth * 0.5f;
if (this.clippingEnable) {
if (dxA < this.clippingPosStart.x()) {
dxA = this.clippingPosStart.x();
}
if (dxB > this.clippingPosStop.x()) {
dxB = this.clippingPosStop.x();
}
if (dyC < this.clippingPosStart.y()) {
dyC = this.clippingPosStart.y();
}
if (dyD > this.clippingPosStop.y()) {
dyD = this.clippingPosStop.y();
}
if (dxpA < this.clippingPosStart.x()) {
dxpA = this.clippingPosStart.x();
}
if (dxpB > this.clippingPosStop.x()) {
dxpB = this.clippingPosStop.x();
}
if (dypC < this.clippingPosStart.y()) {
dypC = this.clippingPosStart.y();
}
if (dypD > this.clippingPosStop.y()) {
dypD = this.clippingPosStop.y();
}
}
if (dyC >= dyD || dxA >= dxB) {
return;
}
// Buttom border:
setPoint(new Vector3f(dxA, dyC, 0));
setPoint(new Vector3f(dxB, dyC, 0));
setPoint(new Vector3f(dxpA, dypC, 0));
setPoint(new Vector3f(dxB, dyC, 0));
setPoint(new Vector3f(dxpA, dypC, 0));
setPoint(new Vector3f(dxpB, dypC, 0));
// Right border:
setPoint(new Vector3f(dxpB, dypC, 0));
setPoint(new Vector3f(dxB, dyC, 0));
setPoint(new Vector3f(dxB, dyD, 0));
setPoint(new Vector3f(dxpB, dypC, 0));
setPoint(new Vector3f(dxB, dyD, 0));
setPoint(new Vector3f(dxpB, dypD, 0));
// Top border:
setPoint(new Vector3f(dxpB, dypD, 0));
setPoint(new Vector3f(dxB, dyD, 0));
setPoint(new Vector3f(dxA, dyD, 0));
setPoint(new Vector3f(dxpB, dypD, 0));
setPoint(new Vector3f(dxA, dyD, 0));
setPoint(new Vector3f(dxpA, dypD, 0));
// Left border:
setPoint(new Vector3f(dxpA, dypD, 0));
setPoint(new Vector3f(dxA, dyD, 0));
setPoint(new Vector3f(dxpA, dypC, 0));
setPoint(new Vector3f(dxA, dyD, 0));
setPoint(new Vector3f(dxpA, dypC, 0));
setPoint(new Vector3f(dxA, dyC, 0));
}
/**
* draw a 2D rectangle to the position requested.
* @param dest Position the the end of the rectangle
*/
public void rectangleRadius(final Vector2f dest, final float radius) {
rectangleRadius(dest.toVector3f(), radius);
}
public void rectangleRadius(final Vector3f dest, final float radius) {
internalSetColor(this.color);
final boolean showConstruct = false;
rectangleRaw(this.position.add(new Vector3f(radius, 0, 0)), dest.less(new Vector3f(radius, 0, 0)));
if (showConstruct) {
internalSetColor(Color.ORANGE);
}
rectangleRaw(this.position.add(new Vector3f(0, radius, 0)),
new Vector3f(this.position.x() + radius, dest.y() - radius, 0));
if (showConstruct) {
internalSetColor(Color.GRAY);
}
rectangleRaw(new Vector3f(dest.x() - radius, this.position.y() + radius, 0),
new Vector3f(dest.x(), dest.y() - radius, 0));
if (showConstruct) {
internalSetColor(Color.AQUA_MARINE);
}
circleRaw(this.position.add(radius, radius, 0), radius, FMath.PI, FMath.PI * 0.5f);
circleRaw(dest.less(radius, radius, 0), radius, 0, FMath.PI * 0.5f);
circleRaw(new Vector3f(dest.x() - radius, this.position.y() + radius, 0), radius, FMath.PI * 1.5f,
FMath.PI * 0.5f);
circleRaw(new Vector3f(this.position.x() + radius, dest.y() - radius, 0), radius, FMath.PI * 0.5f,
FMath.PI * 0.5f);
if (showConstruct) {
internalSetColor(Color.BLACK);
rectangleRaw(this.position, this.position.add(10));
internalSetColor(Color.RED);
rectangleRaw(dest.less(10), dest);
}
}
public void rectangleBorderRadius(final Vector2f dest, final float thickness, final float radius) {
rectangleBorderRadius(dest.toVector3f(), thickness, radius);
}
public void rectangleBorderRadius(final Vector3f dest, final float thickness, final float radius) {
internalSetColor(this.color);
final boolean showConstruct = true;
if (showConstruct) {
internalSetColor(Color.ANTIQUE_WHITE);
}
// Bottom
rectangleRaw(new Vector3f(this.position.x() + radius, this.position.y() - thickness * 0.5f, 0),
new Vector3f(dest.x() - radius, this.position.y() + thickness * 0.5f, 0));
// top
rectangleRaw(new Vector3f(this.position.x() + radius, dest.y() - thickness * 0.5f, 0),
new Vector3f(dest.x() - radius, dest.y() + thickness * 0.5f, 0));
// left
rectangleRaw(new Vector3f(this.position.x() - thickness * 0.5f, this.position.y() + radius, 0),
new Vector3f(this.position.x() + thickness * 0.5f, dest.y() - radius, 0));
// right
rectangleRaw(new Vector3f(dest.x() - thickness * 0.5f, this.position.y() + radius, 0),
new Vector3f(dest.x() + thickness * 0.5f, dest.y() - radius, 0));
if (showConstruct) {
internalSetColor(Color.DARK_RED);
}
circleBorderRaw(this.position.add(radius, radius, 0), radius, thickness, FMath.PI, FMath.PI * 0.5f);
circleBorderRaw(dest.less(radius, radius, 0), radius, thickness, 0, FMath.PI * 0.5f);
circleBorderRaw(new Vector3f(dest.x() - radius, this.position.y() + radius, 0), radius, thickness,
FMath.PI * 1.5f, FMath.PI * 0.5f);
circleBorderRaw(new Vector3f(this.position.x() + radius, dest.y() - radius, 0), radius, thickness,
FMath.PI * 0.5f, FMath.PI * 0.5f);
if (showConstruct) {
internalSetColor(Color.BLACK);
rectangleRaw(this.position, this.position.add(10));
internalSetColor(Color.RED);
rectangleRaw(dest.less(10), dest);
}
}
public void rectangleWidth(final float xxx, final float yyy) {
rectangleWidth(new Vector3f(xxx, yyy, 0));
}
public void rectangleWidth(final float xxx, final float yyy, final float zzz) {
rectangleWidth(new Vector3f(xxx, yyy, zzz));
}
public void rectangleWidth(final Vector2f size) {
rectangleWidth(new Vector3f(size.x(), size.y(), 0));
}
/**
* draw a 2D rectangle to the requested size.
* @param size size of the rectangle
@ -436,18 +654,18 @@ public class CompositingDrawing extends Compositing {
public void rectangleWidth(final Vector3f size) {
rectangle(this.position.add(size));
}
/**
* in case of some error the count can be reset
*/
private void resetCount() {
this.triElement = 0;
}
public void setClipping(final Vector2f pos, final Vector2f posEnd) {
setClipping(new Vector3f(pos.x(), pos.y(), -1), new Vector3f(posEnd.x(), posEnd.y(), 1));
}
/**
* Request a clipping area for the text (next draw only)
* @param pos Start position of the clipping
@ -460,7 +678,7 @@ public class CompositingDrawing extends Compositing {
this.clippingPosStart = Vector3f.min(pos, posEnd);
this.clippingEnable = true;
}
/**
* enable/Disable the clipping (without lose the current clipping
* position)
@ -469,11 +687,11 @@ public class CompositingDrawing extends Compositing {
public void setClippingMode(final boolean newMode) {
this.clippingEnable = newMode;
}
public void setClippingWidth(final Vector2f pos, final Vector2f width) {
setClippingWidth(new Vector3f(pos.x(), pos.y(), -1), new Vector3f(width.x(), width.y(), 2));
}
/**
* Request a clipping area for the text (next draw only)
* @param pos Start position of the clipping
@ -482,7 +700,7 @@ public class CompositingDrawing extends Compositing {
public void setClippingWidth(final Vector3f pos, final Vector3f width) {
setClipping(pos, pos.add(width));
}
/**
* set the Color of the current foreground font
* @param color Color to set on foreground (for next print)
@ -490,7 +708,7 @@ public class CompositingDrawing extends Compositing {
public void setColor(final Color color) {
this.color = color;
}
/**
* set the background color of the font (for selected Text (not the
* global BG))
@ -499,7 +717,7 @@ public class CompositingDrawing extends Compositing {
public void setColorBg(final Color color) {
this.colorBg = color;
}
/**
* internal add of the specific point
* @param point The requeste dpoint to add
@ -512,19 +730,19 @@ public class CompositingDrawing extends Compositing {
}
this.vbo.flush();
}
public void setPos(final float xxx, final float yyy) {
setPos(new Vector3f(xxx, yyy, 0));
}
public void setPos(final float xxx, final float yyy, final float zzz) {
setPos(new Vector3f(xxx, yyy, zzz));
}
public void setPos(final Vector2f pos) {
setPos(new Vector3f(pos.x(), pos.y(), 0));
}
/**
* set position for the next text written
* @param pos Position of the text (in 3D)
@ -532,11 +750,11 @@ public class CompositingDrawing extends Compositing {
public void setPos(final Vector3f pos) {
this.position = pos;
}
public void setRelPos(final float xxx, final float yyy) {
this.position = this.position.add(xxx, yyy, 0);
}
/**
* set relative position for the next text writen
* @param pos ofset apply of the text (in 3D)
@ -544,15 +762,15 @@ public class CompositingDrawing extends Compositing {
public void setRelPos(final float xxx, final float yyy, final float zzz) {
this.position = this.position.add(xxx, yyy, zzz);
}
public void setRelPos(final Vector2f pos) {
setRelPos(new Vector3f(pos.x(), pos.y(), 0));
}
public void setRelPos(final Vector3f pos) {
this.position = this.position.add(pos);
}
/**
* Specify the line thickness for the next elements
* @param thickness The thickness desired for the next print
@ -564,12 +782,12 @@ public class CompositingDrawing extends Compositing {
this.thickness *= -1;
}
}
/**
* Un-Load the openGL program and get all the ID needed
*/
private void unLoadProgram() {
this.oGLprogram = null;
}
}

View File

@ -0,0 +1,73 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.ewol.compositing;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector2f;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CompositingGC extends CompositingDrawing {
private static final Logger LOGGER = LoggerFactory.getLogger(CompositingGC.class);
@Override
public void setPaintFillColor(final Color color) {
setColor(color);
}
@Override
public void setPaintStrokeColor(final Color color) {
setColorBg(color);
}
float strokeSize = 0;
@Override
public void setPaintStrokeWidth(final float width) {
this.strokeSize = width;
}
@Override
public void addLine(final Vector2f startPos, final Vector2f stopPos) {
setPos(startPos);
lineTo(stopPos);
}
@Override
public void addRectangle(final Vector2f position, final Vector2f size) {
setPos(position);
rectangle(position.add(size));
if (this.strokeSize > 0) {
rectangleBorder(position.add(size), this.strokeSize);
}
}
@Override
public void addRectangle(final Vector2f position, final Vector2f size, final Vector2f roundedCorner) {
if (roundedCorner == null || roundedCorner.x() <= 0) {
addRectangle(position, size);
} else {
setPos(position);
rectangleRadius(position.add(size), roundedCorner.x());
if (this.strokeSize > 0) {
rectangleBorderRadius(position.add(size), this.strokeSize, roundedCorner.x());
}
}
}
@Override
public void addCircle(final Vector2f position, final float radius) {
setPos(position);
circle(radius);
}
@Override
public void addEllipse(final Vector2f center, final Vector2f radius) {
// TODO Auto-generated method stub
}
}

View File

@ -1,269 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
package org.atriasoft.ewol.compositing;
import org.atriasoft.egami.ImageByte;
import org.atriasoft.esvg.CapMode;
import org.atriasoft.esvg.GraphicContext;
import org.atriasoft.esvg.JoinMode;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.gale.resource.ResourceTexture2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CompositingGraphicContext extends Compositing {
private static final Logger LOGGER = LoggerFactory.getLogger(CompositingGraphicContext.class);
GraphicContext context = new GraphicContext();
private final ResourceTexture2 texture = new ResourceTexture2();
public CompositingGraphicContext() {
}
public Vector2i calculateTextSize(final String data) {
return this.context.calculateTextSize(data);
}
public void circle(final Vector2f position, final float radius) {
this.context.circle(position, radius);
}
/**
* clear alll tre registered element in the current element
*/
@Override
public void clear() {
// call upper class
super.clear();
// reset Buffer :
this.context.clear();
}
/**
* Clear the fill color (disable fill ==> better that set it transparent)
*/
public void clearColorFill() {
this.context.clearColorFill();
}
/**
* Clear the Stroke color (disable stroke)
*/
public void clearColorStroke() {
this.context.clearColorStroke();
}
@Override
public void draw(final boolean disableDepthTest) {
// TODO Auto-generated method stub
}
public void ellipse(final Vector2f center, final Vector2f radius) {
this.context.ellipse(center, radius);
}
@Override
public void flush() {
if (this.texture == null) {
LOGGER.warn("texture is null");
return;
}
final ImageByte img = this.context.render();
//IOgami.storePNG(new Uri("/home/heero/000000000aaaaplopppp222.png"), img);
this.texture.set(img);
this.texture.flush();
}
/**
* Get the fill color.
* @return fill color.
*/
public Color getColorFill() {
return this.context.getColorFill();
}
/**
* Get the stroke color.
* @return Stroke color.
*/
public Color getColorStroke() {
return this.context.getColorStroke();
}
public CapMode getLineCap() {
return this.context.getLineCap();
}
public JoinMode getLineJoin() {
return this.context.getLineJoin();
}
public float getMiterLimit() {
return this.context.getMiterLimit();
}
public float getOpacity() {
return this.context.getOpacity();
}
/**
* get the source image registered size in the file (<0 when multiple size image)
* @return tre image registered size
*/
public Vector2i getRealSize() {
return this.texture.get().getSize();
}
public int getRendererId() {
return this.texture.getRendererId();
}
public ResourceTexture2 getResourceTexture() {
return this.texture;
}
public float getStrokeWidth() {
return this.context.getStrokeWidth();
}
public int getTextHeight() {
return this.context.getTextHeight();
}
public float getTextSize() {
return this.context.getTextSize();
}
/**
* Sometimes the user declare an image but not allocate the ressources all the time, this is to know it ..
* @return the validity od the resources.
*/
public boolean hasSources() {
return true;
}
public void line(final Vector2f origin, final Vector2f destination) {
this.context.line(origin, destination);
}
public void lineRel(final Vector2f origin, final Vector2f relativeDestination) {
this.context.lineRel(origin, relativeDestination);
}
public void pathLine(final Vector2f pos) {
this.context.pathLine(pos);
}
public void pathLineTo(final Vector2f pos) {
this.context.pathLineTo(pos);
}
public void pathMove(final Vector2f pos) {
this.context.pathMove(pos);
}
public void pathMoveTo(final Vector2f pos) {
this.context.pathMoveTo(pos);
}
public void pathStart() {
this.context.pathStart();
}
public void pathStop() {
this.context.pathStop();
}
public void pathStopLinked() {
this.context.pathStopLinked();
}
public void rectangle(final Vector2f position, final Vector2f destination) {
this.context.rectangle(position, destination);
}
public void rectangleRounded(final Vector2f position, final Vector2f destination, final Vector2f ruound) {
this.context.rectangleRounded(position, destination, ruound);
}
public void rectangleRoundedWidth(final Vector2f position, final Vector2f width, final Vector2f ruound) {
this.context.rectangleRoundedWidth(position, width, ruound);
}
public void rectangleWidth(final Vector2f position, final Vector2f width) {
this.context.rectangleWidth(position, width);
}
/**
* set the fill color
* @param color Color to set on fill
* @apiNote use clearFill() if you want to remove drawing of fill
*/
public void setColorFill(final Color color) {
this.context.setColorFill(color);
}
/**
* set the stroke color
* @param color Color to set on stroke
* @apiNote use clearStroke() if you want to remove drawing of stroke
*/
public void setColorStroke(final Color color) {
this.context.setColorStroke(color);
}
public void setLineCap(final CapMode lineCap) {
this.context.setLineCap(lineCap);
}
public void setLineJoin(final JoinMode lineJoin) {
this.context.setLineJoin(lineJoin);
}
public void setMiterLimit(final float miterLimit) {
this.context.setMiterLimit(miterLimit);
}
public void setOpacity(final float opacity) {
this.context.setOpacity(opacity);
}
/**
* Set global size of the Graphic context (output render size)
* @param xxx Width of the image
* @param yyy Height of the image
* @apiNote It will clear the current context.
*/
public void setSize(final int xxx, final int yyy) {
this.context.setSize(xxx, yyy);
}
/**
* Set global size of the Graphic contexct (output render size)
* @param vector2i New size of the image
* @apiNote It will clear the current context.
*/
public void setSize(final Vector2i size) {
this.context.setSize(size.x(), size.y());
}
public void setStrokeWidth(final float strokeWidth) {
this.context.setStrokeWidth(strokeWidth);
}
public void text(final Vector2f position, final float height, final String data) {
this.context.text(position, height, data);
}
public void text(final Vector2f position, final String data) {
this.context.text(position, data);
}
}

View File

@ -8,13 +8,21 @@ package org.atriasoft.ewol.compositing;
import org.atriasoft.egami.ImageByte;
import org.atriasoft.egami.ImageByteRGBA;
import org.atriasoft.egami.ToolImage;
import org.atriasoft.esvg.CapMode;
import org.atriasoft.esvg.Circle;
import org.atriasoft.esvg.Ellipse;
import org.atriasoft.esvg.EsvgDocument;
import org.atriasoft.esvg.JoinMode;
import org.atriasoft.esvg.Line;
import org.atriasoft.esvg.PaintState;
import org.atriasoft.esvg.Rectangle;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etk.math.Vector3f;
import org.atriasoft.etk.util.Pair;
import org.atriasoft.gale.backend3d.OpenGL;
import org.atriasoft.gale.backend3d.OpenGL.RenderMode;
import org.atriasoft.gale.resource.ResourceProgram;
@ -23,7 +31,7 @@ import org.atriasoft.gale.resource.ResourceVirtualArrayObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CompositingSVG extends Compositing {
public class CompositingSVG extends CompositingDraw {
private static final Logger LOGGER = LoggerFactory.getLogger(CompositingSVG.class);
public static final int NB_VBO = 3;
public static final int SIZE_AUTO = 0;
@ -126,11 +134,14 @@ public class CompositingSVG extends Compositing {
@Override
public void flush() {
this.vbo.setPosition(this.vboDataCoords);
this.vbo.setTextureCoordinate(this.vboDataCoordsTex);
this.vbo.setColors(this.vboDataColors);
this.vbo.setVertexCount(this.vboDataCoords.length);
this.vbo.flush();
generate();
if (this.vboDataCoords != null) {
this.vbo.setPosition(this.vboDataCoords);
this.vbo.setTextureCoordinate(this.vboDataCoordsTex);
this.vbo.setColors(this.vboDataColors);
this.vbo.setVertexCount(this.vboDataCoords.length);
this.vbo.flush();
}
}
/**
@ -407,39 +418,120 @@ public class CompositingSVG extends Compositing {
// Nothing to do ...
return;
}
this.svgData = null;
clear();
final ImageByte tmp = ToolImage.convertImageByte(data.renderImageFloatRGBA(size));
if (tmp == null) {
LOGGER.error("Can not load the Raw SVG ... ");
return;
}
if (this.resource == null) {
this.resource = new ResourceTexture2();
}
this.resource.set(tmp);
this.svgDoc = data;
this.requestSize = size;
generate();
}
protected void generate() {
final Vector2i size = this.requestSize;
if (this.svgDoc != null) {
final ImageByte tmp = ToolImage.convertImageByte(this.svgDoc.renderImageFloatRGBA(size));
if (tmp == null) {
LOGGER.error("Can not load the Raw SVG ... ");
return;
}
if (this.resource == null) {
this.resource = new ResourceTexture2();
}
this.resource.set(tmp);
}
}
PaintState paint = new PaintState();
public void clearPaint() {
this.paint.clear();
}
public void createSize(final Vector2i size) {
clear();
this.paint.clear();
if (this.svgDoc == null) {
this.svgDoc = new EsvgDocument(size);
}
this.requestSize = size;
}
public void setRectangleAsSource(final int sizeX, final int sizeY, final Color color) {
setSource("""
<svg width="%d" height="%d">
<rect
x="%d"
y="%d"
width="%d"
height="%d"
fill="%s"
/>
</svg>""".formatted( //
sizeX, sizeY, //
0, 0, //
sizeX, sizeY, //
color.toStringSharp() //
), new Vector2i(sizeX, sizeY));
@Override
public void setPaintFillColor(final Color color) {
this.paint.fill = new Pair<>(color, "");
}
@Override
public void setPaintStrokeColor(final Color color) {
this.paint.stroke = new Pair<>(color, "");
}
@Override
public void setPaintStrokeWidth(final float width) {
this.paint.strokeWidth = width;
}
public void setPaintLineJoin(final JoinMode lineJoin) {
this.paint.lineJoin = lineJoin;
}
public void setPaintLineCap(final CapMode lineCap) {
this.paint.lineCap = lineCap;
}
public void setPaintMiterLimit(final float miterLimit) {
this.paint.miterLimit = miterLimit;
}
public void setPaintOpacity(final float opacity) {
this.paint.opacity = opacity;
}
@Override
public void addLine(final Vector2f startPos, final Vector2f stopPos) {
if (this.svgDoc == null) {
this.svgDoc = new EsvgDocument();
}
this.svgDoc.addElement(new Line(startPos, stopPos, this.paint));
}
@Override
public void addRectangle(final Vector2f position, final Vector2f size) {
if (this.svgDoc == null) {
this.svgDoc = new EsvgDocument();
}
this.svgDoc.addElement(new Rectangle(position, size, this.paint));
}
@Override
public void addRectangle(final Vector2f position, final Vector2f size, final Vector2f roundedCorner) {
if (this.svgDoc == null) {
this.svgDoc = new EsvgDocument();
}
this.svgDoc.addElement(new Rectangle(position, size, roundedCorner, this.paint));
}
@Override
public void addCircle(final Vector2f position, final float radius) {
if (this.svgDoc == null) {
this.svgDoc = new EsvgDocument();
}
this.svgDoc.addElement(new Circle(position, radius, this.paint));
}
@Override
public void addEllipse(final Vector2f center, final Vector2f radius) {
if (this.svgDoc == null) {
this.svgDoc = new EsvgDocument();
}
this.svgDoc.addElement(new Ellipse(center, radius, this.paint));
}
public void setRectangleAsSource(final int sizeX, final int sizeY, final Color color) {
createSize(new Vector2i(sizeX, sizeY)); // specific for SVG
setPaintFillColor(color);
addRectangle(Vector2f.ZERO, new Vector2f(sizeX, sizeY));
flush();
}
public void setRectangleBorderAsSource(
final int sizeX,
final int sizeY,
@ -447,30 +539,15 @@ public class CompositingSVG extends Compositing {
final int borderSize,
final int borderRadius,
final Color borderColor) {
final int paddingCompensateBorder = Math.round(borderSize * 0.5f);
setSource("""
<svg width="%d" height="%d">
<rect
x="%d"
y="%d"
width="%d"
height="%d"
rx="%d"
ry="%d"
fill="%s"
stroke="%s"
stroke-width="%d"
/>
</svg>""".formatted( //
sizeX, sizeY, //
paddingCompensateBorder, paddingCompensateBorder, //
sizeX - 2 * paddingCompensateBorder, sizeY - 2 * paddingCompensateBorder, //
borderRadius, //
borderRadius, //
color.toStringSharp(), //
borderColor.toStringSharp(), //
borderSize //
), new Vector2i(sizeX, sizeY));
createSize(new Vector2i(sizeX, sizeY)); // specific for SVG
setPaintFillColor(color);
setPaintStrokeColor(borderColor);
setPaintStrokeWidth(borderSize);
addRectangle(new Vector2f(paddingCompensateBorder, paddingCompensateBorder), //
new Vector2f(sizeX - 2 * paddingCompensateBorder, sizeY - 2 * paddingCompensateBorder), //
new Vector2f(borderRadius, borderRadius));
flush();
}
}

View File

@ -13,7 +13,6 @@ import org.atriasoft.etk.Color;
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.util.Dynamic;
import org.atriasoft.ewol.compositing.tools.TextDecoration;
import org.atriasoft.ewol.resource.font.FontMode;
@ -47,7 +46,7 @@ public abstract class TextBase extends Compositing {
protected Color defaultColorFg = Color.BLACK; // !< The text foreground color
// this section is reserved for HTML parsing and display:
public String htmlCurrentLine = ""; // !< current line for HTML display
public List<TextDecoration> htmlDecoration = new ArrayList<>(); // !< current decoration for the HTML display
public TextDecoration htmlDecoTmp = new TextDecoration(); // !< current decoration
protected boolean kerning = true; // !< Kerning enable or disable on the next elements displayed
@ -70,19 +69,19 @@ public abstract class TextBase extends Compositing {
// position)
protected float stopTextPos = 0; // !< end of the alignment (when a string is too height it cut at the word
protected ResourceVirtualArrayObject vbo = null;
protected CompositingDrawing vectorialDraw = new CompositingDrawing();
protected CompositingDrawing vectorialDraw = new CompositingGC();
/**
* generic constructor
*/
public TextBase() {
this(new Uri("DATA", "text.vert", "ewol"), new Uri("DATA", "text.frag", "ewol"));
}
public TextBase(final Uri vertexShader, final Uri fragmentShader) {
this(vertexShader, fragmentShader, true);
}
public TextBase(final Uri vertexShader, final Uri fragmentShader, final boolean loadProgram) {
if (loadProgram) {
loadProgram(vertexShader, fragmentShader);
@ -92,7 +91,7 @@ public abstract class TextBase extends Compositing {
// TO facilitate some debugs we add a name of the VBO:
this.vbo.setName("[VBO] of super.TextBase");
}
/**
* calculate a theoric charcode size
* @param charcode The Unicode value to calculate dimention.
@ -101,7 +100,7 @@ public abstract class TextBase extends Compositing {
public Vector2f calculateSize(final Character charcode) {
return calculateSizeChar(charcode);
}
/**
* calculate a theoric text size
* @param text The string to calculate dimention.
@ -118,10 +117,10 @@ public abstract class TextBase extends Compositing {
}
return outputSize;
}
// ! @previous
public abstract Vector2f calculateSizeChar(Character charcode);
/**
* calculate a theoric text size
* @param text The string to calculate dimention.
@ -131,13 +130,13 @@ public abstract class TextBase extends Compositing {
if (text.length() == 0) {
return Vector2f.ZERO;
}
final StringBuilder tmpData = new StringBuilder("<html><body>\n");
tmpData.append(text);
tmpData.append("\n</body></html>\n");
return calculateSizeHTML(tmpData.toString());
}
/**
* calculate a theoric text size
* @param text The string to calculate dimention.
@ -149,27 +148,27 @@ public abstract class TextBase extends Compositing {
// LOGGER.debug(" 0 size for=\n" + text);
// disable display system
this.needDisplay = false;
setPos(Vector2f.ZERO);
// same as print without the end display ...
printHTML(text);
//LOGGER.error(" ]]]] position={}", this.position);
//LOGGER.error(" ]]]] sizeDisplayStart={}", this.sizeDisplayStart);
//LOGGER.error(" ]]]] sizeDisplayStop={}", this.sizeDisplayStop);
// get the last elements
this.sizeDisplayStop = Vector2f.max(this.position, this.sizeDisplayStop);
this.sizeDisplayStart = Vector2f.min(this.position, this.sizeDisplayStart);
// LOGGER.debug(" 2 Start pos=" + this.sizeDisplayStart);
// LOGGER.debug(" 2 Stop pos=" + this.sizeDisplayStop);
// set back the display system
this.needDisplay = true;
return new Vector2f(this.sizeDisplayStop.x() - this.sizeDisplayStart.x(),
this.sizeDisplayStop.y() - this.sizeDisplayStart.y());
}
/**
* clear all the registered element in the current element
*/
@ -184,14 +183,14 @@ public abstract class TextBase extends Compositing {
// reset temporal variables:
reset();
}
/**
* disable the alignement system
*/
public void disableAlignement() {
this.alignment = AlignMode.DISABLE;
}
/**
* remove the cursor display
*/
@ -199,7 +198,7 @@ public abstract class TextBase extends Compositing {
this.selectionStartPos = -100;
this.cursorPos = -100;
}
/**
* draw All the registered text in the current element on openGL
*/
@ -207,20 +206,20 @@ public abstract class TextBase extends Compositing {
public void draw(final boolean disableDepthTest) {
drawD(disableDepthTest);
}
// ! @previous
public void draw(final Matrix4f transformationMatrix, final boolean enableDepthTest) {
drawMT(transformationMatrix, enableDepthTest);
}
/**
* draw All the refistered text in the current element on openGL
*/
public abstract void drawD(final boolean disableDepthTest);
// ! @previous
public abstract void drawMT(final Matrix4f transformationMatrix, final boolean enableDepthTest);
/**
* calculate the element number that is the first out the alignment
* range (start at the specify ID, and use start pos with current one)
@ -241,21 +240,21 @@ public abstract class TextBase extends Compositing {
final Dynamic<Integer> freeSpace) {
// store previous :
final Character storePrevious = this.previousCharcode;
stop.value = text.length();
space.value = 0;
int lastSpacePosition = start;
int lastSpacefreeSize = 0;
float endPos = this.position.x();
boolean endOfLine = false;
float stopPosition = this.stopTextPos;
if (!this.needDisplay || this.stopTextPos == this.startTextPos) {
stopPosition = this.startTextPos + 3999999999.0f;
}
for (int iii = start; iii < text.length(); iii++) {
final Vector2f tmpSize = calculateSize(text.charAt(iii));
// check overflow :
@ -293,12 +292,12 @@ public abstract class TextBase extends Compositing {
freeSpace.value = lastSpacefreeSize;
return false;
}
@Override
public void flush() {
this.vectorialDraw.flush();
}
/**
* This generate the line return == > it return to the alignment
* position start and at the correct line position ==> it might be use to
@ -308,7 +307,7 @@ public abstract class TextBase extends Compositing {
// reset position :
setPos(new Vector2f(this.startTextPos, this.position.y() - getHeight()));
}
/**
* get the current alignment property
* @return the current alignment type
@ -316,12 +315,12 @@ public abstract class TextBase extends Compositing {
public AlignMode getAlignment() {
return this.alignment;
}
// This is used to draw background selection and other things ...
public CompositingDrawing getDrawing() {
return this.vectorialDraw;
}
/**
* get the current font mode
* @return The font mode applied
@ -329,11 +328,11 @@ public abstract class TextBase extends Compositing {
public FontMode getFontMode() {
return this.mode;
}
public abstract GlyphProperty getGlyphPointer(Character charcode);
public abstract float getHeight();
/**
* get the current display position (sometime needed in the gui control)
* @return the current position.
@ -341,9 +340,9 @@ public abstract class TextBase extends Compositing {
public Vector2f getPos() {
return this.position;
}
public abstract float getSize();
/**
* add a line with the current this.htmlDecoTmp decoration
* @param data The cuurent data to add.
@ -365,7 +364,7 @@ public abstract class TextBase extends Compositing {
this.htmlDecoration.add(this.htmlDecoTmp);
}
}
/**
* draw the current line
*/
@ -376,7 +375,7 @@ public abstract class TextBase extends Compositing {
this.htmlCurrentLine = "";
this.htmlDecoration.clear();
}
/**
* load the openGL program and get all the ID needed
*/
@ -396,7 +395,7 @@ public abstract class TextBase extends Compositing {
old = null;
}
}
/**
* This parse a tinyXML node (void pointer to permit to hide tiny XML in
* include).
@ -509,11 +508,11 @@ public abstract class TextBase extends Compositing {
} else {
LOGGER.error("node not suported type: " + elem.getType() + " val='" + elem.getValue() + "'");
}
//LOGGER.error("Add data elems... @pos=", this.position);
}
}
/**
* display a compleat string in the current element.
* @param text The string to display.
@ -522,7 +521,7 @@ public abstract class TextBase extends Compositing {
final List<TextDecoration> decorationEmpty = new ArrayList<>();
print(text, decorationEmpty);
}
/**
* display a compleat string in the current element whith specific
* decorations (advence mode).
@ -702,14 +701,14 @@ public abstract class TextBase extends Compositing {
+ this.sizeDisplayStop + " pos=" + this.position);
}
}
/**
* display the current char in the current element (note that the kerning
* is availlable if the position is not changed)
* @param charcode Char that might be dispalyed
*/
public abstract void printChar(Character charcode);
/**
* draw a cursor at the specify position
* @param isInsertMode True if the insert mode is activated
@ -717,7 +716,7 @@ public abstract class TextBase extends Compositing {
public void printCursor(final boolean isInsertMode) {
printCursor(isInsertMode, 20.0f);
}
public void printCursor(final boolean isInsertMode, final float cursorSize) {
final int fontHeigh = (int) getHeight();
if (isInsertMode) {
@ -728,7 +727,7 @@ public abstract class TextBase extends Compositing {
this.vectorialDraw.setThickness(0);
}
}
/**
* display a compleat string in the current element with the generic
* decoration specification. (basic html data)
@ -764,7 +763,7 @@ public abstract class TextBase extends Compositing {
// LOGGER.debug("plop : " + tmpData);
printHTML(tmpData.toString());
}
/**
* display a compleat string in the current element with the generic
* decoration specification. (basic html data)
@ -804,7 +803,7 @@ public abstract class TextBase extends Compositing {
return;
}
final XmlElement root = (XmlElement) doc.getNode("html");
if (!root.existNode("body")) {
LOGGER.error("can not load XML: main node not find: 'body'");
return;
@ -826,7 +825,7 @@ public abstract class TextBase extends Compositing {
e.printStackTrace();
}
}
/**
* clear all the intermediate result detween 2 prints
*/
@ -852,19 +851,19 @@ public abstract class TextBase extends Compositing {
this.needDisplay = true;
this.nbCharDisplayed = 0;
}
@Override
public void rotate(final Vector2f vect, final float angle) {
super.rotate(vect, angle);
this.vectorialDraw.rotate(vect, angle);
}
@Override
public void scale(final Vector2f vect) {
super.scale(vect);
this.vectorialDraw.scale(vect);
}
/**
* Request a clipping area for the text (next draw only)
* @param pos Start position of the clipping
@ -878,7 +877,7 @@ public abstract class TextBase extends Compositing {
this.clippingEnable = true;
this.vectorialDraw.setClipping(this.clippingPosStart, this.clippingPosStop);
}
/**
* enable/Disable the clipping (without lose the current clipping
* position)
@ -890,7 +889,6 @@ public abstract class TextBase extends Compositing {
this.vectorialDraw.setClippingMode(this.clippingEnable);
}
/**
* Request a clipping area for the text (next draw only)
* @param pos Start position of the clipping
@ -899,7 +897,7 @@ public abstract class TextBase extends Compositing {
public void setClippingWidth(final Vector2f pos, final Vector2f width) {
setClipping(pos, pos.add(width));
}
/**
* set the Color of the current foreground font
* @param color Color to set on foreground (for next print)
@ -907,7 +905,7 @@ public abstract class TextBase extends Compositing {
public void setColor(final Color color) {
this.color = color;
}
/**
* set the background color of the font (for selected Text (not the
* global BG))
@ -917,7 +915,7 @@ public abstract class TextBase extends Compositing {
this.colorBg = color;
this.vectorialDraw.setColor(color);
}
/**
* change the cursor color
* @param color New color for the Selection
@ -925,7 +923,7 @@ public abstract class TextBase extends Compositing {
public void setCursorColor(final Color color) {
this.colorCursor = color;
}
/**
* set a cursor at a specific position:
* @param cursorPos id of the cursor position
@ -934,7 +932,7 @@ public abstract class TextBase extends Compositing {
this.selectionStartPos = cursorPos;
this.cursorPos = cursorPos;
}
/**
* set a cursor at a specific position with his associated selection:
* @param cursorPos id of the cursor position
@ -944,7 +942,7 @@ public abstract class TextBase extends Compositing {
this.selectionStartPos = selectionStartPos;
this.cursorPos = cursorPos;
}
/**
* set the default background color of the font (when reset, set this
* value ...)
@ -953,7 +951,7 @@ public abstract class TextBase extends Compositing {
public void setDefaultColorBg(final Color color) {
this.defaultColorBg = color;
}
/**
* set the default Foreground color of the font (when reset, set this
* value ...)
@ -962,7 +960,7 @@ public abstract class TextBase extends Compositing {
public void setDefaultColorFg(final Color color) {
this.defaultColorFg = color;
}
/**
* Specify the font property (this reset the internal element of the
* current text (system requirement)
@ -970,7 +968,7 @@ public abstract class TextBase extends Compositing {
* @param fontSize New font size
*/
public abstract void setFont(final String fontName, final int fontSize);
/**
* enable or disable the bold mode
* @param status The new status for this display property
@ -990,7 +988,7 @@ public abstract class TextBase extends Compositing {
setFontMode(FontMode.ITALIC);
}
}
/**
* enable or disable the italic mode
* @param status The new status for this display property
@ -1010,27 +1008,27 @@ public abstract class TextBase extends Compositing {
setFontMode(FontMode.BOLD);
}
}
/**
* Specify the font mode for the next @ref print
* @param mode The font mode requested
*/
public abstract void setFontMode(FontMode mode);
/**
* Specify the font name (this reset the internal element of the current
* text (system requirement)
* @param fontName Current name of the selected font
*/
public abstract void setFontName(final String fontName);
/**
* Specify the font size (this reset the internal element of the current
* text (system requirement)
* @param fontSize New font size
*/
public abstract void setFontSize(final int fontSize);
/**
* set the activation of the Kerning for the display (if it existed)
* @param newMode enable/Diasable the kerning on this font.
@ -1038,7 +1036,7 @@ public abstract class TextBase extends Compositing {
public void setKerningMode(final boolean newMode) {
this.kerning = newMode;
}
/**
* set position for the next text writen
* @param pos Position of the text (in 3D)
@ -1066,7 +1064,7 @@ public abstract class TextBase extends Compositing {
//LOGGER.trace("update size 4 " + this.sizeDisplayStart + " " + this.sizeDisplayStop);
}
}
/**
* set relative position for the next text written
* @param pos offset apply of the text (in 3D)
@ -1076,7 +1074,7 @@ public abstract class TextBase extends Compositing {
this.previousCharcode = 0;
this.vectorialDraw.setPos(this.position);
}
/**
* change the selection color
* @param color New color for the Selection
@ -1084,7 +1082,7 @@ public abstract class TextBase extends Compositing {
public void setSelectionColor(final Color color) {
this.colorSelection = color;
}
/**
* This generate the possibility to generate the big text property
* @param startTextPos The x text start position of the display.
@ -1095,7 +1093,7 @@ public abstract class TextBase extends Compositing {
public void setTextAlignment(final float startTextPos, final float stopTextPos) {
setTextAlignment(startTextPos, stopTextPos, AlignMode.DISABLE);
}
public void setTextAlignment(final float startTextPos, final float stopTextPos, final AlignMode alignement) {
this.startTextPos = startTextPos;
this.stopTextPos = stopTextPos + 1;
@ -1105,11 +1103,11 @@ public abstract class TextBase extends Compositing {
LOGGER.trace("Request alignment with Borne position error : " + startTextPos + " => " + stopTextPos);
}
}
@Override
public void translate(final Vector2f vect) {
super.translate(vect);
this.vectorialDraw.translate(vect);
}
}

View File

@ -9,15 +9,14 @@ import org.atriasoft.etk.Dimension1f;
import org.atriasoft.etk.Dimension2f;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.ewol.compositing.CompositingSVG;
import org.atriasoft.ewol.compositing.CompositingGC;
import org.atriasoft.ewol.event.EventTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Box extends Container {
private static final Logger LOGGER = LoggerFactory.getLogger(Box.class);
protected CompositingSVG compositing = new CompositingSVG();
protected CompositingGC vectorialDraw = new CompositingGC();
public static class BoxParameter {
public Float margin;
@ -218,8 +217,7 @@ public class Box extends Container {
subWidgetSize = subWidgetSize.less(offsetSubWidget.multiply(2));
subWidgetSize = subWidgetSize.clipInteger();
final Vector2f freeSizeWithoutWidget = this.size
.less(offsetSubWidget.multiply(2)).less(subWidgetSize);
final Vector2f freeSizeWithoutWidget = this.size.less(offsetSubWidget.multiply(2)).less(subWidgetSize);
Vector2f subWidgetOrigin = this.origin.add(this.propertyGravity.gravityGenerateDelta(freeSizeWithoutWidget));
subWidgetOrigin = subWidgetOrigin.add(offsetSubWidget);
subWidgetOrigin = subWidgetOrigin.clipInteger();
@ -228,9 +226,6 @@ public class Box extends Container {
this.subWidget.onChangeSize();
}
protected Vector2i renderOrigin;
protected Vector2i renderSize;
private Vector2f calculateOriginRendering(final Vector2f renderSize) {
return this.propertyGravity.gravityGenerateDelta(this.size.less(renderSize));
}
@ -254,40 +249,36 @@ public class Box extends Container {
}
final Vector2f localMargin = this.propertyMargin.size();
Vector2f tmpRenderSize = calculateSizeRendering();
Vector2f tmpRenderOrigin = calculateOriginRendering(tmpRenderSize);
Vector2f renderSize = calculateSizeRendering();
Vector2f renderOrigin = calculateOriginRendering(renderSize);
tmpRenderOrigin = tmpRenderOrigin.add(localMargin);
tmpRenderSize = tmpRenderSize.less(localMargin.multiply(2));
renderOrigin = renderOrigin.add(localMargin);
renderSize = renderSize.less(localMargin.multiply(2));
// not sure this is needed...
tmpRenderSize = tmpRenderSize.clipInteger();
tmpRenderOrigin = tmpRenderOrigin.clipInteger();
this.renderOrigin = new Vector2i((int) tmpRenderOrigin.x(), (int) tmpRenderOrigin.y());
this.renderSize = new Vector2i((int) tmpRenderSize.x(), (int) tmpRenderSize.y());
renderSize = renderSize.clipInteger();
renderOrigin = renderOrigin.clipInteger();
renderOrigin = renderOrigin.clipInteger();
renderSize = renderSize.clipInteger();
this.startPosition = renderOrigin.toVector2i();
this.endPosition = renderSize.toVector2i();
//System.out.println("renderSize: " + this.renderSize);
// remove data of the previous composition :
this.compositing.clear();
this.vectorialDraw.clear();
final int borderSize = (int) this.propertyBorderWidth.size();
final int paddingCompensateBorder = Math.round(borderSize * 0.5f);
if (borderSize > 0.0f) {
this.compositing.setRectangleBorderAsSource(this.renderSize.x(), this.renderSize.y(), this.propertyColor,
borderSize, (int) this.propertyBorderRadius.size(), this.propertyBorderColor);
} else {
this.compositing.setRectangleAsSource(this.renderSize.x(), this.renderSize.y(), this.propertyColor);
}
this.compositing.setPos(this.renderOrigin);
// For events:
this.startPosition = this.renderOrigin;
this.endPosition = this.renderOrigin.add(this.renderSize);
this.compositing.print(this.renderSize);
this.compositing.flush();
this.vectorialDraw.setPaintFillColor(this.propertyColor);
this.vectorialDraw.setPaintStrokeColor(this.propertyBorderColor);
this.vectorialDraw.setPaintStrokeWidth(borderSize);
this.vectorialDraw.addRectangle(renderOrigin, renderSize,
new Vector2f(this.propertyBorderRadius.size(), this.propertyBorderRadius.size()));
this.vectorialDraw.flush();
}
@Override
protected void onDraw() {
if (this.compositing != null) {
this.compositing.draw(true);
if (this.vectorialDraw != null) {
this.vectorialDraw.draw(true);
}
super.onDraw();
}

View File

@ -0,0 +1,293 @@
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.etk.Color;
import org.atriasoft.etk.Dimension1f;
import org.atriasoft.etk.Dimension2f;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.ewol.compositing.CompositingSVG;
import org.atriasoft.ewol.event.EventTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class BoxSVG extends Container {
private static final Logger LOGGER = LoggerFactory.getLogger(BoxSVG.class);
protected CompositingSVG vectorialDraw = new CompositingSVG();
public static class BoxParameter {
public Float margin;
public Float padding;
public Float borderWidth;
public Float borderRadius;
public String borderColor;
public String color;
}
/**
* Periodic call to update grapgic display
* @param event Time generic event
*/
protected static void periodicCall(final BoxSVG self, final EventTime event) {
LOGGER.trace("Periodic call on Entry(" + event + ")");
self.markToRedraw();
}
Vector2i startPosition = Vector2i.ZERO;
Vector2i endPosition = Vector2i.ZERO;
public boolean isInside(final Vector2f value) {
return value.x() > this.startPosition.x() //
&& value.y() > this.startPosition.y() //
&& value.x() < this.endPosition.x() //
&& value.y() < this.endPosition.y();
}
/**
* Constructor
*/
public BoxSVG() {}
/**
* Constructor with his subWidget
*/
public BoxSVG(final Widget subWidget) {
super(subWidget);
}
protected Dimension1f propertyBorderWidth = Dimension1f.ZERO;
@AknotManaged
@AknotAttribute
@AknotName(value = "border-width")
@AknotDescription(value = "Border of the box")
public Dimension1f getPropertyBorderWidth() {
return this.propertyBorderWidth;
}
public void setPropertyBorderWidth(final Dimension1f propertyBorder) {
if (this.propertyBorderWidth.equals(propertyBorder)) {
return;
}
this.propertyBorderWidth = propertyBorder;
markToRedraw();
requestUpdateSize();
}
protected Dimension1f propertyBorderRadius = new Dimension1f(0);
@AknotManaged
@AknotAttribute
@AknotName(value = "border-radius")
@AknotDescription(value = "Border radius of the box")
public Dimension1f getPropertyBorderRadius() {
return this.propertyBorderRadius;
}
public void setPropertyBorderRadius(final Dimension1f propertyBorderRadius) {
if (this.propertyBorderRadius.equals(propertyBorderRadius)) {
return;
}
this.propertyBorderRadius = propertyBorderRadius;
markToRedraw();
requestUpdateSize();
}
protected Color propertyBorderColor = Color.NONE;
@AknotManaged
@AknotAttribute
@AknotName(value = "border-color")
@AknotDescription(value = "Border color of the box")
public Color getPropertyBorderColor() {
return this.propertyBorderColor;
}
public void setPropertyBorderColor(final Color propertyBorderColor) {
if (this.propertyBorderColor.equals(propertyBorderColor)) {
return;
}
this.propertyBorderColor = propertyBorderColor;
markToRedraw();
requestUpdateSize();
}
protected Color propertyColor = Color.NONE;
@AknotManaged
@AknotAttribute
@AknotName(value = "color")
@AknotDescription(value = "Border color of the box")
public Color getPropertyColor() {
return this.propertyColor;
}
public void setPropertyColor(final Color propertyColor) {
if (this.propertyColor.equals(propertyColor)) {
return;
}
this.propertyColor = propertyColor;
markToRedraw();
requestUpdateSize();
}
protected Dimension2f propertyMargin = Dimension2f.ZERO;
@AknotManaged
@AknotAttribute
@AknotName(value = "margin")
@AknotDescription(value = "margin of the box")
public Dimension2f getPropertyMargin() {
return this.propertyMargin;
}
public void setPropertyMargin(final Dimension2f propertyMargin) {
if (this.propertyMargin.equals(propertyMargin)) {
return;
}
this.propertyMargin = propertyMargin;
markToRedraw();
requestUpdateSize();
}
protected Dimension2f propertyPadding = Dimension2f.ZERO;
@AknotManaged
@AknotAttribute
@AknotName(value = "padding")
@AknotDescription(value = "Padding of the box")
public Dimension2f getPropertyPadding() {
return this.propertyPadding;
}
public void setPropertyPadding(final Dimension2f propertyPadding) {
if (this.propertyPadding.equals(propertyPadding)) {
return;
}
this.propertyPadding = propertyPadding;
markToRedraw();
requestUpdateSize();
}
@Override
public void calculateMinMaxSize() {
super.calculateMinMaxSize();
final Vector2f childMinSize = new Vector2f(this.minSize.x(), this.minSize.y());
LOGGER.debug("calculate min size: border=" + this.propertyBorderWidth);
final Vector2f borderSize = new Vector2f(this.propertyBorderWidth.size() * 2.0f,
this.propertyBorderWidth.size() * 2.0f);
final Vector2f padding = this.propertyPadding.size().multiply(2);
final Vector2f margin = this.propertyMargin.size().multiply(2);
final Vector2f calculatedBoxMinSize = childMinSize.add(margin).add(padding).add(borderSize);
this.minSize = calculatedBoxMinSize;
this.maxSize = Vector2f.max(this.minSize, this.propertyMaxSize.size());
markToRedraw();
}
@Override
public void onChangeSize() {
markToRedraw();
if (this.propertyHide) {
return;
}
if (this.subWidget == null) {
return;
}
final Vector2f localPadding = this.propertyPadding.size();
final Vector2f localMargin = this.propertyMargin.size();
final float localBorderSize = this.propertyBorderWidth.size();
final Vector2f offsetSubWidget = localPadding.add(localMargin).add(localBorderSize);
Vector2f subWidgetSize = this.subWidget.getCalculateMinSize();
if (this.subWidget.canExpand().x() && this.propertyFill.x()) {
subWidgetSize = subWidgetSize.withX(this.size.x());
} else {
subWidgetSize = subWidgetSize.withX(this.minSize.x());
}
if (this.subWidget.canExpand().y() && this.propertyFill.y()) {
subWidgetSize = subWidgetSize.withY(this.size.y());
} else {
subWidgetSize = subWidgetSize.withY(this.minSize.y());
}
subWidgetSize = subWidgetSize.less(offsetSubWidget.multiply(2));
subWidgetSize = subWidgetSize.clipInteger();
final Vector2f freeSizeWithoutWidget = this.size.less(offsetSubWidget.multiply(2)).less(subWidgetSize);
Vector2f subWidgetOrigin = this.origin.add(this.propertyGravity.gravityGenerateDelta(freeSizeWithoutWidget));
subWidgetOrigin = subWidgetOrigin.add(offsetSubWidget);
subWidgetOrigin = subWidgetOrigin.clipInteger();
this.subWidget.setOrigin(subWidgetOrigin);
this.subWidget.setSize(subWidgetSize);
this.subWidget.onChangeSize();
}
protected Vector2i renderOrigin;
protected Vector2i renderSize;
private Vector2f calculateOriginRendering(final Vector2f renderSize) {
return this.propertyGravity.gravityGenerateDelta(this.size.less(renderSize));
}
private Vector2f calculateSizeRendering() {
Vector2f tmpRenderSize = this.minSize;
if (this.propertyFill.x()) {
tmpRenderSize = tmpRenderSize.withX(this.size.x());
}
if (this.propertyFill.y()) {
tmpRenderSize = tmpRenderSize.withY(this.size.y());
}
return tmpRenderSize;
}
@Override
public void onRegenerateDisplay() {
super.onRegenerateDisplay();
if (!needRedraw()) {
return;
}
final Vector2f localMargin = this.propertyMargin.size();
Vector2f tmpRenderSize = calculateSizeRendering();
Vector2f tmpRenderOrigin = calculateOriginRendering(tmpRenderSize);
tmpRenderOrigin = tmpRenderOrigin.add(localMargin);
tmpRenderSize = tmpRenderSize.less(localMargin.multiply(2));
// not sure this is needed...
tmpRenderSize = tmpRenderSize.clipInteger();
tmpRenderOrigin = tmpRenderOrigin.clipInteger();
this.renderOrigin = new Vector2i((int) tmpRenderOrigin.x(), (int) tmpRenderOrigin.y());
this.renderSize = new Vector2i((int) tmpRenderSize.x(), (int) tmpRenderSize.y());
//System.out.println("renderSize: " + this.renderSize);
// remove data of the previous composition :
this.vectorialDraw.clear();
final int borderSize = (int) this.propertyBorderWidth.size();
final int paddingCompensateBorder = Math.round(borderSize * 0.5f);
if (borderSize > 0.0f) {
this.vectorialDraw.setRectangleBorderAsSource(this.renderSize.x(), this.renderSize.y(), this.propertyColor,
borderSize, (int) this.propertyBorderRadius.size(), this.propertyBorderColor);
} else {
this.vectorialDraw.setRectangleAsSource(this.renderSize.x(), this.renderSize.y(), this.propertyColor);
}
this.vectorialDraw.setPos(this.renderOrigin);
// For events:
this.startPosition = this.renderOrigin;
this.endPosition = this.renderOrigin.add(this.renderSize);
this.vectorialDraw.print(this.renderSize);
this.vectorialDraw.flush();
}
@Override
protected void onDraw() {
if (this.vectorialDraw != null) {
this.vectorialDraw.draw(true);
}
super.onDraw();
}
}

View File

@ -11,7 +11,6 @@ import org.atriasoft.etk.Color;
import org.atriasoft.etk.Dimension1f;
import org.atriasoft.etk.Dimension2f;
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2b;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.ewol.Gravity;
@ -129,7 +128,7 @@ public class Button extends Box {
@Override
public boolean onEventInput(final EventInput event) {
final Vector2f relPos = relativePosition(event.pos());
//LOGGER.warn("Event on Input ... " + event + " relPos = " + relPos);
//LOGGER.warn("Event on Input ... event={} relPos={}", event, relPos);
final boolean over = isInside(relPos);
//filter if outside the element...
if (event.status() == KeyStatus.leave) {

View File

@ -15,7 +15,6 @@ import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.FMath;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.ewol.Padding;
import org.atriasoft.ewol.compositing.CompositingSVG;
import org.atriasoft.ewol.compositing.CompositingText;
@ -43,7 +42,7 @@ import org.slf4j.LoggerFactory;
*/
public class Entry extends Widget {
private static final Logger LOGGER = LoggerFactory.getLogger(Entry.class);
/**
* Periodic call to update graphic display
* @param _event Time generic event
@ -55,7 +54,7 @@ public class Entry extends Widget {
// }
self.markToRedraw();
}
/// color property of the text foreground
private int colorIdTextFg;
/// Cursor must be display only when the widget has the focus
@ -70,7 +69,7 @@ public class Entry extends Widget {
private int displayCursorPositionPixel = 0;
/// text display this.text
private final CompositingText text = new CompositingText();
protected CompositingSVG compositing = new CompositingSVG();
protected CompositingSVG vectorialDraw = new CompositingSVG();
/// text position can have change
private boolean needUpdateTextPos = true;
/// Periodic call handle to remove it when needed
@ -78,16 +77,16 @@ public class Entry extends Widget {
private Uri propertyConfig = new Uri("THEME", "shape/Entry.json", "ewol");
private int propertyMaxCharacter = Integer.MAX_VALUE; //!< number max of Character in the list
private boolean propertyPassword = false; //!< Disable display of the content of the entry
/// regular expression value
private String propertyRegex = ".*";
/// Text to display when nothing in in the entry (decorated text...)
private String propertyTextWhenNothing = null;
private String propertyValue = "Test Text..."; //!< string that must be displayed
private Pattern regex = null; //!< regular expression to check content
//.create()
@AknotSignal
@AknotName(value = "click")
@ -97,16 +96,16 @@ public class Entry extends Widget {
@AknotName(value = "enter")
@AknotDescription("The cursor enter inside the button")
public Signal<String> signalEnter = new Signal<>(); //!< Enter key is pressed
@AknotSignal
@AknotName(value = "modify")
@AknotDescription("Entry box value change")
public Signal<String> signalModify = new Signal<>(); //!< data change
// element over:
Vector2f overPositionStart = Vector2f.ZERO;
Vector2f overPositionStop = Vector2f.ZERO;
/**
* Constructor
* @param _newData The USting that might be set in the Entry box (no event generation!!)
@ -114,7 +113,7 @@ public class Entry extends Widget {
public Entry() {
this.propertyCanFocus = true;
//onChangePropertyShaper();
this.regex = Pattern.compile(this.propertyRegex);
if (this.regex == null) {
LOGGER.error("can not parse regex for : " + this.propertyRegex);
@ -128,7 +127,7 @@ public class Entry extends Widget {
shortCutAdd("ctrl+shift+a", "select:none");
//TODO this.signalShortcut.connect(this, Entry::onCallbackShortCut);
}
@Override
public void calculateMinMaxSize() {
// call main class
@ -136,7 +135,7 @@ public class Entry extends Widget {
// get generic padding
final Padding padding = Padding.ZERO;
final int minHeight = (int) this.text.getHeight();//calculateSize('A').y();
Vector2f minimumSizeBase = new Vector2f(20, minHeight);
// add padding :
minimumSizeBase = minimumSizeBase.add(padding.x(), padding.y());
@ -145,7 +144,7 @@ public class Entry extends Widget {
checkMinSize();
//LOGGER.trace("min size = " + this.minSize);
}
protected void changeStatusIn(final GuiShapeMode newStatusId) {
// if (this.shape.changeStatusIn(newStatusId)) {
// if (!this.periodicConnectionHanble.isConnected()) {
@ -156,7 +155,7 @@ public class Entry extends Widget {
// markToRedraw();
// }
}
/**
* Copy the selected data on the specify clipboard
* @param clipboardID Selected clipboard
@ -176,48 +175,48 @@ public class Entry extends Widget {
final String tmpData = this.propertyValue.substring(pos1, pos2);
ClipBoard.set(clipboardID, tmpData);
}
public Uri getPropertyConfig() {
return this.propertyConfig;
}
public int getPropertyMaxCharacter() {
return this.propertyMaxCharacter;
}
public String getPropertyRegex() {
return this.propertyRegex;
}
public String getPropertyTextWhenNothing() {
return this.propertyTextWhenNothing;
}
public String getPropertyValue() {
return this.propertyValue;
}
public boolean isPropertyPassword() {
return this.propertyPassword;
}
/**
* informe the system thet the text change and the start position change
*/
protected void markToUpdateTextPosition() {
this.needUpdateTextPos = true;
}
private void onCallbackCopy() {
copySelectionToClipBoard(ClipboardList.CLIPBOARD_STD);
}
private void onCallbackCut() {
copySelectionToClipBoard(ClipboardList.CLIPBOARD_STD);
removeSelected();
this.signalModify.emit(this.propertyValue);
}
private void onCallbackEntryClean() {
this.propertyValue = "";
this.displayStartPosition = 0;
@ -225,11 +224,11 @@ public class Entry extends Widget {
this.displayCursorPosSelection = this.displayCursorPos;
markToRedraw();
}
private void onCallbackPaste() {
ClipBoard.request(ClipboardList.CLIPBOARD_STD);
}
private void onCallbackSelect(final boolean all) {
if (all) {
this.displayCursorPosSelection = 0;
@ -239,7 +238,7 @@ public class Entry extends Widget {
}
markToRedraw();
}
private void onCallbackShortCut(final String value) {
if (value.equals("clean")) {
onCallbackEntryClean();
@ -258,15 +257,15 @@ public class Entry extends Widget {
LOGGER.warn("Unknow event from ShortCut : " + value);
}
}
protected void onChangePropertyMaxCharacter() {
// TODO : check number of char in the data
}
protected void onChangePropertyPassword() {
markToRedraw();
}
protected void onChangePropertyRegex() {
this.regex = Pattern.compile(this.propertyRegex);
if (this.regex != null) {
@ -274,11 +273,11 @@ public class Entry extends Widget {
}
markToRedraw();
}
protected void onChangePropertyTextWhenNothing() {
markToRedraw();
}
protected void onChangePropertyValue() {
String newData = this.propertyValue;
if ((long) newData.length() > this.propertyMaxCharacter) {
@ -294,15 +293,15 @@ public class Entry extends Widget {
}
markToRedraw();
}
@Override
protected void onDraw() {
if (this.compositing != null) {
this.compositing.draw(true);
if (this.vectorialDraw != null) {
this.vectorialDraw.draw(true);
}
this.text.draw();
}
@Override
public void onEventClipboard(final ClipboardList clipboardID) {
// remove curent selected data ...
@ -326,7 +325,7 @@ public class Entry extends Widget {
}
this.signalModify.emit(this.propertyValue);
}
@Override
public boolean onEventEntry(final EventEntry event) {
LOGGER.trace("Event on Entry ... " + event);
@ -402,7 +401,7 @@ public class Entry extends Widget {
}
return false;
}
@Override
public boolean onEventInput(final EventInput event) {
final Vector2f absolutePosition = event.pos();
@ -505,7 +504,7 @@ public class Entry extends Widget {
}
return false;
}
@Override
protected void onGetFocus() {
this.displayCursor = true;
@ -513,7 +512,7 @@ public class Entry extends Widget {
showKeyboard();
markToRedraw();
}
@Override
protected void onLostFocus() {
this.displayCursor = false;
@ -521,14 +520,14 @@ public class Entry extends Widget {
hideKeyboard();
markToRedraw();
}
@Override
public void onRegenerateDisplay() {
if (!needRedraw()) {
//return;
return;
}
//LOGGER.trace("Regenerate Display ==> is needed: '" + this.propertyValue + "'");
this.compositing.clear();
this.vectorialDraw.clear();
this.text.clear();
if (this.colorIdTextFg >= 0) {
//this.text.setDefaultColorFg(this.shape.getColor(this.colorIdTextFg));
@ -538,7 +537,7 @@ public class Entry extends Widget {
}
updateTextPosition();
final Padding padding = Padding.ZERO;
Vector2f tmpSizeShaper = this.minSize;
Vector2f delta = this.propertyGravity.gravityGenerateDelta(this.size.less(this.minSize));
if (this.propertyFill.x()) {
@ -555,7 +554,7 @@ public class Entry extends Widget {
Vector2f tmpOriginText = tmpOriginShaper.add(padding.bottom(), padding.left()); //this.size.less(tmpSizeText).multiply(0.5f);
//Vector2f tmpOriginText = new Vector2f(0, this.text.getSize(), 0);
// sometimes, the user define an height bigger than the real size needed == > in this case we need to center the text in the shaper ...
final int minHeight = (int) this.text.getHeight();
if (tmpSizeText.y() > minHeight) {
tmpOriginText = tmpOriginText.add(0, (tmpSizeText.y() - minHeight) * 0.5f);
@ -565,7 +564,7 @@ public class Entry extends Widget {
tmpOriginShaper = Vector2f.clipInt(tmpOriginShaper);
tmpSizeText = Vector2f.clipInt(tmpSizeText);
tmpOriginText = Vector2f.clipInt(tmpOriginText);
this.text.clear();
//this.text.setSize((int) tmpSizeText.x(), (int) tmpSizeText.y());
this.text.setClippingWidth(tmpOriginText, tmpSizeText);
@ -579,7 +578,7 @@ public class Entry extends Widget {
if (this.propertyPassword) {
Arrays.fill(valueToDisplay, '*');
}
//final Vector2f plop = new Vector2f(tmpOriginText.x() + this.displayStartPosition, tmpOriginText.y());
if (valueToDisplay.length != 0) {
this.text.print(new String(valueToDisplay));
@ -590,7 +589,7 @@ public class Entry extends Widget {
this.overPositionStart = tmpOriginShaper;
this.overPositionStop = tmpOriginShaper.add(tmpSizeShaper);
//this.shape.setShape(tmpOriginShaper, tmpSizeShaper, tmpOriginText, tmpSizeText);
this.compositing.setSource("""
this.vectorialDraw.setSource("""
<svg width="%d" height="%d">
<rect
x="0.5"
@ -605,13 +604,13 @@ public class Entry extends Widget {
(int) tmpSizeShaper.x(), (int) tmpSizeShaper.y(), //
tmpSizeShaper.x() - 0.5, tmpSizeShaper.y() - 0.5//
), new Vector2i((int) tmpSizeShaper.x(), (int) tmpSizeShaper.y()));
this.compositing.setPos(tmpOriginShaper);
this.compositing.print(new Vector2f(tmpSizeShaper.x(), tmpSizeShaper.y()));
this.vectorialDraw.setPos(tmpOriginShaper);
this.vectorialDraw.print(new Vector2f(tmpSizeShaper.x(), tmpSizeShaper.y()));
this.text.flush();
this.compositing.flush();
this.vectorialDraw.flush();
}
/**
* remove the selected area
* @note This request a regeneration of the display
@ -639,7 +638,7 @@ public class Entry extends Widget {
this.propertyValue = tmp.toString();
markToRedraw();
}
/**
* internal check the value with RegExp checking
* @param newData The new string to display
@ -666,7 +665,7 @@ public class Entry extends Widget {
this.propertyValue = newData;
markToRedraw();
}
@AknotManaged
@AknotAttribute
@AknotName(value = "config")
@ -678,7 +677,7 @@ public class Entry extends Widget {
this.propertyConfig = propertyConfig;
//onChangePropertyShaper();
}
@AknotManaged
@AknotAttribute
@AknotName(value = "max")
@ -690,7 +689,7 @@ public class Entry extends Widget {
this.propertyMaxCharacter = propertyMaxCharacter;
onChangePropertyMaxCharacter();
}
@AknotManaged
@AknotAttribute
@AknotName(value = "password")
@ -702,7 +701,7 @@ public class Entry extends Widget {
this.propertyPassword = propertyPassword;
onChangePropertyPassword();
}
@AknotManaged
@AknotAttribute
@AknotName(value = "regex")
@ -714,7 +713,7 @@ public class Entry extends Widget {
this.propertyRegex = propertyRegex;
onChangePropertyRegex();
}
@AknotManaged
@AknotAttribute
@AknotName(value = "empty-text")
@ -726,7 +725,7 @@ public class Entry extends Widget {
this.propertyTextWhenNothing = propertyTextWhenNothing;
onChangePropertyTextWhenNothing();
}
@AknotManaged
@AknotAttribute
@AknotName(value = "value")
@ -738,7 +737,7 @@ public class Entry extends Widget {
this.propertyValue = propertyValue;
onChangePropertyValue();
}
/**
* change the cursor position with the curent position requested on the display
* @param pos Absolute position of the event
@ -747,13 +746,13 @@ public class Entry extends Widget {
protected void updateCursorPosition(final Vector2f pos) {
updateCursorPosition(pos, false);
}
protected void updateCursorPosition(final Vector2f pos, final boolean selection/*=false*/) {
final Padding padding = Padding.ZERO;
final Vector2f relPos = relativePosition(pos).less(this.overPositionStart);
// reject when outside ...
// try to find the new cursor position :
if (this.displayStartPosition > this.propertyValue.length()) {
this.displayStartPosition = this.propertyValue.length();
@ -791,7 +790,7 @@ public class Entry extends Widget {
}
markToUpdateTextPosition();
}
/**
* update the display position start == > depending of the position of the Cursor and the size of the Data inside
* @change this.displayStartPosition < == updated
@ -801,7 +800,7 @@ public class Entry extends Widget {
return;
}
final Padding padding = Padding.ZERO;
int tmpSizeX = (int) this.minSize.x();
if (this.propertyFill.x()) {
tmpSizeX = (int) this.size.x();
@ -831,5 +830,5 @@ public class Entry extends Widget {
//this.displayStartPosition = -totalWidth + tmpUserSize;
}
}
}

View File

@ -13,8 +13,8 @@ import org.atriasoft.aknot.annotation.AknotSignal;
import org.atriasoft.esignal.SignalEmpty;
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.FMath;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etranslate.ETranslate;
import org.atriasoft.ewol.compositing.AlignMode;
import org.atriasoft.ewol.compositing.CompositingText;
@ -30,7 +30,7 @@ public class LabelOnSVG extends Widget {
protected int colorDefaultFgText = -1; //!< Default color of the text
protected ResourceColorFile colorProperty; //!< theme color property
protected boolean propertyAutoTranslate = true; //!< if at true the data is translate automaticaly translate.
protected int propertyFontSize = 0; //!< default size of the font.
protected String propertyValue = ""; //!< decorated text to display.
@AknotSignal
@ -39,7 +39,7 @@ public class LabelOnSVG extends Widget {
public SignalEmpty signalPressed = new SignalEmpty();
protected CompositingText text = new CompositingText(); //!< Compositing text element.
protected String value = "";
public LabelOnSVG() {
this.colorProperty = ResourceColorFile.create(new Uri("THEME", "/color/Label.json", "ewol"));
if (this.colorProperty != null) {
@ -49,7 +49,7 @@ public class LabelOnSVG extends Widget {
setMouseLimit(1);
setPropertyCanFocus(false);
}
/**
* Constructor
* @param newLabel The displayed decorated text.
@ -64,7 +64,7 @@ public class LabelOnSVG extends Widget {
setPropertyCanFocus(false);
setPropertyValue(newLabel);
}
@Override
public void calculateMinMaxSize() {
final Vector2f tmpMax = this.propertyMaxSize.getPixel();
@ -76,30 +76,30 @@ public class LabelOnSVG extends Widget {
}
final Vector2f minSize = this.text.calculateSizeDecorated(this.value);
LOGGER.debug("[" + getId() + "] {" + getClass().getCanonicalName() + "} minSize : " + minSize);
this.minSize = new Vector2f(FMath.avg(tmpMin.x(), 4 + minSize.x(), tmpMax.x()),
FMath.avg(tmpMin.y(), 4 + minSize.y(), tmpMax.y()));
LOGGER.trace("[" + getId() + "] {" + getClass().getCanonicalName() + "} Result min size : " + tmpMin + " < "
+ this.minSize + " < " + tmpMax);
}
public int getPropertyFontSize() {
return this.propertyFontSize;
}
public String getPropertyValue() {
return this.propertyValue;
}
public boolean isPropertyAutoTranslate() {
return this.propertyAutoTranslate;
}
@Override
protected void onDraw() {
this.text.draw();
}
@Override
public boolean onEventInput(final EventInput event) {
//LOGGER.debug("Event on Label ...");
@ -112,32 +112,32 @@ public class LabelOnSVG extends Widget {
}
return false;
}
@Override
public void onRegenerateDisplay() {
if (!needRedraw()) {
//return;
return;
}
this.text.clear();
final int paddingSize = 2;
final Vector2f tmpMax = this.propertyMaxSize.getPixel();
// to know the size of one line :
final Vector2f minSize = this.text.calculateSize('A');
//minSize.setX(etk::max(minSize.x(), this.minSize.x()));
//minSize.setY(etk::max(minSize.y(), this.minSize.y()));
if (tmpMax.x() <= 999999) {
this.text.setTextAlignment(0, tmpMax.x() - 2 * paddingSize, AlignMode.LEFT);
}
final Vector2f currentTextSize = this.text.calculateSizeDecorated(this.value);
Vector2i localSize = new Vector2i((int) this.minSize.x(), (int) this.minSize.y());
// no change for the text origin :
Vector2f tmpTextOrigin = new Vector2f((this.size.x() - this.minSize.x()) / 2.0f,
(this.size.y() - this.minSize.y()) / 2.0f);
if (this.propertyFill.x()) {
localSize = localSize.withX((int) this.size.x());
tmpTextOrigin = tmpTextOrigin.withX(0);
@ -148,14 +148,14 @@ public class LabelOnSVG extends Widget {
}
tmpTextOrigin = tmpTextOrigin.add(paddingSize, paddingSize);
localSize = localSize.less(2 * paddingSize, 2 * paddingSize);
tmpTextOrigin = tmpTextOrigin.withY(tmpTextOrigin.y() + (this.minSize.y() - 2 * paddingSize) - minSize.y());
final Vector2f textPos = new Vector2f(tmpTextOrigin.x(), tmpTextOrigin.y());
final Vector2f drawClippingPos = new Vector2f(paddingSize, paddingSize);
final Vector2f drawClippingSize = new Vector2f((this.size.x() - paddingSize), (this.size.y() - paddingSize));
// clean the element
this.text.reset();
if (this.propertyFontSize != 0) {
@ -170,10 +170,10 @@ public class LabelOnSVG extends Widget {
this.text.setTextAlignment(tmpTextOrigin.x(), tmpTextOrigin.x() + localSize.x(), AlignMode.LEFT);
this.text.setClipping(drawClippingPos, drawClippingSize);
this.text.printDecorated(this.value);
this.text.flush();
}
@AknotManaged
@AknotAttribute
@AknotName("auto-translate")
@ -191,7 +191,7 @@ public class LabelOnSVG extends Widget {
markToRedraw();
requestUpdateSize();
}
@AknotManaged
@AknotAttribute
@AknotName("font-size")
@ -204,7 +204,7 @@ public class LabelOnSVG extends Widget {
markToRedraw();
requestUpdateSize();
}
@AknotManaged
@AknotAttribute
@AknotName("value")
@ -222,5 +222,5 @@ public class LabelOnSVG extends Widget {
requestUpdateSize();
this.propertyValue = propertyValue;
}
}

View File

@ -12,27 +12,28 @@ import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.ewol.compositing.CompositingDrawing;
import org.atriasoft.ewol.compositing.CompositingGC;
class ProgressBar extends Widget {
private static final int DOT_RADIUS = 6;
private final CompositingDrawing draw = new CompositingDrawing(); // basic drawing element
private final CompositingDrawing vectorialDraw = new CompositingGC(); // basic drawing element
protected Color propertyTextColorBgOff = Color.NONE;
protected Color propertyTextColorBgOn = Color.GREEN;
protected Color propertyTextColorFg = Color.BLACK;
protected float propertyValue = 0;
public ProgressBar() {
setPropertyCanFocus(true);
}
@Override
public void calculateMinMaxSize() {
final Vector2f tmpMin = this.propertyMinSize.getPixel();
this.minSize = new Vector2f(Math.max(tmpMin.x(), 40.0f), Math.max(tmpMin.y(), ProgressBar.DOT_RADIUS * 2.0f));
markToRedraw();
}
@AknotManaged
@AknotAttribute
@AknotName(value = "color-off")
@ -40,7 +41,7 @@ class ProgressBar extends Widget {
public Color getPropertyTextColorBgOff() {
return this.propertyTextColorBgOff;
}
@AknotManaged
@AknotAttribute
@AknotName(value = "color-on")
@ -48,7 +49,7 @@ class ProgressBar extends Widget {
public Color getPropertyTextColorBgOn() {
return this.propertyTextColorBgOn;
}
@AknotManaged
@AknotAttribute
@AknotName(value = "color-bg")
@ -56,7 +57,7 @@ class ProgressBar extends Widget {
public Color getPropertyTextColorFg() {
return this.propertyTextColorFg;
}
@AknotManaged
@AknotAttribute
@AknotName(value = "value")
@ -64,38 +65,38 @@ class ProgressBar extends Widget {
public float getPropertyValue() {
return this.propertyValue;
}
@Override
protected void onDraw() {
this.draw.draw();
this.vectorialDraw.draw();
}
@Override
public void onRegenerateDisplay() {
if (!needRedraw()) {
return;
}
// clean the object list ...
this.draw.clear();
this.draw.setColor(this.propertyTextColorFg);
this.vectorialDraw.clear();
this.vectorialDraw.setColor(this.propertyTextColorFg);
final int tmpSizeX = (int) (this.size.x() - 10);
final int tmpSizeY = (int) (this.size.y() - 10);
final int tmpOriginX = 5;
final int tmpOriginY = 5;
this.draw.setColor(this.propertyTextColorBgOn);
this.draw.setPos(new Vector2f(tmpOriginX, tmpOriginY));
this.draw.rectangleWidth(new Vector2f(tmpSizeX * this.propertyValue, tmpSizeY));
this.draw.setColor(this.propertyTextColorBgOff);
this.draw.setPos(new Vector2f(tmpOriginX + tmpSizeX * this.propertyValue, tmpOriginY));
this.draw.rectangleWidth(new Vector2f(tmpSizeX * (1.0f - this.propertyValue), tmpSizeY));
this.vectorialDraw.setColor(this.propertyTextColorBgOn);
this.vectorialDraw.setPos(new Vector2f(tmpOriginX, tmpOriginY));
this.vectorialDraw.rectangleWidth(new Vector2f(tmpSizeX * this.propertyValue, tmpSizeY));
this.vectorialDraw.setColor(this.propertyTextColorBgOff);
this.vectorialDraw.setPos(new Vector2f(tmpOriginX + tmpSizeX * this.propertyValue, tmpOriginY));
this.vectorialDraw.rectangleWidth(new Vector2f(tmpSizeX * (1.0f - this.propertyValue), tmpSizeY));
// TODO : Create a better progress Bar ...
//this.draw.setColor(propertyTextColorFg);
//this.draw.rectangleBorder( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY, 1);
}
public void setPropertyTextColorBgOff(final Color propertyTextColorBgOff) {
if (propertyTextColorBgOff.equals(this.propertyTextColorBgOff)) {
return;
@ -103,7 +104,7 @@ class ProgressBar extends Widget {
this.propertyTextColorBgOff = propertyTextColorBgOff;
markToRedraw();
}
public void setPropertyTextColorBgOn(final Color propertyTextColorBgOn) {
if (propertyTextColorBgOn.equals(this.propertyTextColorBgOn)) {
return;
@ -111,7 +112,7 @@ class ProgressBar extends Widget {
this.propertyTextColorBgOn = propertyTextColorBgOn;
markToRedraw();
}
public void setPropertyTextColorFg(final Color propertyTextColorFg) {
if (propertyTextColorFg.equals(this.propertyTextColorFg)) {
return;
@ -119,7 +120,7 @@ class ProgressBar extends Widget {
this.propertyTextColorFg = propertyTextColorFg;
markToRedraw();
}
public void setPropertyValue(final float propertyValue) {
if (propertyValue == this.propertyValue) {
return;

View File

@ -7,13 +7,11 @@ 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.Vector2f;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.ewol.Padding;
import org.atriasoft.ewol.compositing.CompositingDrawing;
import org.atriasoft.ewol.compositing.CompositingGC;
import org.atriasoft.ewol.compositing.CompositingSVG;
import org.atriasoft.ewol.event.EventInput;
import org.atriasoft.gale.key.KeyStatus;
@ -32,8 +30,6 @@ import org.slf4j.LoggerFactory;
public class Slider extends Widget {
private static final Logger LOGGER = LoggerFactory.getLogger(Slider.class);
private Uri propertyConfig = new Uri("THEME", "shape/Slider.json", "ewol");
private Float propertyValue = 0.0f; //!< string that must be displayed
protected CompositingSVG compositing = new CompositingSVG();
@AknotSignal
@ -59,11 +55,10 @@ public class Slider extends Widget {
private final Color textColorBg = Color.BLACK.withA(0x3F); //!< Background color
CompositingDrawing draw = new CompositingDrawing(); //!< drawing tool.
CompositingGC vectorialDraw = new CompositingGC(); //!< drawing tool.
public Slider() {
this.propertyCanFocus = true;
onChangePropertyShaper();
markToRedraw();
// Limit event at 1:
setMouseLimit(1);
@ -92,14 +87,6 @@ public class Slider extends Widget {
&& 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")
@ -107,6 +94,15 @@ public class Slider extends Widget {
public Float getPropertyMaximum() {
return this.propertyMaximum;
}
public void setPropertyMaximum(final Float propertyMaximum) {
if (this.propertyMaximum == propertyMaximum) {
return;
}
this.propertyMaximum = propertyMaximum;
updateValue(this.propertyValue);
this.signalValue.emit(this.propertyValue);
}
@AknotManaged
@AknotAttribute
@ -116,6 +112,15 @@ public class Slider extends Widget {
return this.propertyMinimum;
}
public void setPropertyMinimum(final Float propertyMinimum) {
if (this.propertyMinimum == propertyMinimum) {
return;
}
this.propertyMinimum = propertyMinimum;
updateValue(this.propertyValue);
this.signalValue.emit(this.propertyValue);
}
@AknotManaged
@AknotAttribute
@AknotName("step")
@ -123,7 +128,16 @@ public class Slider extends Widget {
public Float getPropertyStep() {
return this.propertyStep;
}
public void setPropertyStep(final Float propertyStep) {
if (this.propertyStep == propertyStep) {
return;
}
this.propertyStep = propertyStep;
updateValue(this.propertyValue);
this.signalValue.emit(this.propertyValue);
}
@AknotManaged
@AknotAttribute
@AknotName("value")
@ -131,13 +145,25 @@ public class Slider extends Widget {
public Float getPropertyValue() {
return 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 onChangePropertyShaper() {
// if (this.shape == null) {
// this.shape = new GuiShape(this.propertyConfig);
// } else {
// this.shape.setSource(this.propertyConfig);
// }
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();
}
@Override
@ -208,7 +234,7 @@ public class Slider extends Widget {
@Override
public void onRegenerateDisplay() {
if (!needRedraw()) {
//return;
return;
}
//LOGGER.trace("Regenerate Display ==> is needed: '" + this.propertyValue + "'");
this.compositing.clear();
@ -281,70 +307,15 @@ public class Slider extends Widget {
this.overCursorPositionStop = tmpOriginShaper.add(tmpSizeShaper);
//this.shape.setShape(1, tmpOriginShaper, tmpSizeShaper, tmpOriginInside, tmpSizeInside);
}
LOGGER.error("REQUEST display an immage with size={}x{}", (int) this.overPositionSize.x(),
(int) this.overPositionSize.y());
this.compositing.setRectangleAsSource((int) this.overPositionSize.x(), (int) this.overPositionSize.y(),
Color.GREEN);
// TODO: Refaire le design de cet affichage...
this.compositing.setPos(this.overPositionStart);
this.compositing.print(new Vector2f(this.overPositionSize.x(), this.overPositionSize.y()));
this.compositing.flush();
//this.gc.flush();
this.compositing.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

@ -14,55 +14,56 @@ import org.atriasoft.aknot.annotation.AknotName;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.ewol.compositing.CompositingDrawing;
import org.atriasoft.ewol.compositing.CompositingGC;
public class Spacer extends Widget {
private final CompositingDrawing draw = new CompositingDrawing(); //!< Compositing drawing element
private final CompositingDrawing vectorialDraw = new CompositingGC(); //!< Compositing drawing element
@AknotManaged
@AknotAttribute
@AknotName("color")
@AknotDescription("background of the spacer")
protected Color propertyColor = Color.NONE; //!< Background color
/**
* Main ructer
*/
public Spacer() {
}
public Color getPropertyColor() {
return this.propertyColor;
}
@Override
public Widget getWidgetAtPos(final Vector2f pos) {
return null;
}
@Override
public void onDraw() {
this.draw.draw();
this.vectorialDraw.draw();
}
@Override
public void onRegenerateDisplay() {
if (!needRedraw()) {
return;
}
this.draw.clear();
this.vectorialDraw.clear();
if (this.propertyColor.a() == 0) {
return;
}
this.draw.setColor(this.propertyColor);
this.draw.setPos(Vector2f.ZERO);
this.draw.rectangleWidth(new Vector2f(this.size.x(), this.size.y()));
this.vectorialDraw.setColor(this.propertyColor);
this.vectorialDraw.setPos(Vector2f.ZERO);
this.vectorialDraw.rectangleWidth(new Vector2f(this.size.x(), this.size.y()));
//this.draw.setPos(new Vector2f(this.size.x() * 0.1f, this.size.y() * 0.1f, 0));
//this.draw.rectangleWidth(new Vector2f(this.size.x() * 0.8f, this.size.y() * 0.8f, 0));
this.draw.flush();
this.vectorialDraw.flush();
}
public void setPropertyColor(final Color propertyColor) {
if (propertyColor.equals(this.propertyColor)) {
return;

View File

@ -11,9 +11,7 @@ import org.atriasoft.esignal.SignalEmpty;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.Dimension1f;
import org.atriasoft.etk.Dimension2f;
import org.atriasoft.etk.Dimension2f;
import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2b;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
@ -47,19 +45,19 @@ public Uri> propertyShape; //!< shape of the widget
public class Tick extends Box {
private static final Logger LOGGER = LoggerFactory.getLogger(Tick.class);
protected CompositingSVG compositingTick = new CompositingSVG();
/// 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();
private final Uri propertyConfig = new Uri("THEME", "shape/Tick.json", "ewol");
private final Uri uriCheckGreen = new Uri("THEME", "CheckBoxCrossRed.svg", "ewol");
private Boolean propertyValue = false; //!< string that must be displayed
private Boolean propertyValue = false; //!< string that must be displayed
@AknotSignal
@AknotName("down")
@AknotDescription("Tick is Down")
@ -79,9 +77,9 @@ public class Tick extends Box {
// element over:
Vector2f overPositionStart = Vector2f.ZERO;
Vector2f overPositionStop = Vector2f.ZERO;
private boolean isDown;
/**
* Constuctor
*/
@ -99,9 +97,9 @@ public class Tick extends Box {
setPropertyColor(Color.WHITE);
setPropertyPadding(new Dimension2f(new Vector2f(3, 3)));
setPropertyMargin(new Dimension2f(new Vector2f(0, 0)));
}
@Override
public void calculateMinMaxSize() {
// call main class
@ -109,7 +107,7 @@ public class Tick extends Box {
// get generic padding
final Padding padding = Padding.ZERO;
final Vector2i minHeight = Vector2i.VALUE_16;
Vector2f minimumSizeBase = new Vector2f(minHeight.x(), minHeight.y());
// add padding :
minimumSizeBase = minimumSizeBase.add(padding.x(), padding.y());
@ -118,7 +116,7 @@ public class Tick extends Box {
checkMinSize();
LOGGER.error("min size = " + this.minSize);
}
protected void changeStatusIn(final GuiShapeMode newStatusId) {
// if (this.shape.changeStatusIn(newStatusId)) {
// if (!this.periodicConnectionHanble.isConnected()) {
@ -129,12 +127,12 @@ public class Tick extends Box {
// markToRedraw();
// }
}
private boolean checkIfOver(final Vector2f 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("value")
@ -142,16 +140,16 @@ public class Tick extends Box {
public Boolean getPropertyValue() {
return this.propertyValue;
}
protected void onChangePropertyTextWhenNothing() {
markToRedraw();
}
protected void onChangePropertyValue() {
//Boolean newData = this.propertyValue;
markToRedraw();
}
@Override
protected void onDraw() {
super.onDraw();
@ -164,7 +162,7 @@ public class Tick extends Box {
// this.shape.draw(true, this.propertyValue ? 0 : 1);
// }
}
@Override
public boolean onEventInput(final EventInput event) {
final Vector2f positionAbsolute = new Vector2f(event.pos().x(), event.pos().y());
@ -226,20 +224,19 @@ public class Tick extends Box {
}
return false;
}
@Override
public void onRegenerateDisplay() {
super.onRegenerateDisplay();
if (!needRedraw()) {
//return;
}
this.compositingTick.setSource(Uri.getAllDataString(this.uriCheckGreen), this.renderSize.less(4));
this.compositingTick.setSource(Uri.getAllDataString(this.uriCheckGreen), this.startPosition.less(4));
this.compositingTick.setPos(this.propertyMargin.size().add(2));
this.compositingTick.print(this.renderSize.less(4));
this.compositingTick.print(this.startPosition.less(4).toVector2f());
this.compositingTick.flush();
}
/**
* internal check the value with RegExp checking
* @param newData The new string to display
@ -248,7 +245,7 @@ public class Tick extends Box {
this.propertyValue = newData;
markToRedraw();
}
public void setPropertyValue(final Boolean propertyValue) {
if (this.propertyValue.equals(propertyValue)) {
return;
@ -257,5 +254,5 @@ public class Tick extends Box {
this.signalValue.emit(this.propertyValue);
onChangePropertyValue();
}
}

View File

@ -14,10 +14,9 @@ import java.util.Map.Entry;
import org.atriasoft.etk.Color;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.ewol.compositing.Compositing;
import org.atriasoft.ewol.compositing.CompositingDrawing;
import org.atriasoft.ewol.compositing.CompositingGC;
import org.atriasoft.ewol.compositing.CompositingText;
import org.atriasoft.ewol.event.EventInput;
import org.atriasoft.ewol.widget.model.ListRole;
@ -28,37 +27,37 @@ class WidgetList extends WidgetScrolled {
private static final Logger LOGGER = LoggerFactory.getLogger(WidgetList.class);
// drawing capabilities ....
protected List<Compositing> listOObject = new ArrayList<>(); //!< generic element to display...
protected List<Integer> listSizeX = new ArrayList<>(); //!< size of every colons
protected List<Integer> listSizeY = new ArrayList<>(); //!< size of every rows
protected Map<String, Compositing> compositingElements = new HashMap<>();
// list properties ...
protected int paddingSizeX = 0;
protected int paddingSizeY = 0;
protected int displayStartRaw = 0; //!< Current starting displayed raw
protected int displayCurrentNbLine = 0; //!< Number of line in the display
protected int nbVisibleRaw = 0; // set the number of visible raw (calculate don display)
// function call to display the list :
public WidgetList() {
this.paddingSizeX = 2;
this.paddingSizeY = 2;
this.nbVisibleRaw = 0;
this.propertyCanFocus = true;
this.limitScrolling = new Vector2f(1.0f, 0.5f);
addComposeElemnent("drawing", new CompositingDrawing());
addComposeElemnent("drawing", new CompositingGC());
addComposeElemnent("text", new CompositingText());
}
protected void addComposeElemnent(final String name, final Compositing element) {
this.compositingElements.put(name, element);
//this.listOObject.add(element);
}
/**
* Calculate an element size to estimate the render size.
* @note Does not generate the with the same size.
@ -75,7 +74,7 @@ class WidgetList extends WidgetScrolled {
}
return Vector2f.ZERO;
}
@Override
public void calculateMinMaxSize() {
/*int fontId = getDefaultFontId();
@ -86,18 +85,18 @@ class WidgetList extends WidgetScrolled {
*/
this.minSize = new Vector2f(200, 150);
}
protected void clearComposeElemnent() {
for (final Entry<String, Compositing> it : this.compositingElements.entrySet()) {
//it.setValue(null);
it.getValue().clear();
}
}
public void clearOObjectList() {
//this.listOObject.clear();
}
/**
* Draw the background
*/
@ -109,7 +108,7 @@ class WidgetList extends WidgetScrolled {
BGOObjects.rectangleWidth(new Vector2f(this.size.x(), this.size.y()));
}
}
/**
* Draw an element in the specific size and position.
* @param pos Position of colomn and Raw of the element.
@ -138,7 +137,7 @@ class WidgetList extends WidgetScrolled {
}
}
}
protected void flushElements() {
for (final Entry<String, Compositing> it : this.compositingElements.entrySet()) {
it.getValue().flush();
@ -149,15 +148,15 @@ class WidgetList extends WidgetScrolled {
}
}
}
protected Color getBasicBG() {
return new Color(0xFF, 0xFF, 0xFF, 0xFF);
}
protected Compositing getComposeElemnent(final String name) {
return this.compositingElements.get(name);
}
protected Object getData(final ListRole role, final Vector2i pos) {
switch (role) {
case Text:
@ -174,7 +173,7 @@ class WidgetList extends WidgetScrolled {
}
return null;
}
/**
* Get the number of colomn and row availlable in the list
* @return Number of colomn and row
@ -182,7 +181,7 @@ class WidgetList extends WidgetScrolled {
protected Vector2i getMatrixSize() {
return new Vector2i(1, 0);
}
@Override
protected void onDraw() {
for (final Entry<String, Compositing> it : this.compositingElements.entrySet()) {
@ -195,7 +194,7 @@ class WidgetList extends WidgetScrolled {
}
super.onDraw();
}
@Override
public boolean onEventInput(final EventInput event) {
Vector2f relativePos = relativePosition(new Vector2f(event.pos().x(), event.pos().y()));
@ -247,7 +246,7 @@ class WidgetList extends WidgetScrolled {
}
return isUsed;
}
/**
* set a raw visible in the main display
* @param _id Id of the raw that might be visible.
@ -257,16 +256,16 @@ class WidgetList extends WidgetScrolled {
protected void onGetFocus() {
LOGGER.debug("WidgetList get focus");
}
protected boolean onItemEvent(final EventInput event, final Vector2i pos, final Vector2f mousePosition) {
return false;
}
@Override
protected void onLostFocus() {
LOGGER.debug("WidgetList Lost focus");
}
@Override
public void onRegenerateDisplay() {
if (!needRedraw()) {
@ -394,9 +393,9 @@ class WidgetList extends WidgetScrolled {
// flush all compositing drawing
flushElements();
}
protected void removeComposeElemnent() {
this.compositingElements.clear();
}
}

View File

@ -19,7 +19,6 @@ import org.atriasoft.etk.math.Matrix4f;
import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i;
import org.atriasoft.ewol.DrawProperty;
import org.atriasoft.ewol.compositing.CompositingDrawing;
import org.atriasoft.ewol.context.EwolContext;
import org.atriasoft.ewol.object.EwolObject;
import org.atriasoft.ewol.resource.ResourceColorFile;
@ -51,11 +50,7 @@ public class Windows extends Widget {
protected ResourceColorFile resourceColor = null; //!< theme color property (name of file in @ref propertyColorConfiguration)
protected Widget subWidget;
// internal event at ewol system:
protected CompositingDrawing vectorialDraw = new CompositingDrawing();
protected Windows() {
this.propertyCanFocus = true;
onChangePropertyColor();