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

Function drawDiskKeyShape

KeyDecoding.js:416–468  ·  view source on GitHub ↗
(x, y, width, height, color, diskCount, disks, keyType)

Source from the content-addressed store, hash-verified

414}
415
416function drawDiskKeyShape(x, y, width, height, color, diskCount, disks, keyType) {
417 var keyConfig = keys[keyType] || {};
418 var pinSpacing = keyConfig.pinSpacing || 32;
419 var bladeHeight = keyConfig.bladeHeight || 45;
420 var bladeY = y + (height - bladeHeight) / 2;
421 var bladeBottom = bladeY + bladeHeight;
422
423 var diskCutDepths = [0, 2, 4, 8, 14, 21];
424
425 var entryX = x;
426 var entryY = bladeY;
427 var keyStartOffset = 20;
428 var keyStartX = entryX + keyStartOffset;
429
430 var currX = keyStartX;
431 var prevCutDepth = diskCutDepths[disks[0]] || 0;
432
433 // Connect left side: vertical from bottom to first cut
434 display.drawLine(currX, bladeBottom, currX, bladeBottom - prevCutDepth, color);
435
436 // Draw the first horizontal segment
437 display.drawLine(currX, bladeBottom - prevCutDepth, currX + pinSpacing, bladeBottom - prevCutDepth, color);
438
439 for (var i = 1; i < diskCount; i++) {
440 var cutIdx = disks[i] || 0;
441 var cutDepth = diskCutDepths[cutIdx] || 0;
442 var nextX = currX + pinSpacing;
443
444 // Draw vertical line connecting previous cut to current cut
445 display.drawLine(nextX, bladeBottom - prevCutDepth, nextX, bladeBottom - cutDepth, color);
446
447 // Draw horizontal line for current cut
448 display.drawLine(nextX, bladeBottom - cutDepth, nextX + pinSpacing, bladeBottom - cutDepth, color);
449
450 currX = nextX;
451 prevCutDepth = cutDepth;
452 }
453
454 // Draw end vertical (right side)
455 display.drawLine(currX + pinSpacing + 2, bladeBottom - prevCutDepth, currX + pinSpacing + 2, bladeY, color);
456
457 // Draw bottom edge (from entry to start of key)
458 display.drawLine(entryX, bladeBottom, entryX + keyStartOffset, bladeBottom, color);
459
460 // Draw top edge (from entry to start of key)
461 display.drawLine(entryX, entryY, currX + pinSpacing, bladeY, color);
462
463 // Diagonal from top-left to key start (top edge)
464 display.drawLine(30, bladeY - 10, entryX, bladeY, color);
465
466 // Diagonal from bottom-left to key start (bottom edge)
467 display.drawLine(30, bladeBottom + 10, entryX, bladeBottom, color);
468}
469
470function drawDisksWithUnderline(disks, selectedDiskIndex, showMode, pinSpacing, keyType) {
471 var startY = 55;

Callers 1

drawDisksWithUnderlineFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected