[DEV] rework interface Label and BUTTON

This commit is contained in:
Edouard DUPIN 2022-04-01 00:55:11 +02:00
parent 93d6f70765
commit 2bbe3f3f03
14 changed files with 157 additions and 113 deletions

View File

@ -1,6 +1,6 @@
{ {
"color": [ "color": [
{ name:"background", color:"#0000" }, { name:"background", color:"#0000" },
{ name:"foreground", color:"#FFFF" } { name:"foreground", color:"#000F" }
] ]
} }

View File

@ -116,9 +116,8 @@ public class BasicWindows extends Windows {
simpleSpacer.setPropertyMinSize(new Dimension3f(new Vector3f(30, 30, 30), Distance.PIXEL)); simpleSpacer.setPropertyMinSize(new Dimension3f(new Vector3f(30, 30, 30), Distance.PIXEL));
this.sizerMenuHori.subWidgetAdd(simpleSpacer); this.sizerMenuHori.subWidgetAdd(simpleSpacer);
} }
/*
{ {
this.buttonExpandX = Button.createLabelButton("un-expand X"); this.buttonExpandX = Button.createToggleLabelButton("un-expand X", "expand X");
this.buttonExpandX.setPropertyExpand(Vector3b.FALSE); this.buttonExpandX.setPropertyExpand(Vector3b.FALSE);
this.buttonExpandX.setPropertyFill(Vector3b.FALSE); this.buttonExpandX.setPropertyFill(Vector3b.FALSE);
this.buttonExpandX.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL)); this.buttonExpandX.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL));
@ -126,7 +125,7 @@ public class BasicWindows extends Windows {
this.buttonExpandX.signalClick.connectAuto(this, BasicWindows::eventButtonExpandX); this.buttonExpandX.signalClick.connectAuto(this, BasicWindows::eventButtonExpandX);
} }
{ {
this.buttonExpandY = Button.createLabelButton("un-expand Y"); this.buttonExpandY = Button.createToggleLabelButton("un-expand Y", "expand Y");
this.buttonExpandY.setPropertyExpand(Vector3b.FALSE); this.buttonExpandY.setPropertyExpand(Vector3b.FALSE);
this.buttonExpandY.setPropertyFill(Vector3b.FALSE); this.buttonExpandY.setPropertyFill(Vector3b.FALSE);
this.buttonExpandY.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL)); this.buttonExpandY.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL));
@ -134,7 +133,7 @@ public class BasicWindows extends Windows {
this.buttonExpandY.signalClick.connectAuto(this, BasicWindows::eventButtonExpandY); this.buttonExpandY.signalClick.connectAuto(this, BasicWindows::eventButtonExpandY);
} }
{ {
this.buttonFillX = Button.createLabelButton("un-fill X"); this.buttonFillX = Button.createToggleLabelButton("un-fill X", "fill X");
this.buttonFillX.setPropertyExpand(Vector3b.FALSE); this.buttonFillX.setPropertyExpand(Vector3b.FALSE);
this.buttonFillX.setPropertyFill(Vector3b.FALSE); this.buttonFillX.setPropertyFill(Vector3b.FALSE);
this.buttonFillX.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL)); this.buttonFillX.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL));
@ -142,7 +141,7 @@ public class BasicWindows extends Windows {
this.buttonFillX.signalClick.connectAuto(this, BasicWindows::eventButtonFillX); this.buttonFillX.signalClick.connectAuto(this, BasicWindows::eventButtonFillX);
} }
{ {
this.buttonFillY = Button.createLabelButton("un-fill Y"); this.buttonFillY = Button.createToggleLabelButton("un-fill Y", "fill Y");
this.buttonFillY.setPropertyExpand(Vector3b.FALSE); this.buttonFillY.setPropertyExpand(Vector3b.FALSE);
this.buttonFillY.setPropertyFill(Vector3b.FALSE); this.buttonFillY.setPropertyFill(Vector3b.FALSE);
this.buttonFillY.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL)); this.buttonFillY.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL));
@ -157,7 +156,6 @@ public class BasicWindows extends Windows {
this.sizerMenuHori.subWidgetAdd(this.buttonGravity); this.sizerMenuHori.subWidgetAdd(this.buttonGravity);
this.buttonGravity.signalClick.connectAuto(this, BasicWindows::eventButtonChangeGravity); this.buttonGravity.signalClick.connectAuto(this, BasicWindows::eventButtonChangeGravity);
} }
*/
} }
public void addButton(Widget widget) { public void addButton(Widget widget) {

View File

@ -9,8 +9,7 @@ public class MainWindows extends BasicWindows {
public MainWindows() { public MainWindows() {
setPropertyTitle("Simple Button test"); setPropertyTitle("Simple Button test");
Button simpleButton = Button.createLabelButton("My <font color=\"red\">button <i>internal</i></font> <b>label</b>");
Button simpleButton = Button.createLabelButton("Top Button");
simpleButton.setPropertyExpand(Vector3b.TRUE); simpleButton.setPropertyExpand(Vector3b.TRUE);
simpleButton.setPropertyFill(Vector3b.TRUE); simpleButton.setPropertyFill(Vector3b.TRUE);
this.setTestWidget(simpleButton); this.setTestWidget(simpleButton);

View File

@ -15,15 +15,14 @@ public class MainWindows extends BasicWindows {
//! [ewol_sample_HW_windows_label] //! [ewol_sample_HW_windows_label]
if (true) { if (true) {
//! [ewol_sample_HW_windows_title] //! [ewol_sample_HW_windows_title]
Label simpleLabel = new Label(); final Label simpleLabel = new Label();
simpleLabel.setPropertyValue( simpleLabel.setPropertyValue("He<b>llo.</b> <font color='blue'>World</font><br/><br/> - How are You ???<br/> - Not so Well, I break my leg.<br/><br/><center>The end</center>");
"He<b>llo.</b> <font color='blue'>World</font><br/><br/> - Coucou comment ca vas ???<br/> - Pas trop bien, je me suis cassé la jambe.<br/><br/><center>The end</center>");
simpleLabel.setPropertyExpand(Vector3b.TRUE); simpleLabel.setPropertyExpand(Vector3b.TRUE);
simpleLabel.setPropertyFill(Vector3b.TRUE); simpleLabel.setPropertyFill(Vector3b.TRUE);
this.setTestWidget(simpleLabel); this.setTestWidget(simpleLabel);
//! [ewol_sample_HW_windows_label] //! [ewol_sample_HW_windows_label]
} else { } else {
Spacer simpleSpacer = new Spacer(); final Spacer simpleSpacer = new Spacer();
simpleSpacer.setPropertyExpand(Vector3b.TRUE); simpleSpacer.setPropertyExpand(Vector3b.TRUE);
simpleSpacer.setPropertyFill(Vector3b.TRUE); simpleSpacer.setPropertyFill(Vector3b.TRUE);
this.setTestWidget(simpleSpacer); this.setTestWidget(simpleSpacer);

View File

@ -17,9 +17,9 @@ public class MainWindows extends BasicWindows {
} }
public static void eventButtonChangeKeepRatio(final MainWindows self) { public static void eventButtonChangeKeepRatio(final MainWindows self) {
boolean state = self.testWidget.isPropertyKeepRatio(); final boolean state = self.testWidget.isPropertyKeepRatio();
self.testWidget.setPropertyKeepRatio(!state); self.testWidget.setPropertyKeepRatio(!state);
self.buttonAspectRatio.setPropertyValue(state ? "fkeep aspect ratio" : "un-keep aspect ratio"); //self.buttonAspectRatio.setPropertyValue(state ? "fkeep aspect ratio" : "un-keep aspect ratio");
} }
ImageDisplay testWidget; ImageDisplay testWidget;
@ -36,7 +36,7 @@ public class MainWindows extends BasicWindows {
this.testWidget.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL)); this.testWidget.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL));
this.setTestWidget(this.testWidget); this.setTestWidget(this.testWidget);
{ {
Button button = Button.createLabelButton("Change image"); final Button button = Button.createLabelButton("Change image");
button.setPropertyExpand(Vector3b.FALSE); button.setPropertyExpand(Vector3b.FALSE);
button.setPropertyFill(Vector3b.FALSE); button.setPropertyFill(Vector3b.FALSE);
button.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL)); button.setPropertyMinSize(new Dimension3f(Vector3f.VALUE_16, Distance.PIXEL));

View File

@ -29,18 +29,22 @@ public class CompositingText extends TextBase {
protected List<Vector2f> texturePositions = new ArrayList<>(); protected List<Vector2f> texturePositions = new ArrayList<>();
protected String currentFontName = "";
protected int currentFontSize = -2; // -1 is to perform first initialization
protected int currentFontSizeRequired = -2; // -1 is to perform first initialization
public CompositingText() { public CompositingText() {
this(""); this("");
} }
public CompositingText(final String fontName) { public CompositingText(final String fontName) {
this(fontName, -1); this(fontName, 0);
} }
/** /**
* generic constructor * generic constructor
* @param fontName Name of the font that might be loaded * @param fontName Name of the font that might be loaded
* @param fontSize size of the font that might be loaded * @param fontSize Size of the font that might be loaded
*/ */
public CompositingText(final String fontName, final int fontSize) { public CompositingText(final String fontName, final int fontSize) {
setFont(fontName, fontSize); setFont(fontName, fontSize);
@ -48,6 +52,7 @@ public class CompositingText extends TextBase {
@Override @Override
public Vector3f calculateSizeChar(final Character charcode) { public Vector3f calculateSizeChar(final Character charcode) {
final float renderRatio = (float) this.currentFontSize / (float) this.currentFontSizeRequired;
// get a pointer on the glyph property : // get a pointer on the glyph property :
final GlyphProperty myGlyphProperty = getGlyphPointer(charcode); final GlyphProperty myGlyphProperty = getGlyphPointer(charcode);
final int fontHeigh = (int) getHeight(); final int fontHeigh = (int) getHeight();
@ -57,15 +62,15 @@ public class CompositingText extends TextBase {
} else { } else {
Log.warning("no Glyph... in font : " + this.font.getName()); Log.warning("no Glyph... in font : " + this.font.getName());
} }
return new Vector3f((float) (0.2), (fontHeigh), (float) (0.0)); return new Vector3f(0.2f, fontHeigh, 0);
} }
// get the kerning ofset : // get the kerning offset :
float kerningOffset = 0.0f; float kerningOffset = 0;
if (this.kerning) { if (this.kerning) {
kerningOffset = myGlyphProperty.kerningGet(this.previousCharcode); kerningOffset = myGlyphProperty.kerningGet(this.previousCharcode);
} }
final Vector3f outputSize = new Vector3f(myGlyphProperty.getAdvenceX() + kerningOffset, (fontHeigh), 0.0f); final Vector3f outputSize = new Vector3f((myGlyphProperty.getAdvenceX() + kerningOffset) * renderRatio, (fontHeigh), 0);
// Register the previous character // Register the previous character
this.previousCharcode = charcode; this.previousCharcode = charcode;
return outputSize; return outputSize;
@ -186,7 +191,8 @@ public class CompositingText extends TextBase {
Log.warning("no font..."); Log.warning("no font...");
return 10.0f; return 10.0f;
} }
return this.font.getHeight(this.mode); final float renderRatio = (float) this.currentFontSize / (float) this.currentFontSizeRequired;
return this.font.getHeight(this.mode) * renderRatio;
} }
@Override @Override
@ -195,7 +201,8 @@ public class CompositingText extends TextBase {
Log.warning("no font..."); Log.warning("no font...");
return 1.0f; return 1.0f;
} }
return this.font.getFontSize(); final float renderRatio = (float) this.currentFontSize / (float) this.currentFontSizeRequired;
return this.font.getFontSize() * renderRatio;
} }
@Override @Override
@ -206,13 +213,16 @@ public class CompositingText extends TextBase {
Log.error(" font does not really existed ..."); Log.error(" font does not really existed ...");
return; return;
} }
final int fontSize = (int) getSize(); // sometime we do net require the correct size to the glyph renderer (due to the fact SVG render is not clear on lower size...)
final int fontHeigh = (int) getHeight(); final float renderRatio = (float) this.currentFontSize / (float) this.currentFontSizeRequired;
// get the kerning ofset : final int fontSize = (int) (getSize() * renderRatio);
final int fontHeigh = (int) (getHeight() * renderRatio);
// get the kerning offset :
float kerningOffset = 0; float kerningOffset = 0;
if (this.kerning) { if (this.kerning) {
kerningOffset = myGlyphProperty.kerningGet(this.previousCharcode); kerningOffset = myGlyphProperty.kerningGet(this.previousCharcode) * renderRatio;
if (kerningOffset != 0) { if (kerningOffset != 0) {
// Log.debug("Kerning between : '" + this.previousCharcode + "''" + myGlyph.UVal // Log.debug("Kerning between : '" + this.previousCharcode + "''" + myGlyph.UVal
// + "' value : " + kerningOffset); // + "' value : " + kerningOffset);
@ -223,10 +233,10 @@ public class CompositingText extends TextBase {
/* /*
* Bitmap position xA xB yC *------* | | | | yD *------* * Bitmap position xA xB yC *------* | | | | yD *------*
*/ */
float dxA = this.position.x() + myGlyphProperty.getTextureRenderOffset().x() + kerningOffset; float dxA = this.position.x() + myGlyphProperty.getTextureRenderOffset().x() * renderRatio + kerningOffset;
float dxB = dxA + myGlyphProperty.sizeTexture.x(); float dxB = dxA + myGlyphProperty.sizeTexture.x() * renderRatio;
float dyC = this.position.y() + myGlyphProperty.getTextureRenderOffset().y() + fontHeigh - fontSize; float dyC = this.position.y() + myGlyphProperty.getTextureRenderOffset().y() * renderRatio + fontHeigh - fontSize;
float dyD = dyC - myGlyphProperty.sizeTexture.y(); float dyD = dyC - myGlyphProperty.sizeTexture.y() * renderRatio;
float tuA = myGlyphProperty.texturePosStart.x(); float tuA = myGlyphProperty.texturePosStart.x();
float tuB = tuA + myGlyphProperty.texturePosSize.x(); float tuB = tuA + myGlyphProperty.texturePosSize.x();
@ -301,7 +311,7 @@ public class CompositingText extends TextBase {
* Step 1 : ******** ****** **** ** * Step 1 : ******** ****** **** **
* *
*/ */
// set texture coordonates : // set texture coordinates :
this.texturePositions.add(texturePos0); this.texturePositions.add(texturePos0);
this.texturePositions.add(texturePos1); this.texturePositions.add(texturePos1);
this.texturePositions.add(texturePos2); this.texturePositions.add(texturePos2);
@ -318,7 +328,7 @@ public class CompositingText extends TextBase {
* *
* ** **** ****** ******** * ** **** ****** ********
*/ */
// set texture coordonates : // set texture coordinates :
this.texturePositions.add(texturePos0); this.texturePositions.add(texturePos0);
this.texturePositions.add(texturePos2); this.texturePositions.add(texturePos2);
this.texturePositions.add(texturePos3); this.texturePositions.add(texturePos3);
@ -336,7 +346,7 @@ public class CompositingText extends TextBase {
// move the position : // move the position :
// Log.debug(" 5 pos=" + this.position + " advance=" + myGlyph.advance.x() + " // Log.debug(" 5 pos=" + this.position + " advance=" + myGlyph.advance.x() + "
// kerningOffset=" + kerningOffset); // kerningOffset=" + kerningOffset);
this.position = this.position.withX(this.position.x() + myGlyphProperty.getAdvenceX() + kerningOffset); this.position = this.position.withX(this.position.x() + myGlyphProperty.getAdvenceX() * renderRatio + kerningOffset);
// Log.debug(" 6 print '" + char-code + "' : start=" + this.sizeDisplayStart + " // Log.debug(" 6 print '" + char-code + "' : start=" + this.sizeDisplayStart + "
// stop=" + this.sizeDisplayStop + " pos=" + this.position); // stop=" + this.sizeDisplayStop + " pos=" + this.position);
// Register the previous character // Register the previous character
@ -345,8 +355,13 @@ public class CompositingText extends TextBase {
} }
@Override @Override
public void setFont(String fontName, int fontSize) { public void setFont(final String inputFontName, final int inputFontSize) {
clear(); if (inputFontName.equals(this.currentFontName) && inputFontSize == this.currentFontSize) {
return;
}
String fontName = inputFontName;
int fontSize = inputFontSize;
// remove old one // remove old one
final ResourceTexturedFont previousFont = this.font; final ResourceTexturedFont previousFont = this.font;
if (fontSize <= 0) { if (fontSize <= 0) {
@ -355,14 +370,30 @@ public class CompositingText extends TextBase {
if (fontName.isEmpty()) { if (fontName.isEmpty()) {
fontName = Configs.getConfigFonts().getName(); fontName = Configs.getConfigFonts().getName();
} }
Uri fontUri = Configs.getConfigFonts().getFontUri(fontName).clone();
fontUri.setProperty("size", Integer.toString(fontSize)); // if size in under 25, we request upper size:
Log.verbose("plop : " + fontName + " size=" + fontSize + " result :" + fontName); int sizeRequest = 25;
if (fontSize > 25) {
sizeRequest = fontSize;
}
if (inputFontName.equals(this.currentFontName) && this.currentFontSizeRequired == sizeRequest) {
this.currentFontSize = inputFontSize;
return;
}
clear();
final Uri fontUri = Configs.getConfigFonts().getFontUri(fontName).clone();
fontUri.setProperty("size", Integer.toString(sizeRequest));
Log.verbose("plop : " + fontName + " size=" + sizeRequest + " result :" + fontName);
// link to new one // link to new one
this.font = ResourceTexturedFont.create(fontUri); this.font = ResourceTexturedFont.create(fontUri);
if (this.font == null) { if (this.font == null) {
Log.error("Can not get font resource"); Log.error("Can not get font resource");
this.font = previousFont; this.font = previousFont;
} else {
this.currentFontName = inputFontName;
this.currentFontSize = inputFontSize;
this.currentFontSizeRequired = sizeRequest;
} }
} }
@ -375,25 +406,12 @@ public class CompositingText extends TextBase {
@Override @Override
public void setFontName(final String fontName) { public void setFontName(final String fontName) {
// get old size setFont(fontName, this.currentFontSize);
int fontSize = -1;
if (this.font != null) {
fontSize = this.font.getFontSize();
}
setFont(fontName, fontSize);
} }
@Override @Override
public void setFontSize(final int fontSize) { public void setFontSize(final int fontSize) {
// get old size setFont(this.currentFontName, fontSize);
String fontName = "";
if (this.font != null) {
fontName = this.font.getName();
// Remove the :XX for the size ...
final int pos = fontName.lastIndexOf(':');
fontName = fontName.substring(0, pos);
}
setFont(fontName, fontSize);
} }
} }

View File

@ -29,17 +29,16 @@ import org.atriasoft.gale.key.KeyStatus;
import org.atriasoft.gale.key.KeyType; import org.atriasoft.gale.key.KeyType;
import org.atriasoft.gale.resource.ResourceManager; import org.atriasoft.gale.resource.ResourceManager;
// Here we hereted from the gale application to be agnostic of the OW where we work ... // Here we herited from the gale application to be agnostic of the OW where we work ...
public class EwolContext extends GaleApplication { public class EwolContext extends GaleApplication {
/** /**
* From everyware in the program, we can get the context inteface. * From everywhere in the program, we can get the context inteface.
* @return current reference on the instance. * @return current reference on the instance.
*/ */
@SuppressWarnings("preview")
public static EwolContext getContext() { public static EwolContext getContext() {
GaleApplication appl = Gale.getContext().getApplication(); final GaleApplication appl = Gale.getContext().getApplication();
if (appl instanceof EwolContext elem) { if (appl instanceof final EwolContext elem) {
return elem; return elem;
} }
return null; return null;
@ -47,10 +46,6 @@ public class EwolContext extends GaleApplication {
private EwolApplication application; // !< Application handle private EwolApplication application; // !< Application handle
private final int initStepId = 0;
private final int initTotalStep = 0;
private final InputManager input; private final InputManager input;
private final ObjectManager objectManager; // !< Object Manager main instance private final ObjectManager objectManager; // !< Object Manager main instance

View File

@ -16,51 +16,58 @@ public class Log {
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.VERBOSE); private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.VERBOSE);
private static final boolean PRINT_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING); private static final boolean PRINT_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING);
public static void critical(final String data) { public static void critical(final Exception e, final String data) {
if (Log.PRINT_CRITICAL || Log.FORCE_ALL) { e.printStackTrace();
Logger.critical(Log.LIB_NAME_DRAW, data); if (PRINT_CRITICAL || FORCE_ALL) {
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
} }
} }
public static void debug(final String data) { public static void critical(final String data, final Object... objects) {
if (Log.PRINT_DEBUG || Log.FORCE_ALL) { if (PRINT_CRITICAL || FORCE_ALL) {
Logger.debug(Log.LIB_NAME_DRAW, data); Logger.critical(LIB_NAME_DRAW, data, objects);
} }
} }
public static void error(final String data) { public static void debug(final String data, final Object... objects) {
if (Log.PRINT_ERROR || Log.FORCE_ALL) { if (PRINT_DEBUG || FORCE_ALL) {
Logger.error(Log.LIB_NAME_DRAW, data); Logger.debug(LIB_NAME_DRAW, data, objects);
} }
} }
public static void info(final String data) { public static void error(final String data, final Object... objects) {
if (Log.PRINT_INFO || Log.FORCE_ALL) { if (PRINT_ERROR || FORCE_ALL) {
Logger.info(Log.LIB_NAME_DRAW, data); Logger.error(LIB_NAME_DRAW, data, objects);
} }
} }
public static void print(final String data) { public static void info(final String data, final Object... objects) {
if (Log.PRINT_PRINT || Log.FORCE_ALL) { if (PRINT_INFO || FORCE_ALL) {
Logger.print(Log.LIB_NAME_DRAW, data); Logger.info(LIB_NAME_DRAW, data, objects);
} }
} }
public static void todo(final String data) { public static void print(final String data, final Object... objects) {
if (Log.PRINT_TODO || Log.FORCE_ALL) { if (PRINT_PRINT || FORCE_ALL) {
Logger.todo(Log.LIB_NAME_DRAW, data); Logger.print(LIB_NAME_DRAW, data, objects);
} }
} }
public static void verbose(final String data) { public static void todo(final String data, final Object... objects) {
if (Log.PRINT_VERBOSE || Log.FORCE_ALL) { if (PRINT_TODO || FORCE_ALL) {
Logger.verbose(Log.LIB_NAME_DRAW, data); Logger.todo(LIB_NAME_DRAW, data, objects);
} }
} }
public static void warning(final String data) { public static void verbose(final String data, final Object... objects) {
if (Log.PRINT_WARNING || Log.FORCE_ALL) { if (PRINT_VERBOSE || FORCE_ALL) {
Logger.warning(Log.LIB_NAME_DRAW, data); Logger.verbose(LIB_NAME_DRAW, data, objects);
}
}
public static void warning(final String data, final Object... objects) {
if (PRINT_WARNING || FORCE_ALL) {
Logger.warning(LIB_NAME_DRAW, data, objects);
} }
} }

View File

@ -55,8 +55,7 @@ public class ResourceFontSvg extends Resource {
@Override @Override
public void cleanUp() { public void cleanUp() {
// TODO Auto-generated method stub // nothing to do...
} }
public synchronized void display() { public synchronized void display() {
@ -64,7 +63,7 @@ public class ResourceFontSvg extends Resource {
} }
public synchronized boolean drawGlyph(final ImageByte imageOut, final int fontSize, final Vector2i glyphPosition, final GlyphProperty property, final int posInImage) { public synchronized boolean drawGlyph(final ImageByte imageOut, final int fontSize, final Vector2i glyphPosition, final GlyphProperty property, final int posInImage) {
Weight weight = this.font.render(property.glyph.getUnicodeValue(), fontSize); final Weight weight = this.font.render(property.glyph.getUnicodeValue(), fontSize);
if (weight == null) { if (weight == null) {
return false; return false;
} }
@ -93,7 +92,7 @@ public class ResourceFontSvg extends Resource {
} }
public synchronized boolean drawGlyph(final ImageByteMono imageOut, final int fontSize, final GlyphProperty property, final int borderSize) { public synchronized boolean drawGlyph(final ImageByteMono imageOut, final int fontSize, final GlyphProperty property, final int borderSize) {
Weight weight = this.font.render(property.glyph.getUnicodeValue(), fontSize); final Weight weight = this.font.render(property.glyph.getUnicodeValue(), fontSize);
for (int jjj = 0; jjj < weight.getHeight(); jjj++) { for (int jjj = 0; jjj < weight.getHeight(); jjj++) {
for (int iii = 0; iii < weight.getWidth(); iii++) { for (int iii = 0; iii < weight.getWidth(); iii++) {
final float valueColor = weight.get(iii, weight.getHeight() - 1 - jjj); final float valueColor = weight.get(iii, weight.getHeight() - 1 - jjj);
@ -105,7 +104,7 @@ public class ResourceFontSvg extends Resource {
} }
public synchronized GlyphProperty getGlyphProperty(final int fontSize, final int uicodeVal) { public synchronized GlyphProperty getGlyphProperty(final int fontSize, final int uicodeVal) {
Glyph glyph = this.font.getGlyphNullIfMissing(uicodeVal); final Glyph glyph = this.font.getGlyphNullIfMissing(uicodeVal);
GlyphProperty out; GlyphProperty out;
if (glyph == null) { if (glyph == null) {
out = new GlyphProperty(this.font, uicodeVal, fontSize); out = new GlyphProperty(this.font, uicodeVal, fontSize);
@ -120,8 +119,8 @@ public class ResourceFontSvg extends Resource {
} }
public synchronized Vector2f getSize(final int fontSize, final String unicodeString) { public synchronized Vector2f getSize(final int fontSize, final String unicodeString) {
float width = this.font.calculateWidth(unicodeString, fontSize, false); final float width = this.font.calculateWidth(unicodeString, fontSize, false);
float height = this.font.calculateFontRealHeight(fontSize); final float height = this.font.calculateFontRealHeight(fontSize);
return new Vector2f(width, height); return new Vector2f(width, height);
} }

View File

@ -46,13 +46,13 @@ public class ResourceTexturedFont extends ResourceTexture2 {
private final Uri[] fileName = new Uri[4]; private final Uri[] fileName = new Uri[4];
// specific element to have the the know if the specify element is known... // specific element to have the the know if the specify element is known...
// == > otherwise I can just generate italic ... // == > otherwise I can just generate italic ...
// == > Bold is a little more complicated (maybe with the bordersize) // == > Bold is a little more complicated (maybe with the border-size)
private final ResourceFontSvg[] font = new ResourceFontSvg[4]; private final ResourceFontSvg[] font = new ResourceFontSvg[4];
private final int[] height = new int[4]; private final int[] height = new int[4];
// for the texture generation : // for the texture generation :
public Vector2i[] lastGlyphPos = new Vector2i[4]; public Vector2i[] lastGlyphPos = new Vector2i[4];
public int[] lastRawHeigh = new int[4]; public int[] lastRawHeigh = new int[4];
public List<GlyphProperty>[] listElement = new ArrayList[4];// = new (List<GlyphProperty>)[4]; public List<GlyphProperty>[] listElement = new ArrayList[4];
private final FontMode[] modeWraping = new FontMode[4]; // !< This is a wrapping mode to prevent the fact that no private final FontMode[] modeWraping = new FontMode[4]; // !< This is a wrapping mode to prevent the fact that no
private int size = 10; private int size = 10;
@ -87,16 +87,16 @@ public class ResourceTexturedFont extends ResourceTexture2 {
this.listElement[2] = new ArrayList<>(); this.listElement[2] = new ArrayList<>();
this.listElement[3] = new ArrayList<>(); this.listElement[3] = new ArrayList<>();
String sizeString = fontBaseUri.getProperty("size"); final String sizeString = fontBaseUri.getProperty("size");
if (sizeString == null) { if (sizeString == null) {
this.size = 25; this.size = 25;
} else { } else {
this.size = Integer.parseInt(sizeString); this.size = Integer.parseInt(sizeString);
} }
// find all the fonts... // find all the fonts...
Uri fontBaseUriBold = new Uri(fontBaseUri.getGroup(), fontBaseUri.getPath().replace(".svg", "Bold.svg"), fontBaseUri.getproperties()); final Uri fontBaseUriBold = new Uri(fontBaseUri.getGroup(), fontBaseUri.getPath().replace(".svg", "Bold.svg"), fontBaseUri.getproperties());
Uri fontBaseUriOblique = new Uri(fontBaseUri.getGroup(), fontBaseUri.getPath().replace(".svg", "Oblique.svg"), fontBaseUri.getproperties()); final Uri fontBaseUriOblique = new Uri(fontBaseUri.getGroup(), fontBaseUri.getPath().replace(".svg", "Oblique.svg"), fontBaseUri.getproperties());
Uri fontBaseUriBoldOblique = new Uri(fontBaseUri.getGroup(), fontBaseUri.getPath().replace(".svg", "BoldOblique.svg"), fontBaseUri.getproperties()); final Uri fontBaseUriBoldOblique = new Uri(fontBaseUri.getGroup(), fontBaseUri.getPath().replace(".svg", "BoldOblique.svg"), fontBaseUri.getproperties());
if (fontBaseUri.exist()) { if (fontBaseUri.exist()) {
this.fileName[FontMode.REGULAR.getValue()] = fontBaseUri; this.fileName[FontMode.REGULAR.getValue()] = fontBaseUri;
} }
@ -140,7 +140,7 @@ public class ResourceTexturedFont extends ResourceTexture2 {
} }
} }
for (int iiiFontId = 0; iiiFontId < 4; iiiFontId++) { for (int iiiFontId = 0; iiiFontId < 4; iiiFontId++) {
// set the bassic charset: // set the basic char-set:
this.listElement[iiiFontId].clear(); this.listElement[iiiFontId].clear();
if (this.font[iiiFontId] == null) { if (this.font[iiiFontId] == null) {
continue; continue;
@ -190,7 +190,7 @@ public class ResourceTexturedFont extends ResourceTexture2 {
this.lastGlyphPos[iii] = new Vector2i(1, this.lastGlyphPos[iii].y() + this.lastRawHeigh[iii]); this.lastGlyphPos[iii] = new Vector2i(1, this.lastGlyphPos[iii].y() + this.lastRawHeigh[iii]);
this.lastRawHeigh[iii] = 0; this.lastRawHeigh[iii] = 0;
} }
Log.error("glyph texture size = " + tmpchar.sizeTexture + "last posY=" + this.lastGlyphPos[iii].y() + " out size=" + this.data.getSize()); Log.verbose("glyph texture size = " + tmpchar.sizeTexture + "last posY=" + this.lastGlyphPos[iii].y() + " out size=" + this.data.getSize());
while (this.lastGlyphPos[iii].y() + tmpchar.sizeTexture.y() + 3 > this.data.getSize().y()) { while (this.lastGlyphPos[iii].y() + tmpchar.sizeTexture.y() + 3 > this.data.getSize().y()) {
this.data.resize(this.data.getSize().x(), this.data.getSize().y() * 2); this.data.resize(this.data.getSize().x(), this.data.getSize().y() * 2);
// note : need to rework all the layer due to the fact that the texture is used by the 4 type... // note : need to rework all the layer due to the fact that the texture is used by the 4 type...
@ -238,9 +238,9 @@ public class ResourceTexturedFont extends ResourceTexture2 {
} }
/** /**
* get the pointer on the coresponding glyph * get the pointer on the corresponding glyph
* @param charcode The unicodeValue * @param charcode The unicodeValue
* @param displayMode Mode to display the currrent font * @param displayMode Mode to display the current font
* @return The pointer on the glyph == > never null * @return The pointer on the glyph == > never null
*/ */
public synchronized GlyphProperty getGlyph(final Character charcode, final FontMode displayMode) { public synchronized GlyphProperty getGlyph(final Character charcode, final FontMode displayMode) {
@ -265,8 +265,8 @@ public class ResourceTexturedFont extends ResourceTexture2 {
/** /**
* get the display height of this font * get the display height of this font
* @param DisplayMode Mode to display the currrent font * @param DisplayMode Mode to display the current font
* @return Dimention of the font need between 2 lines * @return Dimension of the font need between 2 lines
*/ */
public int getHeight() { public int getHeight() {
return this.height[FontMode.REGULAR.getValue()]; return this.height[FontMode.REGULAR.getValue()];
@ -279,7 +279,7 @@ public class ResourceTexturedFont extends ResourceTexture2 {
/** /**
* get the ID of a unicode charcode * get the ID of a unicode charcode
* @param charcode The unicodeValue * @param charcode The unicodeValue
* @param displayMode Mode to display the currrent font * @param displayMode Mode to display the current font
* @return The ID in the table (if it does not exist : return 0) * @return The ID in the table (if it does not exist : return 0)
*/ */
private synchronized int getIndex(final Character charcode, final FontMode displayMode) { private synchronized int getIndex(final Character charcode, final FontMode displayMode) {

View File

@ -44,6 +44,7 @@ public class Button extends ContainerToggle {
public static Button createLabelButton(final String label) { public static Button createLabelButton(final String label) {
final Button out = new Button(); final Button out = new Button();
final Label labelWidget = new Label(); final Label labelWidget = new Label();
labelWidget.setPropertyFontSize(12);
labelWidget.setPropertyFill(Vector3b.FALSE); labelWidget.setPropertyFill(Vector3b.FALSE);
labelWidget.setPropertyExpand(Vector3b.FALSE); labelWidget.setPropertyExpand(Vector3b.FALSE);
labelWidget.setPropertyGravity(Gravity.CENTER); labelWidget.setPropertyGravity(Gravity.CENTER);
@ -52,6 +53,28 @@ public class Button extends ContainerToggle {
return out; return out;
} }
public static Button createToggleLabelButton(final String label0, final String label1) {
final Button out = new Button();
{
final Label labelWidget = new Label();
labelWidget.setPropertyFill(Vector3b.FALSE);
labelWidget.setPropertyExpand(Vector3b.FALSE);
labelWidget.setPropertyGravity(Gravity.CENTER);
labelWidget.setPropertyValue(label0);
out.setSubWidget(labelWidget, 0);
}
{
final Label labelWidget = new Label();
labelWidget.setPropertyFill(Vector3b.FALSE);
labelWidget.setPropertyExpand(Vector3b.FALSE);
labelWidget.setPropertyGravity(Gravity.CENTER);
labelWidget.setPropertyValue(label1);
out.setSubWidget(labelWidget, 1);
}
out.setPropertyToggleMode(true);
return out;
}
/** /**
* Periodic call to update grapgic display * Periodic call to update grapgic display
* @param event Time generic event * @param event Time generic event
@ -318,6 +341,9 @@ public class Button extends ContainerToggle {
if (KeyStatus.pressSingle == event.status() && over) { if (KeyStatus.pressSingle == event.status() && over) {
keepFocus(); keepFocus();
this.signalClick.emit(); this.signalClick.emit();
if (this.propertyToggleMode) {
this.setPropertyValue(!this.propertyValue);
}
return true; return true;
} }
if (KeyStatus.down == event.status() && over) { if (KeyStatus.down == event.status() && over) {

View File

@ -22,7 +22,10 @@ public class ContainerToggle extends Widget {
/** /**
* Constructor * Constructor
*/ */
public ContainerToggle() {} public ContainerToggle() {
this.subWidget[0] = null;
this.subWidget[1] = null;
}
// @Override // @Override
// public boolean loadXML(final XmlElement node) { // public boolean loadXML(final XmlElement node) {

View File

@ -23,7 +23,7 @@ import org.atriasoft.exml.annotation.XmlManaged;
import org.atriasoft.exml.annotation.XmlName; import org.atriasoft.exml.annotation.XmlName;
import org.atriasoft.gale.key.KeyStatus; import org.atriasoft.gale.key.KeyStatus;
public class Label extends Widget { public class LabelOnSVG extends Widget {
protected int colorDefaultBgText = -1; //!< Default Background color of the text protected int colorDefaultBgText = -1; //!< Default Background color of the text
protected int colorDefaultFgText = -1; //!< Default color of the text protected int colorDefaultFgText = -1; //!< Default color of the text
protected ResourceColorFile colorProperty; //!< theme color property protected ResourceColorFile colorProperty; //!< theme color property
@ -37,7 +37,7 @@ public class Label extends Widget {
protected CompositingText text = new CompositingText(); //!< Compositing text element. protected CompositingText text = new CompositingText(); //!< Compositing text element.
protected String value = ""; protected String value = "";
public Label() { public LabelOnSVG() {
this.colorProperty = ResourceColorFile.create(new Uri("THEME", "/color/Label.json", "ewol")); this.colorProperty = ResourceColorFile.create(new Uri("THEME", "/color/Label.json", "ewol"));
if (this.colorProperty != null) { if (this.colorProperty != null) {
this.colorDefaultFgText = this.colorProperty.request("foreground"); this.colorDefaultFgText = this.colorProperty.request("foreground");
@ -51,7 +51,7 @@ public class Label extends Widget {
* Constructor * Constructor
* @param newLabel The displayed decorated text. * @param newLabel The displayed decorated text.
*/ */
public Label(final String newLabel) { public LabelOnSVG(final String newLabel) {
this.colorProperty = ResourceColorFile.create(new Uri("THEME", "/color/Label.json", "ewol")); this.colorProperty = ResourceColorFile.create(new Uri("THEME", "/color/Label.json", "ewol"));
if (this.colorProperty != null) { if (this.colorProperty != null) {
this.colorDefaultFgText = this.colorProperty.request("foreground"); this.colorDefaultFgText = this.colorProperty.request("foreground");

View File

@ -10,7 +10,7 @@ public class WidgetXmlFactory implements InterfaceXmlFactoryAccess {
static { static {
listWidgetAvaillable.put("Button", Button.class); listWidgetAvaillable.put("Button", Button.class);
listWidgetAvaillable.put("Sizer", Sizer.class); listWidgetAvaillable.put("Sizer", Sizer.class);
listWidgetAvaillable.put("Label", Label.class); listWidgetAvaillable.put("Label", LabelOnSVG.class);
listWidgetAvaillable.put("CheckBox", CheckBox.class); listWidgetAvaillable.put("CheckBox", CheckBox.class);
listWidgetAvaillable.put("Image", ImageDisplay.class); listWidgetAvaillable.put("Image", ImageDisplay.class);
} }