Screen panel follows resize
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com>
This commit is contained in:
parent
7e6aaac3b2
commit
b0a5f882d6
@ -10,7 +10,7 @@ ORIGINAL_LOC=$(pwd)
|
|||||||
cd ${OUT_DIR}
|
cd ${OUT_DIR}
|
||||||
jar cfm ${PROJECT_NAME}.jar ${ORIGINAL_LOC}/manifest sig
|
jar cfm ${PROJECT_NAME}.jar ${ORIGINAL_LOC}/manifest sig
|
||||||
printf "\n\n\nRunning Program...\n\n"
|
printf "\n\n\nRunning Program...\n\n"
|
||||||
java -jar ${PROJECT_NAME}.jar
|
java -jar ${PROJECT_NAME}.jar "$@"
|
||||||
mv ${PROJECT_NAME}.jar ${ORIGINAL_LOC}
|
mv ${PROJECT_NAME}.jar ${ORIGINAL_LOC}
|
||||||
cd ..
|
cd ..
|
||||||
./scripts/clean.sh
|
./scripts/clean.sh
|
10
scripts/md5
10
scripts/md5
@ -1,5 +1,5 @@
|
|||||||
build.sh:de32fdf9f3ce9eb5d4ea9902ee48dbe0 *-
|
build.sh:a833e7598ad65672a9c01306d244b49f -
|
||||||
clean.sh:8aec15e447257f1c3a4e978f1b56a78e *-
|
clean.sh:96ce35f2d2dcb555421e00a6afda23ca -
|
||||||
commit.sh:21af1fa6f09d01679c9e11408967264a *-
|
commit.sh:21af1fa6f09d01679c9e11408967264a -
|
||||||
jar.sh:2ac636f584c43a1124affb9ea6bdc7bf *-
|
jar.sh:62ce62bbb97d3f3856bcc9b0ad34083c -
|
||||||
lean.sh:3be7b8b182ccd96e48989b4e57311193 *-
|
lean.sh:3be7b8b182ccd96e48989b4e57311193 -
|
||||||
|
@ -12,20 +12,15 @@ public class RabiClone {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JFrame f = new JFrame(PROGRAM_NAME);
|
JFrame f = new JFrame(PROGRAM_NAME);
|
||||||
Panel p = new Panel(f);
|
Panel p = new Panel(f);
|
||||||
|
|
||||||
p.init();
|
p.init();
|
||||||
|
|
||||||
f.add(p);
|
f.add(p);
|
||||||
|
f.addComponentListener(p);
|
||||||
f.setSize(1280,720);
|
f.setSize(1280,720);
|
||||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
f.setVisible(true);
|
f.setVisible(true);
|
||||||
|
|
||||||
p.render();
|
p.render();
|
||||||
BufferedImage nana;
|
|
||||||
try {
|
|
||||||
nana = ImageIO.read(new File("..","3x.png"));
|
|
||||||
p.Draw_Nana(p.Get_Nana(nana));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.event.ComponentEvent;
|
||||||
|
import java.awt.event.ComponentListener;
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
@ -18,11 +20,9 @@ import javax.swing.JPanel;
|
|||||||
|
|
||||||
import sig.RabiClone;
|
import sig.RabiClone;
|
||||||
|
|
||||||
public class Panel extends JPanel implements Runnable {
|
public class Panel extends JPanel implements Runnable,ComponentListener {
|
||||||
JFrame window;
|
JFrame window;
|
||||||
public int pixel[];
|
public int pixel[];
|
||||||
public int width=1280;
|
|
||||||
public int height=720;
|
|
||||||
final int CIRCLE_PRECISION=32;
|
final int CIRCLE_PRECISION=32;
|
||||||
final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor();
|
final int OUTLINE_COL=Color.BRIGHT_WHITE.getColor();
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
@ -37,11 +37,20 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
long lastSecond=0;
|
long lastSecond=0;
|
||||||
int lastFrameCount=0;
|
int lastFrameCount=0;
|
||||||
Sprite nana_sprite;
|
Sprite nana_sprite;
|
||||||
|
boolean resizing=false;
|
||||||
|
|
||||||
public Panel(JFrame f) {
|
public Panel(JFrame f) {
|
||||||
super(true);
|
super(true);
|
||||||
this.window=f;
|
this.window=f;
|
||||||
thread = new Thread(this, "MyPanel Thread");
|
thread = new Thread(this, "MyPanel Thread");
|
||||||
|
|
||||||
|
BufferedImage nana;
|
||||||
|
try {
|
||||||
|
nana = ImageIO.read(new File("..","3x.png"));
|
||||||
|
nana_sprite = Get_Nana(nana);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,22 +68,15 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
* Call it after been visible and after resizes.
|
* Call it after been visible and after resizes.
|
||||||
*/
|
*/
|
||||||
public void init(){
|
public void init(){
|
||||||
BufferedImage nana;
|
|
||||||
try {
|
|
||||||
nana = ImageIO.read(new File("..","3x.png"));
|
|
||||||
nana_sprite = Get_Nana(nana);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
cm = getCompatibleColorModel();
|
cm = getCompatibleColorModel();
|
||||||
int screenSize = width * height;
|
int screenSize = getWidth() * getHeight();
|
||||||
if(pixel == null || pixel.length < screenSize){
|
if(pixel == null || pixel.length < screenSize){
|
||||||
pixel = new int[screenSize];
|
pixel = new int[screenSize];
|
||||||
}
|
}
|
||||||
if(thread.isInterrupted() || !thread.isAlive()){
|
if(thread.isInterrupted() || !thread.isAlive()){
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
mImageProducer = new MemoryImageSource(width, height, cm, pixel,0, width);
|
mImageProducer = new MemoryImageSource(getWidth(), getHeight(), cm, pixel,0, getWidth());
|
||||||
mImageProducer.setAnimated(true);
|
mImageProducer.setAnimated(true);
|
||||||
mImageProducer.setFullBufferUpdates(true);
|
mImageProducer.setFullBufferUpdates(true);
|
||||||
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
|
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
|
||||||
@ -114,12 +116,19 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
|
|
||||||
|
|
||||||
public /* abstract */ void render(){
|
public /* abstract */ void render(){
|
||||||
|
if (resizing) {
|
||||||
|
pixel = new int[getWidth()*getHeight()];
|
||||||
|
resizing=false;
|
||||||
|
mImageProducer = new MemoryImageSource(getWidth(), getHeight(), cm, pixel,0, getWidth());
|
||||||
|
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer);
|
||||||
|
System.out.println("Window resized.");
|
||||||
|
}
|
||||||
int[] p = pixel; // this avoid crash when resizing
|
int[] p = pixel; // this avoid crash when resizing
|
||||||
//a=h/w
|
//a=h/w
|
||||||
|
|
||||||
for (int y=0;y<height;y++) {
|
for (int y=0;y<getHeight();y++) {
|
||||||
for (int x=0;x<width;x++) {
|
for (int x=0;x<getWidth();x++) {
|
||||||
p[y*width+x]=(0<<16)+(0<<8)+0;//RGB
|
p[y*getWidth()+x]=(0<<16)+(0<<8)+0;//RGB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Draw_Nana(nana_sprite);
|
Draw_Nana(nana_sprite);
|
||||||
@ -128,7 +137,7 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
public void FillRect(int[] p,Color col,double x,double y,double w,double h) {
|
public void FillRect(int[] p,Color col,double x,double y,double w,double h) {
|
||||||
for (int xx=0;xx<w;xx++) {
|
for (int xx=0;xx<w;xx++) {
|
||||||
for (int yy=0;yy<h;yy++) {
|
for (int yy=0;yy<h;yy++) {
|
||||||
int index = ((int)y+yy)*width+(int)x+xx;
|
int index = ((int)y+yy)*getWidth()+(int)x+xx;
|
||||||
Draw(p,index,col.getColor());
|
Draw(p,index,col.getColor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,7 +210,7 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
Edge e2 = active_edges.get(i+1);
|
Edge e2 = active_edges.get(i+1);
|
||||||
//System.out.println("Drawing from "+((int)Math.round(e1.x_of_min_y))+" to "+e2.x_of_min_y+" on line "+scanLine);
|
//System.out.println("Drawing from "+((int)Math.round(e1.x_of_min_y))+" to "+e2.x_of_min_y+" on line "+scanLine);
|
||||||
for (int x=(int)Math.round(e1.x_of_min_y);x<=e2.x_of_min_y;x++) {
|
for (int x=(int)Math.round(e1.x_of_min_y);x<=e2.x_of_min_y;x++) {
|
||||||
int index = (scanLine+(int)y_offset)*width+x+(int)x_offset;
|
int index = (scanLine+(int)y_offset)*getWidth()+x+(int)x_offset;
|
||||||
if (index<p.length&&index>=0) {
|
if (index<p.length&&index>=0) {
|
||||||
Draw(p,index,col.getColor());
|
Draw(p,index,col.getColor());
|
||||||
}
|
}
|
||||||
@ -306,7 +315,7 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
int[] p = pixel;
|
int[] p = pixel;
|
||||||
for(int x=0;x<sprite.height;x++){
|
for(int x=0;x<sprite.height;x++){
|
||||||
for(int y=0;y<sprite.width;y++){
|
for(int y=0;y<sprite.width;y++){
|
||||||
p[y*width+x] = sprite.bi_array[y*sprite.width+x];
|
p[y*getWidth()+x] = sprite.bi_array[y*sprite.width+x];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -320,4 +329,28 @@ public class Panel extends JPanel implements Runnable {
|
|||||||
//try {Thread.sleep(1);} catch (InterruptedException e) {}
|
//try {Thread.sleep(1);} catch (InterruptedException e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentHidden(ComponentEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentMoved(ComponentEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentResized(ComponentEvent e) {
|
||||||
|
//COMPONENT_RESIZED (8,564 948x508)
|
||||||
|
resizing=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void componentShown(ComponentEvent e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
10
utils/md5
10
utils/md5
@ -1,5 +1,5 @@
|
|||||||
.coauthors:6a70afcd3d554ff73e01a93ce090c992 *-
|
.coauthors:6a70afcd3d554ff73e01a93ce090c992 -
|
||||||
.updateDirectories:0ede00461e947494545e694040787b3f *-
|
define.sh:d6b20a25a04a60d94f466e48fa60ac69 -
|
||||||
define.sh:d6b20a25a04a60d94f466e48fa60ac69 *-
|
main.sh:32a1f953ffca8584d1eb57c0ecd8a582 -
|
||||||
main.sh:32a1f953ffca8584d1eb57c0ecd8a582 *-
|
search.sh:6eec52214a36f2114442c41ab9c04f72 -
|
||||||
search.sh:6eec52214a36f2114442c41ab9c04f72 *-
|
.updateDirectories:0ede00461e947494545e694040787b3f -
|
||||||
|
Loading…
x
Reference in New Issue
Block a user