MCPcopy Index your code
hub / github.com/SasPes/key-decoding / drawKeyShape

Function drawKeyShape

KeyDecoding.js:337–381  ·  view source on GitHub ↗
(x, y, width, height, color, pinCount, pins, keyType)

Source from the content-addressed store, hash-verified

335}
336
337function drawKeyShape(x, y, width, height, color, pinCount, pins, keyType) {
338 var keyConfig = keys[keyType] || {};
339
340 var pinSpacing = keyConfig.pinSpacing || 31;
341 var maxKeyCut = keyConfig.maxKeyCut || 9;
342 var flatSpotWidth = keyConfig.flatSpotWidth || 5;
343 var cutDepthOffset = keyConfig.cutDepthOffset || 5;
344 var zeroCutOffset = keyConfig.zeroCutOffset || 0;
345 var dipShapes = generateDipShapes(pinSpacing, maxKeyCut, flatSpotWidth, cutDepthOffset, zeroCutOffset);
346
347 var edgeOffsetX = keyConfig.edgeOffsetX || 0;
348 var edgeOffsetY = keyConfig.edgeOffsetY || 0;
349
350 for (var px = Math.round(x); px <= Math.round(x + width + pinSpacing / 2); px++) {
351 var py = y;
352 for (var i = 0; i < pinCount; i++) {
353 var pinValue = pins && pins[i];
354 var dipShape = dipShapes[pinValue];
355 if (dipShape) {
356 var dipWidth = dipShape.length;
357 var pinCenter = Math.round(x + (i + 1) * pinSpacing);
358 var dipStart = pinCenter - Math.floor(dipWidth / 2);
359 var dipEnd = pinCenter + Math.floor(dipWidth / 2);
360 if (px >= dipStart && px < dipEnd) {
361 var dipIdx = px - dipStart;
362 py = y + dipShape[dipIdx];
363 break;
364 }
365 }
366 }
367 display.drawPixel(px, py, color);
368 }
369
370 var edgeX = x + width + pinSpacing / 2 + edgeOffsetX;
371 var edgeY = y + height + edgeOffsetY;
372 var diagLength = 30;
373 var diagBottomX = edgeX + diagLength;
374 var diagBottomY = edgeY - diagLength;
375
376 // Draw diagonals
377 display.drawLine(edgeX, edgeY, diagBottomX, diagBottomY, color); // bottom-right diagonal
378
379 // Draw straight bottom edge
380 display.drawLine(x, edgeY, edgeX, edgeY, color);
381}
382
383function drawPinsWithUnderline(pins, selectedPinIndex, showMode, pinSpacing, keyType) {
384 if (keys[keyType] && keys[keyType].isDiskDetainer) {

Callers 1

drawPinsWithUnderlineFunction · 0.85

Calls 1

generateDipShapesFunction · 0.85

Tested by

no test coverage detected