feat: animated background
All checks were successful
Linux arm64 / Build (push) Successful in 10m56s

This commit is contained in:
2025-01-30 22:28:26 +01:00
parent a74bf42e59
commit f47e4cc309
4 changed files with 37 additions and 7 deletions

View File

@@ -0,0 +1,28 @@
package gui;
import imgui.ImGui;
import imgui.ImVec2;
import imgui.flag.ImGuiWindowFlags;
public class AnimatedBackground {
private float backgroundOffset = 0;
public AnimatedBackground() {
}
public void render() {
backgroundOffset += ImGui.getIO().getDeltaTime() / 10.0f * Options.BackgroundSpeed;
var displaySize = ImGui.getIO().getDisplaySize();
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
ImGui.setNextWindowSize(displaySize);
ImGui.begin("Background", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBackground
| ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoInputs);
ImGui.image(Images.BACKGROUND, displaySize, new ImVec2(backgroundOffset, backgroundOffset),
new ImVec2(1.0f + backgroundOffset, 1.0f + backgroundOffset));
ImGui.end();
}
}

View File

@@ -3,5 +3,6 @@ package gui;
public class Options {
public static Symbols Symboles = Symbols.Numbers;
public static float BackgroundSpeed = 1.0f;
}

View File

@@ -8,6 +8,7 @@ import imgui.type.ImInt;
public class OptionsMenu extends BaseView {
private ImInt currentValue = new ImInt();
private float backgroundSpeed[] = new float[]{Options.BackgroundSpeed};
public OptionsMenu(StateMachine stateMachine) {
super(stateMachine);
@@ -19,6 +20,9 @@ public class OptionsMenu extends BaseView {
if(ImGui.combo("Jeu de symboles", currentValue, Symbols.getSymbolsNames())){
Options.Symboles = Symbols.values()[currentValue.get()];
}
if(ImGui.sliderFloat("Vitesse d'animation de l'arrière plan", backgroundSpeed, 0.0f, 10.0f)){
Options.BackgroundSpeed = backgroundSpeed[0];
}
renderReturnButton();
}

View File

@@ -2,7 +2,7 @@ package gui.menu;
import java.util.Stack;
import gui.Images;
import gui.AnimatedBackground;
import imgui.ImGui;
import imgui.ImVec2;
import imgui.flag.ImGuiKey;
@@ -11,9 +11,11 @@ import imgui.flag.ImGuiWindowFlags;
public class StateMachine {
private final Stack<BaseView> menus;
private final AnimatedBackground background;
public StateMachine() {
this.menus = new Stack<>();
this.background = new AnimatedBackground();
}
public void clear() {
@@ -40,12 +42,7 @@ public class StateMachine {
public void render() {
var displaySize = ImGui.getIO().getDisplaySize();
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
ImGui.setNextWindowSize(displaySize);
ImGui.begin("Background", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoInputs);
ImGui.image(Images.BACKGROUND, displaySize, new ImVec2(0, 0));
ImGui.end();
this.background.render();
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
ImGui.setNextWindowSize(displaySize);
ImGui.begin("##Main Window", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove