diff --git a/src/lime/tools/Icon.hx b/src/lime/tools/Icon.hx index 820dacd61..8bea32123 100644 --- a/src/lime/tools/Icon.hx +++ b/src/lime/tools/Icon.hx @@ -6,11 +6,13 @@ class Icon public var path:String; public var size:Int; public var width:Int; + public var priority:Int; - public function new(path:String, size:Int = 0) + public function new(path:String, size:Int = 0, priority:Int = 0) { this.path = path; this.size = height = width = size; + this.priority = 0; } public function clone():Icon diff --git a/src/lime/tools/IconHelper.hx b/src/lime/tools/IconHelper.hx index 6c529d2da..7233f5379 100644 --- a/src/lime/tools/IconHelper.hx +++ b/src/lime/tools/IconHelper.hx @@ -281,7 +281,7 @@ class IconHelper for (icon in icons) { - if ((icon.width == 0 && icon.height == 0) || (icon.width == width && icon.height == height)) + if (icon.width == width && icon.height == height && (match == null || match.priority < icon.priority)) { match = icon; } @@ -292,33 +292,21 @@ class IconHelper public static function findNearestMatch(icons:Array, width:Int, height:Int):Icon { - var match = null; + var match:Icon = null; + var matchDifference = Math.POSITIVE_INFINITY; for (icon in icons) { - if (icon.width > width / 2 && icon.height > height / 2) + var iconDifference = Math.abs(icon.width - width) + Math.abs(icon.height - height); + if (Path.extension(icon.path) == "svg") { - if (match == null) - { - match = icon; - } - else - { - if (icon.width > match.width && icon.height > match.height) - { - if (match.width < width || match.height < height) - { - match = icon; - } - } - else - { - if (icon.width > width && icon.height > height) - { - match = icon; - } - } - } + iconDifference = 0; + } + + if (iconDifference < matchDifference || iconDifference == matchDifference && icon.priority > match.priority) + { + match = icon; + matchDifference = iconDifference; } } diff --git a/src/lime/tools/ProjectXMLParser.hx b/src/lime/tools/ProjectXMLParser.hx index d6550f6d2..ee009e672 100644 --- a/src/lime/tools/ProjectXMLParser.hx +++ b/src/lime/tools/ProjectXMLParser.hx @@ -1478,6 +1478,11 @@ class ProjectXMLParser extends HXProject icon.height = Std.parseInt(substitute(element.att.height)); } + if (element.has.priority) + { + icon.priority = Std.parseInt(substitute(element.att.priority)); + } + icons.push(icon); case "source", "classpath":