From 47293d14535b32d60114b1ea60570ab81df7bad1 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 25 Mar 2021 18:54:14 +0100 Subject: [PATCH] [DEV] continue update --- .checkstyle | 2 +- CheckStyle.xml | 4 +- ewol.iml | 3 +- .../{ => resources/ewol}/data/color.frag | 0 .../{ => resources/ewol}/data/color.prog | 0 .../{ => resources/ewol}/data/color.vert | 0 .../{ => resources/ewol}/data/color3.frag | 0 .../{ => resources/ewol}/data/color3.prog | 0 .../{ => resources/ewol}/data/color3.vert | 0 .../ewol}/data/ewol-gui-file-chooser.xml | 0 resources/{ => resources/ewol}/data/icon.svg | 0 .../{ => resources/ewol}/data/simple3D.frag | 0 .../{ => resources/ewol}/data/simple3D.prog | 0 .../{ => resources/ewol}/data/simple3D.vert | 0 resources/{ => resources/ewol}/data/text.frag | 0 resources/{ => resources/ewol}/data/text.prog | 0 resources/{ => resources/ewol}/data/text.vert | 0 .../{ => resources/ewol}/data/textured.frag | 0 .../{ => resources/ewol}/data/textured.prog | 0 .../{ => resources/ewol}/data/textured.vert | 0 .../{ => resources/ewol}/data/textured3D.frag | 0 .../{ => resources/ewol}/data/textured3D.prog | 0 .../{ => resources/ewol}/data/textured3D.vert | 0 .../ewol}/data/textured3D2.frag | 0 .../ewol}/data/textured3D2.prog | 0 .../ewol}/data/textured3D2.vert | 0 .../{ => resources/ewol}/data/texturedDF.frag | 0 .../{ => resources/ewol}/data/texturedDF.vert | 0 .../ewol}/data/texturedNoMaterial.frag | 0 .../ewol}/data/texturedNoMaterial.prog | 0 .../ewol}/data/texturedNoMaterial.vert | 0 .../ewol}/fonts/FreeMono.svg | 0 .../ewol}/fonts/FreeMonoBold.svg | 0 .../ewol}/fonts/FreeMonoBoldOblique.svg | 0 .../ewol}/fonts/FreeMonoOblique.svg | 0 .../ewol}/fonts/FreeSans.svg | 0 .../ewol}/fonts/FreeSansBold.svg | 0 .../ewol}/fonts/FreeSansBoldOblique.svg | 0 .../ewol}/fonts/FreeSansOblique.svg | 0 .../ewol}/fonts/FreeSerif.svg | 0 .../ewol}/theme/color/black/Button.json | 0 .../ewol}/theme/color/black/CheckBox.json | 0 .../ewol}/theme/color/black/ContextMenu.json | 0 .../ewol}/theme/color/black/Entry.json | 0 .../ewol}/theme/color/black/Image.json | 0 .../ewol}/theme/color/black/Label.json | 0 .../theme/color/black/ListFileSystem.json | 0 .../ewol}/theme/color/black/PopUp.json | 0 .../theme/color/black/WidgetScrolled.json | 0 .../ewol}/theme/color/black/Windows.json | 0 .../ewol}/theme/color/white/Button.json | 0 .../ewol}/theme/color/white/CheckBox.json | 0 .../ewol}/theme/color/white/ContextMenu.json | 0 .../ewol}/theme/color/white/Entry.json | 0 .../ewol}/theme/color/white/Image.json | 0 .../ewol}/theme/color/white/Label.json | 0 .../theme/color/white/ListFileSystem.json | 0 .../ewol}/theme/color/white/PopUp.json | 0 .../theme/color/white/WidgetScrolled.json | 0 .../ewol}/theme/color/white/Windows.json | 0 .../ewol}/theme/default/Add.svg | 0 .../ewol}/theme/default/AtoZ.svg | 0 .../ewol}/theme/default/Attache.svg | 0 .../ewol}/theme/default/CaseSensitive.svg | 0 .../ewol}/theme/default/ChevronLeft.svg | 0 .../ewol}/theme/default/ChevronLess.svg | 0 .../ewol}/theme/default/ChevronMore.svg | 0 .../ewol}/theme/default/ChevronRight.svg | 0 .../ewol}/theme/default/Close.svg | 0 .../ewol}/theme/default/Contact.svg | 0 .../ewol}/theme/default/Down.svg | 0 .../ewol}/theme/default/FavoriteDisable.svg | 0 .../ewol}/theme/default/FavoriteEnable.svg | 0 .../ewol}/theme/default/FavoriteMiddle.svg | 0 .../ewol}/theme/default/File.svg | 0 .../ewol}/theme/default/Folder.svg | 0 .../ewol}/theme/default/Forbidden.svg | 0 .../ewol}/theme/default/Help.svg | 0 .../ewol}/theme/default/Home.svg | 0 .../ewol}/theme/default/Info.svg | 0 .../ewol}/theme/default/List.svg | 0 .../ewol}/theme/default/Load.svg | 0 .../ewol}/theme/default/Lock.svg | 0 .../ewol}/theme/default/Next.svg | 0 .../ewol}/theme/default/OpenMenu.svg | 0 .../ewol}/theme/default/Parameter.svg | 0 .../ewol}/theme/default/Previous.svg | 0 .../ewol}/theme/default/Quit.svg | 0 .../ewol}/theme/default/Redo.svg | 0 .../ewol}/theme/default/Remove.svg | 0 .../ewol}/theme/default/Remove2.svg | 0 .../ewol}/theme/default/Replace.svg | 0 .../ewol}/theme/default/SDCard.svg | 0 .../ewol}/theme/default/Save.svg | 0 .../ewol}/theme/default/Search.svg | 0 .../ewol}/theme/default/Trash.svg | 0 .../ewol}/theme/default/Undo.svg | 0 .../ewol}/theme/default/Up.svg | 0 .../ewol}/theme/default/Update.svg | 0 .../ewol}/theme/default/Validate.svg | 0 .../ewol}/theme/default/VolumeMax.svg | 0 .../ewol}/theme/default/VolumeMute.svg | 0 .../ewol}/theme/default/Warning.svg | 0 .../ewol}/theme/default/WhereAmI.svg | 0 .../ewol}/theme/default/WrapAround.svg | 0 .../ewol}/theme/default/ZoomIn.svg | 0 .../ewol}/theme/shape/round/Button.frag | 0 .../ewol}/theme/shape/round/Button.json | 0 .../ewol}/theme/shape/round/Button.vert | 0 .../ewol}/theme/shape/round/CheckBox.frag | 0 .../ewol}/theme/shape/round/CheckBox.json | 0 .../ewol}/theme/shape/round/CheckBox.vert | 0 .../ewol}/theme/shape/round/ContextMenu.frag | 0 .../ewol}/theme/shape/round/ContextMenu.json | 0 .../ewol}/theme/shape/round/ContextMenu.vert | 0 .../ewol}/theme/shape/round/Entry.frag | 0 .../ewol}/theme/shape/round/Entry.json | 0 .../ewol}/theme/shape/round/Entry.vert | 0 .../ewol}/theme/shape/round/PopUp.frag | 0 .../ewol}/theme/shape/round/PopUp.json | 0 .../ewol}/theme/shape/round/PopUp.vert | 0 .../theme/shape/round/WidgetScrolled.frag | 0 .../theme/shape/round/WidgetScrolled.json | 0 .../theme/shape/round/WidgetScrolled.vert | 0 .../ewol}/theme/shape/square/Button.frag | 0 .../ewol}/theme/shape/square/Button.json | 0 .../ewol}/theme/shape/square/Button.vert | 0 .../ewol}/theme/shape/square/CheckBox.frag | 0 .../ewol}/theme/shape/square/CheckBox.json | 0 .../ewol}/theme/shape/square/CheckBox.vert | 0 .../ewol}/theme/shape/square/ContextMenu.frag | 0 .../ewol}/theme/shape/square/ContextMenu.json | 0 .../ewol}/theme/shape/square/ContextMenu.vert | 0 .../ewol}/theme/shape/square/Entry.frag | 0 .../ewol}/theme/shape/square/Entry.json | 0 .../ewol}/theme/shape/square/Entry.vert | 0 .../ewol}/theme/shape/square/PopUp.frag | 0 .../ewol}/theme/shape/square/PopUp.json | 0 .../ewol}/theme/shape/square/PopUp.vert | 0 .../ewol}/theme/shape/square/Select.json | 0 .../ewol}/theme/shape/square/SelectBt.json | 0 .../ewol}/theme/shape/square/SelectEntry.json | 0 .../ewol}/theme/shape/square/Spin.json | 0 .../ewol}/theme/shape/square/SpinDown.json | 0 .../ewol}/theme/shape/square/SpinEntry.json | 0 .../ewol}/theme/shape/square/SpinUp.json | 0 .../theme/shape/square/WidgetScrolled.frag | 0 .../theme/shape/square/WidgetScrolled.json | 0 .../theme/shape/square/WidgetScrolled.vert | 0 .../ewol}/translate/EN.json | 0 .../ewol}/translate/FR.json | 0 src/org/atriasoft/echrono/Clock.java | 16 +- src/org/atriasoft/echrono/Duration.java | 16 +- src/org/atriasoft/echrono/Steady.java | 16 +- src/org/atriasoft/echrono/Time.java | 16 +- src/org/atriasoft/egami/Egami.java | 13 + src/org/atriasoft/egami/Image.java | 2 +- src/org/atriasoft/esignal/Signal.java | 10 +- src/org/atriasoft/esignal/SignalEmpty.java | 62 + src/org/atriasoft/etranslate/ETranslate.java | 250 +-- src/org/atriasoft/ewol/DrawProperty.java | 22 +- src/org/atriasoft/ewol/Ewol.java | 24 +- src/org/atriasoft/ewol/Gravity.java | 42 +- src/org/atriasoft/ewol/Padding.java | 125 +- .../ewol/annotation/EwolAnnotation.java | 2 +- .../atriasoft/ewol/compositing/AlignMode.java | 5 + .../ewol/compositing/Compositing.java | 29 +- .../ewol/compositing/CompositingDrawing.java | 447 +++-- .../ewol/compositing/CompositingImage.java | 275 ++- .../ewol/compositing/CompositingText.java | 405 +++++ src/org/atriasoft/ewol/compositing/Text.java | 414 ----- .../atriasoft/ewol/compositing/TextBase.java | 959 +++++------ .../atriasoft/ewol/context/ConfigFont.java | 46 +- .../ewol/context/EwolApplication.java | 30 +- .../atriasoft/ewol/context/EwolContext.java | 251 ++- .../atriasoft/ewol/context/InputManager.java | 391 +++-- src/org/atriasoft/ewol/event/EntrySystem.java | 11 +- src/org/atriasoft/ewol/event/EventEntry.java | 30 +- src/org/atriasoft/ewol/event/EventInput.java | 67 +- .../atriasoft/ewol/event/EventShortCut.java | 30 +- src/org/atriasoft/ewol/event/EventTime.java | 46 +- src/org/atriasoft/ewol/event/InputSystem.java | 35 +- src/org/atriasoft/ewol/ewol.cpp | 32 - src/org/atriasoft/ewol/internal/Tools.java | 4 +- src/org/atriasoft/ewol/object/EwolObject.java | 112 +- .../atriasoft/ewol/object/ObjectManager.java | 68 +- .../resource/RefactorColored3DObject.java | 560 +++--- .../ewol/resource/ResourceColorFile.java | 87 +- .../ewol/resource/ResourceConfigFile.java | 78 +- .../ewol/resource/ResourceFontFreeType.java | 192 +-- .../ewol/resource/ResourceTexture2.java | 177 +- .../ewol/resource/ResourceTextureFile.java | 87 +- .../ewol/resource/ResourceTexturedFont.java | 270 ++- .../ewol/resource/font/FontBase.java | 24 +- .../ewol/resource/font/FontMode.java | 15 +- .../ewol/resource/font/GlyphProperty.java | 24 +- .../atriasoft/ewol/resource/font/Kerning.java | 22 +- src/org/atriasoft/ewol/tools/Message.java | 109 +- src/org/atriasoft/ewol/widget/Container.java | 340 ++-- src/org/atriasoft/ewol/widget/ContainerN.java | 585 ++++--- src/org/atriasoft/ewol/widget/Image.cpp | 239 --- src/org/atriasoft/ewol/widget/Image.java | 82 - .../atriasoft/ewol/widget/ImageDisplay.java | 363 ++++ src/org/atriasoft/ewol/widget/Label.cpp | 175 -- src/org/atriasoft/ewol/widget/Label.java | 265 ++- .../atriasoft/ewol/widget/ProgressBar.java | 141 +- src/org/atriasoft/ewol/widget/Sizer.cpp | 300 ---- src/org/atriasoft/ewol/widget/Sizer.java | 299 +++- src/org/atriasoft/ewol/widget/Spacer.java | 44 +- src/org/atriasoft/ewol/widget/Widget.java | 1512 +++++++++-------- .../atriasoft/ewol/widget/WidgetManager.java | 121 +- src/org/atriasoft/ewol/widget/Windows.cpp | 290 ---- src/org/atriasoft/ewol/widget/Windows.java | 308 +++- 213 files changed, 5444 insertions(+), 5577 deletions(-) rename resources/{ => resources/ewol}/data/color.frag (100%) rename resources/{ => resources/ewol}/data/color.prog (100%) rename resources/{ => resources/ewol}/data/color.vert (100%) rename resources/{ => resources/ewol}/data/color3.frag (100%) rename resources/{ => resources/ewol}/data/color3.prog (100%) rename resources/{ => resources/ewol}/data/color3.vert (100%) rename resources/{ => resources/ewol}/data/ewol-gui-file-chooser.xml (100%) rename resources/{ => resources/ewol}/data/icon.svg (100%) rename resources/{ => resources/ewol}/data/simple3D.frag (100%) rename resources/{ => resources/ewol}/data/simple3D.prog (100%) rename resources/{ => resources/ewol}/data/simple3D.vert (100%) rename resources/{ => resources/ewol}/data/text.frag (100%) rename resources/{ => resources/ewol}/data/text.prog (100%) rename resources/{ => resources/ewol}/data/text.vert (100%) rename resources/{ => resources/ewol}/data/textured.frag (100%) rename resources/{ => resources/ewol}/data/textured.prog (100%) rename resources/{ => resources/ewol}/data/textured.vert (100%) rename resources/{ => resources/ewol}/data/textured3D.frag (100%) rename resources/{ => resources/ewol}/data/textured3D.prog (100%) rename resources/{ => resources/ewol}/data/textured3D.vert (100%) rename resources/{ => resources/ewol}/data/textured3D2.frag (100%) rename resources/{ => resources/ewol}/data/textured3D2.prog (100%) rename resources/{ => resources/ewol}/data/textured3D2.vert (100%) rename resources/{ => resources/ewol}/data/texturedDF.frag (100%) rename resources/{ => resources/ewol}/data/texturedDF.vert (100%) rename resources/{ => resources/ewol}/data/texturedNoMaterial.frag (100%) rename resources/{ => resources/ewol}/data/texturedNoMaterial.prog (100%) rename resources/{ => resources/ewol}/data/texturedNoMaterial.vert (100%) rename resources/{data => resources/ewol}/fonts/FreeMono.svg (100%) rename resources/{data => resources/ewol}/fonts/FreeMonoBold.svg (100%) rename resources/{data => resources/ewol}/fonts/FreeMonoBoldOblique.svg (100%) rename resources/{data => resources/ewol}/fonts/FreeMonoOblique.svg (100%) rename resources/{data => resources/ewol}/fonts/FreeSans.svg (100%) rename resources/{data => resources/ewol}/fonts/FreeSansBold.svg (100%) rename resources/{data => resources/ewol}/fonts/FreeSansBoldOblique.svg (100%) rename resources/{data => resources/ewol}/fonts/FreeSansOblique.svg (100%) rename resources/{data => resources/ewol}/fonts/FreeSerif.svg (100%) rename resources/{data => resources/ewol}/theme/color/black/Button.json (100%) rename resources/{data => resources/ewol}/theme/color/black/CheckBox.json (100%) rename resources/{data => resources/ewol}/theme/color/black/ContextMenu.json (100%) rename resources/{data => resources/ewol}/theme/color/black/Entry.json (100%) rename resources/{data => resources/ewol}/theme/color/black/Image.json (100%) rename resources/{data => resources/ewol}/theme/color/black/Label.json (100%) rename resources/{data => resources/ewol}/theme/color/black/ListFileSystem.json (100%) rename resources/{data => resources/ewol}/theme/color/black/PopUp.json (100%) rename resources/{data => resources/ewol}/theme/color/black/WidgetScrolled.json (100%) rename resources/{data => resources/ewol}/theme/color/black/Windows.json (100%) rename resources/{data => resources/ewol}/theme/color/white/Button.json (100%) rename resources/{data => resources/ewol}/theme/color/white/CheckBox.json (100%) rename resources/{data => resources/ewol}/theme/color/white/ContextMenu.json (100%) rename resources/{data => resources/ewol}/theme/color/white/Entry.json (100%) rename resources/{data => resources/ewol}/theme/color/white/Image.json (100%) rename resources/{data => resources/ewol}/theme/color/white/Label.json (100%) rename resources/{data => resources/ewol}/theme/color/white/ListFileSystem.json (100%) rename resources/{data => resources/ewol}/theme/color/white/PopUp.json (100%) rename resources/{data => resources/ewol}/theme/color/white/WidgetScrolled.json (100%) rename resources/{data => resources/ewol}/theme/color/white/Windows.json (100%) rename resources/{data => resources/ewol}/theme/default/Add.svg (100%) rename resources/{data => resources/ewol}/theme/default/AtoZ.svg (100%) rename resources/{data => resources/ewol}/theme/default/Attache.svg (100%) rename resources/{data => resources/ewol}/theme/default/CaseSensitive.svg (100%) rename resources/{data => resources/ewol}/theme/default/ChevronLeft.svg (100%) rename resources/{data => resources/ewol}/theme/default/ChevronLess.svg (100%) rename resources/{data => resources/ewol}/theme/default/ChevronMore.svg (100%) rename resources/{data => resources/ewol}/theme/default/ChevronRight.svg (100%) rename resources/{data => resources/ewol}/theme/default/Close.svg (100%) rename resources/{data => resources/ewol}/theme/default/Contact.svg (100%) rename resources/{data => resources/ewol}/theme/default/Down.svg (100%) rename resources/{data => resources/ewol}/theme/default/FavoriteDisable.svg (100%) rename resources/{data => resources/ewol}/theme/default/FavoriteEnable.svg (100%) rename resources/{data => resources/ewol}/theme/default/FavoriteMiddle.svg (100%) rename resources/{data => resources/ewol}/theme/default/File.svg (100%) rename resources/{data => resources/ewol}/theme/default/Folder.svg (100%) rename resources/{data => resources/ewol}/theme/default/Forbidden.svg (100%) rename resources/{data => resources/ewol}/theme/default/Help.svg (100%) rename resources/{data => resources/ewol}/theme/default/Home.svg (100%) rename resources/{data => resources/ewol}/theme/default/Info.svg (100%) rename resources/{data => resources/ewol}/theme/default/List.svg (100%) rename resources/{data => resources/ewol}/theme/default/Load.svg (100%) rename resources/{data => resources/ewol}/theme/default/Lock.svg (100%) rename resources/{data => resources/ewol}/theme/default/Next.svg (100%) rename resources/{data => resources/ewol}/theme/default/OpenMenu.svg (100%) rename resources/{data => resources/ewol}/theme/default/Parameter.svg (100%) rename resources/{data => resources/ewol}/theme/default/Previous.svg (100%) rename resources/{data => resources/ewol}/theme/default/Quit.svg (100%) rename resources/{data => resources/ewol}/theme/default/Redo.svg (100%) rename resources/{data => resources/ewol}/theme/default/Remove.svg (100%) rename resources/{data => resources/ewol}/theme/default/Remove2.svg (100%) rename resources/{data => resources/ewol}/theme/default/Replace.svg (100%) rename resources/{data => resources/ewol}/theme/default/SDCard.svg (100%) rename resources/{data => resources/ewol}/theme/default/Save.svg (100%) rename resources/{data => resources/ewol}/theme/default/Search.svg (100%) rename resources/{data => resources/ewol}/theme/default/Trash.svg (100%) rename resources/{data => resources/ewol}/theme/default/Undo.svg (100%) rename resources/{data => resources/ewol}/theme/default/Up.svg (100%) rename resources/{data => resources/ewol}/theme/default/Update.svg (100%) rename resources/{data => resources/ewol}/theme/default/Validate.svg (100%) rename resources/{data => resources/ewol}/theme/default/VolumeMax.svg (100%) rename resources/{data => resources/ewol}/theme/default/VolumeMute.svg (100%) rename resources/{data => resources/ewol}/theme/default/Warning.svg (100%) rename resources/{data => resources/ewol}/theme/default/WhereAmI.svg (100%) rename resources/{data => resources/ewol}/theme/default/WrapAround.svg (100%) rename resources/{data => resources/ewol}/theme/default/ZoomIn.svg (100%) rename resources/{data => resources/ewol}/theme/shape/round/Button.frag (100%) rename resources/{data => resources/ewol}/theme/shape/round/Button.json (100%) rename resources/{data => resources/ewol}/theme/shape/round/Button.vert (100%) rename resources/{data => resources/ewol}/theme/shape/round/CheckBox.frag (100%) rename resources/{data => resources/ewol}/theme/shape/round/CheckBox.json (100%) rename resources/{data => resources/ewol}/theme/shape/round/CheckBox.vert (100%) rename resources/{data => resources/ewol}/theme/shape/round/ContextMenu.frag (100%) rename resources/{data => resources/ewol}/theme/shape/round/ContextMenu.json (100%) rename resources/{data => resources/ewol}/theme/shape/round/ContextMenu.vert (100%) rename resources/{data => resources/ewol}/theme/shape/round/Entry.frag (100%) rename resources/{data => resources/ewol}/theme/shape/round/Entry.json (100%) rename resources/{data => resources/ewol}/theme/shape/round/Entry.vert (100%) rename resources/{data => resources/ewol}/theme/shape/round/PopUp.frag (100%) rename resources/{data => resources/ewol}/theme/shape/round/PopUp.json (100%) rename resources/{data => resources/ewol}/theme/shape/round/PopUp.vert (100%) rename resources/{data => resources/ewol}/theme/shape/round/WidgetScrolled.frag (100%) rename resources/{data => resources/ewol}/theme/shape/round/WidgetScrolled.json (100%) rename resources/{data => resources/ewol}/theme/shape/round/WidgetScrolled.vert (100%) rename resources/{data => resources/ewol}/theme/shape/square/Button.frag (100%) rename resources/{data => resources/ewol}/theme/shape/square/Button.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/Button.vert (100%) rename resources/{data => resources/ewol}/theme/shape/square/CheckBox.frag (100%) rename resources/{data => resources/ewol}/theme/shape/square/CheckBox.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/CheckBox.vert (100%) rename resources/{data => resources/ewol}/theme/shape/square/ContextMenu.frag (100%) rename resources/{data => resources/ewol}/theme/shape/square/ContextMenu.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/ContextMenu.vert (100%) rename resources/{data => resources/ewol}/theme/shape/square/Entry.frag (100%) rename resources/{data => resources/ewol}/theme/shape/square/Entry.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/Entry.vert (100%) rename resources/{data => resources/ewol}/theme/shape/square/PopUp.frag (100%) rename resources/{data => resources/ewol}/theme/shape/square/PopUp.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/PopUp.vert (100%) rename resources/{data => resources/ewol}/theme/shape/square/Select.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/SelectBt.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/SelectEntry.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/Spin.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/SpinDown.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/SpinEntry.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/SpinUp.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/WidgetScrolled.frag (100%) rename resources/{data => resources/ewol}/theme/shape/square/WidgetScrolled.json (100%) rename resources/{data => resources/ewol}/theme/shape/square/WidgetScrolled.vert (100%) rename resources/{data => resources/ewol}/translate/EN.json (100%) rename resources/{data => resources/ewol}/translate/FR.json (100%) create mode 100644 src/org/atriasoft/egami/Egami.java create mode 100644 src/org/atriasoft/esignal/SignalEmpty.java create mode 100644 src/org/atriasoft/ewol/compositing/AlignMode.java create mode 100644 src/org/atriasoft/ewol/compositing/CompositingText.java delete mode 100644 src/org/atriasoft/ewol/compositing/Text.java delete mode 100644 src/org/atriasoft/ewol/ewol.cpp delete mode 100644 src/org/atriasoft/ewol/widget/Image.cpp delete mode 100644 src/org/atriasoft/ewol/widget/Image.java create mode 100644 src/org/atriasoft/ewol/widget/ImageDisplay.java delete mode 100644 src/org/atriasoft/ewol/widget/Label.cpp delete mode 100644 src/org/atriasoft/ewol/widget/Sizer.cpp delete mode 100644 src/org/atriasoft/ewol/widget/Windows.cpp diff --git a/.checkstyle b/.checkstyle index 34ed486..428926e 100644 --- a/.checkstyle +++ b/.checkstyle @@ -1,7 +1,7 @@ - + diff --git a/CheckStyle.xml b/CheckStyle.xml index 1bae003..d68aedd 100755 --- a/CheckStyle.xml +++ b/CheckStyle.xml @@ -3,12 +3,12 @@ diff --git a/ewol.iml b/ewol.iml index 13d9bea..5b42ad0 100644 --- a/ewol.iml +++ b/ewol.iml @@ -3,6 +3,7 @@ + @@ -10,7 +11,7 @@ - + \ No newline at end of file diff --git a/resources/data/color.frag b/resources/resources/ewol/data/color.frag similarity index 100% rename from resources/data/color.frag rename to resources/resources/ewol/data/color.frag diff --git a/resources/data/color.prog b/resources/resources/ewol/data/color.prog similarity index 100% rename from resources/data/color.prog rename to resources/resources/ewol/data/color.prog diff --git a/resources/data/color.vert b/resources/resources/ewol/data/color.vert similarity index 100% rename from resources/data/color.vert rename to resources/resources/ewol/data/color.vert diff --git a/resources/data/color3.frag b/resources/resources/ewol/data/color3.frag similarity index 100% rename from resources/data/color3.frag rename to resources/resources/ewol/data/color3.frag diff --git a/resources/data/color3.prog b/resources/resources/ewol/data/color3.prog similarity index 100% rename from resources/data/color3.prog rename to resources/resources/ewol/data/color3.prog diff --git a/resources/data/color3.vert b/resources/resources/ewol/data/color3.vert similarity index 100% rename from resources/data/color3.vert rename to resources/resources/ewol/data/color3.vert diff --git a/resources/data/ewol-gui-file-chooser.xml b/resources/resources/ewol/data/ewol-gui-file-chooser.xml similarity index 100% rename from resources/data/ewol-gui-file-chooser.xml rename to resources/resources/ewol/data/ewol-gui-file-chooser.xml diff --git a/resources/data/icon.svg b/resources/resources/ewol/data/icon.svg similarity index 100% rename from resources/data/icon.svg rename to resources/resources/ewol/data/icon.svg diff --git a/resources/data/simple3D.frag b/resources/resources/ewol/data/simple3D.frag similarity index 100% rename from resources/data/simple3D.frag rename to resources/resources/ewol/data/simple3D.frag diff --git a/resources/data/simple3D.prog b/resources/resources/ewol/data/simple3D.prog similarity index 100% rename from resources/data/simple3D.prog rename to resources/resources/ewol/data/simple3D.prog diff --git a/resources/data/simple3D.vert b/resources/resources/ewol/data/simple3D.vert similarity index 100% rename from resources/data/simple3D.vert rename to resources/resources/ewol/data/simple3D.vert diff --git a/resources/data/text.frag b/resources/resources/ewol/data/text.frag similarity index 100% rename from resources/data/text.frag rename to resources/resources/ewol/data/text.frag diff --git a/resources/data/text.prog b/resources/resources/ewol/data/text.prog similarity index 100% rename from resources/data/text.prog rename to resources/resources/ewol/data/text.prog diff --git a/resources/data/text.vert b/resources/resources/ewol/data/text.vert similarity index 100% rename from resources/data/text.vert rename to resources/resources/ewol/data/text.vert diff --git a/resources/data/textured.frag b/resources/resources/ewol/data/textured.frag similarity index 100% rename from resources/data/textured.frag rename to resources/resources/ewol/data/textured.frag diff --git a/resources/data/textured.prog b/resources/resources/ewol/data/textured.prog similarity index 100% rename from resources/data/textured.prog rename to resources/resources/ewol/data/textured.prog diff --git a/resources/data/textured.vert b/resources/resources/ewol/data/textured.vert similarity index 100% rename from resources/data/textured.vert rename to resources/resources/ewol/data/textured.vert diff --git a/resources/data/textured3D.frag b/resources/resources/ewol/data/textured3D.frag similarity index 100% rename from resources/data/textured3D.frag rename to resources/resources/ewol/data/textured3D.frag diff --git a/resources/data/textured3D.prog b/resources/resources/ewol/data/textured3D.prog similarity index 100% rename from resources/data/textured3D.prog rename to resources/resources/ewol/data/textured3D.prog diff --git a/resources/data/textured3D.vert b/resources/resources/ewol/data/textured3D.vert similarity index 100% rename from resources/data/textured3D.vert rename to resources/resources/ewol/data/textured3D.vert diff --git a/resources/data/textured3D2.frag b/resources/resources/ewol/data/textured3D2.frag similarity index 100% rename from resources/data/textured3D2.frag rename to resources/resources/ewol/data/textured3D2.frag diff --git a/resources/data/textured3D2.prog b/resources/resources/ewol/data/textured3D2.prog similarity index 100% rename from resources/data/textured3D2.prog rename to resources/resources/ewol/data/textured3D2.prog diff --git a/resources/data/textured3D2.vert b/resources/resources/ewol/data/textured3D2.vert similarity index 100% rename from resources/data/textured3D2.vert rename to resources/resources/ewol/data/textured3D2.vert diff --git a/resources/data/texturedDF.frag b/resources/resources/ewol/data/texturedDF.frag similarity index 100% rename from resources/data/texturedDF.frag rename to resources/resources/ewol/data/texturedDF.frag diff --git a/resources/data/texturedDF.vert b/resources/resources/ewol/data/texturedDF.vert similarity index 100% rename from resources/data/texturedDF.vert rename to resources/resources/ewol/data/texturedDF.vert diff --git a/resources/data/texturedNoMaterial.frag b/resources/resources/ewol/data/texturedNoMaterial.frag similarity index 100% rename from resources/data/texturedNoMaterial.frag rename to resources/resources/ewol/data/texturedNoMaterial.frag diff --git a/resources/data/texturedNoMaterial.prog b/resources/resources/ewol/data/texturedNoMaterial.prog similarity index 100% rename from resources/data/texturedNoMaterial.prog rename to resources/resources/ewol/data/texturedNoMaterial.prog diff --git a/resources/data/texturedNoMaterial.vert b/resources/resources/ewol/data/texturedNoMaterial.vert similarity index 100% rename from resources/data/texturedNoMaterial.vert rename to resources/resources/ewol/data/texturedNoMaterial.vert diff --git a/resources/data/fonts/FreeMono.svg b/resources/resources/ewol/fonts/FreeMono.svg similarity index 100% rename from resources/data/fonts/FreeMono.svg rename to resources/resources/ewol/fonts/FreeMono.svg diff --git a/resources/data/fonts/FreeMonoBold.svg b/resources/resources/ewol/fonts/FreeMonoBold.svg similarity index 100% rename from resources/data/fonts/FreeMonoBold.svg rename to resources/resources/ewol/fonts/FreeMonoBold.svg diff --git a/resources/data/fonts/FreeMonoBoldOblique.svg b/resources/resources/ewol/fonts/FreeMonoBoldOblique.svg similarity index 100% rename from resources/data/fonts/FreeMonoBoldOblique.svg rename to resources/resources/ewol/fonts/FreeMonoBoldOblique.svg diff --git a/resources/data/fonts/FreeMonoOblique.svg b/resources/resources/ewol/fonts/FreeMonoOblique.svg similarity index 100% rename from resources/data/fonts/FreeMonoOblique.svg rename to resources/resources/ewol/fonts/FreeMonoOblique.svg diff --git a/resources/data/fonts/FreeSans.svg b/resources/resources/ewol/fonts/FreeSans.svg similarity index 100% rename from resources/data/fonts/FreeSans.svg rename to resources/resources/ewol/fonts/FreeSans.svg diff --git a/resources/data/fonts/FreeSansBold.svg b/resources/resources/ewol/fonts/FreeSansBold.svg similarity index 100% rename from resources/data/fonts/FreeSansBold.svg rename to resources/resources/ewol/fonts/FreeSansBold.svg diff --git a/resources/data/fonts/FreeSansBoldOblique.svg b/resources/resources/ewol/fonts/FreeSansBoldOblique.svg similarity index 100% rename from resources/data/fonts/FreeSansBoldOblique.svg rename to resources/resources/ewol/fonts/FreeSansBoldOblique.svg diff --git a/resources/data/fonts/FreeSansOblique.svg b/resources/resources/ewol/fonts/FreeSansOblique.svg similarity index 100% rename from resources/data/fonts/FreeSansOblique.svg rename to resources/resources/ewol/fonts/FreeSansOblique.svg diff --git a/resources/data/fonts/FreeSerif.svg b/resources/resources/ewol/fonts/FreeSerif.svg similarity index 100% rename from resources/data/fonts/FreeSerif.svg rename to resources/resources/ewol/fonts/FreeSerif.svg diff --git a/resources/data/theme/color/black/Button.json b/resources/resources/ewol/theme/color/black/Button.json similarity index 100% rename from resources/data/theme/color/black/Button.json rename to resources/resources/ewol/theme/color/black/Button.json diff --git a/resources/data/theme/color/black/CheckBox.json b/resources/resources/ewol/theme/color/black/CheckBox.json similarity index 100% rename from resources/data/theme/color/black/CheckBox.json rename to resources/resources/ewol/theme/color/black/CheckBox.json diff --git a/resources/data/theme/color/black/ContextMenu.json b/resources/resources/ewol/theme/color/black/ContextMenu.json similarity index 100% rename from resources/data/theme/color/black/ContextMenu.json rename to resources/resources/ewol/theme/color/black/ContextMenu.json diff --git a/resources/data/theme/color/black/Entry.json b/resources/resources/ewol/theme/color/black/Entry.json similarity index 100% rename from resources/data/theme/color/black/Entry.json rename to resources/resources/ewol/theme/color/black/Entry.json diff --git a/resources/data/theme/color/black/Image.json b/resources/resources/ewol/theme/color/black/Image.json similarity index 100% rename from resources/data/theme/color/black/Image.json rename to resources/resources/ewol/theme/color/black/Image.json diff --git a/resources/data/theme/color/black/Label.json b/resources/resources/ewol/theme/color/black/Label.json similarity index 100% rename from resources/data/theme/color/black/Label.json rename to resources/resources/ewol/theme/color/black/Label.json diff --git a/resources/data/theme/color/black/ListFileSystem.json b/resources/resources/ewol/theme/color/black/ListFileSystem.json similarity index 100% rename from resources/data/theme/color/black/ListFileSystem.json rename to resources/resources/ewol/theme/color/black/ListFileSystem.json diff --git a/resources/data/theme/color/black/PopUp.json b/resources/resources/ewol/theme/color/black/PopUp.json similarity index 100% rename from resources/data/theme/color/black/PopUp.json rename to resources/resources/ewol/theme/color/black/PopUp.json diff --git a/resources/data/theme/color/black/WidgetScrolled.json b/resources/resources/ewol/theme/color/black/WidgetScrolled.json similarity index 100% rename from resources/data/theme/color/black/WidgetScrolled.json rename to resources/resources/ewol/theme/color/black/WidgetScrolled.json diff --git a/resources/data/theme/color/black/Windows.json b/resources/resources/ewol/theme/color/black/Windows.json similarity index 100% rename from resources/data/theme/color/black/Windows.json rename to resources/resources/ewol/theme/color/black/Windows.json diff --git a/resources/data/theme/color/white/Button.json b/resources/resources/ewol/theme/color/white/Button.json similarity index 100% rename from resources/data/theme/color/white/Button.json rename to resources/resources/ewol/theme/color/white/Button.json diff --git a/resources/data/theme/color/white/CheckBox.json b/resources/resources/ewol/theme/color/white/CheckBox.json similarity index 100% rename from resources/data/theme/color/white/CheckBox.json rename to resources/resources/ewol/theme/color/white/CheckBox.json diff --git a/resources/data/theme/color/white/ContextMenu.json b/resources/resources/ewol/theme/color/white/ContextMenu.json similarity index 100% rename from resources/data/theme/color/white/ContextMenu.json rename to resources/resources/ewol/theme/color/white/ContextMenu.json diff --git a/resources/data/theme/color/white/Entry.json b/resources/resources/ewol/theme/color/white/Entry.json similarity index 100% rename from resources/data/theme/color/white/Entry.json rename to resources/resources/ewol/theme/color/white/Entry.json diff --git a/resources/data/theme/color/white/Image.json b/resources/resources/ewol/theme/color/white/Image.json similarity index 100% rename from resources/data/theme/color/white/Image.json rename to resources/resources/ewol/theme/color/white/Image.json diff --git a/resources/data/theme/color/white/Label.json b/resources/resources/ewol/theme/color/white/Label.json similarity index 100% rename from resources/data/theme/color/white/Label.json rename to resources/resources/ewol/theme/color/white/Label.json diff --git a/resources/data/theme/color/white/ListFileSystem.json b/resources/resources/ewol/theme/color/white/ListFileSystem.json similarity index 100% rename from resources/data/theme/color/white/ListFileSystem.json rename to resources/resources/ewol/theme/color/white/ListFileSystem.json diff --git a/resources/data/theme/color/white/PopUp.json b/resources/resources/ewol/theme/color/white/PopUp.json similarity index 100% rename from resources/data/theme/color/white/PopUp.json rename to resources/resources/ewol/theme/color/white/PopUp.json diff --git a/resources/data/theme/color/white/WidgetScrolled.json b/resources/resources/ewol/theme/color/white/WidgetScrolled.json similarity index 100% rename from resources/data/theme/color/white/WidgetScrolled.json rename to resources/resources/ewol/theme/color/white/WidgetScrolled.json diff --git a/resources/data/theme/color/white/Windows.json b/resources/resources/ewol/theme/color/white/Windows.json similarity index 100% rename from resources/data/theme/color/white/Windows.json rename to resources/resources/ewol/theme/color/white/Windows.json diff --git a/resources/data/theme/default/Add.svg b/resources/resources/ewol/theme/default/Add.svg similarity index 100% rename from resources/data/theme/default/Add.svg rename to resources/resources/ewol/theme/default/Add.svg diff --git a/resources/data/theme/default/AtoZ.svg b/resources/resources/ewol/theme/default/AtoZ.svg similarity index 100% rename from resources/data/theme/default/AtoZ.svg rename to resources/resources/ewol/theme/default/AtoZ.svg diff --git a/resources/data/theme/default/Attache.svg b/resources/resources/ewol/theme/default/Attache.svg similarity index 100% rename from resources/data/theme/default/Attache.svg rename to resources/resources/ewol/theme/default/Attache.svg diff --git a/resources/data/theme/default/CaseSensitive.svg b/resources/resources/ewol/theme/default/CaseSensitive.svg similarity index 100% rename from resources/data/theme/default/CaseSensitive.svg rename to resources/resources/ewol/theme/default/CaseSensitive.svg diff --git a/resources/data/theme/default/ChevronLeft.svg b/resources/resources/ewol/theme/default/ChevronLeft.svg similarity index 100% rename from resources/data/theme/default/ChevronLeft.svg rename to resources/resources/ewol/theme/default/ChevronLeft.svg diff --git a/resources/data/theme/default/ChevronLess.svg b/resources/resources/ewol/theme/default/ChevronLess.svg similarity index 100% rename from resources/data/theme/default/ChevronLess.svg rename to resources/resources/ewol/theme/default/ChevronLess.svg diff --git a/resources/data/theme/default/ChevronMore.svg b/resources/resources/ewol/theme/default/ChevronMore.svg similarity index 100% rename from resources/data/theme/default/ChevronMore.svg rename to resources/resources/ewol/theme/default/ChevronMore.svg diff --git a/resources/data/theme/default/ChevronRight.svg b/resources/resources/ewol/theme/default/ChevronRight.svg similarity index 100% rename from resources/data/theme/default/ChevronRight.svg rename to resources/resources/ewol/theme/default/ChevronRight.svg diff --git a/resources/data/theme/default/Close.svg b/resources/resources/ewol/theme/default/Close.svg similarity index 100% rename from resources/data/theme/default/Close.svg rename to resources/resources/ewol/theme/default/Close.svg diff --git a/resources/data/theme/default/Contact.svg b/resources/resources/ewol/theme/default/Contact.svg similarity index 100% rename from resources/data/theme/default/Contact.svg rename to resources/resources/ewol/theme/default/Contact.svg diff --git a/resources/data/theme/default/Down.svg b/resources/resources/ewol/theme/default/Down.svg similarity index 100% rename from resources/data/theme/default/Down.svg rename to resources/resources/ewol/theme/default/Down.svg diff --git a/resources/data/theme/default/FavoriteDisable.svg b/resources/resources/ewol/theme/default/FavoriteDisable.svg similarity index 100% rename from resources/data/theme/default/FavoriteDisable.svg rename to resources/resources/ewol/theme/default/FavoriteDisable.svg diff --git a/resources/data/theme/default/FavoriteEnable.svg b/resources/resources/ewol/theme/default/FavoriteEnable.svg similarity index 100% rename from resources/data/theme/default/FavoriteEnable.svg rename to resources/resources/ewol/theme/default/FavoriteEnable.svg diff --git a/resources/data/theme/default/FavoriteMiddle.svg b/resources/resources/ewol/theme/default/FavoriteMiddle.svg similarity index 100% rename from resources/data/theme/default/FavoriteMiddle.svg rename to resources/resources/ewol/theme/default/FavoriteMiddle.svg diff --git a/resources/data/theme/default/File.svg b/resources/resources/ewol/theme/default/File.svg similarity index 100% rename from resources/data/theme/default/File.svg rename to resources/resources/ewol/theme/default/File.svg diff --git a/resources/data/theme/default/Folder.svg b/resources/resources/ewol/theme/default/Folder.svg similarity index 100% rename from resources/data/theme/default/Folder.svg rename to resources/resources/ewol/theme/default/Folder.svg diff --git a/resources/data/theme/default/Forbidden.svg b/resources/resources/ewol/theme/default/Forbidden.svg similarity index 100% rename from resources/data/theme/default/Forbidden.svg rename to resources/resources/ewol/theme/default/Forbidden.svg diff --git a/resources/data/theme/default/Help.svg b/resources/resources/ewol/theme/default/Help.svg similarity index 100% rename from resources/data/theme/default/Help.svg rename to resources/resources/ewol/theme/default/Help.svg diff --git a/resources/data/theme/default/Home.svg b/resources/resources/ewol/theme/default/Home.svg similarity index 100% rename from resources/data/theme/default/Home.svg rename to resources/resources/ewol/theme/default/Home.svg diff --git a/resources/data/theme/default/Info.svg b/resources/resources/ewol/theme/default/Info.svg similarity index 100% rename from resources/data/theme/default/Info.svg rename to resources/resources/ewol/theme/default/Info.svg diff --git a/resources/data/theme/default/List.svg b/resources/resources/ewol/theme/default/List.svg similarity index 100% rename from resources/data/theme/default/List.svg rename to resources/resources/ewol/theme/default/List.svg diff --git a/resources/data/theme/default/Load.svg b/resources/resources/ewol/theme/default/Load.svg similarity index 100% rename from resources/data/theme/default/Load.svg rename to resources/resources/ewol/theme/default/Load.svg diff --git a/resources/data/theme/default/Lock.svg b/resources/resources/ewol/theme/default/Lock.svg similarity index 100% rename from resources/data/theme/default/Lock.svg rename to resources/resources/ewol/theme/default/Lock.svg diff --git a/resources/data/theme/default/Next.svg b/resources/resources/ewol/theme/default/Next.svg similarity index 100% rename from resources/data/theme/default/Next.svg rename to resources/resources/ewol/theme/default/Next.svg diff --git a/resources/data/theme/default/OpenMenu.svg b/resources/resources/ewol/theme/default/OpenMenu.svg similarity index 100% rename from resources/data/theme/default/OpenMenu.svg rename to resources/resources/ewol/theme/default/OpenMenu.svg diff --git a/resources/data/theme/default/Parameter.svg b/resources/resources/ewol/theme/default/Parameter.svg similarity index 100% rename from resources/data/theme/default/Parameter.svg rename to resources/resources/ewol/theme/default/Parameter.svg diff --git a/resources/data/theme/default/Previous.svg b/resources/resources/ewol/theme/default/Previous.svg similarity index 100% rename from resources/data/theme/default/Previous.svg rename to resources/resources/ewol/theme/default/Previous.svg diff --git a/resources/data/theme/default/Quit.svg b/resources/resources/ewol/theme/default/Quit.svg similarity index 100% rename from resources/data/theme/default/Quit.svg rename to resources/resources/ewol/theme/default/Quit.svg diff --git a/resources/data/theme/default/Redo.svg b/resources/resources/ewol/theme/default/Redo.svg similarity index 100% rename from resources/data/theme/default/Redo.svg rename to resources/resources/ewol/theme/default/Redo.svg diff --git a/resources/data/theme/default/Remove.svg b/resources/resources/ewol/theme/default/Remove.svg similarity index 100% rename from resources/data/theme/default/Remove.svg rename to resources/resources/ewol/theme/default/Remove.svg diff --git a/resources/data/theme/default/Remove2.svg b/resources/resources/ewol/theme/default/Remove2.svg similarity index 100% rename from resources/data/theme/default/Remove2.svg rename to resources/resources/ewol/theme/default/Remove2.svg diff --git a/resources/data/theme/default/Replace.svg b/resources/resources/ewol/theme/default/Replace.svg similarity index 100% rename from resources/data/theme/default/Replace.svg rename to resources/resources/ewol/theme/default/Replace.svg diff --git a/resources/data/theme/default/SDCard.svg b/resources/resources/ewol/theme/default/SDCard.svg similarity index 100% rename from resources/data/theme/default/SDCard.svg rename to resources/resources/ewol/theme/default/SDCard.svg diff --git a/resources/data/theme/default/Save.svg b/resources/resources/ewol/theme/default/Save.svg similarity index 100% rename from resources/data/theme/default/Save.svg rename to resources/resources/ewol/theme/default/Save.svg diff --git a/resources/data/theme/default/Search.svg b/resources/resources/ewol/theme/default/Search.svg similarity index 100% rename from resources/data/theme/default/Search.svg rename to resources/resources/ewol/theme/default/Search.svg diff --git a/resources/data/theme/default/Trash.svg b/resources/resources/ewol/theme/default/Trash.svg similarity index 100% rename from resources/data/theme/default/Trash.svg rename to resources/resources/ewol/theme/default/Trash.svg diff --git a/resources/data/theme/default/Undo.svg b/resources/resources/ewol/theme/default/Undo.svg similarity index 100% rename from resources/data/theme/default/Undo.svg rename to resources/resources/ewol/theme/default/Undo.svg diff --git a/resources/data/theme/default/Up.svg b/resources/resources/ewol/theme/default/Up.svg similarity index 100% rename from resources/data/theme/default/Up.svg rename to resources/resources/ewol/theme/default/Up.svg diff --git a/resources/data/theme/default/Update.svg b/resources/resources/ewol/theme/default/Update.svg similarity index 100% rename from resources/data/theme/default/Update.svg rename to resources/resources/ewol/theme/default/Update.svg diff --git a/resources/data/theme/default/Validate.svg b/resources/resources/ewol/theme/default/Validate.svg similarity index 100% rename from resources/data/theme/default/Validate.svg rename to resources/resources/ewol/theme/default/Validate.svg diff --git a/resources/data/theme/default/VolumeMax.svg b/resources/resources/ewol/theme/default/VolumeMax.svg similarity index 100% rename from resources/data/theme/default/VolumeMax.svg rename to resources/resources/ewol/theme/default/VolumeMax.svg diff --git a/resources/data/theme/default/VolumeMute.svg b/resources/resources/ewol/theme/default/VolumeMute.svg similarity index 100% rename from resources/data/theme/default/VolumeMute.svg rename to resources/resources/ewol/theme/default/VolumeMute.svg diff --git a/resources/data/theme/default/Warning.svg b/resources/resources/ewol/theme/default/Warning.svg similarity index 100% rename from resources/data/theme/default/Warning.svg rename to resources/resources/ewol/theme/default/Warning.svg diff --git a/resources/data/theme/default/WhereAmI.svg b/resources/resources/ewol/theme/default/WhereAmI.svg similarity index 100% rename from resources/data/theme/default/WhereAmI.svg rename to resources/resources/ewol/theme/default/WhereAmI.svg diff --git a/resources/data/theme/default/WrapAround.svg b/resources/resources/ewol/theme/default/WrapAround.svg similarity index 100% rename from resources/data/theme/default/WrapAround.svg rename to resources/resources/ewol/theme/default/WrapAround.svg diff --git a/resources/data/theme/default/ZoomIn.svg b/resources/resources/ewol/theme/default/ZoomIn.svg similarity index 100% rename from resources/data/theme/default/ZoomIn.svg rename to resources/resources/ewol/theme/default/ZoomIn.svg diff --git a/resources/data/theme/shape/round/Button.frag b/resources/resources/ewol/theme/shape/round/Button.frag similarity index 100% rename from resources/data/theme/shape/round/Button.frag rename to resources/resources/ewol/theme/shape/round/Button.frag diff --git a/resources/data/theme/shape/round/Button.json b/resources/resources/ewol/theme/shape/round/Button.json similarity index 100% rename from resources/data/theme/shape/round/Button.json rename to resources/resources/ewol/theme/shape/round/Button.json diff --git a/resources/data/theme/shape/round/Button.vert b/resources/resources/ewol/theme/shape/round/Button.vert similarity index 100% rename from resources/data/theme/shape/round/Button.vert rename to resources/resources/ewol/theme/shape/round/Button.vert diff --git a/resources/data/theme/shape/round/CheckBox.frag b/resources/resources/ewol/theme/shape/round/CheckBox.frag similarity index 100% rename from resources/data/theme/shape/round/CheckBox.frag rename to resources/resources/ewol/theme/shape/round/CheckBox.frag diff --git a/resources/data/theme/shape/round/CheckBox.json b/resources/resources/ewol/theme/shape/round/CheckBox.json similarity index 100% rename from resources/data/theme/shape/round/CheckBox.json rename to resources/resources/ewol/theme/shape/round/CheckBox.json diff --git a/resources/data/theme/shape/round/CheckBox.vert b/resources/resources/ewol/theme/shape/round/CheckBox.vert similarity index 100% rename from resources/data/theme/shape/round/CheckBox.vert rename to resources/resources/ewol/theme/shape/round/CheckBox.vert diff --git a/resources/data/theme/shape/round/ContextMenu.frag b/resources/resources/ewol/theme/shape/round/ContextMenu.frag similarity index 100% rename from resources/data/theme/shape/round/ContextMenu.frag rename to resources/resources/ewol/theme/shape/round/ContextMenu.frag diff --git a/resources/data/theme/shape/round/ContextMenu.json b/resources/resources/ewol/theme/shape/round/ContextMenu.json similarity index 100% rename from resources/data/theme/shape/round/ContextMenu.json rename to resources/resources/ewol/theme/shape/round/ContextMenu.json diff --git a/resources/data/theme/shape/round/ContextMenu.vert b/resources/resources/ewol/theme/shape/round/ContextMenu.vert similarity index 100% rename from resources/data/theme/shape/round/ContextMenu.vert rename to resources/resources/ewol/theme/shape/round/ContextMenu.vert diff --git a/resources/data/theme/shape/round/Entry.frag b/resources/resources/ewol/theme/shape/round/Entry.frag similarity index 100% rename from resources/data/theme/shape/round/Entry.frag rename to resources/resources/ewol/theme/shape/round/Entry.frag diff --git a/resources/data/theme/shape/round/Entry.json b/resources/resources/ewol/theme/shape/round/Entry.json similarity index 100% rename from resources/data/theme/shape/round/Entry.json rename to resources/resources/ewol/theme/shape/round/Entry.json diff --git a/resources/data/theme/shape/round/Entry.vert b/resources/resources/ewol/theme/shape/round/Entry.vert similarity index 100% rename from resources/data/theme/shape/round/Entry.vert rename to resources/resources/ewol/theme/shape/round/Entry.vert diff --git a/resources/data/theme/shape/round/PopUp.frag b/resources/resources/ewol/theme/shape/round/PopUp.frag similarity index 100% rename from resources/data/theme/shape/round/PopUp.frag rename to resources/resources/ewol/theme/shape/round/PopUp.frag diff --git a/resources/data/theme/shape/round/PopUp.json b/resources/resources/ewol/theme/shape/round/PopUp.json similarity index 100% rename from resources/data/theme/shape/round/PopUp.json rename to resources/resources/ewol/theme/shape/round/PopUp.json diff --git a/resources/data/theme/shape/round/PopUp.vert b/resources/resources/ewol/theme/shape/round/PopUp.vert similarity index 100% rename from resources/data/theme/shape/round/PopUp.vert rename to resources/resources/ewol/theme/shape/round/PopUp.vert diff --git a/resources/data/theme/shape/round/WidgetScrolled.frag b/resources/resources/ewol/theme/shape/round/WidgetScrolled.frag similarity index 100% rename from resources/data/theme/shape/round/WidgetScrolled.frag rename to resources/resources/ewol/theme/shape/round/WidgetScrolled.frag diff --git a/resources/data/theme/shape/round/WidgetScrolled.json b/resources/resources/ewol/theme/shape/round/WidgetScrolled.json similarity index 100% rename from resources/data/theme/shape/round/WidgetScrolled.json rename to resources/resources/ewol/theme/shape/round/WidgetScrolled.json diff --git a/resources/data/theme/shape/round/WidgetScrolled.vert b/resources/resources/ewol/theme/shape/round/WidgetScrolled.vert similarity index 100% rename from resources/data/theme/shape/round/WidgetScrolled.vert rename to resources/resources/ewol/theme/shape/round/WidgetScrolled.vert diff --git a/resources/data/theme/shape/square/Button.frag b/resources/resources/ewol/theme/shape/square/Button.frag similarity index 100% rename from resources/data/theme/shape/square/Button.frag rename to resources/resources/ewol/theme/shape/square/Button.frag diff --git a/resources/data/theme/shape/square/Button.json b/resources/resources/ewol/theme/shape/square/Button.json similarity index 100% rename from resources/data/theme/shape/square/Button.json rename to resources/resources/ewol/theme/shape/square/Button.json diff --git a/resources/data/theme/shape/square/Button.vert b/resources/resources/ewol/theme/shape/square/Button.vert similarity index 100% rename from resources/data/theme/shape/square/Button.vert rename to resources/resources/ewol/theme/shape/square/Button.vert diff --git a/resources/data/theme/shape/square/CheckBox.frag b/resources/resources/ewol/theme/shape/square/CheckBox.frag similarity index 100% rename from resources/data/theme/shape/square/CheckBox.frag rename to resources/resources/ewol/theme/shape/square/CheckBox.frag diff --git a/resources/data/theme/shape/square/CheckBox.json b/resources/resources/ewol/theme/shape/square/CheckBox.json similarity index 100% rename from resources/data/theme/shape/square/CheckBox.json rename to resources/resources/ewol/theme/shape/square/CheckBox.json diff --git a/resources/data/theme/shape/square/CheckBox.vert b/resources/resources/ewol/theme/shape/square/CheckBox.vert similarity index 100% rename from resources/data/theme/shape/square/CheckBox.vert rename to resources/resources/ewol/theme/shape/square/CheckBox.vert diff --git a/resources/data/theme/shape/square/ContextMenu.frag b/resources/resources/ewol/theme/shape/square/ContextMenu.frag similarity index 100% rename from resources/data/theme/shape/square/ContextMenu.frag rename to resources/resources/ewol/theme/shape/square/ContextMenu.frag diff --git a/resources/data/theme/shape/square/ContextMenu.json b/resources/resources/ewol/theme/shape/square/ContextMenu.json similarity index 100% rename from resources/data/theme/shape/square/ContextMenu.json rename to resources/resources/ewol/theme/shape/square/ContextMenu.json diff --git a/resources/data/theme/shape/square/ContextMenu.vert b/resources/resources/ewol/theme/shape/square/ContextMenu.vert similarity index 100% rename from resources/data/theme/shape/square/ContextMenu.vert rename to resources/resources/ewol/theme/shape/square/ContextMenu.vert diff --git a/resources/data/theme/shape/square/Entry.frag b/resources/resources/ewol/theme/shape/square/Entry.frag similarity index 100% rename from resources/data/theme/shape/square/Entry.frag rename to resources/resources/ewol/theme/shape/square/Entry.frag diff --git a/resources/data/theme/shape/square/Entry.json b/resources/resources/ewol/theme/shape/square/Entry.json similarity index 100% rename from resources/data/theme/shape/square/Entry.json rename to resources/resources/ewol/theme/shape/square/Entry.json diff --git a/resources/data/theme/shape/square/Entry.vert b/resources/resources/ewol/theme/shape/square/Entry.vert similarity index 100% rename from resources/data/theme/shape/square/Entry.vert rename to resources/resources/ewol/theme/shape/square/Entry.vert diff --git a/resources/data/theme/shape/square/PopUp.frag b/resources/resources/ewol/theme/shape/square/PopUp.frag similarity index 100% rename from resources/data/theme/shape/square/PopUp.frag rename to resources/resources/ewol/theme/shape/square/PopUp.frag diff --git a/resources/data/theme/shape/square/PopUp.json b/resources/resources/ewol/theme/shape/square/PopUp.json similarity index 100% rename from resources/data/theme/shape/square/PopUp.json rename to resources/resources/ewol/theme/shape/square/PopUp.json diff --git a/resources/data/theme/shape/square/PopUp.vert b/resources/resources/ewol/theme/shape/square/PopUp.vert similarity index 100% rename from resources/data/theme/shape/square/PopUp.vert rename to resources/resources/ewol/theme/shape/square/PopUp.vert diff --git a/resources/data/theme/shape/square/Select.json b/resources/resources/ewol/theme/shape/square/Select.json similarity index 100% rename from resources/data/theme/shape/square/Select.json rename to resources/resources/ewol/theme/shape/square/Select.json diff --git a/resources/data/theme/shape/square/SelectBt.json b/resources/resources/ewol/theme/shape/square/SelectBt.json similarity index 100% rename from resources/data/theme/shape/square/SelectBt.json rename to resources/resources/ewol/theme/shape/square/SelectBt.json diff --git a/resources/data/theme/shape/square/SelectEntry.json b/resources/resources/ewol/theme/shape/square/SelectEntry.json similarity index 100% rename from resources/data/theme/shape/square/SelectEntry.json rename to resources/resources/ewol/theme/shape/square/SelectEntry.json diff --git a/resources/data/theme/shape/square/Spin.json b/resources/resources/ewol/theme/shape/square/Spin.json similarity index 100% rename from resources/data/theme/shape/square/Spin.json rename to resources/resources/ewol/theme/shape/square/Spin.json diff --git a/resources/data/theme/shape/square/SpinDown.json b/resources/resources/ewol/theme/shape/square/SpinDown.json similarity index 100% rename from resources/data/theme/shape/square/SpinDown.json rename to resources/resources/ewol/theme/shape/square/SpinDown.json diff --git a/resources/data/theme/shape/square/SpinEntry.json b/resources/resources/ewol/theme/shape/square/SpinEntry.json similarity index 100% rename from resources/data/theme/shape/square/SpinEntry.json rename to resources/resources/ewol/theme/shape/square/SpinEntry.json diff --git a/resources/data/theme/shape/square/SpinUp.json b/resources/resources/ewol/theme/shape/square/SpinUp.json similarity index 100% rename from resources/data/theme/shape/square/SpinUp.json rename to resources/resources/ewol/theme/shape/square/SpinUp.json diff --git a/resources/data/theme/shape/square/WidgetScrolled.frag b/resources/resources/ewol/theme/shape/square/WidgetScrolled.frag similarity index 100% rename from resources/data/theme/shape/square/WidgetScrolled.frag rename to resources/resources/ewol/theme/shape/square/WidgetScrolled.frag diff --git a/resources/data/theme/shape/square/WidgetScrolled.json b/resources/resources/ewol/theme/shape/square/WidgetScrolled.json similarity index 100% rename from resources/data/theme/shape/square/WidgetScrolled.json rename to resources/resources/ewol/theme/shape/square/WidgetScrolled.json diff --git a/resources/data/theme/shape/square/WidgetScrolled.vert b/resources/resources/ewol/theme/shape/square/WidgetScrolled.vert similarity index 100% rename from resources/data/theme/shape/square/WidgetScrolled.vert rename to resources/resources/ewol/theme/shape/square/WidgetScrolled.vert diff --git a/resources/data/translate/EN.json b/resources/resources/ewol/translate/EN.json similarity index 100% rename from resources/data/translate/EN.json rename to resources/resources/ewol/translate/EN.json diff --git a/resources/data/translate/FR.json b/resources/resources/ewol/translate/FR.json similarity index 100% rename from resources/data/translate/FR.json rename to resources/resources/ewol/translate/FR.json diff --git a/src/org/atriasoft/echrono/Clock.java b/src/org/atriasoft/echrono/Clock.java index 5c7a5a1..5d2490b 100644 --- a/src/org/atriasoft/echrono/Clock.java +++ b/src/org/atriasoft/echrono/Clock.java @@ -14,20 +14,20 @@ public class Clock { this.data = 0; } - public Clock(final double _val) { //value in second - this.data = (long) (_val * 1000000000.0); + public Clock(final double val) { //value in second + this.data = (long) (val * 1000000000.0); } - public Clock(final int _val) { //value in nanosecond - this.data = _val; + public Clock(final int val) { //value in nanosecond + this.data = val; } - public Clock(final long _val) { //value in nanosecond - this.data = _val; + public Clock(final long val) { //value in nanosecond + this.data = val; } - public Clock(final long _valSec, final long _valNano) { //value in second and nanosecond - this.data = _valSec * 1000000000L + _valNano; + public Clock(final long valSec, final long valNano) { //value in second and nanosecond + this.data = valSec * 1000000000L + valNano; } public long get() { diff --git a/src/org/atriasoft/echrono/Duration.java b/src/org/atriasoft/echrono/Duration.java index f3d3cab..cf0a144 100644 --- a/src/org/atriasoft/echrono/Duration.java +++ b/src/org/atriasoft/echrono/Duration.java @@ -11,20 +11,20 @@ public class Duration { this.data = 0; } - public Duration(final double _val) { //value in second - this.data = (long) (_val * 1000000000.0); + public Duration(final double val) { //value in second + this.data = (long) (val * 1000000000.0); } - public Duration(final int _val) { //value in nanosecond - this.data = _val; + public Duration(final int val) { //value in nanosecond + this.data = val; } - public Duration(final long _val) { //value in nanosecond - this.data = _val; + public Duration(final long val) { //value in nanosecond + this.data = val; } - public Duration(final long _valSec, final long _valNano) { //value in second and nanosecond - this.data = _valSec * 1000000000L + _valNano; + public Duration(final long valSec, final long valNano) { //value in second and nanosecond + this.data = valSec * 1000000000L + valNano; } public long get() { diff --git a/src/org/atriasoft/echrono/Steady.java b/src/org/atriasoft/echrono/Steady.java index 022087d..863946f 100644 --- a/src/org/atriasoft/echrono/Steady.java +++ b/src/org/atriasoft/echrono/Steady.java @@ -14,20 +14,20 @@ public class Steady { this.data = 0; } - public Steady(final double _val) { //value in second - this.data = (long) (_val * 1000000000.0); + public Steady(final double val) { //value in second + this.data = (long) (val * 1000000000.0); } - public Steady(final int _val) { //value in nanosecond - this.data = _val; + public Steady(final int val) { //value in nanosecond + this.data = val; } - public Steady(final long _val) { //value in nanosecond - this.data = _val; + public Steady(final long val) { //value in nanosecond + this.data = val; } - public Steady(final long _valSec, final long _valNano) { //value in second and nanosecond - this.data = _valSec * 1000000000L + _valNano; + public Steady(final long valSec, final long valNano) { //value in second and nanosecond + this.data = valSec * 1000000000L + valNano; } public long get() { diff --git a/src/org/atriasoft/echrono/Time.java b/src/org/atriasoft/echrono/Time.java index 6e3671a..ab623db 100644 --- a/src/org/atriasoft/echrono/Time.java +++ b/src/org/atriasoft/echrono/Time.java @@ -14,20 +14,20 @@ public class Time { this.data = 0; } - public Time(final double _val) { //value in second - this.data = (long) (_val * 1000000000.0); + public Time(final double val) { //value in second + this.data = (long) (val * 1000000000.0); } - public Time(final int _val) { //value in nanosecond - this.data = _val; + public Time(final int val) { //value in nanosecond + this.data = val; } - public Time(final long _val) { //value in nanosecond - this.data = _val; + public Time(final long val) { //value in nanosecond + this.data = val; } - public Time(final long _valSec, final long _valNano) { //value in second and nanosecond - this.data = _valSec * 1000000000L + _valNano; + public Time(final long valSec, final long valNano) { //value in second and nanosecond + this.data = valSec * 1000000000L + valNano; } public long get() { diff --git a/src/org/atriasoft/egami/Egami.java b/src/org/atriasoft/egami/Egami.java new file mode 100644 index 0000000..4cbb34b --- /dev/null +++ b/src/org/atriasoft/egami/Egami.java @@ -0,0 +1,13 @@ +package org.atriasoft.egami; + +import org.atriasoft.etk.Uri; +import org.atriasoft.etk.math.Vector2i; +import org.atriasoft.ewol.internal.Log; + +public class Egami { + private Egami() {} + public static Image load(Uri uri, Vector2i size) { + Log.todo("Load image : " + uri + " size=" + size); + return null; + } +} diff --git a/src/org/atriasoft/egami/Image.java b/src/org/atriasoft/egami/Image.java index 661a5ee..a04f0d9 100644 --- a/src/org/atriasoft/egami/Image.java +++ b/src/org/atriasoft/egami/Image.java @@ -63,7 +63,7 @@ public class Image { return this.buffer[(y * this.width + x) * 4]; } - public byte[] GetRaw() { + public byte[] getRaw() { // TODO Auto-generated method stub return this.buffer; } diff --git a/src/org/atriasoft/esignal/Signal.java b/src/org/atriasoft/esignal/Signal.java index 2a85c7b..853ea1e 100644 --- a/src/org/atriasoft/esignal/Signal.java +++ b/src/org/atriasoft/esignal/Signal.java @@ -6,11 +6,11 @@ import java.util.Iterator; import java.util.List; import java.util.function.Consumer; -class connectedElement { +class ConnectedElement { private final WeakReference reference; private final Consumer consumer; - public connectedElement(final WeakReference reference, final Consumer consumer) { + public ConnectedElement(final WeakReference reference, final Consumer consumer) { this.reference = reference; this.consumer = consumer; } @@ -27,7 +27,7 @@ class connectedElement { public class Signal { - List> data = new ArrayList<>(); + List> data = new ArrayList<>(); public void clear(final Object obj) { @@ -47,9 +47,9 @@ public class Signal { } public void emit(final T value) { - final Iterator> iterator = this.data.iterator(); + final Iterator> iterator = this.data.iterator(); while (iterator.hasNext()) { - final connectedElement elem = iterator.next(); + final ConnectedElement elem = iterator.next(); if (elem.getReference().get() == null) { iterator.remove(); } diff --git a/src/org/atriasoft/esignal/SignalEmpty.java b/src/org/atriasoft/esignal/SignalEmpty.java new file mode 100644 index 0000000..6a86dc3 --- /dev/null +++ b/src/org/atriasoft/esignal/SignalEmpty.java @@ -0,0 +1,62 @@ +package org.atriasoft.esignal; + +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +class ConnectedElementEmpty { + private final WeakReference reference; + private final Runnable runnable; + + public ConnectedElementEmpty(final WeakReference reference, final Runnable runnable) { + this.reference = reference; + this.runnable = runnable; + } + + public WeakReference getReference() { + return this.reference; + } + + public Runnable getRunner() { + return this.runnable; + } + +} + +public class SignalEmpty { + + List data = new ArrayList<>(); + + public void clear(final Object obj) { + + } + + public Connection connect(final Object reference, final Runnable runnable) { + + return null; + } + + public void disconnect(final Connection connection) { + + } + + public void disconnect(final Object obj) { + + } + + public void emit() { + final Iterator iterator = this.data.iterator(); + while (iterator.hasNext()) { + final ConnectedElementEmpty elem = iterator.next(); + if (elem.getReference().get() == null) { + iterator.remove(); + } + elem.getRunner().run(); + } + } + + public int size() { + return this.data.size(); + } +} diff --git a/src/org/atriasoft/etranslate/ETranslate.java b/src/org/atriasoft/etranslate/ETranslate.java index 6cb071b..4e26b87 100644 --- a/src/org/atriasoft/etranslate/ETranslate.java +++ b/src/org/atriasoft/etranslate/ETranslate.java @@ -21,263 +21,263 @@ import org.atriasoft.ewol.internal.Log; * 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; - + private static boolean globalIsInit = false; + private static String globalLanguage = ""; + private static String globalLanguageDefault = "EN"; + private static Map globalListPath = new HashMap<>(); + private static String globalMajor = "etranslate"; + private static Map globalTranslate = new HashMap<>(); + private static boolean globalTranslateLoadad = false; + /** * Initialize etranslate - * @param _argc Number of argument list - * @param _argv List of arguments + * @param argc Number of argument list + * @param argv List of arguments */ static { - + } - + /** * Set the path folder of the translation files - * @param _lib Library name that the path depend - * @param _uri ETK generic uri (DATA:... or /xxx) - * @param _major This path is the major path (The last loaded, the one which + * @param lib Library name that the path depend + * @param uri ETK generic uri (DATA:... or /xxx) + * @param 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) { + ETranslate.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 + "'"); + + public static void addPath(final String lib, final Uri uri, final boolean major) { + ETranslate.globalListPath.put(lib, uri); + if (major) { + ETranslate.globalMajor = lib; + Log.info("Change major translation : '" + ETranslate.globalMajor + "'"); } - m_translateLoadad = false; - m_translate.clear(); + ETranslate.globalTranslateLoadad = false; + ETranslate.globalTranslate.clear(); } - + /** * Automatic detection of the system language */ public static void autoDetectLanguage() { - if (g_isInit == false) { + if (!ETranslate.globalIsInit) { 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"; + final String nonameLocalName = "EN"; + final String userLocalName = "EN"; + final 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) { + * 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 == "") { + if (lang.equals("*") || lang.isEmpty()) { lang = userLocalName; } - if (lang == "*" || lang == "") { + if (lang.equals("*") || lang.isEmpty()) { lang = globalLocalName; } - if (lang == "C" || lang == "" || lang.length() < 2) { + if (lang.equals("C") || lang.isEmpty() || lang.length() < 2) { lang = "EN"; } lang = lang.substring(0, 2); lang = lang.toUpperCase(); Log.info("Select Language : '" + lang + "'"); - setLanguage(lang); + ETranslate.setLanguage(lang); } - + /** * Translate a specific text (if not find, it will be retured the same * text). - * @param _instance Text to translate. + * @param 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(); + public static String get(final String instance) { + ETranslate.loadTranslation(); + Log.verbose("Request translate: '" + instance + "'"); + // find all iterance of 'T{' ... '}' + final String out = Pattern.compile("T\\{.*\\}").matcher(instance).replaceAll(mr -> { + final String data = mr.group(); Log.info("translate : '" + data + "'"); - String itTranslate = m_translate.get(data); + final String itTranslate = ETranslate.globalTranslate.get(data); if (itTranslate == null) { - Log.debug("Can not find tranlation : '" + _instance + "'"); + Log.debug("Can not find tranlation : '" + instance + "'"); return data; } return itTranslate; }); return out; } - + /** * Get the current language loaded * @return The 2/3 char defining the language */ public static String getLanguage() { - return m_language; + return ETranslate.globalLanguage; } - + /** * Get the current language selected * @return The 2/3 char defining the language */ public static String getLanguageDefault() { - return m_languageDefault; + return ETranslate.globalLanguageDefault; } - + /** * Get the current paths of the library - * @param _lib Library name that the path depend + * @param lib Library name that the path depend * @return Uri value. */ - public static Uri getPaths(final String _lib) { - return m_listPath.get(_lib); + public static Uri getPaths(final String lib) { + return ETranslate.globalListPath.get(lib); } - + private static void loadTranslation() { - if (m_translateLoadad == true) { + if (ETranslate.globalTranslateLoadad) { return; } - Log.debug("Load Translation MAJOR='" + m_major + "' LANG='" + m_language + "' default=" + m_languageDefault); - Log.debug("list path=" + m_listPath.keySet()); + Log.debug("Load Translation MAJOR='" + ETranslate.globalMajor + "' LANG='" + ETranslate.globalLanguage + "' default=" + ETranslate.globalLanguageDefault); + Log.debug("list path=" + ETranslate.globalListPath.keySet()); // start parse language for Major: - Uri itMajor = m_listPath.get(m_major); + final Uri itMajor = ETranslate.globalListPath.get(ETranslate.globalMajor); if (itMajor != null) { - Uri uri = itMajor.withPath(itMajor.getPath() + "/" + m_language + ".json"); + Uri uri = itMajor.withPath(itMajor.getPath() + "/" + ETranslate.globalLanguage + ".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); + final JsonObject root = (JsonObject) Ejson.parse(uri); + for (final Map.Entry element : root.getNodes().entrySet()) { + final String val = element.getValue().toJsonString().getValue(); + ETranslate.globalTranslate.put(element.getKey(), val); } - } catch (Exception e) { + } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - uri = itMajor.withPath(itMajor.getPath() + "/" + m_languageDefault + ".json"); + uri = itMajor.withPath(itMajor.getPath() + "/" + ETranslate.globalLanguageDefault + ".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); + final JsonObject root = (JsonObject) Ejson.parse(uri); + for (final Map.Entry element : root.getNodes().entrySet()) { + final String val = element.getValue().toJsonString().getValue(); + ETranslate.globalTranslate.put(element.getKey(), val); } - } catch (Exception e) { + } catch (final 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)) { + for (final Map.Entry it : ETranslate.globalListPath.entrySet()) { + if (it.getKey().contentEquals(ETranslate.globalMajor)) { continue; } - Uri uri = it.getValue().withPath(it.getValue().getPath() + "/" + m_language + ".json"); + final Uri uri = it.getValue().withPath(it.getValue().getPath() + "/" + ETranslate.globalLanguage + ".json"); /* * TODO ... if (Uri.exist(uri) == false) { continue; } */ JsonObject doc; try { doc = (JsonObject) Ejson.parse(uri); - } catch (Exception e) { + } catch (final 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); + for (final Map.Entry element : doc.getNodes().entrySet()) { + final String val = element.getValue().toJsonString().getValue(); + ETranslate.globalTranslate.put(element.getKey(), val); } } // start parse default language: - for (Map.Entry it : m_listPath.entrySet()) { - if (it.getKey().contentEquals(m_major)) { + for (final Map.Entry it : ETranslate.globalListPath.entrySet()) { + if (it.getKey().contentEquals(ETranslate.globalMajor)) { continue; } - Uri uri = it.getValue().withPath(it.getValue().getPath() + "/" + m_languageDefault + ".json"); + final Uri uri = it.getValue().withPath(it.getValue().getPath() + "/" + ETranslate.globalLanguageDefault + ".json"); /* * TODO ... if (Uri.exist(uri) == false) { continue; } */ JsonObject doc; try { doc = (JsonObject) Ejson.parse(uri); - } catch (Exception e) { + } catch (final 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); + for (final Map.Entry element : doc.getNodes().entrySet()) { + final String val = element.getValue().toJsonString().getValue(); + ETranslate.globalTranslate.put(element.getKey(), val); } } - m_translateLoadad = true; + ETranslate.globalTranslateLoadad = true; } - + /** * Set the language to load data. when no data availlable, we get the * default language. - * @param _lang Language to load : ("EN" for english, "FR" for french, "DE" + * @param 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) { + public static void setLanguage(final String lang) { + if (ETranslate.globalLanguage.equals(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"); + ETranslate.globalLanguage = lang; + ETranslate.globalTranslateLoadad = false; + ETranslate.globalTranslate.clear(); + if (lang.equals("EN")) { + Log.info("Change language translation: '" + lang + "'=English"); + } else if (lang.equals("FR")) { + Log.info("Change language translation: '" + lang + "'=French"); + } else if (lang.equals("DE")) { + Log.info("Change language translation: '" + lang + "'=German"); + } else if (lang.equals("SP")) { + Log.info("Change language translation: '" + lang + "'=Spanish"); + } else if (lang.equals("JA")) { + Log.info("Change language translation: '" + lang + "'=Japanese"); + } else if (lang.equals("IT")) { + Log.info("Change language translation: '" + lang + "'=Italian"); + } else if (lang.equals("KO")) { + Log.info("Change language translation: '" + lang + "'=Korean"); + } else if (lang.equals("RU")) { + Log.info("Change language translation: '" + lang + "'=Russian"); + } else if (lang.equals("PT")) { + Log.info("Change language translation: '" + lang + "'=Portuguese, Brazilian"); + } else if (lang.equals("ZH")) { + Log.info("Change language translation: '" + lang + "'=Chinese"); } else { - Log.info("Change language translation: '" + _lang + "'=Unknow"); + Log.info("Change language translation: '" + lang + "'=Unknow"); } } - + /** * Set the default language to load data (the default language might * contain all internal data for the basic application) - * @param _lang Language to load : ("EN" for english, "FR" for french, "DE" + * @param 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) { + public static void setLanguageDefault(final String lang) { + if (ETranslate.globalLanguageDefault.equals(lang)) { return; } - Log.info("Change default language translation : '" + _lang + "'"); - m_languageDefault = _lang; - m_translateLoadad = false; - m_translate.clear(); - } - - private ETranslate() { + Log.info("Change default language translation : '" + lang + "'"); + ETranslate.globalLanguageDefault = lang; + ETranslate.globalTranslateLoadad = false; + ETranslate.globalTranslate.clear(); } + + private ETranslate() {} } diff --git a/src/org/atriasoft/ewol/DrawProperty.java b/src/org/atriasoft/ewol/DrawProperty.java index 04bf376..7e11144 100644 --- a/src/org/atriasoft/ewol/DrawProperty.java +++ b/src/org/atriasoft/ewol/DrawProperty.java @@ -10,7 +10,7 @@ import org.atriasoft.etk.math.Vector2i; * @license MPL v2.0 (see license file) */ - //@formatter:off +//@formatter:off /* /- windowsSize *--------------------------------------------------* @@ -36,32 +36,32 @@ import org.atriasoft.etk.math.Vector2i; (0,0) */ //@formatter:on +@SuppressWarnings("preview") 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); + this(Vector2i.ZERO, Vector2i.ZERO, Vector2i.ZERO); } - + public DrawProperty(final Vector2i windowsSize, final Vector2i origin, final Vector2i size) { this.windowsSize = windowsSize; this.origin = origin; this.size = size; } - - public DrawProperty withLimit(final Vector2f _origin, final Vector2f _size) { + + public DrawProperty withLimit(final Vector2f originIn, 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())); + Vector2i origin = this.origin.max((int) originIn.x(), (int) originIn.y()); + tmpSize = tmpSize.min((int) (originIn.x() + size.x()), (int) (originIn.y() + size.y())); tmpSize = tmpSize.less(origin); - return new DrawProperty(windowsSize, origin, tmpSize); + return new DrawProperty(this.windowsSize, origin, tmpSize); } - + @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/Ewol.java b/src/org/atriasoft/ewol/Ewol.java index 2a3afaf..c0879e1 100644 --- a/src/org/atriasoft/ewol/Ewol.java +++ b/src/org/atriasoft/ewol/Ewol.java @@ -6,19 +6,22 @@ import org.atriasoft.etk.Uri; * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ +import org.atriasoft.etranslate.ETranslate; import org.atriasoft.ewol.context.EwolApplication; import org.atriasoft.ewol.context.EwolContext; +import org.atriasoft.gale.Gale; public class Ewol { - static { - Uri.addLibrary("ewol", Ewol.class); - } - public static EwolContext getContext() { // TODO Auto-generated method stub return EwolContext.getContext(); } + public static void init() { + Uri.addLibrary("ewol", Ewol.class, "/resources/ewol/"); + Gale.init(); + } + /** * This is the only one things the User might done in his main(); * @note To answare you before you ask the question, this is really simple: @@ -26,10 +29,15 @@ public class Ewol { * 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 _application just created instance of the applicationo - * @param _argc Standard argc - * @param _argv Standard argv + * @param application just created instance of the applicationo + * @param args Standard args * @return normal error int for the application error management */ - public static int run(final EwolApplication _application, String[] _argv); + public static int run(final EwolApplication application, final String[] args) { + ETranslate.autoDetectLanguage(); + EwolContext context = new EwolContext(application); + return Gale.run(context, args); + } + + private Ewol() {} } diff --git a/src/org/atriasoft/ewol/Gravity.java b/src/org/atriasoft/ewol/Gravity.java index 5b9c403..d20190b 100644 --- a/src/org/atriasoft/ewol/Gravity.java +++ b/src/org/atriasoft/ewol/Gravity.java @@ -11,38 +11,38 @@ import org.atriasoft.etk.math.Vector2f; * 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 + buttom, // !< gravity is in center + buttomLeft, // !< gravity is in top + buttomRight, // !< gravity is in buttom + center, // !< 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) { + right, // !< gravity is in top-right + top, // !< gravity is in top-left + topLeft, // !< gravity is in buttom-right + topRight; // !< 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) { + if (deltas.x() > 0.0001f) { + if (gravity == left || gravity == buttomLeft || gravity == topLeft) { // nothing to do - } else if (_gravity == right || _gravity == buttomRight || _gravity == topRight) { - outX = (int) (_deltas.x()); + } else if (gravity == right || gravity == buttomRight || gravity == topRight) { + outX = (int) (deltas.x()); } else { - outX = (int) (_deltas.x() * 0.5f); + outX = (int) (deltas.x() * 0.5f); } } - if (_deltas.y() > 0.0001f) { - if (_gravity == buttom || _gravity == buttomLeft || _gravity == buttomRight) { + if (deltas.y() > 0.0001f) { + if (gravity == buttom || gravity == buttomLeft || gravity == buttomRight) { // nothing to do - } else if (_gravity == top || _gravity == topRight || _gravity == topLeft) { - outY = (int) (_deltas.y()); + } else if (gravity == top || gravity == topRight || gravity == topLeft) { + outY = (int) (deltas.y()); } else { - outY = (int) (_deltas.y() * 0.5f); + outY = (int) (deltas.y() * 0.5f); } } return new Vector2f(outX, outY); } - + } diff --git a/src/org/atriasoft/ewol/Padding.java b/src/org/atriasoft/ewol/Padding.java index 697d116..af38df5 100644 --- a/src/org/atriasoft/ewol/Padding.java +++ b/src/org/atriasoft/ewol/Padding.java @@ -10,124 +10,123 @@ package org.atriasoft.ewol; */ 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 yTop; + public Padding() { setValue(); } - - public Padding(final float _xLeft) { - setValue(_xLeft); + + 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) { + 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) { + setValue(xLeft, yt, xr); } - - public Padding(final float _xLeft, final float _yt, final float _xr, final float _yb) { - setValue(_xLeft, _yt, _xr, _yb); + + public Padding(final float xLeft, final float yt, final float xr, final float yb) { + setValue(xLeft, yt, xr, yb); } - + /** * Add a vector to this one - * @param _v The vector to add 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; - this.xRight += _v.xRight; - this.yBottom += _v.yBottom; + public Padding add(final Padding v) { + this.xLeft += v.xLeft; + this.yTop += v.yTop; + this.xRight += v.xRight; + this.yBottom += v.yBottom; return this; } - + // ! @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); + 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); } - + public void setValue() { this.xLeft = 0; this.yTop = 0; this.xRight = 0; this.yBottom = 0; } - - public void setValue(final float _xLeft) { - this.xLeft = _xLeft; + + 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; + + 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; + + 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 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 setXLeft(final float val) { + this.xLeft = val; } - - public void setXRight(final float _val) { - this.xRight = _val; + + public void setXRight(final float val) { + this.xRight = val; } - - public void setYButtom(final float _val) { - this.yBottom = _val; + + public void setYButtom(final float val) { + this.yBottom = val; } - - public void setYTop(final float _val) { - this.yTop = _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/annotation/EwolAnnotation.java b/src/org/atriasoft/ewol/annotation/EwolAnnotation.java index fa14477..dfabd80 100644 --- a/src/org/atriasoft/ewol/annotation/EwolAnnotation.java +++ b/src/org/atriasoft/ewol/annotation/EwolAnnotation.java @@ -12,7 +12,7 @@ import java.lang.annotation.Target; * Exml annotations generically, and in future also for * passing other generic annotation configuration. */ -@Target({ ElementType.ANNOTATION_TYPE }) +@Target(ElementType.ANNOTATION_TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface EwolAnnotation { // for now, a pure tag annotation, no parameters diff --git a/src/org/atriasoft/ewol/compositing/AlignMode.java b/src/org/atriasoft/ewol/compositing/AlignMode.java new file mode 100644 index 0000000..2e4c714 --- /dev/null +++ b/src/org/atriasoft/ewol/compositing/AlignMode.java @@ -0,0 +1,5 @@ +package org.atriasoft.ewol.compositing; + +public enum AlignMode { + alignDisable, alignRight, alignLeft, alignCenter, alignJustify +} diff --git a/src/org/atriasoft/ewol/compositing/Compositing.java b/src/org/atriasoft/ewol/compositing/Compositing.java index a2f328b..4d030e7 100644 --- a/src/org/atriasoft/ewol/compositing/Compositing.java +++ b/src/org/atriasoft/ewol/compositing/Compositing.java @@ -10,7 +10,7 @@ import org.atriasoft.etk.math.Vector3f; */ public abstract class Compositing { - protected Matrix4f matrixApply = Matrix4f.IDENTITY;; + protected Matrix4f matrixApply = Matrix4f.IDENTITY; /** * clear alll tre registered element in the current element @@ -26,7 +26,7 @@ public abstract class Compositing { draw(true); } - public abstract void draw(final boolean _disableDepthTest); + public abstract void draw(final boolean disableDepthTest); /** * reset to the eye matrix the openGL mouving system @@ -37,33 +37,34 @@ public abstract class Compositing { /** * rotate the curent display of this element - * @param _vect The rotation vector to apply at the transformation matrix + * @param vect The rotation vector to apply at the transformation matrix */ - public void rotate(final Vector3f _vect, final float _angle) { - this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixRotate(_vect, _angle)); + public void rotate(final Vector3f vect, final float angle) { + this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixRotate(vect, angle)); } /** * scale the current diaplsy of this element - * @param _vect The scaling vector to apply at the transformation matrix + * @param vect The scaling vector to apply at the transformation matrix */ - public void scale(final Vector3f _vect) { - this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixScale(_vect)); + public void scale(final Vector3f vect) { + this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixScale(vect)); } /** * set the transformation matrix - * @param _mat The new matrix. + * @param mat The new matrix. */ - public void setMatrix(final Matrix4f _mat) { - this.matrixApply = _mat; + public void setMatrix(final Matrix4f mat) { + this.matrixApply = mat; } /** * translate the current display of this element - * @param _vect The translation vector to apply at the transformation matrix + * @param vect The translation vector to apply at the transformation matrix */ - public void translate(final Vector3f _vect) { - this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixTranslate(_vect)); + public void translate(final Vector3f vect) { + this.matrixApply = this.matrixApply.multiply(Matrix4f.createMatrixTranslate(vect)); } + } diff --git a/src/org/atriasoft/ewol/compositing/CompositingDrawing.java b/src/org/atriasoft/ewol/compositing/CompositingDrawing.java index e99b372..337f340 100644 --- a/src/org/atriasoft/ewol/compositing/CompositingDrawing.java +++ b/src/org/atriasoft/ewol/compositing/CompositingDrawing.java @@ -20,32 +20,32 @@ import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceVirtualBufferObject; public class CompositingDrawing extends Compositing { - - protected static int vboIdCoord = 0; + protected static int vboIdColor = 1; - private Vector3f position = new Vector3f(0, 0, 0); // !< The current position to draw + protected static int vboIdCoord = 0; + private boolean clippingEnable = false; // !< true if the clipping must be activated private Vector3f clippingPosStart = new Vector3f(0, 0, 0); // !< Clipping start position private Vector3f clippingPosStop = new Vector3f(0, 0, 0); // !< Clipping stop position - private boolean clippingEnable = false; // !< true if the clipping must be activated private Color color = Color.BLACK; // !< The text foreground color private Color colorBg = Color.NONE; // !< The text background color - private ResourceProgram GLprogram; // !< pointer on the opengl display program - private int GLPosition = -1; // !< openGL id on the element (vertex buffer) - private int GLMatrix = -1; // !< openGL id on the element (transformation matrix) - private int GLMatrixPosition = -1; // !< position matrix - private int GLColor = -1; // !< openGL id on the element (color buffer) - protected ResourceVirtualBufferObject VBO; - - private float thickness = 0; // !< when drawing line and other things - - private int triElement = 0; // !< special counter of the single dot generated - - private final Vector3f[] triangle = new Vector3f[3]; // !< Register every system with a combinaison of tiangle - - private final Color[] tricolor = new Color[3]; // !< Register every the associated color foreground - private final List outTriangles = new ArrayList<>(); + private int oGLColor = -1; // !< openGL id on the element (color buffer) + private int oGLMatrix = -1; // !< openGL id on the element (transformation matrix) + private int oGLMatrixPosition = -1; // !< position matrix + private int oGLPosition = -1; // !< openGL id on the element (vertex buffer) + private ResourceProgram oGLprogram; // !< pointer on the opengl display program private final List outColors = new ArrayList<>(); - + private final List outTriangles = new ArrayList<>(); + + private Vector3f position = new Vector3f(0, 0, 0); // !< The current position to draw + + private float thickness = 0; // !< when drawing line and other things + + private final Vector3f[] triangle = new Vector3f[3]; // !< Register every system with a combinaison of tiangle + + private final Color[] tricolor = new Color[3]; // !< Register every the associated color foreground + private int triElement = 0; // !< special counter of the single dot generated + protected ResourceVirtualBufferObject vbo; + // internal API for the generation abstraction of triangles /** * Basic ructor @@ -57,11 +57,11 @@ public class CompositingDrawing extends Compositing { this.tricolor[iii] = this.color; } // Create the VBO: - this.VBO = ResourceVirtualBufferObject.create(4); + this.vbo = ResourceVirtualBufferObject.create(4); // TO facilitate some debugs we add a name of the VBO: - this.VBO.setName("[VBO] of ewol::compositing::Area"); + this.vbo.setName("[VBO] of ewol::compositing::Area"); } - + /** * add a point reference at the current position (this is a vertex * reference at the current position @@ -70,85 +70,85 @@ public class CompositingDrawing extends Compositing { internalSetColor(this.color); setPoint(this.position); } - + /** * draw a 2D circle with the specify rafdius parameter. - * @param _radius Distence to the dorder - * @param _angleStart start angle of this circle ([0..2PI] otherwithe == > + * @param radius Distence to the dorder + * @param angleStart start angle of this circle ([0..2PI] otherwithe == > * disable) - * @param _angleStop stop angle of this circle ([0..2PI] otherwithe == > + * @param angleStop stop angle of this circle ([0..2PI] otherwithe == > * disable) */ - public void circle(final float _radius) { - circle(_radius, 0); + public void circle(final float radius) { + circle(radius, 0); } - - public void circle(final float _radius, final float _angleStart) { - circle(_radius, _angleStart, 2.0f * FMath.PI); - }; - - public void circle(float _radius, final float _angleStart, float _angleStop) { + + public void circle(final float radius, final float angleStart) { + circle(radius, angleStart, 2.0f * FMath.PI); + } + + public void circle(float radius, final float angleStart, float angleStop) { resetCount(); - - if (_radius < 0) { - _radius *= -1; + + if (radius < 0) { + radius *= -1; } - _angleStop = _angleStop - _angleStart; - - int nbOcurence = (int) _radius; + angleStop = angleStop - angleStart; + + int nbOcurence = (int) radius; if (nbOcurence < 10) { nbOcurence = 10; } - + // display background : if (this.colorBg.a() != 0) { internalSetColor(this.colorBg); for (int iii = 0; iii < nbOcurence; iii++) { setPoint(new Vector3f(this.position.x(), this.position.y(), 0)); - - float angleOne = _angleStart + (_angleStop * iii / nbOcurence); - float offsety = FMath.sin(angleOne) * _radius; - float offsetx = FMath.cos(angleOne) * _radius; - + + final float angleOne = angleStart + (angleStop * iii / nbOcurence); + float offsety = FMath.sin(angleOne) * radius; + float offsetx = FMath.cos(angleOne) * radius; + setPoint(new Vector3f(this.position.x() + offsetx, this.position.y() + offsety, 0)); - - float angleTwo = _angleStart + (_angleStop * (iii + 1) / nbOcurence); - offsety = FMath.sin(angleTwo) * _radius; - offsetx = FMath.cos(angleTwo) * _radius; - + + final float angleTwo = angleStart + (angleStop * (iii + 1) / nbOcurence); + offsety = FMath.sin(angleTwo) * radius; + offsetx = FMath.cos(angleTwo) * radius; + setPoint(new Vector3f(this.position.x() + offsetx, this.position.y() + offsety, 0)); } } - + // show if we have a border : if (this.thickness == 0 || this.color.a() == 0) { return; } internalSetColor(this.color); for (int iii = 0; iii < nbOcurence; iii++) { - - float angleOne = _angleStart + (_angleStop * iii / nbOcurence); - float offsetExty = FMath.sin(angleOne) * (_radius + this.thickness / 2); - float offsetExtx = FMath.cos(angleOne) * (_radius + this.thickness / 2); - float offsetInty = FMath.sin(angleOne) * (_radius - this.thickness / 2); - float offsetIntx = FMath.cos(angleOne) * (_radius - this.thickness / 2); - - float angleTwo = _angleStart + (_angleStop * (iii + 1) / nbOcurence); - float offsetExt2y = FMath.sin(angleTwo) * (_radius + this.thickness / 2); - float offsetExt2x = FMath.cos(angleTwo) * (_radius + this.thickness / 2); - float offsetInt2y = FMath.sin(angleTwo) * (_radius - this.thickness / 2); - float offsetInt2x = FMath.cos(angleTwo) * (_radius - this.thickness / 2); - + + final float angleOne = angleStart + (angleStop * iii / nbOcurence); + final float offsetExty = FMath.sin(angleOne) * (radius + this.thickness / 2); + final float offsetExtx = FMath.cos(angleOne) * (radius + this.thickness / 2); + final float offsetInty = FMath.sin(angleOne) * (radius - this.thickness / 2); + final float offsetIntx = FMath.cos(angleOne) * (radius - this.thickness / 2); + + final float angleTwo = angleStart + (angleStop * (iii + 1) / nbOcurence); + final float offsetExt2y = FMath.sin(angleTwo) * (radius + this.thickness / 2); + final float offsetExt2x = FMath.cos(angleTwo) * (radius + this.thickness / 2); + final float offsetInt2y = FMath.sin(angleTwo) * (radius - this.thickness / 2); + final float offsetInt2x = FMath.cos(angleTwo) * (radius - this.thickness / 2); + setPoint(new Vector3f(this.position.x() + offsetIntx, this.position.y() + offsetInty, 0)); setPoint(new Vector3f(this.position.x() + offsetExtx, this.position.y() + offsetExty, 0)); setPoint(new Vector3f(this.position.x() + offsetExt2x, this.position.y() + offsetExt2y, 0)); - + setPoint(new Vector3f(this.position.x() + offsetExt2x, this.position.y() + offsetExt2y, 0)); setPoint(new Vector3f(this.position.x() + offsetInt2x, this.position.y() + offsetInt2y, 0)); setPoint(new Vector3f(this.position.x() + offsetIntx, this.position.y() + offsetInty, 0)); } } - + /** * clear alll tre registered element in the current element */ @@ -157,56 +157,56 @@ public class CompositingDrawing extends Compositing { // call upper class super.clear(); // reset Buffer : - this.VBO.clear(); + this.vbo.clear(); this.outTriangles.clear(); this.outColors.clear(); - + // reset temporal variables : this.position = Vector3f.ZERO; - + this.clippingPosStart = Vector3f.ZERO; this.clippingPosStop = Vector3f.ZERO; this.clippingEnable = false; - + this.color = Color.BLACK; this.colorBg = Color.NONE; - + for (int iii = 0; iii < 3; iii++) { this.triangle[iii] = this.position; this.tricolor[iii] = this.color; } } - + /** * draw All the refistered text in the current element on openGL */ @Override - public void draw(final boolean _disableDepthTest) { - + public void draw(final boolean disableDepthTest) { + // push data on the VBO // TODO optimize this with single push when needed - 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) { + 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.oGLprogram == null) { Log.error("No shader ..."); return; } // set Matrix : translation/positionMatrix - Matrix4f tmpMatrix = OpenGL.getMatrix().multiply(this.matrixApply); - this.GLprogram.use(); - this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix); - this.GLprogram.uniformMatrix(this.GLMatrixPosition, Matrix4f.IDENTITY); + final Matrix4f tmpMatrix = OpenGL.getMatrix().multiply(this.matrixApply); + this.oGLprogram.use(); + this.oGLprogram.uniformMatrix(this.oGLMatrix, tmpMatrix); + this.oGLprogram.uniformMatrix(this.oGLMatrixPosition, Matrix4f.IDENTITY); // position: - this.GLprogram.sendAttributePointer(this.GLPosition, this.VBO, CompositingDrawing.vboIdCoord); + this.oGLprogram.sendAttributePointer(this.oGLPosition, this.vbo, CompositingDrawing.vboIdCoord); // color: - this.GLprogram.sendAttributePointer(this.GLColor, this.VBO, CompositingDrawing.vboIdColor); + this.oGLprogram.sendAttributePointer(this.oGLColor, this.vbo, CompositingDrawing.vboIdColor); // Request the draw od the elements : - OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, this.VBO.bufferSize(CompositingDrawing.vboIdCoord)); - this.GLprogram.unUse(); + OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, this.vbo.bufferSize(CompositingDrawing.vboIdCoord)); + this.oGLprogram.unUse(); } - + /** * Lunch the generation of triangle */ @@ -219,7 +219,7 @@ public class CompositingDrawing extends Compositing { this.outColors.add(this.tricolor[1]); this.outColors.add(this.tricolor[2]); } - + /** * Get the foreground color of the font. * @return Foreground color. @@ -227,73 +227,73 @@ public class CompositingDrawing extends Compositing { public Color getColor() { return this.color; } - + /** * Get the background color of the font. * @return Background color. */ public Color getColorBg() { return this.colorBg; - }; - + } + /** * get the current display position (sometime needed in the gui control) * @return the current position. */ public Vector3f getPos() { return this.position; - }; - + } + /** * set the Color of the current triangle drawing - * @param _color Color to current dots generated + * @param color Color to current dots generated */ - private void internalSetColor(final Color _color) { + private void internalSetColor(final Color color) { if (this.triElement < 1) { - this.tricolor[0] = _color; + this.tricolor[0] = color; } if (this.triElement < 2) { - this.tricolor[1] = _color; + this.tricolor[1] = color; } if (this.triElement < 3) { - this.tricolor[2] = _color; + this.tricolor[2] = color; } - }; - - public void lineRel(final Vector2f _vect) { - lineRel(new Vector3f(_vect.x(), _vect.y(), 0)); - }; - + } + + public void lineRel(final Vector2f vect) { + lineRel(new Vector3f(vect.x(), vect.y(), 0)); + } + /** * Relative drawing a line (spacial vector) - * @param _vect Vector of the curent line. + * @param vect Vector of the curent line. */ - public void lineRel(final Vector3f _vect) { - lineTo(this.position.add(_vect)); - }; - - public void lineTo(final Vector2f _dest) { - lineTo(new Vector3f(_dest.x(), _dest.y(), 0)); - }; - + public void lineRel(final Vector3f vect) { + lineTo(this.position.add(vect)); + } + + public void lineTo(final Vector2f dest) { + lineTo(new Vector3f(dest.x(), dest.y(), 0)); + } + /** * draw a line to a specific position - * @param _dest Position of the end of the line. + * @param dest Position of the end of the line. */ - public void lineTo(final Vector3f _dest) { + public void lineTo(final Vector3f dest) { resetCount(); internalSetColor(this.color); - // Log.verbose("DrawLine : " + this.position + " to " + _dest); - if (this.position.x() == _dest.x() && this.position.y() == _dest.y() && this.position.z() == _dest.z()) { + // Log.verbose("DrawLine : " + this.position + " to " + dest); + if (this.position.x() == dest.x() && this.position.y() == dest.y() && this.position.z() == dest.z()) { // Log.warning("Try to draw a line width 0"); return; } // teta = tan-1(oposer/adjacent) float teta = 0; - if (this.position.x() <= _dest.x()) { - teta = FMath.atan((_dest.y() - this.position.y()) / (_dest.x() - this.position.x())); + if (this.position.x() <= dest.x()) { + teta = FMath.atan((dest.y() - this.position.y()) / (dest.x() - this.position.x())); } else { - teta = FMath.PI + FMath.atan((_dest.y() - this.position.y())) / (_dest.x() - this.position.x()); + teta = FMath.PI + FMath.atan((dest.y() - this.position.y())) / (dest.x() - this.position.x()); } if (teta < 0) { teta += 2 * FMath.PI; @@ -301,19 +301,19 @@ public class CompositingDrawing extends Compositing { teta -= 2 * FMath.PI; } // Log.debug("teta = " + (teta*180/(FMath.PI)) + " deg." ); - float offsety = FMath.sin(teta - FMath.PI / 2) * (this.thickness / 2); - float offsetx = FMath.cos(teta - FMath.PI / 2) * (this.thickness / 2); + final float offsety = FMath.sin(teta - FMath.PI / 2) * (this.thickness / 2); + final float offsetx = FMath.cos(teta - FMath.PI / 2) * (this.thickness / 2); setPoint(new Vector3f(this.position.x() - offsetx, this.position.y() - offsety, this.position.z())); setPoint(new Vector3f(this.position.x() + offsetx, this.position.y() + offsety, this.position.z())); - setPoint(new Vector3f(_dest.x() + offsetx, _dest.y() + offsety, this.position.z())); - - setPoint(new Vector3f(_dest.x() + offsetx, _dest.y() + offsety, _dest.z())); - setPoint(new Vector3f(_dest.x() - offsetx, _dest.y() - offsety, _dest.z())); - setPoint(new Vector3f(this.position.x() - offsetx, this.position.y() - offsety, _dest.z())); + setPoint(new Vector3f(dest.x() + offsetx, dest.y() + offsety, this.position.z())); + + setPoint(new Vector3f(dest.x() + offsetx, dest.y() + offsety, dest.z())); + setPoint(new Vector3f(dest.x() - offsetx, dest.y() - offsety, dest.z())); + setPoint(new Vector3f(this.position.x() - offsetx, this.position.y() - offsety, dest.z())); // update the system position : - this.position = _dest; - }; - + this.position = dest; + } + /** * load the openGL program and get all the ID needed */ @@ -321,48 +321,47 @@ public class CompositingDrawing extends Compositing { // remove previous loading ... in case unLoadProgram(); // oad the new ... - this.GLprogram = ResourceProgram.create(new Uri("DATA", "color3.vert", "ewol"), - new Uri("DATA", "color3.frag", "ewol")); + this.oGLprogram = ResourceProgram.create(new Uri("DATA", "color3.vert", "ewol"), new Uri("DATA", "color3.frag", "ewol")); // get the shader resource : - if (this.GLprogram != null) { - this.GLPosition = this.GLprogram.getAttribute("EW_coord3d"); - this.GLColor = this.GLprogram.getAttribute("EW_color"); - this.GLMatrix = this.GLprogram.getUniform("EW_MatrixTransformation"); - this.GLMatrixPosition = this.GLprogram.getUniform("EW_MatrixPosition"); + if (this.oGLprogram != null) { + this.oGLPosition = this.oGLprogram.getAttribute("EWcoord3d"); + this.oGLColor = this.oGLprogram.getAttribute("EWcolor"); + this.oGLMatrix = this.oGLprogram.getUniform("EWMatrixTransformation"); + this.oGLMatrixPosition = this.oGLprogram.getUniform("EWMatrixPosition"); } - }; - - public void rectangle(final Vector2f _dest) { - rectangle(new Vector3f(_dest.x(), _dest.y(), 0)); - }; - + } + + public void rectangle(final Vector2f dest) { + rectangle(new Vector3f(dest.x(), dest.y(), 0)); + } + /** * draw a 2D rectangle to the position requested. - * @param _dest Position the the end of the rectangle + * @param dest Position the the end of the rectangle */ - public void rectangle(final Vector3f _dest) { + public void rectangle(final Vector3f dest) { resetCount(); internalSetColor(this.color); /* * Bitmap position xA xB yC *------* | | | | yD *------* */ float dxA = this.position.x(); - float dxB = _dest.x(); + float dxB = dest.x(); if (dxA > dxB) { // inverse order : - float tmp = dxA; + final float tmp = dxA; dxA = dxB; dxB = tmp; } float dyC = this.position.y(); - float dyD = _dest.y(); + float dyD = dest.y(); if (dyC > dyD) { // inverse order : - float tmp = dyC; + final float tmp = dyC; dyC = dyD; dyD = tmp; } - if (true == this.clippingEnable) { + if (this.clippingEnable) { if (dxA < this.clippingPosStart.x()) { dxA = this.clippingPosStart.x(); } @@ -382,90 +381,90 @@ public class CompositingDrawing extends Compositing { setPoint(new Vector3f(dxA, dyD, 0)); setPoint(new Vector3f(dxA, dyC, 0)); setPoint(new Vector3f(dxB, dyC, 0)); - + setPoint(new Vector3f(dxB, dyC, 0)); setPoint(new Vector3f(dxB, dyD, 0)); setPoint(new Vector3f(dxA, dyD, 0)); - }; - - public void rectangleWidth(final Vector2f _size) { - rectangleWidth(new Vector3f(_size.x(), _size.y(), 0)); - }; - + } + + public void rectangleWidth(final Vector2f size) { + rectangleWidth(new Vector3f(size.x(), size.y(), 0)); + } + /** * draw a 2D rectangle to the requested size. - * @param _size size of the rectangle + * @param size size of the rectangle */ - public void rectangleWidth(final Vector3f _size) { - rectangle(this.position.add(_size)); + public void rectangleWidth(final Vector3f size) { + rectangle(this.position.add(size)); } - + /** * in case of some error the count can be reset */ private void resetCount() { this.triElement = 0; - }; - - public void setClipping(final Vector2f _pos, final Vector2f _posEnd) { - setClipping(new Vector3f(_pos.x(), _pos.y(), -1), new Vector3f(_posEnd.x(), _posEnd.y(), 1)); - }; - + } + + public void setClipping(final Vector2f pos, final Vector2f posEnd) { + setClipping(new Vector3f(pos.x(), pos.y(), -1), new Vector3f(posEnd.x(), posEnd.y(), 1)); + } + /** * Request a clipping area for the text (next draw only) - * @param _pos Start position of the clipping - * @param _posEnd End position of the clipping + * @param pos Start position of the clipping + * @param posEnd End position of the clipping */ - public void setClipping(final Vector3f _pos, final Vector3f _posEnd) { + public void setClipping(final Vector3f pos, final Vector3f posEnd) { // note the internal system all time request to have a bounding all time in the // same order - this.clippingPosStop = Vector3f.max(_pos, _posEnd); - this.clippingPosStart = Vector3f.min(_pos, _posEnd); + this.clippingPosStop = Vector3f.max(pos, posEnd); + this.clippingPosStart = Vector3f.min(pos, posEnd); this.clippingEnable = true; } - + /** * enable/Disable the clipping (without lose the current clipping * position) - * _newMode The new status of the clipping + * newMode The new status of the clipping */ - public void setClippingMode(final boolean _newMode) { - this.clippingEnable = _newMode; + public void setClippingMode(final boolean newMode) { + this.clippingEnable = newMode; } - - public void setClippingWidth(final Vector2f _pos, final Vector2f _width) { - setClippingWidth(new Vector3f(_pos.x(), _pos.y(), -1), new Vector3f(_width.x(), _width.y(), 2)); + + public void setClippingWidth(final Vector2f pos, final Vector2f width) { + setClippingWidth(new Vector3f(pos.x(), pos.y(), -1), new Vector3f(width.x(), width.y(), 2)); } - + /** * Request a clipping area for the text (next draw only) - * @param_ pos Start position of the clipping - * @param _width Width size of the clipping + * @param pos Start position of the clipping + * @param width Width size of the clipping */ - public void setClippingWidth(final Vector3f _pos, final Vector3f _width) { - setClipping(_pos, _pos.add(_width)); - }; - + public void setClippingWidth(final Vector3f pos, final Vector3f width) { + setClipping(pos, pos.add(width)); + } + /** * set the Color of the current foreground font - * @param _color Color to set on foreground (for next print) + * @param color Color to set on foreground (for next print) */ - public void setColor(final Color _color) { - this.color = _color; - }; - + public void setColor(final Color color) { + this.color = color; + } + /** * set the background color of the font (for selected Text (not the * global BG)) - * @param _color Color to set on background (for next print) + * @param color Color to set on background (for next print) */ - public void setColorBg(final Color _color) { - this.colorBg = _color; - }; - + public void setColorBg(final Color color) { + this.colorBg = color; + } + /** * internal add of the specific point - * @param _point The requeste dpoint to add + * @param point The requeste dpoint to add */ private void setPoint(final Vector3f point) { this.triangle[this.triElement] = point; @@ -473,50 +472,50 @@ public class CompositingDrawing extends Compositing { if (this.triElement >= 3) { generateTriangle(); } - this.VBO.flush(); + this.vbo.flush(); } - - public void setPos(final Vector2f _pos) { - setPos(new Vector3f(_pos.x(), _pos.y(), 0)); - }; - + + public void setPos(final Vector2f pos) { + setPos(new Vector3f(pos.x(), pos.y(), 0)); + } + /** * set position for the next text writen - * @param _pos Position of the text (in 3D) + * @param pos Position of the text (in 3D) */ - public void setPos(final Vector3f _pos) { - this.position = _pos; - }; - - public void setRelPos(final Vector2f _pos) { - setRelPos(new Vector3f(_pos.x(), _pos.y(), 0)); + public void setPos(final Vector3f pos) { + this.position = pos; } - + + public void setRelPos(final Vector2f pos) { + setRelPos(new Vector3f(pos.x(), pos.y(), 0)); + } + /** * set relative position for the next text writen - * @param _pos ofset apply of the text (in 3D) + * @param pos ofset apply of the text (in 3D) */ - public void setRelPos(final Vector3f _pos) { - this.position = this.position.add(_pos); + public void setRelPos(final Vector3f pos) { + this.position = this.position.add(pos); } - + /** * Specify the line thickness for the next elements - * @param _thickness The thickness disired for the next print + * @param thickness The thickness disired for the next print */ - public void setThickness(final float _thickness) { - this.thickness = _thickness; + public void setThickness(final float thickness) { + this.thickness = thickness; // thickness must be positive if (this.thickness < 0) { this.thickness *= -1; } } - + /** * Un-Load the openGL program and get all the ID needed */ private void unLoadProgram() { - this.GLprogram = null; + this.oGLprogram = null; } - + } \ No newline at end of file diff --git a/src/org/atriasoft/ewol/compositing/CompositingImage.java b/src/org/atriasoft/ewol/compositing/CompositingImage.java index 7a88ad6..cb1fa8d 100644 --- a/src/org/atriasoft/ewol/compositing/CompositingImage.java +++ b/src/org/atriasoft/ewol/compositing/CompositingImage.java @@ -21,54 +21,53 @@ import org.atriasoft.gale.backend3d.OpenGL.RenderMode; import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceVirtualBufferObject; -class CompositingImage extends Compositing { - public static final int sizeAuto = 0; - // VBO table property: - public static final int vboIdCoord = 0; - public static final int vboIdCoordTex = 1; - public static final int vboIdColor = 2; +public class CompositingImage extends Compositing { public static final int NB_VBO = 3; - private Uri filename; - private Vector2i requestSize = new Vector2i(2, 2); - private Vector3f position = new Vector3f(0, 0, 0); //!< The current position to draw + public static final int SIZE_AUTO = 0; + public static final int VBO_ID_COLOR = 2; + // VBO table property: + public static final int VBO_ID_COORD = 0; + public static final int VBO_ID_COORD_TEX = 1; + private float angle = 0; //!< Angle to set at the axes + private boolean clippingEnable = true; //!< true if the clipping must be activated private Vector3f clippingPosStart = new Vector3f(0, 0, 0); //!< Clipping start position private Vector3f clippingPosStop = new Vector3f(0, 0, 0); //!< Clipping stop position - private boolean clippingEnable = true; //!< true if the clipping must be activated - private Color color = new Color(1, 1, 1); //!< The text foreground color - private float angle = 0; //!< Angle to set at the axes - private ResourceProgram GLprogram = null; //!< pointer on the opengl display program - private int GLPosition = -1; //!< openGL id on the element (vertex buffer) - private int GLMatrix = -1; //!< openGL id on the element (transformation matrix) - private int GLColor = -1; //!< openGL id on the element (color buffer) - private int GLtexture = -1; //!< openGL id on the element (Texture position) - private int GLtexID = -1; //!< openGL id on the element (texture ID) + private Uri filename; + + private int oGLColor = -1; //!< openGL id on the element (color buffer) + private int oGLMatrix = -1; //!< openGL id on the element (transformation matrix) + private int oGLPosition = -1; //!< openGL id on the element (vertex buffer) + private ResourceProgram oGLprogram = null; //!< pointer on the opengl display program + private int oGLtexID = -1; //!< openGL id on the element (texture ID) + private int oGLtexture = -1; //!< openGL id on the element (Texture position) + private Vector3f position = new Vector3f(0, 0, 0); //!< The current position to draw + private Vector2i requestSize = new Vector2i(2, 2); private ResourceTextureFile resource = null; //!< texture resources private ResourceTexture2 resourceImage = null; //!< texture resources - private ResourceVirtualBufferObject VBO = null; + private ResourceVirtualBufferObject vbo = null; + + public CompositingImage() { + this(new Uri("DATA", ""), CompositingImage.SIZE_AUTO); + } /** * generic ructor - * @param _uri URI of the file that might be loaded - * @param _df enable distance field mode - * @param _size for the image when Verctorial image loading is requested + * @param uri URI of the file that might be loaded + * @param size for the image when Verctorial image loading is requested */ - public CompositingImage() { - this(new Uri(""), sizeAuto); - } - - public CompositingImage(final Uri _uri, final int _size) { - this.filename = _uri; + public CompositingImage(final Uri uri, final int size) { + this.filename = uri; // Create the VBO: - this.VBO = ResourceVirtualBufferObject.create(NB_VBO); - if (this.VBO == null) { + this.vbo = ResourceVirtualBufferObject.create(CompositingImage.NB_VBO); + 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::Image"); - setSource(_uri, _size); + this.vbo.setName("[VBO] of ewol::compositing::Image"); + setSource(uri, size); loadProgram(); } @@ -80,7 +79,7 @@ class CompositingImage extends Compositing { // call upper class super.clear(); // reset Buffer : - this.VBO.clear(); + this.vbo.clear(); // reset temporal variables : this.position = new Vector3f(0, 0, 0); this.clippingPosStart = new Vector3f(0, 0, 0); @@ -92,10 +91,10 @@ class CompositingImage extends Compositing { /** * draw All the refistered text in the current element on openGL - * @param _disableDepthTest disable the Depth test for display + * @param disableDepthTest disable the Depth test for display */ @Override - public void draw(final boolean _disableDepthTest) { + public void draw(final boolean disableDepthTest) { /* if (this.VBO.bufferSize(this.vboIdCoord) <= 0) { //Log.warning("Nothink to draw..."); @@ -106,20 +105,20 @@ class CompositingImage extends Compositing { // this is a normale case ... the user can choice to have no image ... return; } - if (this.GLprogram == null) { + if (this.oGLprogram == null) { Log.error("No shader ..."); return; } //Log.warning("Display image : " + this.VBO.bufferSize(this.vboIdCoord)); - if (_disableDepthTest == true) { + if (disableDepthTest) { OpenGL.disable(OpenGL.Flag.flag_depthTest); } else { OpenGL.enable(OpenGL.Flag.flag_depthTest); } // set Matrix : translation/positionMatrix final Matrix4f tmpMatrix = OpenGL.getMatrix().multiply(this.matrixApply); - this.GLprogram.use(); - this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix); + this.oGLprogram.use(); + this.oGLprogram.uniformMatrix(this.oGLMatrix, tmpMatrix); // TextureID if (this.resourceImage != null) { this.resourceImage.bindForRendering(0); @@ -129,15 +128,15 @@ class CompositingImage extends Compositing { Log.error("FONT type error Request normal and display distance field ..."); } // position: - this.GLprogram.sendAttributePointer(this.GLPosition, this.VBO, CompositingImage.vboIdCoord); + this.oGLprogram.sendAttributePointer(this.oGLPosition, this.vbo, CompositingImage.VBO_ID_COORD); // Texture: - this.GLprogram.sendAttributePointer(this.GLtexture, this.VBO, CompositingImage.vboIdCoordTex); + this.oGLprogram.sendAttributePointer(this.oGLtexture, this.vbo, CompositingImage.VBO_ID_COORD_TEX); // color: - this.GLprogram.sendAttributePointer(this.GLColor, this.VBO, CompositingImage.vboIdColor); + this.oGLprogram.sendAttributePointer(this.oGLColor, this.vbo, CompositingImage.VBO_ID_COLOR); // Request the draw of the elements: - OpenGL.drawArrays(RenderMode.triangle, 0, this.VBO.bufferSize(CompositingImage.vboIdCoord)); + OpenGL.drawArrays(RenderMode.triangle, 0, this.vbo.bufferSize(CompositingImage.VBO_ID_COORD)); - this.GLprogram.unUse(); + this.oGLprogram.unUse(); } /** @@ -154,16 +153,13 @@ class CompositingImage extends Compositing { */ public Vector2i getRealSize() { if (this.resource == null && this.resourceImage == null) { - return new Vector2i(0, 0); + return Vector2i.ZERO; } if (this.resource != null) { return this.resource.getRealSize(); } - if (this.resourceImage != null) { - return this.resourceImage.getUsableSize(); - } - return new Vector2i(0, 0); - }; + return this.resourceImage.getUsableSize(); + } /** * Sometimes the user declare an image but not allocate the ressources all the time, this is to know it .. @@ -171,51 +167,51 @@ class CompositingImage extends Compositing { */ public boolean hasSources() { return this.resource != null; - }; + } /** * load the openGL program and get all the ID needed */ private void loadProgram() { // get the shader resource: - this.GLPosition = 0; - this.GLprogram = ResourceProgram.create(new Uri("DATA", "textured3D.vert", "ewol"), new Uri("DATA", "textured3D.frag", "ewol")); - if (this.GLprogram != null) { - this.GLPosition = this.GLprogram.getAttribute("EW_coord3d"); - this.GLColor = this.GLprogram.getAttribute("EW_color"); - this.GLtexture = this.GLprogram.getAttribute("EW_texture2d"); - this.GLMatrix = this.GLprogram.getUniform("EW_MatrixTransformation"); - this.GLtexID = this.GLprogram.getUniform("EW_texID"); + this.oGLPosition = 0; + this.oGLprogram = ResourceProgram.create(new Uri("DATA", "textured3D.vert", "ewol"), new Uri("DATA", "textured3D.frag", "ewol")); + if (this.oGLprogram != null) { + this.oGLPosition = this.oGLprogram.getAttribute("EWcoord3d"); + this.oGLColor = this.oGLprogram.getAttribute("EWcolor"); + this.oGLtexture = this.oGLprogram.getAttribute("EWtexture2d"); + this.oGLMatrix = this.oGLprogram.getUniform("EWMatrixTransformation"); + this.oGLtexID = this.oGLprogram.getUniform("EWtexID"); } - }; + } - public void print(final Vector2f _size) { - printPart(_size, new Vector2f(0, 0), new Vector2f(1, 1)); + public void print(final Vector2f size) { + printPart(size, new Vector2f(0, 0), new Vector2f(1, 1)); } /** * add a compleate of the image to display with the requested size - * @param _size size of the output image + * @param size size of the output image */ - public void print(final Vector2i _size) { - print(new Vector2f(_size.x(), _size.y())); - }; + public void print(final Vector2i size) { + print(new Vector2f(size.x(), size.y())); + } /** * add a part of the image to display with the requested size - * @param _size size of the output image - * @param _sourcePosStart Start position in the image [0..1] (can be bigger but this repeate the image). - * @param _sourcePosStop Stop position in the image [0..1] (can be bigger but this repeate the image). + * @param size size of the output image + * @param sourcePosStart Start position in the image [0..1] (can be bigger but this repeate the image). + * @param sourcePosStop Stop position in the image [0..1] (can be bigger but this repeate the image). */ - public void printPart(final Vector2f _size, final Vector2f _sourcePosStart, final Vector2f _sourcePosStop) { + public void printPart(final Vector2f size, final Vector2f sourcePosStartIn, final Vector2f sourcePosStopIn) { if (this.resource == null) { return; } final Vector2f openGLSize = new Vector2f(this.resource.getOpenGlSize().x(), this.resource.getOpenGlSize().y()); final Vector2i usefullSize = this.resource.getUsableSize(); final Vector2f ratio = new Vector2f(usefullSize.x() / openGLSize.x(), usefullSize.y() / openGLSize.y()); - final Vector2f sourcePosStart = _sourcePosStart.multiply(ratio); - final Vector2f sourcePosStop = _sourcePosStop.multiply(ratio); + final Vector2f sourcePosStart = sourcePosStartIn.multiply(ratio); + final Vector2f sourcePosStop = sourcePosStopIn.multiply(ratio); Log.verbose(" openGLSize=" + openGLSize + " usableSize=" + usefullSize + " start=" + sourcePosStart + " stop=" + sourcePosStop); if (this.angle == 0.0f) { @@ -233,14 +229,14 @@ class CompositingImage extends Compositing { indexElem++; tex = new Vector2f(sourcePosStop.x(), sourcePosStop.y()); - point = new Vector3f(this.position.x() + _size.x(), this.position.y(), 0); + point = new Vector3f(this.position.x() + size.x(), this.position.y(), 0); coords[indexElem] = point; coordsTex[indexElem] = tex; colors[indexElem] = this.color; indexElem++; tex = new Vector2f(sourcePosStop.x(), sourcePosStart.y()); - point = new Vector3f(this.position.x() + _size.x(), this.position.y() + _size.y(), 0); + point = new Vector3f(this.position.x() + size.x(), this.position.y() + size.y(), 0); coords[indexElem] = point; coordsTex[indexElem] = tex; colors[indexElem] = this.color; @@ -252,7 +248,7 @@ class CompositingImage extends Compositing { indexElem++; tex = new Vector2f(sourcePosStart.x(), sourcePosStart.y()); - point = new Vector3f(this.position.x(), this.position.y() + _size.y(), 0); + point = new Vector3f(this.position.x(), this.position.y() + size.y(), 0); coords[indexElem] = point; coordsTex[indexElem] = tex; colors[indexElem] = this.color; @@ -263,23 +259,22 @@ class CompositingImage extends Compositing { coords[indexElem] = point; coordsTex[indexElem] = tex; colors[indexElem] = this.color; - indexElem++; - this.VBO.setVboData(CompositingImage.vboIdCoord, coords); - this.VBO.setVboData(CompositingImage.vboIdCoordTex, coordsTex); - this.VBO.setVboData(CompositingImage.vboIdColor, colors); + this.vbo.setVboData(CompositingImage.VBO_ID_COORD, coords); + this.vbo.setVboData(CompositingImage.VBO_ID_COORD_TEX, coordsTex); + this.vbo.setVboData(CompositingImage.VBO_ID_COLOR, colors); - this.VBO.flush(); + this.vbo.flush(); return; } - final Vector3f center = this.position.add(new Vector3f(_size.x(), _size.y(), 0)).divide(2.0f); + final Vector3f center = this.position.add(new Vector3f(size.x(), size.y(), 0)).divide(2.0f); - final Vector3f limitedSize = new Vector3f(_size.x() * 0.5f, _size.y() * 0.5f, 0.0f); + final Vector3f limitedSize = new Vector3f(size.x() * 0.5f, size.y() * 0.5f, 0.0f); Vector3f point = new Vector3f(0, 0, 0); - Vector2f tex = new Vector2f(_sourcePosStart.x(), sourcePosStop.y()); + Vector2f tex = new Vector2f(sourcePosStart.x(), sourcePosStop.y()); final Vector3f[] coords = new Vector3f[6]; final Vector2f[] coordsTex = new Vector2f[6]; @@ -328,128 +323,126 @@ class CompositingImage extends Compositing { coords[indexElem] = point; coordsTex[indexElem] = tex; colors[indexElem] = this.color; - indexElem++; - this.VBO.setVboData(CompositingImage.vboIdCoord, coords); - this.VBO.setVboData(CompositingImage.vboIdCoordTex, coordsTex); - this.VBO.setVboData(CompositingImage.vboIdColor, colors); + this.vbo.setVboData(CompositingImage.VBO_ID_COORD, coords); + this.vbo.setVboData(CompositingImage.VBO_ID_COORD_TEX, coordsTex); + this.vbo.setVboData(CompositingImage.VBO_ID_COLOR, colors); - this.VBO.flush(); - }; + this.vbo.flush(); + } /** * set a unique rotation of this element (not set in the rotate Generic system) - * @param _angle Angle to set in radiant. + * @param angleRad Angle to set in radiant. */ - public void setAngle(final float _angleRad) { - this.angle = _angleRad; - }; + public void setAngle(final float angleRad) { + this.angle = angleRad; + } - void setClipping(final Vector2f _pos, final Vector2f _posEnd) { - setClipping(new Vector3f(_pos.x(), _pos.y(), 0), new Vector3f(_posEnd.x(), _posEnd.y(), 0)); - }; + void setClipping(final Vector2f pos, final Vector2f posEnd) { + setClipping(new Vector3f(pos.x(), pos.y(), 0), new Vector3f(posEnd.x(), posEnd.y(), 0)); + } /** * Request a clipping area for the text (next draw only) - * @param _pos Start position of the clipping - * @param _posEnd End position of the clipping + * @param pos Start position of the clipping + * @param posEnd End position of the clipping */ - public void setClipping(final Vector3f _pos, final Vector3f _posEnd) { - this.clippingPosStart = FMath.min(_pos, _posEnd); - this.clippingPosStop = FMath.max(_pos, _posEnd); + public void setClipping(final Vector3f pos, final Vector3f posEnd) { + this.clippingPosStart = FMath.min(pos, posEnd); + this.clippingPosStop = FMath.max(pos, posEnd); this.clippingEnable = true; } /** * enable/Disable the clipping (without lose the current clipping position) - * _newMode The new status of the clipping + * newMode The new status of the clipping */ - public void setClippingMode(final boolean _newMode) { - this.clippingEnable = _newMode; - }; + public void setClippingMode(final boolean newMode) { + this.clippingEnable = newMode; + } - public void setClippingWidth(final Vector2f _pos, final Vector2f _width) { - setClippingWidth(new Vector3f(_pos.x(), _pos.y(), 0), new Vector3f(_width.x(), _width.y(), 0)); - }; + public void setClippingWidth(final Vector2f pos, final Vector2f width) { + setClippingWidth(new Vector3f(pos.x(), pos.y(), 0), new Vector3f(width.x(), width.y(), 0)); + } /** * Request a clipping area for the text (next draw only) - * @param _pos Start position of the clipping - * @param _width Width size of the clipping + * @param pos Start position of the clipping + * @param width Width size of the clipping */ - public void setClippingWidth(final Vector3f _pos, final Vector3f _width) { - setClipping(_pos, _pos.add(_width)); + public void setClippingWidth(final Vector3f pos, final Vector3f width) { + setClipping(pos, pos.add(width)); } /** * set the Color of the current foreground font - * @param _color Color to set on foreground (for next print) + * @param color Color to set on foreground (for next print) */ - public void setColor(final Color _color) { - this.color = _color; - }; + public void setColor(final Color color) { + this.color = color; + } - public void setPos(final Vector2f _pos) { - setPos(new Vector3f(_pos.x(), _pos.y(), 0)); + public void setPos(final Vector2f pos) { + setPos(new Vector3f(pos.x(), pos.y(), 0)); } /** * set position for the next text writen - * @param _pos Position of the text (in 3D) + * @param pos Position of the text (in 3D) */ - public void setPos(final Vector3f _pos) { - this.position = _pos; + public void setPos(final Vector3f pos) { + this.position = pos; } - public void setRelPos(final Vector2f _pos) { - setRelPos(new Vector3f(_pos.x(), _pos.y(), 0)); + public void setRelPos(final Vector2f pos) { + setRelPos(new Vector3f(pos.x(), pos.y(), 0)); } /** * set relative position for the next text writen - * @param _pos ofset apply of the text (in 3D) + * @param pos ofset apply of the text (in 3D) */ - public void setRelPos(final Vector3f _pos) { - this.position.add(_pos); + public void setRelPos(final Vector3f pos) { + this.position = this.position.add(pos); } - public void setSource(final Image _image) { + public void setSource(final Image image) { clear(); this.filename = null; - this.requestSize = _image.getSize(); + this.requestSize = image.getSize(); this.resourceImage = new ResourceTexture2(); - this.resourceImage.set(_image); + this.resourceImage.set(image); } /** * change the image Source == > can not be done to display 2 images at the same time ... - * @param _uri New file of the Image - * @param _size for the image when Verctorial image loading is requested + * @param uri New file of the Image */ - public void setSource(final Uri _uri) { - setSource(_uri, 32); + public void setSource(final Uri uri) { + setSource(uri, 32); } - public void setSource(final Uri _uri, final int _size) { - setSource(_uri, new Vector2i(_size, _size)); + public void setSource(final Uri uri, final int size) { + setSource(uri, new Vector2i(size, size)); } - public void setSource(final Uri _uri, final Vector2i _size) { + public void setSource(final Uri uri, final Vector2i size) { clear(); - if (this.filename == _uri && this.requestSize.x() == _size.x() && this.requestSize.y() == _size.y()) { + if (this.filename == uri && this.requestSize.x() == size.x() && this.requestSize.y() == size.y()) { // Nothing to do ... return; } final ResourceTextureFile resource = this.resource; final ResourceTexture2 resourceTex = this.resourceImage; - this.filename = _uri; - this.requestSize = _size; + this.filename = uri; + this.requestSize = size; this.resource = null; this.resourceImage = null; - final Vector2i tmpSize = new Vector2i(_size.x(), _size.y()); + final Vector2i tmpSize = new Vector2i(size.x(), size.y()); // note that no image can be loaded... - if (_uri.isEmpty() == false) { + if (!uri.isEmpty()) { // link to new one this.resource = ResourceTextureFile.create(this.filename, tmpSize); if (this.resource == null) { diff --git a/src/org/atriasoft/ewol/compositing/CompositingText.java b/src/org/atriasoft/ewol/compositing/CompositingText.java new file mode 100644 index 0000000..a78fee3 --- /dev/null +++ b/src/org/atriasoft/ewol/compositing/CompositingText.java @@ -0,0 +1,405 @@ + +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +package org.atriasoft.ewol.compositing; + +import java.util.ArrayList; +import java.util.List; + +import org.atriasoft.etk.Color; +import org.atriasoft.etk.math.Matrix4f; +import org.atriasoft.etk.math.Vector2f; +import org.atriasoft.etk.math.Vector3f; +import org.atriasoft.ewol.Ewol; +import org.atriasoft.ewol.internal.Log; +import org.atriasoft.ewol.resource.ResourceTexturedFont; +import org.atriasoft.ewol.resource.font.FontMode; +import org.atriasoft.ewol.resource.font.GlyphProperty; +import org.atriasoft.gale.backend3d.OpenGL; + +public class CompositingText extends TextBase { + List colors = new ArrayList<>(); + protected ResourceTexturedFont font; // !< Font resources + List pointPositions = new ArrayList<>(); + protected float size; + + List texturePositions = new ArrayList<>(); + + public CompositingText() { + this(""); + } + + public CompositingText(final String fontName) { + this(fontName, -1); + } + + /** + * generic constructor + * @param fontName Name of the font that might be loaded + * @param fontSize size of the font that might be loaded + */ + public CompositingText(final String fontName, final int fontSize) { + setFont(fontName, fontSize); + } + + @Override + public Vector3f calculateSizeChar(final Character charcode) { + // get a pointer on the glyph property : + final GlyphProperty myGlyph = getGlyphPointer(charcode); + final int fontHeigh = (int) getHeight(); + if (myGlyph == null) { + if (this.font == null) { + Log.warning("no Glyph... in no font"); + } else { + Log.warning("no Glyph... in font : " + this.font.getName()); + } + return new Vector3f((float) (0.2), (fontHeigh), (float) (0.0)); + } + // get the kerning ofset : + float kerningOffset = 0.0f; + if (this.kerning) { + kerningOffset = myGlyph.kerningGet(this.previousCharcode); + } + + final Vector3f outputSize = new Vector3f(myGlyph.advance.x() + kerningOffset, (fontHeigh), 0.0f); + // Register the previous character + this.previousCharcode = charcode; + return outputSize; + } + + @Override + public void clear() { + // call upper class + super.clear(); + this.texturePositions.clear(); + // set display positions : + this.pointPositions.clear(); + // set the color + this.colors.clear(); + } + + @Override + public void drawD(final boolean disableDepthTest) { + // draw BG in any case: + this.vectorialDraw.draw(disableDepthTest); + + // TODO : do it only one time (when needed ...) + // set texture coordonates : + this.vbo.setVboData(TextBase.vboIdCoordText, this.texturePositions.toArray(Vector2f[]::new)); + // set display positions : + this.vbo.setVboData(TextBase.vboIdCoord, this.pointPositions.toArray(Vector3f[]::new)); + // set the color + this.vbo.setVboData(TextBase.vboIdColor, this.colors.toArray(Color[]::new)); + // TODO : do it only one time (when needed ...) --------- end ------- + + if (this.vbo.bufferSize(TextBase.vboIdCoord) <= 0 || this.font == null) { + // Log.warning("Nothink to draw..."); + return; + } + if (this.font == null) { + Log.warning("no font..."); + return; + } + if (this.oGLprogram == null) { + Log.error("No shader ..."); + return; + } + // set Matrix : translation/positionMatrix + final Matrix4f tmpMatrix = OpenGL.getMatrix().multiply(this.matrixApply); + this.oGLprogram.use(); + this.oGLprogram.uniformMatrix(this.oGLMatrix, tmpMatrix); + // Texture : + this.oGLprogram.setTexture0(this.oGLtexID, this.font.getRendererId()); + this.oGLprogram.uniformInt(this.oGLtextWidth, this.font.getOpenGlSize().x()); + this.oGLprogram.uniformInt(this.oGLtextHeight, this.font.getOpenGlSize().x()); + // position: + this.oGLprogram.sendAttributePointer(this.oGLPosition, this.vbo, TextBase.vboIdCoord); + // Texture: + this.oGLprogram.sendAttributePointer(this.oGLtexture, this.vbo, TextBase.vboIdCoordText); + // color: + this.oGLprogram.sendAttributePointer(this.oGLColor, this.vbo, TextBase.vboIdColor); + // Request the draw od the elements : + OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, this.vbo.bufferSize(TextBase.vboIdCoord)); + this.oGLprogram.unUse(); + } + + @Override + public void drawMT(final Matrix4f transformationMatrix, final boolean enableDepthTest) { + + // draw BG in any case: + this.vectorialDraw.draw(); + + // TODO : do it only one time (when needed ...) + // set texture coordonates : + this.vbo.setVboData(TextBase.vboIdCoordText, this.texturePositions.toArray(Vector2f[]::new)); + // set display positions : + this.vbo.setVboData(TextBase.vboIdCoord, this.pointPositions.toArray(Vector3f[]::new)); + // set the color + this.vbo.setVboData(TextBase.vboIdColor, this.colors.toArray(Color[]::new)); + // TODO : do it only one time (when needed ...) --------- end ------- + + if (this.vbo.bufferSize(TextBase.vboIdCoord) <= 0 || this.font == null) { + // TODO : set it back ... + // Log.warning("Nothink to draw..."); + return; + } + if (this.oGLprogram == null) { + Log.error("No shader ..."); + return; + } + if (enableDepthTest) { + OpenGL.enable(OpenGL.Flag.flag_depthTest); + } + // set Matrix : translation/positionMatrix + final Matrix4f projMatrix = OpenGL.getMatrix(); + final Matrix4f camMatrix = OpenGL.getCameraMatrix(); + final Matrix4f tmpMatrix = projMatrix.multiply(camMatrix).multiply(transformationMatrix); + this.oGLprogram.use(); + this.oGLprogram.uniformMatrix(this.oGLMatrix, tmpMatrix); + // Texture: + this.oGLprogram.setTexture0(this.oGLtexID, this.font.getRendererId()); + this.oGLprogram.uniformInt(this.oGLtextWidth, this.font.getOpenGlSize().x()); + this.oGLprogram.uniformInt(this.oGLtextHeight, this.font.getOpenGlSize().x()); + // position: + this.oGLprogram.sendAttributePointer(this.oGLPosition, this.vbo, TextBase.vboIdCoord); + // Texture: + this.oGLprogram.sendAttributePointer(this.oGLtexture, this.vbo, TextBase.vboIdCoordText); + // color: + this.oGLprogram.sendAttributePointer(this.oGLColor, this.vbo, TextBase.vboIdColor); + // Request the draw od the elements: + OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, this.vbo.bufferSize(TextBase.vboIdCoord)); + this.oGLprogram.unUse(); + if (enableDepthTest) { + OpenGL.disable(OpenGL.Flag.flag_depthTest); + } + } + + @Override + public GlyphProperty getGlyphPointer(final Character charcode) { + if (this.font == null) { + Log.warning("no font..."); + return null; + } + return this.font.getGlyph(charcode, this.mode); + } + + @Override + public float getHeight() { + if (this.font == null) { + Log.warning("no font..."); + return 10.0f; + } + return this.font.getHeight(this.mode); + } + + @Override + public float getSize() { + if (this.font == null) { + Log.warning("no font..."); + return 1.0f; + } + return this.font.getFontSize(); + } + + @Override + public void printChar(final Character charcode) { + // get a pointer on the glyph property : + final GlyphProperty myGlyph = getGlyphPointer(charcode); + if (myGlyph == null) { + Log.error(" font does not really existed ..."); + return; + } + final int fontSize = (int) getSize(); + final int fontHeigh = (int) getHeight(); + + // get the kerning ofset : + float kerningOffset = 0; + if (this.kerning) { + kerningOffset = myGlyph.kerningGet(this.previousCharcode); + if (kerningOffset != 0) { + // Log.debug("Kerning between : '" + this.previousCharcode + "''" + myGlyph.UVal + // + "' value : " + kerningOffset); + } + } + // 0x01 == 0x20 == ' '; + if (charcode != 0x01) { + /* + * Bitmap position xA xB yC *------* | | | | yD *------* + */ + float dxA = this.position.x() + myGlyph.bearing.x() + kerningOffset; + float dxB = dxA + myGlyph.sizeTexture.x(); + float dyC = this.position.y() + myGlyph.bearing.y() + fontHeigh - fontSize; + float dyD = dyC - myGlyph.sizeTexture.y(); + + float tuA = myGlyph.texturePosStart.x(); + float tuB = tuA + myGlyph.texturePosSize.x(); + float tvC = myGlyph.texturePosStart.y(); + float tvD = tvC + myGlyph.texturePosSize.y(); + + // Clipping and drawing area + if (this.clippingEnable && (dxB < this.clippingPosStart.x() || dxA > this.clippingPosStop.x() || dyC < this.clippingPosStart.y() || dyD > this.clippingPosStop.y())) { + // Nothing to display ... + } else { + if (this.clippingEnable) { + // generate a positions... + final float texSizeX = tuB - tuA; + if (dxA < this.clippingPosStart.x()) { + // clip display + final float drawSize = this.clippingPosStart.x() - dxA; + // update element start display + dxA = this.clippingPosStart.x(); + final float addElement = texSizeX * drawSize / myGlyph.sizeTexture.x(); + // update texture start X Pos + tuA += addElement; + } + if (dxB > this.clippingPosStop.x()) { + // clip display + final float drawSize = dxB - this.clippingPosStop.x(); + // update element start display + dxB = this.clippingPosStop.x(); + final float addElement = texSizeX * drawSize / myGlyph.sizeTexture.x(); + // update texture start X Pos + tuB -= addElement; + } + final float texSizeY = tvC - tvD; + if (dyC > this.clippingPosStop.y()) { + // clip display + final float drawSize = dyC - this.clippingPosStop.y(); + // update element start display + dyC = this.clippingPosStop.y(); + final float addElement = texSizeY * drawSize / myGlyph.sizeTexture.y(); + // update texture start X Pos + tvC -= addElement; + } + if (dyD < this.clippingPosStart.y()) { + // clip display + final float drawSize = this.clippingPosStart.y() - dyD; + // update element start display + dyD = this.clippingPosStart.y(); + final float addElement = texSizeY * drawSize / myGlyph.sizeTexture.y(); + // update texture start X Pos + tvD += addElement; + } + } + if (dxB <= dxA || dyD >= dyC) { + // nothing to do ... + } else /* + * Bitmap position 0------1 | | | | 3------2 + */ + if (this.needDisplay) { + final Vector3f drawPosition0 = new Vector3f((int) dxA, (int) dyC, 0); + final Vector3f drawPosition1 = new Vector3f((int) dxB, (int) dyC, 0); + final Vector3f drawPosition2 = new Vector3f((int) dxB, (int) dyD, 0); + final Vector3f drawPosition3 = new Vector3f((int) dxA, (int) dyD, 0); + /* + * texture Position : 0------1 | | | | 3------2 + */ + final Vector2f texturePos0 = new Vector2f(tuA + this.mode.getValue(), tvC); + final Vector2f texturePos1 = new Vector2f(tuB + this.mode.getValue(), tvC); + final Vector2f texturePos2 = new Vector2f(tuB + this.mode.getValue(), tvD); + final Vector2f texturePos3 = new Vector2f(tuA + this.mode.getValue(), tvD); + + // NOTE : Android does not support the Quads elements ... + /* + * Step 1 : ******** ****** **** ** + * + */ + // set texture coordonates : + this.texturePositions.add(texturePos0); + this.texturePositions.add(texturePos1); + this.texturePositions.add(texturePos2); + // set display positions : + this.pointPositions.add(drawPosition0); + this.pointPositions.add(drawPosition1); + this.pointPositions.add(drawPosition2); + // set the color + this.colors.add(this.color); + this.colors.add(this.color); + this.colors.add(this.color); + /* + * Step 2 : + * + * ** **** ****** ******** + */ + // set texture coordonates : + this.texturePositions.add(texturePos0); + this.texturePositions.add(texturePos2); + this.texturePositions.add(texturePos3); + // set display positions : + this.pointPositions.add(drawPosition0); + this.pointPositions.add(drawPosition2); + this.pointPositions.add(drawPosition3); + // set the color + this.colors.add(this.color); + this.colors.add(this.color); + this.colors.add(this.color); + } + } + } + // move the position : + // Log.debug(" 5 pos=" + this.position + " advance=" + myGlyph.advance.x() + " + // kerningOffset=" + kerningOffset); + this.position = this.position.withX(this.position.x() + myGlyph.advance.x() + kerningOffset); + // Log.debug(" 6 print '" + char-code + "' : start=" + this.sizeDisplayStart + " + // stop=" + this.sizeDisplayStop + " pos=" + this.position); + // Register the previous character + this.previousCharcode = charcode; + this.vbo.flush(); + } + + @Override + public void setFont(String fontName, int fontSize) { + clear(); + // remove old one + final ResourceTexturedFont previousFont = this.font; + if (fontSize <= 0) { + fontSize = Ewol.getContext().getFontDefault().getSize(); + } + if (fontName.equals("")) { + fontName = Ewol.getContext().getFontDefault().getName(); + } + fontName += ":"; + fontName += fontSize; + Log.verbose("plop : " + fontName + " size=" + fontSize + " result :" + fontName); + // link to new one + this.font = ResourceTexturedFont.create(fontName); + if (this.font == null) { + Log.error("Can not get font resource"); + this.font = previousFont; + } + } + + @Override + public void setFontMode(final FontMode mode) { + if (this.font != null) { + this.mode = this.font.getWrappingMode(mode); + } + } + + @Override + public void setFontName(final String fontName) { + // get old size + int fontSize = -1; + if (this.font != null) { + fontSize = this.font.getFontSize(); + } + setFont(fontName, fontSize); + } + + @Override + public void setFontSize(final int fontSize) { + // get old size + String fontName = ""; + if (this.font != null) { + fontName = this.font.getName(); + // Remove the :XX for the size ... + final int pos = fontName.lastIndexOf(':'); + fontName = fontName.substring(0, pos); + } + setFont(fontName, fontSize); + } + +} diff --git a/src/org/atriasoft/ewol/compositing/Text.java b/src/org/atriasoft/ewol/compositing/Text.java deleted file mode 100644 index 2998060..0000000 --- a/src/org/atriasoft/ewol/compositing/Text.java +++ /dev/null @@ -1,414 +0,0 @@ - -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ -package org.atriasoft.ewol.compositing; - -import java.util.ArrayList; -import java.util.List; - -import org.atriasoft.etk.Color; -import org.atriasoft.etk.math.Matrix4f; -import org.atriasoft.etk.math.Vector2f; -import org.atriasoft.etk.math.Vector3f; -import org.atriasoft.ewol.Ewol; -import org.atriasoft.ewol.internal.Log; -import org.atriasoft.ewol.resource.ResourceTexturedFont; -import org.atriasoft.ewol.resource.font.FontMode; -import org.atriasoft.ewol.resource.font.GlyphProperty; -import org.atriasoft.gale.backend3d.OpenGL; - -class Text extends TextBase { - protected ResourceTexturedFont font; // !< Font resources - - List pointPositions = new ArrayList<>(); - List texturePositions = new ArrayList<>(); - List colors = new ArrayList<>(); - - protected float size; - - /** - * generic ructor - * @param _fontName Name of the font that might be loaded - * @param _fontSize size of the font that might be loaded - */ - public Text() { - this(""); - } - - public Text(final String _fontName) { - this(_fontName, -1); - } - - public Text(final String _fontName, final int _fontSize) { - setFont(_fontName, _fontSize); - } - - @Override - public Vector3f calculateSizeChar(final Character _charcode) { - // get a pointer on the glyph property : - GlyphProperty myGlyph = getGlyphPointer(_charcode); - int fontHeigh = (int) getHeight(); - if (myGlyph == null) { - if (this.font == null) { - Log.warning("no Glyph... in no font"); - } else { - Log.warning("no Glyph... in font : " + this.font.getName()); - } - return new Vector3f((float) (0.2), (fontHeigh), (float) (0.0)); - } - // get the kerning ofset : - float kerningOffset = 0.0f; - if (this.kerning == true) { - kerningOffset = myGlyph.kerningGet(this.previousCharcode); - } - - Vector3f outputSize = new Vector3f(myGlyph.advance.x() + kerningOffset, (fontHeigh), 0.0f); - // Register the previous character - this.previousCharcode = _charcode; - return outputSize; - } - - @Override - public void clear() { - // call upper class - super.clear(); - this.texturePositions.clear(); - // set display positions : - this.pointPositions.clear(); - // set the color - this.colors.clear(); - } - - @Override - public void drawD(final boolean _disableDepthTest) { - // draw BG in any case: - // TODO this.vectorialDraw.draw(_disableDepthTest); - - // TODO : do it only one time (when needed ...) - // set texture coordonates : - this.VBO.setVboData(vboIdCoordText, this.texturePositions.toArray(Vector3f[]::new)); - // set display positions : - this.VBO.setVboData(vboIdCoord, this.pointPositions.toArray(Vector2f[]::new)); - // set the color - this.VBO.setVboData(vboIdColor, this.colors.toArray(Color[]::new)); - // TODO : do it only one time (when needed ...) --------- end ------- - - if (this.VBO.bufferSize(TextBase.vboIdCoord) <= 0 || this.font == null) { - // Log.warning("Nothink to draw..."); - return; - } - if (this.font == null) { - Log.warning("no font..."); - return; - } - if (this.GLprogram == null) { - Log.error("No shader ..."); - return; - } - // set Matrix : translation/positionMatrix - Matrix4f tmpMatrix = OpenGL.getMatrix().multiply(this.matrixApply); - this.GLprogram.use(); - this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix); - // Texture : - this.GLprogram.setTexture0(this.GLtexID, this.font.getRendererId()); - this.GLprogram.uniformInt(this.GLtextWidth, this.font.getOpenGlSize().x()); - this.GLprogram.uniformInt(this.GLtextHeight, this.font.getOpenGlSize().x()); - // position: - this.GLprogram.sendAttributePointer(this.GLPosition, this.VBO, TextBase.vboIdCoord); - // Texture: - this.GLprogram.sendAttributePointer(this.GLtexture, this.VBO, TextBase.vboIdCoordText); - // color: - this.GLprogram.sendAttributePointer(this.GLColor, this.VBO, TextBase.vboIdColor); - // Request the draw od the elements : - OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, this.VBO.bufferSize(TextBase.vboIdCoord)); - this.GLprogram.unUse(); - } - - @Override - public void drawMT(final Matrix4f _transformationMatrix, final boolean _enableDepthTest) { - - // draw BG in any case: - // TODO this.vectorialDraw.draw(); - - // TODO : do it only one time (when needed ...) - // set texture coordonates : - this.VBO.setVboData(vboIdCoordText, this.texturePositions.toArray(Vector3f[]::new)); - // set display positions : - this.VBO.setVboData(vboIdCoord, this.pointPositions.toArray(Vector2f[]::new)); - // set the color - this.VBO.setVboData(vboIdColor, this.colors.toArray(Color[]::new)); - // TODO : do it only one time (when needed ...) --------- end ------- - - if (this.VBO.bufferSize(TextBase.vboIdCoord) <= 0 || this.font == null) { - // TODO : set it back ... - // Log.warning("Nothink to draw..."); - return; - } - if (this.font == null) { - Log.warning("no font..."); - return; - } - if (this.GLprogram == null) { - Log.error("No shader ..."); - return; - } - if (_enableDepthTest == true) { - OpenGL.enable(OpenGL.Flag.flag_depthTest); - } - // set Matrix : translation/positionMatrix - Matrix4f projMatrix = OpenGL.getMatrix(); - Matrix4f camMatrix = OpenGL.getCameraMatrix(); - Matrix4f tmpMatrix = projMatrix.multiply(camMatrix).multiply(_transformationMatrix); - this.GLprogram.use(); - this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix); - // Texture: - this.GLprogram.setTexture0(this.GLtexID, this.font.getRendererId()); - this.GLprogram.uniformInt(this.GLtextWidth, this.font.getOpenGlSize().x()); - this.GLprogram.uniformInt(this.GLtextHeight, this.font.getOpenGlSize().x()); - // position: - this.GLprogram.sendAttributePointer(this.GLPosition, this.VBO, TextBase.vboIdCoord); - // Texture: - this.GLprogram.sendAttributePointer(this.GLtexture, this.VBO, TextBase.vboIdCoordText); - // color: - this.GLprogram.sendAttributePointer(this.GLColor, this.VBO, TextBase.vboIdColor); - // Request the draw od the elements: - OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, this.VBO.bufferSize(TextBase.vboIdCoord)); - this.GLprogram.unUse(); - if (_enableDepthTest == true) { - OpenGL.disable(OpenGL.Flag.flag_depthTest); - } - } - - @Override - public GlyphProperty getGlyphPointer(final Character _charcode) { - if (this.font == null) { - Log.warning("no font..."); - return null; - } - return this.font.getGlyph(_charcode, this.mode); - } - - @Override - public float getHeight() { - if (this.font == null) { - Log.warning("no font..."); - return 10.0f; - } - return this.font.getHeight(this.mode); - } - - @Override - public float getSize() { - if (this.font == null) { - Log.warning("no font..."); - return 1.0f; - } - return this.font.getFontSize(); - } - - @Override - public void printChar(final Character _charcode) { - // get a pointer on the glyph property : - GlyphProperty myGlyph = getGlyphPointer(_charcode); - if (myGlyph == null) { - Log.error(" font does not really existed ..."); - return; - } - int fontSize = (int) getSize(); - int fontHeigh = (int) getHeight(); - - // get the kerning ofset : - float kerningOffset = 0; - if (this.kerning == true) { - kerningOffset = myGlyph.kerningGet(this.previousCharcode); - if (kerningOffset != 0) { - // Log.debug("Kerning between : '" + this.previousCharcode + "''" + myGlyph.UVal - // + "' value : " + kerningOffset); - } - } - // 0x01 == 0x20 == ' '; - if (_charcode != 0x01) { - /* - * Bitmap position xA xB yC *------* | | | | yD *------* - */ - float dxA = this.position.x() + myGlyph.bearing.x() + kerningOffset; - float dxB = dxA + myGlyph.sizeTexture.x(); - float dyC = this.position.y() + myGlyph.bearing.y() + fontHeigh - fontSize; - float dyD = dyC - myGlyph.sizeTexture.y(); - - float tuA = myGlyph.texturePosStart.x(); - float tuB = tuA + myGlyph.texturePosSize.x(); - float tvC = myGlyph.texturePosStart.y(); - float tvD = tvC + myGlyph.texturePosSize.y(); - - // Clipping and drawing area - if (this.clippingEnable == true && (dxB < this.clippingPosStart.x() || dxA > this.clippingPosStop.x() - || dyC < this.clippingPosStart.y() || dyD > this.clippingPosStop.y())) { - // Nothing to diplay ... - } else { - if (this.clippingEnable == true) { - // generata positions... - float TexSizeX = tuB - tuA; - if (dxA < this.clippingPosStart.x()) { - // clip display - float drawSize = this.clippingPosStart.x() - dxA; - // update element start display - dxA = this.clippingPosStart.x(); - float addElement = TexSizeX * drawSize / myGlyph.sizeTexture.x(); - // update texture start X Pos - tuA += addElement; - } - if (dxB > this.clippingPosStop.x()) { - // clip display - float drawSize = dxB - this.clippingPosStop.x(); - // update element start display - dxB = this.clippingPosStop.x(); - float addElement = TexSizeX * drawSize / myGlyph.sizeTexture.x(); - // update texture start X Pos - tuB -= addElement; - } - float TexSizeY = tvC - tvD; - if (dyC > this.clippingPosStop.y()) { - // clip display - float drawSize = dyC - this.clippingPosStop.y(); - // update element start display - dyC = this.clippingPosStop.y(); - float addElement = TexSizeY * drawSize / myGlyph.sizeTexture.y(); - // update texture start X Pos - tvC -= addElement; - } - if (dyD < this.clippingPosStart.y()) { - // clip display - float drawSize = this.clippingPosStart.y() - dyD; - // update element start display - dyD = this.clippingPosStart.y(); - float addElement = TexSizeY * drawSize / myGlyph.sizeTexture.y(); - // update texture start X Pos - tvD += addElement; - } - } - if (dxB <= dxA || dyD >= dyC) { - // nothing to do ... - } else { - /* - * Bitmap position 0------1 | | | | 3------2 - */ - if (this.needDisplay == true) { - Vector3f drawPosition0 = new Vector3f((int) dxA, (int) dyC, 0); - Vector3f drawPosition1 = new Vector3f((int) dxB, (int) dyC, 0); - Vector3f drawPosition2 = new Vector3f((int) dxB, (int) dyD, 0); - Vector3f drawPosition3 = new Vector3f((int) dxA, (int) dyD, 0); - /* - * texture Position : 0------1 | | | | 3------2 - */ - Vector2f texturePos0 = new Vector2f(tuA + this.mode.getValue(), tvC); - Vector2f texturePos1 = new Vector2f(tuB + this.mode.getValue(), tvC); - Vector2f texturePos2 = new Vector2f(tuB + this.mode.getValue(), tvD); - Vector2f texturePos3 = new Vector2f(tuA + this.mode.getValue(), tvD); - - // NOTE : Android does not support the Quads elements ... - /* - * Step 1 : ******** ****** **** ** - * - */ - // set texture coordonates : - this.texturePositions.add(texturePos0); - this.texturePositions.add(texturePos1); - this.texturePositions.add(texturePos2); - // set display positions : - this.pointPositions.add(drawPosition0); - this.pointPositions.add(drawPosition1); - this.pointPositions.add(drawPosition2); - // set the color - this.colors.add(this.color); - this.colors.add(this.color); - this.colors.add(this.color); - /* - * Step 2 : - * - * ** **** ****** ******** - */ - // set texture coordonates : - this.texturePositions.add(texturePos0); - this.texturePositions.add(texturePos2); - this.texturePositions.add(texturePos3); - // set display positions : - this.pointPositions.add(drawPosition0); - this.pointPositions.add(drawPosition2); - this.pointPositions.add(drawPosition3); - // set the color - this.colors.add(this.color); - this.colors.add(this.color); - this.colors.add(this.color); - } - } - } - } - // move the position : - // Log.debug(" 5 pos=" + this.position + " advance=" + myGlyph.advance.x() + " - // kerningOffset=" + kerningOffset); - this.position = this.position.withX(this.position.x() + myGlyph.advance.x() + kerningOffset); - // Log.debug(" 6 print '" + charcode + "' : start=" + this.sizeDisplayStart + " - // stop=" + this.sizeDisplayStop + " pos=" + this.position); - // Register the previous character - this.previousCharcode = _charcode; - this.VBO.flush(); - return; - } - - @Override - public void setFont(String _fontName, int _fontSize) { - clear(); - // remove old one - ResourceTexturedFont previousFont = this.font; - if (_fontSize <= 0) { - _fontSize = Ewol.getContext().getFontDefault().getSize(); - } - if (_fontName == "") { - _fontName = Ewol.getContext().getFontDefault().getName(); - } - _fontName += ":"; - _fontName += _fontSize; - Log.verbose("plop : " + _fontName + " size=" + _fontSize + " result :" + _fontName); - // link to new one - this.font = ResourceTexturedFont.create(_fontName); - if (this.font == null) { - Log.error("Can not get font resource"); - this.font = previousFont; - } - } - - @Override - public void setFontMode(final FontMode _mode) { - if (this.font != null) { - this.mode = this.font.getWrappingMode(_mode); - } - } - - @Override - public void setFontName(final String _fontName) { - // get old size - int fontSize = -1; - if (this.font != null) { - fontSize = this.font.getFontSize(); - } - setFont(_fontName, fontSize); - } - - @Override - public void setFontSize(final int _fontSize) { - // get old size - String fontName = ""; - if (this.font != null) { - fontName = this.font.getName(); - // Remove the :XX for the size ... - int pos = fontName.lastIndexOf(':'); - fontName = fontName.substring(0, pos); - } - setFont(fontName, _fontSize); - } - -}; diff --git a/src/org/atriasoft/ewol/compositing/TextBase.java b/src/org/atriasoft/ewol/compositing/TextBase.java index 96b9095..6439e2d 100644 --- a/src/org/atriasoft/ewol/compositing/TextBase.java +++ b/src/org/atriasoft/ewol/compositing/TextBase.java @@ -27,105 +27,93 @@ import org.atriasoft.exml.model.XmlNode; import org.atriasoft.gale.resource.ResourceProgram; import org.atriasoft.gale.resource.ResourceVirtualBufferObject; -enum AligneMode { - alignDisable, alignRight, alignLeft, alignCenter, alignJustify -}; - public abstract class TextBase extends Compositing { - private static final int NB_VBO = 4; + private static final int NBVBO = 4; + protected static int vboIdColor = 2; // Text protected static int vboIdCoord = 0; protected static int vboIdCoordText = 1; - protected static int vboIdColor = 2; protected static int vboIdGlyphLevel = 3; - // TODO set it back later ... protected CompositingDrawing vectorialDraw; //!< - // This is used to draw background selection and other things ... - /* - * public CompositingDrawing getDrawing() { return //TODO this.vectorialDraw; }; - */ - protected int nbCharDisplayed; // !< prevent some error in calculation size. - protected Vector3f sizeDisplayStart = Vector3f.ZERO; // !< The start windows of the display. - protected Vector3f sizeDisplayStop = Vector3f.ZERO; // !< The end windows of the display. - protected boolean needDisplay; // !< This just need the display and not the size rendering. - protected Vector3f position = Vector3f.ZERO; // !< The current position to draw + // previously this line and the center is perform with this one) + protected AlignMode alignment = AlignMode.alignDisable; // !< Current Alignment mode (justify/left/right ...) + protected boolean clippingEnable = false; // !< true if the clipping must be activated protected Vector3f clippingPosStart = Vector3f.ZERO; // !< Clipping start position protected Vector3f clippingPosStop = Vector3f.ZERO; // !< Clipping stop position - protected boolean clippingEnable = false; // !< true if the clipping must be activated - protected Color defaultColorFg = Color.BLACK; // !< The text foreground color - protected Color defaultColorBg = Color.NONE; // !< The text background color - protected Color color = Color.BLACK; // !< The text foreground color protected Color colorBg = Color.NONE; // !< The text background color protected Color colorCursor = Color.BLACK; // !< The text cursor color protected Color colorSelection = Color.OLIVE; // !< The text Selection color - protected FontMode mode = FontMode.Regular; // !< font display property : Regular/Bold/Italic/BoldItalic - protected boolean kerning = true; // !< Kerning enable or disable on the next elements displayed - protected Character previousCharcode; // !< we remember the previous charcode to perform the kerning. @ref Kerning - protected float startTextpos = 0; // !< start position of the Alignement (when \n the text return at this - // position) - protected float stopTextPos = 0; // !< end of the alignement (when a string is too hight it cut at the word - // previously this line and the center is perform with this one) - protected AligneMode alignement = AligneMode.alignDisable; // !< Current Alignement mode (justify/left/right ...) - protected ResourceProgram GLprogram; // !< pointer on the opengl display program - protected int GLPosition = -1; // !< openGL id on the element (vertex buffer) - protected int GLMatrix = -1; // !< openGL id on the element (transformation matrix) - protected int GLColor = -1; // !< openGL id on the element (color buffer) - protected int GLtexture = -1; // !< openGL id on the element (Texture position) - protected int GLtexID = -1; // !< openGL id on the element (texture ID) - protected int GLtextWidth = -1; // !< openGL Id on the texture width - protected int GLtextHeight = -1; // !< openGL Id on the texture height - protected int selectionStartPos = -100; // !< start position of the Selection (if == this.cursorPos ==> no // selection) protected int cursorPos = -100; // !< Cursor position (default no cursor == > -100) - protected ResourceVirtualBufferObject VBO; + protected Color defaultColorBg = Color.NONE; // !< The text background color + protected Color defaultColorFg = Color.BLACK; // !< The text foreground color // this section is reserved for HTML parsing and display: - public String htmlCurrrentLine = ""; // !< current line for HTML display + public String htmlCurrentLine = ""; // !< current line for HTML display + public List htmlDecoration = new ArrayList<>(); // !< current decoration for the HTML display public TextDecoration htmlDecoTmp = new TextDecoration(); // !< current decoration - + protected boolean kerning = true; // !< Kerning enable or disable on the next elements displayed + protected FontMode mode = FontMode.Regular; // !< font display property : Regular/Bold/Italic/BoldItalic + protected int nbCharDisplayed; // !< prevent some error in calculation size. + protected boolean needDisplay; // !< This just need the display and not the size rendering. + protected int oGLColor = -1; // !< openGL id on the element (color buffer) + protected int oGLMatrix = -1; // !< openGL id on the element (transformation matrix) + protected int oGLPosition = -1; // !< openGL id on the element (vertex buffer) + protected ResourceProgram oGLprogram; // !< pointer on the opengl display program + protected int oGLtexID = -1; // !< openGL id on the element (texture ID) + protected int oGLtextHeight = -1; // !< openGL Id on the texture height + protected int oGLtexture = -1; // !< openGL id on the element (Texture position) + protected int oGLtextWidth = -1; // !< openGL Id on the texture width + protected Vector3f position = Vector3f.ZERO; // !< The current position to draw + protected Character previousCharcode; // !< we remember the previous charcode to perform the kerning. @ref Kerning + protected int selectionStartPos = -100; // !< start position of the Selection (if == this.cursorPos ==> no + protected Vector3f sizeDisplayStart = Vector3f.ZERO; // !< The start windows of the display. + protected Vector3f sizeDisplayStop = Vector3f.ZERO; // !< The end windows of the display. + protected float startTextPos = 0; // !< start position of the Alignment (when \n the text return at this + // position) + protected float stopTextPos = 0; // !< end of the alignment (when a string is too height it cut at the word + protected ResourceVirtualBufferObject vbo; + protected CompositingDrawing vectorialDraw = new CompositingDrawing(); + /** * generic constructor */ public TextBase() { this(new Uri("DATA", "text.vert", "ewol"), new Uri("DATA", "text.frag", "ewol")); } - - public TextBase(final Uri _vertexShader, final Uri _fragmentShader) { - this(_vertexShader, _fragmentShader, true); + + public TextBase(final Uri vertexShader, final Uri fragmentShader) { + this(vertexShader, fragmentShader, true); } - - public TextBase(final Uri _vertexShader, final Uri _fragmentShader, final boolean _loadProgram) { - if (_loadProgram == true) { - loadProgram(_vertexShader, _fragmentShader); + + public TextBase(final Uri vertexShader, final Uri fragmentShader, final boolean loadProgram) { + if (loadProgram) { + loadProgram(vertexShader, fragmentShader); } // Create the VBO: - this.VBO = ResourceVirtualBufferObject.create(NB_VBO); - if (this.VBO == null) { - Log.error("can not instanciate VBO ..."); - return; - } + this.vbo = ResourceVirtualBufferObject.create(TextBase.NBVBO); // TO facilitate some debugs we add a name of the VBO: - this.VBO.setName("[VBO] of super.TextBase"); + this.vbo.setName("[VBO] of super.TextBase"); } - + /** * calculate a theoric charcode size - * @param _charcode The Unicode value to calculate dimention. + * @param charcode The Unicode value to calculate dimention. * @return The theoric size used. */ - public Vector3f calculateSize(final Character _charcode) { - return calculateSizeChar(_charcode); + public Vector3f calculateSize(final Character charcode) { + return calculateSizeChar(charcode); } - + /** * calculate a theoric text size - * @param _text The string to calculate dimention. + * @param text The string to calculate dimention. * @return The theoric size used. */ - public Vector3f calculateSize(final String _text) { + public Vector3f calculateSize(final String text) { Vector3f outputSize = Vector3f.ZERO; - for (int iii = 0; iii < _text.length(); iii++) { - Vector3f tmpp = calculateSize(_text.charAt(iii)); + for (int iii = 0; iii < text.length(); iii++) { + final Vector3f tmpp = calculateSize(text.charAt(iii)); if (outputSize.y() == 0) { outputSize = outputSize.withY(tmpp.y()); } @@ -133,59 +121,56 @@ public abstract class TextBase extends Compositing { } return outputSize; } - + // ! @previous - public abstract Vector3f calculateSizeChar(Character _charcode); - + public abstract Vector3f calculateSizeChar(Character charcode); + /** * calculate a theoric text size - * @param _text The string to calculate dimention. + * @param text The string to calculate dimention. * @return The theoric size used. */ - public Vector3f calculateSizeDecorated(final String _text) { - if (_text.length() == 0) { + public Vector3f calculateSizeDecorated(final String text) { + if (text.length() == 0) { return Vector3f.ZERO; } - + String tmpData = "\n"; - tmpData += _text; + tmpData += text; tmpData += "\n\n"; - Vector3f tmpVal = calculateSizeHTML(tmpData); - return tmpVal; + return calculateSizeHTML(tmpData); } - + /** * calculate a theoric text size - * @param _text The string to calculate dimention. + * @param text The string to calculate dimention. * @return The theoric size used. */ - public Vector3f calculateSizeHTML(final String _text) { + public Vector3f calculateSizeHTML(final String text) { // remove intermediate result reset(); // Log.debug(" 0 size for=\n" + text); // disable display system this.needDisplay = false; - + setPos(Vector3f.ZERO); // same as print without the end display ... - printHTML(_text); + printHTML(text); // Log.debug(" 1 Start pos=" + this.sizeDisplayStart); // Log.debug(" 1 Stop pos=" + this.sizeDisplayStop); - + // get the last elements this.sizeDisplayStop = Vector3f.max(this.position, this.sizeDisplayStop); this.sizeDisplayStart = Vector3f.min(this.position, this.sizeDisplayStop); - + // Log.debug(" 2 Start pos=" + this.sizeDisplayStart); // Log.debug(" 2 Stop pos=" + this.sizeDisplayStop); // set back the display system this.needDisplay = true; - - return new Vector3f(this.sizeDisplayStop.x() - this.sizeDisplayStart.x(), - this.sizeDisplayStop.y() - this.sizeDisplayStart.y(), - this.sizeDisplayStop.z() - this.sizeDisplayStart.z()); + + return new Vector3f(this.sizeDisplayStop.x() - this.sizeDisplayStart.x(), this.sizeDisplayStop.y() - this.sizeDisplayStart.y(), this.sizeDisplayStop.z() - this.sizeDisplayStart.z()); } - + /** * clear all the registered element in the current element */ @@ -194,20 +179,20 @@ public abstract class TextBase extends Compositing { // call upper class super.clear(); // remove sub draw system - // TODO this.vectorialDraw.clear(); + this.vectorialDraw.clear(); // reset Buffer: - this.VBO.clear(); + this.vbo.clear(); // reset temporal variables: reset(); } - + /** * disable the alignement system */ public void disableAlignement() { - this.alignement = AligneMode.alignDisable; + this.alignment = AlignMode.alignDisable; } - + /** * remove the cursor display */ @@ -215,116 +200,119 @@ public abstract class TextBase extends Compositing { this.selectionStartPos = -100; this.cursorPos = -100; } - + /** * draw All the registered text in the current element on openGL */ @Override - public void draw(final boolean _disableDepthTest) { - drawD(_disableDepthTest); + public void draw(final boolean disableDepthTest) { + drawD(disableDepthTest); } - + // ! @previous - public void draw(final Matrix4f _transformationMatrix, final boolean _enableDepthTest) { - drawMT(_transformationMatrix, _enableDepthTest); + public void draw(final Matrix4f transformationMatrix, final boolean enableDepthTest) { + drawMT(transformationMatrix, enableDepthTest); } - + /** * draw All the refistered text in the current element on openGL */ - public abstract void drawD(final boolean _disableDepthTest);; - + public abstract void drawD(final boolean disableDepthTest); + // ! @previous - public abstract void drawMT(final Matrix4f _transformationMatrix, final boolean _enableDepthTest); - + public abstract void drawMT(final Matrix4f transformationMatrix, final boolean enableDepthTest); + /** - * calculate the element number that is the first out the alignement + * calculate the element number that is the first out the alignment * range (start at the specify ID, and use start pos with current one) - * @param _text The string that might be parsed. - * @param _start The first elemnt that might be used to calculate. - * @param _stop The last Id availlable in the current string. - * @param _space Number of space in the string. - * @param _freespace This represent the number of pixel present in the + * @param text The string that might be parsed. + * @param start The first element that might be used to calculate. + * @param stop The last Id available in the current string. + * @param space Number of space in the string. + * @param freeSpace This represent the number of pixel present in the * right white space. - * @return true if the rifht has free space that can be use for jystify. - * @return false if we find '\n' + * @return true if the right has free space that can be use for justify. + * false if we find '\n' */ - public boolean extrapolateLastId(final String _text, final int _start, int _stop, int _space, int _freeSpace) { + public boolean extrapolateLastId(final String text, final int start, int stop, int space, int freeSpace) { // store previous : - Character storePrevious = this.previousCharcode; - - _stop = _text.length(); - _space = 0; - - int lastSpacePosition = _start; + final Character storePrevious = this.previousCharcode; + + stop = text.length(); + space = 0; + + int lastSpacePosition = start; int lastSpacefreeSize = 0; - + float endPos = this.position.x(); boolean endOfLine = false; - + float stopPosition = this.stopTextPos; - if (this.needDisplay == false || this.stopTextPos == this.startTextpos) { - stopPosition = this.startTextpos + 3999999999.0f; + if (!this.needDisplay || this.stopTextPos == this.startTextPos) { + stopPosition = this.startTextPos + 3999999999.0f; } - - for (int iii = _start; iii < _text.length(); iii++) { - Vector3f tmpSize = calculateSize(_text.charAt(iii)); - // check oveflow : + + for (int iii = start; iii < text.length(); iii++) { + final Vector3f tmpSize = calculateSize(text.charAt(iii)); + // check overflow : if (endPos + tmpSize.x() > stopPosition) { - _stop = iii; + stop = iii; break; } // save number of space : - if (_text.charAt(iii) == Character.SPACE_SEPARATOR) { - _space++; + if (text.charAt(iii) == Character.SPACE_SEPARATOR) { + space++; lastSpacePosition = iii; lastSpacefreeSize = (int) (stopPosition - endPos); - } else if (_text.charAt(iii) == Character.LINE_SEPARATOR) { - _stop = iii; + } else if (text.charAt(iii) == Character.LINE_SEPARATOR) { + stop = iii; endOfLine = true; break; } // update local size : endPos += tmpSize.x(); } - _freeSpace = (int) (stopPosition - endPos); - // retore previous : + freeSpace = (int) (stopPosition - endPos); + // restore previous : this.previousCharcode = storePrevious; // need to align left or right ... - if (_stop == (long) _text.length()) { + if (stop == (long) text.length()) { return true; - } else { - if (endOfLine) { - return true; - } else { - if (_space == 0) { - return true; - } - _stop = lastSpacePosition; - _freeSpace = lastSpacefreeSize; - return false; - } } - }; - + if (endOfLine) { + return true; + } + if (space == 0) { + return true; + } + stop = lastSpacePosition; + freeSpace = lastSpacefreeSize; + return false; + } + /** - * This generate the line return == > it return to the alignement + * This generate the line return == > it return to the alignment * position start and at the correct line position ==> it might be use to * not know the line height */ public void forceLineReturn() { // reset position : - setPos(new Vector3f(this.startTextpos, this.position.y() - getHeight(), 0)); + setPos(new Vector3f(this.startTextPos, this.position.y() - getHeight(), 0)); } - + /** - * get the current alignement property - * @return the curent alignement type + * get the current alignment property + * @return the current alignment type */ - public AligneMode getAlignement() { - return this.alignement; - }; - + public AlignMode getAlignment() { + return this.alignment; + } + + // This is used to draw background selection and other things ... + public CompositingDrawing getDrawing() { + return this.vectorialDraw; + } + /** * get the current font mode * @return The font mode applied @@ -332,11 +320,11 @@ public abstract class TextBase extends Compositing { public FontMode getFontMode() { return this.mode; } - - public abstract GlyphProperty getGlyphPointer(Character _charcode); - - public abstract float getHeight();; - + + public abstract GlyphProperty getGlyphPointer(Character charcode); + + public abstract float getHeight(); + /** * get the current display position (sometime needed in the gui control) * @return the current position. @@ -344,122 +332,123 @@ public abstract class TextBase extends Compositing { public Vector3f getPos() { return this.position; } - + public abstract float getSize(); - + /** * add a line with the current this.htmlDecoTmp decoration - * @param _data The cuurent data to add. + * @param data The cuurent data to add. */ - public void htmlAddData(final String _data) { - if (this.htmlCurrrentLine.length() > 0 - && this.htmlCurrrentLine.charAt(this.htmlCurrrentLine.length() - 1) != Character.SPACE_SEPARATOR) { - this.htmlCurrrentLine += Character.SPACE_SEPARATOR; + public void htmlAddData(final String data) { + if (this.htmlCurrentLine.length() > 0 && this.htmlCurrentLine.charAt(this.htmlCurrentLine.length() - 1) != Character.SPACE_SEPARATOR) { + this.htmlCurrentLine += Character.SPACE_SEPARATOR; if (this.htmlDecoration.size() > 0) { - TextDecoration tmp = this.htmlDecoration.get(this.htmlDecoration.size() - 1); + final TextDecoration tmp = this.htmlDecoration.get(this.htmlDecoration.size() - 1); this.htmlDecoration.add(tmp); } else { this.htmlDecoration.add(this.htmlDecoTmp); } } - this.htmlCurrrentLine += _data; - for (int iii = 0; iii < _data.length(); iii++) { + this.htmlCurrentLine += data; + for (int iii = 0; iii < data.length(); iii++) { this.htmlDecoration.add(this.htmlDecoTmp); } - }; - + } + /** * draw the current line */ public void htmlFlush() { - if (this.htmlCurrrentLine.length() > 0) { - print(this.htmlCurrrentLine, this.htmlDecoration); + if (this.htmlCurrentLine.length() > 0) { + print(this.htmlCurrentLine, this.htmlDecoration); } - this.htmlCurrrentLine = ""; + this.htmlCurrentLine = ""; this.htmlDecoration.clear(); } - + /** * load the openGL program and get all the ID needed */ - public void loadProgram(final Uri _vertexShader, final Uri _fragmentShader) { - ResourceProgram old = this.GLprogram; - this.GLprogram = ResourceProgram.create(_vertexShader, _fragmentShader); - if (this.GLprogram != null) { - this.GLPosition = this.GLprogram.getAttribute("EW_coord3d"); - this.GLColor = this.GLprogram.getAttribute("EW_color"); - this.GLtexture = this.GLprogram.getAttribute("EW_texture2d"); - this.GLMatrix = this.GLprogram.getUniform("EW_MatrixTransformation"); - this.GLtexID = this.GLprogram.getUniform("EW_texID"); - this.GLtextWidth = this.GLprogram.getUniform("EW_texWidth"); - this.GLtextHeight = this.GLprogram.getUniform("EW_texHeight"); + public void loadProgram(final Uri vertexShader, final Uri fragmentShader) { + ResourceProgram old = this.oGLprogram; + this.oGLprogram = ResourceProgram.create(vertexShader, fragmentShader); + if (this.oGLprogram != null) { + this.oGLPosition = this.oGLprogram.getAttribute("EWcoord3d"); + this.oGLColor = this.oGLprogram.getAttribute("EWcolor"); + this.oGLtexture = this.oGLprogram.getAttribute("EWtexture2d"); + this.oGLMatrix = this.oGLprogram.getUniform("EWMatrixTransformation"); + this.oGLtexID = this.oGLprogram.getUniform("EWtexID"); + this.oGLtextWidth = this.oGLprogram.getUniform("EWtexWidth"); + this.oGLtextHeight = this.oGLprogram.getUniform("EWtexHeight"); } else { Log.error("Can not load the program => create previous one..."); - this.GLprogram = old; + this.oGLprogram = old; old = null; } - }; - + } + /** * This parse a tinyXML node (void pointer to permit to hide tiny XML in * include). - * @param _element the exml element. + * @param element the exml element. */ - public void parseHtmlNode(final XmlElement _element) { - for (XmlNode it : _element.getNodes()) { - if (it.isComment() == true) { + public void parseHtmlNode(final XmlElement element) { + for (final XmlNode it : element.getNodes()) { + if (it.isComment()) { // nothing to do ... continue; - } else if (it.isText() == true) { + } + if (it.isText()) { htmlAddData(it.getValue()); Log.verbose("XML add : " + it.getValue()); continue; - } else if (it.isElement() == false) { + } + if (!it.isElement()) { Log.error("node not suported type : " + it.getType() + " val='" + it.getValue() + "'"); continue; } - XmlElement elem = (XmlElement) it; - String lowercaseValue = elem.getValue().toLowerCase(); - if (lowercaseValue.contentEquals("br") == true) { + final XmlElement elem = (XmlElement) it; + final String lowercaseValue = elem.getValue().toLowerCase(); + if (lowercaseValue.contentEquals("br")) { htmlFlush(); Log.verbose("XML flush newLine"); forceLineReturn(); - } else if (lowercaseValue.contentEquals("font") == true) { + } else if (lowercaseValue.contentEquals("font")) { Log.verbose("XML Font ..."); - TextDecoration tmpDeco = this.htmlDecoTmp; + final TextDecoration tmpDeco = this.htmlDecoTmp; if (elem.existAttribute("color")) { try { - String colorValue = elem.getAttribute("color"); + final String colorValue = elem.getAttribute("color"); if (colorValue.length() != 0) { this.htmlDecoTmp = this.htmlDecoTmp.withFG(Color.valueOf(colorValue)); } - } catch (ExmlAttributeDoesNotExist e) { + } catch (final ExmlAttributeDoesNotExist e) { Log.error("Can not get attribute 'color' in XML:" + e.getMessage()); e.printStackTrace(); - } catch (Exception e) { + } catch (final Exception e) { Log.error("Can not parse attribute 'color' in XML:" + e.getMessage()); e.printStackTrace(); } } if (elem.existAttribute("colorBg")) { try { - String colorValue = elem.getAttribute("colorBg"); + final String colorValue = elem.getAttribute("colorBg"); if (colorValue.length() != 0) { this.htmlDecoTmp = this.htmlDecoTmp.withBG(Color.valueOf(colorValue)); } - } catch (ExmlAttributeDoesNotExist e) { + } catch (final ExmlAttributeDoesNotExist e) { Log.error("Can not get attribute 'colorBg' in XML:" + e.getMessage()); e.printStackTrace(); - } catch (Exception e) { + } catch (final Exception e) { Log.error("Can not parse attribute 'colorBg' in XML:" + e.getMessage()); e.printStackTrace(); } } parseHtmlNode(elem); this.htmlDecoTmp = tmpDeco; - } else if (lowercaseValue.contentEquals("b") == true || lowercaseValue.contentEquals("bold") == true) { + } else if (lowercaseValue.contentEquals("b") || lowercaseValue.contentEquals("bold")) { Log.verbose("XML bold ..."); - TextDecoration tmpDeco = this.htmlDecoTmp; + final TextDecoration tmpDeco = this.htmlDecoTmp; if (this.htmlDecoTmp.mode() == FontMode.Regular) { this.htmlDecoTmp = this.htmlDecoTmp.withMode(FontMode.Bold); } else if (this.htmlDecoTmp.mode() == FontMode.Italic) { @@ -467,9 +456,9 @@ public abstract class TextBase extends Compositing { } parseHtmlNode(elem); this.htmlDecoTmp = tmpDeco; - } else if (lowercaseValue.contentEquals("i") == true || lowercaseValue.contentEquals("italic") == true) { + } else if (lowercaseValue.contentEquals("i") || lowercaseValue.contentEquals("italic")) { Log.verbose("XML italic ..."); - TextDecoration tmpDeco = this.htmlDecoTmp; + final TextDecoration tmpDeco = this.htmlDecoTmp; if (this.htmlDecoTmp.mode() == FontMode.Regular) { this.htmlDecoTmp = this.htmlDecoTmp.withMode(FontMode.Italic); } else if (this.htmlDecoTmp.mode() == FontMode.Bold) { @@ -477,84 +466,83 @@ public abstract class TextBase extends Compositing { } parseHtmlNode(elem); this.htmlDecoTmp = tmpDeco; - } else if (lowercaseValue.contentEquals("u") == true || lowercaseValue.contentEquals("underline") == true) { + } else if (lowercaseValue.contentEquals("u") || lowercaseValue.contentEquals("underline")) { Log.verbose("XML underline ..."); parseHtmlNode(elem); - } else if (lowercaseValue.contentEquals("p") == true || lowercaseValue.contentEquals("paragraph") == true) { + } else if (lowercaseValue.contentEquals("p") || lowercaseValue.contentEquals("paragraph")) { Log.verbose("XML paragraph ..."); htmlFlush(); - this.alignement = AligneMode.alignLeft; + this.alignment = AlignMode.alignLeft; forceLineReturn(); parseHtmlNode(elem); forceLineReturn(); - } else if (lowercaseValue.contentEquals("center") == true) { + } else if (lowercaseValue.contentEquals("center")) { Log.verbose("XML center ..."); htmlFlush(); - this.alignement = AligneMode.alignCenter; + this.alignment = AlignMode.alignCenter; parseHtmlNode(elem); - } else if (lowercaseValue.contentEquals("left") == true) { + } else if (lowercaseValue.contentEquals("left")) { Log.verbose("XML left ..."); htmlFlush(); - this.alignement = AligneMode.alignLeft; + this.alignment = AlignMode.alignLeft; parseHtmlNode(elem); - } else if (lowercaseValue.contentEquals("right") == true) { + } else if (lowercaseValue.contentEquals("right")) { Log.verbose("XML right ..."); htmlFlush(); - this.alignement = AligneMode.alignRight; + this.alignment = AlignMode.alignRight; parseHtmlNode(elem); - } else if (lowercaseValue.contentEquals("justify") == true) { + } else if (lowercaseValue.contentEquals("justify")) { Log.verbose("XML justify ..."); htmlFlush(); - this.alignement = AligneMode.alignJustify; + this.alignment = AlignMode.alignJustify; parseHtmlNode(elem); } else { Log.error("node not suported type: " + elem.getType() + " val='" + elem.getValue() + "'"); } } } - + /** * display a compleat string in the current element. - * @param _text The string to display. + * @param text The string to display. */ - public void print(final String _text) { - List decorationEmpty = new ArrayList<>(); - print(_text, decorationEmpty); + public void print(final String text) { + final List decorationEmpty = new ArrayList<>(); + print(text, decorationEmpty); } - + /** * display a compleat string in the current element whith specific * decorations (advence mode). - * @param _text The string to display. - * @param _decoration The text decoration for the text that might be display + * @param text The string to display. + * @param decoration The text decoration for the text that might be display * (if the vector is smaller, the last parameter is get) */ - public void print(final String _text, final List _decoration) { + public void print(final String text, final List decoration) { Color tmpFg = this.color; Color tmpBg = this.colorBg; - if (this.alignement == AligneMode.alignDisable) { + if (this.alignment == AlignMode.alignDisable) { // Log.debug(" 1 print in not alligned mode : start=" + this.sizeDisplayStart + // " stop=" + this.sizeDisplayStop + " pos=" + this.position); // display the cursor if needed (if it is at the start position...) - if (this.needDisplay == true) { + if (this.needDisplay) { if (0 == this.cursorPos) { - // TODO this.vectorialDraw.setPos(this.position); + this.vectorialDraw.setPos(this.position); setColorBg(this.colorCursor); printCursor(false); } } // note this is faster when nothing is requested ... - for (int iii = 0; iii < _text.length(); iii++) { + for (int iii = 0; iii < text.length(); iii++) { // check if ve have decoration - if (iii < _decoration.size()) { - tmpFg = _decoration.get(iii).colorFG(); - tmpBg = _decoration.get(iii).colorBG(); - setFontMode(_decoration.get(iii).mode()); + if (iii < decoration.size()) { + tmpFg = decoration.get(iii).colorFG(); + tmpBg = decoration.get(iii).colorBG(); + setFontMode(decoration.get(iii).mode()); } // if real display : ( not display is for size calculation) - if (this.needDisplay == true) { - if ((this.selectionStartPos - 1 < (long) iii && (long) iii <= this.cursorPos - 1) - || (this.selectionStartPos - 1 >= (long) iii && (long) iii > this.cursorPos - 1)) { + if (this.needDisplay) { + if ((this.selectionStartPos - 1 < (long) iii && (long) iii <= this.cursorPos - 1) || (this.selectionStartPos - 1 >= (long) iii && (long) iii > this.cursorPos - 1)) { setColor(Color.BLACK); setColorBg(this.colorSelection); } else { @@ -562,23 +550,21 @@ public abstract class TextBase extends Compositing { setColorBg(tmpBg); } } - if (this.needDisplay == true && this.colorBg.a() != 0) { - Vector3f pos = this.position; - // TODO this.vectorialDraw.setPos(pos); - printChar(_text.charAt(iii)); - float fontHeigh = getHeight(); - // TODO - // this.vectorialDraw.rectangleWidth(Vector3f(this.position.x()-pos.x(),fontHeigh,0.0f) - // ); + if (this.needDisplay && this.colorBg.a() != 0) { + final Vector3f pos = this.position; + this.vectorialDraw.setPos(pos); + printChar(text.charAt(iii)); + final float fontHeigh = getHeight(); + this.vectorialDraw.rectangleWidth(new Vector3f(this.position.x() - pos.x(), fontHeigh, 0.0f)); this.nbCharDisplayed++; } else { - printChar(_text.charAt(iii)); + printChar(text.charAt(iii)); this.nbCharDisplayed++; } // display the cursor if needed (if it is at the other position...) - if (this.needDisplay == true) { + if (this.needDisplay) { if ((long) iii == this.cursorPos - 1) { - // TODO this.vectorialDraw.setPos(this.position); + this.vectorialDraw.setPos(this.position); setColorBg(this.colorCursor); printCursor(false); } @@ -593,54 +579,55 @@ public abstract class TextBase extends Compositing { if (this.stopTextPos < this.position.x()) { forceLineReturn(); } - float basicSpaceWidth = calculateSize(' ').x(); + final float basicSpaceWidth = calculateSize(' ').x(); int currentId = 0; - int stop = 0; - int space = 0; - int freeSpace = 0; - while (currentId < (long) _text.length()) { - boolean needNoJustify = extrapolateLastId(_text, currentId, stop, space, freeSpace); + final int stop = 0; + final int space = 0; + final int freeSpace = 0; + while (currentId < (long) text.length()) { + final boolean needNoJustify = extrapolateLastId(text, currentId, stop, space, freeSpace); float interpolation = basicSpaceWidth; - switch (this.alignement) { - case alignJustify: - if (needNoJustify == false) { - interpolation += (float) freeSpace / (float) (space - 1); - } - break; - case alignDisable: // must not came from here ... - case alignLeft: - // nothing to do ... - break; - case alignRight: - if (this.needDisplay == true) { - // Move the first char at the right : - setPos(new Vector3f(this.position.x() + freeSpace, this.position.y(), this.position.z())); - } - break; - case alignCenter: - if (this.needDisplay == true) { - // Move the first char at the right : - setPos(new Vector3f(this.position.x() + freeSpace / 2, this.position.y(), this.position.z())); - } - break; + switch (this.alignment) { + case alignJustify: + if (!needNoJustify) { + interpolation += (float) freeSpace / (float) (space - 1); + } + break; + case alignDisable: // must not came from here ... + case alignLeft: + // nothing to do ... + break; + case alignRight: + if (this.needDisplay) { + // Move the first char at the right : + setPos(new Vector3f(this.position.x() + freeSpace, this.position.y(), this.position.z())); + } + break; + case alignCenter: + if (this.needDisplay) { + // Move the first char at the right : + setPos(new Vector3f(this.position.x() + freeSpace / 2, this.position.y(), this.position.z())); + } + break; + default: + break; } // display all the elements - if (this.needDisplay == true && this.cursorPos == 0) { - // TODO this.vectorialDraw.setPos(this.position); + if (this.needDisplay && this.cursorPos == 0) { + this.vectorialDraw.setPos(this.position); setColorBg(this.colorCursor); printCursor(false); } - for (int iii = currentId; (long) iii < stop && iii < _text.length(); iii++) { - float fontHeigh = getHeight(); + for (int iii = currentId; (long) iii < stop && iii < text.length(); iii++) { + final float fontHeigh = getHeight(); // get specific decoration if provided - if (iii < _decoration.size()) { - tmpFg = _decoration.get(iii).colorFG(); - tmpBg = _decoration.get(iii).colorBG(); - setFontMode(_decoration.get(iii).mode()); + if (iii < decoration.size()) { + tmpFg = decoration.get(iii).colorFG(); + tmpBg = decoration.get(iii).colorBG(); + setFontMode(decoration.get(iii).mode()); } - if (this.needDisplay == true) { - if ((this.selectionStartPos - 1 < (long) iii && (long) iii <= this.cursorPos - 1) - || (this.selectionStartPos - 1 >= (long) iii && (long) iii > this.cursorPos - 1)) { + if (this.needDisplay) { + if ((this.selectionStartPos - 1 < (long) iii && (long) iii <= this.cursorPos - 1) || (this.selectionStartPos - 1 >= (long) iii && (long) iii > this.cursorPos - 1)) { setColor(Color.BLACK); setColorBg(this.colorSelection); } else { @@ -649,35 +636,30 @@ public abstract class TextBase extends Compositing { } } // special for the justify mode - if (_text.charAt(iii) == Character.SPACE_SEPARATOR) { + if (text.charAt(iii) == Character.SPACE_SEPARATOR) { // Log.debug(" generateString : \" \""); - if (this.needDisplay == true && this.colorBg.a() != 0) { - // TODO this.vectorialDraw.setPos(this.position); + if (this.needDisplay && this.colorBg.a() != 0) { + this.vectorialDraw.setPos(this.position); } // Must generate a dynamic space : setPos(new Vector3f(this.position.x() + interpolation, this.position.y(), this.position.z())); - if (this.needDisplay == true && this.colorBg.a() != 0) { - // TODO this.vectorialDraw.rectangleWidth(Vector3f(interpolation,fontHeigh,0.0f) - // ); + if (this.needDisplay && this.colorBg.a() != 0) { + this.vectorialDraw.rectangleWidth(new Vector3f(interpolation, fontHeigh, 0.0f)); } + } else // Log.debug(" generateString : \"" + (char)text[iii] + "\""); + if (this.needDisplay && this.colorBg.a() != 0) { + final Vector3f pos = this.position; + this.vectorialDraw.setPos(pos); + printChar(text.charAt(iii)); + this.vectorialDraw.rectangleWidth(new Vector3f(this.position.x() - pos.x(), fontHeigh, 0.0f)); + this.nbCharDisplayed++; } else { - // Log.debug(" generateString : \"" + (char)text[iii] + "\""); - if (this.needDisplay == true && this.colorBg.a() != 0) { - Vector3f pos = this.position; - // TODO this.vectorialDraw.setPos(pos); - printChar(_text.charAt(iii)); - // TODO - // this.vectorialDraw.rectangleWidth(Vector3f(this.position.x()-pos.x(),fontHeigh,0.0f) - // ); - this.nbCharDisplayed++; - } else { - printChar(_text.charAt(iii)); - this.nbCharDisplayed++; - } + printChar(text.charAt(iii)); + this.nbCharDisplayed++; } - if (this.needDisplay == true) { + if (this.needDisplay) { if ((long) iii == this.cursorPos - 1) { - // TODO this.vectorialDraw.setPos(this.position); + this.vectorialDraw.setPos(this.position); setColorBg(this.colorCursor); printCursor(false); } @@ -685,15 +667,15 @@ public abstract class TextBase extends Compositing { } if (currentId == stop) { currentId++; - } else if (_text.charAt(stop) == Character.SPACE_SEPARATOR) { + } else if (text.charAt(stop) == Character.SPACE_SEPARATOR) { currentId = stop + 1; // reset position : - setPos(new Vector3f(this.startTextpos, this.position.y() - getHeight(), this.position.z())); + setPos(new Vector3f(this.startTextPos, this.position.y() - getHeight(), this.position.z())); this.nbCharDisplayed++; - } else if (_text.charAt(stop) == Character.LINE_SEPARATOR) { + } else if (text.charAt(stop) == Character.LINE_SEPARATOR) { currentId = stop + 1; // reset position : - setPos(new Vector3f(this.startTextpos, this.position.y() - getHeight(), this.position.z())); + setPos(new Vector3f(this.startTextPos, this.position.y() - getHeight(), this.position.z())); this.nbCharDisplayed++; } else { currentId = stop; @@ -703,35 +685,33 @@ public abstract class TextBase extends Compositing { // " stop=" + this.sizeDisplayStop + " pos=" + this.position); } } - + /** * display the current char in the current element (note that the kerning * is availlable if the position is not changed) - * @param _charcode Char that might be dispalyed + * @param charcode Char that might be dispalyed */ - public abstract void printChar(Character _charcode); - + public abstract void printChar(Character charcode); + /** * draw a cursor at the specify position - * @param _isInsertMode True if the insert mode is activated - * @param _cursorSize The sizae of the cursor that might be set when insert - * mode is set [default 20] + * @param isInsertMode True if the insert mode is activated */ - public void printCursor(final boolean _isInsertMode) { - printCursor(_isInsertMode, 20.0f); + public void printCursor(final boolean isInsertMode) { + printCursor(isInsertMode, 20.0f); } - - public void printCursor(final boolean _isInsertMode, final float _cursorSize) { - int fontHeigh = (int) getHeight(); - if (true == _isInsertMode) { - // TODO this.vectorialDraw.rectangleWidth(Vector3f(_cursorSize, fontHeigh, 0) ); + + public void printCursor(final boolean isInsertMode, final float cursorSize) { + final int fontHeigh = (int) getHeight(); + if (isInsertMode) { + this.vectorialDraw.rectangleWidth(new Vector3f(cursorSize, fontHeigh, 0)); } else { - // TODO this.vectorialDraw.setThickness(2); - // TODO this.vectorialDraw.lineRel( Vector3f(0, fontHeigh, 0) ); - // TODO this.vectorialDraw.setThickness(0); + this.vectorialDraw.setThickness(2); + this.vectorialDraw.lineRel(new Vector3f(0, fontHeigh, 0)); + this.vectorialDraw.setThickness(0); } - }; - + } + /** * display a compleat string in the current element with the generic * decoration specification. (basic html data) @@ -757,17 +737,17 @@ public abstract class TextBase extends Compositing { * * @note This is parsed with tiny xml, then be carfull that the XML is correct, * and all balises are closed ... otherwite the display can not be done - * @param _text The string to display. + * @param text The string to display. * @TODO : implementation not done .... */ - public void printDecorated(final String _text) { + public void printDecorated(final String text) { String tmpData = "\n\n"; - tmpData += _text; + tmpData += text; tmpData += "\n\n\n"; // Log.debug("plop : " + tmpData); printHTML(tmpData); } - + /** * display a compleat string in the current element with the generic * decoration specification. (basic html data) @@ -793,40 +773,40 @@ public abstract class TextBase extends Compositing { * * @note This is parsed with tiny xml, then be carfull that the XML is correct, * and all balises are closed ... otherwite the display can not be done - * @param _text The string to display. + * @param text The string to display. * @TODO : implementation not done .... */ - public void printHTML(final String _text) { + public void printHTML(final String text) { // reset parameter : this.htmlDecoTmp = new TextDecoration(this.defaultColorFg, this.defaultColorBg, FontMode.Regular); try { - XmlElement doc = Exml.parse(_text); - if (doc.existNode("html") == false) { + final XmlElement doc = Exml.parse(text); + if (!doc.existNode("html")) { Log.error("can not load XML: main node not find: 'html'"); Exml.display(doc); return; } - XmlElement root = (XmlElement) doc.getNode("html"); - - if (root.existNode("body") == false) { + final XmlElement root = (XmlElement) doc.getNode("html"); + + if (!root.existNode("body")) { Log.error("can not load XML: main node not find: 'body'"); return; } - XmlElement bodyNode = (XmlElement) root.getNode("body"); + final XmlElement bodyNode = (XmlElement) root.getNode("body"); parseHtmlNode(bodyNode); htmlFlush(); - } catch (ExmlParserErrorMulti e) { + } catch (final ExmlParserErrorMulti e) { Log.error("Can not parse XML data in printHTML:" + e.getMessage()); e.printStackTrace(); - } catch (ExmlBuilderException e) { + } catch (final ExmlBuilderException e) { Log.error("Can not generate XML data in printHTML:" + e.getMessage()); e.printStackTrace(); - } catch (ExmlNodeDoesNotExist e) { + } catch (final ExmlNodeDoesNotExist e) { Log.error("Error in finding node from XML data in printHTML:" + e.getMessage()); e.printStackTrace(); } } - + /** * clear all the intermediate result detween 2 prints */ @@ -842,227 +822,222 @@ public abstract class TextBase extends Compositing { this.colorBg = this.defaultColorBg; this.mode = FontMode.Regular; this.previousCharcode = 0; - this.startTextpos = 0; + this.startTextPos = 0; this.stopTextPos = 0; - this.alignement = AligneMode.alignDisable; - this.htmlCurrrentLine = ""; + this.alignment = AlignMode.alignDisable; + this.htmlCurrentLine = ""; this.selectionStartPos = -100; this.cursorPos = -100; this.htmlDecoration.clear(); this.needDisplay = true; this.nbCharDisplayed = 0; } - + @Override - public void rotate(final Vector3f _vect, final float _angle) { - super.rotate(_vect, _angle); - // TODO this.vectorialDraw.rotate(_vect,_angle); + public void rotate(final Vector3f vect, final float angle) { + super.rotate(vect, angle); + this.vectorialDraw.rotate(vect, angle); } - + @Override - public void scale(final Vector3f _vect) { - super.scale(_vect); - // TODO this.vectorialDraw.scale(_vect); + public void scale(final Vector3f vect) { + super.scale(vect); + this.vectorialDraw.scale(vect); } - + // ! @previous - public void setClipping(final Vector2f _pos, final Vector2f _posEnd) { - setClipping(new Vector3f(_pos.x(), _pos.y(), -1), new Vector3f(_posEnd.x(), _posEnd.y(), 1)); + public void setClipping(final Vector2f pos, final Vector2f posEnd) { + setClipping(new Vector3f(pos.x(), pos.y(), -1), new Vector3f(posEnd.x(), posEnd.y(), 1)); } - + /** * Request a clipping area for the text (next draw only) - * @param _pos Start position of the clipping - * @param _posEnd End position of the clipping + * @param pos Start position of the clipping + * @param posEnd End position of the clipping */ - public void setClipping(final Vector3f _pos, final Vector3f _posEnd) { + public void setClipping(final Vector3f pos, final Vector3f posEnd) { // note the internal system all time request to have a bounding all time in the // same order - this.clippingPosStop = Vector3f.max(_pos, _posEnd); - this.clippingPosStart = Vector3f.min(_pos, _posEnd); + this.clippingPosStop = Vector3f.max(pos, posEnd); + this.clippingPosStart = Vector3f.min(pos, posEnd); this.clippingEnable = true; - // //TODO this.vectorialDraw.setClipping(this.clippingPosStart, - // this.clippingPosStop); + this.vectorialDraw.setClipping(this.clippingPosStart, this.clippingPosStop); } - + /** * enable/Disable the clipping (without lose the current clipping * position) - * _newMode The new status of the clipping + * newMode The new status of the clipping */ // TODO : Rename setClippingActivity - public void setClippingMode(final boolean _newMode) { - this.clippingEnable = _newMode; - // //TODO this.vectorialDraw.setClippingMode(this.clippingEnable); + public void setClippingMode(final boolean newMode) { + this.clippingEnable = newMode; + this.vectorialDraw.setClippingMode(this.clippingEnable); } - + // ! @previous - public void setClippingWidth(final Vector2f _pos, final Vector2f _width) { - setClipping(_pos, _pos.add(_width)); + public void setClippingWidth(final Vector2f pos, final Vector2f width) { + setClipping(pos, pos.add(width)); } - + /** * Request a clipping area for the text (next draw only) - * @param _pos Start position of the clipping - * @param _width Width size of the clipping + * @param pos Start position of the clipping + * @param width Width size of the clipping */ - public void setClippingWidth(final Vector3f _pos, final Vector3f _width) { - setClipping(_pos, _pos.add(_width)); + public void setClippingWidth(final Vector3f pos, final Vector3f width) { + setClipping(pos, pos.add(width)); } - + /** * set the Color of the current foreground font - * @param _color Color to set on foreground (for next print) + * @param color Color to set on foreground (for next print) */ - public void setColor(final Color _color) { - this.color = _color; + public void setColor(final Color color) { + this.color = color; } - + /** * set the background color of the font (for selected Text (not the * global BG)) - * @param _color Color to set on background (for next print) + * @param color Color to set on background (for next print) */ - public void setColorBg(final Color _color) { - this.colorBg = _color; - // TODO this.vectorialDraw.setColor(_color); + public void setColorBg(final Color color) { + this.colorBg = color; + this.vectorialDraw.setColor(color); } - + /** * change the cursor color - * @param _color New color for the Selection + * @param color New color for the Selection */ - public void setCursorColor(final Color _color) { - this.colorCursor = _color; + public void setCursorColor(final Color color) { + this.colorCursor = color; } - + /** * set a cursor at a specific position: - * @param _cursorPos id of the cursor position + * @param cursorPos id of the cursor position */ - public void setCursorPos(final int _cursorPos) { - this.selectionStartPos = _cursorPos; - this.cursorPos = _cursorPos; + public void setCursorPos(final int cursorPos) { + this.selectionStartPos = cursorPos; + this.cursorPos = cursorPos; } - + /** * set a cursor at a specific position with his associated selection: - * @param _cursorPos id of the cursor position - * @param _selectionStartPos id of the starting of the selection + * @param cursorPos id of the cursor position + * @param selectionStartPos id of the starting of the selection */ - public void setCursorSelection(final int _cursorPos, final int _selectionStartPos) { - this.selectionStartPos = _selectionStartPos; - this.cursorPos = _cursorPos; + public void setCursorSelection(final int cursorPos, final int selectionStartPos) { + this.selectionStartPos = selectionStartPos; + this.cursorPos = cursorPos; } - + /** * set the default background color of the font (when reset, set this * value ...) - * @param _color Color to set on background + * @param color Color to set on background */ - public void setDefaultColorBg(final Color _color) { - this.defaultColorBg = _color; + public void setDefaultColorBg(final Color color) { + this.defaultColorBg = color; } - + /** * set the default Foreground color of the font (when reset, set this * value ...) - * @param _color Color to set on foreground + * @param color Color to set on foreground */ - public void setDefaultColorFg(final Color _color) { - this.defaultColorFg = _color; + public void setDefaultColorFg(final Color color) { + this.defaultColorFg = color; } - + /** * Specify the font property (this reset the internal element of the * current text (system requirement) * @param fontName Current name of the selected font * @param fontSize New font size */ - public abstract void setFont(final String _fontName, final int _fontSize); - + public abstract void setFont(final String fontName, final int fontSize); + /** * enable or disable the bold mode - * @param _status The new status for this display property + * @param status The new status for this display property */ - public void setFontBold(final boolean _status) { - if (_status == true) { + public void setFontBold(final boolean status) { + if (status) { // enable if (this.mode == FontMode.Regular) { setFontMode(FontMode.Bold); } else if (this.mode == FontMode.Italic) { setFontMode(FontMode.BoldItalic); } - } else { - // disable - if (this.mode == FontMode.Bold) { - setFontMode(FontMode.Regular); - } else if (this.mode == FontMode.BoldItalic) { - setFontMode(FontMode.Italic); - } + } else // disable + if (this.mode == FontMode.Bold) { + setFontMode(FontMode.Regular); + } else if (this.mode == FontMode.BoldItalic) { + setFontMode(FontMode.Italic); } } - + /** * enable or disable the italic mode - * @param _status The new status for this display property + * @param status The new status for this display property */ - public void setFontItalic(final boolean _status) { - if (_status == true) { + public void setFontItalic(final boolean status) { + if (status) { // enable if (this.mode == FontMode.Regular) { setFontMode(FontMode.Italic); } else if (this.mode == FontMode.Bold) { setFontMode(FontMode.BoldItalic); } - } else { - // disable - if (this.mode == FontMode.Italic) { - setFontMode(FontMode.Regular); - } else if (this.mode == FontMode.BoldItalic) { - setFontMode(FontMode.Bold); - } + } else // disable + if (this.mode == FontMode.Italic) { + setFontMode(FontMode.Regular); + } else if (this.mode == FontMode.BoldItalic) { + setFontMode(FontMode.Bold); } } - + /** * Specify the font mode for the next @ref print * @param mode The font mode requested */ - public abstract void setFontMode(FontMode _mode);; - + public abstract void setFontMode(FontMode mode); + /** * Specify the font name (this reset the internal element of the current * text (system requirement) - * @param _fontName Current name of the selected font + * @param fontName Current name of the selected font */ - public abstract void setFontName(final String _fontName); - + public abstract void setFontName(final String fontName); + /** * Specify the font size (this reset the internal element of the current * text (system requirement) - * @param _fontSize New font size + * @param fontSize New font size */ - public abstract void setFontSize(final int _fontSize); - + public abstract void setFontSize(final int fontSize); + /** * set the activation of the Kerning for the display (if it existed) - * @param _newMode enable/Diasable the kerning on this font. + * @param newMode enable/Diasable the kerning on this font. */ - public void setKerningMode(final boolean _newMode) { - this.kerning = _newMode; + public void setKerningMode(final boolean newMode) { + this.kerning = newMode; } - + // ! @previous - public void setPos(final Vector2f _pos) { - setPos(new Vector3f(_pos.x(), _pos.y(), 0)); + public void setPos(final Vector2f pos) { + setPos(new Vector3f(pos.x(), pos.y(), 0)); } - + /** * set position for the next text writen - * @param _pos Position of the text (in 3D) + * @param pos Position of the text (in 3D) */ - public void setPos(final Vector3f _pos) { + public void setPos(final Vector3f pos) { // check min max for display area if (this.nbCharDisplayed != 0) { Log.verbose("update size 1 " + this.sizeDisplayStart + " " + this.sizeDisplayStop); @@ -1070,8 +1045,9 @@ public abstract class TextBase extends Compositing { this.sizeDisplayStart = Vector3f.min(this.position, this.sizeDisplayStart); } // update position - this.position = _pos; - this.previousCharcode = 0;// TODO this.vectorialDraw.setPos(this.position); + this.position = pos; + this.previousCharcode = 0; + this.vectorialDraw.setPos(this.position); // update min max of the display area: if (this.nbCharDisplayed == 0) { this.sizeDisplayStart = this.position; @@ -1084,56 +1060,55 @@ public abstract class TextBase extends Compositing { Log.verbose("update size 4 " + this.sizeDisplayStart + " " + this.sizeDisplayStop); } } - + // ! @previous - public void setRelPos(final Vector2f _pos) { - setRelPos(new Vector3f(_pos.x(), _pos.y(), 0)); + public void setRelPos(final Vector2f pos) { + setRelPos(new Vector3f(pos.x(), pos.y(), 0)); } - + /** * set relative position for the next text written - * @param _pos offset apply of the text (in 3D) + * @param pos offset apply of the text (in 3D) */ - public void setRelPos(final Vector3f _pos) { - this.position = this.position.add(_pos); + public void setRelPos(final Vector3f pos) { + this.position = this.position.add(pos); this.previousCharcode = 0; - // TODO this.vectorialDraw.setPos(this.position); + this.vectorialDraw.setPos(this.position); } - + /** * change the selection color - * @param _color New color for the Selection + * @param color New color for the Selection */ - public void setSelectionColor(final Color _color) { - this.colorSelection = _color; + public void setSelectionColor(final Color color) { + this.colorSelection = color; } - + /** * This generate the possibility to generate the big text property - * @param _startTextpos The x text start position of the display. - * @param _stopTextPos The x text stop position of the display. - * @param _alignement mode of alignement for the Text. + * @param startTextPos The x text start position of the display. + * @param stopTextPos The x text stop position of the display. * @note The text align in center change of line every display done (even if it * was just a char) */ - public void setTextAlignement(final float _startTextpos, final float _stopTextPos) { - setTextAlignement(_startTextpos, _stopTextPos, AligneMode.alignDisable); + public void setTextAlignment(final float startTextPos, final float stopTextPos) { + setTextAlignment(startTextPos, stopTextPos, AlignMode.alignDisable); } - - public void setTextAlignement(final float _startTextpos, final float _stopTextPos, final AligneMode _alignement) { - this.startTextpos = _startTextpos; - this.stopTextPos = _stopTextPos + 1; - this.alignement = _alignement; - if (this.startTextpos >= this.stopTextPos) { - // TODO: understand why this flush ... - Log.verbose("Request allignement with Borne position error : " + _startTextpos + " => " + _stopTextPos); + + public void setTextAlignment(final float startTextPos, final float stopTextPos, final AlignMode alignement) { + this.startTextPos = startTextPos; + this.stopTextPos = stopTextPos + 1; + this.alignment = alignement; + if (this.startTextPos >= this.stopTextPos) { + // TODO understand why this flush ... + Log.verbose("Request alignment with Borne position error : " + startTextPos + " => " + stopTextPos); } } - + @Override - public void translate(final Vector3f _vect) { - super.translate(_vect); - // TODO this.vectorialDraw.translate(_vect); + public void translate(final Vector3f vect) { + super.translate(vect); + this.vectorialDraw.translate(vect); } - + } \ No newline at end of file diff --git a/src/org/atriasoft/ewol/context/ConfigFont.java b/src/org/atriasoft/ewol/context/ConfigFont.java index 9dd8303..b4d25d7 100644 --- a/src/org/atriasoft/ewol/context/ConfigFont.java +++ b/src/org/atriasoft/ewol/context/ConfigFont.java @@ -10,7 +10,7 @@ import org.atriasoft.ewol.internal.Log; */ public class ConfigFont { - private Uri folder = new Uri("DATA:///fonts?lib=ewol"); + private Uri folder = new Uri("DATA", "fonts", "ewol"); private String name = "Arial;Helvetica"; private int size = 10; private boolean useExternal = false; @@ -42,7 +42,7 @@ public class ConfigFont { */ public int getSize() { return this.size; - }; + } /** * get the use of internal/external Font @@ -54,46 +54,46 @@ public class ConfigFont { /** * set the defaut font for all the widgets and basics display. - * @param _fontName The font name requested (not case sensitive) ex "Arial" or multiple separate by ';' ex : "Arial;Helvetica". - * @param _size The default size of the font default=10. + * @param fontName The font name requested (not case sensitive) ex "Arial" or multiple separate by ';' ex : "Arial;Helvetica". + * @param size The default size of the font default=10. */ - public void set(final String _fontName, final int _size) { - this.name = _fontName; - this.size = _size; + public void set(final String fontName, final int size) { + this.name = fontName; + this.size = size; Log.debug("Set default Font : '" + this.name + "' size=" + this.size); - }; + } /** * Specify the default font folder for the Ewol search system (only needed when embended font) - * @param _folder basic folder of the font (ex: DATA:fonts) + * @param folder basic folder of the font (ex: DATA:fonts) */ - public void setFolder(final Uri _folder) { - this.folder = _folder; + public void setFolder(final Uri folder) { + this.folder = folder; } /** * Set the current default font name - * @param _fontName The font name requested (not case sensitive) ex "Arial" or multiple separate by ';' ex : "Arial;Helvetica". + * @param fontName The font name requested (not case sensitive) ex "Arial" or multiple separate by ';' ex : "Arial;Helvetica". */ - public void setName(final String _fontName) { - this.name = _fontName; + public void setName(final String fontName) { + this.name = fontName; Log.debug("Set default Font : '" + this.name + "' size=" + this.size + " (change name only)"); } /** * Set the default font size. - * @param _size new font size. + * @param size new font size. */ - public void setSize(final int _size) { - this.size = _size; + public void setSize(final int size) { + this.size = size; Log.debug("Set default Font : '" + this.name + "' size=" + this.size + " (change size only)"); - }; + } /** * set use of internal/external Font - * @param _val true to enable search of internal data. + * @param val true to enable search of internal data. */ - public void setUseExternal(final boolean _val) { - this.useExternal = _val; - }; -}; + public void setUseExternal(final boolean val) { + this.useExternal = val; + } +} diff --git a/src/org/atriasoft/ewol/context/EwolApplication.java b/src/org/atriasoft/ewol/context/EwolApplication.java index 4b96ffb..720750f 100644 --- a/src/org/atriasoft/ewol/context/EwolApplication.java +++ b/src/org/atriasoft/ewol/context/EwolApplication.java @@ -9,45 +9,45 @@ package org.atriasoft.ewol.context; public interface EwolApplication { /** * The application is created. - * @param _context Current ewol context. + * @param context Current ewol context. */ - void onCreate(EwolContext _context); + void onCreate(EwolContext context); /** * The application is removed (call destructor just adter it.). - * @param _context Current ewol context. + * @param context Current ewol context. */ - void onDestroy(EwolContext _context); + void onDestroy(EwolContext context); /** * The user request application removing. - * @param _context Current ewol context. + * @param context Current ewol context. */ - default void onKillDemand(final EwolContext _context) { - _context.exit(0); + default void onKillDemand(final EwolContext context) { + context.exit(0); } /** * The application is Hide / not visible. - * @param _context Current ewol context. + * @param context Current ewol context. */ - void onPause(EwolContext _context); + void onPause(EwolContext context); /** * The application is resumed (now visible). - * @param _context Current ewol context. + * @param context Current ewol context. */ - void onResume(EwolContext _context); + void onResume(EwolContext context); /** * The application is started. - * @param _context Current ewol context. + * @param context Current ewol context. */ - void onStart(EwolContext _context); + void onStart(EwolContext context); /** * The application is stopped. - * @param _context Current ewol context. + * @param context Current ewol context. */ - void onStop(EwolContext _context); + void onStop(EwolContext context); } \ No newline at end of file diff --git a/src/org/atriasoft/ewol/context/EwolContext.java b/src/org/atriasoft/ewol/context/EwolContext.java index 546038c..a286bda 100644 --- a/src/org/atriasoft/ewol/context/EwolContext.java +++ b/src/org/atriasoft/ewol/context/EwolContext.java @@ -28,56 +28,42 @@ import org.atriasoft.gale.key.KeyType; 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 { +public class EwolContext extends Application { private static EwolContext curentInterface = null; - + /** * From everyware in the program, we can get the context inteface. * @return current reference on the instance. */ public static EwolContext getContext() { - return curentInterface; + return EwolContext.curentInterface; } - - /** - * 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 _argc Standard argc - * @param _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; + + private final InputManager input; + + private final ObjectManager objectManager; // !< Object Manager main instance + + private WidgetManager widgetManager; // !< global widget manager + + private Windows windowsCurrent = null; // !< current displayed windows + + public EwolContext(final EwolApplication application) { + this.application = application; this.objectManager = new ObjectManager(this); this.input = new InputManager(this); if (this.application == null) { Log.critical("Can not start context with no Application ==> rtfm ..."); } } - + /** * Redraw all the windows */ @@ -89,31 +75,31 @@ public abstract class EwolContext extends Application { 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; } - + /** * get the current windows that is displayed * @return the current handle on the windows (can be null) @@ -121,25 +107,25 @@ public abstract class EwolContext extends Application { public Windows getWindows() { return this.windowsCurrent; } - + /** * This fonction lock the pointer properties to move in relative instead * of absolute * @param widget The widget that lock the pointer events */ - public void inputEventGrabPointer(final Widget _widget) { - this.input.grabPointer(_widget); + public void inputEventGrabPointer(final Widget widget) { + this.input.grabPointer(widget); } - + /** * 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); + public void inputEventTransfertWidget(final Widget source, final Widget destination) { + this.input.transfertEvent(source, destination); } - + /** * This fonction un-lock the pointer properties to move in relative * instead of absolute @@ -147,24 +133,24 @@ public abstract class EwolContext extends Application { public void inputEventUnGrabPointer() { this.input.unGrabPointer(); } - + @Override - public void onClipboardEvent(final ClipboardList _clipboardId) { + public void onClipboardEvent(final ClipboardList clipboardId) { final Widget tmpWidget = this.widgetManager.focusGet(); if (tmpWidget != null) { - tmpWidget.onEventClipboard(_clipboardId); + tmpWidget.onEventClipboard(clipboardId); } } - + @Override - public void onCreate(final Context _context) { + public void onCreate(final Context context) { Log.info(" == > Ewol system create (BEGIN)"); // Add basic ewol translation: 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).equals("-h") || context.getCmd().get(iii).equals("--help")) { Log.print("ewol - help : "); Log.print(" xxxxxxxxxxxxx [options]"); Log.print(" -h/--help: Display this help"); @@ -172,21 +158,19 @@ public abstract class EwolContext extends Application { Log.print(" xxxxxxxxxxxxx --help"); // this is a global help system does not remove it continue; - } else { - continue; } - _context.getCmd().remove(iii); - --iii; + //context.getCmd().remove(iii); + //--iii; } - + // Log.info("EWOL v:" + ewol::getVersion()); // force a recalculation /* * requestUpdateSize(){ Context context = gale::getContext(); * context.requestUpdateSize(); } #if - * defined(__EWOL_ANDROID_ORIENTATION_LANDSCAPE__) + * defined(EWOLANDROIDORIENTATIONLANDSCAPE) * forceOrientation(ewol::screenLandscape); #elif - * defined(__EWOL_ANDROID_ORIENTATION_PORTRAIT__) + * defined(EWOLANDROIDORIENTATIONPORTRAIT) * forceOrientation(ewol::screenPortrait); #else * forceOrientation(ewol::screenAuto); #endif */ @@ -198,9 +182,9 @@ public abstract class EwolContext extends Application { appl.onCreate(this); Log.info(" == > Ewol system create (END)"); } - + @Override - public void onDestroy(final Context _context) { + public void onDestroy(final Context context) { Log.info(" == > Ewol system destroy (BEGIN)"); // Remove current windows this.windowsCurrent = null; @@ -220,9 +204,9 @@ public abstract class EwolContext extends Application { this.objectManager.unInit(); Log.info(" == > Ewol system destroy (END)"); } - + @Override - public void onDraw(final Context _context) { + public void onDraw(final Context context) { // Log.info("DRAW"); // clean internal data... this.objectManager.cleanInternalRemoved(); @@ -233,20 +217,19 @@ public abstract class EwolContext extends Application { } window.sysDraw(); } - + @Override - public void onKeyboard(final KeySpecial _special, final KeyKeyboard _type, final Character _value, - final KeyStatus _state) { - Log.verbose("event {" + _special + "} " + _type + " " + _value + " " + _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); + this.input.setLastKeyboardSpecial(special); if (this.windowsCurrent == null) { // No windows ... return; } - final boolean repeate = (_state == KeyStatus.downRepeate); - final boolean isDown = (_state == KeyStatus.downRepeate) || (_state == KeyStatus.down); - if (this.windowsCurrent.onEventShortCut(_special, _value, _type, isDown) == true) { + final boolean repeate = (state == KeyStatus.downRepeat); + final boolean isDown = (state == KeyStatus.downRepeat) || (state == KeyStatus.down); + if (this.windowsCurrent.onEventShortCut(special, value, type, isDown)) { // Keep a shortcut ... return; } @@ -259,24 +242,24 @@ public abstract class EwolContext extends Application { // check if the widget allow repeating key events. // Log.info("repeating test :" + repeate + " widget=" + // tmpWidget.getKeyboardRepeate() + " state=" + isDown); - if (repeate == false || (repeate == true && tmpWidget.getKeyboardRepeat() == true)) { + if (!repeate || (repeate && tmpWidget.getKeyboardRepeat())) { // check Widget shortcut - if (tmpWidget.onEventShortCut(_special, _value, _type, isDown) == false) { + if (!tmpWidget.onEventShortCut(special, value, type, isDown)) { // generate the direct event ... - if (_type == KeyKeyboard.character) { + if (type == KeyKeyboard.character) { final EntrySystem tmpEntryEvent; - if (isDown == true) { - tmpEntryEvent = new EntrySystem(KeyKeyboard.character, KeyStatus.down, _special, _value); + if (isDown) { + tmpEntryEvent = new EntrySystem(KeyKeyboard.character, KeyStatus.down, special, value); } else { - tmpEntryEvent = new EntrySystem(KeyKeyboard.character, KeyStatus.up, _special, _value); + tmpEntryEvent = new EntrySystem(KeyKeyboard.character, KeyStatus.up, special, value); } tmpWidget.systemEventEntry(tmpEntryEvent); - } else { // THREAD_KEYBORAD_MOVE + } else { // THREADKEYBORADMOVE final EntrySystem tmpEntryEvent; - if (isDown == true) { - tmpEntryEvent = new EntrySystem(KeyKeyboard.character, KeyStatus.down, _special, null); + if (isDown) { + tmpEntryEvent = new EntrySystem(KeyKeyboard.character, KeyStatus.down, special, null); } else { - tmpEntryEvent = new EntrySystem(KeyKeyboard.character, KeyStatus.up, _special, null); + tmpEntryEvent = new EntrySystem(KeyKeyboard.character, KeyStatus.up, special, null); } tmpWidget.systemEventEntry(tmpEntryEvent); } @@ -285,9 +268,9 @@ public abstract class EwolContext extends Application { } } } - + @Override - public void onKillDemand(final Context _context) { + public void onKillDemand(final Context context) { Log.info(" == > User demand a destroy (BEGIN)"); final EwolApplication appl = this.application; if (appl == null) { @@ -297,9 +280,9 @@ public abstract class EwolContext extends Application { appl.onKillDemand(this); Log.info(" == > User demand a destroy (END)"); } - + @Override - public void onPause(final Context _context) { + public void onPause(final Context context) { Log.info(" == > Ewol system pause (BEGIN)"); final EwolApplication appl = this.application; if (appl == null) { @@ -307,36 +290,36 @@ public abstract class EwolContext extends Application { } 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; + + 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 downRepeat: + // 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"); + public void onRegenerateDisplay(final Context context) { + // Log.info("REGENERATEDISPLAY"); // check if the user selected a windows final Windows window = this.windowsCurrent; if (window == null) { @@ -345,19 +328,19 @@ public abstract class EwolContext extends Application { } // Redraw all needed elements window.onRegenerateDisplay(); - if (this.widgetManager.isDrawingNeeded() == true) { + if (this.widgetManager.isDrawingNeeded()) { markDrawingIsNeeded(); } // markDrawingIsNeeded(); } - - public void onResize(final Vector2i _size) { - Log.verbose("Resize: " + _size); + + public void onResize(final Vector2i size) { + Log.verbose("Resize: " + size); forceRedrawAll(); } - + @Override - public void onResume(final Context _context) { + public void onResume(final Context context) { Log.info(" == > Ewol system resume (BEGIN)"); final EwolApplication appl = this.application; if (appl == null) { @@ -366,9 +349,9 @@ public abstract class EwolContext extends Application { appl.onResume(this); Log.info(" == > Ewol system resume (END)"); } - + @Override - public void onStart(final Context _context) { + public void onStart(final Context context) { Log.info(" == > Ewol system start (BEGIN)"); final EwolApplication appl = this.application; if (appl == null) { @@ -378,9 +361,9 @@ public abstract class EwolContext extends Application { appl.onStart(this); Log.info(" == > Ewol system start (END)"); } - + @Override - public void onStop(final Context _context) { + public void onStop(final Context context) { Log.info(" == > Ewol system stop (BEGIN)"); final EwolApplication appl = this.application; if (appl == null) { @@ -389,7 +372,7 @@ public abstract class EwolContext extends Application { appl.onStop(this); Log.info(" == > Ewol system stop (END)"); } - + /** * Request a display after call a resize */ @@ -397,35 +380,35 @@ public abstract class EwolContext extends Application { final Context context = Gale.getContext(); context.requestUpdateSize(); } - + /** * reset event management for the IO like Input ou Mouse or keyborad */ public void resetIOEvent() { this.input.newLayerSet(); } - + /** * Special for init (main) set the start image when loading data - * @param _fileName Name of the image to load + * @param fileName Name of the image to load */ - public void setInitImage(final Uri _fileName) { - // this.initDisplayImageName = _fileName; + public void setInitImage(final Uri fileName) { + // this.initDisplayImageName = fileName; } - + /** * set the current windows to display : - * @param _windows Windows that might be displayed + * @param windows Windows that might be displayed */ - public void setWindows(final Windows _windows) { + public void setWindows(final Windows windows) { Log.info("set New windows"); // remove current focus : this.widgetManager.focusSetDefault(null); this.widgetManager.focusRelease(); // set the new pointer as windows system - this.windowsCurrent = _windows; + this.windowsCurrent = windows; // set the new default focus: - this.widgetManager.focusSetDefault(_windows); + this.widgetManager.focusSetDefault(windows); // display the title of the Windows: if (this.windowsCurrent != null) { setTitle(this.windowsCurrent.propertyTitle); diff --git a/src/org/atriasoft/ewol/context/InputManager.java b/src/org/atriasoft/ewol/context/InputManager.java index 9529690..f5bd4c5 100644 --- a/src/org/atriasoft/ewol/context/InputManager.java +++ b/src/org/atriasoft/ewol/context/InputManager.java @@ -23,29 +23,29 @@ import org.atriasoft.gale.key.KeyType; * internal structure */ class InputLimit { + public int dpiOffset; public Duration sepatateTime; - public int DpiOffset; -}; +} class InputManager { - private final static int MAX_MANAGE_INPUT = 15; + private static final int MAX_MANAGE_INPUT = 15; + + private final EwolContext context; + private int dpi; + private InputLimit eventInputLimit; + private final InputPoperty[] eventInputSaved = new InputPoperty[InputManager.MAX_MANAGE_INPUT]; + private InputLimit eventMouseLimit; + private final InputPoperty[] eventMouseSaved = new InputPoperty[InputManager.MAX_MANAGE_INPUT]; // special grab pointer mode : private WeakReference grabWidget = null; //!< widget that grab the curent pointer. - private int dpi; - private InputLimit eventInputLimit; - private InputLimit eventMouseLimit; - private final InputPoperty[] eventInputSaved = new InputPoperty[MAX_MANAGE_INPUT]; - private final InputPoperty[] eventMouseSaved = new InputPoperty[MAX_MANAGE_INPUT]; - - private final EwolContext context; private KeySpecial specialKey; - public InputManager(final EwolContext _context) { - this.context = _context; + public InputManager(final EwolContext context) { + this.context = context; setDpi(200); Log.info("Init (start)"); - for (int iii = 0; iii < MAX_MANAGE_INPUT; iii++) { + for (int iii = 0; iii < InputManager.MAX_MANAGE_INPUT; iii++) { // remove the property of this input ... cleanElement(this.eventInputSaved, iii); cleanElement(this.eventMouseSaved, iii); @@ -53,76 +53,75 @@ class InputManager { Log.info("Init (end)"); } - public void abortElement(final InputPoperty[] _eventTable, final int _idInput, final KeyType _type) { - if (_eventTable == null) { + public void abortElement(final InputPoperty[] eventTable, final int idInput, final KeyType type) { + if (eventTable == null) { return; } - if (_eventTable[_idInput].isUsed == true) { - localEventInput(_type, _eventTable[_idInput].curentWidgetEvent.get(), _eventTable[_idInput].destinationInputId, KeyStatus.abort, _eventTable[_idInput].posEvent); + if (eventTable[idInput].isUsed) { + localEventInput(type, eventTable[idInput].curentWidgetEvent.get(), eventTable[idInput].destinationInputId, KeyStatus.abort, eventTable[idInput].posEvent); } } private void calculateLimit() { this.eventInputLimit.sepatateTime = Duration.milliseconds(300); - this.eventInputLimit.DpiOffset = this.dpi * 100; + this.eventInputLimit.dpiOffset = this.dpi * 100; this.eventMouseLimit.sepatateTime = Duration.milliseconds(300); - this.eventMouseLimit.DpiOffset = (int) (this.dpi * 0.1f); + this.eventMouseLimit.dpiOffset = (int) (this.dpi * 0.1f); } - public void cleanElement(final InputPoperty[] eventMouseSaved2, final int _idInput) { + public void cleanElement(final InputPoperty[] eventMouseSaved2, final int idInput) { if (eventMouseSaved2 == null) { return; } //Log.info("CleanElement[" + idInput + "] = @" + (long)eventTable); - eventMouseSaved2[_idInput].isUsed = false; - eventMouseSaved2[_idInput].destinationInputId = 0; - eventMouseSaved2[_idInput].lastTimeEvent = new Clock(); - eventMouseSaved2[_idInput].curentWidgetEvent = null; - eventMouseSaved2[_idInput].origin = new Vector2f(0, 0); - eventMouseSaved2[_idInput].size = new Vector2f(99999999, 99999999); - eventMouseSaved2[_idInput].downStart = new Vector2f(0, 0); - eventMouseSaved2[_idInput].isDown = false; - eventMouseSaved2[_idInput].isInside = false; - eventMouseSaved2[_idInput].nbClickEvent = 0; - eventMouseSaved2[_idInput].posEvent = new Vector2f(0, 0); + eventMouseSaved2[idInput].isUsed = false; + eventMouseSaved2[idInput].destinationInputId = 0; + eventMouseSaved2[idInput].lastTimeEvent = new Clock(); + eventMouseSaved2[idInput].curentWidgetEvent = null; + eventMouseSaved2[idInput].origin = new Vector2f(0, 0); + eventMouseSaved2[idInput].size = new Vector2f(99999999, 99999999); + eventMouseSaved2[idInput].downStart = new Vector2f(0, 0); + eventMouseSaved2[idInput].isDown = false; + eventMouseSaved2[idInput].isInside = false; + eventMouseSaved2[idInput].nbClickEvent = 0; + eventMouseSaved2[idInput].posEvent = new Vector2f(0, 0); } /** * This fonction lock the pointer properties to move in relative instead of absolute - * @param _widget The widget that lock the pointer events + * @param widget The widget that lock the pointer events */ - public void grabPointer(final Widget _widget) { - if (_widget == null) { + public void grabPointer(final Widget widget) { + if (widget == null) { return; } - this.grabWidget = new WeakReference<>(_widget); + this.grabWidget = new WeakReference<>(widget); /* TODO : - this.context.grabPointerEvents(true, _widget.getOrigin() - + Vector2i(_widget.getSize().x/2.0f, - _widget.getSize().y/2.0f) ); + this.context.grabPointerEvents(true, widget.getOrigin() + + Vector2i(widget.getSize().x/2.0f, + widget.getSize().y/2.0f) ); */ } /** * generate the event on the destinated widget. - * @param _type Type of the event that might be sended. - * @param _destWidget Pointer on the requested widget that element might be sended - * @param _IdInput Id of the event (PC : [0..9] and touch : [1..9]) - * @param _typeEvent type of the eventg generated - * @param _pos position of the event + * @param type Type of the event that might be sended. + * @param destWidget Pointer on the requested widget that element might be sended + * @param idInput Id of the event (PC : [0..9] and touch : [1..9]) + * @param typeEvent type of the eventg generated + * @param pos position of the event * @return true if event has been greped */ - public boolean localEventInput(final KeyType _type, final Widget _destWidget, final int _IdInput, final KeyStatus _status, final Vector2f _pos) { - if (_destWidget != null) { - if (_type == KeyType.mouse || _type == KeyType.finger) { + public boolean localEventInput(final KeyType type, final Widget destWidget, final int idInput, final KeyStatus status, final Vector2f pos) { + if (destWidget != null) { + if (type == KeyType.mouse || type == KeyType.finger) { // create the system Event : // TODO : set the real ID ... - final InputSystem tmpEventSystem = new InputSystem(_type, _status, _IdInput, _pos, _destWidget, 0, this.specialKey); + final InputSystem tmpEventSystem = new InputSystem(type, status, idInput, pos, destWidget, 0, this.specialKey); // generate the event : - return _destWidget.systemEventInput(tmpEventSystem); - } else { - return false; + return destWidget.systemEventInput(tmpEventSystem); } + return false; } return false; } @@ -131,19 +130,19 @@ class InputManager { * convert the system event id in the correct EWOL id depending of the system management mode * This function find the next input id unused on the specifiic widget * == > on PC, the ID does not change (GUI is not the same) - * @param _type Type of the kay event. - * @param _destWidget Pointer of the widget destination - * @param _realInputId system Id + * @param type Type of the kay event. + * @param destWidget Pointer of the widget destination + * @param realInputId system Id * @return the ewol input id */ - public int localGetDestinationId(final KeyType _type, final Widget _destWidget, final int _realInputId) { - if (_type == KeyType.finger) { + public int localGetDestinationId(final KeyType type, final Widget destWidget, final int realInputId) { + if (type == KeyType.finger) { int lastMinimum = 0; - for (int iii = 0; iii < MAX_MANAGE_INPUT; iii++) { - if (true == this.eventInputSaved[iii].isUsed) { + for (int iii = 0; iii < InputManager.MAX_MANAGE_INPUT; iii++) { + if (this.eventInputSaved[iii].isUsed) { final Widget tmpWidget = this.eventInputSaved[iii].curentWidgetEvent.get(); - if (tmpWidget == _destWidget) { - if (iii != _realInputId) { + if (tmpWidget == destWidget) { + if (iii != realInputId) { lastMinimum = FMath.max(lastMinimum, this.eventInputSaved[iii].destinationInputId); } } @@ -151,32 +150,32 @@ class InputManager { } return lastMinimum + 1; } - return _realInputId; + return realInputId; } // note if id<0 == > the it was finger event ... - public void motion(final KeyType _type, final int _pointerID, final Vector2f _pos) { - //Log.debug("motion event : " + _type + " " + _pointerID + " " + _pos); - if (MAX_MANAGE_INPUT <= _pointerID) { + public void motion(final KeyType type, final int pointerID, final Vector2f pos) { + //Log.debug("motion event : " + type + " " + pointerID + " " + pos); + if (InputManager.MAX_MANAGE_INPUT <= pointerID) { // reject pointer == > out of IDs... return; } InputPoperty[] eventTable = null; - if (_type == KeyType.mouse) { + if (type == KeyType.mouse) { eventTable = this.eventMouseSaved; - } else if (_type == KeyType.finger) { + } else if (type == KeyType.finger) { eventTable = this.eventInputSaved; } else { Log.error("Unknown type of event"); return; } - if (_pointerID > MAX_MANAGE_INPUT || _pointerID < 0) { + if (pointerID > InputManager.MAX_MANAGE_INPUT || pointerID < 0) { // not manage input return; } final Windows tmpWindows = this.context.getWindows(); // special case for the mouse event 0 that represent the hover event of the system : - if (_type == KeyType.mouse && _pointerID == 0) { + if (type == KeyType.mouse && pointerID == 0) { // this event is all time on the good widget ... and manage the enter and leave ... // NOTE : the "layer widget" force us to get the widget at the specific position all the time : Widget tmpWidget = null; @@ -184,54 +183,54 @@ class InputManager { // grab all events ... tmpWidget = this.grabWidget.get(); } else if (tmpWindows != null) { - tmpWidget = tmpWindows.getWidgetAtPos(_pos); + tmpWidget = tmpWindows.getWidgetAtPos(pos); } - if (tmpWidget != eventTable[_pointerID].curentWidgetEvent.get() - || (eventTable[_pointerID].isInside == true && (eventTable[_pointerID].origin.x() > _pos.x() || eventTable[_pointerID].origin.y() > _pos.y() - || (eventTable[_pointerID].origin.x() + eventTable[_pointerID].size.x()) < _pos.x() || (eventTable[_pointerID].origin.y() + eventTable[_pointerID].size.y()) < _pos.y()))) { - eventTable[_pointerID].isInside = false; - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [LEAVE] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, eventTable[_pointerID].curentWidgetEvent.get(), eventTable[_pointerID].destinationInputId, KeyStatus.leave, _pos); + if (tmpWidget != eventTable[pointerID].curentWidgetEvent.get() + || (eventTable[pointerID].isInside && (eventTable[pointerID].origin.x() > pos.x() || eventTable[pointerID].origin.y() > pos.y() + || (eventTable[pointerID].origin.x() + eventTable[pointerID].size.x()) < pos.x() || (eventTable[pointerID].origin.y() + eventTable[pointerID].size.y()) < pos.y()))) { + eventTable[pointerID].isInside = false; + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [LEAVE] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, eventTable[pointerID].curentWidgetEvent.get(), eventTable[pointerID].destinationInputId, KeyStatus.leave, pos); } - if (eventTable[_pointerID].isInside == false) { + if (!eventTable[pointerID].isInside) { // set the element inside ... - eventTable[_pointerID].isInside = true; + eventTable[pointerID].isInside = true; // get destination widget : - eventTable[_pointerID].curentWidgetEvent = new WeakReference<>(tmpWidget); + eventTable[pointerID].curentWidgetEvent = new WeakReference<>(tmpWidget); if (tmpWidget == null) { - eventTable[_pointerID].isInside = false; + eventTable[pointerID].isInside = false; } else { - eventTable[_pointerID].origin = tmpWidget.getOrigin(); - eventTable[_pointerID].size = tmpWidget.getSize(); + eventTable[pointerID].origin = tmpWidget.getOrigin(); + eventTable[pointerID].size = tmpWidget.getSize(); } - eventTable[_pointerID].destinationInputId = 0; - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [ENTER] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, tmpWidget, eventTable[_pointerID].destinationInputId, KeyStatus.enter, _pos); + eventTable[pointerID].destinationInputId = 0; + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [ENTER] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, tmpWidget, eventTable[pointerID].destinationInputId, KeyStatus.enter, pos); } - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [MOVE] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, tmpWidget, eventTable[_pointerID].destinationInputId, KeyStatus.move, _pos); - } else if (eventTable[_pointerID].isUsed == true) { - if (eventTable[_pointerID].isInside == true) { - if (eventTable[_pointerID].origin.x() > _pos.x() || eventTable[_pointerID].origin.y() > _pos.y() || (eventTable[_pointerID].origin.x() + eventTable[_pointerID].size.x()) < _pos.x() - || (eventTable[_pointerID].origin.y() + eventTable[_pointerID].size.y()) < _pos.y()) { - eventTable[_pointerID].isInside = false; - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [LEAVE] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, eventTable[_pointerID].curentWidgetEvent.get(), eventTable[_pointerID].destinationInputId, KeyStatus.leave, _pos); + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [MOVE] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, tmpWidget, eventTable[pointerID].destinationInputId, KeyStatus.move, pos); + } else if (eventTable[pointerID].isUsed) { + if (eventTable[pointerID].isInside) { + if (eventTable[pointerID].origin.x() > pos.x() || eventTable[pointerID].origin.y() > pos.y() || (eventTable[pointerID].origin.x() + eventTable[pointerID].size.x()) < pos.x() + || (eventTable[pointerID].origin.y() + eventTable[pointerID].size.y()) < pos.y()) { + eventTable[pointerID].isInside = false; + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [LEAVE] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, eventTable[pointerID].curentWidgetEvent.get(), eventTable[pointerID].destinationInputId, KeyStatus.leave, pos); } - } else if ((eventTable[_pointerID].origin.x() <= _pos.x() && (eventTable[_pointerID].origin.x() + eventTable[_pointerID].size.x()) >= _pos.x()) - && (eventTable[_pointerID].origin.y() <= _pos.y() && (eventTable[_pointerID].origin.y() + eventTable[_pointerID].size.y()) >= _pos.y())) { - eventTable[_pointerID].isInside = true; - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [ENTER] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, eventTable[_pointerID].curentWidgetEvent.get(), eventTable[_pointerID].destinationInputId, KeyStatus.enter, _pos); + } else if ((eventTable[pointerID].origin.x() <= pos.x() && (eventTable[pointerID].origin.x() + eventTable[pointerID].size.x()) >= pos.x()) + && (eventTable[pointerID].origin.y() <= pos.y() && (eventTable[pointerID].origin.y() + eventTable[pointerID].size.y()) >= pos.y())) { + eventTable[pointerID].isInside = true; + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [ENTER] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, eventTable[pointerID].curentWidgetEvent.get(), eventTable[pointerID].destinationInputId, KeyStatus.enter, pos); } - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [MOVE] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, eventTable[_pointerID].curentWidgetEvent.get(), eventTable[_pointerID].destinationInputId, KeyStatus.move, _pos); + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [MOVE] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, eventTable[pointerID].curentWidgetEvent.get(), eventTable[pointerID].destinationInputId, KeyStatus.move, pos); } } @@ -239,7 +238,7 @@ class InputManager { * a new layer on the windows is set == > might remove all the property of the current element ... */ public void newLayerSet() { - for (int iii = 0; iii < MAX_MANAGE_INPUT; iii++) { + for (int iii = 0; iii < InputManager.MAX_MANAGE_INPUT; iii++) { // remove the property of this input ... abortElement(this.eventInputSaved, iii, KeyType.finger); cleanElement(this.eventInputSaved, iii); @@ -254,30 +253,30 @@ class InputManager { calculateLimit(); } - public void setLastKeyboardSpecial(final KeySpecial _specialKey) { - this.specialKey = _specialKey; + public void setLastKeyboardSpecial(final KeySpecial specialKey) { + this.specialKey = specialKey; } - public void state(final KeyType _type, final int _pointerID, final boolean _isDown, final Vector2f _pos) { - if (_pointerID >= MAX_MANAGE_INPUT) { + public void state(final KeyType type, final int pointerID, final boolean isDown, final Vector2f pos) { + if (pointerID >= InputManager.MAX_MANAGE_INPUT) { // reject pointer == > out of IDs... return; } - //Log.debug("event pointerId=" + _pointerID); + //Log.debug("event pointerId=" + pointerID); // convert position in open-GL coordonates ... InputPoperty[] eventTable = null; InputLimit localLimit; - if (_type == KeyType.mouse) { + if (type == KeyType.mouse) { eventTable = this.eventMouseSaved; localLimit = this.eventMouseLimit; - } else if (_type == KeyType.finger) { + } else if (type == KeyType.finger) { eventTable = this.eventInputSaved; localLimit = this.eventInputLimit; } else { Log.error("Unknown type of event"); return; } - if (_pointerID > MAX_MANAGE_INPUT || _pointerID <= 0) { + if (pointerID > InputManager.MAX_MANAGE_INPUT || pointerID <= 0) { // not manage input return; } @@ -285,119 +284,117 @@ class InputManager { final Clock currentTime = Clock.now(); final Windows tmpWindows = this.context.getWindows(); - if (_isDown == true) { - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [DOWN] " + _pos); - if (eventTable[_pointerID].isUsed == true) { + if (isDown) { + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [DOWN] " + pos); + if (eventTable[pointerID].isUsed) { // we have an event previously ... check delay between click and offset position - if (currentTime.less(eventTable[_pointerID].lastTimeEvent).isGreaterThan(localLimit.sepatateTime)) { - cleanElement(eventTable, _pointerID); - } else if (FMath.abs(eventTable[_pointerID].downStart.x() - _pos.x()) >= localLimit.DpiOffset || FMath.abs(eventTable[_pointerID].downStart.y() - _pos.y()) >= localLimit.DpiOffset) { - cleanElement(eventTable, _pointerID); + if (currentTime.less(eventTable[pointerID].lastTimeEvent).isGreaterThan(localLimit.sepatateTime)) { + cleanElement(eventTable, pointerID); + } else if (FMath.abs(eventTable[pointerID].downStart.x() - pos.x()) >= localLimit.dpiOffset || FMath.abs(eventTable[pointerID].downStart.y() - pos.y()) >= localLimit.dpiOffset) { + cleanElement(eventTable, pointerID); } } - if (eventTable[_pointerID].isUsed == true) { + if (eventTable[pointerID].isUsed) { // save start time - eventTable[_pointerID].lastTimeEvent = currentTime; + eventTable[pointerID].lastTimeEvent = currentTime; // generate DOWN Event - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [DOWN] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, eventTable[_pointerID].curentWidgetEvent.get(), eventTable[_pointerID].destinationInputId, KeyStatus.down, _pos); + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [DOWN] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, eventTable[pointerID].curentWidgetEvent.get(), eventTable[pointerID].destinationInputId, KeyStatus.down, pos); } else { // Mark it used : - eventTable[_pointerID].isUsed = true; + eventTable[pointerID].isUsed = true; // Save current position : - eventTable[_pointerID].downStart = _pos; + eventTable[pointerID].downStart = pos; // save start time - eventTable[_pointerID].lastTimeEvent = currentTime; + eventTable[pointerID].lastTimeEvent = currentTime; // set the element inside ... - eventTable[_pointerID].isInside = true; + eventTable[pointerID].isInside = true; Widget tmpWidget = this.grabWidget.get(); // get destination widget : if (tmpWindows != null) { - if (tmpWidget != null && _type == KeyType.mouse) { - eventTable[_pointerID].curentWidgetEvent = new WeakReference<>(tmpWidget); + if (tmpWidget != null && type == KeyType.mouse) { + eventTable[pointerID].curentWidgetEvent = new WeakReference<>(tmpWidget); } else { - tmpWidget = tmpWindows.getWidgetAtPos(_pos); - eventTable[_pointerID].curentWidgetEvent = new WeakReference<>(tmpWidget); + tmpWidget = tmpWindows.getWidgetAtPos(pos); + eventTable[pointerID].curentWidgetEvent = new WeakReference<>(tmpWidget); /* if (tmpWidget != null) { - Log.debug("Get widget at pos=" + _pos + " type: " + tmpWidget.getObjectType()); + Log.debug("Get widget at pos=" + pos + " type: " + tmpWidget.getObjectType()); } else { - Log.debug("Get widget at pos=" + _pos + " NO WIDGET"); + Log.debug("Get widget at pos=" + pos + " NO WIDGET"); } */ } } else { - eventTable[_pointerID].curentWidgetEvent = null; + eventTable[pointerID].curentWidgetEvent = null; } - tmpWidget = eventTable[_pointerID].curentWidgetEvent.get(); + tmpWidget = eventTable[pointerID].curentWidgetEvent.get(); if (tmpWidget != null) { - eventTable[_pointerID].origin = tmpWidget.getOrigin(); - eventTable[_pointerID].size = tmpWidget.getSize(); - eventTable[_pointerID].destinationInputId = localGetDestinationId(_type, tmpWidget, _pointerID); + eventTable[pointerID].origin = tmpWidget.getOrigin(); + eventTable[pointerID].size = tmpWidget.getSize(); + eventTable[pointerID].destinationInputId = localGetDestinationId(type, tmpWidget, pointerID); } else { - eventTable[_pointerID].destinationInputId = -1; + eventTable[pointerID].destinationInputId = -1; } // generate DOWN Event - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [DOWN] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, tmpWidget, eventTable[_pointerID].destinationInputId, KeyStatus.down, _pos); + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [DOWN] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, tmpWidget, eventTable[pointerID].destinationInputId, KeyStatus.down, pos); } } else { - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [UP] " + _pos); - final Widget tmpWidget = eventTable[_pointerID].curentWidgetEvent.get(); - if (eventTable[_pointerID].isUsed == false) { + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [UP] " + pos); + final Widget tmpWidget = eventTable[pointerID].curentWidgetEvent.get(); + if (!eventTable[pointerID].isUsed) { // bad case ... ??? Log.debug("Up event without previous down ... "); // Mark it un-used : - eventTable[_pointerID].isUsed = false; + eventTable[pointerID].isUsed = false; // revove the widget ... - eventTable[_pointerID].curentWidgetEvent = null; + eventTable[pointerID].curentWidgetEvent = null; } else if (tmpWidget == null) { // The widget has been removed: //Log.debug(" Object Removed ..."); // Mark it un-used : - eventTable[_pointerID].isUsed = false; + eventTable[pointerID].isUsed = false; // revove the widget ... - eventTable[_pointerID].curentWidgetEvent = null; + eventTable[pointerID].curentWidgetEvent = null; } else { // generate UP Event - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [UP] " + _pos); - eventTable[_pointerID].posEvent = _pos; + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [UP] " + pos); + eventTable[pointerID].posEvent = pos; // send up event after the single event to prevent multiple widget getting elements - localEventInput(_type, tmpWidget, _pointerID, KeyStatus.up, _pos); + localEventInput(type, tmpWidget, pointerID, KeyStatus.up, pos); // generate event (single) - if (FMath.abs(eventTable[_pointerID].downStart.x() - _pos.x()) < localLimit.DpiOffset && FMath.abs(eventTable[_pointerID].downStart.y() - _pos.y()) < localLimit.DpiOffset) { + if (FMath.abs(eventTable[pointerID].downStart.x() - pos.x()) < localLimit.dpiOffset && FMath.abs(eventTable[pointerID].downStart.y() - pos.y()) < localLimit.dpiOffset) { // Save current position : - eventTable[_pointerID].downStart = _pos; + eventTable[pointerID].downStart = pos; // save start time - eventTable[_pointerID].lastTimeEvent = currentTime; + eventTable[pointerID].lastTimeEvent = currentTime; int nbClickMax = 0; - if (tmpWidget != null) { - nbClickMax = tmpWidget.getMouseLimit(); - if (nbClickMax > 5) { - nbClickMax = 5; - } + nbClickMax = tmpWidget.getMouseLimit(); + if (nbClickMax > 5) { + nbClickMax = 5; } // in grab mode the single to quinte event are not generated .... - if ((this.grabWidget.get() == null || _type != KeyType.mouse) && eventTable[_pointerID].nbClickEvent < nbClickMax) { + if ((this.grabWidget.get() == null || type != KeyType.mouse) && eventTable[pointerID].nbClickEvent < nbClickMax) { // generate event SINGLE : - eventTable[_pointerID].nbClickEvent++; - //Log.debug("GUI : Input ID=" + _pointerID + " == >" + eventTable[_pointerID].destinationInputId + " [" + eventTable[_pointerID].nbClickEvent + "] " + _pos); - eventTable[_pointerID].posEvent = _pos; - localEventInput(_type, tmpWidget, eventTable[_pointerID].destinationInputId, KeyStatus.pressCount(eventTable[_pointerID].nbClickEvent), _pos); - if (eventTable[_pointerID].nbClickEvent >= nbClickMax) { - eventTable[_pointerID].nbClickEvent = 0; + eventTable[pointerID].nbClickEvent++; + //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [" + eventTable[pointerID].nbClickEvent + "] " + pos); + eventTable[pointerID].posEvent = pos; + localEventInput(type, tmpWidget, eventTable[pointerID].destinationInputId, KeyStatus.pressCount(eventTable[pointerID].nbClickEvent), pos); + if (eventTable[pointerID].nbClickEvent >= nbClickMax) { + eventTable[pointerID].nbClickEvent = 0; } } else { - eventTable[_pointerID].nbClickEvent = 0; + eventTable[pointerID].nbClickEvent = 0; } } // send up event after the single event to prevent multiple widget getting elements - localEventInput(_type, tmpWidget, _pointerID, KeyStatus.upAfter, _pos); + localEventInput(type, tmpWidget, pointerID, KeyStatus.upAfter, pos); // specific for tuch event - if (_type == KeyType.finger) { - cleanElement(eventTable, _pointerID); + if (type == KeyType.finger) { + cleanElement(eventTable, pointerID); } } } @@ -405,36 +402,36 @@ class InputManager { /** * 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 + * @param source the widget where the event came from + * @param destination the widget where the event mitgh be generated now */ - public void transfertEvent(final Widget _source, final Widget _destination) { - if (_source == null || _destination == null) { + public void transfertEvent(final Widget source, final Widget destination) { + if (source == null || destination == null) { // prevent errors ... return; } - for (int iii = 0; iii < MAX_MANAGE_INPUT; iii++) { + for (int iii = 0; iii < InputManager.MAX_MANAGE_INPUT; iii++) { Widget tmpWidget = this.eventInputSaved[iii].curentWidgetEvent.get(); - if (tmpWidget == _source) { + if (tmpWidget == source) { // inform the widget that it does not receive the event now - //Log.debug("GUI : Input ID=" + iii + " == >" + this.eventInputSaved[iii].destinationInputId + " [EVENT_INPUT_TYPE_ABORT] " + this.eventInputSaved[iii].posEvent); + //Log.debug("GUI : Input ID=" + iii + " == >" + this.eventInputSaved[iii].destinationInputId + " [EVENTINPUTTYPEABORT] " + this.eventInputSaved[iii].posEvent); localEventInput(KeyType.finger, tmpWidget, this.eventInputSaved[iii].destinationInputId, KeyStatus.abort, this.eventInputSaved[iii].posEvent); // set the new widget ... - this.eventInputSaved[iii].curentWidgetEvent = new WeakReference<>(_destination); + this.eventInputSaved[iii].curentWidgetEvent = new WeakReference<>(destination); // inform the widget that he receive the event property now... - //Log.debug("GUI : Input ID=" + iii + " == >" + this.eventInputSaved[iii].destinationInputId + " [EVENT_INPUT_TYPE_TRANSFERT] " + this.eventInputSaved[iii].posEvent); - localEventInput(KeyType.finger, _destination, this.eventInputSaved[iii].destinationInputId, KeyStatus.transfert, this.eventInputSaved[iii].posEvent); + //Log.debug("GUI : Input ID=" + iii + " == >" + this.eventInputSaved[iii].destinationInputId + " [EVENTINPUTTYPETRANSFERT] " + this.eventInputSaved[iii].posEvent); + localEventInput(KeyType.finger, destination, this.eventInputSaved[iii].destinationInputId, KeyStatus.transfer, this.eventInputSaved[iii].posEvent); } tmpWidget = this.eventMouseSaved[iii].curentWidgetEvent.get(); - if (tmpWidget == _source) { + if (tmpWidget == source) { // inform the widget that it does not receive the event now - //Log.debug("GUI : Input ID=" + iii + " == >" + this.eventMouseSaved[iii].destinationInputId + " [EVENT_INPUT_TYPE_ABORT] " + this.eventMouseSaved[iii].posEvent); + //Log.debug("GUI : Input ID=" + iii + " == >" + this.eventMouseSaved[iii].destinationInputId + " [EVENTINPUTTYPEABORT] " + this.eventMouseSaved[iii].posEvent); localEventInput(KeyType.mouse, tmpWidget, this.eventMouseSaved[iii].destinationInputId, KeyStatus.abort, this.eventMouseSaved[iii].posEvent); // set the new widget ... - this.eventMouseSaved[iii].curentWidgetEvent = new WeakReference<>(_destination); + this.eventMouseSaved[iii].curentWidgetEvent = new WeakReference<>(destination); // inform the widget that he receive the event property now... - //Log.debug("GUI : Input ID=" + iii + " == >" + this.eventMouseSaved[iii].destinationInputId + " [EVENT_INPUT_TYPE_TRANSFERT] " + this.eventMouseSaved[iii].posEvent); - localEventInput(KeyType.mouse, _destination, this.eventMouseSaved[iii].destinationInputId, KeyStatus.transfert, this.eventMouseSaved[iii].posEvent); + //Log.debug("GUI : Input ID=" + iii + " == >" + this.eventMouseSaved[iii].destinationInputId + " [EVENTINPUTTYPETRANSFERT] " + this.eventMouseSaved[iii].posEvent); + localEventInput(KeyType.mouse, destination, this.eventMouseSaved[iii].destinationInputId, KeyStatus.transfer, this.eventMouseSaved[iii].posEvent); } } } @@ -444,24 +441,24 @@ class InputManager { */ public void unGrabPointer() { this.grabWidget = null; - // TODO: this.context.grabPointerEvents(false, Vector2f(0,0)); + // TODO this.context.grabPointerEvents(false, Vector2f(0,0)); } -}; +} /** * internal structure */ class InputPoperty { - public boolean isUsed; - public int destinationInputId; - public Clock lastTimeEvent; public WeakReference curentWidgetEvent; - public Vector2f origin; - public Vector2f size; + public int destinationInputId; public Vector2f downStart; - public Vector2f posEvent; public boolean isDown; public boolean isInside; + public boolean isUsed; + public Clock lastTimeEvent; public int nbClickEvent; // 0 .. 1 .. 2 .. 3 + public Vector2f origin; + public Vector2f posEvent; + public Vector2f size; } diff --git a/src/org/atriasoft/ewol/event/EntrySystem.java b/src/org/atriasoft/ewol/event/EntrySystem.java index 7830843..cba6dd0 100644 --- a/src/org/atriasoft/ewol/event/EntrySystem.java +++ b/src/org/atriasoft/ewol/event/EntrySystem.java @@ -4,10 +4,13 @@ import org.atriasoft.gale.key.KeyKeyboard; import org.atriasoft.gale.key.KeySpecial; import org.atriasoft.gale.key.KeyStatus; -public class EntrySystem { - public final EventEntry event; +public record EntrySystem( + EventEntry event) { + public EntrySystem(final EventEntry event) { + this.event = event; + } - public EntrySystem(final KeyKeyboard _type, final KeyStatus _status, final KeySpecial _specialKey, final Character _char) { - this.event = new EventEntry(_specialKey, _type, _status, _char); + public EntrySystem(final KeyKeyboard type, final KeyStatus status, final KeySpecial specialKey, final Character unicodeChar) { + this(new EventEntry(specialKey, type, status, unicodeChar)); } } \ No newline at end of file diff --git a/src/org/atriasoft/ewol/event/EventEntry.java b/src/org/atriasoft/ewol/event/EventEntry.java index 8a5bbab..56f6c0c 100644 --- a/src/org/atriasoft/ewol/event/EventEntry.java +++ b/src/org/atriasoft/ewol/event/EventEntry.java @@ -4,35 +4,17 @@ import org.atriasoft.gale.key.KeyKeyboard; import org.atriasoft.gale.key.KeySpecial; import org.atriasoft.gale.key.KeyStatus; -public class EventEntry { - private final KeySpecial specialKey; //!< input key status (prevent change in time..) - private final KeyKeyboard type; //!< type of hardware event - private final KeyStatus status; //!< status of hardware event - private final Character unicodeData; //!< Unicode data (in some case) - - public EventEntry(final KeySpecial specialKey, final KeyKeyboard type, final KeyStatus status, final Character charValue) { - this.type = type; - this.status = status; - this.specialKey = specialKey; - this.unicodeData = charValue; - } +public record EventEntry( + KeySpecial specialKey, //!< input key status (prevent change in time..) + KeyKeyboard type, //!< type of hardware event + KeyStatus status, //!< status of hardware event + Character unicodeData //!< Unicode data (in some case) + ){ public Character getChar() { return this.unicodeData; } - public KeySpecial getSpecialKey() { - return this.specialKey; - } - - public KeyStatus getStatus() { - return this.status; - } - - public KeyKeyboard getType() { - return this.type; - }; - @Override public String toString() { return "EventEntry [type=" + this.type + ", status=" + this.status + ", unicodeData=" + this.unicodeData + ", specialKey=" + this.specialKey + "]"; diff --git a/src/org/atriasoft/ewol/event/EventInput.java b/src/org/atriasoft/ewol/event/EventInput.java index d18816a..31f27a0 100644 --- a/src/org/atriasoft/ewol/event/EventInput.java +++ b/src/org/atriasoft/ewol/event/EventInput.java @@ -11,66 +11,11 @@ import org.atriasoft.gale.key.KeyType; * @license MPL v2.0 (see license file) */ -public class EventInput { - private KeyType type; - private KeyStatus status; - private int inputId; - private Vector2f pos; - private KeySpecial specialKey; //!< input key status (prevent change in time..) +public record EventInput( + KeyType type, + KeyStatus status, + int inputId, + Vector2f pos, + KeySpecial specialKey) { - public EventInput(final KeyType _type, final KeyStatus _status, final int _id, final Vector2f _pos, final KeySpecial _specialKey) { - this.type = _type; - this.status = _status; - this.inputId = _id; - this.pos = _pos; - this.specialKey = _specialKey; - - }; - - public int getId() { - return this.inputId; - }; - - public Vector2f getPos() { - return this.pos; - }; - - public KeySpecial getSpecialKey() { - return this.specialKey; - }; - - public KeyStatus getStatus() { - return this.status; - }; - - public KeyType getType() { - return this.type; - }; - - /** - * Reset the input property of the curent event. - */ - public void reset() { - // TODO : Call the entry element ant rest it ... - }; - - public void setId(final int _id) { - this.inputId = _id; - }; - - public void setPos(final Vector2f _pos) { - this.pos = _pos; - }; - - public void setSpecialKey(final KeySpecial _specialKey) { - this.specialKey = _specialKey; - }; - - public void setStatus(final KeyStatus _status) { - this.status = _status; - }; - - public void setType(final KeyType _type) { - this.type = _type; - } } diff --git a/src/org/atriasoft/ewol/event/EventShortCut.java b/src/org/atriasoft/ewol/event/EventShortCut.java index 654dd86..d793755 100644 --- a/src/org/atriasoft/ewol/event/EventShortCut.java +++ b/src/org/atriasoft/ewol/event/EventShortCut.java @@ -3,19 +3,33 @@ 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 class EventShortCut{ + private final String message; //!< data link with the event + private final KeySpecial specialKey; //!< special board key + private final Character unicodeValue; //!< 0 if not used + private 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(); + public EventShortCut(String message, KeySpecial specialKey, Character unicodeValue, KeyKeyboard keyboardMoveValue, boolean isActive) { this.message = message; this.specialKey = specialKey; this.unicodeValue = unicodeValue; this.keyboardMoveValue = keyboardMoveValue; this.isActive = isActive; } + + public String message() { + return message; + } + + public KeySpecial specialKey() { + return specialKey; + } + + public Character unicodeValue() { + return unicodeValue; + } + + public KeyKeyboard keyboardMoveValue() { + return keyboardMoveValue; + } } diff --git a/src/org/atriasoft/ewol/event/EventTime.java b/src/org/atriasoft/ewol/event/EventTime.java index 7321c74..f5495f7 100644 --- a/src/org/atriasoft/ewol/event/EventTime.java +++ b/src/org/atriasoft/ewol/event/EventTime.java @@ -8,46 +8,18 @@ import org.atriasoft.echrono.Duration; * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ -public class EventTime { - private final Clock timeSystem; //!< Current system time (micro-second) - private final Clock timeUpAppl; //!< Current application wake up-time (micro-second) - private final Duration timeDelta; //!< Time from the last cycle call of the system (main appl tick) (second) - private final Duration timeDeltaCall; //!< Time from the last call (when we can manage periodic call with specifying periode) (second) - - public EventTime(final Clock _timeSystem, final Clock _timeUpAppl, final Duration _timeDelta, final Duration _timeDeltaCall) { - this.timeSystem = _timeSystem; - this.timeUpAppl = _timeUpAppl; - this.timeDelta = _timeDelta; - this.timeDeltaCall = _timeDeltaCall; - - }; +public record EventTime( + Clock timeSystem, //!< Current system time (micro-second) + Clock timeUpAppl, //!< Current application wake up-time (micro-second) + Duration timeDelta, //!< Time from the last cycle call of the system (main appl tick) (second) + Duration timeDeltaCall //!< Time from the last call (when we can manage periodic call with specifying periode) (second) + ) { + public float getTimeDeltaCallSecond() { + return this.timeDeltaCall.toSeconds(); + } public Duration getApplUpTime() { return this.timeSystem.less(this.timeUpAppl); }; - public Clock getApplWakeUpTime() { - return this.timeUpAppl; - }; - - public float getDelta() { - return this.timeDelta.toSeconds(); - }; - - public float getDeltaCall() { - return this.timeDeltaCall.toSeconds(); - }; - - public Duration getDeltaCallDuration() { - return this.timeDeltaCall; - }; - - public Duration getDeltaDuration() { - return this.timeDelta; - }; - - public Clock getTime() { - return this.timeSystem; - }; - } diff --git a/src/org/atriasoft/ewol/event/InputSystem.java b/src/org/atriasoft/ewol/event/InputSystem.java index 3ee16a4..de12053 100644 --- a/src/org/atriasoft/ewol/event/InputSystem.java +++ b/src/org/atriasoft/ewol/event/InputSystem.java @@ -6,32 +6,19 @@ import org.atriasoft.gale.key.KeySpecial; import org.atriasoft.gale.key.KeyStatus; import org.atriasoft.gale.key.KeyType; -public class InputSystem { - public EventInput event; - - private Widget dest; - - private int realIdEvent; - - public InputSystem(final KeyType _type, final KeyStatus _status, final int _id, final Vector2f _pos, final Widget _dest, final int _realIdEvent, final KeySpecial _specialKey) { - this.event = new EventInput(_type, _status, _id, _pos, _specialKey); - this.dest = _dest; - this.realIdEvent = _realIdEvent; +@SuppressWarnings("preview") +public record InputSystem( + EventInput event, + Widget dest, + int realIdEvent) { + public InputSystem(final EventInput event, final Widget dest, final int realIdEvent) { + this.event = event; + this.dest = dest; + this.realIdEvent = realIdEvent; } - public Widget getDestWidget() { - return this.dest; + public InputSystem(final KeyType type, final KeyStatus status, final int id, final Vector2f pos, final Widget dest, final int realIdEvent, final KeySpecial specialKey) { + this(new EventInput(type, status, id, pos, specialKey), dest, realIdEvent); } - public int getRealId() { - return this.realIdEvent; - } - - public void setDestWidget(final Widget _dest) { - this.dest = _dest; - } - - public void setRealId(final int _realIdEvent) { - this.realIdEvent = _realIdEvent; - } } \ No newline at end of file diff --git a/src/org/atriasoft/ewol/ewol.cpp b/src/org/atriasoft/ewol/ewol.cpp deleted file mode 100644 index 0d5d735..0000000 --- a/src/org/atriasoft/ewol/ewol.cpp +++ /dev/null @@ -1,32 +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 - -#ifndef EWOL_VERSION -#define EWOL_VERSION "0.0.0" -#endif - -String ewol::getVersion() { - return EWOL_VERSION; -} - - -int ewol::run(EwolApplication* _application, - int _argc, - char* _argv[]) { - etranslate::init(_argc, _argv); - return gale::run(ETK_NEW(EwolContext, _application), _argc, _argv); -} - - diff --git a/src/org/atriasoft/ewol/internal/Tools.java b/src/org/atriasoft/ewol/internal/Tools.java index b706c0c..ffe804d 100644 --- a/src/org/atriasoft/ewol/internal/Tools.java +++ b/src/org/atriasoft/ewol/internal/Tools.java @@ -6,10 +6,10 @@ public class Tools { * @param value Value that we want the next power of 2 * @return result value */ - public static int nextP2(final int _value) { + public static int nextP2(final int value) { int val = 1; for (int iii = 1; iii < 31; iii++) { - if (_value <= val) { + if (value <= val) { return val; } val *= 2; diff --git a/src/org/atriasoft/ewol/object/EwolObject.java b/src/org/atriasoft/ewol/object/EwolObject.java index 50beca6..2df0312 100644 --- a/src/org/atriasoft/ewol/object/EwolObject.java +++ b/src/org/atriasoft/ewol/object/EwolObject.java @@ -38,38 +38,38 @@ public class EwolObject { /** * Retrive an object with his name (in the global list) - * @param _name Name of the object + * @param objectName Name of the object * @return the requested object or null */ - public static EwolObject getObjectNamed(final String _objectName) { - return getObjectManager().getObjectNamed(_objectName); + public static EwolObject getObjectNamed(final String objectName) { + return EwolObject.getObjectManager().getObjectNamed(objectName); } + protected boolean destroy = false; //!< Flag to know if the object is requesting has destroy. + + private boolean isResource = false; //!< enable this when you want to declare this element is auto-remove + //@EwolPropertyDescription("Object name, might be a unique reference in all the program") //@JacksonXmlProperty(isAttribute = true, localName = "name") protected String name = ""; //!< name of the element ... protected WeakReference parent = null; //!< Reference on the current parent. - protected boolean destroy = false; //!< Flag to know if the object is requesting has destroy. - private final boolean staticObject = false; //!< set this variable at true if this element must not be auto destroy (exemple : use static object); private final int uniqueId; //!< Object UniqueID == > TODO : Check if it use is needed - private boolean isResource = false; //!< enable this when you want to declare this element is auto-remove - /** * Constructor. */ public EwolObject() { // note this is nearly atomic ... (but it is enough) - synchronized (valUID) { + synchronized (EwolObject.valUID) { this.uniqueId = EwolObject.valUID++; } Log.debug("new Object : [" + this.uniqueId + "]"); - getObjectManager().add(this); + EwolObject.getObjectManager().add(this); } /** @@ -93,7 +93,7 @@ public class EwolObject { */ public void destroy() { autoDestroy(); - }; + } /** * get the UniqueId of the Object @@ -105,22 +105,22 @@ public class EwolObject { public String getName() { return this.name; - }; + } /** * load attribute properties with an XML node. - * @param _node Reference on the XML node. + * @param node Reference on the XML node. * @return true : All has been done corectly. * @return false : An error occured. */ /* - boolean loadXMLAttributes( exml::Element _node){ - if (_node.exist() == false) { + boolean loadXMLAttributes( exml::Element node){ + if (node.exist() == false) { return false; } boolean errorOccured = false; - for( auto it : _node.attributes) { + for( auto it : node.attributes) { auto pair = it.getPair(); if (pair.first == "") { continue; @@ -133,35 +133,6 @@ public class EwolObject { } */ - /** - * load properties with an XML node. - * @param _node Reference on the XML node. - * @return true : All has been done corectly. - * @return false : An error occured. - */ - protected boolean loadXML(XmlElement _node) { - return true; - } - - /** - * store properties in this XML node. - * @param[in,out] _node Reference on the XML node. - * @return true : All has been done corectly. - * @return false : An error occured. - */ - /* - boolean storeXML(exml::Element _node){ - if (_node.exist() == false) { - return false; - } - boolean errorOccured = true; - for (auto it : properties.getAll(true)) { - _node.attributes.set(it.first, it.second); - } - return errorOccured; - } - */ - /** * get the static status of the Object == > mark at true if the user set the object mark as static allocated element ==> not auto remove element * @return true if it might not be removed == > usefull for conficuration class @@ -170,6 +141,25 @@ public class EwolObject { return this.staticObject; } + /** + * store properties in this XML node. + * @param[in,out] node Reference on the XML node. + * @return true : All has been done corectly. + * @return false : An error occured. + */ + /* + boolean storeXML(exml::Element node){ + if (node.exist() == false) { + return false; + } + boolean errorOccured = true; + for (auto it : properties.getAll(true)) { + node.attributes.set(it.first, it.second); + } + return errorOccured; + } + */ + /** * Get the resource status of the element. * @return the resource status. @@ -180,12 +170,12 @@ public class EwolObject { /** * Retrive an object with his name (in the global list) - * @param _name Name of the object + * @param name Name of the object * @return the requested object or null */ - public EwolObject getSubObjectNamed(final String _objectName) { - Log.verbose("check if name : " + _objectName + " ?= " + this.name); - if (_objectName == this.name) { + public EwolObject getSubObjectNamed(final String objectName) { + Log.verbose("check if name : " + objectName + " ?= " + this.name); + if (objectName.equals(this.name)) { return this; } return null; @@ -200,6 +190,16 @@ public class EwolObject { return this.destroy; } + /** + * load properties with an XML node. + * @param node Reference on the XML node. + * @return true : All has been done corectly. + * @return false : An error occured. + */ + protected boolean loadXML(final XmlElement node) { + return true; + } + /** * Remove the current parenting. */ @@ -209,9 +209,9 @@ public class EwolObject { /** * Called by a whild that want to remove pointer of itself from the current list of his parrent - * @param _child Object of the child that want to remove itself + * @param child Object of the child that want to remove itself */ - protected void requestDestroyFromChild(final EwolObject _child) { + protected void requestDestroyFromChild(final EwolObject child) { Log.info("requestDestroyFromChild(...) is called when an object reference as a parent have a child that request quto-destroy ..."); Log.critical("Call From Child with no effects ==> must implement : requestDestroyFromChild(...)"); } @@ -222,20 +222,20 @@ public class EwolObject { /** * Set the Object has new parrent. - * @param _newParent Object that requesting the parenting + * @param newParent Object that requesting the parenting */ - public void setParent(final EwolObject _newParent) { + public void setParent(final EwolObject newParent) { // TODO : Implement change of parent ... - this.parent = new WeakReference<>(_newParent); + this.parent = new WeakReference<>(newParent); } /** * Declare this element as a resource (or singleton) this mean the element will * not be auto Remove at the end of the programm. It just notify that it is not removed. - * @param _val Value of the type of the element. + * @param val Value of the type of the element. */ - public void setStatusResource(final boolean _val) { - this.isResource = _val; + public void setStatusResource(final boolean val) { + this.isResource = val; } } diff --git a/src/org/atriasoft/ewol/object/ObjectManager.java b/src/org/atriasoft/ewol/object/ObjectManager.java index 589db19..45dbcee 100644 --- a/src/org/atriasoft/ewol/object/ObjectManager.java +++ b/src/org/atriasoft/ewol/object/ObjectManager.java @@ -20,19 +20,19 @@ import org.atriasoft.ewol.internal.Log; */ public class ObjectManager { - private final List> eObjectList = new ArrayList<>(); // all widget allocated == > all time increment ... never removed ... + private final Time applWakeUpTime; //!< Time of the application initialize private EwolContext context = null; - private final List workerList = new ArrayList<>(); - - public final Signal periodicCall = new Signal<>(); - - private final Time applWakeUpTime; //!< Time of the application initialize + private final List> eObjectList = new ArrayList<>(); // all widget allocated == > all time increment ... never removed ... private Clock lastPeriodicCallTime; //!< last call time ... - public ObjectManager(final EwolContext _context) { - this.context = _context; + public final Signal periodicCall = new Signal<>(); + + private final List workerList = new ArrayList<>(); + + public ObjectManager(final EwolContext context) { + this.context = context; //periodicCall(this, "periodic", "Call every time system render"); Log.debug(" == > init Object-Manager"); Log.todo("set this back ..."); @@ -45,17 +45,17 @@ public class ObjectManager { /** * Internal API that used only with Object toi reference itself in the manager. * @note The manager remove the object when the refecence Low down 1 (last keeper) - * @param _object Reference shared pointer on the object + * @param object Reference shared pointer on the object */ - public synchronized void add(final EwolObject _object) { - if (_object == null) { + public synchronized void add(final EwolObject object) { + if (object == null) { Log.error("try to add an inexistant Object in manager"); } - this.eObjectList.add(new WeakReference<>(_object)); + this.eObjectList.add(new WeakReference<>(object)); } /** - * clean the weak pointer list (remove weak_ptr that is remoed) + * clean the weak pointer list (remove weakptr that is remoed) */ public synchronized void cleanInternalRemoved() { final int nbObject = this.eObjectList.size(); @@ -87,16 +87,16 @@ public class ObjectManager { /** * Retrive an Object with his name - * @param _name Name of the Object + * @param name Name of the Object * @return Pointer on the finded Object. */ - public synchronized EwolObject get(final String _name) { - if (_name.isEmpty() == true) { + public synchronized EwolObject get(final String name) { + if (name.isEmpty()) { return null; } for (final WeakReference it : this.eObjectList) { final EwolObject element = it.get(); - if (element != null && element.getName().contentEquals(_name)) { + if (element != null && element.getName().contentEquals(name)) { return element; } } @@ -113,26 +113,26 @@ public class ObjectManager { /** * retrive an object with his name - * @param _name Name of the object + * @param name Name of the object * @return the requested object or null */ - public synchronized EwolObject getObjectNamed(final String _name) { - return get(_name); + public synchronized EwolObject getObjectNamed(final String name) { + return get(name); } /** * Call every time we can with the current time - * @param _localTime Current system Time. + * @param localTime Current system Time. */ - public synchronized void timeCall(final Clock _localTime) { + public synchronized void timeCall(final Clock localTime) { final Clock previousTime = this.lastPeriodicCallTime; - this.lastPeriodicCallTime = _localTime; + this.lastPeriodicCallTime = localTime; if (this.periodicCall.size() <= 0) { return; } - final Duration deltaTime = new Duration(_localTime.get() - previousTime.get()); + final Duration deltaTime = new Duration(localTime.get() - previousTime.get()); - final EventTime myTime = new EventTime(_localTime, this.applWakeUpTime.toClock(), deltaTime, deltaTime); + final EventTime myTime = new EventTime(localTime, this.applWakeUpTime.toClock(), deltaTime, deltaTime); this.periodicCall.emit(myTime); } @@ -146,10 +146,10 @@ public class ObjectManager { /** * If the application is suspended The Ewol Object manager does not know it, just call this to update delta call - * @param _localTime Current system Time. + * @param localTime Current system Time. */ - public synchronized void timeCallResume(final Clock _localTime) { - this.lastPeriodicCallTime = _localTime; + public synchronized void timeCallResume(final Clock localTime) { + this.lastPeriodicCallTime = localTime; } /** @@ -175,22 +175,22 @@ public class ObjectManager { /** * Add a worker on the system list. - * @param _worker Worker to add in the list. + * @param worker Worker to add in the list. */ - public synchronized void workerAdd(final EwolObject _worker) { - this.workerList.add(_worker); + public synchronized void workerAdd(final EwolObject worker) { + this.workerList.add(worker); } /** * Remove a worker on the system list. - * @param _worker Worker to add in the list. + * @param worker Worker to add in the list. */ - public synchronized void workerRemove(final EwolObject _worker) { + public synchronized void workerRemove(final EwolObject worker) { final Iterator iterator = this.workerList.iterator(); while (iterator.hasNext()) { final EwolObject elem = iterator.next(); - if (elem == _worker) { + if (elem == worker) { iterator.remove(); } } diff --git a/src/org/atriasoft/ewol/resource/RefactorColored3DObject.java b/src/org/atriasoft/ewol/resource/RefactorColored3DObject.java index 1867f2e..b6a992a 100644 --- a/src/org/atriasoft/ewol/resource/RefactorColored3DObject.java +++ b/src/org/atriasoft/ewol/resource/RefactorColored3DObject.java @@ -22,143 +22,136 @@ import org.atriasoft.gale.resource.ResourceProgram; * ALL platform (like webGL) */ public class RefactorColored3DObject extends Resource { - protected ResourceProgram GLprogram; - protected int GLPosition; - protected int GLMatrix; - protected int GLColor; - + protected int oGLColor; + protected int oGLMatrix; + protected int oGLPosition; + protected ResourceProgram oGLprogram; + 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")); - 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"); + this.oGLPosition = 0; + this.oGLprogram = ResourceProgram.create(new Uri("DATA", "simple3D.vert", "ewol"), new Uri("DATA", "simple3D.frag", "ewol")); + if (this.oGLprogram != null) { + this.oGLPosition = this.oGLprogram.getAttribute("EWcoord3d"); + this.oGLColor = this.oGLprogram.getUniform("EWcolor"); + this.oGLMatrix = this.oGLprogram.getUniform("EWMatrixTransformation"); } } - + @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) { + draw(vertices, color, true, true); } - - public void draw(final List _vertices, final Color _color, final boolean _updateDepthBuffer, - final boolean _depthtest) { - if (_vertices.size() <= 0) { + + public void draw(final List vertices, final Color color, final boolean updateDepthBuffer, final boolean depthtest) { + if (vertices.size() <= 0) { return; } - if (this.GLprogram == null) { + if (this.oGLprogram == null) { Log.error("No shader ..."); return; } - if (true == _depthtest) { + if (depthtest) { OpenGL.enable(OpenGL.Flag.flag_depthTest); - if (false == _updateDepthBuffer) { + if (!updateDepthBuffer) { OpenGL.setDeathMask(false); } } - + // Log.debug(" display " + this.coord.size() + " elements" ); - this.GLprogram.use(); + this.oGLprogram.use(); // set Matrix: translation/positionMatrix final Matrix4f projMatrix = OpenGL.getMatrix(); final Matrix4f camMatrix = OpenGL.getCameraMatrix(); - final Matrix4f tmpMatrix = projMatrix.multiplyNew(camMatrix); - this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix); + final Matrix4f tmpMatrix = projMatrix.multiply(camMatrix); + this.oGLprogram.uniformMatrix(this.oGLMatrix, tmpMatrix); // position : - this.GLprogram.sendAttribute(this.GLPosition, 3/* x,y,z,unused */, - ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3); + this.oGLprogram.sendAttribute(this.oGLPosition, 3/* x,y,z,unused */, ResourceProgram.storeDataInFloatBufferVector3f(vertices), 3); // color : - this.GLprogram.uniformColor(this.GLColor, _color); + this.oGLprogram.uniformColor(this.oGLColor, color); // Request the draw od the elements: - OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, _vertices.size()); - this.GLprogram.unUse(); + OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, vertices.size()); + this.oGLprogram.unUse(); // Request the draw od the elements: - // glDrawArrays(GL_LINES, 0, vertices.size()); + // glDrawArrays(GLLINES, 0, vertices.size()); // this.GLprogram.UnUse(); - if (true == _depthtest) { - if (false == _updateDepthBuffer) { + if (depthtest) { + if (!updateDepthBuffer) { OpenGL.setDeathMask(true); - ; + } 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) { + draw(vertices, color, transformationMatrix, true, true); } - - public void draw(final List _vertices, final Color _color, final Matrix4f _transformationMatrix, - final boolean _updateDepthBuffer, final boolean _depthtest) { - if (_vertices.size() <= 0) { + + public void draw(final List vertices, final Color color, final Matrix4f transformationMatrix, final boolean updateDepthBuffer, final boolean depthTest) { + if (vertices.size() <= 0) { return; } - if (this.GLprogram == null) { + if (this.oGLprogram == null) { Log.error("No shader ..."); return; } - if (true == _depthtest) { + if (depthTest) { OpenGL.enable(OpenGL.Flag.flag_depthTest); - if (false == _updateDepthBuffer) { + if (!updateDepthBuffer) { OpenGL.setDeathMask(false); } } // Log.debug(" display " + this.coord.size() + " elements" ); - this.GLprogram.use(); + this.oGLprogram.use(); // set Matrix: translation/positionMatrix final Matrix4f projMatrix = OpenGL.getMatrix(); final Matrix4f camMatrix = OpenGL.getCameraMatrix(); - final Matrix4f tmpMatrix = projMatrix.multiplyNew(camMatrix).multiply(_transformationMatrix); - this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix); + final Matrix4f tmpMatrix = projMatrix.multiply(camMatrix).multiply(transformationMatrix); + this.oGLprogram.uniformMatrix(this.oGLMatrix, tmpMatrix); // position : - this.GLprogram.sendAttribute(this.GLPosition, 3/* x,y,z */, - ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3); // TODO : check 4->3 + this.oGLprogram.sendAttribute(this.oGLPosition, 3/* x,y,z */, ResourceProgram.storeDataInFloatBufferVector3f(vertices), 3); // TODO : check 4->3 // color : - this.GLprogram.uniformColor(this.GLColor, _color); + this.oGLprogram.uniformColor(this.oGLColor, color); // Request the draw od the elements: - OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, _vertices.size()); - this.GLprogram.unUse(); - if (true == _depthtest) { - if (false == _updateDepthBuffer) { + OpenGL.drawArrays(OpenGL.RenderMode.triangle, 0, vertices.size()); + this.oGLprogram.unUse(); + if (depthTest) { + if (!updateDepthBuffer) { OpenGL.setDeathMask(true); } 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; - + 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 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; + + 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 + offset); @@ -166,56 +159,56 @@ public class RefactorColored3DObject extends Resource { tmpVertices.add(v1); tmpVertices.add(v2); tmpVertices.add(v3); - + tmpVertices.add(v1); tmpVertices.add(v3); tmpVertices.add(v4); } } // 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); + 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); + + 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); } - // center to border (BUTTOM) - offset = -_size * 0.5f; - for (int iii = 0; iii <= _lats / 2; ++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; + // center to border (BOTTOM) + offset = -size * 0.5f; + for (int iii = 0; iii <= lats / 2; ++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; + + 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 + offset); @@ -223,263 +216,252 @@ public class RefactorColored3DObject extends Resource { tmpVertices.add(v1); tmpVertices.add(v2); tmpVertices.add(v3); - + tmpVertices.add(v1); tmpVertices.add(v3); tmpVertices.add(v4); } } - draw(tmpVertices, _tmpColor, _transformationMatrix); + 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); - final Vector3f v3 = new Vector3f(x, y, _size / 2); + 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); + final Vector3f v3 = new Vector3f(x, y, size / 2); tmpVertices.add(v1); tmpVertices.add(v3); tmpVertices.add(v2); } - // 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); - final Vector3f v3 = new Vector3f(x, y, _size / 2); + // center to border (BOTTOM) + 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); + final Vector3f v3 = new Vector3f(x, y, size / 2); tmpVertices.add(v1); tmpVertices.add(v2); tmpVertices.add(v3); } - draw(tmpVertices, _tmpColor, _transformationMatrix); + draw(tmpVertices, tmpColor, 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) { + 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())); - - drawLine(vertices, _color, _transformationMatrix, _updateDepthBuffer, _depthtest); + 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; + 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); + + 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); + + 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); tmpVertices.add(v1); tmpVertices.add(v3); tmpVertices.add(v2); } // 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); + 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); + + 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); } - // 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; + // center to border (BOTTOM) + 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); + + 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); + + 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); tmpVertices.add(v1); tmpVertices.add(v2); tmpVertices.add(v3); } - draw(tmpVertices, _tmpColor, _transformationMatrix); + 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) { + drawLine(vertices, color, transformationMatrix, true, true); } - - public void drawLine(final List _vertices, final Color _color, final Matrix4f _transformationMatrix, - final boolean _updateDepthBuffer, final boolean _depthtest) { - if (_vertices.size() <= 0) { + + public void drawLine(final List vertices, final Color color, final Matrix4f transformationMatrix, final boolean updateDepthBuffer, final boolean depthTest) { + if (vertices.size() <= 0) { return; } - if (this.GLprogram == null) { + if (this.oGLprogram == null) { Log.error("No shader ..."); return; } - if (true == _depthtest) { + if (depthTest) { OpenGL.enable(OpenGL.Flag.flag_depthTest); - if (false == _updateDepthBuffer) { + if (!updateDepthBuffer) { OpenGL.setDeathMask(false); } } // Log.debug(" display " + this.coord.size() + " elements" ); - this.GLprogram.use(); + this.oGLprogram.use(); // set Matrix: translation/positionMatrix final Matrix4f projMatrix = OpenGL.getMatrix(); final Matrix4f camMatrix = OpenGL.getCameraMatrix(); - final Matrix4f tmpMatrix = projMatrix.multiplyNew(camMatrix).multiply(_transformationMatrix); - this.GLprogram.uniformMatrix(this.GLMatrix, tmpMatrix); + final Matrix4f tmpMatrix = projMatrix.multiply(camMatrix).multiply(transformationMatrix); + this.oGLprogram.uniformMatrix(this.oGLMatrix, tmpMatrix); // position : - this.GLprogram.sendAttribute(this.GLPosition, 3/* x,y,z */, - ResourceProgram.storeDataInFloatBufferVector3f(_vertices), 3);// TODO : check 4->3 + this.oGLprogram.sendAttribute(this.oGLPosition, 3/* x,y,z */, ResourceProgram.storeDataInFloatBufferVector3f(vertices), 3);// TODO check 4->3 // color : - this.GLprogram.uniformColor(this.GLColor, _color); + this.oGLprogram.uniformColor(this.oGLColor, color); // Request the draw od the elements: - OpenGL.drawArrays(OpenGL.RenderMode.line, 0, _vertices.size()); - this.GLprogram.unUse(); - if (true == _depthtest) { - if (false == _updateDepthBuffer) { + OpenGL.drawArrays(OpenGL.RenderMode.line, 0, vertices.size()); + this.oGLprogram.unUse(); + if (depthTest) { + if (!updateDepthBuffer) { OpenGL.setDeathMask(true); } 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; + 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; + + 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); } } - draw(tmpVertices, _tmpColor, _transformationMatrix); + draw(tmpVertices, tmpColor, transformationMatrix); } - - public void drawSquare(final Vector3f _size, final Matrix4f _transformationMatrix, final Color _tmpColor) { + + 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()) }; - tmpVertices.clear(); + 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()) }; for (int iii = 0; iii < 36; iii += 3) { // normal calculation : // btVector3 normal = @@ -489,28 +471,26 @@ public class RefactorColored3DObject extends Resource { tmpVertices.add(vertices[indices[iii + 1]]); tmpVertices.add(vertices[indices[iii + 2]]); } - draw(tmpVertices, _tmpColor, _transformationMatrix); + draw(tmpVertices, tmpColor, transformationMatrix); } - - 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) { + 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)).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]]); + for (int iii = 0; iii < indice.size() / 3; ++iii) { + tmpVertices.add(vertex.get(indice.get(iii * 3)).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()); - draw(tmpVertices, _tmpColor, _transformationMatrix); + // 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 000c56c..526eff7 100644 --- a/src/org/atriasoft/ewol/resource/ResourceColorFile.java +++ b/src/org/atriasoft/ewol/resource/ResourceColorFile.java @@ -18,15 +18,14 @@ import org.atriasoft.ewol.internal.Log; import org.atriasoft.gale.resource.Resource; class ListElement { - public String name; public Color color; - + public String name; + public ListElement(final String name, final Color color) { - super(); this.name = name; this.color = color; } - + } /** @@ -34,37 +33,54 @@ class ListElement { * example black, or white or orange ...) */ public class ResourceColorFile extends Resource { - private final List list = new ArrayList<>(); // !< List of all color in the file + public static ResourceColorFile create(final Uri uri) { + Log.verbose("KEEP: ColorFile: " + uri); + ResourceColorFile object = null; + final Resource object2 = Resource.getManager().localKeep(uri); + if (object2 != null) { + if (object2 instanceof ResourceColorFile) { + return (ResourceColorFile) object2; + } + Log.critical("Request resource file : '" + uri + "' With the wrong type (dynamic cast error)"); + return null; + } + Log.debug("CREATE: FontFreeType: " + uri); + // need to crate a new one ... + return new ResourceColorFile(uri); + } + private Color errorColor = Color.ORANGE; - + + private final List list = new ArrayList<>(); // !< List of all color in the file + /** * Constructor of the color property file - * @param _uri Name of the file needed + * @param uri Name of the file needed */ - public ResourceColorFile(final Uri _uri) { - super(_uri.get()); - Log.debug("CF : load \"" + _uri + "\""); + public ResourceColorFile(final Uri uri) { + super(uri.get()); + Log.debug("CF : load \"" + uri + "\""); reload(); // Log.debug("List of all color : " + this.list.keySet()); } - + @Override public void cleanUp() { - + } - + /** * Get the associated color of the ID. - * @param _Id Id of the color. + * @param id Id of the color. * @return The requested color. */ - Color get(final int _id) { - if (_id < 0) { + public Color get(final int id) { + if (id < 0) { return this.errorColor; } - return this.list.get(_id).color; + return this.list.get(id).color; } - + /** * Get All color name * @return list of all color existing @@ -75,8 +91,8 @@ public class ResourceColorFile extends Resource { out.add(this.list.get(iii).name); } 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); @@ -87,7 +103,7 @@ public class ResourceColorFile extends Resource { } this.list.add(new ListElement(name, color)); } - + @Override public synchronized void reload() { // remove all previous set of value : @@ -97,8 +113,8 @@ public class ResourceColorFile extends Resource { Log.todo("Mut be implemented ..."); // open and read all json elements: try { - final JsonObject out = Ejson.parse(new Uri(this.name)).toJsonObject(); - + final JsonObject out = Ejson.parse(Uri.valueOf(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); @@ -123,11 +139,10 @@ public class ResourceColorFile extends Resource { } if (color.length() == 0) { put(name, this.errorColor); - } else { } put(name, Color.valueOf(color)); } - if (findError == true) { + if (findError) { Log.error("pb in parsing file:" + this.name); Ejson.display(out); } @@ -136,29 +151,29 @@ public class ResourceColorFile extends Resource { e.printStackTrace(); } } - + /** * Request the presence of a specific color. - * @param _paramName Name of the color. + * @param paramName Name of the color. * @return A unique ID of the color (or -1 if an error occured). */ - public synchronized int request(final String _paramName) { + public synchronized int request(final String paramName) { for (int iii = 0; iii < this.list.size(); iii++) { final ListElement elem = this.list.get(iii); - if (elem.name.contentEquals(_paramName)) { + if (elem.name.contentEquals(paramName)) { return iii; } } - this.list.add(new ListElement(_paramName, this.errorColor)); + this.list.add(new ListElement(paramName, this.errorColor)); return this.list.size() - 1; } - + /** * Set the error color. - * @param _errorColor Color that might be set when not finding a color + * @param errorColor Color that might be set when not finding a color */ - public void setErrorColor(final Color _errorColor) { - this.errorColor = _errorColor; + public void setErrorColor(final Color errorColor) { + this.errorColor = errorColor; } - -}; + +} diff --git a/src/org/atriasoft/ewol/resource/ResourceConfigFile.java b/src/org/atriasoft/ewol/resource/ResourceConfigFile.java index 2ac3262..281969e 100644 --- a/src/org/atriasoft/ewol/resource/ResourceConfigFile.java +++ b/src/org/atriasoft/ewol/resource/ResourceConfigFile.java @@ -1,4 +1,4 @@ -/** @file +/* @file * @author Edouard DUPIN * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) @@ -15,17 +15,27 @@ import org.atriasoft.etk.Uri; import org.atriasoft.ewol.internal.Log; import org.atriasoft.gale.resource.Resource; +class ListElementConfig { + public final String name; + public JsonNode node; + + public ListElementConfig(final String name, final JsonNode node) { + this.name = name; + this.node = node; + } +} + public class ResourceConfigFile extends Resource { /** * keep the resource pointer. * @note Never free this pointer by your own... - * @param _filename Name of the configuration file. - * @return pointer on the resource or null if an error occured. + * @param name Name of the configuration file. + * @return pointer on the resource or null if an error occurred. */ public static ResourceConfigFile keep(final String name) { Resource resource2 = null; - if (name.isEmpty() == false && name != "---") { - resource2 = getManager().localKeep(name); + if (!name.isEmpty() && !name.contentEquals("---")) { + resource2 = Resource.getManager().localKeep(name); } if (resource2 != null) { if (resource2 instanceof ResourceConfigFile) { @@ -35,8 +45,8 @@ public class ResourceConfigFile extends Resource { Log.critical("Request resource file : '" + name + "' With the wrong type (dynamic cast error)"); return null; } - final ResourceConfigFile resource = new ResourceConfigFile(new Uri(name)); - getManager().localAdd(resource); + final ResourceConfigFile resource = new ResourceConfigFile(Uri.valueOf(name)); + Resource.getManager().localAdd(resource); return resource; } @@ -44,9 +54,9 @@ public class ResourceConfigFile extends Resource { // List of all color in the file private final List list = new ArrayList<>(); - protected ResourceConfigFile(final Uri _uri) { - super(_uri.get()); - Log.debug("SFP : load '" + _uri + "'"); + protected ResourceConfigFile(final Uri uri) { + super(uri.get()); + Log.debug("SFP : load '" + uri + "'"); reload(); } @@ -57,30 +67,29 @@ public class ResourceConfigFile extends Resource { } - boolean getBoolean(final int _id) { - if (_id < 0 || this.list.get(_id).node == null || this.list.get(_id).node.isJsonBoolean() == false) { + boolean getBoolean(final int id) { + if (id < 0 || this.list.get(id).node == null || !this.list.get(id).node.isJsonBoolean()) { return false; } - return this.list.get(_id).node.toJsonBoolean().getValue(); + return this.list.get(id).node.toJsonBoolean().getValue(); } - public synchronized double getNumber(final int _id) { - if (_id < 0 || this.list.get(_id).node == null || this.list.get(_id).node.isJsonNumber() == false) { + public synchronized double getNumber(final int id) { + if (id < 0 || this.list.get(id).node == null || !this.list.get(id).node.isJsonNumber()) { return 0.0; } - return this.list.get(_id).node.toJsonNumber().getValue(); + return this.list.get(id).node.toJsonNumber().getValue(); } - String getString(final int _id) { - if (_id < 0 || this.list.get(_id).node == null || this.list.get(_id).node.isJsonString() == false) { + String getString(final int id) { + if (id < 0 || this.list.get(id).node == null || !this.list.get(id).node.isJsonString()) { return ""; } - return this.list.get(_id).node.toJsonString().getValue(); + return this.list.get(id).node.toJsonString().getValue(); } public synchronized void put(final String name, final JsonNode node) { - for (int iii = 0; iii < this.list.size(); iii++) { - final ListElementConfig elem = this.list.get(iii); + for (final ListElementConfig elem : this.list) { if (elem.name.contentEquals(name)) { elem.node = node; return; @@ -92,41 +101,28 @@ public class ResourceConfigFile extends Resource { @Override public synchronized void reload() { // reset all parameters - for (int iii = 0; iii < this.list.size(); ++iii) { - this.list.get(iii).node = null; + for (ListElementConfig listElementConfig : this.list) { + listElementConfig.node = null; } JsonObject out; try { - out = Ejson.parse(new Uri(this.name)).toJsonObject(); + out = Ejson.parse(Uri.valueOf(this.name)).toJsonObject(); } catch (final Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return; } - out.getNodes().forEach((key, value) -> { - put(key, value); - }); + out.getNodes().forEach(this::put); } - public synchronized int request(final String _paramName) { + public synchronized int request(final String paramName) { for (int iii = 0; iii < this.list.size(); iii++) { final ListElementConfig elem = this.list.get(iii); - if (elem.name.contentEquals(_paramName)) { + if (elem.name.contentEquals(paramName)) { return iii; } } - this.list.add(new ListElementConfig(_paramName, null)); + this.list.add(new ListElementConfig(paramName, null)); return this.list.size() - 1; } -} - -class ListElementConfig { - public final String name; - public JsonNode node; - - public ListElementConfig(final String name, final JsonNode node) { - super(); - this.name = name; - this.node = node; - } } \ No newline at end of file diff --git a/src/org/atriasoft/ewol/resource/ResourceFontFreeType.java b/src/org/atriasoft/ewol/resource/ResourceFontFreeType.java index 0941b17..922f6e4 100644 --- a/src/org/atriasoft/ewol/resource/ResourceFontFreeType.java +++ b/src/org/atriasoft/ewol/resource/ResourceFontFreeType.java @@ -30,21 +30,21 @@ import com.mlomb.freetypejni.Library; // show : http://www.freetype.org/freetype2/docs/tutorial/step2.html public class ResourceFontFreeType extends FontBase { - private static final Library library; + private static final Library LIBRARY; static { - library = FreeType.newLibrary(); + LIBRARY = FreeType.newLibrary(); } - + public static ResourceFontFreeType create(final Uri uri) { Log.verbose("KEEP: FontFreeType: " + uri); ResourceFontFreeType object = null; - final Resource object2 = getManager().localKeep(uri); + final Resource object2 = Resource.getManager().localKeep(uri); if (object2 != null) { - object = (ResourceFontFreeType) object2; - if (object == null) { + if (!(object2 instanceof ResourceFontFreeType)) { Log.critical("Request resource file : '" + uri + "' With the wrong type (dynamic cast error)"); return null; } + object = (ResourceFontFreeType) object2; } if (object != null) { return object; @@ -53,40 +53,38 @@ public class ResourceFontFreeType extends FontBase { // need to crate a new one ... return new ResourceFontFreeType(uri); } - - private final byte[] FileBuffer; + private final Face fftFace; - + private final byte[] fileBuffer; + private boolean init; - - private ResourceFontFreeType(final Uri _uri) { - super(_uri); - this.FileBuffer = LoadPackageStream.getAllData(_uri.getPath()); + + private ResourceFontFreeType(final Uri uri) { + super(uri); + this.fileBuffer = LoadPackageStream.getAllData(uri.getPath()); // load Face ... - this.fftFace = library.newFace(this.FileBuffer, 0); + this.fftFace = ResourceFontFreeType.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()); + Log.debug("load font : \"" + uri + "\" glyph count = " + this.fftFace.getNumGlyphs()); this.init = true; // display(); } } - + @Override public synchronized void display() { - if (this.init == false) { + if (!this.init) { return; } 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) { - if (this.init == false) { + public synchronized boolean drawGlyph(final Image imageOut, final int fontSize, final Vector2i glyphPosition, final GlyphProperty property, final int posInImage) { + if (!this.init) { return false; } // 300dpi (hight quality) 96 dpi (normal quality) @@ -94,23 +92,23 @@ public class ResourceFontFreeType extends FontBase { // Select size ... // 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 ..."); + boolean error = this.fftFace.setCharSize(fontSize + 6, fontSize + 6, fontQuality, fontQuality); + if (!error) { + Log.error("FTSetCharSize == > error in settings ..."); return false; } // a small shortcut final GlyphSlot slot = this.fftFace.getGlyphSlot(); // load glyph image into the slot (erase previous one) - error = this.fftFace.loadGlyph(_property.glyphIndex, FreeTypeConstants.FT_LOAD_DEFAULT); - if (error == false) { - Log.error("FT_Load_Glyph specify Glyph"); + error = this.fftFace.loadGlyph(property.glyphIndex, FreeTypeConstants.FT_LOAD_DEFAULT); + if (!error) { + Log.error("FTLoadGlyph specify Glyph"); return false; } // convert to an anti-aliased bitmap error = slot.renderGlyph(FT_Render_Mode.FT_RENDER_MODE_NORMAL); - if (error == false) { - Log.error("FT_Render_Glyph"); + if (!error) { + Log.error("FTRenderGlyph"); return false; } // draw it on the output Image : @@ -119,32 +117,31 @@ public class ResourceFontFreeType extends FontBase { for (int iii = 0; iii < bitmap.getWidth(); iii++) { 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; + 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; } // real set of color - + } } return true; } - + @Override - public synchronized boolean drawGlyph(final ImageMono _imageOut, final int _fontSize, final GlyphProperty _property, - final int _borderSize) { - if (false == this.init) { + public synchronized boolean drawGlyph(final ImageMono imageOut, final int fontSize, final GlyphProperty property, final int borderSize) { + if (!this.init) { return false; } // 300dpi (hight quality) 96 dpi (normal quality) @@ -152,47 +149,47 @@ public class ResourceFontFreeType extends FontBase { // Select size ... // 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 ..."); + boolean error = this.fftFace.setCharSize(fontSize + 6, fontSize + 6, fontQuality, fontQuality); + if (!error) { + Log.error("FTSetCharSize == > error in settings ..."); return false; } // a small shortcut final GlyphSlot slot = this.fftFace.getGlyphSlot(); // load glyph image into the slot (erase previous one) - error = this.fftFace.loadGlyph(_property.glyphIndex, // glyph index + error = this.fftFace.loadGlyph(property.glyphIndex, // glyph index FreeTypeConstants.FT_LOAD_DEFAULT); - if (error == false) { - Log.error("FT_Load_Glyph specify Glyph"); + if (!error) { + Log.error("FTLoadGlyph specify Glyph"); 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 ... - if (error == false) { - Log.error("FT_Render_Glyph"); + error = slot.renderGlyph(FT_Render_Mode.FT_RENDER_MODE_NORMAL); // TODO set FT_RENDER_MODE_MONO ==> 1 bit + // value ==> faster generation ... + if (!error) { + Log.error("FTRenderGlyph"); return false; } // resize output image : final Bitmap bitmap = slot.getBitmap(); - _imageOut.resize(bitmap.getWidth() + 2 * _borderSize, bitmap.getRows() + 2 * _borderSize); - + 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); // real set of color - _imageOut.set(_borderSize + iii, _borderSize + jjj, valueColor); + imageOut.set(borderSize + iii, borderSize + jjj, valueColor); } } return true; } - + @Override public synchronized void generateKerning(final int fontSize, final List listGlyph) { - if (this.init == false) { + if (!this.init) { return; } - if (this.fftFace.hasKerning() == false) { + if (!this.fftFace.hasKerning()) { Log.info("No kerning generation (disable) in the font"); } // 300dpi (hight quality) 96 dpi (normal quality) @@ -201,19 +198,18 @@ public class ResourceFontFreeType extends FontBase { // 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 ..."); + if (!error) { + Log.error("FTSetCharSize == > error in settings ..."); return; } // For all the kerning element we get the kerning value : 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); + 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); + 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)); @@ -221,10 +217,10 @@ public class ResourceFontFreeType extends FontBase { } } } - + @Override - public synchronized boolean getGlyphProperty(final int _fontSize, final GlyphProperty _property) { - if (false == this.init) { + public synchronized boolean getGlyphProperty(final int fontSize, final GlyphProperty property) { + if (!this.init) { return false; } // 300dpi (hight quality) 96 dpi (normal quality) @@ -232,56 +228,54 @@ public class ResourceFontFreeType extends FontBase { // Select size ... // 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 ..."); + boolean error = this.fftFace.setCharSize(fontSize + 6, fontSize + 6, fontQuality, fontQuality); + if (!error) { + Log.error("FTSetCharSize == > error in settings ..."); return false; } // a small shortcut final GlyphSlot slot = this.fftFace.getGlyphSlot(); // retrieve glyph index from character code - final int glyph_index = this.fftFace.getCharIndex(_property.UVal); + final int glyphindex = this.fftFace.getCharIndex(property.uVal); // load glyph image into the slot (erase previous one) - error = this.fftFace.loadGlyph(glyph_index, // glyph index + error = this.fftFace.loadGlyph(glyphindex, // glyph index FreeTypeConstants.FT_LOAD_DEFAULT); - if (error == false) { - Log.error("FT_Load_Glyph specify Glyph"); + if (!error) { + Log.error("FTLoadGlyph specify Glyph"); return false; } // convert to an anti-aliased bitmap error = slot.renderGlyph(FT_Render_Mode.FT_RENDER_MODE_NORMAL); - if (error == false) { - Log.error("FT_Render_Glyph"); + if (!error) { + Log.error("FTRenderGlyph"); return false; } // set properties : - _property.glyphIndex = glyph_index; + property.glyphIndex = glyphindex; final Bitmap bitmap = slot.getBitmap(); - _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); + 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 ... + 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) { + public synchronized Vector2f getSize(final int fontSize, final String unicodeString) { + if (!this.init) { return new Vector2f(0, 0); } // TODO ... return new Vector2f(0, 0); } - + @Override - public synchronized float getSizeWithHeight(final float _fontHeight) { - return _fontHeight * 0.6993f; // this is a really "magic" number ... + 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 ece05be..3ded17a 100644 --- a/src/org/atriasoft/ewol/resource/ResourceTexture2.java +++ b/src/org/atriasoft/ewol/resource/ResourceTexture2.java @@ -13,23 +13,13 @@ import org.atriasoft.ewol.internal.Log; import org.atriasoft.ewol.internal.Tools; import org.atriasoft.gale.backend3d.OpenGL; import org.atriasoft.gale.resource.Resource; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL13; public class ResourceTexture2 extends Resource { public enum TextureColorMode { 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 };; - + /* * public static ResourceTexture2 createFromPng(final Uri uriTexture) { return * createFromPng(uriTexture, 1); } @@ -50,7 +40,7 @@ public class ResourceTexture2 extends Resource { * (decodedData.isHasAlpha() == true ? TextureColorMode.rgba : * TextureColorMode.rgb), textureUnit); resource.flush(); return resource; } */ - + /** * get the next power 2 if the input * @param value Value that we want the next power of 2 @@ -67,92 +57,90 @@ public class ResourceTexture2 extends Resource { Log.critical("impossible CASE...."); return val; } - - protected int texId = -1; // !< openGl textureID. + // openGl Context properties : protected Image data = new Image(32, 32); + // !< Color space of the image. + private final TextureColorMode dataColorSpace = TextureColorMode.rgba; + // Filter apply at the image when rendering it + protected TextureFilter filter = TextureFilter.linear; // ! Last loaded size in the system openGL protected Vector2i lastSize = new Vector2i(1, 1); + protected int lastSizeObject = 0; + protected int lastTypeObject = 0; + // internal state of the openGl system. + protected boolean loaded = false; // ! 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; - protected int lastTypeObject = 0; - 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. - private final TextureColorMode dataColorSpace = TextureColorMode.rgba; - - public ResourceTexture2() { - super(); - } - + + protected int texId = -1; // !< openGl textureID. + + public ResourceTexture2() {} + 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); } } + * GL11.glBindTexture(GL11.GLTEXTURE2D, this.texId); if (this.dataColorSpace + * == TextureColorMode.rgb) { OpenGL.enable(OpenGL.Flag.flagcullFace); + * OpenGL.enable(OpenGL.Flag.flagback); } } */ - + public ResourceTexture2(final Uri filename) { super(filename); } - + public void bindForRendering(final int idTexture) { - if (this.loaded == false) { + if (!this.loaded) { return; } - GL13.glActiveTexture(textureIdBinding[idTexture]); - GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.texId); + OpenGL.activeTexture(idTexture); + OpenGL.bindTexture2D(this.texId); if (this.dataColorSpace == TextureColorMode.rgb) { OpenGL.enable(OpenGL.Flag.flag_cullFace); 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); - }; - + Resource.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) { + if (this.loaded) { // Request remove texture ... Log.info("TEXTURE: Rm [" + getId() + "] texId=" + this.texId); // TODO Check if we are in the correct thread @@ -160,57 +148,56 @@ public class ResourceTexture2 extends Resource { this.loaded = false; } } - + @Override public synchronized void removeContextToLate() { this.loaded = false; this.texId = -1; - }; - + } + /** * Set the image in the texture system * @note It will resize in square2 if needed by the system. - * @param _image Image to set. + * @param image Image to set. */ - public synchronized void set(final Image _image) { + public synchronized void set(final Image image) { Log.debug("Set a new image in a texture:"); - Log.debug(" size=" + _image.getSize()); - this.data = _image; + Log.debug(" size=" + image.getSize()); + this.data = image; this.realImageSize = this.data.getSize(); - final Vector2i compatibilityHWSize = new Vector2i(Tools.nextP2(this.realImageSize.x()), - Tools.nextP2(this.realImageSize.y())); - if (this.realImageSize != compatibilityHWSize) { + final Vector2i compatibilityHWSize = new Vector2i(Tools.nextP2(this.realImageSize.x()), Tools.nextP2(this.realImageSize.y())); + if (!this.realImageSize.equals(compatibilityHWSize)) { Log.verbose("RESIZE Image for HArwareCompatibility:" + this.realImageSize + " => " + compatibilityHWSize); this.data.resize(compatibilityHWSize.x(), compatibilityHWSize.y()); } flush(); - }; - + } + /** * Set the Filter mode to apply at the image when display with a scale * (not 1:1 ratio) - * @param _value Value of the new filter mode + * @param filter Value of the new filter mode */ - public void setFilterMode(final TextureFilter _filter) { - this.filter = _filter; + 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(Vector2i _newSize) { - _newSize = new Vector2i(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()); + } + /** * Set the repeate mode of the images if UV range is out of [0..1] - * @param _value Value of the new repeate mode + * @param value Value of the new repeate mode */ - public void setRepeat(final boolean _value) { - this.repeat = _value; + public void setRepeat(final boolean value) { + this.repeat = value; } - + public void unBindForRendering() { - if (this.loaded == false) { + if (!this.loaded) { return; } if (this.dataColorSpace == TextureColorMode.rgb) { @@ -218,7 +205,7 @@ public class ResourceTexture2 extends Resource { OpenGL.disable(OpenGL.Flag.flag_back); } } - + @Override public synchronized boolean updateContext() { Log.verbose("updateContext [START]"); @@ -229,32 +216,29 @@ public class ResourceTexture2 extends Resource { */ 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.loaded) { + if (this.lastTypeObject != typeObject || this.lastSizeObject != sizeObject || !this.lastSize.equals(this.data.getSize())) { Log.warning("TEXTURE: Rm [" + getId() + "] texId=" + this.texId); OpenGL.glDeleteTextures(this.texId); this.loaded = false; } } - if (this.loaded == false) { + if (!this.loaded) { // Request a new texture at openGl : this.texId = OpenGL.glGenTextures(); 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() + " OGlId=" + 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() + " OGlId=" + 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) { + + if (!this.loaded) { + if (!this.repeat) { OpenGL.setTexture2DWrapClampToEdge(); } else { OpenGL.setTexture2DWrapRepeat(); @@ -265,10 +249,10 @@ public class ResourceTexture2 extends Resource { OpenGL.setTexture2DFilterNearest(); } } - // glPixelStorei(GL_UNPACK_ALIGNMENT,1); + // glPixelStorei(GLUNPACKALIGNMENT,1); final Steady toc1 = Steady.now(); Log.verbose(" BIND ==> " + toc1.less(tic)); - // egami::store(this.data, String("~/texture_") + etk::toString(getId()) + + // egami::store(this.data, String("~/texture") + etk::toString(getId()) + // ".bmp"); /* * if (false) { // On some embended target, the texture size must be square of @@ -277,31 +261,32 @@ public class ResourceTexture2 extends Resource { * 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, // + * OpenGL.glTexImage2D(GLTEXTURE2D, // 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 + * glTexSubImage2D(GLTEXTURE2D, // 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) { + */ + if (!this.loaded) { OpenGL.glTexImage2D(0, // Level typeObject, // Format internal this.data.getWidth(), this.data.getHeight(), 0, // Border typeObject, // format sizeObject, // type - this.data.GetRaw()); - + this.data.getRaw()); + } else { OpenGL.glTexSubImage2D(0, // Level 0, // x offset 0, // y offset this.data.getWidth(), this.data.getHeight(), typeObject, // format sizeObject, // type - this.data.GetRaw()); + this.data.getRaw()); } // now the data is loaded this.loaded = true; @@ -309,8 +294,8 @@ public class ResourceTexture2 extends Resource { // Log.error(" updateContext [STOP] ==> " + (toc - toc1)); return true; } -}; +} enum TextureFilter { - nearest, linear + linear, nearest } diff --git a/src/org/atriasoft/ewol/resource/ResourceTextureFile.java b/src/org/atriasoft/ewol/resource/ResourceTextureFile.java index d1d0189..56165ca 100644 --- a/src/org/atriasoft/ewol/resource/ResourceTextureFile.java +++ b/src/org/atriasoft/ewol/resource/ResourceTextureFile.java @@ -5,6 +5,7 @@ */ package org.atriasoft.ewol.resource; +import org.atriasoft.egami.Egami; import org.atriasoft.egami.Image; import org.atriasoft.etk.Uri; import org.atriasoft.etk.math.Vector2i; @@ -17,31 +18,30 @@ 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); - + + public static ResourceTextureFile create(final Uri filename) { + return ResourceTextureFile.create(filename, ResourceTextureFile.sizeAuto); + } + + public static ResourceTextureFile create(final Uri filename, final Vector2i size) { + return ResourceTextureFile.create(filename, size, ResourceTextureFile.sizeAuto); + } + /** * keep the resource pointer. * @note Never free this pointer by your own... - * @param _filename Name of the image file. - * @param _requested size of the image (usefull when loading .svg to + * @param uri Name of the image file. + * @param size size of the image (usefull when loading .svg to * automatic rescale) - * @param _sizeRegister size register in named (When you preaload the images + * @param 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; - if (_uri == null) { - final ResourceTextureFile object = new ResourceTextureFile(); - return object; + public static ResourceTextureFile create(final Uri uri, final Vector2i inSize, final Vector2i sizeRegister) { + Log.verbose("KEEP: TextureFile: '" + uri + "' size=" + inSize + " sizeRegister=" + sizeRegister); + Vector2i size = inSize; + if (uri == null) { + return new ResourceTextureFile(); } if (size.x() == 0) { size = size.withX(-1); @@ -51,54 +51,49 @@ public class ResourceTextureFile extends ResourceTexture2 { 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 (!uri.getExtention().toLowerCase().contentEquals("svg")) { + size = ResourceTextureFile.sizeAuto; } if (size.x() > 0 && size.y() > 0) { Log.verbose(" == > specific size : " + size); size = new Vector2i(Tools.nextP2(size.x()), Tools.nextP2(size.y())); - if (_sizeRegister.equals(sizeAuto) == false) { - if (_sizeRegister.equals(sizeDefault) == false) { + if (!sizeRegister.equals(ResourceTextureFile.sizeAuto)) { + if (!sizeRegister.equals(ResourceTextureFile.sizeDefault)) { // 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()); + + Log.verbose("KEEP: TextureFile: '" + uri + "' new size=" + size); + final Resource object2 = Resource.getManager().localKeep(uri.toString()); if (object2 != null) { - object = (ResourceTextureFile) object2; - if (object == null) { - Log.critical("Request resource file : '" + tmpFilename + "' With the wrong type (dynamic cast error)"); - return null; + if (object2 instanceof ResourceTextureFile out) { + object2.keep(); + return out; } + Log.critical("Request resource file : '" + uri + "' With the wrong type (dynamic cast error)"); + return null; } - if (object != null) { - return object; - } - Log.debug("CREATE: TextureFile: '" + tmpFilename + "' size=" + size); + Log.debug("CREATE: TextureFile: '" + uri + "' size=" + size); // need to crate a new one ... - object = new ResourceTextureFile(tmpFilename.toString(), _uri, size); - getManager().localAdd(object); + ResourceTextureFile object = new ResourceTextureFile(uri.toString(), uri, size); + Resource.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); + + 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/resource/ResourceTexturedFont.java b/src/org/atriasoft/ewol/resource/ResourceTexturedFont.java index 69553bd..b9d9b18 100644 --- a/src/org/atriasoft/ewol/resource/ResourceTexturedFont.java +++ b/src/org/atriasoft/ewol/resource/ResourceTexturedFont.java @@ -6,6 +6,7 @@ package org.atriasoft.ewol.resource; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.atriasoft.etk.Uri; @@ -22,12 +23,11 @@ public class ResourceTexturedFont extends ResourceTexture2 { public static ResourceTexturedFont create(final String fontName) { ResourceTexturedFont resource; Resource resource2; - if (fontName.isEmpty() == false && fontName.contentEquals("---")) { - resource2 = getManager().localKeep(fontName); - } else { + if (fontName.isEmpty() || !fontName.contentEquals("---")) { Log.error("Can not create a shader without a filaname"); return null; } + resource2 = Resource.getManager().localKeep(fontName); if (resource2 != null) { if (resource2 instanceof ResourceTexturedFont) { resource2.keep(); @@ -37,101 +37,100 @@ public class ResourceTexturedFont extends ResourceTexture2 { return null; } resource = new ResourceTexturedFont(fontName); - getManager().localAdd(resource); + Resource.getManager().localAdd(resource); return resource; } - + /** * Get all the Path contain in the specidy path: - * @param _path Generic path to parse ... + * @param path Generic path to parse ... * @return The list of path found - * @example[start] auto out = explodeMultiplePath("DATA:///font?lib=ewol"); // + * example[start] auto out = explodeMultiplePath("DATA:///font?lib=ewol"); // * out contain: {"DATA:///font", * "DATA:///font?lib=ewol"} @example[stop] */ - private static List explodeMultiplePath(final Uri _uri) { + private static List explodeMultiplePath(final Uri uri) { final List out = new ArrayList<>(); - out.add(_uri); + out.add(uri); return out; } - + + // font is define for a specific mode + public GlyphProperty emptyGlyph; private final Uri[] fileName = new Uri[4]; - private int size = 10; - private final int[] height = new int[4]; // specific element to have the the know if the specify element is known... // == > otherwise I can just generate italic ... // == > Bold is a little more complicated (maybe with the bordersize) private final FontBase[] font = new FontBase[4]; - private final FontMode[] modeWraping = new FontMode[4]; // !< This is a wrapping mode to prevent the fact that no - // font is define for a specific mode - public GlyphProperty emptyGlyph; - public List[] listElement;// = new (List)[4]; - + private final int[] height = new int[4]; // for the texture generation : public Vector2i[] lastGlyphPos = new Vector2i[4]; public int[] lastRawHeigh = new int[4]; - - protected ResourceTexturedFont(final String _fontName) { - super(_fontName); - - Log.debug("Load font : '" + _fontName + "'"); - + public List[] listElement;// = new (List)[4]; + + private final FontMode[] modeWraping = new FontMode[4]; // !< This is a wrapping mode to prevent the fact that no + private int size = 10; + + protected ResourceTexturedFont(final String fontName) { + super(fontName); + + Log.debug("Load font : '" + fontName + "'"); + this.font[0] = null; this.font[1] = null; this.font[2] = null; this.font[3] = null; - + this.modeWraping[0] = FontMode.Regular; this.modeWraping[1] = FontMode.Regular; this.modeWraping[2] = FontMode.Regular; this.modeWraping[3] = FontMode.Regular; - + this.lastGlyphPos[0] = Vector2i.ONE; this.lastGlyphPos[1] = Vector2i.ONE; this.lastGlyphPos[2] = Vector2i.ONE; this.lastGlyphPos[3] = Vector2i.ONE; - + this.lastRawHeigh[0] = 0; this.lastRawHeigh[1] = 0; this.lastRawHeigh[2] = 0; this.lastRawHeigh[3] = 0; - + int tmpSize = 0; // extarct name and size : - final String[] tmpList = _fontName.split(":"); - + final String[] tmpList = fontName.split(":"); + if (tmpList.length == 1) { this.size = 1; - Log.critical("Can not parse the font name: '" + _fontName + "' ??? ':' "); + Log.critical("Can not parse the font name: '" + fontName + "' ??? ':' "); return; - } else { - // zsdefsdf - tmpSize = Integer.valueOf(tmpList[1]); } - + // zsdefsdf + tmpSize = Integer.parseInt(tmpList[1]); + final String localName = tmpList[0]; if (tmpSize > 400) { Log.error("Font size too big ==> limit at 400 when exceed ==> error: " + tmpSize + "==>30"); tmpSize = 30; } this.size = tmpSize; - + final List folderList = new ArrayList<>(); - if (Ewol.getContext().getFontDefault().getUseExternal() == true) { + if (Ewol.getContext().getFontDefault().getUseExternal()) { /* - * #if defined(__TARGET_OS__Android) + * #if defined(TARGETOSAndroid) * folderList.pushBack(etk::Path("/system/fonts"));#elif - * defined(__TARGET_OS__Linux) + * defined(TARGETOSLinux) * folderList.pushBack(etk::Path("/usr/share/fonts")); #endif */ } final Uri applicationBaseFont = Ewol.getContext().getFontDefault().getFolder(); - for (final Uri it : explodeMultiplePath(applicationBaseFont)) { + for (final Uri it : ResourceTexturedFont.explodeMultiplePath(applicationBaseFont)) { folderList.add(it); } for (int folderID = 0; folderID < folderList.size(); folderID++) { final List output = Uri.listRecursive(folderList.get(folderID)); - + final String[] split = localName.split(";"); Log.debug("try to find font named : " + split + " in: " + output); // Log.critical("parse string : " + split); @@ -141,58 +140,43 @@ public class ResourceTexturedFont extends ResourceTexture2 { for (int iii = 0; iii < output.size(); iii++) { final String nameFolder = output.get(iii).getPath(); // Log.debug(" file : " + output.get(iii)); - if (nameFolder.endsWith(split[jjj] + "-" + "bold" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "b" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "bd" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "bold" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "bd" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "b" + ".ttf") == true) { + if (nameFolder.endsWith(split[jjj] + "-" + "bold" + ".ttf") || nameFolder.endsWith(split[jjj] + "-" + "b" + ".ttf") || nameFolder.endsWith(split[jjj] + "-" + "bd" + ".ttf") + || nameFolder.endsWith(split[jjj] + "bold" + ".ttf") || nameFolder.endsWith(split[jjj] + "bd" + ".ttf") || nameFolder.endsWith(split[jjj] + "b" + ".ttf")) { Log.debug(" find Font [Bold] : " + output.get(iii)); this.fileName[FontMode.Bold.getValue()] = output.get(iii); hasFindAFont = true; - } else if (nameFolder.endsWith(split[jjj] + "-" + "oblique" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "italic" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "Light" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "i" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "oblique" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "italic" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "light" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "i" + ".ttf") == true) { + } else if (nameFolder.endsWith(split[jjj] + "-" + "oblique" + ".ttf") || nameFolder.endsWith(split[jjj] + "-" + "italic" + ".ttf") + || nameFolder.endsWith(split[jjj] + "-" + "Light" + ".ttf") || nameFolder.endsWith(split[jjj] + "-" + "i" + ".ttf") || nameFolder.endsWith(split[jjj] + "oblique" + ".ttf") + || nameFolder.endsWith(split[jjj] + "italic" + ".ttf") || nameFolder.endsWith(split[jjj] + "light" + ".ttf") || nameFolder.endsWith(split[jjj] + "i" + ".ttf")) { Log.debug(" find Font [Italic] : " + output.get(iii)); this.fileName[FontMode.Italic.getValue()] = output.get(iii); hasFindAFont = true; - } else if (nameFolder.endsWith(split[jjj] + "-" + "bolditalic" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "boldoblique" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "bi" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "z" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "bolditalic" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "boldoblique" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "bi" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "z" + ".ttf") == true) { + } else if (nameFolder.endsWith(split[jjj] + "-" + "bolditalic" + ".ttf") || nameFolder.endsWith(split[jjj] + "-" + "boldoblique" + ".ttf") + || nameFolder.endsWith(split[jjj] + "-" + "bi" + ".ttf") || nameFolder.endsWith(split[jjj] + "-" + "z" + ".ttf") || nameFolder.endsWith(split[jjj] + "bolditalic" + ".ttf") + || nameFolder.endsWith(split[jjj] + "boldoblique" + ".ttf") || nameFolder.endsWith(split[jjj] + "bi" + ".ttf") || nameFolder.endsWith(split[jjj] + "z" + ".ttf")) { Log.debug(" find Font [Bold-Italic] : " + output.get(iii)); this.fileName[FontMode.BoldItalic.getValue()] = output.get(iii); hasFindAFont = true; - } else if (nameFolder.endsWith(split[jjj] + "-" + "regular" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "-" + "r" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "regular" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + "r" + ".ttf") == true - || nameFolder.endsWith(split[jjj] + ".ttf") == true) { + } else if (nameFolder.endsWith(split[jjj] + "-" + "regular" + ".ttf") || nameFolder.endsWith(split[jjj] + "-" + "r" + ".ttf") + || nameFolder.endsWith(split[jjj] + "regular" + ".ttf") || nameFolder.endsWith(split[jjj] + "r" + ".ttf") || nameFolder.endsWith(split[jjj] + ".ttf")) { Log.debug(" find Font [Regular] : " + output.get(iii)); this.fileName[FontMode.Regular.getValue()] = output.get(iii); hasFindAFont = true; } } - if (hasFindAFont == true) { + if (hasFindAFont) { Log.debug(" find this font : '" + split[jjj] + "'"); break; - } else if (jjj == split.length - 1) { - Log.debug("Find NO font in the LIST ... " + split); + } + if (jjj == split.length - 1) { + Log.debug("Find NO font in the LIST ... " + Arrays.toString(split)); } } - if (hasFindAFont == true) { + if (hasFindAFont) { Log.debug(" find this font : '" + folderList.get(folderID) + "'"); break; - } else if (folderID == folderList.size() - 1) { + } + if (folderID == folderList.size() - 1) { Log.error("Find NO font in the LIST ... " + folderList); } } @@ -212,20 +196,17 @@ public class ResourceTexturedFont extends ResourceTexture2 { this.modeWraping[iii] = refMode; } } - + for (int iiiFontId = 0; iiiFontId < 4; iiiFontId++) { if (this.fileName[iiiFontId] == null) { - Log.debug("can not load FONT [" + iiiFontId + "] name : \"" + this.fileName[iiiFontId] - + "\" == > size=" + this.size); + Log.debug("can not load FONT [" + iiiFontId + "] name : \"" + this.fileName[iiiFontId] + "\" == > size=" + this.size); this.font[iiiFontId] = null; continue; } - Log.debug("Load FONT [" + iiiFontId + "] name : \"" + this.fileName[iiiFontId] + "\" == > size=" - + this.size); + Log.debug("Load FONT [" + iiiFontId + "] name : \"" + this.fileName[iiiFontId] + "\" == > size=" + this.size); this.font[iiiFontId] = ResourceFontFreeType.create(this.fileName[iiiFontId]); if (this.font[iiiFontId] == null) { - Log.debug("error in loading FONT [" + iiiFontId + "] name : \"" + this.fileName[iiiFontId] - + "\" == > size=" + this.size); + Log.debug("error in loading FONT [" + iiiFontId + "] name : \"" + this.fileName[iiiFontId] + "\" == > size=" + this.size); } } for (int iiiFontId = 0; iiiFontId < 4; iiiFontId++) { @@ -255,13 +236,13 @@ public class ResourceTexturedFont extends ResourceTexture2 { Log.debug(" " + FontMode.Bold + " == >" + getWrappingMode(FontMode.Bold)); Log.debug(" " + FontMode.BoldItalic + " == >" + getWrappingMode(FontMode.BoldItalic)); } - + /** * add a glyph in a texture font. - * @param _val Char value to add. + * @param val Char value to add. * @return true if the image size have change, false otherwise */ - private synchronized boolean addGlyph(final Character _val) { + private synchronized boolean addGlyph(final Character val) { boolean hasChange = false; // for each font : for (int iii = 0; iii < 4; iii++) { @@ -270,10 +251,10 @@ public class ResourceTexturedFont extends ResourceTexture2 { } // add the curent "char" final GlyphProperty tmpchar = new GlyphProperty(); - tmpchar.UVal = _val; - - if (this.font[iii].getGlyphProperty(this.size, tmpchar) == true) { - // Log.debug("load char : '" + _val + "'=" + _val.get()); + tmpchar.uVal = val; + + if (this.font[iii].getGlyphProperty(this.size, tmpchar)) { + // Log.debug("load char : '" + val + "'=" + val.get()); hasChange = true; // change line if needed ... if (this.lastGlyphPos[iii].x() + tmpchar.sizeTexture.x() + 3 > this.data.getSize().x()) { @@ -287,24 +268,17 @@ public class ResourceTexturedFont extends ResourceTexture2 { for (int kkk = 0; kkk < 4; kkk++) { // change the coordonate on the element in the texture for (int jjj = 0; jjj < this.listElement[kkk].size(); ++jjj) { - this.listElement[kkk] - .get(jjj).texturePosStart = this.listElement[kkk].get(jjj).texturePosStart - .multiply(new Vector2f(1.0f, 0.5f)); - this.listElement[kkk] - .get(jjj).texturePosSize = this.listElement[kkk].get(jjj).texturePosSize - .multiply(new Vector2f(1.0f, 0.5f)); + this.listElement[kkk].get(jjj).texturePosStart = this.listElement[kkk].get(jjj).texturePosStart.multiply(new Vector2f(1.0f, 0.5f)); + this.listElement[kkk].get(jjj).texturePosSize = this.listElement[kkk].get(jjj).texturePosSize.multiply(new Vector2f(1.0f, 0.5f)); } } } // draw the glyph this.font[iii].drawGlyph(this.data, this.size, this.lastGlyphPos[iii], tmpchar, iii); // set video position - tmpchar.texturePosStart = new Vector2f( - (float) this.lastGlyphPos[iii].x() / (float) this.data.getSize().x(), - (float) this.lastGlyphPos[iii].y() / (float) this.data.getSize().y()); - tmpchar.texturePosSize = new Vector2f((float) tmpchar.sizeTexture.x() / this.data.getSize().x(), - (float) tmpchar.sizeTexture.y() / this.data.getSize().y()); - + tmpchar.texturePosStart = new Vector2f((float) this.lastGlyphPos[iii].x() / (float) this.data.getSize().x(), (float) this.lastGlyphPos[iii].y() / (float) this.data.getSize().y()); + tmpchar.texturePosSize = new Vector2f((float) tmpchar.sizeTexture.x() / this.data.getSize().x(), (float) tmpchar.sizeTexture.y() / this.data.getSize().y()); + // update the maximum of the line hight : if (this.lastRawHeigh[iii] < tmpchar.sizeTexture.y()) { // note : +1 is for the overlapping of the glyph (Part 2) @@ -314,25 +288,25 @@ public class ResourceTexturedFont extends ResourceTexture2 { // update the Bitmap position drawing : this.lastGlyphPos[iii] = this.lastGlyphPos[iii].add(new Vector2i(tmpchar.sizeTexture.x() + 1, 0)); } else { - Log.warning("Did not find char : '" + _val + "'=" + _val); + Log.warning("Did not find char : '" + val + "'=" + val); tmpchar.setNotExist(); } this.listElement[iii].add(tmpchar); // this.font[iii].display; // generate the kerning for all the characters : - if (tmpchar.exist() == true) { + if (tmpchar.exist()) { // TODO : set the kerning back ... // this.font[iii].generateKerning(this.size, this.listElement[iii]); } } - if (hasChange == true) { + if (hasChange) { flush(); Ewol.getContext().forceRedrawAll(); // egami::store(this.data, "fileFont.bmp"); // ==> for debug test only ... } return hasChange; } - + /** * get the font height (user friendly) * @return Dimention of the font the user requested @@ -340,88 +314,88 @@ public class ResourceTexturedFont extends ResourceTexture2 { public int getFontSize() { return this.size; } - + /** * get the pointer on the coresponding glyph - * @param _charcode The unicodeValue - * @param _displayMode Mode to display the currrent font + * @param charcode The unicodeValue + * @param displayMode Mode to display the currrent font * @return The pointer on the glyph == > never null */ - public synchronized GlyphProperty getGlyph(final Character _charcode, final FontMode _displayMode) { - // Log.debug("Get glyph property for mode: " + _displayMode + " == > wrapping - // index : " + this.modeWraping[_displayMode]); - final int index = getIndex(_charcode, _displayMode); - if (index < 0 || index >= this.listElement[_displayMode.getValue()].size()) { + public synchronized GlyphProperty getGlyph(final Character charcode, final FontMode displayMode) { + // Log.debug("Get glyph property for mode: " + displayMode + " == > wrapping + // index : " + this.modeWraping[displayMode]); + final int index = getIndex(charcode, displayMode); + if (index < 0 || index >= this.listElement[displayMode.getValue()].size()) { Log.error(" Try to get glyph index inexistant ... == > return the index 0 ... id=" + index); - if (this.listElement[_displayMode.getValue()].size() > 0) { - return this.listElement[_displayMode.getValue()].get(0); + if (this.listElement[displayMode.getValue()].size() > 0) { + return this.listElement[displayMode.getValue()].get(0); } return this.emptyGlyph; } // Log.error(" index=" + index); - // Log.error(" this.UVal=" + this.listElement[_displayMode][index].UVal); + // Log.error(" this.UVal=" + this.listElement[displayMode][index].UVal); // Log.error(" this.glyphIndex=" + - // this.listElement[_displayMode][index].glyphIndex); - // Log.error(" this.advance=" + this.listElement[_displayMode][index].advance); - // Log.error(" this.bearing=" + this.listElement[_displayMode][index].bearing); - return this.listElement[_displayMode.getValue()].get(index); - }; - + // this.listElement[displayMode][index].glyphIndex); + // Log.error(" this.advance=" + this.listElement[displayMode][index].advance); + // Log.error(" this.bearing=" + this.listElement[displayMode][index].bearing); + return this.listElement[displayMode.getValue()].get(index); + } + /** * get the display height of this font - * @param _displayMode Mode to display the currrent font + * @param DisplayMode Mode to display the currrent font * @return Dimention of the font need between 2 lines */ public int getHeight() { return this.height[FontMode.Regular.getValue()]; } - - public int getHeight(final FontMode _displayMode) { - return this.height[_displayMode.getValue()]; + + public int getHeight(final FontMode displayMode) { + return this.height[displayMode.getValue()]; } - + /** * get the ID of a unicode charcode - * @param _charcode The unicodeValue - * @param _displayMode Mode to display the currrent font + * @param charcode The unicodeValue + * @param displayMode Mode to display the currrent font * @return The ID in the table (if it does not exist : return 0) */ - private synchronized int getIndex(final Character _charcode, final FontMode _displayMode) { - if (_charcode < 0x20) { + private synchronized int getIndex(final Character charcode, final FontMode displayMode) { + if (charcode < 0x20) { return 0; - } else if (_charcode < 0x80) { - return _charcode - 0x1F; - } else { - for (int iii = 0x80 - 0x20; iii < this.listElement[_displayMode.getValue()].size(); iii++) { - // Log.debug("search : '" + charcode + "' =?= '" + - // (this.listElement[displayMode])[iii].UVal + "'"); - if (_charcode == this.listElement[_displayMode.getValue()].get(iii).UVal) { - // Log.debug("search : '" + charcode + "'"); - if (this.listElement[_displayMode.getValue()].get(iii).exist()) { - // Log.debug("return " + iii); - return iii; - } else { - return 0; - } + } + if (charcode < 0x80) { + return charcode - 0x1F; + } + for (int iii = 0x80 - 0x20; iii < this.listElement[displayMode.getValue()].size(); iii++) { + // Log.debug("search : '" + charcode + "' =?= '" + + // (this.listElement[displayMode])[iii].UVal + "'"); + if (charcode == this.listElement[displayMode.getValue()].get(iii).uVal) { + // Log.debug("search : '" + charcode + "'"); + if (this.listElement[displayMode.getValue()].get(iii).exist()) { + // Log.debug("return " + iii); + return iii; + } else { + return 0; } } } - if (addGlyph(_charcode) == true) { + if (addGlyph(charcode)) { // TODO : This does not work due to the fact that the update of open GL is not // done in the context main cycle !!! Ewol.getContext().forceRedrawAll(); } return 0; - }; - + } + /** * The wrapping mode is used to prevent the non existance of a specific * mode. For exemple when a blod mode does not exist, this resend a * regular mode. - * @param _source The requested mode. + * @param source The requested mode. * @return the best mode we have in stock. */ - public FontMode getWrappingMode(final FontMode _source) { - return this.modeWraping[_source.getValue()]; + public FontMode getWrappingMode(final FontMode source) { + return this.modeWraping[source.getValue()]; } } diff --git a/src/org/atriasoft/ewol/resource/font/FontBase.java b/src/org/atriasoft/ewol/resource/font/FontBase.java index 5830832..95b1dd8 100644 --- a/src/org/atriasoft/ewol/resource/font/FontBase.java +++ b/src/org/atriasoft/ewol/resource/font/FontBase.java @@ -14,12 +14,12 @@ import org.atriasoft.etk.math.Vector2f; import org.atriasoft.etk.math.Vector2i; import org.atriasoft.gale.resource.Resource; -// https://developer.mozilla.org/fr/docs/Web/SVG/Tutorial/SVG_fonts +// https://developer.mozilla.org/fr/docs/Web/SVG/Tutorial/SVGfonts // https://convertio.co/fr/ttf-svg/ public abstract class FontBase extends Resource { - public FontBase(final Uri _uri) { - super(_uri); + public FontBase(final Uri uri) { + super(uri); } @Override @@ -30,21 +30,21 @@ public abstract class FontBase extends Resource { public void display() {} - public abstract boolean drawGlyph(final Image _imageOut, final int _fontSize, final Vector2i _glyphPosition, GlyphProperty _property, int _posInImage); + public abstract boolean drawGlyph(final Image imageOut, final int fontSize, final Vector2i glyphPosition, GlyphProperty property, int posInImage); - public boolean drawGlyph(final ImageMono _imageOut, final int _fontSize, final GlyphProperty _property) { - return drawGlyph(_imageOut, _fontSize, _property, 0); + public boolean drawGlyph(final ImageMono imageOut, final int fontSize, final GlyphProperty property) { + return drawGlyph(imageOut, fontSize, property, 0); } - public abstract boolean drawGlyph(final ImageMono _imageOut, final int _fontSize, GlyphProperty _property, int _borderSize); + public abstract boolean drawGlyph(final ImageMono imageOut, final int fontSize, GlyphProperty property, int borderSize); - public void generateKerning(final int _fontSize, final List _listGlyph) {} + public void generateKerning(final int fontSize, final List listGlyph) {} - public abstract boolean getGlyphProperty(final int _fontSize, GlyphProperty _property); + public abstract boolean getGlyphProperty(final int fontSize, GlyphProperty property); - public abstract int getHeight(final int _fontSize); + public abstract int getHeight(final int fontSize); - public abstract Vector2f getSize(final int _fontSize, final String _unicodeString); + public abstract Vector2f getSize(final int fontSize, final String unicodeString); - public abstract float getSizeWithHeight(final float _fontHeight);; + public abstract float getSizeWithHeight(final float fontHeight); } \ No newline at end of file diff --git a/src/org/atriasoft/ewol/resource/font/FontMode.java b/src/org/atriasoft/ewol/resource/font/FontMode.java index 194de03..71f24f4 100644 --- a/src/org/atriasoft/ewol/resource/font/FontMode.java +++ b/src/org/atriasoft/ewol/resource/font/FontMode.java @@ -7,15 +7,12 @@ public enum FontMode { BoldItalic(3); public static FontMode get(final int newValue) { - switch (newValue) { - case 1: - return Italic; - case 2: - return Bold; - case 3: - return BoldItalic; - } - return Regular; + return switch (newValue) { + case 1 -> Italic; + case 2 -> Bold; + case 3 -> BoldItalic; + default -> Regular; + }; } private final int value; diff --git a/src/org/atriasoft/ewol/resource/font/GlyphProperty.java b/src/org/atriasoft/ewol/resource/font/GlyphProperty.java index 3d0520c..cbb6ea1 100644 --- a/src/org/atriasoft/ewol/resource/font/GlyphProperty.java +++ b/src/org/atriasoft/ewol/resource/font/GlyphProperty.java @@ -35,7 +35,7 @@ import org.atriasoft.etk.math.Vector2i; /-. | | \-. \. | bearing.y | - |____*________________________*____________>> X + |**>> X <-----------------------. : advance.x @@ -46,18 +46,18 @@ import org.atriasoft.etk.math.Vector2i; */ /** - * @not_in_doc + * @notindoc */ public class GlyphProperty { - public Character UVal = 0; //!< Unicode value + public Vector2i advance = new Vector2i(10, 10); //!< space use in the display for this specific char + public Vector2i bearing = new Vector2i(2, 2); //!< offset to display the data (can be negatif id the texture sise is bigger than the theoric places in the string) public boolean exist = true; public int glyphIndex = 0; //!< Glyph index in the system - public Vector2i sizeTexture = new Vector2i(10, 10); //!< size of the element to display - public Vector2i bearing = new Vector2i(2, 2); //!< offset to display the data (can be negatif id the texture sise is bigger than the theoric places in the string) - public Vector2i advance = new Vector2i(10, 10); //!< space use in the display for this specific char - public Vector2f texturePosStart = new Vector2f(0, 0); //!< Texture normalized position (START) - public Vector2f texturePosSize = new Vector2f(0, 0); //!< Texture normalized position (SIZE) private final List kerning = new ArrayList<>(); //!< kerning values of link of all elements + public Vector2i sizeTexture = new Vector2i(10, 10); //!< size of the element to display + public Vector2f texturePosSize = new Vector2f(0, 0); //!< Texture normalized position (SIZE) + public Vector2f texturePosStart = new Vector2f(0, 0); //!< Texture normalized position (START) + public Character uVal = 0; //!< Unicode value public GlyphProperty() { @@ -71,17 +71,17 @@ public class GlyphProperty { return this.exist; } - public void kerningAdd(final Character _charcode, final float _value) { - this.kerning.add(new Kerning(_charcode, _value)); + public void kerningAdd(final Character charcode, final float value) { + this.kerning.add(new Kerning(charcode, value)); } public void kerningClear() { this.kerning.clear(); } - public float kerningGet(final Character _charcode) { + public float kerningGet(final Character charcode) { for (int iii = 0; iii < this.kerning.size(); iii++) { - if (this.kerning.get(iii).UVal == _charcode) { + if (this.kerning.get(iii).uVal == charcode) { return this.kerning.get(iii).value; } } diff --git a/src/org/atriasoft/ewol/resource/font/Kerning.java b/src/org/atriasoft/ewol/resource/font/Kerning.java index 9acacf1..5be19fe 100644 --- a/src/org/atriasoft/ewol/resource/font/Kerning.java +++ b/src/org/atriasoft/ewol/resource/font/Kerning.java @@ -6,7 +6,7 @@ package org.atriasoft.ewol.resource.font; /** - * @not_in_doc + * @notindoc * Kerning properties of one specific Glyph with an other * * Without Kerning : @@ -15,7 +15,7 @@ package org.atriasoft.ewol.resource.font; * \ / /\ * \ / / \ * \ / / \ - * \ / /______\ + * \ / /\ * \ / / \ * \/ / \ * v v a a @@ -27,7 +27,7 @@ package org.atriasoft.ewol.resource.font; * \ / /\ * \ / / \ * \ / / \ - * \ / /______\ + * \ / /\ * \ / / \ * \/ / \ * v a v a @@ -37,24 +37,24 @@ package org.atriasoft.ewol.resource.font; * the "VA" has 2 letter that overlap themself. This name Kerning */ public class Kerning { - public Character UVal; //!< unicode value (the previous character that must be before) + public Character uVal; //!< unicode value (the previous character that must be before) public float value; //!< kerning real offset /** * Simple ructor that allow to allocate the List element */ public Kerning() { - this.UVal = 0; + this.uVal = 0; this.value = 0; - }; + } /** * Normal ructor - * @param _charcode The Unicode value of the coresponding character that might be before - * @param _value The Kerning value of the offset (nb pixel number) + * @param charcode The Unicode value of the coresponding character that might be before + * @param value The Kerning value of the offset (nb pixel number) */ - public Kerning(final Character _charcode, final float _value) { - this.UVal = _charcode; - this.value = _value; + public Kerning(final Character charcode, final float value) { + this.uVal = charcode; + this.value = value; } } diff --git a/src/org/atriasoft/ewol/tools/Message.java b/src/org/atriasoft/ewol/tools/Message.java index 78dca14..7ee78a4 100644 --- a/src/org/atriasoft/ewol/tools/Message.java +++ b/src/org/atriasoft/ewol/tools/Message.java @@ -4,76 +4,79 @@ * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ -package org.atriasoft.ewol.tools; +package org.atriasoft.ewol.tools; -import org.atriasoft.ewol.Ewol; +import org.atriasoft.ewol.internal.Log; public class Message { - - /** - * Create a simple pop-up message on the screen for application error. - * @param _type Type of the error. - * @param _message message to display (decorated text) - */ - private static void create(Type _type, String _message){ + private enum Type { + critical, //!< Critical message pop-up, //!< information message pop-up + error, //!< warning message pop-up + info, //!< Error message pop-up + warning + } + + /** + * Create a simple pop-up message on the screen for application error. + * @param type Type of the error. + * @param message message to display (decorated text) + */ + private static void create(final Type type, final String message) { + Log.todo("Generic message display (simple interface...)"); + /* 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}"); + 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.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); + Log.error("can not get the current windows ... ==> can not display message : " + message); return; } windows.popUpWidgetPush(tmpPopUp); + */ } - + /** - * Create a simple information message - * @param _message message to display (decorated text) - */ - public static void displayInfo(String _message){ - create(Type.info, _message); + * Create a simple critical message + * @param message message to display (decorated text) + */ + public static void displayCritical(final String message) { + Message.create(Type.critical, message); } - - /** - * Create a simple warning message - * @param _message message to display (decorated text) - */ - public static void displayWarning(String _message) { - create(Type.warning, _message); + + /** + * Create a simple error message + * @param message message to display (decorated text) + */ + public static void displayError(final String message) { + Message.create(Type.error, message); } - - /** - * Create a simple error message - * @param _message message to display (decorated text) - */ - public static void displayError(String _message) { - create(Type.error,_message); + + /** + * Create a simple information message + * @param message message to display (decorated text) + */ + public static void displayInfo(final String message) { + Message.create(Type.info, message); } - /** - * Create a simple critical message - * @param _message message to display (decorated text) - */ - public static void displayCritical(String _message){ - create(Type.critical, _message); + + /** + * Create a simple warning message + * @param message message to display (decorated text) + */ + public static void displayWarning(final String message) { + Message.create(Type.warning, message); } - - private enum Type { - info, //!< information message pop-up - warning, //!< warning message pop-up - error, //!< Error message pop-up - critical //!< Critical message pop-up - } - - + + private Message() {} + } - diff --git a/src/org/atriasoft/ewol/widget/Container.java b/src/org/atriasoft/ewol/widget/Container.java index 203630f..c9c314e 100644 --- a/src/org/atriasoft/ewol/widget/Container.java +++ b/src/org/atriasoft/ewol/widget/Container.java @@ -1,72 +1,195 @@ +/* + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +package org.atriasoft.ewol.widget; + 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) - */ /* * @ingroup ewolWidgetGroup * the Cotainer widget is a widget that have an only one subWidget */ -class Container extends Widget { +public class Container extends Widget { protected Widget subWidget = null; + /** * Constructor */ public Container() { - super(); } + + @Override + 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); + } + + @Override + public void drawWidgetTree(int level) { + super.drawWidgetTree(level); + level++; + if (this.subWidget != null) { + this.subWidget.drawWidgetTree(level); + } + } + + @Override + public EwolObject getSubObjectNamed(final String objectName) { + EwolObject tmpObject = super.getSubObjectNamed(objectName); + if (tmpObject != null) { + return tmpObject; + } + if (this.subWidget != null) { + return this.subWidget.getSubObjectNamed(objectName); + } + return null; + } + /** * get the main node widget * @return the requested pointer on the node */ - public Widget getSubWidget(){ + public Widget getSubWidget() { return this.subWidget; } - /** - * set the subWidget node widget. - * @param _newWidget The widget to add. - */ - public void setSubWidget(Widget _newWidget){ - if (_newWidget == null) { + + @Override + public Widget getWidgetAtPos(final Vector2f pos) { + if (!this.propertyHide) { + if (this.subWidget != null) { + return this.subWidget.getWidgetAtPos(pos); + } + } + return null; + } + + @Override + public boolean loadXML(final 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; + } + + @Override + public void onChangeSize() { + super.onChangeSize(); + if (this.propertyHide) { return; } - subWidgetRemove(); - this.subWidget = _newWidget; - if (this.subWidget != null) { - this.subWidget.setParent(this); + if (this.subWidget == null) { + return; } - markToRedraw(); - requestUpdateSize(); + Vector2f origin = this.origin.add(this.offset); + Vector2f minSize = this.subWidget.getCalculateMinSize(); + Vector2b expand = this.subWidget.getPropertyExpand(); + origin = origin.add(Gravity.gravityGenerateDelta(this.propertyGravity, minSize.less(this.size))); + this.subWidget.setOrigin(origin); + this.subWidget.setSize(this.size); + this.subWidget.onChangeSize(); } - /** - * Replace a old subwidget with a new one. - * @param _oldWidget The widget to replace. - * @param _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"); + + @Override + public void onRegenerateDisplay() { + if (this.subWidget != null) { + this.subWidget.onRegenerateDisplay(); + } + } + + @Override + public void requestDestroyFromChild(final EwolObject child) { + if (this.subWidget != child) { + return; + } + if (this.subWidget == null) { return; } this.subWidget.removeParent(); - this.subWidget = _newWidget; + this.subWidget = null; + markToRedraw(); + } + + @Override + public void setOffset(final Vector2f newVal) { + if (this.offset.equals(newVal)) { + return; + } + super.setOffset(newVal); + // recalculate the new sise and position of sub widget ... + onChangeSize(); + + } + + /** + * set the subWidget node widget. + * @param newWidget The widget to add. + */ + public void setSubWidget(final Widget newWidget) { + if (newWidget == null) { + return; + } + subWidgetRemove(); + this.subWidget = newWidget; if (this.subWidget != null) { this.subWidget.setParent(this); } markToRedraw(); requestUpdateSize(); } + /** * remove the subWidget node (async). */ @@ -78,148 +201,49 @@ class Container extends Widget { requestUpdateSize(); } } + + /** + * Replace a old subwidget with a new one. + * @param oldWidget The widget to replace. + * @param newWidget The widget to set. + */ + public void subWidgetReplace(final Widget oldWidget, final 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(); + } + /** * Unlink the subwidget Node. */ - public void subWidgetUnLink(){ + public void subWidgetUnLink() { if (this.subWidget != null) { this.subWidget.removeParent(); } this.subWidget = null; } - public void systemDraw( DrawProperty _displayProp){ - if (propertyHide){ + + @Override + public void systemDraw(final DrawProperty displayProp) { + if (this.propertyHide) { // widget is hidden ... return; } - super.systemDraw(_displayProp); + super.systemDraw(displayProp); if (this.subWidget != null) { - DrawProperty prop = _displayProp.withLimit(this.origin, this.size); + 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 +} \ No newline at end of file diff --git a/src/org/atriasoft/ewol/widget/ContainerN.java b/src/org/atriasoft/ewol/widget/ContainerN.java index cfcb439..761204e 100644 --- a/src/org/atriasoft/ewol/widget/ContainerN.java +++ b/src/org/atriasoft/ewol/widget/ContainerN.java @@ -1,46 +1,79 @@ -package org.atriasoft.ewol.widget; /** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ +package org.atriasoft.ewol.widget; -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; +/** @file +* @author Edouard DUPIN +* @copyright 2011, Edouard DUPIN, all right reserved +* @license MPL v2.0 (see license file) +*/ import java.util.ArrayList; import java.util.List; +import java.util.ListIterator; + +import org.atriasoft.etk.math.Vector2b; +import org.atriasoft.etk.math.Vector2f; +import org.atriasoft.ewol.DrawProperty; +import org.atriasoft.ewol.annotation.EwolDescription; +import org.atriasoft.ewol.internal.Log; +import org.atriasoft.ewol.object.EwolObject; +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.exml.model.XmlNode; /** * @ingroup ewolWidgetGroup * the Cotainer widget is a widget that have an only one subWidget */ public class ContainerN extends Widget { - @XmlManaged() - @XmlProperty() + + @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 Vector2b propertyLockExpand = new Vector2b(false, false); //!< Lock the expend of the sub widget to this one == > this permit to limit bigger subWidget + protected Vector2b subExpend = new Vector2b(false, false); //!< reference of the sub element expention requested. protected List subWidget = new ArrayList<>(); - protected Vector2b subExpend = new Vector2b(false,false); //!< reference of the sub element expention requested. + /** * Constructor */ - protected ContainerN() {} + protected ContainerN() {} + + @Override + public void calculateMinMaxSize() { + this.subExpend = new Vector2b(false, false); + this.minSize = Vector2f.ZERO; + this.maxSize = Vector2f.MAX_VALUE; + //Log.error("[" + getId() + "] {" + getObjectType() + "} set min size : " + this.minSize); + for (Widget it : this.subWidget) { + if (it != null) { + it.calculateMinMaxSize(); + Vector2b subExpendProp = it.canExpand(); + if (subExpendProp.x()) { + this.subExpend = this.subExpend.withX(true); + } + if (subExpendProp.y()) { + this.subExpend = this.subExpend.withX(true); + } + Vector2f tmpSize = it.getCalculateMinSize(); + this.minSize = Vector2f.max(tmpSize, this.minSize); + } + } + //Log.error("[" + getId() + "] {" + getObjectType() + "} Result min size : " + this.minSize); + } + // herited function + @Override public Vector2b canExpand() { - Vector2b res = propertyExpand; - if (!propertyLockExpand.x()) { + Vector2b res = this.propertyExpand; + if (!this.propertyLockExpand.x()) { if (this.subExpend.x()) { res = res.withX(true); } } - if (!propertyLockExpand.y()) { + if (!this.propertyLockExpand.y()) { if (this.subExpend.y()) { res = res.withY(true); } @@ -48,203 +81,42 @@ public class ContainerN extends Widget { //Log.debug("Expend check : user=" + this.userExpand + " lock=" + propertyLockExpand + " sub=" + this.subExpend + " res=" + res); return res; } - /** - * 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(); - } - /** - * remove all sub element from the widget (delayed to prevent remove in the callbback). - */ - public void subWidgetRemoveAllDelayed(){ - subWidgetRemoveAll(); - } - /** - * Replace a old subwidget with a new one. - * @param _oldWidget The widget to replace. - * @param _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(); - } - /** - * add at end position a Widget (note : This system use an inverted phylisophie (button to top, and left to right) - * @param _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); - }; - /** - * add at start position a Widget (note : This system use an inverted phylisophie (button to top, and left to right) - * @param _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); - }; - /** - * remove definitly a widget from the system and this layer. - * @param _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; - } - } - } - /** - * Just unlick the specify widget, this function does not remove it from the system (if you can, do nt use it ...) - * @param _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(){ + @Override + public void drawWidgetTree(int level) { + super.drawWidgetTree(level); + level++; for (Widget it : this.subWidget) { if (it != null) { - it.onRegenerateDisplay(); + it.drawWidgetTree(level); } } } - 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); + public Vector2b getPropertyLockExpand() { + return this.propertyLockExpand; + } + + @Override + public EwolObject getSubObjectNamed(final String objectName) { + EwolObject tmpObject = super.getSubObjectNamed(objectName); + if (tmpObject != null) { + return tmpObject; + } for (Widget it : this.subWidget) { if (it != null) { - it.calculateMinMaxSize(); - Vector2b subExpendProp = it.canExpand(); - if (true == subExpendProp.x()) { - this.subExpend.setX(true); + tmpObject = it.getSubObjectNamed(objectName); + if (tmpObject != null) { + return tmpObject; } - 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); + return null; } - public Widget getWidgetAtPos( Vector2f _pos) { - if (*propertyHide == true) { + + @Override + public Widget getWidgetAtPos(final Vector2f pos) { + if (this.propertyHide) { return null; } // for all element in the sizer ... @@ -252,10 +124,8 @@ public class ContainerN extends Widget { 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 ((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; } @@ -265,111 +135,278 @@ public class ContainerN extends Widget { } } 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) { + + @Override + public boolean loadXML(final XmlElement node) { + if (node == null) { return false; } // parse generic properties : - Widget::loadXML(_node); + super.loadXML(node); // remove previous element : subWidgetRemoveAll(); - String tmpAttributeValue = _node.attributes["lock"]; - if (tmpAttributeValue.size()!=0) { - propertyLockExpand.set(tmpAttributeValue); + String tmpAttributeValue = node.getAttribute("lock", ""); + if (tmpAttributeValue.length() != 0) { + setPropertyLockExpand(Vector2b.valueOf(tmpAttributeValue)); } - boolean invertAdding=false; - tmpAttributeValue = _node.attributes["addmode"]; - if(etk::compare_no_case(tmpAttributeValue, "invert")) { - invertAdding=true; + boolean invertAdding = false; + tmpAttributeValue = node.getAttribute("addmode", "").toLowerCase(); + if (tmpAttributeValue.contentEquals("invert")) { + invertAdding = true; } // parse all the elements : - for ( auto nodeIt : _node.nodes) { - exml::Element pNode = nodeIt.toElement(); - if (pNode.exist() == false) { + for (XmlNode nodeIt : node.getNodes()) { + if (!nodeIt.isElement()) { // trash here all that is not element continue; } + XmlElement pNode = nodeIt.toElement(); 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() << "]" ); + Log.verbose(" t=" + this.getClass().getCanonicalName() + " Load node name : '" + widgetName + "'"); + if (!getWidgetManager().exist(widgetName)) { + Log.error("[" + getId() + "] {" + this.getClass().getCanonicalName() + "} Unknown basic node='" + widgetName + "' not in : [" + getWidgetManager().list() + "]"); continue; } - Log.debug("[" + getId() + "] {" + getObjectType() + "} load new element : '" + widgetName + "'"); + Log.debug("[" + getId() + "] {" + this.getClass().getCanonicalName() + "} 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 + "'"); + Log.error("[" + getId() + "] {" + this.getClass().getCanonicalName() + "} Can not create the widget : '" + widgetName + "'"); continue; } // add sub element : - if (invertAdding == false) { + if (!invertAdding) { subWidgetAdd(subWidget); } else { subWidgetAddStart(subWidget); } - if (subWidget.loadXML(pNode) == false) { - Log.error("[" + getId() + "] {" + getObjectType() + "} (l " + pNode.getPos() + ") can not load widget properties : '" + widgetName + "'"); + if (!subWidget.loadXML(pNode)) { + Log.error("[" + getId() + "] {" + this.getClass().getCanonicalName() + "} 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(); + + @Override + public void onChangeSize() { + for (Widget it : this.subWidget) { + if (it == null) { continue; } - ++it; + it.setOrigin(this.origin.add(this.offset)); + it.setSize(this.size); + it.onChangeSize(); } } - public void drawWidgetTree(int _level) { - super.drawWidgetTree(_level); - _level++; - for (Widget it: this.subWidget) { + + @Override + public void onRegenerateDisplay() { + for (Widget it : this.subWidget) { if (it != null) { - it.drawWidgetTree(_level); + it.onRegenerateDisplay(); } } } - protected void onChangePropertyLockExpand() { + @Override + public void requestDestroyFromChild(final EwolObject child) { + ListIterator it = this.subWidget.listIterator(); + while (it.hasNext()) { + Widget elem = it.next(); + if (elem != child) { + continue; + } + if (elem == null) { + it.remove(); + continue; + } + elem.removeParent(); + it.remove(); + it = this.subWidget.listIterator(); + markToRedraw(); + } + } + + @Override + public void setOffset(final Vector2f newVal) { + if (this.offset != newVal) { + super.setOffset(newVal); + // recalculate the new sise and position of sub widget ... + onChangeSize(); + } + } + + public void setPropertyLockExpand(final Vector2b propertyLockExpand) { + if (propertyLockExpand.equals(this.propertyLockExpand)) { + return; + } + this.propertyLockExpand = propertyLockExpand; markToRedraw(); requestUpdateSize(); } + + /** + * add at end position a Widget (note : This system use an inverted phylisophie (button to top, and left to right) + * @param newWidget the element pointer + * @return the ID of the set element + */ + public int subWidgetAdd(final 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(final Widget newWidget) { + return subWidgetAdd(newWidget); + } + + //! @previous + public int subWidgetAddEnd(final Widget newWidget) { + return subWidgetAdd(newWidget); + } + + //! @previous + public int subWidgetAddFront(final Widget newWidget) { + return subWidgetAddStart(newWidget); + } + + /** + * add at start position a Widget (note : This system use an inverted phylisophie (button to top, and left to right) + * @param newWidget the element pointer + * @return the ID of the set element + */ + public int subWidgetAddStart(final 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.add(0, newWidget); + markToRedraw(); + requestUpdateSize(); + return newWidget.getId(); + } + + /** + * remove definitly a widget from the system and this layer. + * @param newWidget the element pointer. + */ + public void subWidgetRemove(final Widget newWidget) { + if (newWidget == null) { + return; + } + int errorControl = this.subWidget.size(); + + ListIterator it = this.subWidget.listIterator(); + while (it.hasNext()) { + Widget elem = it.next(); + if (newWidget == elem) { + elem.removeParent(); + it.remove(); + markToRedraw(); + requestUpdateSize(); + } + } + } + + /** + * 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(); + } + + /** + * remove all sub element from the widget (delayed to prevent remove in the callbback). + */ + public void subWidgetRemoveAllDelayed() { + subWidgetRemoveAll(); + } + + /** + * Replace a old subwidget with a new one. + * @param oldWidget The widget to replace. + * @param newWidget The widget to set. + */ + public void subWidgetReplace(final Widget oldWidget, final Widget newWidget) { + boolean haveChange = false; + ListIterator it = this.subWidget.listIterator(); + while (it.hasNext()) { + Widget elem = it.next(); + if (elem != oldWidget) { + continue; + } + elem.removeParent(); + if (newWidget != null) { + newWidget.setParent(this); + } + it.set(newWidget); + haveChange = true; + } + if (!haveChange) { + Log.warning("Request replace with a wrong old widget"); + return; + } + markToRedraw(); + requestUpdateSize(); + } + + /** + * Just unlock the specify widget, this function does not remove it from the system (if you can, do nt use it ...) + * @param newWidget the element pointer. + */ + public void subWidgetUnLink(final Widget newWidget) { + if (newWidget == null) { + return; + } + ListIterator it = this.subWidget.listIterator(); + while (it.hasNext()) { + Widget elem = it.next(); + if (newWidget == elem) { + elem.removeParent(); + it.remove(); + markToRedraw(); + requestUpdateSize(); + } + } + } + + @Override + public void systemDraw(final DrawProperty displayProp) { + if (this.propertyHide) { + // widget is hidden ... + return; + } + // local widget draw + super.systemDraw(displayProp); + // subwidget draw + DrawProperty prop = displayProp; + prop = prop.withLimit(this.origin, this.size); + ListIterator it = this.subWidget.listIterator(this.subWidget.size()); + while (it.hasPrevious()) { + Widget elem = it.previous(); + if (elem != null) { + //Log.info(" ***** : [" + (*it).propertyName + "] t=" + (*it).getObjectType() + " o=" + (*it).this.origin + " s=" + (*it).this.size); + elem.systemDraw(prop); + } + } + } } diff --git a/src/org/atriasoft/ewol/widget/Image.cpp b/src/org/atriasoft/ewol/widget/Image.cpp deleted file mode 100644 index 327dda2..0000000 --- a/src/org/atriasoft/ewol/widget/Image.cpp +++ /dev/null @@ -1,239 +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 -ETK_DECLARE_TYPE(ewol::widget::Image); - -ewol::widget::Image::Image() : - signalPressed(this, "pressed", "Image is pressed"), - propertySource(this, "src", "", "Image source path", ewol::widget::Image::onChangePropertySource), - propertyBorder(this, "border", Vector2f(0,0), "Border of the image", ewol::widget::Image::onChangePropertyGlobalSize), - propertyImageSize(this, "size", Vector2f(0,0), "Basic display size of the image", ewol::widget::Image::onChangePropertyGlobalSize), - propertyKeepRatio(this, "ratio", true, "Keep ratio of the image", ewol::widget::Image::onChangePropertyGlobalSize), - propertyPosStart(this, "part-start", Vector2f(0.0f, 0.0f), Vector2f(0.0f, 0.0f), Vector2f(1.0f, 1.0f), "Start display position in the image", ewol::widget::Image::onChangePropertyGlobalSize), - propertyPosStop(this, "part-stop", Vector2f(1.0f, 1.0f), Vector2f(0.0f, 0.0f), Vector2f(1.0f, 1.0f), "Start display position in the image", ewol::widget::Image::onChangePropertyGlobalSize), - propertyDistanceFieldMode(this, "distance-field", false, "Distance field mode", ewol::widget::Image::onChangePropertyDistanceFieldMode), - propertySmooth(this, "smooth", true, "Smooth display of the image", ewol::widget::Image::onChangePropertySmooth), - propertyUseThemeColor(this, "use-theme-color", false, "use the theme color to display images", ewol::widget::Image::onChangePropertyUseThemeColor), - this.colorProperty(null), - this.colorId(-1) { - addObjectType("ewol::widget::Image"); - this.imageRenderSize = Vector2f(0,0); - this.colorProperty = ewol::resource::ColorFile::create(etk::Uri("THEME_COLOR:///Image.json?lib=ewol")); - if (this.colorProperty != null) { - this.colorId = this.colorProperty.request("foreground"); - } -} -ewol::widget::Image::~Image() { - -} - -void ewol::widget::Image::init() { - Widget::init(); - if (*propertySource != "") { - onChangePropertySource(); - } -} - -void ewol::widget::Image::set( etk::Uri _uri, gale::Dimension _border) { - Log.verbose("Set Image : " + _uri + " border=" + _border); - propertyBorder.set(_border); - propertySource.set(_uri); -} - -void ewol::widget::Image::setCustumSource( egami::Image _image) { - // TODO : Better interfacing of all element internal ==> this is a temporary prototype - this.compositing.setSource(_image); - markToRedraw(); - requestUpdateSize(); -} - -void ewol::widget::Image::onDraw() { - this.compositing.draw(); -} - -void ewol::widget::Image::onRegenerateDisplay() { - if (needRedraw() == false) { - return; - } - // remove data of the previous composition : - this.compositing.clear(); - if ( *propertyUseThemeColor == true - LOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOMLOM this.colorProperty != null) { - this.compositing.setColor(this.colorProperty.get(this.colorId)); - } - // Calculate the new position and size: - Vector2f imageBoder = propertyBorder.getPixel(); - Vector2f origin = imageBoder; - imageBoder *= 2.0f; - Vector2f imageRealSize = this.imageRenderSize - imageBoder; - Vector2f imageRealSizeMax = this.size - imageBoder; - - Vector2f ratioSizeDisplayRequested = *propertyPosStop - *propertyPosStart; - //imageRealSizeMax *= ratioSizeDisplayRequested; - - Vector2f delta = ewol::gravityGenerateDelta(*propertyGravity, this.size-this.imageRenderSize); - if (propertyFill.x() == true) { - imageRealSize.setX(imageRealSizeMax.x()); - delta.setX(0.0); - } - if (propertyFill.y() == true) { - imageRealSize.setY(imageRealSizeMax.y()); - delta.setY(0.0); - } - origin += delta; - - if (*propertyKeepRatio == true) { - Vector2f tmpSize = this.compositing.getRealSize(); - //float ratio = tmpSize.x() / tmpSize.y(); - float ratio = (tmpSize.x()*ratioSizeDisplayRequested.x()) / (tmpSize.y() * ratioSizeDisplayRequested.y()); - //float ratioCurrent = (imageRealSize.x()*ratioSizeDisplayRequested.x()) / (imageRealSize.y() * ratioSizeDisplayRequested.y()); - float ratioCurrent = imageRealSize.x() / imageRealSize.y(); - if (ratio == ratioCurrent) { - // nothing to do ... - } else if (ratio < ratioCurrent) { - float oldX = imageRealSize.x(); - imageRealSize.setX(imageRealSize.y()*ratio); - origin += Vector2f((oldX - imageRealSize.x()) * 0.5f, 0); - } else { - float oldY = imageRealSize.y(); - imageRealSize.setY(imageRealSize.x()/ratio); - origin += Vector2f(0, (oldY - imageRealSize.y()) * 0.5f); - } - } - - // set the somposition properties : - if (*propertySmooth == true) { - this.compositing.setPos(origin); - } else { - this.compositing.setPos(Vector2i(origin)); - } - this.compositing.printPart(imageRealSize, *propertyPosStart, *propertyPosStop); - Log.debug("Paint Image at : " + origin + " size=" + imageRealSize); - Log.debug("Paint Image :" + *propertySource + " realsize=" + this.compositing.getRealSize() + " origin=" + origin + " size=" + imageRealSize); - Log.debug(" start=" + *propertyPosStart + " stop=" + *propertyPosStop); -} - -void ewol::widget::Image::calculateMinMaxSize() { - Log.debug("calculate min size: border=" + propertyBorder + " size=" + propertyImageSize + " min-size=" + propertyMinSize); - Vector2f imageBoder = propertyBorder.getPixel()*2.0f; - Vector2f imageSize = propertyImageSize.getPixel(); - Vector2f size = propertyMinSize.getPixel(); - Log.debug(" ==> border=" + imageBoder + " size=" + imageSize + " min-size=" + size); - if (imageSize != Vector2f(0,0)) { - this.minSize = imageBoder+imageSize; - this.maxSize = this.minSize; - } else { - Vector2f imageSizeReal = this.compositing.getRealSize(); - Log.verbose(" Real Size = " + imageSizeReal); - Vector2f min1 = imageBoder+propertyMinSize.getPixel(); - this.minSize = imageBoder+imageSizeReal; - Log.verbose(" set max : " + this.minSize + " min1=" + min1); - this.minSize.setMax(min1); - Log.verbose(" result : " + this.minSize); - this.maxSize = imageBoder+propertyMaxSize.getPixel(); - this.minSize.setMin(this.maxSize); - } - this.imageRenderSize = this.minSize; - this.minSize.setMax(size); - this.maxSize.setMax(this.minSize); - Log.debug("set widget min=" + this.minSize + " max=" + this.maxSize + " with real Image size=" + this.imageRenderSize + " img size=" + imageSize + " " << propertyImageSize); - markToRedraw(); -} - - -boolean ewol::widget::Image::onEventInput( ewol::event::Input _event) { - //Log.debug("Event on BT ..."); - if (_event.getId() == 1) { - if(KeyStatus::pressSingle == _event.getStatus()) { - signalPressed.emit(); - return true; - } - } - return false; -} - -boolean ewol::widget::Image::loadXML( exml::Element _node) { - if (_node.exist() == false) { - return false; - } - Widget::loadXML(_node); - // get internal data : - - String tmpAttributeValue = _node.attributes["ratio"]; - if (tmpAttributeValue.size() != 0) { - if (etk::compare_no_case(tmpAttributeValue, "true") == true) { - propertyKeepRatio.setDirect(true); - } else if (tmpAttributeValue == "1") { - propertyKeepRatio.setDirect(true); - } else { - propertyKeepRatio.setDirect(false); - } - } - tmpAttributeValue = _node.attributes["size"]; - if (tmpAttributeValue.size() != 0) { - //Log.critical(" Parse SIZE : " + tmpAttributeValue); - propertyImageSize.setDirect(tmpAttributeValue); - //Log.critical(" == > " + propertyImageSize); - } - tmpAttributeValue = _node.attributes["border"]; - if (tmpAttributeValue.size() != 0) { - propertyBorder.setDirect(tmpAttributeValue); - } - tmpAttributeValue = _node.attributes["smooth"]; - if (tmpAttributeValue.size() != 0) { - propertySmooth.setDirect(etk::string_to_bool(tmpAttributeValue)); - } - //Log.debug("Load label:" + node.ToElement().getText()); - if (_node.nodes.size() != 0) { - propertySource.set(_node.getText()); - } else { - tmpAttributeValue = _node.attributes["src"]; - if (tmpAttributeValue.size() != 0) { - propertySource.set(tmpAttributeValue); - } - } - return true; -} - -void ewol::widget::Image::onChangePropertySource() { - markToRedraw(); - requestUpdateSize(); - Log.verbose("Set sources : " + *propertySource + " size=" + *propertyImageSize); - this.compositing.setSource(*propertySource, propertyImageSize.getPixel()); -} - -void ewol::widget::Image::onChangePropertyImageSize() { - markToRedraw(); - requestUpdateSize(); - Log.verbose("Set sources : " + *propertySource + " size=" + *propertyImageSize); - this.compositing.setSource(*propertySource, propertyImageSize.getPixel()); -} - -void ewol::widget::Image::onChangePropertyGlobalSize() { - markToRedraw(); - requestUpdateSize(); -} - -void ewol::widget::Image::onChangePropertySmooth() { - markToRedraw(); -} - -void ewol::widget::Image::onChangePropertyDistanceFieldMode() { - this.compositing.setDistanceFieldMode(*propertyDistanceFieldMode); - markToRedraw(); -} - -void ewol::widget::Image::onChangePropertyUseThemeColor() { - markToRedraw(); -} - diff --git a/src/org/atriasoft/ewol/widget/Image.java b/src/org/atriasoft/ewol/widget/Image.java deleted file mode 100644 index 44d5a4a..0000000 --- a/src/org/atriasoft/ewol/widget/Image.java +++ /dev/null @@ -1,82 +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 -#include -#include - -namespace ewol { - namespace widget { - class Image; - using Image = ememory::Ptr; - using ImageWeak = ememory::WeakPtr; - /** - * @ingroup ewolWidgetGroup - */ - class Image :public Widget { - public: // signals - esignal::Signal<> signalPressed; - public: // properties - eproperty::Value propertySource; //!< file name of the image. - eproperty::Value propertyBorder; //!< border to add at the image. - eproperty::Value propertyImageSize; //!< border to add at the image. - eproperty::Value propertyKeepRatio; //!< keep the image ratio between width and hight - eproperty::Range propertyPosStart; //!< position in the image to start the sisplay (when we want not to display all the image) - eproperty::Range propertyPosStop; //!< position in the image to start the sisplay (when we want not to display all the image) - eproperty::Value propertyDistanceFieldMode; //!< to have a parameter - eproperty::Value propertySmooth; //!< display is done in the pixed approximation if false - eproperty::Value propertyUseThemeColor; //!< Use the themo color management ("THEME_COLOR:///Image.json?lib=ewol") default false - protected: - ewol::compositing::Image this.compositing; //!< compositing element of the image. - ememory::Ptr this.colorProperty; //!< theme color property - int this.colorId; //!< Color of the image. - public: - /** - * - */ - Image(); - void init() ; - public: - DECLARE_WIDGET_FACTORY(Image, "Image"); - /** - * - */ - ~Image(); - /** - * set All the configuration of the current image - * @param _uri URI of the new image - * @param _border New border size to set - */ - void set( etk::Uri _uri, gale::Dimension _border); - /** - * Set an image with direct elements - * @param _image Image to set in the display - */ - void setCustumSource( egami::Image _image); - protected: - Vector2f this.imageRenderSize; //!< size of the image when we render it - protected: - void onDraw() ; - public: - void calculateMinMaxSize() ; - void onRegenerateDisplay() ; - boolean onEventInput( ewol::event::Input _event) ; - boolean loadXML( exml::Element _node) ; - protected: - void onChangePropertySource(); - void onChangePropertyImageSize(); - void onChangePropertyGlobalSize(); - void onChangePropertySmooth(); - void onChangePropertyDistanceFieldMode(); - void onChangePropertyUseThemeColor(); - }; - }; -}; diff --git a/src/org/atriasoft/ewol/widget/ImageDisplay.java b/src/org/atriasoft/ewol/widget/ImageDisplay.java new file mode 100644 index 0000000..3458050 --- /dev/null +++ b/src/org/atriasoft/ewol/widget/ImageDisplay.java @@ -0,0 +1,363 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +package org.atriasoft.ewol.widget; + +import org.atriasoft.egami.Image; +import org.atriasoft.esignal.SignalEmpty; +import org.atriasoft.etk.Uri; +import org.atriasoft.etk.math.Vector2f; +import org.atriasoft.etk.math.Vector2i; +import org.atriasoft.ewol.Gravity; +import org.atriasoft.ewol.annotation.EwolDescription; +import org.atriasoft.ewol.annotation.EwolSignal; +import org.atriasoft.ewol.compositing.CompositingImage; +import org.atriasoft.ewol.event.EventInput; +import org.atriasoft.ewol.internal.Log; +import org.atriasoft.ewol.resource.ResourceColorFile; +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.key.KeyStatus; + +/** + * @ingroup ewolWidgetGroup + */ +public class ImageDisplay extends Widget { + protected int colorId = -1; //!< Color of the image. + protected ResourceColorFile colorProperty = null; //!< theme color property + protected CompositingImage compositing = new CompositingImage(); //!< compositing element of the image. + protected Vector2f imageRenderSize = Vector2f.ZERO; //!< size of the image when we render it + @XmlManaged + @XmlProperty + @XmlName(value = "border") + @EwolDescription(value = "Border of the image") + protected Dimension propertyBorder = Dimension.ZERO; //!< border to add at the image. + @XmlManaged + @XmlProperty + @XmlName(value = "size") + @EwolDescription(value = "Basic display size of the image") + protected Dimension propertyImageSize = Dimension.ZERO; //!< border to add at the image. + @XmlManaged + @XmlProperty + @XmlName(value = "ratio") + @EwolDescription(value = "Keep ratio of the image") + protected boolean propertyKeepRatio = true; //!< keep the image ratio between width and hight + @XmlManaged + @XmlProperty + @XmlName(value = "part-start") + @EwolDescription(value = "Start display position in the image") + protected Vector2f propertyPosStart = Vector2f.ZERO; //!< position in the image to start the sisplay (when we want not to display all the image) + @XmlManaged + @XmlProperty + @XmlName(value = "part-stop") + @EwolDescription(value = "Start display position in the image") + protected Vector2f propertyPosStop = Vector2f.ZERO; //!< position in the image to start the sisplay (when we want not to display all the image) + + @XmlManaged + @XmlProperty + @XmlName(value = "smooth") + @EwolDescription(value = "Smooth display of the image") + protected boolean propertySmooth = true; //!< display is done in the pixed approximation if false + @XmlManaged + @XmlProperty + @XmlName(value = "src") + @EwolDescription(value = "Image source path") + protected Uri propertySource = null; //!< file name of the image. + @XmlManaged + @XmlProperty + @XmlName(value = "use-theme-color") + @EwolDescription(value = "Use the theme color to display images") + protected boolean propertyUseThemeColor = false; //!< Use the themo color management ("THEMECOLOR:///Image.json?lib=ewol") default false + @EwolSignal(name = "pressed") + @EwolDescription(value = "Image is pressed") + public final SignalEmpty signalPressed = new SignalEmpty(); + + /** + * + */ + public ImageDisplay() {} + + @Override + public void calculateMinMaxSize() { + Log.debug("calculate min size: border=" + this.propertyBorder + " size=" + this.propertyImageSize + " min-size=" + this.propertyMinSize); + Vector2f imageBoder = this.propertyBorder.getPixel().multiply(2.0f); + Vector2f imageSize = this.propertyImageSize.getPixel(); + Vector2f size = this.propertyMinSize.getPixel(); + Log.debug(" ==> border=" + imageBoder + " size=" + imageSize + " min-size=" + size); + if (!imageSize.isZero()) { + this.minSize = imageBoder.add(imageSize); + this.maxSize = this.minSize; + } else { + Vector2i imageSizeReal = this.compositing.getRealSize(); + Log.verbose(" Real Size = " + imageSizeReal); + Vector2f min1 = imageBoder.add(this.propertyMinSize.getPixel()); + this.minSize = imageBoder.add(imageSizeReal); + Log.verbose(" set max : " + this.minSize + " min1=" + min1); + this.minSize = Vector2f.max(this.minSize, min1); + Log.verbose(" result : " + this.minSize); + this.maxSize = imageBoder.add(this.propertyMaxSize.getPixel()); + this.minSize = Vector2f.min(this.minSize, this.maxSize); + } + this.imageRenderSize = this.minSize; + this.minSize = Vector2f.max(this.minSize, size); + this.maxSize = Vector2f.max(this.maxSize, this.minSize); + Log.debug("set widget min=" + this.minSize + " max=" + this.maxSize + " with real Image size=" + this.imageRenderSize + " img size=" + imageSize + " " + this.propertyImageSize); + markToRedraw(); + } + + public Dimension getPropertyBorder() { + return this.propertyBorder; + } + + public Dimension getPropertyImageSize() { + return this.propertyImageSize; + } + + public Vector2f getPropertyPosStart() { + return this.propertyPosStart; + } + + public Vector2f getPropertyPosStop() { + return this.propertyPosStop; + } + + public Uri getPropertySource() { + return this.propertySource; + } + + public boolean isPropertyKeepRatio() { + return this.propertyKeepRatio; + } + + public boolean isPropertySmooth() { + return this.propertySmooth; + } + + public boolean isPropertyUseThemeColor() { + return this.propertyUseThemeColor; + } + + @Override + public boolean loadXML(final XmlElement node) { + if (node == null) { + return false; + } + super.loadXML(node); + // get internal data : + + String tmpAttributeValue = node.getAttribute("ratio", "").toLowerCase(); + if (tmpAttributeValue.length() != 0) { + if (tmpAttributeValue.equals("true")) { + this.propertyKeepRatio = true; + } else if (tmpAttributeValue.equals("1")) { + this.propertyKeepRatio = true; + } else { + this.propertyKeepRatio = false; + } + } + tmpAttributeValue = node.getAttribute("size", ""); + if (tmpAttributeValue.length() != 0) { + //Log.critical(" Parse SIZE : " + tmpAttributeValue); + this.propertyImageSize = Dimension.valueOf(tmpAttributeValue); + //Log.critical(" == > " + propertyImageSize); + } + tmpAttributeValue = node.getAttribute("border", ""); + if (tmpAttributeValue.length() != 0) { + this.propertyBorder = Dimension.valueOf(tmpAttributeValue); + } + tmpAttributeValue = node.getAttribute("smooth", ""); + if (tmpAttributeValue.length() != 0) { + this.propertySmooth = Boolean.parseBoolean(tmpAttributeValue); + } + //Log.debug("Load label:" + node.ToElement().getText()); + if (node.getNodes().size() != 0) { + this.propertySource = Uri.valueOf(node.getText()); + } else { + tmpAttributeValue = node.getAttribute("src", ""); + if (tmpAttributeValue.length() != 0) { + this.propertySource = Uri.valueOf(tmpAttributeValue); + } + } + return true; + } + + @Override + protected void onDraw() { + this.compositing.draw(); + } + + @Override + public boolean onEventInput(final EventInput event) { + //Log.debug("Event on BT ..."); + if (event.inputId() == 1) { + if (KeyStatus.pressSingle == event.status()) { + this.signalPressed.emit(); + return true; + } + } + return false; + } + + @Override + public void onRegenerateDisplay() { + if (!needRedraw()) { + return; + } + // remove data of the previous composition : + this.compositing.clear(); + if (this.propertyUseThemeColor && this.colorProperty != null) { + this.compositing.setColor(this.colorProperty.get(this.colorId)); + } + // Calculate the new position and size: + Vector2f imageBoder = this.propertyBorder.getPixel(); + Vector2f origin = imageBoder; + imageBoder = imageBoder.multiply(2.0f); + Vector2f imageRealSize = this.imageRenderSize.less(imageBoder); + Vector2f imageRealSizeMax = this.size.less(imageBoder); + + Vector2f ratioSizeDisplayRequested = this.propertyPosStop.less(this.propertyPosStart); + //imageRealSizeMax *= ratioSizeDisplayRequested; + + Vector2f delta = Gravity.gravityGenerateDelta(this.propertyGravity, this.size.less(this.imageRenderSize)); + if (this.propertyFill.x()) { + imageRealSize = imageRealSize.withX(imageRealSizeMax.x()); + delta = delta.withX(0.0f); + } + if (this.propertyFill.y()) { + imageRealSize = imageRealSize.withY(imageRealSizeMax.y()); + delta = delta.withY(0.0f); + } + origin = origin.add(delta); + + if (this.propertyKeepRatio) { + Vector2i tmpSize = this.compositing.getRealSize(); + //float ratio = tmpSize.x() / tmpSize.y(); + float ratio = (tmpSize.x() * ratioSizeDisplayRequested.x()) / (tmpSize.y() * ratioSizeDisplayRequested.y()); + //float ratioCurrent = (imageRealSize.x()*ratioSizeDisplayRequested.x()) / (imageRealSize.y() * ratioSizeDisplayRequested.y()); + float ratioCurrent = imageRealSize.x() / imageRealSize.y(); + if (ratio == ratioCurrent) { + // nothing to do ... + } else if (ratio < ratioCurrent) { + float oldX = imageRealSize.x(); + imageRealSize = imageRealSize.withX(imageRealSize.y() * ratio); + origin = origin.add((oldX - imageRealSize.x()) * 0.5f, 0); + } else { + float oldY = imageRealSize.y(); + imageRealSize = imageRealSize.withY(imageRealSize.x() / ratio); + origin = origin.add(0, (oldY - imageRealSize.y()) * 0.5f); + } + } + + // set the somposition properties : + if (this.propertySmooth) { + this.compositing.setPos(origin); + } else { + this.compositing.setPos(Vector2f.clipInt(origin)); + } + this.compositing.printPart(imageRealSize, this.propertyPosStart, this.propertyPosStop); + Log.debug("Paint Image at : " + origin + " size=" + imageRealSize); + Log.debug("Paint Image :" + this.propertySource + " realsize=" + this.compositing.getRealSize() + " origin=" + origin + " size=" + imageRealSize); + Log.debug(" start=" + this.propertyPosStart + " stop=" + this.propertyPosStop); + } + + /** + * set All the configuration of the current image + * @param uri URI of the new image + * @param border New border size to set + */ + public void set(final Uri uri, final Dimension border) { + Log.verbose("Set Image : " + uri + " border=" + border); + setPropertyBorder(border); + setPropertySource(uri); + } + + /** + * Set an image with direct elements + * @param image Image to set in the display + */ + public void setCustumSource(final Image image) { + // TODO : Better interfacing of all element internal ==> this is a temporary prototype + this.compositing.setSource(image); + markToRedraw(); + requestUpdateSize(); + } + + public void setPropertyBorder(final Dimension propertyBorder) { + if (this.propertyBorder.equals(propertyBorder)) { + return; + } + this.propertyBorder = propertyBorder; + markToRedraw(); + requestUpdateSize(); + } + + public void setPropertyImageSize(final Dimension propertyImageSize) { + if (this.propertyImageSize.equals(propertyImageSize)) { + return; + } + this.propertyImageSize = propertyImageSize; + markToRedraw(); + requestUpdateSize(); + Log.verbose("Set sources : " + this.propertySource + " size=" + propertyImageSize); + this.compositing.setSource(this.propertySource, propertyImageSize.getPixeli()); + } + + public void setPropertyKeepRatio(final boolean propertyKeepRatio) { + if (this.propertyKeepRatio == propertyKeepRatio) { + return; + } + this.propertyKeepRatio = propertyKeepRatio; + markToRedraw(); + requestUpdateSize(); + } + + public void setPropertyPosStart(final Vector2f propertyPosStart) { + if (this.propertyPosStart.equals(propertyPosStart)) { + return; + } + this.propertyPosStart = propertyPosStart; + markToRedraw(); + requestUpdateSize(); + } + + public void setPropertyPosStop(final Vector2f propertyPosStop) { + if (this.propertyPosStop.equals(propertyPosStop)) { + return; + } + this.propertyPosStop = propertyPosStop; + markToRedraw(); + requestUpdateSize(); + } + + public void setPropertySmooth(final boolean propertySmooth) { + if (this.propertySmooth == propertySmooth) { + return; + } + this.propertySmooth = propertySmooth; + markToRedraw(); + } + + public void setPropertySource(final Uri propertySource) { + if (this.propertySource.equals(propertySource)) { + return; + } + this.propertySource = propertySource; + markToRedraw(); + requestUpdateSize(); + Log.verbose("Set sources : " + propertySource + " size=" + this.propertyImageSize); + this.compositing.setSource(propertySource, this.propertyImageSize.getPixeli()); + } + + public void setPropertyUseThemeColor(final boolean propertyUseThemeColor) { + if (this.propertyUseThemeColor == propertyUseThemeColor) { + return; + } + this.propertyUseThemeColor = propertyUseThemeColor; + markToRedraw(); + } +} \ No newline at end of file diff --git a/src/org/atriasoft/ewol/widget/Label.cpp b/src/org/atriasoft/ewol/widget/Label.cpp deleted file mode 100644 index d056a17..0000000 --- a/src/org/atriasoft/ewol/widget/Label.cpp +++ /dev/null @@ -1,175 +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 -ETK_DECLARE_TYPE(ewol::widget::Label); - -// TODO : Remove the label name in the ructor ... -ewol::widget::Label::Label() : - signalPressed(this, "pressed", ""), - propertyAutoTranslate(this, "auto-translate", - true, - "Translate the String with the marker _{T:xxxxxx}", - ewol::widget::Label::onChangePropertyAutoTranslate), - propertyValue(this, "value", - "", - "displayed value string", - ewol::widget::Label::onChangePropertyValue), - propertyFontSize(this, "font-size", - 0, - "default font size (0=> system default)", - ewol::widget::Label::onChangePropertyFontSize), - this.value(U""), - this.colorProperty(null), - this.colorDefaultFgText(-1), - this.colorDefaultBgText(-1){ - addObjectType("ewol::widget::Label"); - this.colorProperty = ewol::resource::ColorFile::create(etk::Uri("THEME_COLOR:///Label.json?lib=ewol")); - if (this.colorProperty != null) { - this.colorDefaultFgText = this.colorProperty.request("foreground"); - this.colorDefaultBgText = this.colorProperty.request("background"); - } - setMouseLimit(1); - propertyCanFocus.setDirectCheck(false); -} - -ewol::widget::Label::~Label() { - -} - -void ewol::widget::Label::init() { - Widget::init(); - // Force update the value of internal display - onChangePropertyValue(); -} - - -void ewol::widget::Label::calculateMinMaxSize() { - Vector2f tmpMax = propertyMaxSize.getPixel(); - Vector2f tmpMin = propertyMinSize.getPixel(); - //Log.debug("[" + getId() + "] {" + getObjectType() + "} tmpMax : " + tmpMax); - if (tmpMax.x() <= 999999) { - this.text.setTextAlignement(0, tmpMax.x()-4, ewol::compositing::alignLeft); - //Log.debug("[" + getId() + "] {" + getObjectType() + "} forcez Alignement "); - } - Vector3f minSize = this.text.calculateSizeDecorated(this.value); - //Log.debug("[" + getId() + "] {" + getObjectType() + "} minSize : " + minSize); - - this.minSize.setX(etk::avg(tmpMin.x(), 4 + minSize.x(), tmpMax.x())); - this.minSize.setY(etk::avg(tmpMin.y(), 4 + minSize.y(), tmpMax.y())); - Log.verbose("[" + getId() + "] {" + getObjectType() + "} Result min size : " + tmpMin + " < " + this.minSize + " < " << tmpMax); -} - -void ewol::widget::Label::onDraw() { - this.text.draw(); -} - -void ewol::widget::Label::onRegenerateDisplay() { - if (needRedraw() == false) { - return; - } - this.text.clear(); - int paddingSize = 2; - - Vector2f tmpMax = propertyMaxSize.getPixel(); - // to know the size of one line : - Vector3f minSize = this.text.calculateSize(Character('A')); - - //minSize.setX(etk::max(minSize.x(), this.minSize.x())); - //minSize.setY(etk::max(minSize.y(), this.minSize.y())); - if (tmpMax.x() <= 999999) { - this.text.setTextAlignement(0, tmpMax.x()-2*paddingSize, ewol::compositing::alignLeft); - } - Vector3f curentTextSize = this.text.calculateSizeDecorated(this.value); - - Vector2i localSize = this.minSize; - - // no change for the text orogin : - Vector3f tmpTextOrigin((this.size.x() - this.minSize.x()) / 2.0, - (this.size.y() - this.minSize.y()) / 2.0, - 0); - - if (propertyFill.x() == true) { - localSize.setX(this.size.x()); - tmpTextOrigin.setX(0); - } - if (propertyFill.y() == true) { - localSize.setY(this.size.y()); - tmpTextOrigin.setY(this.size.y() - 2*paddingSize - curentTextSize.y()); - } - tmpTextOrigin += Vector3f(paddingSize, paddingSize, 0); - localSize -= Vector2f(2*paddingSize,2*paddingSize); - - tmpTextOrigin.setY( tmpTextOrigin.y() + (this.minSize.y()-2*paddingSize) - minSize.y()); - - Vector2f textPos(tmpTextOrigin.x(), tmpTextOrigin.y()); - - Vector3f drawClippingPos(paddingSize, paddingSize, -0.5); - Vector3f drawClippingSize((this.size.x() - paddingSize), - (this.size.y() - paddingSize), - 1); - - // clean the element - this.text.reset(); - if (propertyFontSize.get() != 0) { - this.text.setFontSize(propertyFontSize.get()); - } - if (this.colorProperty != null) { - this.text.setDefaultColorFg(this.colorProperty.get(this.colorDefaultFgText)); - this.text.setDefaultColorBg(this.colorProperty.get(this.colorDefaultBgText)); - } - this.text.setPos(tmpTextOrigin); - Log.verbose("[" + getId() + "] {" + this.value + "} display at pos : " + tmpTextOrigin); - this.text.setTextAlignement(tmpTextOrigin.x(), tmpTextOrigin.x()+localSize.x(), ewol::compositing::alignLeft); - this.text.setClipping(drawClippingPos, drawClippingSize); - this.text.printDecorated(this.value); -} - -boolean ewol::widget::Label::onEventInput( ewol::event::Input _event) { - //Log.debug("Event on Label ..."); - if (_event.getId() == 1) { - if (KeyStatus::pressSingle == _event.getStatus()) { - // nothing to do ... - signalPressed.emit(); - return true; - } - } - return false; -} - -boolean ewol::widget::Label::loadXML( exml::Element _node) { - if (_node.exist() == false) { - return false; - } - Widget::loadXML(_node); - // get internal data : - Log.debug("Load label:" + _node.getText()); - propertyValue.set(_node.getText()); - return true; -} - -void ewol::widget::Label::onChangePropertyValue() { - if (*propertyAutoTranslate == true) { - this.value = etk::toUString(etranslate::get(*propertyValue)); - } else { - this.value = etk::toUString(*propertyValue); - } - markToRedraw(); - requestUpdateSize(); -} - -void ewol::widget::Label::onChangePropertyFontSize() { - onChangePropertyValue(); -} - -void ewol::widget::Label::onChangePropertyAutoTranslate() { - onChangePropertyValue(); -} diff --git a/src/org/atriasoft/ewol/widget/Label.java b/src/org/atriasoft/ewol/widget/Label.java index daabce5..5f9c2a9 100644 --- a/src/org/atriasoft/ewol/widget/Label.java +++ b/src/org/atriasoft/ewol/widget/Label.java @@ -3,45 +3,230 @@ * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ +package org.atriasoft.ewol.widget; + +import org.atriasoft.esignal.SignalEmpty; +import org.atriasoft.etk.Uri; +import org.atriasoft.etk.math.FMath; +import org.atriasoft.etk.math.Vector2f; +import org.atriasoft.etk.math.Vector2i; +import org.atriasoft.etk.math.Vector3f; +import org.atriasoft.etranslate.ETranslate; +import org.atriasoft.ewol.annotation.EwolDescription; +import org.atriasoft.ewol.annotation.EwolSignal; +import org.atriasoft.ewol.compositing.AlignMode; +import org.atriasoft.ewol.compositing.CompositingText; +import org.atriasoft.ewol.event.EventInput; +import org.atriasoft.ewol.internal.Log; +import org.atriasoft.ewol.resource.ResourceColorFile; +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.key.KeyStatus; -/** - * @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: - /** - * Constructor - * @param _newLabel The displayed decorated text. - */ - Label(); - void init() ; - public: - DECLARE_WIDGET_FACTORY(Label, "Label"); - /** - * 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(); -}; + protected int colorDefaultBgText = -1; //!< Default Background color of the text + protected int colorDefaultFgText = -1; //!< Default color of the text + protected ResourceColorFile colorProperty; //!< theme color property + @XmlManaged + @XmlProperty + @XmlName(value = "auto-translate") + @EwolDescription(value = "Translate the String with the marker {T:xxxxxx}") + protected boolean propertyAutoTranslate = true; //!< if at true the data is translate automaticaly translate. + @XmlManaged + @XmlProperty + @XmlName(value = "font-size") + @EwolDescription(value = "Default font size (0=> system default)") + + protected int propertyFontSize = 0; //!< default size of the font. + @XmlManaged + @XmlProperty + @XmlName(value = "value") + @EwolDescription(value = "Displayed value string") + protected String propertyValue; //!< decorated text to display. + @EwolSignal(name = "pressed") + @EwolDescription(value = "Label is pressed") + public SignalEmpty signalPressed; + protected CompositingText text = new CompositingText(); //!< Compositing text element. + protected String value = ""; + + public Label() { + this.colorProperty = ResourceColorFile.create(new Uri("DATA", "/color/Label.json", "ewol")); + if (this.colorProperty != null) { + this.colorDefaultFgText = this.colorProperty.request("foreground"); + this.colorDefaultBgText = this.colorProperty.request("background"); + } + setMouseLimit(1); + setPropertyCanFocus(false); + } + + /** + * Constructor + * @param newLabel The displayed decorated text. + */ + public Label(final String newLabel) { + this.colorProperty = ResourceColorFile.create(new Uri("DATA", "/color/Label.json", "ewol")); + if (this.colorProperty != null) { + this.colorDefaultFgText = this.colorProperty.request("foreground"); + this.colorDefaultBgText = this.colorProperty.request("background"); + } + setMouseLimit(1); + setPropertyCanFocus(false); + setPropertyValue(newLabel); + } + + @Override + public void calculateMinMaxSize() { + Vector2f tmpMax = this.propertyMaxSize.getPixel(); + Vector2f tmpMin = this.propertyMinSize.getPixel(); + //Log.debug("[" + getId() + "] {" + getClass().getCanonicalName() + "} tmpMax : " + tmpMax); + if (tmpMax.x() <= 999999) { + this.text.setTextAlignment(0, tmpMax.x() - 4, AlignMode.alignLeft); + //Log.debug("[" + getId() + "] {" + getClass().getCanonicalName() + "} forcez Alignement "); + } + Vector3f minSize = this.text.calculateSizeDecorated(this.value); + //Log.debug("[" + getId() + "] {" + getClass().getCanonicalName() + "} minSize : " + minSize); + + this.minSize = new Vector2f(FMath.avg(tmpMin.x(), 4 + minSize.x(), tmpMax.x()), FMath.avg(tmpMin.y(), 4 + minSize.y(), tmpMax.y())); + Log.verbose("[" + getId() + "] {" + getClass().getCanonicalName() + "} Result min size : " + tmpMin + " < " + this.minSize + " < " + tmpMax); + } + + public int getPropertyFontSize() { + return this.propertyFontSize; + } + + public String getPropertyValue() { + return this.propertyValue; + } + + public boolean isPropertyAutoTranslate() { + return this.propertyAutoTranslate; + } + + @Override + public boolean loadXML(final XmlElement node) { + if (node == null) { + return false; + } + super.loadXML(node); + // get internal data : + Log.debug("Load label:" + node.getText()); + setPropertyValue(node.getText()); + return true; + } + + @Override + protected void onDraw() { + this.text.draw(); + } + + @Override + public boolean onEventInput(final EventInput event) { + //Log.debug("Event on Label ..."); + if (event.inputId() == 1) { + if (KeyStatus.pressSingle == event.status()) { + // nothing to do ... + this.signalPressed.emit(); + return true; + } + } + return false; + } + + @Override + public void onRegenerateDisplay() { + if (!needRedraw()) { + return; + } + this.text.clear(); + int paddingSize = 2; + + Vector2f tmpMax = this.propertyMaxSize.getPixel(); + // to know the size of one line : + Vector3f minSize = this.text.calculateSize('A'); + + //minSize.setX(etk::max(minSize.x(), this.minSize.x())); + //minSize.setY(etk::max(minSize.y(), this.minSize.y())); + if (tmpMax.x() <= 999999) { + this.text.setTextAlignment(0, tmpMax.x() - 2 * paddingSize, AlignMode.alignLeft); + } + Vector3f currentTextSize = this.text.calculateSizeDecorated(this.value); + + Vector2i localSize = new Vector2i((int) this.minSize.x(), (int) this.minSize.y()); + + // no change for the text orogin : + Vector3f tmpTextOrigin = new Vector3f((this.size.x() - this.minSize.x()) / 2.0f, (this.size.y() - this.minSize.y()) / 2.0f, 0); + + if (this.propertyFill.x()) { + localSize = localSize.withX((int) this.size.x()); + tmpTextOrigin = tmpTextOrigin.withX(0); + } + if (this.propertyFill.y()) { + localSize = localSize.withY((int) this.size.y()); + tmpTextOrigin = tmpTextOrigin.withY(this.size.y() - 2 * paddingSize - currentTextSize.y()); + } + tmpTextOrigin = tmpTextOrigin.add(paddingSize, paddingSize, 0); + localSize = localSize.less(2 * paddingSize, 2 * paddingSize); + + tmpTextOrigin = tmpTextOrigin.withY(tmpTextOrigin.y() + (this.minSize.y() - 2 * paddingSize) - minSize.y()); + + Vector2f textPos = new Vector2f(tmpTextOrigin.x(), tmpTextOrigin.y()); + + Vector3f drawClippingPos = new Vector3f(paddingSize, paddingSize, -0.5f); + Vector3f drawClippingSize = new Vector3f((this.size.x() - paddingSize), (this.size.y() - paddingSize), 1); + + // clean the element + this.text.reset(); + if (this.propertyFontSize != 0) { + this.text.setFontSize(this.propertyFontSize); + } + if (this.colorProperty != null) { + this.text.setDefaultColorFg(this.colorProperty.get(this.colorDefaultFgText)); + this.text.setDefaultColorBg(this.colorProperty.get(this.colorDefaultBgText)); + } + this.text.setPos(tmpTextOrigin); + Log.verbose("[" + getId() + "] {" + this.value + "} display at pos : " + tmpTextOrigin); + this.text.setTextAlignment(tmpTextOrigin.x(), tmpTextOrigin.x() + localSize.x(), AlignMode.alignLeft); + this.text.setClipping(drawClippingPos, drawClippingSize); + this.text.printDecorated(this.value); + } + + public void setPropertyAutoTranslate(final boolean propertyAutoTranslate) { + if (this.propertyAutoTranslate == propertyAutoTranslate) { + return; + } + this.propertyAutoTranslate = propertyAutoTranslate; + if (propertyAutoTranslate) { + this.value = ETranslate.get(this.propertyValue); + } else { + this.value = this.propertyValue; + } + markToRedraw(); + requestUpdateSize(); + } + + public void setPropertyFontSize(final int propertyFontSize) { + if (this.propertyFontSize == propertyFontSize) { + return; + } + this.propertyFontSize = propertyFontSize; + markToRedraw(); + requestUpdateSize(); + } + + public void setPropertyValue(final String propertyValue) { + if (this.propertyValue.equals(propertyValue)) { + return; + } + if (this.propertyAutoTranslate) { + this.value = ETranslate.get(propertyValue); + } else { + this.value = propertyValue; + } + markToRedraw(); + requestUpdateSize(); + this.propertyValue = propertyValue; + } + +} diff --git a/src/org/atriasoft/ewol/widget/ProgressBar.java b/src/org/atriasoft/ewol/widget/ProgressBar.java index ce13b9f..513cd8a 100644 --- a/src/org/atriasoft/ewol/widget/ProgressBar.java +++ b/src/org/atriasoft/ewol/widget/ProgressBar.java @@ -1,51 +1,76 @@ +/* + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +package org.atriasoft.ewol.widget; + 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) - */ 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() + private static final int DOT_RADIUS = 6; + private final CompositingDrawing draw = new CompositingDrawing(); // basic drawing element + @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; + @XmlManaged + @XmlProperty + @XmlName(value = "color-on") + @EwolDescription(value = "Color of the true value") + protected Color propertyTextColorBgOn = Color.GREEN; + @XmlManaged + @XmlProperty + @XmlName(value = "color-bg") + @EwolDescription(value = "ackground color") + protected Color propertyTextColorFg = Color.BLACK; + @XmlManaged + @XmlProperty + @XmlName(value = "value") + @EwolDescription(value = "Value of the progress bar [0..1]") + protected float propertyValue = 0; + public ProgressBar() { - super(); setPropertyCanFocus(true); } - private CompositingDrawing draw = new CompositingDrawing(); // basic drawing element + @Override + public void calculateMinMaxSize() { + Vector2f tmpMin = this.propertyMinSize.getPixel(); + this.minSize = new Vector2f(Math.max(tmpMin.x(), 40.0f), Math.max(tmpMin.y(), ProgressBar.DOT_RADIUS * 2.0f)); + markToRedraw(); + } + public Color getPropertyTextColorBgOff() { + return this.propertyTextColorBgOff; + } + + public Color getPropertyTextColorBgOn() { + return this.propertyTextColorBgOn; + } + + public Color getPropertyTextColorFg() { + return this.propertyTextColorFg; + } + + public float getPropertyValue() { + return this.propertyValue; + } + + @Override protected void onDraw() { this.draw.draw(); } + @Override public void onRegenerateDisplay() { if (!needRedraw()) { return; @@ -53,59 +78,33 @@ class ProgressBar extends Widget { // clean the object list ... this.draw.clear(); - this.draw.setColor(propertyTextColorFg); + this.draw.setColor(this.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.setColor(this.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)); + this.draw.rectangleWidth(new Vector3f(tmpSizeX * this.propertyValue, tmpSizeY, 0)); + this.draw.setColor(this.propertyTextColorBgOff); + this.draw.setPos(new Vector3f(tmpOriginX + tmpSizeX * this.propertyValue, tmpOriginY, 0)); + this.draw.rectangleWidth(new Vector3f(tmpSizeX * (1.0f - this.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) { + public void setPropertyTextColorBgOff(final Color propertyTextColorBgOff) { + if (propertyTextColorBgOff.equals(this.propertyTextColorBgOff)) { return; } - this.propertyValue = propertyValue; + this.propertyTextColorBgOff = propertyTextColorBgOff; 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) { + public void setPropertyTextColorBgOn(final Color propertyTextColorBgOn) { if (propertyTextColorBgOn.equals(this.propertyTextColorBgOn)) { return; } @@ -113,15 +112,19 @@ class ProgressBar extends Widget { markToRedraw(); } - public Color getPropertyTextColorBgOff() { - return propertyTextColorBgOff; - } - - public void setPropertyTextColorBgOff(Color propertyTextColorBgOff) { - if (propertyTextColorBgOff.equals(this.propertyTextColorBgOff)) { + public void setPropertyTextColorFg(final Color propertyTextColorFg) { + if (propertyTextColorFg.equals(this.propertyTextColorFg)) { return; } - this.propertyTextColorBgOff = propertyTextColorBgOff; + this.propertyTextColorFg = propertyTextColorFg; + markToRedraw(); + } + + public void setPropertyValue(final float propertyValue) { + if (propertyValue == this.propertyValue) { + return; + } + this.propertyValue = propertyValue; markToRedraw(); } } diff --git a/src/org/atriasoft/ewol/widget/Sizer.cpp b/src/org/atriasoft/ewol/widget/Sizer.cpp deleted file mode 100644 index c61880b..0000000 --- a/src/org/atriasoft/ewol/widget/Sizer.cpp +++ /dev/null @@ -1,300 +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::Sizer); -ETK_DECLARE_TYPE(enum ewol::widget::Sizer::animation); -ETK_DECLARE_TYPE(enum ewol::widget::Sizer::displayMode); -ewol::widget::Sizer::Sizer() : - propertyMode(this, "mode", - modeHori, - "The display mode", - ewol::widget::Sizer::onChangePropertyMode), - propertyBorderSize(this, "border", - Vector2f(0,0), - "The sizer border size", - ewol::widget::Sizer::onChangePropertyBorderSize), - propertyAnimation(this, "annimation", - animationNone, - "sizer annimation"), - propertyAnimationTime(this, "annimation-time", - 0, - "time of the anniation") { - addObjectType("ewol::widget::Sizer"); - propertyMode.add(modeHori, "hori"); - propertyMode.add(modeVert, "vert"); - propertyAnimation.add(animationNone, "none"); - propertyAnimation.add(animationTop, "top"); - propertyAnimation.add(animationbuttom, "buttom"); - propertyAnimation.add(animationLeft, "left"); - propertyAnimation.add(animationRight, "right"); -} - -ewol::widget::Sizer::~Sizer() { - //Log.debug("[" + getId() + "]={" + getObjectType() + "} sizer : destroy (mode=" + (propertyMode == ewol::widget::Sizer::modeVert?"Vert":"Hori") + ")"); -} - - -void ewol::widget::Sizer::onChangeSize() { - Widget::onChangeSize(); - Vector2f tmpBorderSize = propertyBorderSize.getPixel(); - Log.verbose("[" + getId() + "] update size : " + this.size + " nbElement : " + this.subWidget.size() + " borderSize=" + tmpBorderSize + " from border=" << propertyBorderSize); - Vector2f localWidgetSize = this.size - tmpBorderSize*2.0f; - // -1- calculate min-size and expand requested: - Vector2f minSize(0.0f, 0.0f); - Vector2i nbWidgetExpand(0,0); - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - Vector2f tmpSize = it.getCalculateMinSize(); - if (*propertyMode == ewol::widget::Sizer::modeVert) { - minSize = Vector2f(etk::max(minSize.x(), tmpSize.x()), - minSize.y() + tmpSize.y()); - } else { - minSize = Vector2f(minSize.x() + tmpSize.x(), - etk::max(minSize.y(), tmpSize.y())); - } - Vector2b expand = it.canExpand(); - nbWidgetExpand += Vector2i(expand.x()==true?1:0, - expand.y()==true?1:0); - } - // -2- Calculate the size to add at every elements... - float deltaExpandSize = 0.0f; - if (nbWidgetExpand != Vector2i(0,0)) { - if (*propertyMode == ewol::widget::Sizer::modeVert) { - deltaExpandSize = (localWidgetSize.y() - minSize.y()) / float(nbWidgetExpand.y()); - } else { - deltaExpandSize = (localWidgetSize.x() - minSize.x()) / float(nbWidgetExpand.x()); - } - if (deltaExpandSize<0.0) { - deltaExpandSize=0; - } - } - // -3- Configure all at the min size ... - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - it.setSize(it.getCalculateMinSize()); - } - // -4- For each element we apply the minmax range and update if needed - while (deltaExpandSize > 0.0001f) { - float residualNext = 0.0f; - // get the number of element that need to devide... - int countCalculation = nbWidgetExpand.x(); - if (*propertyMode == ewol::widget::Sizer::modeVert) { - countCalculation = nbWidgetExpand.y(); - } - // -4.1- Update every subWidget size - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - Vector2f tmpSizeMin = it.getSize(); - Vector2f tmpSizeMax = it.getCalculateMaxSize(); - // Now update his size his size in X and the curent sizer size in Y: - if (*propertyMode == ewol::widget::Sizer::modeVert) { - if (it.canExpand().y() == true) { - float sizeExpand = tmpSizeMin.y() + deltaExpandSize; - if (sizeExpand > tmpSizeMax.y()) { - residualNext += (sizeExpand - tmpSizeMax.y()); - sizeExpand = tmpSizeMax.y(); - countCalculation--; - } - tmpSizeMin.setY(sizeExpand); - } - it.setSize(tmpSizeMin); - } else { - if (it.canExpand().x() == true) { - float sizeExpand = tmpSizeMin.x() + deltaExpandSize; - if (sizeExpand > tmpSizeMax.x()) { - residualNext += (sizeExpand - tmpSizeMax.x()); - sizeExpand = tmpSizeMax.x(); - countCalculation--; - } - tmpSizeMin.setX(sizeExpand); - } - it.setSize(tmpSizeMin); - } - } - // Reset size add ... - deltaExpandSize = 0.0f; - if (residualNext < 0.0001f) { - break; - } - if (countCalculation <= 0) { - break; - } - if (*propertyMode == ewol::widget::Sizer::modeVert) { - deltaExpandSize = residualNext / float(countCalculation); - } else { - deltaExpandSize = residualNext / float(countCalculation); - } - if (deltaExpandSize < 0.0f) { - deltaExpandSize = 0.0f; - break; - } - } - // -5- Update the expand in the second size if vert ==> X and if hori ==> Y - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - // Now update his size his size in X and the curent sizer size in Y: - if (*propertyMode == ewol::widget::Sizer::modeVert) { - if (it.canExpand().x() == false) { - continue; - } - Vector2f tmpSizeMin = it.getSize(); - tmpSizeMin.setX(etk::avg(tmpSizeMin.x(), localWidgetSize.x(), it.getCalculateMaxSize().x())); - it.setSize(tmpSizeMin); - } else { - if (it.canExpand().y() == false) { - continue; - } - Vector2f tmpSizeMin = it.getSize(); - tmpSizeMin.setY(etk::avg(tmpSizeMin.y(), localWidgetSize.y(), it.getCalculateMaxSize().y())); - it.setSize(tmpSizeMin); - } - } - // -6- Force size at the entire number: - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - it.setSize(Vector2fClipInt32(it.getSize())); - } - // -7- get under Size - Vector2f underSize(0,0); - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - Vector2f size = it.getSize(); - if (*propertyMode == ewol::widget::Sizer::modeVert) { - underSize += Vector2f(0.0f, size.y()); - underSize.setX(etk::max(underSize.x(), size.x())); - } else { - underSize += Vector2f(size.x(), 0.0f); - underSize.setY(etk::max(underSize.y(), size.y())); - } - } - Vector2f deltas = localWidgetSize - underSize; - - // -8- Calculate the local origin, depending of the gravity: - Vector2f tmpOrigin = this.origin + tmpBorderSize + ewol::gravityGenerateDelta(propertyGravity, deltas); - // -9- Set sub widget origin: - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - Vector2f origin; - Vector2f size = it.getSize(); - if (*propertyMode == ewol::widget::Sizer::modeVert) { - origin = Vector2fClipInt32(tmpOrigin+this.offset + ewol::gravityGenerateDelta(propertyGravity, Vector2f(underSize.x()-size.x(),0.0f))); - } else { - origin = Vector2fClipInt32(tmpOrigin+this.offset + ewol::gravityGenerateDelta(propertyGravity, Vector2f(0.0f, underSize.y()-size.y()))); - } - it.setOrigin(origin); - if (*propertyMode == ewol::widget::Sizer::modeVert) { - tmpOrigin.setY(tmpOrigin.y() + size.y()); - } else { - tmpOrigin.setX(tmpOrigin.x() + size.x()); - } - } - // -10- Update all subSize at every element: - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - it.onChangeSize(); - } - markToRedraw(); -} - -void ewol::widget::Sizer::calculateMinMaxSize() { - Log.verbose("[" + getId() + "] update minimum size"); - this.subExpend.setValue(false, false); - this.minSize = propertyMinSize.getPixel(); - Vector2f tmpBorderSize = propertyBorderSize.getPixel(); - Log.verbose("[" + getId() + "] {" + getObjectType() + "} set min size : " + this.minSize); - for (auto it : this.subWidget) { - if (it == null) { - continue; - } - it.calculateMinMaxSize(); - if (it.canExpand().x() == true) { - this.subExpend.setX(true); - } - if (it.canExpand().y() == true) { - this.subExpend.setY(true); - } - Vector2f tmpSize = it.getCalculateMinSize(); - Log.verbose("[" + getId() + "] NewMinSize=" + tmpSize); - Log.verbose("[" + getId() + "] {" + getObjectType() + "} Get minSize="+ tmpSize); - if (*propertyMode == ewol::widget::Sizer::modeVert) { - this.minSize.setY(this.minSize.y() + tmpSize.y()); - if (tmpSize.x()>this.minSize.x()) { - this.minSize.setX(tmpSize.x()); - } - } else { - this.minSize.setX(this.minSize.x() + tmpSize.x()); - if (tmpSize.y()>this.minSize.y()) { - this.minSize.setY(tmpSize.y()); - } - } - } - this.minSize += tmpBorderSize*2; - //Log.error("[" + getId() + "] {" + getObjectType() + "} Result min size : " + this.minSize); -} - -int ewol::widget::Sizer::subWidgetAdd(Widget _newWidget) { - if (*propertyAnimation == animationNone) { - return ewol::widget::ContainerN::subWidgetAdd(_newWidget); - } - // TODO : ... - return ewol::widget::ContainerN::subWidgetAdd(_newWidget); -} - -int ewol::widget::Sizer::subWidgetAddStart(Widget _newWidget) { - if (*propertyAnimation == animationNone) { - return ewol::widget::ContainerN::subWidgetAddStart(_newWidget); - } - // TODO : ... - return ewol::widget::ContainerN::subWidgetAddStart(_newWidget); -} - -void ewol::widget::Sizer::subWidgetRemove(Widget _newWidget) { - if (*propertyAnimation == animationNone) { - ewol::widget::ContainerN::subWidgetRemove(_newWidget); - return; - } - // TODO : ... - ewol::widget::ContainerN::subWidgetRemove(_newWidget); -} - -void ewol::widget::Sizer::subWidgetUnLink(Widget _newWidget) { - if (*propertyAnimation == animationNone) { - ewol::widget::ContainerN::subWidgetUnLink(_newWidget); - return; - } - // TODO : ... - ewol::widget::ContainerN::subWidgetUnLink(_newWidget); -} - -void ewol::widget::Sizer::onChangePropertyMode() { - markToRedraw(); - requestUpdateSize(); -} - -void ewol::widget::Sizer::onChangePropertyBorderSize() { - markToRedraw(); - requestUpdateSize(); -} diff --git a/src/org/atriasoft/ewol/widget/Sizer.java b/src/org/atriasoft/ewol/widget/Sizer.java index a46e88d..ab6e941 100644 --- a/src/org/atriasoft/ewol/widget/Sizer.java +++ b/src/org/atriasoft/ewol/widget/Sizer.java @@ -1,31 +1,286 @@ -/** @file +/* * @author Edouard DUPIN * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ -/** - * @ingroup ewolWidgetGroup - */ +package org.atriasoft.ewol.widget; + +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.ewol.Gravity; +import org.atriasoft.ewol.annotation.EwolDescription; +import org.atriasoft.ewol.internal.Log; +import org.atriasoft.exml.annotation.XmlManaged; +import org.atriasoft.exml.annotation.XmlName; +import org.atriasoft.exml.annotation.XmlProperty; +import org.atriasoft.gale.Dimension; +import org.atriasoft.gale.Distance; + 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 + public enum DisplayMode { + modeHori, //!< Vertical mode + modeVert; //!< Horizontal mode + } + + @XmlManaged + @XmlProperty + @XmlName(value = "border") + @EwolDescription(value = "The sizer border size") + public Dimension propertyBorderSize = new Dimension(Vector2f.ZERO, Distance.PIXEL); //!< Border size needed for all the display + + @XmlManaged + @XmlProperty + @XmlName(value = "mode") + @EwolDescription(value = "The display mode") + public DisplayMode propertyMode = DisplayMode.modeHori; //!< Methode to display the widget list (vert/hory ...) + /** * Constructor - * @param _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(); + public Sizer() { + + } + + /** + * Constructor + * @param mode The mode to display the elements + */ + public Sizer(final DisplayMode mode) { + this.propertyMode = mode; + } + + @Override + public void calculateMinMaxSize() { + Log.verbose("[" + getId() + "] update minimum size"); + this.subExpend = Vector2b.FALSE; + this.minSize = this.propertyMinSize.getPixel(); + Vector2f tmpBorderSize = this.propertyBorderSize.getPixel(); + Log.verbose("[" + getId() + "] {" + getClass().getCanonicalName() + "} set min size : " + this.minSize); + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + it.calculateMinMaxSize(); + if (it.canExpand().x()) { + this.subExpend = this.subExpend.withX(true); + } + if (it.canExpand().y()) { + this.subExpend = this.subExpend.withY(true); + } + Vector2f tmpSize = it.getCalculateMinSize(); + Log.verbose("[" + getId() + "] NewMinSize=" + tmpSize); + Log.verbose("[" + getId() + "] {" + getClass().getCanonicalName() + "} Get minSize=" + tmpSize); + if (this.propertyMode == DisplayMode.modeVert) { + this.minSize = this.minSize.withY(this.minSize.y() + tmpSize.y()); + if (tmpSize.x() > this.minSize.x()) { + this.minSize = this.minSize.withX(tmpSize.x()); + } + } else { + this.minSize = this.minSize.withX(this.minSize.x() + tmpSize.x()); + if (tmpSize.y() > this.minSize.y()) { + this.minSize = this.minSize.withY(tmpSize.y()); + } + } + } + this.minSize = this.minSize.add(tmpBorderSize.multiply(2)); + //Log.error("[" + getId() + "] {" + getObjectType() + "} Result min size : " + this.minSize); + } + + public Dimension getPropertyBorderSize() { + return this.propertyBorderSize; + } + + public DisplayMode getPropertyMode() { + return this.propertyMode; + } + + @Override + public void onChangeSize() { + super.onChangeSize(); + Vector2f tmpBorderSize = this.propertyBorderSize.getPixel(); + Log.verbose("[" + getId() + "] update size : " + this.size + " nbElement : " + this.subWidget.size() + " borderSize=" + tmpBorderSize + " from border=" + this.propertyBorderSize); + Vector2f localWidgetSize = this.size.less(tmpBorderSize.multiply(2.0f)); + // -1- calculate min-size and expand requested: + Vector2f minSize = Vector2f.ZERO; + Vector2i nbWidgetExpand = Vector2i.ZERO; + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + Vector2f tmpSize = it.getCalculateMinSize(); + if (this.propertyMode == DisplayMode.modeVert) { + minSize = new Vector2f(Math.max(minSize.x(), tmpSize.x()), minSize.y() + tmpSize.y()); + } else { + minSize = new Vector2f(minSize.x() + tmpSize.x(), Math.max(minSize.y(), tmpSize.y())); + } + Vector2b expand = it.canExpand(); + nbWidgetExpand = nbWidgetExpand.add(expand.x() ? 1 : 0, expand.y() ? 1 : 0); + } + // -2- Calculate the size to add at every elements... + float deltaExpandSize = 0.0f; + if (!nbWidgetExpand.isEqual(Vector2i.ZERO)) { + if (this.propertyMode == DisplayMode.modeVert) { + deltaExpandSize = (localWidgetSize.y() - minSize.y()) / (nbWidgetExpand.y()); + } else { + deltaExpandSize = (localWidgetSize.x() - minSize.x()) / (nbWidgetExpand.x()); + } + if (deltaExpandSize < 0.0) { + deltaExpandSize = 0; + } + } + // -3- Configure all at the min size ... + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + it.setSize(it.getCalculateMinSize()); + } + // -4- For each element we apply the minmax range and update if needed + while (deltaExpandSize > 0.0001f) { + float residualNext = 0.0f; + // get the number of element that need to devide... + int countCalculation = nbWidgetExpand.x(); + if (this.propertyMode == DisplayMode.modeVert) { + countCalculation = nbWidgetExpand.y(); + } + // -4.1- Update every subWidget size + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + Vector2f tmpSizeMin = it.getSize(); + Vector2f tmpSizeMax = it.getCalculateMaxSize(); + // Now update his size his size in X and the curent sizer size in Y: + if (this.propertyMode == DisplayMode.modeVert) { + if (it.canExpand().y()) { + float sizeExpand = tmpSizeMin.y() + deltaExpandSize; + if (sizeExpand > tmpSizeMax.y()) { + residualNext += (sizeExpand - tmpSizeMax.y()); + sizeExpand = tmpSizeMax.y(); + countCalculation--; + } + tmpSizeMin = tmpSizeMin.withY(sizeExpand); + } + it.setSize(tmpSizeMin); + } else { + if (it.canExpand().x()) { + float sizeExpand = tmpSizeMin.x() + deltaExpandSize; + if (sizeExpand > tmpSizeMax.x()) { + residualNext += (sizeExpand - tmpSizeMax.x()); + sizeExpand = tmpSizeMax.x(); + countCalculation--; + } + tmpSizeMin = tmpSizeMin.withX(sizeExpand); + } + it.setSize(tmpSizeMin); + } + } + // Reset size add ... + deltaExpandSize = 0.0f; + if (residualNext < 0.0001f) { + break; + } + if (countCalculation <= 0) { + break; + } + if (this.propertyMode == DisplayMode.modeVert) { + deltaExpandSize = residualNext / (countCalculation); + } else { + deltaExpandSize = residualNext / (countCalculation); + } + if (deltaExpandSize < 0.0f) { + deltaExpandSize = 0.0f; + break; + } + } + // -5- Update the expand in the second size if vert ==> X and if hori ==> Y + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + // Now update his size his size in X and the curent sizer size in Y: + if (this.propertyMode == DisplayMode.modeVert) { + if (!it.canExpand().x()) { + continue; + } + Vector2f tmpSizeMin = it.getSize(); + tmpSizeMin = tmpSizeMin.withX(FMath.avg(tmpSizeMin.x(), localWidgetSize.x(), it.getCalculateMaxSize().x())); + it.setSize(tmpSizeMin); + } else { + if (!it.canExpand().y()) { + continue; + } + Vector2f tmpSizeMin = it.getSize(); + tmpSizeMin = tmpSizeMin.withY(FMath.avg(tmpSizeMin.y(), localWidgetSize.y(), it.getCalculateMaxSize().y())); + it.setSize(tmpSizeMin); + } + } + // -6- Force size at the entire number: + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + it.setSize(Vector2f.clipInt(it.getSize())); + } + // -7- get under Size + Vector2f underSize = Vector2f.ZERO; + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + Vector2f size = it.getSize(); + if (this.propertyMode == DisplayMode.modeVert) { + underSize = new Vector2f(Math.max(underSize.x(), size.x()), underSize.y() + size.y()); + } else { + underSize = new Vector2f(underSize.x() + size.x(), Math.max(underSize.y(), size.y())); + } + } + Vector2f deltas = localWidgetSize.less(underSize); + + // -8- Calculate the local origin, depending of the gravity: + Vector2f tmpOrigin = this.origin.add(tmpBorderSize).add(Gravity.gravityGenerateDelta(this.propertyGravity, deltas)); + // -9- Set sub widget origin: + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + Vector2f origin; + Vector2f size = it.getSize(); + if (this.propertyMode == DisplayMode.modeVert) { + origin = Vector2f.clipInt(tmpOrigin.add(this.offset).add(Gravity.gravityGenerateDelta(this.propertyGravity, new Vector2f(underSize.x() - size.x(), 0.0f)))); + } else { + origin = Vector2f.clipInt(tmpOrigin.add(this.offset).add(Gravity.gravityGenerateDelta(this.propertyGravity, new Vector2f(0.0f, underSize.y() - size.y())))); + } + it.setOrigin(origin); + if (this.propertyMode == DisplayMode.modeVert) { + tmpOrigin = tmpOrigin.withY(tmpOrigin.y() + size.y()); + } else { + tmpOrigin = tmpOrigin.withX(tmpOrigin.x() + size.x()); + } + } + // -10- Update all subSize at every element: + for (Widget it : this.subWidget) { + if (it == null) { + continue; + } + it.onChangeSize(); + } + markToRedraw(); + } + + public void setPropertyBorderSize(final Dimension propertyBorderSize) { + if (this.propertyBorderSize.equals(propertyBorderSize)) { + return; + } + this.propertyBorderSize = propertyBorderSize; + } + + public void setPropertyMode(final DisplayMode propertyMode) { + if (this.propertyMode.equals(propertyMode)) { + return; + } + this.propertyMode = propertyMode; + } } - diff --git a/src/org/atriasoft/ewol/widget/Spacer.java b/src/org/atriasoft/ewol/widget/Spacer.java index a07073d..32c7a9d 100644 --- a/src/org/atriasoft/ewol/widget/Spacer.java +++ b/src/org/atriasoft/ewol/widget/Spacer.java @@ -1,4 +1,5 @@ package org.atriasoft.ewol.widget; + /** @file * @author Edouard DUPIN * @copyright 2011, Edouard DUPIN, all right reserved @@ -10,7 +11,6 @@ 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; @@ -19,43 +19,50 @@ import org.atriasoft.exml.annotation.XmlProperty; * @ingroup ewolWidgetGroup */ class Spacer extends Widget { - @XmlManaged() - @XmlProperty() + private CompositingDrawing draw; //!< Compositing drawing element + @XmlManaged + @XmlProperty @XmlName(value = "color") @EwolDescription(value = "background of the spacer") protected Color propertyColor; //!< Background color + /** * Main ructer */ public Spacer() { - + } - private CompositingDrawing draw; //!< Compositing drawing element + + public Color getPropertyColor() { + return this.propertyColor; + } + + @Override + public Widget getWidgetAtPos(final Vector2f pos) { + return null; + } + + @Override + public void onDraw() { + this.draw.draw(); + } + @Override - public Widget getWidgetAtPos( Vector2f _pos) { - return null; - }; public void onRegenerateDisplay() { if (!needRedraw()) { return; } this.draw.clear(); - if (propertyColor.a() == 0) { + if (this.propertyColor.a() == 0) { return; } - this.draw.setColor(propertyColor); + this.draw.setColor(this.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; + this.draw.rectangleWidth(new Vector3f(this.size.x(), this.size.y(), 0)); } - public void setPropertyTextColorBgOn(Color propertyColor) { + public void setPropertyTextColorBgOn(final Color propertyColor) { if (propertyColor.equals(this.propertyColor)) { return; } @@ -63,4 +70,3 @@ class Spacer extends Widget { markToRedraw(); } } - diff --git a/src/org/atriasoft/ewol/widget/Widget.java b/src/org/atriasoft/ewol/widget/Widget.java index 01e236c..c7885f8 100644 --- a/src/org/atriasoft/ewol/widget/Widget.java +++ b/src/org/atriasoft/ewol/widget/Widget.java @@ -7,15 +7,24 @@ 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.*; +import org.atriasoft.etk.math.FMath; +import org.atriasoft.etk.math.Matrix4f; +import org.atriasoft.etk.math.Vector2b; +import org.atriasoft.etk.math.Vector2f; +import org.atriasoft.etk.math.Vector2i; +import org.atriasoft.etk.math.Vector3f; 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.*; +import org.atriasoft.ewol.event.EntrySystem; +import org.atriasoft.ewol.event.EventEntry; +import org.atriasoft.ewol.event.EventInput; +import org.atriasoft.ewol.event.EventShortCut; +import org.atriasoft.ewol.event.InputSystem; import org.atriasoft.ewol.internal.Log; import org.atriasoft.ewol.object.EwolObject; import org.atriasoft.exml.annotation.XmlDefaultManaged; @@ -26,11 +35,10 @@ import org.atriasoft.exml.model.XmlElement; import org.atriasoft.gale.Dimension; import org.atriasoft.gale.Distance; import org.atriasoft.gale.backend3d.OpenGL; -import org.atriasoft.gale.key.KeyKeyboard; -import org.atriasoft.gale.key.KeySpecial; import org.atriasoft.gale.context.ClipboardList; import org.atriasoft.gale.context.Cursor; - +import org.atriasoft.gale.key.KeyKeyboard; +import org.atriasoft.gale.key.KeySpecial; /** * Widget class is the main widget interface, it has so me generic properties: @@ -42,54 +50,94 @@ import org.atriasoft.gale.context.Cursor; */ @XmlDefaultManaged(value = false) public class Widget extends EwolObject { - @XmlManaged() - @XmlProperty() - @XmlName(value = "min-size") - @EwolDescription(value = "User minimum size") - protected Dimension propertyMinSize = new Dimension(new Vector2f(0, 0), Distance.PIXEL); //!< user define the minimum size of the widget + // ---------------------------------------------------------------------------------------------------------------- + // -- keyboard event properties Area + // ---------------------------------------------------------------------------------------------------------------- + private boolean allowRepeatKeyboardEvent = true; //!< This remove the repeating keybord event due to the ant pressing key. - @XmlManaged() - @XmlProperty() - @XmlName(value = "max-size") - @EwolDescription(value = "User maximum size") - protected Dimension propertyMaxSize = new Dimension(new Vector2f(999999, 999999), Distance.PIXEL); //!< user define the maximum size of the widget + private Cursor cursorDisplay = Cursor.arrow; - @XmlManaged() - @XmlProperty() - @XmlName(value = "gravity") - @EwolDescription(value = "Gravity orientation") - protected Gravity propertyGravity = Gravity.buttomLeft; //!< Gravity of the widget + // grab cursor mode + private boolean grabCursor = false; - @XmlManaged() - @XmlProperty() + // ---------------------------------------------------------------------------------------------------------------- + // -- focus Area + // ---------------------------------------------------------------------------------------------------------------- + private boolean hasFocus = false; //!< set the focus on this widget + + // ---------------------------------------------------------------------------------------------------------------- + // -- Mouse event properties Area + // ---------------------------------------------------------------------------------------------------------------- + private int limitMouseEvent = 3; //!< this is to limit the number of mouse event that the widget can supported + + private final List localShortcut = new ArrayList<>(); //!< list of all shortcut in the widget + + protected Vector2f maxSize = new Vector2f(999999, 999999); //!< internal: maximum size of the widget + + protected Vector2f minSize = new Vector2f(0, 0); //!< internal: minimum size of the widget + // ---------------------------------------------------------------------------------------------------------------- + // -- drawing : All drawing must be done in 2 separate buffer 1 for the current display and 1 for the working... + // ---------------------------------------------------------------------------------------------------------------- + protected boolean needRegenerateDisplay = true; //!< the display might be done the next regeneration + protected Vector2f offset = new Vector2f(0, 0); //!< Offset of the display in the view-port + + protected Vector2f origin = new Vector2f(0, 0); //!< internal ... I do not really known how if can use it ... + + @XmlManaged + @XmlProperty @XmlName(value = "focus") @EwolDescription(value = "enable the widget to have the focus capacity") protected boolean propertyCanFocus = false; //!< the focus can be done on this widget - @XmlManaged() - @XmlProperty() + @XmlManaged + @XmlProperty @XmlName(value = "expand") @EwolDescription(value = "Request the widget Expand size while space is available") protected Vector2b propertyExpand = new Vector2b(false, false); //!< the widget will expand if possible - @XmlManaged() - @XmlProperty() + @XmlManaged + @XmlProperty @XmlName(value = "fill") @EwolDescription(value = "Fill the widget available size") protected Vector2b propertyFill = new Vector2b(true, true); //!< the widget will fill all the space provided by the parent. - @XmlManaged() - @XmlProperty() + @XmlManaged + @XmlProperty + @XmlName(value = "gravity") + @EwolDescription(value = "Gravity orientation") + protected Gravity propertyGravity = Gravity.buttomLeft; //!< Gravity of the widget + + @XmlManaged + @XmlProperty @XmlName(value = "hide") @EwolDescription(value = "The widget start hided") protected boolean propertyHide = false; //!< hide a widget on the display + @XmlManaged + @XmlProperty + @XmlName(value = "max-size") + @EwolDescription(value = "User maximum size") + protected Dimension propertyMaxSize = new Dimension(new Vector2f(999999, 999999), Distance.PIXEL); //!< user define the maximum size of the widget + + @XmlManaged + @XmlProperty + @XmlName(value = "min-size") + @EwolDescription(value = "User minimum size") + protected Dimension propertyMinSize = new Dimension(new Vector2f(0, 0), Distance.PIXEL); //!< user define the minimum size of the widget + + // ---------------------------------------------------------------------------------------------------------------- + // -- Shortcut : management of the shortcut + // ---------------------------------------------------------------------------------------------------------------- + @EwolSignal(name = "shortcut") + public Signal signalShortcut; //!< signal handle of the message + // ---------------------------------------------------------------------------------------------------------------- // -- Widget size: // ---------------------------------------------------------------------------------------------------------------- protected Vector2f size = new Vector2f(10, 10); //!< internal: current size of the widget - protected Vector2f minSize = new Vector2f(0, 0); //!< internal: minimum size of the widget - protected Vector2f maxSize = new Vector2f(999999, 999999); //!< internal: maximum size of the widget + + // internal element calculated by the system + protected float zoom = 1.0f; //!< generic widget zoom /** * Constructor of the widget classes @@ -97,47 +145,6 @@ public class Widget extends EwolObject { */ public Widget() {} - /** - * 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.less(this.origin); - } - - /** - * Parent have set the size and the origin. The container need to update the child widget property - * @note INTERNAL EWOL SYSTEM - */ - public void onChangeSize() { - Log.verbose("[" + getId() + "] {" + getClass().getCanonicalName() + "} update size : " + this.size); - markToRedraw(); - } - - public void calculateSize() {}; - - /** - * get the widget size - * @return Requested size - * @note : INTERNAL EWOL SYSTEM - */ - public Vector2f getSize() { - if (!this.propertyHide) { - return this.size; - } - return new Vector2f(0, 0); - } - - /** - * 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 - */ - public void setSize(final Vector2f _value) { - this.size = _value; - } - /** * calculate the minimum and maximum size (need to estimate expend properties of the widget) * @note : INTERNAL EWOL SYSTEM @@ -149,136 +156,7 @@ public class Widget extends EwolObject { markToRedraw(); } - /** - * get the widget minimum size calculated - * @return Requested size - * @note : INTERNAL EWOL SYSTEM - */ - public Vector2f getCalculateMinSize() { - if (!this.propertyHide) { - return this.minSize; - } - return new Vector2f(0, 0); - } - - /** - * get the widget maximum size calculated - * @return Requested size - * @note : INTERNAL EWOL SYSTEM - */ - public Vector2f getCalculateMaxSize() { - if (!this.propertyHide) { - return this.maxSize; - } - return new Vector2f(999999, 999999); - } - - protected Vector2f offset = new Vector2f(0, 0); //!< Offset of the display in the view-port - - /** - * set the zoom property of the widget. - * @param _newVal offset value. - */ - public void setOffset(final Vector2f _newVal) { - Log.info("Set offset: " + _newVal); - if (this.offset != _newVal) { - this.offset = _newVal; - markToRedraw(); - } - } - - /** - * get the offset property of the widget. - * @return The current offset value. - */ - Vector2f getOffset() { - return this.offset; - }; - - // internal element calculated by the system - protected float zoom = 1.0f; //!< generic widget zoom - - /** - * set the zoom property of the widget - * @param _newVal newZoom value - */ - public void setZoom(final float _newVal) { - if (this.zoom == _newVal) { - return; - } - this.zoom = FMath.avg(0.0000001f, _newVal, 1000000.0f); - markToRedraw(); - } - - /** - * get the zoom property of the widget - * @return the current zoom value - */ - public float getZoom() { - return this.zoom; - } - - /** - * Change Zoom property. - * @param _range Range of the zoom change. - */ - void changeZoom(final float _range) { - - }; - - protected Vector2f origin = new Vector2f(0, 0); //!< internal ... I do not really known how if can use it ... - - /** - * Set origin at the widget (must be an parent widget that set this parameter). - * This represent the absolute origin in the program windows. - * @param _pos Position of the origin. - * @note : INTERNAL EWOL SYSTEM - */ - public void setOrigin(final Vector2f _pos) { - this.origin = _pos; - } - - /** - * Get the origin (absolute position in the windows). - * @return Coordinate of the origin requested. - */ - public Vector2f getOrigin() { - return this.origin; - } - - /** - * User set No minimum size. - */ - public void setNoMinSize() { - this.propertyMinSize.set(new Dimension(new Vector2f(0, 0), Distance.PIXEL)); - } - - /** - * 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 = Vector2f.max(this.minSize, pixelSize); - } - - /** - * User set No maximum size. - */ - public void setNoMaxSize() { - this.propertyMaxSize.set(new Dimension(new Vector2f(999999, 999999), Distance.PIXEL)); - } - - /** - * 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 = Vector2f.min(this.maxSize, pixelSize); - } + public void calculateSize() {} /** * get the expend capabilities (xy) @@ -301,10 +179,73 @@ public class Widget extends EwolObject { return this.propertyFill; } - // ---------------------------------------------------------------------------------------------------------------- - // -- focus Area - // ---------------------------------------------------------------------------------------------------------------- - private boolean hasFocus = false; //!< set the focus on this widget + /** + * Change Zoom property. + * @param range Range of the zoom change. + */ + void changeZoom(final float range) { + + } + + /** + * 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 = Vector2f.min(this.maxSize, pixelSize); + } + + /** + * 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 = Vector2f.max(this.minSize, pixelSize); + } + + public void drawWidgetTree(final int level) { + String space = ""; + for (int iii = 0; iii < level; ++iii) { + space += " "; + } + Log.print(space + "[" + getId() + "] name='" + this.name + "' type=" + getClass().getCanonicalName() + " o=" + this.origin + " s=" + this.size + " hide=" + this.propertyHide); + } + + /** + * get the widget maximum size calculated + * @return Requested size + * @note : INTERNAL EWOL SYSTEM + */ + public Vector2f getCalculateMaxSize() { + if (!this.propertyHide) { + return this.maxSize; + } + return new Vector2f(999999, 999999); + } + + /** + * get the widget minimum size calculated + * @return Requested size + * @note : INTERNAL EWOL SYSTEM + */ + public Vector2f getCalculateMinSize() { + if (!this.propertyHide) { + return this.minSize; + } + return new Vector2f(0, 0); + } + + /** + * get the current cursor. + * @return the type of the cursor. + */ + public Cursor getCursor() { + return this.cursorDisplay; + } /** * get the focus state of the widget @@ -312,39 +253,142 @@ public class Widget extends EwolObject { */ public boolean getFocus() { return this.hasFocus; - }; - - /** - * 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) { - if (!this.hasFocus) { - this.hasFocus = true; - onGetFocus(); - } - Log.verbose("set focus (stop) ret true"); - return true; - } - Log.verbose("set focus (stop) ret false"); - return false; } /** - * remove the focus on this widget - * @return return true if the widget have release his focus (if he has it) + * get the grabbing status of the cursor. + * @return true if the cursor is currently grabbed */ - public boolean rmFocus() { - if (this.propertyCanFocus) { - if (this.hasFocus) { - this.hasFocus = false; - onLostFocus(); - } - return true; + public boolean getGrabStatus() { + return this.grabCursor; + } + + /** + * get the keyboard repeating event supporting. + * @return true : the event can be repeated. + * @return false : the event must not be repeated. + */ + public boolean getKeyboardRepeat() { + return this.allowRepeatKeyboardEvent; + } + + /** + * get the number of mouse event supported + * @return return the number of event that the mouse supported [0..3] + */ + public int getMouseLimit() { + return this.limitMouseEvent; + } + + /** + * get the offset property of the widget. + * @return The current offset value. + */ + Vector2f getOffset() { + return this.offset; + } + + /** + * Get the origin (absolute position in the windows). + * @return Coordinate of the origin requested. + */ + public Vector2f getOrigin() { + return this.origin; + } + + public boolean getPropertyCanFocus() { + return this.propertyCanFocus; + } + + public Vector2b getPropertyExpand() { + return this.propertyExpand; + } + + protected Vector2b getPropertyFill() { + return this.propertyFill; + } + + protected Gravity getPropertyGravity() { + return this.propertyGravity; + } + + protected boolean getPropertyHide() { + return this.propertyHide; + } + + protected Dimension getPropertyMaxSize() { + return this.propertyMaxSize; + } + + protected Dimension getPropertyMinSize() { + return this.propertyMinSize; + } + + /** + * get the widget size + * @return Requested size + * @note : INTERNAL EWOL SYSTEM + */ + public Vector2f getSize() { + if (!this.propertyHide) { + return this.size; } - return false; + return new Vector2f(0, 0); + } + + /** + * 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) { + return this; + } + return null; + } + + /** + * Get the current Widget Manager. + */ + public WidgetManager getWidgetManager() { + return EwolObject.getContext().getWidgetManager(); + } + + /** + * Get the current Windows. + */ + public Windows getWindows() { + return EwolObject.getContext().getWindows(); + } + + /** + * get the zoom property of the widget + * @return the current zoom value + */ + public float getZoom() { + return this.zoom; + } + + /** + * 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) { + EwolObject.getContext().inputEventGrabPointer(this); + this.grabCursor = true; + } + } + + /** + * Hide the keyboard (if needed) + */ + protected void hideKeyboard() { + EwolObject.getContext().keyboardHide(); } /** @@ -354,324 +398,13 @@ public class Widget extends EwolObject { getWidgetManager().focusKeep(this); } - /** - * Event of the focus has been grabed by the current widget - */ - protected void onGetFocus() {}; - - /** - * Event of the focus has been lost by the current widget - */ - protected void onLostFocus() {}; - - // ---------------------------------------------------------------------------------------------------------------- - // -- Mouse event properties Area - // ---------------------------------------------------------------------------------------------------------------- - private int limitMouseEvent = 3; //!< this is to limit the number of mouse event that the widget can supported - - /** - * get the number of mouse event supported - * @return return the number of event that the mouse supported [0..3] - */ - public int getMouseLimit() { - return this.limitMouseEvent; - }; - - /** - * 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; - }; - - // ---------------------------------------------------------------------------------------------------------------- - // -- keyboard event properties Area - // ---------------------------------------------------------------------------------------------------------------- - private boolean allowRepeatKeyboardEvent = true; //!< This remove the repeating keybord event due to the ant pressing key. - - /** - * get the keyboard repeating event supporting. - * @return true : the event can be repeated. - * @return false : the event must not be repeated. - */ - public boolean getKeyboardRepeat() { - return this.allowRepeatKeyboardEvent; - }; - - /** - * set the keyboard repeating event supporting. - * @param _state The repeating status (true: enable, false disable). - */ - protected void setKeyboardRepeat(final boolean _state) { - this.allowRepeatKeyboardEvent = _state; - }; - - /** - * display the keyboard (if needed) - */ - protected void showKeyboard() { - getContext().keyboardShow(); + @Override + public boolean loadXML(final XmlElement node) { + super.loadXML(node); + markToRedraw(); + return true; } - /** - * Hide the keyboard (if needed) - */ - protected void hideKeyboard() { - getContext().keyboardHide(); - } - - /** - * 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) { - return this; - } - return null; - } - - // event section: - /** - * {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)) { - return true; - } - } - return onEventInput(_event.event); - } - - /** - * 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 - */ - protected boolean onEventInput(final EventInput _event) { - return false; - }; - - /** - * {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)) { - return true; - } - } - return onEventEntry(_event.event); - } - - /** - * Entry event. - * represent the physical event : - * - Keyboard (key event and move event) - * - Accelerometer - * - Joystick - * @param _event Event properties - * @return true if the event has been used - * @return false if the event has not been used - */ - protected boolean onEventEntry(final EventEntry _event) { - return false; - }; - - /** - * 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 _clipboardID Mode of data requested - */ - public void onEventClipboard(final ClipboardList _clipboardID) {}; - - // ---------------------------------------------------------------------------------------------------------------- - // -- Shortcut : management of the shortcut - // ---------------------------------------------------------------------------------------------------------------- - @EwolSignal(name = "shortcut") - public Signal signalShortcut; //!< signal handle of the message - private final List localShortcut = new ArrayList<>(); //!< list of all shortcut in the widget - - /** - * 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 ..."); - return; - } - String message; //!< data link with the event - final KeySpecial specialKey = new KeySpecial(); //!< special board key - Character unicodeValue = null; //!< 0 if not used - KeyKeyboard keyboardMoveValue = KeyKeyboard.unknow; //!< ewol::EVENT_KB_MOVE_TYPE_NONE if not used - if (_message.length() == 0) { - message = _descriptiveString; - } else { - message = _message; - } - // parsing of the string: - //"ctrl+shift+alt+metatmpElement.+s" - if (_descriptiveString.contains("ctrl")) { - specialKey.setCtrlLeft(true); - } - if (_descriptiveString.contains("shift")) { - specialKey.setShiftLeft(true); - } - if (_descriptiveString.contains("alt")) { - specialKey.setAltLeft(true); - } - if (_descriptiveString.contains("meta")) { - specialKey.setMetaLeft(true); - } - if (_descriptiveString.contains("F12")) { - keyboardMoveValue = KeyKeyboard.f12; - } else if (_descriptiveString.contains("F11")) { - keyboardMoveValue = KeyKeyboard.f11; - } else if (_descriptiveString.contains("F10")) { - keyboardMoveValue = KeyKeyboard.f10; - } else if (_descriptiveString.contains("F9")) { - keyboardMoveValue = KeyKeyboard.f9; - } else if (_descriptiveString.contains("F8")) { - keyboardMoveValue = KeyKeyboard.f8; - } else if (_descriptiveString.contains("F7")) { - keyboardMoveValue = KeyKeyboard.f7; - } else if (_descriptiveString.contains("F6")) { - keyboardMoveValue = KeyKeyboard.f6; - } else if (_descriptiveString.contains("F5")) { - keyboardMoveValue = KeyKeyboard.f5; - } else if (_descriptiveString.contains("F4")) { - keyboardMoveValue = KeyKeyboard.f4; - } else if (_descriptiveString.contains("F3")) { - keyboardMoveValue = KeyKeyboard.f3; - } else if (_descriptiveString.contains("F2")) { - keyboardMoveValue = KeyKeyboard.f2; - } else if (_descriptiveString.contains("F1")) { - keyboardMoveValue = KeyKeyboard.f1; - } else if (_descriptiveString.contains("LEFT")) { - keyboardMoveValue = KeyKeyboard.left; - } else if (_descriptiveString.contains("RIGHT")) { - keyboardMoveValue = KeyKeyboard.right; - } else if (_descriptiveString.contains("UP")) { - keyboardMoveValue = KeyKeyboard.up; - } else if (_descriptiveString.contains("DOWN")) { - keyboardMoveValue = KeyKeyboard.down; - } else if (_descriptiveString.contains("PAGE_UP")) { - keyboardMoveValue = KeyKeyboard.pageUp; - } else if (_descriptiveString.contains("PAGE_DOWN")) { - keyboardMoveValue = KeyKeyboard.pageDown; - } else if (_descriptiveString.contains("START")) { - keyboardMoveValue = KeyKeyboard.start; - } else if (_descriptiveString.contains("END")) { - keyboardMoveValue = KeyKeyboard.end; - } else if (_descriptiveString.contains("PRINT")) { - keyboardMoveValue = KeyKeyboard.print; - } else if (_descriptiveString.contains("ARRET_DEFIL")) { - keyboardMoveValue = KeyKeyboard.stopDefil; - } else if (_descriptiveString.contains("WAIT")) { - keyboardMoveValue = KeyKeyboard.wait; - } else if (_descriptiveString.contains("INSERT")) { - keyboardMoveValue = KeyKeyboard.insert; - } else if (_descriptiveString.contains("CAPLOCK")) { - keyboardMoveValue = KeyKeyboard.capLock; - } else if (_descriptiveString.contains("CONTEXT_MENU")) { - keyboardMoveValue = KeyKeyboard.contextMenu; - } else if (_descriptiveString.contains("NUM_LOCK")) { - keyboardMoveValue = KeyKeyboard.numLock; - } else { - unicodeValue = _descriptiveString.charAt(_descriptiveString.length() - 1); - } - // add it on the List ... - this.localShortcut.add(new EventShortCut(message, specialKey, unicodeValue, keyboardMoveValue, true)); - } - - /** - * remove all current shortCut - */ - protected void shortCutClean() { - this.localShortcut.clear(); - } - - /** - * remove a specific shortCut with his event name - * @param _message generated event name - */ - protected void shortCutRemove(final String _message) { - this.localShortcut.removeIf(eventShortCut -> eventShortCut.message.contentEquals(_message)); - } - - /** - * 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. - */ - public boolean onEventShortCut(final KeySpecial _special, Character _unicodeValue, final KeyKeyboard _kbMove, final boolean _isDown) { - _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) { - for (int iii = this.localShortcut.size() - 1; iii >= 0; iii--) { - if (!this.localShortcut.get(iii).isActive) { - continue; - } - if ((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)) { - // In this case we grap the event in case of an error can occured ... - this.localShortcut.get(iii).isActive = false; - Log.verbose("detect up of a shortcut"); - return true; - } - } - } - //Log.info("Try to indexOf generic shortcut ..."); - for (int iii = this.localShortcut.size() - 1; iii >= 0; iii--) { - if (this.localShortcut.get(iii).specialKey.getShift() == _special.getShift() && this.localShortcut.get(iii).specialKey.getCtrl() == _special.getCtrl() - && 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) { - this.localShortcut.get(iii).isActive = true; - Log.verbose("Generate shortCut: " + this.localShortcut.get(iii).message); - this.signalShortcut.emit(this.localShortcut.get(iii).message); - } - return true; - } - } - return false; - } - - // ---------------------------------------------------------------------------------------------------------------- - // -- drawing : All drawing must be done in 2 separate buffer 1 for the current display and 1 for the working... - // ---------------------------------------------------------------------------------------------------------------- - protected boolean needRegenerateDisplay = true; //!< the display might be done the next regeneration - /** * The widget mark itself that it need to regenerate the nest time. */ @@ -692,178 +425,235 @@ public class Widget extends EwolObject { final boolean tmpData = this.needRegenerateDisplay; this.needRegenerateDisplay = false; return tmpData; - }; + } /** - * {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 _displayProp properties of the current display - * @note : INTERNAL EWOL SYSTEM - /-. _displayProp.this.windowsSize - *------------------------------------------------------* - | | - | this.size | - | / | - | *-----------------------* | - | ' ' | - | ' _displayProp.this.size ' | - | Viewport ' / ' | - | o---------'---------o ' | - | | ' | ' | - | | ' | ' | - | | ' | ' | - | | ' | ' | - | | *-----------------------* | - | | / | | - | | this.offset | | - | | | | - | o-------------------o | - | / | - | _displayProp.this.origin | - | | - *------------------------------------------------------* - / - (0,0) - */ - public void systemDraw( final DrawProperty _displayProp){ - //Log.info("[" + getId() + "] Draw : [" + propertyName + "] t=" + getObjectType() + " o=" + this.origin + " s=" << this.size << " hide=" << propertyHide); - if (this.propertyHide){ - // widget is hidden ... - return; - } - 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() ) { - // out of the windows == > nothing to display ... - return; - } - - final DrawProperty tmpSize = _displayProp.withLimit(this.origin, this.size); - if (tmpSize.size().x() <= 0 || tmpSize.size().y() <= 0) { - return; - } - OpenGL.setViewPort( tmpSize.origin(), tmpSize.size()); - // special case, when origin < display origin, we need to cut the display : - 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 = 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.multiply(tmpScale).multiply(tmpTranslate); - - OpenGL.push(); - // set internal matrix system : - OpenGL.setMatrix(tmpMat); - //long ___startTime = ewol::getTime(); - onDraw(); - OpenGL.pop(); - } + * Parent have set the size and the origin. The container need to update the child widget property + * @note INTERNAL EWOL SYSTEM + */ + public void onChangeSize() { + Log.verbose("[" + getId() + "] {" + getClass().getCanonicalName() + "} update size : " + this.size); + markToRedraw(); + } /** * Common widget drawing function (called by the drawing thread [Android, X11, ...]) */ - protected void onDraw() {}; + protected void onDraw() {} + + /** + * 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 clipboardID Mode of data requested + */ + public void onEventClipboard(final ClipboardList clipboardID) {} + + /** + * Entry event. + * represent the physical event : + * - Keyboard (key event and move event) + * - Accelerometer + * - Joystick + * @param event Event properties + * @return true if the event has been used + * @return false if the event has not been used + */ + protected boolean onEventEntry(final EventEntry event) { + return false; + } + + /** + * 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 + */ + protected boolean onEventInput(final EventInput event) { + return false; + } + + /** + * 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::EVENTKBMOVETYPENONE. + * @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. + */ + public boolean onEventShortCut(final KeySpecial special, Character unicodeValue, final KeyKeyboard kbMove, final boolean isDown) { + 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) { + for (int iii = this.localShortcut.size() - 1; iii >= 0; iii--) { + if (!this.localShortcut.get(iii).isActive) { + continue; + } + if ((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)) { + // In this case we grap the event in case of an error can occured ... + this.localShortcut.get(iii).isActive = false; + Log.verbose("detect up of a shortcut"); + return true; + } + } + } + //Log.info("Try to indexOf generic shortcut ..."); + for (int iii = this.localShortcut.size() - 1; iii >= 0; iii--) { + if (this.localShortcut.get(iii).specialKey().getShift() == special.getShift() && this.localShortcut.get(iii).specialKey().getCtrl() == special.getCtrl() + && 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) { + this.localShortcut.get(iii).isActive = true; + Log.verbose("Generate shortCut: " + this.localShortcut.get(iii).message()); + this.signalShortcut.emit(this.localShortcut.get(iii).message()); + } + return true; + } + } + return false; + } + + /** + * Event of the focus has been grabed by the current widget + */ + protected void onGetFocus() {} + + /** + * Event of the focus has been lost by the current widget + */ + protected void onLostFocus() {} /** * Event generated when a redraw is needed */ - public void onRegenerateDisplay() {}; + public void onRegenerateDisplay() {} - // grab cursor mode - private boolean grabCursor = false; - - /** - * 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) { - getContext().inputEventGrabPointer(this); - this.grabCursor = true; + protected void onUmpdateMinMaxSize() { + final Vector2f pixelMin = this.propertyMinSize.getPixel(); + final Vector2f pixelMax = this.propertyMaxSize.getPixel(); + // check minimum maximum compatibility : + 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(); } /** - * Un-Grab the cursor (default mode cursor offset) + * Convert the absolute position in the local Position (Relative) + * @param pos Absolute position that you request conversion. + * @return The relative position. */ - public void unGrabCursor() { - if (this.grabCursor) { - getContext().inputEventUnGrabPointer(); - this.grabCursor = false; - } - } - - /** - * get the grabbing status of the cursor. - * @return true if the cursor is currently grabbed - */ - public boolean getGrabStatus() { - return this.grabCursor; - } - - private Cursor cursorDisplay = Cursor.arrow; - - /** - * set the cursor display type. - * @param _newCursor selected new cursor. - */ - public void setCursor(final Cursor _newCursor) { - Log.debug("Change Cursor in " + _newCursor); - this.cursorDisplay = _newCursor; - getContext().setCursor(this.cursorDisplay); - } - - /** - * get the current cursor. - * @return the type of the cursor. - */ - public Cursor getCursor() { - return this.cursorDisplay; - } - - public boolean loadXML( XmlElement _node){ - super.loadXML(_node); - markToRedraw(); - return true; + public Vector2f relativePosition(final Vector2f pos) { + return pos.less(this.origin); } /** * 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(); + EwolObject.getContext().requestUpdateSize(); } /** - * Get the current Widget Manager. + * remove the focus on this widget + * @return return true if the widget have release his focus (if he has it) */ - public WidgetManager getWidgetManager() { - return getContext().getWidgetManager(); + public boolean rmFocus() { + if (this.propertyCanFocus) { + if (this.hasFocus) { + this.hasFocus = false; + onLostFocus(); + } + return true; + } + return false; } /** - * Get the current Windows. + * set the cursor display type. + * @param newCursor selected new cursor. */ - public Windows getWindows() { - return getContext().getWindows(); + public void setCursor(final Cursor newCursor) { + Log.debug("Change Cursor in " + newCursor); + this.cursorDisplay = newCursor; + EwolObject.getContext().setCursor(this.cursorDisplay); } - public boolean getPropertyCanFocus() { - return this.propertyCanFocus; + /** + * 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) { + if (!this.hasFocus) { + this.hasFocus = true; + onGetFocus(); + } + Log.verbose("set focus (stop) ret true"); + return true; + } + Log.verbose("set focus (stop) ret false"); + return false; } - public void setPropertyCanFocus(boolean canFocus) { + + /** + * set the keyboard repeating event supporting. + * @param state The repeating status (true: enable, false disable). + */ + protected void setKeyboardRepeat(final boolean state) { + this.allowRepeatKeyboardEvent = state; + } + + /** + * 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; + } + + /** + * User set No maximum size. + */ + public void setNoMaxSize() { + setPropertyMaxSize(new Dimension(new Vector2f(999999, 999999), Distance.PIXEL)); + } + + /** + * User set No minimum size. + */ + public void setNoMinSize() { + setPropertyMinSize(new Dimension(new Vector2f(0, 0), Distance.PIXEL)); + } + + /** + * set the zoom property of the widget. + * @param newVal offset value. + */ + public void setOffset(final Vector2f newVal) { + Log.info("Set offset: " + newVal); + if (this.offset != newVal) { + this.offset = newVal; + markToRedraw(); + } + } + + /** + * Set origin at the widget (must be an parent widget that set this parameter). + * This represent the absolute origin in the program windows. + * @param pos Position of the origin. + * @note : INTERNAL EWOL SYSTEM + */ + public void setOrigin(final Vector2f pos) { + this.origin = pos; + } + + public void setPropertyCanFocus(final boolean canFocus) { if (this.propertyCanFocus == canFocus) { return; } @@ -876,45 +666,7 @@ public class Widget extends EwolObject { } } - protected Gravity getPropertyGravity() { - return this.propertyGravity; - } - protected void setPropertyGravity(Gravity gravity) { - if (this.propertyGravity.equals(gravity)) { - return; - } - this.propertyGravity = gravity; - markToRedraw(); - requestUpdateSize(); - } - - protected boolean getPropertyHide() { - return this.propertyHide; - } - protected void setPropertyHide(boolean value) { - if (this.propertyHide == value) { - return; - } - this.propertyHide = value; - markToRedraw(); - requestUpdateSize(); - } - - 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) { + protected void setPropertyExpand(final Vector2b value) { if (this.propertyExpand.equals(value)) { return; } @@ -923,31 +675,42 @@ public class Widget extends EwolObject { requestUpdateSize(); } - protected Dimension getPropertyMaxSize() { - return this.propertyMaxSize; + protected void setPropertyFill(final Vector2b value) { + if (this.propertyFill.equals(value)) { + return; + } + this.propertyFill = value; + markToRedraw(); + requestUpdateSize(); } - protected void setPropertyMaxSize(Dimension value) { + + protected void setPropertyGravity(final Gravity gravity) { + if (this.propertyGravity.equals(gravity)) { + return; + } + this.propertyGravity = gravity; + markToRedraw(); + requestUpdateSize(); + } + + protected void setPropertyHide(final boolean value) { + if (this.propertyHide == value) { + return; + } + this.propertyHide = value; + markToRedraw(); + requestUpdateSize(); + } + + protected void setPropertyMaxSize(final 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 : - 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 Dimension getPropertyMinSize() { - return this.propertyMinSize; - } - protected void setPropertyMinSize(Dimension value) { + protected void setPropertyMinSize(final Dimension value) { if (this.propertyMinSize.equals(value)) { return; } @@ -955,11 +718,260 @@ public class Widget extends EwolObject { onUmpdateMinMaxSize(); } - public void drawWidgetTree(final int _level) { - String space = ""; - for (int iii = 0; iii < _level; ++iii) { - space += " "; + /** + * 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 + */ + public void setSize(final Vector2f value) { + this.size = value; + } + + /** + * set the zoom property of the widget + * @param newVal newZoom value + */ + public void setZoom(final float newVal) { + if (this.zoom == newVal) { + return; + } + this.zoom = FMath.avg(0.0000001f, newVal, 1000000.0f); + markToRedraw(); + } + + /** + * 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 sendMessage) { + if (descriptiveString.length() == 0) { + Log.error("try to add shortcut with no descriptive string ..."); + return; + } + String message; //!< data link with the event + final KeySpecial specialKey = new KeySpecial(); //!< special board key + Character unicodeValue = null; //!< 0 if not used + KeyKeyboard keyboardMoveValue = KeyKeyboard.unknow; //!< ewol::EVENTKBMOVETYPENONE if not used + if (sendMessage.length() == 0) { + message = descriptiveString; + } else { + message = sendMessage; + } + // parsing of the string: + //"ctrl+shift+alt+metatmpElement.+s" + if (descriptiveString.contains("ctrl")) { + specialKey.setCtrlLeft(true); + } + if (descriptiveString.contains("shift")) { + specialKey.setShiftLeft(true); + } + if (descriptiveString.contains("alt")) { + specialKey.setAltLeft(true); + } + if (descriptiveString.contains("meta")) { + specialKey.setMetaLeft(true); + } + if (descriptiveString.contains("F12")) { + keyboardMoveValue = KeyKeyboard.f12; + } else if (descriptiveString.contains("F11")) { + keyboardMoveValue = KeyKeyboard.f11; + } else if (descriptiveString.contains("F10")) { + keyboardMoveValue = KeyKeyboard.f10; + } else if (descriptiveString.contains("F9")) { + keyboardMoveValue = KeyKeyboard.f9; + } else if (descriptiveString.contains("F8")) { + keyboardMoveValue = KeyKeyboard.f8; + } else if (descriptiveString.contains("F7")) { + keyboardMoveValue = KeyKeyboard.f7; + } else if (descriptiveString.contains("F6")) { + keyboardMoveValue = KeyKeyboard.f6; + } else if (descriptiveString.contains("F5")) { + keyboardMoveValue = KeyKeyboard.f5; + } else if (descriptiveString.contains("F4")) { + keyboardMoveValue = KeyKeyboard.f4; + } else if (descriptiveString.contains("F3")) { + keyboardMoveValue = KeyKeyboard.f3; + } else if (descriptiveString.contains("F2")) { + keyboardMoveValue = KeyKeyboard.f2; + } else if (descriptiveString.contains("F1")) { + keyboardMoveValue = KeyKeyboard.f1; + } else if (descriptiveString.contains("LEFT")) { + keyboardMoveValue = KeyKeyboard.left; + } else if (descriptiveString.contains("RIGHT")) { + keyboardMoveValue = KeyKeyboard.right; + } else if (descriptiveString.contains("UP")) { + keyboardMoveValue = KeyKeyboard.up; + } else if (descriptiveString.contains("DOWN")) { + keyboardMoveValue = KeyKeyboard.down; + } else if (descriptiveString.contains("PAGEUP")) { + keyboardMoveValue = KeyKeyboard.pageUp; + } else if (descriptiveString.contains("PAGEDOWN")) { + keyboardMoveValue = KeyKeyboard.pageDown; + } else if (descriptiveString.contains("START")) { + keyboardMoveValue = KeyKeyboard.start; + } else if (descriptiveString.contains("END")) { + keyboardMoveValue = KeyKeyboard.end; + } else if (descriptiveString.contains("PRINT")) { + keyboardMoveValue = KeyKeyboard.print; + } else if (descriptiveString.contains("ARRETDEFIL")) { + keyboardMoveValue = KeyKeyboard.stopDefil; + } else if (descriptiveString.contains("WAIT")) { + keyboardMoveValue = KeyKeyboard.wait; + } else if (descriptiveString.contains("INSERT")) { + keyboardMoveValue = KeyKeyboard.insert; + } else if (descriptiveString.contains("CAPLOCK")) { + keyboardMoveValue = KeyKeyboard.capLock; + } else if (descriptiveString.contains("CONTEXTMENU")) { + keyboardMoveValue = KeyKeyboard.contextMenu; + } else if (descriptiveString.contains("NUMLOCK")) { + keyboardMoveValue = KeyKeyboard.numLock; + } else { + unicodeValue = descriptiveString.charAt(descriptiveString.length() - 1); + } + // add it on the List ... + this.localShortcut.add(new EventShortCut(message, specialKey, unicodeValue, keyboardMoveValue, true)); + } + + /** + * remove all current shortCut + */ + protected void shortCutClean() { + this.localShortcut.clear(); + } + + /** + * remove a specific shortCut with his event name + * @param message generated event name + */ + protected void shortCutRemove(final String message) { + this.localShortcut.removeIf(eventShortCut -> eventShortCut.message().contentEquals(message)); + } + + /** + * display the keyboard (if needed) + */ + protected void showKeyboard() { + EwolObject.getContext().keyboardShow(); + } + + /** + * {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 displayProp properties of the current display + * @note : INTERNAL EWOL SYSTEM + /-. displayProp.this.windowsSize + *------------------------------------------------------* + | | + | this.size | + | / | + | *-----------------------* | + | ' ' | + | ' displayProp.this.size ' | + | Viewport ' / ' | + | o---------'---------o ' | + | | ' | ' | + | | ' | ' | + | | ' | ' | + | | ' | ' | + | | *-----------------------* | + | | / | | + | | this.offset | | + | | | | + | o-------------------o | + | / | + | displayProp.this.origin | + | | + *------------------------------------------------------* + / + (0,0) + */ + public void systemDraw(final DrawProperty displayProp) { + //Log.info("[" + getId() + "] Draw : [" + propertyName + "] t=" + getObjectType() + " o=" + this.origin + " s=" << this.size << " hide=" << propertyHide); + if (this.propertyHide) { + // widget is hidden ... + return; + } + 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()) { + // out of the windows == > nothing to display ... + return; + } + + final DrawProperty tmpSize = displayProp.withLimit(this.origin, this.size); + if (tmpSize.size().x() <= 0 || tmpSize.size().y() <= 0) { + return; + } + OpenGL.setViewPort(tmpSize.origin(), tmpSize.size()); + // special case, when origin < display origin, we need to cut the display : + 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 = 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((-tmpSize.size().x()) >> 1, (tmpSize.size().x()) >> 1, (-tmpSize.size().y()) >> 1, (tmpSize.size().y()) >> 1, (-1), (1)); + Matrix4f tmpMat = tmpProjection.multiply(tmpScale).multiply(tmpTranslate); + + OpenGL.push(); + // set internal matrix system : + OpenGL.setMatrix(tmpMat); + //long startTime = ewol::getTime(); + onDraw(); + OpenGL.pop(); + } + + /** + * {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)) { + return true; + } + } + return onEventEntry(event.event()); + } + + // event section: + /** + * {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)) { + return true; + } + } + return onEventInput(event.event()); + } + + /** + * Un-Grab the cursor (default mode cursor offset) + */ + public void unGrabCursor() { + if (this.grabCursor) { + EwolObject.getContext().inputEventUnGrabPointer(); + this.grabCursor = false; } - Log.print(space + "[" + getId() + "] name='" + this.name + "' type=" + getClass().getCanonicalName() + " o=" + this.origin + " s=" + this.size + " hide=" + this.propertyHide); } } diff --git a/src/org/atriasoft/ewol/widget/WidgetManager.java b/src/org/atriasoft/ewol/widget/WidgetManager.java index 94ce591..5360aaa 100644 --- a/src/org/atriasoft/ewol/widget/WidgetManager.java +++ b/src/org/atriasoft/ewol/widget/WidgetManager.java @@ -15,47 +15,47 @@ import org.atriasoft.exml.model.XmlElement; */ public class WidgetManager { - // --------------------------------------------- - // -- Focus area - // --------------------------------------------- - private WeakReference focusWidgetDefault; //!< default focus when no current focus is set - private WeakReference focusWidgetCurrent; //!< Current focus selected // --------------------------------------------- // -- Factory area // --------------------------------------------- private final Map> creatorList = new HashMap<>(); //!< List of factory of a widget - + private WeakReference focusWidgetCurrent; //!< Current focus selected // --------------------------------------------- - // -- Something change area (TODO: maybe set it in the windows) + // -- Focus area // --------------------------------------------- - private boolean haveRedraw = true; //!< something request a redraw + private WeakReference focusWidgetDefault; //!< default focus when no current focus is set private Runnable funcRedrawNeeded = null; + // --------------------------------------------- + // -- Something change area (TODO maybe set it in the windows) + // --------------------------------------------- + private boolean haveRedraw = true; //!< something request a redraw + /** * Create a widget with his name. - * @param _name Name of the widget to create. - * @param _node Reference on the XML node. + * @param name Name of the widget to create. + * @param node Reference on the XML node. * @return The widget created (null if it does not exist). */ - /* - public Widget create( final String _name, exml::Element _node){ - final String nameLower = _name.toLowerCase(); - final Class it = this.creatorList.get(nameLower); - if (it != null) { - try { - return it.getConstructor().newInstance(_node); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return null; + /* + public Widget create( final String name, exml::Element node){ + final String nameLower = name.toLowerCase(); + final Class it = this.creatorList.get(nameLower); + if (it != null) { + try { + return it.getConstructor().newInstance(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; } - Log.warning("try to create an UnExistant widget : " + nameLower); - return null; - } - */ - + */ + public WidgetManager() { /* this.creatorList.put("Button", Button.class); @@ -85,31 +85,31 @@ public class WidgetManager { /** * @throws Exception * add a factory of a specific widget. - * @param _name Name of the widget that is associated of the factory. - * @param _class class interface + * @param name Name of the widget that is associated of the factory. + * @param klass class interface */ - public void addWidgetCreator(final String _name, final Class _class) throws Exception { - if (_class == null) { + public void addWidgetCreator(final String name, final Class klass) throws Exception { + if (klass == null) { throw new Exception("Can not add widget creator without specified class."); } //Keep name in lower case : - final String nameLower = _name.toLowerCase(); + final String nameLower = name.toLowerCase(); final Class it = this.creatorList.get(nameLower); if (it != null) { Log.warning("Replace Creator of a specify widget : " + nameLower); return; } - this.creatorList.put(nameLower, _class); + this.creatorList.put(nameLower, klass); // TODO check constructors ... } /** * Create a widget with his name. - * @param _name Name of the widget to create. + * @param name Name of the widget to create. * @return The widget created (null if it does not exist). */ - public Widget create(final String _name) { - final String nameLower = _name.toLowerCase(); + public Widget create(final String name) { + final String nameLower = name.toLowerCase(); final Class it = this.creatorList.get(nameLower); if (it != null) { try { @@ -123,8 +123,9 @@ 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(); + + public Widget create(final String name, final XmlElement node) { + final String nameLower = name.toLowerCase(); final Class it = this.creatorList.get(nameLower); if (it != null) { try { @@ -142,12 +143,12 @@ public class WidgetManager { /** * Check if an Widget exist - * @param _name Name of the widget to check. + * @param name Name of the widget to check. * @return true The Widget exist. * @return false The Widget Does NOT exist. */ - public boolean exist(final String _name) { - return this.creatorList.get(_name.toLowerCase()) != null; + public boolean exist(final String name) { + return this.creatorList.get(name.toLowerCase()) != null; } /** @@ -160,17 +161,17 @@ public class WidgetManager { /** * Request a focus on a specify widget. - * @param _newWidget Widget that might get the focus. + * @param newWidget Widget that might get the focus. */ - public void focusKeep(final Widget _newWidget) { - if (_newWidget == null) { + public void focusKeep(final Widget newWidget) { + if (newWidget == null) { // nothing to do ... return; } - Log.debug("focusKeep=" + _newWidget.getId()); + Log.debug("focusKeep=" + newWidget.getId()); //elog::displayBacktrace(); Widget focusWidgetCurrent = this.focusWidgetCurrent.get(); - if (_newWidget == focusWidgetCurrent) { + if (newWidget == focusWidgetCurrent) { // nothing to do ... return; } @@ -179,11 +180,11 @@ public class WidgetManager { focusWidgetCurrent.rmFocus(); focusWidgetCurrent = null; } - if (!_newWidget.propertyCanFocus) { - Log.debug("Widget can not have focus, id=" + _newWidget.getId()); + if (!newWidget.propertyCanFocus) { + Log.debug("Widget can not have focus, id=" + newWidget.getId()); return; } - this.focusWidgetCurrent = new WeakReference<>(_newWidget); + this.focusWidgetCurrent = new WeakReference<>(newWidget); } /** @@ -210,11 +211,11 @@ public class WidgetManager { /** * Set the default focus when none selected. - * @param _newWidget Widget that might get the focus (when nothing else). + * @param newWidget Widget that might get the focus (when nothing else). */ - public void focusSetDefault(final Widget _newWidget) { - if ((_newWidget != null) && (!_newWidget.propertyCanFocus)) { - Log.verbose("Widget can not have focus, id=" + _newWidget.getId()); + public void focusSetDefault(final Widget newWidget) { + if ((newWidget != null) && (!newWidget.propertyCanFocus)) { + Log.verbose("Widget can not have focus, id=" + newWidget.getId()); return; } final Widget focusWidgetDefault = this.focusWidgetDefault.get(); @@ -224,13 +225,13 @@ public class WidgetManager { Log.debug("Rm focus on WidgetID=" + focusWidgetCurrent.getId()); focusWidgetCurrent.rmFocus(); } - this.focusWidgetCurrent = new WeakReference<>(_newWidget); - if (_newWidget != null) { - Log.debug("Set focus on WidgetID=" + _newWidget.getId()); - _newWidget.setFocus(); + this.focusWidgetCurrent = new WeakReference<>(newWidget); + if (newWidget != null) { + Log.debug("Set focus on WidgetID=" + newWidget.getId()); + newWidget.setFocus(); } } - this.focusWidgetDefault = new WeakReference<>(_newWidget); + this.focusWidgetDefault = new WeakReference<>(newWidget); } /** @@ -266,10 +267,10 @@ public class WidgetManager { /** * Set a callback when we need redraw the display (need by MacOs) - * @param _func function to call + * @param func function to call */ - public void setCallbackonRedrawNeeded(final Runnable _func) { - this.funcRedrawNeeded = _func; + public void setCallbackonRedrawNeeded(final Runnable func) { + this.funcRedrawNeeded = func; } } diff --git a/src/org/atriasoft/ewol/widget/Windows.cpp b/src/org/atriasoft/ewol/widget/Windows.cpp deleted file mode 100644 index 3e0190c..0000000 --- a/src/org/atriasoft/ewol/widget/Windows.cpp +++ /dev/null @@ -1,290 +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 -#include -#include -#include -ETK_DECLARE_TYPE(ewol::widget::Windows); - -ewol::widget::Windows::Windows() : - propertyColorConfiguration(this, - "file-color", - etk::Uri("THEME_COLOR:///Windows.json?lib=ewol"), - "File color of the Windows", - ewol::widget::Windows::onChangePropertyColor), - propertyTitle(this, - "title", - "No title", - "Title of the windows", - ewol::widget::Windows::onChangePropertyTitle), - this.resourceColor(null), - this.colorBg(-1) { - addObjectType("ewol::widget::Windows"); - propertyCanFocus.setDirectCheck(true); - //KeyboardShow(KEYBOARD_MODE_CODE); -} - - -void ewol::widget::Windows::init() { - Widget::init(); - onChangePropertyColor(); -} - -ewol::widget::Windows::~Windows() { - this.subWidget.reset(); - this.popUpWidgetList.clear(); -} - -void ewol::widget::Windows::onChangeSize() { - Widget::onChangeSize(); - if (this.subWidget != null) { - this.subWidget.calculateMinMaxSize(); - // TODO : do it better ... and manage gravity ... - this.subWidget.setSize(this.size); - this.subWidget.setOrigin(Vector2f(0.0f, 0.0f)); - this.subWidget.onChangeSize(); - } - for (auto it : this.popUpWidgetList) { - if(it != null) { - it.calculateMinMaxSize(); - it.setSize(this.size); - it.setOrigin(Vector2f(0.0f, 0.0f)); - it.onChangeSize(); - } - } -} - -Widget ewol::widget::Windows::getWidgetAtPos( Vector2f _pos) { - Log.verbose("Get widget at pos : " + _pos); - // calculate relative position - Vector2f relativePos = relativePosition(_pos); - // event go directly on the pop-up - if (this.popUpWidgetList.size() != 0) { - return this.popUpWidgetList.back().getWidgetAtPos(_pos); - // otherwise in the normal windows - } else if (this.subWidget != null) { - return this.subWidget.getWidgetAtPos(_pos); - } - // otherwise the event go to this widget ... - return ememory::dynamicPointerCast(sharedFromThis()); -} - -void ewol::widget::Windows::sysDraw() { - Log.verbose("Draw on " + this.size); - // set the size of the open GL system - gale::openGL::setViewPort(Vector2f(0,0), this.size); - gale::openGL::disable(gale::openGL::flag_dither); - //gale::openGL::disable(gale::openGL::flag_blend); - gale::openGL::disable(gale::openGL::flag_stencilTest); - gale::openGL::disable(gale::openGL::flag_alphaTest); - gale::openGL::disable(gale::openGL::flag_fog); - gale::openGL::disable(gale::openGL::flag_texture2D); - gale::openGL::disable(gale::openGL::flag_depthTest); - - gale::openGL::enable(gale::openGL::flag_blend); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - // clear the matrix system : - Matrix4f newOne; - gale::openGL::setBasicMatrix(newOne); - - ewol::DrawProperty displayProp; - displayProp.this.windowsSize = this.size; - displayProp.this.origin.setValue(0,0); - displayProp.this.size = this.size; - systemDraw(displayProp); - gale::openGL::disable(gale::openGL::flag_blend); - return; -} - -void ewol::widget::Windows::onRegenerateDisplay() { - if (this.subWidget != null) { - this.subWidget.onRegenerateDisplay(); - } - for (auto it : this.popUpWidgetList) { - if (it != null) { - it.onRegenerateDisplay(); - } - } -} - -//#define TEST_PERFO_WINDOWS - -void ewol::widget::Windows::systemDraw( ewol::DrawProperty _displayProp) { - Widget::systemDraw(_displayProp); - #ifdef TEST_PERFO_WINDOWS - long ___startTime0 = ewol::getTime(); - #endif - // clear the screen with transparency ... - Color colorBg(0.5, 0.5, 0.5, 0.5); - if (this.resourceColor != null) { - colorBg = this.resourceColor.get(this.colorBg); - } - gale::openGL::clearColor(colorBg); - gale::openGL::clear( uint(gale::openGL::clearFlag_colorBuffer) - | uint(gale::openGL::clearFlag_depthBuffer)); - #ifdef TEST_PERFO_WINDOWS - float ___localTime0 = (float)(ewol::getTime() - ___startTime0) / 1000.0f; - Log.error(" Windows000 : " + ___localTime0 + "ms "); - long ___startTime1 = ewol::getTime(); - #endif - //Log.warning(" WINDOWS draw on " + this.currentDrawId); - // first display the windows on the display - if (this.subWidget != null) { - this.subWidget.systemDraw(_displayProp); - //Log.debug("Draw Windows"); - } - #ifdef TEST_PERFO_WINDOWS - float ___localTime1 = (float)(ewol::getTime() - ___startTime1) / 1000.0f; - Log.error(" Windows111 : " + ___localTime1 + "ms "); - long ___startTime2 = ewol::getTime(); - #endif - // second display the pop-up - for (auto it : this.popUpWidgetList) { - if (it != null) { - it.systemDraw(_displayProp); - //Log.debug("Draw Pop-up"); - } - } - #ifdef TEST_PERFO_WINDOWS - float ___localTime2 = (float)(ewol::getTime() - ___startTime2) / 1000.0f; - Log.error(" Windows222 : " + ___localTime2 + "ms "); - #endif -} - -void ewol::widget::Windows::setSubWidget(Widget _widget) { - if (this.subWidget != null) { - Log.info("Remove current main windows Widget..."); - this.subWidget.removeParent(); - this.subWidget.reset(); - } - if (_widget != null) { - this.subWidget = _widget; - this.subWidget.setParent(sharedFromThis()); - } - - // Regenerate the size calculation : - onChangeSize(); -} - -void ewol::widget::Windows::popUpWidgetPush(Widget _widget) { - if (_widget == null) { - // nothing to do an error appear : - Log.error("can not set widget pop-up (null pointer)"); - return; - } - this.popUpWidgetList.pushBack(_widget); - _widget.setParent(sharedFromThis()); - // force the focus on the basic widget ==> this remove many time the virual keyboard area - _widget.keepFocus(); - // Regenerate the size calculation : - onChangeSize(); - // TODO : it is dangerous to access directly to the system ... - getContext().resetIOEvent(); -} - -void ewol::widget::Windows::popUpWidgetPop() { - if (this.popUpWidgetList.size() == 0) { - return; - } - this.popUpWidgetList.popBack(); -} - -void ewol::widget::Windows::onChangePropertyColor() { - this.resourceColor = ewol::resource::ColorFile::create(*propertyColorConfiguration); - if (this.resourceColor != null) { - this.colorBg = this.resourceColor.request("background"); - } else { - Log.warning("Can not open the default color configuration file for the windows: " + *propertyColorConfiguration); - } -} - -void ewol::widget::Windows::onChangePropertyTitle() { - EwolContext context = getContext(); - if (context.getWindows() == sharedFromThis()) { - context.setTitle(*propertyTitle); - } else { - Log.info("Set title is delayed ..."); - } -} - -void ewol::widget::Windows::requestDestroyFromChild( EwolObject _child) { - Log.verbose("A child has been removed"); - auto it = this.popUpWidgetList.begin(); - while (it != this.popUpWidgetList.end()) { - if (*it == _child) { - Log.verbose(" Find it ..."); - if (*it == null) { - this.popUpWidgetList.erase(it); - it = this.popUpWidgetList.begin(); - continue; - } - (*it).removeParent(); - (*it).reset(); - this.popUpWidgetList.erase(it); - it = this.popUpWidgetList.begin(); - markToRedraw(); - continue; - } - ++it; - } - if (this.subWidget == _child) { - Log.verbose(" Find it ... 2"); - if (this.subWidget == null) { - return; - } - this.subWidget.removeParent(); - this.subWidget.reset(); - markToRedraw(); - } -} - -EwolObject ewol::widget::Windows::getSubObjectNamed( String _objectName) { - EwolObject tmpObject = Widget::getSubObjectNamed(_objectName); - if (tmpObject != null) { - return tmpObject; - } - // check direct subwidget - if (this.subWidget != null) { - tmpObject = this.subWidget.getSubObjectNamed(_objectName); - if (tmpObject != null) { - return tmpObject; - } - } - // get all subwidget "pop-up" - for (auto it : this.popUpWidgetList) { - if (it != null) { - tmpObject = it.getSubObjectNamed(_objectName); - if (tmpObject != null) { - return tmpObject; - } - } - } - // not find ... - return null; -} - -void ewol::widget::Windows::drawWidgetTree(int _level) { - Widget::drawWidgetTree(_level); - _level++; - if (this.subWidget != null) { - this.subWidget.drawWidgetTree(_level); - } - for (auto it: this.popUpWidgetList) { - if (it != null) { - it.drawWidgetTree(_level); - } - } -} - diff --git a/src/org/atriasoft/ewol/widget/Windows.java b/src/org/atriasoft/ewol/widget/Windows.java index 118cde3..fa10b04 100644 --- a/src/org/atriasoft/ewol/widget/Windows.java +++ b/src/org/atriasoft/ewol/widget/Windows.java @@ -1,60 +1,167 @@ -package org.atriasoft.ewol.widget; - -import java.util.ArrayList; -import java.util.List; - -import org.atriasoft.etk.Uri; -import org.atriasoft.etk.math.Vector2f; -import org.atriasoft.ewol.DrawProperty; -import org.atriasoft.ewol.object.EwolObject; -import org.atriasoft.ewol.resource.ResourceColorFile; - /** @file * @author Edouard DUPIN * @copyright 2011, Edouard DUPIN, all right reserved * @license MPL v2.0 (see license file) */ +package org.atriasoft.ewol.widget; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; + +import org.atriasoft.etk.Color; +import org.atriasoft.etk.Uri; +import org.atriasoft.etk.math.Matrix4f; +import org.atriasoft.etk.math.Vector2f; +import org.atriasoft.etk.math.Vector2i; +import org.atriasoft.ewol.DrawProperty; +import org.atriasoft.ewol.annotation.EwolDescription; +import org.atriasoft.ewol.context.EwolContext; +import org.atriasoft.ewol.internal.Log; +import org.atriasoft.ewol.object.EwolObject; +import org.atriasoft.ewol.resource.ResourceColorFile; +import org.atriasoft.exml.annotation.XmlManaged; +import org.atriasoft.exml.annotation.XmlName; +import org.atriasoft.exml.annotation.XmlProperty; +import org.atriasoft.gale.backend3d.OpenGL; /** * Windows basic interface */ public class Windows extends Widget { - public Uri propertyColorConfiguration; //!< Configuration file of the windows theme - public String propertyTitle; //!< Current title of the windows - protected ResourceColorFile resourceColor; //!< theme color property (name of file in @ref propertyColorConfiguration) - protected int colorBg; //!< Default background color of the windows + protected int colorBg = -1; //!< Default background color of the windows + protected List popUpWidgetList = new ArrayList(); + @XmlManaged + @XmlProperty + @XmlName(value = "file-color") + @EwolDescription(value = "File color of the Windows") + public Uri propertyColorConfiguration = new Uri("DATA", "color/Windows.json", "ewol"); //!< Configuration file of the windows theme + @XmlManaged + @XmlProperty + @XmlName(value = "title") + @EwolDescription(value = "Title of the windows") + public String propertyTitle = "No title"; //!< Current title of the windows + + protected ResourceColorFile resourceColor = null; //!< theme color property (name of file in @ref propertyColorConfiguration) + // internal event at ewol system: protected Widget subWidget; - protected Windows(); + protected Windows() { + this.propertyCanFocus = true; + onChangePropertyColor(); + } + + //!< List of pop-up displayed + @Override + public void drawWidgetTree(int level) { + super.drawWidgetTree(level); + level++; + if (this.subWidget != null) { + this.subWidget.drawWidgetTree(level); + } + for (Widget it : this.popUpWidgetList) { + if (it != null) { + it.drawWidgetTree(level); + } + } + } + + public Uri getPropertyColorConfiguration() { + return this.propertyColorConfiguration; + } + + public String getPropertyTitle() { + return this.propertyTitle; + } @Override - public void drawWidgetTree(int _level); //!< List of pop-up displayed + public EwolObject getSubObjectNamed(final String objectName) { + EwolObject tmpObject = super.getSubObjectNamed(objectName); + if (tmpObject != null) { + return tmpObject; + } + // check direct subwidget + if (this.subWidget != null) { + tmpObject = this.subWidget.getSubObjectNamed(objectName); + if (tmpObject != null) { + return tmpObject; + } + } + // get all subwidget "pop-up" + for (Widget it : this.popUpWidgetList) { + if (it != null) { + tmpObject = it.getSubObjectNamed(objectName); + if (tmpObject != null) { + return tmpObject; + } + } + } + // not find ... + return null; + } @Override - public EwolObject getSubObjectNamed(String _objectName); + public Widget getWidgetAtPos(final Vector2f pos) { + Log.verbose("Get widget at pos : " + pos); + // calculate relative position + Vector2f relativePos = relativePosition(pos); + // event go directly on the pop-up + if (this.popUpWidgetList.size() != 0) { + return this.popUpWidgetList.get(this.popUpWidgetList.size() - 1).getWidgetAtPos(pos); + // otherwise in the normal windows + } + if (this.subWidget != null) { + return this.subWidget.getWidgetAtPos(pos); + } + // otherwise the event go to this widget ... + return this; + } - public Widget getWidgetAtPos(Vector2f _pos); - - /** - * Called when property change: Color configuration file - */ - protected void onChangePropertyColor(); - - /** - * Called when property change: Title - */ - protected void onChangePropertyTitle(); + protected void onChangePropertyColor() { + this.resourceColor = ResourceColorFile.create(this.propertyColorConfiguration); + if (this.resourceColor != null) { + this.colorBg = this.resourceColor.request("background"); + } else { + Log.warning("Can not open the default color configuration file for the windows: " + this.propertyColorConfiguration); + } + } @Override - public void onChangeSize(); + public void onChangeSize() { + super.onChangeSize(); + if (this.subWidget != null) { + this.subWidget.calculateMinMaxSize(); + // TODO : do it better ... and manage gravity ... + this.subWidget.setSize(this.size); + this.subWidget.setOrigin(Vector2f.ZERO); + this.subWidget.onChangeSize(); + } + for (Widget it : this.popUpWidgetList) { + if (it != null) { + it.calculateMinMaxSize(); + it.setSize(this.size); + it.setOrigin(Vector2f.ZERO); + it.onChangeSize(); + } + } + } @Override - public void onRegenerateDisplay(); + public void onRegenerateDisplay() { + if (this.subWidget != null) { + this.subWidget.onRegenerateDisplay(); + } + for (Widget it : this.popUpWidgetList) { + if (it != null) { + it.onRegenerateDisplay(); + } + } + } /** * Get the number of pop-up @@ -67,23 +174,146 @@ public class Windows extends Widget { /** * Remove the pop-up on top. */ - public void popUpWidgetPop(); + public void popUpWidgetPop() { + if (this.popUpWidgetList.size() == 0) { + return; + } + this.popUpWidgetList.remove(this.popUpWidgetList.size() - 1); + } /** * Add a pop-up on the Windows. - * @param _widget Widget to set on top of the pop-up. + * @param widget Widget to set on top of the pop-up. */ - public void popUpWidgetPush(Widget _widget); + public void popUpWidgetPush(final Widget widget) { + if (widget == null) { + // nothing to do an error appear : + Log.error("can not set widget pop-up (null pointer)"); + return; + } + this.popUpWidgetList.add(widget); + widget.setParent(this); + // force the focus on the basic widget ==> this remove many time the virual keyboard area + widget.keepFocus(); + // Regenerate the size calculation : + onChangeSize(); + // TODO : it is dangerous to access directly to the system ... + EwolObject.getContext().resetIOEvent(); + } - public void requestDestroyFromChild(EwolObject _child); //!< main sub-widget of the Windows. + //!< main sub-widget of the Windows. + @Override + public void requestDestroyFromChild(final EwolObject child) { + Log.verbose("A child has been removed"); + ListIterator it = this.popUpWidgetList.listIterator(); + while (it.hasNext()) { + Widget elem = it.next(); + if (elem == child) { + Log.verbose(" Find it ..."); + if (elem != null) { + elem.removeParent(); + } + it.remove(); + it = this.popUpWidgetList.listIterator(); + markToRedraw(); + } + } + if (this.subWidget == child) { + Log.verbose(" Find it ... 2"); + if (this.subWidget == null) { + return; + } + this.subWidget.removeParent(); + this.subWidget = null; + markToRedraw(); + } + } + + public void setPropertyColorConfiguration(final Uri propertyColorConfiguration) { + if (this.propertyColorConfiguration.equals(propertyColorConfiguration)) { + return; + } + this.propertyColorConfiguration = propertyColorConfiguration; + onChangePropertyColor(); + } + + public void setPropertyTitle(final String propertyTitle) { + if (this.propertyTitle.contentEquals(propertyTitle)) { + return; + } + this.propertyTitle = propertyTitle; + EwolContext context = EwolObject.getContext(); + if (context.getWindows() == this) { + context.setTitle(propertyTitle); + } else { + Log.info("Set title is delayed ..."); + } + } /** * Set the main widget of the application. - * @param _widget Widget to set in the windows. + * @param widget Widget to set in the windows. */ - public void setSubWidget(Widget _widget); + public void setSubWidget(final Widget widget) { + if (this.subWidget != null) { + Log.info("Remove current main windows Widget..."); + this.subWidget.removeParent(); + this.subWidget = null; + } + if (widget != null) { + this.subWidget = widget; + this.subWidget.setParent(this); + } + // Regenerate the size calculation : + onChangeSize(); + } - public void sysDraw(); + public void sysDraw() { + Log.verbose("Draw on " + this.size); + // set the size of the open GL system + OpenGL.setViewPort(Vector2f.ZERO, this.size); + OpenGL.disable(OpenGL.Flag.flag_dither); + //OpenGL.disable(OpenGL.Flag.flagblend); + OpenGL.disable(OpenGL.Flag.flag_stencilTest); + OpenGL.disable(OpenGL.Flag.flag_alphaTest); + OpenGL.disable(OpenGL.Flag.flag_fog); + OpenGL.disable(OpenGL.Flag.flag_texture2D); + OpenGL.disable(OpenGL.Flag.flag_depthTest); + + OpenGL.enable(OpenGL.Flag.flag_blend); + OpenGL.blendFuncAuto(); + + // clear the matrix system : + OpenGL.setBasicMatrix(Matrix4f.IDENTITY); + Vector2i tmpSize = new Vector2i((int) this.size.x(), (int) this.size.y()); + DrawProperty displayProp = new DrawProperty(tmpSize, Vector2i.ZERO, tmpSize); + systemDraw(displayProp); + OpenGL.disable(OpenGL.Flag.flag_blend); + } - protected void systemDraw(DrawProperty _displayProp); + @Override + public void systemDraw(final DrawProperty displayProp) { + super.systemDraw(displayProp); + // clear the screen with transparency ... + Color colorBg = Color.GRAY; + if (this.resourceColor != null) { + colorBg = this.resourceColor.get(this.colorBg); + } + OpenGL.clearColor(colorBg); + OpenGL.clear(OpenGL.ClearFlag.clearFlag_colorBuffer); + OpenGL.clear(OpenGL.ClearFlag.clearFlag_depthBuffer); + //Log.warning(" WINDOWS draw on " + this.currentDrawId); + // first display the windows on the display + if (this.subWidget != null) { + this.subWidget.systemDraw(displayProp); + //Log.debug("Draw Windows"); + } + // second display the pop-up + for (Widget it : this.popUpWidgetList) { + if (it != null) { + it.systemDraw(displayProp); + //Log.debug("Draw Pop-up"); + } + } + } }