Merge remote-tracking branch 'origin/retina-display'
commit
64cb9edf57
|
|
@ -97,5 +97,6 @@ public abstract interface BasicApp {
|
|||
|
||||
public abstract void click();
|
||||
|
||||
public abstract void updateDimensions(int width, int height);
|
||||
|
||||
}
|
||||
|
|
@ -82,6 +82,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
* IN CFG.
|
||||
*/
|
||||
private static int WIDTH = 800, HEIGHT = 600, app = 0;
|
||||
public static int BUFFER_WIDTH = 800, BUFFER_HEIGHT = 600;
|
||||
|
||||
/**
|
||||
* this bit is important. its the array of apps that we reference later on.
|
||||
|
|
@ -128,23 +129,32 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
|
||||
/**
|
||||
* the main Main object but staticed so we can like use it from that static
|
||||
* context. its not final because its static but don't change it.
|
||||
* context. its not final because its static but don't change it.<br/>
|
||||
* public until i figure out how to work with the changing resolution.
|
||||
*/
|
||||
private static Engine staticMain;
|
||||
public static Engine staticMain;
|
||||
|
||||
/**
|
||||
* debug level.
|
||||
*/
|
||||
public static int debug = 2;
|
||||
|
||||
/**
|
||||
* because retina support
|
||||
*/
|
||||
private final boolean retina;
|
||||
|
||||
/**
|
||||
* SRSLY CALL DYS ONCE. DAS IT. ALL YOU GET. ONE SHOT. because this is a
|
||||
* static engine, yeah
|
||||
* @param retina
|
||||
*/
|
||||
public Engine(String[] classes, boolean showLoading) {
|
||||
public Engine(String[] classes, boolean showLoading, boolean retina) {
|
||||
|
||||
// frame.setVisible(true);
|
||||
|
||||
this.retina = retina;
|
||||
|
||||
// set static object
|
||||
staticMain = this;
|
||||
|
||||
|
|
@ -191,6 +201,8 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
|
||||
switchApps(0);
|
||||
|
||||
BUFFER_HEIGHT = HEIGHT*(retina?2:1);
|
||||
BUFFER_WIDTH = WIDTH*(retina?2:1);
|
||||
createBuffer();
|
||||
|
||||
}
|
||||
|
|
@ -236,8 +248,8 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
/**
|
||||
* makes a buffer and stuff, called with new windows and things. MOVE ALONG
|
||||
*/
|
||||
private static void createBuffer() {
|
||||
buffer = (new BufferedImage(WIDTH, HEIGHT, BufferedImage.TRANSLUCENT));
|
||||
private void createBuffer() {
|
||||
buffer = (new BufferedImage(BUFFER_WIDTH, BUFFER_HEIGHT, BufferedImage.TRANSLUCENT));
|
||||
g2 = (Graphics2D) buffer.getGraphics();
|
||||
}
|
||||
|
||||
|
|
@ -248,14 +260,15 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
public void update(Graphics g) {
|
||||
// Graphics g2 = buffer.getGraphics();
|
||||
|
||||
/*
|
||||
if (buffer.getWidth() != WIDTH || buffer.getHeight() != HEIGHT) {
|
||||
System.out.println("bork " + buffer.getWidth());
|
||||
System.out.println("bork " + WIDTH);
|
||||
createBuffer();
|
||||
}
|
||||
|
||||
*/
|
||||
paint(g2);
|
||||
g.drawImage(buffer, 0, 0, null);
|
||||
g.drawImage(buffer, 0, 0, WIDTH, HEIGHT, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -266,16 +279,9 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
*/
|
||||
public static boolean switchApps(int i) {
|
||||
try {
|
||||
log("pausing " + apps[app].getTitle());
|
||||
apps[app].pauseApp();
|
||||
app = i;
|
||||
log("initializing " + apps[app].getTitle());
|
||||
apps[app].initialize();
|
||||
log("resuming " + apps[app].getTitle());
|
||||
apps[app].resumeApp();
|
||||
log("setting window properties");
|
||||
setWindowProperties(apps[app]);
|
||||
log("Started up " + apps[app].getTitle());
|
||||
apps[app].updateDimensions(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||
|
||||
frame.pack();
|
||||
|
||||
|
|
@ -354,11 +360,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
if (lag)
|
||||
g.fillOval(10, 10, 10, 10);
|
||||
|
||||
g.setColor(Color.WHITE);
|
||||
if (debug > 0)
|
||||
if (!(log.size() == 0))
|
||||
for (int i = log.size() - 1; i >= 0; i--)
|
||||
log.elementAt(i).render(g, WIDTH - 200, HEIGHT - 10 - (i * 12));
|
||||
} catch (Exception e) {
|
||||
g.setFont(largerFont);
|
||||
g.setColor(Color.BLACK);
|
||||
|
|
@ -376,24 +377,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
|
||||
private void tick() {
|
||||
apps[app].tick();
|
||||
for (int i = 0; i < log.size(); i++)
|
||||
log.elementAt(i).tick();
|
||||
|
||||
int i = 0;
|
||||
while (i < log.size()) {
|
||||
if (!log.elementAt(i).getAlive())
|
||||
log.remove(i);
|
||||
else
|
||||
i++;
|
||||
}
|
||||
|
||||
while (log.size() > 10) {
|
||||
log.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public static void log(String s) {
|
||||
log.insertElementAt(new LogItem(s, 100), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -427,36 +410,42 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
|
||||
@Override
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
mouseX = e.getX();
|
||||
mouseY = e.getY();
|
||||
updateMouse(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
mouseX = e.getX();
|
||||
mouseY = e.getY();
|
||||
updateMouse(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent arg0) {
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent arg0) {
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent arg0) {
|
||||
mouse = true;
|
||||
public void mousePressed(MouseEvent e) {
|
||||
updateMouse(e);
|
||||
apps[app].click();
|
||||
mouse = true;
|
||||
}
|
||||
|
||||
private void updateMouse(MouseEvent e) {
|
||||
mouseX = (int)(((double)e.getX() / WIDTH)*BUFFER_WIDTH);
|
||||
mouseY = (int)(((double)e.getY() / HEIGHT)*BUFFER_HEIGHT);
|
||||
mouse = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent arg0) {
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
updateMouse(e);
|
||||
mouse = false;
|
||||
}
|
||||
|
||||
|
|
@ -487,8 +476,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
@Override
|
||||
public void componentResized(ComponentEvent e) {
|
||||
setSize(getPreferredSize());
|
||||
System.out.println("HEIGHT: " + HEIGHT);
|
||||
System.out.println("WIDTH: " + WIDTH);
|
||||
WIDTH = getSize().width;
|
||||
HEIGHT = getSize().height;
|
||||
createBuffer();
|
||||
|
|
@ -500,4 +487,4 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
|||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue