Changeset 5811 in josm


Ignore:
Timestamp:
2013-03-29T12:21:07+01:00 (11 years ago)
Author:
bastiK
Message:

mapcss: add width+height properties for repeat-image

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java

    r5571 r5811  
    2424 * applies for Nodes and turn restriction relations
    2525 */
    26 public class NodeElemStyle extends ElemStyle {
     26public class NodeElemStyle extends ElemStyle implements StyleKeys {
    2727    public MapImage mapImage;
    2828    public Symbol symbol;
     
    104104        Cascade c = env.mc.getCascade(env.layer);
    105105
    106         MapImage mapImage = createIcon(env);
     106        MapImage mapImage = createIcon(env, ICON_KEYS);
    107107        Symbol symbol = null;
    108108        if (mapImage == null) {
     
    118118    }
    119119
    120     private static MapImage createIcon(Environment env) {
     120    public static MapImage createIcon(Environment env, String[] keys) {
    121121        Cascade c = env.mc.getCascade(env.layer);
    122         Cascade c_def = env.mc.getCascade("default");
    123 
    124         final IconReference iconRef = c.get(ICON_IMAGE, null, IconReference.class);
     122
     123        final IconReference iconRef = c.get(keys[ICON_IMAGE_IDX], null, IconReference.class);
    125124        if (iconRef == null)
    126125            return null;
    127126
    128         Float widthOnDefault = c_def.get("icon-width", null, Float.class);
     127        Cascade c_def = env.mc.getCascade("default");
     128
     129        Float widthOnDefault = c_def.get(keys[ICON_WIDTH_IDX], null, Float.class);
    129130        if (widthOnDefault != null && widthOnDefault <= 0) {
    130131            widthOnDefault = null;
    131132        }
    132         Float widthF = getWidth(c, "icon-width", widthOnDefault);
    133 
    134         Float heightOnDefault = c_def.get("icon-height", null, Float.class);
     133        Float widthF = getWidth(c, keys[ICON_WIDTH_IDX], widthOnDefault);
     134
     135        Float heightOnDefault = c_def.get(keys[ICON_HEIGHT_IDX], null, Float.class);
    135136        if (heightOnDefault != null && heightOnDefault <= 0) {
    136137            heightOnDefault = null;
    137138        }
    138         Float heightF = getWidth(c, "icon-height", heightOnDefault);
     139        Float heightF = getWidth(c, keys[ICON_HEIGHT_IDX], heightOnDefault);
    139140
    140141        int width = widthF == null ? -1 : Math.round(widthF);
     
    147148
    148149        mapImage.alpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
    149         Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
     150        Integer pAlpha = Utils.color_float2int(c.get(keys[ICON_OPACITY_IDX], null, float.class));
    150151        if (pAlpha != null) {
    151152            mapImage.alpha = pAlpha;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java

    r5801 r5811  
    88import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
    99import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
    10 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    1110import org.openstreetmap.josm.tools.CheckParameterUtil;
    1211
     
    3130
    3231    public static RepeatImageElemStyle create(Environment env) {
    33         // FIXME: make use of NodeElemStyle.createIcon, in order to have
    34         // -width, -height and -opacity properties.
     32        MapImage pattern = NodeElemStyle.createIcon(env, REPEAT_IMAGE_KEYS);
     33        if (pattern == null)
     34            return null;
    3535        Cascade c = env.mc.getCascade(env.layer);
    36 
    37         IconReference iconRef = c.get(REPEAT_IMAGE, null, IconReference.class);
    38         if (iconRef == null)
    39             return null;
    40         MapImage pattern = new MapImage(iconRef.iconName, iconRef.source);
    4136        Float offset = c.get(REPEAT_IMAGE_OFFSET, 0f, Float.class);
    4237        Float spacing = c.get(REPEAT_IMAGE_SPACING, 0f, Float.class);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java

    r5801 r5811  
    2626    String REPEAT_IMAGE_SPACING = "repeat-image-spacing";
    2727    String REPEAT_IMAGE_ALIGN = "repeat-image-align";
     28
     29    int ICON_IMAGE_IDX = 0;
     30    int ICON_WIDTH_IDX = 1;
     31    int ICON_HEIGHT_IDX = 2;
     32    int ICON_OPACITY_IDX = 3;
     33    String[] ICON_KEYS = {"icon-image", "icon-width", "icon-height", "icon-opacity"};
     34    String[] REPEAT_IMAGE_KEYS = {"repeat-image", "repeat-image-width", "repeat-image-height", "repeat-image-opacity"};
    2835}
Note: See TracChangeset for help on using the changeset viewer.