Implement text drawing features
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
6a418eb9db
commit
bf59e5c7c2
@ -1,6 +1,7 @@
|
||||
package sig;
|
||||
|
||||
import sig.engine.Alpha;
|
||||
import sig.engine.Font;
|
||||
import sig.engine.PaletteColor;
|
||||
import sig.engine.Panel;
|
||||
import sig.engine.Sprite;
|
||||
@ -26,6 +27,27 @@ public class DrawLoop {
|
||||
}
|
||||
}
|
||||
|
||||
public static void Draw_Text(double x, double y, StringBuilder s, Font f) {
|
||||
Draw_Text_Ext(x,y,s,f,Alpha.ALPHA0,PaletteColor.NORMAL);
|
||||
}
|
||||
|
||||
public static void Draw_Text_Ext(double x, double y, StringBuilder s, Font f, Alpha alpha, PaletteColor col) {
|
||||
String finalS = s.toString();
|
||||
int charCount=0;
|
||||
int yOffset=0;
|
||||
int xOffset=0;
|
||||
for (int i=0;i<finalS.length();i++) {
|
||||
if (finalS.charAt(i)=='\n') {
|
||||
xOffset+=(charCount+1)*f.getGlyphWidth();
|
||||
yOffset+=f.getGlyphHeight();
|
||||
charCount=0;
|
||||
} else {
|
||||
Draw_Sprite_Partial_Ext(x+i*f.getGlyphWidth()-xOffset, y+yOffset, f.getCharInfo(finalS.charAt(i)).getX(), f.getCharInfo(finalS.charAt(i)).getY(), f.getCharInfo(finalS.charAt(i)).getWidth(), f.getCharInfo(finalS.charAt(i)).getHeight(), f.getSprite(),alpha,col);
|
||||
charCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Draw_Sprite(double x, double y, Sprite sprite){
|
||||
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite);
|
||||
}
|
||||
|
||||
46
src/sig/engine/Font.java
Normal file
46
src/sig/engine/Font.java
Normal file
@ -0,0 +1,46 @@
|
||||
package sig.engine;
|
||||
|
||||
public enum Font {
|
||||
PROFONT_12((byte)7,(byte)14,Sprite.PROFONT),
|
||||
;
|
||||
|
||||
byte glyphWidth,glyphHeight;
|
||||
int glyphCountX,glyphCountY;
|
||||
Rectangle[] charBounds;
|
||||
Sprite spr;
|
||||
|
||||
Font(byte glyphWidth, byte glyphHeight, Sprite spr) {
|
||||
this.glyphWidth=glyphWidth;
|
||||
this.glyphHeight=glyphHeight;
|
||||
this.glyphCountX=spr.width/glyphWidth;
|
||||
this.glyphCountY=spr.height/glyphHeight;
|
||||
this.charBounds = new Rectangle[256];
|
||||
for (int y=0;y<glyphCountY;y++) {
|
||||
for (int x=0;x<glyphCountX;x++) {
|
||||
if (y*glyphCountX+x<256) {
|
||||
charBounds[y*glyphCountX+x]=new Rectangle(x*glyphWidth,y*glyphHeight,glyphWidth,glyphHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.spr=spr;
|
||||
}
|
||||
|
||||
public Rectangle getCharacterBounds(char c) {
|
||||
return charBounds[c];
|
||||
}
|
||||
|
||||
public byte getGlyphWidth() {
|
||||
return glyphWidth;
|
||||
}
|
||||
|
||||
public byte getGlyphHeight() {
|
||||
return glyphHeight;
|
||||
}
|
||||
public Rectangle getCharInfo(char c) {
|
||||
return charBounds[c];
|
||||
}
|
||||
|
||||
public Sprite getSprite() {
|
||||
return spr;
|
||||
}
|
||||
}
|
||||
@ -54,6 +54,14 @@ public abstract class Object implements GameEntity{
|
||||
DrawLoop.Draw_Sprite(x,y,sprite);
|
||||
}
|
||||
|
||||
protected void Draw_Text(double x, double y, StringBuilder string, Font font){
|
||||
DrawLoop.Draw_Text(x,y,string,font);
|
||||
}
|
||||
|
||||
protected void Draw_Text_Ext(double x, double y, StringBuilder string, Font font, Alpha alpha, PaletteColor col){
|
||||
DrawLoop.Draw_Text_Ext(x,y,string,font,alpha,col);
|
||||
}
|
||||
|
||||
protected void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite){
|
||||
DrawLoop.Draw_Sprite_Partial(x,y,xOffset,yOffset,w,h,sprite);
|
||||
}
|
||||
|
||||
45
src/sig/engine/Rectangle.java
Normal file
45
src/sig/engine/Rectangle.java
Normal file
@ -0,0 +1,45 @@
|
||||
package sig.engine;
|
||||
|
||||
public class Rectangle {
|
||||
int x,y,w,h;
|
||||
|
||||
public Rectangle(int x, int y, int w, int h) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public void setWidth(int w) {
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return h;
|
||||
}
|
||||
|
||||
public void setHeight(int h) {
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
}
|
||||
@ -5,6 +5,7 @@ import java.awt.event.MouseEvent;
|
||||
|
||||
import sig.RabiClone;
|
||||
import sig.engine.Alpha;
|
||||
import sig.engine.Font;
|
||||
import sig.engine.MouseScrollValue;
|
||||
import sig.engine.PaletteColor;
|
||||
import sig.engine.Panel;
|
||||
@ -16,6 +17,10 @@ public class EditorRenderer extends LevelRenderer{
|
||||
|
||||
Tile selectedTile = Tile.WALL;
|
||||
|
||||
final StringBuilder tempText = new StringBuilder("Hello World!\n\n Test newlines!\nTest\nTest2\nTest3");
|
||||
int frameCount=0;
|
||||
StringBuilder frameCheck = new StringBuilder("I am blue! Frame:").append(frameCount);
|
||||
|
||||
public EditorRenderer(Panel panel) {
|
||||
super(panel);
|
||||
}
|
||||
@ -59,7 +64,8 @@ public class EditorRenderer extends LevelRenderer{
|
||||
@Override
|
||||
public void draw(byte[] p) {
|
||||
super.draw(p);
|
||||
Draw_Sprite_Partial_Ext(16, 16, 0, 0, 96, 96, Sprite.PROFONT, Alpha.ALPHA0, PaletteColor.SKY_BLUE);
|
||||
Draw_Text(32,16,tempText,Font.PROFONT_12);
|
||||
Draw_Text_Ext(104,137,new StringBuilder("I am blue! Frame:").append(frameCount++),Font.PROFONT_12,Alpha.ALPHA0,PaletteColor.SLATE_BLUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user