-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add events for GuiComponent rendering
- Loading branch information
1 parent
884d1a9
commit bfc8d2f
Showing
4 changed files
with
158 additions
and
21 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
core/src/main/java/de/gurkenlabs/litiengine/gui/ComponentRenderEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package de.gurkenlabs.litiengine.gui; | ||
|
||
import java.awt.Graphics2D; | ||
import java.util.EventObject; | ||
|
||
public class ComponentRenderEvent extends EventObject { | ||
|
||
private final transient Graphics2D graphics; | ||
private final transient GuiComponent component; | ||
|
||
/** | ||
* Constructs a prototypical Event. | ||
* | ||
* @param source the object on which the Event initially occurred | ||
* @throws IllegalArgumentException if source is null | ||
*/ | ||
public ComponentRenderEvent(final Graphics2D graphics, final GuiComponent source) { | ||
super(source); | ||
|
||
this.graphics = graphics; | ||
this.component = source; | ||
} | ||
|
||
/** | ||
* Get the component involved with the rendering process. | ||
* | ||
* @return The component involved with the rendering process. | ||
*/ | ||
public GuiComponent getComponent() { | ||
return this.component; | ||
} | ||
|
||
/** | ||
* Gets the graphics object on which the entity is rendered. | ||
* | ||
* @return The graphics object on which the entity is rendered. | ||
*/ | ||
public Graphics2D getGraphics() { | ||
return this.graphics; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
core/src/main/java/de/gurkenlabs/litiengine/gui/ComponentRenderListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package de.gurkenlabs.litiengine.gui; | ||
|
||
import de.gurkenlabs.litiengine.entities.EntityRenderEvent; | ||
import java.awt.Graphics2D; | ||
|
||
/** | ||
* This listener interface is used for receiving events during a component's rendering process. | ||
* | ||
* @see GuiComponent#render(Graphics2D) | ||
*/ | ||
public interface ComponentRenderListener extends ComponentRenderedListener { | ||
|
||
/** | ||
* This method gets called after all rendering checks have successfully passed and right before | ||
* the component is about to be rendered. | ||
* | ||
* @param event The event that contains the render data. | ||
*/ | ||
default void rendering(ComponentRenderEvent event) { | ||
} | ||
|
||
/** | ||
* This method gets called before an {@code GuiComponent} is about to be rendered. Returning false | ||
* prevents the rendering of the specified component. | ||
* | ||
* @param component The component to be rendered. | ||
* @return True if the component should be rendered; otherwise false. | ||
*/ | ||
default boolean canRender(GuiComponent component) { | ||
return true; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/main/java/de/gurkenlabs/litiengine/gui/ComponentRenderedListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package de.gurkenlabs.litiengine.gui; | ||
|
||
import java.awt.Graphics2D; | ||
import java.util.EventListener; | ||
|
||
/** | ||
* This listener interface is used for receiving events after an component was rendered. | ||
* | ||
* @see GuiComponent#render(Graphics2D) | ||
*/ | ||
@FunctionalInterface | ||
public interface ComponentRenderedListener extends EventListener { | ||
|
||
/** | ||
* This method gets called after an {@link GuiComponent} was rendered. | ||
* | ||
* @param event The event that contains the render data. | ||
*/ | ||
void rendered(ComponentRenderEvent event); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters