[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

@ -98,9 +98,9 @@ public class BasicWindows extends Windows {
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());

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,7 +20,7 @@ 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;
@ -90,6 +90,61 @@ public class CompositingDrawing extends Compositing {
circle(radius, angleStart, 2.0f * FMath.PI);
}
public void circleBorderRaw(
final Vector3f centerPos,
final float radius,
final float thickness,
final float angleStart,
final float angleStop) {
resetCount();
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();
@ -98,29 +153,10 @@ public class CompositingDrawing extends Compositing {
}
angleStop = angleStop - angleStart;
int nbOcurence = (int) radius;
if (nbOcurence < 10) {
nbOcurence = 10;
}
// 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 :
@ -128,32 +164,11 @@ public class CompositingDrawing extends Compositing {
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() {
@ -362,7 +377,7 @@ public class CompositingDrawing extends Compositing {
}
public void rectangle(final Vector2f dest) {
rectangle(new Vector3f(dest.x(), dest.y(), 0));
rectangle(dest.toVector3f());
}
/**
@ -370,21 +385,29 @@ public class CompositingDrawing extends Compositing {
* @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;
@ -417,6 +440,201 @@ public class CompositingDrawing extends Compositing {
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));
}

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,12 +134,15 @@ public class CompositingSVG extends Compositing {
@Override
public void 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();
}
}
/**
* get the current display position (sometime needed in the gui control)
@ -407,9 +418,16 @@ public class CompositingSVG extends Compositing {
// Nothing to do ...
return;
}
this.svgData = null;
clear();
final ImageByte tmp = ToolImage.convertImageByte(data.renderImageFloatRGBA(size));
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;
@ -418,26 +436,100 @@ public class CompositingSVG extends Compositing {
this.resource = new ResourceTexture2();
}
this.resource.set(tmp);
this.svgDoc = data;
}
}
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;
}
@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) {
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));
createSize(new Vector2i(sizeX, sizeY)); // specific for SVG
setPaintFillColor(color);
addRectangle(Vector2f.ZERO, new Vector2f(sizeX, sizeY));
flush();
}
public void setRectangleBorderAsSource(
@ -449,28 +541,13 @@ public class CompositingSVG extends Compositing {
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;
@ -70,7 +69,7 @@ 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
@ -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

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();
renderSize = renderSize.clipInteger();
renderOrigin = renderOrigin.clipInteger();
renderOrigin = renderOrigin.clipInteger();
renderSize = renderSize.clipInteger();
this.startPosition = renderOrigin.toVector2i();
this.endPosition = renderSize.toVector2i();
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.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;
@ -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
@ -297,8 +296,8 @@ public class Entry extends Widget {
@Override
protected void onDraw() {
if (this.compositing != null) {
this.compositing.draw(true);
if (this.vectorialDraw != null) {
this.vectorialDraw.draw(true);
}
this.text.draw();
}
@ -525,10 +524,10 @@ public class Entry extends Widget {
@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));
@ -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,10 +604,10 @@ 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();
}

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;
@ -116,7 +116,7 @@ public class LabelOnSVG extends Widget {
@Override
public void onRegenerateDisplay() {
if (!needRedraw()) {
//return;
return;
}
this.text.clear();
final int paddingSize = 2;

View File

@ -12,10 +12,11 @@ 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;
@ -67,7 +68,7 @@ class ProgressBar extends Widget {
@Override
protected void onDraw() {
this.draw.draw();
this.vectorialDraw.draw();
}
@Override
@ -76,20 +77,20 @@ class ProgressBar extends Widget {
return;
}
// clean the object list ...
this.draw.clear();
this.vectorialDraw.clear();
this.draw.setColor(this.propertyTextColorFg);
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);

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")
@ -108,6 +95,15 @@ public class Slider extends Widget {
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
@AknotName("minimum")
@ -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")
@ -124,6 +129,15 @@ public class Slider extends Widget {
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")
@ -132,12 +146,24 @@ public class Slider extends Widget {
return this.propertyValue;
}
protected void onChangePropertyShaper() {
// if (this.shape == null) {
// this.shape = new GuiShape(this.propertyConfig);
// } else {
// this.shape.setSource(this.propertyConfig);
// }
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();
}
@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,6 +307,8 @@ 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...
@ -288,63 +316,6 @@ public class Slider extends Widget {
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,9 +14,10 @@ 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")
@ -41,7 +42,7 @@ public class Spacer extends Widget {
@Override
public void onDraw() {
this.draw.draw();
this.vectorialDraw.draw();
}
@Override
@ -49,18 +50,18 @@ public class Spacer extends Widget {
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) {

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;
@ -233,10 +231,9 @@ public class Tick extends Box {
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();
}

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;
@ -50,7 +49,7 @@ class WidgetList extends WidgetScrolled {
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());
}

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;
@ -52,10 +51,6 @@ public class Windows extends Widget {
protected Widget subWidget;
// internal event at ewol system:
protected CompositingDrawing vectorialDraw = new CompositingDrawing();
protected Windows() {
this.propertyCanFocus = true;
onChangePropertyColor();