From b8467666b7b5a2065d10759112484329fa925380 Mon Sep 17 00:00:00 2001 From: shutaozhenzhen <3462232313@qq.com> Date: Fri, 7 Dec 2018 22:01:10 +0800 Subject: [PATCH] Add files via upload --- box/IconMake/IconMake/README.md | 13 ++ box/IconMake/IconMake/assets/html/canvas.html | 10 ++ box/IconMake/IconMake/assets/icon.png | Bin 0 -> 915 bytes box/IconMake/IconMake/config.json | 23 +++ box/IconMake/IconMake/main.js | 13 ++ box/IconMake/IconMake/scripts/const.js | 153 ++++++++++++++++++ box/IconMake/IconMake/strings/en.strings | 2 + box/IconMake/IconMake/strings/zh-Hans.strings | 2 + 8 files changed, 216 insertions(+) create mode 100644 box/IconMake/IconMake/README.md create mode 100644 box/IconMake/IconMake/assets/html/canvas.html create mode 100644 box/IconMake/IconMake/assets/icon.png create mode 100644 box/IconMake/IconMake/config.json create mode 100644 box/IconMake/IconMake/main.js create mode 100644 box/IconMake/IconMake/scripts/const.js create mode 100644 box/IconMake/IconMake/strings/en.strings create mode 100644 box/IconMake/IconMake/strings/zh-Hans.strings 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 0000000000000000000000000000000000000000..c9685f4ffd41eb9e2842cf401540d9f753878be9 GIT binary patch literal 915 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY3?!3`olAjKOMp*^E09i4PftilNK8!3&(DW2 zfb6WSthBVWNs}f4*+2jhPfkt-G9c`vq@~A(*;T#=a@L>!z2AOxh`NW3XAFWb zf3@@}nw4BwD;=U@Y~soK;r*hF6^`xsFK*T~%sd$HgxjgYS~K#R(ii7>=O5+w_*bI*-qLzOihsqoJJB)!Vy3F? zoHj$>edZz$@x2WlEToijnr_-VJoLbD~?eoT-PulnToXIr?pzK6;kmE4#m@@Ea%i}QZ*rj;9iiQ#lg zd$!YMhQ=o!8{0>Y>8iP*bNnYazg+ioW8wVEmll+i-&OlE?~HiNmxW&ZX?=l$f9kDGA+HxXgx)`7QHrd}RXKh^&-L8}NKJ!3Z*JMFa%?%>&*`0IVPuear zZ~gU6MxrZ@g?80U@R;xK|0Hv-l2_2v|GTqye%5W80eRy|L`l)%je0GeXd5YCRRO>65_dkx;{E%(#rOpH*X)f zs7Bk**4z+XFMe9}v&NAHDPQGF-Jc2l+$S*Qg8#9OKlXKu);VjcE?(JS1WeTop00i_ I>zopr02YR#W&i*H literal 0 HcmV?d00001 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