Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions box/IconMake/IconMake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
18/12/07
0.0.2

* 将非安装包格式转移至安装包格式,尝试重构ui和代码
* 字符本地化,函数改善。(修改compare函数以准备未来从input或slider输入颜色)

0.0.3

* 本地化字符

0.0.4

* 分离常量
10 changes: 10 additions & 0 deletions box/IconMake/IconMake/assets/html/canvas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Icon</title>
</head>
<body>
<canvas></canvas>
</body>
</html>
Binary file added box/IconMake/IconMake/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions box/IconMake/IconMake/config.json
Original file line number Diff line number Diff line change
@@ -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": ""
}
}
13 changes: 13 additions & 0 deletions box/IconMake/IconMake/main.js
Original file line number Diff line number Diff line change
@@ -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);
153 changes: 153 additions & 0 deletions box/IconMake/IconMake/scripts/const.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions box/IconMake/IconMake/strings/en.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"select"="select";
"save"="save";
2 changes: 2 additions & 0 deletions box/IconMake/IconMake/strings/zh-Hans.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"select"="选择";
"save"="存储";