diff --git a/ewol.iml b/ewol.iml new file mode 100644 index 0000000..13d9bea --- /dev/null +++ b/ewol.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/org/atriasoft/ewol/widget/Button.cpp b/old_widget/Button.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Button.cpp rename to old_widget/Button.cpp diff --git a/src/org/atriasoft/ewol/widget/Button.java b/old_widget/Button.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Button.java rename to old_widget/Button.java diff --git a/src/org/atriasoft/ewol/widget/ButtonColor.cpp b/old_widget/ButtonColor.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/ButtonColor.cpp rename to old_widget/ButtonColor.cpp diff --git a/src/org/atriasoft/ewol/widget/ButtonColor.java b/old_widget/ButtonColor.java similarity index 100% rename from src/org/atriasoft/ewol/widget/ButtonColor.java rename to old_widget/ButtonColor.java diff --git a/src/org/atriasoft/ewol/widget/CheckBox.cpp b/old_widget/CheckBox.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/CheckBox.cpp rename to old_widget/CheckBox.cpp diff --git a/src/org/atriasoft/ewol/widget/CheckBox.java b/old_widget/CheckBox.java similarity index 100% rename from src/org/atriasoft/ewol/widget/CheckBox.java rename to old_widget/CheckBox.java diff --git a/src/org/atriasoft/ewol/widget/ColorBar.cpp b/old_widget/ColorBar.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/ColorBar.cpp rename to old_widget/ColorBar.cpp diff --git a/src/org/atriasoft/ewol/widget/ColorBar.java b/old_widget/ColorBar.java similarity index 100% rename from src/org/atriasoft/ewol/widget/ColorBar.java rename to old_widget/ColorBar.java diff --git a/src/org/atriasoft/ewol/widget/Composer.cpp b/old_widget/Composer.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Composer.cpp rename to old_widget/Composer.cpp diff --git a/src/org/atriasoft/ewol/widget/Composer.java b/old_widget/Composer.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Composer.java rename to old_widget/Composer.java diff --git a/src/org/atriasoft/ewol/widget/Container2.cpp b/old_widget/Container2.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Container2.cpp rename to old_widget/Container2.cpp diff --git a/src/org/atriasoft/ewol/widget/Container2.java b/old_widget/Container2.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Container2.java rename to old_widget/Container2.java diff --git a/src/org/atriasoft/ewol/widget/ContextMenu.cpp b/old_widget/ContextMenu.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/ContextMenu.cpp rename to old_widget/ContextMenu.cpp diff --git a/src/org/atriasoft/ewol/widget/ContextMenu.java b/old_widget/ContextMenu.java similarity index 100% rename from src/org/atriasoft/ewol/widget/ContextMenu.java rename to old_widget/ContextMenu.java diff --git a/src/org/atriasoft/ewol/widget/Entry.cpp b/old_widget/Entry.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Entry.cpp rename to old_widget/Entry.cpp diff --git a/src/org/atriasoft/ewol/widget/Entry.java b/old_widget/Entry.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Entry.java rename to old_widget/Entry.java diff --git a/src/org/atriasoft/ewol/widget/Gird.cpp b/old_widget/Gird.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Gird.cpp rename to old_widget/Gird.cpp diff --git a/src/org/atriasoft/ewol/widget/Gird.java b/old_widget/Gird.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Gird.java rename to old_widget/Gird.java diff --git a/src/org/atriasoft/ewol/widget/Joystick.cpp b/old_widget/Joystick.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Joystick.cpp rename to old_widget/Joystick.cpp diff --git a/src/org/atriasoft/ewol/widget/Joystick.java b/old_widget/Joystick.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Joystick.java rename to old_widget/Joystick.java diff --git a/src/org/atriasoft/ewol/widget/Layer.cpp b/old_widget/Layer.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Layer.cpp rename to old_widget/Layer.cpp diff --git a/src/org/atriasoft/ewol/widget/Layer.java b/old_widget/Layer.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Layer.java rename to old_widget/Layer.java diff --git a/src/org/atriasoft/ewol/widget/List.cpp b/old_widget/List.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/List.cpp rename to old_widget/List.cpp diff --git a/src/org/atriasoft/ewol/widget/List.java b/old_widget/List.java similarity index 100% rename from src/org/atriasoft/ewol/widget/List.java rename to old_widget/List.java diff --git a/src/org/atriasoft/ewol/widget/ListFileSystem.cpp b/old_widget/ListFileSystem.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/ListFileSystem.cpp rename to old_widget/ListFileSystem.cpp diff --git a/src/org/atriasoft/ewol/widget/ListFileSystem.java b/old_widget/ListFileSystem.java similarity index 100% rename from src/org/atriasoft/ewol/widget/ListFileSystem.java rename to old_widget/ListFileSystem.java diff --git a/src/org/atriasoft/ewol/widget/Menu.cpp b/old_widget/Menu.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Menu.cpp rename to old_widget/Menu.cpp diff --git a/src/org/atriasoft/ewol/widget/Menu.java b/old_widget/Menu.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Menu.java rename to old_widget/Menu.java diff --git a/src/org/atriasoft/ewol/widget/Panned.cpp b/old_widget/Panned.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Panned.cpp rename to old_widget/Panned.cpp diff --git a/src/org/atriasoft/ewol/widget/Panned.java b/old_widget/Panned.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Panned.java rename to old_widget/Panned.java diff --git a/src/org/atriasoft/ewol/widget/PopUp.cpp b/old_widget/PopUp.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/PopUp.cpp rename to old_widget/PopUp.cpp diff --git a/src/org/atriasoft/ewol/widget/PopUp.java b/old_widget/PopUp.java similarity index 100% rename from src/org/atriasoft/ewol/widget/PopUp.java rename to old_widget/PopUp.java diff --git a/src/org/atriasoft/ewol/widget/Scroll.cpp b/old_widget/Scroll.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Scroll.cpp rename to old_widget/Scroll.cpp diff --git a/src/org/atriasoft/ewol/widget/Scroll.java b/old_widget/Scroll.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Scroll.java rename to old_widget/Scroll.java diff --git a/src/org/atriasoft/ewol/widget/Select.cpp b/old_widget/Select.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Select.cpp rename to old_widget/Select.cpp diff --git a/src/org/atriasoft/ewol/widget/Select.java b/old_widget/Select.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Select.java rename to old_widget/Select.java diff --git a/src/org/atriasoft/ewol/widget/Slider.cpp b/old_widget/Slider.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Slider.cpp rename to old_widget/Slider.cpp diff --git a/src/org/atriasoft/ewol/widget/Slider.java b/old_widget/Slider.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Slider.java rename to old_widget/Slider.java diff --git a/src/org/atriasoft/ewol/widget/Spin.cpp b/old_widget/Spin.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/Spin.cpp rename to old_widget/Spin.cpp diff --git a/src/org/atriasoft/ewol/widget/Spin.java b/old_widget/Spin.java similarity index 100% rename from src/org/atriasoft/ewol/widget/Spin.java rename to old_widget/Spin.java diff --git a/src/org/atriasoft/ewol/widget/TreeView.cpp b/old_widget/TreeView.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/TreeView.cpp rename to old_widget/TreeView.cpp diff --git a/src/org/atriasoft/ewol/widget/TreeView.java b/old_widget/TreeView.java similarity index 100% rename from src/org/atriasoft/ewol/widget/TreeView.java rename to old_widget/TreeView.java diff --git a/src/org/atriasoft/ewol/widget/WSlider.cpp b/old_widget/WSlider.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/WSlider.cpp rename to old_widget/WSlider.cpp diff --git a/src/org/atriasoft/ewol/widget/WSlider.java b/old_widget/WSlider.java similarity index 100% rename from src/org/atriasoft/ewol/widget/WSlider.java rename to old_widget/WSlider.java diff --git a/src/org/atriasoft/ewol/widget/WidgetScrolled.cpp b/old_widget/WidgetScrolled.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/WidgetScrolled.cpp rename to old_widget/WidgetScrolled.cpp diff --git a/src/org/atriasoft/ewol/widget/WidgetScrolled.java b/old_widget/WidgetScrolled.java similarity index 100% rename from src/org/atriasoft/ewol/widget/WidgetScrolled.java rename to old_widget/WidgetScrolled.java diff --git a/src/org/atriasoft/ewol/widget/meta/ColorChooser.cpp b/old_widget/meta/ColorChooser.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/ColorChooser.cpp rename to old_widget/meta/ColorChooser.cpp diff --git a/src/org/atriasoft/ewol/widget/meta/ColorChooser.java b/old_widget/meta/ColorChooser.java similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/ColorChooser.java rename to old_widget/meta/ColorChooser.java diff --git a/src/org/atriasoft/ewol/widget/meta/FileChooser.cpp b/old_widget/meta/FileChooser.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/FileChooser.cpp rename to old_widget/meta/FileChooser.cpp diff --git a/src/org/atriasoft/ewol/widget/meta/FileChooser.java b/old_widget/meta/FileChooser.java similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/FileChooser.java rename to old_widget/meta/FileChooser.java diff --git a/src/org/atriasoft/ewol/widget/meta/Parameter.cpp b/old_widget/meta/Parameter.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/Parameter.cpp rename to old_widget/meta/Parameter.cpp diff --git a/src/org/atriasoft/ewol/widget/meta/Parameter.java b/old_widget/meta/Parameter.java similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/Parameter.java rename to old_widget/meta/Parameter.java diff --git a/src/org/atriasoft/ewol/widget/meta/ParameterList.cpp b/old_widget/meta/ParameterList.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/ParameterList.cpp rename to old_widget/meta/ParameterList.cpp diff --git a/src/org/atriasoft/ewol/widget/meta/ParameterList.java b/old_widget/meta/ParameterList.java similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/ParameterList.java rename to old_widget/meta/ParameterList.java diff --git a/src/org/atriasoft/ewol/widget/meta/SpinBase.cpp b/old_widget/meta/SpinBase.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/SpinBase.cpp rename to old_widget/meta/SpinBase.cpp diff --git a/src/org/atriasoft/ewol/widget/meta/SpinBase.java b/old_widget/meta/SpinBase.java similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/SpinBase.java rename to old_widget/meta/SpinBase.java diff --git a/src/org/atriasoft/ewol/widget/meta/StdPopUp.cpp b/old_widget/meta/StdPopUp.cpp similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/StdPopUp.cpp rename to old_widget/meta/StdPopUp.cpp diff --git a/src/org/atriasoft/ewol/widget/meta/StdPopUp.java b/old_widget/meta/StdPopUp.java similarity index 100% rename from src/org/atriasoft/ewol/widget/meta/StdPopUp.java rename to old_widget/meta/StdPopUp.java diff --git a/src/module-info.java b/src/module-info.java index eaea52f..1b9e33b 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -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; diff --git a/src/org/atriasoft/etranslate/ETranslate.java b/src/org/atriasoft/etranslate/ETranslate.java new file mode 100644 index 0000000..6598b3c --- /dev/null +++ b/src/org/atriasoft/etranslate/ETranslate.java @@ -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 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 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 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 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 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 element : doc.getNodes().entrySet()) { + String val = element.getValue().toJsonString().getValue(); + m_translate.put(element.getKey(), val); + } + } + // start parse default language: + for (Map.Entry 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 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() { + } +} diff --git a/src/org/atriasoft/ewol/DrawProperty.java b/src/org/atriasoft/ewol/DrawProperty.java index 5a44339..04bf376 100644 --- a/src/org/atriasoft/ewol/DrawProperty.java +++ b/src/org/atriasoft/ewol/DrawProperty.java @@ -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) + "]"; } } diff --git a/src/org/atriasoft/ewol/Gravity.java b/src/org/atriasoft/ewol/Gravity.java index 1420a1e..7098f19 100644 --- a/src/org/atriasoft/ewol/Gravity.java +++ b/src/org/atriasoft/ewol/Gravity.java @@ -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); } - + } diff --git a/src/org/atriasoft/ewol/Padding.java b/src/org/atriasoft/ewol/Padding.java index 94239f8..ae50e94 100644 --- a/src/org/atriasoft/ewol/Padding.java +++ b/src/org/atriasoft/ewol/Padding.java @@ -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; } diff --git a/src/org/atriasoft/ewol/compositing/Compositing.java b/src/org/atriasoft/ewol/compositing/Compositing.java index d71b048..f9392f7 100644 --- a/src/org/atriasoft/ewol/compositing/Compositing.java +++ b/src/org/atriasoft/ewol/compositing/Compositing.java @@ -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)); } } diff --git a/src/org/atriasoft/ewol/compositing/Drawing.java b/src/org/atriasoft/ewol/compositing/CompositingDrawing.java similarity index 96% rename from src/org/atriasoft/ewol/compositing/Drawing.java rename to src/org/atriasoft/ewol/compositing/CompositingDrawing.java index 01754f2..dab66f2 100644 --- a/src/org/atriasoft/ewol/compositing/Drawing.java +++ b/src/org/atriasoft/ewol/compositing/CompositingDrawing.java @@ -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(); } diff --git a/src/org/atriasoft/ewol/context/EwolContext.java b/src/org/atriasoft/ewol/context/EwolContext.java index b3ef67c..0a325b9 100644 --- a/src/org/atriasoft/ewol/context/EwolContext.java +++ b/src/org/atriasoft/ewol/context/EwolContext.java @@ -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); - } } diff --git a/src/org/atriasoft/ewol/event/EventShortCut.java b/src/org/atriasoft/ewol/event/EventShortCut.java new file mode 100644 index 0000000..654dd86 --- /dev/null +++ b/src/org/atriasoft/ewol/event/EventShortCut.java @@ -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; + } +} diff --git a/src/org/atriasoft/ewol/object/EwolObject.java b/src/org/atriasoft/ewol/object/EwolObject.java index 37ffeec..013ea9a 100644 --- a/src/org/atriasoft/ewol/object/EwolObject.java +++ b/src/org/atriasoft/ewol/object/EwolObject.java @@ -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; } diff --git a/src/org/atriasoft/ewol/resource/RefactorColored3DObject.java b/src/org/atriasoft/ewol/resource/RefactorColored3DObject.java index 62a52e6..de2dab8 100644 --- a/src/org/atriasoft/ewol/resource/RefactorColored3DObject.java +++ b/src/org/atriasoft/ewol/resource/RefactorColored3DObject.java @@ -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 _vertices, final Color _color) { draw(_vertices, _color, true, true); } - - public void draw(final List _vertices, final Color _color, final boolean _updateDepthBuffer, final boolean _depthtest) { + + public void draw(final List _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 _vertices, final Color _color, final Matrix4f _transformationMatrix) { draw(_vertices, _color, _transformationMatrix, true, true); } - - public void draw(final List _vertices, final Color _color, final Matrix4f _transformationMatrix, final boolean _updateDepthBuffer, final boolean _depthtest) { + + public void draw(final List _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 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 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 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 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 _vertices, final Color _color, final Matrix4f _transformationMatrix) { drawLine(_vertices, _color, _transformationMatrix, true, true); } - - public void drawLine(final List _vertices, final Color _color, final Matrix4f _transformationMatrix, final boolean _updateDepthBuffer, final boolean _depthtest) { + + public void drawLine(final List _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 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 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 _vertex, final List _indice, final Matrix4f _transformationMatrix, final Color _tmpColor) { + + public void drawTriangles(final List _vertex, final List _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 _vertex, final List _indice, final Matrix4f _transformationMatrix, final Color _tmpColor, final Vector3f _offset) { + + public void drawTriangles(final List _vertex, final List _indice, + final Matrix4f _transformationMatrix, final Color _tmpColor, final Vector3f _offset) { final List 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); } } diff --git a/src/org/atriasoft/ewol/resource/ResourceColorFile.java b/src/org/atriasoft/ewol/resource/ResourceColorFile.java index 2553cee..5001972 100644 --- a/src/org/atriasoft/ewol/resource/ResourceColorFile.java +++ b/src/org/atriasoft/ewol/resource/ResourceColorFile.java @@ -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 list = new ArrayList<>(); //!< List of all color in the file + private final List 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; - } - }; diff --git a/src/org/atriasoft/ewol/resource/ResourceFontFreeType.java b/src/org/atriasoft/ewol/resource/ResourceFontFreeType.java index 4484bd0..0941b17 100644 --- a/src/org/atriasoft/ewol/resource/ResourceFontFreeType.java +++ b/src/org/atriasoft/ewol/resource/ResourceFontFreeType.java @@ -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 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 ... } - + } diff --git a/src/org/atriasoft/ewol/resource/ResourceTexture2.java b/src/org/atriasoft/ewol/resource/ResourceTexture2.java index 12acb2f..5cab712 100644 --- a/src/org/atriasoft/ewol/resource/ResourceTexture2.java +++ b/src/org/atriasoft/ewol/resource/ResourceTexture2.java @@ -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 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 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 } diff --git a/src/org/atriasoft/ewol/resource/ResourceTextureFile.java b/src/org/atriasoft/ewol/resource/ResourceTextureFile.java index 462ab98..d92e28a 100644 --- a/src/org/atriasoft/ewol/resource/ResourceTextureFile.java +++ b/src/org/atriasoft/ewol/resource/ResourceTextureFile.java @@ -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; } - + } diff --git a/src/org/atriasoft/ewol/tools/Message.java b/src/org/atriasoft/ewol/tools/Message.java new file mode 100644 index 0000000..d29d43c --- /dev/null +++ b/src/org/atriasoft/ewol/tools/Message.java @@ -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("_T{Info}"); + case Type.warning -> tmpPopUp.propertyTitle.set("_T{Warning}"); + case Type.error -> tmpPopUp.propertyTitle.set("_T{Error}"); + case Type.critical -> tmpPopUp.propertyTitle.set("_T{Critical}"); + } + 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 + } + + +} + diff --git a/src/org/atriasoft/ewol/tools/message.cpp b/src/org/atriasoft/ewol/tools/message.cpp deleted file mode 100644 index f145e7e..0000000 --- a/src/org/atriasoft/ewol/tools/message.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -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("_T{Info}"); - break; - case ewol::tools::message::type::warning: - tmpPopUp.propertyTitle.set("_T{Warning}"); - break; - case ewol::tools::message::type::error: - tmpPopUp.propertyTitle.set("_T{Error}"); - break; - case ewol::tools::message::type::critical: - tmpPopUp.propertyTitle.set("_T{Critical}"); - 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); -} - - diff --git a/src/org/atriasoft/ewol/tools/message.java b/src/org/atriasoft/ewol/tools/message.java deleted file mode 100644 index f48cb4d..0000000 --- a/src/org/atriasoft/ewol/tools/message.java +++ /dev/null @@ -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 -#include -#include -#include -#include - -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); - } - } -} - diff --git a/src/org/atriasoft/ewol/widget/Container.cpp b/src/org/atriasoft/ewol/widget/Container.cpp deleted file mode 100644 index 063ee81..0000000 --- a/src/org/atriasoft/ewol/widget/Container.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - - -#include -#include -#include - -#include -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); - } -} diff --git a/src/org/atriasoft/ewol/widget/Container.java b/src/org/atriasoft/ewol/widget/Container.java index d10aa88..f0f0d20 100644 --- a/src/org/atriasoft/ewol/widget/Container.java +++ b/src/org/atriasoft/ewol/widget/Container.java @@ -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 -#include -#include - -namespace ewol { - namespace widget { - class Container; - using Container = ememory::Ptr; - using ContainerWeak = ememory::WeakPtr; - /** - * @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); + } + } +}; \ No newline at end of file diff --git a/src/org/atriasoft/ewol/widget/ContainerN.cpp b/src/org/atriasoft/ewol/widget/ContainerN.cpp deleted file mode 100644 index 6ec2429..0000000 --- a/src/org/atriasoft/ewol/widget/ContainerN.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - - -#include -#include -#include - -#include -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); - } - } -} diff --git a/src/org/atriasoft/ewol/widget/ContainerN.java b/src/org/atriasoft/ewol/widget/ContainerN.java index a27f574..81e52e6 100644 --- a/src/org/atriasoft/ewol/widget/ContainerN.java +++ b/src/org/atriasoft/ewol/widget/ContainerN.java @@ -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 -#include -#include +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; - using ContainerNWeak = ememory::WeakPtr; +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 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 propertyLockExpand; //!< Lock the expend of the sub widget to this one == > this permit to limit bigger subWidget - protected: - List 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(); + } +} diff --git a/src/org/atriasoft/ewol/widget/Label.java b/src/org/atriasoft/ewol/widget/Label.java index ed4e6da..56d4f1a 100644 --- a/src/org/atriasoft/ewol/widget/Label.java +++ b/src/org/atriasoft/ewol/widget/Label.java @@ -3,62 +3,45 @@ * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ -#pragma once -#include -#include -#include -#include -#include -#include -#include - -namespace ewol { - namespace widget { - class Label; - using Label = ememory::Ptr; - using LabelWeak = ememory::WeakPtr; +/** + * @ingroup ewolWidgetGroup + */ +class Label extends Widget { + public: // signals + esignal::Signal<> signalPressed; + public: // properties + eproperty::Value propertyAutoTranslate; //!< if at true the data is translate automaticaly translate. + eproperty::Value propertyValue; //!< decorated text to display. + eproperty::Value propertyFontSize; //!< default size of the font. + private: + ewol::compositing::Text this.text; //!< Compositing text element. + etk::UString this.value; + ememory::Ptr 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 propertyAutoTranslate; //!< if at true the data is translate automaticaly translate. - eproperty::Value propertyValue; //!< decorated text to display. - eproperty::Value propertyFontSize; //!< default size of the font. - private: - ewol::compositing::Text this.text; //!< Compositing text element. - etk::UString this.value; - ememory::Ptr 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(); }; - diff --git a/src/org/atriasoft/ewol/widget/ProgressBar.cpp b/src/org/atriasoft/ewol/widget/ProgressBar.cpp deleted file mode 100644 index a6f847d..0000000 --- a/src/org/atriasoft/ewol/widget/ProgressBar.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include - -#include -#include -#include -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(); -} - - diff --git a/src/org/atriasoft/ewol/widget/ProgressBar.java b/src/org/atriasoft/ewol/widget/ProgressBar.java index 2e0c2fb..ce13b9f 100644 --- a/src/org/atriasoft/ewol/widget/ProgressBar.java +++ b/src/org/atriasoft/ewol/widget/ProgressBar.java @@ -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 -#include -#include -#include -#include -#include - -namespace ewol { - namespace widget { - class ProgressBar; - using ProgressBar = ememory::Ptr; - using ProgressBarWeak = ememory::WeakPtr; - /** - * @ingroup ewolWidgetGroup - */ - class ProgressBar : public Widget { - public: // properties - eproperty::Range propertyValue; //!< % used - eproperty::Value> propertyTextColorFg; //!< forder bar color - eproperty::Value> propertyTextColorBgOn; //!< bar color enable - eproperty::Value> 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(); + } +} diff --git a/src/org/atriasoft/ewol/widget/Sizer.java b/src/org/atriasoft/ewol/widget/Sizer.java index 9f6145b..e91342e 100644 --- a/src/org/atriasoft/ewol/widget/Sizer.java +++ b/src/org/atriasoft/ewol/widget/Sizer.java @@ -3,66 +3,29 @@ * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ -#pragma once - -#include -#include -#include -#include -#include -#include - -namespace ewol { - namespace widget { - class Sizer; - using Sizer = ememory::Ptr; - using SizerWeak = ememory::WeakPtr; - /** - * @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 propertyMode; //!< Methode to display the widget list (vert/hory ...) - eproperty::Value propertyBorderSize; //!< Border size needed for all the display - eproperty::List propertyAnimation; //!< Methode add and remove element (animation) - eproperty::Value 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(); } diff --git a/src/org/atriasoft/ewol/widget/Spacer.cpp b/src/org/atriasoft/ewol/widget/Spacer.cpp deleted file mode 100644 index cd9dba1..0000000 --- a/src/org/atriasoft/ewol/widget/Spacer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - -#include - -#include -#include -#include -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(); -} - diff --git a/src/org/atriasoft/ewol/widget/Spacer.java b/src/org/atriasoft/ewol/widget/Spacer.java index a426f27..4267834 100644 --- a/src/org/atriasoft/ewol/widget/Spacer.java +++ b/src/org/atriasoft/ewol/widget/Spacer.java @@ -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 -#include -#include -#include -#include -#include +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; - using SpacerWeak = ememory::WeakPtr; - /** - * @ingroup ewolWidgetGroup - */ - class Spacer : public Widget { - public: // properties: - eproperty::Value> 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(); } } diff --git a/src/org/atriasoft/ewol/widget/Widget.java b/src/org/atriasoft/ewol/widget/Widget.java index b73261d..01e236c 100644 --- a/src/org/atriasoft/ewol/widget/Widget.java +++ b/src/org/atriasoft/ewol/widget/Widget.java @@ -6,27 +6,23 @@ */ package org.atriasoft.ewol.widget; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.atriasoft.esignal.Signal; -import org.atriasoft.etk.math.FMath; -import org.atriasoft.etk.math.Vector2b; -import org.atriasoft.etk.math.Vector2f; -import org.atriasoft.etk.math.Vector2i; +import org.atriasoft.etk.math.*; import org.atriasoft.ewol.DrawProperty; import org.atriasoft.ewol.Gravity; import org.atriasoft.ewol.annotation.EwolDescription; import org.atriasoft.ewol.annotation.EwolSignal; -import org.atriasoft.ewol.event.EntrySystem; -import org.atriasoft.ewol.event.EventEntry; -import org.atriasoft.ewol.event.EventInput; -import org.atriasoft.ewol.event.InputSystem; +import org.atriasoft.ewol.event.*; import org.atriasoft.ewol.internal.Log; import org.atriasoft.ewol.object.EwolObject; import org.atriasoft.exml.annotation.XmlDefaultManaged; import org.atriasoft.exml.annotation.XmlManaged; import org.atriasoft.exml.annotation.XmlName; import org.atriasoft.exml.annotation.XmlProperty; +import org.atriasoft.exml.model.XmlElement; import org.atriasoft.gale.Dimension; import org.atriasoft.gale.Distance; import org.atriasoft.gale.backend3d.OpenGL; @@ -35,26 +31,9 @@ import org.atriasoft.gale.key.KeySpecial; import org.atriasoft.gale.context.ClipboardList; import org.atriasoft.gale.context.Cursor; -// TODO: change position of this ... -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; - } -}; /** - * @brief Widget class is the main widget interface, it has so me generic properties: + * Widget class is the main widget interface, it has so me generic properties: * :** known his parent * :** Can be display at a special position with a special scale * :** Can get focus @@ -91,19 +70,19 @@ public class Widget extends EwolObject { @XmlProperty() @XmlName(value = "expand") @EwolDescription(value = "Request the widget Expand size while space is available") - Vector2b propertyExpand = new Vector2b(false, false); //!< the widget will expand if possible + protected Vector2b propertyExpand = new Vector2b(false, false); //!< the widget will expand if possible @XmlManaged() @XmlProperty() @XmlName(value = "fill") @EwolDescription(value = "Fill the widget available size") - Vector2b propertyFill = new Vector2b(true, true); //!< the widget will fill all the space provided by the parent. + protected Vector2b propertyFill = new Vector2b(true, true); //!< the widget will fill all the space provided by the parent. @XmlManaged() @XmlProperty() @XmlName(value = "hide") @EwolDescription(value = "The widget start hided") - boolean propertyHide = false; //!< hide a widget on the display + protected boolean propertyHide = false; //!< hide a widget on the display // ---------------------------------------------------------------------------------------------------------------- // -- Widget size: @@ -113,22 +92,22 @@ public class Widget extends EwolObject { protected Vector2f maxSize = new Vector2f(999999, 999999); //!< internal: maximum size of the widget /** - * @brief Constructor of the widget classes + * Constructor of the widget classes * @return (no exception generated (not managed in embedded platform)) */ public Widget() {} /** - * @brief Convert the absolute position in the local Position (Relative) - * @param[in] _pos Absolute position that you request conversion. + * Convert the absolute position in the local Position (Relative) + * @param _pos Absolute position that you request conversion. * @return The relative position. */ public Vector2f relativePosition(final Vector2f _pos) { - return _pos.lessNew(this.origin); + return _pos.less(this.origin); } /** - * @brief Parent have set the size and the origin. The container need to update the child widget property + * Parent have set the size and the origin. The container need to update the child widget property * @note INTERNAL EWOL SYSTEM */ public void onChangeSize() { @@ -139,19 +118,19 @@ public class Widget extends EwolObject { public void calculateSize() {}; /** - * @brief get the widget size + * get the widget size * @return Requested size * @note : INTERNAL EWOL SYSTEM */ public Vector2f getSize() { - if (this.propertyHide == false) { + if (!this.propertyHide) { return this.size; } return new Vector2f(0, 0); } /** - * @brief set the widget size + * set the widget size * @return Requested size * @note : INTERNAL EWOL SYSTEM Do not modify the size yourself: calculation is complex and need knowledge of around widget */ @@ -160,7 +139,7 @@ public class Widget extends EwolObject { } /** - * @brief calculate the minimum and maximum size (need to estimate expend properties of the widget) + * calculate the minimum and maximum size (need to estimate expend properties of the widget) * @note : INTERNAL EWOL SYSTEM */ public void calculateMinMaxSize() { @@ -171,24 +150,24 @@ public class Widget extends EwolObject { } /** - * @brief get the widget minimum size calculated + * get the widget minimum size calculated * @return Requested size * @note : INTERNAL EWOL SYSTEM */ public Vector2f getCalculateMinSize() { - if (this.propertyHide == false) { + if (!this.propertyHide) { return this.minSize; } return new Vector2f(0, 0); } /** - * @brief get the widget maximum size calculated + * get the widget maximum size calculated * @return Requested size * @note : INTERNAL EWOL SYSTEM */ public Vector2f getCalculateMaxSize() { - if (this.propertyHide == false) { + if (!this.propertyHide) { return this.maxSize; } return new Vector2f(999999, 999999); @@ -197,8 +176,8 @@ public class Widget extends EwolObject { protected Vector2f offset = new Vector2f(0, 0); //!< Offset of the display in the view-port /** - * @brief set the zoom property of the widget. - * @param[in] _newVal offset value. + * set the zoom property of the widget. + * @param _newVal offset value. */ public void setOffset(final Vector2f _newVal) { Log.info("Set offset: " + _newVal); @@ -209,7 +188,7 @@ public class Widget extends EwolObject { } /** - * @brief get the offset property of the widget. + * get the offset property of the widget. * @return The current offset value. */ Vector2f getOffset() { @@ -220,8 +199,8 @@ public class Widget extends EwolObject { protected float zoom = 1.0f; //!< generic widget zoom /** - * @brief set the zoom property of the widget - * @param[in] _newVal newZoom value + * set the zoom property of the widget + * @param _newVal newZoom value */ public void setZoom(final float _newVal) { if (this.zoom == _newVal) { @@ -232,7 +211,7 @@ public class Widget extends EwolObject { } /** - * @brief get the zoom property of the widget + * get the zoom property of the widget * @return the current zoom value */ public float getZoom() { @@ -240,8 +219,8 @@ public class Widget extends EwolObject { } /** - * @brief Change Zoom property. - * @param[in] _range Range of the zoom change. + * Change Zoom property. + * @param _range Range of the zoom change. */ void changeZoom(final float _range) { @@ -250,9 +229,9 @@ public class Widget extends EwolObject { protected Vector2f origin = new Vector2f(0, 0); //!< internal ... I do not really known how if can use it ... /** - * @brief Set origin at the widget (must be an parent widget that set this parameter). + * Set origin at the widget (must be an parent widget that set this parameter). * This represent the absolute origin in the program windows. - * @param[in] _pos Position of the origin. + * @param _pos Position of the origin. * @note : INTERNAL EWOL SYSTEM */ public void setOrigin(final Vector2f _pos) { @@ -260,7 +239,7 @@ public class Widget extends EwolObject { } /** - * @brief Get the origin (absolute position in the windows). + * Get the origin (absolute position in the windows). * @return Coordinate of the origin requested. */ public Vector2f getOrigin() { @@ -268,55 +247,53 @@ public class Widget extends EwolObject { } /** - * @brief User set No minimum size. + * User set No minimum size. */ public void setNoMinSize() { this.propertyMinSize.set(new Dimension(new Vector2f(0, 0), Distance.PIXEL)); } /** - * @brief Check if the current min size is compatible with the user minimum size + * Check if the current min size is compatible with the user minimum size * If it is not the user minimum size will overWrite the minimum size set. * @note : INTERNAL EWOL SYSTEM */ public void checkMinSize() { final Vector2f pixelSize = this.propertyMinSize.getPixel(); - this.minSize.setX(FMath.max(this.minSize.x, pixelSize.x)); - this.minSize.setY(FMath.max(this.minSize.y, pixelSize.y)); + this.minSize = Vector2f.max(this.minSize, pixelSize); } /** - * @brief User set No maximum size. + * User set No maximum size. */ public void setNoMaxSize() { this.propertyMaxSize.set(new Dimension(new Vector2f(999999, 999999), Distance.PIXEL)); } /** - * @brief Check if the current max size is compatible with the user maximum size + * Check if the current max size is compatible with the user maximum size * If it is not the user maximum size will overWrite the maximum size set. * @note : INTERNAL EWOL SYSTEM */ public void checkMaxSize() { final Vector2f pixelSize = this.propertyMaxSize.getPixel(); - this.maxSize.setX(FMath.min(this.maxSize.x, pixelSize.x)); - this.maxSize.setY(FMath.min(this.maxSize.y, pixelSize.y)); + this.maxSize = Vector2f.min(this.maxSize, pixelSize); } /** - * @brief get the expend capabilities (xy) + * get the expend capabilities (xy) * @return 2D boolean represents the capacity to expend * @note : INTERNAL EWOL SYSTEM */ public Vector2b canExpand() { - if (this.propertyHide == false) { + if (!this.propertyHide) { return this.propertyExpand; } return new Vector2b(false, false); } /** - * @brief get the filling capabilities xy + * get the filling capabilities xy * @return Vector2b repensent the capacity to xy filling * @note : INTERNAL EWOL SYSTEM */ @@ -330,7 +307,7 @@ public class Widget extends EwolObject { private boolean hasFocus = false; //!< set the focus on this widget /** - * @brief get the focus state of the widget + * get the focus state of the widget * @return focus state */ public boolean getFocus() { @@ -338,13 +315,13 @@ public class Widget extends EwolObject { }; /** - * @brief set focus on this widget + * set focus on this widget * @return return true if the widget keep the focus */ public boolean setFocus() { Log.verbose("set focus (start) *propertyCanFocus=" + this.propertyCanFocus + " this.hasFocus=" + this.hasFocus); - if (this.propertyCanFocus == true) { - if (this.hasFocus == false) { + if (this.propertyCanFocus) { + if (!this.hasFocus) { this.hasFocus = true; onGetFocus(); } @@ -356,12 +333,12 @@ public class Widget extends EwolObject { } /** - * @brief remove the focus on this widget + * remove the focus on this widget * @return return true if the widget have release his focus (if he has it) */ public boolean rmFocus() { - if (this.propertyCanFocus == true) { - if (this.hasFocus == true) { + if (this.propertyCanFocus) { + if (this.hasFocus) { this.hasFocus = false; onLostFocus(); } @@ -371,19 +348,19 @@ public class Widget extends EwolObject { } /** - * @brief keep the focus on this widget == > this remove the previous focus on all other widget + * keep the focus on this widget == > this remove the previous focus on all other widget */ public void keepFocus() { getWidgetManager().focusKeep(this); } /** - * @brief Event of the focus has been grabed by the current widget + * Event of the focus has been grabed by the current widget */ protected void onGetFocus() {}; /** - * @brief Event of the focus has been lost by the current widget + * Event of the focus has been lost by the current widget */ protected void onLostFocus() {}; @@ -393,7 +370,7 @@ public class Widget extends EwolObject { private int limitMouseEvent = 3; //!< this is to limit the number of mouse event that the widget can supported /** - * @brief get the number of mouse event supported + * get the number of mouse event supported * @return return the number of event that the mouse supported [0..3] */ public int getMouseLimit() { @@ -401,8 +378,8 @@ public class Widget extends EwolObject { }; /** - * @brief get the number of mouse event supported - * @param[in] _numberState The number of event that the mouse supported [0..3] + * get the number of mouse event supported + * @param _numberState The number of event that the mouse supported [0..3] */ public void setMouseLimit(final int _numberState) { this.limitMouseEvent = _numberState; @@ -414,7 +391,7 @@ public class Widget extends EwolObject { private boolean allowRepeatKeyboardEvent = true; //!< This remove the repeating keybord event due to the ant pressing key. /** - * @brief get the keyboard repeating event supporting. + * get the keyboard repeating event supporting. * @return true : the event can be repeated. * @return false : the event must not be repeated. */ @@ -423,36 +400,36 @@ public class Widget extends EwolObject { }; /** - * @brief set the keyboard repeating event supporting. - * @param[in] _state The repeating status (true: enable, false disable). + * set the keyboard repeating event supporting. + * @param _state The repeating status (true: enable, false disable). */ protected void setKeyboardRepeat(final boolean _state) { this.allowRepeatKeyboardEvent = _state; }; /** - * @brief display the keyboard (if needed) + * display the keyboard (if needed) */ protected void showKeyboard() { getContext().keyboardShow(); } /** - * @brief Hide the keyboard (if needed) + * Hide the keyboard (if needed) */ protected void hideKeyboard() { getContext().keyboardHide(); } /** - * @brief get the widget at the specific windows absolute position - * @param[in] _pos gAbsolute position of the requested widget knowledge + * get the widget at the specific windows absolute position + * @param _pos gAbsolute position of the requested widget knowledge * @return null No widget found * @return pointer on the widget found * @note : INTERNAL EWOL SYSTEM */ public Widget getWidgetAtPos(final Vector2f _pos) { - if (this.propertyHide == false) { + if (!this.propertyHide) { return this; } return null; @@ -460,15 +437,15 @@ public class Widget extends EwolObject { // event section: /** - * @brief {SYSTEM} system event input (only meta widget might overwrite this function). - * @param[in] _event Event properties + * {SYSTEM} system event input (only meta widget might overwrite this function). + * @param _event Event properties * @return true the event is used * @return false the event is not used */ public boolean systemEventInput(final InputSystem _event) { final Widget up = (Widget) this.parent.get(); if (up != null) { - if (up.systemEventInput(_event) == true) { + if (up.systemEventInput(_event)) { return true; } } @@ -476,8 +453,8 @@ public class Widget extends EwolObject { } /** - * @brief Event on an input of this Widget (finger, mouse, stylet) - * @param[in] _event Event properties + * Event on an input of this Widget (finger, mouse, stylet) + * @param _event Event properties * @return true the event is used * @return false the event is not used */ @@ -486,15 +463,15 @@ public class Widget extends EwolObject { }; /** - * @brief {SYSTEM} Entry event (only meta widget might overwrite this function). - * @param[in] _event Event properties + * {SYSTEM} Entry event (only meta widget might overwrite this function). + * @param _event Event properties * @return true if the event has been used * @return false if the event has not been used */ public boolean systemEventEntry(final EntrySystem _event) { final Widget up = (Widget) this.parent.get(); if (up != null) { - if (up.systemEventEntry(_event) == true) { + if (up.systemEventEntry(_event)) { return true; } } @@ -502,12 +479,12 @@ public class Widget extends EwolObject { } /** - * @brief Entry event. + * Entry event. * represent the physical event : * - Keyboard (key event and move event) * - Accelerometer * - Joystick - * @param[in] _event Event properties + * @param _event Event properties * @return true if the event has been used * @return false if the event has not been used */ @@ -516,9 +493,9 @@ public class Widget extends EwolObject { }; /** - * @brief Event on a past event == > this event is asynchronous due to all system does not support direct getting data. + * Event on a past event == > this event is asynchronous due to all system does not support direct getting data. * @note : need to have focus ... - * @param[in] mode Mode of data requested + * @param _clipboardID Mode of data requested */ public void onEventClipboard(final ClipboardList _clipboardID) {}; @@ -527,17 +504,21 @@ public class Widget extends EwolObject { // ---------------------------------------------------------------------------------------------------------------- @EwolSignal(name = "shortcut") public Signal signalShortcut; //!< signal handle of the message - private List localShortcut; //!< list of all shortcut in the widget + private final List localShortcut = new ArrayList<>(); //!< list of all shortcut in the widget /** - * @brief add a specific shortcut with his description - * @param[in] _descriptiveString Description string of the shortcut - * @param[in] _message massage to generate (or shortcut name) + * add a specific shortcut with his description + * @param _descriptiveString Description string of the shortcut */ protected void shortCutAdd(final String _descriptiveString) { shortCutAdd(_descriptiveString, ""); } - + + /** + * add a specific shortcut with his description + * @param _descriptiveString Description string of the shortcut + * @param _message massage to generate (or shortcut name) + */ protected void shortCutAdd(final String _descriptiveString, final String _message) { if (_descriptiveString.length() == 0) { Log.error("try to add shortcut with no descriptive string ..."); @@ -554,71 +535,71 @@ public class Widget extends EwolObject { } // parsing of the string: //"ctrl+shift+alt+metatmpElement.+s" - if (_descriptiveString.indexOf("ctrl") != -1) { + if (_descriptiveString.contains("ctrl")) { specialKey.setCtrlLeft(true); } - if (_descriptiveString.indexOf("shift") != -1) { + if (_descriptiveString.contains("shift")) { specialKey.setShiftLeft(true); } - if (_descriptiveString.indexOf("alt") != -1) { + if (_descriptiveString.contains("alt")) { specialKey.setAltLeft(true); } - if (_descriptiveString.indexOf("meta") != -1) { + if (_descriptiveString.contains("meta")) { specialKey.setMetaLeft(true); } - if (_descriptiveString.indexOf("F12") != -1) { + if (_descriptiveString.contains("F12")) { keyboardMoveValue = KeyKeyboard.f12; - } else if (_descriptiveString.indexOf("F11") != -1) { + } else if (_descriptiveString.contains("F11")) { keyboardMoveValue = KeyKeyboard.f11; - } else if (_descriptiveString.indexOf("F10") != -1) { + } else if (_descriptiveString.contains("F10")) { keyboardMoveValue = KeyKeyboard.f10; - } else if (_descriptiveString.indexOf("F9") != -1) { + } else if (_descriptiveString.contains("F9")) { keyboardMoveValue = KeyKeyboard.f9; - } else if (_descriptiveString.indexOf("F8") != -1) { + } else if (_descriptiveString.contains("F8")) { keyboardMoveValue = KeyKeyboard.f8; - } else if (_descriptiveString.indexOf("F7") != -1) { + } else if (_descriptiveString.contains("F7")) { keyboardMoveValue = KeyKeyboard.f7; - } else if (_descriptiveString.indexOf("F6") != -1) { + } else if (_descriptiveString.contains("F6")) { keyboardMoveValue = KeyKeyboard.f6; - } else if (_descriptiveString.indexOf("F5") != -1) { + } else if (_descriptiveString.contains("F5")) { keyboardMoveValue = KeyKeyboard.f5; - } else if (_descriptiveString.indexOf("F4") != -1) { + } else if (_descriptiveString.contains("F4")) { keyboardMoveValue = KeyKeyboard.f4; - } else if (_descriptiveString.indexOf("F3") != -1) { + } else if (_descriptiveString.contains("F3")) { keyboardMoveValue = KeyKeyboard.f3; - } else if (_descriptiveString.indexOf("F2") != -1) { + } else if (_descriptiveString.contains("F2")) { keyboardMoveValue = KeyKeyboard.f2; - } else if (_descriptiveString.indexOf("F1") != -1) { + } else if (_descriptiveString.contains("F1")) { keyboardMoveValue = KeyKeyboard.f1; - } else if (_descriptiveString.indexOf("LEFT") != -1) { + } else if (_descriptiveString.contains("LEFT")) { keyboardMoveValue = KeyKeyboard.left; - } else if (_descriptiveString.indexOf("RIGHT") != -1) { + } else if (_descriptiveString.contains("RIGHT")) { keyboardMoveValue = KeyKeyboard.right; - } else if (_descriptiveString.indexOf("UP") != -1) { + } else if (_descriptiveString.contains("UP")) { keyboardMoveValue = KeyKeyboard.up; - } else if (_descriptiveString.indexOf("DOWN") != -1) { + } else if (_descriptiveString.contains("DOWN")) { keyboardMoveValue = KeyKeyboard.down; - } else if (_descriptiveString.indexOf("PAGE_UP") != -1) { + } else if (_descriptiveString.contains("PAGE_UP")) { keyboardMoveValue = KeyKeyboard.pageUp; - } else if (_descriptiveString.indexOf("PAGE_DOWN") != -1) { + } else if (_descriptiveString.contains("PAGE_DOWN")) { keyboardMoveValue = KeyKeyboard.pageDown; - } else if (_descriptiveString.indexOf("START") != -1) { + } else if (_descriptiveString.contains("START")) { keyboardMoveValue = KeyKeyboard.start; - } else if (_descriptiveString.indexOf("END") != -1) { + } else if (_descriptiveString.contains("END")) { keyboardMoveValue = KeyKeyboard.end; - } else if (_descriptiveString.indexOf("PRINT") != -1) { + } else if (_descriptiveString.contains("PRINT")) { keyboardMoveValue = KeyKeyboard.print; - } else if (_descriptiveString.indexOf("ARRET_DEFIL") != -1) { + } else if (_descriptiveString.contains("ARRET_DEFIL")) { keyboardMoveValue = KeyKeyboard.stopDefil; - } else if (_descriptiveString.indexOf("WAIT") != -1) { + } else if (_descriptiveString.contains("WAIT")) { keyboardMoveValue = KeyKeyboard.wait; - } else if (_descriptiveString.indexOf("INSERT") != -1) { + } else if (_descriptiveString.contains("INSERT")) { keyboardMoveValue = KeyKeyboard.insert; - } else if (_descriptiveString.indexOf("CAPLOCK") != -1) { + } else if (_descriptiveString.contains("CAPLOCK")) { keyboardMoveValue = KeyKeyboard.capLock; - } else if (_descriptiveString.indexOf("CONTEXT_MENU") != -1) { + } else if (_descriptiveString.contains("CONTEXT_MENU")) { keyboardMoveValue = KeyKeyboard.contextMenu; - } else if (_descriptiveString.indexOf("NUM_LOCK") != -1) { + } else if (_descriptiveString.contains("NUM_LOCK")) { keyboardMoveValue = KeyKeyboard.numLock; } else { unicodeValue = _descriptiveString.charAt(_descriptiveString.length() - 1); @@ -628,30 +609,25 @@ public class Widget extends EwolObject { } /** - * @brief remove all current shortCut + * remove all current shortCut */ protected void shortCutClean() { this.localShortcut.clear(); } /** - * @brief remove a specific shortCut with his event name - * @param[in] _message generated event name + * remove a specific shortCut with his event name + * @param _message generated event name */ protected void shortCutRemove(final String _message) { - final Iterator iterator = this.localShortcut.iterator(); - while (iterator.hasNext()) { - if (iterator.next().message.contentEquals(_message) == true) { - iterator.remove(); - } - } + this.localShortcut.removeIf(eventShortCut -> eventShortCut.message.contentEquals(_message)); } /** - * @brief Event on a short-cut of this Widget (in case of return false, the event on the keyevent will arrive in the function @ref onEventKb). - * @param[in] _special All the special kay pressed at this time. - * @param[in] _unicodeValue Key pressed by the user not used if the kbMove!=ewol::EVENT_KB_MOVE_TYPE_NONE. - * @param[in] _kbMove Special key of the keyboard. + * Event on a short-cut of this Widget (in case of return false, the event on the keyevent will arrive in the function @ref onEventKb). + * @param _special All the special kay pressed at this time. + * @param _unicodeValue Key pressed by the user not used if the kbMove!=ewol::EVENT_KB_MOVE_TYPE_NONE. + * @param _kbMove Special key of the keyboard. * @return true if the event has been used. * @return false if the event has not been used. * @note To prevent some error when you get an event get it if it is down and Up ... ==> like this it could not generate some mistake in the error. @@ -660,9 +636,9 @@ public class Widget extends EwolObject { _unicodeValue = Character.toLowerCase(_unicodeValue); Log.verbose("check shortcut...." + _special + " " + _unicodeValue + " " + _kbMove + " " + (_isDown ? "DOWN" : "UP") + " nb shortcut:" + this.localShortcut.size()); // Remove the up event of the shortcut... - if (_isDown == false) { + if (!_isDown) { for (int iii = this.localShortcut.size() - 1; iii >= 0; iii--) { - if (this.localShortcut.get(iii).isActive == false) { + if (!this.localShortcut.get(iii).isActive) { continue; } if ((this.localShortcut.get(iii).keyboardMoveValue == KeyKeyboard.unknow && this.localShortcut.get(iii).unicodeValue == _unicodeValue) @@ -680,7 +656,7 @@ public class Widget extends EwolObject { && this.localShortcut.get(iii).specialKey.getAlt() == _special.getAlt() && this.localShortcut.get(iii).specialKey.getMeta() == _special.getMeta() && ((this.localShortcut.get(iii).keyboardMoveValue == KeyKeyboard.unknow && this.localShortcut.get(iii).unicodeValue == _unicodeValue) || (this.localShortcut.get(iii).keyboardMoveValue == _kbMove && this.localShortcut.get(iii).unicodeValue == 0))) { - if (_isDown == true) { + if (_isDown) { this.localShortcut.get(iii).isActive = true; Log.verbose("Generate shortCut: " + this.localShortcut.get(iii).message); this.signalShortcut.emit(this.localShortcut.get(iii).message); @@ -697,10 +673,10 @@ public class Widget extends EwolObject { protected boolean needRegenerateDisplay = true; //!< the display might be done the next regeneration /** - * @brief The widget mark itself that it need to regenerate the nest time. + * The widget mark itself that it need to regenerate the nest time. */ public void markToRedraw() { - if (this.needRegenerateDisplay == true) { + if (this.needRegenerateDisplay) { return; } this.needRegenerateDisplay = true; @@ -708,7 +684,7 @@ public class Widget extends EwolObject { } /** - * @brief get the need of the redrawing of the widget and reset it to false + * get the need of the redrawing of the widget and reset it to false * @return true if we need to redraw * @return false if we have no need to redraw */ @@ -719,10 +695,10 @@ public class Widget extends EwolObject { }; /** - * @brief {SYSTEM} extern interface to request a draw ... (called by the drawing thread [Android, X11, ...]) + * {SYSTEM} extern interface to request a draw ... (called by the drawing thread [Android, X11, ...]) * This function generate a clipping with the view-port openGL system. Like this a widget draw can not draw over an other widget * @note This function is for the scrolled widget, and the more complicated openGL widget - * @param[in] _displayProp properties of the current display + * @param _displayProp properties of the current display * @note : INTERNAL EWOL SYSTEM /-. _displayProp.this.windowsSize *------------------------------------------------------* @@ -752,43 +728,39 @@ public class Widget extends EwolObject { */ public void systemDraw( final DrawProperty _displayProp){ //Log.info("[" + getId() + "] Draw : [" + propertyName + "] t=" + getObjectType() + " o=" + this.origin + " s=" << this.size << " hide=" << propertyHide); - if (this.propertyHide == true){ + if (this.propertyHide){ // widget is hidden ... return; } - final Vector2f displayOrigin = this.origin.addNew(this.offset); + final Vector2f displayOrigin = this.origin.add(this.offset); // check if the element is displayable in the windows : - if( _displayProp.windowsSize.x < this.origin.x - || _displayProp.windowsSize.y < this.origin.y ) { + if( _displayProp.windowsSize().x() < this.origin.x() + || _displayProp.windowsSize().y() < this.origin.y() ) { // out of the windows == > nothing to display ... return; } - final DrawProperty tmpSize = _displayProp.clone(); - tmpSize.limit(this.origin, this.size); - if (tmpSize.size.x <= 0 || tmpSize.size.y <= 0) { + final DrawProperty tmpSize = _displayProp.withLimit(this.origin, this.size); + if (tmpSize.size().x() <= 0 || tmpSize.size().y() <= 0) { return; } - OpenGL.glViewport( (int)tmpSize.origin.x, - (int)tmpSize.origin.y, - (int)tmpSize.size.x, - (int)tmpSize.size.y); + OpenGL.setViewPort( tmpSize.origin(), tmpSize.size()); // special case, when origin < display origin, we need to cut the display : - final Vector2i downOffset = new Vector2i((int)(this.origin.x - tmpSize.origin.x), (int)(this.origin.y - tmpSize.origin.y)); - downOffset.setMin(new Vector2i(0,0)); + Vector2i downOffset = new Vector2i((int)(this.origin.x() - tmpSize.origin().x()), (int)(this.origin.y() - tmpSize.origin().y())); + downOffset = Vector2i.min(downOffset, Vector2i.ZERO); - final Matrix4f tmpTranslate = etk::matTranslate(Vector3fClipInt32(new Vector3f(-tmpSize.size.x/2+this.offset.x + downOffset.x, - -tmpSize.size.y/2+this.offset.y + downOffset.y, - -1.0f))); - final Matrix4f tmpScale = etk::matScale(Vector3f(this.zoom, this.zoom, 1.0f)); - final Matrix4f tmpProjection = etk::matOrtho((int)(-tmpSize.this.size.x)>>1, - (int)( tmpSize.this.size.x)>>1, - (int)(-tmpSize.this.size.y)>>1, - (int)( tmpSize.this.size.y)>>1, + final Matrix4f tmpTranslate = Matrix4f.createMatrixTranslate((new Vector3f(-tmpSize.size().x()/2+this.offset.x() + downOffset.x(), + -tmpSize.size().y()/2+this.offset.y() + downOffset.y(), + -1.0f)).clipInteger()); + final Matrix4f tmpScale = Matrix4f.createMatrixScale(this.zoom, this.zoom, 1.0f); + final Matrix4f tmpProjection = Matrix4f.createMatrixOrtho((int)(-tmpSize.size().x())>>1, + (int)( tmpSize.size().x())>>1, + (int)(-tmpSize.size().y())>>1, + (int)( tmpSize.size().y())>>1, (int)(-1), (int)( 1)); - Matrix4f tmpMat = tmpProjection * tmpScale * tmpTranslate; + Matrix4f tmpMat = tmpProjection.multiply(tmpScale).multiply(tmpTranslate); OpenGL.push(); // set internal matrix system : @@ -796,16 +768,15 @@ public class Widget extends EwolObject { //long ___startTime = ewol::getTime(); onDraw(); OpenGL.pop(); - return; } /** - * @brief Common widget drawing function (called by the drawing thread [Android, X11, ...]) + * Common widget drawing function (called by the drawing thread [Android, X11, ...]) */ protected void onDraw() {}; /** - * @brief Event generated when a redraw is needed + * Event generated when a redraw is needed */ public void onRegenerateDisplay() {}; @@ -813,29 +784,29 @@ public class Widget extends EwolObject { private boolean grabCursor = false; /** - * @brief Grab the cursor : This get all the movement of the mouse in PC mode, and generate an offset instead of a position. + * Grab the cursor : This get all the movement of the mouse in PC mode, and generate an offset instead of a position. * @note : the generation of the offset is due to the fact the cursor position is forced at the center of the widget. * @note This done nothing in "Finger" or "Stylet" mode. */ public void grabCursor() { - if (this.grabCursor == false) { + if (!this.grabCursor) { getContext().inputEventGrabPointer(this); this.grabCursor = true; } } /** - * @brief Un-Grab the cursor (default mode cursor offset) + * Un-Grab the cursor (default mode cursor offset) */ public void unGrabCursor() { - if (this.grabCursor == true) { + if (this.grabCursor) { getContext().inputEventUnGrabPointer(); this.grabCursor = false; } } /** - * @brief get the grabbing status of the cursor. + * get the grabbing status of the cursor. * @return true if the cursor is currently grabbed */ public boolean getGrabStatus() { @@ -845,8 +816,8 @@ public class Widget extends EwolObject { private Cursor cursorDisplay = Cursor.arrow; /** - * @brief set the cursor display type. - * @param[in] _newCursor selected new cursor. + * set the cursor display type. + * @param _newCursor selected new cursor. */ public void setCursor(final Cursor _newCursor) { Log.debug("Change Cursor in " + _newCursor); @@ -855,102 +826,133 @@ public class Widget extends EwolObject { } /** - * @brief get the current cursor. + * get the current cursor. * @return the type of the cursor. */ public Cursor getCursor() { return this.cursorDisplay; } - /* public boolean loadXML( XmlElement _node){ - EwolObject::loadXML(_node); + super.loadXML(_node); markToRedraw(); return true; } - */ /** - * @brief Need to be call When the size of the current widget have change ==> this force the system to recalculate all the widget positions. + * Need to be call When the size of the current widget have change ==> this force the system to recalculate all the widget positions. */ public void requestUpdateSize() { getContext().requestUpdateSize(); } /** - * @brief Get the current Widget Manager. + * Get the current Widget Manager. */ public WidgetManager getWidgetManager() { return getContext().getWidgetManager(); } /** - * @brief Get the current Windows. + * Get the current Windows. */ public Windows getWindows() { return getContext().getWindows(); } - protected void onChangePropertyCanFocus() { - if (this.hasFocus == true) { + public boolean getPropertyCanFocus() { + return this.propertyCanFocus; + } + public void setPropertyCanFocus(boolean canFocus) { + if (this.propertyCanFocus == canFocus) { + return; + } + this.propertyCanFocus = canFocus; + if (this.propertyCanFocus) { + return; + } + if (this.hasFocus) { rmFocus(); } } - protected void onChangePropertyGravity() { + protected Gravity getPropertyGravity() { + return this.propertyGravity; + } + protected void setPropertyGravity(Gravity gravity) { + if (this.propertyGravity.equals(gravity)) { + return; + } + this.propertyGravity = gravity; markToRedraw(); requestUpdateSize(); } - protected void onChangePropertyHide() { + protected boolean getPropertyHide() { + return this.propertyHide; + } + protected void setPropertyHide(boolean value) { + if (this.propertyHide == value) { + return; + } + this.propertyHide = value; markToRedraw(); requestUpdateSize(); } - protected void onChangePropertyFill() { + protected Vector2b getPropertyFill() { + return this.propertyFill; + } + protected void setPropertyFill(Vector2b value) { + if (this.propertyFill.equals(value)) { + return; + } + this.propertyFill = value; + markToRedraw(); + requestUpdateSize(); + } + public Vector2b getPropertyExpand() { + return this.propertyExpand; + } + protected void setPropertyExpand(Vector2b value) { + if (this.propertyExpand.equals(value)) { + return; + } + this.propertyExpand = value; markToRedraw(); requestUpdateSize(); } - protected void onChangePropertyExpand() { - requestUpdateSize(); - markToRedraw(); + protected Dimension getPropertyMaxSize() { + return this.propertyMaxSize; } - - protected void onChangePropertyMaxSize() { + protected void setPropertyMaxSize(Dimension value) { + if (this.propertyMaxSize.equals(value)) { + return; + } + this.propertyMaxSize = value; + onUmpdateMinMaxSize(); + } + protected void onUmpdateMinMaxSize() { final Vector2f pixelMin = this.propertyMinSize.getPixel(); final Vector2f pixelMax = this.propertyMaxSize.getPixel(); // check minimum maximum compatibility : - boolean error = false; - if (pixelMin.x > pixelMax.x) { - error = true; - } - if (pixelMin.y > pixelMax.y) { - error = true; - } - if (error == true) { + if (pixelMin.x() > pixelMax.x() || pixelMin.y() > pixelMax.y()) { Log.error("Can not set a 'min size' > 'max size' reset to maximum ..."); this.propertyMaxSize = new Dimension(new Vector2f(999999, 999999), Distance.PIXEL); } requestUpdateSize(); } - protected void onChangePropertyMinSize() { - final Vector2f pixelMin = this.propertyMinSize.getPixel(); - final Vector2f pixelMax = this.propertyMaxSize.getPixel(); - // check minimum maximum compatibility : - boolean error = false; - if (pixelMin.x > pixelMax.x) { - error = true; + protected Dimension getPropertyMinSize() { + return this.propertyMinSize; + } + protected void setPropertyMinSize(Dimension value) { + if (this.propertyMinSize.equals(value)) { + return; } - if (pixelMin.y > pixelMax.y) { - error = true; - } - if (error == true) { - Log.error("Can not set a 'min size' > 'max size' set nothing ..."); - this.propertyMinSize = new Dimension(new Vector2f(0, 0), Distance.PIXEL); - } - requestUpdateSize(); + this.propertyMinSize = value; + onUmpdateMinMaxSize(); } public void drawWidgetTree(final int _level) { diff --git a/src/org/atriasoft/ewol/widget/WidgetManager.java b/src/org/atriasoft/ewol/widget/WidgetManager.java index 5f91a05..5035282 100644 --- a/src/org/atriasoft/ewol/widget/WidgetManager.java +++ b/src/org/atriasoft/ewol/widget/WidgetManager.java @@ -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;