first
parent
a8be3bddc0
commit
d8608d9348
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/MAndEngine"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/SpaceWars"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MAndApps</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
MAndApps.apps.MainMenu
|
||||
MAndApps.apps.Settings
|
||||
MAndApps.apps.SpaceWars
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package MAndApps.apps;
|
||||
|
||||
public class BackgroundSettings {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package MAndApps.apps;
|
||||
|
||||
public class GraphicalArrayList {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
package MAndApps.apps;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import MAndEngine.BasicApp;
|
||||
|
||||
class JonsLearningPlayground implements BasicApp {
|
||||
|
||||
@Override
|
||||
public Dimension getResolution() {
|
||||
return new Dimension(800, 600);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeApp() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseApp() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Graphics2D g) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "Jons Learning Playground";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return Color.WHITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramerate() {
|
||||
return 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResizable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visibleInMenu() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resized(int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,248 @@
|
|||
package MAndApps.apps;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import MAndEngine.AppHelper;
|
||||
import MAndEngine.BasicApp;
|
||||
import MAndEngine.Engine;
|
||||
import MAndEngine.Variable;
|
||||
import static MAndEngine.Engine.ANIMATION_CONSTANT;
|
||||
|
||||
public class MainMenu implements BasicApp {
|
||||
|
||||
public static Variable wallpaperPath;
|
||||
|
||||
private static Image BKG;
|
||||
private Color GREY, GREEN, WHITE, BLACK;
|
||||
private int xMargin = 300, yMargin = 303, yGap = 50, selection = 0;
|
||||
private double yOffset = 0;
|
||||
private Color[] appColors;
|
||||
private String[] appNames;
|
||||
private int visibleApps;
|
||||
private double backgroundScroll = 0;
|
||||
private int backgroundRange = 0;
|
||||
|
||||
@Override
|
||||
public Dimension getResolution() {
|
||||
// TODO Auto-generated method stub
|
||||
return new Dimension(800, 600);
|
||||
}
|
||||
|
||||
/**
|
||||
* THIS PART STARTS STUFF!
|
||||
* WOO!
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
|
||||
if(wallpaperPath == null) wallpaperPath = new Variable("MAndWorks\\MAndApps\\Settings", "wallpaper", "http://www.controltheweb.com/images/desktop-background-large/milkyWay.jpg", true);
|
||||
|
||||
//COLORS! Because ... wait actually why?
|
||||
//we don't use the colors.
|
||||
GREY = new Color(50, 50, 50);
|
||||
GREEN = new Color(137, 198, 35);
|
||||
WHITE = new Color(200, 200, 200);
|
||||
BLACK = new Color(10, 10, 10);
|
||||
|
||||
//WE HAVE APPS THAT ARE LIKE ... VISIBLE. LETS COUNT THEM
|
||||
visibleApps = 0;
|
||||
|
||||
for (int i = 0, app = 0; app < Engine.apps.length; i++, app++) {
|
||||
if (Engine.apps[app].visibleInMenu()) {
|
||||
//oneee......
|
||||
//wat no...
|
||||
//i.......
|
||||
visibleApps++;
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
//these are names, because we can't render null now can we timmy.
|
||||
//yeah he fucked up the basic course in Graphics2D...
|
||||
//timmy was me
|
||||
//2 days ago.
|
||||
appNames = new String[visibleApps];
|
||||
|
||||
appColors = new Color[visibleApps];
|
||||
|
||||
//loopshit. what are we looping?
|
||||
//FILL THE ARRAYS WITH ALLLLL LTHE DATA!
|
||||
for (int i = 0, app = 0; app < Engine.apps.length; i++, app++) {
|
||||
if (Engine.apps[app].visibleInMenu()) {
|
||||
appNames[i] = Engine.apps[app].getTitle();
|
||||
appColors[i] = Engine.apps[app].getColor();
|
||||
} else {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
backgroundScroll = 0;
|
||||
|
||||
try {
|
||||
BufferedImage image = ImageIO.read(new URL(wallpaperPath.getValue()));
|
||||
image = getScaledImage(image, 800);
|
||||
BKG = image;
|
||||
backgroundRange = image.getHeight() - 600;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseApp() {
|
||||
//why the actual fuck would we pause the main. fucking. menu.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeApp() {
|
||||
//see pause.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
int desiredYOffset = selection * yGap;
|
||||
yOffset -= (yOffset - desiredYOffset) / ANIMATION_CONSTANT;
|
||||
|
||||
int desiredBackgroundScroll = (int) (backgroundRange * ((double)selection/(visibleApps - 1)));
|
||||
backgroundScroll -= ((double)backgroundScroll - desiredBackgroundScroll)/ANIMATION_CONSTANT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Graphics2D g) {
|
||||
g.drawImage(BKG, 0, (int) (0 - backgroundScroll), null);
|
||||
|
||||
g.setColor(appColors[selection]);
|
||||
g.fillRect(0, 290, 800, 20);
|
||||
g.setColor(BLACK);
|
||||
g.fillRect(0, 291, 800, 18);
|
||||
g.setColor(WHITE);
|
||||
|
||||
final int clearMargin = 190;
|
||||
final int range = 100;
|
||||
|
||||
for (int i = 0; i < visibleApps; i++) {
|
||||
|
||||
int y = yMargin + (i * yGap) - (int) yOffset;
|
||||
float opacity = y;
|
||||
opacity -= clearMargin;
|
||||
opacity = opacity < 0 ? 0 : opacity;
|
||||
|
||||
opacity /= range;
|
||||
|
||||
opacity = opacity > 1 ? 1 : opacity;
|
||||
|
||||
g.setColor(createColor(WHITE, opacity));
|
||||
|
||||
g.drawString(appNames[i], xMargin, y);
|
||||
}
|
||||
|
||||
g.setFont(new java.awt.Font("Tahoma", java.awt.Font.PLAIN, 30));
|
||||
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawString("MAndApps", 300, 100);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyChar() == 'w')
|
||||
if (selection > 0)
|
||||
selection--;
|
||||
else
|
||||
selection = visibleApps - 1;
|
||||
if (e.getKeyChar() == 's')
|
||||
if (selection < visibleApps - 1)
|
||||
selection++;
|
||||
else
|
||||
selection = 0;
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
int openApp = AppHelper.getIDbyName(appNames[selection]);
|
||||
Engine.switchApps(openApp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
//WE DUNN DO SHIT.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "Main Menu";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return new Color(255, 255, 255);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramerate() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResizable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visibleInMenu() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* im sorry about creating a new color object every tick. <br/>
|
||||
* jk, #soznosoz
|
||||
*
|
||||
* @param base
|
||||
* @param opacity
|
||||
* @return
|
||||
*/
|
||||
public static Color createColor(Color base, float opacity) {
|
||||
int r = base.getRed();
|
||||
int g = base.getGreen();
|
||||
int b = base.getBlue();
|
||||
int a = (int) (opacity * 255);
|
||||
return new Color(r, g, b, a);
|
||||
}
|
||||
|
||||
public static BufferedImage getScaledImage(BufferedImage image, int width) throws IOException {
|
||||
int imageWidth = image.getWidth();
|
||||
int imageHeight = image.getHeight();
|
||||
|
||||
double scaleX = (double)width/imageWidth;
|
||||
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleX);
|
||||
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
|
||||
|
||||
return bilinearScaleOp.filter(
|
||||
image,
|
||||
new BufferedImage(width, (int)(imageHeight * scaleX), image.getType()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resized(int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,307 @@
|
|||
package MAndApps.apps;
|
||||
|
||||
import static MAndEngine.Engine.ANIMATION_CONSTANT;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import MAndApps.apps.settings.Item;
|
||||
import MAndEngine.AppHelper;
|
||||
import MAndEngine.BasicApp;
|
||||
import MAndEngine.Engine;
|
||||
import MAndEngine.Variable;
|
||||
|
||||
public class Settings implements BasicApp {
|
||||
|
||||
private static final int WIDTH = 800, HEIGHT = 600;
|
||||
|
||||
// we need to have a home in case all else fails.
|
||||
private static final String defaultSearchDirectory = System.getenv("APPDATA") + "\\MAndWorks\\MAndApps\\Backgrounds\\";
|
||||
|
||||
// current selection
|
||||
private int selection = 0;
|
||||
|
||||
// rendering animation number thing that
|
||||
// looks like selection but is rendered
|
||||
// horizontally and stuff. in pixels. BC ANIMATION
|
||||
private double scroll;
|
||||
|
||||
// TIME. pretty self explanatory.
|
||||
private static double time = 0;
|
||||
|
||||
// items list
|
||||
private ArrayList<Item> items;
|
||||
|
||||
private File currentDirectoryFile;
|
||||
private Variable currentDirectoryVariable;
|
||||
|
||||
final int THUMB_WIDTH = 80;
|
||||
final int THUMB_MARGIN = 30;
|
||||
final int FULL_WIDTH = THUMB_WIDTH + THUMB_MARGIN;
|
||||
final int Y_OFFSET = 470;
|
||||
|
||||
final int X_OFFSET_SELECTION = (int)(THUMB_MARGIN + (selection * FULL_WIDTH) - (scroll * FULL_WIDTH));
|
||||
|
||||
final int LEFT_BAR_WIDTH = FULL_WIDTH + THUMB_MARGIN;
|
||||
final int INNER_FRAME_HEIGHT = (int)(((WIDTH - LEFT_BAR_WIDTH) / 4d) * 3d);
|
||||
final int TOP_BAR_HEIGHT = HEIGHT - INNER_FRAME_HEIGHT;
|
||||
final int INNER_FRAME_WIDTH = WIDTH - LEFT_BAR_WIDTH;
|
||||
|
||||
//YES IT WORKED
|
||||
|
||||
@Override
|
||||
public Dimension getResolution() {
|
||||
return new Dimension(WIDTH, HEIGHT);
|
||||
}
|
||||
|
||||
private void setCurrentDir(String path) {
|
||||
currentDirectoryVariable.setValue(path);
|
||||
currentDirectoryFile = new File(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
//uhhhh basically, i think we forgot to actually... MAKE the folder...
|
||||
if(!new File(defaultSearchDirectory).exists()) new File(defaultSearchDirectory).mkdir();
|
||||
|
||||
|
||||
// make sure we have our variable and file
|
||||
// we can explicitly set them as we are trying to pick up where we left
|
||||
// off
|
||||
currentDirectoryVariable = new Variable("MAndWorks\\MAndApps\\Settings", "WallpaperSearchDirectory", defaultSearchDirectory, false);
|
||||
currentDirectoryFile = new File(currentDirectoryVariable.getValue());
|
||||
|
||||
// which we use, be it variable or file, is completely arbitrary here.
|
||||
reload();
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
|
||||
// we need to reset ERRYTHANG well, important stuff.
|
||||
items = new ArrayList<Item>();
|
||||
selection = 0;
|
||||
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
repopulate();
|
||||
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void repopulate() {
|
||||
|
||||
if (currentDirectoryFile.isDirectory()) {
|
||||
|
||||
// parent?
|
||||
String parent = currentDirectoryFile.getParent();
|
||||
if (parent != null) {
|
||||
Item item = new Item(parent);
|
||||
if (item.getSeemsLegit())
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
// folderssss
|
||||
for (String path : currentDirectoryFile.list()) {
|
||||
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
||||
if (file.isDirectory()) {
|
||||
Item item = new Item(file.getAbsolutePath());
|
||||
if (item.getSeemsLegit())
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
// filezzzz
|
||||
for (String path : currentDirectoryFile.list()) {
|
||||
File file = new File(currentDirectoryFile.getAbsolutePath() + "\\" + path);
|
||||
if (!file.isDirectory()) {
|
||||
Item item = new Item(file.getAbsolutePath());
|
||||
if (item.getSeemsLegit())
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
// how did you manage that... this is specified by the system...
|
||||
// whatever, i'll reset the variable for you and we can retry...
|
||||
setCurrentDir(defaultSearchDirectory);
|
||||
repopulate();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeApp() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseApp() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
int desiredScroll = selection;
|
||||
|
||||
|
||||
scroll -= (scroll - desiredScroll) / (ANIMATION_CONSTANT);
|
||||
|
||||
|
||||
time += 1 / 60d;
|
||||
time = Math.PI + 1; // PI IS TOP, 0/2PI is bottom
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(Graphics2D g) {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
//this is the black box
|
||||
//NOW IN GREY
|
||||
g.setColor(new Color(200, 200, 200));
|
||||
g.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
|
||||
try{
|
||||
g.drawImage(items.get(selection).getImage(), WIDTH - items.get(selection).getImage().getWidth()/2 - INNER_FRAME_WIDTH/2, TOP_BAR_HEIGHT, null);
|
||||
}catch(Exception e) {
|
||||
//between ticks, nothing really big
|
||||
}
|
||||
|
||||
|
||||
g.setColor(new Color(225, 225, 225));
|
||||
g.fillRect(0, 0, WIDTH, TOP_BAR_HEIGHT);
|
||||
g.setColor(new Color(255, 127, 0));
|
||||
g.drawLine(0, TOP_BAR_HEIGHT - 1, WIDTH, TOP_BAR_HEIGHT - 1);
|
||||
|
||||
g.setColor(new Color(240, 240, 240));
|
||||
g.fillRect(0, 0, FULL_WIDTH + THUMB_MARGIN, HEIGHT);
|
||||
g.setColor(new Color(255, 127, 0));
|
||||
g.drawLine(LEFT_BAR_WIDTH - 1, 0, LEFT_BAR_WIDTH - 1, HEIGHT);
|
||||
|
||||
g.setColor(new Color(35, 35, 35));
|
||||
//g.setFont(Main.largerFont);
|
||||
int dirWidth = g.getFontMetrics().stringWidth(currentDirectoryVariable.getValue());
|
||||
|
||||
g.drawString(currentDirectoryVariable.getValue(), LEFT_BAR_WIDTH + THUMB_MARGIN, TOP_BAR_HEIGHT / 2 + 5);
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < items.size(); i++)
|
||||
g.drawImage(items.get(i).getThumbnail(), THUMB_MARGIN, -1 + (int)(THUMB_MARGIN + (i * FULL_WIDTH) - (scroll * FULL_WIDTH)), null);
|
||||
|
||||
/*
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawRect(THUMB_MARGIN - 2, Y_OFFSET - 2, THUMB_WIDTH + 3, THUMB_WIDTH + 3);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.drawRect(THUMB_MARGIN - 1, Y_OFFSET - 1, THUMB_WIDTH + 1, THUMB_WIDTH + 1);
|
||||
g.drawRect(THUMB_MARGIN - 3, Y_OFFSET - 3, THUMB_WIDTH + 5, THUMB_WIDTH + 5);
|
||||
*/
|
||||
g.setColor(new Color(0, 127, 255));
|
||||
g.fillRect(445, 285, 35, 100);
|
||||
|
||||
g.setColor(new Color(0, 127, 255));
|
||||
g.fillRect(350, 300, 150, 100);
|
||||
g.setColor(new Color(255, 255, 255));
|
||||
g.fillRect(351, 301, 148, 98);
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.fillRect(0, 0, 800, 600);
|
||||
g.setColor(Color.WHITE);
|
||||
g.drawString("Please wait...", 0, 600);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
|
||||
Engine.log("" + e.getKeyCode());
|
||||
|
||||
if (e.getKeyCode() == KeyEvent.VK_D ||
|
||||
e.getKeyCode() == KeyEvent.VK_S) {
|
||||
if (selection == items.size() - 1)
|
||||
selection = 0;
|
||||
else
|
||||
selection++;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_A ||
|
||||
e.getKeyCode() == KeyEvent.VK_W) {
|
||||
selection--;
|
||||
if (selection < 0)
|
||||
selection = items.size() - 1;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
if (new File(items.get(selection).getPath()).isDirectory()) {
|
||||
setCurrentDir(items.get(selection).getPath());
|
||||
reload();
|
||||
} else {
|
||||
MainMenu.wallpaperPath.setValue(items.get(selection).getPath());
|
||||
Engine.switchApps(AppHelper.getIDbyClass("Main Menu"));
|
||||
}
|
||||
}
|
||||
if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||
|
||||
if(selection == 0) {
|
||||
Engine.switchApps(AppHelper.getIDbyClass("Main Menu"));
|
||||
} else {
|
||||
selection = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "Settings";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return new Color(255, 127, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramerate() {
|
||||
return 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getResizable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visibleInMenu() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resized(int width, int height) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void click() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
package MAndApps.apps.settings;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Image;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.image.AffineTransformOp;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
public class Item {
|
||||
|
||||
private static int scaleToHeight;
|
||||
|
||||
//cropped to a thumb nail, of size 80*80
|
||||
private final BufferedImage thumbnail;
|
||||
|
||||
//the original image, not cropped or anything.
|
||||
private final BufferedImage image;
|
||||
|
||||
//Absolute path, i think.
|
||||
private final String path;
|
||||
private String name;
|
||||
|
||||
// we need this because im scared.
|
||||
// if literally anything in the creating of an item
|
||||
// goes MODERATELY wrong, you set this to FALSE.
|
||||
// then we don't try and render something that
|
||||
// makes no sense.
|
||||
// set this to false by the end of the constructor
|
||||
// and when it comes back to being added to the list,
|
||||
// it'll be thrown out.
|
||||
private boolean seemsLegit = true;
|
||||
|
||||
public Item(String path) {
|
||||
|
||||
BufferedImage thumbnail = null;
|
||||
BufferedImage image = null;
|
||||
|
||||
try {
|
||||
File file = new File(path);
|
||||
if (file.isDirectory()) {
|
||||
// then lets do the directory thing!
|
||||
|
||||
thumbnail = new BufferedImage(80, 80, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics thumbnailGraphics = thumbnail.getGraphics();
|
||||
thumbnailGraphics.setColor(new Color(0, 0, 255));
|
||||
thumbnailGraphics.fillRect(0, 0, 80, 80);
|
||||
|
||||
image = new BufferedImage((int)((scaleToHeight/3d)*4d), scaleToHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics imageGraphics = image.getGraphics();
|
||||
imageGraphics.fillRect(0, 0, (int)((scaleToHeight/3d)*4d), scaleToHeight);
|
||||
|
||||
imageGraphics.setColor(Color.black);
|
||||
imageGraphics.drawString("" + path, 100, 100);
|
||||
|
||||
name = file.getName();
|
||||
|
||||
} else {
|
||||
|
||||
// try and do the image thing!
|
||||
image = ImageIO.read(file);
|
||||
image = getScaledImage(image, scaleToHeight);
|
||||
thumbnail = (getScaledImageFill(image, 80, 80));
|
||||
path = file.getAbsolutePath();
|
||||
|
||||
// discard it as it won't fit the screen.
|
||||
if (!(((double) image.getWidth() / image.getHeight()) <= (4 / 3d))) {
|
||||
seemsLegit = false;
|
||||
}
|
||||
|
||||
name = "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
seemsLegit = false;
|
||||
}
|
||||
|
||||
this.image = image;
|
||||
this.path = path;
|
||||
this.thumbnail = thumbnail;
|
||||
}
|
||||
|
||||
public boolean getSeemsLegit() {
|
||||
return seemsLegit;
|
||||
}
|
||||
|
||||
private static BufferedImage getScaledImage(BufferedImage image, int height) throws IOException {
|
||||
int imageWidth = image.getWidth();
|
||||
int imageHeight = image.getHeight();
|
||||
double scale = (double) height / imageHeight;
|
||||
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scale, scale);
|
||||
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
|
||||
return bilinearScaleOp.filter(image, new BufferedImage((int) (imageWidth * scale), height, image.getType()));
|
||||
}
|
||||
|
||||
private static BufferedImage getScaledImageFill(BufferedImage image, int width, int height) throws IOException {
|
||||
int imageWidth = image.getWidth();
|
||||
int imageHeight = image.getHeight();
|
||||
double scaleX = (double) width / imageWidth;
|
||||
double scaleY = (double) height / imageHeight;
|
||||
double scale = scaleX > scaleY ? scaleX : scaleY;
|
||||
AffineTransform scaleTransform = AffineTransform.getScaleInstance(scale, scale);
|
||||
AffineTransformOp bilinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
|
||||
return bilinearScaleOp.filter(image, new BufferedImage(width, height, image.getType()));
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public BufferedImage getThumbnail() {
|
||||
return thumbnail;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
import MAndEngine.Engine;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
try{
|
||||
Scanner scan = new Scanner(new FileInputStream(new File("./AppList.cfg")));
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
while(scan.hasNextLine()) {
|
||||
String line = scan.nextLine();
|
||||
list.add("" + line);
|
||||
|
||||
}
|
||||
|
||||
String[] classes = new String[list.size()];
|
||||
classes = list.toArray(classes);
|
||||
|
||||
Engine engine = new Engine(classes, true);
|
||||
engine.run();
|
||||
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue