forked from espruino/BangleApps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dane_arwes.js
118 lines (99 loc) · 2.68 KB
/
dane_arwes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright (c) 2020 OmegaRogue. See the file LICENSE for copying permission. */
/*
Graphics Functions based on the React Sci-Fi UI Framework Arwes
Take a look at README.md for hints on developing with this library.
*/
var C = {
cornerSize: 14, // description
cornerOffset: 3, // description
borderWidth: 1 // description
};
function Arwes(cornerSize, cornerOffset) {
this.cornerSize = cornerSize;
this.cornerOffset = cornerOffset;
}
/** 'public' constants here */
Arwes.prototype.C = {
color: {
primary: {
base: "#26dafd",
light: "#8bebfe",
dark: "#029dbb"
},
secondary: {
base: "#df9527",
light: "#ecc180",
dark: "#8b5c15"
},
header: {
base: "#a1ecfb",
light: "#fff",
dark: "#3fd8f7"
},
control: {
base: "#acf9fb",
light: "#fff",
dark: "#4bf2f6"
},
success: {
base: "#00ff00",
light: "#6f6",
dark: "#090"
},
alert: {
base: "#ff0000",
light: "#f66",
dark: "#900"
},
disabled: {
base: "#999999",
light: "#ccc",
dark: "#666"
}
}
};
function drawCorner(obj, x, y, n) {
g.setColor(obj.C.color.primary.base);
let s1 = (n&1)?1:-1, s2 = (n&2)?1:-1;
const x1 = x + obj.cornerOffset * s1;
const y1 = y + obj.cornerOffset * s2;
g.fillRect(x1, y1, x - obj.cornerSize*s1 + obj.cornerOffset*s1, y);
g.fillRect(x1, y1, x, y - obj.cornerSize*s2 + obj.cornerOffset*s2);
}
Arwes.prototype.drawFrameNoCorners = function (x1, y1, x2, y2) {
g.setColor(this.C.color.primary.dark);
g.drawRect(x1, y1, x2, y2);
}
Arwes.prototype.drawFrame = function (x1, y1, x2, y2) {
drawCorner(this, x1, y1, 0);
drawCorner(this, x2, y1, 1);
drawCorner(this, x1, y2, 2);
drawCorner(this, x2, y2, 3);
this.drawFrameNoCorners(x1, y1, x2, y2);
}
Arwes.prototype.drawFrameBottomCorners = function (x1, y1, x2, y2) {
drawCorner(this, x1, y2, 2);
drawCorner(this, x2, y2, 3);
this.drawFrameNoCorners(x1, y1, x2, y2);
}
Arwes.prototype.drawFrameTopCorners = function (x1, y1, x2, y2) {
drawCorner(this, x1, y1, 0);
drawCorner(this, x2, y1, 1);
this.drawFrameNoCorners(x1, y1, x2, y2);
}
Arwes.prototype.drawFrameLeftCorners = function (x1, y1, x2, y2) {
drawCorner(this, x1, y1, 0);
drawCorner(this, x1, y2, 2);
this.drawFrameNoCorners(x1, y1, x2, y2);
}
Arwes.prototype.drawFrameRightCorners = function (x1, y1, x2, y2) {
drawCorner(this, x2, y1, 1);
drawCorner(this, x2, y2, 3);
this.drawFrameNoCorners(x1, y1, x2, y2);
}
exports.create = function (cornerSize, cornerOffset) {
return new Arwes(cornerSize, cornerOffset);
};
exports.default = function () {
return new Arwes(C.cornerSize, C.cornerOffset);
};