[DEV] continue transcription
This commit is contained in:
parent
4f5a929b2f
commit
c43eae6857
16
ewol.iml
Normal file
16
ewol.iml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="gale" exported="" />
|
||||
<orderEntry type="module" module-name="ejson" exported="" />
|
||||
<orderEntry type="module" module-name="exml" exported="" />
|
||||
<orderEntry type="library" exported="" name="freetype-jni" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="org.junit.jupiter:junit-jupiter-api:5.7.1" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -12,9 +12,9 @@ open module org.atriasoft.ewol {
|
||||
exports org.atriasoft.ewol.object;
|
||||
exports org.atriasoft.ewol.resource;
|
||||
exports org.atriasoft.ewol.resource.font;
|
||||
exports org.atriasoft.ewol.tools;
|
||||
//exports org.atriasoft.ewol.tools;
|
||||
exports org.atriasoft.ewol.widget;
|
||||
exports org.atriasoft.ewol.widget.meta;
|
||||
//exports org.atriasoft.ewol.widget.meta;
|
||||
|
||||
exports org.atriasoft.echrono;
|
||||
exports org.atriasoft.egami;
|
||||
|
283
src/org/atriasoft/etranslate/ETranslate.java
Normal file
283
src/org/atriasoft/etranslate/ETranslate.java
Normal file
@ -0,0 +1,283 @@
|
||||
package org.atriasoft.etranslate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.atriasoft.ejson.Ejson;
|
||||
import org.atriasoft.ejson.model.JsonNode;
|
||||
import org.atriasoft.ejson.model.JsonObject;
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.ewol.internal.Log;
|
||||
|
||||
/**
|
||||
* @brief This is a simple interface to converte application display string in a
|
||||
* generic current system language
|
||||
* @note: The current name of language reprenent the file name, then if you want
|
||||
* to get the machine language in an other than generic passed, juste add
|
||||
* it. Generic langage char: (all translation might be done in UTF-8 this
|
||||
* simplify interface) English : "EN" French : "FR" German : "DE" Spanish
|
||||
* : "SP" Japanese : "JA" Italian : "IT" Korean : "KO" Russian : "RU"
|
||||
* Portuguese, Brazilian : "PT" Chinese : "ZH"
|
||||
*/
|
||||
public class ETranslate {
|
||||
private static Map<String, Uri> m_listPath = new HashMap<>();
|
||||
private static String m_major = "etranslate";
|
||||
private static String m_languageDefault = "EN";
|
||||
private static String m_language = "";
|
||||
private static boolean m_translateLoadad = false;
|
||||
private static Map<String, String> m_translate = new HashMap<>();
|
||||
private static boolean g_isInit = false;
|
||||
|
||||
/**
|
||||
* @brief Initialize etranslate
|
||||
* @param[in] _argc Number of argument list
|
||||
* @param[in] _argv List of arguments
|
||||
*/
|
||||
static {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the path folder of the translation files
|
||||
* @param[in] _lib Library name that the path depend
|
||||
* @param[in] _uri ETK generic uri (DATA:... or /xxx)
|
||||
* @param[in] _major This path is the major path (The last loaded, the one which
|
||||
* overload all)
|
||||
*/
|
||||
public static void addPath(final String _lib, final Uri _uri) {
|
||||
addPath(_lib, _uri, false);
|
||||
}
|
||||
|
||||
public static void addPath(final String _lib, final Uri _uri, final boolean _major) {
|
||||
m_listPath.put(_lib, _uri);
|
||||
if (_major == true) {
|
||||
m_major = _lib;
|
||||
Log.info("Change major translation : '" + m_major + "'");
|
||||
}
|
||||
m_translateLoadad = false;
|
||||
m_translate.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Automatic detection of the system language
|
||||
*/
|
||||
public static void autoDetectLanguage() {
|
||||
if (g_isInit == false) {
|
||||
Log.error("E-translate system has not been init");
|
||||
}
|
||||
Log.verbose("Auto-detect language of system");
|
||||
String nonameLocalName = "EN";
|
||||
String userLocalName = "EN";
|
||||
String globalLocalName = "EN";
|
||||
/*
|
||||
* try { nonameLocalName = setlocale(LC_ALL, ""); userLocalName =
|
||||
* setlocale(LC_MESSAGES, ""); globalLocalName = setlocale(LC_CTYPE, "");
|
||||
* Log.error(" The default locale is '" + globalLocalName + "'");
|
||||
* Log.error(" The user's locale is '" + userLocalName + "'");
|
||||
* Log.error(" A nameless locale is '" + nonameLocalName + "'"); } catch (int
|
||||
* e) { // TODO: Do it better RuntimeError e) {
|
||||
* Log.error("Can not get Locals ==> set English ..."); }
|
||||
*/
|
||||
Log.error("Can not get Locals ==> set English ...");
|
||||
|
||||
String lang = nonameLocalName;
|
||||
if (lang == "*" || lang == "") {
|
||||
lang = userLocalName;
|
||||
}
|
||||
if (lang == "*" || lang == "") {
|
||||
lang = globalLocalName;
|
||||
}
|
||||
if (lang == "C" || lang == "" || lang.length() < 2) {
|
||||
lang = "EN";
|
||||
}
|
||||
lang = lang.substring(0, 2);
|
||||
lang = lang.toUpperCase();
|
||||
Log.info("Select Language : '" + lang + "'");
|
||||
setLanguage(lang);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Translate a specific text (if not find, it will be retured the same
|
||||
* text).
|
||||
* @param[in] _instance Text to translate.
|
||||
* @return The tranlated text.
|
||||
*/
|
||||
public static String get(final String _instance) {
|
||||
loadTranslation();
|
||||
Log.verbose("Request translate: '" + _instance + "'");
|
||||
// find all iterance of '_T{' ... '}'
|
||||
String out = Pattern.compile("_T\\{.*\\}").matcher(_instance).replaceAll(mr -> {
|
||||
String data = mr.group();
|
||||
Log.info("translate : '" + data + "'");
|
||||
String itTranslate = m_translate.get(data);
|
||||
if (itTranslate == null) {
|
||||
Log.debug("Can not find tranlation : '" + _instance + "'");
|
||||
return data;
|
||||
}
|
||||
return itTranslate;
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current language loaded
|
||||
* @return The 2/3 char defining the language
|
||||
*/
|
||||
public static String getLanguage() {
|
||||
return m_language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current language selected
|
||||
* @return The 2/3 char defining the language
|
||||
*/
|
||||
public static String getLanguageDefault() {
|
||||
return m_languageDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current paths of the library
|
||||
* @param[in] _lib Library name that the path depend
|
||||
* @return Uri value.
|
||||
*/
|
||||
public static Uri getPaths(final String _lib) {
|
||||
return m_listPath.get(_lib);
|
||||
}
|
||||
|
||||
private static void loadTranslation() {
|
||||
if (m_translateLoadad == true) {
|
||||
return;
|
||||
}
|
||||
Log.debug("Load Translation MAJOR='" + m_major + "' LANG='" + m_language + "' default=" + m_languageDefault);
|
||||
Log.debug("list path=" + m_listPath.keySet());
|
||||
// start parse language for Major:
|
||||
Uri itMajor = m_listPath.get(m_major);
|
||||
if (itMajor != null) {
|
||||
Uri uri = itMajor.withPath(itMajor.getPath() + "/" + m_language + ".json");
|
||||
try {
|
||||
JsonObject root = (JsonObject) Ejson.parse(uri);
|
||||
for (Map.Entry<String, JsonNode> element : root.getNodes().entrySet()) {
|
||||
String val = element.getValue().toJsonString().getValue();
|
||||
m_translate.put(element.getKey(), val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
uri = itMajor.withPath(itMajor.getPath() + "/" + m_languageDefault + ".json");
|
||||
try {
|
||||
JsonObject root = (JsonObject) Ejson.parse(uri);
|
||||
for (Map.Entry<String, JsonNode> element : root.getNodes().entrySet()) {
|
||||
String val = element.getValue().toJsonString().getValue();
|
||||
m_translate.put(element.getKey(), val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// start parse language:
|
||||
for (Map.Entry<String, Uri> it : m_listPath.entrySet()) {
|
||||
if (it.getKey().contentEquals(m_major)) {
|
||||
continue;
|
||||
}
|
||||
Uri uri = it.getValue().withPath(it.getValue().getPath() + "/" + m_language + ".json");
|
||||
/*
|
||||
* TODO ... if (Uri.exist(uri) == false) { continue; }
|
||||
*/
|
||||
JsonObject doc;
|
||||
try {
|
||||
doc = (JsonObject) Ejson.parse(uri);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
for (Map.Entry<String, JsonNode> element : doc.getNodes().entrySet()) {
|
||||
String val = element.getValue().toJsonString().getValue();
|
||||
m_translate.put(element.getKey(), val);
|
||||
}
|
||||
}
|
||||
// start parse default language:
|
||||
for (Map.Entry<String, Uri> it : m_listPath.entrySet()) {
|
||||
if (it.getKey().contentEquals(m_major)) {
|
||||
continue;
|
||||
}
|
||||
Uri uri = it.getValue().withPath(it.getValue().getPath() + "/" + m_languageDefault + ".json");
|
||||
/*
|
||||
* TODO ... if (Uri.exist(uri) == false) { continue; }
|
||||
*/
|
||||
JsonObject doc;
|
||||
try {
|
||||
doc = (JsonObject) Ejson.parse(uri);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
continue;
|
||||
}
|
||||
for (Map.Entry<String, JsonNode> element : doc.getNodes().entrySet()) {
|
||||
String val = element.getValue().toJsonString().getValue();
|
||||
m_translate.put(element.getKey(), val);
|
||||
}
|
||||
}
|
||||
m_translateLoadad = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the language to load data. when no data availlable, we get the
|
||||
* default language.
|
||||
* @param[in] _lang Language to load : ("EN" for english, "FR" for french, "DE"
|
||||
* for German, "SP" for spanish ...)
|
||||
*/
|
||||
public static void setLanguage(final String _lang) {
|
||||
if (m_language == _lang) {
|
||||
return;
|
||||
}
|
||||
m_language = _lang;
|
||||
m_translateLoadad = false;
|
||||
m_translate.clear();
|
||||
if (_lang == "EN") {
|
||||
Log.info("Change language translation: '" + _lang + "'=English");
|
||||
} else if (_lang == "FR") {
|
||||
Log.info("Change language translation: '" + _lang + "'=French");
|
||||
} else if (_lang == "DE") {
|
||||
Log.info("Change language translation: '" + _lang + "'=German");
|
||||
} else if (_lang == "SP") {
|
||||
Log.info("Change language translation: '" + _lang + "'=Spanish");
|
||||
} else if (_lang == "JA") {
|
||||
Log.info("Change language translation: '" + _lang + "'=Japanese");
|
||||
} else if (_lang == "IT") {
|
||||
Log.info("Change language translation: '" + _lang + "'=Italian");
|
||||
} else if (_lang == "KO") {
|
||||
Log.info("Change language translation: '" + _lang + "'=Korean");
|
||||
} else if (_lang == "RU") {
|
||||
Log.info("Change language translation: '" + _lang + "'=Russian");
|
||||
} else if (_lang == "PT") {
|
||||
Log.info("Change language translation: '" + _lang + "'=Portuguese, Brazilian");
|
||||
} else if (_lang == "ZH") {
|
||||
Log.info("Change language translation: '" + _lang + "'=Chinese");
|
||||
} else {
|
||||
Log.info("Change language translation: '" + _lang + "'=Unknow");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the default language to load data (the default language might
|
||||
* contain all internal data for the basic application)
|
||||
* @param[in] _lang Language to load : ("EN" for english, "FR" for french, "DE"
|
||||
* for German, "SP" for spanish ...)
|
||||
*/
|
||||
public static void setLanguageDefault(final String _lang) {
|
||||
if (m_languageDefault == _lang) {
|
||||
return;
|
||||
}
|
||||
Log.info("Change default language translation : '" + _lang + "'");
|
||||
m_languageDefault = _lang;
|
||||
m_translateLoadad = false;
|
||||
m_translate.clear();
|
||||
}
|
||||
|
||||
private ETranslate() {
|
||||
}
|
||||
}
|
@ -3,66 +3,65 @@ package org.atriasoft.ewol;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector2i;
|
||||
|
||||
/** @file
|
||||
/**
|
||||
* @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
public class DrawProperty {
|
||||
//@formatter:off
|
||||
/*
|
||||
/-. windowsSize
|
||||
*--------------------------------------------------*
|
||||
| |
|
||||
| |
|
||||
| size |
|
||||
| / |
|
||||
| o-------------------o |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| o-------------------o |
|
||||
| / |
|
||||
| origin |
|
||||
| |
|
||||
*--------------------------------------------------*
|
||||
/
|
||||
(0,0)
|
||||
/- windowsSize
|
||||
*--------------------------------------------------*
|
||||
| |
|
||||
| |
|
||||
| size |
|
||||
| / |
|
||||
| o-------------------o |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| | | |
|
||||
| o-------------------o |
|
||||
| / |
|
||||
| origin |
|
||||
| |
|
||||
*--------------------------------------------------*
|
||||
/
|
||||
(0,0)
|
||||
*/
|
||||
public Vector2i windowsSize = new Vector2i(0, 0); //!< Windows complete size
|
||||
public Vector2i origin = new Vector2i(0, 0); //!< Windows clipping upper widget (can not be <0)
|
||||
public Vector2i size = new Vector2i(0, 0); //!< Windows clipping upper widget (can not be <0 and >this.windowsSize)
|
||||
|
||||
//@formatter:on
|
||||
public record DrawProperty(
|
||||
Vector2i windowsSize, // !< Windows complete size
|
||||
Vector2i origin, // !< Windows clipping upper widget (can not be <0)
|
||||
Vector2i size// !< Windows clipping upper widget (can not be <0 and >this.windowsSize)
|
||||
) {
|
||||
public DrawProperty() {
|
||||
|
||||
this(Vector2i.ZERO,Vector2i.ZERO,Vector2i.ZERO);
|
||||
}
|
||||
|
||||
|
||||
public DrawProperty(final Vector2i windowsSize, final Vector2i origin, final Vector2i size) {
|
||||
super();
|
||||
this.windowsSize = windowsSize;
|
||||
this.origin = origin;
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DrawProperty clone() {
|
||||
return new DrawProperty(this.windowsSize, this.origin, this.size);
|
||||
|
||||
public DrawProperty withLimit(final Vector2f _origin, final Vector2f _size) {
|
||||
Vector2i tmpSize = this.size.add(this.origin);
|
||||
Vector2i origin = this.origin.max((int) _origin.x(), (int) _origin.y());
|
||||
tmpSize = tmpSize.min((int) (_origin.x() + _size.x()), (int) (_origin.y() + _size.y()));
|
||||
tmpSize = tmpSize.less(origin);
|
||||
return new DrawProperty(windowsSize, origin, tmpSize);
|
||||
}
|
||||
|
||||
public void limit(final Vector2f _origin, final Vector2f _size) {
|
||||
this.size.add(this.origin);
|
||||
this.origin.setMax((int) _origin.x, (int) _origin.y);
|
||||
this.size.setMin((int) (_origin.x + _size.x), (int) (_origin.y + _size.y));
|
||||
this.size.less(this.origin);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DrawProperty [windowsSize=" + this.windowsSize + ", start=" + this.origin + ", stop=" + this.origin.add(this.size) + "]";
|
||||
return "DrawProperty [windowsSize=" + this.windowsSize + ", start=" + this.origin + ", stop="
|
||||
+ this.origin.add(this.size) + "]";
|
||||
}
|
||||
}
|
||||
|
@ -11,37 +11,38 @@ import org.atriasoft.etk.math.Vector2f;
|
||||
* @brief Gravity of the widget property
|
||||
*/
|
||||
public enum Gravity {
|
||||
center, //!< gravity is in center
|
||||
top, //!< gravity is in top
|
||||
buttom, //!< gravity is in buttom
|
||||
right, //!< gravity is in right
|
||||
left, //!< gravity is in left
|
||||
topRight, //!< gravity is in top-right
|
||||
topLeft, //!< gravity is in top-left
|
||||
buttomRight, //!< gravity is in buttom-right
|
||||
buttomLeft; //!< gravity is in buttom-left
|
||||
|
||||
Vector2f gravityGenerateDelta(final Gravity _gravity, final Vector2f _deltas) {
|
||||
final Vector2f out = new Vector2f(0.0f, 0.0f);
|
||||
if (_deltas.x > 0.0001f) {
|
||||
center, // !< gravity is in center
|
||||
top, // !< gravity is in top
|
||||
buttom, // !< gravity is in buttom
|
||||
right, // !< gravity is in right
|
||||
left, // !< gravity is in left
|
||||
topRight, // !< gravity is in top-right
|
||||
topLeft, // !< gravity is in top-left
|
||||
buttomRight, // !< gravity is in buttom-right
|
||||
buttomLeft; // !< gravity is in buttom-left
|
||||
|
||||
public static Vector2f gravityGenerateDelta(final Gravity _gravity, final Vector2f _deltas) {
|
||||
float outX = 0;
|
||||
float outY = 0;
|
||||
if (_deltas.x() > 0.0001f) {
|
||||
if (_gravity == left || _gravity == buttomLeft || _gravity == topLeft) {
|
||||
// nothing to do
|
||||
} else if (_gravity == right || _gravity == buttomRight || _gravity == topRight) {
|
||||
out.x = (int) (_deltas.x);
|
||||
outX = (int) (_deltas.x());
|
||||
} else {
|
||||
out.x = (int) (_deltas.x * 0.5f);
|
||||
outX = (int) (_deltas.x() * 0.5f);
|
||||
}
|
||||
}
|
||||
if (_deltas.y > 0.0001f) {
|
||||
if (_deltas.y() > 0.0001f) {
|
||||
if (_gravity == buttom || _gravity == buttomLeft || _gravity == buttomRight) {
|
||||
// nothing to do
|
||||
} else if (_gravity == top || _gravity == topRight || _gravity == topLeft) {
|
||||
out.y = (int) (_deltas.y);
|
||||
outY = (int) (_deltas.y());
|
||||
} else {
|
||||
out.y = (int) (_deltas.y * 0.5f);
|
||||
outY = (int) (_deltas.y() * 0.5f);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
return new Vector2f(outX, outY);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
package org.atriasoft.ewol;
|
||||
|
||||
/**
|
||||
* @breif Simple class to abstarct the padding porperty.
|
||||
@ -11,32 +12,32 @@ public class Padding {
|
||||
private float xLeft;
|
||||
private float yTop;
|
||||
private float xRight;
|
||||
private float yBottom; //!< this represent the 4 padding value Left top right buttom (like css)
|
||||
|
||||
private float yBottom; // !< this represent the 4 padding value Left top right buttom (like css)
|
||||
|
||||
public Padding() {
|
||||
setValue();
|
||||
}
|
||||
|
||||
|
||||
public Padding(final float _xLeft) {
|
||||
setValue(_xLeft);
|
||||
}
|
||||
|
||||
|
||||
public Padding(final float _xLeft, final float _yt) {
|
||||
setValue(_xLeft, _yt);
|
||||
}
|
||||
|
||||
|
||||
public Padding(final float _xLeft, final float _yt, final float _xr) {
|
||||
setValue(_xLeft, _yt, _xr);
|
||||
}
|
||||
|
||||
|
||||
public Padding(final float _xLeft, final float _yt, final float _xr, final float _yb) {
|
||||
setValue(_xLeft, _yt, _xr, _yb);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Add a vector to this one
|
||||
* @param _v The vector to add to this one
|
||||
*/
|
||||
* @brief Add a vector to this one
|
||||
* @param _v The vector to add to this one
|
||||
*/
|
||||
public Padding add(final Padding _v) {
|
||||
this.xLeft += _v.xLeft;
|
||||
this.yTop += _v.yTop;
|
||||
@ -44,88 +45,89 @@ public class Padding {
|
||||
this.yBottom += _v.yBottom;
|
||||
return this;
|
||||
}
|
||||
|
||||
//! @previous
|
||||
|
||||
// ! @previous
|
||||
public Padding addNew(final Padding _v) {
|
||||
return new Padding(this.xLeft + _v.xLeft, this.yTop + _v.yTop, this.xRight + _v.xRight, this.yBottom + _v.yBottom);
|
||||
return new Padding(this.xLeft + _v.xLeft, this.yTop + _v.yTop, this.xRight + _v.xRight,
|
||||
this.yBottom + _v.yBottom);
|
||||
}
|
||||
|
||||
|
||||
public void setValue() {
|
||||
this.xLeft = 0;
|
||||
this.yTop = 0;
|
||||
this.xRight = 0;
|
||||
this.yBottom = 0;
|
||||
}
|
||||
|
||||
|
||||
public void setValue(final float _xLeft) {
|
||||
this.xLeft = _xLeft;
|
||||
this.yTop = 0;
|
||||
this.xRight = 0;
|
||||
this.yBottom = 0;
|
||||
}
|
||||
|
||||
|
||||
public void setValue(final float _xLeft, final float _yt) {
|
||||
this.xLeft = _xLeft;
|
||||
this.yTop = _yt;
|
||||
this.xRight = 0;
|
||||
this.yBottom = 0;
|
||||
}
|
||||
|
||||
|
||||
public void setValue(final float _xLeft, final float _yt, final float _xr) {
|
||||
this.xLeft = _xLeft;
|
||||
this.yTop = _yt;
|
||||
this.xRight = _xr;
|
||||
this.yBottom = 0;
|
||||
}
|
||||
|
||||
|
||||
public void setValue(final float _xLeft, final float _yt, final float _xr, final float _yb) {
|
||||
this.xLeft = _xLeft;
|
||||
this.yTop = _yt;
|
||||
this.xRight = _xr;
|
||||
this.yBottom = _yb;
|
||||
}
|
||||
|
||||
|
||||
public void setXLeft(final float _val) {
|
||||
this.xLeft = _val;
|
||||
}
|
||||
|
||||
|
||||
public void setXRight(final float _val) {
|
||||
this.xRight = _val;
|
||||
}
|
||||
|
||||
|
||||
public void setYButtom(final float _val) {
|
||||
this.yBottom = _val;
|
||||
}
|
||||
|
||||
|
||||
public void setYTop(final float _val) {
|
||||
this.yTop = _val;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + xLeft() + "," + yTop() + "," + xRight() + "," + yButtom() + "}";
|
||||
}
|
||||
|
||||
|
||||
public float x() {
|
||||
return this.xLeft + this.xRight;
|
||||
}
|
||||
|
||||
|
||||
public float xLeft() {
|
||||
return this.xLeft;
|
||||
}
|
||||
|
||||
|
||||
public float xRight() {
|
||||
return this.xRight;
|
||||
}
|
||||
|
||||
|
||||
public float y() {
|
||||
return this.yTop + this.yBottom;
|
||||
}
|
||||
|
||||
|
||||
public float yButtom() {
|
||||
return this.yBottom;
|
||||
}
|
||||
|
||||
|
||||
public float yTop() {
|
||||
return this.yTop;
|
||||
}
|
||||
|
@ -10,13 +10,13 @@ import org.atriasoft.etk.math.Vector3f;
|
||||
*/
|
||||
|
||||
public abstract class Compositing {
|
||||
protected Matrix4f matrixApply = Matrix4f.identity();
|
||||
protected Matrix4f matrixApply = Matrix4f.IDENTITY;;
|
||||
|
||||
/**
|
||||
* @brief clear alll tre registered element in the current element
|
||||
*/
|
||||
public void clear() {
|
||||
this.matrixApply.setIdentity();
|
||||
this.matrixApply = Matrix4f.IDENTITY;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,7 +32,7 @@ public abstract class Compositing {
|
||||
* @brief reset to the eye matrix the openGL mouving system
|
||||
*/
|
||||
public void resetMatrix() {
|
||||
this.matrixApply.setIdentity();
|
||||
this.matrixApply = Matrix4f.IDENTITY;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +40,7 @@ public abstract class Compositing {
|
||||
* @param[in] _vect The rotation vector to apply at the transformation matrix
|
||||
*/
|
||||
public void rotate(final Vector3f _vect, final float _angle) {
|
||||
this.matrixApply.multiply(Matrix4f.createMatrixRotate(_vect, _angle));
|
||||
this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixRotate(_vect, _angle));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,7 +48,7 @@ public abstract class Compositing {
|
||||
* @param[in] _vect The scaling vector to apply at the transformation matrix
|
||||
*/
|
||||
public void scale(final Vector3f _vect) {
|
||||
this.matrixApply.multiply(Matrix4f.createMatrixScale(_vect));
|
||||
this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixScale(_vect));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,6 +64,6 @@ public abstract class Compositing {
|
||||
* @param[in] _vect The translation vector to apply at the transformation matrix
|
||||
*/
|
||||
public void translate(final Vector3f _vect) {
|
||||
this.matrixApply.multiply(Matrix4f.createMatrixTranslate(_vect));
|
||||
this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixTranslate(_vect));
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import org.atriasoft.gale.backend3d.OpenGL;
|
||||
import org.atriasoft.gale.resource.ResourceProgram;
|
||||
import org.atriasoft.gale.resource.ResourceVirtualBufferObject;
|
||||
|
||||
class Drawing extends Compositing {
|
||||
public class CompositingDrawing extends Compositing {
|
||||
|
||||
protected static int vboIdCoord = 0;
|
||||
protected static int vboIdColor = 1;
|
||||
@ -50,7 +50,7 @@ class Drawing extends Compositing {
|
||||
/**
|
||||
* @brief Basic ructor
|
||||
*/
|
||||
public Drawing() {
|
||||
public CompositingDrawing() {
|
||||
loadProgram();
|
||||
for (int iii = 0; iii < 3; iii++) {
|
||||
this.triangle[iii] = this.position;
|
||||
@ -58,10 +58,6 @@ class Drawing extends Compositing {
|
||||
}
|
||||
// Create the VBO:
|
||||
this.VBO = ResourceVirtualBufferObject.create(4);
|
||||
if (this.VBO == null) {
|
||||
Log.error("can not instanciate VBO ...");
|
||||
return;
|
||||
}
|
||||
// TO facilitate some debugs we add a name of the VBO:
|
||||
this.VBO.setName("[VBO] of ewol::compositing::Area");
|
||||
}
|
||||
@ -189,8 +185,8 @@ class Drawing extends Compositing {
|
||||
|
||||
// push data on the VBO
|
||||
// TODO optimize this with single push when needed
|
||||
this.VBO.setVboData(Drawing.vboIdCoord, this.outTriangles.toArray(Vector3f[]::new));
|
||||
this.VBO.setVboData(Drawing.vboIdColor, this.outColors.toArray(Color[]::new));
|
||||
this.VBO.setVboData(CompositingDrawing.vboIdCoord, this.outTriangles.toArray(Vector3f[]::new));
|
||||
this.VBO.setVboData(CompositingDrawing.vboIdColor, this.outColors.toArray(Color[]::new));
|
||||
this.VBO.flush();
|
||||
|
||||
if (this.GLprogram == null) {
|
||||
@ -198,16 +194,16 @@ class Drawing extends Compositing {
|
||||
return;
|
||||
}
|
||||
// set Matrix : translation/positionMatrix
|
||||
Matrix4f tmpMatrix = OpenGL.getMatrix().multiplyNew(this.matrixApply);
|
||||
Matrix4f tmpMatrix = OpenGL.getMatrix().multiply(this.matrixApply);
|
||||
this.GLprogram.use();
|
||||
this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix);
|
||||
this.GLprogram.uniformMatrix(this.GLMatrixPosition, Matrix4f.identity());
|
||||
this.GLprogram.uniformMatrix(this.GLMatrixPosition, Matrix4f.IDENTITY);
|
||||
// position:
|
||||
this.GLprogram.sendAttributePointer(this.GLPosition, this.VBO, Drawing.vboIdCoord);
|
||||
this.GLprogram.sendAttributePointer(this.GLPosition, this.VBO, CompositingDrawing.vboIdCoord);
|
||||
// color:
|
||||
this.GLprogram.sendAttributePointer(this.GLColor, this.VBO, Drawing.vboIdColor);
|
||||
this.GLprogram.sendAttributePointer(this.GLColor, this.VBO, CompositingDrawing.vboIdColor);
|
||||
// Request the draw od the elements :
|
||||
OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, this.VBO.bufferSize(Drawing.vboIdCoord));
|
||||
OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, this.VBO.bufferSize(CompositingDrawing.vboIdCoord));
|
||||
this.GLprogram.unUse();
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.atriasoft.echrono.Clock;
|
||||
import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector2i;
|
||||
import org.atriasoft.etranslate.ETranslate;
|
||||
import org.atriasoft.ewol.event.EntrySystem;
|
||||
import org.atriasoft.ewol.internal.Log;
|
||||
import org.atriasoft.ewol.object.ObjectManager;
|
||||
@ -29,7 +30,7 @@ import org.atriasoft.gale.resource.ResourceManager;
|
||||
// Here we hereted from the gale application to be agnostic of the OW where we work ...
|
||||
public abstract class EwolContext extends Application {
|
||||
private static EwolContext curentInterface = null;
|
||||
|
||||
|
||||
/**
|
||||
* @brief From everyware in the program, we can get the context inteface.
|
||||
* @return current reference on the instance.
|
||||
@ -37,39 +38,37 @@ public abstract class EwolContext extends Application {
|
||||
public static EwolContext getContext() {
|
||||
return curentInterface;
|
||||
}
|
||||
|
||||
private EwolApplication application; //!< Application handle
|
||||
|
||||
public EwolApplication getApplication() {
|
||||
return this.application;
|
||||
}
|
||||
|
||||
public CommandLine getCmd() {
|
||||
return Gale.getContext().getCmd();
|
||||
}
|
||||
|
||||
private ConfigFont configFont; //!< global font configuration
|
||||
|
||||
public ConfigFont getFontDefault() {
|
||||
return this.configFont;
|
||||
}
|
||||
|
||||
private final ObjectManager objectManager; //!< Object Manager main instance
|
||||
|
||||
public ObjectManager getEObjectManager() {
|
||||
return this.objectManager;
|
||||
}
|
||||
|
||||
private WidgetManager widgetManager; //!< global widget manager
|
||||
|
||||
public WidgetManager getWidgetManager() {
|
||||
return this.widgetManager;
|
||||
}
|
||||
|
||||
public ResourceManager getResourcesManager() {
|
||||
return Gale.getContext().getResourcesManager();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief This is the only one things the User might done in his main();
|
||||
* @note : must be implemented in all system OPS implementation
|
||||
* @note To answare you before you ask the question, this is really simple: Due
|
||||
* to the fect that the current system is multiple-platform, you "main"
|
||||
* Does not exist in the android platform, then ewol call other start and
|
||||
* stop function, to permit to have only one code
|
||||
* @note The main can not be in the ewol, due to the fact thet is an librairy
|
||||
* @param[in] _argc Standard argc
|
||||
* @param[in] _argv Standard argv
|
||||
* @return normal error int for the application error management
|
||||
*/
|
||||
public static int main(String[] _args);
|
||||
|
||||
private EwolApplication application; // !< Application handle
|
||||
|
||||
private ConfigFont configFont; // !< global font configuration
|
||||
|
||||
private final ObjectManager objectManager; // !< Object Manager main instance
|
||||
|
||||
private WidgetManager widgetManager; // !< global widget manager
|
||||
|
||||
private final InputManager input;
|
||||
|
||||
private Windows windowsCurrent = null; // !< current displayed windows
|
||||
|
||||
private final int initStepId = 0;
|
||||
|
||||
private final int initTotalStep = 0;
|
||||
|
||||
public EwolContext(final EwolApplication _application) {
|
||||
this.application = _application;
|
||||
this.objectManager = new ObjectManager(this);
|
||||
@ -78,22 +77,94 @@ public abstract class EwolContext extends Application {
|
||||
Log.critical("Can not start context with no Application ==> rtfm ...");
|
||||
}
|
||||
}
|
||||
|
||||
private final InputManager input;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Redraw all the windows
|
||||
*/
|
||||
public void forceRedrawAll() {
|
||||
if (this.windowsCurrent == null) {
|
||||
return;
|
||||
}
|
||||
final Vector2f size = getSize();
|
||||
this.windowsCurrent.setSize(new Vector2f((int) size.x(), (int) size.y()));
|
||||
this.windowsCurrent.onChangeSize();
|
||||
}
|
||||
|
||||
public EwolApplication getApplication() {
|
||||
return this.application;
|
||||
}
|
||||
|
||||
public CommandLine getCmd() {
|
||||
return Gale.getContext().getCmd();
|
||||
}
|
||||
|
||||
public ObjectManager getEObjectManager() {
|
||||
return this.objectManager;
|
||||
}
|
||||
|
||||
public ConfigFont getFontDefault() {
|
||||
return this.configFont;
|
||||
}
|
||||
|
||||
public ResourceManager getResourcesManager() {
|
||||
return Gale.getContext().getResourcesManager();
|
||||
}
|
||||
|
||||
public WidgetManager getWidgetManager() {
|
||||
return this.widgetManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current windows that is displayed
|
||||
* @return the current handle on the windows (can be null)
|
||||
*/
|
||||
public Windows getWindows() {
|
||||
return this.windowsCurrent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This fonction lock the pointer properties to move in relative instead
|
||||
* of absolute
|
||||
* @param[in] widget The widget that lock the pointer events
|
||||
*/
|
||||
public void inputEventGrabPointer(final Widget _widget) {
|
||||
this.input.grabPointer(_widget);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This is to transfert the event from one widget to another one
|
||||
* @param source the widget where the event came from
|
||||
* @param destination the widget where the event mitgh be generated now
|
||||
*/
|
||||
public void inputEventTransfertWidget(final Widget _source, final Widget _destination) {
|
||||
this.input.transfertEvent(_source, _destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This fonction un-lock the pointer properties to move in relative
|
||||
* instead of absolute
|
||||
*/
|
||||
public void inputEventUnGrabPointer() {
|
||||
this.input.unGrabPointer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClipboardEvent(final ClipboardList _clipboardId) {
|
||||
final Widget tmpWidget = this.widgetManager.focusGet();
|
||||
if (tmpWidget != null) {
|
||||
tmpWidget.onEventClipboard(_clipboardId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final Context _context) {
|
||||
Log.info(" == > Ewol system create (BEGIN)");
|
||||
// Add basic ewol translation:
|
||||
//etranslate::addPath("ewol", "DATA:///translate/ewol/?lib=ewol");
|
||||
//etranslate::autoDetectLanguage();
|
||||
// By default we set 2 themes (1 color and 1 shape ...) :
|
||||
etk::theme::setNameDefault("GUI", "shape/square/");
|
||||
etk::theme::setNameDefault("COLOR", "color/black/");
|
||||
ETranslate.addPath("ewol", new Uri("DATA", "translate/ewol/", "ewol"));
|
||||
ETranslate.autoDetectLanguage();
|
||||
// parse for help:
|
||||
for(int iii = 0; iii < _context.getCmd().size() ; ++iii) {
|
||||
if ( _context.getCmd().get(iii) == "-h"
|
||||
|| _context.getCmd().get(iii) == "--help") {
|
||||
for (int iii = 0; iii < _context.getCmd().size(); ++iii) {
|
||||
if (_context.getCmd().get(iii) == "-h" || _context.getCmd().get(iii) == "--help") {
|
||||
Log.print("ewol - help : ");
|
||||
Log.print(" xxxxxxxxxxxxx [options]");
|
||||
Log.print(" -h/--help: Display this help");
|
||||
@ -107,22 +178,18 @@ public abstract class EwolContext extends Application {
|
||||
_context.getCmd().remove(iii);
|
||||
--iii;
|
||||
}
|
||||
|
||||
//Log.info("EWOL v:" + ewol::getVersion());
|
||||
|
||||
// Log.info("EWOL v:" + ewol::getVersion());
|
||||
// force a recalculation
|
||||
/*
|
||||
requestUpdateSize(){
|
||||
Context context = gale::getContext();
|
||||
context.requestUpdateSize();
|
||||
}
|
||||
#if defined(__EWOL_ANDROID_ORIENTATION_LANDSCAPE__)
|
||||
forceOrientation(ewol::screenLandscape);
|
||||
#elif defined(__EWOL_ANDROID_ORIENTATION_PORTRAIT__)
|
||||
forceOrientation(ewol::screenPortrait);
|
||||
#else
|
||||
forceOrientation(ewol::screenAuto);
|
||||
#endif
|
||||
*/
|
||||
* requestUpdateSize(){ Context context = gale::getContext();
|
||||
* context.requestUpdateSize(); } #if
|
||||
* defined(__EWOL_ANDROID_ORIENTATION_LANDSCAPE__)
|
||||
* forceOrientation(ewol::screenLandscape); #elif
|
||||
* defined(__EWOL_ANDROID_ORIENTATION_PORTRAIT__)
|
||||
* forceOrientation(ewol::screenPortrait); #else
|
||||
* forceOrientation(ewol::screenAuto); #endif
|
||||
*/
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
Log.error(" == > Create without application");
|
||||
@ -131,82 +198,7 @@ public abstract class EwolContext extends Application {
|
||||
appl.onCreate(this);
|
||||
Log.info(" == > Ewol system create (END)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(final Context _context) {
|
||||
Log.info(" == > Ewol system start (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
// TODO : Request exit of the application .... with error ...
|
||||
return;
|
||||
}
|
||||
appl.onStart(this);
|
||||
Log.info(" == > Ewol system start (END)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(final Context _context) {
|
||||
Log.info(" == > Ewol system resume (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
return;
|
||||
}
|
||||
appl.onResume(this);
|
||||
Log.info(" == > Ewol system resume (END)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRegenerateDisplay(final Context _context) {
|
||||
//Log.info("REGENERATE_DISPLAY");
|
||||
// check if the user selected a windows
|
||||
final Windows window = this.windowsCurrent;
|
||||
if (window == null) {
|
||||
Log.debug("No windows ...");
|
||||
return;
|
||||
}
|
||||
// Redraw all needed elements
|
||||
window.onRegenerateDisplay();
|
||||
if (this.widgetManager.isDrawingNeeded() == true) {
|
||||
markDrawingIsNeeded();
|
||||
}
|
||||
//markDrawingIsNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(final Context _context) {
|
||||
//Log.info("DRAW");
|
||||
// clean internal data...
|
||||
this.objectManager.cleanInternalRemoved();
|
||||
// real draw...
|
||||
final Windows window = this.windowsCurrent;
|
||||
if (window == null) {
|
||||
return;
|
||||
}
|
||||
window.sysDraw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(final Context _context) {
|
||||
Log.info(" == > Ewol system pause (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
return;
|
||||
}
|
||||
appl.onPause(this);
|
||||
Log.info(" == > Ewol system pause (END)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(final Context _context) {
|
||||
Log.info(" == > Ewol system stop (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
return;
|
||||
}
|
||||
appl.onStop(this);
|
||||
Log.info(" == > Ewol system stop (END)");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy(final Context _context) {
|
||||
Log.info(" == > Ewol system destroy (BEGIN)");
|
||||
@ -228,42 +220,23 @@ public abstract class EwolContext extends Application {
|
||||
this.objectManager.unInit();
|
||||
Log.info(" == > Ewol system destroy (END)");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onKillDemand(final Context _context) {
|
||||
Log.info(" == > User demand a destroy (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
exit(0);
|
||||
public void onDraw(final Context _context) {
|
||||
// Log.info("DRAW");
|
||||
// clean internal data...
|
||||
this.objectManager.cleanInternalRemoved();
|
||||
// real draw...
|
||||
final Windows window = this.windowsCurrent;
|
||||
if (window == null) {
|
||||
return;
|
||||
}
|
||||
appl.onKillDemand(this);
|
||||
Log.info(" == > User demand a destroy (END)");
|
||||
window.sysDraw();
|
||||
}
|
||||
|
||||
public void onPointer(final KeyType _type, final int _pointerID, final Vector2f _pos, final KeyStatus _state) {
|
||||
switch (_state) {
|
||||
case move:
|
||||
//Log.debug("Receive MSG : THREAD_INPUT_MOTION");
|
||||
this.input.motion(_type, _pointerID, _pos);
|
||||
break;
|
||||
case down:
|
||||
case downRepeate:
|
||||
//Log.debug("Receive MSG : THREAD_INPUT_STATE");
|
||||
this.input.state(_type, _pointerID, true, _pos);
|
||||
break;
|
||||
case up:
|
||||
//Log.debug("Receive MSG : THREAD_INPUT_STATE");
|
||||
this.input.state(_type, _pointerID, false, _pos);
|
||||
break;
|
||||
default:
|
||||
Log.debug("Unknow state : " + _state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onKeyboard(final KeySpecial _special, final KeyKeyboard _type, final Character _value, final KeyStatus _state) {
|
||||
public void onKeyboard(final KeySpecial _special, final KeyKeyboard _type, final Character _value,
|
||||
final KeyStatus _state) {
|
||||
Log.verbose("event {" + _special + "} " + _type + " " + _value + " " + _state);
|
||||
// store the keyboard special key status for mouse event...
|
||||
this.input.setLastKeyboardSpecial(_special);
|
||||
@ -284,7 +257,8 @@ public abstract class EwolContext extends Application {
|
||||
return;
|
||||
}
|
||||
// check if the widget allow repeating key events.
|
||||
//Log.info("repeating test :" + repeate + " widget=" + tmpWidget.getKeyboardRepeate() + " state=" + isDown);
|
||||
// Log.info("repeating test :" + repeate + " widget=" +
|
||||
// tmpWidget.getKeyboardRepeate() + " state=" + isDown);
|
||||
if (repeate == false || (repeate == true && tmpWidget.getKeyboardRepeat() == true)) {
|
||||
// check Widget shortcut
|
||||
if (tmpWidget.onEventShortCut(_special, _value, _type, isDown) == false) {
|
||||
@ -311,24 +285,134 @@ public abstract class EwolContext extends Application {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClipboardEvent(final ClipboardList _clipboardId) {
|
||||
final Widget tmpWidget = this.widgetManager.focusGet();
|
||||
if (tmpWidget != null) {
|
||||
tmpWidget.onEventClipboard(_clipboardId);
|
||||
public void onKillDemand(final Context _context) {
|
||||
Log.info(" == > User demand a destroy (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
exit(0);
|
||||
return;
|
||||
}
|
||||
appl.onKillDemand(this);
|
||||
Log.info(" == > User demand a destroy (END)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(final Context _context) {
|
||||
Log.info(" == > Ewol system pause (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
return;
|
||||
}
|
||||
appl.onPause(this);
|
||||
Log.info(" == > Ewol system pause (END)");
|
||||
};
|
||||
|
||||
public void onPeriod(final Clock _time) {
|
||||
this.objectManager.timeCall(_time);
|
||||
}
|
||||
|
||||
public void onPointer(final KeyType _type, final int _pointerID, final Vector2f _pos, final KeyStatus _state) {
|
||||
switch (_state) {
|
||||
case move:
|
||||
// Log.debug("Receive MSG : THREAD_INPUT_MOTION");
|
||||
this.input.motion(_type, _pointerID, _pos);
|
||||
break;
|
||||
case down:
|
||||
case downRepeate:
|
||||
// Log.debug("Receive MSG : THREAD_INPUT_STATE");
|
||||
this.input.state(_type, _pointerID, true, _pos);
|
||||
break;
|
||||
case up:
|
||||
// Log.debug("Receive MSG : THREAD_INPUT_STATE");
|
||||
this.input.state(_type, _pointerID, false, _pos);
|
||||
break;
|
||||
default:
|
||||
Log.debug("Unknow state : " + _state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onRegenerateDisplay(final Context _context) {
|
||||
// Log.info("REGENERATE_DISPLAY");
|
||||
// check if the user selected a windows
|
||||
final Windows window = this.windowsCurrent;
|
||||
if (window == null) {
|
||||
Log.debug("No windows ...");
|
||||
return;
|
||||
}
|
||||
// Redraw all needed elements
|
||||
window.onRegenerateDisplay();
|
||||
if (this.widgetManager.isDrawingNeeded() == true) {
|
||||
markDrawingIsNeeded();
|
||||
}
|
||||
// markDrawingIsNeeded();
|
||||
}
|
||||
|
||||
public void onResize(final Vector2i _size) {
|
||||
Log.verbose("Resize: " + _size);
|
||||
forceRedrawAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(final Context _context) {
|
||||
Log.info(" == > Ewol system resume (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
return;
|
||||
}
|
||||
appl.onResume(this);
|
||||
Log.info(" == > Ewol system resume (END)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart(final Context _context) {
|
||||
Log.info(" == > Ewol system start (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
// TODO : Request exit of the application .... with error ...
|
||||
return;
|
||||
}
|
||||
appl.onStart(this);
|
||||
Log.info(" == > Ewol system start (END)");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop(final Context _context) {
|
||||
Log.info(" == > Ewol system stop (BEGIN)");
|
||||
final EwolApplication appl = this.application;
|
||||
if (appl == null) {
|
||||
return;
|
||||
}
|
||||
appl.onStop(this);
|
||||
Log.info(" == > Ewol system stop (END)");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request a display after call a resize
|
||||
*/
|
||||
public void requestUpdateSize() {
|
||||
final Context context = Gale.getContext();
|
||||
context.requestUpdateSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief reset event management for the IO like Input ou Mouse or keyborad
|
||||
*/
|
||||
public void resetIOEvent() {
|
||||
this.input.newLayerSet();
|
||||
}
|
||||
|
||||
private Windows windowsCurrent = null; //!< current displayed windows
|
||||
|
||||
|
||||
/**
|
||||
* @brief Special for init (main) set the start image when loading data
|
||||
* @param[in] _fileName Name of the image to load
|
||||
*/
|
||||
public void setInitImage(final Uri _fileName) {
|
||||
// this.initDisplayImageName = _fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set the current windows to display :
|
||||
* @param _windows Windows that might be displayed
|
||||
@ -349,90 +433,4 @@ public abstract class EwolContext extends Application {
|
||||
// request all the widget redrawing
|
||||
forceRedrawAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief get the current windows that is displayed
|
||||
* @return the current handle on the windows (can be null)
|
||||
*/
|
||||
public Windows getWindows() {
|
||||
return this.windowsCurrent;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Redraw all the windows
|
||||
*/
|
||||
public void forceRedrawAll() {
|
||||
if (this.windowsCurrent == null) {
|
||||
return;
|
||||
}
|
||||
final Vector2f size = getSize();
|
||||
this.windowsCurrent.setSize(new Vector2f((int) size.x(), (int) size.y()));
|
||||
this.windowsCurrent.onChangeSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This is to transfert the event from one widget to another one
|
||||
* @param source the widget where the event came from
|
||||
* @param destination the widget where the event mitgh be generated now
|
||||
*/
|
||||
public void inputEventTransfertWidget(final Widget _source, final Widget _destination) {
|
||||
this.input.transfertEvent(_source, _destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This fonction lock the pointer properties to move in relative instead of absolute
|
||||
* @param[in] widget The widget that lock the pointer events
|
||||
*/
|
||||
public void inputEventGrabPointer(final Widget _widget) {
|
||||
this.input.grabPointer(_widget);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This fonction un-lock the pointer properties to move in relative instead of absolute
|
||||
*/
|
||||
public void inputEventUnGrabPointer() {
|
||||
this.input.unGrabPointer();
|
||||
}
|
||||
|
||||
public void onResize(final Vector2i _size) {
|
||||
Log.verbose("Resize: " + _size);
|
||||
forceRedrawAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This is the only one things the User might done in his main();
|
||||
* @note : must be implemented in all system OPS implementation
|
||||
* @note To answare you before you ask the question, this is really simple:
|
||||
* Due to the fect that the current system is multiple-platform, you "main"
|
||||
* Does not exist in the android platform, then ewol call other start
|
||||
* and stop function, to permit to have only one code
|
||||
* @note The main can not be in the ewol, due to the fact thet is an librairy
|
||||
* @param[in] _argc Standard argc
|
||||
* @param[in] _argv Standard argv
|
||||
* @return normal error int for the application error management
|
||||
*/
|
||||
public static int main(String[] _args);
|
||||
|
||||
private final int initStepId = 0;
|
||||
private final int initTotalStep = 0;
|
||||
|
||||
/**
|
||||
* @brief Special for init (main) set the start image when loading data
|
||||
* @param[in] _fileName Name of the image to load
|
||||
*/
|
||||
public void setInitImage(final Uri _fileName) {
|
||||
//this.initDisplayImageName = _fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Request a display after call a resize
|
||||
*/
|
||||
public void requestUpdateSize() {
|
||||
final Context context = Gale.getContext();
|
||||
context.requestUpdateSize();
|
||||
}
|
||||
|
||||
public void onPeriod(final Clock _time) {
|
||||
this.objectManager.timeCall(_time);
|
||||
}
|
||||
}
|
||||
|
21
src/org/atriasoft/ewol/event/EventShortCut.java
Normal file
21
src/org/atriasoft/ewol/event/EventShortCut.java
Normal file
@ -0,0 +1,21 @@
|
||||
package org.atriasoft.ewol.event;
|
||||
|
||||
import org.atriasoft.gale.key.KeyKeyboard;
|
||||
import org.atriasoft.gale.key.KeySpecial;
|
||||
|
||||
public class EventShortCut {
|
||||
public final String message; //!< data link with the event
|
||||
public final KeySpecial specialKey; //!< special board key
|
||||
public final Character unicodeValue; //!< 0 if not used
|
||||
public final KeyKeyboard keyboardMoveValue; //!< ewol::EVENT_KB_MOVE_TYPE_NONE if not used
|
||||
public boolean isActive; //!< If true, we need to filter the up key of ascii element (not control)
|
||||
|
||||
public EventShortCut(final String message, final KeySpecial specialKey, final Character unicodeValue, final KeyKeyboard keyboardMoveValue, final boolean isActive) {
|
||||
super();
|
||||
this.message = message;
|
||||
this.specialKey = specialKey;
|
||||
this.unicodeValue = unicodeValue;
|
||||
this.keyboardMoveValue = keyboardMoveValue;
|
||||
this.isActive = isActive;
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ import java.lang.ref.WeakReference;
|
||||
import org.atriasoft.ewol.Ewol;
|
||||
import org.atriasoft.ewol.context.EwolContext;
|
||||
import org.atriasoft.ewol.internal.Log;
|
||||
import org.atriasoft.exml.model.XmlElement;
|
||||
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
@ -138,7 +139,9 @@ public class EwolObject {
|
||||
* @return true : All has been done corectly.
|
||||
* @return false : An error occured.
|
||||
*/
|
||||
//boolean loadXML( exml::Element _node);
|
||||
protected boolean loadXML(XmlElement _node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief store properties in this XML node.
|
||||
@ -200,7 +203,7 @@ public class EwolObject {
|
||||
/**
|
||||
* @brief Remove the current parenting.
|
||||
*/
|
||||
void removeParent() {
|
||||
public void removeParent() {
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
|
@ -18,37 +18,40 @@ import org.atriasoft.gale.resource.Resource;
|
||||
import org.atriasoft.gale.resource.ResourceProgram;
|
||||
|
||||
/**
|
||||
* @brief simple display of Colored3DObject ==> for DEBUG only Not availlable on ALL platform (like webGL)
|
||||
* @brief simple display of Colored3DObject ==> for DEBUG only Not availlable on
|
||||
* ALL platform (like webGL)
|
||||
*/
|
||||
public class RefactorColored3DObject extends Resource {
|
||||
protected ResourceProgram GLprogram;
|
||||
protected int GLPosition;
|
||||
protected int GLMatrix;
|
||||
protected int GLColor;
|
||||
|
||||
|
||||
public RefactorColored3DObject() {
|
||||
super();
|
||||
// get the shader resource :
|
||||
this.GLPosition = 0;
|
||||
this.GLprogram = ResourceProgram.create(new Uri("DATA:///simple3D.vert?lib=ewol"), new Uri("DATA:///simple3D.frag?lib=ewol"));
|
||||
this.GLprogram = ResourceProgram.create(new Uri("DATA:///simple3D.vert?lib=ewol"),
|
||||
new Uri("DATA:///simple3D.frag?lib=ewol"));
|
||||
if (this.GLprogram != null) {
|
||||
this.GLPosition = this.GLprogram.getAttribute("EW_coord3d");
|
||||
this.GLColor = this.GLprogram.getUniform("EW_color");
|
||||
this.GLMatrix = this.GLprogram.getUniform("EW_MatrixTransformation");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void draw(final List<Vector3f> _vertices, final Color _color) {
|
||||
draw(_vertices, _color, true, true);
|
||||
}
|
||||
|
||||
public void draw(final List<Vector3f> _vertices, final Color _color, final boolean _updateDepthBuffer, final boolean _depthtest) {
|
||||
|
||||
public void draw(final List<Vector3f> _vertices, final Color _color, final boolean _updateDepthBuffer,
|
||||
final boolean _depthtest) {
|
||||
if (_vertices.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
@ -62,8 +65,8 @@ public class RefactorColored3DObject extends Resource {
|
||||
OpenGL.setDeathMask(false);
|
||||
}
|
||||
}
|
||||
|
||||
//Log.debug(" display " + this.coord.size() + " elements" );
|
||||
|
||||
// Log.debug(" display " + this.coord.size() + " elements" );
|
||||
this.GLprogram.use();
|
||||
// set Matrix: translation/positionMatrix
|
||||
final Matrix4f projMatrix = OpenGL.getMatrix();
|
||||
@ -71,15 +74,16 @@ public class RefactorColored3DObject extends Resource {
|
||||
final Matrix4f tmpMatrix = projMatrix.multiplyNew(camMatrix);
|
||||
this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
this.GLprogram.sendAttribute(this.GLPosition, 3/*x,y,z,unused*/, ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3);
|
||||
this.GLprogram.sendAttribute(this.GLPosition, 3/* x,y,z,unused */,
|
||||
ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3);
|
||||
// color :
|
||||
this.GLprogram.uniformColor(this.GLColor, _color);
|
||||
// Request the draw od the elements:
|
||||
// Request the draw od the elements:
|
||||
OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, _vertices.size());
|
||||
this.GLprogram.unUse();
|
||||
// Request the draw od the elements:
|
||||
//glDrawArrays(GL_LINES, 0, vertices.size());
|
||||
//this.GLprogram.UnUse();
|
||||
// Request the draw od the elements:
|
||||
// glDrawArrays(GL_LINES, 0, vertices.size());
|
||||
// this.GLprogram.UnUse();
|
||||
if (true == _depthtest) {
|
||||
if (false == _updateDepthBuffer) {
|
||||
OpenGL.setDeathMask(true);
|
||||
@ -88,12 +92,13 @@ public class RefactorColored3DObject extends Resource {
|
||||
OpenGL.disable(OpenGL.Flag.flag_depthTest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void draw(final List<Vector3f> _vertices, final Color _color, final Matrix4f _transformationMatrix) {
|
||||
draw(_vertices, _color, _transformationMatrix, true, true);
|
||||
}
|
||||
|
||||
public void draw(final List<Vector3f> _vertices, final Color _color, final Matrix4f _transformationMatrix, final boolean _updateDepthBuffer, final boolean _depthtest) {
|
||||
|
||||
public void draw(final List<Vector3f> _vertices, final Color _color, final Matrix4f _transformationMatrix,
|
||||
final boolean _updateDepthBuffer, final boolean _depthtest) {
|
||||
if (_vertices.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
@ -107,7 +112,7 @@ public class RefactorColored3DObject extends Resource {
|
||||
OpenGL.setDeathMask(false);
|
||||
}
|
||||
}
|
||||
//Log.debug(" display " + this.coord.size() + " elements" );
|
||||
// Log.debug(" display " + this.coord.size() + " elements" );
|
||||
this.GLprogram.use();
|
||||
// set Matrix: translation/positionMatrix
|
||||
final Matrix4f projMatrix = OpenGL.getMatrix();
|
||||
@ -115,10 +120,11 @@ public class RefactorColored3DObject extends Resource {
|
||||
final Matrix4f tmpMatrix = projMatrix.multiplyNew(camMatrix).multiply(_transformationMatrix);
|
||||
this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
this.GLprogram.sendAttribute(this.GLPosition, 3/*x,y,z*/, ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3); // TODO : check 4->3
|
||||
this.GLprogram.sendAttribute(this.GLPosition, 3/* x,y,z */,
|
||||
ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3); // TODO : check 4->3
|
||||
// color :
|
||||
this.GLprogram.uniformColor(this.GLColor, _color);
|
||||
// Request the draw od the elements:
|
||||
// Request the draw od the elements:
|
||||
OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, _vertices.size());
|
||||
this.GLprogram.unUse();
|
||||
if (true == _depthtest) {
|
||||
@ -128,29 +134,30 @@ public class RefactorColored3DObject extends Resource {
|
||||
OpenGL.disable(OpenGL.Flag.flag_depthTest);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawCapsule(final float _radius, final float _size, int _lats, final int _longs, final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
|
||||
public void drawCapsule(final float _radius, final float _size, int _lats, final int _longs,
|
||||
final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
_lats = _lats / 2 * 2;
|
||||
|
||||
|
||||
// center to border (TOP)
|
||||
float offset = _size * 0.5f;
|
||||
for (int iii = _lats / 2 + 1; iii <= _lats; ++iii) {
|
||||
final float lat0 = (float) (Math.PI) * (-0.5f + (float) (iii - 1) / _lats);
|
||||
final float z0 = (float) (_radius * Math.sin(lat0));
|
||||
final float zr0 = (float) (_radius * Math.cos(lat0));
|
||||
|
||||
|
||||
final float lat1 = (float) (Math.PI) * (-0.5f + (float) (iii) / _lats);
|
||||
final float z1 = (float) (_radius * Math.sin(lat1));
|
||||
final float zr1 = (float) (_radius * Math.cos(lat1));
|
||||
|
||||
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
float x = (float) Math.cos(lng);
|
||||
float y = (float) Math.sin(lng);
|
||||
final Vector3f v1 = new Vector3f(x * zr1, y * zr1, z1 + offset);
|
||||
final Vector3f v4 = new Vector3f(x * zr0, y * zr0, z0 + offset);
|
||||
|
||||
|
||||
lng = 2 * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) Math.cos(lng);
|
||||
y = (float) Math.sin(lng);
|
||||
@ -159,7 +166,7 @@ public class RefactorColored3DObject extends Resource {
|
||||
tmpVertices.add(v1);
|
||||
tmpVertices.add(v2);
|
||||
tmpVertices.add(v3);
|
||||
|
||||
|
||||
tmpVertices.add(v1);
|
||||
tmpVertices.add(v3);
|
||||
tmpVertices.add(v4);
|
||||
@ -168,24 +175,24 @@ public class RefactorColored3DObject extends Resource {
|
||||
// Cylinder
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
|
||||
|
||||
final float z = _size * 0.5f;
|
||||
|
||||
|
||||
float x = (float) (Math.cos(lng) * _radius);
|
||||
float y = (float) (Math.sin(lng) * _radius);
|
||||
final Vector3f v2 = new Vector3f(x, y, z);
|
||||
final Vector3f v2b = new Vector3f(x, y, -z);
|
||||
|
||||
|
||||
lng = 2.0f * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) (Math.cos(lng) * _radius);
|
||||
y = (float) (Math.sin(lng) * _radius);
|
||||
final Vector3f v3 = new Vector3f(x, y, z);
|
||||
final Vector3f v3b = new Vector3f(x, y, -z);
|
||||
|
||||
|
||||
tmpVertices.add(v2);
|
||||
tmpVertices.add(v3);
|
||||
tmpVertices.add(v3b);
|
||||
|
||||
|
||||
tmpVertices.add(v2);
|
||||
tmpVertices.add(v3b);
|
||||
tmpVertices.add(v2b);
|
||||
@ -196,18 +203,18 @@ public class RefactorColored3DObject extends Resource {
|
||||
final float lat0 = (float) (Math.PI) * (-0.5f + (float) (iii - 1) / _lats);
|
||||
final float z0 = (float) (_radius * Math.sin(lat0));
|
||||
final float zr0 = (float) (_radius * Math.cos(lat0));
|
||||
|
||||
|
||||
final float lat1 = (float) (Math.PI) * (-0.5f + (float) (iii) / _lats);
|
||||
final float z1 = (float) (_radius * Math.sin(lat1));
|
||||
final float zr1 = (float) (_radius * Math.cos(lat1));
|
||||
|
||||
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
float x = (float) Math.cos(lng);
|
||||
float y = (float) Math.sin(lng);
|
||||
final Vector3f v1 = new Vector3f(x * zr1, y * zr1, z1 + offset);
|
||||
final Vector3f v4 = new Vector3f(x * zr0, y * zr0, z0 + offset);
|
||||
|
||||
|
||||
lng = 2 * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) Math.cos(lng);
|
||||
y = (float) Math.sin(lng);
|
||||
@ -216,7 +223,7 @@ public class RefactorColored3DObject extends Resource {
|
||||
tmpVertices.add(v1);
|
||||
tmpVertices.add(v2);
|
||||
tmpVertices.add(v3);
|
||||
|
||||
|
||||
tmpVertices.add(v1);
|
||||
tmpVertices.add(v3);
|
||||
tmpVertices.add(v4);
|
||||
@ -224,18 +231,19 @@ public class RefactorColored3DObject extends Resource {
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
public void drawCone(final float _radius, final float _size, final int _lats, final int _longs, final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
|
||||
public void drawCone(final float _radius, final float _size, final int _lats, final int _longs,
|
||||
final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
// center to border (TOP)
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
final Vector3f v1 = new Vector3f(0.0f, 0.0f, -_size / 2);
|
||||
|
||||
|
||||
float x = (float) (Math.cos(lng) * _radius);
|
||||
float y = (float) (Math.sin(lng) * _radius);
|
||||
final Vector3f v2 = new Vector3f(x, y, _size / 2);
|
||||
|
||||
|
||||
lng = 2.0f * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) (Math.cos(lng) * _radius);
|
||||
y = (float) (Math.sin(lng) * _radius);
|
||||
@ -247,13 +255,13 @@ public class RefactorColored3DObject extends Resource {
|
||||
// center to border (BUTTOM)
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
|
||||
|
||||
final Vector3f v1 = new Vector3f(0.0f, 0.0f, _size / 2);
|
||||
|
||||
|
||||
float x = (float) (Math.cos(lng) * _radius);
|
||||
float y = (float) (Math.sin(lng) * _radius);
|
||||
final Vector3f v2 = new Vector3f(x, y, _size / 2);
|
||||
|
||||
|
||||
lng = 2.0f * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) (Math.cos(lng) * _radius);
|
||||
y = (float) (Math.sin(lng) * _radius);
|
||||
@ -264,67 +272,70 @@ public class RefactorColored3DObject extends Resource {
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
public void drawCubeLine(final Vector3f _min, final Vector3f _max, final Color _color, final Matrix4f _transformationMatrix) {
|
||||
|
||||
public void drawCubeLine(final Vector3f _min, final Vector3f _max, final Color _color,
|
||||
final Matrix4f _transformationMatrix) {
|
||||
drawCubeLine(_min, _max, _color, _transformationMatrix, true, true);
|
||||
}
|
||||
|
||||
public void drawCubeLine(final Vector3f _min, final Vector3f _max, final Color _color, final Matrix4f _transformationMatrix, final boolean _updateDepthBuffer, final boolean _depthtest) {
|
||||
|
||||
public void drawCubeLine(final Vector3f _min, final Vector3f _max, final Color _color,
|
||||
final Matrix4f _transformationMatrix, final boolean _updateDepthBuffer, final boolean _depthtest) {
|
||||
final List<Vector3f> vertices = new ArrayList<>();
|
||||
vertices.add(new Vector3f(_min.x, _min.y, _min.z));
|
||||
vertices.add(new Vector3f(_max.x, _min.y, _min.z));
|
||||
|
||||
vertices.add(new Vector3f(_max.x, _min.y, _min.z));
|
||||
vertices.add(new Vector3f(_max.x, _min.y, _max.z));
|
||||
|
||||
vertices.add(new Vector3f(_max.x, _min.y, _max.z));
|
||||
vertices.add(new Vector3f(_min.x, _min.y, _max.z));
|
||||
|
||||
vertices.add(new Vector3f(_min.x, _min.y, _max.z));
|
||||
vertices.add(new Vector3f(_min.x, _min.y, _min.z));
|
||||
|
||||
vertices.add(new Vector3f(_min.x, _max.y, _min.z));
|
||||
vertices.add(new Vector3f(_max.x, _max.y, _min.z));
|
||||
|
||||
vertices.add(new Vector3f(_max.x, _max.y, _min.z));
|
||||
vertices.add(new Vector3f(_max.x, _max.y, _max.z));
|
||||
|
||||
vertices.add(new Vector3f(_max.x, _max.y, _max.z));
|
||||
vertices.add(new Vector3f(_min.x, _max.y, _max.z));
|
||||
|
||||
vertices.add(new Vector3f(_min.x, _max.y, _max.z));
|
||||
vertices.add(new Vector3f(_min.x, _max.y, _min.z));
|
||||
|
||||
vertices.add(new Vector3f(_min.x, _min.y, _min.z));
|
||||
vertices.add(new Vector3f(_min.x, _max.y, _min.z));
|
||||
|
||||
vertices.add(new Vector3f(_max.x, _min.y, _min.z));
|
||||
vertices.add(new Vector3f(_max.x, _max.y, _min.z));
|
||||
|
||||
vertices.add(new Vector3f(_max.x, _min.y, _max.z));
|
||||
vertices.add(new Vector3f(_max.x, _max.y, _max.z));
|
||||
|
||||
vertices.add(new Vector3f(_min.x, _min.y, _max.z));
|
||||
vertices.add(new Vector3f(_min.x, _max.y, _max.z));
|
||||
|
||||
vertices.add(new Vector3f(_min.x(), _min.y(), _min.z()));
|
||||
vertices.add(new Vector3f(_max.x(), _min.y(), _min.z()));
|
||||
|
||||
vertices.add(new Vector3f(_max.x(), _min.y(), _min.z()));
|
||||
vertices.add(new Vector3f(_max.x(), _min.y(), _max.z()));
|
||||
|
||||
vertices.add(new Vector3f(_max.x(), _min.y(), _max.z()));
|
||||
vertices.add(new Vector3f(_min.x(), _min.y(), _max.z()));
|
||||
|
||||
vertices.add(new Vector3f(_min.x(), _min.y(), _max.z()));
|
||||
vertices.add(new Vector3f(_min.x(), _min.y(), _min.z()));
|
||||
|
||||
vertices.add(new Vector3f(_min.x(), _max.y(), _min.z()));
|
||||
vertices.add(new Vector3f(_max.x(), _max.y(), _min.z()));
|
||||
|
||||
vertices.add(new Vector3f(_max.x(), _max.y(), _min.z()));
|
||||
vertices.add(new Vector3f(_max.x(), _max.y(), _max.z()));
|
||||
|
||||
vertices.add(new Vector3f(_max.x(), _max.y(), _max.z()));
|
||||
vertices.add(new Vector3f(_min.x(), _max.y(), _max.z()));
|
||||
|
||||
vertices.add(new Vector3f(_min.x(), _max.y(), _max.z()));
|
||||
vertices.add(new Vector3f(_min.x(), _max.y(), _min.z()));
|
||||
|
||||
vertices.add(new Vector3f(_min.x(), _min.y(), _min.z()));
|
||||
vertices.add(new Vector3f(_min.x(), _max.y(), _min.z()));
|
||||
|
||||
vertices.add(new Vector3f(_max.x(), _min.y(), _min.z()));
|
||||
vertices.add(new Vector3f(_max.x(), _max.y(), _min.z()));
|
||||
|
||||
vertices.add(new Vector3f(_max.x(), _min.y(), _max.z()));
|
||||
vertices.add(new Vector3f(_max.x(), _max.y(), _max.z()));
|
||||
|
||||
vertices.add(new Vector3f(_min.x(), _min.y(), _max.z()));
|
||||
vertices.add(new Vector3f(_min.x(), _max.y(), _max.z()));
|
||||
|
||||
drawLine(vertices, _color, _transformationMatrix, _updateDepthBuffer, _depthtest);
|
||||
}
|
||||
|
||||
public void drawCylinder(final float _radius, final float _size, final int _lats, final int _longs, final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
|
||||
public void drawCylinder(final float _radius, final float _size, final int _lats, final int _longs,
|
||||
final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
// center to border (TOP)
|
||||
|
||||
|
||||
// center to border (TOP)
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
|
||||
|
||||
final float z = _size * 0.5f;
|
||||
final Vector3f v1 = new Vector3f(0.0f, 0.0f, z);
|
||||
|
||||
|
||||
float x = (float) (Math.cos(lng) * _radius);
|
||||
float y = (float) (Math.sin(lng) * _radius);
|
||||
final Vector3f v2 = new Vector3f(x, y, z);
|
||||
|
||||
|
||||
lng = 2.0f * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) (Math.cos(lng) * _radius);
|
||||
y = (float) (Math.sin(lng) * _radius);
|
||||
@ -336,24 +347,24 @@ public class RefactorColored3DObject extends Resource {
|
||||
// Cylinder
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
|
||||
|
||||
final float z = _size * 0.5f;
|
||||
|
||||
|
||||
float x = (float) (Math.cos(lng) * _radius);
|
||||
float y = (float) (Math.sin(lng) * _radius);
|
||||
final Vector3f v2 = new Vector3f(x, y, z);
|
||||
final Vector3f v2b = new Vector3f(x, y, -z);
|
||||
|
||||
|
||||
lng = 2.0f * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) (Math.cos(lng) * _radius);
|
||||
y = (float) (Math.sin(lng) * _radius);
|
||||
final Vector3f v3 = new Vector3f(x, y, z);
|
||||
final Vector3f v3b = new Vector3f(x, y, -z);
|
||||
|
||||
|
||||
tmpVertices.add(v2);
|
||||
tmpVertices.add(v3);
|
||||
tmpVertices.add(v3b);
|
||||
|
||||
|
||||
tmpVertices.add(v2);
|
||||
tmpVertices.add(v3b);
|
||||
tmpVertices.add(v2b);
|
||||
@ -361,14 +372,14 @@ public class RefactorColored3DObject extends Resource {
|
||||
// center to border (BUTTOM)
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
|
||||
|
||||
final float z = _size * -0.5f;
|
||||
final Vector3f v1 = new Vector3f(0.0f, 0.0f, z);
|
||||
|
||||
|
||||
float x = (float) (Math.cos(lng) * _radius);
|
||||
float y = (float) (Math.sin(lng) * _radius);
|
||||
final Vector3f v2 = new Vector3f(x, y, z);
|
||||
|
||||
|
||||
lng = 2.0f * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) (Math.cos(lng) * _radius);
|
||||
y = (float) (Math.sin(lng) * _radius);
|
||||
@ -379,12 +390,13 @@ public class RefactorColored3DObject extends Resource {
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
|
||||
public void drawLine(final List<Vector3f> _vertices, final Color _color, final Matrix4f _transformationMatrix) {
|
||||
drawLine(_vertices, _color, _transformationMatrix, true, true);
|
||||
}
|
||||
|
||||
public void drawLine(final List<Vector3f> _vertices, final Color _color, final Matrix4f _transformationMatrix, final boolean _updateDepthBuffer, final boolean _depthtest) {
|
||||
|
||||
public void drawLine(final List<Vector3f> _vertices, final Color _color, final Matrix4f _transformationMatrix,
|
||||
final boolean _updateDepthBuffer, final boolean _depthtest) {
|
||||
if (_vertices.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
@ -398,7 +410,7 @@ public class RefactorColored3DObject extends Resource {
|
||||
OpenGL.setDeathMask(false);
|
||||
}
|
||||
}
|
||||
//Log.debug(" display " + this.coord.size() + " elements" );
|
||||
// Log.debug(" display " + this.coord.size() + " elements" );
|
||||
this.GLprogram.use();
|
||||
// set Matrix: translation/positionMatrix
|
||||
final Matrix4f projMatrix = OpenGL.getMatrix();
|
||||
@ -406,10 +418,11 @@ public class RefactorColored3DObject extends Resource {
|
||||
final Matrix4f tmpMatrix = projMatrix.multiplyNew(camMatrix).multiply(_transformationMatrix);
|
||||
this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix);
|
||||
// position :
|
||||
this.GLprogram.sendAttribute(this.GLPosition, 3/*x,y,z*/, ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3);// TODO : check 4->3
|
||||
this.GLprogram.sendAttribute(this.GLPosition, 3/* x,y,z */,
|
||||
ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3);// TODO : check 4->3
|
||||
// color :
|
||||
this.GLprogram.uniformColor(this.GLColor, _color);
|
||||
// Request the draw od the elements:
|
||||
// Request the draw od the elements:
|
||||
OpenGL.drawArrays(OpenGL.RenderMode.line, 0, _vertices.size());
|
||||
this.GLprogram.unUse();
|
||||
if (true == _depthtest) {
|
||||
@ -419,35 +432,36 @@ public class RefactorColored3DObject extends Resource {
|
||||
OpenGL.disable(OpenGL.Flag.flag_depthTest);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawSphere(final float _radius, final int _lats, final int _longs, final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
|
||||
public void drawSphere(final float _radius, final int _lats, final int _longs, final Matrix4f _transformationMatrix,
|
||||
final Color _tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
for (int iii = 0; iii <= _lats; ++iii) {
|
||||
final float lat0 = (float) (Math.PI) * (-0.5f + (float) (iii - 1) / _lats);
|
||||
final float z0 = (float) (_radius * Math.sin(lat0));
|
||||
final float zr0 = (float) (_radius * Math.cos(lat0));
|
||||
|
||||
|
||||
final float lat1 = (float) (Math.PI) * (-0.5f + (float) (iii) / _lats);
|
||||
final float z1 = (float) (_radius * Math.sin(lat1));
|
||||
final float zr1 = (float) (_radius * Math.cos(lat1));
|
||||
|
||||
|
||||
for (int jjj = 0; jjj < _longs; ++jjj) {
|
||||
float lng = 2.0f * (float) (Math.PI) * (jjj - 1) / _longs;
|
||||
float x = (float) Math.cos(lng);
|
||||
float y = (float) Math.sin(lng);
|
||||
final Vector3f v1 = new Vector3f(x * zr1, y * zr1, z1);
|
||||
final Vector3f v4 = new Vector3f(x * zr0, y * zr0, z0);
|
||||
|
||||
|
||||
lng = 2 * (float) (Math.PI) * (jjj) / _longs;
|
||||
x = (float) Math.cos(lng);
|
||||
y = (float) Math.sin(lng);
|
||||
final Vector3f v2 = new Vector3f(x * zr1, y * zr1, z1);
|
||||
final Vector3f v3 = new Vector3f(x * zr0, y * zr0, z0);
|
||||
|
||||
|
||||
tmpVertices.add(v1);
|
||||
tmpVertices.add(v2);
|
||||
tmpVertices.add(v3);
|
||||
|
||||
|
||||
tmpVertices.add(v1);
|
||||
tmpVertices.add(v3);
|
||||
tmpVertices.add(v4);
|
||||
@ -455,39 +469,48 @@ public class RefactorColored3DObject extends Resource {
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
|
||||
public void drawSquare(final Vector3f _size, final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
final int[] indices = { 0, 1, 2, 3, 2, 1, 4, 0, 6, 6, 0, 2, 5, 1, 4, 4, 1, 0, 7, 3, 1, 7, 1, 5, 5, 4, 7, 7, 4, 6, 7, 2, 3, 7, 6, 2 };
|
||||
final Vector3f[] vertices = { new Vector3f(_size.x, _size.y, _size.z), new Vector3f(-_size.x, _size.y, _size.z), new Vector3f(_size.x, -_size.y, _size.z),
|
||||
new Vector3f(-_size.x, -_size.y, _size.z), new Vector3f(_size.x, _size.y, -_size.z), new Vector3f(-_size.x, _size.y, -_size.z), new Vector3f(_size.x, -_size.y, -_size.z),
|
||||
new Vector3f(-_size.x, -_size.y, -_size.z) };
|
||||
final int[] indices = { 0, 1, 2, 3, 2, 1, 4, 0, 6, 6, 0, 2, 5, 1, 4, 4, 1, 0, 7, 3, 1, 7, 1, 5, 5, 4, 7, 7, 4,
|
||||
6, 7, 2, 3, 7, 6, 2 };
|
||||
final Vector3f[] vertices = { new Vector3f(_size.x(), _size.y(), _size.z()),
|
||||
new Vector3f(-_size.x(), _size.y(), _size.z()), new Vector3f(_size.x(), -_size.y(), _size.z()),
|
||||
new Vector3f(-_size.x(), -_size.y(), _size.z()), new Vector3f(_size.x(), _size.y(), -_size.z()),
|
||||
new Vector3f(-_size.x(), _size.y(), -_size.z()), new Vector3f(_size.x(), -_size.y(), -_size.z()),
|
||||
new Vector3f(-_size.x(), -_size.y(), -_size.z()) };
|
||||
tmpVertices.clear();
|
||||
for (int iii = 0; iii < 36; iii += 3) {
|
||||
// normal calculation :
|
||||
//btVector3 normal = (vertices[indices[iii+2]]-vertices[indices[iii]]).cross(vertices[indices[iii+1]]-vertices[indices[iii]]);
|
||||
//normal.normalize ();
|
||||
// btVector3 normal =
|
||||
// (vertices[indices[iii+2]]-vertices[indices[iii]]).cross(vertices[indices[iii+1]]-vertices[indices[iii]]);
|
||||
// normal.normalize ();
|
||||
tmpVertices.add(vertices[indices[iii]]);
|
||||
tmpVertices.add(vertices[indices[iii + 1]]);
|
||||
tmpVertices.add(vertices[indices[iii + 2]]);
|
||||
}
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
|
||||
public void drawTriangles(final List<Vector3f> _vertex, final List<Integer> _indice, final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
|
||||
public void drawTriangles(final List<Vector3f> _vertex, final List<Integer> _indice,
|
||||
final Matrix4f _transformationMatrix, final Color _tmpColor) {
|
||||
drawTriangles(_vertex, _indice, _transformationMatrix, _tmpColor, new Vector3f(0.0f, 0.0f, 0.1f));
|
||||
}
|
||||
|
||||
public void drawTriangles(final List<Vector3f> _vertex, final List<Integer> _indice, final Matrix4f _transformationMatrix, final Color _tmpColor, final Vector3f _offset) {
|
||||
|
||||
public void drawTriangles(final List<Vector3f> _vertex, final List<Integer> _indice,
|
||||
final Matrix4f _transformationMatrix, final Color _tmpColor, final Vector3f _offset) {
|
||||
final List<Vector3f> tmpVertices = new ArrayList<>();
|
||||
for (int iii = 0; iii < _indice.size() / 3; ++iii) {
|
||||
tmpVertices.add(_vertex.get(_indice.get(iii * 3 + 0)).addNew(_offset));
|
||||
tmpVertices.add(_vertex.get(_indice.get(iii * 3 + 1)).addNew(_offset));
|
||||
tmpVertices.add(_vertex.get(_indice.get(iii * 3 + 2)).addNew(_offset));
|
||||
//Log.info(" indices " + _indice[iii*3 + 0] + " " + _indice[iii*3 + 1] + " " + _indice[iii*3 + 2]);
|
||||
//Log.info(" triangle " + _vertex[_indice[iii*3 + 0]] + " " + _vertex[_indice[iii*3 + 1]] + " " + _vertex[_indice[iii*3 + 2]]);
|
||||
tmpVertices.add(_vertex.get(_indice.get(iii * 3 + 0)).add(_offset));
|
||||
tmpVertices.add(_vertex.get(_indice.get(iii * 3 + 1)).add(_offset));
|
||||
tmpVertices.add(_vertex.get(_indice.get(iii * 3 + 2)).add(_offset));
|
||||
// Log.info(" indices " + _indice[iii*3 + 0] + " " + _indice[iii*3 + 1] + " " +
|
||||
// _indice[iii*3 + 2]);
|
||||
// Log.info(" triangle " + _vertex[_indice[iii*3 + 0]] + " " +
|
||||
// _vertex[_indice[iii*3 + 1]] + " " + _vertex[_indice[iii*3 + 2]]);
|
||||
}
|
||||
//Log.info("display " + tmpVertices.size() + " vertices form " + _indice.size());
|
||||
// Log.info("display " + tmpVertices.size() + " vertices form " +
|
||||
// _indice.size());
|
||||
draw(tmpVertices, _tmpColor, _transformationMatrix);
|
||||
}
|
||||
}
|
||||
|
@ -17,13 +17,26 @@ import org.atriasoft.etk.Uri;
|
||||
import org.atriasoft.ewol.internal.Log;
|
||||
import org.atriasoft.gale.resource.Resource;
|
||||
|
||||
class ListElement {
|
||||
public String name;
|
||||
public Color color;
|
||||
|
||||
public ListElement(final String name, final Color color) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ColorFile is a Resource designed to be specific with the theme (for example black, or white or orange ...)
|
||||
* @brief ColorFile is a Resource designed to be specific with the theme (for
|
||||
* example black, or white or orange ...)
|
||||
*/
|
||||
public class ResourceColorFile extends Resource {
|
||||
private final List<ListElement> list = new ArrayList<>(); //!< List of all color in the file
|
||||
private final List<ListElement> list = new ArrayList<>(); // !< List of all color in the file
|
||||
private Color errorColor = Color.ORANGE;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Constructor of the color property file
|
||||
* @param[in] _uri Name of the file needed
|
||||
@ -32,14 +45,14 @@ public class ResourceColorFile extends Resource {
|
||||
super(_uri.get());
|
||||
Log.debug("CF : load \"" + _uri + "\"");
|
||||
reload();
|
||||
//Log.debug("List of all color : " + this.list.keySet());
|
||||
// Log.debug("List of all color : " + this.list.keySet());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the associated color of the ID.
|
||||
* @param[in] _Id Id of the color.
|
||||
@ -51,7 +64,7 @@ public class ResourceColorFile extends Resource {
|
||||
}
|
||||
return this.list.get(_id).color;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get All color name
|
||||
* @return list of all color existing
|
||||
@ -63,7 +76,7 @@ public class ResourceColorFile extends Resource {
|
||||
}
|
||||
return out;
|
||||
};
|
||||
|
||||
|
||||
public synchronized void put(final String name, final Color color) {
|
||||
for (int iii = 0; iii < this.list.size(); iii++) {
|
||||
final ListElement elem = this.list.get(iii);
|
||||
@ -74,7 +87,7 @@ public class ResourceColorFile extends Resource {
|
||||
}
|
||||
this.list.add(new ListElement(name, color));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void reload() {
|
||||
// remove all previous set of value :
|
||||
@ -85,7 +98,7 @@ public class ResourceColorFile extends Resource {
|
||||
// open and read all json elements:
|
||||
try {
|
||||
final JsonObject out = Ejson.parse(new Uri(this.name)).toJsonObject();
|
||||
|
||||
|
||||
final JsonArray baseArray = out.get("color").toJsonArray();
|
||||
if (baseArray == null) {
|
||||
Log.error("Can not get basic array : 'color' in file:" + this.name);
|
||||
@ -109,8 +122,9 @@ public class ResourceColorFile extends Resource {
|
||||
continue;
|
||||
}
|
||||
if (color.length() == 0) {
|
||||
put(name, this.errorColor.clone());
|
||||
} else {}
|
||||
put(name, this.errorColor);
|
||||
} else {
|
||||
}
|
||||
put(name, Color.valueOf(color));
|
||||
}
|
||||
if (findError == true) {
|
||||
@ -122,7 +136,7 @@ public class ResourceColorFile extends Resource {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Request the presence of a specific color.
|
||||
* @param[in] _paramName Name of the color.
|
||||
@ -135,10 +149,10 @@ public class ResourceColorFile extends Resource {
|
||||
return iii;
|
||||
}
|
||||
}
|
||||
this.list.add(new ListElement(_paramName, this.errorColor.clone()));
|
||||
this.list.add(new ListElement(_paramName, this.errorColor));
|
||||
return this.list.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the error color.
|
||||
* @param[in] _errorColor Color that might be set when not finding a color
|
||||
@ -146,17 +160,5 @@ public class ResourceColorFile extends Resource {
|
||||
public void setErrorColor(final Color _errorColor) {
|
||||
this.errorColor = _errorColor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ListElement {
|
||||
public String name;
|
||||
public Color color;
|
||||
|
||||
public ListElement(final String name, final Color color) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -34,7 +34,7 @@ public class ResourceFontFreeType extends FontBase {
|
||||
static {
|
||||
library = FreeType.newLibrary();
|
||||
}
|
||||
|
||||
|
||||
public static ResourceFontFreeType create(final Uri uri) {
|
||||
Log.verbose("KEEP: FontFreeType: " + uri);
|
||||
ResourceFontFreeType object = null;
|
||||
@ -53,19 +53,20 @@ public class ResourceFontFreeType extends FontBase {
|
||||
// need to crate a new one ...
|
||||
return new ResourceFontFreeType(uri);
|
||||
}
|
||||
|
||||
|
||||
private final byte[] FileBuffer;
|
||||
private final Face fftFace;
|
||||
|
||||
|
||||
private boolean init;
|
||||
|
||||
|
||||
private ResourceFontFreeType(final Uri _uri) {
|
||||
super(_uri);
|
||||
this.FileBuffer = LoadPackageStream.getAllData(_uri.getPath());
|
||||
// load Face ...
|
||||
this.fftFace = library.newFace(this.FileBuffer, 0);
|
||||
if (this.fftFace == null) {
|
||||
Log.error("... the font file could be opened and read, but it appears ... that its font format is unsupported");
|
||||
Log.error(
|
||||
"... the font file could be opened and read, but it appears ... that its font format is unsupported");
|
||||
} else {
|
||||
// all OK
|
||||
Log.debug("load font : \"" + _uri + "\" glyph count = " + this.fftFace.getNumGlyphs());
|
||||
@ -73,7 +74,7 @@ public class ResourceFontFreeType extends FontBase {
|
||||
// display();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void display() {
|
||||
if (this.init == false) {
|
||||
@ -81,16 +82,18 @@ public class ResourceFontFreeType extends FontBase {
|
||||
}
|
||||
Log.info(" number of glyph = " + this.fftFace.getNumGlyphs());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean drawGlyph(final Image _imageOut, final int _fontSize, final Vector2i _glyphPosition, final GlyphProperty _property, final int _posInImage) {
|
||||
public synchronized boolean drawGlyph(final Image _imageOut, final int _fontSize, final Vector2i _glyphPosition,
|
||||
final GlyphProperty _property, final int _posInImage) {
|
||||
if (this.init == false) {
|
||||
return false;
|
||||
}
|
||||
// 300dpi (hight quality) 96 dpi (normal quality)
|
||||
final int fontQuality = 96;
|
||||
// Select size ...
|
||||
// note tha +6 == *64 corespond with the 1/64th of points calculation of freetype
|
||||
// note tha +6 == *64 corespond with the 1/64th of points calculation of
|
||||
// freetype
|
||||
boolean error = this.fftFace.setCharSize(_fontSize + 6, _fontSize + 6, fontQuality, fontQuality);
|
||||
if (error == false) {
|
||||
Log.error("FT_Set_Char_Size == > error in settings ...");
|
||||
@ -117,36 +120,38 @@ public class ResourceFontFreeType extends FontBase {
|
||||
final int valueColor = bitmap.getBuffer().get(iii + bitmap.getWidth() * jjj);
|
||||
// set only alpha :
|
||||
switch (_posInImage) {
|
||||
default:
|
||||
case 0:
|
||||
_imageOut.setA(_glyphPosition.x + iii, _glyphPosition.y + jjj, valueColor);
|
||||
break;
|
||||
case 1:
|
||||
_imageOut.setR(_glyphPosition.x + iii, _glyphPosition.y + jjj, valueColor);
|
||||
break;
|
||||
case 2:
|
||||
_imageOut.setG(_glyphPosition.x + iii, _glyphPosition.y + jjj, valueColor);
|
||||
break;
|
||||
case 3:
|
||||
_imageOut.setB(_glyphPosition.x + iii, _glyphPosition.y + jjj, valueColor);
|
||||
break;
|
||||
default:
|
||||
case 0:
|
||||
_imageOut.setA(_glyphPosition.x() + iii, _glyphPosition.y() + jjj, valueColor);
|
||||
break;
|
||||
case 1:
|
||||
_imageOut.setR(_glyphPosition.x() + iii, _glyphPosition.y() + jjj, valueColor);
|
||||
break;
|
||||
case 2:
|
||||
_imageOut.setG(_glyphPosition.x() + iii, _glyphPosition.y() + jjj, valueColor);
|
||||
break;
|
||||
case 3:
|
||||
_imageOut.setB(_glyphPosition.x() + iii, _glyphPosition.y() + jjj, valueColor);
|
||||
break;
|
||||
}
|
||||
// real set of color
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean drawGlyph(final ImageMono _imageOut, final int _fontSize, final GlyphProperty _property, final int _borderSize) {
|
||||
public synchronized boolean drawGlyph(final ImageMono _imageOut, final int _fontSize, final GlyphProperty _property,
|
||||
final int _borderSize) {
|
||||
if (false == this.init) {
|
||||
return false;
|
||||
}
|
||||
// 300dpi (hight quality) 96 dpi (normal quality)
|
||||
final int fontQuality = 96;
|
||||
// Select size ...
|
||||
// note tha +6 == *64 corespond with the 1/64th of points calculation of freetype
|
||||
// note tha +6 == *64 corespond with the 1/64th of points calculation of
|
||||
// freetype
|
||||
boolean error = this.fftFace.setCharSize(_fontSize + 6, _fontSize + 6, fontQuality, fontQuality);
|
||||
if (error == false) {
|
||||
Log.error("FT_Set_Char_Size == > error in settings ...");
|
||||
@ -162,7 +167,8 @@ public class ResourceFontFreeType extends FontBase {
|
||||
return false;
|
||||
}
|
||||
// convert to an anti-aliased bitmap
|
||||
error = slot.renderGlyph(FT_Render_Mode.FT_RENDER_MODE_NORMAL); // TODO : set FT_RENDER_MODE_MONO ==> 1 bit value ==> faster generation ...
|
||||
error = slot.renderGlyph(FT_Render_Mode.FT_RENDER_MODE_NORMAL); // TODO : set FT_RENDER_MODE_MONO ==> 1 bit
|
||||
// value ==> faster generation ...
|
||||
if (error == false) {
|
||||
Log.error("FT_Render_Glyph");
|
||||
return false;
|
||||
@ -170,7 +176,7 @@ public class ResourceFontFreeType extends FontBase {
|
||||
// resize output image :
|
||||
final Bitmap bitmap = slot.getBitmap();
|
||||
_imageOut.resize(bitmap.getWidth() + 2 * _borderSize, bitmap.getRows() + 2 * _borderSize);
|
||||
|
||||
|
||||
for (int jjj = 0; jjj < bitmap.getRows(); jjj++) {
|
||||
for (int iii = 0; iii < bitmap.getWidth(); iii++) {
|
||||
final int valueColor = bitmap.getBuffer().get(iii + bitmap.getWidth() * jjj);
|
||||
@ -180,7 +186,7 @@ public class ResourceFontFreeType extends FontBase {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void generateKerning(final int fontSize, final List<GlyphProperty> listGlyph) {
|
||||
if (this.init == false) {
|
||||
@ -192,7 +198,8 @@ public class ResourceFontFreeType extends FontBase {
|
||||
// 300dpi (hight quality) 96 dpi (normal quality)
|
||||
final int fontQuality = 96;
|
||||
// Select size ...
|
||||
// note tha +6 == *64 corespond with the 1/64th of points calculation of freetype
|
||||
// note tha +6 == *64 corespond with the 1/64th of points calculation of
|
||||
// freetype
|
||||
final boolean error = this.fftFace.setCharSize(fontSize + 6, fontSize + 6, fontQuality, fontQuality);
|
||||
if (error == false) {
|
||||
Log.error("FT_Set_Char_Size == > error in settings ...");
|
||||
@ -202,16 +209,19 @@ public class ResourceFontFreeType extends FontBase {
|
||||
for (int iii = 0; iii < listGlyph.size(); iii++) {
|
||||
listGlyph.get(iii).kerningClear();
|
||||
for (int kkk = 0; kkk < listGlyph.size(); kkk++) {
|
||||
final Kerning kerning = this.fftFace.getKerning(listGlyph.get(kkk).glyphIndex, listGlyph.get(iii).glyphIndex, FT_Kerning_Mode.FT_KERNING_UNFITTED);
|
||||
// add the kerning only if != 0 ...
|
||||
final Kerning kerning = this.fftFace.getKerning(listGlyph.get(kkk).glyphIndex,
|
||||
listGlyph.get(iii).glyphIndex, FT_Kerning_Mode.FT_KERNING_UNFITTED);
|
||||
// add the kerning only if != 0 ...
|
||||
if (kerning.x != 0) {
|
||||
listGlyph.get(iii).kerningAdd(listGlyph.get(kkk).UVal, kerning.x / 32.0f);
|
||||
//Log.debug("Kerning between : '" + (char)listGlyph[iii].this.UVal + "''" + (char)listGlyph[kkk].this.UVal + "' value : " + kerning.x + " => " + (kerning.x/64.0f));
|
||||
// Log.debug("Kerning between : '" + (char)listGlyph[iii].this.UVal + "''" +
|
||||
// (char)listGlyph[kkk].this.UVal + "' value : " + kerning.x + " => " +
|
||||
// (kerning.x/64.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean getGlyphProperty(final int _fontSize, final GlyphProperty _property) {
|
||||
if (false == this.init) {
|
||||
@ -220,7 +230,8 @@ public class ResourceFontFreeType extends FontBase {
|
||||
// 300dpi (hight quality) 96 dpi (normal quality)
|
||||
final int fontQuality = 96;
|
||||
// Select size ...
|
||||
// note tha +6 == *64 corespond with the 1/64th of points calculation of freetype
|
||||
// note tha +6 == *64 corespond with the 1/64th of points calculation of
|
||||
// freetype
|
||||
boolean error = this.fftFace.setCharSize(_fontSize + 6, _fontSize + 6, fontQuality, fontQuality);
|
||||
if (error == false) {
|
||||
Log.error("FT_Set_Char_Size == > error in settings ...");
|
||||
@ -228,7 +239,7 @@ public class ResourceFontFreeType extends FontBase {
|
||||
}
|
||||
// a small shortcut
|
||||
final GlyphSlot slot = this.fftFace.getGlyphSlot();
|
||||
// retrieve glyph index from character code
|
||||
// retrieve glyph index from character code
|
||||
final int glyph_index = this.fftFace.getCharIndex(_property.UVal);
|
||||
// load glyph image into the slot (erase previous one)
|
||||
error = this.fftFace.loadGlyph(glyph_index, // glyph index
|
||||
@ -246,17 +257,19 @@ public class ResourceFontFreeType extends FontBase {
|
||||
// set properties :
|
||||
_property.glyphIndex = glyph_index;
|
||||
final Bitmap bitmap = slot.getBitmap();
|
||||
_property.sizeTexture.setValue(bitmap.getWidth(), bitmap.getRows());
|
||||
_property.bearing.setValue(slot.getMetrics().getHoriBearingX() >> 6, slot.getMetrics().getHoriBearingY() >> 6);
|
||||
_property.advance.setValue(slot.getMetrics().getHoriAdvance() >> 6, slot.getMetrics().getVertAdvance() >> 6);
|
||||
_property.sizeTexture = new Vector2i(bitmap.getWidth(), bitmap.getRows());
|
||||
_property.bearing = new Vector2i(slot.getMetrics().getHoriBearingX() >> 6,
|
||||
slot.getMetrics().getHoriBearingY() >> 6);
|
||||
_property.advance = new Vector2i(slot.getMetrics().getHoriAdvance() >> 6,
|
||||
slot.getMetrics().getVertAdvance() >> 6);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized int getHeight(final int _fontSize) {
|
||||
return (int) (_fontSize * 1.43f); // this is a really "magic" number ...
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized Vector2f getSize(final int _fontSize, final String _unicodeString) {
|
||||
if (this.init == false) {
|
||||
@ -265,10 +278,10 @@ public class ResourceFontFreeType extends FontBase {
|
||||
// TODO ...
|
||||
return new Vector2f(0, 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized float getSizeWithHeight(final float _fontHeight) {
|
||||
return _fontHeight * 0.6993f; // this is a really "magic" number ...
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -18,47 +18,39 @@ import org.lwjgl.opengl.GL13;
|
||||
|
||||
public class ResourceTexture2 extends Resource {
|
||||
public enum TextureColorMode {
|
||||
rgb, //!< red/green/blue data
|
||||
rgba //!< red/green/blue/alpha data
|
||||
rgb, // !< red/green/blue data
|
||||
rgba // !< red/green/blue/alpha data
|
||||
}
|
||||
|
||||
private static int[] textureIdBinding = { GL13.GL_TEXTURE0, GL13.GL_TEXTURE1, GL13.GL_TEXTURE2, GL13.GL_TEXTURE3, GL13.GL_TEXTURE4, GL13.GL_TEXTURE5, GL13.GL_TEXTURE6, GL13.GL_TEXTURE7,
|
||||
GL13.GL_TEXTURE8, GL13.GL_TEXTURE9, GL13.GL_TEXTURE10, GL13.GL_TEXTURE11, GL13.GL_TEXTURE12, GL13.GL_TEXTURE13, GL13.GL_TEXTURE14, GL13.GL_TEXTURE15, GL13.GL_TEXTURE16, GL13.GL_TEXTURE17,
|
||||
GL13.GL_TEXTURE18, GL13.GL_TEXTURE19, GL13.GL_TEXTURE20, GL13.GL_TEXTURE21, GL13.GL_TEXTURE22, GL13.GL_TEXTURE23, GL13.GL_TEXTURE24, GL13.GL_TEXTURE25, GL13.GL_TEXTURE26,
|
||||
GL13.GL_TEXTURE27, GL13.GL_TEXTURE28, GL13.GL_TEXTURE29, GL13.GL_TEXTURE30, GL13.GL_TEXTURE31 };;
|
||||
|
||||
|
||||
private static int[] textureIdBinding = { GL13.GL_TEXTURE0, GL13.GL_TEXTURE1, GL13.GL_TEXTURE2, GL13.GL_TEXTURE3,
|
||||
GL13.GL_TEXTURE4, GL13.GL_TEXTURE5, GL13.GL_TEXTURE6, GL13.GL_TEXTURE7, GL13.GL_TEXTURE8, GL13.GL_TEXTURE9,
|
||||
GL13.GL_TEXTURE10, GL13.GL_TEXTURE11, GL13.GL_TEXTURE12, GL13.GL_TEXTURE13, GL13.GL_TEXTURE14,
|
||||
GL13.GL_TEXTURE15, GL13.GL_TEXTURE16, GL13.GL_TEXTURE17, GL13.GL_TEXTURE18, GL13.GL_TEXTURE19,
|
||||
GL13.GL_TEXTURE20, GL13.GL_TEXTURE21, GL13.GL_TEXTURE22, GL13.GL_TEXTURE23, GL13.GL_TEXTURE24,
|
||||
GL13.GL_TEXTURE25, GL13.GL_TEXTURE26, GL13.GL_TEXTURE27, GL13.GL_TEXTURE28, GL13.GL_TEXTURE29,
|
||||
GL13.GL_TEXTURE30, GL13.GL_TEXTURE31 };;
|
||||
|
||||
/*
|
||||
public static ResourceTexture2 createFromPng(final Uri uriTexture) {
|
||||
return createFromPng(uriTexture, 1);
|
||||
}
|
||||
|
||||
public static ResourceTexture2 createFromPng(final Uri uriTexture, final int textureUnit) {
|
||||
ResourceTexture2 resource;
|
||||
Resource resource2;
|
||||
final String name = uriTexture.getValue();
|
||||
if (name.isEmpty() == false && name != "---") {
|
||||
resource2 = getManager().localKeep(name);
|
||||
} else {
|
||||
Log.error("Can not create a shader without a filaname");
|
||||
return null;
|
||||
}
|
||||
if (resource2 != null) {
|
||||
if (resource2 instanceof ResourceTexture2) {
|
||||
resource2.keep();
|
||||
return (ResourceTexture2) resource2;
|
||||
}
|
||||
Log.critical("Request resource file : '" + name + "' With the wrong type (dynamic cast error)");
|
||||
return null;
|
||||
}
|
||||
resource = new ResourceTexture2(uriTexture, textureUnit);
|
||||
final ImageRawData decodedData = ImageLoader.decodePngFile(uriTexture);
|
||||
resource.setTexture(decodedData.getBuffer(), new Vector2i(decodedData.getWidth(), decodedData.getHeight()), (decodedData.isHasAlpha() == true ? TextureColorMode.rgba : TextureColorMode.rgb),
|
||||
textureUnit);
|
||||
resource.flush();
|
||||
return resource;
|
||||
}
|
||||
*/
|
||||
|
||||
* public static ResourceTexture2 createFromPng(final Uri uriTexture) { return
|
||||
* createFromPng(uriTexture, 1); }
|
||||
*
|
||||
* public static ResourceTexture2 createFromPng(final Uri uriTexture, final int
|
||||
* textureUnit) { ResourceTexture2 resource; Resource resource2; final String
|
||||
* name = uriTexture.getValue(); if (name.isEmpty() == false && name != "---") {
|
||||
* resource2 = getManager().localKeep(name); } else {
|
||||
* Log.error("Can not create a shader without a filaname"); return null; } if
|
||||
* (resource2 != null) { if (resource2 instanceof ResourceTexture2) {
|
||||
* resource2.keep(); return (ResourceTexture2) resource2; }
|
||||
* Log.critical("Request resource file : '" + name +
|
||||
* "' With the wrong type (dynamic cast error)"); return null; } resource = new
|
||||
* ResourceTexture2(uriTexture, textureUnit); final ImageRawData decodedData =
|
||||
* ImageLoader.decodePngFile(uriTexture);
|
||||
* resource.setTexture(decodedData.getBuffer(), new
|
||||
* Vector2i(decodedData.getWidth(), decodedData.getHeight()),
|
||||
* (decodedData.isHasAlpha() == true ? TextureColorMode.rgba :
|
||||
* TextureColorMode.rgb), textureUnit); resource.flush(); return resource; }
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief get the next power 2 if the input
|
||||
* @param value Value that we want the next power of 2
|
||||
@ -75,13 +67,14 @@ public class ResourceTexture2 extends Resource {
|
||||
Log.critical("impossible CASE....");
|
||||
return val;
|
||||
}
|
||||
|
||||
protected int texId = -1; //!< openGl textureID.
|
||||
|
||||
protected int texId = -1; // !< openGl textureID.
|
||||
// openGl Context properties :
|
||||
protected Image data = new Image(32, 32);
|
||||
//! Last loaded size in the system openGL
|
||||
// ! Last loaded size in the system openGL
|
||||
protected Vector2i lastSize = new Vector2i(1, 1);
|
||||
//! some image are not square == > we need to sqared it to prevent some openGl api error the the displayable size is not all the time 0.0 . 1.0
|
||||
// ! some image are not square == > we need to sqared it to prevent some openGl
|
||||
// api error the the displayable size is not all the time 0.0 . 1.0
|
||||
protected Vector2i realImageSize = new Vector2i(1, 1);
|
||||
// internal state of the openGl system.
|
||||
protected boolean loaded = false;
|
||||
@ -89,39 +82,33 @@ public class ResourceTexture2 extends Resource {
|
||||
protected int lastSizeObject = 0;
|
||||
// repeat mode of the image (repeat the image if out of range [0..1])
|
||||
protected boolean repeat = false;
|
||||
|
||||
|
||||
// Filter apply at the image when rendering it
|
||||
protected TextureFilter filter = TextureFilter.linear;
|
||||
|
||||
//!< Color space of the image.
|
||||
|
||||
// !< Color space of the image.
|
||||
private final TextureColorMode dataColorSpace = TextureColorMode.rgba;
|
||||
|
||||
|
||||
public ResourceTexture2() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public ResourceTexture2(final String filename) {
|
||||
super(filename);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public void bindForRendering(final int idTexture) {
|
||||
if (this.loaded == false) {
|
||||
return;
|
||||
}
|
||||
GL13.glActiveTexture(textureIdBinding[idTexture]);
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texId);
|
||||
if (this.dataColorSpace == TextureColorMode.rgb) {
|
||||
OpenGL.enable(OpenGL.Flag.flag_cullFace);
|
||||
OpenGL.enable(OpenGL.Flag.flag_back);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
* public void bindForRendering(final int idTexture) { if (this.loaded == false)
|
||||
* { return; } GL13.glActiveTexture(textureIdBinding[idTexture]);
|
||||
* GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texId); if (this.dataColorSpace
|
||||
* == TextureColorMode.rgb) { OpenGL.enable(OpenGL.Flag.flag_cullFace);
|
||||
* OpenGL.enable(OpenGL.Flag.flag_back); } }
|
||||
*/
|
||||
|
||||
public ResourceTexture2(final Uri filename) {
|
||||
super(filename);
|
||||
}
|
||||
|
||||
|
||||
public void bindForRendering(final int idTexture) {
|
||||
if (this.loaded == false) {
|
||||
return;
|
||||
@ -133,36 +120,36 @@ public class ResourceTexture2 extends Resource {
|
||||
OpenGL.enable(OpenGL.Flag.flag_back);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
removeContext();
|
||||
}
|
||||
|
||||
|
||||
// Flush the data to send it at the openGl system
|
||||
public synchronized void flush() {
|
||||
// request to the manager to be call at the next update ...
|
||||
Log.verbose("Request UPDATE of Element");
|
||||
getManager().update(this);
|
||||
};
|
||||
|
||||
|
||||
// Get the reference on this image to draw something on it ...
|
||||
public Image get() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
|
||||
public Vector2i getOpenGlSize() {
|
||||
return this.data.getSize();
|
||||
}
|
||||
|
||||
|
||||
public int getRendererId() {
|
||||
return this.texId;
|
||||
}
|
||||
|
||||
|
||||
public Vector2i getUsableSize() {
|
||||
return this.realImageSize;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void removeContext() {
|
||||
if (this.loaded == true) {
|
||||
@ -173,13 +160,13 @@ public class ResourceTexture2 extends Resource {
|
||||
this.loaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized void removeContextToLate() {
|
||||
this.loaded = false;
|
||||
this.texId = -1;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the image in the texture system
|
||||
* @note It will resize in square2 if needed by the system.
|
||||
@ -189,29 +176,31 @@ public class ResourceTexture2 extends Resource {
|
||||
Log.debug("Set a new image in a texture:");
|
||||
Log.debug(" size=" + _image.getSize());
|
||||
this.data = _image;
|
||||
this.realImageSize = this.data.getSize().clone();
|
||||
final Vector2i compatibilityHWSize = new Vector2i(Tools.nextP2(this.realImageSize.x), Tools.nextP2(this.realImageSize.y));
|
||||
this.realImageSize = this.data.getSize();
|
||||
final Vector2i compatibilityHWSize = new Vector2i(Tools.nextP2(this.realImageSize.x()),
|
||||
Tools.nextP2(this.realImageSize.y()));
|
||||
if (this.realImageSize != compatibilityHWSize) {
|
||||
Log.verbose("RESIZE Image for HArwareCompatibility:" + this.realImageSize + " => " + compatibilityHWSize);
|
||||
this.data.resize(compatibilityHWSize.x, compatibilityHWSize.y);
|
||||
this.data.resize(compatibilityHWSize.x(), compatibilityHWSize.y());
|
||||
}
|
||||
flush();
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the Filter mode to apply at the image when display with a scale (not 1:1 ratio)
|
||||
* @brief Set the Filter mode to apply at the image when display with a scale
|
||||
* (not 1:1 ratio)
|
||||
* @param[in] _value Value of the new filter mode
|
||||
*/
|
||||
public void setFilterMode(final TextureFilter _filter) {
|
||||
this.filter = _filter;
|
||||
}
|
||||
|
||||
|
||||
// You must set the size here, because it will be set in multiple of pow(2)
|
||||
public synchronized void setImageSize(final Vector2i _newSize) {
|
||||
_newSize.setValue(Tools.nextP2(_newSize.x), Tools.nextP2(_newSize.y));
|
||||
this.data.resize(_newSize.x, _newSize.y);
|
||||
public synchronized void setImageSize(Vector2i _newSize) {
|
||||
_newSize = new Vector2i(Tools.nextP2(_newSize.x()), Tools.nextP2(_newSize.y()));
|
||||
this.data.resize(_newSize.x(), _newSize.y());
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the repeate mode of the images if UV range is out of [0..1]
|
||||
* @param[in] _value Value of the new repeate mode
|
||||
@ -219,7 +208,7 @@ public class ResourceTexture2 extends Resource {
|
||||
public void setRepeat(final boolean _value) {
|
||||
this.repeat = _value;
|
||||
}
|
||||
|
||||
|
||||
public void unBindForRendering() {
|
||||
if (this.loaded == false) {
|
||||
return;
|
||||
@ -229,21 +218,20 @@ public class ResourceTexture2 extends Resource {
|
||||
OpenGL.disable(OpenGL.Flag.flag_back);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean updateContext() {
|
||||
Log.verbose("updateContext [START]");
|
||||
final Steady tic = Steady.now();
|
||||
/* TODO : use unlockable synchronized ...
|
||||
if (lock.tryLock() == false) {
|
||||
//Lock error ==> try later ...
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
* TODO : use unlockable synchronized ... if (lock.tryLock() == false) { //Lock
|
||||
* error ==> try later ... return false; }
|
||||
*/
|
||||
final int typeObject = OpenGL.GL_RGBA;
|
||||
final int sizeObject = OpenGL.GL_UNSIGNED_BYTE;
|
||||
if (this.loaded == true) {
|
||||
if (this.lastTypeObject != typeObject || this.lastSizeObject != sizeObject || this.lastSize.equals(this.data.getSize()) == false) {
|
||||
if (this.lastTypeObject != typeObject || this.lastSizeObject != sizeObject
|
||||
|| this.lastSize.equals(this.data.getSize()) == false) {
|
||||
Log.warning("TEXTURE: Rm [" + getId() + "] texId=" + this.texId);
|
||||
OpenGL.glDeleteTextures(this.texId);
|
||||
this.loaded = false;
|
||||
@ -255,14 +243,16 @@ public class ResourceTexture2 extends Resource {
|
||||
this.lastSize = this.data.getSize();
|
||||
this.lastTypeObject = typeObject;
|
||||
this.lastSizeObject = sizeObject;
|
||||
Log.debug("TEXTURE: add [" + getId() + "]=" + this.data.getSize() + "=>" + this.data.getGPUSize() + " OGl_Id=" + this.texId + " type=" + this.data.getClass().getCanonicalName());
|
||||
Log.debug("TEXTURE: add [" + getId() + "]=" + this.data.getSize() + "=>" + this.data.getGPUSize()
|
||||
+ " OGl_Id=" + this.texId + " type=" + this.data.getClass().getCanonicalName());
|
||||
} else {
|
||||
Log.debug("TEXTURE: update [" + getId() + "]=" + this.data.getSize() + "=>" + this.data.getGPUSize() + " OGl_Id=" + this.texId + " type=" + this.data.getClass().getCanonicalName());
|
||||
Log.debug("TEXTURE: update [" + getId() + "]=" + this.data.getSize() + "=>" + this.data.getGPUSize()
|
||||
+ " OGl_Id=" + this.texId + " type=" + this.data.getClass().getCanonicalName());
|
||||
}
|
||||
// in all case we set the texture properties :
|
||||
// TODO : check error ???
|
||||
OpenGL.bindTexture2D(this.texId);
|
||||
|
||||
|
||||
if (this.loaded == false) {
|
||||
if (this.repeat == false) {
|
||||
OpenGL.setTexture2DWrapClampToEdge();
|
||||
@ -275,53 +265,36 @@ public class ResourceTexture2 extends Resource {
|
||||
OpenGL.setTexture2DFilterNearest();
|
||||
}
|
||||
}
|
||||
//glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
||||
// glPixelStorei(GL_UNPACK_ALIGNMENT,1);
|
||||
final Steady toc1 = Steady.now();
|
||||
Log.verbose(" BIND ==> " + toc1.less(tic));
|
||||
//egami::store(this.data, String("~/texture_") + etk::toString(getId()) + ".bmp");
|
||||
/*if (false) {
|
||||
// On some embended target, the texture size must be square of 2:
|
||||
if (this.loaded == false) {
|
||||
// 1: Create the square 2 texture:
|
||||
final int bufferSize = this.data.getGPUSize().x() * this.data.getGPUSize().y() * 8;
|
||||
static List<float> tmpData;
|
||||
if (tmpData.size() < bufferSize) {
|
||||
tmpData.resize(bufferSize, 0.0f);
|
||||
}
|
||||
Log.debug(" CREATE texture ==> " + this.data.getGPUSize());
|
||||
// 2 create a new empty texture:
|
||||
OpenGL.glTexImage2D(GL_TEXTURE_2D, // Target
|
||||
0, // Level
|
||||
typeObject, // Format internal
|
||||
this.data.getGPUSize().x(),
|
||||
this.data.getGPUSize().y(),
|
||||
0, // Border
|
||||
typeObject, // format
|
||||
sizeObject, // type
|
||||
tmpData[0] );
|
||||
|
||||
}
|
||||
//3 Flush all time the data:
|
||||
Steady tic1 = Steady.now();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, // Target
|
||||
0, // Level
|
||||
0, // x offset
|
||||
0, // y offset
|
||||
this.data.getWidth(),
|
||||
this.data.getHeight(),
|
||||
typeObject, // format
|
||||
sizeObject, // type
|
||||
(void*)((char*)this.data.getTextureDataPointer()) );
|
||||
Steady toc2 = Steady.now();
|
||||
Log.info(" updateContext [STOP] ==> " + toc2.less(tic1));
|
||||
} else */if (this.loaded == false) {
|
||||
// egami::store(this.data, String("~/texture_") + etk::toString(getId()) +
|
||||
// ".bmp");
|
||||
/*
|
||||
* if (false) { // On some embended target, the texture size must be square of
|
||||
* 2: if (this.loaded == false) { // 1: Create the square 2 texture: final int
|
||||
* bufferSize = this.data.getGPUSize().x() * this.data.getGPUSize().y() * 8;
|
||||
* static List<float> tmpData; if (tmpData.size() < bufferSize) {
|
||||
* tmpData.resize(bufferSize, 0.0f); } Log.debug(" CREATE texture ==> " +
|
||||
* this.data.getGPUSize()); // 2 create a new empty texture:
|
||||
* OpenGL.glTexImage2D(GL_TEXTURE_2D, // Target 0, // Level typeObject, //
|
||||
* Format internal this.data.getGPUSize().x(), this.data.getGPUSize().y(), 0, //
|
||||
* Border typeObject, // format sizeObject, // type tmpData[0] );
|
||||
*
|
||||
* } //3 Flush all time the data: Steady tic1 = Steady.now();
|
||||
* glTexSubImage2D(GL_TEXTURE_2D, // Target 0, // Level 0, // x offset 0, // y
|
||||
* offset this.data.getWidth(), this.data.getHeight(), typeObject, // format
|
||||
* sizeObject, // type (void*)((char*)this.data.getTextureDataPointer()) );
|
||||
* Steady toc2 = Steady.now(); Log.info(" updateContext [STOP] ==> " +
|
||||
* toc2.less(tic1)); } else
|
||||
*/if (this.loaded == false) {
|
||||
OpenGL.glTexImage2D(0, // Level
|
||||
typeObject, // Format internal
|
||||
this.data.getWidth(), this.data.getHeight(), 0, // Border
|
||||
typeObject, // format
|
||||
sizeObject, // type
|
||||
this.data.GetRaw());
|
||||
|
||||
|
||||
} else {
|
||||
OpenGL.glTexSubImage2D(0, // Level
|
||||
0, // x offset
|
||||
@ -333,12 +306,11 @@ public class ResourceTexture2 extends Resource {
|
||||
// now the data is loaded
|
||||
this.loaded = true;
|
||||
final Steady toc = Steady.now();
|
||||
//Log.error(" updateContext [STOP] ==> " + (toc - toc1));
|
||||
// Log.error(" updateContext [STOP] ==> " + (toc - toc1));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
enum TextureFilter {
|
||||
nearest,
|
||||
linear
|
||||
nearest, linear
|
||||
}
|
||||
|
@ -17,53 +17,55 @@ import org.atriasoft.gale.resource.Resource;
|
||||
public class ResourceTextureFile extends ResourceTexture2 {
|
||||
public static Vector2i sizeAuto = new Vector2i(-1, -1);
|
||||
public static Vector2i sizeDefault = new Vector2i(0, 0);
|
||||
|
||||
|
||||
/**
|
||||
* @brief keep the resource pointer.
|
||||
* @note Never free this pointer by your own...
|
||||
* @param[in] _filename Name of the image file.
|
||||
* @param[in] _requested size of the image (usefull when loading .svg to automatic rescale)
|
||||
* @param[in] _sizeRegister size register in named (When you preaload the images the size write here will be )
|
||||
* @param[in] _requested size of the image (usefull when loading .svg to
|
||||
* automatic rescale)
|
||||
* @param[in] _sizeRegister size register in named (When you preaload the images
|
||||
* the size write here will be )
|
||||
* @return pointer on the resource or null if an error occured.
|
||||
*/
|
||||
public static ResourceTextureFile create(final Uri _filename) {
|
||||
return create(_filename, sizeAuto);
|
||||
}
|
||||
|
||||
|
||||
public static ResourceTextureFile create(final Uri _filename, final Vector2i _size) {
|
||||
return create(_filename, _size, sizeAuto);
|
||||
}
|
||||
|
||||
|
||||
public static ResourceTextureFile create(final Uri _uri, final Vector2i _size, final Vector2i _sizeRegister) {
|
||||
Log.verbose("KEEP: TextureFile: '" + _uri + "' size=" + _size + " sizeRegister=" + _sizeRegister);
|
||||
Vector2i size = _size.clone();
|
||||
Vector2i size = _size;
|
||||
if (_uri == null) {
|
||||
final ResourceTextureFile object = new ResourceTextureFile();
|
||||
return object;
|
||||
}
|
||||
if (size.x == 0) {
|
||||
size.setX(-1);
|
||||
//Log.error("Error Request the image size.x() =0 ???");
|
||||
if (size.x() == 0) {
|
||||
size = size.withX(-1);
|
||||
// Log.error("Error Request the image size.x() =0 ???");
|
||||
}
|
||||
if (size.y == 0) {
|
||||
size.setY(-1);
|
||||
//Log.error("Error Request the image size.y() =0 ???");
|
||||
if (size.y() == 0) {
|
||||
size = size.withY(-1);
|
||||
// Log.error("Error Request the image size.y() =0 ???");
|
||||
}
|
||||
final Uri tmpFilename = _uri;
|
||||
if (_uri.getExtention().toLowerCase().contentEquals("svg") == false) {
|
||||
size = sizeAuto;
|
||||
}
|
||||
if (size.x > 0 && size.y > 0) {
|
||||
if (size.x() > 0 && size.y() > 0) {
|
||||
Log.verbose(" == > specific size : " + size);
|
||||
size.setValue(Tools.nextP2(size.x), Tools.nextP2(size.y));
|
||||
size = new Vector2i(Tools.nextP2(size.x()), Tools.nextP2(size.y()));
|
||||
if (_sizeRegister.equals(sizeAuto) == false) {
|
||||
if (_sizeRegister.equals(sizeDefault) == false) {
|
||||
//tmpFilename.getQuery().set("x", "" + size.x));
|
||||
//tmpFilename.getQuery().set("y", "" + size.y));
|
||||
// tmpFilename.getQuery().set("x", "" + size.x));
|
||||
// tmpFilename.getQuery().set("y", "" + size.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Log.verbose("KEEP: TextureFile: '" + tmpFilename + "' new size=" + size);
|
||||
ResourceTextureFile object = null;
|
||||
final Resource object2 = getManager().localKeep(tmpFilename.toString());
|
||||
@ -83,20 +85,20 @@ public class ResourceTextureFile extends ResourceTexture2 {
|
||||
getManager().localAdd(object);
|
||||
return object;
|
||||
}
|
||||
|
||||
|
||||
protected ResourceTextureFile() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
protected ResourceTextureFile(final String _genName, final Uri _uri, final Vector2i _size) {
|
||||
super(_genName);
|
||||
Log.debug("create a new resource::Image : _genName=" + _genName + " _uri=" + _uri + " size=" + _size);
|
||||
final Image tmp = Egami.load(_uri, _size);
|
||||
set(tmp);
|
||||
}
|
||||
|
||||
|
||||
public Vector2i getRealSize() {
|
||||
return this.realImageSize;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
79
src/org/atriasoft/ewol/tools/Message.java
Normal file
79
src/org/atriasoft/ewol/tools/Message.java
Normal file
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* @author Edouard DUPIN
|
||||
* @file
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
package org.atriasoft.ewol.tools;
|
||||
|
||||
import org.atriasoft.ewol.Ewol;
|
||||
|
||||
public class Message {
|
||||
|
||||
/**
|
||||
* @brief Create a simple pop-up message on the screen for application error.
|
||||
* @param[in] _type Type of the error.
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
private static void create(Type _type, String _message){
|
||||
StdPopUp tmpPopUp = new StdPopUp();
|
||||
switch (_type) {
|
||||
case Type.info -> tmpPopUp.propertyTitle.set("<bold>_T{Info}</bold>");
|
||||
case Type.warning -> tmpPopUp.propertyTitle.set("<bold><font color='orange'>_T{Warning}</font></bold>");
|
||||
case Type.error -> tmpPopUp.propertyTitle.set("<bold><font color='red'>_T{Error}</font></bold>");
|
||||
case Type.critical -> tmpPopUp.propertyTitle.set("<bold><font colorBg='red'>_T{Critical}</font></bold>");
|
||||
}
|
||||
tmpPopUp.propertyComment.set(_message);
|
||||
tmpPopUp.addButton("_T{close}", true);
|
||||
tmpPopUp.propertyCloseOutEvent.set(true);
|
||||
// get windows:
|
||||
EwolContext context = Ewol.getContext();
|
||||
Windows windows = context.getWindows();
|
||||
if (windows == null) {
|
||||
Log.error("can not get the current windows ... ==> can not display message : " + _message);
|
||||
return;
|
||||
}
|
||||
windows.popUpWidgetPush(tmpPopUp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a simple information message
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
public static void displayInfo(String _message){
|
||||
create(Type.info, _message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a simple warning message
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
public static void displayWarning(String _message) {
|
||||
create(Type.warning, _message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a simple error message
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
public static void displayError(String _message) {
|
||||
create(Type.error,_message);
|
||||
}
|
||||
/**
|
||||
* @brief Create a simple critical message
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
public static void displayCritical(String _message){
|
||||
create(Type.critical, _message);
|
||||
}
|
||||
|
||||
private enum Type {
|
||||
info, //!< information message pop-up
|
||||
warning, //!< warning message pop-up
|
||||
error, //!< Error message pop-up
|
||||
critical //!< Critical message pop-up
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,65 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/ewol.hpp>
|
||||
#include <ewol/tools/message.hpp>
|
||||
#include <ewol/context/Context.hpp>
|
||||
#include <ewol/widget/Widget.hpp>
|
||||
#include <ewol/widget/Windows.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
#include <ewol/widget/meta/StdPopUp.hpp>
|
||||
|
||||
void ewol::tools::message::create(enum ewol::tools::message::type _type, String _message) {
|
||||
ewol::widget::StdPopUp tmpPopUp = widget::StdPopUp::create();
|
||||
if (tmpPopUp == null) {
|
||||
Log.error("Can not create a simple pop-up");
|
||||
return;
|
||||
}
|
||||
switch(_type) {
|
||||
case ewol::tools::message::type::info:
|
||||
tmpPopUp.propertyTitle.set("<bold>_T{Info}</bold>");
|
||||
break;
|
||||
case ewol::tools::message::type::warning:
|
||||
tmpPopUp.propertyTitle.set("<bold><font color='orange'>_T{Warning}</font></bold>");
|
||||
break;
|
||||
case ewol::tools::message::type::error:
|
||||
tmpPopUp.propertyTitle.set("<bold><font color='red'>_T{Error}</font></bold>");
|
||||
break;
|
||||
case ewol::tools::message::type::critical:
|
||||
tmpPopUp.propertyTitle.set("<bold><font colorBg='red'>_T{Critical}</font></bold>");
|
||||
break;
|
||||
}
|
||||
tmpPopUp.propertyComment.set(_message);
|
||||
tmpPopUp.addButton("_T{close}", true);
|
||||
tmpPopUp.propertyCloseOutEvent.set(true);
|
||||
// get windows:
|
||||
EwolContext context = ewol::getContext();
|
||||
ewol::widget::Windows windows = context.getWindows();
|
||||
if (windows == null) {
|
||||
Log.error("can not get the current windows ... ==> can not display message : " + _message);
|
||||
return;
|
||||
}
|
||||
windows.popUpWidgetPush(tmpPopUp);
|
||||
}
|
||||
|
||||
void ewol::tools::message::displayInfo( String _message) {
|
||||
ewol::tools::message::create(ewol::tools::message::type::info, _message);
|
||||
}
|
||||
|
||||
void ewol::tools::message::displayWarning( String _message) {
|
||||
ewol::tools::message::create(ewol::tools::message::type::warning, _message);
|
||||
}
|
||||
|
||||
void ewol::tools::message::displayError( String _message) {
|
||||
ewol::tools::message::create(ewol::tools::message::type::error, _message);
|
||||
}
|
||||
|
||||
void ewol::tools::message::displayCritical( String _message) {
|
||||
ewol::tools::message::create(ewol::tools::message::type::critical, _message);
|
||||
}
|
||||
|
||||
|
@ -1,52 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/debug.hpp>
|
||||
#include <ewol/widget/Widget.hpp>
|
||||
#include <etk/Color.hpp>
|
||||
#include <ewol/resource/ColorFile.hpp>
|
||||
|
||||
namespace ewol {
|
||||
namespace tools {
|
||||
namespace message {
|
||||
enum class type {
|
||||
info, //!< information message pop-up
|
||||
warning, //!< warning message pop-up
|
||||
error, //!< Error message pop-up
|
||||
critical //!< Critical message pop-up
|
||||
};
|
||||
/**
|
||||
* @brief Create a simple pop-up message on the screen for application error.
|
||||
* @param[in] _type Type of the error.
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
void create(enum ewol::tools::message::type _type, String _message);
|
||||
/**
|
||||
* @brief Create a simple information message
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
void displayInfo( String _message);
|
||||
/**
|
||||
* @brief Create a simple warning message
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
void displayWarning( String _message);
|
||||
/**
|
||||
* @brief Create a simple error message
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
void displayError( String _message);
|
||||
/**
|
||||
* @brief Create a simple critical message
|
||||
* @param[in] _message message to display (decorated text)
|
||||
*/
|
||||
void displayCritical( String _message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,215 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <ewol/ewol.hpp>
|
||||
#include <ewol/widget/Container.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ewol::widget::Container);
|
||||
|
||||
ewol::widget::Container::Container() {
|
||||
addObjectType("ewol::widget::Container");
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
ewol::widget::Container::~Container() {
|
||||
subWidgetRemove();
|
||||
}
|
||||
|
||||
Widget ewol::widget::Container::getSubWidget() {
|
||||
return this.subWidget;
|
||||
}
|
||||
|
||||
void ewol::widget::Container::setSubWidget(Widget _newWidget) {
|
||||
if (_newWidget == null) {
|
||||
return;
|
||||
}
|
||||
subWidgetRemove();
|
||||
this.subWidget = _newWidget;
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.setParent(sharedFromThis());
|
||||
}
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
|
||||
void ewol::widget::Container::subWidgetReplace( Widget _oldWidget,
|
||||
Widget _newWidget) {
|
||||
if (this.subWidget != _oldWidget) {
|
||||
Log.warning("Request replace with a wrong old widget");
|
||||
return;
|
||||
}
|
||||
this.subWidget.removeParent();
|
||||
this.subWidget.reset();
|
||||
this.subWidget = _newWidget;
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.setParent(sharedFromThis());
|
||||
}
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
|
||||
void ewol::widget::Container::subWidgetRemove() {
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.removeParent();
|
||||
this.subWidget.reset();
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::Container::subWidgetUnLink() {
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.removeParent();
|
||||
}
|
||||
this.subWidget.reset();
|
||||
}
|
||||
|
||||
EwolObject ewol::widget::Container::getSubObjectNamed( String _objectName) {
|
||||
EwolObject tmpObject = Widget::getSubObjectNamed(_objectName);
|
||||
if (tmpObject != null) {
|
||||
return tmpObject;
|
||||
}
|
||||
if (this.subWidget != null) {
|
||||
return this.subWidget.getSubObjectNamed(_objectName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void ewol::widget::Container::systemDraw( ewol::DrawProperty _displayProp) {
|
||||
if (propertyHide.get() == true){
|
||||
// widget is hidden ...
|
||||
return;
|
||||
}
|
||||
Widget::systemDraw(_displayProp);
|
||||
if (this.subWidget != null) {
|
||||
ewol::DrawProperty prop = _displayProp;
|
||||
prop.limit(this.origin, this.size);
|
||||
//Log.info("Draw : [" + propertyName + "] t=" + getObjectType() + " o=" + this.origin + " s=" + this.size);
|
||||
this.subWidget.systemDraw(prop);
|
||||
} else {
|
||||
Log.info("[" + getId() + "] ++++++ : [null]");
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::Container::onChangeSize() {
|
||||
Widget::onChangeSize();
|
||||
if (*propertyHide == true) {
|
||||
return;
|
||||
}
|
||||
if (this.subWidget == null) {
|
||||
return;
|
||||
}
|
||||
Vector2f origin = this.origin+this.offset;
|
||||
Vector2f minSize = this.subWidget.getCalculateMinSize();
|
||||
Vector2b expand = this.subWidget.propertyExpand.get();
|
||||
origin += ewol::gravityGenerateDelta(propertyGravity.get(), minSize - this.size);
|
||||
this.subWidget.setOrigin(origin);
|
||||
this.subWidget.setSize(this.size);
|
||||
this.subWidget.onChangeSize();
|
||||
}
|
||||
|
||||
void ewol::widget::Container::calculateMinMaxSize() {
|
||||
// call main class
|
||||
Widget::calculateMinMaxSize();
|
||||
// call sub classes
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.calculateMinMaxSize();
|
||||
Vector2f min = this.subWidget.getCalculateMinSize();
|
||||
this.minSize.setMax(min);
|
||||
}
|
||||
//Log.error("[" + getId() + "] Result min size : " + this.minSize);
|
||||
}
|
||||
|
||||
void ewol::widget::Container::onRegenerateDisplay() {
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.onRegenerateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
Widget ewol::widget::Container::getWidgetAtPos( Vector2f _pos) {
|
||||
if (propertyHide.get() == false) {
|
||||
if (this.subWidget != null) {
|
||||
return this.subWidget.getWidgetAtPos(_pos);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
boolean ewol::widget::Container::loadXML( exml::Element _node) {
|
||||
if (_node.exist() == false) {
|
||||
return false;
|
||||
}
|
||||
// parse generic properties:
|
||||
Widget::loadXML(_node);
|
||||
// remove previous element:
|
||||
subWidgetRemove();
|
||||
// parse all the elements:
|
||||
for ( auto it : _node.nodes) {
|
||||
exml::Element pNode = it.toElement();
|
||||
if (pNode.exist() == false) {
|
||||
// trash here all that is not element
|
||||
continue;
|
||||
}
|
||||
String widgetName = pNode.getValue();
|
||||
Log.verbose("[" + getId() + "] t=" + getObjectType() + " Load node name : '" + widgetName + "'");
|
||||
if (getWidgetManager().exist(widgetName) == false) {
|
||||
Log.error("(l " + pNode.getPos() + ") Unknown basic node='" + widgetName + "' not in : [" + getWidgetManager().list() + "]" );
|
||||
continue;
|
||||
}
|
||||
if (getSubWidget() != null) {
|
||||
Log.error("(l " + pNode.getPos() + ") Can only have one subWidget ??? node='" + widgetName + "'" );
|
||||
continue;
|
||||
}
|
||||
Log.debug("try to create subwidget : '" + widgetName + "'");
|
||||
Widget tmpWidget = getWidgetManager().create(widgetName, pNode);
|
||||
if (tmpWidget == null) {
|
||||
EWOL_ERROR ("(l " + pNode.getPos() + ") Can not create the widget : '" + widgetName + "'");
|
||||
continue;
|
||||
}
|
||||
// add widget :
|
||||
setSubWidget(tmpWidget);
|
||||
if (tmpWidget.loadXML(pNode) == false) {
|
||||
EWOL_ERROR ("(l " + pNode.getPos() + ") can not load widget properties : '" + widgetName + "'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( _node.nodes.size() != 0
|
||||
LOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOM this.subWidget == null) {
|
||||
Log.warning("Load container with no data inside");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ewol::widget::Container::setOffset( Vector2f _newVal) {
|
||||
if (this.offset != _newVal) {
|
||||
Widget::setOffset(_newVal);
|
||||
// recalculate the new sise and position of sub widget ...
|
||||
onChangeSize();
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::Container::requestDestroyFromChild( EwolObject _child) {
|
||||
if (this.subWidget != _child) {
|
||||
return;
|
||||
}
|
||||
if (this.subWidget == null) {
|
||||
return;
|
||||
}
|
||||
this.subWidget.removeParent();
|
||||
this.subWidget.reset();
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::Container::drawWidgetTree(int _level) {
|
||||
Widget::drawWidgetTree(_level);
|
||||
_level++;
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.drawWidgetTree(_level);
|
||||
}
|
||||
}
|
@ -1,73 +1,225 @@
|
||||
import org.atriasoft.etk.math.Vector2b;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.ewol.DrawProperty;
|
||||
import org.atriasoft.ewol.Gravity;
|
||||
import org.atriasoft.ewol.internal.Log;
|
||||
import org.atriasoft.ewol.object.EwolObject;
|
||||
import org.atriasoft.ewol.widget.Widget;
|
||||
import org.atriasoft.exml.model.XmlElement;
|
||||
import org.atriasoft.exml.model.XmlNode;
|
||||
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/debug.hpp>
|
||||
#include <ewol/widget/Widget.hpp>
|
||||
|
||||
namespace ewol {
|
||||
namespace widget {
|
||||
class Container;
|
||||
using Container = ememory::Ptr<ewol::widget::Container>;
|
||||
using ContainerWeak = ememory::WeakPtr<ewol::widget::Container>;
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
* @brief the Cotainer widget is a widget that have an only one subWidget
|
||||
*/
|
||||
class Container : public Widget {
|
||||
protected:
|
||||
Widget this.subWidget;
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
Container();
|
||||
public:
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~Container();
|
||||
public:
|
||||
/**
|
||||
* @brief get the main node widget
|
||||
* @return the requested pointer on the node
|
||||
*/
|
||||
Widget getSubWidget();
|
||||
/**
|
||||
* @brief set the subWidget node widget.
|
||||
* @param[in] _newWidget The widget to add.
|
||||
*/
|
||||
void setSubWidget(Widget _newWidget);
|
||||
/**
|
||||
* @brief Replace a old subwidget with a new one.
|
||||
* @param[in] _oldWidget The widget to replace.
|
||||
* @param[in] _newWidget The widget to set.
|
||||
*/
|
||||
void subWidgetReplace( Widget _oldWidget,
|
||||
Widget _newWidget);
|
||||
/**
|
||||
* @brief remove the subWidget node (async).
|
||||
*/
|
||||
void subWidgetRemove();
|
||||
/**
|
||||
* @brief Unlink the subwidget Node.
|
||||
*/
|
||||
void subWidgetUnLink();
|
||||
public:
|
||||
void systemDraw( ewol::DrawProperty _displayProp) ;
|
||||
void onRegenerateDisplay() ;
|
||||
void onChangeSize() ;
|
||||
void calculateMinMaxSize() ;
|
||||
Widget getWidgetAtPos( Vector2f _pos) ;
|
||||
EwolObject getSubObjectNamed( String _objectName) ;
|
||||
boolean loadXML( exml::Element _node) ;
|
||||
void setOffset( Vector2f _newVal) ;
|
||||
void requestDestroyFromChild( EwolObject _child) ;
|
||||
void drawWidgetTree(int _level=0) ;
|
||||
};
|
||||
/*
|
||||
* @ingroup ewolWidgetGroup
|
||||
* @brief the Cotainer widget is a widget that have an only one subWidget
|
||||
*/
|
||||
class Container extends Widget {
|
||||
protected Widget subWidget = null;
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
public Container() {
|
||||
super();
|
||||
}
|
||||
/**
|
||||
* @brief get the main node widget
|
||||
* @return the requested pointer on the node
|
||||
*/
|
||||
public Widget getSubWidget(){
|
||||
return this.subWidget;
|
||||
}
|
||||
/**
|
||||
* @brief set the subWidget node widget.
|
||||
* @param[in] _newWidget The widget to add.
|
||||
*/
|
||||
public void setSubWidget(Widget _newWidget){
|
||||
if (_newWidget == null) {
|
||||
return;
|
||||
}
|
||||
subWidgetRemove();
|
||||
this.subWidget = _newWidget;
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.setParent(this);
|
||||
}
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
/**
|
||||
* @brief Replace a old subwidget with a new one.
|
||||
* @param[in] _oldWidget The widget to replace.
|
||||
* @param[in] _newWidget The widget to set.
|
||||
*/
|
||||
public void subWidgetReplace( Widget _oldWidget,
|
||||
Widget _newWidget){
|
||||
if (this.subWidget != _oldWidget) {
|
||||
Log.warning("Request replace with a wrong old widget");
|
||||
return;
|
||||
}
|
||||
this.subWidget.removeParent();
|
||||
this.subWidget = _newWidget;
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.setParent(this);
|
||||
}
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
/**
|
||||
* @brief remove the subWidget node (async).
|
||||
*/
|
||||
public void subWidgetRemove() {
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.removeParent();
|
||||
this.subWidget = null;
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Unlink the subwidget Node.
|
||||
*/
|
||||
public void subWidgetUnLink(){
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.removeParent();
|
||||
}
|
||||
this.subWidget = null;
|
||||
}
|
||||
public void systemDraw( DrawProperty _displayProp){
|
||||
if (propertyHide){
|
||||
// widget is hidden ...
|
||||
return;
|
||||
}
|
||||
super.systemDraw(_displayProp);
|
||||
if (this.subWidget != null) {
|
||||
DrawProperty prop = _displayProp.withLimit(this.origin, this.size);
|
||||
//Log.info("Draw : [" + propertyName + "] t=" + getObjectType() + " o=" + this.origin + " s=" + this.size);
|
||||
this.subWidget.systemDraw(prop);
|
||||
} else {
|
||||
Log.info("[" + getId() + "] ++++++ : [null]");
|
||||
}
|
||||
}
|
||||
public void onRegenerateDisplay() {
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.onRegenerateDisplay();
|
||||
}
|
||||
}
|
||||
public void onChangeSize() {
|
||||
super.onChangeSize();
|
||||
if (propertyHide) {
|
||||
return;
|
||||
}
|
||||
if (this.subWidget == null) {
|
||||
return;
|
||||
}
|
||||
Vector2f origin = this.origin.add(this.offset);
|
||||
Vector2f minSize = this.subWidget.getCalculateMinSize();
|
||||
Vector2b expand = this.subWidget.getPropertyExpand();
|
||||
origin = origin.add(Gravity.gravityGenerateDelta(propertyGravity, minSize.less(this.size)));
|
||||
this.subWidget.setOrigin(origin);
|
||||
this.subWidget.setSize(this.size);
|
||||
this.subWidget.onChangeSize();
|
||||
}
|
||||
public void calculateMinMaxSize(){
|
||||
// call main class
|
||||
super.calculateMinMaxSize();
|
||||
// call sub classes
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.calculateMinMaxSize();
|
||||
Vector2f min = this.subWidget.getCalculateMinSize();
|
||||
this.minSize = Vector2f.max(this.minSize, min);
|
||||
}
|
||||
//Log.error("[" + getId() + "] Result min size : " + this.minSize);
|
||||
}
|
||||
public Widget getWidgetAtPos( Vector2f _pos) {
|
||||
if (!propertyHide) {
|
||||
if (this.subWidget != null) {
|
||||
return this.subWidget.getWidgetAtPos(_pos);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
};
|
||||
public EwolObject getSubObjectNamed( String _objectName) {
|
||||
EwolObject tmpObject = super.getSubObjectNamed(_objectName);
|
||||
if (tmpObject != null) {
|
||||
return tmpObject;
|
||||
}
|
||||
if (this.subWidget != null) {
|
||||
return this.subWidget.getSubObjectNamed(_objectName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean loadXML( XmlElement _node) {
|
||||
if (_node == null) {
|
||||
return false;
|
||||
}
|
||||
// parse generic properties:
|
||||
super.loadXML(_node);
|
||||
// remove previous element:
|
||||
subWidgetRemove();
|
||||
// parse all the elements:
|
||||
for (XmlNode it : _node.getNodes()) {
|
||||
if (!it.isElement()) {
|
||||
// trash here all that is not element
|
||||
continue;
|
||||
}
|
||||
XmlElement pNode = it.toElement();
|
||||
String widgetName = pNode.getValue();
|
||||
Log.verbose("[" + getId() + "] t=" + getClass().getCanonicalName() + " Load node name : '" + widgetName + "'");
|
||||
if (!getWidgetManager().exist(widgetName)) {
|
||||
Log.error("Unknown basic node='" + widgetName + "' not in : [" + getWidgetManager().list() + "]" );
|
||||
continue;
|
||||
}
|
||||
if (getSubWidget() != null) {
|
||||
Log.error("Can only have one subWidget ??? node='" + widgetName + "'" );
|
||||
continue;
|
||||
}
|
||||
Log.debug("try to create subwidget : '" + widgetName + "'");
|
||||
Widget tmpWidget = getWidgetManager().create(widgetName, pNode);
|
||||
if (tmpWidget == null) {
|
||||
Log.error ("Can not create the widget : '" + widgetName + "'");
|
||||
continue;
|
||||
}
|
||||
// add widget :
|
||||
setSubWidget(tmpWidget);
|
||||
if (!tmpWidget.loadXML(pNode)) {
|
||||
Log.error ("can not load widget properties : '" + widgetName + "'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (_node.getNodes().size() != 0 && this.subWidget == null) {
|
||||
Log.warning("Load container with no data inside");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void setOffset( Vector2f _newVal) {
|
||||
if (this.offset.equals(_newVal)) {
|
||||
return;
|
||||
}
|
||||
super.setOffset(_newVal);
|
||||
// recalculate the new sise and position of sub widget ...
|
||||
onChangeSize();
|
||||
|
||||
}
|
||||
public void requestDestroyFromChild( EwolObject _child){
|
||||
if (this.subWidget != _child) {
|
||||
return;
|
||||
}
|
||||
if (this.subWidget == null) {
|
||||
return;
|
||||
}
|
||||
this.subWidget.removeParent();
|
||||
this.subWidget = null;
|
||||
markToRedraw();
|
||||
}
|
||||
public void drawWidgetTree(int _level) {
|
||||
super.drawWidgetTree(_level);
|
||||
_level++;
|
||||
if (this.subWidget != null) {
|
||||
this.subWidget.drawWidgetTree(_level);
|
||||
}
|
||||
}
|
||||
};
|
@ -1,342 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
|
||||
#include <ewol/ewol.hpp>
|
||||
#include <ewol/widget/ContainerN.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ewol::widget::ContainerN);
|
||||
|
||||
ewol::widget::ContainerN::ContainerN() :
|
||||
propertyLockExpand(this, "lock",
|
||||
Vector2f(false,false),
|
||||
"Lock the subwidget expand",
|
||||
ewol::widget::ContainerN::onChangePropertyLockExpand),
|
||||
this.subExpend(false,false) {
|
||||
addObjectType("ewol::widget::ContainerN");
|
||||
// nothing to do ...
|
||||
}
|
||||
|
||||
ewol::widget::ContainerN::~ContainerN() {
|
||||
subWidgetRemoveAll();
|
||||
}
|
||||
|
||||
|
||||
Vector2b ewol::widget::ContainerN::canExpand() {
|
||||
Vector2b res = propertyExpand.get();
|
||||
if (propertyLockExpand.x() == false) {
|
||||
if (this.subExpend.x() == true) {
|
||||
res.setX(true);
|
||||
}
|
||||
}
|
||||
if (propertyLockExpand.y() == false) {
|
||||
if (this.subExpend.y() == true) {
|
||||
res.setY(true);
|
||||
}
|
||||
}
|
||||
//Log.debug("Expend check : user=" + this.userExpand + " lock=" + propertyLockExpand + " sub=" + this.subExpend + " res=" + res);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::onChangePropertyLockExpand() {
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::subWidgetReplace(Widget _oldWidget,
|
||||
Widget _newWidget) {
|
||||
boolean haveChange = false;
|
||||
for (auto it : this.subWidget) {
|
||||
if (it != _oldWidget) {
|
||||
continue;
|
||||
}
|
||||
it.removeParent();
|
||||
it.reset();
|
||||
if (_newWidget != null) {
|
||||
_newWidget.setParent(sharedFromThis());
|
||||
}
|
||||
it = _newWidget;
|
||||
haveChange = true;
|
||||
}
|
||||
if (haveChange == false) {
|
||||
Log.warning("Request replace with a wrong old widget");
|
||||
return;
|
||||
}
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
|
||||
int ewol::widget::ContainerN::subWidgetAdd(Widget _newWidget) {
|
||||
if (_newWidget == null) {
|
||||
Log.error("[" + getId() + "] {" + getObjectType() + "} Try to add An empty Widget ... ");
|
||||
return -1;
|
||||
}
|
||||
_newWidget.setParent(sharedFromThis());
|
||||
this.subWidget.pushBack(_newWidget);
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
// added at the last eelement :
|
||||
return _newWidget.getId();
|
||||
}
|
||||
|
||||
int ewol::widget::ContainerN::subWidgetAddStart(Widget _newWidget) {
|
||||
if (_newWidget == null) {
|
||||
Log.error("[" + getId() + "] {" + getObjectType() + "} Try to add start An empty Widget ... ");
|
||||
return -1;
|
||||
}
|
||||
if (_newWidget != null) {
|
||||
_newWidget.setParent(sharedFromThis());
|
||||
}
|
||||
this.subWidget.insert(this.subWidget.begin(), _newWidget);
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
return _newWidget.getId();
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::subWidgetRemove(Widget _newWidget) {
|
||||
if (_newWidget == null) {
|
||||
return;
|
||||
}
|
||||
int errorControl = this.subWidget.size();
|
||||
|
||||
auto it(this.subWidget.begin());
|
||||
while (it != this.subWidget.end()) {
|
||||
if (_newWidget == *it) {
|
||||
(*it).removeParent();
|
||||
this.subWidget.erase(it);
|
||||
it = this.subWidget.begin();
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::subWidgetUnLink(Widget _newWidget) {
|
||||
if (_newWidget == null) {
|
||||
return;
|
||||
}
|
||||
auto it(this.subWidget.begin());
|
||||
while (it != this.subWidget.end()) {
|
||||
if (_newWidget == *it) {
|
||||
(*it).removeParent();
|
||||
(*it).reset();
|
||||
this.subWidget.erase(it);
|
||||
it = this.subWidget.begin();
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::subWidgetRemoveAll() {
|
||||
for(auto it : this.subWidget) {
|
||||
if (it != null) {
|
||||
it.removeParent();
|
||||
}
|
||||
it.reset();
|
||||
}
|
||||
this.subWidget.clear();
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::subWidgetRemoveAllDelayed() {
|
||||
subWidgetRemoveAll();
|
||||
}
|
||||
|
||||
EwolObject ewol::widget::ContainerN::getSubObjectNamed( String _objectName) {
|
||||
EwolObject tmpObject = Widget::getSubObjectNamed(_objectName);
|
||||
if (tmpObject != null) {
|
||||
return tmpObject;
|
||||
}
|
||||
for (auto it : this.subWidget) {
|
||||
if (it != null) {
|
||||
tmpObject = it.getSubObjectNamed(_objectName);
|
||||
if (tmpObject != null) {
|
||||
return tmpObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::systemDraw( ewol::DrawProperty _displayProp) {
|
||||
if (*propertyHide == true){
|
||||
// widget is hidden ...
|
||||
return;
|
||||
}
|
||||
// local widget draw
|
||||
Widget::systemDraw(_displayProp);
|
||||
// subwidget draw
|
||||
ewol::DrawProperty prop = _displayProp;
|
||||
prop.limit(this.origin, this.size);
|
||||
for (long iii = this.subWidget.size()-1; iii>=0; --iii) {
|
||||
if (this.subWidget[iii] != null) {
|
||||
//Log.info(" ***** : [" + (*it).propertyName + "] t=" + (*it).getObjectType() + " o=" + (*it).this.origin + " s=" + (*it).this.size);
|
||||
this.subWidget[iii].systemDraw(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::onChangeSize() {
|
||||
for (auto it : this.subWidget) {
|
||||
if (it == null) {
|
||||
continue;
|
||||
}
|
||||
it.setOrigin(this.origin+this.offset);
|
||||
it.setSize(this.size);
|
||||
it.onChangeSize();
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::calculateMinMaxSize() {
|
||||
this.subExpend.setValue(false, false);
|
||||
this.minSize.setValue(0,0);
|
||||
this.maxSize.setValue(ULTIMATE_MAX_SIZE,ULTIMATE_MAX_SIZE);
|
||||
//Log.error("[" + getId() + "] {" + getObjectType() + "} set min size : " + this.minSize);
|
||||
for (auto it : this.subWidget) {
|
||||
if (it != null) {
|
||||
it.calculateMinMaxSize();
|
||||
Vector2b subExpendProp = it.canExpand();
|
||||
if (true == subExpendProp.x()) {
|
||||
this.subExpend.setX(true);
|
||||
}
|
||||
if (true == subExpendProp.y()) {
|
||||
this.subExpend.setY(true);
|
||||
}
|
||||
Vector2f tmpSize = it.getCalculateMinSize();
|
||||
this.minSize.setValue( etk::max(tmpSize.x(), this.minSize.x()),
|
||||
etk::max(tmpSize.y(), this.minSize.y()) );
|
||||
}
|
||||
}
|
||||
//Log.error("[" + getId() + "] {" + getObjectType() + "} Result min size : " + this.minSize);
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::onRegenerateDisplay() {
|
||||
for (auto it : this.subWidget) {
|
||||
if (it != null) {
|
||||
it.onRegenerateDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Widget ewol::widget::ContainerN::getWidgetAtPos( Vector2f _pos) {
|
||||
if (*propertyHide == true) {
|
||||
return null;
|
||||
}
|
||||
// for all element in the sizer ...
|
||||
for (auto it : this.subWidget) {
|
||||
if (it != null) {
|
||||
Vector2f tmpSize = it.getSize();
|
||||
Vector2f tmpOrigin = it.getOrigin();
|
||||
if( (tmpOrigin.x() <= _pos.x() LOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOM tmpOrigin.x() + tmpSize.x() >= _pos.x())
|
||||
LOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOM (tmpOrigin.y() <= _pos.y() LOMLOMLOMLOMLOM tmpOrigin.y() + tmpSize.y() >= _pos.y()) )
|
||||
{
|
||||
Widget tmpWidget = it.getWidgetAtPos(_pos);
|
||||
if (tmpWidget != null) {
|
||||
return tmpWidget;
|
||||
}
|
||||
// stop searching
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
boolean ewol::widget::ContainerN::loadXML( exml::Element _node) {
|
||||
if (_node.exist() == false) {
|
||||
return false;
|
||||
}
|
||||
// parse generic properties :
|
||||
Widget::loadXML(_node);
|
||||
// remove previous element :
|
||||
subWidgetRemoveAll();
|
||||
|
||||
String tmpAttributeValue = _node.attributes["lock"];
|
||||
if (tmpAttributeValue.size()!=0) {
|
||||
propertyLockExpand.set(tmpAttributeValue);
|
||||
}
|
||||
boolean invertAdding=false;
|
||||
tmpAttributeValue = _node.attributes["addmode"];
|
||||
if(etk::compare_no_case(tmpAttributeValue, "invert")) {
|
||||
invertAdding=true;
|
||||
}
|
||||
// parse all the elements :
|
||||
for ( auto nodeIt : _node.nodes) {
|
||||
exml::Element pNode = nodeIt.toElement();
|
||||
if (pNode.exist() == false) {
|
||||
// trash here all that is not element
|
||||
continue;
|
||||
}
|
||||
String widgetName = pNode.getValue();
|
||||
Log.verbose(" t=" + getObjectType() + " Load node name : '" + widgetName + "'");
|
||||
if (getWidgetManager().exist(widgetName) == false) {
|
||||
Log.error("[" + getId() + "] {" + getObjectType() + "} (l " + pNode.getPos() + ") Unknown basic node='" + widgetName + "' not in : [" << getWidgetManager().list() << "]" );
|
||||
continue;
|
||||
}
|
||||
Log.debug("[" + getId() + "] {" + getObjectType() + "} load new element : '" + widgetName + "'");
|
||||
Widget subWidget = getWidgetManager().create(widgetName, pNode);
|
||||
if (subWidget == null) {
|
||||
EWOL_ERROR ("[" + getId() + "] {" + getObjectType() + "} (l " + pNode.getPos() + ") Can not create the widget : '" + widgetName + "'");
|
||||
continue;
|
||||
}
|
||||
// add sub element :
|
||||
if (invertAdding == false) {
|
||||
subWidgetAdd(subWidget);
|
||||
} else {
|
||||
subWidgetAddStart(subWidget);
|
||||
}
|
||||
if (subWidget.loadXML(pNode) == false) {
|
||||
Log.error("[" + getId() + "] {" + getObjectType() + "} (l " + pNode.getPos() + ") can not load widget properties : '" + widgetName + "'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ewol::widget::ContainerN::setOffset( Vector2f _newVal) {
|
||||
if (this.offset != _newVal) {
|
||||
Widget::setOffset(_newVal);
|
||||
// recalculate the new sise and position of sub widget ...
|
||||
onChangeSize();
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::requestDestroyFromChild( EwolObject _child) {
|
||||
auto it = this.subWidget.begin();
|
||||
while (it != this.subWidget.end()) {
|
||||
if (*it == _child) {
|
||||
if (*it == null) {
|
||||
this.subWidget.erase(it);
|
||||
it = this.subWidget.begin();
|
||||
continue;
|
||||
}
|
||||
(*it).removeParent();
|
||||
(*it).reset();
|
||||
this.subWidget.erase(it);
|
||||
it = this.subWidget.begin();
|
||||
markToRedraw();
|
||||
continue;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void ewol::widget::ContainerN::drawWidgetTree(int _level) {
|
||||
Widget::drawWidgetTree(_level);
|
||||
_level++;
|
||||
for (auto it: this.subWidget) {
|
||||
if (it != null) {
|
||||
it.drawWidgetTree(_level);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,105 +1,375 @@
|
||||
/** @file
|
||||
package org.atriasoft.ewol.widget; /** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/debug.hpp>
|
||||
#include <ewol/widget/Widget.hpp>
|
||||
import org.atriasoft.etk.math.Vector2b;
|
||||
import org.atriasoft.ewol.DrawProperty;
|
||||
import org.atriasoft.ewol.annotation.EwolDescription;
|
||||
import org.atriasoft.ewol.internal.Log;
|
||||
import org.atriasoft.ewol.widget.Widget;
|
||||
import org.atriasoft.exml.annotation.XmlManaged;
|
||||
import org.atriasoft.exml.annotation.XmlName;
|
||||
import org.atriasoft.exml.annotation.XmlProperty;
|
||||
|
||||
namespace ewol {
|
||||
namespace widget {
|
||||
class ContainerN;
|
||||
using ContainerN = ememory::Ptr<ewol::widget::ContainerN>;
|
||||
using ContainerNWeak = ememory::WeakPtr<ewol::widget::ContainerN>;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
* @brief the Cotainer widget is a widget that have an only one subWidget
|
||||
*/
|
||||
public class ContainerN extends Widget {
|
||||
@XmlManaged()
|
||||
@XmlProperty()
|
||||
@XmlName(value = "lock")
|
||||
@EwolDescription(value = "Lock the subwidget expand")
|
||||
protected Vector2b propertyLockExpand = new Vector2b(false,false); //!< Lock the expend of the sub widget to this one == > this permit to limit bigger subWidget
|
||||
protected List<Widget> subWidget = new ArrayList<>();
|
||||
protected Vector2b subExpend = new Vector2b(false,false); //!< reference of the sub element expention requested.
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
protected ContainerN() {}
|
||||
// herited function
|
||||
public Vector2b canExpand() {
|
||||
Vector2b res = propertyExpand;
|
||||
if (!propertyLockExpand.x()) {
|
||||
if (this.subExpend.x()) {
|
||||
res = res.withX(true);
|
||||
}
|
||||
}
|
||||
if (!propertyLockExpand.y()) {
|
||||
if (this.subExpend.y()) {
|
||||
res = res.withY(true);
|
||||
}
|
||||
}
|
||||
//Log.debug("Expend check : user=" + this.userExpand + " lock=" + propertyLockExpand + " sub=" + this.subExpend + " res=" + res);
|
||||
return res;
|
||||
}
|
||||
/**
|
||||
* @brief remove all sub element from the widget.
|
||||
*/
|
||||
public void subWidgetRemoveAll(){
|
||||
for(Widget it : this.subWidget) {
|
||||
if (it != null) {
|
||||
it.removeParent();
|
||||
}
|
||||
it = null;
|
||||
}
|
||||
this.subWidget.clear();
|
||||
}
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
* @brief the Cotainer widget is a widget that have an only one subWidget
|
||||
* @brief remove all sub element from the widget (delayed to prevent remove in the callbback).
|
||||
*/
|
||||
class ContainerN : public Widget {
|
||||
public: // properties:
|
||||
eproperty::Value<Vector2b> propertyLockExpand; //!< Lock the expend of the sub widget to this one == > this permit to limit bigger subWidget
|
||||
protected:
|
||||
List<Widget> this.subWidget;
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*/
|
||||
ContainerN();
|
||||
public:
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~ContainerN();
|
||||
protected:
|
||||
Vector2b this.subExpend; //!< reference of the sub element expention requested.
|
||||
// herited function
|
||||
Vector2b canExpand() ;
|
||||
public:
|
||||
/**
|
||||
* @brief remove all sub element from the widget.
|
||||
*/
|
||||
void subWidgetRemoveAll();
|
||||
/**
|
||||
* @brief remove all sub element from the widget (delayed to prevent remove in the callbback).
|
||||
*/
|
||||
void subWidgetRemoveAllDelayed();
|
||||
/**
|
||||
* @brief Replace a old subwidget with a new one.
|
||||
* @param[in] _oldWidget The widget to replace.
|
||||
* @param[in] _newWidget The widget to set.
|
||||
*/
|
||||
void subWidgetReplace(Widget _oldWidget,
|
||||
Widget _newWidget);
|
||||
/**
|
||||
* @brief add at end position a Widget (note : This system use an inverted phylisophie (button to top, and left to right)
|
||||
* @param[in] _newWidget the element pointer
|
||||
* @return the ID of the set element
|
||||
*/
|
||||
int subWidgetAdd(Widget _newWidget);
|
||||
//! @previous
|
||||
int subWidgetAddBack(Widget _newWidget) {
|
||||
return subWidgetAdd(_newWidget);
|
||||
};
|
||||
//! @previous
|
||||
int subWidgetAddEnd(Widget _newWidget) {
|
||||
return subWidgetAdd(_newWidget);
|
||||
};
|
||||
/**
|
||||
* @brief add at start position a Widget (note : This system use an inverted phylisophie (button to top, and left to right)
|
||||
* @param[in] _newWidget the element pointer
|
||||
* @return the ID of the set element
|
||||
*/
|
||||
int subWidgetAddStart(Widget _newWidget);
|
||||
//! @previous
|
||||
int subWidgetAddFront(Widget _newWidget) {
|
||||
return subWidgetAddStart(_newWidget);
|
||||
};
|
||||
/**
|
||||
* @brief remove definitly a widget from the system and this layer.
|
||||
* @param[in] _newWidget the element pointer.
|
||||
*/
|
||||
void subWidgetRemove(Widget _newWidget);
|
||||
/**
|
||||
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...)
|
||||
* @param[in] _newWidget the element pointer.
|
||||
*/
|
||||
void subWidgetUnLink(Widget _newWidget);
|
||||
public:
|
||||
void systemDraw( ewol::DrawProperty _displayProp) ;
|
||||
void onRegenerateDisplay() ;
|
||||
void onChangeSize() ;
|
||||
void calculateMinMaxSize() ;
|
||||
Widget getWidgetAtPos( Vector2f _pos) ;
|
||||
EwolObject getSubObjectNamed( String _objectName) ;
|
||||
boolean loadXML( exml::Element _node) ;
|
||||
void setOffset( Vector2f _newVal) ;
|
||||
void requestDestroyFromChild( EwolObject _child) ;
|
||||
void drawWidgetTree(int _level=0) ;
|
||||
protected:
|
||||
void onChangePropertyLockExpand();
|
||||
public void subWidgetRemoveAllDelayed(){
|
||||
subWidgetRemoveAll();
|
||||
}
|
||||
/**
|
||||
* @brief Replace a old subwidget with a new one.
|
||||
* @param[in] _oldWidget The widget to replace.
|
||||
* @param[in] _newWidget The widget to set.
|
||||
*/
|
||||
public void subWidgetReplace(Widget _oldWidget,
|
||||
Widget _newWidget) {
|
||||
boolean haveChange = false;
|
||||
for (Widget it : this.subWidget) {
|
||||
if (it != _oldWidget) {
|
||||
continue;
|
||||
}
|
||||
it.removeParent();
|
||||
it.reset();
|
||||
if (_newWidget != null) {
|
||||
_newWidget.setParent(this);
|
||||
}
|
||||
it = _newWidget;
|
||||
haveChange = true;
|
||||
}
|
||||
if (!haveChange) {
|
||||
Log.warning("Request replace with a wrong old widget");
|
||||
return;
|
||||
}
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
/**
|
||||
* @brief add at end position a Widget (note : This system use an inverted phylisophie (button to top, and left to right)
|
||||
* @param[in] _newWidget the element pointer
|
||||
* @return the ID of the set element
|
||||
*/
|
||||
public int subWidgetAdd(Widget _newWidget) {
|
||||
if (_newWidget == null) {
|
||||
Log.error("[" + getId() + "] {" + getClass().getCanonicalName() + "} Try to add An empty Widget ... ");
|
||||
return -1;
|
||||
}
|
||||
_newWidget.setParent(this);
|
||||
this.subWidget.add(_newWidget);
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
// added at the last eelement :
|
||||
return _newWidget.getId();
|
||||
}
|
||||
|
||||
//! @previous
|
||||
public int subWidgetAddBack(Widget _newWidget) {
|
||||
return subWidgetAdd(_newWidget);
|
||||
};
|
||||
//! @previous
|
||||
public int subWidgetAddEnd(Widget _newWidget) {
|
||||
return subWidgetAdd(_newWidget);
|
||||
};
|
||||
/**
|
||||
* @brief add at start position a Widget (note : This system use an inverted phylisophie (button to top, and left to right)
|
||||
* @param[in] _newWidget the element pointer
|
||||
* @return the ID of the set element
|
||||
*/
|
||||
public int subWidgetAddStart(Widget _newWidget) {
|
||||
if (_newWidget == null) {
|
||||
Log.error("[" + getId() + "] {" + getClass().getCanonicalName() + "} Try to add start An empty Widget ... ");
|
||||
return -1;
|
||||
}
|
||||
if (_newWidget != null) {
|
||||
_newWidget.setParent(this);
|
||||
}
|
||||
this.subWidget.insert(this.subWidget.begin(), _newWidget);
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
return _newWidget.getId();
|
||||
}
|
||||
//! @previous
|
||||
public int subWidgetAddFront(Widget _newWidget) {
|
||||
return subWidgetAddStart(_newWidget);
|
||||
};
|
||||
/**
|
||||
* @brief remove definitly a widget from the system and this layer.
|
||||
* @param[in] _newWidget the element pointer.
|
||||
*/
|
||||
public void subWidgetRemove(Widget _newWidget){
|
||||
if (_newWidget == null) {
|
||||
return;
|
||||
}
|
||||
int errorControl = this.subWidget.size();
|
||||
|
||||
auto it(this.subWidget.begin());
|
||||
while (it != this.subWidget.end()) {
|
||||
if (_newWidget == *it) {
|
||||
(*it).removeParent();
|
||||
this.subWidget.erase(it);
|
||||
it = this.subWidget.begin();
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @brief Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...)
|
||||
* @param[in] _newWidget the element pointer.
|
||||
*/
|
||||
public void subWidgetUnLink(Widget _newWidget) {
|
||||
if (_newWidget == null) {
|
||||
return;
|
||||
}
|
||||
auto it(this.subWidget.begin());
|
||||
while (it != this.subWidget.end()) {
|
||||
if (_newWidget == *it) {
|
||||
(*it).removeParent();
|
||||
(*it).reset();
|
||||
this.subWidget.erase(it);
|
||||
it = this.subWidget.begin();
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void systemDraw( DrawProperty _displayProp) {
|
||||
if (propertyHide){
|
||||
// widget is hidden ...
|
||||
return;
|
||||
}
|
||||
// local widget draw
|
||||
super.systemDraw(_displayProp);
|
||||
// subwidget draw
|
||||
DrawProperty prop = _displayProp;
|
||||
prop = prop.withLimit(this.origin, this.size);
|
||||
for (long iii = this.subWidget.size()-1; iii>=0; --iii) {
|
||||
if (this.subWidget[iii] != null) {
|
||||
//Log.info(" ***** : [" + (*it).propertyName + "] t=" + (*it).getObjectType() + " o=" + (*it).this.origin + " s=" + (*it).this.size);
|
||||
this.subWidget[iii].systemDraw(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onRegenerateDisplay(){
|
||||
for (Widget it : this.subWidget) {
|
||||
if (it != null) {
|
||||
it.onRegenerateDisplay();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onChangeSize(){
|
||||
for (Widget it : this.subWidget) {
|
||||
if (it == null) {
|
||||
continue;
|
||||
}
|
||||
it.setOrigin(this.origin+this.offset);
|
||||
it.setSize(this.size);
|
||||
it.onChangeSize();
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateMinMaxSize() {
|
||||
this.subExpend.setValue(false, false);
|
||||
this.minSize.setValue(0,0);
|
||||
this.maxSize.setValue(ULTIMATE_MAX_SIZE,ULTIMATE_MAX_SIZE);
|
||||
//Log.error("[" + getId() + "] {" + getObjectType() + "} set min size : " + this.minSize);
|
||||
for (Widget it : this.subWidget) {
|
||||
if (it != null) {
|
||||
it.calculateMinMaxSize();
|
||||
Vector2b subExpendProp = it.canExpand();
|
||||
if (true == subExpendProp.x()) {
|
||||
this.subExpend.setX(true);
|
||||
}
|
||||
if (true == subExpendProp.y()) {
|
||||
this.subExpend.setY(true);
|
||||
}
|
||||
Vector2f tmpSize = it.getCalculateMinSize();
|
||||
this.minSize.setValue( etk::max(tmpSize.x(), this.minSize.x()),
|
||||
etk::max(tmpSize.y(), this.minSize.y()) );
|
||||
}
|
||||
}
|
||||
//Log.error("[" + getId() + "] {" + getObjectType() + "} Result min size : " + this.minSize);
|
||||
}
|
||||
public Widget getWidgetAtPos( Vector2f _pos) {
|
||||
if (*propertyHide == true) {
|
||||
return null;
|
||||
}
|
||||
// for all element in the sizer ...
|
||||
for (Widget it : this.subWidget) {
|
||||
if (it != null) {
|
||||
Vector2f tmpSize = it.getSize();
|
||||
Vector2f tmpOrigin = it.getOrigin();
|
||||
if( (tmpOrigin.x() <= _pos.x() && tmpOrigin.x() + tmpSize.x() >= _pos.x())
|
||||
&& (tmpOrigin.y() <= _pos.y() && tmpOrigin.y() + tmpSize.y() >= _pos.y()) )
|
||||
{
|
||||
Widget tmpWidget = it.getWidgetAtPos(_pos);
|
||||
if (tmpWidget != null) {
|
||||
return tmpWidget;
|
||||
}
|
||||
// stop searching
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
};
|
||||
|
||||
public EwolObject getSubObjectNamed( String _objectName) {
|
||||
EwolObject tmpObject = Widget::getSubObjectNamed(_objectName);
|
||||
if (tmpObject != null) {
|
||||
return tmpObject;
|
||||
}
|
||||
for (Widget it : this.subWidget) {
|
||||
if (it != null) {
|
||||
tmpObject = it.getSubObjectNamed(_objectName);
|
||||
if (tmpObject != null) {
|
||||
return tmpObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public boolean loadXML( exml::Element _node) {
|
||||
if (_node.exist() == false) {
|
||||
return false;
|
||||
}
|
||||
// parse generic properties :
|
||||
Widget::loadXML(_node);
|
||||
// remove previous element :
|
||||
subWidgetRemoveAll();
|
||||
|
||||
String tmpAttributeValue = _node.attributes["lock"];
|
||||
if (tmpAttributeValue.size()!=0) {
|
||||
propertyLockExpand.set(tmpAttributeValue);
|
||||
}
|
||||
boolean invertAdding=false;
|
||||
tmpAttributeValue = _node.attributes["addmode"];
|
||||
if(etk::compare_no_case(tmpAttributeValue, "invert")) {
|
||||
invertAdding=true;
|
||||
}
|
||||
// parse all the elements :
|
||||
for ( auto nodeIt : _node.nodes) {
|
||||
exml::Element pNode = nodeIt.toElement();
|
||||
if (pNode.exist() == false) {
|
||||
// trash here all that is not element
|
||||
continue;
|
||||
}
|
||||
String widgetName = pNode.getValue();
|
||||
Log.verbose(" t=" + getObjectType() + " Load node name : '" + widgetName + "'");
|
||||
if (getWidgetManager().exist(widgetName) == false) {
|
||||
Log.error("[" + getId() + "] {" + getObjectType() + "} (l " + pNode.getPos() + ") Unknown basic node='" + widgetName + "' not in : [" << getWidgetManager().list() << "]" );
|
||||
continue;
|
||||
}
|
||||
Log.debug("[" + getId() + "] {" + getObjectType() + "} load new element : '" + widgetName + "'");
|
||||
Widget subWidget = getWidgetManager().create(widgetName, pNode);
|
||||
if (subWidget == null) {
|
||||
EWOL_ERROR ("[" + getId() + "] {" + getObjectType() + "} (l " + pNode.getPos() + ") Can not create the widget : '" + widgetName + "'");
|
||||
continue;
|
||||
}
|
||||
// add sub element :
|
||||
if (invertAdding == false) {
|
||||
subWidgetAdd(subWidget);
|
||||
} else {
|
||||
subWidgetAddStart(subWidget);
|
||||
}
|
||||
if (subWidget.loadXML(pNode) == false) {
|
||||
Log.error("[" + getId() + "] {" + getObjectType() + "} (l " + pNode.getPos() + ") can not load widget properties : '" + widgetName + "'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void setOffset( Vector2f _newVal){
|
||||
if (this.offset != _newVal) {
|
||||
Widget::setOffset(_newVal);
|
||||
// recalculate the new sise and position of sub widget ...
|
||||
onChangeSize();
|
||||
}
|
||||
}
|
||||
public void requestDestroyFromChild( EwolObject _child) {
|
||||
auto it = this.subWidget.begin();
|
||||
while (it != this.subWidget.end()) {
|
||||
if (*it == _child) {
|
||||
if (*it == null) {
|
||||
this.subWidget.erase(it);
|
||||
it = this.subWidget.begin();
|
||||
continue;
|
||||
}
|
||||
(*it).removeParent();
|
||||
(*it).reset();
|
||||
this.subWidget.erase(it);
|
||||
it = this.subWidget.begin();
|
||||
markToRedraw();
|
||||
continue;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
public void drawWidgetTree(int _level) {
|
||||
super.drawWidgetTree(_level);
|
||||
_level++;
|
||||
for (Widget it: this.subWidget) {
|
||||
if (it != null) {
|
||||
it.drawWidgetTree(_level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onChangePropertyLockExpand() {
|
||||
markToRedraw();
|
||||
requestUpdateSize();
|
||||
}
|
||||
}
|
||||
|
@ -3,62 +3,45 @@
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/debug.hpp>
|
||||
#include <ewol/compositing/Text.hpp>
|
||||
#include <ewol/widget/Widget.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
#include <ewol/resource/ColorFile.hpp>
|
||||
#include <esignal/Signal.hpp>
|
||||
|
||||
namespace ewol {
|
||||
namespace widget {
|
||||
class Label;
|
||||
using Label = ememory::Ptr<ewol::widget::Label>;
|
||||
using LabelWeak = ememory::WeakPtr<ewol::widget::Label>;
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
*/
|
||||
class Label extends Widget {
|
||||
public: // signals
|
||||
esignal::Signal<> signalPressed;
|
||||
public: // properties
|
||||
eproperty::Value<bool> propertyAutoTranslate; //!< if at true the data is translate automaticaly translate.
|
||||
eproperty::Value<String> propertyValue; //!< decorated text to display.
|
||||
eproperty::Value<int> propertyFontSize; //!< default size of the font.
|
||||
private:
|
||||
ewol::compositing::Text this.text; //!< Compositing text element.
|
||||
etk::UString this.value;
|
||||
ememory::Ptr<ewol::resource::ColorFile> this.colorProperty; //!< theme color property
|
||||
int this.colorDefaultFgText; //!< Default color of the text
|
||||
int this.colorDefaultBgText; //!< Default Background color of the text
|
||||
protected:
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
* @brief Constructor
|
||||
* @param[in] _newLabel The displayed decorated text.
|
||||
*/
|
||||
class Label : public Widget {
|
||||
public: // signals
|
||||
esignal::Signal<> signalPressed;
|
||||
public: // properties
|
||||
eproperty::Value<bool> propertyAutoTranslate; //!< if at true the data is translate automaticaly translate.
|
||||
eproperty::Value<String> propertyValue; //!< decorated text to display.
|
||||
eproperty::Value<int> propertyFontSize; //!< default size of the font.
|
||||
private:
|
||||
ewol::compositing::Text this.text; //!< Compositing text element.
|
||||
etk::UString this.value;
|
||||
ememory::Ptr<ewol::resource::ColorFile> this.colorProperty; //!< theme color property
|
||||
int this.colorDefaultFgText; //!< Default color of the text
|
||||
int this.colorDefaultBgText; //!< Default Background color of the text
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _newLabel The displayed decorated text.
|
||||
*/
|
||||
Label();
|
||||
void init() ;
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(Label, "Label");
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
~Label();
|
||||
protected:
|
||||
void onDraw() ;
|
||||
public:
|
||||
void calculateMinMaxSize() ;
|
||||
void onRegenerateDisplay() ;
|
||||
boolean onEventInput( ewol::event::Input _event) ;
|
||||
boolean loadXML( exml::Element _node) ;
|
||||
protected:
|
||||
void onChangePropertyValue();
|
||||
void onChangePropertyAutoTranslate();
|
||||
void onChangePropertyFontSize();
|
||||
};
|
||||
};
|
||||
Label();
|
||||
void init() ;
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(Label, "Label");
|
||||
/**
|
||||
* @brief destructor
|
||||
*/
|
||||
~Label();
|
||||
protected:
|
||||
void onDraw() ;
|
||||
public:
|
||||
void calculateMinMaxSize() ;
|
||||
void onRegenerateDisplay() ;
|
||||
boolean onEventInput( ewol::event::Input _event) ;
|
||||
boolean loadXML( exml::Element _node) ;
|
||||
protected:
|
||||
void onChangePropertyValue();
|
||||
void onChangePropertyAutoTranslate();
|
||||
void onChangePropertyFontSize();
|
||||
};
|
||||
|
||||
|
@ -1,97 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/widget/ProgressBar.hpp>
|
||||
|
||||
#include <ewol/compositing/Drawing.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ewol::widget::ProgressBar);
|
||||
|
||||
int dotRadius = 6;
|
||||
|
||||
ewol::widget::ProgressBar::ProgressBar() :
|
||||
propertyValue(this, "value",
|
||||
0.0f, 0.0f, 1.0f,
|
||||
"Value of the progress bar",
|
||||
ewol::widget::ProgressBar::onChangePropertyValue),
|
||||
propertyTextColorFg(this, "color-bg",
|
||||
etk::color::black,
|
||||
"Background color",
|
||||
ewol::widget::ProgressBar::onChangePropertyTextColorFg),
|
||||
propertyTextColorBgOn(this, "color-on",
|
||||
etk::Color<>(0x00, 0xFF, 0x00, 0xFF),
|
||||
"Color of the true value",
|
||||
ewol::widget::ProgressBar::onChangePropertyTextColorBgOn),
|
||||
propertyTextColorBgOff(this, "color-off",
|
||||
etk::color::none,
|
||||
"Color of the false value",
|
||||
ewol::widget::ProgressBar::onChangePropertyTextColorBgOff) {
|
||||
addObjectType("ewol::widget::ProgressBar");
|
||||
}
|
||||
|
||||
void ewol::widget::ProgressBar::init() {
|
||||
Widget::init();
|
||||
propertyCanFocus.set(true);
|
||||
}
|
||||
|
||||
ewol::widget::ProgressBar::~ProgressBar() {
|
||||
|
||||
}
|
||||
|
||||
void ewol::widget::ProgressBar::calculateMinMaxSize() {
|
||||
Vector2f tmpMin = propertyMinSize.getPixel();
|
||||
this.minSize.setValue( etk::max(tmpMin.x(), 40.0f),
|
||||
etk::max(tmpMin.y(), dotRadius*2.0f) );
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::ProgressBar::onDraw() {
|
||||
this.draw.draw();
|
||||
}
|
||||
|
||||
void ewol::widget::ProgressBar::onRegenerateDisplay() {
|
||||
if (needRedraw() == false) {
|
||||
return;
|
||||
}
|
||||
// clean the object list ...
|
||||
this.draw.clear();
|
||||
|
||||
this.draw.setColor(propertyTextColorFg);
|
||||
|
||||
int tmpSizeX = this.size.x() - 10;
|
||||
int tmpSizeY = this.size.y() - 10;
|
||||
int tmpOriginX = 5;
|
||||
int tmpOriginY = 5;
|
||||
this.draw.setColor(propertyTextColorBgOn);
|
||||
this.draw.setPos(Vector3f(tmpOriginX, tmpOriginY, 0) );
|
||||
this.draw.rectangleWidth(Vector3f(tmpSizeX*propertyValue, tmpSizeY, 0) );
|
||||
this.draw.setColor(propertyTextColorBgOff);
|
||||
this.draw.setPos(Vector3f(tmpOriginX+tmpSizeX*propertyValue, tmpOriginY, 0) );
|
||||
this.draw.rectangleWidth(Vector3f(tmpSizeX*(1.0-propertyValue), tmpSizeY, 0) );
|
||||
|
||||
// TODO : Create a better progress Bar ...
|
||||
//this.draw.setColor(propertyTextColorFg);
|
||||
//this.draw.rectangleBorder( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY, 1);
|
||||
}
|
||||
|
||||
void ewol::widget::ProgressBar::onChangePropertyValue() {
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::ProgressBar::onChangePropertyTextColorFg() {
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::ProgressBar::onChangePropertyTextColorBgOn() {
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
void ewol::widget::ProgressBar::onChangePropertyTextColorBgOff() {
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
|
@ -1,50 +1,127 @@
|
||||
import org.atriasoft.etk.Color;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.ewol.annotation.EwolDescription;
|
||||
import org.atriasoft.ewol.compositing.CompositingDrawing;
|
||||
import org.atriasoft.ewol.widget.Widget;
|
||||
import org.atriasoft.exml.annotation.XmlManaged;
|
||||
import org.atriasoft.exml.annotation.XmlName;
|
||||
import org.atriasoft.exml.annotation.XmlProperty;
|
||||
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/Color.hpp>
|
||||
#include <ewol/debug.hpp>
|
||||
#include <ewol/widget/Widget.hpp>
|
||||
#include <ewol/compositing/Drawing.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
|
||||
namespace ewol {
|
||||
namespace widget {
|
||||
class ProgressBar;
|
||||
using ProgressBar = ememory::Ptr<ewol::widget::ProgressBar>;
|
||||
using ProgressBarWeak = ememory::WeakPtr<ewol::widget::ProgressBar>;
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
*/
|
||||
class ProgressBar : public Widget {
|
||||
public: // properties
|
||||
eproperty::Range<float> propertyValue; //!< % used
|
||||
eproperty::Value<etk::Color<>> propertyTextColorFg; //!< forder bar color
|
||||
eproperty::Value<etk::Color<>> propertyTextColorBgOn; //!< bar color enable
|
||||
eproperty::Value<etk::Color<>> propertyTextColorBgOff; //!< bar color disable
|
||||
protected:
|
||||
ProgressBar();
|
||||
void init() ;
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(ProgressBar, "ProgressBar");
|
||||
~ProgressBar();
|
||||
private:
|
||||
ewol::compositing::Drawing this.draw; // basic drawing element
|
||||
protected:
|
||||
void onDraw() ;
|
||||
public:
|
||||
void onRegenerateDisplay() ;
|
||||
void calculateMinMaxSize() ;
|
||||
protected:
|
||||
void onChangePropertyValue();
|
||||
void onChangePropertyTextColorFg();
|
||||
void onChangePropertyTextColorBgOn();
|
||||
void onChangePropertyTextColorBgOff();
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
class ProgressBar extends Widget {
|
||||
@XmlManaged()
|
||||
@XmlProperty()
|
||||
@XmlName(value = "value")
|
||||
@EwolDescription(value = "Value of the progress bar [0..1]")
|
||||
protected float propertyValue = 0;
|
||||
@XmlManaged()
|
||||
@XmlProperty()
|
||||
@XmlName(value = "color-bg")
|
||||
@EwolDescription(value = "ackground color")
|
||||
protected Color propertyTextColorFg = Color.BLACK;
|
||||
@XmlManaged()
|
||||
@XmlProperty()
|
||||
@XmlName(value = "color-on")
|
||||
@EwolDescription(value = "Color of the true value")
|
||||
protected Color propertyTextColorBgOn = Color.GREEN;
|
||||
@XmlManaged()
|
||||
@XmlProperty()
|
||||
@XmlName(value = "color-off")
|
||||
@EwolDescription(value = "Color of the false value")
|
||||
protected Color propertyTextColorBgOff = Color.NONE;
|
||||
static private final int DOT_RADIUS = 6;
|
||||
public ProgressBar() {
|
||||
super();
|
||||
setPropertyCanFocus(true);
|
||||
}
|
||||
|
||||
private CompositingDrawing draw = new CompositingDrawing(); // basic drawing element
|
||||
|
||||
protected void onDraw() {
|
||||
this.draw.draw();
|
||||
}
|
||||
|
||||
public void onRegenerateDisplay() {
|
||||
if (!needRedraw()) {
|
||||
return;
|
||||
}
|
||||
// clean the object list ...
|
||||
this.draw.clear();
|
||||
|
||||
this.draw.setColor(propertyTextColorFg);
|
||||
|
||||
int tmpSizeX = (int) (this.size.x() - 10);
|
||||
int tmpSizeY = (int) (this.size.y() - 10);
|
||||
int tmpOriginX = 5;
|
||||
int tmpOriginY = 5;
|
||||
this.draw.setColor(propertyTextColorBgOn);
|
||||
this.draw.setPos(new Vector3f(tmpOriginX, tmpOriginY, 0));
|
||||
this.draw.rectangleWidth(new Vector3f(tmpSizeX * propertyValue, tmpSizeY, 0));
|
||||
this.draw.setColor(propertyTextColorBgOff);
|
||||
this.draw.setPos(new Vector3f(tmpOriginX + tmpSizeX * propertyValue, tmpOriginY, 0));
|
||||
this.draw.rectangleWidth(new Vector3f(tmpSizeX * (1.0f - propertyValue), tmpSizeY, 0));
|
||||
|
||||
// TODO : Create a better progress Bar ...
|
||||
//this.draw.setColor(propertyTextColorFg);
|
||||
//this.draw.rectangleBorder( tmpOriginX, tmpOriginY, tmpSizeX, tmpSizeY, 1);
|
||||
}
|
||||
|
||||
public void calculateMinMaxSize() {
|
||||
Vector2f tmpMin = propertyMinSize.getPixel();
|
||||
this.minSize = new Vector2f(Math.max(tmpMin.x(), 40.0f),Math.max(tmpMin.y(), DOT_RADIUS * 2.0f) );
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
public float getPropertyValue() {
|
||||
return propertyValue;
|
||||
}
|
||||
|
||||
public void setPropertyValue(float propertyValue) {
|
||||
if (propertyValue == this.propertyValue) {
|
||||
return;
|
||||
}
|
||||
this.propertyValue = propertyValue;
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
public Color getPropertyTextColorFg() {
|
||||
return propertyTextColorFg;
|
||||
}
|
||||
|
||||
public void setPropertyTextColorFg(Color propertyTextColorFg) {
|
||||
if (propertyTextColorFg.equals(this.propertyTextColorFg)) {
|
||||
return;
|
||||
}
|
||||
this.propertyTextColorFg = propertyTextColorFg;
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
public Color getPropertyTextColorBgOn() {
|
||||
return propertyTextColorBgOn;
|
||||
}
|
||||
|
||||
public void setPropertyTextColorBgOn(Color propertyTextColorBgOn) {
|
||||
if (propertyTextColorBgOn.equals(this.propertyTextColorBgOn)) {
|
||||
return;
|
||||
}
|
||||
this.propertyTextColorBgOn = propertyTextColorBgOn;
|
||||
markToRedraw();
|
||||
}
|
||||
|
||||
public Color getPropertyTextColorBgOff() {
|
||||
return propertyTextColorBgOff;
|
||||
}
|
||||
|
||||
public void setPropertyTextColorBgOff(Color propertyTextColorBgOff) {
|
||||
if (propertyTextColorBgOff.equals(this.propertyTextColorBgOff)) {
|
||||
return;
|
||||
}
|
||||
this.propertyTextColorBgOff = propertyTextColorBgOff;
|
||||
markToRedraw();
|
||||
}
|
||||
}
|
||||
|
@ -3,66 +3,29 @@
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <ewol/debug.hpp>
|
||||
#include <ewol/widget/ContainerN.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
#include <etk/Color.hpp>
|
||||
#include <ewol/compositing/Drawing.hpp>
|
||||
|
||||
namespace ewol {
|
||||
namespace widget {
|
||||
class Sizer;
|
||||
using Sizer = ememory::Ptr<ewol::widget::Sizer>;
|
||||
using SizerWeak = ememory::WeakPtr<ewol::widget::Sizer>;
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
*/
|
||||
class Sizer : public ewol::widget::ContainerN {
|
||||
public:
|
||||
enum displayMode {
|
||||
modeVert, //!< Vertical mode
|
||||
modeHori, //!< Horizontal mode
|
||||
};
|
||||
enum animation {
|
||||
animationNone, //!< No annimation
|
||||
animationTop, //!< element came from the top
|
||||
animationbuttom, //!< element came from the buttom
|
||||
animationLeft, //!< element came from the Left
|
||||
animationRight //!< element came from the right
|
||||
//animationZoom //!< element came from zooming
|
||||
};
|
||||
public: // properties:
|
||||
eproperty::List<enum displayMode> propertyMode; //!< Methode to display the widget list (vert/hory ...)
|
||||
eproperty::Value<gale::Dimension> propertyBorderSize; //!< Border size needed for all the display
|
||||
eproperty::List<enum animation> propertyAnimation; //!< Methode add and remove element (animation)
|
||||
eproperty::Value<float> propertyAnimationTime; //!< Time in second to generate animation
|
||||
protected:
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _mode The mode to display the elements
|
||||
*/
|
||||
Sizer();
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(Sizer, "Sizer");
|
||||
/**
|
||||
* @brief Destructor
|
||||
*/
|
||||
~Sizer();
|
||||
public:
|
||||
void onChangeSize() ;
|
||||
void calculateMinMaxSize() ;
|
||||
// overwrite the set fuction to start annimations ...
|
||||
int subWidgetAdd(Widget _newWidget) ;
|
||||
int subWidgetAddStart(Widget _newWidget) ;
|
||||
void subWidgetRemove(Widget _newWidget) ;
|
||||
void subWidgetUnLink(Widget _newWidget) ;
|
||||
protected:
|
||||
void onChangePropertyMode();
|
||||
void onChangePropertyBorderSize();
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
*/
|
||||
public class Sizer extends ContainerN {
|
||||
public enum displayMode {
|
||||
modeVert, //!< Vertical mode
|
||||
modeHori, //!< Horizontal mode
|
||||
};
|
||||
}
|
||||
public displayMode propertyMode; //!< Methode to display the widget list (vert/hory ...)
|
||||
public Dimension propertyBorderSize; //!< Border size needed for all the display
|
||||
/**
|
||||
* @brief Constructor
|
||||
* @param[in] _mode The mode to display the elements
|
||||
*/
|
||||
public Sizer();
|
||||
public void onChangeSize() ;
|
||||
public void calculateMinMaxSize() ;
|
||||
// overwrite the set fuction to start annimations ...
|
||||
public int subWidgetAdd(Widget _newWidget) ;
|
||||
public int subWidgetAddStart(Widget _newWidget) ;
|
||||
public void subWidgetRemove(Widget _newWidget) ;
|
||||
public void subWidgetUnLink(Widget _newWidget) ;
|
||||
protected void onChangePropertyMode();
|
||||
protected void onChangePropertyBorderSize();
|
||||
}
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
|
||||
#include <ewol/widget/Spacer.hpp>
|
||||
|
||||
#include <ewol/compositing/Drawing.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
#include <etk/typeInfo.hpp>
|
||||
ETK_DECLARE_TYPE(ewol::widget::Spacer);
|
||||
|
||||
ewol::widget::Spacer::Spacer() :
|
||||
propertyColor(this, "color",
|
||||
etk::color::none,
|
||||
"background of the spacer",
|
||||
ewol::widget::Spacer::onChangePropertyColor) {
|
||||
addObjectType("ewol::widget::Spacer");
|
||||
propertyMinSize.setDirectCheck(gale::Dimension(Vector2f(10,10)));
|
||||
propertyCanFocus.setDirectCheck(true);
|
||||
}
|
||||
|
||||
ewol::widget::Spacer::~Spacer() {
|
||||
|
||||
}
|
||||
|
||||
void ewol::widget::Spacer::onDraw() {
|
||||
this.draw.draw();
|
||||
}
|
||||
|
||||
#define BORDER_SIZE_TMP (4)
|
||||
void ewol::widget::Spacer::onRegenerateDisplay() {
|
||||
if (false == needRedraw()) {
|
||||
return;
|
||||
}
|
||||
this.draw.clear();
|
||||
|
||||
if (propertyColor.a() == 0) {
|
||||
return;
|
||||
}
|
||||
this.draw.setColor(propertyColor);
|
||||
this.draw.setPos(Vector3f(0, 0, 0) );
|
||||
this.draw.rectangleWidth(Vector3f(this.size.x(), this.size.y(),0) );
|
||||
}
|
||||
|
||||
void ewol::widget::Spacer::onChangePropertyColor() {
|
||||
markToRedraw();
|
||||
}
|
||||
|
@ -1,50 +1,66 @@
|
||||
package org.atriasoft.ewol.widget;
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
||||
* @license MPL v2.0 (see license file)
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <etk/types.hpp>
|
||||
#include <etk/Color.hpp>
|
||||
#include <ewol/debug.hpp>
|
||||
#include <ewol/widget/Widget.hpp>
|
||||
#include <ewol/compositing/Drawing.hpp>
|
||||
#include <ewol/widget/Manager.hpp>
|
||||
import org.atriasoft.etk.Color;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector3f;
|
||||
import org.atriasoft.ewol.annotation.EwolDescription;
|
||||
import org.atriasoft.ewol.compositing.CompositingDrawing;
|
||||
import org.atriasoft.ewol.widget.Widget;
|
||||
import org.atriasoft.exml.annotation.XmlManaged;
|
||||
import org.atriasoft.exml.annotation.XmlName;
|
||||
import org.atriasoft.exml.annotation.XmlProperty;
|
||||
|
||||
namespace ewol {
|
||||
namespace widget {
|
||||
class Spacer;
|
||||
using Spacer = ememory::Ptr<ewol::widget::Spacer>;
|
||||
using SpacerWeak = ememory::WeakPtr<ewol::widget::Spacer>;
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
*/
|
||||
class Spacer : public Widget {
|
||||
public: // properties:
|
||||
eproperty::Value<etk::Color<>> propertyColor; //!< Background color
|
||||
protected:
|
||||
/**
|
||||
* @brief Main ructer
|
||||
*/
|
||||
Spacer();
|
||||
public:
|
||||
DECLARE_WIDGET_FACTORY(Spacer, "Spacer");
|
||||
/**
|
||||
* @brief Main destructer
|
||||
*/
|
||||
~Spacer();
|
||||
private:
|
||||
ewol::compositing::Drawing this.draw; //!< Compositing drawing element
|
||||
public:
|
||||
Widget getWidgetAtPos( Vector2f _pos) {
|
||||
return null;
|
||||
};
|
||||
void onRegenerateDisplay() ;
|
||||
void onDraw() ;
|
||||
protected:
|
||||
void onChangePropertyColor();
|
||||
/**
|
||||
* @ingroup ewolWidgetGroup
|
||||
*/
|
||||
class Spacer extends Widget {
|
||||
@XmlManaged()
|
||||
@XmlProperty()
|
||||
@XmlName(value = "color")
|
||||
@EwolDescription(value = "background of the spacer")
|
||||
protected Color propertyColor; //!< Background color
|
||||
/**
|
||||
* @brief Main ructer
|
||||
*/
|
||||
public Spacer() {
|
||||
|
||||
}
|
||||
private CompositingDrawing draw; //!< Compositing drawing element
|
||||
@Override
|
||||
public Widget getWidgetAtPos( Vector2f _pos) {
|
||||
return null;
|
||||
};
|
||||
public void onRegenerateDisplay() {
|
||||
if (!needRedraw()) {
|
||||
return;
|
||||
}
|
||||
this.draw.clear();
|
||||
|
||||
if (propertyColor.a() == 0) {
|
||||
return;
|
||||
}
|
||||
this.draw.setColor(propertyColor);
|
||||
this.draw.setPos(Vector3f.ZERO);
|
||||
this.draw.rectangleWidth(new Vector3f(this.size.x(), this.size.y(),0) );
|
||||
}
|
||||
public void onDraw(){
|
||||
this.draw.draw();
|
||||
}
|
||||
public Color getPropertyColor() {
|
||||
return propertyColor;
|
||||
}
|
||||
|
||||
public void setPropertyTextColorBgOn(Color propertyColor) {
|
||||
if (propertyColor.equals(this.propertyColor)) {
|
||||
return;
|
||||
}
|
||||
this.propertyColor = propertyColor;
|
||||
markToRedraw();
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.atriasoft.ewol.internal.Log;
|
||||
import org.atriasoft.exml.model.XmlElement;
|
||||
|
||||
/** @file
|
||||
* @author Edouard DUPIN
|
||||
@ -56,6 +57,7 @@ public class WidgetManager {
|
||||
*/
|
||||
|
||||
public WidgetManager() {
|
||||
/*
|
||||
this.creatorList.put("Button", Button.class);
|
||||
this.creatorList.put("ButtonColor", ButtonColor.class);
|
||||
this.creatorList.put("Spacer", Spacer.class);
|
||||
@ -77,6 +79,7 @@ public class WidgetManager {
|
||||
this.creatorList.put("Composer", Composer.class);
|
||||
this.creatorList.put("Select", Select.class);
|
||||
this.creatorList.put("Spin", Spin.class);
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,6 +123,22 @@ public class WidgetManager {
|
||||
Log.warning("try to create an UnExistant widget : " + nameLower);
|
||||
return null;
|
||||
}
|
||||
public Widget create(final String _name, XmlElement node) {
|
||||
final String nameLower = _name.toLowerCase();
|
||||
final Class<?> it = this.creatorList.get(nameLower);
|
||||
if (it != null) {
|
||||
try {
|
||||
Widget tmp = (Widget) it.getConstructor().newInstance();
|
||||
tmp.loadXML(node);
|
||||
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Log.warning("try to create an UnExistant widget : " + nameLower);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if an Widget exist
|
||||
@ -160,15 +179,11 @@ public class WidgetManager {
|
||||
focusWidgetCurrent.rmFocus();
|
||||
focusWidgetCurrent = null;
|
||||
}
|
||||
if (_newWidget.propertyCanFocus == false) {
|
||||
if (!_newWidget.propertyCanFocus) {
|
||||
Log.debug("Widget can not have focus, id=" + _newWidget.getId());
|
||||
return;
|
||||
}
|
||||
this.focusWidgetCurrent = new WeakReference<>(_newWidget);
|
||||
if (_newWidget != null) {
|
||||
Log.debug("Set focus on WidgetID=" + _newWidget.getId());
|
||||
_newWidget.setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -198,7 +213,7 @@ public class WidgetManager {
|
||||
* @param[in] _newWidget Widget that might get the focus (when nothing else).
|
||||
*/
|
||||
public void focusSetDefault(final Widget _newWidget) {
|
||||
if (_newWidget != null && _newWidget.propertyCanFocus == false) {
|
||||
if ((_newWidget != null) && (!_newWidget.propertyCanFocus)) {
|
||||
Log.verbose("Widget can not have focus, id=" + _newWidget.getId());
|
||||
return;
|
||||
}
|
||||
@ -240,7 +255,7 @@ public class WidgetManager {
|
||||
* @brief Mark the display to redraw
|
||||
*/
|
||||
public void markDrawingIsNeeded() {
|
||||
if (this.haveRedraw == true) {
|
||||
if (this.haveRedraw) {
|
||||
return;
|
||||
}
|
||||
this.haveRedraw = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user