|
|
|
@ -11,6 +11,8 @@ import java.awt.event.MouseEvent; |
|
|
|
|
import java.awt.event.MouseMotionListener; |
|
|
|
|
import java.awt.event.MouseWheelEvent; |
|
|
|
|
import java.awt.event.MouseWheelListener; |
|
|
|
|
import java.awt.event.ComponentEvent; |
|
|
|
|
import java.awt.event.ComponentAdapter; |
|
|
|
|
|
|
|
|
|
import java.awt.GraphicsEnvironment; |
|
|
|
|
import java.awt.GraphicsConfiguration; |
|
|
|
@ -25,6 +27,7 @@ import java.awt.Graphics2D; |
|
|
|
|
import java.awt.RenderingHints; |
|
|
|
|
|
|
|
|
|
import java.awt.Cursor; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
|
|
|
|
|
import sig.JavaProjectTemplate; |
|
|
|
|
|
|
|
|
@ -62,6 +65,8 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
public static Panel p; |
|
|
|
|
public static JFrame f; |
|
|
|
|
|
|
|
|
|
int ACTUAL_WINDOW_WIDTH,ACTUAL_WINDOW_HEIGHT; |
|
|
|
|
|
|
|
|
|
static Cursor currentCursor = new Cursor(Cursor.DEFAULT_CURSOR); |
|
|
|
|
|
|
|
|
|
public static void InitializeEngine(JavaProjectTemplate instance){ |
|
|
|
@ -78,12 +83,21 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
RENDERHINTS.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_SPEED); |
|
|
|
|
|
|
|
|
|
f = new JFrame(JavaProjectTemplate.PROGRAM_NAME); |
|
|
|
|
f.setResizable(false); |
|
|
|
|
f.setResizable(true); |
|
|
|
|
f.setSize(JavaProjectTemplate.WINDOW_WIDTH,JavaProjectTemplate.WINDOW_HEIGHT); |
|
|
|
|
f.addComponentListener(new ComponentAdapter() { |
|
|
|
|
public void componentResized(ComponentEvent e) { |
|
|
|
|
Dimension d = p.getSize(); |
|
|
|
|
p.pixel=new int[(int)d.getWidth()*(int)d.getHeight()]; |
|
|
|
|
p.ACTUAL_WINDOW_WIDTH=(int)d.getWidth(); |
|
|
|
|
p.ACTUAL_WINDOW_HEIGHT=(int)d.getHeight(); |
|
|
|
|
p.init(false); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
p = new Panel(f); |
|
|
|
|
JavaProjectTemplate.game=p; |
|
|
|
|
|
|
|
|
|
p.init(); |
|
|
|
|
p.init(true); |
|
|
|
|
|
|
|
|
|
f.add(p); |
|
|
|
|
f.addKeyListener(p); |
|
|
|
@ -206,27 +220,26 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
/** |
|
|
|
|
* Call it after been visible and after resizes. |
|
|
|
|
*/ |
|
|
|
|
public void init(){ |
|
|
|
|
public void init(boolean runThread){ |
|
|
|
|
cm = getCompatibleColorModel(); |
|
|
|
|
int screenSize = JavaProjectTemplate.WINDOW_WIDTH * JavaProjectTemplate.WINDOW_HEIGHT; |
|
|
|
|
int screenSize = ACTUAL_WINDOW_WIDTH * ACTUAL_WINDOW_HEIGHT; |
|
|
|
|
if(pixel == null || pixel.length < screenSize){ |
|
|
|
|
pixel = new int[screenSize]; |
|
|
|
|
} |
|
|
|
|
mImageProducer = new MemoryImageSource(JavaProjectTemplate.WINDOW_WIDTH, JavaProjectTemplate.WINDOW_HEIGHT, cm, pixel,0, JavaProjectTemplate.WINDOW_WIDTH); |
|
|
|
|
mImageProducer = new MemoryImageSource(ACTUAL_WINDOW_WIDTH, ACTUAL_WINDOW_HEIGHT, cm, pixel,0, ACTUAL_WINDOW_WIDTH); |
|
|
|
|
mImageProducer.setAnimated(true); |
|
|
|
|
mImageProducer.setFullBufferUpdates(true); |
|
|
|
|
imageBuffer = Toolkit.getDefaultToolkit().createImage(mImageProducer); |
|
|
|
|
if(thread.isInterrupted() || !thread.isAlive()){ |
|
|
|
|
if(runThread && thread.isInterrupted() || !thread.isAlive()){ |
|
|
|
|
thread.start(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
@Override |
|
|
|
|
public void paintComponent(Graphics g) { |
|
|
|
|
//super.paintComponent(g);
|
|
|
|
|
// perform draws on pixels
|
|
|
|
|
long startTime = System.currentTimeMillis(); |
|
|
|
|
g.drawImage(this.imageBuffer,0,0,JavaProjectTemplate.WINDOW_WIDTH,JavaProjectTemplate.WINDOW_HEIGHT,0,0,JavaProjectTemplate.WINDOW_WIDTH,JavaProjectTemplate.WINDOW_HEIGHT,this); |
|
|
|
|
g.drawImage(this.imageBuffer,0,0,ACTUAL_WINDOW_WIDTH,ACTUAL_WINDOW_HEIGHT,0,0,ACTUAL_WINDOW_WIDTH,ACTUAL_WINDOW_HEIGHT,this); |
|
|
|
|
scaleTime=System.currentTimeMillis()-startTime; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -308,12 +321,12 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Draw(int x, int y, Color col) { |
|
|
|
|
if (x<0||y<0||x>=JavaProjectTemplate.WINDOW_WIDTH||y>=JavaProjectTemplate.WINDOW_HEIGHT) return; |
|
|
|
|
Draw(y*JavaProjectTemplate.WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
if (x<0||y<0||x>=ACTUAL_WINDOW_WIDTH||y>=ACTUAL_WINDOW_HEIGHT) return; |
|
|
|
|
Draw(y*ACTUAL_WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Draw(int index, int col) { |
|
|
|
|
if (((col>>>24)&0xff)==0) return; |
|
|
|
|
if (((col>>>24)&0xff)==0||index>=pixel.length) return; |
|
|
|
|
if (((col>>>24)&0xff)!=255) { |
|
|
|
|
pixel[index]=ColorLerpNoAlpha(new Color(pixel[index]),new Color(col),((col>>>24)&0xff)/255f).getColor(); |
|
|
|
|
} else { |
|
|
|
@ -443,7 +456,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
} |
|
|
|
|
px=px+2*(dy1-dx1); |
|
|
|
|
} |
|
|
|
|
Draw(y*JavaProjectTemplate.WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
Draw(y*ACTUAL_WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (dy>=0) { |
|
|
|
@ -451,7 +464,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
} else { |
|
|
|
|
x=x2-1;y=y2-1;ye=y1; |
|
|
|
|
} |
|
|
|
|
Draw(y*JavaProjectTemplate.WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
Draw(y*ACTUAL_WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
while (y<ye) { |
|
|
|
|
y=y+1; |
|
|
|
|
if (py<=0) { |
|
|
|
@ -464,7 +477,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
} |
|
|
|
|
py=py+2*(dx1-dy1); |
|
|
|
|
} |
|
|
|
|
Draw(y*JavaProjectTemplate.WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
Draw(y*ACTUAL_WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -472,8 +485,8 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
public void Fill_Rect(double x,double y,double w,double h,Color col) { |
|
|
|
|
for (int xx=0;xx<w;xx++) { |
|
|
|
|
for (int yy=0;yy<h;yy++) { |
|
|
|
|
if (x+xx>=0&&y+yy>=0&&x+xx<JavaProjectTemplate.WINDOW_WIDTH&&y+yy<JavaProjectTemplate.WINDOW_HEIGHT) { |
|
|
|
|
int index = ((int)y+yy)*JavaProjectTemplate.WINDOW_WIDTH+(int)x+xx; |
|
|
|
|
if (x+xx>=0&&y+yy>=0&&x+xx<ACTUAL_WINDOW_WIDTH&&y+yy<ACTUAL_WINDOW_HEIGHT) { |
|
|
|
|
int index = ((int)y+yy)*ACTUAL_WINDOW_WIDTH+(int)x+xx; |
|
|
|
|
Draw(index,col.getColor()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -518,14 +531,14 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
boolean vertical = transform==Transform.VERTICAL||transform==Transform.HORIZ_VERTIC; |
|
|
|
|
for(int X=(int)xOffset;X<(int)(w+xOffset);X++){ |
|
|
|
|
for(int Y=(int)yOffset;Y<(int)(h+yOffset);Y++){ |
|
|
|
|
if (X+x-xOffset<0||Y+y-yOffset<0||X-xOffset+x>=JavaProjectTemplate.WINDOW_WIDTH||Y-yOffset+y>=JavaProjectTemplate.WINDOW_HEIGHT) { |
|
|
|
|
if (X+x-xOffset<0||Y+y-yOffset<0||X-xOffset+x>=ACTUAL_WINDOW_WIDTH||Y-yOffset+y>=ACTUAL_WINDOW_HEIGHT) { |
|
|
|
|
continue; |
|
|
|
|
} else { |
|
|
|
|
int index = |
|
|
|
|
((vertical? |
|
|
|
|
sprite.getHeight()-(Y-(int)yOffset): |
|
|
|
|
(Y-(int)yOffset)) |
|
|
|
|
+(int)y)*JavaProjectTemplate.WINDOW_WIDTH+ |
|
|
|
|
+(int)y)*ACTUAL_WINDOW_WIDTH+ |
|
|
|
|
(horizontal? |
|
|
|
|
sprite.getWidth()-(X-(int)xOffset): |
|
|
|
|
(X-(int)xOffset)) |
|
|
|
@ -838,7 +851,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
|
|
|
|
|
//The mask indicates which pie slices to draw, each bit of the mask represents 1/8th of a pie slice. By default all pie slices are drawn.
|
|
|
|
|
public void Draw_Circle(int x, int y, int radius, Color col, byte mask) { |
|
|
|
|
if (radius < 0 || x < -radius || y < -radius || x - JavaProjectTemplate.WINDOW_WIDTH > radius || y - JavaProjectTemplate.WINDOW_HEIGHT > radius) |
|
|
|
|
if (radius < 0 || x < -radius || y < -radius || x - ACTUAL_WINDOW_WIDTH > radius || y - ACTUAL_WINDOW_HEIGHT > radius) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (radius > 0) |
|
|
|
@ -873,7 +886,7 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Fill_Circle(int x, int y, int radius, Color col) { |
|
|
|
|
if (radius < 0 || x < -radius || y < -radius || x - JavaProjectTemplate.WINDOW_WIDTH > radius || y - JavaProjectTemplate.WINDOW_HEIGHT > radius) |
|
|
|
|
if (radius < 0 || x < -radius || y < -radius || x - ACTUAL_WINDOW_WIDTH > radius || y - ACTUAL_WINDOW_HEIGHT > radius) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
if (radius > 0) |
|
|
|
@ -957,9 +970,9 @@ public class Panel extends JPanel implements Runnable,KeyListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Clear(Color col){ |
|
|
|
|
for (int y=0;y<JavaProjectTemplate.WINDOW_HEIGHT;y++) { |
|
|
|
|
for (int x=0;x<JavaProjectTemplate.WINDOW_WIDTH;x++) { |
|
|
|
|
Draw(y*JavaProjectTemplate.WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
for (int y=0;y<ACTUAL_WINDOW_HEIGHT;y++) { |
|
|
|
|
for (int x=0;x<ACTUAL_WINDOW_WIDTH;x++) { |
|
|
|
|
Draw(y*ACTUAL_WINDOW_WIDTH+x,col.getColor()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|