Changeset 6413


Ignore:
Timestamp:
Jun 29, 2016, 2:46:27 PM (8 years ago)
Author:
ldelgass
Message:

Add methods to Map object to convert style flags to CSS style.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/map.tcl

    r6324 r6413  
    8181    protected method parseXML { xmlobj path }
    8282
     83    protected proc colorToHTML { color }
     84    protected proc fixBoolean { val }
     85    protected proc fixEnum { str }
     86    protected proc fixQuotes { str }
     87    protected proc isBooleanProp { prop }
     88    protected proc isColorProp { prop }
    8389    protected proc isFileProp { prop }
    8490    protected proc parseStylesheet { stylesheet }
     91    protected proc styleToCSS { layerType props {styleName "style"} }
     92    protected proc translateProp { layerType styleProp styleValue }
    8593
    8694    private variable _tree "";         # Tree of information about the map.
     
    10741082}
    10751083
     1084itcl::body Rappture::Map::styleToCSS { layerType props {styleName "style"} } {
     1085    append output "$styleName { "
     1086    foreach {name value} $props {
     1087        if {[string range $name 0 0] eq "-"} {
     1088            set name [string range $name 1 end]
     1089        }
     1090        # These aren't really style properties
     1091        if {$name eq "minrange" || $name eq "maxrange" } {
     1092            continue
     1093        }
     1094        foreach {name value} [translateProp $layerType $name $value] {}
     1095        # TODO: Fix quoting
     1096        if {$name ne ""} {
     1097            append output "$name: $value; "
     1098        }
     1099    }
     1100    append output "}"
     1101    return $output
     1102}
     1103
     1104itcl::body Rappture::Map::colorToHTML { color } {
     1105    foreach {r g b} [winfo rgb . $color] break
     1106    return [format "#%02X%02X%02X" [expr {$r/256}] [expr {$g/256}] [expr {$b/256}]]
     1107}
     1108
     1109itcl::body Rappture::Map::isColorProp { prop } {
     1110    foreach colorprop { fill stroke point-fill text-fill text-halo } {
     1111        if { $prop eq $colorprop } {
     1112            return 1
     1113        }
     1114    }
     1115    return 0
     1116}
     1117
     1118itcl::body Rappture::Map::isBooleanProp { prop } {
     1119    foreach boolprop {
     1120        extrusion-flatten
     1121        skin-tiled
     1122        icon-declutter
     1123        render-depth-test
     1124        render-lighting
     1125        render-transparent
     1126        render-depth-offset
     1127        text-declutter
     1128    } {
     1129        if { $prop eq $boolprop } {
     1130            return 1
     1131        }
     1132    }
     1133    return 0
     1134}
     1135
    10761136itcl::body Rappture::Map::isFileProp { prop } {
    10771137    foreach fileprop {
     
    10841144    }
    10851145    return 0
     1146}
     1147
     1148itcl::body Rappture::Map::fixQuotes { str } {
     1149    return [string map {"\{" "\"" "\}" "\""} [list $str]]
     1150}
     1151
     1152itcl::body Rappture::Map::fixEnum { str } {
     1153    return [string map {"_" "-"} $str]
     1154}
     1155
     1156itcl::body Rappture::Map::fixBoolean { val } {
     1157    if { $val } {
     1158        return "true"
     1159    } else {
     1160        return "false"
     1161    }
     1162}
     1163
     1164itcl::body Rappture::Map::translateProp { layerType styleProp styleValue } {
     1165    switch -- $layerType {
     1166        "icon" {
     1167            array set trans {
     1168                "align" "icon-align"
     1169                "clamping" "altitude-clamping"
     1170                "clamptechnique" "altitude-technique"
     1171                "declutter" "icon-declutter"
     1172                "library" "icon-library"
     1173                "minbias" "render-depth-offset-min-bias"
     1174                "maxbias" "render-depth-offset-max-bias"
     1175                "scale" "icon-scale"
     1176                "heading" "icon-heading"
     1177                "placement" "icon-placement"
     1178                "url" "icon"
     1179            }
     1180        }
     1181        "label" {
     1182            array set trans {
     1183                "align" "text-align"
     1184                "clamping" "altitude-clamping"
     1185                "clamptechnique" "altitude-technique"
     1186                "color" "text-fill"
     1187                "content" "text-content"
     1188                "declutter" "text-declutter"
     1189                "font" "text-font"
     1190                "fontsize" "text-size"
     1191                "halocolor" "text-halo"
     1192                "halowidth" "text-halo-offset"
     1193                "layout" "text-layout"
     1194                "minbias" "render-depth-offset-min-bias"
     1195                "maxbias" "render-depth-offset-max-bias"
     1196                "priority" "text-priority"
     1197                "xoffset" "text-offset-x"
     1198                "yoffset" "text-offset-y"
     1199            }
     1200        }
     1201        "line" {
     1202            array set trans {
     1203                "cap" "stroke-linecap"
     1204                "clamping" "altitude-clamping"
     1205                "clamptechnique" "altitude-technique"
     1206                "color" "stroke"
     1207                "join" "stroke-linejoin"
     1208                "minbias" "render-depth-offset-min-bias"
     1209                "maxbias" "render-depth-offset-max-bias"
     1210                "stipplepattern" "stroke-stipple-pattern"
     1211                "stipplefactor" "stroke-stipple-factor"
     1212                "width" "stroke-width"
     1213            }
     1214        }
     1215        "point" {
     1216             array set trans {
     1217                "clamping" "altitude-clamping"
     1218                "clamptechnique" "altitude-technique"
     1219                "color" "point-fill"
     1220                "minbias" "render-depth-offset-min-bias"
     1221                "maxbias" "render-depth-offset-max-bias"
     1222                "size" "point-size"
     1223            }
     1224        }
     1225        "polygon" {
     1226            array set trans {
     1227                "clamping" "altitude-clamping"
     1228                "clamptechnique" "altitude-technique"
     1229                "color" "fill"
     1230                "minbias" "render-depth-offset-min-bias"
     1231                "maxbias" "render-depth-offset-max-bias"
     1232                "strokecolor" "stroke"
     1233                "strokewidth" "stroke-width"
     1234            }
     1235        }
     1236        "image" - "elevation" - "feature" {
     1237        }
     1238        default {
     1239            error "Unknown layer type: \"$layerType\""
     1240        }
     1241    }
     1242    if {[info exists trans($styleProp)]} {
     1243        set styleProp $trans($styleProp)
     1244    }
     1245    if {[isColorProp $styleProp]} {
     1246        set styleValue [colorToHTML $styleValue]
     1247    }
     1248    if {$styleProp eq "icon-scale" && $styleValue eq ""} {
     1249        set styleProp ""
     1250    }
     1251    if {$styleProp eq "icon-heading" && $styleValue eq ""} {
     1252        set styleProp ""
     1253    }
     1254    if {$styleProp eq "text-align" || $styleProp eq "icon-align"} {
     1255        set styleValue [fixEnum $styleValue]
     1256    }
     1257    if {[isBooleanProp $styleProp]} {
     1258        set styleValue [fixBoolean $styleValue]
     1259    }
     1260    set styleValue [fixQuotes $styleValue]
     1261    return [list $styleProp $styleValue]
    10861262}
    10871263
Note: See TracChangeset for help on using the changeset viewer.