Ability to specify border color

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
gpu
sigonasr2 2 years ago
parent 1c98574f06
commit c30f780bb5
  1. 6
      src/sig/JavaProjectTemplate.java
  2. 63
      src/sig/engine/Panel.java

@ -34,7 +34,7 @@ public class JavaProjectTemplate {
public void initializeGame(){
//Initialize your game here.
game.SetBorderColor(Color.BRIGHT_BLACK);
game.Cursor_SetCursor(new Sprite("cursor.png"),0,0);
}
@ -93,8 +93,8 @@ public class JavaProjectTemplate {
game.Draw_Animated_Sprite(pl.x,pl.y,pl.spr,pl.animationFrame); //Animated Sprite drawing
game.Draw_Text(10,40,"Mouse X: "+Mouse.x+" Mouse Y:"+Mouse.y,Font.PROFONT_12); //Draw Mouse coordinates in tiny font
game.Draw_Text_Ext(10,52,"Hello World 2!",Font.PROFONT_36,Color.MAGENTA); //Draw in larger font
game.Draw_Text_Ext(10,40,"Mouse X: "+Mouse.x+" Mouse Y:"+Mouse.y,Font.PROFONT_12,Color.BLACK,2,2); //Draw Mouse coordinates in tiny font
game.Draw_Text_Ext(10,52,"Hello World 2!",Font.PROFONT_36,Color.MAGENTA,1,1); //Draw in larger font
game.Fill_Triangle(160,160,190,190,50,250,new Color(255,0,0,150)); //Draw a translucent colored triangle

@ -65,7 +65,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
public static Panel p;
public static JFrame f;
int ACTUAL_WINDOW_WIDTH,ACTUAL_WINDOW_HEIGHT;
int ACTUAL_WINDOW_WIDTH=JavaProjectTemplate.WINDOW_WIDTH,ACTUAL_WINDOW_HEIGHT=JavaProjectTemplate.WINDOW_HEIGHT;
Point<Integer> vViewSize = new Point<Integer>(1,1);
Point<Integer> vViewPos = new Point<Integer>(1,1);
java.awt.Color borderCol = java.awt.Color.BLACK;
@ -376,7 +376,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
}
void Draw(int index, int col) {
if (((col>>>24)&0xff)==0||index>=pixel.length) return;
if (((col>>>24)&0xff)==0) return;
if (((col>>>24)&0xff)!=255) {
pixel[index]=ColorLerpNoAlpha(new Color(pixel[index]),new Color(col),((col>>>24)&0xff)/255f).getColor();
} else {
@ -457,15 +457,15 @@ public class Panel extends JPanel implements Runnable,KeyListener {
Draw_Text(x,y,new String(s),f);
}
public void Draw_Text_Ext(double x, double y, java.lang.String s, Font f, Color col){
Draw_Text_Ext(x,y,new String(s),f,col);
public void Draw_Text_Ext(double x, double y, java.lang.String s, Font f, Color col, int scalex, int scaley){
Draw_Text_Ext(x,y,new String(s),f,col,scalex,scaley);
}
private void Draw_Text(double x, double y, String s, Font f) {
Draw_Text_Ext(x,y,s,f,Color.BLACK);
Draw_Text_Ext(x,y,s,f,Color.BLACK,1,1);
}
private void Draw_Text_Ext(double x, double y, String s, Font f, Color col) {
private void Draw_Text_Ext(double x, double y, String s, Font f, Color col, int scalex, int scaley) {
java.lang.String finalS = s.toString();
int charCount=0;
int yOffset=0;
@ -477,7 +477,7 @@ public class Panel extends JPanel implements Runnable,KeyListener {
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(), 0,currentCol,Transform.NONE);
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(), currentCol,Transform.NONE,scalex,scaley);
charCount++;
}
}
@ -544,39 +544,38 @@ public class Panel extends JPanel implements Runnable,KeyListener {
}
public void Draw_Sprite(double x, double y, Sprite sprite){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Color.WHITE,Transform.NONE);
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,Color.WHITE,Transform.NONE);
}
public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,Color.WHITE,Transform.NONE);
Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,Color.WHITE,Transform.NONE);
}
public void Draw_Sprite(double x, double y, Sprite sprite, Color col){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,col,Transform.NONE);
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,col,Transform.NONE);
}
public void Draw_Sprite(double x, double y, Sprite sprite, Transform transform){
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,0,Color.WHITE,transform);
Draw_Sprite_Partial(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,Color.WHITE,transform);
}
public void Draw_Sprite(double x, double y, Sprite sprite, Color col, Transform transform, int scalex, int scaley){
Draw_Sprite_Partial_Ext(x,y,0,0,sprite.getWidth(),sprite.getHeight(),sprite,col,transform,scalex,scaley);
}
public void Draw_Animated_Sprite(double x, double y, AnimatedSprite sprite, double frameIndex, Color col, Transform transform){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,frameIndex,col,transform);
}
public void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Color col, Transform transform){
Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,frame_index, col,transform);
Draw_Sprite_Partial(x,y,frameRectangle.getX(),frameRectangle.getY(),frameRectangle.getWidth(),frameRectangle.getHeight(),sprite,col,transform);
}
public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Color col, Transform transform){
Draw_Sprite_Partial_Ext(x, y, xOffset, yOffset, w, h, sprite, 0, col, transform);
public void Draw_Sprite_Partial(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Color col, Transform transform){
Draw_Sprite_Partial_Ext(x,y,xOffset,yOffset,w,h,sprite,col,transform,1,1);
}
public void Draw_Animated_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, AnimatedSprite sprite, double frameIndex, Color col, Transform transform){
public void Draw_Animated_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, AnimatedSprite sprite, double frameIndex, Color col, Transform transform, int scalex, int scaley){
Rectangle frameRectangle=sprite.getFrame((int)frameIndex);
Draw_Sprite_Partial_Ext(x, y, frameRectangle.getX(), frameRectangle.getY(), frameRectangle.getWidth(), frameRectangle.getHeight(), sprite, 0, col, transform);
Draw_Sprite_Partial_Ext(x, y, frameRectangle.getX(), frameRectangle.getY(), frameRectangle.getWidth(), frameRectangle.getHeight(), sprite, col, transform, scalex, scaley);
}
public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, double frame_index, Color col, Transform transform){
public void Draw_Sprite_Partial_Ext(double x, double y, double xOffset, double yOffset, double w, double h, Sprite sprite, Color col, Transform transform, int scalex, int scaley){
boolean horizontal = transform==Transform.HORIZONTAL||transform==Transform.HORIZ_VERTIC;
boolean vertical = transform==Transform.VERTICAL||transform==Transform.HORIZ_VERTIC;
for(int X=(int)xOffset;X<(int)(w+xOffset);X++){
@ -587,20 +586,32 @@ public class Panel extends JPanel implements Runnable,KeyListener {
int index =
((vertical?
sprite.getHeight()-(Y-(int)yOffset):
(Y-(int)yOffset))
(Y-(int)yOffset))*scaley
+(int)y)*ACTUAL_WINDOW_WIDTH+
(horizontal?
sprite.getWidth()-(X-(int)xOffset):
(X-(int)xOffset))
(X-(int)xOffset))*scalex
+(int)x;
if (((sprite.getImg().getRGB(X,Y)>>>24)&0xFF)==0||index<0||index>=pixel.length) {
continue;
} else {
if (col==Color.WHITE) {
Draw(index,sprite.getImg().getRGB(X,Y));
for (int XX=0;XX<scalex;XX++) {
int newindex=index;
newindex+=XX+X*scalex;
for (int YY=0;YY<scaley;YY++) {
newindex+=(YY+Y*scaley)*ACTUAL_WINDOW_WIDTH;
Draw(newindex,sprite.getImg().getRGB(X,Y));
}
}
} else {
Color img = new Color(sprite.getImg().getRGB(X,Y));
Draw(index,new Color(
for (int XX=0;XX<scalex;XX++) {
int newindex=index;
newindex+=XX+X*scalex;
for (int YY=0;YY<scaley;YY++) {
newindex+=(YY+Y*scaley)*ACTUAL_WINDOW_WIDTH;
Draw(newindex,new Color(
(int)Math.min(255.0f,Math.max(0,(float)img.r * col.r / 255.0f)),
(int)Math.min(255.0f,Math.max(0,(float)img.g * col.g / 255.0f)),
(int)Math.min(255.0f,Math.max(0,(float)img.b * col.b / 255.0f)),
@ -612,6 +623,8 @@ public class Panel extends JPanel implements Runnable,KeyListener {
}
}
}
}
}
public void Draw_Rect(double x,double y, double w, double h, Color col) {
Draw_Line((int)x, (int)y, (int)x+(int)w, (int)y, col);

Loading…
Cancel
Save