+ Added copy of BitmapEncoder
+ New sprite and unit "Town center" * Provisional collision checking. * Many other modifications.
This commit is contained in:
parent
b764612a79
commit
2cf2d608af
|
@ -0,0 +1,23 @@
|
|||
# Auto detect text files and perform LF normalization
|
||||
* text=auto
|
||||
*.jar binary
|
||||
|
||||
# Custom for Visual Studio
|
||||
*.cs diff=csharp
|
||||
*.sln merge=union
|
||||
*.csproj merge=union
|
||||
*.vbproj merge=union
|
||||
*.fsproj merge=union
|
||||
*.dbproj merge=union
|
||||
|
||||
# Standard to msysgit
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
|
@ -0,0 +1,3 @@
|
|||
/build/
|
||||
/dist/
|
||||
/settings.dat
|
Binary file not shown.
|
@ -0,0 +1,10 @@
|
|||
BitmapEncoder
|
||||
=============
|
||||
|
||||
**Encode images to display them on your Gamebuino**
|
||||
|
||||
The encoder is programmed using Java 8, so you have to install the Java 8 JRE if you don't already have it.
|
||||
|
||||
You can download it here: [Java 8 Download](http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html)
|
||||
|
||||
Once Java is installed, simply double click on BitmapEncoder.jar to run it.
|
|
@ -0,0 +1,13 @@
|
|||
#2014-08-12
|
||||
* larger output text area
|
||||
* upper case output hex value
|
||||
* bitmap takes the name of the selected file
|
||||
|
||||
#2014-08-19
|
||||
* added radio buttons to choose single or multi-file mode
|
||||
* added method for handling multiple image files in a single operation
|
||||
* various tweaks to the interface to accommodate new layout and modes
|
||||
* minor code cleanup/standardization (access modifiers, getters/setters, etc.)
|
||||
|
||||
#2014-08-26
|
||||
* fixed issue with saved directories for FileChooser that no longer exist
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,8 @@
|
|||
build.xml.data.CRC32=64fa75ef
|
||||
build.xml.script.CRC32=478ad818
|
||||
build.xml.stylesheet.CRC32=8064a381@1.74.2.48
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=64fa75ef
|
||||
nbproject/build-impl.xml.script.CRC32=9209127f
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.2.48
|
|
@ -0,0 +1,2 @@
|
|||
compile.on.save=true
|
||||
user.properties.file=D:\\Dropbox\\Program Files\\netbean_user\\build.properties
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group>
|
||||
<file>file:/D:/Dropbox/Gamebuino/BitmapEncoder/src/bitmapencoder/BitmapFrame.java</file>
|
||||
<file>file:/D:/Dropbox/Gamebuino/BitmapEncoder/src/bitmapencoder/BitmapEncoder.java</file>
|
||||
</group>
|
||||
</open-files>
|
||||
</project-private>
|
|
@ -0,0 +1,73 @@
|
|||
annotation.processing.enabled=true
|
||||
annotation.processing.enabled.in.editor=false
|
||||
annotation.processing.processor.options=
|
||||
annotation.processing.processors.list=
|
||||
annotation.processing.run.all.processors=true
|
||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
build.generated.sources.dir=${build.dir}/generated-sources
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
# Uncomment to specify the preferred debugger connection transport:
|
||||
#debug.transport=dt_socket
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# Files in build.classes.dir which should be excluded from distribution jar
|
||||
dist.archive.excludes=
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/BitmapEncoder.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
excludes=
|
||||
includes=**
|
||||
jar.compress=false
|
||||
javac.classpath=
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.processorpath=\
|
||||
${javac.classpath}
|
||||
javac.source=1.8
|
||||
javac.target=1.8
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
javac.test.processorpath=\
|
||||
${javac.test.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=${source.encoding}
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=bitmapencoder.BitmapFrame
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project.
|
||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
source.encoding=UTF-8
|
||||
src.dir=src
|
||||
test.src.dir=test
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>BitmapEncoder</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package bitmapencoder;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.io.File;
|
||||
import java.awt.image.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rodot
|
||||
*/
|
||||
public class BitmapEncoder {
|
||||
|
||||
private BufferedImage inputImage;
|
||||
private BufferedImage outputImage;
|
||||
private String bitmapName = "myBitmap";
|
||||
private boolean hexFormatting = false;
|
||||
private boolean wrapping = true;
|
||||
private static File[] filesToConvert;
|
||||
private static int imageCounter;
|
||||
private static int fileCount;
|
||||
|
||||
protected void BitmapEncoder() {
|
||||
}
|
||||
|
||||
protected void open(File file) {
|
||||
try {
|
||||
inputImage = ImageIO.read(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (inputImage != null) {
|
||||
if ((inputImage.getWidth() > 200) || (inputImage.getHeight() > 200)) {
|
||||
inputImage = null;
|
||||
return;
|
||||
}
|
||||
outputImage = deepCopy(inputImage);
|
||||
}
|
||||
}
|
||||
|
||||
protected void threshold(int thres) {
|
||||
if (inputImage == null) {
|
||||
return;
|
||||
}
|
||||
for (int y = 0; y < inputImage.getHeight(); y++) {
|
||||
for (int x = 0; x < inputImage.getWidth(); x++) {
|
||||
int rgb = inputImage.getRGB(x, y);
|
||||
int red = (rgb >> 16) & 0x000000FF;
|
||||
int green = (rgb >> 8) & 0x000000FF;
|
||||
int blue = (rgb) & 0x000000FF;
|
||||
int value = red + green + blue;
|
||||
if (value > thres) {
|
||||
outputImage.setRGB(x, y, 0x00FFFFFF);
|
||||
} else {
|
||||
outputImage.setRGB(x, y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String generateOutput(int thres) {
|
||||
if (inputImage == null) {
|
||||
return "";
|
||||
}
|
||||
String output = "";
|
||||
output = output.concat("const byte ");
|
||||
output = output.concat(bitmapName);
|
||||
output = output.concat("[] PROGMEM = {");
|
||||
int width = ((inputImage.getWidth() - 1) / 8 + 1) * 8; //round to the closest larger multiple of 8
|
||||
output = output.concat(width + "," + inputImage.getHeight() + ",");
|
||||
if (wrapping) {
|
||||
output = output.concat("\n");
|
||||
}
|
||||
for (int y = 0; y < inputImage.getHeight(); y++) {
|
||||
for (int x = 0; x < inputImage.getWidth(); x += 8) {
|
||||
if (hexFormatting) {
|
||||
output = output.concat("0x");
|
||||
} else {
|
||||
output = output.concat("B");
|
||||
}
|
||||
int thisByte = 0;
|
||||
for (int b = 0; b < 8; b++) {
|
||||
int value = 0xFFFF;
|
||||
if (x + b < inputImage.getWidth()) {
|
||||
int rgb = inputImage.getRGB(x + b, y);
|
||||
int red = (rgb >> 16) & 0x000000FF;
|
||||
int green = (rgb >> 8) & 0x000000FF;
|
||||
int blue = (rgb) & 0x000000FF;
|
||||
value = red + green + blue;
|
||||
}
|
||||
if (hexFormatting) {
|
||||
thisByte *= 2;
|
||||
if (value < thres) {
|
||||
thisByte++;
|
||||
}
|
||||
} else {//binary formattning
|
||||
if (value < thres) {
|
||||
output = output.concat("1");
|
||||
} else {
|
||||
output = output.concat("0");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (hexFormatting) {
|
||||
output = output.concat(Integer.toString(thisByte, 16).
|
||||
toUpperCase());
|
||||
}
|
||||
output = output.concat(",");
|
||||
}
|
||||
if (wrapping) {
|
||||
output = output.concat("\n");
|
||||
}
|
||||
}
|
||||
output = output.concat("};");
|
||||
return output;
|
||||
}
|
||||
|
||||
protected static BufferedImage deepCopy(BufferedImage bi) {
|
||||
ColorModel cm = bi.getColorModel();
|
||||
boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
|
||||
WritableRaster raster = bi.copyData(null);
|
||||
return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
|
||||
}
|
||||
|
||||
protected static int countFiles(File[] list, boolean recursed) {
|
||||
|
||||
if (list == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!recursed) {
|
||||
fileCount = 0;
|
||||
}
|
||||
|
||||
for (File f : list) {
|
||||
if (f.isDirectory()) {
|
||||
countFiles(f.listFiles(), true);
|
||||
} else {
|
||||
if (isImage(f)) {
|
||||
fileCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return fileCount;
|
||||
}
|
||||
|
||||
protected static boolean isImage(File f) {
|
||||
boolean isImage = false;
|
||||
if (f.getName().endsWith(".bmp") || f.getName().endsWith(".png")
|
||||
|| f.getName().endsWith(".jpeg")
|
||||
|| f.getName().endsWith(".jpg")) {
|
||||
isImage = true;
|
||||
}
|
||||
return isImage;
|
||||
}
|
||||
|
||||
protected static File[] processSelectedFiles(File[] list, boolean recursed) {
|
||||
if (!recursed) {
|
||||
filesToConvert = new File[countFiles(list, false)];
|
||||
imageCounter = 0;
|
||||
}
|
||||
if (list == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (File f : list) {
|
||||
if (f.isDirectory()) {
|
||||
processSelectedFiles(f.listFiles(), true);
|
||||
} else {
|
||||
if (isImage(f)) {
|
||||
filesToConvert[imageCounter] = f;
|
||||
imageCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return filesToConvert;
|
||||
}
|
||||
|
||||
protected BufferedImage getInputImage() {
|
||||
return inputImage;
|
||||
}
|
||||
|
||||
protected BufferedImage getOutputImage() {
|
||||
return outputImage;
|
||||
}
|
||||
|
||||
protected String getBitmapName() {
|
||||
return bitmapName;
|
||||
}
|
||||
|
||||
protected boolean isHexFormatting() {
|
||||
return hexFormatting;
|
||||
}
|
||||
|
||||
protected boolean isWrapping() {
|
||||
return wrapping;
|
||||
}
|
||||
|
||||
protected void setInputImage(BufferedImage inputImage) {
|
||||
this.inputImage = inputImage;
|
||||
}
|
||||
|
||||
protected void setOutputImage(BufferedImage outputImage) {
|
||||
this.outputImage = outputImage;
|
||||
}
|
||||
|
||||
protected void setBitmapName(String bitmapName) {
|
||||
this.bitmapName = bitmapName;
|
||||
}
|
||||
|
||||
protected void setHexFormatting(boolean hexFormatting) {
|
||||
this.hexFormatting = hexFormatting;
|
||||
}
|
||||
|
||||
protected void setWrapping(boolean wrapping) {
|
||||
this.wrapping = wrapping;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,530 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JFrameFormInfo">
|
||||
<NonVisualComponents>
|
||||
<Component class="javax.swing.ButtonGroup" name="buttonGroup1">
|
||||
</Component>
|
||||
</NonVisualComponents>
|
||||
<Properties>
|
||||
<Property name="defaultCloseOperation" type="int" value="2"/>
|
||||
<Property name="title" type="java.lang.String" value="Bitmap Encoder - Gamebuino"/>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[600, 502]"/>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="bitmapFrame" noResource="true"/>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[800, 600]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AccessibilityProperties>
|
||||
<Property name="AccessibleContext.accessibleDescription" type="java.lang.String" value=""/>
|
||||
</AccessibilityProperties>
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
|
||||
</SyntheticProperties>
|
||||
<Events>
|
||||
<EventHandler event="windowClosing" listener="java.awt.event.WindowListener" parameters="java.awt.event.WindowEvent" handler="formWindowClosing"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="jPanel3" max="32767" attributes="0"/>
|
||||
<Component id="jPanel1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jPanel2" max="32767" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="jPanel2" max="32767" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jPanel3" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="98" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="jPanel1">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="Input"/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="originalPanel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="previewPanel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="FileSelectionPanel" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="openButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="message" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="thresholdSlider" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="-2" pref="45" max="-2" attributes="0"/>
|
||||
<Component id="thresholdSlider" min="-2" pref="120" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="FileSelectionPanel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="openButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="message" alignment="3" min="-2" pref="23" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="originalPanel" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="previewPanel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="openButton">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Open"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="openButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="message">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Please select a file to encode"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="originalPanel">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
|
||||
<EtchetBorder/>
|
||||
</Border>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[400, 400]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[120, 120]"/>
|
||||
</Property>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[120, 120]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="original" alignment="0" pref="116" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="original" alignment="0" pref="116" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="original">
|
||||
<Properties>
|
||||
<Property name="horizontalAlignment" type="int" value="0"/>
|
||||
<Property name="text" type="java.lang.String" value="original"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="previewPanel">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
|
||||
<EtchetBorder/>
|
||||
</Border>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[400, 400]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[120, 120]"/>
|
||||
</Property>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[120, 120]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="preview" alignment="0" pref="116" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="preview" alignment="0" pref="116" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="preview">
|
||||
<Properties>
|
||||
<Property name="horizontalAlignment" type="int" value="0"/>
|
||||
<Property name="text" type="java.lang.String" value="preview"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Component class="javax.swing.JSlider" name="thresholdSlider">
|
||||
<Properties>
|
||||
<Property name="maximum" type="int" value="765"/>
|
||||
<Property name="orientation" type="int" value="1"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Use to adjust the thresold between black and white."/>
|
||||
<Property name="value" type="int" value="384"/>
|
||||
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
|
||||
<Color id="Default Cursor"/>
|
||||
</Property>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[20, 32767]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[20, 36]"/>
|
||||
</Property>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[20, 150]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="mouseReleased" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="thresholdSliderMouseReleased"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Container class="javax.swing.JPanel" name="FileSelectionPanel">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="File Selection Mode"/>
|
||||
</Border>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="" noResource="true"/>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="21" pref="21" max="-2" attributes="0"/>
|
||||
<Component id="allowDirectorySelectionCheckBox" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="singleFileModeRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="multiFileModeRadioButton" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="singleFileModeRadioButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="multiFileModeRadioButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="allowDirectorySelectionCheckBox" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="8" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JRadioButton" name="singleFileModeRadioButton">
|
||||
<Properties>
|
||||
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
|
||||
<ComponentRef name="buttonGroup1"/>
|
||||
</Property>
|
||||
<Property name="selected" type="boolean" value="true"/>
|
||||
<Property name="text" type="java.lang.String" value="Single File Mode"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="singleFileModeRadioButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JRadioButton" name="multiFileModeRadioButton">
|
||||
<Properties>
|
||||
<Property name="buttonGroup" type="javax.swing.ButtonGroup" editor="org.netbeans.modules.form.RADComponent$ButtonGroupPropertyEditor">
|
||||
<ComponentRef name="buttonGroup1"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="Multi File Mode (disables preview)"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="multiFileModeRadioButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="allowDirectorySelectionCheckBox">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Allow directory selection"/>
|
||||
<Property name="enabled" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="allowDirectorySelectionCheckBoxActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="jPanel2">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="Output"/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="outputScrollPane" alignment="0" pref="444" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="outputScrollPane" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JScrollPane" name="outputScrollPane">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Monospaced" size="11" style="0"/>
|
||||
</Property>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[200, 200]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTextArea" name="outputTextArea">
|
||||
<Properties>
|
||||
<Property name="columns" type="int" value="20"/>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Consolas" size="10" style="0"/>
|
||||
</Property>
|
||||
<Property name="rows" type="int" value="5"/>
|
||||
<Property name="autoscrolls" type="boolean" value="false"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="jPanel3">
|
||||
<Properties>
|
||||
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
|
||||
<Border info="org.netbeans.modules.form.compat2.border.TitledBorderInfo">
|
||||
<TitledBorder title="Settings"/>
|
||||
</Border>
|
||||
</Property>
|
||||
</Properties>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" max="-2" attributes="0">
|
||||
<Component id="wrapCheckbox" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="formattingBox" max="32767" attributes="0"/>
|
||||
<Component id="nameTextField" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="scaleSlider" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="scaleLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="nameLabel" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="formattingLabel" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="wrapLabel" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Component id="scaleLabel" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<Component id="scaleSlider" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="nameTextField" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="nameLabel" alignment="3" min="-2" pref="20" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="formattingLabel" min="-2" pref="21" max="-2" attributes="0"/>
|
||||
<Component id="formattingBox" alignment="0" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Component id="wrapCheckbox" max="32767" attributes="0"/>
|
||||
<Component id="wrapLabel" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JSlider" name="scaleSlider">
|
||||
<Properties>
|
||||
<Property name="maximum" type="int" value="4"/>
|
||||
<Property name="minimum" type="int" value="1"/>
|
||||
<Property name="minorTickSpacing" type="int" value="1"/>
|
||||
<Property name="paintLabels" type="boolean" value="true"/>
|
||||
<Property name="paintTicks" type="boolean" value="true"/>
|
||||
<Property name="snapToTicks" type="boolean" value="true"/>
|
||||
<Property name="value" type="int" value="2"/>
|
||||
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[150, 31]"/>
|
||||
</Property>
|
||||
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[150, 31]"/>
|
||||
</Property>
|
||||
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||
<Dimension value="[150, 31]"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="scaleSliderStateChanged"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="scaleLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Preview scale"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="nameTextField">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||
<Font name="Consolas" size="11" style="0"/>
|
||||
</Property>
|
||||
<Property name="text" type="java.lang.String" value="bitmapName"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="nameLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Bitmap name"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="formattingBox">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="2">
|
||||
<StringItem index="0" value="Binary (ex: B00110010)"/>
|
||||
<StringItem index="1" value="Hexadecimal (ex: 0x32)"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
<Property name="name" type="java.lang.String" value="" noResource="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="formattingBoxActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="formattingLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Output number formatting"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBox" name="wrapCheckbox">
|
||||
<Properties>
|
||||
<Property name="selected" type="boolean" value="true"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="wrapCheckboxActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="wrapLabel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Wrap output lines"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
|
@ -0,0 +1,799 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package bitmapencoder;
|
||||
|
||||
import static bitmapencoder.BitmapEncoder.deepCopy;
|
||||
import static bitmapencoder.BitmapEncoder.isImage;
|
||||
import static bitmapencoder.BitmapEncoder.processSelectedFiles;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rodot
|
||||
*/
|
||||
public class BitmapFrame extends javax.swing.JFrame {
|
||||
|
||||
BitmapEncoder encoder = new BitmapEncoder();
|
||||
final JFileChooser fileChooser = new JFileChooser();
|
||||
final JFileChooser multiFileChooser = new JFileChooser();
|
||||
private File[] filesSelected = null;
|
||||
private String lastSingleDirectory = System.getProperty("user.home");
|
||||
private String lastMultiDirectory = System.getProperty("user.home");
|
||||
private byte multiFormattingSetting = 1;
|
||||
private byte singleFormattingSetting = 0;
|
||||
private boolean multiWrapSetting = false;
|
||||
private boolean singleWrapSetting = true;
|
||||
private boolean allowDirectorySelection = false;
|
||||
|
||||
/**
|
||||
* Creates new form BitmapFrame
|
||||
*/
|
||||
private BitmapFrame() {
|
||||
initComponents();
|
||||
try {
|
||||
loadSettingsFromDisk();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(BitmapFrame.class.getName()).
|
||||
log(Level.SEVERE, null, ex);
|
||||
}
|
||||
formattingBox.setSelectedIndex((int) singleFormattingSetting);
|
||||
encoder.setHexFormatting(formattingBox.getSelectedIndex() == 1);
|
||||
wrapCheckbox.setSelected(singleWrapSetting);
|
||||
encoder.setWrapping(wrapCheckbox.isSelected());
|
||||
allowDirectorySelectionCheckBox.setSelected(allowDirectorySelection);
|
||||
File singleDirectory = new File(lastSingleDirectory);
|
||||
if (!singleDirectory.exists()) {
|
||||
lastSingleDirectory = System.getProperty("user.home");
|
||||
}
|
||||
fileChooser.setCurrentDirectory(new File(lastSingleDirectory));
|
||||
File multiDirectory = new File(lastMultiDirectory);
|
||||
if (!multiDirectory.exists()) {
|
||||
lastMultiDirectory = System.getProperty("user.home");
|
||||
}
|
||||
multiFileChooser.setCurrentDirectory(new File(lastMultiDirectory));
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called from within the constructor to initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is always
|
||||
* regenerated by the Form Editor.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
buttonGroup1 = new javax.swing.ButtonGroup();
|
||||
jPanel1 = new javax.swing.JPanel();
|
||||
openButton = new javax.swing.JButton();
|
||||
message = new javax.swing.JLabel();
|
||||
originalPanel = new javax.swing.JPanel();
|
||||
original = new javax.swing.JLabel();
|
||||
previewPanel = new javax.swing.JPanel();
|
||||
preview = new javax.swing.JLabel();
|
||||
thresholdSlider = new javax.swing.JSlider();
|
||||
FileSelectionPanel = new javax.swing.JPanel();
|
||||
singleFileModeRadioButton = new javax.swing.JRadioButton();
|
||||
multiFileModeRadioButton = new javax.swing.JRadioButton();
|
||||
allowDirectorySelectionCheckBox = new javax.swing.JCheckBox();
|
||||
jPanel2 = new javax.swing.JPanel();
|
||||
outputScrollPane = new javax.swing.JScrollPane();
|
||||
outputTextArea = new javax.swing.JTextArea();
|
||||
jPanel3 = new javax.swing.JPanel();
|
||||
scaleSlider = new javax.swing.JSlider();
|
||||
scaleLabel = new javax.swing.JLabel();
|
||||
nameTextField = new javax.swing.JTextField();
|
||||
nameLabel = new javax.swing.JLabel();
|
||||
formattingBox = new javax.swing.JComboBox();
|
||||
formattingLabel = new javax.swing.JLabel();
|
||||
wrapCheckbox = new javax.swing.JCheckBox();
|
||||
wrapLabel = new javax.swing.JLabel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
setTitle("Bitmap Encoder - Gamebuino");
|
||||
setMinimumSize(new java.awt.Dimension(600, 502));
|
||||
setName("bitmapFrame"); // NOI18N
|
||||
setPreferredSize(new java.awt.Dimension(800, 600));
|
||||
addWindowListener(new java.awt.event.WindowAdapter() {
|
||||
public void windowClosing(java.awt.event.WindowEvent evt) {
|
||||
formWindowClosing(evt);
|
||||
}
|
||||
});
|
||||
|
||||
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Input"));
|
||||
|
||||
openButton.setText("Open");
|
||||
openButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
openButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
message.setText("Please select a file to encode");
|
||||
|
||||
originalPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
|
||||
originalPanel.setMaximumSize(new java.awt.Dimension(400, 400));
|
||||
originalPanel.setMinimumSize(new java.awt.Dimension(120, 120));
|
||||
originalPanel.setPreferredSize(new java.awt.Dimension(120, 120));
|
||||
|
||||
original.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||
original.setText("original");
|
||||
|
||||
javax.swing.GroupLayout originalPanelLayout = new javax.swing.GroupLayout(originalPanel);
|
||||
originalPanel.setLayout(originalPanelLayout);
|
||||
originalPanelLayout.setHorizontalGroup(
|
||||
originalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(original, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
|
||||
);
|
||||
originalPanelLayout.setVerticalGroup(
|
||||
originalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(original, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
previewPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
|
||||
previewPanel.setMaximumSize(new java.awt.Dimension(400, 400));
|
||||
previewPanel.setMinimumSize(new java.awt.Dimension(120, 120));
|
||||
previewPanel.setPreferredSize(new java.awt.Dimension(120, 120));
|
||||
|
||||
preview.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||
preview.setText("preview");
|
||||
|
||||
javax.swing.GroupLayout previewPanelLayout = new javax.swing.GroupLayout(previewPanel);
|
||||
previewPanel.setLayout(previewPanelLayout);
|
||||
previewPanelLayout.setHorizontalGroup(
|
||||
previewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(preview, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
|
||||
);
|
||||
previewPanelLayout.setVerticalGroup(
|
||||
previewPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(preview, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
thresholdSlider.setMaximum(765);
|
||||
thresholdSlider.setOrientation(javax.swing.JSlider.VERTICAL);
|
||||
thresholdSlider.setToolTipText("Use to adjust the thresold between black and white.");
|
||||
thresholdSlider.setValue(384);
|
||||
thresholdSlider.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
|
||||
thresholdSlider.setMaximumSize(new java.awt.Dimension(20, 32767));
|
||||
thresholdSlider.setMinimumSize(new java.awt.Dimension(20, 36));
|
||||
thresholdSlider.setPreferredSize(new java.awt.Dimension(20, 150));
|
||||
thresholdSlider.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
public void mouseReleased(java.awt.event.MouseEvent evt) {
|
||||
thresholdSliderMouseReleased(evt);
|
||||
}
|
||||
});
|
||||
|
||||
FileSelectionPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("File Selection Mode"));
|
||||
FileSelectionPanel.setName(""); // NOI18N
|
||||
|
||||
buttonGroup1.add(singleFileModeRadioButton);
|
||||
singleFileModeRadioButton.setSelected(true);
|
||||
singleFileModeRadioButton.setText("Single File Mode");
|
||||
singleFileModeRadioButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
singleFileModeRadioButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonGroup1.add(multiFileModeRadioButton);
|
||||
multiFileModeRadioButton.setText("Multi File Mode (disables preview)");
|
||||
multiFileModeRadioButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
multiFileModeRadioButtonActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
allowDirectorySelectionCheckBox.setText("Allow directory selection");
|
||||
allowDirectorySelectionCheckBox.setEnabled(false);
|
||||
allowDirectorySelectionCheckBox.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
allowDirectorySelectionCheckBoxActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout FileSelectionPanelLayout = new javax.swing.GroupLayout(FileSelectionPanel);
|
||||
FileSelectionPanel.setLayout(FileSelectionPanelLayout);
|
||||
FileSelectionPanelLayout.setHorizontalGroup(
|
||||
FileSelectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(FileSelectionPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(FileSelectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(FileSelectionPanelLayout.createSequentialGroup()
|
||||
.addGap(21, 21, 21)
|
||||
.addComponent(allowDirectorySelectionCheckBox))
|
||||
.addComponent(singleFileModeRadioButton)
|
||||
.addComponent(multiFileModeRadioButton))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
FileSelectionPanelLayout.setVerticalGroup(
|
||||
FileSelectionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(FileSelectionPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(singleFileModeRadioButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(multiFileModeRadioButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(allowDirectorySelectionCheckBox)
|
||||
.addContainerGap(8, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||
jPanel1.setLayout(jPanel1Layout);
|
||||
jPanel1Layout.setHorizontalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(originalPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(previewPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addComponent(FileSelectionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addComponent(openButton)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addComponent(message)))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(thresholdSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap())
|
||||
);
|
||||
jPanel1Layout.setVerticalGroup(
|
||||
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addGap(45, 45, 45)
|
||||
.addComponent(thresholdSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addGroup(jPanel1Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(FileSelectionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(openButton)
|
||||
.addComponent(message, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(originalPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(previewPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Output"));
|
||||
|
||||
outputScrollPane.setFont(new java.awt.Font("Monospaced", 0, 11)); // NOI18N
|
||||
outputScrollPane.setPreferredSize(new java.awt.Dimension(200, 200));
|
||||
|
||||
outputTextArea.setColumns(20);
|
||||
outputTextArea.setFont(new java.awt.Font("Consolas", 0, 10)); // NOI18N
|
||||
outputTextArea.setRows(5);
|
||||
outputTextArea.setAutoscrolls(false);
|
||||
outputScrollPane.setViewportView(outputTextArea);
|
||||
|
||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
||||
jPanel2.setLayout(jPanel2Layout);
|
||||
jPanel2Layout.setHorizontalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(outputScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)
|
||||
);
|
||||
jPanel2Layout.setVerticalGroup(
|
||||
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(outputScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
);
|
||||
|
||||
jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings"));
|
||||
|
||||
scaleSlider.setMaximum(4);
|
||||
scaleSlider.setMinimum(1);
|
||||
scaleSlider.setMinorTickSpacing(1);
|
||||
scaleSlider.setPaintLabels(true);
|
||||
scaleSlider.setPaintTicks(true);
|
||||
scaleSlider.setSnapToTicks(true);
|
||||
scaleSlider.setValue(2);
|
||||
scaleSlider.setMaximumSize(new java.awt.Dimension(150, 31));
|
||||
scaleSlider.setMinimumSize(new java.awt.Dimension(150, 31));
|
||||
scaleSlider.setPreferredSize(new java.awt.Dimension(150, 31));
|
||||
scaleSlider.addChangeListener(new javax.swing.event.ChangeListener() {
|
||||
public void stateChanged(javax.swing.event.ChangeEvent evt) {
|
||||
scaleSliderStateChanged(evt);
|
||||
}
|
||||
});
|
||||
|
||||
scaleLabel.setText("Preview scale");
|
||||
|
||||
nameTextField.setFont(new java.awt.Font("Consolas", 0, 11)); // NOI18N
|
||||
nameTextField.setText("bitmapName");
|
||||
|
||||
nameLabel.setText("Bitmap name");
|
||||
|
||||
formattingBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Binary (ex: B00110010)", "Hexadecimal (ex: 0x32)" }));
|
||||
formattingBox.setName(""); // NOI18N
|
||||
formattingBox.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
formattingBoxActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
formattingLabel.setText("Output number formatting");
|
||||
|
||||
wrapCheckbox.setSelected(true);
|
||||
wrapCheckbox.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
wrapCheckboxActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
wrapLabel.setText("Wrap output lines");
|
||||
|
||||
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
|
||||
jPanel3.setLayout(jPanel3Layout);
|
||||
jPanel3Layout.setHorizontalGroup(
|
||||
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel3Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
||||
.addComponent(wrapCheckbox)
|
||||
.addComponent(formattingBox, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(nameTextField, javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(scaleSlider, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel3Layout.createSequentialGroup()
|
||||
.addComponent(scaleLabel)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addGroup(jPanel3Layout.createSequentialGroup()
|
||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(nameLabel)
|
||||
.addComponent(formattingLabel)
|
||||
.addComponent(wrapLabel))
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
|
||||
);
|
||||
jPanel3Layout.setVerticalGroup(
|
||||
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanel3Layout.createSequentialGroup()
|
||||
.addComponent(scaleLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
|
||||
.addComponent(scaleSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(8, 8, 8)))
|
||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(nameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(formattingLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addComponent(formattingBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
|
||||
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addComponent(wrapCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(wrapLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGap(0, 98, Short.MAX_VALUE)))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
getAccessibleContext().setAccessibleDescription("");
|
||||
|
||||
pack();
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
||||
private void scaleSliderStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_scaleSliderStateChanged
|
||||
if (singleFileModeRadioButton.isSelected()) {
|
||||
redrawPreview();
|
||||
}
|
||||
}//GEN-LAST:event_scaleSliderStateChanged
|
||||
|
||||
private void formattingBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formattingBoxActionPerformed
|
||||
encoder.setHexFormatting(formattingBox.getSelectedIndex() == 1);
|
||||
if (singleFileModeRadioButton.isSelected()) {
|
||||
singleFormattingSetting = (byte) formattingBox.getSelectedIndex();
|
||||
updateOutput();
|
||||
} else {
|
||||
multiFormattingSetting = (byte) formattingBox.getSelectedIndex();
|
||||
processMultiFiles();
|
||||
}
|
||||
}//GEN-LAST:event_formattingBoxActionPerformed
|
||||
|
||||
private void wrapCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wrapCheckboxActionPerformed
|
||||
encoder.setWrapping(wrapCheckbox.isSelected());
|
||||
if (singleFileModeRadioButton.isSelected()) {
|
||||
singleWrapSetting = wrapCheckbox.isSelected();
|
||||
updateOutput();
|
||||
} else {
|
||||
multiWrapSetting = wrapCheckbox.isSelected();;
|
||||
processMultiFiles();
|
||||
}
|
||||
}//GEN-LAST:event_wrapCheckboxActionPerformed
|
||||
|
||||
private void thresholdSliderMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_thresholdSliderMouseReleased
|
||||
if (encoder.getInputImage() == null && singleFileModeRadioButton.isSelected()) {
|
||||
message.setText("Open a image before you play with that slider!");
|
||||
} else if (singleFileModeRadioButton.isSelected()) {
|
||||
message.setText("Loading...");
|
||||
redrawPreview();
|
||||
message.setText("Output updated");
|
||||
} else if (multiFileModeRadioButton.isSelected()) {
|
||||
processMultiFiles();
|
||||
}
|
||||
}//GEN-LAST:event_thresholdSliderMouseReleased
|
||||
|
||||
private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed
|
||||
if (singleFileModeRadioButton.isSelected()) {
|
||||
int returnVal = fileChooser.showOpenDialog(BitmapFrame.this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
lastSingleDirectory = fileChooser.getCurrentDirectory().
|
||||
getAbsolutePath();
|
||||
File file = fileChooser.getSelectedFile();
|
||||
encoder.open(file);
|
||||
if (encoder.getInputImage() == null) {
|
||||
message.setText("Can't open the selected image");
|
||||
} else {
|
||||
message.setText("Image succesfully loaded");
|
||||
String fileName = file.getName();
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
|
||||
nameTextField.setText(fileName);
|
||||
redrawPreview();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
if (allowDirectorySelectionCheckBox.isSelected()) {
|
||||
multiFileChooser.setFileSelectionMode(
|
||||
JFileChooser.FILES_AND_DIRECTORIES);
|
||||
} else {
|
||||
multiFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||
}
|
||||
multiFileChooser.setMultiSelectionEnabled(true);
|
||||
int returnVal = multiFileChooser.showOpenDialog(this);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
lastMultiDirectory = multiFileChooser.getCurrentDirectory().
|
||||
getAbsolutePath();
|
||||
filesSelected = multiFileChooser.getSelectedFiles();
|
||||
processMultiFiles();
|
||||
}
|
||||
}
|
||||
try {
|
||||
saveSettingsToDisk(new File("settings.dat"));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(BitmapFrame.class.getName()).
|
||||
log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}//GEN-LAST:event_openButtonActionPerformed
|
||||
|
||||
private void processMultiFiles() {
|
||||
outputTextArea.setText("");
|
||||
String eol = System.lineSeparator();
|
||||
File[] filesToConvert = processSelectedFiles(filesSelected, false);
|
||||
if (filesToConvert == null) {
|
||||
return;
|
||||
}
|
||||
for (File f : filesToConvert) {
|
||||
if (f != null) {
|
||||
if (isImage(f)) {
|
||||
try {
|
||||
System.out.println("Reading image " + f.getName()
|
||||
+ "...");
|
||||
BufferedImage img = ImageIO.read(f);
|
||||
if (img != null) {
|
||||
if ((img.getWidth() > 200) || (img.getHeight()
|
||||
> 200)) {
|
||||
System.out.println("File " + f.getName()
|
||||
+ " is too large.");
|
||||
continue;
|
||||
}
|
||||
System.out.println("Deep copy of " + f.getName()
|
||||
+ ".");
|
||||
BufferedImage newImg = deepCopy(img);
|
||||
int threshold = thresholdSlider.getValue();
|
||||
System.out.println(
|
||||
"Setting threshold for new image.");
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
int rgb = img.getRGB(x, y);
|
||||
int red = (rgb >> 16) & 0x000000FF;
|
||||
int green = (rgb >> 8) & 0x000000FF;
|
||||
int blue = (rgb) & 0x000000FF;
|
||||
int value = red + green + blue;
|
||||
if (value > threshold) {
|
||||
newImg.setRGB(x, y, 0x00FFFFFF);
|
||||
} else {
|
||||
newImg.setRGB(x, y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
String bitmapName = f.getName().substring(0, f.
|
||||
getName().lastIndexOf("."));
|
||||
System.out.println("Generating output for " + f.
|
||||
getName() + ".");
|
||||
String output = outputTextArea.getText();
|
||||
output = output.concat("const byte ");
|
||||
output = output.concat(bitmapName);
|
||||
output = output.concat("[] PROGMEM = {");
|
||||
if (encoder.isWrapping()) {
|
||||
output = output.concat(eol);
|
||||
}
|
||||
int width = ((img.getWidth() - 1) / 8 + 1) * 8; //round to the closest larger multiple of 8
|
||||
output = output.concat(width + "," + img.
|
||||
getHeight() + ",");
|
||||
if (encoder.isWrapping()) {
|
||||
output = output.concat(eol);
|
||||
}
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth(); x += 8) {
|
||||
if (encoder.isHexFormatting()) {
|
||||
output = output.concat("0x");
|
||||
} else {
|
||||
output = output.concat("B");
|
||||
}
|
||||
int thisByte = 0;
|
||||
for (int b = 0; b < 8; b++) {
|
||||
int value = 0xFFFF;
|
||||
if (x + b < img.getWidth()) {
|
||||
int rgb = img.getRGB(x + b, y);
|
||||
int red = (rgb >> 16)
|
||||
& 0x000000FF;
|
||||
int green = (rgb >> 8)
|
||||
& 0x000000FF;
|
||||
int blue = (rgb) & 0x000000FF;
|
||||
value = red + green + blue;
|
||||
}
|
||||
if (encoder.isHexFormatting()) {
|
||||
thisByte *= 2;
|
||||
if (value < threshold) {
|
||||
thisByte++;
|
||||
}
|
||||
} else {//binary formatting
|
||||
if (value < threshold) {
|
||||
output = output.concat("1");
|
||||
} else {
|
||||
output = output.concat("0");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (encoder.isHexFormatting()) {
|
||||
output = output.concat(Integer.
|
||||
toString(thisByte, 16).
|
||||
toUpperCase());
|
||||
}
|
||||
output = output.concat(",");
|
||||
}
|
||||
if (encoder.isWrapping()) {
|
||||
output = output.concat(eol);
|
||||
}
|
||||
}
|
||||
output = output.concat("};" + eol);
|
||||
if (encoder.isWrapping()) {
|
||||
output = output.concat(eol);
|
||||
}
|
||||
outputTextArea.setText(output);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(BitmapFrame.class.
|
||||
getName()).
|
||||
log(Level.SEVERE, null, ex);
|
||||
}
|
||||
} else {
|
||||
System.out.println("File " + f.getName()
|
||||
+ " is not an image.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void singleFileModeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_singleFileModeRadioButtonActionPerformed
|
||||
scaleSlider.setEnabled(true);
|
||||
nameTextField.setEnabled(true);
|
||||
allowDirectorySelectionCheckBox.setEnabled(false);
|
||||
formattingBox.setSelectedIndex((int) singleFormattingSetting);
|
||||
encoder.setHexFormatting(formattingBox.getSelectedIndex() == 1);
|
||||
wrapCheckbox.setSelected(singleWrapSetting);
|
||||
encoder.setWrapping(wrapCheckbox.isSelected());
|
||||
updateOutput();
|
||||
}//GEN-LAST:event_singleFileModeRadioButtonActionPerformed
|
||||
|
||||
private void multiFileModeRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiFileModeRadioButtonActionPerformed
|
||||
scaleSlider.setEnabled(false);
|
||||
nameTextField.setEnabled(false);
|
||||
allowDirectorySelectionCheckBox.setEnabled(true);
|
||||
formattingBox.setSelectedIndex((int) multiFormattingSetting);
|
||||
encoder.setHexFormatting(formattingBox.getSelectedIndex() == 1);
|
||||
wrapCheckbox.setSelected(multiWrapSetting);
|
||||
encoder.setWrapping(wrapCheckbox.isSelected());
|
||||
processMultiFiles();
|
||||
}//GEN-LAST:event_multiFileModeRadioButtonActionPerformed
|
||||
|
||||
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
|
||||
try {
|
||||
saveSettingsToDisk(new File("settings.dat"));
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(BitmapFrame.class.getName()).
|
||||
log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}//GEN-LAST:event_formWindowClosing
|
||||
|
||||
private void allowDirectorySelectionCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_allowDirectorySelectionCheckBoxActionPerformed
|
||||
allowDirectorySelection = allowDirectorySelectionCheckBox.isSelected();
|
||||
}//GEN-LAST:event_allowDirectorySelectionCheckBoxActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
/* Set the Nimbus look and feel */
|
||||
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
|
||||
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
|
||||
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
|
||||
*/
|
||||
try {
|
||||
/*for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
|
||||
if ("Nimbus".equals(info.getName())) {
|
||||
javax.swing.UIManager.setLookAndFeel(info.getClassName());
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.
|
||||
getSystemLookAndFeelClassName());
|
||||
} catch (ClassNotFoundException | InstantiationException |
|
||||
IllegalAccessException |
|
||||
javax.swing.UnsupportedLookAndFeelException ex) {
|
||||
java.util.logging.Logger.getLogger(BitmapFrame.class.getName()).log(
|
||||
java.util.logging.Level.SEVERE, null, ex);
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
/* Create and display the form */
|
||||
java.awt.EventQueue.invokeLater(() -> {
|
||||
new BitmapFrame().setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
private void redrawPreview() {
|
||||
int scale = scaleSlider.getValue();
|
||||
//input image
|
||||
Image in = BitmapEncoder.deepCopy(encoder.getInputImage());
|
||||
in = in.getScaledInstance(in.getWidth(null) * scale, in.getHeight(null)
|
||||
* scale, java.awt.Image.SCALE_REPLICATE);
|
||||
ImageIcon originalIcon = new ImageIcon(in);
|
||||
original.setText("");
|
||||
original.setIcon(originalIcon);
|
||||
//output image
|
||||
encoder.threshold(thresholdSlider.getValue());
|
||||
Image out = BitmapEncoder.deepCopy(encoder.getOutputImage());
|
||||
out = out.getScaledInstance(out.getWidth(null) * scale, out.getHeight(
|
||||
null) * scale, java.awt.Image.SCALE_REPLICATE);
|
||||
ImageIcon previewIcon = new ImageIcon(out);
|
||||
preview.setText("");
|
||||
preview.setIcon(previewIcon);
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
private void updateOutput() {
|
||||
encoder.setBitmapName(nameTextField.getText());
|
||||
outputTextArea.setText(encoder.
|
||||
generateOutput(thresholdSlider.getValue()));
|
||||
outputTextArea.setCaretPosition(0);
|
||||
}
|
||||
|
||||
private void loadSettingsFromDisk() throws IOException {
|
||||
File saveFile = new File("settings.dat");
|
||||
if (saveFile.createNewFile()) {
|
||||
saveSettingsToDisk(saveFile);
|
||||
} else {
|
||||
BufferedReader br = new BufferedReader(new FileReader(saveFile));
|
||||
for (String line; (line = br.readLine()) != null;) {
|
||||
String settingName = line.trim().substring(0, line.indexOf(":"));
|
||||
String setting = line.substring((line.indexOf(":") + 1)).trim();
|
||||
switch (settingName) {
|
||||
case "LAST_SINGLE_DIRECTORY":
|
||||
lastSingleDirectory = setting;
|
||||
break;
|
||||
case "LAST_MULTI_DIRECTORY":
|
||||
lastMultiDirectory = setting;
|
||||
break;
|
||||
case "SINGLE_FORMATTING":
|
||||
singleFormattingSetting = Byte.valueOf(setting);
|
||||
break;
|
||||
case "MULTI_FORMATTING":
|
||||
multiFormattingSetting = Byte.valueOf(setting);
|
||||
break;
|
||||
case "SINGLE_WRAPPING":
|
||||
singleWrapSetting = Boolean.valueOf(setting);
|
||||
break;
|
||||
case "MULTI_WRAPPING":
|
||||
multiWrapSetting = Boolean.valueOf(setting);
|
||||
break;
|
||||
case "ALLOW_DIRECTORY_SELECTION":
|
||||
allowDirectorySelection = Boolean.valueOf(setting);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// line is not visible here.
|
||||
}
|
||||
}
|
||||
|
||||
private void saveSettingsToDisk(File saveFile) throws IOException {
|
||||
try (BufferedWriter out = new BufferedWriter(new FileWriter(saveFile))) {
|
||||
out.write("LAST_SINGLE_DIRECTORY: " + lastSingleDirectory);
|
||||
out.newLine();
|
||||
out.write("LAST_MULTI_DIRECTORY: " + lastMultiDirectory);
|
||||
out.newLine();
|
||||
out.write("SINGLE_FORMATTING: " + singleFormattingSetting);
|
||||
out.newLine();
|
||||
out.write("MULTI_FORMATTING: " + multiFormattingSetting);
|
||||
out.newLine();
|
||||
out.write("SINGLE_WRAPPING: " + singleWrapSetting);
|
||||
out.newLine();
|
||||
out.write("MULTI_WRAPPING: " + multiWrapSetting);
|
||||
out.newLine();
|
||||
out.write("ALLOW_DIRECTORY_SELECTION: " + allowDirectorySelection);
|
||||
out.newLine();
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JPanel FileSelectionPanel;
|
||||
private javax.swing.JCheckBox allowDirectorySelectionCheckBox;
|
||||
private javax.swing.ButtonGroup buttonGroup1;
|
||||
private javax.swing.JComboBox formattingBox;
|
||||
private javax.swing.JLabel formattingLabel;
|
||||
private javax.swing.JPanel jPanel1;
|
||||
private javax.swing.JPanel jPanel2;
|
||||
private javax.swing.JPanel jPanel3;
|
||||
private javax.swing.JLabel message;
|
||||
private javax.swing.JRadioButton multiFileModeRadioButton;
|
||||
private javax.swing.JLabel nameLabel;
|
||||
private javax.swing.JTextField nameTextField;
|
||||
private javax.swing.JButton openButton;
|
||||
private javax.swing.JLabel original;
|
||||
private javax.swing.JPanel originalPanel;
|
||||
private javax.swing.JScrollPane outputScrollPane;
|
||||
private javax.swing.JTextArea outputTextArea;
|
||||
private javax.swing.JLabel preview;
|
||||
private javax.swing.JPanel previewPanel;
|
||||
private javax.swing.JLabel scaleLabel;
|
||||
private javax.swing.JSlider scaleSlider;
|
||||
private javax.swing.JRadioButton singleFileModeRadioButton;
|
||||
private javax.swing.JSlider thresholdSlider;
|
||||
private javax.swing.JCheckBox wrapCheckbox;
|
||||
private javax.swing.JLabel wrapLabel;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
}
|
2
Camera.c
2
Camera.c
|
@ -43,7 +43,7 @@ TYPE_COLLISION_BLOCK CameraApplyCoordinatesToCoordinates( TYPE_CAMERA* ptrCamera
|
|||
}
|
||||
|
||||
void CameraApplyCoordinatesToSprite(TYPE_CAMERA* ptrCamera,
|
||||
TYPE_SPRITE * spr,
|
||||
TYPE_SPRITE* spr,
|
||||
uint16_t x,
|
||||
uint16_t y )
|
||||
{
|
||||
|
|
2
Camera.h
2
Camera.h
|
@ -42,7 +42,7 @@ void CameraInit(TYPE_CAMERA* ptrCamera);
|
|||
void CameraHandler(TYPE_CAMERA* ptrCamera);
|
||||
void CameraSetLock(TYPE_CAMERA* ptrCamera, bool value);
|
||||
void CameraApplyCoordinatesToSprite( TYPE_CAMERA* ptrCamera,
|
||||
TYPE_SPRITE * spr,
|
||||
TYPE_SPRITE* spr,
|
||||
uint16_t x,
|
||||
uint16_t y );
|
||||
TYPE_COLLISION_BLOCK CameraApplyCoordinatesToCoordinates( TYPE_CAMERA* ptrCamera,
|
||||
|
|
BIN
Exe/POCKET.ELF
BIN
Exe/POCKET.ELF
Binary file not shown.
2634
Exe/POCKET.HEX
2634
Exe/POCKET.HEX
File diff suppressed because it is too large
Load Diff
1099
Exe/POCKET.MAP
1099
Exe/POCKET.MAP
File diff suppressed because it is too large
Load Diff
47
Gameplay.cpp
47
Gameplay.cpp
|
@ -3,8 +3,9 @@
|
|||
* **************************************/
|
||||
|
||||
#include "Gameplay.h"
|
||||
#include "MouseSpr.c"
|
||||
#include "MouseSpr.i"
|
||||
#include "Pad.h"
|
||||
#include "Camera.h"
|
||||
|
||||
/* **************************************
|
||||
* Defines *
|
||||
|
@ -24,7 +25,7 @@ static const char PauseMenuOption_0[] PROGMEM = "Resume";
|
|||
static const char PauseMenuOption_1[] PROGMEM = "Quit";
|
||||
static TYPE_SPRITE MouseSpr;
|
||||
|
||||
static const char* const PauseMenuOptions[] PROGMEM = {PauseMenuOption_0,
|
||||
static const char* const PauseMenuOptions[] PROGMEM = { PauseMenuOption_0,
|
||||
PauseMenuOption_1 };
|
||||
|
||||
/* **************************************
|
||||
|
@ -36,48 +37,9 @@ static void GameGraphics(void);
|
|||
static bool GamePause(void);
|
||||
static void GameLoop(void);
|
||||
|
||||
/*
|
||||
|
||||
const byte TowerSpr[] PROGMEM = {16,32,
|
||||
0xF,0xF0,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0xF,0xF0,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x1B,0xD8,
|
||||
0x2A,0x54,
|
||||
0x4A,0x52,
|
||||
0xFB,0xDF,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x9,0x90,
|
||||
0x9,0x90,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x9,0x90,
|
||||
0x9,0x90,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0xB,0xD0,
|
||||
0xA,0x50,
|
||||
0xA,0x50,
|
||||
0xF,0xF0,
|
||||
};*/
|
||||
|
||||
void GameInit(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < GAME_MAX_PLAYERS; i++)
|
||||
for (uint8_t i = 0; i < GAME_MAX_PLAYERS; i++)
|
||||
{
|
||||
GamePlayers[i].Init();
|
||||
}
|
||||
|
@ -100,7 +62,6 @@ bool GamePause(void)
|
|||
{
|
||||
if (PadButtonReleased(PAD_C) == true)
|
||||
{
|
||||
//int8_t menu(const char* const* items, uint8_t length);
|
||||
uint8_t choice = gb.menu(PauseMenuOptions, 2);
|
||||
|
||||
if (choice != 0)
|
||||
|
|
|
@ -12,7 +12,11 @@
|
|||
* Defines *
|
||||
* **************************************/
|
||||
|
||||
#define GAME_MAX_PLAYERS 1
|
||||
#define GAME_MAX_PLAYERS 1
|
||||
|
||||
/* **************************************
|
||||
* Structs and enums *
|
||||
* **************************************/
|
||||
|
||||
/* **************************************
|
||||
* Global prototypes *
|
||||
|
|
53
Gfx.cpp
53
Gfx.cpp
|
@ -24,8 +24,13 @@ void GfxInit(void)
|
|||
gb.display.setFont(font3x5);
|
||||
}
|
||||
|
||||
void GfxDrawSprite(TYPE_SPRITE * ptrSprite)
|
||||
void GfxDrawSprite(TYPE_SPRITE* ptrSprite)
|
||||
{
|
||||
if (ptrSprite == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (GfxIsSpriteInsideScreenArea(ptrSprite) == true)
|
||||
{
|
||||
int8_t orig_color = gb.display.getColor();
|
||||
|
@ -84,7 +89,7 @@ bool GfxIsInsideScreenArea(int8_t x, int8_t y, uint8_t w, uint8_t h)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool GfxIsSpriteInsideScreenArea(TYPE_SPRITE * spr)
|
||||
bool GfxIsSpriteInsideScreenArea(TYPE_SPRITE* spr)
|
||||
{
|
||||
return GfxIsInsideScreenArea(spr->x, spr->y, spr->w, spr->h);
|
||||
}
|
||||
|
@ -125,50 +130,6 @@ void GfxPrintTextFont(const char* str, const uint8_t* font, uint8_t x, uint8_t y
|
|||
}
|
||||
}
|
||||
|
||||
void GfxRenderTiles(TYPE_CAMERA* ptrCamera)
|
||||
{
|
||||
gb.display.setColor(GFX_GRAY);
|
||||
|
||||
if (ptrCamera == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Y_SCREEN_RESOLUTION; i+=8)
|
||||
{
|
||||
for (int j = 0; j < X_SCREEN_RESOLUTION; j++)
|
||||
{
|
||||
//if (j & 1)
|
||||
//{
|
||||
int x = j + ptrCamera->X_Offset;
|
||||
int y = i + ptrCamera->Y_Offset;
|
||||
|
||||
if ((x >= 0) && (y >= 0))
|
||||
{
|
||||
gb.display.drawPixel(j + ptrCamera->X_Offset, i + ptrCamera->Y_Offset);
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < X_SCREEN_RESOLUTION; i+=8)
|
||||
{
|
||||
for (int j = 0; j < Y_SCREEN_RESOLUTION; j++)
|
||||
{
|
||||
//if (j & 1)
|
||||
//{
|
||||
int x = j + ptrCamera->X_Offset;
|
||||
int y = i + ptrCamera->Y_Offset;
|
||||
|
||||
if ((x >= 0) && (y >= 0))
|
||||
{
|
||||
gb.display.drawPixel(i + ptrCamera->X_Offset, j + ptrCamera->Y_Offset);
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GfxPrintText(const char* str, uint8_t x, uint8_t y)
|
||||
{
|
||||
GfxPrintTextFont(str, font3x5, x, y);
|
||||
|
|
5
Gfx.h
5
Gfx.h
|
@ -59,7 +59,7 @@ typedef struct t_Camera TYPE_CAMERA;
|
|||
* Global prototypes
|
||||
* *************************************/
|
||||
|
||||
void GfxDrawSprite(TYPE_SPRITE * ptrSprite);
|
||||
void GfxDrawSprite(TYPE_SPRITE* ptrSprite);
|
||||
void GfxDrawCircle(uint16_t x, uint16_t y, uint8_t radius, int8_t color);
|
||||
void GfxDrawRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, int8_t color);
|
||||
void GfxFillRectangle(uint8_t x, uint8_t y, uint8_t w, uint8_t h, int8_t color);
|
||||
|
@ -68,7 +68,7 @@ bool GfxRefreshNeeded(void);
|
|||
void GfxShowKeyboard(char* str, uint8_t length);
|
||||
uint8_t GfxGetWidthFromSpriteData(const uint8_t* sprData);
|
||||
uint8_t GfxGetHeightFromSpriteData(const uint8_t* sprData);
|
||||
bool GfxIsSpriteInsideScreenArea(TYPE_SPRITE * spr);
|
||||
bool GfxIsSpriteInsideScreenArea(TYPE_SPRITE* spr);
|
||||
void GfxClearScreen(void);
|
||||
#ifdef __cplusplus
|
||||
void GfxPrintText_Flash(const __FlashStringHelper * str);
|
||||
|
@ -76,7 +76,6 @@ void GfxPrintText_Flash(const __FlashStringHelper * str);
|
|||
void GfxPrintText(const char* str, uint8_t x, uint8_t y);
|
||||
void GfxPrintTextFont(const char* str, const uint8_t* font, uint8_t x, uint8_t y);
|
||||
void GfxInit(void);
|
||||
void GfxRenderTiles(TYPE_CAMERA* ptrCamera);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ $(LIBNAME): $(OBJECTS)
|
|||
|
||||
%.o: %.cpp
|
||||
$(CXX) $< -o $@ $(INCLUDE) $(DEFINE) $(CC_FLAGS)
|
||||
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $< -o $@ $(INCLUDE) $(DEFINE) $(CC_FLAGS)
|
||||
|
||||
|
|
|
@ -30,5 +30,5 @@ $(LIBNAME): $(OBJECTS)
|
|||
clean:
|
||||
rm -f $(OBJECTS)
|
||||
rm -f $(LIBS_FOLDER)/$(LIBNAME)
|
||||
|
||||
|
||||
.PHONY: default clean
|
||||
|
|
|
@ -12,7 +12,7 @@ LIBNAME=lib$(PROJECT).a
|
|||
OBJECTS=mmc.o petit_fatfs.o pff.o
|
||||
|
||||
default: $(LIBNAME)
|
||||
|
||||
|
||||
$(LIBNAME): $(OBJECTS)
|
||||
avr-ar rcs $@ $^
|
||||
mkdir -p $(INCLUDE_FOLDER)/$(PROJECT)
|
||||
|
@ -22,12 +22,12 @@ $(LIBNAME): $(OBJECTS)
|
|||
|
||||
%.o: %.cpp
|
||||
$(CXX) $< -o $@ $(DEFINE) $(INCLUDE) $(CC_FLAGS)
|
||||
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $< -o $@ $(DEFINE) $(INCLUDE) $(CC_FLAGS)
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS)
|
||||
rm -f $(LIBS_FOLDER)/$(LIBNAME)
|
||||
|
||||
|
||||
.PHONY: default clean
|
||||
|
|
|
@ -21,7 +21,7 @@ $(LIBNAME): $(OBJECTS)
|
|||
|
||||
%.o: %.cpp
|
||||
$(CXX) $< -o $@ $(INCLUDE) $(DEFINE) $(CC_FLAGS)
|
||||
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $< -o $@ $(INCLUDE) $(DEFINE) $(CC_FLAGS)
|
||||
|
||||
|
|
47
Player.cpp
47
Player.cpp
|
@ -5,7 +5,7 @@
|
|||
#include "Player.h"
|
||||
#include "Pad.h"
|
||||
#include "Unit.h"
|
||||
#include <limits.h>
|
||||
#include "Gameplay.h"
|
||||
|
||||
/* **************************************
|
||||
* Defines *
|
||||
|
@ -53,7 +53,7 @@ void Player::Init(void)
|
|||
cb.x = SystemRand(0, 20);
|
||||
cb.y = SystemRand(0, 20);
|
||||
|
||||
if (createUnit(BARRACKS, cb) == false)
|
||||
if (createUnit(TOWN_CENTER, cb) == false)
|
||||
{
|
||||
GfxPrintText_Flash(F("Failed to create building!"));
|
||||
}
|
||||
|
@ -104,8 +104,6 @@ void Player::DrawHandler(void)
|
|||
uint8_t i;
|
||||
bool bAnyoneSelected = false;
|
||||
|
||||
//GfxRenderTiles(&Camera);
|
||||
|
||||
for (i = 0; i < PLAYER_MAX_UNITS_BUILDINGS; i++)
|
||||
{
|
||||
TYPE_UNIT* u = &units[i];
|
||||
|
@ -318,7 +316,7 @@ void Player::ActionsMenu(void)
|
|||
IncreaseShowActionsMenuIndex();
|
||||
}
|
||||
|
||||
UNIT_ACTION action = (UNIT_ACTION) (showActionsMenu_index);
|
||||
UNIT_ACTION action = (UNIT_ACTION)(showActionsMenu_index);
|
||||
|
||||
const char* str = UnitGetActionString(action);
|
||||
|
||||
|
@ -371,8 +369,6 @@ void Player::ButtonHandler(void)
|
|||
{
|
||||
ButtonRightReleased();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Player::ButtonAPressed(void)
|
||||
|
@ -418,10 +414,19 @@ void Player::ButtonAReleased(void)
|
|||
|
||||
if (ptrUnit->selected == true)
|
||||
{
|
||||
showActionsMenu_counterLevel1 = 0;
|
||||
|
||||
switch (showActionsMenu_index)
|
||||
{
|
||||
case ACTION_CREATE_UNIT:
|
||||
ActionCreateUnit(ptrUnit);
|
||||
case ACTION_CREATE_PEASANT:
|
||||
ActionCreateUnit(ptrUnit, PEASANT);
|
||||
break;
|
||||
|
||||
case ACTION_BUILD_BARRACKS:
|
||||
ActionCreateBuilding(ptrUnit, BARRACKS);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -433,18 +438,22 @@ void Player::ButtonAReleased(void)
|
|||
showActionsMenu = (showActionsMenu_counter < ACCEPT_UNIT_BUILDING_OPTIONS_FRAMES)? false: true;
|
||||
}
|
||||
|
||||
void Player::ActionCreateUnit(TYPE_UNIT* ptrUnit)
|
||||
void Player::ActionCreateUnit(TYPE_UNIT* ptrUnit, TYPE_UNIT_ID unit)
|
||||
{
|
||||
if (showActionsMenu_index == ACTION_CREATE_UNIT)
|
||||
{
|
||||
uint8_t w = UnitGetWidthFromID(ptrUnit->id);
|
||||
uint8_t h = UnitGetHeightFromID(ptrUnit->id);
|
||||
uint8_t new_pos_x = ptrUnit->x + SystemRand(w, w + (w >> 1));
|
||||
uint8_t new_pos_y = ptrUnit->y + SystemRand(h, h + (h >> 1));
|
||||
TYPE_COLLISION_BLOCK cb = {.x = new_pos_x, .y = new_pos_y};
|
||||
uint8_t w = UnitGetWidthFromID(ptrUnit->id);
|
||||
uint8_t h = UnitGetHeightFromID(ptrUnit->id);
|
||||
uint8_t new_pos_x = ptrUnit->x + SystemRand(w, w + (w >> 1));
|
||||
uint8_t new_pos_y = ptrUnit->y + SystemRand(h, h + (h >> 1));
|
||||
TYPE_COLLISION_BLOCK cb = {.x = new_pos_x, .y = new_pos_y};
|
||||
|
||||
createUnit(PEASANT, cb);
|
||||
}
|
||||
createUnit(unit, cb);
|
||||
}
|
||||
|
||||
void Player::ActionCreateBuilding(TYPE_UNIT* ptrUnit, TYPE_UNIT_ID bldg)
|
||||
{
|
||||
TYPE_COLLISION_BLOCK cb = GetCursorPos();
|
||||
|
||||
createUnit(bldg, cb);
|
||||
}
|
||||
|
||||
void Player::ButtonBPressed(void)
|
||||
|
|
7
Player.h
7
Player.h
|
@ -61,6 +61,9 @@ class Player
|
|||
// Camera handling
|
||||
TYPE_CAMERA Camera;
|
||||
|
||||
// Map rendering
|
||||
void RenderMap(void);
|
||||
|
||||
// Button pressed/released events
|
||||
void ButtonLeftReleased(void);
|
||||
void ButtonRightReleased(void);
|
||||
|
@ -85,10 +88,12 @@ class Player
|
|||
bool showActionsMenu;
|
||||
uint8_t showActionsMenu_counter;
|
||||
uint8_t showActionsMenu_index;
|
||||
uint8_t showActionsMenu_counterLevel1;
|
||||
void IncreaseShowActionsMenuIndex();
|
||||
|
||||
// Action callbacks
|
||||
void ActionCreateUnit (TYPE_UNIT* ptrUnit);
|
||||
void ActionCreateUnit(TYPE_UNIT* ptrUnit, TYPE_UNIT_ID unit);
|
||||
void ActionCreateBuilding(TYPE_UNIT* ptrUnit, TYPE_UNIT_ID bldg);
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
[Dolphin]
|
||||
PreviewsShown=true
|
||||
Timestamp=2017,11,5,4,13,19
|
||||
Version=3
|
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
|
@ -0,0 +1,33 @@
|
|||
const byte TowerSpr[] PROGMEM = { 16,32,
|
||||
0xF,0xF0,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0xF,0xF0,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x1B,0xD8,
|
||||
0x2A,0x54,
|
||||
0x4A,0x52,
|
||||
0xFB,0xDF,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x9,0x90,
|
||||
0x9,0x90,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x9,0x90,
|
||||
0x9,0x90,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0x8,0x10,
|
||||
0xB,0xD0,
|
||||
0xA,0x50,
|
||||
0xA,0x50,
|
||||
0xF,0xF0, };
|
|
@ -0,0 +1,53 @@
|
|||
const uint8_t TownCentreSprData[] PROGMEM = {24,24,
|
||||
0x3,0xFF,0xC0,
|
||||
0xC,0x0,0x30,
|
||||
0x37,0xFF,0xEC,
|
||||
0x78,0x0,0x16,
|
||||
0xAF,0xFF,0xF5,
|
||||
0xA8,0x0,0x15,
|
||||
0xA8,0xFF,0x15,
|
||||
0xA8,0x81,0x15,
|
||||
0xA8,0xFF,0xD5,
|
||||
0xAB,0x81,0x55,
|
||||
0xAA,0xA5,0xD5,
|
||||
0xAB,0x81,0x55,
|
||||
0xAA,0xA5,0x55,
|
||||
0xAB,0x81,0xD5,
|
||||
0xA8,0x99,0x15,
|
||||
0xA8,0xFF,0x15,
|
||||
0xA6,0x0,0x65,
|
||||
0x91,0xC3,0x89,
|
||||
0x8C,0x42,0x31,
|
||||
0x83,0xC3,0xC1,
|
||||
0x40,0x42,0x2,
|
||||
0x30,0x42,0xC,
|
||||
0xC,0x42,0x30,
|
||||
0x3,0xC3,0xC0,
|
||||
};
|
||||
|
||||
const uint8_t TownCentreShadowSprData[] PROGMEM = {24,24,
|
||||
0x1F,0x80,0x0,
|
||||
0x7E,0x0,0x0,
|
||||
0xF8,0x0,0x0,
|
||||
0xF0,0x0,0x0,
|
||||
0xE0,0x0,0x0,
|
||||
0xE0,0x0,0x4,
|
||||
0xE0,0x0,0x4,
|
||||
0xE0,0x0,0x4,
|
||||
0xE2,0xE0,0x4,
|
||||
0xE2,0x80,0x4,
|
||||
0xE2,0x80,0x4,
|
||||
0xE2,0x80,0x4,
|
||||
0xE2,0x80,0x4,
|
||||
0xE2,0x80,0x4,
|
||||
0xE2,0xE0,0x4,
|
||||
0xE0,0x60,0xC,
|
||||
0xE0,0x0,0x10,
|
||||
0xE0,0x0,0x0,
|
||||
0xE0,0x0,0x0,
|
||||
0xE0,0x1,0x80,
|
||||
0xF0,0x1,0x80,
|
||||
0xF8,0x1,0x80,
|
||||
0x7E,0x1,0x80,
|
||||
0x1F,0x81,0x80,
|
||||
};
|
74
Unit.c
74
Unit.c
|
@ -3,8 +3,9 @@
|
|||
* **************************************/
|
||||
|
||||
#include "Unit.h"
|
||||
#include "PeasantSpr.inc"
|
||||
#include "BarracksSpr.inc"
|
||||
#include "PeasantSpr.i"
|
||||
#include "BarracksSpr.i"
|
||||
#include "TownCentre.i"
|
||||
|
||||
/* **************************************
|
||||
* Defines *
|
||||
|
@ -30,33 +31,32 @@ struct t_coordinates
|
|||
|
||||
/* Tables */
|
||||
static uint8_t const UnitHPTable[MAX_UNITS_BUILDINGS] = { [PEASANT] = 25 ,
|
||||
[BARRACKS] = 100 };
|
||||
static uint8_t const UnitSpeedTable[MAX_UNITS_BUILDINGS] = { [PEASANT] = 1 ,
|
||||
[BARRACKS] = 0 };
|
||||
[BARRACKS] = 100,
|
||||
[TOWN_CENTER] = 200 };
|
||||
|
||||
static const char* const UnitActionsTable_Level[MAX_ACTIONS] = { [ACTION_BUILD] = "BUILD",
|
||||
[ACTION_ATTACK] = "ATTACK",
|
||||
[ACTION_CREATE_UNIT] = "CREATE"};
|
||||
static uint8_t const UnitSpeedTable[MAX_UNITS_BUILDINGS] = { [PEASANT] = 1,
|
||||
[BARRACKS] = 0,
|
||||
[TOWN_CENTER] = 0 };
|
||||
|
||||
static uint8_t const UnitActionsTable[MAX_UNITS_BUILDINGS] = { [PEASANT] = ((1 << ACTION_BUILD) | (1 << ACTION_ATTACK)),
|
||||
[BARRACKS] = (1 << ACTION_CREATE_UNIT) };
|
||||
static const char* const UnitActionsTable_Level[MAX_ACTIONS] = { [ACTION_BUILD_BARRACKS] = "B.BARR",
|
||||
[ACTION_ATTACK] = "ATTACK",
|
||||
[ACTION_CREATE_PEASANT] = "C.PEAS."};
|
||||
|
||||
static uint8_t const UnitActionsTable[MAX_UNITS_BUILDINGS] = { [PEASANT] = ((1 << ACTION_BUILD_BARRACKS) | (1 << ACTION_ATTACK)),
|
||||
[BARRACKS] = (1 << ACTION_CREATE_PEASANT),
|
||||
[TOWN_CENTER] = (1 << ACTION_CREATE_PEASANT) };
|
||||
|
||||
// **************
|
||||
// Sprite tables
|
||||
// **************
|
||||
static TYPE_SPRITE UnitSprTable[MAX_UNITS_BUILDINGS];
|
||||
static TYPE_SPRITE UnitWalkingShadowSprTable[MAX_UNITS_BUILDINGS];
|
||||
static const struct t_coordinates UnitShadowOffsetTable[MAX_BUILDING_ID - FIRST_BUILDING_ID] = { [BARRACKS - FIRST_BUILDING_ID] = {.x = -6, .y = 0} };
|
||||
static const struct t_coordinates UnitShadowOffsetTable[MAX_BUILDING_ID - FIRST_BUILDING_ID] = { [BARRACKS - FIRST_BUILDING_ID] = {.x = -6, .y = 0},
|
||||
[TOWN_CENTER - FIRST_BUILDING_ID] = {.x = -3, .y = 0} };
|
||||
|
||||
void UnitInit(void)
|
||||
{
|
||||
enum
|
||||
{
|
||||
BARRACKS_SHADOW_OFFSET_X = -8,
|
||||
BARRACKS_SHADOW_OFFSET_Y = 0
|
||||
};
|
||||
|
||||
UnitSprTable[PEASANT].Data = Peasant_SprData;
|
||||
UnitSprTable[PEASANT].Data = Peasant_SprData;
|
||||
UnitSprTable[PEASANT].w = GfxGetWidthFromSpriteData(Peasant_SprData);
|
||||
UnitSprTable[PEASANT].h = GfxGetHeightFromSpriteData(Peasant_SprData);
|
||||
UnitSprTable[PEASANT].flip = 0;
|
||||
|
@ -77,18 +77,32 @@ void UnitInit(void)
|
|||
UnitSprTable[BARRACKS].rotation = 0;
|
||||
UnitSprTable[BARRACKS].color = GFX_BLACK;
|
||||
|
||||
UnitSprTable[TOWN_CENTER].Data = TownCentreSprData;
|
||||
UnitSprTable[TOWN_CENTER].w = GfxGetWidthFromSpriteData(TownCentreSprData);
|
||||
UnitSprTable[TOWN_CENTER].h = GfxGetHeightFromSpriteData(TownCentreSprData);
|
||||
UnitSprTable[TOWN_CENTER].flip = 0;
|
||||
UnitSprTable[TOWN_CENTER].rotation = 0;
|
||||
UnitSprTable[TOWN_CENTER].color = GFX_BLACK;
|
||||
|
||||
UnitWalkingShadowSprTable[BARRACKS].Data = BarracksShadowSpr_Data;
|
||||
UnitWalkingShadowSprTable[BARRACKS].w = GfxGetWidthFromSpriteData(BarracksShadowSpr_Data);
|
||||
UnitWalkingShadowSprTable[BARRACKS].h = GfxGetHeightFromSpriteData(BarracksShadowSpr_Data);
|
||||
UnitWalkingShadowSprTable[BARRACKS].flip = 0;
|
||||
UnitWalkingShadowSprTable[BARRACKS].rotation = 0;
|
||||
UnitWalkingShadowSprTable[BARRACKS].color = GFX_GRAY;
|
||||
|
||||
UnitWalkingShadowSprTable[TOWN_CENTER].Data = TownCentreShadowSprData;
|
||||
UnitWalkingShadowSprTable[TOWN_CENTER].w = GfxGetWidthFromSpriteData(TownCentreShadowSprData);
|
||||
UnitWalkingShadowSprTable[TOWN_CENTER].h = GfxGetHeightFromSpriteData(TownCentreShadowSprData);
|
||||
UnitWalkingShadowSprTable[TOWN_CENTER].flip = 0;
|
||||
UnitWalkingShadowSprTable[TOWN_CENTER].rotation = 0;
|
||||
UnitWalkingShadowSprTable[TOWN_CENTER].color = GFX_GRAY;
|
||||
}
|
||||
|
||||
void UnitDraw(TYPE_UNIT* ptrUnit, TYPE_CAMERA* ptrCamera, bool bHighlighted)
|
||||
{
|
||||
uint8_t id = ptrUnit->id;
|
||||
TYPE_SPRITE * ptrSpr;
|
||||
TYPE_SPRITE* ptrSpr;
|
||||
|
||||
if (ptrUnit->alive == false)
|
||||
{
|
||||
|
@ -156,10 +170,6 @@ void UnitDraw(TYPE_UNIT* ptrUnit, TYPE_CAMERA* ptrCamera, bool bHighlighted)
|
|||
ptrSpr->flip |= GFX_FLIPV;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Invalid direction
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -244,7 +254,7 @@ void UnitHandler(TYPE_UNIT* unitArray, size_t sz)
|
|||
}
|
||||
|
||||
|
||||
bool bMoving = false;
|
||||
bool bMoving = true;
|
||||
|
||||
if (ptrUnit->walking == true)
|
||||
{
|
||||
|
@ -256,14 +266,12 @@ void UnitHandler(TYPE_UNIT* unitArray, size_t sz)
|
|||
ptrUnit->dir = DIRECTION_LEFT;
|
||||
x_d = -UnitSpeedTable[ptrUnit->id];
|
||||
//~ ptrUnit->x -= UnitSpeedTable[ptrUnit->id];
|
||||
bMoving = true;
|
||||
}
|
||||
else if ( (ptrUnit->x + UnitSpeedTable[ptrUnit->id]) < ptrUnit->target_x)
|
||||
{
|
||||
ptrUnit->dir = DIRECTION_RIGHT;
|
||||
x_d = UnitSpeedTable[ptrUnit->id];
|
||||
//~ ptrUnit->x += UnitSpeedTable[ptrUnit->id];
|
||||
bMoving = true;
|
||||
}
|
||||
|
||||
if ( (ptrUnit->y - UnitSpeedTable[ptrUnit->id]) > ptrUnit->target_y)
|
||||
|
@ -271,14 +279,18 @@ void UnitHandler(TYPE_UNIT* unitArray, size_t sz)
|
|||
ptrUnit->dir = DIRECTION_UP;
|
||||
y_d = -UnitSpeedTable[ptrUnit->id];
|
||||
//~ ptrUnit->y -= UnitSpeedTable[ptrUnit->id];
|
||||
bMoving = true;
|
||||
}
|
||||
else if ( (ptrUnit->y + UnitSpeedTable[ptrUnit->id]) < ptrUnit->target_y)
|
||||
{
|
||||
ptrUnit->dir = DIRECTION_DOWN;
|
||||
y_d = UnitSpeedTable[ptrUnit->id];
|
||||
//~ ptrUnit->y += UnitSpeedTable[ptrUnit->id];
|
||||
bMoving = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
x_d = ptrUnit->x - ptrUnit->target_x;
|
||||
y_d = ptrUnit->y - ptrUnit->target_y;
|
||||
bMoving = false;
|
||||
}
|
||||
|
||||
ptrUnit->walking = bMoving;
|
||||
|
@ -298,7 +310,7 @@ void UnitHandler(TYPE_UNIT* unitArray, size_t sz)
|
|||
.w = UnitGetWidthFromID(ptrUnit->id),
|
||||
.h = UnitGetHeightFromID(ptrUnit->id) };
|
||||
TYPE_COLLISION_BLOCK ou;
|
||||
|
||||
|
||||
if (ptrOtherUnit->alive == false)
|
||||
{
|
||||
continue;
|
||||
|
@ -315,7 +327,7 @@ void UnitHandler(TYPE_UNIT* unitArray, size_t sz)
|
|||
ou.y = ptrOtherUnit->x;
|
||||
ou.w = UnitGetWidthFromID(ptrOtherUnit->id);
|
||||
ou.h = UnitGetHeightFromID(ptrOtherUnit->id);
|
||||
|
||||
|
||||
if (SystemCollisionCheck(cu, ou) == true)
|
||||
{
|
||||
ptrUnit->walking = false;
|
||||
|
@ -323,7 +335,7 @@ void UnitHandler(TYPE_UNIT* unitArray, size_t sz)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (ptrUnit->walking == true)
|
||||
{
|
||||
// If no collision is detected, keep moving to the new position
|
||||
|
|
5
Unit.h
5
Unit.h
|
@ -58,6 +58,7 @@ typedef enum t_unitid
|
|||
// Buildings
|
||||
BARRACKS,
|
||||
TOWER,
|
||||
TOWN_CENTER,
|
||||
|
||||
MAX_BUILDING_ID,
|
||||
|
||||
|
@ -75,9 +76,9 @@ typedef struct
|
|||
|
||||
typedef enum t_availableactions
|
||||
{
|
||||
ACTION_BUILD,
|
||||
ACTION_BUILD_BARRACKS,
|
||||
ACTION_ATTACK,
|
||||
ACTION_CREATE_UNIT,
|
||||
ACTION_CREATE_PEASANT,
|
||||
MAX_ACTIONS
|
||||
}UNIT_ACTION;
|
||||
|
||||
|
|
Loading…
Reference in New Issue