diff --git a/box/IconMake/IconMake/README.md b/box/IconMake/IconMake/README.md new file mode 100644 index 0000000..d659f6f --- /dev/null +++ b/box/IconMake/IconMake/README.md @@ -0,0 +1,13 @@ +18/12/07 +0.0.2 + +* 将非安装包格式转移至安装包格式,尝试重构ui和代码 +* 字符本地化,函数改善。(修改compare函数以准备未来从input或slider输入颜色) + +0.0.3 + +* 本地化字符 + +0.0.4 + +* 分离常量 diff --git a/box/IconMake/IconMake/assets/html/canvas.html b/box/IconMake/IconMake/assets/html/canvas.html new file mode 100644 index 0000000..6a3f2f7 --- /dev/null +++ b/box/IconMake/IconMake/assets/html/canvas.html @@ -0,0 +1,10 @@ + + + + +Icon + + + + + \ No newline at end of file diff --git a/box/IconMake/IconMake/assets/icon.png b/box/IconMake/IconMake/assets/icon.png new file mode 100644 index 0000000..c9685f4 Binary files /dev/null and b/box/IconMake/IconMake/assets/icon.png differ diff --git a/box/IconMake/IconMake/config.json b/box/IconMake/IconMake/config.json new file mode 100644 index 0000000..f32ac79 --- /dev/null +++ b/box/IconMake/IconMake/config.json @@ -0,0 +1,23 @@ +{ + "info": { + "name": "", + "url": "", + "version": "0.0.2", + "author": "", + "website": "", + "types": 0 + }, + "settings": { + "minSDKVer": "1.0.0", + "minOSVer": "10.0.0", + "idleTimerDisabled": false, + "autoKeyboardEnabled": false, + "keyboardToolbarEnabled": false, + "rotateDisabled": false + }, + "widget": { + "height": 0, + "tintColor": "", + "iconColor": "" + } +} diff --git a/box/IconMake/IconMake/main.js b/box/IconMake/IconMake/main.js new file mode 100644 index 0000000..58d9833 --- /dev/null +++ b/box/IconMake/IconMake/main.js @@ -0,0 +1,13 @@ +//$ui.alert($file.list("shared://../Icons")) +let image +const + mainViews = require("./scripts/const.js"), + ui = { + type: "view", + props: { + id: "main" + }, + layout: $layout.fill, + views: mainViews + }; +$ui.render(ui); \ No newline at end of file diff --git a/box/IconMake/IconMake/scripts/const.js b/box/IconMake/IconMake/scripts/const.js new file mode 100644 index 0000000..d968fef --- /dev/null +++ b/box/IconMake/IconMake/scripts/const.js @@ -0,0 +1,153 @@ +const + sideLength = Math.ceil(72.0 / $device.info.screen.scale), + view = { + type: "view", + props: { + id: "viewMain" + }, + layout: function (make, view) { + make.center.equalTo(view.super) + make.size.equalTo($size(sideLength, sideLength)) + } + }, + getSnapshot = function () { + return $("viewMain").snapshot; + }, + compare = function (imageT, colorC) { + let + colorCComponents = colorC.components, + red = colorCComponents.red, + green = colorCComponents.green, + blue = colorCComponents.blue, + sum = red + green + blue; + return function (w, h) { + let color = imageT.colorAtPixel($point(w, h)), + components = color.components, + r = components.red, + g = components.green, + b = components.blue, + sumT = r + g + b; + if (sumT > sum) { + return true + } else { + return false + } + } + }, + compareAvg = function (imageT) { + return compare(imageT, imageT.averageColor); + }, + buttonSave = { + type: "button", + props: { + title: $l10n("save") + }, + layout: function (make, view) { + make.centerX.equalTo(view.super).multipliedBy(1.4) + make.centerY.equalTo(view.super).multipliedBy(1.5) + make.width.equalTo(view.super).multipliedBy(0.15) + }, + events: { + tapped: function () { + let data = $("canvasView").snapshot.resized($size(72, 72)).png, + path = "shared://iconMake/" + if ($file.isDirectory(path)) { + + } else { + $file.mkdir(path) + } + var success = $file.write({ + data: data, + path: path + "icon.png" + }) + if (success) { + $ui.alert({ + title: "", + message: "存储成功,地址:\n" + path + "icon.png", + }); + } else { + $ui.alert({ + title: "", + message: "存储失败", + }); + } + //$quicklook.open({ image: $("canvasView").snapshot }); + } + } + }, + buttonSelect = { + type: "button", + props: { + title: $l10n("select") + }, + layout: function (make, view) { + make.centerX.equalTo(view.super).multipliedBy(0.6) + make.centerY.equalTo(view.super).multipliedBy(1.5) + make.width.equalTo(view.super).multipliedBy(0.15) + }, + events: { + tapped: function () { + if ($("canvasView")) { + $("canvasView").remove() + } + + let viewMain = $("viewMain") + $photo.pick().then(function (resp) { + if (resp.image) { + image = resp.image; + viewMain.add({ + type: "canvas", + props: { + id: "canvasView" + }, + layout: $layout.fill, + events: { + draw: function (view, ctx) { + ctx.drawImage(view.frame, image) + } + } + }) + image = getSnapshot() + $("canvasView").remove() + viewMain.add({ + type: "canvas", + props: { + id: "canvasView" + }, + layout: $layout.fill, + events: { + draw: function (view, ctx) { + let gray = $color("gray"), + clear = $color("clear") + let compareWH = compareAvg(image) + for (let w = 0; w < sideLength; w++) { + for (let h = 0; h < sideLength; h++) { + if (compareWH(w, h)) { + ctx.fillColor = gray; + } else { + ctx.fillColor = clear; + } + ctx.fillRect($rect(w, h, 1, 1)) + } + } + } + } + }) + $quicklook.open({ image: getSnapshot() }); + } else { + $ui.alert({ + title: "提醒", + message: "你没有选择图片", + }); + $app.close(); + } + }); + } + } + }, + mainViews = [ + view, + buttonSave, + buttonSelect + ] +module.exports=mainViews \ No newline at end of file diff --git a/box/IconMake/IconMake/strings/en.strings b/box/IconMake/IconMake/strings/en.strings new file mode 100644 index 0000000..b112787 --- /dev/null +++ b/box/IconMake/IconMake/strings/en.strings @@ -0,0 +1,2 @@ +"select"="select"; +"save"="save"; diff --git a/box/IconMake/IconMake/strings/zh-Hans.strings b/box/IconMake/IconMake/strings/zh-Hans.strings new file mode 100644 index 0000000..1eeaafb --- /dev/null +++ b/box/IconMake/IconMake/strings/zh-Hans.strings @@ -0,0 +1,2 @@ +"select"="选择"; +"save"="存储"; \ No newline at end of file