Skip to content

Commit

Permalink
IMGUI themes and adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbuzatto committed Jan 25, 2025
1 parent f393d1f commit 6a7d09e
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 75 deletions.
Binary file added resources/images/moon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/sunAndMoon.fla
Binary file not shown.
35 changes: 27 additions & 8 deletions src/br/com/davidbuzatto/jsge/examples/basic/IMGUIExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import br.com.davidbuzatto.jsge.collision.CollisionUtils;
import br.com.davidbuzatto.jsge.core.engine.EngineFrame;
import br.com.davidbuzatto.jsge.image.Image;
import br.com.davidbuzatto.jsge.imgui.GuiButton;
import br.com.davidbuzatto.jsge.imgui.GuiButtonGroup;
import br.com.davidbuzatto.jsge.imgui.GuiCheckBox;
Expand Down Expand Up @@ -134,6 +135,9 @@ public class IMGUIExample extends EngineFrame {
private GuiTheme currentTheme;
private ChangeThemeButton changeThemeButton;

private Image sunIcon;
private Image moonIcon;

/**
* Cria o exemplo.
*/
Expand Down Expand Up @@ -296,7 +300,12 @@ public void create() {
checkVisible = new GuiCheckBox( x, y += vSpacing, 100, 20, "Visible" );
checkVisible.setSelected( true );
checkDrawBounds = new GuiCheckBox( x, y += vSpacing, 100, 20, "Draw bounds" );
changeThemeButton = new ChangeThemeButton( getScreenWidth() - 60, getScreenHeight() - 60, 50, 50 );

changeThemeButton = new ChangeThemeButton(
getScreenWidth() - 60, getScreenHeight() - 60, 50, 50,
loadImage( "resources/images/sun.png" ),
loadImage( "resources/images/moon.png" )
);

toolTipLabel1 = new GuiToolTip( label1, "Top and Left Label" );
toolTipLabel2 = new GuiToolTip( label2, "Middle and Center Label" );
Expand All @@ -316,7 +325,6 @@ public void create() {
interactionComponents.add( checkDrawBounds );
interactionComponents.add( changeThemeButton );


}

@Override
Expand Down Expand Up @@ -495,14 +503,13 @@ public void update( double delta ) {
if ( changeThemeButton.isMousePressed() ) {
changeThemeButton.darkThemeActive = !changeThemeButton.darkThemeActive;
if ( changeThemeButton.darkThemeActive ) {
darkTheme.install( components );
darkTheme.install( interactionComponents );
currentTheme = darkTheme;
} else {
lightTheme.install( components );
lightTheme.install( interactionComponents );
currentTheme = lightTheme;
}
currentTheme.apply( components );
currentTheme.apply( interactionComponents );
currentTheme.install();
}

if ( isMouseButtonPressed( MOUSE_BUTTON_RIGHT ) ) {
Expand Down Expand Up @@ -657,17 +664,29 @@ private void drawColoredRectangle( double x, double y, Color color ) {
private class ChangeThemeButton extends GuiComponent {

private boolean darkThemeActive;
private Image sunIcon;
private Image moonIcon;

public ChangeThemeButton( double x, double y, double width, double height ) {
public ChangeThemeButton( double x, double y, double width, double height, Image sunIcon, Image moonIcon ) {
super( x, y, width, height );
this.sunIcon = sunIcon;
this.moonIcon = moonIcon;
}

public ChangeThemeButton( double x, double y, double width, double height, EngineFrame engine ) {
public ChangeThemeButton( double x, double y, double width, double height, Image sunIcon, Image moonIcon, EngineFrame engine ) {
super( x, y, width, height, engine );
this.sunIcon = sunIcon;
this.moonIcon = moonIcon;
}

@Override
public void draw() {
fillRectangle( bounds, backgroundColor );
if ( darkThemeActive ) {
drawImage( moonIcon, bounds.x, bounds.y );
} else {
drawImage( sunIcon, bounds.x, bounds.y );
}
drawRectangle( bounds, borderColor );
}

Expand Down
3 changes: 1 addition & 2 deletions src/br/com/davidbuzatto/jsge/imgui/GuiDropdownList.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import br.com.davidbuzatto.jsge.core.engine.EngineFrame;
import br.com.davidbuzatto.jsge.geom.Rectangle;
import br.com.davidbuzatto.jsge.math.MathUtils;
import br.com.davidbuzatto.jsge.math.Vector2;
import java.awt.Color;
import java.util.List;

Expand Down Expand Up @@ -205,7 +204,7 @@ private void drawDropdownList( Color borderColor, Color containerColor, Color te
@Override
public void setEnabled( boolean enabled ) {
super.setEnabled( enabled );
itemsList.setEnabled( enabled );
//itemsList.setEnabled( enabled );
}

/**
Expand Down
Loading

0 comments on commit 6a7d09e

Please sign in to comment.