|
| 1 | +/* |
| 2 | + * Pixel2CPP - Editor Tab Component |
| 3 | + * |
| 4 | + * MIT License |
| 5 | + * Copyright (c) 2025 CodeRandom |
| 6 | + * |
| 7 | + * This software is provided free of charge for educational and personal use. |
| 8 | + * Commercial use and redistribution must comply with the MIT License terms. |
| 9 | + */ |
| 10 | + |
| 11 | +import React from "react"; |
| 12 | +import PixelCanvas from "./PixelCanvas.jsx"; |
| 13 | + |
| 14 | +/** |
| 15 | + * Editor Tab component containing the main canvas editor interface |
| 16 | + * |
| 17 | + * @param {Object} props - Component props |
| 18 | + * @param {number} props.w - Canvas width |
| 19 | + * @param {number} props.h - Canvas height |
| 20 | + * @param {number} props.zoom - Zoom level |
| 21 | + * @param {Array} props.data - Pixel data array |
| 22 | + * @param {string} props.backgroundColor - Background color setting |
| 23 | + * @param {string} props.tool - Current active tool |
| 24 | + * @param {string} props.drawMode - Current draw mode |
| 25 | + * @param {Function} props.handleMouseDown - Mouse down handler |
| 26 | + * @param {Function} props.handleMouseMove - Mouse move handler |
| 27 | + * @param {Function} props.handleMouseUp - Mouse up handler |
| 28 | + */ |
| 29 | +export default function EditorTab({ |
| 30 | + w, |
| 31 | + h, |
| 32 | + zoom, |
| 33 | + data, |
| 34 | + backgroundColor, |
| 35 | + tool, |
| 36 | + drawMode, |
| 37 | + handleMouseDown, |
| 38 | + handleMouseMove, |
| 39 | + handleMouseUp |
| 40 | +}) { |
| 41 | + return ( |
| 42 | + <div className="space-y-4"> |
| 43 | + {/* Canvas Container */} |
| 44 | + <div className="bg-neutral-900 rounded-2xl p-4 overflow-auto inline-block shadow-xl border border-neutral-700"> |
| 45 | + <PixelCanvas |
| 46 | + width={w} |
| 47 | + height={h} |
| 48 | + zoom={zoom} |
| 49 | + pixels={data} |
| 50 | + backgroundColor={backgroundColor} |
| 51 | + cursor={tool === "eyedropper" ? "crosshair" : "pointer"} |
| 52 | + onPointerDown={handleMouseDown} |
| 53 | + onPointerMove={handleMouseMove} |
| 54 | + onPointerUp={handleMouseUp} |
| 55 | + /> |
| 56 | + </div> |
| 57 | + |
| 58 | + {/* Canvas Info */} |
| 59 | + <div className="bg-neutral-900/50 rounded-xl p-4 border border-neutral-700"> |
| 60 | + <div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-sm"> |
| 61 | + <div className="text-center"> |
| 62 | + <div className="text-neutral-400">Canvas Size</div> |
| 63 | + <div className="font-mono text-white">{w} × {h} px</div> |
| 64 | + </div> |
| 65 | + <div className="text-center"> |
| 66 | + <div className="text-neutral-400">Zoom Level</div> |
| 67 | + <div className="font-mono text-white">{zoom}×</div> |
| 68 | + </div> |
| 69 | + <div className="text-center"> |
| 70 | + <div className="text-neutral-400">Active Tool</div> |
| 71 | + <div className="font-medium text-emerald-400 capitalize">{tool}</div> |
| 72 | + </div> |
| 73 | + <div className="text-center"> |
| 74 | + <div className="text-neutral-400">Draw Mode</div> |
| 75 | + <div className="font-mono text-blue-400 text-xs">{drawMode}</div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + </div> |
| 79 | + |
| 80 | + {/* Keyboard Shortcuts Help */} |
| 81 | + <div className="bg-neutral-900/50 rounded-xl p-4 border border-neutral-700"> |
| 82 | + <h3 className="font-medium text-sm mb-3">Keyboard Shortcuts</h3> |
| 83 | + <div className="grid grid-cols-2 md:grid-cols-4 gap-4 text-xs"> |
| 84 | + <div className="space-y-1"> |
| 85 | + <div className="flex justify-between"> |
| 86 | + <span className="text-neutral-400">B:</span> |
| 87 | + <span className="font-mono text-white">Brush</span> |
| 88 | + </div> |
| 89 | + <div className="flex justify-between"> |
| 90 | + <span className="text-neutral-400">E:</span> |
| 91 | + <span className="font-mono text-white">Erase</span> |
| 92 | + </div> |
| 93 | + <div className="flex justify-between"> |
| 94 | + <span className="text-neutral-400">F:</span> |
| 95 | + <span className="font-mono text-white">Fill</span> |
| 96 | + </div> |
| 97 | + </div> |
| 98 | + <div className="space-y-1"> |
| 99 | + <div className="flex justify-between"> |
| 100 | + <span className="text-neutral-400">I:</span> |
| 101 | + <span className="font-mono text-white">Eyedropper</span> |
| 102 | + </div> |
| 103 | + <div className="flex justify-between"> |
| 104 | + <span className="text-neutral-400">C:</span> |
| 105 | + <span className="font-mono text-white">Clear</span> |
| 106 | + </div> |
| 107 | + <div className="flex justify-between"> |
| 108 | + <span className="text-neutral-400">X:</span> |
| 109 | + <span className="font-mono text-white">Swap Colors</span> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + <div className="space-y-1"> |
| 113 | + <div className="flex justify-between"> |
| 114 | + <span className="text-neutral-400">Ctrl+Z:</span> |
| 115 | + <span className="font-mono text-white">Undo</span> |
| 116 | + </div> |
| 117 | + <div className="flex justify-between"> |
| 118 | + <span className="text-neutral-400">Ctrl+Y:</span> |
| 119 | + <span className="font-mono text-white">Redo</span> |
| 120 | + </div> |
| 121 | + <div className="flex justify-between"> |
| 122 | + <span className="text-neutral-400">Ctrl++:</span> |
| 123 | + <span className="font-mono text-white">Zoom In</span> |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + <div className="space-y-1"> |
| 127 | + <div className="flex justify-between"> |
| 128 | + <span className="text-neutral-400">Ctrl+-:</span> |
| 129 | + <span className="font-mono text-white">Zoom Out</span> |
| 130 | + </div> |
| 131 | + <div className="flex justify-between"> |
| 132 | + <span className="text-neutral-400">Ctrl+0:</span> |
| 133 | + <span className="font-mono text-white">Reset Zoom</span> |
| 134 | + </div> |
| 135 | + <div className="flex justify-between"> |
| 136 | + <span className="text-neutral-400">RMB:</span> |
| 137 | + <span className="font-mono text-white">Secondary Color</span> |
| 138 | + </div> |
| 139 | + </div> |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + </div> |
| 143 | + ); |
| 144 | +} |
0 commit comments