Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed LibGDX deps for 1.95.1

  • Loading branch information...
commit 24a9d2110116275bcdaa3d0a789e7c79ad3138f4 1 parent 19d24eb
@tommyettinger tommyettinger authored
Showing with 1,665 additions and 1,797 deletions.
  1. +62 −31 pom.xml
  2. +120 −0 pom.xml.releaseBackup
  3. +21 −0 release.properties
  4. +27 −0 src/main/java/squidpony/annotation/Beta.java
  5. +8 −0 src/main/java/squidpony/package.html
  6. +17 −39 src/main/java/squidpony/squidcolor/SColor.java
  7. +271 −0 src/main/java/squidpony/squidcolor/SColorChooserPanel.java
  8. +111 −22 src/main/java/squidpony/squidcolor/SColorFactory.java
  9. +1 −1  src/main/java/squidpony/squidgrid/fov/BasicRadiusStrategy.java
  10. +15 −19 src/main/java/squidpony/squidgrid/fov/BresenhamLOS.java
  11. +90 −0 src/main/java/squidpony/squidgrid/fov/EliasFOV.java
  12. +90 −0 src/main/java/squidpony/squidgrid/fov/EliasLOS.java
  13. +1 −1  src/main/java/squidpony/squidgrid/fov/FOVSolver.java
  14. +1 −1  src/main/java/squidpony/squidgrid/fov/LOSSolver.java
  15. +3 −1 src/main/java/squidpony/squidgrid/fov/MergedFOV.java
  16. +1 −1  src/main/java/squidpony/squidgrid/fov/RadiusStrategy.java
  17. +10 −8 src/main/java/squidpony/squidgrid/fov/RayCastingFOV.java
  18. +2 −0  src/main/java/squidpony/squidgrid/fov/RayCastingLOS.java
  19. +47 −27 src/main/java/squidpony/squidgrid/fov/RippleFOV.java
  20. +7 −7 src/main/java/squidpony/squidgrid/fov/ShadowFOV.java
  21. +4 −1 src/main/java/squidpony/squidgrid/fov/SpreadFOV.java
  22. +3 −0  src/main/java/squidpony/squidgrid/fov/ThreadedFOVSolver.java
  23. +126 −0 src/main/java/squidpony/squidgrid/fov/TranslucenceWrapperFOV.java
  24. +8 −1 src/main/java/squidpony/squidgrid/gui/SGPane.java
  25. +2 −2 src/main/java/squidpony/squidgrid/gui/awt/ImageCellMap.java
  26. +46 −142 src/main/java/squidpony/squidgrid/gui/awt/TextCellFactory.java
  27. +1 −1  src/main/java/squidpony/squidgrid/gui/awt/event/SGKeyListener.java
  28. +1 −1  src/main/java/squidpony/squidgrid/gui/awt/event/SGMouseListener.java
  29. +0 −49 src/main/java/squidpony/squidgrid/gui/libgdx/PixmapFactory.java
  30. +0 −286 src/main/java/squidpony/squidgrid/gui/libgdx/SGPanelGDX.java
  31. +1 −3 src/main/java/squidpony/squidgrid/gui/swing/JRotation.java
  32. +1 −1  src/main/java/squidpony/squidgrid/gui/swing/SwingPane.java
  33. +0 −1,032 src/main/java/squidpony/squidgrid/gui/swing/SwingPaneBeanInfo.java
  34. +22 −19 src/main/java/squidpony/squidgrid/gui/swing/animation/Animation.java
  35. +1 −1  src/main/java/squidpony/squidgrid/gui/swing/animation/AnimationManager.java
  36. +11 −9 src/main/java/squidpony/squidgrid/gui/swing/animation/BumpAnimation.java
  37. +2 −3 src/main/java/squidpony/squidgrid/gui/swing/animation/SlideAnimation.java
  38. +5 −4 src/main/java/squidpony/squidgrid/gui/swing/animation/WiggleAnimation.java
  39. +90 −1 src/main/java/squidpony/squidgrid/util/Direction.java
  40. +71 −77 src/main/java/squidpony/squidmath/Bresenham.java
  41. +179 −0 src/main/java/squidpony/squidmath/Elias.java
  42. +1 −1  src/main/java/squidpony/squidmath/Point3D.java
  43. +179 −1 src/main/java/squidpony/squidmath/RNG.java
  44. +5 −3 src/main/java/squidpony/squidutility/Pair.java
  45. +1 −1  src/main/java/squidpony/squidutility/SCollections.java
View
93 pom.xml
@@ -3,7 +3,7 @@
<groupId>com.squidpony</groupId>
<artifactId>squidlib</artifactId>
- <version>1.95</version>
+ <version>1.95.1</version>
<packaging>jar</packaging>
<parent>
@@ -57,12 +57,6 @@
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
<encoding>UTF-8</encoding>
</properties>
- <repositories>
- <repository>
- <id>gdx-nightlies</id>
- <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
- </repository>
- </repositories>
<build>
<plugins>
<plugin>
@@ -75,20 +69,6 @@
</configuration>
</plugin>
- <plugin>
- <groupId>com.googlecode.mavennatives</groupId>
- <artifactId>maven-nativedependencies-plugin</artifactId>
- <version>0.0.7</version>
- <executions>
- <execution>
- <id>unpacknatives</id>
- <goals>
- <goal>copy</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
@@ -103,18 +83,69 @@
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>2.1.2</version>
+ <executions>
+ <execution>
+ <id>package-jars</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ <goal>test-jar</goal>
+ </goals>
+ <configuration>
+ <includePom>true</includePom>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <includePom>true</includePom>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>2.8</version>
+ <inherited>true</inherited>
+ <executions>
+ <execution>
+ <id>package-jars</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ <goal>test-jar</goal>
+ </goals>
+ <configuration>
+ <includePom>true</includePom>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <debug>true</debug>
+ <minmemory>128m</minmemory>
+ <maxmemory>1024m</maxmemory>
+ <quiet>true</quiet>
+ <doctitle>${project.name} ${project.version}</doctitle>
+ <windowtitle>${project.name} ${project.version}</windowtitle>
+ <testDoctitle>${project.name} ${project.version} (TEST API)</testDoctitle>
+ <testWindowtitle>${project.name} ${project.version} (TEST API)</testWindowtitle>
+ <splitindex>true</splitindex>
+ <encoding>${project.build.sourceEncoding}</encoding>
+ <links>
+ <link>http://java.sun.com/j2se/1.6.0/docs/api</link>
+ <link>http://java.sun.com/j2se/1.5.0/docs/api</link>
+ <link>http://java.sun.com/j2se/1.4.2/docs/api</link>
+ <link>http://java.sun.com/j2ee/1.4/docs/api</link>
+ </links>
+ <linksource>true</linksource>
+ <detectOfflineLinks>false</detectOfflineLinks>
+ </configuration>
+ </plugin>
+
</plugins>
</build>
<dependencies>
- <dependency>
- <groupId>com.badlogicgames.gdx</groupId>
- <artifactId>gdx</artifactId>
- <version>0.9.9-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>com.badlogicgames.gdx</groupId>
- <artifactId>gdx-backend-lwjgl</artifactId>
- <version>0.9.9-SNAPSHOT</version>
- </dependency>
</dependencies>
</project>
View
120 pom.xml.releaseBackup
@@ -0,0 +1,120 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.squidpony</groupId>
+ <artifactId>squidlib</artifactId>
+ <version>1.95-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>org.sonatype.oss</groupId>
+ <artifactId>oss-parent</artifactId>
+ <version>7</version>
+ </parent>
+
+ <name>SquidLib</name>
+ <description>Please refer to https://github.com/SquidPony/SquidLib .</description>
+
+ <url>https://github.com/SquidPony/SquidLib</url>
+
+ <developers>
+ <developer>
+ <name>Eben Howard ( https://github.com/SquidPony )</name>
+ <email>example@example.com</email>
+ </developer>
+ </developers>
+
+ <licenses>
+ <license>
+ <name>Apache Public License</name>
+ <url>
+ https://www.apache.org/licenses/LICENSE-2.0.html
+ </url>
+ <comments>LICENSE.txt</comments>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+
+ <inceptionYear>2012</inceptionYear>
+
+ <prerequisites>
+ <maven>3.0.3</maven>
+ </prerequisites>
+
+ <issueManagement>
+ <url>https://github.com/SquidPony/SquidLib/issues</url>
+ <system>GitHub Issues</system>
+ </issueManagement>
+
+ <scm>
+ <connection>scm:git:git@github.com:tommyettinger/SquidLib.git</connection>
+ <developerConnection>scm:git:git@github.com:tommyettinger/SquidLib.git</developerConnection>
+ <url>git@github.com:tommyettinger/SquidLib.git</url>
+ </scm>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
+ <encoding>UTF-8</encoding>
+ </properties>
+ <repositories>
+ <repository>
+ <id>gdx-nightlies</id>
+ <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
+ </repository>
+ </repositories>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.0</version>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>com.googlecode.mavennatives</groupId>
+ <artifactId>maven-nativedependencies-plugin</artifactId>
+ <version>0.0.7</version>
+ <executions>
+ <execution>
+ <id>unpacknatives</id>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-gpg-plugin</artifactId>
+ <version>1.4</version>
+ <executions>
+ <execution>
+ <id>sign-artifacts</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>sign</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>com.badlogicgames.gdx</groupId>
+ <artifactId>gdx</artifactId>
+ <version>0.9.9-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.badlogicgames.gdx</groupId>
+ <artifactId>gdx-backend-lwjgl</artifactId>
+ <version>0.9.9-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
View
21 release.properties
@@ -0,0 +1,21 @@
+#release configuration
+#Fri Jul 26 03:48:22 PDT 2013
+scm.commentPrefix=[maven-release-plugin]
+pushChanges=true
+dependency.dependency.com.badlogicgames.gdx\:gdx.development=0.9.9-SNAPSHOT
+project.scm.com.squidpony\:squidlib.tag=HEAD
+dependency.dependency.com.badlogicgames.gdx\:gdx.release=0.9.9-SNAPSHOT
+scm.tag=squidlib-1.95
+project.dev.com.squidpony\:squidlib=1.96-SNAPSHOT
+remoteTagging=true
+exec.additionalArguments=-Psonatype-oss-release
+project.scm.com.squidpony\:squidlib.developerConnection=scm\:git\:git@github.com\:tommyettinger/SquidLib.git
+project.scm.com.squidpony\:squidlib.url=git@github.com\:tommyettinger/SquidLib.git
+scm.url=scm\:git\:git@github.com\:tommyettinger/SquidLib.git
+preparationGoals=clean verify
+dependency.dependency.com.badlogicgames.gdx\:gdx-backend-lwjgl.development=0.9.9-SNAPSHOT
+scm.username=tommyettinger
+project.rel.com.squidpony\:squidlib=1.95
+dependency.dependency.com.badlogicgames.gdx\:gdx-backend-lwjgl.release=0.9.9-SNAPSHOT
+project.scm.com.squidpony\:squidlib.connection=scm\:git\:git@github.com\:tommyettinger/SquidLib.git
+completedPhase=run-preparation-goals
View
27 src/main/java/squidpony/annotation/Beta.java
@@ -0,0 +1,27 @@
+package squidpony.annotation;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Signifies that a public API (public class, method or field) is subject to
+ * incompatible changes, or even removal, in a future release. An API bearing
+ * this annotation is exempt from any compatibility guarantees made by its
+ * containing library.
+ *
+ * @author Kevin Bourrillion
+ */
+@Retention(RetentionPolicy.CLASS)
+@Target({
+ ElementType.ANNOTATION_TYPE,
+ ElementType.CONSTRUCTOR,
+ ElementType.FIELD,
+ ElementType.METHOD,
+ ElementType.TYPE})
+@Documented
+@Beta
+public @interface Beta {
+}
View
8 src/main/java/squidpony/package.html
@@ -0,0 +1,8 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+ <body bgcolor="white">
+ <p>
+ This is the base package for all components of the SquidLib Library.
+ </p>
+ </body>
+</html>
View
56 src/main/java/squidpony/squidcolor/SColor.java
@@ -1,6 +1,7 @@
package squidpony.squidcolor;
import java.awt.Color;
+import java.util.Objects;
/**
* Allows for the use of custom colors with custom names.
@@ -8,12 +9,11 @@
* These colors are comparable for equality but the ordering of them is based on
* their hex values.
*
- * Has some built in pallets available as SColor arrays.
+ * Has some built in palettes available as SColor arrays.
*
- * @author Eben Howard - http://squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
-public class SColor extends Color implements Comparable {
-
+public class SColor extends Color {
private String name = "Unnamed";
/**
* Color constant<PRE><font style="background-color: #f0f8ff;" color=000000>&nbsp&nbsp&nbsp</font><font style="background-color: #000000;" color=000000>&nbsp&nbsp&nbsp</font><font style="background-color: #888888;" color=000000>&nbsp&nbsp&nbsp</font><font style="background-color: #ffffff;" color=000000>&nbsp&nbsp&nbsp</font><font style="background-color: #f0f8ff;" color=000000>&nbsp@&nbsp</font>
@@ -5416,41 +5416,6 @@ public SColor(int r, int g, int b, String name) {
this.name = name;
}
- /**
- * Compares the current color to another color. Comparison is not guaranteed
- * to lead to a logical color ordering that may be expected.
- *
- * @param color new color to compare with current color
- * @return indicator of comparison between colors
- */
- public int compareTo(SColor color) {
- int compare = 0;//default to being equal
- if (getRGB() < color.getRGB()) {
- compare = -1;
- } else if (getRGB() > color.getRGB()) {
- compare = 1;
- }
- return compare;
- }
-
- /**
- * Compares the current color to another object of any type. If the second
- * object is not a SColor object than an exception will be thrown.
- *
- * @throws UnsupportedOperationException if second object not a SColor
- * object
- * @param arg0 second object to be compared to
- * @return indicator of comparison between colors
- */
- @Override
- public int compareTo(Object arg0) {
- try {
- return compareTo((SColor) arg0);
- } catch (Exception e) {
- throw new UnsupportedOperationException("Incorrect Object Type");
- }
- }
-
@Override
public String toString() {
return name + " " + super.toString();
@@ -5459,4 +5424,17 @@ public String toString() {
public String getName() {
return name;
}
+
+ @Override
+ public boolean equals(Object other) {
+ return other instanceof SColor || other instanceof Color ? this.getRGB() == ((Color) other).getRGB() : false;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 31 * hash + Objects.hashCode(this.name);
+ hash += 31 * hash + Objects.hashCode(this.getRGB());
+ return hash;
+ }
}
View
271 src/main/java/squidpony/squidcolor/SColorChooserPanel.java
@@ -0,0 +1,271 @@
+package squidpony.squidcolor;
+
+import java.awt.AWTException;
+import java.awt.BorderLayout;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.event.MouseEvent;
+import java.util.TreeMap;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.Icon;
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+import javax.swing.Scrollable;
+import javax.swing.SwingConstants;
+import javax.swing.colorchooser.AbstractColorChooserPanel;
+import javax.swing.event.MouseInputListener;
+
+/**
+ * This class provides a way to interact with the pre-defined SColor constants
+ * in a Swing GUI.
+ *
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
+ */
+public class SColorChooserPanel extends AbstractColorChooserPanel {
+
+ private SColor[] colors = SColor.FULL_PALLET;
+ private TreeMap<String, SColor[]> colorMap = new TreeMap<>();
+ private int colorHeight = 20;
+ private int colorWidth = 40;
+ private ColorPanel displayPanel = new ColorPanel();
+ private JScrollPane scrollPane = new JScrollPane();
+ private JComboBox colorComboBox = new JComboBox();
+ private JTextField colorName = new JTextField();
+
+ @Override
+ public void updateChooser() {
+ }
+
+ @Override
+ protected void buildChooser() {
+
+ scrollPane.setViewportView(displayPanel);
+ displayPanel.addMouseListener(displayPanel);
+ displayPanel.addMouseMotionListener(displayPanel);
+ colorComboBox.addActionListener(new java.awt.event.ActionListener() {
+ @Override
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ colorComboBoxActionPerformed(evt);
+ }
+ });
+
+ colorMap.put("Achromatic Series", SColor.ACHROMATIC_SERIES);
+ colorMap.put("Blue Green Series", SColor.BLUE_GREEN_SERIES);
+ colorMap.put("Blue Violet Series", SColor.BLUE_VIOLET_SERIES);
+ colorMap.put("Full Pallet", SColor.FULL_PALLET);
+ colorMap.put("Rainbow", SColor.RAINBOW);
+ colorMap.put("Red Series", SColor.RED_SERIES);
+ colorMap.put("Red Violet Series", SColor.RED_VIOLET_SERIES);
+ colorMap.put("Violet Series", SColor.VIOLET_SERIES);
+ colorMap.put("Yellow Green Series", SColor.YELLOW_GREEN_SERIES);
+ colorMap.put("Yellow Red Series", SColor.YELLOW_RED_SERIES);
+ colorMap.put("Yellow Series", SColor.YELLOW_SERIES);
+
+ colorComboBox.setModel(new DefaultComboBoxModel(colorMap.keySet().toArray()));
+ setLayout(new BorderLayout());
+ add(colorComboBox, BorderLayout.NORTH);
+ add(scrollPane, BorderLayout.CENTER);
+ colorName.setEditable(false);
+ colorName.setHorizontalAlignment(JTextField.CENTER);
+ add(colorName, BorderLayout.SOUTH);
+ }
+
+ private void refreshPanel() {
+ scrollPane.getViewport().setViewSize(displayPanel.getPreferredScrollableViewportSize());
+ scrollPane.getViewport().revalidate();
+ repaint();
+ }
+
+ private void colorComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
+ colors = colorMap.get((String) colorComboBox.getSelectedItem());
+ refreshPanel();
+ }
+
+ private void displayPanelMouseMoved(java.awt.event.MouseEvent evt) {
+ int index = evt.getY() / 20;
+ if (index < colors.length) {
+ String text = "";
+ switch (evt.getX() / colorWidth) {
+ case 0:
+ text += "Fully Desaturated ";
+ break;
+ case 1:
+ text += "80% Desaturated ";
+ break;
+ case 2:
+ text += "Lightest ";
+ break;
+ case 3:
+ text += "Lighter ";
+ break;
+ case 4:
+ text += "Light ";
+ break;
+ case 6:
+ text += "Dim ";
+ break;
+ case 7:
+ text += "Dimmer ";
+ break;
+ case 8:
+ text += "Dimmest ";
+ break;
+ }
+ text += colors[index].getName();
+// displayPanel.setToolTipText(text);//don't need the tooltip with the display area
+ colorName.setText(text);
+ }
+ }
+
+ @Override
+ public String getDisplayName() {
+ return "SColor";
+ }
+
+ @Override
+ public Icon getSmallDisplayIcon() {
+ return null;
+ }
+
+ @Override
+ public Icon getLargeDisplayIcon() {
+ return null;
+ }
+
+ private class ColorPanel extends JPanel implements Scrollable, MouseInputListener {
+
+ ColorPanel() {
+ super(new FlowLayout());
+ }
+
+ @Override
+ public Dimension getPreferredSize() {
+ return new Dimension(colorWidth * 9, colorHeight * colors.length);
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ int x = 0;
+ int y = 0;
+
+ g.setColor(SColor.WHITE);
+ g.fillRect(0, 0, getWidth(), colorHeight);
+
+ for (int i = 0; i < colors.length; i++) {
+ SColor color = colors[i];
+
+ g.setColor(SColorFactory.desaturated(color));
+ g.fillRect(x, y, colorWidth, colorHeight);
+ x += colorWidth;
+
+ g.setColor(SColorFactory.desaturate(color, 0.8));
+ g.fillRect(x, y, colorWidth, colorHeight);
+ x += colorWidth;
+
+ g.setColor(SColorFactory.lightest(color));
+ g.fillRect(x, y, colorWidth, colorHeight);
+ x += colorWidth;
+
+ g.setColor(SColorFactory.lighter(color));
+ g.fillRect(x, y, colorWidth, colorHeight);
+ x += colorWidth;
+
+
+ g.setColor(SColorFactory.light(color));
+ g.fillRect(x, y, colorWidth, colorHeight);
+ x += colorWidth;
+
+ g.setColor(color);
+ g.fillRect(x, y, colorWidth, colorHeight);
+ x += colorWidth;
+
+ g.setColor(SColorFactory.dim(color));
+ g.fillRect(x, y, colorWidth, colorHeight);
+ x += colorWidth;
+
+ g.setColor(SColorFactory.dimmer(color));
+ g.fillRect(x, y, colorWidth, colorHeight);
+ x += colorWidth;
+
+ g.setColor(SColorFactory.dimmest(color));
+ g.fillRect(x, y, getWidth() - x, colorHeight);//last column fills out the rest of the space
+
+ x = 0;
+ y += colorHeight;
+ }
+ }
+
+ @Override
+ public Dimension getPreferredScrollableViewportSize() {
+ return new Dimension(colorWidth * 9, Math.min(400, colorHeight * colors.length));
+ }
+
+ @Override
+ public int getScrollableUnitIncrement(Rectangle rctngl, int i, int i1) {
+ if (i == SwingConstants.VERTICAL) {
+ return colorHeight;
+ } else {
+ return colorWidth;
+ }
+ }
+
+ @Override
+ public int getScrollableBlockIncrement(Rectangle rctngl, int i, int i1) {
+ if (i == SwingConstants.VERTICAL) {
+ return colorHeight * 5;
+ } else {
+ return colorWidth * 3;
+ }
+ }
+
+ @Override
+ public boolean getScrollableTracksViewportWidth() {
+ return false;
+ }
+
+ @Override
+ public boolean getScrollableTracksViewportHeight() {
+ return false;
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ try {
+ Robot robot = new Robot();
+ getColorSelectionModel().setSelectedColor(robot.getPixelColor(e.getXOnScreen(), e.getYOnScreen()));
+ } catch (AWTException ex) {
+ }
+ }
+
+ @Override
+ public void mousePressed(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseEntered(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseExited(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ displayPanelMouseMoved(e);
+ }
+ }
+}
View
133 src/main/java/squidpony/squidcolor/SColorFactory.java
@@ -1,9 +1,17 @@
package squidpony.squidcolor;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
+import java.util.TreeMap;
+import javax.swing.JColorChooser;
+import javax.swing.JDialog;
+import javax.swing.colorchooser.AbstractColorChooserPanel;
import squidpony.squidmath.Bresenham;
import squidpony.squidmath.Point3D;
import squidpony.squidmath.RNG;
@@ -15,14 +23,16 @@
* All returned SColor objects are cached so multiple requests for the same
* SColor will not create duplicate long term objects.
*
- * @author Eben Howard - http://squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public class SColorFactory {
+ private static final TreeMap<String, SColor> nameLookup = new TreeMap<>();
+ private static final TreeMap<Integer, SColor> valueLookup = new TreeMap<>();
private static RNG rng = new RNG();
private static Map<Integer, SColor> colorBag = new HashMap<>();
private static Map<String, ArrayList<SColor>> pallets = new HashMap<>();
- private static int flooring = 1;//what multiple to floor rgb values to in order to reduce total colors
+ private static int floor = 1;//what multiple to floor rgb values to in order to reduce total colors
/**
* Prevents any instances from being created.
@@ -31,11 +41,52 @@ private SColorFactory() {
}
/**
+ * Returns the SColor Constant who's name is the one provided. If one cannot
+ * be found then null is returned.
+ *
+ * This method constructs a list of the SColor constants the first time it
+ * is called.
+ *
+ * @param s
+ * @return
+ */
+ public static SColor colorForName(String s) {
+ if (nameLookup.isEmpty()) {
+ for (SColor sc : SColor.FULL_PALLET) {
+ nameLookup.put(sc.getName(), sc);
+ }
+ }
+
+ return nameLookup.get(s);
+ }
+
+ /**
+ * Returns the SColor who's value matches the one passed in. If no SColor
+ * Constant matches that value then a cached or new SColor is returned that
+ * matches the provided value.
+ *
+ * This method constructs a list of the SColor constants the first time it
+ * is called.
+ *
+ * @param rgb
+ * @return
+ */
+ public static SColor colorForValue(int rgb) {
+ if (valueLookup.isEmpty()) {
+ for (SColor sc : SColor.FULL_PALLET) {
+ valueLookup.put(sc.getRGB(), sc);
+ }
+ }
+
+ return valueLookup.containsKey(rgb) ? valueLookup.get(rgb) : asSColor(rgb);
+ }
+
+ /**
* Returns the number of SColor objects currently cached.
*
* @return
*/
- public static int getQuantityCached() {
+ public static int quantityCached() {
return colorBag.size();
}
@@ -64,7 +115,7 @@ private static int blend(int a, int b, double coef) {
* @return
*/
public static SColor blend(SColor color1, SColor color2, double coef) {
- return getSColor(blend(color1.getRed(), color2.getRed(), coef),
+ return asSColor(blend(color1.getRed(), color2.getRed(), coef),
blend(color1.getGreen(), color2.getGreen(), coef),
blend(color1.getBlue(), color2.getBlue(), coef));
}
@@ -107,8 +158,8 @@ public static void emptyCache() {
*
* @param value
*/
- public static void setRGBFloorValue(int value) {
- flooring = Math.max(1, value);
+ public static void setFloor(int value) {
+ floor = Math.max(1, value);
}
/**
@@ -117,25 +168,29 @@ public static void setRGBFloorValue(int value) {
* If the color is not already in the cache, it is created and added to the
* cache.
*
+ * This method does not check to see if the value is already available as a
+ * SColor constant. If such functionality is desired then please use
+ * colorForValue(int rgb) instead.
+ *
* @param rgb
* @return
*/
- public static SColor getSColor(int rgb) {
- if (flooring != 1) {//need to convert to floored values
+ public static SColor asSColor(int rgb) {
+ if (floor != 1) {//need to convert to floored values
int a = (rgb >> 24) & 0xff;
- a -= a % flooring;
+ a -= a % floor;
int r = (rgb >> 16) & 0xff;
- r -= r % flooring;
+ r -= r % floor;
int g = (rgb >> 8) & 0xff;
- g -= g % flooring;
- int b = (rgb >> 0) & 0xff;
- b -= b % flooring;
+ g -= g % floor;
+ int b = rgb & 0xff;
+ b -= b % floor;
//put back together
rgb = ((a & 0xFF) << 24)
| ((r & 0xFF) << 16)
| ((g & 0xFF) << 8)
- | ((b & 0xFF) << 0);
+ | (b & 0xFF);
}
if (colorBag.containsKey(rgb)) {
@@ -156,14 +211,26 @@ public static SColor getSColor(int rgb) {
* @param b
* @return
*/
- public static SColor getSColor(int r, int g, int b) {
+ public static SColor asSColor(int r, int g, int b) {
r = Math.min(r, 255);
r = Math.max(r, 0);
g = Math.min(g, 255);
g = Math.max(g, 0);
b = Math.min(b, 255);
b = Math.max(b, 0);
- return getSColor(r * 256 * 256 + g * 256 + b);
+ return asSColor(r * 256 * 256 + g * 256 + b);
+ }
+
+ /**
+ * Returns an SColor representation of the provided Color. If there is a
+ * named SColor constant that matches the value, then that constant is
+ * returned.
+ *
+ * @param color
+ * @return
+ */
+ public static SColor asSColor(Color color) {
+ return colorForValue(color.getRGB());
}
/**
@@ -243,7 +310,7 @@ public static SColor desaturated(SColor color) {
int b = color.getBlue();
int average = (int) (r * 0.299 + g * 0.587 + b * 0.114);
- return getSColor(average, average, average);
+ return asSColor(average, average, average);
}
/**
@@ -267,7 +334,7 @@ public static SColor desaturate(SColor color, double percent) {
* @param color2
* @return
*/
- public static ArrayList<SColor> getGradient(SColor color1, SColor color2) {
+ public static ArrayList<SColor> asGradient(SColor color1, SColor color2) {
String name = palletNamer(color1, color2);
if (pallets.containsKey(name)) {
return pallets.get(name);
@@ -291,7 +358,7 @@ public static SColor desaturate(SColor color, double percent) {
* @param name
* @return
*/
- public static ArrayList<SColor> getPallet(String name) {
+ public static ArrayList<SColor> pallet(String name) {
return pallets.get(name);
}
@@ -307,7 +374,7 @@ public static SColor desaturate(SColor color, double percent) {
* @param percent
* @return
*/
- public static SColor getFromPallet(String name, float percent) {
+ public static SColor fromPallet(String name, float percent) {
ArrayList<SColor> list = pallets.get(name);
if (list == null) {
return null;
@@ -320,6 +387,28 @@ public static SColor getFromPallet(String name, float percent) {
}
/**
+ * Returns an SColor chosen from a pop-up JColorChooser dialog.
+ *
+ * @param parent The component which is the parent of this dialog
+ * @return
+ */
+ public static SColor showSColorChooser(Component parent) {
+ final JColorChooser chooser = new JColorChooser();
+ chooser.setChooserPanels(new AbstractColorChooserPanel[]{new SColorChooserPanel()});
+
+ JDialog dialog = JColorChooser.createDialog(parent, "Choose A Color", true, chooser, new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ pickedColor = asSColor(chooser.getColor().getRGB());
+ }
+ }, null);
+ dialog.setLocationRelativeTo(parent);
+ dialog.setVisible(true);
+
+ return pickedColor;
+ }
+ private static SColor pickedColor;//needed for the color chooser
+
+ /**
* Places the pallet into the cache, along with each of the member colors.
*
* @param name
@@ -330,7 +419,7 @@ public static void addPallet(String name, ArrayList<SColor> pallet) {
//make sure all the colors in the pallet are also in the general color cache
for (SColor sc : pallet) {
- temp.add(getSColor(sc.getRGB()));
+ temp.add(asSColor(sc.getRGB()));
}
pallets.put(name, temp);
@@ -355,7 +444,7 @@ private static Point3D scolorToCoord3D(SColor color) {
* @return
*/
private static SColor coord3DToSColor(Point3D coord) {
- return getSColor(coord.x, coord.y, coord.z);
+ return asSColor(coord.x, coord.y, coord.z);
}
private static String palletNamer(SColor color1, SColor color2) {
View
2  src/main/java/squidpony/squidgrid/fov/BasicRadiusStrategy.java
@@ -3,7 +3,7 @@
/**
* Basic radius strategy implementations.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public enum BasicRadiusStrategy implements RadiusStrategy {
View
34 src/main/java/squidpony/squidgrid/fov/BresenhamLOS.java
@@ -4,47 +4,43 @@
import java.util.LinkedList;
import java.util.Queue;
import squidpony.squidmath.Bresenham;
-import squidpony.squidmath.Point3D;
/**
* A Bresenham-based line-of-sight algorithm.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public class BresenhamLOS implements LOSSolver {
- Queue<Point3D> lastPath = new LinkedList<>();
+ Queue<Point> lastPath = new LinkedList<>();
@Override
- public boolean isReachable(float[][] map, int x, int y, int targetX, int targetY, float force, float decay, RadiusStrategy radiusStrategy) {
- Queue<Point3D> path = Bresenham.line2D(x, y, targetX, targetY);
+ public boolean isReachable(float[][] resistanceMap, int startx, int starty, int targetx, int targety, float force, float decay, RadiusStrategy radiusStrategy) {
+ Queue<Point> path = Bresenham.line2D(startx, starty, targetx, targety);
lastPath = new LinkedList<>(path);//save path for later retreival
- path.poll();//remove starting point
- for (Point3D p : path) {
- if (p.x == targetX && p.y == targetY) {
+ float currentForce = force;
+ for (Point p : path) {
+ if (p.x == targetx && p.y == targety) {
return true;//reached the end
}
- force -= map[p.x][p.y];
- double radius = radiusStrategy.radius(x, y, p.x, p.y);
- if (force - (radius * decay) <= 0) {
+ if (p.x != startx || p.y != starty) {//don't discount the start location even if on resistant cell
+ currentForce *= (1 - resistanceMap[p.x][p.y]);
+ }
+ double radius = radiusStrategy.radius(startx, starty, p.x, p.y);
+ if (currentForce - (radius * decay) <= 0) {
return false;//too much resistance
}
}
- return true;//made it all the way to the target
+ return false;//never got to the target point
}
@Override
public Queue<Point> getLastPath() {
- //copy the Point3D elements into a 2D Point structure only if needed
- Queue<Point> returnPath = new LinkedList<>();
- for (Point3D p : lastPath) {
- returnPath.add(new Point(p.x, p.y));
- }
- return returnPath;
+ return lastPath;
}
@Override
public boolean isReachable(float[][] resistanceMap, int startx, int starty, int targetx, int targety) {
- return isReachable(resistanceMap, startx, starty, targety, targety, Float.MAX_VALUE, 0f, BasicRadiusStrategy.CIRCLE);
+ return isReachable(resistanceMap, startx, starty, targetx, targety, Float.MAX_VALUE, 0f, BasicRadiusStrategy.CIRCLE);
}
}
View
90 src/main/java/squidpony/squidgrid/fov/EliasFOV.java
@@ -0,0 +1,90 @@
+package squidpony.squidgrid.fov;
+
+import squidpony.annotation.Beta;
+import squidpony.squidmath.Elias;
+
+/**
+ * Uses the Elias line running to raycast.
+ *
+ * Does not currently support translucency.
+ *
+ * For information on the sideview parameter, see the EliasLOS documentation.
+ *
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
+ */
+@Beta
+public class EliasFOV implements FOVSolver {
+
+ private float[][] lightMap, resistanceMap;
+ private float maxRadius, force, decay;
+ private int width, height;
+ private RadiusStrategy rStrat;
+ private float sideview = 0.75f;
+
+ /**
+ * Creates a solver which will use the default sideview on the internal
+ * EliasLOS solver.
+ */
+ public EliasFOV() {
+ }
+
+ /**
+ * Creates a solver which will use the provided sideview value on the
+ * internal EliasLOS solver.
+ *
+ * @param sideview
+ */
+ public EliasFOV(float sideview) {
+ this.sideview = sideview;
+ }
+
+ @Override
+ public float[][] calculateFOV(float[][] resistanceMap, int startx, int starty, float force, float decay, RadiusStrategy radiusStrategy) {
+ this.resistanceMap = resistanceMap;
+ width = resistanceMap.length;
+ height = resistanceMap[0].length;
+ lightMap = new float[width][height];
+ this.force = force;
+ this.decay = decay;
+ rStrat = radiusStrategy;
+
+ maxRadius = force / decay;
+ int left = (int) Math.max(0, startx - maxRadius - 1);
+ int right = (int) Math.min(width - 1, startx + maxRadius + 1);
+ int top = (int) Math.max(0, starty - maxRadius - 1);
+ int bottom = (int) Math.min(height - 1, starty + maxRadius + 1);
+
+
+ //run rays out to edges
+ for (int x = left; x <= right; x++) {
+ runLineGroup(startx, starty, x, top);
+ runLineGroup(startx, starty, x, bottom);
+ }
+ for (int y = top; y <= bottom; y++) {
+ runLineGroup(startx, starty, left, y);
+ runLineGroup(startx, starty, right, y);
+ }
+
+ return lightMap;
+ }
+
+ private void runLineGroup(int startx, int starty, int endx, int endy) {
+ float[][] tempMap = Elias.lightMap(startx, starty, endx, endy);
+ EliasLOS los = new EliasLOS(sideview);
+// boolean xpositive = endx > startx;
+// boolean ypositive = endy > starty;
+ for (int x = Math.min(startx, endx); x <= Math.max(startx, endx); x++) {
+ for (int y = Math.min(starty, endy); y <= Math.max(starty, endy); y++) {
+ float radius = rStrat.radius(startx, starty, x, y);
+ if (radius < maxRadius && los.isReachable(resistanceMap, startx, starty, x, y)) {
+ lightMap[x][y] = Math.max(lightMap[x][y], tempMap[x][y] * (force - radius * decay));
+ }
+ }
+ }
+ }
+
+ @Override
+ public float[][] calculateFOV(float[][] resistanceMap, int startx, int starty, float radius) {
+ return calculateFOV(resistanceMap, startx, starty, 1, 1 / radius, BasicRadiusStrategy.CIRCLE);
+ }
+}
View
90 src/main/java/squidpony/squidgrid/fov/EliasLOS.java
@@ -0,0 +1,90 @@
+package squidpony.squidgrid.fov;
+
+import java.awt.Point;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import squidpony.annotation.Beta;
+import squidpony.squidmath.Elias;
+
+/**
+ * Uses Wu's Algorithm as modified by Elias to draw the line.
+ *
+ * The side view parameter is how far along the antialiased path to consider
+ * when determining if the far end can be seen, from 0.0 to 1.0 with 1.0
+ * considering the entire line. The closer to 1.0 this value is, the more
+ * complete and symmetrical end-to-end the line is, but the computation cost
+ * also increases.
+ *
+ * If undesired artifacts are seen when running the lines (missing squares
+ * perhaps), try increasing the sideview value.
+ *
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
+ */
+@Beta
+public class EliasLOS implements LOSSolver {
+
+ private Queue<Point> lastPath = new LinkedList<>();
+ private float sideview = 0.75f;
+
+ /**
+ * Creates this solver with the default side view parameter.
+ */
+ public EliasLOS() {
+ }
+
+ /**
+ * Creates this solver with the provided value for how far along the
+ * antialiased line the antialiased portion will be considered.
+ *
+ * @param sideview
+ */
+ public EliasLOS(float sideview) {
+ this.sideview = sideview;
+ }
+
+ public float getSideview() {
+ return sideview;
+ }
+
+ public void setSideview(float sideview) {
+ this.sideview = sideview;
+ }
+
+ @Override
+ public boolean isReachable(float[][] resistanceMap, int startx, int starty, int targetx, int targety, float force, float decay, RadiusStrategy radiusStrategy) {
+ List<Point> path = Elias.line(startx, starty, targetx, targety);
+ lastPath = new LinkedList<>(path);//save path for later retreival
+
+ BresenhamLOS los1 = new BresenhamLOS(),
+ los2 = new BresenhamLOS();
+
+ float checkRadius = radiusStrategy.radius(startx, starty) * 0.75f;
+ while (!path.isEmpty()) {
+ Point p = path.remove(0);
+
+ //if a non-solid midpoint on the path can see both the start and end, consider the two ends to be able to see each other
+ if (resistanceMap[p.x][p.y] < 1
+ && radiusStrategy.radius(startx, starty, p.x, p.y) < checkRadius
+ && los1.isReachable(resistanceMap, p.x, p.y, targetx, targety, force - (radiusStrategy.radius(startx, starty, p.x, p.y) * decay), decay, radiusStrategy)
+ && los2.isReachable(resistanceMap, startx, starty, p.x, p.y, force, decay, radiusStrategy)) {
+
+ //record actual sight path used
+ lastPath = new LinkedList<>(los1.lastPath);
+ lastPath.addAll(los2.lastPath);
+ return true;
+ }
+ }
+ return false;//never got to the target point
+ }
+
+ @Override
+ public boolean isReachable(float[][] resistanceMap, int startx, int starty, int targetx, int targety) {
+ return isReachable(resistanceMap, startx, starty, targetx, targety, Float.MAX_VALUE, 0f, BasicRadiusStrategy.CIRCLE);
+ }
+
+ @Override
+ public Queue<Point> getLastPath() {
+ return lastPath;
+ }
+}
View
2  src/main/java/squidpony/squidgrid/fov/FOVSolver.java
@@ -22,7 +22,7 @@
* are not opaque. Check the documentation for the individual solvers for more
* details.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public interface FOVSolver {
View
2  src/main/java/squidpony/squidgrid/fov/LOSSolver.java
@@ -14,7 +14,7 @@
* calculation of force, decay, and resistances prevent the line from reaching
* the target.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public interface LOSSolver {
View
4 src/main/java/squidpony/squidgrid/fov/MergedFOV.java
@@ -1,13 +1,15 @@
package squidpony.squidgrid.fov;
+import squidpony.annotation.Beta;
+
/**
* This class merges the results from two or more FOVSolvers.
*
* Currently a work in progress.
*
* @author Eben Howard - http://squidpony.com - howard@squidpony.com
- * @deprecated
*/
+@Beta
public class MergedFOV implements FOVSolver {
private float totalWeight;
View
2  src/main/java/squidpony/squidgrid/fov/RadiusStrategy.java
@@ -4,7 +4,7 @@
* Indicates which method of dealing with the radius during FOV and LOS solving
* is preferred.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public interface RadiusStrategy {
View
18 src/main/java/squidpony/squidgrid/fov/RayCastingFOV.java
@@ -1,5 +1,7 @@
package squidpony.squidgrid.fov;
+import squidpony.annotation.Beta;
+
/**
* Simple raytracing algorithm for Field of View. In large areas will be
* relatively inefficient due to repeated visiting of some cells.
@@ -17,9 +19,9 @@
*
* Currently a work in progress.
*
- * @deprecated
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
+@Beta
public class RayCastingFOV implements FOVSolver {
private float gap = 0.4f;//how much gap to leave from the edges when tracing rays
@@ -48,15 +50,15 @@ public RayCastingFOV() {
}
@Override
- public float[][] calculateFOV(float[][] map, int startx, int starty, float force, float decay, RadiusStrategy radiusStrategy) {
- this.map = map;
+ public float[][] calculateFOV(float[][] resistanceMap, int startx, int starty, float force, float decay, RadiusStrategy radiusStrategy) {
+ this.map = resistanceMap;
this.force = force;
this.decay = decay;
this.fx = startx + 0.5f;
this.fy = starty + 0.5f;
this.rStrat = radiusStrategy;
- width = map.length;
- height = map[0].length;
+ width = resistanceMap.length;
+ height = resistanceMap[0].length;
lightMap = new float[width][height];
float maxRadius = force / decay + 1;
@@ -142,7 +144,7 @@ private void runLine(float x, float y, double angle, float currentLight) {
}
@Override
- public float[][] calculateFOV(float[][] map, int startx, int starty, float radius) {
- return calculateFOV(map, startx, starty, 1, 1 / radius, BasicRadiusStrategy.CIRCLE);
+ public float[][] calculateFOV(float[][] resistanceMap, int startx, int starty, float radius) {
+ return calculateFOV(resistanceMap, startx, starty, 1, 1 / radius, BasicRadiusStrategy.CIRCLE);
}
}
View
2  src/main/java/squidpony/squidgrid/fov/RayCastingLOS.java
@@ -3,6 +3,7 @@
import java.awt.Point;
import java.util.LinkedList;
import java.util.Queue;
+import squidpony.annotation.Beta;
/**
* Uses a series of rays internal to the start and end point to determine
@@ -10,6 +11,7 @@
*
* @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
+@Beta
public class RayCastingLOS implements LOSSolver {
Queue<Point> path;
View
74 src/main/java/squidpony/squidgrid/fov/RippleFOV.java
@@ -1,17 +1,21 @@
package squidpony.squidgrid.fov;
+import squidpony.annotation.Beta;
+
/**
* Performs FOV by pushing values outwards from the source location. It will
* only go around corners slightly.
*
* This algorithm does perform bounds checking.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
+@Beta
public class RippleFOV implements FOVSolver {
private float[][] lightMap;
private float[][] map;
+ private boolean[][] indirect;//marks when a tile is only indirectly lit
private float radius, decay;
private int startx, starty, width = 1, height = 1;
private RadiusStrategy rStrat;
@@ -27,6 +31,14 @@ public RippleFOV() {
* @return
*/
private float getNearLight(int x, int y) {
+ if (Math.abs(startx - x) <= 1 && Math.abs(starty - y) <= 1) {//if next to start cell, get full light
+ return lightMap[startx][starty];
+ }
+
+ if (indirect[x][y]) {
+ return 0f;//no light if this one was only indirectly lit
+ }
+
int x2 = x - (int) Math.signum(x - startx);
int y2 = y - (int) Math.signum(y - starty);
@@ -48,9 +60,8 @@ private float getNearLight(int x, int y) {
//find largest emmitted light in direction of source
float light = 0f;
- int close = rStrat.radius(startx, starty, x, y) <= 1 ? 0 : 1; //if next to start cell, don't apply start cell's resistance
- if (map[x2][y2] < 1f && lightMap[x2][y2] > 0) {
- light = Math.max(light, lightMap[x2][y2] * (1 - close * map[x2][y2]));
+ if (!indirect[x2][y2] && map[x2][y2] < 1f && lightMap[x2][y2] > 0) {
+ light = Math.max(light, lightMap[x2][y2] * (1 - map[x2][y2]));
mainLit = true;
}
@@ -58,43 +69,47 @@ private float getNearLight(int x, int y) {
if (x2 == x) {//add one left and right
int dx1 = Math.max(0, x - 1);
int dx2 = Math.min(width - 1, x + 1);
- int dy = y2;
- if (map[dx2][dy] < 1f && lightMap[dx2][dy] > 0) {
- light = Math.max(light, lightMap[dx2][dy] * (1 - close * map[dx2][dy]));
+ int dy = y + (int) Math.signum(y - starty);//move one step further away from the source
+ dy = Math.max(dy, 0);
+ dy = Math.min(dy, height - 1);
+ if (!indirect[dx2][dy] && map[dx2][dy] < 1f && lightMap[dx2][dy] > 0) {
+ light = Math.max(light, lightMap[dx2][dy] * (1 - map[dx2][dy]));
sideALit = true;
}
- if (map[dx1][dy] < 1f && lightMap[dx1][dy] > 0) {
- light = Math.max(light, lightMap[dx1][dy] * (1 - close * map[dx1][dy]));
+ if (!indirect[dx1][dy] && map[dx1][dy] < 1f && lightMap[dx1][dy] > 0) {
+ light = Math.max(light, lightMap[dx1][dy] * (1 - map[dx1][dy]));
sideBLit = true;
}
} else if (y2 == y) {//add one up and one down
int dy1 = Math.max(0, y - 1);
int dy2 = Math.min(height - 1, y + 1);
- int dx = x2;
- if (map[dx][dy1] < 1f && lightMap[dx][dy1] > 0) {
- light = Math.max(light, lightMap[dx][dy1] * (1 - close * map[dx][dy1]));
+ int dx = x + (int) Math.signum(x - startx);//move one step further away from the source
+ dx = Math.max(dx, 0);
+ dx = Math.min(dx, width - 1);
+ if (!indirect[dx][dy1] && map[dx][dy1] < 1f && lightMap[dx][dy1] > 0) {
+ light = Math.max(light, lightMap[dx][dy1] * (1 - map[dx][dy1]));
sideALit = true;
}
- if (map[dx][dy2] < 1f && lightMap[dx][dy2] > 0) {
- light = Math.max(light, lightMap[dx][dy2] * (1 - close * map[dx][dy2]));
+ if (!indirect[dx][dy2] && map[dx][dy2] < 1f && lightMap[dx][dy2] > 0) {
+ light = Math.max(light, lightMap[dx][dy2] * (1 - map[dx][dy2]));
sideBLit = true;
}
} else {
- if (xDominance > 0 && map[x2][y] < 1f && lightMap[x2][y] > 0) {
+ if (!indirect[x2][y] && xDominance > 0 && map[x2][y] < 1f && lightMap[x2][y] > 0) {
float tempLight = lightMap[x2][y];
if (tempLight > 0) {
- light = Math.max(light, tempLight * (1 - close * map[x2][y]));
+ light = Math.max(light, tempLight * (1 - map[x2][y]));
sideALit = true;
}
- } else if (xDominance < 0 && map[x][y2] < 1f && lightMap[x][y2] > 0) {
+ } else if (!indirect[x][y2] && xDominance < 0 && map[x][y2] < 1f && lightMap[x][y2] > 0) {
float tempLight = lightMap[x][y2];
if (tempLight > 0) {
- light = Math.max(light, tempLight * (1 - close * map[x][y2]));
+ light = Math.max(light, tempLight * (1 - map[x][y2]));
sideBLit = true;
}
- } else if (xDominance == 0 && (map[x2][y2] < 1f || (map[x][y2] < 1f && map[x2][y] < 1f))) {//on a diagonal
- float tempLight = Math.max(lightMap[x2][y2] * (1 - close * map[x2][y2]),
- Math.max(lightMap[x2][y] * (1 - close * map[x2][y]), lightMap[x][y2] * (1 - close * map[x][y2])));
+ } else if (!indirect[x2][y2] && xDominance == 0 && (map[x2][y2] < 1f || (map[x][y2] < 1f && map[x2][y] < 1f))) {//on a diagonal
+ float tempLight = Math.max(lightMap[x2][y2] * (1 - map[x2][y2]),
+ Math.max(lightMap[x2][y] * (1 - map[x2][y]), lightMap[x][y2] * (1 - map[x][y2])));
if (tempLight > 0) {
light = Math.max(light, tempLight);
mainLit = true;//really it might be that both sides are lit, but that counts the same
@@ -106,12 +121,15 @@ private float getNearLight(int x, int y) {
boolean killLight = true;//broken out into steps for debugging
if (mainLit || (sideALit && sideBLit) || corner) {
killLight = false;
+ if (!mainLit) {
+ indirect[x][y] = true;
+ }
}
- if (killLight) {
+ if (killLight) {//not lit at all counts as indirectly lit
light = 0;
}
- light = light - decay * distance;
+ light -= decay * distance;
return light;
}
@@ -128,10 +146,12 @@ private float getNearLight(int x, int y) {
width = map.length;
height = map[0].length;
lightMap = new float[width][height];
- }else{
- for(int x = 0;x<width;x++){
- for(int y = 0;y<height;y++){
+ indirect = new boolean[width][height];
+ } else {
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
lightMap[x][y] = 0f;//mark as unlit
+ indirect[x][y] = false;
}
}
}
@@ -144,7 +164,7 @@ private float getNearLight(int x, int y) {
}
private void lightSurroundings(int x, int y) {
- if (lightMap[x][y] <= 0) {
+ if (lightMap[x][y] <= 0 || indirect[x][y]) {
return;//no light to spread
}
View
14 src/main/java/squidpony/squidgrid/fov/ShadowFOV.java
@@ -8,7 +8,7 @@
*
* Performs bounds checking so edges are not required to be opaque.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public class ShadowFOV implements FOVSolver {
@@ -19,16 +19,16 @@
private RadiusStrategy rStrat;
@Override
- public float[][] calculateFOV(float[][] map, int startx, int starty, float force, float decay, RadiusStrategy rStrat) {
+ public float[][] calculateFOV(float[][] resistanceMap, int startx, int starty, float force, float decay, RadiusStrategy rStrat) {
this.startx = startx;
this.starty = starty;
this.force = force;
this.decay = decay;
this.rStrat = rStrat;
- this.resistanceMap = map;
+ this.resistanceMap = resistanceMap;
- width = map.length;
- height = map[0].length;
+ width = resistanceMap.length;
+ height = resistanceMap[0].length;
lightMap = new float[width][height];
radius = (force / decay);
@@ -88,7 +88,7 @@ private void castLight(int row, float start, float end, int xx, int xy, int yx,
}
@Override
- public float[][] calculateFOV(float[][] map, int startx, int starty, float radius) {
- return calculateFOV(map, startx, starty, 1, 1 / radius, BasicRadiusStrategy.CIRCLE);
+ public float[][] calculateFOV(float[][] resistanceMap, int startx, int starty, float radius) {
+ return calculateFOV(resistanceMap, startx, starty, 1, 1 / radius, BasicRadiusStrategy.CIRCLE);
}
}
View
5 src/main/java/squidpony/squidgrid/fov/SpreadFOV.java
@@ -1,5 +1,7 @@
package squidpony.squidgrid.fov;
+import squidpony.annotation.Beta;
+
/**
* Performs FOV by pushing values outwards from the source location. It will
* spread around edges like smoke or water. This may not be the desired behavior
@@ -7,8 +9,9 @@
*
* This algorithm does perform bounds checking.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
+@Beta
public class SpreadFOV implements FOVSolver {
private float[][] lightMap;
View
3  src/main/java/squidpony/squidgrid/fov/ThreadedFOVSolver.java
@@ -1,5 +1,7 @@
package squidpony.squidgrid.fov;
+import squidpony.annotation.Beta;
+
/**
* A threaded wrapper for an FOVSolver.
*
@@ -14,6 +16,7 @@
*
* @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
+@Beta
public class ThreadedFOVSolver implements FOVSolver, Runnable {
private FOVSolver solver;
View
126 src/main/java/squidpony/squidgrid/fov/TranslucenceWrapperFOV.java
@@ -0,0 +1,126 @@
+package squidpony.squidgrid.fov;
+
+import static squidpony.squidgrid.fov.TranslucenceWrapperFOV.RayType.*;
+import squidpony.squidgrid.util.Direction;
+
+/**
+ * Acts as a wrapper which fully respects translucency and lights based on
+ * another FOVSolver.
+ *
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
+ */
+public class TranslucenceWrapperFOV implements FOVSolver {
+
+ static enum RayType {
+
+ PRIMARY, SECONDARY, TERTIARY
+ };
+ private FOVSolver fov = new ShadowFOV();
+ private float[][] lightMap, resistanceMap, shadowMap;
+ private int width, height, startx, starty;
+ private RadiusStrategy rStrat;
+ private float decay;
+
+ /**
+ * Uses default ShadowFOV to create lit area mapping
+ */
+ public TranslucenceWrapperFOV() {
+ }
+
+ /**
+ * Uses provided FOVSolver to create lit area mapping
+ *
+ * @param fov
+ */
+ public TranslucenceWrapperFOV(FOVSolver fov) {
+ this.fov = fov;
+ }
+
+ @Override
+ public float[][] calculateFOV(float[][] resistanceMap, int startx, int starty, float force, float decay, RadiusStrategy radiusStrategy) {
+ width = resistanceMap.length;
+ height = resistanceMap[0].length;
+ this.startx = startx;
+ this.starty = starty;
+ this.decay = decay;
+ this.resistanceMap = resistanceMap;
+ this.rStrat = radiusStrategy;
+ lightMap = new float[width][height];
+ shadowMap = fov.calculateFOV(resistanceMap, startx, starty, force, decay, radiusStrategy);
+
+ lightMap[startx][starty] = force;//start out at full force
+ for (Direction dir : Direction.OUTWARDS) {
+ pushLight(startx + dir.deltaX, starty + dir.deltaY, force + decay, dir, dir, PRIMARY);
+ }
+
+ return lightMap;
+ }
+
+ /**
+ * Pushes light outwards based on the light coming into this cell.
+ *
+ * Tertiary light should only light up opaque objects, with more opaque
+ * objects requiring less light to be lit up.
+ *
+ * @param x
+ * @param y
+ * @param light the amount of light coming into this tile
+ * @param tertiary whether the light coming in is tertiary
+ */
+ private void pushLight(int x, int y, float light, Direction dir, Direction previous, RayType type) {
+ if (light <= 0 || x < 0 || x >= width || y < 0 || y >= height || shadowMap[x][y] <= 0 || lightMap[x][y] >= light) {
+ return;//out of light, off the edge, base fov not lit, or already well lit
+ }
+
+ lightMap[x][y] = light;//apply passed in light
+
+ if (type == PRIMARY) {
+ //push primary ray
+ float radius = rStrat.radius(x, y, x + dir.deltaX, y + dir.deltaY);
+ float brightness = light;
+ brightness *= (1 - resistanceMap[x][y]);//light is reduced by the portion of the square passed through
+ brightness -= radius * decay;//reduce by the amount of decay from passing through
+ pushLight(x + dir.deltaX, y + dir.deltaY, brightness, dir, dir, PRIMARY);
+
+ Direction pushing = dir.clockwise();
+ radius = rStrat.radius(x, y, x + pushing.deltaX, y + pushing.deltaY);
+ brightness = light * (1 - resistanceMap[x][y]);//light is reduced by the portion of the square passed through
+ brightness -= radius * decay;//reduce by the amount of decay from passing through
+ pushLight(x + pushing.deltaX, y + pushing.deltaY, brightness, dir, pushing, SECONDARY);
+
+ pushing = dir.counterClockwise();
+ radius = rStrat.radius(x, y, x + pushing.deltaX, y + pushing.deltaY);
+ brightness = light * (1 - resistanceMap[x][y]);//light is reduced by the portion of the square passed through
+ brightness -= radius * decay;//reduce by the amount of decay from passing through
+ pushLight(x + pushing.deltaX, y + pushing.deltaY, brightness, dir, pushing, SECONDARY);
+ } else {//type == SECONDARY at this point
+ //push pass-through secondary ray
+ Direction pushing = previous;//redirect to previous' previous direction
+ float radius = rStrat.radius(x, y, x + pushing.deltaX, y + pushing.deltaY);
+ float brightness = light * (1 - resistanceMap[x][y]);//light is reduced by the portion of the square passed through
+ brightness -= radius * decay;//reduce by the amount of decay from passing through
+ pushLight(x + pushing.deltaX, y + pushing.deltaY, brightness, dir, pushing, SECONDARY);
+
+ //now push through tertiary rays, first just continues in direction passed in
+ radius = rStrat.radius(x, y, x + dir.deltaX, y + dir.deltaY);
+ brightness = light * (1 - resistanceMap[x][y]);//light is reduced by the portion of the square passed through
+ brightness -= radius * decay;//reduce by the amount of decay from passing through
+ pushLight(x + dir.deltaX, y + dir.deltaY, brightness, dir, pushing, SECONDARY);
+ if (previous.clockwise().equals(dir)) {
+ pushing = previous.clockwise();
+ } else {
+ pushing = previous.counterClockwise();
+ }
+
+ radius = rStrat.radius(x, y, x + pushing.deltaX, y + pushing.deltaY);
+ brightness = light * (1 - resistanceMap[x][y]);//light is reduced by the portion of the square passed through
+ brightness -= radius * decay;//reduce by the amount of decay from passing through
+ pushLight(x + pushing.deltaX, y + pushing.deltaY, brightness, dir, pushing, SECONDARY);
+ }
+ }
+
+ @Override
+ public float[][] calculateFOV(float[][] resistanceMap, int startx, int starty, float radius) {
+ return calculateFOV(resistanceMap, startx, starty, 1, 1 / radius, BasicRadiusStrategy.CIRCLE);
+ }
+}
View
9 src/main/java/squidpony/squidgrid/gui/SGPane.java
@@ -2,11 +2,18 @@
import java.awt.Color;
import java.awt.Font;
+import squidpony.annotation.Beta;
/**
+ * A basic interface for working with grids.
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * This interface's Beta status is due to the libGDX version potentially
+ * becoming different enough that this interface is removed in favor of direct
+ * implementation of desired back end panels.
+ *
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
+@Beta
public interface SGPane {
/**
View
4 src/main/java/squidpony/squidgrid/gui/awt/ImageCellMap.java
@@ -11,13 +11,13 @@
/**
* Class for managing tile images. All images must be the same dimensions.
*
- * @author Eben Howard -- http://squidpony.com
+ * @author Eben Howard -- http://squidpony.com - howard@squidpony.com
*/
public class ImageCellMap implements Map {
private BufferedImage nullImage;
int cellWidth, cellHeight;
- TreeMap<String, BufferedImage> blocks = new TreeMap<String, BufferedImage>();
+ TreeMap<String, BufferedImage> blocks = new TreeMap<>();
/**
* A cached image set.
View
188 src/main/java/squidpony/squidgrid/gui/awt/TextCellFactory.java
@@ -1,12 +1,14 @@
package squidpony.squidgrid.gui.awt;
import java.awt.*;
+import java.awt.font.FontRenderContext;
+import java.awt.font.GlyphVector;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.TreeMap;
import squidpony.squidcolor.SColor;
import squidpony.squidgrid.util.Direction;
-import squidpony.squidutility.Pair;
/**
* Class for creating text blocks.
@@ -14,7 +16,7 @@
* The default characters guaranteed to fit are ASCII 33 through 125, which are
* the commonly used symbols, numbers, and letters.
*
- * @author Eben Howard - http://squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public class TextCellFactory implements Cloneable {
@@ -181,8 +183,6 @@ private void sizeCellByFont() {
horizontalOffset = cellWidth / 2;
findSize();
- cullLargeCharacters();
- trimCell();
//restore cell sizes based on padding
leftPadding = tempLeftPadding;
@@ -196,160 +196,64 @@ private void sizeCellByFont() {
}
private void findSize() {
- //size up with square cells, it's okay if we oversize since we'll shrink back down
- int bestw = 1;
- int besth = 1;
- ArrayList<Character> testingList;
- if (!largeCharacters.isEmpty()) {
- testingList = largeCharacters;
-// largeCharacters = new ArrayList<>();//TODO -- determine if there are any cases where changing font size would change which character is the widest or tallest
- } else {
- testingList = new ArrayList<>();
- for (char c : fitting) {
- testingList.add(c);
- }
- }
-
- for (char c : testingList) {//try all requested characters
- int largestw = 1;
- int largesth = 1;
- int smallestw = 1000;
- int smallesth = 1000;
-
- //size up until part of the font is seen or size is maxed out, in second case don't change the width and heights
- float factor = 2f;
- int maxVal = (int) (1000 / factor);
- BufferedImage image = new BufferedImage(cellWidth, cellHeight, BufferedImage.TYPE_BYTE_GRAY);
- boolean visible = visible(c, image);
- while (maxVal > cellWidth && maxVal > cellHeight && !visible) {
- cellWidth *= factor;
- cellHeight *= factor;
- horizontalOffset = cellWidth / 2;
- image = new BufferedImage(cellWidth, cellHeight, BufferedImage.TYPE_BYTE_GRAY);
- visible = visible(c, image);
- }
+ int left = Integer.MAX_VALUE, right = Integer.MIN_VALUE,
+ top = Integer.MAX_VALUE, bottom = Integer.MIN_VALUE;
+ HashMap<Direction, Character> larges = new HashMap<>();
- //certain at this point that the character is a printing character, find size that works
- if (visible) {
- smallestw = Math.min(smallestw, cellWidth);
- smallesth = Math.min(smallesth, cellHeight);
- boolean fits = willFit(c);
-
- //size up until it fits
- while (maxVal > cellWidth && maxVal > cellHeight && !fits) {
- cellWidth *= factor;
- cellHeight *= factor;
- horizontalOffset = cellWidth / 2;
- fits = willFit(c);
- }
- if (fits) {//if it doesn't fit than the requested font is too large
- largestw = Math.max(largestw, cellWidth);
- largesth = Math.max(largesth, cellHeight);
-
- //binary search between smallest and largest to find right size
- do {
- cellWidth = (int) Math.floor((largestw + smallestw) / 2.0);
- cellHeight = (int) Math.floor((largesth + smallesth) / 2.0);//make sure to round up
- horizontalOffset = cellWidth / 2;
-
- fits = willFit(c);
- if (fits) {//enough room, size down
- largestw = cellWidth;
- largesth = cellHeight;
- } else {//not enough room, size up by 1 since we know those sizes didn't work
- smallestw = cellWidth + 1;
- smallesth = cellHeight + 1;
- }
- } while (smallestw < largestw && smallesth < largesth);//if equal need to size up once
-
- cellWidth = smallestw;
- cellHeight = smallesth;
- horizontalOffset = cellWidth / 2;
- bestw = Math.max(bestw, cellWidth);
- besth = Math.max(besth, cellHeight);
-
- if (bestw == cellWidth || besth == cellHeight) {//this character hit an edge and expanded the cell size requirement, log it
- largeCharacters.add(c);
- }
- }
- } else {
- cellWidth = largestw;
- cellHeight = largesth;
- }
- }
-
- cellWidth = bestw;
- cellHeight = besth;
- horizontalOffset = cellWidth / 2;
- }
+ BufferedImage image = new BufferedImage(cellWidth, cellHeight, BufferedImage.TYPE_4BYTE_ABGR);
+ Graphics2D g = image.createGraphics();
+ g.setFont(font);
- private void cullLargeCharacters() {
- if (largeCharacters.isEmpty()) {
- return;
+ g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
+ if (antialias) {
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+ } else {
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
}
- Pair<Integer, Character> left = new Pair(Integer.MAX_VALUE, ' '),
- right = new Pair(Integer.MIN_VALUE, ' '),
- top = new Pair(Integer.MAX_VALUE, ' '),
- bottom = new Pair(Integer.MIN_VALUE, ' ');
- BufferedImage image = new BufferedImage(cellWidth, cellHeight, BufferedImage.TYPE_BYTE_GRAY);
- for (char c : largeCharacters) {
- BufferedImage tile = makeMonoImage(c, image);
-
- leftCheck:
- for (int x = 0; x < Math.min(left.getFirst(), cellWidth); x++) {
- for (int y = 0; y < cellHeight; y++) {
- if (tile.getRGB(x, y) != Color.WHITE.getRGB()) {
- left = new Pair(x, c);//this character is further left than any so far so mark it
- break leftCheck;
- }
+ FontRenderContext context = g.getFontRenderContext();
+
+ for (int i = 0; i < fitting.length; i++) {
+ GlyphVector vect = font.createGlyphVector(context, new char[]{fitting[i]});
+ if (vect.getGlyphCode(0) != font.getMissingGlyphCode()
+ && !Character.isISOControl(fitting[i])
+ && !Character.isWhitespace(fitting[i])
+ && Character.getDirectionality(fitting[i]) == Character.DIRECTIONALITY_LEFT_TO_RIGHT) {
+ Rectangle rect = vect.getGlyphPixelBounds(0, context, 0, 0);
+ if (rect.x < left) {
+ larges.put(Direction.LEFT, fitting[i]);
+ left = rect.x;
}
- }
-
- rightCheck:
- for (int x = cellWidth - 1; x > Math.max(right.getFirst(), -1); x--) {
- for (int y = 0; y < cellHeight; y++) {
- if (tile.getRGB(x, y) != Color.WHITE.getRGB()) {
- right = new Pair(x, c);//this character is further left than any so far so mark it
- break rightCheck;
- }
+ if (rect.y < top) {
+ larges.put(Direction.UP, fitting[i]);
+ top = rect.y;
}
- }
-
- topCheck:
- for (int y = 0; y < Math.min(top.getFirst(), cellHeight); y++) {
- for (int x = 0; x < cellWidth; x++) {
- if (tile.getRGB(x, y) != Color.WHITE.getRGB()) {
- top = new Pair(y, c);//this character is further left than any so far so mark it
- break topCheck;
- }
+ if (rect.x + rect.width > right) {
+ larges.put(Direction.RIGHT, fitting[i]);
+ right = rect.x + rect.width;
}
- }
-
- bottomCheck:
- for (int y = cellHeight - 1; y > Math.max(bottom.getFirst(), -1); y--) {
- for (int x = 0; x < cellWidth; x++) {
- if (tile.getRGB(x, y) != Color.WHITE.getRGB()) {
- bottom = new Pair(y, c);//this character is further left than any so far so mark it
- break bottomCheck;
- }
+ if (rect.y + rect.height > bottom) {
+ larges.put(Direction.DOWN, fitting[i]);
+ bottom = rect.y + rect.height;
}
}
-
}
+ largeCharacters = new ArrayList<>(larges.values());
- largeCharacters = new ArrayList<>();
- largeCharacters.add(left.getSecond());
- largeCharacters.add(right.getSecond());
- largeCharacters.add(top.getSecond());
- largeCharacters.add(bottom.getSecond());
+ cellWidth = right - left;
+ cellWidth *= 2;
+ cellHeight = bottom - top;
+ cellHeight *= 2;
+ horizontalOffset = cellWidth / 2;
+ verticalOffset = 0;
+ trimCell();
}
private void trimCell() {
BufferedImage image = new BufferedImage(cellWidth, cellHeight, BufferedImage.TYPE_BYTE_GRAY);
//find best horizontal offset
- int bestHorizontalOffset = 0;//worst case, already in position
+ int bestHorizontalOffset = Integer.MIN_VALUE;
for (char c : largeCharacters) {
int tempHorizontalOffset = horizontalOffset;
if (visible(c, image)) {//only calculate on printable characters
@@ -363,7 +267,7 @@ private void trimCell() {
horizontalOffset = bestHorizontalOffset;
//find best vertical offset
- int bestVerticalOffset = -cellHeight;//worst case, already in position
+ int bestVerticalOffset = Integer.MIN_VALUE;
for (char c : largeCharacters) {
int tempVerticalOffset = verticalOffset;
while (verticalOffset > -cellHeight && willFit(c)) {
View
2  src/main/java/squidpony/squidgrid/gui/awt/event/SGKeyListener.java
@@ -18,7 +18,7 @@
* regularly checks for user input. If your application is event driven then a
* standard java.awt.even.KeyListener would be more appropriate to use;
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public class SGKeyListener implements KeyListener, Iterable<KeyEvent>, Iterator<KeyEvent> {
View
2  src/main/java/squidpony/squidgrid/gui/awt/event/SGMouseListener.java
@@ -11,7 +11,7 @@
* This class is meant to be used as a wrapper to your own mouse listener, it
* simply converts the coordinates from UI Component x,y to Grid based x,y
*
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
+ * @author Eben Howard - http://squidpony.com - howard@squidpony.com
*/
public class SGMouseListener implements MouseInputListener {
View
49 src/main/java/squidpony/squidgrid/gui/libgdx/PixmapFactory.java
@@ -1,49 +0,0 @@
-package squidpony.squidgrid.gui.libgdx;
-
-import com.badlogic.gdx.graphics.Pixmap;
-import java.awt.image.BufferedImage;
-
-/**
- * Provides methods for converting images to Pixmaps
- *
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
- */
-public class PixmapFactory {
-
- /**
- * Builds and returns a Pixmap based on the input image.
- *
- * @param image
- * @return
- */
- public static Pixmap createPixmap(BufferedImage image) {
- int width = image.getWidth();
- int height = image.getHeight();
- Pixmap pix = new Pixmap(width, height, Pixmap.Format.RGBA8888);
- int[] pixels = image.getRGB(0, 0, width, height, null, 0, width);
-
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- int pixel = pixels[y * width + x];
- pix.drawPixel(x, y, getRGBA(pixel));
- }
- }
-
- return pix;
- }
-
- /**
- * Shifts java.awt.Color ARGB values to gdx RGBA values.
- *
- * @param rgb
- * @return
- */
- public static int getRGBA(int rgb) {
- int a = rgb >> 24;
- a &= 0x000000ff;
- int rest = rgb & 0x00ffffff;//mask out the alpha channel
- rest <<= 8;
- rest |= a;
- return rest;
- }
-}
View
286 src/main/java/squidpony/squidgrid/gui/libgdx/SGPanelGDX.java
@@ -1,286 +0,0 @@
-package squidpony.squidgrid.gui.libgdx;
-
-import com.badlogic.gdx.graphics.Pixmap;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.scenes.scene2d.Group;
-import com.badlogic.gdx.scenes.scene2d.ui.Image;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.image.BufferedImage;
-import java.util.TreeMap;
-import squidpony.squidcolor.SColor;
-import squidpony.squidgrid.gui.SGPane;
-import squidpony.squidgrid.gui.awt.TextCellFactory;
-import sun.reflect.generics.reflectiveObjects.NotImplementedException;
-
-/**
- * A libGDX implementation of SPanel that allows both text and graphics.
- *
- * @author Eben Howard - http://squidpony.com - eben@squidpony.com
- */
-public class SGPanelGDX extends Group implements SGPane {
-
- private TextCellFactory textFactory = new TextCellFactory();
- private TreeMap<String, Pixmap> imageMap = new TreeMap<>();
- private Pixmap backgroundImage, foregroundImage;
- private Image backImage, foreImage;
- private int cellWidth, cellHeight, gridWidth, gridHeight;
- private boolean[][] imageChanged;
- private Font font;
- private Color defaultBackColor = SColor.BLACK;
- private Color defaultForeColor = SColor.WHITE;
-
- @Override
- public int getCellHeight() {
- return cellHeight;
- }
-
- @Override
- public int getCellWidth() {
- return cellWidth;
- }
-
- @Override
- public int getGridHeight() {
- return gridHeight;
- }
-
- @Override
- public int getGridWidth() {
- return gridWidth;
- }
-
- @Override
- public void initialize(int cellWidth, int cellHeight, int gridWidth, int gridHeight, Font font) {
- textFactory.initializeBySize(cellWidth, cellHeight, font);
- this.font = textFactory.getFont();
- doInitialization(gridWidth, gridHeight);
- }
-
- @Override
- public void initialize(int gridWidth, int gridHeight, Font font) {
- textFactory.initializeByFont(font);
- this.font = textFactory.getFont();
- doInitialization(gridWidth, gridHeight);
- }
-
- /**
- * Clears backing arrays and sets fields to proper size for the new grid
-