-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeatmapChartControlDX.cs
More file actions
799 lines (717 loc) · 30.8 KB
/
HeatmapChartControlDX.cs
File metadata and controls
799 lines (717 loc) · 30.8 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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
using DevExpress.XtraCharts;
using DevExpress.XtraCharts.Heatmap;
using DevExpress.XtraCharts.Native;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace GameOfLife
{
public partial class HeatmapChartControlDX : DevExpress.XtraEditors.XtraUserControl, IMessageFilterReceiver
{
#region Constants
int RECTANGULAR_ZOOM_CONTROL_MARGIN = 2;
#endregion
#region Fields
// HeatmapControl of DevExpress.
HeatmapControl heatmapControl;
Chart heatmapControlChart;
int[] xAxis;
int[] yAxis;
int[][] valuesToPlot;
int xStartIdx;
int xEndIdx;
int yStartIdx;
int yEndIdx;
int xStartPxls;
int xEndPxls;
int yStartPxls;
int yEndPxls;
int currentXIdxCoord;
int currentYIdxCoord;
bool isMouseDown;
bool isCtrlKeyPressed;
bool dataHasBeenUpdated;
bool isToPaint;
bool isCopyPasteInAction;
bool isRectangleCopyPasteSelectionActive;
MessageFilter message;
#endregion
#region Constructor
public HeatmapChartControlDX()
{
InitializeComponent();
CreateHeatMapControl();
// Create a MessageFilter Object.
message = new MessageFilter(this);
//Application.AddMessageFilter(message);
}
#endregion
#region Properties
/// <summary>
/// Set the X axis.
/// </summary>
public int[] XAxis
{
get { return this.xAxis; }
set
{
if (this.xAxis != value)
{
this.xAxis = value;
// Assign the new X axis ticks to the heatmap.
((MatrixDataAdapterExt)heatmapControl.DataAdapter).XArguments = this.xAxis;
}
}
}
/// <summary>
/// Set the Y axis.
/// </summary>
public int[] YAxis
{
get { return this.yAxis; }
set
{
if (this.yAxis != value)
{
this.yAxis = value;
// Assign the new Y axis ticks to the heatmap.
((MatrixDataAdapterExt)heatmapControl.DataAdapter).YArguments = this.yAxis;
}
}
}
/// <summary>
/// Set the Value to plot.
/// </summary>
public int[][] ValuesToPlot
{
get { return this.valuesToPlot; }
set
{
this.valuesToPlot = value;
//((HeatmapMatrixAdapter)heatmapControl.DataAdapter).Values = null;
// ---- Assign the new X axis ticks to the heatmap.
// Before convert the 0s and 1s of the jagged array into Colors.
int[][] colorsToPlot = ConvertValuesToColors(this.valuesToPlot);
// Only if the Y axis orientation of the matrix needs to be inverted.
// int[][] colorsToPlotInverted = InvertYAxisOrientation(colorsToPlot);
// Then convert the double jagged array into a 2D matrix.
double[,] colorsToPlotMatrix = ReshapeIntoMatrix(colorsToPlot);
if (colorsToPlotMatrix.GetLength(0) != this.yAxis.Length || colorsToPlotMatrix.GetLength(1) != this.xAxis.Length)
return;
// Now assign the new values to the HeatMap.
((MatrixDataAdapterExt)heatmapControl.DataAdapter).Values = colorsToPlotMatrix;
}
}
public bool DataHasBeenUpdated
{
get { return this.dataHasBeenUpdated; }
set
{
if (this.dataHasBeenUpdated != value)
{
this.dataHasBeenUpdated = value;
}
}
}
public bool IsCopyPasteInAction
{
get { return this.isCopyPasteInAction; }
set { this.isCopyPasteInAction = value; }
}
#endregion
#region Methods
private void CreateHeatMapControl()
{
// Cerate an instance of the DevExpress Heatmap Control.
heatmapControl = new HeatmapControl();
heatmapControlChart = ((IChartContainer)heatmapControl).Chart;
// Docking style of the heatmap control.
heatmapControl.Dock = DockStyle.Fill;
// Set the Appearance of the HeatMap Chart.
ChartAppearance();
// Add the heatmap to the Controls list.
this.Controls.Add(heatmapControl);
// Initialize the heatmap DataAdapter, which allows you to use collections of values to specify x-arguments and y-arguments, and pass a matrix of numeric values to define heatmap cell values.
heatmapControl.DataAdapter = new MatrixDataAdapterExt();
heatmapControl.MouseDown -= HeatmapControl_MouseDown;
heatmapControl.MouseDown += HeatmapControl_MouseDown;
heatmapControl.MouseMove -= HeatmapControl_MouseMove;
heatmapControl.MouseMove += HeatmapControl_MouseMove;
heatmapControl.MouseUp -= HeatmapControl_MouseUp;
heatmapControl.MouseUp += HeatmapControl_MouseUp;
heatmapControl.Paint -= HeatmapControl_Paint;
heatmapControl.Paint += HeatmapControl_Paint;
heatmapControl.KeyPress -= HeatmapControl_KeyPress;
heatmapControl.KeyPress += HeatmapControl_KeyPress;
heatmapControl.MouseClick += HeatmapControl_MouseClick;
}
/// <summary>
/// Define the appearance of the HeatMap Chart Control.
/// </summary>
private void ChartAppearance()
{
heatmapControlChart.Border.Visibility = DevExpress.Utils.DefaultBoolean.False;
heatmapControlChart.Padding.All = 0;
((XYDiagram)heatmapControlChart.Diagram).Margins.All = 0;
((XYDiagram)heatmapControlChart.Diagram).DefaultPane.BorderVisible = true;
heatmapControl.Diagram.BorderVisible = true;
heatmapControl.Diagram.BackColor = Color.Green;
heatmapControl.HighlightMode = HeatmapHighlightMode.Cell;
// Axis Visibility.
heatmapControl.AxisX.Title.Visibility = DevExpress.Utils.DefaultBoolean.False;
heatmapControl.AxisY.Title.Visibility = DevExpress.Utils.DefaultBoolean.False;
heatmapControl.AxisX.Visibility = DevExpress.Utils.DefaultBoolean.False;
heatmapControl.AxisY.Visibility = DevExpress.Utils.DefaultBoolean.False;
heatmapControl.AxisX.Label.Visible = false;
heatmapControl.AxisY.Label.Visible = false;
heatmapControl.AxisX.Tickmarks.Visible = false;
heatmapControl.AxisY.Tickmarks.Visible = false;
}
#endregion
#region Utility Methods
/// <summary>
/// Method for converting the numerical values of the valueToPlot matrix into Colors.
/// </summary>
/// <returns></returns>
private int[][] ConvertValuesToColors(int[][] valuesToPlotNumerical)
{
int[][] valuesToPlotColors = new int[valuesToPlotNumerical.Length][];
// Loop through all the values of the valuesToPlotNumerical and convert them to colors. For the moment Black and White.
for (int row = 0; row < valuesToPlotNumerical.Length; row++)
{
valuesToPlotColors[row] = new int[valuesToPlotNumerical[row].Length];
for (int col = 0; col < valuesToPlotNumerical[row].Length; col++)
{
// If the value is 1, then convert it to BLACK;
if (valuesToPlotNumerical[row][col] == 1)
{
valuesToPlotColors[row][col] = Color.Blue.ToArgb();
}
else if (valuesToPlotNumerical[row][col] == 2)
{
Color newColor = Color.FromArgb(245, 216, 224);
valuesToPlotColors[row][col] = newColor.ToArgb();
}
// If the value is 0, then convert it to LIGHT GRAY;
else
{
valuesToPlotColors[row][col] = Color.LightGray.ToArgb();
}
}
}
return valuesToPlotColors;
}
/// <summary>
/// Method used only when there is the need to invert the Y axis of the matrix.
/// </summary>
/// <param name="colorsToPlot"></param>
/// <returns></returns>
private int[][] InvertYAxisOrientation(int[][] colorsToPlot)
{
int[][] colorsToPlotInverted = new int[colorsToPlot.Length][];
for (int row = 0; row < colorsToPlot.Length; row++)
{
// Compute the new inverted index on the Y axis.
int newRowIdx = colorsToPlot.Length - 1 - row;
colorsToPlotInverted[newRowIdx] = colorsToPlot[row];
}
return colorsToPlotInverted;
}
/// <summary>
/// Method for reshaping the double jagged array into a 2D matrix.
/// </summary>
/// <param name="colorsToPlotJagged"></param>
/// <returns></returns>
private double[,] ReshapeIntoMatrix(int[][] colorsToPlotJagged)
{
double[,] colorsToPlotMatrix = new double[colorsToPlotJagged.Length, colorsToPlotJagged[0].Length];
for (int row = 0; row < colorsToPlotJagged.Length; row++)
{
for (int col = 0; col < colorsToPlotJagged[row].Length; col++)
{
colorsToPlotMatrix[row, col] = (double)colorsToPlotJagged[row][col];
}
}
return colorsToPlotMatrix;
}
public void ClearData()
{
// Re-Initialize the HeatMapControl Data Adapter.
heatmapControl.DataAdapter = new HeatmapMatrixAdapter();
}
#endregion
#region EventHandler
protected void RaiseHeatMapCellSelection(object sender, int x, int y, bool isFromRightClick)
{
HeatMapCellSelection?.Invoke(sender, new SelectedCellsEventArgs(x, y, isFromRightClick));
}
protected void RaiseHeatMapCopyPasteSelection(object sender, int xStart, int yStart, int xEnd, int yEnd)
{
HeatMapCopyPasteSelection?.Invoke(sender, new CopyPasteSelectionEventArgs(xStart, yStart, xEnd, yEnd));
}
private void RaiseHeatMapCopyPasteCtrlC(object sender, KeyPressEventArgs e)
{
HeatMapCopyPasteCtrlC?.Invoke(sender, e);
}
private void RaiseHeatMapCopyPasteCtrlV(object sender, int xIdx, int yIdx)
{
HeatMapCopyPasteCtrlV?.Invoke(sender, new CopyPasteCtrlVEventArgs(xIdx, yIdx));
}
private void RaiseHeatMapCopyPasteCtrlX(object sender, KeyPressEventArgs e)
{
HeatMapCopyPasteCtrlX?.Invoke(sender, e);
}
private void HeatmapControl_MouseDown(object sender, MouseEventArgs e)
{
// Set the boolean isMouseDown to True.
this.isMouseDown = true;
// Set the isToPaint bool to false, so that the copy paste highlighting square will disappear.
this.isToPaint = false;
// Check if the Ctrl key is pressed. If it is, then it means that we are selecting the area for the copy paste action.
if (ModifierKeys == Keys.Control)
{
this.isCtrlKeyPressed = true;
// Store the X and Y coordinates indexes.
HeatmapHitInfo mouseDownInfo = heatmapControl.CalcHitInfo(e.Location);
if (mouseDownInfo.Cell != null)
{
// Extract the X and Y indexes of the selected cell.
this.xStartIdx = (int)mouseDownInfo.Cell.XArgument;
this.yStartIdx = (int)mouseDownInfo.Cell.YArgument;
}
// Retrieve and also store the X and Y pixels coordinates of the starting point.
this.xStartPxls = e.X;
this.yStartPxls = e.Y;
this.xEndPxls = e.X;
this.yEndPxls = e.Y;
this.isToPaint = true;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Ways of listening the events that coming from buttons and actions. ///////////////////////////////////
//
// 1) ---- ModifierKeys
//
// if (ModifierKeys
// Keys.Control)
// {
// // Check if the ModifierKeys (the pressed key) is the Ctrl key.
// }
//
//
// 2) ---- Message Filter Class
//
// Application.AddMessageFilter(message);
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
}
private void HeatmapControl_MouseMove(object sender, MouseEventArgs e)
{
//this.isMouseMoving = true;
if (this.isMouseDown)
{
HeatmapHitInfo mouseMoveInfo = heatmapControl.CalcHitInfo(e.Location);
// First check if the Ctrl key is pressed.
if (ModifierKeys == Keys.Control)
{
// In this case the Ctrl key has been pressed while the mouse was down and moving (therefore the mouse was used for painting)
// Interrupt the paining and start the
if (this.isCtrlKeyPressed == false)
{
this.isCtrlKeyPressed = true;
this.isToPaint = true;
// Store the X and Y index coordinates as the starting ones.
// Sometimes can happen (if you select the cell in a specific position) that the xStartIdx and yStartIdx don't take the value of the clicked cell.
if (mouseMoveInfo.Cell != null || ((this.xStartPxls == 0 || this.yStartIdx == 0) && mouseMoveInfo.Cell != null))
{
// Extract the X and Y indexes of the selected cell.
this.xStartIdx = (int)mouseMoveInfo.Cell.XArgument;
this.yStartIdx = (int)mouseMoveInfo.Cell.YArgument;
}
// Retrieve and also store the X and Y pixels coordinates of the starting point.
// Do things for copy paste. Paint for the square.
//heatmapControl.Paint -= HeatmapControl_Paint;
//heatmapControl.Paint += HeatmapControl_Paint;
this.xStartPxls = e.X;
this.yStartPxls = e.Y;
this.xEndPxls = e.X;
this.yEndPxls = e.Y;
heatmapControl.Refresh();
//heatmapControl.Paint -= HeatmapControl_Paint;
}
else
{
// Always store the current X and Y index coordinates as the end ones. Just in case, even if I then save the final one at mouse up.
if (mouseMoveInfo.Cell != null || ((this.xEndPxls == 0 || this.yEndIdx == 0) && mouseMoveInfo.Cell != null))
{
// Extract the X and Y indexes of the selected cell.
this.xEndIdx = (int)mouseMoveInfo.Cell.XArgument;
this.yEndIdx = (int)mouseMoveInfo.Cell.YArgument;
}
//// Do things for copy paste. Paint for the square.
//heatmapControl.Paint -= HeatmapControl_Paint;
//heatmapControl.Paint += HeatmapControl_Paint;
this.xEndPxls = e.X;
this.yEndPxls = e.Y;
heatmapControl.Refresh();
//heatmapControl.Paint -= HeatmapControl_Paint;
}
}
// If it is not, then do action for the painting of the heatmap cell.
else
{
// If it enters in this else, means that the isCtrlKeyPressed is not pressed or has been released.
this.isCtrlKeyPressed = false;
if (mouseMoveInfo.Cell != null)
{
// Extract the X and Y indexes of the selected cell.
int x = (int)mouseMoveInfo.Cell.XArgument;
int y = (int)mouseMoveInfo.Cell.YArgument;
// Check if the mouse click event is coming from the right or left click on the mouse. If it comes from the right, means that we are erasing.
if (e.Button == MouseButtons.Right)
RaiseHeatMapCellSelection(this, x, y, true);
else
RaiseHeatMapCellSelection(this, x, y, false);
}
}
}
}
private void HeatmapControl_MouseUp(object sender, MouseEventArgs e)
{
if (this.isMouseDown)
{
HeatmapHitInfo mouseUpInfo = heatmapControl.CalcHitInfo(e.Location);
// If the Ctrl key is pressed, I'm selected the cells for the Copy Paste action.
if (this.isCtrlKeyPressed == true)
{
if (mouseUpInfo.Cell != null)
{
// Extract the X and Y indexes where the mouse click has been released.
this.xEndIdx = (int)mouseUpInfo.Cell.XArgument;
this.yEndIdx = (int)mouseUpInfo.Cell.YArgument;
}
heatmapControl.Refresh();
this.isCopyPasteInAction = true;
RaiseHeatMapCopyPasteSelection(this, this.xStartIdx, this.yStartIdx, this.xEndIdx, this.yEndIdx);
}
// Otherwise I'm painting the heatmap cells.
else
{
// If this command arrives when the rectangle for the copy paste selection is active, then just remove the rectangle.
if (this.isRectangleCopyPasteSelectionActive)
{
this.isRectangleCopyPasteSelectionActive = false;
//this.isMouseDown = false;
//this.isCtrlKeyPressed = false;
//return;
}
else
{
if (mouseUpInfo.Cell != null)
{
int x = (int)mouseUpInfo.Cell.XArgument;
int y = (int)mouseUpInfo.Cell.YArgument;
// Check if the mouse click event is coming from the right or left click on the mouse. If it comes from the right, means that we are erasing.
if (e.Button == MouseButtons.Right)
RaiseHeatMapCellSelection(this, x, y, true);
else
RaiseHeatMapCellSelection(this, x, y, false);
}
}
}
}
this.isMouseDown = false;
this.isCtrlKeyPressed = false;
//this.isToPaint = true;
}
private void HeatmapControl_Paint(object sender, PaintEventArgs e)
{
// If you want the red border to not disappear, then comment this isToPaint check.
if (this.isToPaint == false)
return;
this.isRectangleCopyPasteSelectionActive = true;
// Rectangle width and height.
float rectangleWidth = 0;
float rectangleHeight = 0;
// Rectangle X and Y starting point.
float xStartN = 0;
float yStartN = 0;
rectangleWidth = Math.Abs(this.xEndPxls - this.xStartPxls);
rectangleHeight = Math.Abs(this.yEndPxls - this.yStartPxls);
if (this.xEndPxls >= this.xStartPxls && this.yEndPxls >= this.yStartPxls)
{
xStartN = this.xStartPxls;
yStartN = this.yStartPxls;
// Check whether the rectangle to draw exceeds the dimension of the control itself. Minus 5 pixels because of the DefaultMargins.
if (xStartN + rectangleWidth > this.heatmapControl.Width - RECTANGULAR_ZOOM_CONTROL_MARGIN)
{
rectangleWidth = this.heatmapControl.Width - xStartN - RECTANGULAR_ZOOM_CONTROL_MARGIN;
}
if (yStartN + rectangleHeight > this.heatmapControl.Height - RECTANGULAR_ZOOM_CONTROL_MARGIN)
{
rectangleHeight = this.heatmapControl.Height - yStartN - RECTANGULAR_ZOOM_CONTROL_MARGIN;
}
}
else if (this.xEndPxls >= this.xStartPxls && this.yEndPxls <= this.yStartPxls)
{
xStartN = this.xStartPxls;
yStartN = this.yEndPxls;
// Check whether the rectangle to draw exceeds the dimension of the control itself. Minus 5 pixels because of the DefaultMargins.
if (yStartN < RECTANGULAR_ZOOM_CONTROL_MARGIN)
{
yStartN = RECTANGULAR_ZOOM_CONTROL_MARGIN;
rectangleHeight = this.yStartPxls - yStartN;
}
if (xStartN + rectangleWidth > this.heatmapControl.Width - RECTANGULAR_ZOOM_CONTROL_MARGIN)
{
rectangleWidth = this.heatmapControl.Width - xStartN - RECTANGULAR_ZOOM_CONTROL_MARGIN;
}
}
else if (this.xEndPxls <= this.xStartPxls && this.yEndPxls <= this.yStartPxls)
{
xStartN = this.xEndPxls;
yStartN = this.yEndPxls;
// Check whether the rectangle to draw exceeds the dimension of the control itself. Minus 5 pixels because of the DefaultMargins.
if (yStartN < RECTANGULAR_ZOOM_CONTROL_MARGIN)
{
yStartN = RECTANGULAR_ZOOM_CONTROL_MARGIN;
rectangleHeight = this.yStartPxls - yStartN;
}
if (xStartN < RECTANGULAR_ZOOM_CONTROL_MARGIN)
{
xStartN = RECTANGULAR_ZOOM_CONTROL_MARGIN;
rectangleWidth = this.xStartPxls - xStartN;
}
}
else if (this.xEndPxls <= this.xStartPxls && this.yEndPxls >= this.yStartPxls)
{
xStartN = this.xEndPxls;
yStartN = this.yStartPxls;
// Check whether the rectangle to draw exceeds the dimension of the control itself. Minus 5 pixels because of the DefaultMargins.
if (xStartN < RECTANGULAR_ZOOM_CONTROL_MARGIN)
{
xStartN = RECTANGULAR_ZOOM_CONTROL_MARGIN;
rectangleWidth = this.xStartPxls - xStartN;
}
if (yStartN + rectangleHeight > this.heatmapControl.Height - RECTANGULAR_ZOOM_CONTROL_MARGIN)
{
rectangleHeight = this.heatmapControl.Height - yStartN - RECTANGULAR_ZOOM_CONTROL_MARGIN;
}
}
// If the compute rectangle Width or Height are 0, then assign them a value of 1.
if (rectangleWidth == 0)
rectangleWidth = 1;
if (rectangleHeight == 0)
rectangleHeight = 1;
// ---- Draw Rectangle
Pen p = new Pen(Color.Red, 2);
Brush b = new SolidBrush(Color.FromArgb(130, Color.Red));
e.Graphics.DrawRectangle(p, xStartN, yStartN, rectangleWidth, rectangleHeight);
e.Graphics.FillRectangle(b, xStartN, yStartN, rectangleWidth, rectangleHeight);
}
private void HeatmapControl_MouseClick(object sender, MouseEventArgs e)
{
HeatmapHitInfo mouseClickInfo = heatmapControl.CalcHitInfo(e.Location);
if (mouseClickInfo.Cell != null)
{
this.currentXIdxCoord = (int)mouseClickInfo.Cell.XArgument;
this.currentYIdxCoord = (int)mouseClickInfo.Cell.YArgument;
}
}
private void HeatmapControl_KeyPress(object sender, KeyPressEventArgs e)
{
// Check if the combo of key pressed is Ctrl+C (Copy command).
if (e.KeyChar == '\u0003')
{
this.isToPaint = false;
heatmapControl.Refresh();
// Raise the Copy (Ctrl+C) event delegate.
RaiseHeatMapCopyPasteCtrlC(sender, e);
}
// Check if the combo of key pressed is Ctrl+X (Cut command).
else if (e.KeyChar == '\u0018')
{
this.isToPaint = false;
heatmapControl.Refresh();
RaiseHeatMapCopyPasteCtrlX(sender, e);
}
// Check if the combo of key pressed is Ctrl+V (Paste command).
else if (e.KeyChar == '\u0016')
{
RaiseHeatMapCopyPasteCtrlV(this, this.currentXIdxCoord, this.currentYIdxCoord);
}
}
public bool OnMessageFilterMessageReceived(ref Message message)
{
//Mouse Left Button Up
if (message.Msg == (int)0x0202)
{
}
// Mouse Left Button Down
else if (message.Msg == (int)0x0201)
{
}
// Mouse Right Button Down
else if (message.Msg == (int)0x0204)
{
}
// Mouse Right Button Up
else if (message.Msg == (int)0x0205)
{
}
// Mouse Move
else if (message.Msg == (int)0x0200)
{
}
// Key Down
else if (message.Msg == (int)0x0100)
{
}
// Key Up
else if (message.Msg == (int)0x0101)
{
}
// Allow continue dispatching the message
return false;
}
#endregion
#region Event
public event EventHandlerSelectedCell HeatMapCellSelection;
public event EventHandlerCopyPasteSelection HeatMapCopyPasteSelection;
public event EventHandlerCopyPasteCtrlC HeatMapCopyPasteCtrlC;
public event EventHandlerCopyPasteCtrlV HeatMapCopyPasteCtrlV;
public event EventHandlerCopyPasteCtrlX HeatMapCopyPasteCtrlX;
#endregion
}
public class CopyPasteCtrlVEventArgs : EventArgs
{
#region Fields
int xIdxCtrlV;
int yIdxCtrlV;
#endregion
#region Properties
public int XIdxCtrlV
{
get { return this.xIdxCtrlV; }
set { this.xIdxCtrlV = value; }
}
public int YIdxCtrlV
{
get { return this.yIdxCtrlV; }
set { this.yIdxCtrlV = value; }
}
#endregion
#region Constructor
public CopyPasteCtrlVEventArgs(int xIdxCtrlV, int yIdxCtrlV)
{
this.xIdxCtrlV = xIdxCtrlV;
this.yIdxCtrlV = yIdxCtrlV;
}
#endregion
}
/// <summary>
/// Arguments of the new EventHandlerClickOnSelectedCell for Cell Colorization Event Handler.
/// </summary>
public class SelectedCellsEventArgs : EventArgs
{
#region Fields
int xIdx;
int yIdx;
bool isFromRightClick;
#endregion
#region Properties
public int XIdx
{
get { return xIdx; }
set { this.xIdx = value; }
}
public int YIdx
{
get { return yIdx; }
set { this.yIdx = value; }
}
public bool IsFromRightClick
{
get { return isFromRightClick; }
set { this.isFromRightClick = value; }
}
#endregion
#region Constructor
public SelectedCellsEventArgs(int xIndex, int yIndex, bool isFromRightClick = false)
{
this.xIdx = xIndex;
this.yIdx = yIndex;
this.isFromRightClick = isFromRightClick;
}
#endregion
}
/// <summary>
/// Arguments of the new CopyPasteSelectionEventArgs for the Copy Paste of the selected cells.
/// </summary>
public class CopyPasteSelectionEventArgs : EventArgs
{
#region Fields
int xStartIdx;
int xEndIdx;
int yStartIdx;
int yEndIdx;
int cellLength;
int cellWidth;
#endregion
#region Properties
public int XStartIdx
{
get { return xStartIdx; }
set { this.xStartIdx = value; }
}
public int XEndIdx
{
get { return xEndIdx; }
set { this.xEndIdx = value; }
}
public int YStartIdx
{
get { return yStartIdx; }
set { this.yStartIdx = value; }
}
public int YEndIdx
{
get { return yEndIdx; }
set { this.yEndIdx = value; }
}
public int CellLength
{
get { return cellLength; }
set { this.cellLength = value; }
}
public int CellWidth
{
get { return cellWidth; }
set { this.cellWidth = value; }
}
#endregion
#region Constructor
public CopyPasteSelectionEventArgs(int xStartIdx, int yStartIdx, int xEndIdx, int yEndIdx)
{
this.xStartIdx = xStartIdx;
this.yStartIdx = yStartIdx;
this.xEndIdx = xEndIdx;
this.yEndIdx = yEndIdx;
ComputeWidhtAndLength();
}
private void ComputeWidhtAndLength()
{
this.cellLength = this.xEndIdx - this.xStartIdx;
this.cellWidth = this.yEndIdx - this.yStartIdx;
}
#endregion
}
/// <summary>
/// Delegate.
/// </summary>
public delegate void EventHandlerSelectedCell(object sender, SelectedCellsEventArgs e);
public delegate void EventHandlerCopyPasteSelection(object sender, CopyPasteSelectionEventArgs e);
public delegate void EventHandlerCopyPasteCtrlC(object sender, EventArgs e);
public delegate void EventHandlerCopyPasteCtrlV(object sender, CopyPasteCtrlVEventArgs e);
public delegate void EventHandlerCopyPasteCtrlX(object sender, EventArgs e);
}