From 8137a3000da652026d16ac1ca50ddb8f66a4a365 Mon Sep 17 00:00:00 2001 From: andreas Date: Tue, 4 Nov 2014 11:31:21 +0100 Subject: [PATCH] =?UTF-8?q?Anpassungen=20f=C3=BCr=20das=20Skalieren?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/de/heatup/objects/StaticObject.java | 41 ++++++++++++++----- HeatUp/src/de/heatup/testing/GameLoop.java | 3 +- HeatUp/src/de/heatup/ui/GameInterface.java | 12 +++--- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/HeatUp/src/de/heatup/objects/StaticObject.java b/HeatUp/src/de/heatup/objects/StaticObject.java index ebf1066..0a31fac 100644 --- a/HeatUp/src/de/heatup/objects/StaticObject.java +++ b/HeatUp/src/de/heatup/objects/StaticObject.java @@ -30,12 +30,15 @@ public class StaticObject extends JComponent { private int staticObjectHeight; public StaticObject(char staticObjectType, Point location, int staticObjectWidth, int staticObjectHeight) { + System.out.println("Object Type: " + staticObjectType + "\t" +staticObjectHeight + " h:w " + staticObjectWidth); this.staticObjectType = staticObjectType; this.location = location; this.staticObjectWidth = staticObjectWidth; this.staticObjectHeight = staticObjectHeight; loadBufferedImage(); setAutoBounds(location.x, location.y); + autoRescale(); + //System.out.println(getDebugInfo()); } public StaticObject(char staticObjectType, Point location) { @@ -51,7 +54,9 @@ public class StaticObject extends JComponent { } //g2d.rotate(0.2, 10, 10); + // TODO: Check if we can store a rescaled image in bf1??? if ( doRescale ) { + //System.out.println("hit"); g2d.scale(rescaleFactorX, rescaleFactorY); } @@ -67,24 +72,40 @@ public class StaticObject extends JComponent { this.bf1 = image; } - public void setRescale(double rescaleFactorX, double rescaleFactorY) { - this.rescaleFactorX = rescaleFactorX; - this.rescaleFactorY = rescaleFactorY; - this.doRescale = true; + private void autoRescale() { + // TODO: get original width and hight of bf1 + // Calculate factor new/original + // Rescale image using factor + // Save new bf in bf1 ??? + this.rescaleFactorX = this.staticObjectWidth / this.bf1.getWidth(); + this.rescaleFactorY = this.staticObjectHeight / this.bf1.getHeight(); + + System.out.println("Object: " + this.staticObjectType + "\tBuffered Image: Height: " + this.bf1.getHeight() + "\t Width: " + this.bf1.getWidth() + "\tStatic Object: Height: " + this.staticObjectHeight + "\t Width: " + this.staticObjectWidth); + + if (this.rescaleFactorX != 1 && this.rescaleFactorY != 1 ) { + this.doRescale = true; + } + } - public void unsetRescale() { - this.rescaleFactorX = 0.0; - this.rescaleFactorY = 0.0; - this.doRescale = false; - } +// public void setRescale(double rescaleFactorX, double rescaleFactorY) { +// this.rescaleFactorX = rescaleFactorX; +// this.rescaleFactorY = rescaleFactorY; +// this.doRescale = true; +// } + +// public void unsetRescale() { +// this.rescaleFactorX = 0.0; +// this.rescaleFactorY = 0.0; +// this.doRescale = false; +// } public void setAutoBounds(int x, int y) { this.setBounds(x, y, this.bf1.getWidth(), this.bf1.getHeight()); } public String getDebugInfo() { - String info = "Debug: " + "Rescale enabled:" + this.doRescale + "Rescale X:" + this.rescaleFactorX + "Rescale Y:" + this.rescaleFactorY + " Heigth:" + this.staticObjectHeight + " Width:" + this.staticObjectWidth + " StaticObjectType:" + this.staticObjectType + " X Position:" + this.location.x + " Y Position:" + this.location.y; + String info = "Debug: " + "Rescale? " + this.doRescale + "\tScale X:" + this.rescaleFactorX + "\tScale Y: " + this.rescaleFactorY + "\tH: " + this.staticObjectHeight + "\tW: " + this.staticObjectWidth + "\tStaticObjectType: " + this.staticObjectType + "\tX : " + this.location.x + "\tY :" + this.location.y; return info; } } diff --git a/HeatUp/src/de/heatup/testing/GameLoop.java b/HeatUp/src/de/heatup/testing/GameLoop.java index be6d589..cfa93b5 100644 --- a/HeatUp/src/de/heatup/testing/GameLoop.java +++ b/HeatUp/src/de/heatup/testing/GameLoop.java @@ -2,6 +2,7 @@ package de.heatup.testing; import javax.swing.JLabel; +import de.heatup.cfg.Config; import de.heatup.mapengine.MapEngine; import de.heatup.objects.DynamicObject; import de.heatup.objects.StaticObject; @@ -25,7 +26,7 @@ public class GameLoop { //dynO3.setRescale(1.5,3.5); - + Config.setGamePanelWidth(850); MapEngine me = new MapEngine(1); for (StaticObject currentStaticObject : me.getAllMapObjects()) { GameInterface.getGamePanel().add(currentStaticObject); diff --git a/HeatUp/src/de/heatup/ui/GameInterface.java b/HeatUp/src/de/heatup/ui/GameInterface.java index 1f2d99b..b5edc06 100644 --- a/HeatUp/src/de/heatup/ui/GameInterface.java +++ b/HeatUp/src/de/heatup/ui/GameInterface.java @@ -51,11 +51,11 @@ public class GameInterface extends JFrame { final JFrame frame = new JFrame(); // Fullscreen testing: Remember not to use pack() when using fullscreen mode - frame.setUndecorated(true); - frame.setResizable(false); - frame.setExtendedState(Frame.MAXIMIZED_BOTH); - frame.validate(); - GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame); +// frame.setUndecorated(true); +// frame.setResizable(false); +// frame.setExtendedState(Frame.MAXIMIZED_BOTH); +// frame.validate(); +// GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(frame); frame.setTitle("HeatUP!"); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); @@ -94,7 +94,7 @@ public class GameInterface extends JFrame { frame.add(outerPanel); // Comment out for fullscreen - //frame.pack(); + frame.pack(); frame.setVisible(true); frame.repaint(); }