aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/catalogTrailer.txt
blob: 064fdd535c7ee013057d2128308b11361d84fcdb (plain)
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

var canvas
var context
var getFromWeb = true
var mouseDown = false
var scale = .6
var outset = 15
var columnWidth = 256
var maxHeight = 256
var lastLink = null
var lastLinkStr = null
var labelback = {}
var loadedImages = 0
var images = {}
var imagesLength = 0;

function recContains(rec, value) {
    if (!value.length)
        return 0
    var lc = value.toLowerCase()
    if (rec.name.toLowerCase().indexOf(lc) >= 0)
        return 1
    if (rec.code.toLowerCase().indexOf(lc) >= 0)
        return 2
    return 3
}

function setLink(recstr) {
    var under
    var link = recstr
    if (!link.startsWith("Sk")) {
        under = link.indexOf('_')
        link = link.substring(under + 1)
    }
    under = link.lastIndexOf('_')
    var len = link.length
    if (under == len - 2) {
        var letter = link[len - 1]
        if ('a' <= letter && letter <= 'z') {
            link = link.substr(0, len - 2)
        } else if ('0' <= letter && letter <= '9') {
            link = link.substr(0, len - 2)
        }
    }
    lastLinkStr = link
}

function showLink() {
    var link = lastLink.file + '#' + lastLinkStr
    context.save()
    context.font = "normal 16px Arial";
    labelback.w = Math.max(labelback.w, context.measureText(link).width + 8)
    context.beginPath()
    context.rect(labelback.x, labelback.y, labelback.w, labelback.h)
    context.fillStyle = "rgba(232,180,220, 1)"
    context.fill()
    context.fillStyle = "rgba(64,32,48, 1)"
    context.fillText(link, labelback.x + 4, labelback.y + 16)
    context.restore()
}

function imageIterator(callout, state) {
    var row = outset + 30
    var column = outset
    for (var recstr in pngs) {
        var rec = pngs[recstr]
        var contains = recContains(rec, input.value)
        if (3 == contains)
            continue;
        var height = rec.height < maxHeight ? rec.height : maxHeight
        if (callout(state, column, row, height, contains, recstr))
            break;
        row += height + outset
        if (row >= canvas.height / scale) {
            row = 0
            column += columnWidth + outset
            if (column >= canvas.width / scale) {
                break
            }
        }
    }
}

function handleMouseOver(event) {
    var callout = function(state, column, row, height, contains, recstr) {
        if (state.x >= column && state.x <= column + columnWidth &&
                state.y >= row && state.y <= row + height) {
            document.body.style.cursor = "pointer"
            lastLink = pngs[recstr]
            setLink(recstr)
            showLink()
            return true
        }
        return false
    }
    var state = {
        x: (event.clientX - 5) / scale,
        y: (event.clientY - 7) / scale
    }
    document.body.style.cursor = ""
    lastLink = null
    imageIterator(callout, state)
}

function handleMouseClick() {
    if (null != lastLink) {
        var link = 'https://skia.org/user/api/' + lastLink.file + '#' + lastLinkStr
        window.location = link
    }
}

function doKeyPress(evt) {
    idiv.style.height = 20
    input.focus()
}

function drawImage(hash, x, y, w, h, contains) {
    context.save()
    context.transform(scale, 0, 0, scale, 0, 0)
    context.save()
    context.beginPath()
    context.rect(x, y, w, h)
    context.clip()
    context.drawImage(images[hash], x, y)
    context.restore()
    context.beginPath()
    context.rect(x, y, w, h)
    context.strokeStyle = 1 == contains ? "red" : "black"
    context.stroke()
    context.restore()
}

function draw() {
    var callout = function(state, column, row, height, contains, recstr) {
        drawImage(pngs[recstr].hash, column, row, columnWidth, height, contains)
        return false
    }
    imageIterator(callout, null)
}

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function redraw() {
    context.strokeStyle = "white"
    context.beginPath()
    context.fillStyle = "white"
    context.rect(0, 30, canvas.width, canvas.height)
    context.fill()
    context.rect((256 + outset) * scale, 0, canvas.width, 30)
    context.fill()
    for (var image in images) {
        image.drawn = false
    }
    do {
        draw();
        if (loadedImages >= imagesLength)
            break;
        console.debug(" loadedImages:" + loadedImages + " imagesLength:" + imagesLength)
        await sleep(1000);
    } while (true)
}

function resize() {
    setSize()
    redraw()
}

function setSize() {
    canvas.width = window.innerWidth - 20
    canvas.height = window.innerHeight - 20
    labelback.x = 0
    labelback.y = canvas.height - 20
    labelback.w = 0
    labelback.h = 20
}

function loadImages() {
    for (var recstr in pngs) {
        var rec = pngs[recstr]
        var image = new Image()
        images[rec.hash] = image
        if (getFromWeb)
            image.src = 'https://fiddle.skia.org/i/'
        image.src += rec.hash + '_raster.png'
        image.onload = function () {
            loadedImages += 1
        }
        imagesLength += 1;
    }
}

function start() {
    loadImages()
    window.addEventListener('keypress', doKeyPress, true);
    window.addEventListener('keydown', doKeyPress, true);
    canvas = document.getElementById('canvas')
    context = canvas.getContext('2d')
    resize()
}

</script>
</head>

<body onLoad="start()" onresize="resize()">
<div style="height:0" id="idiv">
<input type="text" id="input" onkeypress="redraw()" onkeydown="redraw()"/>
</div>
<canvas id="canvas" width="750" height="500"
onmousedown="mouseDown = true"
onmouseup="mouseDown = false"
onmousemove="handleMouseOver(event)"
onclick="handleMouseClick()"
></canvas >
</body>
</html>