diff options
Diffstat (limited to 'ardor3d-ui/src/main')
3 files changed, 134 insertions, 50 deletions
diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/border/ImageBorder.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/border/ImageBorder.java index 9de5221..452d24e 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/border/ImageBorder.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/border/ImageBorder.java @@ -34,58 +34,58 @@ public class ImageBorder extends UIBorder { private SubTex _bottomRightCorner = null; /** - * Construct this border as a 9-slice using the given image. The corners will not be drawn. + * Construct this border as a 9-slice using the given subtex and its defined borders. * - * @param image - * @param top - * @param left - * @param bottom - * @param right + * @param subtex */ - public ImageBorder(final SubTex image, final int top, final int left, final int bottom, final int right) { - super(top, left, bottom, right); + public ImageBorder(final SubTex subtex) { + super(subtex.getBorderTop(), subtex.getBorderLeft(), subtex.getBorderBottom(), subtex.getBorderRight()); + final int top = subtex.getBorderTop(); + final int left = subtex.getBorderLeft(); + final int bottom = subtex.getBorderBottom(); + final int right = subtex.getBorderRight(); if (top > 0) { - _topEdge = new SubTex(image.getTexture(), image.getX() + left, image.getY(), image.getWidth() - left + _topEdge = new SubTex(subtex.getTexture(), subtex.getX() + left, subtex.getY(), subtex.getWidth() - left - right, top); if (left > 0) { - _topLeftCorner = new SubTex(image.getTexture(), image.getX(), image.getY(), left, top); + _topLeftCorner = new SubTex(subtex.getTexture(), subtex.getX(), subtex.getY(), left, top); } if (right > 0) { - _topRightCorner = new SubTex(image.getTexture(), image.getX() + image.getWidth() - right, image.getY(), - right, top); + _topRightCorner = new SubTex(subtex.getTexture(), subtex.getX() + subtex.getWidth() - right, + subtex.getY(), right, top); } } else { - _topEdge = new SubTex(image.getTexture(), 0, 0, 0, 0); + _topEdge = new SubTex(subtex.getTexture(), 0, 0, 0, 0); } if (left > 0) { - _leftEdge = new SubTex(image.getTexture(), image.getX(), image.getY() + top, left, image.getHeight() - top - - bottom); + _leftEdge = new SubTex(subtex.getTexture(), subtex.getX(), subtex.getY() + top, left, subtex.getHeight() + - top - bottom); } else { - _leftEdge = new SubTex(image.getTexture(), 0, 0, 0, 0); + _leftEdge = new SubTex(subtex.getTexture(), 0, 0, 0, 0); } if (right > 0) { - _rightEdge = new SubTex(image.getTexture(), image.getX() + image.getWidth() - right, image.getY() + top, - right, image.getHeight() - top - bottom); + _rightEdge = new SubTex(subtex.getTexture(), subtex.getX() + subtex.getWidth() - right, + subtex.getY() + top, right, subtex.getHeight() - top - bottom); } else { - _rightEdge = new SubTex(image.getTexture(), 0, 0, 0, 0); + _rightEdge = new SubTex(subtex.getTexture(), 0, 0, 0, 0); } if (bottom > 0) { - final int botY = image.getY() + image.getHeight() - bottom; - _bottomEdge = new SubTex(image.getTexture(), image.getX() + left, botY, image.getWidth() - left - right, + final int botY = subtex.getY() + subtex.getHeight() - bottom; + _bottomEdge = new SubTex(subtex.getTexture(), subtex.getX() + left, botY, subtex.getWidth() - left - right, bottom); if (left > 0) { - _bottomLeftCorner = new SubTex(image.getTexture(), image.getX(), botY, left, bottom); + _bottomLeftCorner = new SubTex(subtex.getTexture(), subtex.getX(), botY, left, bottom); } if (right > 0) { - _bottomRightCorner = new SubTex(image.getTexture(), image.getX() + image.getWidth() - right, botY, + _bottomRightCorner = new SubTex(subtex.getTexture(), subtex.getX() + subtex.getWidth() - right, botY, right, bottom); } } else { - _bottomEdge = new SubTex(image.getTexture(), 0, 0, 0, 0); + _bottomEdge = new SubTex(subtex.getTexture(), 0, 0, 0, 0); } } diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/generic/GenericSkin.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/generic/GenericSkin.java index 94918da..2013294 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/generic/GenericSkin.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/skin/generic/GenericSkin.java @@ -107,14 +107,17 @@ public class GenericSkin extends Skin { final SubTex defaultTex = new SubTex(_sharedTex, 51 - leftE, 11 - topE, 26 + leftE + rightE, 10 + topE + bottomE); - final UIBorder defaultBorder = new ImageBorder(defaultTex, topE, leftE, bottomE, rightE); + defaultTex.setBorders(topE, leftE, bottomE, rightE); + final UIBorder defaultBorder = new ImageBorder(defaultTex); final SubTex overTex = new SubTex(_sharedTex, 51 - leftE, 33 - topE, 26 + leftE + rightE, 10 + topE + bottomE); - final UIBorder overBorder = new ImageBorder(overTex, topE, leftE, bottomE, rightE); + overTex.setBorders(topE, leftE, bottomE, rightE); + final UIBorder overBorder = new ImageBorder(overTex); final SubTex pressedTex = new SubTex(_sharedTex, 51 - leftE, 55 - topE, 26 + leftE + rightE, 10 + topE + bottomE); - final UIBorder pressedBorder = new ImageBorder(pressedTex, topE, leftE, bottomE, rightE); + pressedTex.setBorders(topE, leftE, bottomE, rightE); + final UIBorder pressedBorder = new ImageBorder(pressedTex); final ColorRGBA upTop = new ColorRGBA(235 / 255f, 235 / 255f, 235 / 255f, 1); final ColorRGBA upBottom = new ColorRGBA(200 / 255f, 200 / 255f, 200 / 255f, 1); @@ -172,14 +175,14 @@ public class GenericSkin extends Skin { component.setPadding(new Insets(2, 14, 2, 14)); // State values... - final SubTex defaultTex = new SubTex(_sharedTex, 47, 7, 34, 18); - final UIBorder defaultBorder = new ImageBorder(defaultTex, 4, 4, 4, 4); + final SubTex defaultTex = new SubTex(_sharedTex, 47, 7, 34, 18, 4, 4, 4, 4); + final UIBorder defaultBorder = new ImageBorder(defaultTex); - final SubTex overTex = new SubTex(_sharedTex, 47, 29, 34, 18); - final UIBorder overBorder = new ImageBorder(overTex, 4, 4, 4, 4); + final SubTex overTex = new SubTex(_sharedTex, 47, 29, 34, 18, 4, 4, 4, 4); + final UIBorder overBorder = new ImageBorder(overTex); - final SubTex pressedTex = new SubTex(_sharedTex, 47, 51, 34, 18); - final UIBorder pressedBorder = new ImageBorder(pressedTex, 4, 4, 4, 4); + final SubTex pressedTex = new SubTex(_sharedTex, 47, 51, 34, 18, 4, 4, 4, 4); + final UIBorder pressedBorder = new ImageBorder(pressedTex); final ColorRGBA upTop = new ColorRGBA(235 / 255f, 235 / 255f, 235 / 255f, 1); final ColorRGBA upBottom = new ColorRGBA(200 / 255f, 200 / 255f, 200 / 255f, 1); @@ -281,8 +284,8 @@ public class GenericSkin extends Skin { if (titleBar != null && titleBar.getParent() == component) { titleBar.setMargin(new Insets(0, 0, 0, 0)); titleBar.setPadding(new Insets(0, 0, 0, 0)); - final SubTex borderTex = new SubTex(_sharedTex, 4, 5, 32, 13); - final UIBorder border = new ImageBorder(borderTex, 6, 6, 1, 6); + final SubTex borderTex = new SubTex(_sharedTex, 4, 5, 32, 13, 6, 6, 1, 6); + final UIBorder border = new ImageBorder(borderTex); titleBar.setBorder(border); final ColorRGBA top = new ColorRGBA(203 / 255f, 203 / 255f, 203 / 255f, 1); final ColorRGBA bottom = new ColorRGBA(208 / 255f, 208 / 255f, 208 / 255f, 1); @@ -384,8 +387,8 @@ public class GenericSkin extends Skin { base.setMargin(new Insets(0, 0, 0, 0)); base.setPadding(new Insets(0, 0, 0, 0)); - final SubTex borderTex = new SubTex(_sharedTex, 4, 17, 32, 36); - final UIBorder border = new ImageBorder(borderTex, 0, 6, 7, 6); + final SubTex borderTex = new SubTex(_sharedTex, 4, 17, 32, 36, 0, 6, 7, 6); + final UIBorder border = new ImageBorder(borderTex); base.setBorder(border); final ColorRGBA top = new ColorRGBA(210 / 255f, 210 / 255f, 210 / 255f, 1); final ColorRGBA bottom = new ColorRGBA(244 / 255f, 244 / 255f, 244 / 255f, 1); @@ -563,13 +566,13 @@ public class GenericSkin extends Skin { final UIPanel back = component.getBackPanel(); if (component.getOrientation() == Orientation.Horizontal) { - final SubTex borderTex = new SubTex(_sharedTex, 7, 79, 30, 17); - final UIBorder border = new ImageBorder(borderTex, 6, 4, 4, 4); + final SubTex borderTex = new SubTex(_sharedTex, 7, 79, 30, 17, 6, 4, 4, 4); + final UIBorder border = new ImageBorder(borderTex); back.setBorder(border); back.setMinimumContentSize(1, 7); } else { - final SubTex borderTex = new SubTex(_sharedTex, 67, 91, 18, 29); - final UIBorder border = new ImageBorder(borderTex, 6, 5, 4, 5); + final SubTex borderTex = new SubTex(_sharedTex, 67, 91, 18, 29, 6, 5, 4, 5); + final UIBorder border = new ImageBorder(borderTex); back.setBorder(border); back.setMinimumContentSize(8, 1); } @@ -592,8 +595,8 @@ public class GenericSkin extends Skin { // value label { - final SubTex borderTex = new SubTex(_sharedTex, 155, 7, 21, 18); - final UIBorder labelBorder = new ImageBorder(borderTex, 4, 4, 4, 1); + final SubTex borderTex = new SubTex(_sharedTex, 155, 7, 21, 18, 4, 4, 4, 1); + final UIBorder labelBorder = new ImageBorder(borderTex); final UILabel label = component.getValueLabel(); label.setBackdrop(upBack); @@ -604,8 +607,8 @@ public class GenericSkin extends Skin { // drop down button { - final SubTex borderTex = new SubTex(_sharedTex, 177, 7, 12, 18); - final UIBorder buttonBorder = new ImageBorder(borderTex, 4, 1, 4, 4); + final SubTex borderTex = new SubTex(_sharedTex, 177, 7, 12, 18, 4, 1, 4, 4); + final UIBorder buttonBorder = new ImageBorder(borderTex); final UIButton button = component.getOpenButton(); button.setButtonText(""); diff --git a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/util/SubTex.java b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/util/SubTex.java index 7d84897..6874168 100644 --- a/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/util/SubTex.java +++ b/ardor3d-ui/src/main/java/com/ardor3d/extension/ui/util/SubTex.java @@ -3,7 +3,7 @@ * * This file is part of Ardor3D. * - * Ardor3D is free software: you can redistribute it and/or modify it + * Ardor3D is free software: you can redistribute it and/or modify it * under the terms of its license which may be found in the accompanying * LICENSE file or at <http://www.ardor3d.com/LICENSE>. */ @@ -37,8 +37,29 @@ public class SubTex { private ColorRGBA _tint = null; /** + * The number of pixels of the inside-top of this subtex that is considered a border. Used by some UIBorders and + * UIBackdrops in 9-slicing. + */ + private int _borderTop; + /** + * The number of pixels of the inside-left of this subtex that is considered a border. Used by some UIBorders and + * UIBackdrops in 9-slicing. + */ + private int _borderLeft; + /** + * The number of pixels of the inside-bottom of this subtex that is considered a border. Used by some UIBorders and + * UIBackdrops in 9-slicing. + */ + private int _borderBottom; + /** + * The number of pixels of the inside-right of this subtex that is considered a border. Used by some UIBorders and + * UIBackdrops in 9-slicing. + */ + private int _borderRight; + + /** * Construct a new SubTex that covers the entire width and height of the supplied Texture. - * + * * @param texture * the base texture. Must already have a supplied image with a valid width and height. */ @@ -48,7 +69,7 @@ public class SubTex { /** * Construct a new SubTex using the specified dimensions and location. - * + * * @param texture * the master texture we are a part of * @param x @@ -68,6 +89,42 @@ public class SubTex { _height = height; } + /** + * Construct a new SubTex using the specified dimensions and location. + * + * @param texture + * the master texture we are a part of + * @param x + * the x location, in pixels, of our upper left corner. + * @param y + * the y location, in pixels, of our upper left corner. + * @param width + * the width, in pixels, of our part of the texture. + * @param height + * the height, in pixels, of our part of the texture. + * @param borderTop + * border, in pixels, of top. + * @param borderLeft + * border, in pixels, of left. + * @param borderBottom + * border, in pixels, of bottom. + * @param borderRight + * border, in pixels, of right. + */ + public SubTex(final Texture texture, final int x, final int y, final int width, final int height, + final int borderTop, final int borderLeft, final int borderBottom, final int borderRight) { + _texture = texture; + _x = x; + _y = y; + _width = width; + _height = height; + + _borderTop = borderTop; + _borderLeft = borderLeft; + _borderBottom = borderBottom; + _borderRight = borderRight; + } + public Texture getTexture() { return _texture; } @@ -92,8 +149,31 @@ public class SubTex { return _tint; } + public int getBorderTop() { + return _borderTop; + } + + public int getBorderLeft() { + return _borderLeft; + } + + public int getBorderBottom() { + return _borderBottom; + } + + public int getBorderRight() { + return _borderRight; + } + + public void setBorders(final int top, final int left, final int bottom, final int right) { + _borderTop = top; + _borderLeft = left; + _borderBottom = bottom; + _borderRight = right; + } + /** - * + * * @param color * a color to blend our texture with when rendering SubTex objects. The default is null (which is * interpreted as pure white and gives an unaltered version of the texture.) @@ -110,7 +190,8 @@ public class SubTex { @Override public String toString() { - return "SubTex of " + _texture + ": " + _x + ", " + _y + " dims: " + _width + ", " + _height; + return String.format("SubTex of %0$s: %1$d, %2$d dims: %3$dx%4$d tint: %5$s border: %6$d,%7$d,%8$d,%9$d", + _texture, _x, _y, _width, _height, _tint, _borderTop, _borderLeft, _borderBottom, _borderRight); } public void setHeight(final int height) { |