Merge remote-tracking branch 'origin/retina-display'
commit
64cb9edf57
|
|
@ -97,5 +97,6 @@ public abstract interface BasicApp {
|
||||||
|
|
||||||
public abstract void click();
|
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.
|
* IN CFG.
|
||||||
*/
|
*/
|
||||||
private static int WIDTH = 800, HEIGHT = 600, app = 0;
|
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.
|
* 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
|
* 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.
|
* debug level.
|
||||||
*/
|
*/
|
||||||
public static int debug = 2;
|
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
|
* SRSLY CALL DYS ONCE. DAS IT. ALL YOU GET. ONE SHOT. because this is a
|
||||||
* static engine, yeah
|
* static engine, yeah
|
||||||
|
* @param retina
|
||||||
*/
|
*/
|
||||||
public Engine(String[] classes, boolean showLoading) {
|
public Engine(String[] classes, boolean showLoading, boolean retina) {
|
||||||
|
|
||||||
// frame.setVisible(true);
|
// frame.setVisible(true);
|
||||||
|
|
||||||
|
this.retina = retina;
|
||||||
|
|
||||||
// set static object
|
// set static object
|
||||||
staticMain = this;
|
staticMain = this;
|
||||||
|
|
||||||
|
|
@ -191,6 +201,8 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
||||||
|
|
||||||
switchApps(0);
|
switchApps(0);
|
||||||
|
|
||||||
|
BUFFER_HEIGHT = HEIGHT*(retina?2:1);
|
||||||
|
BUFFER_WIDTH = WIDTH*(retina?2:1);
|
||||||
createBuffer();
|
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
|
* makes a buffer and stuff, called with new windows and things. MOVE ALONG
|
||||||
*/
|
*/
|
||||||
private static void createBuffer() {
|
private void createBuffer() {
|
||||||
buffer = (new BufferedImage(WIDTH, HEIGHT, BufferedImage.TRANSLUCENT));
|
buffer = (new BufferedImage(BUFFER_WIDTH, BUFFER_HEIGHT, BufferedImage.TRANSLUCENT));
|
||||||
g2 = (Graphics2D) buffer.getGraphics();
|
g2 = (Graphics2D) buffer.getGraphics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -248,14 +260,15 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
||||||
public void update(Graphics g) {
|
public void update(Graphics g) {
|
||||||
// Graphics g2 = buffer.getGraphics();
|
// Graphics g2 = buffer.getGraphics();
|
||||||
|
|
||||||
|
/*
|
||||||
if (buffer.getWidth() != WIDTH || buffer.getHeight() != HEIGHT) {
|
if (buffer.getWidth() != WIDTH || buffer.getHeight() != HEIGHT) {
|
||||||
System.out.println("bork " + buffer.getWidth());
|
System.out.println("bork " + buffer.getWidth());
|
||||||
System.out.println("bork " + WIDTH);
|
System.out.println("bork " + WIDTH);
|
||||||
createBuffer();
|
createBuffer();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
paint(g2);
|
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) {
|
public static boolean switchApps(int i) {
|
||||||
try {
|
try {
|
||||||
log("pausing " + apps[app].getTitle());
|
|
||||||
apps[app].pauseApp();
|
|
||||||
app = i;
|
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]);
|
setWindowProperties(apps[app]);
|
||||||
log("Started up " + apps[app].getTitle());
|
apps[app].updateDimensions(BUFFER_WIDTH, BUFFER_HEIGHT);
|
||||||
|
|
||||||
frame.pack();
|
frame.pack();
|
||||||
|
|
||||||
|
|
@ -354,11 +360,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
||||||
if (lag)
|
if (lag)
|
||||||
g.fillOval(10, 10, 10, 10);
|
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) {
|
} catch (Exception e) {
|
||||||
g.setFont(largerFont);
|
g.setFont(largerFont);
|
||||||
g.setColor(Color.BLACK);
|
g.setColor(Color.BLACK);
|
||||||
|
|
@ -376,24 +377,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
||||||
|
|
||||||
private void tick() {
|
private void tick() {
|
||||||
apps[app].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
|
@Override
|
||||||
|
|
@ -427,36 +410,42 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseDragged(MouseEvent e) {
|
public void mouseDragged(MouseEvent e) {
|
||||||
mouseX = e.getX();
|
updateMouse(e);
|
||||||
mouseY = e.getY();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
mouseX = e.getX();
|
updateMouse(e);
|
||||||
mouseY = e.getY();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent arg0) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseEntered(MouseEvent arg0) {
|
public void mouseEntered(MouseEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseExited(MouseEvent arg0) {
|
public void mouseExited(MouseEvent e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent arg0) {
|
public void mousePressed(MouseEvent e) {
|
||||||
mouse = true;
|
updateMouse(e);
|
||||||
apps[app].click();
|
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
|
@Override
|
||||||
public void mouseReleased(MouseEvent arg0) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
updateMouse(e);
|
||||||
mouse = false;
|
mouse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -487,8 +476,6 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
||||||
@Override
|
@Override
|
||||||
public void componentResized(ComponentEvent e) {
|
public void componentResized(ComponentEvent e) {
|
||||||
setSize(getPreferredSize());
|
setSize(getPreferredSize());
|
||||||
System.out.println("HEIGHT: " + HEIGHT);
|
|
||||||
System.out.println("WIDTH: " + WIDTH);
|
|
||||||
WIDTH = getSize().width;
|
WIDTH = getSize().width;
|
||||||
HEIGHT = getSize().height;
|
HEIGHT = getSize().height;
|
||||||
createBuffer();
|
createBuffer();
|
||||||
|
|
@ -500,4 +487,4 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener,
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue