From 22b75413d0b52d281a63e180cb6c0e848b150a7c Mon Sep 17 00:00:00 2001 From: Marcus Gosselin Date: Thu, 5 Mar 2015 08:08:31 -0500 Subject: [PATCH 1/3] trying to make retina a thing --- src/MAndEngine/Engine.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/MAndEngine/Engine.java b/src/MAndEngine/Engine.java index a5e1f55..086fdfc 100644 --- a/src/MAndEngine/Engine.java +++ b/src/MAndEngine/Engine.java @@ -137,14 +137,22 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener, */ public static int debug = 0; + /** + * 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; @@ -236,8 +244,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(WIDTH*(retina?2:1), HEIGHT*(retina?2:1), BufferedImage.TRANSLUCENT)); g2 = (Graphics2D) buffer.getGraphics(); } @@ -255,7 +263,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener, } paint(g2); - g.drawImage(buffer, 0, 0, null); + g.drawImage(buffer, 0, 0, WIDTH, HEIGHT, null); } /** From 1d9dde6bcfacd5821911fdccae36c2add4249536 Mon Sep 17 00:00:00 2001 From: Marcus Gosselin Date: Thu, 5 Mar 2015 10:44:16 -0500 Subject: [PATCH 2/3] buffer width and buffer height totally accounted for in the engine now --- src/MAndEngine/Engine.java | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/MAndEngine/Engine.java b/src/MAndEngine/Engine.java index 086fdfc..fc334ac 100644 --- a/src/MAndEngine/Engine.java +++ b/src/MAndEngine/Engine.java @@ -82,6 +82,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener, * IN CFG. */ private static int WIDTH = 800, HEIGHT = 600, app = 0; + private static int BUFFER_WIDTH = 800, BUFFER_HEIGHT = 600; /** * this bit is important. its the array of apps that we reference later on. @@ -199,6 +200,8 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener, switchApps(0); + BUFFER_HEIGHT = HEIGHT*(retina?2:1); + BUFFER_WIDTH = WIDTH*(retina?2:1); createBuffer(); } @@ -245,7 +248,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener, * makes a buffer and stuff, called with new windows and things. MOVE ALONG */ private void createBuffer() { - buffer = (new BufferedImage(WIDTH*(retina?2:1), HEIGHT*(retina?2:1), BufferedImage.TRANSLUCENT)); + buffer = (new BufferedImage(BUFFER_WIDTH, BUFFER_HEIGHT, BufferedImage.TRANSLUCENT)); g2 = (Graphics2D) buffer.getGraphics(); } @@ -256,12 +259,13 @@ 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, WIDTH, HEIGHT, null); } @@ -435,36 +439,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; } From 20dcc50ebd26fbd73feb1ea5578bb3926bb9584d Mon Sep 17 00:00:00 2001 From: Marcus Gosselin Date: Wed, 1 Apr 2015 10:50:12 -0400 Subject: [PATCH 3/3] minor nothingness --- src/MAndEngine/BasicApp.java | 1 + src/MAndEngine/Engine.java | 41 +++++------------------------------- 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/src/MAndEngine/BasicApp.java b/src/MAndEngine/BasicApp.java index 9f2b09e..a22ce52 100644 --- a/src/MAndEngine/BasicApp.java +++ b/src/MAndEngine/BasicApp.java @@ -97,5 +97,6 @@ public abstract interface BasicApp { public abstract void click(); + public abstract void updateDimensions(int width, int height); } \ No newline at end of file diff --git a/src/MAndEngine/Engine.java b/src/MAndEngine/Engine.java index fc334ac..5671aaa 100644 --- a/src/MAndEngine/Engine.java +++ b/src/MAndEngine/Engine.java @@ -82,7 +82,7 @@ public class Engine extends Canvas implements KeyListener, MouseMotionListener, * IN CFG. */ private static int WIDTH = 800, HEIGHT = 600, app = 0; - private static int BUFFER_WIDTH = 800, BUFFER_HEIGHT = 600; + public static int BUFFER_WIDTH = 800, BUFFER_HEIGHT = 600; /** * this bit is important. its the array of apps that we reference later on. @@ -129,9 +129,10 @@ 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.
+ * public until i figure out how to work with the changing resolution. */ - private static Engine staticMain; + public static Engine staticMain; /** * debug level. @@ -278,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(); @@ -366,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); @@ -388,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 @@ -505,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();