This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
palette.htm
140 lines (123 loc) · 3.88 KB
/
palette.htm
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<html>
<head>
<title>Pick Sight Color</title>
<style>
html, body {
size: *;
background: white;
margin: 0;
padding: 0;
margin-top: 15dip;
}
widget[type=hsv] {
var(hue): #ff0000;
prototype: HSVSelector;
display: block;
size: max-content;
}
widget[type=hsv]>input.hue {
display: block;
border: none;
height: 3dip;
width: 182dip;
margin: 0 *;
background: linear-gradient(to right, #ff0000 0%, #ffff00 17%, #00ff00 33%, #00ffff 50%, #0000ff 67%, #ff00ff 83%, #ff0000 100%);
}
widget[type=hsv]>div.layers {
size: 180dip;
flow: stack;
margin: *;
}
widget[type=hsv]>div.layers>div.value {
size: *;
background: linear-gradient(to bottom, rgba(0, 0, 0, 0.0) 0%, rgba(0, 0, 0, 0.0) 1%, rgba(0, 0, 0, 1.0) 100%);
}
widget[type=hsv]>div.layers>div.saturation {
size: *;
background: linear-gradient(to right, color(hue) 0%, #ffffff 100%);
}
widget[type=hsv]>div.layers>div.pointer {
border: 2dip solid #fff;
size: 7dip;
transform: translate(-50%, -50%);
border-radius: 50%;
}
</style>
<script type="text/tiscript">
function self.ready() {
const w = 200dip;
const h = 240dip;
const (sw, sh) = view.screenBox(#frame, #dimension);
view.move((sw / 2) - (w / 2), (sh / 2) - (h / 2), w, h, true);
view.windowResizable = false;
}
var dragging = false;
$(widget[type=hsv]) << event mousedown {
dragging = 1;
}
$(widget[type=hsv]) << event mouseup {
dragging = 0;
}
$(widget[type=hsv]) << event mouseleave {
dragging = 0;
}
class HSVSelector: Element
{
this var hue = 0; // 0..360
this var val = 0.0; // 0..1.0
this var sat = 0.0; // 0..1.0
function attached() {
var me = this;
$(div.value) << event mousemove(evt) {
if (!dragging) return;
var (w,h) = this.box(#dimension);
me.val = 1.0 - (evt.y + 0.5) / h.toFloat();
me.sat = 1.0 - (evt.x + 0.5) / w.toFloat();
me.postEvent("change");
me.$(div.pointer).style.set {
margin-left: evt.x,
margin-top: evt.y,
};
};
$(div.value) << event mousedown(evt) {
var (w,h) = this.box(#dimension);
me.val = 1.0 - (evt.y + 0.5) / h.toFloat();
me.sat = 1.0 - (evt.x + 0.5) / w.toFloat();
me.postEvent("change");
me.$(div.pointer).style.set {
margin-left: evt.x,
margin-top: evt.y,
};
};
}
event change $(input.hue) (evt, elHue) {
this.hue = elHue.value;
var color = Color.hsv(this.hue,1,1);
this.style.variable("hue", color);
this.postEvent("change");
}
property value(v) {
get return Color.hsv( this.hue, this.sat, this.val );
set {
// left as an exercise for the reader
}
}
}
event change $(widget#color) {
$(#out).text = this.value.toString();
view.parameters.callbacks.changeColor(this.value);
}
</script>
</head>
<body>
<widget |hsv #color>
<div .layers>
<div .saturation />
<div .value />
<div .pointer />
</div>
<input |hslider .hue min=0 max=360 />
</widget>
<center><div #out></div></center>
</body>
</html>