├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── build.gradle ├── common └── src │ ├── main │ ├── java │ │ └── net │ │ │ └── voxelindustry │ │ │ └── brokkgui │ │ │ ├── BrokkGuiPlatform.java │ │ │ ├── GuiFocusManager.java │ │ │ ├── animation │ │ │ ├── Animation.java │ │ │ ├── AnimationStatus.java │ │ │ ├── ITickSender.java │ │ │ ├── ITicking.java │ │ │ ├── Interpolator.java │ │ │ ├── Interpolators.java │ │ │ └── transition │ │ │ │ ├── FadeTransition.java │ │ │ │ ├── RotateTransition.java │ │ │ │ ├── ScaleTransition.java │ │ │ │ ├── SequentialTransition.java │ │ │ │ ├── SizeTransition.java │ │ │ │ ├── Transition.java │ │ │ │ ├── TranslateTransition.java │ │ │ │ └── WaitTransition.java │ │ │ ├── behavior │ │ │ ├── GuiBehaviorBase.java │ │ │ ├── GuiButtonBehavior.java │ │ │ ├── GuiScrollableBehavior.java │ │ │ └── IGuiBehavable.java │ │ │ ├── border │ │ │ ├── ColorBorderDrawer.java │ │ │ └── ImageBorderDrawer.java │ │ │ ├── component │ │ │ ├── GuiNode.java │ │ │ ├── IGuiPopup.java │ │ │ ├── IGuiTooltip.java │ │ │ └── ITextInput.java │ │ │ ├── control │ │ │ ├── DragHelper.java │ │ │ ├── GuiButtonBase.java │ │ │ ├── GuiElement.java │ │ │ ├── GuiFather.java │ │ │ ├── GuiLabeled.java │ │ │ └── GuiScrollableBase.java │ │ │ ├── data │ │ │ ├── Position.java │ │ │ ├── PositionType.java │ │ │ ├── RectAlignment.java │ │ │ ├── RectArea.java │ │ │ ├── RectAxis.java │ │ │ ├── RectBox.java │ │ │ ├── RectCorner.java │ │ │ ├── RectSide.java │ │ │ ├── RelativeBindingHelper.java │ │ │ ├── Resource.java │ │ │ ├── Rotation.java │ │ │ ├── RotationOrigin.java │ │ │ ├── Scale.java │ │ │ └── Vector2i.java │ │ │ ├── event │ │ │ ├── ActionEvent.java │ │ │ ├── AnimationFinishEvent.java │ │ │ ├── ClickEvent.java │ │ │ ├── CursorMoveEvent.java │ │ │ ├── DisableEvent.java │ │ │ ├── DisposeEvent.java │ │ │ ├── FocusEvent.java │ │ │ ├── GuiInputEvent.java │ │ │ ├── GuiMouseEvent.java │ │ │ ├── GuiStateEvent.java │ │ │ ├── HoverEvent.java │ │ │ ├── KeyEvent.java │ │ │ ├── LayoutEvent.java │ │ │ ├── ScrollEvent.java │ │ │ ├── SelectEvent.java │ │ │ ├── TextTypedEvent.java │ │ │ └── WindowEvent.java │ │ │ ├── gui │ │ │ ├── GuiCompositeWindow.java │ │ │ ├── IGuiSubWindow.java │ │ │ ├── IGuiWindow.java │ │ │ ├── InputType.java │ │ │ ├── ListenerPool.java │ │ │ └── SubGuiScreen.java │ │ │ ├── internal │ │ │ ├── DesktopUtils.java │ │ │ ├── EGuiRenderMode.java │ │ │ ├── IBrokkGuiImpl.java │ │ │ ├── IGuiHelper.java │ │ │ ├── IGuiRenderer.java │ │ │ ├── IKeyboardUtil.java │ │ │ ├── IMouseUtil.java │ │ │ ├── IResourceHandler.java │ │ │ ├── PopupHandler.java │ │ │ └── profiler │ │ │ │ ├── GuiProfiler.java │ │ │ │ ├── IProfiler.java │ │ │ │ └── ProfilerNoop.java │ │ │ ├── paint │ │ │ ├── Color.java │ │ │ ├── Color1DGradient.java │ │ │ ├── ColorConstants.java │ │ │ ├── GuiPaint.java │ │ │ ├── RenderPass.java │ │ │ └── RenderTarget.java │ │ │ ├── panel │ │ │ ├── GuiAbsolutePane.java │ │ │ ├── GuiPane.java │ │ │ └── GuiRelativePane.java │ │ │ ├── policy │ │ │ ├── GuiOverflowPolicy.java │ │ │ └── GuiScrollbarPolicy.java │ │ │ ├── shape │ │ │ ├── Circle.java │ │ │ ├── CircleShape.java │ │ │ ├── GuiShape.java │ │ │ ├── Line.java │ │ │ ├── LineShape.java │ │ │ ├── Rectangle.java │ │ │ ├── RectangleShape.java │ │ │ ├── ScissorBox.java │ │ │ ├── ShapeDefinition.java │ │ │ ├── ShapeSpriteRotationCache.java │ │ │ └── Text.java │ │ │ ├── skin │ │ │ ├── GuiBehaviorSkinBase.java │ │ │ ├── GuiLabeledSkinBase.java │ │ │ ├── GuiScrollableSkin.java │ │ │ ├── GuiSkinBase.java │ │ │ ├── IGuiSkin.java │ │ │ └── IGuiSkinnable.java │ │ │ ├── sprite │ │ │ ├── RandomSpriteRotation.java │ │ │ ├── SpriteAnimation.java │ │ │ ├── SpriteAnimationInstance.java │ │ │ ├── SpriteAnimationParser.java │ │ │ ├── SpriteBackgroundDrawer.java │ │ │ ├── SpriteRepeat.java │ │ │ ├── SpriteRotation.java │ │ │ └── Texture.java │ │ │ ├── style │ │ │ ├── adapter │ │ │ │ ├── BackgroundRepeatStyleTranslator.java │ │ │ │ ├── ColorStyleTranslator.java │ │ │ │ ├── RandomSpriteRotationStyleTranslator.java │ │ │ │ ├── RectAlignmentStyleTranslator.java │ │ │ │ ├── RectBoxTranslator.java │ │ │ │ ├── ResourceStyleTranslator.java │ │ │ │ ├── StyleEngine.java │ │ │ │ └── TextureStyleTranslator.java │ │ │ └── optional │ │ │ │ ├── BorderImageProperties.java │ │ │ │ ├── BorderProperties.java │ │ │ │ ├── SpriteProperties.java │ │ │ │ └── SpriteRandomRotationProperties.java │ │ │ ├── util │ │ │ ├── ListUtil.java │ │ │ └── MathUtils.java │ │ │ └── validation │ │ │ ├── AlphaNumericTextValidator.java │ │ │ ├── AsciiPrintableTextValidator.java │ │ │ ├── BaseTextValidator.java │ │ │ ├── IDataValidator.java │ │ │ ├── ITextValidator.java │ │ │ ├── NumericTextValidator.java │ │ │ └── RequiredInputTextValidator.java │ └── resources │ │ ├── assets │ │ └── brokkgui │ │ │ └── css │ │ │ └── user_agent.css │ │ └── mcmod.info │ └── test │ ├── java │ └── net │ │ └── voxelindustry │ │ └── brokkgui │ │ ├── paint │ │ ├── Color1DGradientTest.java │ │ └── ColorTest.java │ │ ├── sprite │ │ ├── SpriteAnimationInstanceTest.java │ │ └── SpriteAnimationParserTest.java │ │ └── style │ │ ├── StyleHolderTest.java │ │ ├── StyleNodeTest.java │ │ ├── StylePropertyTest.java │ │ ├── StylesheetManagerTest.java │ │ ├── adapter │ │ ├── ColorStyleTranslatorTest.java │ │ ├── RandomSpriteRotationStyleTranslatorTest.java │ │ ├── RectBoxTranslatorTest.java │ │ └── TextureStyleTranslatorTest.java │ │ ├── parser │ │ ├── StyleSelectorParserTest.java │ │ └── StyleTranslatorTest.java │ │ ├── shorthand │ │ ├── GenericShorthandPropertyTest.java │ │ ├── ShorthandArgMappersTest.java │ │ └── ShorthandPropertyTest.java │ │ └── tree │ │ ├── StyleListTest.java │ │ ├── StyleSelectorHierarchicTest.java │ │ └── StyleSelectorTest.java │ └── resources │ └── assets │ └── brokkgui │ ├── animation │ └── sprite_animation.json │ └── css │ ├── import.css │ ├── test.css │ ├── test2.css │ ├── test_background_alias.css │ ├── test_hierarchic_border.css │ └── test_simple_border.css ├── core └── src │ ├── main │ ├── java │ │ └── net │ │ │ └── voxelindustry │ │ │ └── brokkgui │ │ │ ├── debug │ │ │ ├── DebugHierarchy.java │ │ │ ├── DebugRenderer.java │ │ │ ├── DebugWindow.java │ │ │ ├── StyleDebugPanel.java │ │ │ └── hierarchy │ │ │ │ ├── AccordionItem.java │ │ │ │ └── AccordionLayout.java │ │ │ └── gui │ │ │ └── BrokkGuiScreen.java │ └── resources │ │ └── assets │ │ └── brokkgui │ │ └── css │ │ ├── debug-window.css │ │ └── debug.css │ └── test │ └── java │ └── net │ └── voxelindustry │ └── brokkgui │ └── debug │ └── hierarchy │ └── AccordionLayoutTest.java ├── element └── src │ └── main │ └── java │ └── net │ └── voxelindustry │ └── brokkgui │ ├── behavior │ ├── GuiLinkBehavior.java │ ├── GuiListViewBehavior.java │ ├── GuiTabPaneBehavior.java │ ├── GuiTextfieldBehavior.java │ ├── GuiTextfieldCompleteBehavior.java │ └── GuiTogglableButtonBehavior.java │ ├── element │ ├── GuiLabel.java │ ├── GuiLink.java │ ├── GuiListCell.java │ ├── GuiListView.java │ ├── GuiProgressBar.java │ ├── GuiToast.java │ ├── GuiTooltip.java │ ├── IGuiTogglable.java │ ├── TabHeaderFactory.java │ ├── ToastManager.java │ ├── input │ │ ├── GuiButton.java │ │ ├── GuiCheckbox.java │ │ ├── GuiRadioButton.java │ │ ├── GuiTextfield.java │ │ ├── GuiTextfieldComplete.java │ │ ├── GuiToggleButton.java │ │ └── GuiToggleGroup.java │ └── pane │ │ ├── GuiTab.java │ │ ├── GuiTabPane.java │ │ └── ScrollPane.java │ └── skin │ ├── GuiButtonSkin.java │ ├── GuiCheckboxSkin.java │ ├── GuiListCellSkin.java │ ├── GuiListViewSkin.java │ ├── GuiProgressBarSkin.java │ ├── GuiRadioButtonSkin.java │ ├── GuiTabPaneSkin.java │ ├── GuiTextfieldCompleteSkin.java │ └── GuiTextfieldSkin.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── guidelines ├── brokkgui.importorder ├── cleanup.xml └── formatter.xml ├── immediate └── src │ └── main │ └── java │ └── net │ └── voxelindustry │ └── brokkgui │ └── immediate │ ├── BaseImmediateWindow.java │ ├── ImmediateWindow.java │ ├── InteractionResult.java │ ├── element │ ├── BoxElement.java │ ├── ButtonElement.java │ ├── ImmediateElement.java │ ├── ImmediateWindowBridge.java │ ├── TextBoxElement.java │ └── TextElement.java │ └── style │ ├── BoxStyle.java │ ├── ButtonStyle.java │ ├── EmptyBoxStyle.java │ ├── ReducedStyleList.java │ ├── StyleType.java │ ├── TextBoxStyle.java │ └── TextStyle.java ├── settings.gradle └── style └── src └── main └── java └── net └── voxelindustry └── brokkgui ├── style ├── HeldPropertyState.java ├── ICascadeStyleable.java ├── IStyleParent.java ├── IStyleRoot.java ├── IStyleable.java ├── StyleHolder.java ├── StyleProperty.java ├── StyleSource.java ├── StylesheetManager.java ├── adapter │ ├── DoubleTranslator.java │ ├── FloatTranslator.java │ ├── IStyleDecoder.java │ ├── IStyleEncoder.java │ ├── IStyleValidator.java │ └── StyleTranslator.java ├── event │ └── StyleRefreshEvent.java ├── parser │ ├── StyleSelectorParser.java │ └── StylesheetParser.java ├── selector │ ├── IStyleSelector.java │ ├── StyleSelector.java │ ├── StyleSelectorHierarchic.java │ ├── StyleSelectorType.java │ └── structural │ │ ├── StructuralSelector.java │ │ └── StructuralSelectors.java ├── shorthand │ ├── GenericShorthandProperty.java │ ├── ShorthandArgMapper.java │ ├── ShorthandArgMappers.java │ └── ShorthandProperty.java └── tree │ ├── StyleEntry.java │ ├── StyleList.java │ └── StyleRule.java └── util ├── NumberedLineIterator.java └── StringCountUtils.java /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/java,gradle,eclipse,intellij 2 | 3 | ### Java ### 4 | *.class 5 | 6 | # Mobile Tools for Java (J2ME) 7 | .mtj.tmp/ 8 | 9 | # Package Files # 10 | *.jar 11 | *.war 12 | *.ear 13 | 14 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 15 | hs_err_pid* 16 | 17 | 18 | ### Gradle ### 19 | .gradle 20 | build/ 21 | 22 | # Ignore Gradle GUI config 23 | gradle-app.setting 24 | 25 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 26 | !gradle-wrapper.jar 27 | 28 | 29 | ### Eclipse ### 30 | *.pydevproject 31 | .metadata 32 | .gradle 33 | bin/ 34 | tmp/ 35 | *.tmp 36 | *.bak 37 | *.swp 38 | *~.nib 39 | local.properties 40 | .settings/ 41 | .loadpath 42 | 43 | # Eclipse Core 44 | .project 45 | 46 | # External tool builders 47 | .externalToolBuilders/ 48 | 49 | # Locally stored "Eclipse launch configurations" 50 | *.launch 51 | 52 | # CDT-specific 53 | .cproject 54 | 55 | # JDT-specific (Eclipse Java Development Tools) 56 | .classpath 57 | 58 | # Java annotation processor (APT) 59 | .factorypath 60 | 61 | # PDT-specific 62 | .buildpath 63 | 64 | # sbteclipse plugin 65 | .target 66 | 67 | # TeXlipse plugin 68 | .texlipse 69 | 70 | 71 | ### Intellij ### 72 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio 73 | 74 | *.iml 75 | 76 | ## Directory-based project format: 77 | .idea/ 78 | # if you remove the above rule, at least ignore the following: 79 | 80 | # User-specific stuff: 81 | # .idea/workspace.xml 82 | # .idea/tasks.xml 83 | # .idea/dictionaries 84 | 85 | # Sensitive or high-churn files: 86 | # .idea/dataSources.ids 87 | # .idea/dataSources.xml 88 | # .idea/sqlDataSources.xml 89 | # .idea/dynamic.xml 90 | # .idea/uiDesigner.xml 91 | 92 | # Gradle: 93 | # .idea/gradle.xml 94 | # .idea/libraries 95 | 96 | # Mongo Explorer plugin: 97 | # .idea/mongoSettings.xml 98 | 99 | ## File-based project format: 100 | *.ipr 101 | *.iws 102 | 103 | ## Plugin-specific files: 104 | 105 | # IntelliJ 106 | /out/ 107 | core/out/ 108 | 109 | # mpeltonen/sbt-idea plugin 110 | .idea_modules/ 111 | 112 | # JIRA plugin 113 | atlassian-ide-plugin.xml 114 | 115 | # Crashlytics plugin (for Android Studio and IntelliJ) 116 | com_crashlytics_export_strings.xml 117 | crashlytics.properties 118 | crashlytics-build.properties 119 | 120 | classes/ 121 | 122 | saves/* 123 | logs/* 124 | config/* 125 | crash-reports/* 126 | asm/* 127 | run/* 128 | temporary/* 129 | options.txt 130 | usernamecache.json 131 | Thumbs.db 132 | 133 | # Minecraft 134 | 1.12/run/ 135 | 136 | 1.12/saves/* 137 | 1.12/logs/* 138 | 1.12/config/* 139 | 1.12/crash-reports/* 140 | 1.12/asm/* 141 | */run/* 142 | 143 | */out/* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | before_install: 4 | - chmod +x gradlew 5 | script: 6 | - ./gradlew build check sonarqube 7 | before_cache: 8 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock 9 | cache: 10 | - directories: 11 | - ./libs 12 | - $HOME/.gradle/caches 13 | - $HOME/.gradle/wrapper 14 | os: linux 15 | jdk: oraclejdk8 16 | global_env: TERM=dumb 17 | group: stable -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/GuiFocusManager.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | import net.voxelindustry.brokkgui.component.GuiNode; 5 | 6 | /** 7 | * @author Ourten 8 oct. 2016 8 | */ 9 | public class GuiFocusManager 10 | { 11 | private static volatile GuiFocusManager INSTANCE; 12 | 13 | public static GuiFocusManager getInstance() 14 | { 15 | if (GuiFocusManager.INSTANCE == null) 16 | synchronized (GuiFocusManager.class) 17 | { 18 | if (GuiFocusManager.INSTANCE == null) 19 | GuiFocusManager.INSTANCE = new GuiFocusManager(); 20 | } 21 | return GuiFocusManager.INSTANCE; 22 | } 23 | 24 | private final BaseProperty focusedNodeProperty; 25 | 26 | private GuiFocusManager() 27 | { 28 | this.focusedNodeProperty = new BaseProperty<>(null, "focusedNodeProperty"); 29 | } 30 | 31 | public GuiNode getFocusedNode() 32 | { 33 | return this.focusedNodeProperty.getValue(); 34 | } 35 | 36 | private void setFocusedNode(final GuiNode node) 37 | { 38 | this.focusedNodeProperty.setValue(node); 39 | } 40 | 41 | public void requestFocus(final GuiNode guiNode) 42 | { 43 | if (this.getFocusedNode() != null) 44 | this.getFocusedNode().internalSetFocused(false); 45 | this.setFocusedNode(guiNode); 46 | if (this.getFocusedNode() != null) 47 | this.getFocusedNode().internalSetFocused(true); 48 | } 49 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/AnimationStatus.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation; 2 | 3 | public enum AnimationStatus 4 | { 5 | NOT_STARTED, 6 | PAUSED, 7 | RUNNING, 8 | COMPLETED 9 | } 10 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/ITickSender.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation; 2 | 3 | public interface ITickSender 4 | { 5 | void addTicking(ITicking toTick); 6 | 7 | void removeTicking(ITicking toTick); 8 | } 9 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/ITicking.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation; 2 | 3 | public interface ITicking 4 | { 5 | void tick(long currentMillis); 6 | } 7 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/Interpolator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation; 2 | 3 | @FunctionalInterface 4 | public interface Interpolator 5 | { 6 | float apply(float delta); 7 | } 8 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/transition/FadeTransition.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation.transition; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class FadeTransition extends Transition 8 | { 9 | private Double startOpacity; 10 | private Double endOpacity; 11 | 12 | private double fromOpacity; 13 | private double opacity; 14 | 15 | public FadeTransition(GuiNode node, long duration, TimeUnit unit) 16 | { 17 | super(node, duration, unit); 18 | } 19 | 20 | @Override 21 | protected void apply(float interpolated) 22 | { 23 | if (getNode() == null) 24 | return; 25 | 26 | getNode().setOpacity(fromOpacity + (endOpacity - fromOpacity) * interpolated); 27 | } 28 | 29 | @Override 30 | public void restart() 31 | { 32 | super.restart(); 33 | 34 | if (startOpacity == null) 35 | fromOpacity = getNode().getOpacity(); 36 | else 37 | fromOpacity = startOpacity; 38 | 39 | if (endOpacity == null) 40 | endOpacity = fromOpacity + opacity; 41 | } 42 | 43 | public double getStartOpacity() 44 | { 45 | return startOpacity; 46 | } 47 | 48 | public void setStartOpacity(double startOpacity) 49 | { 50 | this.startOpacity = startOpacity; 51 | } 52 | 53 | public double getEndOpacity() 54 | { 55 | return endOpacity; 56 | } 57 | 58 | public void setEndOpacity(double endOpacity) 59 | { 60 | this.endOpacity = endOpacity; 61 | } 62 | 63 | public double getOpacity() 64 | { 65 | return opacity; 66 | } 67 | 68 | public void setOpacity(double opacity) 69 | { 70 | this.opacity = opacity; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/transition/RotateTransition.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation.transition; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class RotateTransition extends Transition 8 | { 9 | private Float startAngle; 10 | private Float endAngle; 11 | 12 | private float fromAngle; 13 | private float rotateAngle; 14 | 15 | public RotateTransition(GuiNode node, long duration, TimeUnit unit) 16 | { 17 | super(node, duration, unit); 18 | } 19 | 20 | @Override 21 | protected void apply(float interpolated) 22 | { 23 | if (getNode() == null) 24 | return; 25 | 26 | getNode().getRotation().setAngle(fromAngle + (endAngle - fromAngle) * interpolated); 27 | } 28 | 29 | @Override 30 | public void restart() 31 | { 32 | super.restart(); 33 | 34 | if (startAngle == null) 35 | fromAngle = getNode().getRotation().getAngle(); 36 | else 37 | fromAngle = startAngle; 38 | 39 | if (endAngle == null) 40 | endAngle = fromAngle + rotateAngle; 41 | } 42 | 43 | public Float getStartAngle() 44 | { 45 | return startAngle; 46 | } 47 | 48 | public void setStartAngle(Float startAngle) 49 | { 50 | this.startAngle = startAngle; 51 | } 52 | 53 | public Float getEndAngle() 54 | { 55 | return endAngle; 56 | } 57 | 58 | public void setEndAngle(Float endAngle) 59 | { 60 | this.endAngle = endAngle; 61 | } 62 | 63 | public float getRotateAngle() 64 | { 65 | return rotateAngle; 66 | } 67 | 68 | public void setRotateAngle(float rotateAngle) 69 | { 70 | this.rotateAngle = rotateAngle; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/transition/SequentialTransition.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation.transition; 2 | 3 | import net.voxelindustry.brokkgui.animation.Animation; 4 | import net.voxelindustry.brokkgui.animation.Interpolators; 5 | import net.voxelindustry.brokkgui.component.GuiNode; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | public class SequentialTransition extends Transition 12 | { 13 | private List animations; 14 | 15 | private Animation current; 16 | 17 | public SequentialTransition(GuiNode node, Animation... animations) 18 | { 19 | super(node, 0, TimeUnit.MILLISECONDS); 20 | 21 | this.setInterpolator(Interpolators.LINEAR); 22 | 23 | this.animations = Arrays.asList(animations); 24 | this.setDuration(this.animations.stream() 25 | .mapToLong(animation -> animation.getDuration() * animation.getMaxCycles()).sum()); 26 | this.animations.forEach(animation -> animation.setParent(this)); 27 | } 28 | 29 | @Override 30 | protected void apply(float interpolated) 31 | { 32 | Animation animation = null; 33 | 34 | float currentPart = 0; 35 | for (Animation anim : animations) 36 | { 37 | float part = ((float) anim.getDuration() * anim.getMaxCycles()) / this.getDuration(); 38 | 39 | if (currentPart + part > interpolated) 40 | { 41 | animation = anim; 42 | break; 43 | } 44 | currentPart += part; 45 | } 46 | 47 | if (animation == null) 48 | return; 49 | 50 | if (current != animation) 51 | { 52 | if (current != null) 53 | current.complete(); 54 | 55 | current = animation; 56 | current.restart(); 57 | } 58 | 59 | animation.setCurrentProgress(interpolated - currentPart); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/transition/SizeTransition.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation.transition; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class SizeTransition extends Transition 8 | { 9 | private Float startX, startY; 10 | private Float endX, endY; 11 | 12 | private float fromX, fromY; 13 | private float translateX, translateY; 14 | 15 | public SizeTransition(GuiNode node, long duration, TimeUnit unit) 16 | { 17 | super(node, duration, unit); 18 | } 19 | 20 | @Override 21 | protected void apply(float interpolated) 22 | { 23 | if (getNode() == null) 24 | return; 25 | 26 | getNode().setSize(fromX + (endX - fromX) * interpolated, fromY + (endY - fromY) * interpolated); 27 | } 28 | 29 | @Override 30 | public void restart() 31 | { 32 | super.restart(); 33 | 34 | if (startX == null) 35 | fromX = getNode().getScaleX(); 36 | else 37 | fromX = startX; 38 | 39 | if (startY == null) 40 | fromY = getNode().getScaleY(); 41 | else 42 | fromY = startY; 43 | 44 | if (endX == null) 45 | endX = fromX + translateX; 46 | if (endY == null) 47 | endY = fromY + translateY; 48 | } 49 | 50 | public Float getStartX() 51 | { 52 | return startX; 53 | } 54 | 55 | public void setStartX(Float startX) 56 | { 57 | this.startX = startX; 58 | } 59 | 60 | public Float getStartY() 61 | { 62 | return startY; 63 | } 64 | 65 | public void setStartY(Float startY) 66 | { 67 | this.startY = startY; 68 | } 69 | 70 | public Float getEndX() 71 | { 72 | return endX; 73 | } 74 | 75 | public void setEndX(Float endX) 76 | { 77 | this.endX = endX; 78 | } 79 | 80 | public Float getEndY() 81 | { 82 | return endY; 83 | } 84 | 85 | public void setEndY(Float endY) 86 | { 87 | this.endY = endY; 88 | } 89 | 90 | public float getTranslateX() 91 | { 92 | return translateX; 93 | } 94 | 95 | public void setTranslateX(float translateX) 96 | { 97 | this.translateX = translateX; 98 | } 99 | 100 | public float getTranslateY() 101 | { 102 | return translateY; 103 | } 104 | 105 | public void setTranslateY(float translateY) 106 | { 107 | this.translateY = translateY; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/transition/Transition.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation.transition; 2 | 3 | import net.voxelindustry.brokkgui.animation.Animation; 4 | import net.voxelindustry.brokkgui.animation.Interpolator; 5 | import net.voxelindustry.brokkgui.animation.Interpolators; 6 | import net.voxelindustry.brokkgui.component.GuiNode; 7 | import net.voxelindustry.brokkgui.event.DisposeEvent; 8 | 9 | import java.util.concurrent.TimeUnit; 10 | 11 | public abstract class Transition extends Animation 12 | { 13 | private Interpolator interpolator; 14 | private GuiNode node; 15 | 16 | public Transition(GuiNode node, long duration, TimeUnit unit) 17 | { 18 | super(duration, unit); 19 | 20 | this.interpolator = Interpolators.QUAD_BOTH; 21 | 22 | this.getProgressProperty().addListener(obs -> apply(interpolator.apply(getProgress()))); 23 | 24 | this.node = node; 25 | this.node.getEventDispatcher().addHandler(DisposeEvent.TYPE, event -> this.complete()); 26 | } 27 | 28 | protected abstract void apply(float interpolated); 29 | 30 | public Interpolator getInterpolator() 31 | { 32 | return interpolator; 33 | } 34 | 35 | public void setInterpolator(Interpolator interpolator) 36 | { 37 | this.interpolator = interpolator; 38 | } 39 | 40 | public GuiNode getNode() 41 | { 42 | if (node == null && getParent() instanceof Transition) 43 | return ((Transition) getParent()).getNode(); 44 | return node; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/transition/TranslateTransition.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation.transition; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class TranslateTransition extends Transition 8 | { 9 | private Float startX, startY; 10 | private Float endX, endY; 11 | 12 | private float fromX, fromY; 13 | private float translateX, translateY; 14 | 15 | public TranslateTransition(GuiNode node, long millis) 16 | { 17 | this(node, millis, TimeUnit.MILLISECONDS); 18 | } 19 | 20 | public TranslateTransition(GuiNode node, long duration, TimeUnit unit) 21 | { 22 | super(node, duration, unit); 23 | } 24 | 25 | @Override 26 | protected void apply(float interpolated) 27 | { 28 | if (getNode() == null) 29 | return; 30 | 31 | getNode().setTranslate(fromX + (endX - fromX) * interpolated, fromY + (endY - fromY) * interpolated); 32 | } 33 | 34 | @Override 35 | public void restart() 36 | { 37 | super.restart(); 38 | 39 | if (startX == null) 40 | fromX = getNode().getxTranslate(); 41 | else 42 | fromX = startX; 43 | 44 | if (startY == null) 45 | fromY = getNode().getyTranslate(); 46 | else 47 | fromY = startY; 48 | 49 | if (endX == null) 50 | endX = fromX + translateX; 51 | if (endY == null) 52 | endY = fromY + translateY; 53 | } 54 | 55 | public float getStartX() 56 | { 57 | return startX; 58 | } 59 | 60 | public void setStartX(float startX) 61 | { 62 | this.startX = startX; 63 | } 64 | 65 | public float getStartY() 66 | { 67 | return startY; 68 | } 69 | 70 | public void setStartY(float startY) 71 | { 72 | this.startY = startY; 73 | } 74 | 75 | public float getEndX() 76 | { 77 | return endX; 78 | } 79 | 80 | public void setEndX(float endX) 81 | { 82 | this.endX = endX; 83 | } 84 | 85 | public float getEndY() 86 | { 87 | return endY; 88 | } 89 | 90 | public void setEndY(float endY) 91 | { 92 | this.endY = endY; 93 | } 94 | 95 | public float getTranslateX() 96 | { 97 | return translateX; 98 | } 99 | 100 | public void setTranslateX(float translateX) 101 | { 102 | this.translateX = translateX; 103 | } 104 | 105 | public float getTranslateY() 106 | { 107 | return translateY; 108 | } 109 | 110 | public void setTranslateY(float translateY) 111 | { 112 | this.translateY = translateY; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/animation/transition/WaitTransition.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.animation.transition; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | 5 | import java.util.concurrent.TimeUnit; 6 | 7 | public class WaitTransition extends Transition 8 | { 9 | public WaitTransition(GuiNode node, long duration, TimeUnit unit) 10 | { 11 | super(node, duration, unit); 12 | } 13 | 14 | @Override 15 | protected void apply(float interpolated) 16 | { 17 | // This animation does absolutely nothing. 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/behavior/GuiBehaviorBase.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.behavior; 2 | 3 | import net.voxelindustry.brokkgui.control.GuiElement; 4 | 5 | public class GuiBehaviorBase 6 | { 7 | private C model; 8 | 9 | public GuiBehaviorBase(final C model) 10 | { 11 | if (model == null) 12 | throw new IllegalArgumentException("Cannot pass a null model"); 13 | this.model = model; 14 | } 15 | 16 | public void setModel(final C model) 17 | { 18 | this.model = model; 19 | } 20 | 21 | public C getModel() 22 | { 23 | return this.model; 24 | } 25 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/behavior/GuiButtonBehavior.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.behavior; 2 | 3 | import net.voxelindustry.brokkgui.control.GuiButtonBase; 4 | import net.voxelindustry.brokkgui.event.ClickEvent; 5 | 6 | public class GuiButtonBehavior extends GuiBehaviorBase 7 | { 8 | public GuiButtonBehavior(final C model) 9 | { 10 | super(model); 11 | 12 | this.getModel().getEventDispatcher().addHandler(ClickEvent.Left.TYPE, this::onClick); 13 | } 14 | 15 | public void onClick(final ClickEvent.Left event) 16 | { 17 | if (!this.getModel().isDisabled()) 18 | this.getModel().activate(); 19 | } 20 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/behavior/IGuiBehavable.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.behavior; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | 5 | public interface IGuiBehavable> 6 | { 7 | default B getBehaviour() 8 | { 9 | return this.getBehaviourProperty().getValue(); 10 | } 11 | 12 | BaseProperty getBehaviourProperty(); 13 | 14 | void setBehaviour(B value); 15 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/component/IGuiPopup.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.component; 2 | 3 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 4 | import net.voxelindustry.brokkgui.paint.RenderPass; 5 | 6 | public interface IGuiPopup 7 | { 8 | void renderNode(IGuiRenderer renderer, RenderPass pass, int mouseX, int mouseY); 9 | } 10 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/component/IGuiTooltip.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.component; 2 | 3 | import net.voxelindustry.brokkgui.control.GuiElement; 4 | 5 | public interface IGuiTooltip extends IGuiPopup 6 | { 7 | void setOwner(GuiElement owner); 8 | } 9 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/component/ITextInput.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.component; 2 | 3 | public interface ITextInput 4 | { 5 | String getText(); 6 | 7 | void setText(String text); 8 | 9 | boolean isEditable(); 10 | 11 | void setEditable(boolean editable); 12 | 13 | /** 14 | * Validate the content of the ITextInput if it has validators registered. 15 | */ 16 | void validate(); 17 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/control/DragHelper.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.control; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.data.RectArea; 5 | import net.voxelindustry.brokkgui.event.GuiMouseEvent; 6 | 7 | import javax.annotation.Nullable; 8 | import java.util.concurrent.atomic.AtomicBoolean; 9 | 10 | public class DragHelper 11 | { 12 | public static void setDraggable(GuiNode node) 13 | { 14 | setDraggable(node, null, null); 15 | } 16 | 17 | public static void setDraggable(GuiNode node, @Nullable RectArea nodeDragStart, @Nullable RectArea dragArea) 18 | { 19 | AtomicBoolean isDragged = new AtomicBoolean(false); 20 | 21 | node.getEventDispatcher().addHandler(GuiMouseEvent.DRAG_START, e -> 22 | { 23 | if (nodeDragStart == null || nodeDragStart.isPointInside(e.getMouseX(), e.getMouseY())) 24 | isDragged.set(true); 25 | }); 26 | node.getEventDispatcher().addHandler(GuiMouseEvent.DRAGGING, e -> 27 | { 28 | if (isDragged.get() && (dragArea == null || dragArea.isPointInside(e.getMouseX(), e.getMouseY()))) 29 | { 30 | node.setxTranslate(e.getMouseX()); 31 | node.setyTranslate(e.getMouseY()); 32 | } 33 | }); 34 | node.getEventDispatcher().addHandler(GuiMouseEvent.DRAG_STOP, e -> isDragged.set(false)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/control/GuiElement.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.control; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | import net.voxelindustry.brokkgui.component.IGuiTooltip; 5 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 6 | import net.voxelindustry.brokkgui.paint.RenderPass; 7 | import net.voxelindustry.brokkgui.skin.GuiSkinBase; 8 | import net.voxelindustry.brokkgui.skin.IGuiSkinnable; 9 | 10 | public abstract class GuiElement extends GuiFather implements IGuiSkinnable 11 | { 12 | private final BaseProperty> skinProperty; 13 | private final BaseProperty tooltipProperty; 14 | 15 | public GuiElement(String type) 16 | { 17 | super(type); 18 | 19 | this.skinProperty = new BaseProperty<>(null, "skinProperty"); 20 | this.tooltipProperty = new BaseProperty<>(null, "tooltipProperty"); 21 | 22 | this.tooltipProperty.addListener((obs, oldValue, newValue) -> 23 | { 24 | if (oldValue != null) 25 | oldValue.setOwner(null); 26 | if (newValue != null) 27 | newValue.setOwner(this); 28 | }); 29 | } 30 | 31 | @Override 32 | public void renderContent(IGuiRenderer renderer, RenderPass pass, int mouseX, int mouseY) 33 | { 34 | this.getSkin().render(pass, renderer, mouseX, mouseY); 35 | super.renderContent(renderer, pass, mouseX, mouseY); 36 | } 37 | 38 | protected abstract GuiSkinBase makeDefaultSkin(); 39 | 40 | @Override 41 | public GuiSkinBase getSkin() 42 | { 43 | if (!this.skinProperty.isPresent()) 44 | this.skinProperty.setValue(this.makeDefaultSkin()); 45 | return this.skinProperty.getValue(); 46 | } 47 | 48 | @Override 49 | public void setStyle(String style) 50 | { 51 | if (!this.skinProperty.isPresent()) 52 | this.skinProperty.setValue(this.makeDefaultSkin()); 53 | super.setStyle(style); 54 | } 55 | 56 | @Override 57 | public void refreshStyle() 58 | { 59 | if (!this.skinProperty.isPresent()) 60 | this.skinProperty.setValue(this.makeDefaultSkin()); 61 | super.refreshStyle(); 62 | } 63 | 64 | public BaseProperty getTooltipProperty() 65 | { 66 | return this.tooltipProperty; 67 | } 68 | 69 | public IGuiTooltip getTooltip() 70 | { 71 | return this.getTooltipProperty().getValue(); 72 | } 73 | 74 | public void setTooltip(IGuiTooltip tooltip) 75 | { 76 | this.getTooltipProperty().setValue(tooltip); 77 | } 78 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/Position.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | 5 | public class Position 6 | { 7 | private float x; 8 | private float y; 9 | 10 | private PositionType type; 11 | 12 | private Position(float x, float y, PositionType type) 13 | { 14 | this.x = x; 15 | this.y = y; 16 | this.type = type; 17 | } 18 | 19 | public static Position absolute(float x, float y) 20 | { 21 | return new Position(x, y, PositionType.ABSOLUTE); 22 | } 23 | 24 | public static Position relative(float x, float y) 25 | { 26 | return new Position(x, y, PositionType.RELATIVE); 27 | } 28 | 29 | public float getX(GuiNode node) 30 | { 31 | if (type == PositionType.RELATIVE) 32 | return node.getWidth() * x; 33 | return x; 34 | } 35 | 36 | public float getY(GuiNode node) 37 | { 38 | if (type == PositionType.RELATIVE) 39 | return node.getHeight() * y; 40 | return y; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/PositionType.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | public enum PositionType 4 | { 5 | ABSOLUTE, 6 | RELATIVE 7 | } 8 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/RectAlignment.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | public enum RectAlignment 4 | { 5 | LEFT_CENTER, 6 | RIGHT_CENTER, 7 | MIDDLE_CENTER, 8 | LEFT_UP, 9 | RIGHT_UP, 10 | MIDDLE_UP, 11 | LEFT_DOWN, 12 | MIDDLE_DOWN, 13 | RIGHT_DOWN; 14 | 15 | public boolean isVerticalCentered() 16 | { 17 | return this == LEFT_CENTER || this == RIGHT_CENTER || this == MIDDLE_CENTER; 18 | } 19 | 20 | public boolean isHorizontalCentered() 21 | { 22 | return this == MIDDLE_UP || this == MIDDLE_CENTER || this == MIDDLE_DOWN; 23 | } 24 | 25 | public boolean isLeft() 26 | { 27 | return this == LEFT_CENTER || this == LEFT_DOWN || this == LEFT_UP; 28 | } 29 | 30 | public boolean isRight() 31 | { 32 | return this == RIGHT_CENTER || this == RIGHT_DOWN || this == RIGHT_UP; 33 | } 34 | 35 | public boolean isUp() 36 | { 37 | return this == LEFT_UP || this == RIGHT_UP || this == MIDDLE_UP; 38 | } 39 | 40 | public boolean isDown() 41 | { 42 | return this == LEFT_DOWN || this == RIGHT_DOWN || this == MIDDLE_DOWN; 43 | } 44 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/RectArea.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | import fr.ourten.teabeans.binding.BaseExpression; 4 | import fr.ourten.teabeans.value.BaseProperty; 5 | import fr.ourten.teabeans.value.ObservableValue; 6 | import net.voxelindustry.brokkgui.component.GuiNode; 7 | 8 | public class RectArea 9 | { 10 | private GuiNode node; 11 | private ObservableValue startX, startY, endX, endY; 12 | 13 | public static RectArea fitNode(GuiNode node) 14 | { 15 | return nodePart(node, 1, 1); 16 | } 17 | 18 | public static RectArea nodePart(GuiNode node, float widthFrac, float heightFrac) 19 | { 20 | RectArea rectArea = new RectArea(); 21 | rectArea.node = node; 22 | 23 | rectArea.startX = BaseExpression.biCombine(node.getxPosProperty(), node.getxTranslateProperty(), Float::sum); 24 | rectArea.startY = BaseExpression.biCombine(node.getyPosProperty(), node.getyTranslateProperty(), Float::sum); 25 | 26 | rectArea.endX = BaseExpression.biCombine(rectArea.startX, node.getWidthProperty(), 27 | (startX, width) -> startX + width * widthFrac); 28 | rectArea.endY = BaseExpression.biCombine(rectArea.startY, node.getHeightProperty(), 29 | (startY, height) -> startY + height * heightFrac); 30 | 31 | return rectArea; 32 | } 33 | 34 | public static RectArea withRegion(float startX, float startY, float endX, float endY) 35 | { 36 | RectArea rectArea = new RectArea(); 37 | 38 | rectArea.startX = new BaseProperty<>(startX, "startXProperty"); 39 | rectArea.startY = new BaseProperty<>(startY, "startYProperty"); 40 | rectArea.endX = new BaseProperty<>(endX, "endXProperty"); 41 | rectArea.endY = new BaseProperty<>(endY, "endYProperty"); 42 | 43 | return rectArea; 44 | } 45 | 46 | public void dispose() 47 | { 48 | if (node == null) 49 | return; 50 | 51 | ((BaseExpression) this.startX).unbind(node.getxPosProperty(), node.getxTranslateProperty()); 52 | ((BaseExpression) this.startY).unbind(node.getyPosProperty(), node.getyTranslateProperty()); 53 | 54 | ((BaseExpression) this.endX).unbind(this.startX, node.getWidthProperty()); 55 | ((BaseExpression) this.endY).unbind(this.startY, node.getHeightProperty()); 56 | } 57 | 58 | public boolean isPointInside(float x, float y) 59 | { 60 | return x > startX.getValue() && x < endX.getValue() && y > startY.getValue() && y < endY.getValue(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/RectAxis.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | public enum RectAxis 4 | { 5 | HORIZONTAL, VERTICAL 6 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/RectCorner.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | public enum RectCorner 4 | { 5 | TOP_LEFT("top-left"), 6 | TOP_RIGHT("top-right"), 7 | BOTTOM_LEFT("bottom-left"), 8 | BOTTOM_RIGHT("bottom-right"); 9 | 10 | private String cssString; 11 | 12 | RectCorner(String cssString) 13 | { 14 | this.cssString = cssString; 15 | } 16 | 17 | public String getCssString() 18 | { 19 | return cssString; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/RectSide.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | public enum RectSide 4 | { 5 | UP("top"), 6 | DOWN("bottom"), 7 | LEFT("left"), 8 | RIGHT("right"); 9 | 10 | private String cssString; 11 | 12 | RectSide(String cssString) 13 | { 14 | this.cssString = cssString; 15 | } 16 | 17 | public String getCssString() 18 | { 19 | return cssString; 20 | } 21 | 22 | public boolean isVertical() 23 | { 24 | return this == UP || this == DOWN; 25 | } 26 | 27 | public boolean isHorizontal() 28 | { 29 | return this == LEFT || this == RIGHT; 30 | } 31 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/Resource.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | import java.util.Objects; 4 | 5 | public class Resource 6 | { 7 | private final String type; 8 | private final String path; 9 | 10 | public Resource(String type, String path) 11 | { 12 | this.type = type; 13 | this.path = path; 14 | } 15 | 16 | public String getType() 17 | { 18 | return type; 19 | } 20 | 21 | public String getPath() 22 | { 23 | return path; 24 | } 25 | 26 | @Override 27 | public boolean equals(Object o) 28 | { 29 | if (this == o) return true; 30 | if (o == null || getClass() != o.getClass()) return false; 31 | Resource resource = (Resource) o; 32 | return Objects.equals(path, resource.path) && Objects.equals(type, resource.type); 33 | } 34 | 35 | @Override 36 | public int hashCode() 37 | { 38 | return Objects.hash(path, type); 39 | } 40 | 41 | @Override 42 | public String toString() 43 | { 44 | return "Resource{" + 45 | "type='" + type + "', " + 46 | "path='" + path + '\'' + 47 | '}'; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/Rotation.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | 5 | public class Rotation 6 | { 7 | public static final Rotation NONE = Rotation.build().fromCenter().angle(0).create(); 8 | 9 | private final BaseProperty angleProperty; 10 | private final BaseProperty originProperty; 11 | 12 | private Rotation(float angle, RotationOrigin origin) 13 | { 14 | this.angleProperty = new BaseProperty<>(angle, "angleProperty"); 15 | this.originProperty = new BaseProperty<>(origin, "originProperty"); 16 | } 17 | 18 | public BaseProperty getAngleProperty() 19 | { 20 | return angleProperty; 21 | } 22 | 23 | public BaseProperty getOriginProperty() 24 | { 25 | return originProperty; 26 | } 27 | 28 | public float getAngle() 29 | { 30 | return this.getAngleProperty().getValue(); 31 | } 32 | 33 | public void setAngle(float angle) 34 | { 35 | this.getAngleProperty().setValue(angle); 36 | } 37 | 38 | public RotationOrigin getOrigin() 39 | { 40 | return this.getOriginProperty().getValue(); 41 | } 42 | 43 | public void setOrigin(RotationOrigin origin) 44 | { 45 | this.getOriginProperty().setValue(origin); 46 | } 47 | 48 | public static Builder build() 49 | { 50 | return new Builder(); 51 | } 52 | 53 | public static final class Builder 54 | { 55 | private float angle; 56 | private RotationOrigin origin; 57 | 58 | Builder() 59 | { 60 | 61 | } 62 | 63 | public Builder from(RotationOrigin origin) 64 | { 65 | this.origin = origin; 66 | return this; 67 | } 68 | 69 | public Builder fromCenter() 70 | { 71 | this.origin = RotationOrigin.CENTER; 72 | return this; 73 | } 74 | 75 | public Builder from(float fromX, float fromY) 76 | { 77 | this.origin = new RotationOrigin(fromX, fromY, false); 78 | return this; 79 | } 80 | 81 | public Builder fromRelative(float fromX, float fromY) 82 | { 83 | this.origin = new RotationOrigin(fromX, fromY, true); 84 | return this; 85 | } 86 | 87 | public Builder angle(float angle) 88 | { 89 | this.angle = angle; 90 | return this; 91 | } 92 | 93 | public Rotation create() 94 | { 95 | if (origin != null) 96 | return new Rotation(angle, origin); 97 | throw new RuntimeException("A rotation origin must be specified!"); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/RotationOrigin.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | public class RotationOrigin 4 | { 5 | public static final RotationOrigin CENTER = new RotationOrigin(0.5f, 0.5f, true); 6 | 7 | public static final RotationOrigin LEFT_TOP = new RotationOrigin(0, 0, true); 8 | public static final RotationOrigin LEFT_BOTTOM = new RotationOrigin(0, 1, true); 9 | public static final RotationOrigin RIGHT_TOP = new RotationOrigin(1, 0, true); 10 | public static final RotationOrigin RIGHT_BOTTOM = new RotationOrigin(1, 1, true); 11 | 12 | 13 | private boolean relativePos; 14 | private float originX, originY; 15 | 16 | RotationOrigin(float originX, float originY, boolean relativePos) 17 | { 18 | this.originX = originX; 19 | this.originY = originY; 20 | this.relativePos = relativePos; 21 | } 22 | 23 | public boolean isRelativePos() 24 | { 25 | return relativePos; 26 | } 27 | 28 | public float getOriginX() 29 | { 30 | return originX; 31 | } 32 | 33 | public float getOriginY() 34 | { 35 | return originY; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/Scale.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 5 | 6 | import java.util.Optional; 7 | 8 | public class Scale 9 | { 10 | private float x; 11 | private float y; 12 | private float z; 13 | 14 | private Optional pivot; 15 | 16 | public Scale(float x, float y, float z, Position pivot) 17 | { 18 | this.x = x; 19 | this.y = y; 20 | this.z = z; 21 | this.pivot = Optional.ofNullable(pivot); 22 | } 23 | 24 | public Scale(float x, float y, Position pivot) 25 | { 26 | this(x, y, y, pivot); 27 | } 28 | 29 | public Scale(float x, float y, float z) 30 | { 31 | this(x, y, z, null); 32 | } 33 | 34 | public Scale(float x, float y) 35 | { 36 | this(x, y, y); 37 | } 38 | 39 | public boolean apply(IGuiRenderer renderer, GuiNode node, boolean createdMatrix) 40 | { 41 | if (x == 1 && y == 1 && z == 1) 42 | return false; 43 | 44 | if (!createdMatrix) 45 | renderer.beginMatrix(); 46 | 47 | renderer.translateMatrix( 48 | node.getLeftPos() + pivot.map(pos -> pos.getX(node)).orElse(0F), 49 | node.getTopPos() + pivot.map(pos -> pos.getY(node)).orElse(0F), 50 | 0 51 | ); 52 | 53 | renderer.scaleMatrix(x, y, z); 54 | 55 | renderer.translateMatrix( 56 | -(node.getLeftPos() + pivot.map(pos -> pos.getX(node)).orElse(0F)), 57 | -(node.getTopPos() + pivot.map(pos -> pos.getY(node)).orElse(0F)), 58 | 0 59 | ); 60 | 61 | return true; 62 | } 63 | 64 | public float getX() 65 | { 66 | return x; 67 | } 68 | 69 | public float getY() 70 | { 71 | return y; 72 | } 73 | 74 | public float getZ() 75 | { 76 | return z; 77 | } 78 | 79 | public Optional getPivot() 80 | { 81 | return pivot; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/data/Vector2i.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.data; 2 | 3 | public class Vector2i 4 | { 5 | private int x, y; 6 | 7 | public Vector2i(final int x, final int y) 8 | { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | public Vector2i(final Vector2i from) 14 | { 15 | this(from.x, from.y); 16 | } 17 | 18 | public int getX() 19 | { 20 | return this.x; 21 | } 22 | 23 | public void setX(final int x) 24 | { 25 | this.x = x; 26 | } 27 | 28 | public int getY() 29 | { 30 | return this.y; 31 | } 32 | 33 | public void setY(final int y) 34 | { 35 | this.y = y; 36 | } 37 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/ActionEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.control.GuiButtonBase; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class ActionEvent extends GuiInputEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(ANY, "ACTION_INPUT_EVENT"); 10 | 11 | public ActionEvent(GuiButtonBase source) 12 | { 13 | super(source); 14 | } 15 | 16 | @Override 17 | public ActionEvent copy(IEventEmitter source) 18 | { 19 | return new ActionEvent((GuiButtonBase) source); 20 | } 21 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/AnimationFinishEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.hermod.HermodEvent; 4 | import net.voxelindustry.hermod.IEventEmitter; 5 | 6 | public class AnimationFinishEvent extends HermodEvent 7 | { 8 | public AnimationFinishEvent(IEventEmitter source) 9 | { 10 | super(source); 11 | } 12 | 13 | @Override 14 | public AnimationFinishEvent copy(IEventEmitter source) 15 | { 16 | return new AnimationFinishEvent(source); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/ClickEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class ClickEvent extends GuiMouseEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(ANY, "MOUSE_CLICK_EVENT"); 10 | 11 | private final int key; 12 | 13 | public ClickEvent(GuiNode source) 14 | { 15 | this(source, 0, 0, 0); 16 | } 17 | 18 | public ClickEvent(GuiNode source, int mouseX, int mouseY, int key) 19 | { 20 | super(source, mouseX, mouseY); 21 | 22 | this.key = key; 23 | } 24 | 25 | public int getKey() 26 | { 27 | return this.key; 28 | } 29 | 30 | @Override 31 | public ClickEvent copy(IEventEmitter source) 32 | { 33 | return new ClickEvent((GuiNode) source, getMouseX(), getMouseY(), getKey()); 34 | } 35 | 36 | public static class Left extends ClickEvent 37 | { 38 | public static EventType TYPE = new EventType<>(ClickEvent.TYPE, 39 | "MOUSE_LEFT_CLICK_EVENT"); 40 | 41 | public Left(GuiNode source, int mouseX, int mouseY) 42 | { 43 | super(source, mouseX, mouseY, 0); 44 | } 45 | 46 | @Override 47 | public Left copy(IEventEmitter source) 48 | { 49 | return new Left((GuiNode) source, getMouseX(), getMouseY()); 50 | } 51 | } 52 | 53 | public static class Right extends ClickEvent 54 | { 55 | public static EventType TYPE = new EventType<>(ClickEvent.TYPE, 56 | "MOUSE_RIGHT_CLICK_EVENT"); 57 | 58 | public Right(GuiNode source, int mouseX, int mouseY) 59 | { 60 | super(source, mouseX, mouseY, 1); 61 | } 62 | 63 | @Override 64 | public Right copy(IEventEmitter source) 65 | { 66 | return new Right((GuiNode) source, getMouseX(), getMouseY()); 67 | } 68 | } 69 | 70 | public static class Middle extends ClickEvent 71 | { 72 | public static EventType TYPE = new EventType<>(ClickEvent.TYPE, 73 | "MOUSE_MIDDLE_CLICK_EVENT"); 74 | 75 | public Middle(GuiNode source, int mouseX, int mouseY) 76 | { 77 | super(source, mouseX, mouseY, 2); 78 | } 79 | 80 | @Override 81 | public Middle copy(IEventEmitter source) 82 | { 83 | return new Middle((GuiNode) source, getMouseX(), getMouseY()); 84 | } 85 | } 86 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/CursorMoveEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class CursorMoveEvent extends GuiMouseEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(GuiMouseEvent.ANY, "MOUSE_MOVE_EVENT"); 10 | 11 | public CursorMoveEvent(GuiNode source) 12 | { 13 | this(source, 0, 0); 14 | } 15 | 16 | public CursorMoveEvent(GuiNode source, int mouseX, int mouseY) 17 | { 18 | super(source, mouseX, mouseY); 19 | } 20 | 21 | @Override 22 | public CursorMoveEvent copy(IEventEmitter source) 23 | { 24 | return new CursorMoveEvent((GuiNode) source, getMouseX(), getMouseY()); 25 | } 26 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/DisableEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class DisableEvent extends GuiStateEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(ANY, "DISABLE_STATE_EVENT"); 10 | 11 | private final boolean disabled; 12 | 13 | public DisableEvent(GuiNode source) 14 | { 15 | this(source, false); 16 | } 17 | 18 | public DisableEvent(GuiNode source, boolean disabled) 19 | { 20 | super(source); 21 | 22 | this.disabled = disabled; 23 | } 24 | 25 | public boolean isDisabled() 26 | { 27 | return this.disabled; 28 | } 29 | 30 | @Override 31 | public DisableEvent copy(IEventEmitter source) 32 | { 33 | return new DisableEvent((GuiNode) source, isDisabled()); 34 | } 35 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/DisposeEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class DisposeEvent extends GuiStateEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(ANY, "DISPOSE_STATE_EVENT"); 10 | 11 | public DisposeEvent(GuiNode source) 12 | { 13 | super(source); 14 | } 15 | 16 | @Override 17 | public DisposeEvent copy(IEventEmitter source) 18 | { 19 | return new DisposeEvent((GuiNode) source); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/FocusEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class FocusEvent extends GuiStateEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(GuiStateEvent.ANY, "FOCUS_STATE_EVENT"); 10 | 11 | private final boolean focused; 12 | 13 | public FocusEvent(GuiNode source) 14 | { 15 | this(source, false); 16 | } 17 | 18 | public FocusEvent(GuiNode source, boolean focused) 19 | { 20 | super(source); 21 | 22 | this.focused = focused; 23 | } 24 | 25 | public boolean isFocused() 26 | { 27 | return this.focused; 28 | } 29 | 30 | @Override 31 | public FocusEvent copy(IEventEmitter source) 32 | { 33 | return new FocusEvent((GuiNode) source, isFocused()); 34 | } 35 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/GuiInputEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.HermodEvent; 6 | import net.voxelindustry.hermod.IEventEmitter; 7 | 8 | public class GuiInputEvent extends HermodEvent 9 | { 10 | public static final EventType ANY = new EventType<>("INPUT_EVENT"); 11 | 12 | public GuiInputEvent(final GuiNode source) 13 | { 14 | super(source); 15 | } 16 | 17 | @Override 18 | public GuiInputEvent copy(IEventEmitter source) 19 | { 20 | return new GuiInputEvent((GuiNode) source); 21 | } 22 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/GuiStateEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.HermodEvent; 6 | import net.voxelindustry.hermod.IEventEmitter; 7 | 8 | public class GuiStateEvent extends HermodEvent 9 | { 10 | public static final EventType ANY = new EventType<>("STATE_EVENT"); 11 | 12 | public GuiStateEvent(final GuiNode source) 13 | { 14 | super(source); 15 | } 16 | 17 | @Override 18 | public GuiStateEvent copy(IEventEmitter source) 19 | { 20 | return new GuiStateEvent((GuiNode) source); 21 | } 22 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/HoverEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class HoverEvent extends GuiStateEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(GuiStateEvent.ANY, "HOVER_STATE_EVENT"); 10 | 11 | private final boolean entering; 12 | 13 | public HoverEvent(GuiNode source) 14 | { 15 | this(source, false); 16 | } 17 | 18 | public HoverEvent(GuiNode source, boolean entering) 19 | { 20 | super(source); 21 | 22 | this.entering = entering; 23 | } 24 | 25 | public boolean isEntering() 26 | { 27 | return this.entering; 28 | } 29 | 30 | @Override 31 | public HoverEvent copy(IEventEmitter source) 32 | { 33 | return new HoverEvent((GuiNode) source, isEntering()); 34 | } 35 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/KeyEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.BrokkGuiPlatform; 4 | import net.voxelindustry.brokkgui.component.GuiNode; 5 | import net.voxelindustry.hermod.EventType; 6 | import net.voxelindustry.hermod.IEventEmitter; 7 | 8 | public class KeyEvent extends GuiInputEvent 9 | { 10 | public static final EventType ANY = new EventType<>(GuiInputEvent.ANY, "INPUT_KEY_EVENT"); 11 | public static final EventType INPUT = new EventType<>(ANY, "KEY_INPUT_EVENT"); 12 | public static final EventType PRESS = new EventType<>(ANY, "KEY_PRESS_EVENT"); 13 | public static final EventType RELEASE = new EventType<>(ANY, "KEY_RELEASE_EVENT"); 14 | 15 | private final int key; 16 | 17 | public KeyEvent(GuiNode source) 18 | { 19 | this(source, 0); 20 | } 21 | 22 | public KeyEvent(GuiNode source, int key) 23 | { 24 | super(source); 25 | this.key = key; 26 | } 27 | 28 | public int getKey() 29 | { 30 | return this.key; 31 | } 32 | 33 | public boolean isCtrlDown() 34 | { 35 | return BrokkGuiPlatform.getInstance().getKeyboardUtil().isCtrlKeyDown(); 36 | } 37 | 38 | public boolean isShiftDown() 39 | { 40 | return BrokkGuiPlatform.getInstance().getKeyboardUtil().isShiftKeyDown(); 41 | } 42 | 43 | @Override 44 | public KeyEvent copy(IEventEmitter source) 45 | { 46 | return new KeyEvent((GuiNode) source, getKey()); 47 | } 48 | 49 | public static class Input extends KeyEvent 50 | { 51 | private final char character; 52 | 53 | public Input(GuiNode source, char character, int key) 54 | { 55 | super(source, key); 56 | this.character = character; 57 | } 58 | 59 | public char getCharacter() 60 | { 61 | return this.character; 62 | } 63 | 64 | @Override 65 | public KeyEvent.Input copy(IEventEmitter source) 66 | { 67 | return new KeyEvent.Input((GuiNode) source,getCharacter(), getKey()); 68 | } 69 | } 70 | 71 | public static class Press extends KeyEvent 72 | { 73 | public Press(GuiNode source, int key) 74 | { 75 | super(source, key); 76 | } 77 | 78 | @Override 79 | public KeyEvent.Press copy(IEventEmitter source) 80 | { 81 | return new KeyEvent.Press((GuiNode) source, getKey()); 82 | } 83 | } 84 | 85 | public static class Release extends KeyEvent 86 | { 87 | public Release(GuiNode source, int key) 88 | { 89 | super(source, key); 90 | } 91 | 92 | @Override 93 | public KeyEvent.Release copy(IEventEmitter source) 94 | { 95 | return new KeyEvent.Release((GuiNode) source, getKey()); 96 | } 97 | } 98 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/LayoutEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.HermodEvent; 6 | import net.voxelindustry.hermod.IEventEmitter; 7 | 8 | public class LayoutEvent extends HermodEvent 9 | { 10 | public static final EventType ANY = new EventType<>("LAYOUT_EVENT"); 11 | public static final EventType ADD = new EventType<>(ANY, "LAYOUT_ADD_EVENT"); 12 | public static final EventType REMOVE = new EventType<>(ANY, "LAYOUT_REMOVE_EVENT"); 13 | 14 | public LayoutEvent(GuiNode source) 15 | { 16 | super(source); 17 | } 18 | 19 | @Override 20 | public LayoutEvent copy(IEventEmitter source) 21 | { 22 | return new LayoutEvent((GuiNode) source); 23 | } 24 | 25 | public static class Add extends LayoutEvent 26 | { 27 | public Add(GuiNode source) 28 | { 29 | super(source); 30 | } 31 | 32 | @Override 33 | public Add copy(IEventEmitter source) 34 | { 35 | return new Add((GuiNode) source); 36 | } 37 | } 38 | 39 | public static class Remove extends LayoutEvent 40 | { 41 | public Remove(GuiNode source) 42 | { 43 | super(source); 44 | } 45 | 46 | @Override 47 | public Remove copy(IEventEmitter source) 48 | { 49 | return new Remove((GuiNode) source); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/ScrollEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | /** 8 | * @author Ourten 9 oct. 2016 9 | */ 10 | public class ScrollEvent extends GuiInputEvent 11 | { 12 | public static final EventType TYPE = new EventType<>(ANY, "INPUT_SCROLL_EVENT"); 13 | 14 | private final float scrollX, scrollY; 15 | 16 | public ScrollEvent(GuiNode source, float scrollX, float scrollY) 17 | { 18 | super(source); 19 | 20 | this.scrollX = scrollX; 21 | this.scrollY = scrollY; 22 | } 23 | 24 | public float getScrollX() 25 | { 26 | return this.scrollX; 27 | } 28 | 29 | public float getScrollY() 30 | { 31 | return this.scrollY; 32 | } 33 | 34 | @Override 35 | public ScrollEvent copy(IEventEmitter source) 36 | { 37 | return new ScrollEvent((GuiNode) source, getScrollX(), getScrollY()); 38 | } 39 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/SelectEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.control.GuiButtonBase; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class SelectEvent extends GuiInputEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(ANY, "SELECT_INPUT_EVENT"); 10 | 11 | private boolean isSelected; 12 | 13 | public SelectEvent(GuiButtonBase source, boolean isSelected) 14 | { 15 | super(source); 16 | 17 | this.isSelected = isSelected; 18 | } 19 | 20 | public boolean isSelected() 21 | { 22 | return isSelected; 23 | } 24 | 25 | @Override 26 | public SelectEvent copy(IEventEmitter source) 27 | { 28 | return new SelectEvent((GuiButtonBase) source, isSelected); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/TextTypedEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class TextTypedEvent extends GuiInputEvent 8 | { 9 | public static final EventType TYPE = new EventType<>(GuiInputEvent.ANY, "TEXT_INPUT_EVENT"); 10 | 11 | private final String oldText, newText; 12 | 13 | public TextTypedEvent(GuiNode source) 14 | { 15 | this(source, "", ""); 16 | } 17 | 18 | public TextTypedEvent(GuiNode source, String oldText, String newText) 19 | { 20 | super(source); 21 | this.oldText = oldText; 22 | this.newText = newText; 23 | } 24 | 25 | public String getOldText() 26 | { 27 | return this.oldText; 28 | } 29 | 30 | public String getNewText() 31 | { 32 | return this.newText; 33 | } 34 | 35 | @Override 36 | public TextTypedEvent copy(IEventEmitter source) 37 | { 38 | return new TextTypedEvent((GuiNode) source, getOldText(), getNewText()); 39 | } 40 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/event/WindowEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.event; 2 | 3 | import net.voxelindustry.hermod.EventType; 4 | import net.voxelindustry.hermod.HermodEvent; 5 | import net.voxelindustry.hermod.IEventEmitter; 6 | 7 | public class WindowEvent extends HermodEvent 8 | { 9 | public static final EventType ANY = new EventType<>("WINDOW_EVENT"); 10 | public static final EventType CLOSE = new EventType<>(WindowEvent.ANY, "WINDOW_CLOSE_EVENT"); 11 | public static final EventType OPEN = new EventType<>(WindowEvent.ANY, "WINDOW_OPEN_EVENT"); 12 | 13 | public WindowEvent(IEventEmitter source) 14 | { 15 | super(source); 16 | } 17 | 18 | @Override 19 | public WindowEvent copy(IEventEmitter source) 20 | { 21 | return new WindowEvent(source); 22 | } 23 | 24 | public static class Close extends WindowEvent 25 | { 26 | public Close(IEventEmitter source) 27 | { 28 | super(source); 29 | } 30 | 31 | @Override 32 | public Close copy(IEventEmitter source) 33 | { 34 | return new Close(source); 35 | } 36 | } 37 | 38 | public static class Open extends WindowEvent 39 | { 40 | public Open(IEventEmitter source) 41 | { 42 | super(source); 43 | } 44 | 45 | @Override 46 | public Open copy(IEventEmitter source) 47 | { 48 | return new Open(source); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/gui/IGuiSubWindow.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.gui; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | import net.voxelindustry.hermod.EventHandler; 5 | import net.voxelindustry.hermod.EventType; 6 | import net.voxelindustry.hermod.HermodEvent; 7 | 8 | /** 9 | * @author Ourten 31 oct. 2016 10 | */ 11 | public interface IGuiSubWindow 12 | { 13 | void open(); 14 | 15 | void close(); 16 | 17 | float getxRelativePos(); 18 | 19 | float getyRelativePos(); 20 | 21 | BaseProperty getxRelativePosProperty(); 22 | 23 | BaseProperty getyRelativePosProperty(); 24 | 25 | float getWidth(); 26 | 27 | float getHeight(); 28 | 29 | void addEventHandler(EventType type, EventHandler handler); 30 | 31 | void removeEventHandler(EventType type, EventHandler handler); 32 | 33 | void dispatchEventRedirect(EventType type, HermodEvent event); 34 | 35 | void dispatchEvent(EventType type, HermodEvent event); 36 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/gui/IGuiWindow.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.gui; 2 | 3 | import fr.ourten.teabeans.value.IProperty; 4 | import net.voxelindustry.brokkgui.internal.IBrokkGuiImpl; 5 | import net.voxelindustry.brokkgui.paint.RenderPass; 6 | import net.voxelindustry.brokkgui.paint.RenderTarget; 7 | 8 | /** 9 | * @author Ourten 31 oct. 2016 10 | */ 11 | public interface IGuiWindow extends IGuiSubWindow 12 | { 13 | void onOpen(); 14 | 15 | void onClose(); 16 | 17 | void setWrapper(IBrokkGuiImpl wrapper); 18 | 19 | void setScreenWidth(int width); 20 | 21 | void setScreenHeight(int height); 22 | 23 | IProperty getScreenWidthProperty(); 24 | 25 | IProperty getScreenHeightProperty(); 26 | 27 | void render(int mouseX, int mouseY, RenderTarget target, RenderPass... pass); 28 | 29 | void renderLast(int mouseX, int mouseY); 30 | 31 | void tick(); 32 | 33 | void initGui(); 34 | 35 | IBrokkGuiImpl getWrapper(); 36 | 37 | boolean doesOccludePoint(int mouseX, int mouseY); 38 | 39 | //////////// 40 | // INPUTS // 41 | //////////// 42 | 43 | void onMouseMoved(int mouseX, int mouseY); 44 | 45 | void onKeyPressed(int key); 46 | 47 | void onKeyTyped(char c, int key); 48 | 49 | void onKeyReleased(int key); 50 | 51 | void onClick(int mouseX, int mouseY, int key); 52 | 53 | void onClickDrag(int mouseX, int mouseY, int clickedMouseButton, double dragX, double dragY); 54 | 55 | void onClickStop(int mouseX, int mouseY, int state); 56 | 57 | void handleMouseScroll(double scrolled); 58 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/gui/InputType.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.gui; 2 | 3 | public enum InputType 4 | { 5 | KEY_PRESS, 6 | KEY_TYPE, 7 | KEY_RELEASE, 8 | MOUSE_CLICK, 9 | MOUSE_DRAG_START, 10 | MOUSE_DRAG_STOP, 11 | MOUSE_SCROLL, 12 | MOUSE_MOVE 13 | } 14 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/DesktopUtils.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal; 2 | 3 | import java.awt.*; 4 | import java.io.IOException; 5 | import java.net.URI; 6 | import java.net.URISyntaxException; 7 | 8 | public class DesktopUtils 9 | { 10 | public static final void openURL(final String url) 11 | { 12 | if (Desktop.isDesktopSupported()) 13 | { 14 | final Desktop desktop = Desktop.getDesktop(); 15 | try 16 | { 17 | desktop.browse(new URI(url)); 18 | } catch (IOException | URISyntaxException e) 19 | { 20 | e.printStackTrace(); 21 | } 22 | } 23 | else 24 | { 25 | final Runtime runtime = Runtime.getRuntime(); 26 | try 27 | { 28 | runtime.exec("xdg-open " + url); 29 | } catch (final IOException e) 30 | { 31 | e.printStackTrace(); 32 | } 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/EGuiRenderMode.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal; 2 | 3 | /** 4 | * @author Ourten 16 oct. 2016 5 | */ 6 | public enum EGuiRenderMode 7 | { 8 | POINTS, LINE_STRIP, LINES, QUADS, TRIANGLES, TRIANGLE_STRIP, TRIANGLE_FAN, POLYGON, LINE_LOOP, QUAD_STRIP 9 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/IBrokkGuiImpl.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal; 2 | 3 | import net.voxelindustry.brokkgui.gui.IGuiWindow; 4 | 5 | public interface IBrokkGuiImpl 6 | { 7 | void askOpen(); 8 | 9 | void askClose(); 10 | 11 | IGuiRenderer getRenderer(); 12 | 13 | String getThemeID(); 14 | 15 | float getGuiRelativePosX(float guiXRelativePos, float guiWidth); 16 | 17 | float getGuiRelativePosY(float guiYRelativePos, float guiHeight); 18 | 19 | IGuiWindow getGui(); 20 | 21 | void setGuiWindow(IGuiWindow window); 22 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/IGuiRenderer.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal; 2 | 3 | import net.voxelindustry.brokkgui.paint.RenderPass; 4 | 5 | /** 6 | * @author Ourten 5 oct. 2016 7 | */ 8 | public interface IGuiRenderer 9 | { 10 | void beginPass(RenderPass pass); 11 | 12 | void endPass(RenderPass pass); 13 | 14 | void beginDrawing(EGuiRenderMode mode, boolean texture); 15 | 16 | default void beginDrawingQuads(final boolean texture) 17 | { 18 | this.beginDrawing(EGuiRenderMode.QUADS, texture); 19 | } 20 | 21 | void endDrawing(); 22 | 23 | void addVertex(final double x, final double y, final double z); 24 | 25 | void addVertexWithUV(final double x, final double y, final double z, final double u, final double v); 26 | 27 | IGuiHelper getHelper(); 28 | 29 | void beginMatrix(); 30 | 31 | void endMatrix(); 32 | 33 | void translateMatrix(float posX, float posY, float posZ); 34 | 35 | void rotateMatrix(float rotation, float x, float y, float z); 36 | 37 | void scaleMatrix(float scaleX, float scaleY, float scaleZ); 38 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/IKeyboardUtil.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal; 2 | 3 | /** 4 | * @author Ourten 5 oct. 2016 5 | */ 6 | public interface IKeyboardUtil 7 | { 8 | /** 9 | * @return if a key passed in parameter is translatable to a char writtable 10 | * into a textfield 11 | */ 12 | boolean isKeyValidChar(final int key); 13 | 14 | boolean isCtrlKeyDown(); 15 | 16 | /** 17 | * @return if SHIFT_LEFT or SHIFT_RIGHT are down 18 | */ 19 | boolean isShiftKeyDown(); 20 | 21 | String getClipboardString(); 22 | 23 | int getKeyCode(String keyName); 24 | 25 | String getKeyName(int keyCode); 26 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/IMouseUtil.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal; 2 | 3 | /** 4 | * @author Ourten 9 oct. 2016 5 | */ 6 | public interface IMouseUtil 7 | { 8 | int getMouseX(); 9 | 10 | int getMouseY(); 11 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/IResourceHandler.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal; 2 | 3 | import net.voxelindustry.brokkgui.data.Resource; 4 | 5 | import java.io.IOException; 6 | import java.util.List; 7 | 8 | public interface IResourceHandler 9 | { 10 | boolean isTypeSupported(String resourceType); 11 | 12 | String readToString(Resource resource) throws IOException; 13 | 14 | List readToLines(Resource resource) throws IOException; 15 | } 16 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/profiler/IProfiler.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal.profiler; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | 5 | public interface IProfiler 6 | { 7 | void preElementRender(GuiNode node); 8 | 9 | void postElementRender(GuiNode node); 10 | 11 | void preElementStyleRefresh(GuiNode node); 12 | 13 | void postElementStyleRefresh(GuiNode node); 14 | 15 | void beginRenderFrame(); 16 | 17 | void endRenderFrame(); 18 | } 19 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/internal/profiler/ProfilerNoop.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.internal.profiler; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | 5 | public class ProfilerNoop implements IProfiler 6 | { 7 | @Override 8 | public void preElementRender(GuiNode node) 9 | { 10 | // NOOP 11 | } 12 | 13 | @Override 14 | public void postElementRender(GuiNode node) 15 | { 16 | // NOOP 17 | } 18 | 19 | @Override 20 | public void preElementStyleRefresh(GuiNode node) 21 | { 22 | // NOOP 23 | } 24 | 25 | @Override 26 | public void postElementStyleRefresh(GuiNode node) 27 | { 28 | // NOOP 29 | } 30 | 31 | @Override 32 | public void beginRenderFrame() 33 | { 34 | // NOOP 35 | } 36 | 37 | @Override 38 | public void endRenderFrame() 39 | { 40 | // NOOP 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/paint/GuiPaint.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.paint; 2 | 3 | public abstract class GuiPaint 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/paint/RenderPass.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.paint; 2 | 3 | public class RenderPass 4 | { 5 | public static final RenderPass BACKGROUND = new RenderPass("background", 0); 6 | public static final RenderPass MAIN = new RenderPass("main", 1); 7 | public static final RenderPass FOREGROUND = new RenderPass("foreground", 2); 8 | public static final RenderPass HOVER = new RenderPass("hover", 3); 9 | 10 | /** 11 | * Create a new RenderPass according to parameters. 12 | * Should only be used in wrappers and impl of the api. 13 | * 14 | * @param name of the pass 15 | * @param priority of the pass in render 16 | * @return the created RenderPass 17 | */ 18 | public static RenderPass create(String name, int priority) 19 | { 20 | return new RenderPass(name, priority); 21 | } 22 | 23 | private String name; 24 | private int priority; 25 | 26 | private RenderPass(String name, int priority) 27 | { 28 | this.name = name; 29 | this.priority = priority; 30 | } 31 | 32 | public String getName() 33 | { 34 | return name; 35 | } 36 | 37 | public int getPriority() 38 | { 39 | return priority; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/paint/RenderTarget.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.paint; 2 | 3 | public enum RenderTarget 4 | { 5 | MAIN, WINDOW, POPUP 6 | } 7 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/panel/GuiAbsolutePane.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.panel; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.data.RelativeBindingHelper; 5 | 6 | public class GuiAbsolutePane extends GuiPane 7 | { 8 | @Override 9 | public void addChild(final GuiNode node) 10 | { 11 | this.addChild(node, this.getWidth() / 2 - node.getWidth() / 2, this.getHeight() / 2 - node.getHeight() / 2); 12 | } 13 | 14 | public void addChild(final GuiNode node, final float posX, final float posY) 15 | { 16 | this.getChildrensProperty().add(node); 17 | node.setFather(this); 18 | 19 | node.getxPosProperty().unbind(); 20 | node.getyPosProperty().unbind(); 21 | 22 | RelativeBindingHelper.bindToPos(node, this, posX, posY); 23 | } 24 | 25 | public void setChildPos(final GuiNode node, final float posX, final float posY) 26 | { 27 | if (this.getChildrensProperty().contains(node)) 28 | { 29 | node.getxPosProperty().unbind(); 30 | node.getyPosProperty().unbind(); 31 | 32 | RelativeBindingHelper.bindToPos(node, this, posX, posY); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/panel/GuiPane.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.panel; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.control.GuiFather; 5 | import net.voxelindustry.brokkgui.data.RelativeBindingHelper; 6 | 7 | public class GuiPane extends GuiFather 8 | { 9 | public GuiPane() 10 | { 11 | super("pane"); 12 | } 13 | 14 | @Override 15 | public void addChild(final GuiNode node) 16 | { 17 | super.addChild(node); 18 | 19 | RelativeBindingHelper.bindToCenter(node, this); 20 | } 21 | 22 | @Override 23 | public void removeChild(final GuiNode node) 24 | { 25 | super.removeChild(node); 26 | 27 | node.getxPosProperty().unbind(); 28 | node.getyPosProperty().unbind(); 29 | } 30 | 31 | @Override 32 | public void clearChilds() 33 | { 34 | this.getChildrensProperty().getValue().forEach(node -> 35 | { 36 | node.setFather(null); 37 | node.getxPosProperty().unbind(); 38 | node.getyPosProperty().unbind(); 39 | }); 40 | this.getChildrensProperty().clear(); 41 | } 42 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/panel/GuiRelativePane.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.panel; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.data.RelativeBindingHelper; 5 | 6 | /** 7 | * @author Ourten 9 oct. 2016 8 | */ 9 | public class GuiRelativePane extends GuiPane 10 | { 11 | @Override 12 | public void addChild(final GuiNode node) 13 | { 14 | this.addChild(node, .5f, .5f); 15 | } 16 | 17 | public void addChild(final GuiNode node, final float ratioX, final float ratioY) 18 | { 19 | this.getChildrensProperty().add(node); 20 | node.setFather(this); 21 | 22 | RelativeBindingHelper.bindToRelative(node, this, ratioX, ratioY); 23 | } 24 | 25 | public void setChildPos(final GuiNode node, final float ratioX, final float ratioY) 26 | { 27 | if (this.getChildrensProperty().contains(node)) 28 | { 29 | node.getxPosProperty().unbind(); 30 | node.getyPosProperty().unbind(); 31 | 32 | RelativeBindingHelper.bindToRelative(node, this, ratioX, ratioY); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/policy/GuiOverflowPolicy.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.policy; 2 | 3 | public enum GuiOverflowPolicy 4 | { 5 | /** 6 | * NONE : Nothing is trimmed, inside elements can go everywhere they want. 7 | * 8 | * TRIM : All classical inside elements are trimmed, only special-cased 9 | * stuff like ToolTips are ignored. 10 | * 11 | * TRIM_ALL : Absolutely everything is trimmed. 12 | */ 13 | NONE, TRIM, TRIM_ALL 14 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/policy/GuiScrollbarPolicy.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.policy; 2 | 3 | /** 4 | * @author Ourten 9 oct. 2016 5 | */ 6 | public enum GuiScrollbarPolicy 7 | { 8 | ALWAYS, NEVER, NEEDED 9 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/shape/Circle.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.shape; 2 | 3 | public class Circle extends GuiShape 4 | { 5 | public static final CircleShape SHAPE = new CircleShape(); 6 | 7 | public Circle(float xPosition, float yPosition, float radius) 8 | { 9 | super("circle", SHAPE); 10 | 11 | this.setxTranslate(xPosition); 12 | this.setyTranslate(yPosition); 13 | this.setWidth(radius); 14 | this.setHeight(radius); 15 | } 16 | 17 | public Circle(float radius) 18 | { 19 | this(0, 0, radius); 20 | } 21 | 22 | public Circle() 23 | { 24 | this(0, 0, 0); 25 | } 26 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/shape/CircleShape.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.shape; 2 | 3 | import net.voxelindustry.brokkgui.data.RectBox; 4 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 5 | import net.voxelindustry.brokkgui.paint.Color; 6 | import net.voxelindustry.brokkgui.sprite.Texture; 7 | 8 | public class CircleShape implements ShapeDefinition 9 | { 10 | @Override 11 | public void drawColored(GuiShape shape, IGuiRenderer renderer, float startX, float startY, Color color, 12 | float zLevel, RectBox spritePosition) 13 | { 14 | renderer.getHelper().drawColoredCircle(renderer, startX, startY, shape.getWidth(), zLevel, color); 15 | } 16 | 17 | @Override 18 | public void drawColoredEmpty(GuiShape shape, IGuiRenderer renderer, float startX, float startY, float lineWidth, 19 | Color color, float zLevel) 20 | { 21 | renderer.getHelper().drawColoredEmptyCircle(renderer, startX, startY, shape.getWidth(), zLevel, color, 22 | lineWidth); 23 | } 24 | 25 | @Override 26 | public void drawTextured(GuiShape shape, IGuiRenderer renderer, float startX, float startY, Texture texture, 27 | float zLevel, RectBox spritePosition) 28 | { 29 | renderer.getHelper().drawTexturedCircle(renderer, startX, startY, texture.getUMin(), texture.getVMin(), 30 | texture.getUMax(), texture.getVMax(), shape.getWidth(), zLevel); 31 | } 32 | 33 | @Override 34 | public boolean isMouseInside(GuiShape shape, float mouseX, float mouseY) 35 | { 36 | if (!Rectangle.SHAPE.isMouseInside(shape, mouseX, mouseY)) 37 | return false; 38 | 39 | float pointX = (mouseX - shape.getxPos() - shape.getxTranslate()); 40 | float pointY = (mouseY - shape.getyPos() - shape.getyTranslate()); 41 | return (pointX * pointX) + (pointY * pointY) < shape.getWidth() * shape.getWidth(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/shape/Line.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.shape; 2 | 3 | public class Line extends GuiShape 4 | { 5 | public Line(float startX, float startY, float endX, float endY) 6 | { 7 | super("line", null); 8 | this.setShape(new LineShape(this::getLineThin)); 9 | this.setxTranslate(startX); 10 | this.setyTranslate(startY); 11 | 12 | this.setWidth(Math.abs(startX - endX)); 13 | this.setHeight(Math.abs(startY - endY)); 14 | 15 | this.getStyle().registerProperty("line-thin", 1f, Float.class); 16 | } 17 | 18 | public Line(float endX, float endY) 19 | { 20 | this(0, 0, endX, endY); 21 | } 22 | 23 | public Line() 24 | { 25 | this(0, 0); 26 | } 27 | 28 | public float getLineThin() 29 | { 30 | return this.getStyle().getStyleValue("line-thin", Float.class, 1f); 31 | } 32 | 33 | public void setLineThin(float lineThin) 34 | { 35 | this.getStyle().setPropertyDirect("line-thin", lineThin, Float.class); 36 | } 37 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/shape/LineShape.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.shape; 2 | 3 | import net.voxelindustry.brokkgui.data.RectBox; 4 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 5 | import net.voxelindustry.brokkgui.paint.Color; 6 | import net.voxelindustry.brokkgui.sprite.Texture; 7 | 8 | import java.util.function.Supplier; 9 | 10 | public class LineShape implements ShapeDefinition 11 | { 12 | private Supplier lineWidthSupplier; 13 | 14 | public LineShape(Supplier lineWidthSupplier) 15 | { 16 | this.lineWidthSupplier = lineWidthSupplier; 17 | } 18 | 19 | @Override 20 | public void drawColored(GuiShape shape, IGuiRenderer renderer, float startX, float startY, Color color, 21 | float zLevel, RectBox spritePosition) 22 | { 23 | renderer.getHelper().drawColoredLine(renderer, startX, startY, 24 | startX + shape.getWidth(), startY + shape.getHeight(), 25 | lineWidthSupplier.get(), zLevel, color); 26 | } 27 | 28 | @Override 29 | public void drawColoredEmpty(GuiShape shape, IGuiRenderer renderer, float startX, float startY, float lineWidth, 30 | Color color, float zLevel) 31 | { 32 | renderer.getHelper().drawColoredLine(renderer, startX, startY, 33 | startX + shape.getWidth(), startY + shape.getHeight(), 34 | lineWidthSupplier.get(), zLevel, color); 35 | } 36 | 37 | @Override 38 | public void drawTextured(GuiShape shape, IGuiRenderer renderer, float startX, float startY, Texture texture, 39 | float zLevel, RectBox spritePosition) 40 | { 41 | // TODO : Add helper for drawing textured lines 42 | } 43 | 44 | @Override 45 | public boolean isMouseInside(GuiShape shape, float mouseX, float mouseY) 46 | { 47 | if(!Rectangle.SHAPE.isMouseInside(shape, mouseX, mouseY)) // Bad behavior expected with very high line width 48 | return false; // and at line's extremities 49 | 50 | /* 51 | Let AM = (mouseX - startX, mouseY - startY) a vec2 52 | Let AB = (shapeWidth, shapeHeight) a vec2 53 | dist(M, AB) = |det(AB,AM)| / ||AB|| 54 | */ 55 | 56 | // Vector from segment beginning to mouse position 57 | float AMx = mouseX - (shape.getxPos() + shape.getxTranslate()); 58 | float AMy = mouseY - (shape.getyPos() + shape.getyTranslate()); 59 | 60 | float ABx = shape.getWidth(); 61 | float ABy = shape.getHeight(); 62 | 63 | // Remember : det(A,B) = Ax * By - Ay * Bx 64 | 65 | double dist = Math.abs(AMx * ABy - AMy * ABx) / Math.sqrt(ABx * ABx + ABy * ABy); 66 | 67 | return dist < lineWidthSupplier.get() / 4d; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/shape/Rectangle.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.shape; 2 | 3 | public class Rectangle extends GuiShape 4 | { 5 | public static final RectangleShape SHAPE = new RectangleShape(); 6 | 7 | public Rectangle(float xLeft, float yLeft, float width, float height) 8 | { 9 | super("rectangle", SHAPE); 10 | 11 | this.setxTranslate(xLeft); 12 | this.setyTranslate(yLeft); 13 | 14 | this.setWidth(width); 15 | this.setHeight(height); 16 | } 17 | 18 | public Rectangle(float width, float height) 19 | { 20 | this(0, 0, width, height); 21 | } 22 | 23 | public Rectangle() 24 | { 25 | this(0, 0, 0, 0); 26 | } 27 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/shape/ShapeDefinition.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.shape; 2 | 3 | import net.voxelindustry.brokkgui.data.RectBox; 4 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 5 | import net.voxelindustry.brokkgui.paint.Color; 6 | import net.voxelindustry.brokkgui.sprite.Texture; 7 | 8 | public interface ShapeDefinition 9 | { 10 | void drawColored(GuiShape shape, IGuiRenderer renderer, float startX, float startY, Color color, float zLevel, RectBox spritePosition); 11 | 12 | void drawColoredEmpty(GuiShape shape, IGuiRenderer renderer, float startX, float startY, float lineWidth, 13 | Color color, float zLevel); 14 | 15 | void drawTextured(GuiShape shape, IGuiRenderer renderer, float startX, float startY, Texture texture, float zLevel, RectBox spritePosition); 16 | 17 | boolean isMouseInside(GuiShape shape, float mouseX, float mouseY); 18 | } 19 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/shape/Text.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.shape; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 5 | import net.voxelindustry.brokkgui.paint.Color; 6 | import net.voxelindustry.brokkgui.paint.RenderPass; 7 | 8 | public class Text extends GuiShape 9 | { 10 | private final BaseProperty textProperty; 11 | private final BaseProperty lineSpacingProperty; 12 | 13 | public Text(float posX, float posY, String text) 14 | { 15 | super("text", Rectangle.SHAPE); 16 | 17 | this.setxTranslate(posX); 18 | this.setyTranslate(posY); 19 | 20 | this.textProperty = new BaseProperty<>(text, "textProperty"); 21 | this.lineSpacingProperty = new BaseProperty<>(1, "lineSpacingProperty"); 22 | 23 | this.getStyle().registerProperty("shadow-color", Color.WHITE, Color.class); 24 | this.getStyle().registerProperty("shadow", true, Boolean.class); 25 | 26 | this.getStyle().registerProperty("color", Color.BLACK, Color.class); 27 | } 28 | 29 | public Text(final String text) 30 | { 31 | this(0, 0, text); 32 | } 33 | 34 | @Override 35 | public void renderContent(IGuiRenderer renderer, RenderPass pass, int mouseX, int mouseY) 36 | { 37 | super.renderContent(renderer, pass, mouseX, mouseY); 38 | 39 | if (pass == RenderPass.MAIN) 40 | { 41 | renderer.getHelper().drawString(this.getText(), this.getxPos() + this.getxTranslate(), 42 | this.getyPos() + this.getyTranslate(), this.getzLevel(), 43 | this.getColor(), this.useShadow() ? this.getShadowColor() : Color.ALPHA); 44 | } 45 | } 46 | 47 | public BaseProperty getTextProperty() 48 | { 49 | return this.textProperty; 50 | } 51 | 52 | public BaseProperty getLineSpacingProperty() 53 | { 54 | return this.lineSpacingProperty; 55 | } 56 | 57 | public String getText() 58 | { 59 | return this.getTextProperty().getValue(); 60 | } 61 | 62 | public void setText(final String text) 63 | { 64 | this.getTextProperty().setValue(text); 65 | } 66 | 67 | public int getLineSpacing() 68 | { 69 | return this.getLineSpacingProperty().getValue(); 70 | } 71 | 72 | public void setLineSpacing(final int lineSpacing) 73 | { 74 | this.getLineSpacingProperty().setValue(lineSpacing); 75 | } 76 | 77 | public Color getShadowColor() 78 | { 79 | return this.getStyle().getStyleValue("shadow-color", Color.class, Color.ALPHA); 80 | } 81 | 82 | public boolean useShadow() 83 | { 84 | return this.getStyle().getStyleValue("shadow", Boolean.class, false); 85 | } 86 | 87 | public Color getColor() 88 | { 89 | return this.getStyle().getStyleValue("color", Color.class, Color.BLACK); 90 | } 91 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/skin/GuiBehaviorSkinBase.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | import net.voxelindustry.brokkgui.behavior.GuiBehaviorBase; 4 | import net.voxelindustry.brokkgui.control.GuiElement; 5 | 6 | public class GuiBehaviorSkinBase> extends GuiSkinBase 7 | { 8 | private final B behavior; 9 | 10 | public GuiBehaviorSkinBase(final C model, final B behavior) 11 | { 12 | super(model); 13 | this.behavior = behavior; 14 | } 15 | 16 | public B getBehavior() 17 | { 18 | return this.behavior; 19 | } 20 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/skin/GuiSkinBase.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.control.GuiElement; 5 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 6 | import net.voxelindustry.brokkgui.paint.RenderPass; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | public class GuiSkinBase implements IGuiSkin 12 | { 13 | private final List childrens; 14 | private final T model; 15 | 16 | public GuiSkinBase(final T model) 17 | { 18 | if (model == null) 19 | throw new IllegalArgumentException("Cannot pass a null model"); 20 | this.model = model; 21 | 22 | this.childrens = new ArrayList<>(); 23 | } 24 | 25 | public T getModel() 26 | { 27 | return this.model; 28 | } 29 | 30 | @Override 31 | public void render(final RenderPass pass, final IGuiRenderer renderer, final int mouseX, final int mouseY) 32 | { 33 | } 34 | 35 | public List getChildrens() 36 | { 37 | return this.childrens; 38 | } 39 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/skin/IGuiSkin.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 4 | import net.voxelindustry.brokkgui.paint.RenderPass; 5 | 6 | public interface IGuiSkin 7 | { 8 | void render(final RenderPass pass, final IGuiRenderer renderer, int mouseX, int mouseY); 9 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/skin/IGuiSkinnable.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | public interface IGuiSkinnable 4 | { 5 | GuiSkinBase getSkin(); 6 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/sprite/RandomSpriteRotation.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.sprite; 2 | 3 | import java.util.Map; 4 | import java.util.Objects; 5 | 6 | public class RandomSpriteRotation 7 | { 8 | private Map chanceByRotation; 9 | 10 | public RandomSpriteRotation(Map chanceByRotation) 11 | { 12 | this.chanceByRotation = chanceByRotation; 13 | } 14 | 15 | public Map getChanceByRotation() 16 | { 17 | return chanceByRotation; 18 | } 19 | 20 | @Override 21 | public boolean equals(Object o) 22 | { 23 | if (this == o) return true; 24 | if (o == null || getClass() != o.getClass()) return false; 25 | RandomSpriteRotation that = (RandomSpriteRotation) o; 26 | return Objects.equals(chanceByRotation, that.chanceByRotation); 27 | } 28 | 29 | @Override 30 | public int hashCode() 31 | { 32 | return Objects.hash(chanceByRotation); 33 | } 34 | 35 | @Override 36 | public String toString() 37 | { 38 | return "RandomSpriteRotation{" + 39 | "chanceByRotation=" + chanceByRotation + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/sprite/SpriteAnimation.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.sprite; 2 | 3 | import java.util.Map; 4 | 5 | public class SpriteAnimation 6 | { 7 | private boolean vertical; 8 | 9 | private int frameCount; 10 | private long durationMillis; 11 | 12 | private Map frameTimeMillisByFrameIndex; 13 | 14 | public SpriteAnimation(boolean vertical, int frameCount, Map frameTimeMillisByFrameIndex) 15 | { 16 | this.vertical = vertical; 17 | this.frameCount = frameCount; 18 | this.frameTimeMillisByFrameIndex = frameTimeMillisByFrameIndex; 19 | 20 | this.durationMillis = frameTimeMillisByFrameIndex.get(frameTimeMillisByFrameIndex.size() - 1); 21 | } 22 | 23 | public SpriteAnimationInstance instantiate() 24 | { 25 | return new SpriteAnimationInstance(vertical, frameCount, frameTimeMillisByFrameIndex); 26 | } 27 | 28 | public boolean isVertical() 29 | { 30 | return vertical; 31 | } 32 | 33 | public int getFrameCount() 34 | { 35 | return frameCount; 36 | } 37 | 38 | public long getDurationMillis() 39 | { 40 | return durationMillis; 41 | } 42 | 43 | public Map getFrameTimeMillisByFrameIndex() 44 | { 45 | return frameTimeMillisByFrameIndex; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/sprite/SpriteAnimationInstance.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.sprite; 2 | 3 | import java.util.Map; 4 | 5 | public class SpriteAnimationInstance extends SpriteAnimation 6 | { 7 | private final Texture[] computedTextures; 8 | private long startTimeMillis; 9 | 10 | public SpriteAnimationInstance(boolean vertical, int frameCount, Map frameTimeMillisByFrameIndex) 11 | { 12 | super(vertical, frameCount, frameTimeMillisByFrameIndex); 13 | this.computedTextures = new Texture[frameCount]; 14 | } 15 | 16 | public void start(long currentTimeMillis) 17 | { 18 | this.startTimeMillis = currentTimeMillis; 19 | } 20 | 21 | public Texture getCurrentFrame(long currentTimeMillis) 22 | { 23 | if (currentTimeMillis - this.startTimeMillis > this.getDurationMillis()) 24 | { 25 | this.startTimeMillis = currentTimeMillis - (currentTimeMillis - this.startTimeMillis) % this.getDurationMillis(); 26 | } 27 | 28 | int index; 29 | for (index = 0; index < this.getFrameCount(); index++) 30 | { 31 | if (this.getFrameTimeMillisByFrameIndex().get(index) >= currentTimeMillis - this.startTimeMillis) 32 | break; 33 | } 34 | 35 | return this.computedTextures[index]; 36 | } 37 | 38 | public void computeTextures(Texture origin) 39 | { 40 | for (int frame = 0; frame < getFrameCount(); frame++) 41 | { 42 | if (this.isVertical()) 43 | { 44 | this.computedTextures[frame] = new Texture( 45 | origin.getResource(), 46 | origin.getUMin(), 47 | (origin.getVMax() - origin.getVMin()) / getFrameCount() * frame + origin.getVMin(), 48 | origin.getUMax(), 49 | (origin.getVMax() - origin.getVMin()) / getFrameCount() * (frame + 1) + origin.getVMin(), 50 | origin.getPixelWidth(), 51 | origin.getPixelHeight()); 52 | } 53 | else 54 | { 55 | this.computedTextures[frame] = new Texture( 56 | origin.getResource(), 57 | (origin.getUMax() - origin.getUMin()) / getFrameCount() * frame + origin.getUMin(), 58 | origin.getVMin(), 59 | (origin.getUMax() - origin.getUMin()) / getFrameCount() * (frame + 1) + origin.getUMin(), 60 | origin.getVMax(), 61 | origin.getPixelWidth(), 62 | origin.getPixelHeight()); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/sprite/SpriteRepeat.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.sprite; 2 | 3 | import static java.lang.Math.ceil; 4 | 5 | public enum SpriteRepeat 6 | { 7 | NONE, 8 | REPEAT_X, 9 | REPEAT_Y, 10 | REPEAT_BOTH; 11 | 12 | public int getRepeatCount(Texture texture, float width, float height) 13 | { 14 | switch (this) 15 | { 16 | case NONE: 17 | return 1; 18 | case REPEAT_X: 19 | return (int) ceil(width / texture.getPixelWidth()); 20 | case REPEAT_Y: 21 | return (int) ceil(height / texture.getPixelHeight()); 22 | case REPEAT_BOTH: 23 | return (int) (ceil(width / texture.getPixelWidth()) * ceil(height / texture.getPixelHeight())); 24 | } 25 | return 0; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/sprite/SpriteRotation.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.sprite; 2 | 3 | public enum SpriteRotation 4 | { 5 | NONE, 6 | CLOCKWISE, 7 | UPSIDE, 8 | COUNTERCLOCKWISE; 9 | } 10 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/style/adapter/BackgroundRepeatStyleTranslator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import net.voxelindustry.brokkgui.sprite.SpriteRepeat; 4 | 5 | public class BackgroundRepeatStyleTranslator implements IStyleDecoder, IStyleEncoder, IStyleValidator 6 | { 7 | @Override 8 | public SpriteRepeat decode(String style) 9 | { 10 | switch (style) 11 | { 12 | case "none": 13 | return SpriteRepeat.NONE; 14 | case "repeat-x": 15 | return SpriteRepeat.REPEAT_X; 16 | case "repeat-y": 17 | return SpriteRepeat.REPEAT_Y; 18 | case "repeat": 19 | return SpriteRepeat.REPEAT_BOTH; 20 | } 21 | throw new IllegalArgumentException("Cannot decode BackgroundRepeat value of [" + style + "]"); 22 | } 23 | 24 | @Override 25 | public String encode(SpriteRepeat value, boolean prettyPrint) 26 | { 27 | switch (value) 28 | { 29 | case NONE: 30 | return "none"; 31 | case REPEAT_X: 32 | return "repeat-x"; 33 | case REPEAT_Y: 34 | return "repeat-y"; 35 | case REPEAT_BOTH: 36 | return "repeat"; 37 | } 38 | throw new RuntimeException("Unknown value given to BackgroundRepeatStyleTranslator! " + value.name()); 39 | } 40 | 41 | @Override 42 | public int validate(String style) 43 | { 44 | switch (style) 45 | { 46 | case "none": 47 | return 4; 48 | case "repeat-x": 49 | case "repeat-y": 50 | return 8; 51 | case "repeat": 52 | return 6; 53 | } 54 | return 0; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/style/adapter/RandomSpriteRotationStyleTranslator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import com.google.common.base.Enums; 4 | import net.voxelindustry.brokkgui.sprite.RandomSpriteRotation; 5 | import net.voxelindustry.brokkgui.sprite.SpriteRotation; 6 | 7 | import java.util.EnumMap; 8 | import java.util.Map; 9 | import java.util.Objects; 10 | 11 | public class RandomSpriteRotationStyleTranslator implements IStyleDecoder, IStyleEncoder, IStyleValidator 12 | { 13 | @Override 14 | public RandomSpriteRotation decode(String style) 15 | { 16 | String[] parts = style.split(" "); 17 | 18 | EnumMap rotations = new EnumMap<>(SpriteRotation.class); 19 | SpriteRotation rotation = null; 20 | 21 | for (String part : parts) 22 | { 23 | String trimmedPart = part.trim(); 24 | if (trimmedPart.endsWith("%")) 25 | { 26 | if (rotation != null) 27 | rotations.put(rotation, Float.parseFloat(trimmedPart.replace("%", "")) / 100); 28 | continue; 29 | } 30 | 31 | rotation = Enums.getIfPresent(SpriteRotation.class, trimmedPart.toUpperCase()).toJavaUtil() 32 | .orElseThrow(() -> new RuntimeException("Cannot parse SpriteRotation argument. value=" + trimmedPart)); 33 | rotations.put(rotation, null); 34 | } 35 | 36 | double total = rotations.values().stream().filter(Objects::nonNull).mapToDouble(Float::doubleValue).sum(); 37 | long nullCount = rotations.values().stream().filter(Objects::isNull).count(); 38 | 39 | if (nullCount != 0) 40 | { 41 | rotations.forEach((rotationKey, chanceValue) -> 42 | { 43 | if (chanceValue == null) 44 | rotations.put(rotationKey, (float) ((1 - total) / nullCount)); 45 | }); 46 | } 47 | else 48 | rotations.put(SpriteRotation.NONE, (float) (rotations.getOrDefault(SpriteRotation.NONE, 0F) + (1 - total))); 49 | 50 | return new RandomSpriteRotation(rotations); 51 | } 52 | 53 | @Override 54 | public String encode(RandomSpriteRotation value, boolean prettyPrint) 55 | { 56 | String result = ""; 57 | 58 | for (Map.Entry entry : value.getChanceByRotation().entrySet()) 59 | { 60 | SpriteRotation rotation = entry.getKey(); 61 | Float chance = entry.getValue(); 62 | result = result.concat(rotation.name()).concat(" ").concat(String.valueOf(chance)).concat("% "); 63 | } 64 | return result.trim(); 65 | } 66 | 67 | @Override 68 | public int validate(String style) 69 | { 70 | // TODO: RandomSpriteRotation validator 71 | return 0; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/style/adapter/ResourceStyleTranslator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import net.voxelindustry.brokkgui.BrokkGuiPlatform; 4 | import net.voxelindustry.brokkgui.data.Resource; 5 | 6 | public class ResourceStyleTranslator implements IStyleDecoder, IStyleEncoder, IStyleValidator 7 | { 8 | @Override 9 | public Resource decode(String style) 10 | { 11 | String[] pathWithKey = style.split("\\("); 12 | 13 | String key = pathWithKey[0].trim(); 14 | String path = pathWithKey[1].replace(")", "").replace("\"", ""); 15 | 16 | if (!BrokkGuiPlatform.getInstance().getResourceHandler().isTypeSupported(key)) 17 | throw new UnsupportedOperationException("Unsupported resource type used. Check that your current binding resource support. type=" + key); 18 | 19 | return new Resource(key, path); 20 | } 21 | 22 | @Override 23 | public String encode(Resource value, boolean prettyPrint) 24 | { 25 | return value.getPath(); 26 | } 27 | 28 | @Override 29 | public int validate(String style) 30 | { 31 | return style.substring(0, style.indexOf(')') + 1).length(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/style/adapter/StyleEngine.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import net.voxelindustry.brokkgui.data.RectAlignment; 4 | import net.voxelindustry.brokkgui.data.RectBox; 5 | import net.voxelindustry.brokkgui.data.Resource; 6 | import net.voxelindustry.brokkgui.paint.Color; 7 | import net.voxelindustry.brokkgui.sprite.RandomSpriteRotation; 8 | import net.voxelindustry.brokkgui.sprite.SpriteRepeat; 9 | import net.voxelindustry.brokkgui.sprite.Texture; 10 | 11 | public class StyleEngine 12 | { 13 | private static StyleEngine instance; 14 | 15 | public static StyleEngine getInstance() 16 | { 17 | if (instance == null) 18 | instance = new StyleEngine(); 19 | return instance; 20 | } 21 | 22 | private StyleEngine() 23 | { 24 | 25 | } 26 | 27 | public void start() 28 | { 29 | StyleTranslator.getInstance().registerTranslator(Color.class, new ColorStyleTranslator()); 30 | StyleTranslator.getInstance().registerTranslator(Texture.class, new TextureStyleTranslator()); 31 | 32 | StyleTranslator.getInstance().registerTranslator(RectBox.class, new RectBoxTranslator()); 33 | 34 | StyleTranslator.getInstance().registerTranslator(SpriteRepeat.class, new BackgroundRepeatStyleTranslator()); 35 | 36 | StyleTranslator.getInstance().registerTranslator(Resource.class, new ResourceStyleTranslator()); 37 | 38 | StyleTranslator.getInstance().registerTranslator(RandomSpriteRotation.class, new RandomSpriteRotationStyleTranslator()); 39 | 40 | StyleTranslator.getInstance().registerTranslator(RectAlignment.class, new RectAlignmentStyleTranslator()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/style/optional/BorderImageProperties.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.optional; 2 | 3 | import net.voxelindustry.brokkgui.data.RectBox; 4 | import net.voxelindustry.brokkgui.sprite.Texture; 5 | import net.voxelindustry.brokkgui.style.StyleHolder; 6 | import net.voxelindustry.brokkgui.style.StyleProperty; 7 | 8 | import java.util.function.Consumer; 9 | 10 | public class BorderImageProperties implements Consumer 11 | { 12 | private static BorderImageProperties instance; 13 | 14 | public static BorderImageProperties getInstance() 15 | { 16 | if (instance == null) 17 | instance = new BorderImageProperties(); 18 | return instance; 19 | } 20 | 21 | private BorderImageProperties() 22 | { 23 | 24 | } 25 | 26 | @Override 27 | public void accept(StyleHolder holder) 28 | { 29 | StyleProperty borderTextureProperty = holder.registerProperty("border-image-source", Texture.EMPTY, 30 | Texture.class); 31 | 32 | StyleProperty borderImageWidthProperty = holder.registerProperty("border-image-width", 33 | RectBox.build().all(1).create(), RectBox.class); 34 | 35 | StyleProperty borderImageOutsetProperty = holder.registerProperty("border-image-outset", 36 | RectBox.build().all(0).create(), RectBox.class); 37 | 38 | StyleProperty borderImageSliceProperty = holder.registerProperty("border-image-slice", 39 | RectBox.build().all(1).create(), RectBox.class); 40 | 41 | StyleProperty borderImageFill = holder.registerProperty("border-image-fill", false, Boolean.class); 42 | 43 | holder.registerGenericShorthand("border-image", "", borderTextureProperty, 44 | borderImageSliceProperty, borderImageWidthProperty, borderImageOutsetProperty, borderImageFill); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/style/optional/BorderProperties.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.optional; 2 | 3 | import net.voxelindustry.brokkgui.paint.Color; 4 | import net.voxelindustry.brokkgui.style.StyleHolder; 5 | import net.voxelindustry.brokkgui.style.StyleProperty; 6 | import net.voxelindustry.brokkgui.style.shorthand.ShorthandArgMappers; 7 | import net.voxelindustry.brokkgui.style.shorthand.ShorthandProperty; 8 | 9 | import java.util.function.Consumer; 10 | 11 | public class BorderProperties implements Consumer 12 | { 13 | private static BorderProperties instance; 14 | 15 | public static BorderProperties getInstance() 16 | { 17 | if (instance == null) 18 | instance = new BorderProperties(); 19 | return instance; 20 | } 21 | 22 | private BorderProperties() 23 | { 24 | 25 | } 26 | 27 | @Override 28 | public void accept(StyleHolder holder) 29 | { 30 | StyleProperty borderColorProperty = holder.registerProperty("border-color", Color.BLACK, Color.class); 31 | 32 | ShorthandProperty borderWidthProperty = holder.registerShorthand("border-width", 0f, 33 | Float.class, ShorthandArgMappers.BOX_MAPPER, 34 | "border-top-width", "border-right-width", "border-bottom-width", "border-left-width"); 35 | 36 | 37 | holder.registerShorthand("border-radius", 0, Integer.class, ShorthandArgMappers.BOX_MAPPER, 38 | "border-top-left-radius", "border-top-right-radius", 39 | "border-bottom-right-radius", "border-bottom-left-radius"); 40 | 41 | holder.registerGenericShorthand("border", "", borderColorProperty, borderWidthProperty); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/util/ListUtil.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.util; 2 | 3 | import java.util.List; 4 | import java.util.Optional; 5 | 6 | import static java.util.Optional.empty; 7 | import static java.util.Optional.ofNullable; 8 | 9 | public class ListUtil 10 | { 11 | public static Optional tryGetIndex(List list, int index) 12 | { 13 | if (list.size() > index && index >= 0) 14 | return ofNullable(list.get(index)); 15 | return empty(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/util/MathUtils.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.util; 2 | 3 | public class MathUtils 4 | { 5 | public static float clamp(float minValue, float maxValue, float toClamp) 6 | { 7 | return toClamp < minValue ? minValue : (toClamp > maxValue ? maxValue : toClamp); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/validation/AlphaNumericTextValidator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.validation; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | public class AlphaNumericTextValidator extends BaseTextValidator 6 | { 7 | public AlphaNumericTextValidator() 8 | { 9 | this.setMessage("Invalid input, only AlphaNumeric text is supported !"); 10 | } 11 | 12 | @Override 13 | public boolean eval(final String data) 14 | { 15 | return StringUtils.isAlphanumeric(data); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/validation/AsciiPrintableTextValidator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.validation; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | public class AsciiPrintableTextValidator extends BaseTextValidator 6 | { 7 | public AsciiPrintableTextValidator() 8 | { 9 | this.setMessage("Only printable characters are supported !"); 10 | } 11 | 12 | @Override 13 | public boolean eval(final String data) 14 | { 15 | return StringUtils.isAsciiPrintable(data); 16 | } 17 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/validation/BaseTextValidator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.validation; 2 | 3 | public abstract class BaseTextValidator implements ITextValidator 4 | { 5 | private String message; 6 | private boolean isErrored; 7 | 8 | @Override 9 | public boolean validate(final String data) 10 | { 11 | if (!this.eval(data)) 12 | this.setErrored(true); 13 | return this.isErrored; 14 | } 15 | 16 | public boolean isErrored() 17 | { 18 | return this.isErrored; 19 | } 20 | 21 | public void setErrored(final boolean isErrored) 22 | { 23 | this.isErrored = isErrored; 24 | } 25 | 26 | @Override 27 | public String toString() 28 | { 29 | return "BaseTextValidator [isErrored=" + this.isErrored + "]"; 30 | } 31 | 32 | @Override 33 | public void setMessage(final String message) 34 | { 35 | this.message = message; 36 | } 37 | 38 | @Override 39 | public String getMessage() 40 | { 41 | return this.message; 42 | } 43 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/validation/IDataValidator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.validation; 2 | 3 | public interface IDataValidator 4 | { 5 | void setMessage(String message); 6 | 7 | String getMessage(); 8 | 9 | boolean validate(T data); 10 | 11 | boolean eval(T data); 12 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/validation/ITextValidator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.validation; 2 | 3 | public interface ITextValidator extends IDataValidator 4 | { 5 | 6 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/validation/NumericTextValidator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.validation; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | public class NumericTextValidator extends BaseTextValidator 6 | { 7 | public NumericTextValidator() 8 | { 9 | this.setMessage("Only numbers are allowed !"); 10 | } 11 | 12 | @Override 13 | public boolean eval(final String data) 14 | { 15 | return StringUtils.isNumeric(data); 16 | } 17 | } -------------------------------------------------------------------------------- /common/src/main/java/net/voxelindustry/brokkgui/validation/RequiredInputTextValidator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.validation; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | 5 | public class RequiredInputTextValidator extends BaseTextValidator 6 | { 7 | public RequiredInputTextValidator() 8 | { 9 | this.setMessage("Cannot be blank. Input is required !"); 10 | } 11 | 12 | @Override 13 | public boolean eval(final String data) 14 | { 15 | return StringUtils.isEmpty(data); 16 | } 17 | } -------------------------------------------------------------------------------- /common/src/main/resources/assets/brokkgui/css/user_agent.css: -------------------------------------------------------------------------------- 1 | scrollpane > .grip-x, scrollpane > .grip-y { 2 | background-color: lightgrey; 3 | } 4 | 5 | progressbar > .track { 6 | background-color: red; 7 | } 8 | 9 | radio-button >> .box { 10 | background-color: rgba(0, 0, 0, 0); 11 | border-color: black; 12 | border-width: 1; 13 | } 14 | 15 | radio-button >> .mark { 16 | background-color: black; 17 | } 18 | 19 | checkbox >> .box { 20 | background-color: rgba(0, 0, 0, 0); 21 | border-color: black; 22 | border-width: 1; 23 | } 24 | 25 | checkbox >> .mark { 26 | background-color: gray; 27 | } 28 | 29 | textfield .text { 30 | color: white; 31 | shadow-color: #4c4c4c; 32 | } 33 | 34 | textfield .prompt { 35 | color: #7f7f7f; 36 | shadow: false; 37 | } 38 | 39 | label > text { 40 | shadow: false; 41 | color: #404040; 42 | } -------------------------------------------------------------------------------- /common/src/main/resources/mcmod.info: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "modid": "brokkgui", 4 | "name": "BrokkGui", 5 | "description": "An API to add some swing-like utilities to minecraft gui drawing.", 6 | "version": "${version}", 7 | "mcversion": "${mcversion}", 8 | "url": "", 9 | "updateUrl": "", 10 | "authorList": ["Ourten"], 11 | "credits": "Ourten for the code", 12 | "logoFile": "", 13 | "screenshots": [], 14 | "dependencies": [] 15 | } 16 | ] 17 | -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/paint/Color1DGradientTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.paint; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.assertj.core.api.Assertions.assertThat; 6 | 7 | public class Color1DGradientTest 8 | { 9 | @Test 10 | public void twoValuesGradient() 11 | { 12 | Color1DGradient gradient = Color1DGradient.build().color(Color.RED, 0).color(Color.YELLOW, 1).create(); 13 | 14 | assertThat(gradient.getValue(0)).isEqualTo(Color.RED); 15 | assertThat(gradient.getValue(1)).isEqualTo(Color.YELLOW); 16 | } 17 | 18 | @Test 19 | public void twoValuesCachedGradient() 20 | { 21 | Color1DGradient gradient = Color1DGradient.build().color(Color.RED, 0).color(Color.YELLOW, 1).precompute(0.5f).create(); 22 | 23 | assertThat(gradient.getValue(0)).isEqualTo(Color.RED); 24 | assertThat(gradient.getValue(1)).isEqualTo(Color.YELLOW); 25 | } 26 | 27 | @Test 28 | public void threeValuesWrappingGradient() 29 | { 30 | Color1DGradient gradient = Color1DGradient.build().color(Color.RED, 0).color(Color.YELLOW, 0.5f).color(Color.RED, 1).create(); 31 | 32 | assertThat(gradient.getValue(0)).isEqualTo(Color.RED); 33 | assertThat(gradient.getValue(0.5f)).isEqualTo(Color.YELLOW); 34 | assertThat(gradient.getValue(1)).isEqualTo(Color.RED); 35 | 36 | assertThat(gradient.getValue(0.25f)).isEqualTo(Color.RED.interpolate(Color.YELLOW, 0.5f)); 37 | assertThat(gradient.getValue(0.75f)).isEqualTo(Color.RED.interpolate(Color.YELLOW, 0.5f)); 38 | } 39 | 40 | @Test 41 | public void threeValuesWrappingCachedGradient() 42 | { 43 | Color1DGradient gradient = Color1DGradient.build().color(Color.RED, 0).color(Color.YELLOW, 0.5f).color(Color.RED, 1).precompute(0.05f).create(); 44 | 45 | assertThat(gradient.getValue(0)).isEqualTo(Color.RED); 46 | assertThat(gradient.getValue(0.5f)).isEqualTo(Color.YELLOW); 47 | assertThat(gradient.getValue(1)).isEqualTo(Color.RED); 48 | 49 | assertThat(gradient.getValue(0.25f)).isEqualTo(Color.RED.interpolate(Color.YELLOW, 0.5f)); 50 | assertThat(gradient.getValue(0.75f)).isEqualTo(Color.RED.interpolate(Color.YELLOW, 0.5f)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/paint/ColorTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.paint; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.api.extension.ExtendWith; 5 | import org.mockito.junit.jupiter.MockitoExtension; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | @ExtendWith(MockitoExtension.class) 10 | public class ColorTest 11 | { 12 | @Test 13 | public void rgbTranslation() 14 | { 15 | assertThat(Color.fromRGBInt(16711680)).isEqualTo(Color.RED); 16 | assertThat(Color.RED.toRGBInt()).isEqualTo(16711680); 17 | } 18 | 19 | @Test 20 | public void hexTranslation() 21 | { 22 | assertThat(Color.fromHex("#00FFFF")).isEqualTo(Color.AQUA); 23 | assertThat(Color.AQUA.toHex()).isEqualToIgnoringCase("#00FFFF"); 24 | } 25 | 26 | @Test 27 | public void copy() 28 | { 29 | assertThat(Color.from(Color.RED)).isEqualTo(Color.RED); 30 | } 31 | 32 | @Test 33 | public void modifiers() 34 | { 35 | assertThat(Color.RED.addGreen(0.1f).getGreen()).isEqualTo(0.1f); 36 | assertThat(Color.BLUE.addRed(0.1f).getRed()).isEqualTo(0.1f); 37 | assertThat(Color.RED.addBlue(0.1f).getBlue()).isEqualTo(0.1f); 38 | assertThat(Color.BLACK.addAlpha(-0.1f).getAlpha()).isEqualTo(0.9f); 39 | 40 | assertThat(Color.WHITE.shade(0.1f)).isEqualTo(new Color(0.9f, 0.9f, 0.9f)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/sprite/SpriteAnimationInstanceTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.sprite; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | public class SpriteAnimationInstanceTest 11 | { 12 | @Test 13 | public void getCurrentTexture_givenFourFramesWithLinearTime_thenShouldReturnCorrectFrameAtGivenTime() 14 | { 15 | Map frames = new HashMap<>(); 16 | frames.put(0, 250L); 17 | frames.put(1, 500L); 18 | frames.put(2, 750L); 19 | frames.put(3, 1000L); 20 | 21 | Texture texture = new Texture("blabla", 0, 0, 1, 1); 22 | 23 | SpriteAnimation spriteAnimation = new SpriteAnimation(false, 4, frames); 24 | SpriteAnimationInstance spriteAnimationInstance = spriteAnimation.instantiate(); 25 | 26 | spriteAnimationInstance.computeTextures(texture); 27 | spriteAnimationInstance.start(0); 28 | 29 | assertThat(spriteAnimationInstance.getCurrentFrame(1)) 30 | .isEqualTo(new Texture("blabla", 0, 0, 0.25F, 1)); 31 | assertThat(spriteAnimationInstance.getCurrentFrame(251)) 32 | .isEqualTo(new Texture("blabla", 0.25F, 0, 0.5F, 1)); 33 | assertThat(spriteAnimationInstance.getCurrentFrame(501)) 34 | .isEqualTo(new Texture("blabla", 0.5F, 0, 0.75F, 1)); 35 | assertThat(spriteAnimationInstance.getCurrentFrame(751)) 36 | .isEqualTo(new Texture("blabla", 0.75F, 0, 1, 1)); 37 | } 38 | 39 | @Test 40 | public void getCurrentTexture_givenFourFramesWithLinearTime_andTimeOutsideDuration_thenShouldLoopBack() 41 | { 42 | Map frames = new HashMap<>(); 43 | frames.put(0, 250L); 44 | frames.put(1, 500L); 45 | frames.put(2, 750L); 46 | frames.put(3, 1000L); 47 | 48 | Texture texture = new Texture("blabla", 0, 0, 1, 1); 49 | 50 | SpriteAnimation spriteAnimation = new SpriteAnimation(false, 4, frames); 51 | SpriteAnimationInstance spriteAnimationInstance = spriteAnimation.instantiate(); 52 | 53 | spriteAnimationInstance.computeTextures(texture); 54 | spriteAnimationInstance.start(0); 55 | 56 | assertThat(spriteAnimationInstance.getCurrentFrame(1001)) 57 | .isEqualTo(new Texture("blabla", 0, 0, 0.25F, 1)); 58 | assertThat(spriteAnimationInstance.getCurrentFrame(1251)) 59 | .isEqualTo(new Texture("blabla", 0.25F, 0, 0.5F, 1)); 60 | assertThat(spriteAnimationInstance.getCurrentFrame(1501)) 61 | .isEqualTo(new Texture("blabla", 0.5F, 0, 0.75F, 1)); 62 | assertThat(spriteAnimationInstance.getCurrentFrame(1751)) 63 | .isEqualTo(new Texture("blabla", 0.75F, 0, 1, 1)); 64 | } 65 | } -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/sprite/SpriteAnimationParserTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.sprite; 2 | 3 | import org.apache.commons.io.IOUtils; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.IOException; 7 | import java.nio.charset.StandardCharsets; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | public class SpriteAnimationParserTest 12 | { 13 | @Test 14 | public void parse() 15 | { 16 | String json = null; 17 | try 18 | { 19 | json = IOUtils.toString(SpriteAnimationParserTest.class.getResourceAsStream("/assets/brokkgui/animation/sprite_animation.json"), StandardCharsets.UTF_8); 20 | } catch (IOException e) 21 | { 22 | e.printStackTrace(); 23 | } 24 | 25 | SpriteAnimation spriteAnimation = SpriteAnimationParser.parse(json); 26 | 27 | assertThat(spriteAnimation.getFrameCount()).isEqualTo(9); 28 | assertThat(spriteAnimation.isVertical()).isTrue(); 29 | 30 | assertThat(spriteAnimation.getFrameTimeMillisByFrameIndex()).hasSize(9); 31 | assertThat(spriteAnimation.getFrameTimeMillisByFrameIndex()).containsEntry(0, 111L); 32 | assertThat(spriteAnimation.getFrameTimeMillisByFrameIndex()).containsEntry(8, 1888L); 33 | } 34 | } -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/style/StyleHolderTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | import net.voxelindustry.brokkgui.paint.Color; 4 | import net.voxelindustry.brokkgui.style.adapter.StyleEngine; 5 | import net.voxelindustry.brokkgui.style.optional.BorderProperties; 6 | import org.junit.jupiter.api.BeforeEach; 7 | import org.junit.jupiter.api.Test; 8 | import org.junit.jupiter.api.extension.ExtendWith; 9 | import org.mockito.junit.jupiter.MockitoExtension; 10 | 11 | import static org.assertj.core.api.Assertions.assertThat; 12 | 13 | @ExtendWith(MockitoExtension.class) 14 | public class StyleHolderTest 15 | { 16 | @BeforeEach 17 | public void before() 18 | { 19 | StyleEngine.getInstance().start(); 20 | } 21 | 22 | @Test 23 | public void parseSimpleCSS() 24 | { 25 | StyleHolder styleHolder = new StyleHolder(null); 26 | 27 | styleHolder.registerProperty("border-width", 0, Integer.class); 28 | styleHolder.registerProperty("border-color", Color.BLACK, Color.class); 29 | styleHolder.registerProperty("color", Color.WHITE, Color.class); 30 | 31 | styleHolder.parseInlineCSS("color: aqua; border-color: red; border-width: 2;"); 32 | 33 | assertThat(styleHolder.getStyleProperty("border-width", Integer.class).getValue()).isEqualTo(2); 34 | assertThat(styleHolder.getStyleProperty("border-color", Color.class).getValue()).isEqualTo(Color.RED); 35 | assertThat(styleHolder.getStyleProperty("color", Color.class).getValue()).isEqualTo(Color.AQUA); 36 | } 37 | 38 | @Test 39 | public void parseConditionalProperties() 40 | { 41 | StyleHolder styleHolder = new StyleHolder(null); 42 | 43 | assertThat(styleHolder.doesHoldProperty("border-color")).isEqualTo(HeldPropertyState.ABSENT); 44 | 45 | styleHolder.registerConditionalProperties("border*", BorderProperties.getInstance()); 46 | 47 | assertThat(styleHolder.doesHoldProperty("border-color")).isEqualTo(HeldPropertyState.CONDITIONAL); 48 | styleHolder.parseInlineCSS("border-color: red;"); 49 | 50 | assertThat(styleHolder.doesHoldProperty("border-color")).isEqualTo(HeldPropertyState.PRESENT); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/style/StylePropertyTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | import net.voxelindustry.brokkgui.style.adapter.StyleEngine; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | public class StylePropertyTest 10 | { 11 | @BeforeEach 12 | public void init() 13 | { 14 | StyleEngine.getInstance().start(); 15 | } 16 | 17 | @Test 18 | public void forcefullSet() 19 | { 20 | String defaultValue = "defaultValue"; 21 | String codeValue = "codeValue"; 22 | String authorValue = "authorValue"; 23 | 24 | StyleProperty styleProperty = new StyleProperty<>(defaultValue, "name", String.class); 25 | 26 | assertThat(styleProperty.getValue()).isEqualTo(defaultValue); 27 | 28 | styleProperty.setValue(codeValue); 29 | assertThat(styleProperty.getValue()).isEqualTo(codeValue); 30 | 31 | styleProperty.setToDefault(); 32 | 33 | assertThat(styleProperty.getValue()).isEqualTo(defaultValue); 34 | 35 | styleProperty.setStyle(StyleSource.AUTHOR, 10, authorValue); 36 | assertThat(styleProperty.getValue()).isEqualTo(authorValue); 37 | 38 | styleProperty.setValue(codeValue); 39 | 40 | assertThat(styleProperty.getValue()).isEqualTo(codeValue); 41 | 42 | // AUTHOR has lowest priority than CODE 43 | // Value should not be changed 44 | styleProperty.setStyle(StyleSource.AUTHOR, 10, authorValue); 45 | assertThat(styleProperty.getValue()).isNotEqualTo(authorValue).isEqualTo(codeValue); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/style/adapter/ColorStyleTranslatorTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import net.voxelindustry.brokkgui.paint.Color; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.extension.ExtendWith; 7 | import org.mockito.junit.jupiter.MockitoExtension; 8 | 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | import static org.assertj.core.api.Assertions.assertThatThrownBy; 11 | 12 | @ExtendWith(MockitoExtension.class) 13 | public class ColorStyleTranslatorTest 14 | { 15 | private ColorStyleTranslator adapter; 16 | 17 | @BeforeEach 18 | public void init() 19 | { 20 | this.adapter = new ColorStyleTranslator(); 21 | } 22 | 23 | @Test 24 | public void testHexDecode() 25 | { 26 | Color color = Color.fromHex("#ffaa25"); 27 | 28 | assertThat(adapter.decode("#ffaa25")).isEqualTo(color); 29 | 30 | Color color2 = Color.fromHex("#aaff25", 0.3f); 31 | 32 | assertThat(adapter.decode("#aaff25 30%")).isEqualTo(color2); 33 | } 34 | 35 | @Test 36 | public void testRGBDecode() 37 | { 38 | Color color = new Color(0.2f, 0.2f, 0.2f); 39 | 40 | assertThat(adapter.decode("rgb( 20%,20% ,20%)")).isEqualTo(color); 41 | assertThat(adapter.decode("rgb( 51, 51,51)")).isEqualTo(color); 42 | } 43 | 44 | @Test 45 | public void testRGBADecode() 46 | { 47 | Color color = new Color(0.2f, 0.2f, 0.2f, 0.5f); 48 | 49 | assertThat(adapter.decode("rgba( 20%,20% ,20%, 0.5)")).isEqualTo(color); 50 | assertThat(adapter.decode("rgba( 51, 51,51,0.5 )")).isEqualTo(color); 51 | } 52 | 53 | @Test 54 | public void testColorNameDecode() 55 | { 56 | Color color = Color.AQUA; 57 | 58 | assertThat(adapter.decode("aqua")).isEqualTo(color); 59 | } 60 | 61 | @Test 62 | public void testError() 63 | { 64 | assertThatThrownBy(() -> adapter.decode("abcdef")).hasMessageContaining("Cannot retrieve specified Color constant."); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/style/adapter/RandomSpriteRotationStyleTranslatorTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import net.voxelindustry.brokkgui.sprite.RandomSpriteRotation; 4 | import org.assertj.core.data.MapEntry; 5 | import org.junit.jupiter.api.BeforeEach; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import static net.voxelindustry.brokkgui.sprite.SpriteRotation.*; 9 | import static org.assertj.core.api.Assertions.assertThat; 10 | 11 | public class RandomSpriteRotationStyleTranslatorTest 12 | { 13 | private RandomSpriteRotationStyleTranslator translator; 14 | 15 | @BeforeEach 16 | public void setup() 17 | { 18 | translator = new RandomSpriteRotationStyleTranslator(); 19 | } 20 | 21 | @Test 22 | public void decode_givenOneRotationWithoutChance_thenShouldGiveOneRotationWithFullChance() 23 | { 24 | String simpleRotation = "clockwise"; 25 | 26 | RandomSpriteRotation randomSpriteRotation = translator.decode(simpleRotation); 27 | 28 | assertThat(randomSpriteRotation.getChanceByRotation()).containsExactly(MapEntry.entry(CLOCKWISE, 1F)); 29 | } 30 | 31 | @Test 32 | public void decode_givenOneRotationWithChance_thenShouldGiveOneRotationWithChanceAndNoRotationWithRemainingChance() 33 | { 34 | String rotationWithChance = "clockwise 20%"; 35 | 36 | RandomSpriteRotation randomSpriteRotation = translator.decode(rotationWithChance); 37 | 38 | assertThat(randomSpriteRotation.getChanceByRotation()).containsOnly( 39 | MapEntry.entry(CLOCKWISE, 0.2F), 40 | MapEntry.entry(NONE, 0.8F)); 41 | } 42 | 43 | @Test 44 | public void decode_givenTwoRotation_OneWithChanceOneWithout_thenShouldGiveRemainingChanceToRotationWithout() 45 | { 46 | String rotations = "clockwise 20% counterclockwise"; 47 | 48 | RandomSpriteRotation randomSpriteRotation = translator.decode(rotations); 49 | 50 | assertThat(randomSpriteRotation.getChanceByRotation()).containsOnly( 51 | MapEntry.entry(CLOCKWISE, 0.2F), 52 | MapEntry.entry(COUNTERCLOCKWISE, 0.8F)); 53 | } 54 | } -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/style/adapter/RectBoxTranslatorTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import net.voxelindustry.brokkgui.data.RectBox; 4 | import org.junit.jupiter.api.BeforeEach; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import static org.assertj.core.api.Assertions.assertThat; 8 | 9 | public class RectBoxTranslatorTest 10 | { 11 | private RectBoxTranslator adapter; 12 | 13 | @BeforeEach 14 | public void init() 15 | { 16 | this.adapter = new RectBoxTranslator(); 17 | } 18 | 19 | @Test 20 | public void oneValue() 21 | { 22 | RectBox box = adapter.decode("1.5"); 23 | 24 | assertThat(box.getLeft()) 25 | .isEqualTo(box.getTop()) 26 | .isEqualTo(box.getRight()) 27 | .isEqualTo(box.getBottom()) 28 | .isEqualTo(1.5f); 29 | } 30 | 31 | @Test 32 | public void twoValue() 33 | { 34 | RectBox box = adapter.decode("1.5 0.2"); 35 | 36 | assertThat(box.getLeft()).isEqualTo(box.getRight()).isEqualTo(0.2f); 37 | assertThat(box.getTop()).isEqualTo(box.getBottom()).isEqualTo(1.5f); 38 | } 39 | 40 | @Test 41 | public void threeValue() 42 | { 43 | RectBox box = adapter.decode("1.5 0.2 3.5"); 44 | 45 | assertThat(box.getTop()).isEqualTo(1.5f); 46 | assertThat(box.getLeft()).isEqualTo(box.getRight()).isEqualTo(0.2f); 47 | assertThat(box.getBottom()).isEqualTo(3.5f); 48 | } 49 | 50 | @Test 51 | public void fourValue() 52 | { 53 | RectBox box = adapter.decode("1.5 0.2 3.5 .1"); 54 | 55 | assertThat(box.getTop()).isEqualTo(1.5f); 56 | assertThat(box.getRight()).isEqualTo(0.2f); 57 | assertThat(box.getBottom()).isEqualTo(3.5f); 58 | assertThat(box.getLeft()).isEqualTo(0.1f); 59 | } 60 | } -------------------------------------------------------------------------------- /common/src/test/java/net/voxelindustry/brokkgui/style/parser/StyleTranslatorTest.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.parser; 2 | 3 | import net.voxelindustry.brokkgui.style.adapter.StyleTranslator; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.extension.ExtendWith; 6 | import org.mockito.junit.jupiter.MockitoExtension; 7 | 8 | import static org.assertj.core.api.Assertions.assertThat; 9 | 10 | @ExtendWith(MockitoExtension.class) 11 | public class StyleTranslatorTest 12 | { 13 | @Test 14 | public void testPrimitives() 15 | { 16 | assertThat((Integer) StyleTranslator.getInstance().decode("6", Integer.class)).isEqualTo(6); 17 | assertThat((Long) StyleTranslator.getInstance().decode("25645875250000", Long.class)).isEqualTo(25645875250000L); 18 | assertThat((Float) StyleTranslator.getInstance().decode("6.5", Float.class)).isEqualTo(6.5f); 19 | assertThat((Double) StyleTranslator.getInstance().decode("6.00000000012", Double.class)).isEqualTo(6.00000000012); 20 | assertThat((Boolean) StyleTranslator.getInstance().decode("true", Boolean.class)).isEqualTo(true); 21 | assertThat((String) StyleTranslator.getInstance().decode("one", String.class)).isEqualTo("one"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /common/src/test/resources/assets/brokkgui/animation/sprite_animation.json: -------------------------------------------------------------------------------- 1 | { 2 | "frameCount": 9, 3 | "orientation": "vertical", 4 | "duration": 1000, 5 | "interpolator": "linear", 6 | "frames": [ 7 | { 8 | "index": 8, 9 | "time": 1000 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /common/src/test/resources/assets/brokkgui/css/import.css: -------------------------------------------------------------------------------- 1 | @import url("/assets/brokkgui/css/test.css"); -------------------------------------------------------------------------------- /common/src/test/resources/assets/brokkgui/css/test.css: -------------------------------------------------------------------------------- 1 | pane { 2 | background-color: red; 3 | border-color: blue; 4 | border-width: 1; 5 | } 6 | 7 | pane > .snowflakes { 8 | border-color: khaki; 9 | border-width: 2; 10 | } 11 | 12 | #cyan { 13 | background-color: cyan; 14 | } 15 | 16 | #cyan:hover { 17 | background-color: lightblue; 18 | } -------------------------------------------------------------------------------- /common/src/test/resources/assets/brokkgui/css/test2.css: -------------------------------------------------------------------------------- 1 | pane > .snowflakes { 2 | font-width: 10; 3 | font-family: Open Sans; 4 | } 5 | 6 | #cyan { 7 | text-decoration: underline; 8 | } -------------------------------------------------------------------------------- /common/src/test/resources/assets/brokkgui/css/test_background_alias.css: -------------------------------------------------------------------------------- 1 | pane { 2 | background-color: limegreen; 3 | } -------------------------------------------------------------------------------- /common/src/test/resources/assets/brokkgui/css/test_hierarchic_border.css: -------------------------------------------------------------------------------- 1 | .myPane { 2 | border-width: 2; 3 | border-color: khaki; 4 | } 5 | 6 | .myPane > .myChildPane { 7 | border-color: red; 8 | } -------------------------------------------------------------------------------- /common/src/test/resources/assets/brokkgui/css/test_simple_border.css: -------------------------------------------------------------------------------- 1 | pane { 2 | border-width: 2; 3 | border-color: khaki; 4 | } -------------------------------------------------------------------------------- /core/src/main/java/net/voxelindustry/brokkgui/debug/DebugHierarchy.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.debug; 2 | 3 | import net.voxelindustry.brokkgui.debug.hierarchy.AccordionItem; 4 | 5 | import java.util.Objects; 6 | 7 | public class DebugHierarchy implements AccordionItem 8 | { 9 | private String name; 10 | private float scrollY; 11 | private boolean isCollapsed; 12 | private float headerPos; 13 | 14 | public DebugHierarchy(String name, float scrollY, boolean isCollapsed, float headerPos) 15 | { 16 | this.name = name; 17 | this.scrollY = scrollY; 18 | this.isCollapsed = isCollapsed; 19 | this.headerPos = headerPos; 20 | } 21 | 22 | public String getName() 23 | { 24 | return name; 25 | } 26 | 27 | public void setName(String name) 28 | { 29 | this.name = name; 30 | } 31 | 32 | public float getScrollY() 33 | { 34 | return scrollY; 35 | } 36 | 37 | public void setScrollY(float scrollY) 38 | { 39 | this.scrollY = scrollY; 40 | } 41 | 42 | @Override 43 | public boolean isCollapsed() 44 | { 45 | return isCollapsed; 46 | } 47 | 48 | public void setCollapsed(boolean collapsed) 49 | { 50 | isCollapsed = collapsed; 51 | } 52 | 53 | @Override 54 | public float getHeaderPos() 55 | { 56 | return headerPos; 57 | } 58 | 59 | @Override 60 | public void setHeaderPos(float headerPos) 61 | { 62 | this.headerPos = headerPos; 63 | } 64 | 65 | @Override 66 | public boolean equals(Object o) 67 | { 68 | if (this == o) return true; 69 | if (o == null || getClass() != o.getClass()) return false; 70 | DebugHierarchy that = (DebugHierarchy) o; 71 | return Float.compare(that.scrollY, scrollY) == 0 && 72 | isCollapsed == that.isCollapsed && 73 | Float.compare(that.headerPos, headerPos) == 0 && 74 | Objects.equals(name, that.name); 75 | } 76 | 77 | @Override 78 | public int hashCode() 79 | { 80 | return Objects.hash(name, scrollY, isCollapsed, headerPos); 81 | } 82 | 83 | @Override 84 | public String toString() 85 | { 86 | return "DebugHierarchy{" + 87 | "name='" + name + '\'' + 88 | ", scrollY=" + scrollY + 89 | ", isOpen=" + isCollapsed + 90 | ", headerPosY=" + headerPos + 91 | '}'; 92 | } 93 | 94 | @Override 95 | public float getHeaderSize() 96 | { 97 | return 14; 98 | } 99 | 100 | @Override 101 | public float getMinimalSize() 102 | { 103 | return getHeaderSize() * 3; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /core/src/main/java/net/voxelindustry/brokkgui/debug/DebugRenderer.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.debug; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.gui.BrokkGuiScreen; 5 | import net.voxelindustry.brokkgui.gui.GuiCompositeWindow; 6 | import org.apache.commons.lang3.StringUtils; 7 | 8 | public class DebugRenderer 9 | { 10 | public static DebugWindow wrap(BrokkGuiScreen brokkGuiScreen) 11 | { 12 | DebugWindow debugWindow = new DebugWindow(brokkGuiScreen); 13 | GuiCompositeWindow composite = new GuiCompositeWindow(brokkGuiScreen, debugWindow); 14 | composite.setInputEventFilter(debugWindow); 15 | debugWindow.setWrapper(brokkGuiScreen.getWrapper()); 16 | brokkGuiScreen.getWrapper().setGuiWindow(composite); 17 | 18 | debugWindow.initGui(); 19 | return debugWindow; 20 | } 21 | 22 | public static String getNodeName(GuiNode node) 23 | { 24 | StringBuilder builder = new StringBuilder(); 25 | 26 | if (!StringUtils.isEmpty(node.getID())) 27 | builder.append("#").append(node.getID()); 28 | else 29 | builder.append(node.getClass().getSimpleName()); 30 | 31 | return builder.toString(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /core/src/main/java/net/voxelindustry/brokkgui/debug/StyleDebugPanel.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.debug; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 5 | import net.voxelindustry.brokkgui.style.StyleProperty; 6 | import net.voxelindustry.brokkgui.style.adapter.StyleTranslator; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | public class StyleDebugPanel 13 | { 14 | private GuiNode node; 15 | 16 | public StyleDebugPanel(GuiNode node) 17 | { 18 | this.node = node; 19 | } 20 | 21 | public void render(IGuiRenderer renderer, float windowWidth, float windowHeight, int mouseX, int mouseY) 22 | { 23 | List styleText = new ArrayList<>(); 24 | 25 | for (Map.Entry> entry : node.getStyle().getProperties().entrySet()) 26 | { 27 | styleText.add(entry.getKey() + ": " + (entry.getValue().getValue() != null ? 28 | StyleTranslator.getInstance().encode(entry.getValue().getValue(), 29 | entry.getValue().getValueClass(), true) : "null")); 30 | } 31 | 32 | float width = (float) styleText.stream().mapToDouble(renderer.getHelper()::getStringWidth).max().orElse(0); 33 | float height = styleText.size() * renderer.getHelper().getStringHeight(); 34 | float currentY = windowHeight - height; 35 | 36 | // renderer.getHelper().drawColoredRect(renderer, 0, currentY, width, height, 300, DebugRenderer.BOX_COLOR); 37 | 38 | for (String line : styleText) 39 | { 40 | // renderer.getHelper().drawString(line, 0, currentY, 300, DebugRenderer.TEXT_COLOR); 41 | currentY += renderer.getHelper().getStringHeight(); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /core/src/main/java/net/voxelindustry/brokkgui/debug/hierarchy/AccordionItem.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.debug.hierarchy; 2 | 3 | public interface AccordionItem 4 | { 5 | float getHeaderPos(); 6 | 7 | void setHeaderPos(float headerPos); 8 | 9 | float getHeaderSize(); 10 | 11 | float getMinimalSize(); 12 | 13 | boolean isCollapsed(); 14 | } 15 | -------------------------------------------------------------------------------- /core/src/main/resources/assets/brokkgui/css/debug-window.css: -------------------------------------------------------------------------------- 1 | box { 2 | background-color: #505050; 3 | border-color: #424242; 4 | } 5 | 6 | text { 7 | text-color: #FAFAFA; 8 | } 9 | 10 | text:hover { 11 | text-color: #FDFDFD; 12 | } 13 | 14 | text.light { 15 | text-color: #9E9E9E 78%; 16 | } 17 | 18 | text.light:hover { 19 | text-color: #757575 78%; 20 | } 21 | 22 | text-box { 23 | text-color: #212121; 24 | background-color: #FAFAFA; 25 | border-color: #212121; 26 | padding: 2; 27 | } 28 | 29 | text-box:hover { 30 | background-color: #EEEEEE; 31 | } 32 | 33 | empty-box { 34 | border-color: #00FFFF; 35 | border-width: 0.5; 36 | } 37 | 38 | button { 39 | text-color: #EEEEEE; 40 | } 41 | 42 | button:hover { 43 | text-color: #E0E0E0; 44 | } 45 | 46 | .menu { 47 | background-color: #FAFAFA; 48 | text-color: #212121; 49 | border-color: #212121; 50 | padding: 2; 51 | } 52 | 53 | .menu:hover { 54 | text-color: #212121; 55 | } 56 | 57 | .menu:hover { 58 | background-color: #EEEEEE; 59 | } 60 | 61 | .menu.dark { 62 | background-color: #E0E0E0; 63 | } 64 | 65 | .menu.dark:hover { 66 | background-color: #BDBDBD; 67 | } 68 | 69 | .invisible { 70 | text-color: #9E9E9E 78%; 71 | } 72 | 73 | .invisible:hover { 74 | text-color: #898989 78%; 75 | } 76 | 77 | .invisible.dark { 78 | text-color: #BEBEBE 94%; 79 | } 80 | 81 | .invisible.dark:hover { 82 | text-color: #AEAEAE 94%; 83 | } 84 | 85 | .mouse-lock { 86 | background-color: #00CCCC 50%; 87 | border-color: #00FFFF 60%; 88 | border-width: 1; 89 | } 90 | 91 | button.action { 92 | padding: 4; 93 | text-color: #212121; 94 | background-color: #cfd8dc; 95 | border-color: #212121; 96 | } 97 | 98 | button.action:hover { 99 | background-color: #b0bec5; 100 | text-color: #212121; 101 | } -------------------------------------------------------------------------------- /core/src/main/resources/assets/brokkgui/css/debug.css: -------------------------------------------------------------------------------- 1 | listcell > label > text { 2 | color: #FFD700; 3 | } 4 | 5 | listcell > label:hover > text { 6 | color: rgb(204, 172, 0); 7 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/behavior/GuiLinkBehavior.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.behavior; 2 | 3 | import net.voxelindustry.brokkgui.element.GuiLink; 4 | import net.voxelindustry.brokkgui.event.ClickEvent; 5 | import net.voxelindustry.brokkgui.internal.DesktopUtils; 6 | 7 | /** 8 | * @author Ourten 15 oct. 2016 9 | */ 10 | public class GuiLinkBehavior extends GuiBehaviorBase 11 | { 12 | public GuiLinkBehavior(final GuiLink model) 13 | { 14 | super(model); 15 | 16 | // TODO: hover system to display link content 17 | this.getModel().getEventDispatcher().addHandler(ClickEvent.Left.TYPE, this::onClick); 18 | } 19 | 20 | public void onClick(final ClickEvent.Left e) 21 | { 22 | DesktopUtils.openURL(this.getModel().getUrl()); 23 | } 24 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/behavior/GuiTabPaneBehavior.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.behavior; 2 | 3 | import net.voxelindustry.brokkgui.element.pane.GuiTabPane; 4 | 5 | /** 6 | * @author Ourten 15 oct. 2016 7 | */ 8 | public class GuiTabPaneBehavior extends GuiBehaviorBase 9 | { 10 | public GuiTabPaneBehavior(T model) 11 | { 12 | super(model); 13 | 14 | } 15 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/behavior/GuiTogglableButtonBehavior.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.behavior; 2 | 3 | import net.voxelindustry.brokkgui.control.GuiButtonBase; 4 | import net.voxelindustry.brokkgui.element.IGuiTogglable; 5 | import net.voxelindustry.brokkgui.event.ClickEvent; 6 | 7 | public class GuiTogglableButtonBehavior extends GuiButtonBehavior 8 | { 9 | public GuiTogglableButtonBehavior(final C model) 10 | { 11 | super(model); 12 | } 13 | 14 | @Override 15 | public void onClick(final ClickEvent.Left event) 16 | { 17 | super.onClick(event); 18 | 19 | if (!this.getModel().isDisabled()) 20 | this.getModel().setSelected(!this.getModel().isSelected()); 21 | } 22 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/GuiLabel.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element; 2 | 3 | import net.voxelindustry.brokkgui.behavior.GuiBehaviorBase; 4 | import net.voxelindustry.brokkgui.component.GuiNode; 5 | import net.voxelindustry.brokkgui.control.GuiLabeled; 6 | import net.voxelindustry.brokkgui.skin.GuiLabeledSkinBase; 7 | import net.voxelindustry.brokkgui.skin.GuiSkinBase; 8 | 9 | public class GuiLabel extends GuiLabeled 10 | { 11 | public GuiLabel(String text, GuiNode icon) 12 | { 13 | super("label", text, icon); 14 | } 15 | 16 | public GuiLabel(String text) 17 | { 18 | this(text, null); 19 | } 20 | 21 | public GuiLabel() 22 | { 23 | this(""); 24 | } 25 | 26 | @Override 27 | protected GuiSkinBase makeDefaultSkin() 28 | { 29 | return new GuiLabeledSkinBase<>(this, new GuiBehaviorBase<>(this)); 30 | } 31 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/GuiLink.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | import net.voxelindustry.brokkgui.behavior.GuiLinkBehavior; 5 | import net.voxelindustry.brokkgui.component.GuiNode; 6 | import net.voxelindustry.brokkgui.control.GuiLabeled; 7 | import net.voxelindustry.brokkgui.skin.GuiLabeledSkinBase; 8 | import net.voxelindustry.brokkgui.skin.GuiSkinBase; 9 | 10 | /** 11 | * @author Ourten 15 oct. 2016 12 | */ 13 | public class GuiLink extends GuiLabeled 14 | { 15 | private final BaseProperty urlProperty; 16 | 17 | public GuiLink(String url, String text, GuiNode icon) 18 | { 19 | super("link", text, icon); 20 | this.urlProperty = new BaseProperty<>(url, "urlProperty"); 21 | this.setStyle("text-color: blue"); 22 | } 23 | 24 | public GuiLink(String url, String text) 25 | { 26 | this(url, text, null); 27 | } 28 | 29 | public GuiLink(String url) 30 | { 31 | this(url, url); 32 | } 33 | 34 | public GuiLink() 35 | { 36 | this(""); 37 | } 38 | 39 | @Override 40 | protected GuiSkinBase makeDefaultSkin() 41 | { 42 | return new GuiLabeledSkinBase<>(this, new GuiLinkBehavior(this)); 43 | } 44 | 45 | public BaseProperty getUrlProperty() 46 | { 47 | return this.urlProperty; 48 | } 49 | 50 | public String getUrl() 51 | { 52 | return this.getUrlProperty().getValue(); 53 | } 54 | 55 | public void setUrl(final String URL) 56 | { 57 | this.getUrlProperty().setValue(URL); 58 | } 59 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/GuiProgressBar.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | import net.voxelindustry.brokkgui.behavior.GuiBehaviorBase; 5 | import net.voxelindustry.brokkgui.control.GuiLabeled; 6 | import net.voxelindustry.brokkgui.data.RectAlignment; 7 | import net.voxelindustry.brokkgui.data.RectSide; 8 | import net.voxelindustry.brokkgui.skin.GuiProgressBarSkin; 9 | import net.voxelindustry.brokkgui.skin.GuiSkinBase; 10 | 11 | /** 12 | * @author Phenix246 13 | */ 14 | public class GuiProgressBar extends GuiLabeled 15 | { 16 | private final BaseProperty progressBarProgressProperty; 17 | private final BaseProperty progressBarProgressDirection; 18 | 19 | public GuiProgressBar(final String text, final float progressRatio) 20 | { 21 | super("progressbar", text); 22 | this.progressBarProgressProperty = new BaseProperty<>(0f, "progressProperty"); 23 | this.progressBarProgressDirection = new BaseProperty<>(RectSide.RIGHT, "progressDirectionProperty"); 24 | 25 | this.progressBarProgressProperty.setChecker((old, set) -> 26 | { 27 | if (set < 0 || set > 1) 28 | return old; 29 | return set; 30 | }); 31 | 32 | this.progressBarProgressProperty.setValue(progressRatio); 33 | this.getTextAlignmentProperty().setValue(RectAlignment.MIDDLE_CENTER); 34 | } 35 | 36 | public GuiProgressBar(final String text) 37 | { 38 | this(text, 0); 39 | } 40 | 41 | public GuiProgressBar(final float progressRatio) 42 | { 43 | this("", progressRatio); 44 | } 45 | 46 | public GuiProgressBar() 47 | { 48 | this(""); 49 | } 50 | 51 | @Override 52 | protected GuiSkinBase makeDefaultSkin() 53 | { 54 | return new GuiProgressBarSkin<>(this, new GuiBehaviorBase<>(this)); 55 | } 56 | 57 | public BaseProperty getProgressProperty() 58 | { 59 | return this.progressBarProgressProperty; 60 | } 61 | 62 | public BaseProperty getProgressDirectionProperty() 63 | { 64 | return this.progressBarProgressDirection; 65 | } 66 | 67 | public float getProgress() 68 | { 69 | return this.getProgressProperty().getValue(); 70 | } 71 | 72 | public void setProgress(float progress) 73 | { 74 | this.getProgressProperty().setValue(progress); 75 | } 76 | 77 | public RectSide getProgressDirection() 78 | { 79 | return this.getProgressDirectionProperty().getValue(); 80 | } 81 | 82 | public void setProgressDirection(RectSide direction) 83 | { 84 | this.getProgressDirectionProperty().setValue(direction); 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/IGuiTogglable.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | import net.voxelindustry.brokkgui.element.input.GuiToggleGroup; 5 | 6 | /** 7 | * @author Ourten 8 | * 9 | * Interface for Togglable elements of BrokkGui. Allow implementation of 10 | * ToggleGroups, they are mostly used with RadioButtons. 11 | */ 12 | public interface IGuiTogglable 13 | { 14 | /** 15 | * @return the GuiToggleGroup to this Togglable element belongs. 16 | */ 17 | GuiToggleGroup getToggleGroup(); 18 | 19 | /** 20 | * @param selected 21 | * boolean 22 | * @return the state after GuiToggleGroup checks. Useful when the 23 | * ToggleGroup might disable empty selection or when this Togglable 24 | * is already selected. 25 | */ 26 | boolean setSelected(boolean selected); 27 | 28 | /** 29 | * @return the value of the selected property. When a GuiToggleGroup is set 30 | * you are guaranteed that it's the group selected Togglable. 31 | */ 32 | default boolean isSelected() 33 | { 34 | return this.getSelectedProperty().getValue(); 35 | } 36 | 37 | /** 38 | * @return the internal selected property of the Togglable object. 39 | */ 40 | BaseProperty getSelectedProperty(); 41 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/TabHeaderFactory.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element; 2 | 3 | import net.voxelindustry.brokkgui.component.GuiNode; 4 | import net.voxelindustry.brokkgui.element.pane.GuiTab; 5 | 6 | @FunctionalInterface 7 | public interface TabHeaderFactory 8 | { 9 | GuiNode create(GuiTab tab, float maxWidth, float maxHeight); 10 | } 11 | -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/input/GuiButton.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element.input; 2 | 3 | import net.voxelindustry.brokkgui.behavior.GuiButtonBehavior; 4 | import net.voxelindustry.brokkgui.component.GuiNode; 5 | import net.voxelindustry.brokkgui.control.GuiButtonBase; 6 | import net.voxelindustry.brokkgui.control.GuiLabeled; 7 | import net.voxelindustry.brokkgui.data.RectAlignment; 8 | import net.voxelindustry.brokkgui.element.GuiLabel; 9 | import net.voxelindustry.brokkgui.skin.GuiButtonSkin; 10 | import net.voxelindustry.brokkgui.skin.GuiSkinBase; 11 | 12 | public class GuiButton extends GuiButtonBase 13 | { 14 | public GuiButton(String text, GuiNode icon) 15 | { 16 | super("button", text, icon); 17 | 18 | this.getLabel().setTextAlignment(RectAlignment.MIDDLE_CENTER); 19 | } 20 | 21 | public GuiButton(String text) 22 | { 23 | this(text, null); 24 | } 25 | 26 | public GuiButton() 27 | { 28 | this(""); 29 | } 30 | 31 | @Override 32 | protected GuiLabeled createGuiLabel(String text, GuiNode icon) 33 | { 34 | return new GuiLabel(text, icon); 35 | } 36 | 37 | @Override 38 | protected GuiSkinBase makeDefaultSkin() 39 | { 40 | return new GuiButtonSkin<>(this, new GuiButtonBehavior<>(this)); 41 | } 42 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/input/GuiCheckbox.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element.input; 2 | 3 | import fr.ourten.teabeans.binding.BaseExpression; 4 | import net.voxelindustry.brokkgui.behavior.GuiTogglableButtonBehavior; 5 | import net.voxelindustry.brokkgui.control.GuiFather; 6 | import net.voxelindustry.brokkgui.data.RelativeBindingHelper; 7 | import net.voxelindustry.brokkgui.shape.Rectangle; 8 | import net.voxelindustry.brokkgui.shape.Text; 9 | import net.voxelindustry.brokkgui.skin.GuiCheckboxSkin; 10 | import net.voxelindustry.brokkgui.skin.GuiSkinBase; 11 | 12 | public class GuiCheckbox extends GuiRadioButton 13 | { 14 | public GuiCheckbox(String text) 15 | { 16 | super(text); 17 | this.setType("checkbox"); 18 | 19 | this.setButtonNode(new CheckboxButtonContent(this)); 20 | } 21 | 22 | public GuiCheckbox() 23 | { 24 | this(""); 25 | } 26 | 27 | @Override 28 | protected GuiSkinBase makeDefaultSkin() 29 | { 30 | return new GuiCheckboxSkin(this, new GuiTogglableButtonBehavior<>(this)); 31 | } 32 | 33 | public static class CheckboxButtonContent extends GuiFather 34 | { 35 | private Rectangle box; 36 | private Text mark; 37 | 38 | public CheckboxButtonContent(GuiCheckbox parent) 39 | { 40 | super("checkbox-content"); 41 | 42 | this.setHeightRatio(1); 43 | this.getWidthProperty().bind(this.getHeightProperty()); 44 | 45 | this.box = new Rectangle(); 46 | this.mark = new Text("✔"); 47 | 48 | this.box.getStyleClass().add("box"); 49 | this.mark.getStyleClass().add("mark"); 50 | 51 | this.addChild(this.mark); 52 | RelativeBindingHelper.bindToCenter(this.mark, this, 0, -1); 53 | 54 | this.addChild(this.box); 55 | RelativeBindingHelper.bindToCenter(this.box, this); 56 | 57 | this.box.getWidthProperty().bind(this.box.getHeightProperty()); 58 | this.box.getHeightProperty().bind(this.getHeightProperty()); 59 | 60 | this.mark.getWidthProperty().bind(this.mark.getHeightProperty()); 61 | this.mark.getHeightProperty().bind(BaseExpression.transform(this.box.getHeightProperty(), 62 | height -> height - 2)); 63 | 64 | this.mark.getVisibleProperty().bind(parent.getSelectedProperty()); 65 | } 66 | 67 | public Rectangle getBox() 68 | { 69 | return this.box; 70 | } 71 | 72 | public Text getMark() 73 | { 74 | return this.mark; 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/input/GuiToggleGroup.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element.input; 2 | 3 | import fr.ourten.teabeans.value.BaseListProperty; 4 | import fr.ourten.teabeans.value.BaseProperty; 5 | import net.voxelindustry.brokkgui.element.IGuiTogglable; 6 | 7 | import java.util.Arrays; 8 | import java.util.List; 9 | 10 | public class GuiToggleGroup 11 | { 12 | private final BaseProperty selectedButtonProperty; 13 | private final BaseListProperty buttonListProperty; 14 | private boolean allowNothing; 15 | 16 | public GuiToggleGroup() 17 | { 18 | this.selectedButtonProperty = new BaseProperty<>(null, "selectedButtonProperty"); 19 | this.buttonListProperty = new BaseListProperty<>(null, "buttonListProperty"); 20 | } 21 | 22 | public void setSelectedButton(final IGuiTogglable button) 23 | { 24 | if (this.buttonListProperty.contains(button)) 25 | { 26 | this.selectedButtonProperty.setValue(button); 27 | this.buttonListProperty.getValue() 28 | .forEach(button2 -> button2.getSelectedProperty().setValue(button2 == button)); 29 | } 30 | else if (this.allowNothing() && button == null) 31 | { 32 | this.selectedButtonProperty.setValue(null); 33 | this.buttonListProperty.getValue().forEach(button2 -> button2.getSelectedProperty().setValue(false)); 34 | } 35 | } 36 | 37 | public IGuiTogglable getSelectedButton() 38 | { 39 | return this.getSelectedButtonProperty().getValue(); 40 | } 41 | 42 | /** 43 | * @return an immutable list 44 | */ 45 | public List getButtonList() 46 | { 47 | return this.getButtonListProperty().getValue(); 48 | } 49 | 50 | public void addButton(final GuiToggleButton button) 51 | { 52 | if (!this.getButtonListProperty().contains(button)) 53 | { 54 | this.getButtonListProperty().add(button); 55 | button.setToggleGroup(this); 56 | } 57 | } 58 | 59 | public void addButtons(final GuiToggleButton... buttons) 60 | { 61 | Arrays.asList(buttons).forEach(this::addButton); 62 | } 63 | 64 | public boolean allowNothing() 65 | { 66 | return this.allowNothing; 67 | } 68 | 69 | public void setAllowNothing(final boolean allowNothing) 70 | { 71 | this.allowNothing = allowNothing; 72 | } 73 | 74 | public BaseProperty getSelectedButtonProperty() 75 | { 76 | return this.selectedButtonProperty; 77 | } 78 | 79 | public BaseListProperty getButtonListProperty() 80 | { 81 | return this.buttonListProperty; 82 | } 83 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/element/pane/ScrollPane.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.element.pane; 2 | 3 | import net.voxelindustry.brokkgui.behavior.GuiScrollableBehavior; 4 | import net.voxelindustry.brokkgui.component.GuiNode; 5 | import net.voxelindustry.brokkgui.control.GuiScrollableBase; 6 | import net.voxelindustry.brokkgui.data.RelativeBindingHelper; 7 | import net.voxelindustry.brokkgui.skin.GuiScrollableSkin; 8 | import net.voxelindustry.brokkgui.skin.GuiSkinBase; 9 | 10 | /** 11 | * @author Ourten 9 oct. 2016 12 | */ 13 | public class ScrollPane extends GuiScrollableBase 14 | { 15 | private GuiNode contentNode; 16 | 17 | public ScrollPane(final GuiNode node) 18 | { 19 | super("scrollpane"); 20 | 21 | if (node != null) 22 | this.setChild(node); 23 | } 24 | 25 | public ScrollPane() 26 | { 27 | this(null); 28 | } 29 | 30 | public void setChild(final GuiNode node) 31 | { 32 | if(contentNode != null) 33 | { 34 | this.getTrueWidthProperty().unbind(); 35 | this.getTrueHeightProperty().unbind(); 36 | this.removeChild(contentNode); 37 | } 38 | 39 | this.contentNode = node; 40 | this.addChild(node); 41 | RelativeBindingHelper.bindToPos(node, this, this.getScrollXProperty(), this.getScrollYProperty()); 42 | 43 | this.getTrueWidthProperty().bind(node.getWidthProperty()); 44 | this.getTrueHeightProperty().bind(node.getHeightProperty()); 45 | } 46 | 47 | @Override 48 | protected GuiSkinBase makeDefaultSkin() 49 | { 50 | return new GuiScrollableSkin<>(this, new GuiScrollableBehavior<>(this)); 51 | } 52 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/skin/GuiButtonSkin.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | import net.voxelindustry.brokkgui.behavior.GuiButtonBehavior; 4 | import net.voxelindustry.brokkgui.control.GuiButtonBase; 5 | import net.voxelindustry.brokkgui.data.RelativeBindingHelper; 6 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 7 | import net.voxelindustry.brokkgui.paint.RenderPass; 8 | 9 | public class GuiButtonSkin> extends GuiBehaviorSkinBase 10 | { 11 | public GuiButtonSkin(final C model, final B behaviour) 12 | { 13 | super(model, behaviour); 14 | 15 | this.getModel().getLabel().getStyleClass().add("label"); 16 | this.bindLabel(); 17 | } 18 | 19 | protected void bindLabel() 20 | { 21 | RelativeBindingHelper.bindToCenter(getModel().getLabel(), getModel()); 22 | 23 | getModel().getExpandToLabelProperty().addListener(obs -> this.refreshLabelBinding()); 24 | this.refreshLabelBinding(); 25 | } 26 | 27 | private void refreshLabelBinding() 28 | { 29 | if (getModel().expandToLabel()) 30 | { 31 | getModel().getLabel().getWidthProperty().unbind(); 32 | getModel().getLabel().getHeightProperty().unbind(); 33 | 34 | getModel().getLabel().setExpandToText(true); 35 | 36 | getModel().getWidthProperty().bind(getModel().getLabel().getWidthProperty()); 37 | getModel().getHeightProperty().bind(getModel().getLabel().getHeightProperty()); 38 | } 39 | else 40 | { 41 | getModel().getLabel().setExpandToText(false); 42 | 43 | getModel().getWidthProperty().unbind(); 44 | getModel().getHeightProperty().unbind(); 45 | 46 | getModel().getLabel().getWidthProperty().bind(getModel().getWidthProperty()); 47 | getModel().getLabel().getHeightProperty().bind(getModel().getHeightProperty()); 48 | } 49 | } 50 | 51 | @Override 52 | public void render(RenderPass pass, IGuiRenderer renderer, int mouseX, int mouseY) 53 | { 54 | super.render(pass, renderer, mouseX, mouseY); 55 | } 56 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/skin/GuiCheckboxSkin.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | import net.voxelindustry.brokkgui.behavior.GuiButtonBehavior; 4 | import net.voxelindustry.brokkgui.element.input.GuiCheckbox; 5 | import net.voxelindustry.brokkgui.element.input.GuiRadioButton; 6 | 7 | public class GuiCheckboxSkin extends GuiRadioButtonSkin 8 | { 9 | public GuiCheckboxSkin(GuiCheckbox model, GuiButtonBehavior behaviour) 10 | { 11 | super(model, behaviour); 12 | } 13 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/skin/GuiListCellSkin.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | import net.voxelindustry.brokkgui.behavior.GuiBehaviorBase; 4 | import net.voxelindustry.brokkgui.element.GuiListCell; 5 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 6 | import net.voxelindustry.brokkgui.paint.RenderPass; 7 | 8 | public class GuiListCellSkin extends GuiBehaviorSkinBase, GuiBehaviorBase>> 9 | { 10 | public GuiListCellSkin(GuiListCell model) 11 | { 12 | super(model, new GuiBehaviorBase<>(model)); 13 | } 14 | 15 | @Override 16 | public void render(RenderPass pass, IGuiRenderer renderer, int mouseX, int mouseY) 17 | { 18 | super.render(pass, renderer, mouseX, mouseY); 19 | 20 | if (this.getModel().getGraphicProperty().isPresent()) 21 | this.getModel().getGraphic().renderNode(renderer, pass, mouseX, mouseY); 22 | } 23 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/skin/GuiListViewSkin.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | import net.voxelindustry.brokkgui.behavior.GuiListViewBehavior; 4 | import net.voxelindustry.brokkgui.element.GuiListView; 5 | 6 | public class GuiListViewSkin extends GuiScrollableSkin, GuiListViewBehavior> 7 | { 8 | public GuiListViewSkin(final GuiListView model, final GuiListViewBehavior behaviour) 9 | { 10 | super(model, behaviour); 11 | } 12 | } -------------------------------------------------------------------------------- /element/src/main/java/net/voxelindustry/brokkgui/skin/GuiProgressBarSkin.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.skin; 2 | 3 | import fr.ourten.teabeans.binding.BaseExpression; 4 | import net.voxelindustry.brokkgui.behavior.GuiBehaviorBase; 5 | import net.voxelindustry.brokkgui.data.RectSide; 6 | import net.voxelindustry.brokkgui.element.GuiProgressBar; 7 | import net.voxelindustry.brokkgui.shape.Rectangle; 8 | 9 | public class GuiProgressBarSkin> extends GuiLabeledSkinBase 10 | { 11 | private final Rectangle track; 12 | 13 | public GuiProgressBarSkin(final C model, final B behaviour) 14 | { 15 | super(model, behaviour); 16 | 17 | this.track = new Rectangle(model.getxPos(), model.getyPos(), model.getWidth(), model.getHeight()); 18 | this.track.getxPosProperty().bind(new BaseExpression<>(() -> 19 | { 20 | if (model.getProgressDirection() == RectSide.LEFT) 21 | return model.getxPos() + model.getWidth() - this.track.getWidth(); 22 | return model.getxPos(); 23 | }, model.getxPosProperty(), model.getWidthProperty(), model.getProgressDirectionProperty())); 24 | this.track.getyPosProperty().bind(model.getyPosProperty()); 25 | this.track.getWidthProperty().bind(new BaseExpression<>(() -> 26 | model.getWidth() * model.getProgress(), model.getProgressProperty(), model.getWidthProperty())); 27 | 28 | this.track.getStyleClass().add("track"); 29 | 30 | this.getText().getxPosProperty().bind(new BaseExpression<>(() -> 31 | model.getxPos() + model.getWidth() / 2, model.getxPosProperty(), model.getWidthProperty())); 32 | 33 | this.getText().getyPosProperty().bind(new BaseExpression<>(() -> 34 | model.getyPos() + model.getHeight() / 2, model.getyPosProperty(), model.getHeightProperty())); 35 | 36 | this.getText().getzLevelProperty().bind(new BaseExpression<>(() -> 37 | model.getzLevel() + 1, model.getzLevelProperty())); 38 | 39 | this.getModel().addChild(track); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | artifactory_contextUrl=https://maven.ferenyr.info/artifactory 2 | artifactory_user=none 3 | artifactory_password=none 4 | org.gradle.jvmargs=-Xms256m -Xmx2048m 5 | org.gradle.daemon=true 6 | # 7 | # 8 | brokkgui_version=1.0.0-63-SNAPSHOT 9 | # 10 | # 11 | teabeans_version=1.3.0 12 | hermod_version=2.0.0 13 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VoxelIndustry/BrokkGUI/d68825e64c8838265c7514aa25bae291d04128cd/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip 6 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /guidelines/brokkgui.importorder: -------------------------------------------------------------------------------- 1 | #Organize Import Order 2 | #Sat Oct 15 16:01:29 CEST 2016 3 | 3=com 4 | 2=org 5 | 1=javax 6 | 0=java 7 | -------------------------------------------------------------------------------- /immediate/src/main/java/net/voxelindustry/brokkgui/immediate/InteractionResult.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.immediate; 2 | 3 | public enum InteractionResult 4 | { 5 | NONE, 6 | HOVERED, 7 | CLICKED; 8 | 9 | public boolean isHovered() 10 | { 11 | return this == HOVERED || this == CLICKED; 12 | } 13 | 14 | public boolean isClicked() 15 | { 16 | return this == CLICKED; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /immediate/src/main/java/net/voxelindustry/brokkgui/immediate/element/ImmediateElement.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.immediate.element; 2 | 3 | public interface ImmediateElement extends ImmediateWindowBridge 4 | { 5 | } 6 | -------------------------------------------------------------------------------- /immediate/src/main/java/net/voxelindustry/brokkgui/immediate/element/ImmediateWindowBridge.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.immediate.element; 2 | 3 | import net.voxelindustry.brokkgui.immediate.style.StyleType; 4 | import net.voxelindustry.brokkgui.internal.IGuiRenderer; 5 | 6 | import java.util.function.Function; 7 | 8 | public interface ImmediateWindowBridge 9 | { 10 | void setStyleObject(T object, StyleType type); 11 | 12 | T getStyleObject(StyleType type, Class objectClass, Function styleObjectSupplier); 13 | 14 | default T getStyleValue(String element, StyleType styleType, String rule, T defaultValue) 15 | { 16 | return getStyleValue(element, styleType, "", rule, defaultValue); 17 | } 18 | 19 | T getStyleValue(String element, StyleType styleType, String pseudoClass, String rule, T defaultValue); 20 | 21 | IGuiRenderer getRenderer(); 22 | 23 | int getMouseX(); 24 | 25 | int getMouseY(); 26 | 27 | int getLastClickX(); 28 | 29 | int getLastClickY(); 30 | 31 | boolean isAreaHovered(float startX, float startY, float endX, float endY); 32 | 33 | boolean isAreaClicked(float startX, float startY, float endX, float endY); 34 | 35 | boolean isAreaWheeled(float startX, float startY, float endX, float endY); 36 | } 37 | -------------------------------------------------------------------------------- /immediate/src/main/java/net/voxelindustry/brokkgui/immediate/element/TextElement.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.immediate.element; 2 | 3 | import net.voxelindustry.brokkgui.immediate.style.StyleType; 4 | import net.voxelindustry.brokkgui.immediate.style.TextStyle; 5 | import net.voxelindustry.brokkgui.paint.Color; 6 | 7 | import static net.voxelindustry.brokkgui.immediate.style.StyleType.NORMAL; 8 | 9 | public interface TextElement extends ImmediateElement 10 | { 11 | String TEXT_TYPE = "text"; 12 | 13 | default void setTextStyle(TextStyle style) 14 | { 15 | setTextStyle(style, NORMAL); 16 | } 17 | 18 | default void setTextStyle(TextStyle style, StyleType type) 19 | { 20 | setStyleObject(style, type); 21 | } 22 | 23 | default TextStyle textStyleFromType(StyleType type) 24 | { 25 | return TextStyle.build() 26 | .setTextColor(getStyleValue(TEXT_TYPE, type, "text-color", Color.BLACK)) 27 | .setHoverTextColor(getStyleValue(TEXT_TYPE, type, "hover", "text-color", Color.BLACK)) 28 | .setShadowColor(getStyleValue(TEXT_TYPE, type, "shadow-color", Color.ALPHA)) 29 | .setHoverShadowColor(getStyleValue(TEXT_TYPE, type, "hover", "shadow-color", Color.ALPHA)) 30 | .create(); 31 | } 32 | 33 | default boolean text(String text, float x, float y) 34 | { 35 | return text(text, x, y, NORMAL); 36 | } 37 | 38 | default boolean text(String text, float x, float y, StyleType type) 39 | { 40 | return text(text, x, y, getStyleObject(type, TextStyle.class, this::textStyleFromType)); 41 | } 42 | 43 | default boolean text(String text, float x, float y, TextStyle style) 44 | { 45 | return text(text, x, y, style.textColor, style.shadowColor, style.hoverTextColor, style.hoverShadowColor); 46 | } 47 | 48 | default boolean text(String text, float x, float y, Color color, Color shadowColor, Color hoverColor, Color hoverShadowColor) 49 | { 50 | boolean isHovered = isAreaHovered(x, y, x + getRenderer().getHelper().getStringWidthMultiLine(text), y + getRenderer().getHelper().getStringHeightMultiLine(text)); 51 | 52 | if (!isHovered) 53 | getRenderer().getHelper().drawStringMultiline(text, x, y, 1, color, shadowColor); 54 | else 55 | getRenderer().getHelper().drawStringMultiline(text, x, y, 1, hoverColor, hoverShadowColor); 56 | 57 | return isHovered; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /immediate/src/main/java/net/voxelindustry/brokkgui/immediate/style/BoxStyle.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.immediate.style; 2 | 3 | import net.voxelindustry.brokkgui.paint.Color; 4 | 5 | public class BoxStyle 6 | { 7 | public final Color boxColor; 8 | public final Color borderColor; 9 | public final float borderThin; 10 | 11 | public final Color hoverBoxColor; 12 | public final Color hoverBorderColor; 13 | 14 | public BoxStyle(Color boxColor, Color borderColor, float borderThin, Color hoverBoxColor, Color hoverBorderColor) 15 | { 16 | this.boxColor = boxColor; 17 | this.borderColor = borderColor; 18 | this.borderThin = borderThin; 19 | this.hoverBoxColor = hoverBoxColor; 20 | this.hoverBorderColor = hoverBorderColor; 21 | } 22 | 23 | public static BoxStyleBuilder build() 24 | { 25 | return new BoxStyleBuilder(); 26 | } 27 | 28 | public static class BoxStyleBuilder 29 | { 30 | private Color boxColor; 31 | private Color borderColor = Color.ALPHA; 32 | private float borderThin = 1; 33 | 34 | private Color hoverBoxColor; 35 | private Color hoverBorderColor; 36 | 37 | public BoxStyleBuilder setBoxColor(Color boxColor) 38 | { 39 | this.boxColor = boxColor; 40 | return this; 41 | } 42 | 43 | public BoxStyleBuilder setBorderColor(Color borderColor) 44 | { 45 | this.borderColor = borderColor; 46 | return this; 47 | } 48 | 49 | public BoxStyleBuilder setBorderThin(float borderThin) 50 | { 51 | this.borderThin = borderThin; 52 | return this; 53 | } 54 | 55 | public BoxStyleBuilder setHoverBoxColor(Color hoverBoxColor) 56 | { 57 | this.hoverBoxColor = hoverBoxColor; 58 | return this; 59 | } 60 | 61 | public BoxStyleBuilder setHoverBorderColor(Color hoverBorderColor) 62 | { 63 | this.hoverBorderColor = hoverBorderColor; 64 | return this; 65 | } 66 | 67 | public BoxStyle create() 68 | { 69 | if (hoverBoxColor == null) 70 | hoverBoxColor = boxColor; 71 | if (hoverBorderColor == null) 72 | hoverBorderColor = borderColor; 73 | 74 | return new BoxStyle(boxColor, borderColor, borderThin, hoverBoxColor, hoverBorderColor); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /immediate/src/main/java/net/voxelindustry/brokkgui/immediate/style/EmptyBoxStyle.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.immediate.style; 2 | 3 | import net.voxelindustry.brokkgui.paint.Color; 4 | 5 | public class EmptyBoxStyle 6 | { 7 | public final Color borderColor; 8 | public final float borderThin; 9 | 10 | public final Color hoverBorderColor; 11 | 12 | public EmptyBoxStyle(Color borderColor, float borderThin, Color hoverBorderColor) 13 | { 14 | this.borderColor = borderColor; 15 | this.borderThin = borderThin; 16 | this.hoverBorderColor = hoverBorderColor; 17 | } 18 | 19 | public static EmptyBoxStyleBuilder build() 20 | { 21 | return new EmptyBoxStyleBuilder(); 22 | } 23 | 24 | public static class EmptyBoxStyleBuilder 25 | { 26 | private Color borderColor = Color.ALPHA; 27 | private float borderThin = 1; 28 | 29 | private Color hoverBorderColor; 30 | 31 | public EmptyBoxStyleBuilder setBorderColor(Color borderColor) 32 | { 33 | this.borderColor = borderColor; 34 | return this; 35 | } 36 | 37 | public EmptyBoxStyleBuilder setBorderThin(float borderThin) 38 | { 39 | this.borderThin = borderThin; 40 | return this; 41 | } 42 | 43 | public EmptyBoxStyleBuilder setHoverBorderColor(Color hoverBorderColor) 44 | { 45 | this.hoverBorderColor = hoverBorderColor; 46 | return this; 47 | } 48 | 49 | public EmptyBoxStyle create() 50 | { 51 | if (hoverBorderColor == null) 52 | hoverBorderColor = borderColor; 53 | 54 | return new EmptyBoxStyle(borderColor, borderThin, hoverBorderColor); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /immediate/src/main/java/net/voxelindustry/brokkgui/immediate/style/StyleType.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.immediate.style; 2 | 3 | import java.util.Collection; 4 | import java.util.Objects; 5 | 6 | import static com.google.common.collect.ImmutableSet.toImmutableSet; 7 | import static java.util.Arrays.stream; 8 | import static java.util.Collections.singleton; 9 | 10 | public class StyleType 11 | { 12 | public static final StyleType LIGHT = StyleType.of("light"); 13 | public static final StyleType NORMAL = StyleType.of("normal"); 14 | public static final StyleType DARK = StyleType.of("dark"); 15 | 16 | private Collection names; 17 | 18 | private StyleType(Collection names) 19 | { 20 | this.names = names; 21 | } 22 | 23 | public static StyleType of(String name) 24 | { 25 | return new StyleType(singleton(name)); 26 | } 27 | 28 | public static StyleType combine(StyleType... types) 29 | { 30 | return new StyleType(stream(types) 31 | .flatMap(type -> type.getNames().stream()) 32 | .collect(toImmutableSet())); 33 | } 34 | 35 | public Collection getNames() 36 | { 37 | return names; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object o) 42 | { 43 | if (this == o) return true; 44 | if (o == null || getClass() != o.getClass()) return false; 45 | StyleType styleType = (StyleType) o; 46 | return Objects.equals(names, styleType.names); 47 | } 48 | 49 | @Override 50 | public int hashCode() 51 | { 52 | return Objects.hash(names); 53 | } 54 | 55 | @Override 56 | public String toString() 57 | { 58 | return "StyleType{" + 59 | "names=" + names + 60 | '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /immediate/src/main/java/net/voxelindustry/brokkgui/immediate/style/TextStyle.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.immediate.style; 2 | 3 | import net.voxelindustry.brokkgui.paint.Color; 4 | 5 | public class TextStyle 6 | { 7 | public final Color textColor; 8 | public final Color shadowColor; 9 | public final Color hoverTextColor; 10 | public final Color hoverShadowColor; 11 | 12 | public TextStyle(Color textColor, Color shadowColor, Color hoverTextColor, Color hoverShadowColor) 13 | { 14 | this.textColor = textColor; 15 | this.shadowColor = shadowColor; 16 | this.hoverTextColor = hoverTextColor; 17 | this.hoverShadowColor = hoverShadowColor; 18 | } 19 | 20 | public static TextStyleBuilder build() 21 | { 22 | return new TextStyleBuilder(); 23 | } 24 | 25 | public static class TextStyleBuilder 26 | { 27 | private Color textColor; 28 | private Color shadowColor = Color.ALPHA; 29 | private Color hoverTextColor; 30 | private Color hoverShadowColor; 31 | 32 | public TextStyleBuilder setTextColor(Color textColor) 33 | { 34 | this.textColor = textColor; 35 | return this; 36 | } 37 | 38 | public TextStyleBuilder setShadowColor(Color shadowColor) 39 | { 40 | this.shadowColor = shadowColor; 41 | return this; 42 | } 43 | 44 | public TextStyleBuilder setHoverTextColor(Color hoverTextColor) 45 | { 46 | this.hoverTextColor = hoverTextColor; 47 | return this; 48 | } 49 | 50 | public TextStyleBuilder setHoverShadowColor(Color hoverShadowColor) 51 | { 52 | this.hoverShadowColor = hoverShadowColor; 53 | return this; 54 | } 55 | 56 | public TextStyle create() 57 | { 58 | if (hoverTextColor == null) 59 | hoverTextColor = textColor; 60 | if (hoverShadowColor == null) 61 | hoverShadowColor = shadowColor; 62 | 63 | return new TextStyle(textColor, shadowColor, hoverTextColor, hoverShadowColor); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'common' 2 | include 'element' 3 | include 'style' 4 | include 'immediate' 5 | include 'core' -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/HeldPropertyState.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | public enum HeldPropertyState 4 | { 5 | PRESENT, 6 | CONDITIONAL, 7 | ABSENT; 8 | 9 | public boolean isHeld() 10 | { 11 | return this != ABSENT; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/ICascadeStyleable.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | import net.voxelindustry.brokkgui.style.tree.StyleList; 4 | import net.voxelindustry.hermod.IEventEmitter; 5 | 6 | import java.util.function.Supplier; 7 | 8 | public interface ICascadeStyleable extends IStyleable, IEventEmitter 9 | { 10 | ICascadeStyleable getParent(); 11 | 12 | void setParent(ICascadeStyleable styleable); 13 | 14 | void setStyleListSupplier(Supplier treeSupplier); 15 | } 16 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/IStyleParent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | import java.util.List; 4 | 5 | public interface IStyleParent 6 | { 7 | List getChildStyles(); 8 | 9 | int getChildCount(); 10 | } 11 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/IStyleRoot.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | import net.voxelindustry.brokkgui.style.tree.StyleList; 4 | 5 | import java.util.List; 6 | 7 | public interface IStyleRoot 8 | { 9 | String getThemeID(); 10 | 11 | List getStylesheets(); 12 | 13 | void setStyleList(StyleList list); 14 | } 15 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/IStyleable.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | import fr.ourten.teabeans.value.BaseSetProperty; 4 | 5 | public interface IStyleable 6 | { 7 | void setID(String id); 8 | 9 | String getID(); 10 | 11 | default void addStyleClass(String styleClass) 12 | { 13 | this.getStyleClass().add(styleClass); 14 | } 15 | 16 | default void removeStyleClass(String styleClass) 17 | { 18 | this.getStyleClass().remove(styleClass); 19 | } 20 | 21 | default void clearStyleClass() 22 | { 23 | this.getStyleClass().clear(); 24 | } 25 | 26 | BaseSetProperty getStyleClass(); 27 | 28 | BaseSetProperty getActivePseudoClass(); 29 | 30 | StyleHolder getStyle(); 31 | 32 | default void setStyle(String style) 33 | { 34 | this.getStyle().parseInlineCSS(style); 35 | } 36 | 37 | String getType(); 38 | 39 | void refreshStyle(); 40 | } 41 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/StyleProperty.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | import fr.ourten.teabeans.value.BaseProperty; 4 | import net.voxelindustry.brokkgui.style.adapter.StyleTranslator; 5 | 6 | public class StyleProperty extends BaseProperty 7 | { 8 | private final Class valueClass; 9 | private int specificitySet; 10 | private StyleSource source; 11 | private T defaultValue; 12 | 13 | public StyleProperty(T defaultValue, String name, Class valueClass) 14 | { 15 | super(defaultValue, name); 16 | 17 | this.valueClass = valueClass; 18 | this.source = StyleSource.USER_AGENT; 19 | this.specificitySet = 0; 20 | this.defaultValue = defaultValue; 21 | } 22 | 23 | public boolean setStyleRaw(StyleSource source, int specificity, String rawValue) 24 | { 25 | if (source.ordinal() > this.source.ordinal() || 26 | (source.ordinal() == this.source.ordinal() && specificity >= this.specificitySet)) 27 | { 28 | this.internalSetStyle(source, specificity, StyleTranslator.getInstance().decode(rawValue, this.getValueClass())); 29 | return true; 30 | } 31 | return false; 32 | } 33 | 34 | public boolean setStyle(StyleSource source, int specificity, T value) 35 | { 36 | if (source.ordinal() > this.source.ordinal() || 37 | (source.ordinal() == this.source.ordinal() && specificity >= this.specificitySet)) 38 | { 39 | internalSetStyle(source, specificity, value); 40 | return true; 41 | } 42 | return false; 43 | } 44 | 45 | protected void internalSetStyle(StyleSource source, int specificity, T value) 46 | { 47 | this.source = source; 48 | this.specificitySet = specificity; 49 | super.setValue(value); 50 | } 51 | 52 | @Override 53 | public void setValue(T value) 54 | { 55 | this.source = StyleSource.CODE; 56 | this.specificitySet = 10_000; 57 | super.setValue(value); 58 | } 59 | 60 | public void setToDefault() 61 | { 62 | this.internalSetStyle(StyleSource.USER_AGENT, 0, defaultValue); 63 | } 64 | 65 | public Class getValueClass() 66 | { 67 | return valueClass; 68 | } 69 | 70 | public int getSpecificity() 71 | { 72 | return specificitySet; 73 | } 74 | 75 | public StyleSource getSource() 76 | { 77 | return source; 78 | } 79 | 80 | public T getDefaultValue() 81 | { 82 | return defaultValue; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/StyleSource.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style; 2 | 3 | public enum StyleSource 4 | { 5 | USER_AGENT, 6 | AUTHOR, 7 | INLINE, 8 | CODE 9 | } 10 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/adapter/DoubleTranslator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import net.voxelindustry.brokkgui.util.StringCountUtils; 4 | 5 | public class DoubleTranslator implements IStyleDecoder, IStyleEncoder, IStyleValidator 6 | { 7 | @Override 8 | public String encode(Double value, boolean prettyPrint) 9 | { 10 | return value.toString(); 11 | } 12 | 13 | @Override 14 | public Double decode(String style) 15 | { 16 | if (style.contains("%")) 17 | return Double.valueOf(style.replace('%', '\0')) / 100; 18 | return Double.valueOf(style); 19 | } 20 | 21 | @Override 22 | public int validate(String style) 23 | { 24 | int doubleLength = StringCountUtils.floatAtStart(style); 25 | 26 | if (doubleLength == 0) 27 | return 0; 28 | 29 | if (doubleLength < style.length() && style.charAt(doubleLength) == '%') 30 | return doubleLength + 1; 31 | return doubleLength; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/adapter/FloatTranslator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | import net.voxelindustry.brokkgui.util.StringCountUtils; 4 | 5 | public class FloatTranslator implements IStyleDecoder, IStyleEncoder, IStyleValidator 6 | { 7 | @Override 8 | public String encode(Float value, boolean prettyPrint) 9 | { 10 | return value.toString(); 11 | } 12 | 13 | @Override 14 | public Float decode(String style) 15 | { 16 | if (style.contains("%")) 17 | return Float.valueOf(style.replace('%', '\0')) / 100; 18 | return Float.valueOf(style); 19 | } 20 | 21 | @Override 22 | public int validate(String style) 23 | { 24 | int floatLength = StringCountUtils.floatAtStart(style); 25 | 26 | if (floatLength == 0) 27 | return 0; 28 | 29 | if (floatLength < style.length() && style.charAt(floatLength) == '%') 30 | return floatLength + 1; 31 | return floatLength; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/adapter/IStyleDecoder.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | @FunctionalInterface 4 | public interface IStyleDecoder 5 | { 6 | /** 7 | * Decode a css string and return the value. 8 | * 9 | * @param style css string 10 | * @return the decoded value 11 | */ 12 | T decode(String style); 13 | } 14 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/adapter/IStyleEncoder.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | @FunctionalInterface 4 | public interface IStyleEncoder 5 | { 6 | String encode(T value, boolean prettyPrint); 7 | } 8 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/adapter/IStyleValidator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.adapter; 2 | 3 | @FunctionalInterface 4 | public interface IStyleValidator 5 | { 6 | /** 7 | * Validate a css string and return the consumed length. 8 | * return 0 for an invalid css String. 9 | * 10 | * @param style css string 11 | * @return the consumed chars count 12 | */ 13 | int validate(String style); 14 | } 15 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/event/StyleRefreshEvent.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.event; 2 | 3 | import net.voxelindustry.brokkgui.style.ICascadeStyleable; 4 | import net.voxelindustry.hermod.EventType; 5 | import net.voxelindustry.hermod.HermodEvent; 6 | import net.voxelindustry.hermod.IEventEmitter; 7 | 8 | public class StyleRefreshEvent extends HermodEvent 9 | { 10 | public static final EventType ANY = new EventType<>("STYLE_REFRESH_EVENT"); 11 | 12 | public static final EventType BEFORE = new EventType<>("BEFORE_STYLE_REFRESH_EVENT"); 13 | public static final EventType AFTER = new EventType<>("AFTER_STYLE_REFRESH_EVENT"); 14 | 15 | public StyleRefreshEvent(ICascadeStyleable source) 16 | { 17 | super(source); 18 | } 19 | 20 | @Override 21 | public HermodEvent copy(IEventEmitter source) 22 | { 23 | return new StyleRefreshEvent((ICascadeStyleable) source); 24 | } 25 | 26 | public static class BeforeEvent extends StyleRefreshEvent 27 | { 28 | public BeforeEvent(ICascadeStyleable source) 29 | { 30 | super(source); 31 | } 32 | 33 | @Override 34 | public HermodEvent copy(IEventEmitter source) 35 | { 36 | return new BeforeEvent((ICascadeStyleable) source); 37 | } 38 | } 39 | 40 | public static class AfterEvent extends StyleRefreshEvent 41 | { 42 | public AfterEvent(ICascadeStyleable source) 43 | { 44 | super(source); 45 | } 46 | 47 | @Override 48 | public HermodEvent copy(IEventEmitter source) 49 | { 50 | return new AfterEvent((ICascadeStyleable) source); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/selector/IStyleSelector.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.selector; 2 | 3 | import net.voxelindustry.brokkgui.style.StyleHolder; 4 | 5 | public interface IStyleSelector 6 | { 7 | boolean match(StyleHolder styleHolder); 8 | 9 | boolean match(IStyleSelector selector); 10 | 11 | int getSpecificity(); 12 | 13 | IStyleSelector add(StyleSelectorType type, String selector); 14 | } 15 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/selector/StyleSelectorType.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.selector; 2 | 3 | public enum StyleSelectorType 4 | { 5 | WILDCARD(0), 6 | TYPE(1), 7 | CLASS(1_000), 8 | ID(1_000_000), 9 | PSEUDOCLASS(1_000), 10 | STRUCTURAL_PSEUDOCLASS(1_000); 11 | 12 | int specificity; 13 | 14 | StyleSelectorType(int specificity) 15 | { 16 | this.specificity = specificity; 17 | } 18 | 19 | public int getSpecificity() 20 | { 21 | return this.specificity; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/selector/structural/StructuralSelector.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.selector.structural; 2 | 3 | import net.voxelindustry.brokkgui.style.StyleHolder; 4 | 5 | import java.util.function.Predicate; 6 | 7 | public interface StructuralSelector extends Predicate 8 | { 9 | } 10 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/shorthand/GenericShorthandProperty.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.shorthand; 2 | 3 | import net.voxelindustry.brokkgui.style.StyleProperty; 4 | import net.voxelindustry.brokkgui.style.StyleSource; 5 | import net.voxelindustry.brokkgui.style.adapter.StyleTranslator; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class GenericShorthandProperty extends StyleProperty 11 | { 12 | private final List> childProperties; 13 | 14 | public GenericShorthandProperty(String defaultValue, String name) 15 | { 16 | super(defaultValue, name, String.class); 17 | 18 | this.childProperties = new ArrayList<>(); 19 | } 20 | 21 | public void addChild(StyleProperty childProperty) 22 | { 23 | childProperties.add(childProperty); 24 | } 25 | 26 | public void removeChild(StyleProperty childProperty) 27 | { 28 | childProperties.remove(childProperty); 29 | } 30 | 31 | public void applyDefaultValue() 32 | { 33 | this.setStyleRaw(StyleSource.USER_AGENT, 0, this.getDefaultValue()); 34 | } 35 | 36 | @Override 37 | public boolean setStyleRaw(StyleSource source, int specificity, String rawValue) 38 | { 39 | String current = rawValue; 40 | boolean anySet; 41 | List> alreadySet = new ArrayList<>(); 42 | 43 | while (!current.isEmpty()) 44 | { 45 | anySet = false; 46 | for (StyleProperty child : this.childProperties) 47 | { 48 | if (alreadySet.contains(child)) 49 | continue; 50 | 51 | int validated = StyleTranslator.getInstance().validate(current, child.getValueClass()); 52 | 53 | if (validated != 0) 54 | { 55 | child.setStyleRaw(source, specificity, current.substring(0, validated)); 56 | current = current.substring(validated).trim(); 57 | 58 | alreadySet.add(child); 59 | anySet = true; 60 | break; 61 | } 62 | } 63 | 64 | if (!anySet) 65 | return false; 66 | } 67 | return true; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/shorthand/ShorthandArgMapper.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.shorthand; 2 | 3 | @FunctionalInterface 4 | public interface ShorthandArgMapper 5 | { 6 | /** 7 | * Map a shorthand syntax to child properties indexes 8 | * 9 | * @param index of the current argument (0 ... n) 10 | * @param count numbers of specified arguments (1 ... n) 11 | * @return an array containing the indexes of the child properties to which apply the current argument 12 | */ 13 | int[] map(int index, int count); 14 | } 15 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/shorthand/ShorthandArgMappers.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.shorthand; 2 | 3 | public class ShorthandArgMappers 4 | { 5 | public static ShorthandArgMapper BOX_MAPPER = (index, count) -> 6 | { 7 | switch (count) 8 | { 9 | case 1: 10 | return new int[]{0, 1, 2, 3}; // top, right, bottom, left 11 | case 2: 12 | if (index == 0) 13 | return new int[]{0, 2}; // top, bottom 14 | return new int[]{1, 3}; // right, left 15 | case 3: 16 | if (index == 0) 17 | return new int[]{0}; // top 18 | if (index == 2) 19 | return new int[]{2}; // bottom 20 | return new int[]{1, 3}; // right, left 21 | case 4: 22 | return new int[]{index}; 23 | default: 24 | return new int[0]; 25 | } 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/shorthand/ShorthandProperty.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.shorthand; 2 | 3 | import net.voxelindustry.brokkgui.style.StyleProperty; 4 | import net.voxelindustry.brokkgui.style.StyleSource; 5 | import net.voxelindustry.brokkgui.style.adapter.StyleTranslator; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class ShorthandProperty extends StyleProperty 11 | { 12 | private final List> childProperties; 13 | private final ShorthandArgMapper argMapper; 14 | 15 | public ShorthandProperty(T defaultValue, String name, Class valueClass, ShorthandArgMapper argMapper) 16 | { 17 | super(defaultValue, name, valueClass); 18 | 19 | this.childProperties = new ArrayList<>(); 20 | this.argMapper = argMapper; 21 | } 22 | 23 | public void addChild(StyleProperty childProperty) 24 | { 25 | childProperties.add(childProperty); 26 | } 27 | 28 | public void removeChild(StyleProperty childProperty) 29 | { 30 | childProperties.remove(childProperty); 31 | } 32 | 33 | @Override 34 | public boolean setStyle(StyleSource source, int specificity, T value) 35 | { 36 | this.childProperties.forEach(child -> child.setStyle(source, specificity, value)); 37 | return super.setStyle(source, specificity, value); 38 | } 39 | 40 | @Override 41 | public boolean setStyleRaw(StyleSource source, int specificity, String rawValue) 42 | { 43 | List values = new ArrayList<>(); 44 | String current = rawValue; 45 | 46 | while (!current.isEmpty()) 47 | { 48 | int validated = StyleTranslator.getInstance().validate(current, this.getValueClass()); 49 | 50 | if (validated == 0) 51 | break; 52 | 53 | values.add(StyleTranslator.getInstance().decode(current.substring(0, validated), this.getValueClass())); 54 | current = current.substring(validated).trim(); 55 | } 56 | 57 | for (int valueIndex = 0; valueIndex < values.size(); valueIndex++) 58 | { 59 | for (int childIndex : argMapper.map(valueIndex, values.size())) 60 | childProperties.get(childIndex).setStyle(source, specificity, values.get(valueIndex)); 61 | } 62 | 63 | if (!values.isEmpty()) 64 | this.internalSetStyle(source, specificity, values.get(0)); 65 | return true; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/tree/StyleEntry.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.tree; 2 | 3 | import net.voxelindustry.brokkgui.style.selector.IStyleSelector; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class StyleEntry 9 | { 10 | private IStyleSelector selector; 11 | private List rules; 12 | 13 | public StyleEntry(IStyleSelector selector) 14 | { 15 | this.selector = selector; 16 | this.rules = new ArrayList<>(); 17 | } 18 | 19 | public void mergeRules(List rules) 20 | { 21 | rules.forEach(rule -> 22 | { 23 | if (this.rules.stream().noneMatch(rule2 -> rule2.getRuleIdentifier().equals(rule.getRuleIdentifier()))) 24 | this.rule(rule); 25 | }); 26 | } 27 | 28 | public StyleEntry rule(StyleRule rule) 29 | { 30 | if (!this.rules.contains(rule)) 31 | this.rules.add(rule); 32 | return this; 33 | } 34 | 35 | public IStyleSelector getSelector() 36 | { 37 | return selector; 38 | } 39 | 40 | public List getRules() 41 | { 42 | return rules; 43 | } 44 | 45 | @Override 46 | public String toString() 47 | { 48 | return "{selector=" + selector + ", rules=" + rules + '}'; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/tree/StyleList.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.tree; 2 | 3 | import net.voxelindustry.brokkgui.style.StyleHolder; 4 | import net.voxelindustry.brokkgui.style.selector.IStyleSelector; 5 | import net.voxelindustry.brokkgui.style.selector.StyleSelector; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import java.util.Optional; 10 | 11 | public class StyleList 12 | { 13 | private List styleEntries; 14 | private StyleEntry wildcard; 15 | 16 | public StyleList() 17 | { 18 | this.wildcard = new StyleEntry(new StyleSelector().addWildcard()); 19 | this.styleEntries = new ArrayList<>(); 20 | this.styleEntries.add(this.wildcard); 21 | } 22 | 23 | public StyleList(StyleList original) 24 | { 25 | this(); 26 | this.merge(original); 27 | } 28 | 29 | public StyleList merge(StyleList src) 30 | { 31 | src.getInternalStyleList().forEach(entry -> this.addEntry(entry.getSelector(), entry.getRules())); 32 | return this; 33 | } 34 | 35 | public void addEntry(IStyleSelector selectors, List rules) 36 | { 37 | StyleEntry lastAdded; 38 | 39 | Optional match = this.styleEntries.stream().filter(styleEntry -> 40 | styleEntry.getSelector().match(selectors)).findFirst(); 41 | 42 | if (!match.isPresent()) 43 | { 44 | StyleEntry newEntry = new StyleEntry(selectors); 45 | this.styleEntries.add(newEntry); 46 | lastAdded = newEntry; 47 | } 48 | else 49 | lastAdded = match.get(); 50 | lastAdded.mergeRules(rules); 51 | } 52 | 53 | public List getInternalStyleList() 54 | { 55 | return this.styleEntries; 56 | } 57 | 58 | public StyleEntry getWildcard() 59 | { 60 | return this.wildcard; 61 | } 62 | 63 | void clear() 64 | { 65 | this.styleEntries.clear(); 66 | this.styleEntries.add(wildcard); 67 | this.wildcard.getRules().clear(); 68 | } 69 | 70 | boolean isEmpty() 71 | { 72 | return this.styleEntries.size() == 1 && this.wildcard.getRules().isEmpty(); 73 | } 74 | 75 | public List getEntriesMatching(StyleHolder styleHolder) 76 | { 77 | List entries = new ArrayList<>(); 78 | 79 | entries.add(this.wildcard); 80 | this.styleEntries.forEach(entry -> 81 | { 82 | if (entry.getSelector().match(styleHolder)) 83 | entries.add(entry); 84 | }); 85 | return entries; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/style/tree/StyleRule.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.style.tree; 2 | 3 | import javax.annotation.Nonnull; 4 | 5 | public class StyleRule 6 | { 7 | private final String ruleIdentifier; 8 | private final String ruleValue; 9 | 10 | public StyleRule(@Nonnull String ruleIdentifier, @Nonnull String ruleValue) 11 | { 12 | this.ruleIdentifier = ruleIdentifier; 13 | this.ruleValue = ruleValue; 14 | } 15 | 16 | public String getRuleIdentifier() 17 | { 18 | return ruleIdentifier; 19 | } 20 | 21 | public String getRuleValue() 22 | { 23 | return ruleValue; 24 | } 25 | 26 | @Override 27 | public String toString() 28 | { 29 | return "{ruleIdentifier='" + ruleIdentifier + '\'' + ", ruleValue='" + ruleValue + '\'' + '}'; 30 | } 31 | 32 | @Override 33 | public boolean equals(Object o) 34 | { 35 | if (this == o) return true; 36 | if (o == null || getClass() != o.getClass()) return false; 37 | 38 | StyleRule styleRule = (StyleRule) o; 39 | 40 | return getRuleIdentifier().equals(styleRule.getRuleIdentifier()) && getRuleValue().equals(styleRule 41 | .getRuleValue()); 42 | } 43 | 44 | @Override 45 | public int hashCode() 46 | { 47 | int result = getRuleIdentifier().hashCode(); 48 | result = 31 * result + getRuleValue().hashCode(); 49 | return result; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/util/NumberedLineIterator.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.util; 2 | 3 | import org.apache.commons.io.LineIterator; 4 | 5 | import java.io.Reader; 6 | 7 | public class NumberedLineIterator extends LineIterator 8 | { 9 | private int lineNumber; 10 | 11 | public NumberedLineIterator(Reader reader) throws IllegalArgumentException 12 | { 13 | super(reader); 14 | 15 | this.lineNumber = -1; 16 | } 17 | 18 | public String nextLine() 19 | { 20 | lineNumber++; 21 | return super.nextLine(); 22 | } 23 | 24 | public int getLineNumber() 25 | { 26 | return lineNumber; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /style/src/main/java/net/voxelindustry/brokkgui/util/StringCountUtils.java: -------------------------------------------------------------------------------- 1 | package net.voxelindustry.brokkgui.util; 2 | 3 | public class StringCountUtils 4 | { 5 | public static int integerAtStart(String str) 6 | { 7 | int count = 0; 8 | 9 | for (int index = 0; index < str.length(); index++) 10 | { 11 | // Early return to prevent parsing a floating number 12 | if (str.charAt(index) == '.') 13 | return 0; 14 | 15 | if (!Character.isDigit(str.charAt(index)) && ((index != 0 || str.charAt(index) != '+') && str.charAt(index) != '-')) 16 | break; 17 | count++; 18 | } 19 | return count; 20 | } 21 | 22 | public static int floatAtStart(String str) 23 | { 24 | int count = 0; 25 | boolean decimalPart = false; 26 | 27 | for (int index = 0; index < str.length(); index++) 28 | { 29 | if (str.charAt(index) == '.' && !decimalPart) 30 | decimalPart = true; 31 | else if (!Character.isDigit(str.charAt(index)) && ((index != 0 || str.charAt(index) != '+') && str.charAt(index) != '-')) 32 | break; 33 | count++; 34 | } 35 | return count; 36 | } 37 | 38 | public static int boolAtStart(String str) 39 | { 40 | if (str.equalsIgnoreCase("true")) 41 | return 4; 42 | else 43 | return 5; 44 | } 45 | } 46 | --------------------------------------------------------------------------------