1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tools.hiero.unicodefont.effects; 18 19 import java.awt.Color; 20 import java.awt.Graphics2D; 21 import java.awt.image.BufferedImage; 22 import java.util.ArrayList; 23 import java.util.Iterator; 24 import java.util.List; 25 26 import com.badlogic.gdx.tools.hiero.unicodefont.Glyph; 27 import com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont; 28 29 /** Makes glyphs a solid color. 30 * @author Nathan Sweet */ 31 public class ColorEffect implements ConfigurableEffect { 32 private Color color = Color.white; 33 34 public ColorEffect () { 35 } 36 37 public ColorEffect (Color color) { 38 this.color = color; 39 } 40 41 public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) { 42 g.setColor(color); 43 try { 44 g.fill(glyph.getShape()); // Java2D fails on some glyph shapes?! 45 } catch (Throwable ignored) { 46 } 47 } 48 49 public Color getColor () { 50 return color; 51 } 52 53 public void setColor (Color color) { 54 if (color == null) throw new IllegalArgumentException("color cannot be null."); 55 this.color = color; 56 } 57 58 public String toString () { 59 return "Color"; 60 } 61 62 public List getValues () { 63 List values = new ArrayList(); 64 values.add(EffectUtil.colorValue("Color", color)); 65 return values; 66 } 67 68 public void setValues (List values) { 69 for (Iterator iter = values.iterator(); iter.hasNext();) { 70 Value value = (Value)iter.next(); 71 if (value.getName().equals("Color")) { 72 setColor((Color)value.getObject()); 73 } 74 } 75 } 76 } 77