gdx-studio
git clone https://git.pyrossh.dev/gdx-studio
An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop
src_libs/com/badlogic/gdx/tools/hiero/unicodefont/effects/OutlineEffect.java
| a62d533 | 1 | /******************************************************************************* |
| a62d533 | 2 | * Copyright 2011 See AUTHORS file. |
| a62d533 | 3 | * |
| a62d533 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| a62d533 | 5 | * you may not use this file except in compliance with the License. |
| a62d533 | 6 | * You may obtain a copy of the License at |
| a62d533 | 7 | * |
| a62d533 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| a62d533 | 9 | * |
| a62d533 | 10 | * Unless required by applicable law or agreed to in writing, software |
| a62d533 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| a62d533 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| a62d533 | 13 | * See the License for the specific language governing permissions and |
| a62d533 | 14 | * limitations under the License. |
| a62d533 | 15 | ******************************************************************************/ |
| a62d533 | 16 | |
| a62d533 | 17 | package com.badlogic.gdx.tools.hiero.unicodefont.effects; |
| a62d533 | 18 | |
| a62d533 | 19 | import java.awt.BasicStroke; |
| a62d533 | 20 | import java.awt.Color; |
| a62d533 | 21 | import java.awt.Graphics2D; |
| a62d533 | 22 | import java.awt.Stroke; |
| a62d533 | 23 | import java.awt.image.BufferedImage; |
| a62d533 | 24 | import java.util.ArrayList; |
| a62d533 | 25 | import java.util.Iterator; |
| a62d533 | 26 | import java.util.List; |
| a62d533 | 27 | |
| a62d533 | 28 | import com.badlogic.gdx.tools.hiero.unicodefont.Glyph; |
| a62d533 | 29 | import com.badlogic.gdx.tools.hiero.unicodefont.UnicodeFont; |
| a62d533 | 30 | |
| a62d533 | 31 | /** Strokes glyphs with an outline. |
| a62d533 | 32 | * @author Nathan Sweet */ |
| a62d533 | 33 | public class OutlineEffect implements ConfigurableEffect {
|
| a62d533 | 34 | private float width = 2; |
| a62d533 | 35 | private Color color = Color.black; |
| a62d533 | 36 | private int join = BasicStroke.JOIN_BEVEL; |
| a62d533 | 37 | private Stroke stroke; |
| a62d533 | 38 | |
| a62d533 | 39 | public OutlineEffect () {
|
| a62d533 | 40 | } |
| a62d533 | 41 | |
| a62d533 | 42 | public OutlineEffect (int width, Color color) {
|
| a62d533 | 43 | this.width = width; |
| a62d533 | 44 | this.color = color; |
| a62d533 | 45 | } |
| a62d533 | 46 | |
| a62d533 | 47 | public void draw (BufferedImage image, Graphics2D g, UnicodeFont unicodeFont, Glyph glyph) {
|
| a62d533 | 48 | g = (Graphics2D)g.create(); |
| a62d533 | 49 | if (stroke != null) |
| a62d533 | 50 | g.setStroke(stroke); |
| a62d533 | 51 | else |
| a62d533 | 52 | g.setStroke(getStroke()); |
| a62d533 | 53 | g.setColor(color); |
| a62d533 | 54 | g.draw(glyph.getShape()); |
| a62d533 | 55 | g.dispose(); |
| a62d533 | 56 | } |
| a62d533 | 57 | |
| a62d533 | 58 | public float getWidth () {
|
| a62d533 | 59 | return width; |
| a62d533 | 60 | } |
| a62d533 | 61 | |
| a62d533 | 62 | /** Sets the width of the outline. The glyphs will need padding so the outline doesn't get clipped. */ |
| a62d533 | 63 | public void setWidth (int width) {
|
| a62d533 | 64 | this.width = width; |
| a62d533 | 65 | } |
| a62d533 | 66 | |
| a62d533 | 67 | public Color getColor () {
|
| a62d533 | 68 | return color; |
| a62d533 | 69 | } |
| a62d533 | 70 | |
| a62d533 | 71 | public void setColor (Color color) {
|
| a62d533 | 72 | this.color = color; |
| a62d533 | 73 | } |
| a62d533 | 74 | |
| a62d533 | 75 | public int getJoin () {
|
| a62d533 | 76 | return join; |
| a62d533 | 77 | } |
| a62d533 | 78 | |
| a62d533 | 79 | public Stroke getStroke () {
|
| a62d533 | 80 | if (stroke == null) return new BasicStroke(width, BasicStroke.CAP_SQUARE, join); |
| a62d533 | 81 | return stroke; |
| a62d533 | 82 | } |
| a62d533 | 83 | |
| a62d533 | 84 | /** Sets the stroke to use for the outline. If this is set, the other outline settings are ignored. */ |
| a62d533 | 85 | public void setStroke (Stroke stroke) {
|
| a62d533 | 86 | this.stroke = stroke; |
| a62d533 | 87 | } |
| a62d533 | 88 | |
| a62d533 | 89 | /** Sets how the corners of the outline are drawn. This is usually only noticeable at large outline widths. |
| a62d533 | 90 | * @param join One of: {@link BasicStroke#JOIN_BEVEL}, {@link BasicStroke#JOIN_MITER}, {@link BasicStroke#JOIN_ROUND} */
|
| a62d533 | 91 | public void setJoin (int join) {
|
| a62d533 | 92 | this.join = join; |
| a62d533 | 93 | } |
| a62d533 | 94 | |
| a62d533 | 95 | public String toString () {
|
| a62d533 | 96 | return "Outline"; |
| a62d533 | 97 | } |
| a62d533 | 98 | |
| a62d533 | 99 | public List getValues () {
|
| a62d533 | 100 | List values = new ArrayList(); |
| a62d533 | 101 | values.add(EffectUtil.colorValue("Color", color));
|
| a62d533 | 102 | values.add(EffectUtil.floatValue("Width", width, 0.1f, 999, "This setting controls the width of the outline. "
|
| a62d533 | 103 | + "The glyphs will need padding so the outline doesn't get clipped.")); |
| a62d533 | 104 | values.add(EffectUtil.optionValue("Join", String.valueOf(join), new String[][] { {"Bevel", BasicStroke.JOIN_BEVEL + ""},
|
| a62d533 | 105 | {"Miter", BasicStroke.JOIN_MITER + ""}, {"Round", BasicStroke.JOIN_ROUND + ""}},
|
| a62d533 | 106 | "This setting defines how the corners of the outline are drawn. " |
| a62d533 | 107 | + "This is usually only noticeable at large outline widths.")); |
| a62d533 | 108 | return values; |
| a62d533 | 109 | } |
| a62d533 | 110 | |
| a62d533 | 111 | public void setValues (List values) {
|
| a62d533 | 112 | for (Iterator iter = values.iterator(); iter.hasNext();) {
|
| a62d533 | 113 | Value value = (Value)iter.next(); |
| a62d533 | 114 | if (value.getName().equals("Color")) {
|
| a62d533 | 115 | color = (Color)value.getObject(); |
| a62d533 | 116 | } else if (value.getName().equals("Width")) {
|
| a62d533 | 117 | width = ((Float)value.getObject()).floatValue(); |
| a62d533 | 118 | } else if (value.getName().equals("Join")) {
|
| a62d533 | 119 | join = Integer.parseInt((String)value.getObject()); |
| a62d533 | 120 | } |
| a62d533 | 121 | } |
| a62d533 | 122 | } |
| a62d533 | 123 | } |