-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormTiles.cs
More file actions
335 lines (269 loc) · 9.51 KB
/
Copy pathFormTiles.cs
File metadata and controls
335 lines (269 loc) · 9.51 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
using RetroDevStudio;
using RetroDevStudio.Displayer;
using RetroDevStudio.Formats;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Configuration;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static ElementEditor.Project;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
namespace ElementEditor
{
public partial class FormTiles : Form
{
private Project m_Project;
private Project.Screen m_Screen;
private int m_UsedCharsetIndex = -1;
public event EventHandler TileSelected;
public event EventHandler FallingTilesModified;
public event EventHandler Modified;
public int SelectedTileIndex
{
get
{
return listTiles.SelectedIndex;
}
}
public FormTiles()
{
InitializeComponent();
}
internal void UpdateTiles( Project Project, Project.Screen Screen, bool ForceUpdate = false )
{
m_Project = Project;
m_Screen = Screen;
if ( m_Screen == null )
{
return;
}
if ( ( m_UsedCharsetIndex == m_Screen.CharsetIndex )
&& ( !ForceUpdate ) )
{
// no changes
listFallingTiles.BeginUpdate();
listFallingTiles.Items.Clear();
foreach ( var item in m_Screen.FallingTiles )
{
if ( ( item == 254 )
|| ( item == 0 ) )
{
// special items have no bitmap!
listFallingTiles.Items.Add( new Tuple<byte, Bitmap>( item, null ) );
}
else
{
listFallingTiles.Items.Add( new Tuple<byte, Bitmap>( item, (Bitmap)listTiles.Items[item] ) );
}
}
listFallingTiles.EndUpdate();
return;
}
m_UsedCharsetIndex = m_Screen.CharsetIndex;
listTiles.BeginUpdate();
listTiles.Items.Clear();
CharsetProject charSet = m_Project.Charsets[m_Screen.CharsetIndex];
var charsetInfo = m_Project.CharsetProjects[m_Screen.CharsetIndex];
foreach ( var element in Project.Elements )
{
var memoryImage = new GR.Image.MemoryImage( element.Characters.Width * 8, element.Characters.Height * 8, GR.Drawing.PixelFormat.Format32bppRgb );
for ( int i = 0; i < element.Characters.Width; ++i )
{
for ( int j = 0; j < element.Characters.Height; ++j )
{
if ( charSet != null )
{
CharacterDisplayer.DisplayChar( charSet, element.Characters[i, j].Char, memoryImage, i * 8, j * 8,
element.Characters[i, j].Color,
charSet.Colors.BackgroundColor,
charSet.Colors.MultiColor1,
charSet.Colors.MultiColor2,
charSet.Colors.BGColor4,
charsetInfo.Multicolor ? TextCharMode.COMMODORE_MULTICOLOR : TextCharMode.COMMODORE_HIRES );
}
}
}
listTiles.Items.Add( memoryImage.GetAsBitmap() );
}
if ( Project.Screens.Count > 0 )
{
listTiles.ItemHeight = Project.Screens[0].TileHeight * 2 * 8;
listFallingTiles.ItemHeight = Project.Screens[0].TileHeight * 2 * 8;
}
listFallingTiles.BeginUpdate();
listFallingTiles.Items.Clear();
foreach ( var item in m_Screen.FallingTiles )
{
if ( ( item == 254 )
|| ( item == 0 ) )
{
// special items have no bitmap!
listFallingTiles.Items.Add( new Tuple<byte, Bitmap>( item, null ) );
}
else
{
listFallingTiles.Items.Add( new Tuple<byte, Bitmap>( item, (Bitmap)listTiles.Items[item] ) );
}
}
listFallingTiles.EndUpdate();
listTiles.EndUpdate();
}
private void listTiles_DrawItem( object sender, DrawItemEventArgs e )
{
if ( e.Index != -1 )
{
var bmp = (Bitmap)listTiles.Items[e.Index];
e.DrawBackground();
var bounds = new Rectangle( e.Bounds.Left, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1 );
if ( bounds.Width > listTiles.ItemHeight )
{
bounds.Width = listTiles.ItemHeight;
}
e.Graphics.DrawImage( bmp, bounds );
if ( ( e.State & DrawItemState.Selected ) != 0 )
{
e.Graphics.DrawRectangle( new Pen( Color.Aqua, 1 ), bounds );
}
}
else
{
e.DrawBackground();
}
}
private void listTiles_SelectedIndexChanged( object sender, EventArgs e )
{
TileSelected?.Invoke( this, e );
}
private void listTiles_MouseDoubleClick( object sender, MouseEventArgs e )
{
if ( listTiles.SelectedIndex != -1 )
{
if ( listFallingTiles.Items.Count < 256 )
{
// do not allow empty, border and cherry
if ( ( listTiles.SelectedIndex != 0 )
&& ( listTiles.SelectedIndex != 3 )
&& ( listTiles.SelectedIndex != 12 ) )
{
listFallingTiles.Items.Add( new Tuple<byte, Bitmap>( (byte)listTiles.SelectedIndex, (Bitmap)listTiles.Items[listTiles.SelectedIndex] ) );
FallingTilesModified?.Invoke( this, e );
}
}
}
}
private void listFallingTiles_DrawItem( object sender, DrawItemEventArgs e )
{
if ( e.Index != -1 )
{
var item = (Tuple<byte,Bitmap>)listFallingTiles.Items[e.Index];
var bmp = item.Item2;
e.DrawBackground();
var bounds = new Rectangle( e.Bounds.Left, e.Bounds.Top, e.Bounds.Width - 1, e.Bounds.Height - 1 );
if ( bounds.Width > listFallingTiles.ItemHeight )
{
bounds.Width = listFallingTiles.ItemHeight;
}
if ( item.Item1 == 254 )
{
e.Graphics.DrawString( "RAND", e.Font, SystemBrushes.WindowText, bounds );
}
else if ( item.Item1 == 0 )
{
e.Graphics.DrawString( "END", e.Font, SystemBrushes.WindowText, bounds );
}
else
{
e.Graphics.DrawImage( bmp, bounds );
}
if ( ( e.State & DrawItemState.Selected ) != 0 )
{
e.Graphics.DrawRectangle( new Pen( Color.Aqua, 1 ), bounds );
}
}
else
{
e.DrawBackground();
}
}
private void listFallingTiles_SelectedIndexChanged( object sender, EventArgs e )
{
btnShiftDown.Enabled = ( ( listFallingTiles.SelectedIndex != -1 )
&& ( listFallingTiles.SelectedIndex + 1 < listFallingTiles.Items.Count ) );
btnShiftUp.Enabled = ( listFallingTiles.SelectedIndex > 0 );
btnDelete.Enabled = listFallingTiles.SelectedIndex != -1;
btnCopy.Enabled = listFallingTiles.SelectedIndex != -1;
}
private void btnShiftUp_Click( object sender, EventArgs e )
{
if ( listFallingTiles.SelectedIndex > 0 )
{
listFallingTiles.BeginUpdate();
int index1 = listFallingTiles.SelectedIndex - 1;
int index2 = listFallingTiles.SelectedIndex;
var item1 = listFallingTiles.Items[index1];
var item2 = listFallingTiles.Items[index2];
listFallingTiles.Items.RemoveAt( index2 );
listFallingTiles.Items.Insert( index1, item2 );
listFallingTiles.SelectedIndex = index1;
listFallingTiles.EndUpdate();
FallingTilesModified?.Invoke( this, e );
}
}
private void btnShiftDown_Click( object sender, EventArgs e )
{
if ( listFallingTiles.SelectedIndex + 1 < listFallingTiles.Items.Count )
{
listFallingTiles.BeginUpdate();
int index1 = listFallingTiles.SelectedIndex;
int index2 = listFallingTiles.SelectedIndex + 1;
var item1 = listFallingTiles.Items[index1];
var item2 = listFallingTiles.Items[index2];
listFallingTiles.Items.RemoveAt( index2 );
listFallingTiles.Items.Insert( index1, item2 );
listFallingTiles.SelectedIndex = index2;
listFallingTiles.EndUpdate();
FallingTilesModified?.Invoke( this, e );
}
}
private void btnDelete_Click( object sender, EventArgs e )
{
if ( listFallingTiles.SelectedIndex != -1 )
{
listFallingTiles.Items.RemoveAt( listFallingTiles.SelectedIndex );
FallingTilesModified?.Invoke( this, e );
}
}
private void btnCopy_Click( object sender, EventArgs e )
{
if ( ( listFallingTiles.SelectedIndex != -1 )
&& ( listFallingTiles.Items.Count < 256 ) )
{
listFallingTiles.Items.Add( listFallingTiles.Items[listFallingTiles.SelectedIndex] );
FallingTilesModified?.Invoke( this, e );
}
}
private void btnRandom_Click( object sender, EventArgs e )
{
if ( listFallingTiles.Items.Count < 256 )
{
listFallingTiles.Items.Add( new Tuple<byte, Bitmap>( 254, null ) );
FallingTilesModified?.Invoke( this, e );
}
}
private void btnEnd_Click( object sender, EventArgs e )
{
if ( listFallingTiles.Items.Count < 256 )
{
listFallingTiles.Items.Add( new Tuple<byte, Bitmap>( 0, null ) );
FallingTilesModified?.Invoke( this, e );
}
}
}
}