@@ -6,7 +6,7 @@ interface |
| 6 |
|
6 |
|
| 7 |
uses |
7 |
uses |
| 8 |
Classes, SysUtils, Controls, Graphics, Constants, LCLType, math, |
8 |
Classes, SysUtils, Controls, Graphics, Constants, LCLType, math, |
| 9 |
LCLIntf, LMessages, ClipboardUtils, Clipbrd, HugeDatatypes; |
9 |
LCLIntf, LMessages, ClipboardUtils, HugeDatatypes; |
| 10 |
|
10 |
|
| 11 |
const |
11 |
const |
| 12 |
clMisc = clMaroon; |
12 |
clMisc = clMaroon; |
@@ -16,7 +16,7 @@ const |
| 16 |
clSong = clRed; |
16 |
clSong = clRed; |
| 17 |
|
17 |
|
| 18 |
type |
18 |
type |
| 19 |
TCellPart = (cpNote, cpInstrument, cpEffect); |
19 |
TCellPart = (cpNote, cpInstrument, cpVolume, cpEffect); |
| 20 |
|
20 |
|
| 21 |
TSelectionPos = record |
21 |
TSelectionPos = record |
| 22 |
X, Y: Integer; |
22 |
X, Y: Integer; |
@@ -30,12 +30,18 @@ type |
| 30 |
procedure Paint; override; |
30 |
procedure Paint; override; |
| 31 |
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); |
31 |
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); |
| 32 |
override; |
32 |
override; |
|
|
33 |
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override; |
|
|
34 |
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; |
|
|
35 |
|
| 33 |
procedure KeyDown(var Key: Word; Shift: TShiftState); override; |
36 |
procedure KeyDown(var Key: Word; Shift: TShiftState); override; |
| 34 |
|
37 |
|
| 35 |
procedure DoPaste(var Msg: TLMessage); message LM_PASTE; |
38 |
procedure DoPaste(var Msg: TLMessage); message LM_PASTE; |
| 36 |
procedure DoCopy(var Msg: TLMessage); message LM_COPY; |
39 |
procedure DoCopy(var Msg: TLMessage); message LM_COPY; |
| 37 |
procedure DoCut(var Msg: TLMessage); message LM_CUT; |
40 |
procedure DoCut(var Msg: TLMessage); message LM_CUT; |
| 38 |
|
41 |
|
|
|
42 |
procedure RenderSelectedArea; |
|
|
43 |
procedure ClampCursors; |
|
|
44 |
|
| 39 |
private |
45 |
private |
| 40 |
Cells: array[0..3, 0..63] of TCell; |
46 |
Cells: array[0..3, 0..63] of TCell; |
| 41 |
|
47 |
|
@@ -44,28 +50,27 @@ type |
| 44 |
CharHeight: Integer; |
50 |
CharHeight: Integer; |
| 45 |
CharWidth: Integer; |
51 |
CharWidth: Integer; |
| 46 |
|
52 |
|
| 47 |
CursorCell, OtherCell: TCell; |
53 |
MouseButtonDown: Boolean; |
|
|
54 |
Selecting: Boolean; |
| 48 |
|
55 |
|
| 49 |
procedure RenderRow(Row: Integer); |
56 |
procedure RenderRow(Row: Integer); |
| 50 |
procedure RenderCell(Cell: TCell); |
57 |
procedure RenderCell(Cell: TCell); |
| 51 |
|
58 |
|
| 52 |
function GetEffectColor(EffectCode: Integer): TColor; |
59 |
function GetEffectColor(EffectCode: Integer): TColor; |
| 53 |
function CellIndexToRect(X, Y: Integer): TRect; |
60 |
function SelectionsToRect(S1, S2: TSelectionPos): TRect; |
| 54 |
|
61 |
|
| 55 |
public |
62 |
public |
| 56 |
Cursor, Other: TSelectionPos; |
63 |
Cursor, Other: TSelectionPos; |
| 57 |
SelectedRow: Integer; |
64 |
SelectedRow: Integer; |
| 58 |
end; |
65 |
end; |
| 59 |
|
66 |
|
| 60 |
implementation |
67 |
const |
|
|
68 |
NotePosition = 0; |
|
|
69 |
InstrumentPosition = 3; |
|
|
70 |
VolumePosition = 5; |
|
|
71 |
EffectPosition = 8; |
| 61 |
|
72 |
|
| 62 |
function TTrackerGrid.CellIndexToRect(X, Y: Integer): TRect; |
73 |
implementation |
| 63 |
begin |
|
|
| 64 |
Result.Left := X*ColumnWidth; |
|
|
| 65 |
Result.Top := Y*RowHeight; |
|
|
| 66 |
Result.Width := ColumnWidth; |
|
|
| 67 |
Result.Height := RowHeight; |
|
|
| 68 |
end; |
|
|
| 69 |
|
74 |
|
| 70 |
{ TTrackerGrid } |
75 |
{ TTrackerGrid } |
| 71 |
|
76 |
|
@@ -101,7 +106,7 @@ end; |
| 101 |
procedure TTrackerGrid.Paint; |
106 |
procedure TTrackerGrid.Paint; |
| 102 |
var |
107 |
var |
| 103 |
I: Integer; |
108 |
I: Integer; |
| 104 |
P: TRect; |
109 |
R: TRect; |
| 105 |
begin |
110 |
begin |
| 106 |
inherited Paint; |
111 |
inherited Paint; |
| 107 |
|
112 |
|
@@ -128,19 +133,20 @@ begin |
| 128 |
end; |
133 |
end; |
| 129 |
end; |
134 |
end; |
| 130 |
|
135 |
|
| 131 |
P := CellIndexToRect(Cursor.X, Cursor.Y); |
136 |
{Canvas.Pen.Color := RGBToColor(169, 153, 122); |
| 132 |
with Cursor do begin |
137 |
Canvas.Pen.Width := 2; |
| 133 |
BitBlt( |
138 |
R := TRect.Create(0, 0, ColumnWidth+1, Height); |
| 134 |
Canvas.Handle, |
139 |
Canvas.Rectangle(R); |
| 135 |
P.Left, |
140 |
R := TRect.Create(ColumnWidth, 0, ColumnWidth, Height); |
| 136 |
P.Top, |
141 |
Canvas.Rectangle(R); |
| 137 |
P.Width, |
142 |
R := TRect.Create(ColumnWidth*2, 0, ColumnWidth, Height); |
| 138 |
P.Height, |
143 |
Canvas.Rectangle(R); |
| 139 |
Canvas.Handle, |
144 |
R := TRect.Create(ColumnWidth*3, 0, ColumnWidth, Height); |
| 140 |
P.Left, |
145 |
Canvas.Rectangle(R); |
| 141 |
P.Top, |
146 |
R := TRect.Create(ColumnWidth*4, 0, ColumnWidth, Height); |
| 142 |
DSTINVERT); |
147 |
Canvas.Rectangle(R);} |
| 143 |
end; |
148 |
|
|
|
149 |
RenderSelectedArea; |
| 144 |
end; |
150 |
end; |
| 145 |
|
151 |
|
| 146 |
procedure TTrackerGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, |
152 |
procedure TTrackerGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, |
@@ -150,6 +156,9 @@ var |
| 150 |
begin |
156 |
begin |
| 151 |
inherited MouseDown(Button, Shift, X, Y); |
157 |
inherited MouseDown(Button, Shift, X, Y); |
| 152 |
|
158 |
|
|
|
159 |
MouseButtonDown := True; |
|
|
160 |
Selecting := False; |
|
|
161 |
|
| 153 |
if not (csDesigning in ComponentState) and CanFocus then |
162 |
if not (csDesigning in ComponentState) and CanFocus then |
| 154 |
SetFocus; |
163 |
SetFocus; |
| 155 |
|
164 |
|
@@ -160,43 +169,122 @@ begin |
| 160 |
Y := SelectedRow; |
169 |
Y := SelectedRow; |
| 161 |
SelectedPart := []; |
170 |
SelectedPart := []; |
| 162 |
end; |
171 |
end; |
| 163 |
CursorCell := Cells[SelectedColumn, SelectedRow]; |
172 |
|
|
|
173 |
ClampCursors; |
|
|
174 |
Other := Cursor; |
|
|
175 |
|
| 164 |
Invalidate; |
176 |
Invalidate; |
| 165 |
end; |
177 |
end; |
| 166 |
|
178 |
|
|
|
179 |
procedure TTrackerGrid.MouseMove(Shift: TShiftState; X, Y: Integer); |
|
|
180 |
var |
|
|
181 |
SelectedRow, SelectedColumn: Integer; |
|
|
182 |
begin |
|
|
183 |
inherited MouseMove(Shift, X, Y); |
|
|
184 |
|
|
|
185 |
if MouseButtonDown then begin |
|
|
186 |
Selecting := True; |
|
|
187 |
SelectedRow := Round((Y/Height)*63); |
|
|
188 |
SelectedColumn := Round((X/Width)*4); |
|
|
189 |
with Other do begin |
|
|
190 |
X := SelectedColumn; |
|
|
191 |
Y := SelectedRow; |
|
|
192 |
SelectedPart := []; |
|
|
193 |
end; |
|
|
194 |
|
|
|
195 |
ClampCursors; |
|
|
196 |
|
|
|
197 |
Invalidate; |
|
|
198 |
end; |
|
|
199 |
end; |
|
|
200 |
|
|
|
201 |
procedure TTrackerGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X, |
|
|
202 |
Y: Integer); |
|
|
203 |
begin |
|
|
204 |
inherited MouseUp(Button, Shift, X, Y); |
|
|
205 |
|
|
|
206 |
MouseButtonDown := False; |
|
|
207 |
end; |
|
|
208 |
|
| 167 |
procedure TTrackerGrid.KeyDown(var Key: Word; Shift: TShiftState); |
209 |
procedure TTrackerGrid.KeyDown(var Key: Word; Shift: TShiftState); |
| 168 |
begin |
210 |
begin |
| 169 |
inherited KeyDown(Key, Shift); |
211 |
inherited KeyDown(Key, Shift); |
| 170 |
|
212 |
|
|
|
213 |
Selecting := False; |
|
|
214 |
|
| 171 |
case Key of |
215 |
case Key of |
| 172 |
VK_UP: SelectedRow -= 1; |
216 |
VK_UP: Cursor.Y -= 1; |
| 173 |
VK_DOWN: SelectedRow += 1; |
217 |
VK_DOWN: Cursor.Y += 1; |
|
|
218 |
VK_LEFT: Cursor.X -= 1; |
|
|
219 |
VK_RIGHT: Cursor.X += 1; |
|
|
220 |
else begin |
|
|
221 |
with Cells[Cursor.X, Cursor.Y] do begin |
|
|
222 |
Instrument := Random(20); |
|
|
223 |
EffectCode := Random($F); |
|
|
224 |
EffectParams := Random($FF); |
|
|
225 |
Note := NoteMap.Keys[Random(NoteMap.Count)]; |
|
|
226 |
end; |
|
|
227 |
end; |
| 174 |
end; |
228 |
end; |
| 175 |
|
229 |
|
| 176 |
SelectedRow := Min(63, Max(0, SelectedRow)); |
230 |
ClampCursors; |
|
|
231 |
SelectedRow := Cursor.Y; |
| 177 |
|
232 |
|
| 178 |
Invalidate |
233 |
Invalidate |
| 179 |
end; |
234 |
end; |
| 180 |
|
235 |
|
| 181 |
procedure TTrackerGrid.DoPaste(var Msg: TLMessage); |
236 |
procedure TTrackerGrid.DoPaste(var Msg: TLMessage); |
| 182 |
var |
|
|
| 183 |
C: TCell; |
|
|
| 184 |
X: TModplugClipboardCell; |
|
|
| 185 |
ClipboardBytes: array of Byte; |
|
|
| 186 |
begin |
237 |
begin |
| 187 |
ClipboardBytes := TEncoding.UTF8.GetBytes(Clipboard.AsText); |
|
|
| 188 |
Move(ClipboardBytes, X, sizeof(X)); |
|
|
| 189 |
C := ModplugToHuge(X); |
|
|
| 190 |
end; |
238 |
end; |
| 191 |
|
239 |
|
| 192 |
procedure TTrackerGrid.DoCopy(var Msg: TLMessage); |
240 |
procedure TTrackerGrid.DoCopy(var Msg: TLMessage); |
| 193 |
begin |
241 |
begin |
| 194 |
//writeln('copying'); |
|
|
| 195 |
end; |
242 |
end; |
| 196 |
|
243 |
|
| 197 |
procedure TTrackerGrid.DoCut(var Msg: TLMessage); |
244 |
procedure TTrackerGrid.DoCut(var Msg: TLMessage); |
| 198 |
begin |
245 |
begin |
| 199 |
//writeln('cutting'); |
246 |
end; |
|
|
247 |
|
|
|
248 |
procedure TTrackerGrid.RenderSelectedArea; |
|
|
249 |
var |
|
|
250 |
R: TRect; |
|
|
251 |
begin |
|
|
252 |
if Selecting then begin |
|
|
253 |
R := SelectionsToRect(Cursor, Other); |
|
|
254 |
|
|
|
255 |
with Cursor do begin; |
|
|
256 |
BitBlt( |
|
|
257 |
Canvas.Handle, |
|
|
258 |
R.Left, |
|
|
259 |
R.Top, |
|
|
260 |
R.Width, |
|
|
261 |
R.Height, |
|
|
262 |
Canvas.Handle, |
|
|
263 |
R.Left, |
|
|
264 |
R.Top, |
|
|
265 |
DSTINVERT); |
|
|
266 |
end; |
|
|
267 |
end |
|
|
268 |
else |
|
|
269 |
with Cursor do |
|
|
270 |
BitBlt( |
|
|
271 |
Canvas.Handle, |
|
|
272 |
Cursor.X*ColumnWidth, |
|
|
273 |
Cursor.Y*RowHeight, |
|
|
274 |
ColumnWidth, |
|
|
275 |
RowHeight, |
|
|
276 |
Canvas.Handle, |
|
|
277 |
Cursor.X*ColumnWidth, |
|
|
278 |
Cursor.Y*RowHeight, |
|
|
279 |
DSTINVERT); |
|
|
280 |
end; |
|
|
281 |
|
|
|
282 |
procedure TTrackerGrid.ClampCursors; |
|
|
283 |
begin |
|
|
284 |
Cursor.Y := Min(63, Max(0, Cursor.Y)); |
|
|
285 |
Cursor.X := Min(3, Max(0, Cursor.X)); |
|
|
286 |
Other.Y := Min(63, Max(0, Other.Y)); |
|
|
287 |
Other.X := Min(3, Max(0, Other.X)); |
| 200 |
end; |
288 |
end; |
| 201 |
|
289 |
|
| 202 |
procedure TTrackerGrid.RenderRow(Row: Integer); |
290 |
procedure TTrackerGrid.RenderRow(Row: Integer); |
@@ -228,7 +316,7 @@ begin |
| 228 |
|
316 |
|
| 229 |
if Cell.Instrument <> 0 then begin |
317 |
if Cell.Instrument <> 0 then begin |
| 230 |
Font.Color := clTeal; |
318 |
Font.Color := clTeal; |
| 231 |
TextOut(PenPos.X, PenPos.Y, IntToStr(Cell.Instrument)); |
319 |
TextOut(PenPos.X, PenPos.Y, FormatFloat('00', Cell.Instrument)); |
| 232 |
end |
320 |
end |
| 233 |
else begin |
321 |
else begin |
| 234 |
Font.Color := clGray; |
322 |
Font.Color := clGray; |
@@ -239,7 +327,7 @@ begin |
| 239 |
Font.Color := clGray; |
327 |
Font.Color := clGray; |
| 240 |
TextOut(PenPos.X, PenPos.Y, '...'); |
328 |
TextOut(PenPos.X, PenPos.Y, '...'); |
| 241 |
|
329 |
|
| 242 |
if Cell.EffectCode <> 0 then begin |
330 |
if (Cell.EffectCode <> 0) or (Cell.EffectParams <> 0) then begin |
| 243 |
Font.Color := GetEffectColor(Cell.EffectCode); |
331 |
Font.Color := GetEffectColor(Cell.EffectCode); |
| 244 |
TextOut( |
332 |
TextOut( |
| 245 |
PenPos.X, |
333 |
PenPos.X, |
@@ -277,5 +365,11 @@ begin |
| 277 |
end; |
365 |
end; |
| 278 |
end; |
366 |
end; |
| 279 |
|
367 |
|
|
|
368 |
function TTrackerGrid.SelectionsToRect(S1, S2: TSelectionPos): TRect; |
|
|
369 |
begin |
|
|
370 |
Result := TRect.Create(S1.X*ColumnWidth, S1.Y*RowHeight, S1.X*ColumnWidth + ColumnWidth, S1.Y*RowHeight + RowHeight); |
|
|
371 |
Result.Union(TRect.Create(S2.X*ColumnWidth, S2.Y*RowHeight, S2.X*ColumnWidth + ColumnWidth, S2.Y*RowHeight + RowHeight)); |
|
|
372 |
end; |
|
|
373 |
|
| 280 |
end. |
374 |
end. |
| 281 |
|
375 |
|