Slick Forums

Discuss the Slick 2D Library
It is currently Sun May 19, 2013 2:23 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Sep 09, 2009 1:56 pm 
Offline

Joined: Wed May 07, 2008 2:52 pm
Posts: 5
Hi,

I was just trying out UnicodeFont and added effects from org.newdawn.slick.font.effects, when I ran into the problem that effects wouldn't show up. Turns out contructors of OutlineZigzagEffect and OutlineWobbleEffect, that take width and colour as parameters, do not set the appropriate stroke. They just call super(), which in turn uses a default BasicStroke. Setting any values has no effect. Constructors without parameters set the stroke correctly.

For example this works:
Code:
            OutlineZigzagEffect zigzag = new OutlineZigzagEffect();
            zigzag.setWidth(3);
            zigzag.setColor(Color.ORANGE);
            List values = new ArrayList();
            values.add(EffectUtil.floatValue("Wavelength", 10, 1, 100, ""));
            values.add(EffectUtil.floatValue("Amplitude", 3, 0.5f, 500, ""));
            zigzag.setValues(values);


This doesn't:
Code:
            OutlineZigzagEffect zigzag = new OutlineZigzagEffect(3, Color.ORANGE);
            List values = new ArrayList();
            values.add(EffectUtil.floatValue("Wavelength", 10, 1, 100, ""));
            values.add(EffectUtil.floatValue("Amplitude", 3, 0.5f, 500, ""));
            zigzag.setValues(values);


Should be easily fixable by adding e.g. setStroke(new WobbleStroke()); to the constructor with parameters.

Great font drawing classes by the way :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 09, 2009 9:43 pm 
Offline
Game Developer
User avatar

Joined: Sun May 25, 2008 9:45 am
Posts: 578
Good find! Patch below.

Did you know you can use the Hiero app to define your fonts?
http://slick.cokeandcode.com/demos/hiero.jnlp
Then you can save a .hiero file for use with UnicodeFont, or a .fnt and .png file for use with AngelCodeFont.

If you do want to set it up programmatically, I added the missing bean property methods, so you don't have to call setValues (which is typically just for the Hiero UI).

Code:
Index: src/org/newdawn/slick/font/effects/OutlineWobbleEffect.java
===================================================================
--- src/org/newdawn/slick/font/effects/OutlineWobbleEffect.java   (revision 1244)
+++ src/org/newdawn/slick/font/effects/OutlineWobbleEffect.java   (working copy)
@@ -51,6 +51,7 @@
    */
   public OutlineWobbleEffect (int width, Color color) {
      super(width, color);
+      setStroke(new WobbleStroke());
   }

   /**
@@ -61,6 +62,34 @@
   }

   /**
+    * Gets the detail of the wobble effect.
+    */   
+   public float getDetail () {
+      return detail;
+   }
+
+   /**
+    * Sets the detail of the wobble effect.
+    */   
+   public void setDetail (float detail) {
+      this.detail = detail;
+   }
+
+   /**
+    * Gets the amplitude of the wobble effect.
+    */   
+   public float getAmplitude () {
+      return amplitude;
+   }
+
+   /**
+    * Sets the amplitude of the wobble effect.
+    */   
+   public void setAmplitude (float amplitude) {
+      this.amplitude = amplitude;
+   }
+
+   /**
    * @see org.newdawn.slick.font.effects.OutlineEffect#getValues()
    */
   public List getValues() {
@@ -88,7 +117,7 @@
   }

   /**
-    * A stroke that generate a wobbly line
+    * A stroke that generates a wobbly line.
    *
    * @author Jerry Huxtable
    * @author Nathan Sweet <misc@n4te.com>
Index: src/org/newdawn/slick/font/effects/OutlineZigzagEffect.java
===================================================================
--- src/org/newdawn/slick/font/effects/OutlineZigzagEffect.java   (revision 1244)
+++ src/org/newdawn/slick/font/effects/OutlineZigzagEffect.java   (working copy)
@@ -61,6 +61,34 @@
   }

   /**
+    * Gets the amplitude of the zigzag.
+    */
+   public float getAmplitude () {
+      return amplitude;
+   }
+
+   /**
+    * Sets the amplitude of the zigzag.
+    */
+   public void setAmplitude (float amplitude) {
+      this.amplitude = amplitude;
+   }
+
+   /**
+    * Gets the wavelength of the zigzag.
+    */
+   public float getWavelength () {
+      return wavelength;
+   }
+
+   /**
+    * Sets the wavelength of the zigzag.
+    */
+   public void setWavelength (float wavelength) {
+      this.wavelength = wavelength;
+   }
+
+   /**
    * @see org.newdawn.slick.font.effects.OutlineEffect#getValues()
    */
   public List getValues() {

_________________
SingSong Karaoke - http://singthegame.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 11, 2009 9:24 am 
Offline

Joined: Wed May 07, 2008 2:52 pm
Posts: 5
Thanks, the getters and setters are helpful.

NateS wrote:
Did you know you can use the Hiero app to define your fonts?
http://slick.cokeandcode.com/demos/hiero.jnlp
Then you can save a .hiero file for use with UnicodeFont, or a .fnt and .png file for use with AngelCodeFont.


I tried that before but it didn't quite work for me. The AngelCodeFont class cannot load multi-page fonts as far as I can tell. One page only per font didn't look too good with bigger fonts; and I didn't want to make individual textures too big. That was just a test, though. So I might not really need it. However I prefer the flexibility of UnicodeFont.

Loading Hiero settings files directly didn't work without writing a ResourceLocation to use my own resource loader as Slick wouldn't find the .hiero file in my classpath. Mine uses ResourceFactoryClass.class.getResource* instead of ResourceFactoryClass.class.getClassLoader().getResource*. Programmatically creating Hiero effects was my lazy way out for some tests :)

Edit: by the way, OutlineZigZagEffect also needs a "setStroke(new ZigzagStroke());" in the constructor with parameters.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 15, 2009 8:02 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Commited. Thanks.

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group