Enable full support for icon sets in GUI
This commit is contained in:
@@ -44,6 +44,8 @@ public interface GUI extends Renderable, Updatable, Disposable {
|
||||
|
||||
Image getImage(String imageUid, int imageFlags);
|
||||
|
||||
IconSet getIconSet(String iconSetUid);
|
||||
|
||||
void beginPath();
|
||||
|
||||
void closePath();
|
||||
@@ -114,9 +116,13 @@ public interface GUI extends Renderable, Updatable, Disposable {
|
||||
|
||||
void radialGradient(float x, float y, float innerRadius, float outerRadius, Color start, Color end, Paint target);
|
||||
|
||||
void imagePattern(float x, float y, float angle, float alpha, Image image, Paint target);
|
||||
Paint imagePattern(float x, float y, float angle, float alpha, Image image, Paint target);
|
||||
|
||||
void imagePattern(float x, float y, float width, float height, float angle, float alpha, Image image, Paint target);
|
||||
Paint imagePattern(float x, float y, float width, float height, float angle, float alpha, Image image, Paint target);
|
||||
|
||||
void image(float x, float y, float scaleX, float scaleY, float angle, float alpha, Image image, Paint target);
|
||||
|
||||
void icon(float x, float y, float scaleX, float scaleY, float angle, float alpha, IconSet iconSet, int row, int column, Paint target);
|
||||
|
||||
void clip(float x, float y, float width, float height);
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.bartlomiejpluta.base.api.gui;
|
||||
|
||||
public interface IconSet {
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
|
||||
int getRows();
|
||||
|
||||
int getColumns();
|
||||
|
||||
int getIconHeight();
|
||||
|
||||
int getIconWidth();
|
||||
}
|
||||
@@ -6,4 +6,10 @@ public interface Icon extends Entity {
|
||||
void changeIcon(int row, int column);
|
||||
|
||||
void changeIcon(String iconSetUid, int row, int column);
|
||||
|
||||
String getIconSetUid();
|
||||
|
||||
int getIconSetRow();
|
||||
|
||||
int getIconSetColumn();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package com.bartlomiejpluta.base.lib.gui;
|
||||
|
||||
import com.bartlomiejpluta.base.api.context.Context;
|
||||
import com.bartlomiejpluta.base.api.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.gui.IconSet;
|
||||
import com.bartlomiejpluta.base.api.gui.Paint;
|
||||
import com.bartlomiejpluta.base.api.icon.Icon;
|
||||
import com.bartlomiejpluta.base.api.screen.Screen;
|
||||
import lombok.NonNull;
|
||||
import lombok.Setter;
|
||||
|
||||
public class IconView extends BaseComponent {
|
||||
private final GUI gui;
|
||||
private final Paint paint;
|
||||
|
||||
private IconSet iconSet;
|
||||
|
||||
@NonNull
|
||||
@Setter
|
||||
private Float scaleX = 1f;
|
||||
|
||||
@NonNull
|
||||
@Setter
|
||||
private Float scaleY = 1f;
|
||||
|
||||
@NonNull
|
||||
@Setter
|
||||
private Float angle = 0f;
|
||||
|
||||
@NonNull
|
||||
@Setter
|
||||
private Float alpha = 1f;
|
||||
|
||||
@NonNull
|
||||
@Setter
|
||||
private Integer iconSetRow = 0;
|
||||
|
||||
@NonNull
|
||||
@Setter
|
||||
private Integer iconSetColumn = 0;
|
||||
|
||||
|
||||
public IconView(Context context, GUI gui) {
|
||||
super(context, gui);
|
||||
this.gui = gui;
|
||||
this.paint = gui.createPaint();
|
||||
}
|
||||
|
||||
public void setIcon(Icon icon) {
|
||||
if (icon == null) {
|
||||
iconSet = null;
|
||||
return;
|
||||
}
|
||||
|
||||
iconSet = gui.getIconSet(icon.getIconSetUid());
|
||||
iconSetRow = icon.getIconSetRow();
|
||||
iconSetColumn = icon.getIconSetColumn();
|
||||
}
|
||||
|
||||
public void setScale(@NonNull Float scale) {
|
||||
this.scaleX = scale;
|
||||
this.scaleY = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getContentWidth() {
|
||||
return iconSet != null ? iconSet.getIconWidth() * scaleX : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getContentHeight() {
|
||||
return iconSet != null ? iconSet.getIconHeight() * scaleY : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Screen screen, GUI gui) {
|
||||
if (iconSet == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
gui.icon(x, y, scaleX, scaleY, angle, alpha, iconSet, iconSetRow, iconSetColumn, paint);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user