From 0b46ea60e3c819371a75fc7717752f4ef25d853c Mon Sep 17 00:00:00 2001 From: Doublestrike Date: Mon, 10 Oct 2011 11:57:39 +0000 Subject: [PATCH] Update to FRoundedPanel: - Can now decide which corners to round. - No settings file required in skin (all removed) --- .gitattributes | 2 - res/images/skins/default/settings.txt | 16 - res/images/skins/rebel/settings.txt | 16 - .../java/forge/gui/skin/FRoundedPanel.java | 277 ++++++++++-------- src/main/java/forge/gui/skin/FSkin.java | 77 +---- 5 files changed, 150 insertions(+), 238 deletions(-) delete mode 100644 res/images/skins/default/settings.txt delete mode 100644 res/images/skins/rebel/settings.txt diff --git a/.gitattributes b/.gitattributes index 54b4fe97f57..035c6c61afa 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9396,7 +9396,6 @@ res/images/skins/default/btnRup.png -text res/images/skins/default/font1.ttf -text res/images/skins/default/font2.ttf -text res/images/skins/default/palette.jpg -text -res/images/skins/default/settings.txt -text res/images/skins/default/texture1.jpg -text res/images/skins/default/texture2.jpg -text res/images/skins/default/texture3.jpg -text @@ -9413,7 +9412,6 @@ res/images/skins/rebel/btnRup.png -text res/images/skins/rebel/font1.ttf -text res/images/skins/rebel/font2.ttf -text res/images/skins/rebel/palette.jpg -text -res/images/skins/rebel/settings.txt -text res/images/skins/rebel/texture1.jpg -text res/images/skins/rebel/texture2.jpg -text res/images/skins/rebel/texture3.jpg -text diff --git a/res/images/skins/default/settings.txt b/res/images/skins/default/settings.txt deleted file mode 100644 index da39ccc2a4f..00000000000 --- a/res/images/skins/default/settings.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Settings are stored in a key=value format. -# Color values are stored as RR,GG,BB[,AA] values 0 to 255 -# Dimension values are stored as x,y -# Incomplete settings will make the file switch to the default theme. - -# Texture opacity settings, 0-100 -texture1opacity=100; -texture2opacity=100; -texture3opacity=100; - -# FRoundedPanel -shadowColor=150,150,150,150 -borderColor=0,0,0 -shadowDistance=5,5 -shadowThickness=5 -cornerDiameter=20 \ No newline at end of file diff --git a/res/images/skins/rebel/settings.txt b/res/images/skins/rebel/settings.txt deleted file mode 100644 index da39ccc2a4f..00000000000 --- a/res/images/skins/rebel/settings.txt +++ /dev/null @@ -1,16 +0,0 @@ -# Settings are stored in a key=value format. -# Color values are stored as RR,GG,BB[,AA] values 0 to 255 -# Dimension values are stored as x,y -# Incomplete settings will make the file switch to the default theme. - -# Texture opacity settings, 0-100 -texture1opacity=100; -texture2opacity=100; -texture3opacity=100; - -# FRoundedPanel -shadowColor=150,150,150,150 -borderColor=0,0,0 -shadowDistance=5,5 -shadowThickness=5 -cornerDiameter=20 \ No newline at end of file diff --git a/src/main/java/forge/gui/skin/FRoundedPanel.java b/src/main/java/forge/gui/skin/FRoundedPanel.java index 47f3eb1e800..fd322161ae9 100644 --- a/src/main/java/forge/gui/skin/FRoundedPanel.java +++ b/src/main/java/forge/gui/skin/FRoundedPanel.java @@ -1,34 +1,28 @@ package forge.gui.skin; -import java.awt.BasicStroke; import java.awt.Color; -import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.LayoutManager; import java.awt.RenderingHints; - import javax.swing.JPanel; -import forge.AllZone; - /**

FRoundedPanel.

- * A subclass of JPanel with optional rounded corners and - * optional drop shadow, for special cases only. FPanel recommended for regular use. - * Limitations - cannot use background image, and single line border only. + * A subclass of JPanel with any of four corners rounded, + * drop shadow, and 1px line border. * - * Default values provided, later updated from skin settings, and can be - * set dynamically. + * Limitations: Cannot tile background image, cannot set border width. * */ @SuppressWarnings("serial") public class FRoundedPanel extends JPanel { - private FSkin skin; + public boolean[] corners = {true,true,true,true}; //NW, SW, SE, NE + private Color shadowColor = new Color(150,150,150,150); private Color borderColor = Color.black; - private Dimension shadowDistance = new Dimension(5,5); - private int shadowThickness = 5; - private int cornerDiameter = 20; + private int shadowOffset = 5; + private int cornerRadius = 10; + private boolean showShadow = false; /** *

FRoundedPanel.

@@ -38,26 +32,6 @@ public class FRoundedPanel extends JPanel { public FRoundedPanel() { super(); this.setOpaque(false); - skin = AllZone.getSkin(); - - Color tempC; - Dimension tempD; - String tempS; - - tempC = parseColorString(skin.getSetting("shadowColor")); - if(tempC != null) { shadowColor = tempC; } - - tempC = parseColorString(skin.getSetting("borderColor")); - if(tempC != null) { borderColor = tempC; } - - tempD = parseDimensionString(skin.getSetting("shadowDistance")); - if(tempD != null) { shadowDistance = tempD; } - - tempS = skin.getSetting("shadowThickness"); - if(tempS != null) { shadowThickness = Integer.parseInt(tempS); } - - tempS = skin.getSetting("cornerDiameter"); - if(tempS != null) { cornerDiameter = Integer.parseInt(tempS); } } /** @@ -81,37 +55,131 @@ public class FRoundedPanel extends JPanel { super.paintComponent(g); int w = getWidth(); int h = getHeight(); + int so = shadowOffset; + int r = cornerRadius; Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - // Draw shadow - g2d.setColor(shadowColor); - g2d.setStroke(new BasicStroke(shadowThickness)); - g2d.drawRoundRect( - 0 + (int)shadowDistance.getWidth() + (shadowThickness/2), - 0 + (int)shadowDistance.getHeight() + (shadowThickness/2), - w - (int)shadowDistance.getWidth() - shadowThickness, - h - (int)shadowDistance.getHeight() - shadowThickness, - cornerDiameter, cornerDiameter); + if(showShadow) { + // Mid, left, right rectangles: shadow + g2d.setColor(shadowColor); + g2d.fillRect(r + so, so, w - 2*r - so, h - so); + g2d.fillRect(so, r + so, r, h - 2*r - so); + g2d.fillRect(w - r, r + so, r, h - 2*r - so); + + // Corners: shadow + // NW + if(corners[0]) { + g2d.fillArc(so, so, 2*r, 2*r, 90, 90); + } + else { + g2d.fillRect(so, so, r, r); + } + // SW + if(corners[1]) { + g2d.fillArc(so, h - 2*r, 2*r, 2*r, 180, 90); + } + else { + g2d.fillRect(so, h - r, r, r); + } + // SE + if(corners[2]) { + g2d.fillArc(w - 2*r, h - 2*r, 2*r, 2*r, 270, 90); + } + else { + g2d.fillRect(w - r, h - r, r, r); + } + // NE + if(corners[3]) { + g2d.fillArc(w - 2*r, so, 2*r, 2*r, 0, 90); + } + else { + g2d.fillRect(w - r, so, r, r); + } + } // End if(showShadow) + else { + so = 0; + so = 0; + } - // Draw content rectangle (on top of shadow) - g2d.setColor(this.getBackground()); - g2d.fillRoundRect( - 0, 0, - w - shadowThickness, - h - shadowThickness, - cornerDiameter, cornerDiameter); + // Mid, left, right rectangles: content + g2d.setColor(getBackground()); + g2d.fillRect(r, 0, w - 2*r - so, h - so); + g2d.fillRect(0, r, r, h - 2*r - so); + g2d.fillRect(w - r - so, r, r, h - 2*r - so); - // Stroke border + // Corners: content + // NW + if(corners[0]) { + g2d.fillArc(0, 0, 2*r, 2*r, 90, 90); + } + else { + g2d.fillRect(0, 0, r, r); + } + // SW + if(corners[1]) { + g2d.fillArc(0, h - 2*r - so, 2*r, 2*r, 180, 90); + } + else { + g2d.fillRect(0, h - r - so, r, r); + } + // SE + if(corners[2]) { + g2d.fillArc(w - 2*r - so, h - 2*r - so, 2*r, 2*r, 270, 90); + } + else { + g2d.fillRect(w - r - so, h - r - so, r, r); + } + // NE + if(corners[3]) { + g2d.fillArc(w - 2*r - so, 0, 2*r, 2*r, 0, 90); + } + else { + g2d.fillRect(w - r - so, 0, r, r); + } + + // Mid, left, right rectangles: border g2d.setColor(this.borderColor); - g2d.setStroke(new BasicStroke(1)); - g2d.drawRoundRect( - 0,0, - w - shadowThickness - 1, - h - shadowThickness - 1, - cornerDiameter, cornerDiameter); + g2d.drawLine(r, 0, w - r - so, 0); + g2d.drawLine(r, h - so - 1, w - r - so, h - so - 1); + g2d.drawLine(0, r, 0, h - r - so); + g2d.drawLine(w - so - 1, r, w - so - 1, h - r - so); + + // Corners: border + // NW + if(corners[0]) { + g2d.drawArc(0, 0, 2*r, 2*r, 90, 90); + } + else { + g2d.drawLine(0, 0, r, 0); + g2d.drawLine(0, 0, 0, r); + } + // SW + if(corners[1]) { + g2d.drawArc(0, h - 2*r - so, 2*r, 2*r - 1, 180, 90); + } + else { + g2d.drawLine(0, h - so - 1, 0, h - r - so - 1); + g2d.drawLine(0, h - so - 1, r, h - so - 1); + } + // SE + if(corners[2]) { + g2d.drawArc(w - 2*r - so, h - 2*r - so, 2*r - 1, 2*r - 1, 270, 90); + } + else { + g2d.drawLine(w - so - 1, h - so - 1, w - so - 1, h - r - so); + g2d.drawLine(w - so - 1, h - so - 1, w - r - so, h - so - 1); + } + // NE + if(corners[3]) { + g2d.drawArc(w - 2*r - so, 0, 2*r - 1, 2*r - 1, 0, 90); + } + else { + g2d.drawLine(w - so - 1, 0, w - so - r, 0); + g2d.drawLine(w - so - 1, 0, w - so - 1, r); + } } /** @@ -135,96 +203,47 @@ public class FRoundedPanel extends JPanel { } /** - *

setShadowDistance.

- * Sets distance of shadow from rounded panel. + *

setShadowOffset.

+ * Sets offset of shadow from rounded panel. * * @param {@link java.lang.Integer} side */ - public void setShadowDistance(int side) { - this.shadowDistance = new Dimension(side,side); + public void setShadowOffset(int i) { + if(i < 0) { + i = 0; + } + this.shadowOffset = i; } /** - *

setShadowDistance.

- * Sets distance of shadow from rounded panel. - * - * @param {@link java.lang.Integer} x - * @param {@link java.lang.Integer} y - */ - public void setShadowDistance(int x, int y) { - this.shadowDistance = new Dimension(x,y); - } - - /** - *

setShadowDistance.

- * Sets thickness of rounded panel shadow. - * - * @param {@link java.lang.Integer} t - */ - public void setShadowThickness(int t) { - this.shadowThickness = t; - } - - /** - *

setCornerDiameter.

- * Sets diameter of each corner on rounded panel. + *

setCornerRadius.

+ * Sets radius of each corner on rounded panel. * * @param {@link java.lang.Integer} r */ - public void setCornerDiameter(int r) { + public void setCornerRadius(int r) { if(r < 0) { r = 0; } - this.cornerDiameter = r*2; + this.cornerRadius = r; } /** - *

parseColorString.

- * Uses string from settings file to make a new rgba color instance. - * - * @param {@link java.lang.String} s + *

setCorners.

+ * Sets if corners should be rounded or not in the following order: + * NW, SW, SE, NE + * @param boolean vals[] must be length 4 */ - private Color parseColorString(String s) { - Color c = null; - int r,g,b,a = 0; - String[] temp = s.split(","); - - if(temp.length==3 || temp.length==4) { - r = Integer.parseInt(temp[0]); - g = Integer.parseInt(temp[1]); - b = Integer.parseInt(temp[2]); - if(temp.length==4) { - a = Integer.parseInt(temp[3]); - } - c = new Color(r,g,b,a); - } - - return c; - } - - /** - *

parseDimensionString.

- * Uses string from settings file to make a new dimension instance. - * - * @param {@link java.lang.String} s - */ - private Dimension parseDimensionString(String s) { - Dimension d = null; - int w,h = 0; - String[] temp = s.split(","); - - if(temp.length==2) { - w = Integer.parseInt(temp[0]); - h = Integer.parseInt(temp[0]); - d = new Dimension(w,h); - } - else if(temp.length==1 && !temp[0].equals("")) { - w = Integer.parseInt(temp[0]); - h = w; - d = new Dimension(w,h); + public void setCorners(boolean vals[] ) { + if(vals.length!=4) { + throw new IllegalArgumentException("FRoundedPanel > setCorners requires an array of booleans of length 4."); } - return d; + corners = vals; + } + + public void setShowShadow(boolean b) { + showShadow = b; } } diff --git a/src/main/java/forge/gui/skin/FSkin.java b/src/main/java/forge/gui/skin/FSkin.java index 44d9ba6e340..06d8281def4 100644 --- a/src/main/java/forge/gui/skin/FSkin.java +++ b/src/main/java/forge/gui/skin/FSkin.java @@ -3,11 +3,8 @@ package forge.gui.skin; import java.awt.Color; import java.awt.Font; import java.awt.image.BufferedImage; -import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; import java.io.IOException; -import java.util.Hashtable; import javax.imageio.ImageIO; import javax.swing.ImageIcon; @@ -52,8 +49,9 @@ public class FSkin { public Color txt3a = Color.red; public Color txt3b = Color.red; + public String name = "default"; + //===== Private fields - private final String settingsfile = "settings.txt"; private final String paletteFile = "palette.jpg"; private final String font1file = "font1.ttf"; private final String font2file = "font2.ttf"; @@ -76,10 +74,6 @@ public class FSkin { private String skin; private String notfound = "FSkin.java: \""+skin+ "\" skin can't find "; - private Hashtable customSettings = - new Hashtable(); - private Hashtable defaultSettings = - new Hashtable(); /** * FSkin constructor. No arguments, will generate default skin settings, @@ -99,49 +93,13 @@ public class FSkin { * @throws Exception */ public FSkin(String skinName) throws Exception { - defaultSettings = loadSettings("default"); loadFontAndImages("default"); if(!skinName.equals("default")) { - customSettings = loadSettings(skinName); loadFontAndImages(skinName); } } - /** - * Retrieves skin settings from file, returns in hashtable. - * - * @param skinName - * @return settings hashtable - * @throws Exception - */ - private Hashtable loadSettings(String skinName) throws Exception { - String filename = "res/images/skins/"+skinName+"/"+settingsfile; - - String notfound = "FSkin > load: Can't find \"" + filename + "\"."; - Hashtable settings = new Hashtable(); - - File f = new File(filename); - customSettings.put("name",skinName); - - if (!f.exists()) { - throw new RuntimeException(notfound); - } - - BufferedReader input = new BufferedReader(new FileReader(f)); - String line = null; - while ((line = input.readLine()) != null) { - String[] data = line.split("="); - if (line.startsWith("#") || line.length() == 0 || data.length != 2) { - continue; - } - - settings.put(data[0],data[1]); - } - - return settings; - } - /** * Loads objects from skin folder, prints brief error if not found. * @@ -237,35 +195,4 @@ public class FSkin { (pixel & 0x000000ff) ); } - - /** - *

getSetting.

- * Retrieves a specific skin setting. If skin setting is not defined, - * will attempt to use default value. - * - * @param key a {@link java.lang.String} object. - * @return a {@link java.lang.String} object. - */ - public String getSetting(String key) { - String val = null; - - if(customSettings.size() > 1) { - val = customSettings.get(key); - if(val==null) { - System.err.println("FSkin > getSetting: Could not find "+key+ - " setting for "+customSettings.get("name")+" skin!"); - } - } - - if(val==null) { - val = defaultSettings.get(key); - } - - if(val==null) { - System.err.println("FSkin > getSetting: Could not find "+key+ - " in default settings!"); - } - - return val; - } }