forked from thedeemon/gep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraphForm.cs
1183 lines (1073 loc) · 42.9 KB
/
GraphForm.cs
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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DirectShowLib;
using System.Runtime.InteropServices;
namespace gep
{
partial class GraphForm : Form
{
Graph graph;
string savedFileName;
static int ngraphs = 0;
int toolStripHeight;
Timer timer = new Timer();
Timer animTimer = new Timer();
public static int slider_start = 330;
public GraphForm()
{
graph = new Graph(this);
Init();
}
public GraphForm(IGraphBuilder gb)
{
graph = new Graph(this, gb);
Init();
RecalcScrolls();
//Invalidate();
}
private void Init()
{
InitializeComponent();
ngraphs++;
Text = "Graph " + ngraphs.ToString();
RecalcScrolls();
slider_start = zoomCombo.Bounds.Right + 12;
showCode[0] = delegate(string code) { return new GenerateCodeGfxForm(code); };
showCode[1] = delegate(string code) { return new GenerateCodeForm(code); };
}
public bool IsFromRot { get { return graph.IsFromRot; } }
public bool UseClock
{
get { return graph.UseClock; }
set { graph.UseClock = value; }
}
public Point ViewPoint { get { return new Point(hScrollBar.Value, vScrollBar.Value - toolStripHeight); } }
private void GraphForm_Paint(object sender, PaintEventArgs e)
{
Point viewpoint = new Point(hScrollBar.Value, vScrollBar.Value - toolStripHeight);
graph.Draw(e.Graphics, viewpoint);
if (connectingPin != null && connectingPin.Connection==null)
{
Pen pen = otherPin==null ? Pens.Red : Pens.LightGreen;
Point mstart = movingStart;
mstart.X -= viewpoint.X;
mstart.Y -= viewpoint.Y;
Point mpos = mousepos;
mpos.X -= viewpoint.X;
mpos.Y -= viewpoint.Y;
e.Graphics.DrawLine(pen, mstart, mpos);
}
if (selecting)
{
Point mstart = movingStart;
mstart.X -= viewpoint.X;
mstart.Y -= viewpoint.Y;
Point mpos = mousepos;
mpos.X -= viewpoint.X;
mpos.Y -= viewpoint.Y;
Rectangle rc = new Rectangle(Math.Min(mstart.X, mpos.X), Math.Min(mstart.Y, mpos.Y), Math.Abs(mstart.X - mpos.X), Math.Abs(mstart.Y - mpos.Y));
e.Graphics.DrawRectangle(Pens.Cyan, rc);
}
}
public int WidthForFilter(List<string> names)
{
int max = 0;
using (Graphics g = CreateGraphics())
foreach (string s in names)
max = Math.Max(max, g.MeasureString(s, Filter.namefont).ToSize().Width);
int cellsize = (graph != null) ? graph.cellsize : 16;
return Math.Max(max / cellsize + 2, 8);
}
public void AddFilter(FilterProps fp)
{
AddFilter(fp, null);
}
private void AddFilter(FilterProps fp, Point? desired_pos)
{
graph.AddFilter(fp, desired_pos);
RecalcScrolls();
Invalidate();
}
private void GraphForm_Activated(object sender, EventArgs e)
{
MainForm mf = (MainForm)MdiParent;
mf.ActiveGraphForm = this;
mf.Text = Text + " - GraphEditPlus";
}
public void RenderFile(object sender, EventArgs e)
{
using (var fd = new OpenFileDialog())
{
fd.DefaultExt = "*.*";
if (fd.ShowDialog() != DialogResult.OK)
return;
RenderThisFile(fd.FileName);
}
}
public void RenderThisFile(string fname)
{
graph.RenderFile(fname);
RecalcScrolls();
Invalidate();
}
public void AddSourceFilter(object sender, EventArgs e)
{
using (var fd = new OpenFileDialog())
{
fd.DefaultExt = "*.*";
if (fd.ShowDialog() != DialogResult.OK)
return;
graph.AddSourceFilter(fd.FileName);
}
RecalcScrolls();
Invalidate();
}
public EventLogForm eventlogform;
public void ShowEventLog(object sender, EventArgs e)
{
if (eventlogform == null)
{
eventlogform = new EventLogForm(graph);
eventlogform.MdiParent = MdiParent;
eventlogform.Show();
}
else eventlogform.BringToFront();
}
private void RenderPin(object sender, EventArgs e)
{
if (connectingPin != null)
graph.RenderPin(connectingPin);
connectingPin = null;
otherPin = null;
RecalcScrolls();
Invalidate();
}
private void VoidMenuAction(object sender, EventArgs e)
{
connectingPin = null;
}
public void RenderURL(string url)
{
graph.RenderURL(url);
RecalcScrolls();
Invalidate();
}
private void ShowPropertyPage(object sender, EventArgs e)
{
if (rightClickedFilter != null)
{
FilterGraphTools.ShowFilterPropertyPage(rightClickedFilter.BaseFilter, Handle);
rightClickedFilter = null;
}
if (connectingPin != null)
{
connectingPin.ShowPropertyPage(Handle);
connectingPin = null;
}
}
private void ScanInterfaces(object sender, EventArgs e)
{
List<InterfaceInfo> lst = null;
string name = null;
if (rightClickedFilter != null)
{
lst = rightClickedFilter.ScanInterfaces();
name = rightClickedFilter.Name + " interfaces";
rightClickedFilter = null;
}
if (connectingPin != null)
{
lst = connectingPin.ScanInterfaces();
name = connectingPin.UniqName + " interfaces";
connectingPin = null;
}
if (lst != null)
{
InterfacesListForm ilf = new InterfacesListForm();
ilf.MdiParent = MdiParent;
ilf.Text = name;
ilf.SetList(lst);
ilf.Show();
}
}
private void VfWConfig(object sender, EventArgs e)
{
if (rightClickedFilter != null)
(rightClickedFilter.BaseFilter as IAMVfwCompressDialogs).ShowDialog(VfwCompressDialogs.Config, Handle);
rightClickedFilter = null;
}
private void VfWAbout(object sender, EventArgs e)
{
if (rightClickedFilter != null)
(rightClickedFilter.BaseFilter as IAMVfwCompressDialogs).ShowDialog(VfwCompressDialogs.About, Handle);
rightClickedFilter = null;
}
private void ShowMatchingFilters(object sender, EventArgs e)
{
if (connectingPin != null)
{
MatchingFiltersForm mf = new MatchingFiltersForm(connectingPin);
mf.MdiParent = MdiParent;
mf.Show();
}
connectingPin = null;
}
private void WatchSampleGrabber(object sender, EventArgs e)
{
if (rightClickedFilter != null)
{
if (rightClickedFilter.sampleGrabberForm == null)
{
ISampleGrabber sg = rightClickedFilter.BaseFilter as ISampleGrabber;
if (sg != null)
{
SampleGrabberForm sf = new SampleGrabberForm(sg, rightClickedFilter);
sf.MdiParent = MdiParent;
sf.Show();
}
}
else
rightClickedFilter.sampleGrabberForm.BringToFront();
}
rightClickedFilter = null;
}
private void SetSGMediaType(object sender, EventArgs e)
{
if (rightClickedFilter != null)
{
ISampleGrabber sg = rightClickedFilter.BaseFilter as ISampleGrabber;
if (sg != null)
{
using(var sf = new MediaTypeForm(sg))
sf.ShowDialog();
}
}
rightClickedFilter = null;
}
private void AddToFavorites(object sender, EventArgs e)
{
if (rightClickedFilter != null)
Program.mainform.AddToFavorites(rightClickedFilter.filterProps);
rightClickedFilter = null;
}
private void FindFilterInList(object sender, EventArgs e)
{
if (rightClickedFilter != null)
Program.mainform.filterz.FindFilterInList(rightClickedFilter.filterProps.DisplayName);
rightClickedFilter = null;
}
private void ConfigStream(object sender, EventArgs e)
{
if (connectingPin != null)
{
IAMStreamConfig isc = connectingPin.IPin as IAMStreamConfig;
if (isc != null)
{
using (var f = new MediaTypeListForm(isc))
{
if (f.ShowDialog() == DialogResult.OK)
graph.PinSetFormat(connectingPin, f.selected_mt);
}
}
}
connectingPin = null;
}
private void GetStreamCaps(object sender, EventArgs e)
{
try
{
if (connectingPin != null)
connectingPin.GetStreamCaps();
}
catch (COMException ex)
{
Graph.ShowCOMException(ex, "Error getting stream caps");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
connectingPin = null;
}
private void ShowAllocatorProperties(object sender, EventArgs e)
{
if (connectingPin != null)
{
IMemInputPin imip = connectingPin.IPin as IMemInputPin;
if (imip != null)
{
IMemAllocator ma = null;
imip.GetAllocator(out ma);
if (ma != null)
{
AllocatorProperties pr = new AllocatorProperties();
ma.GetProperties(pr);
Program.mainform.propform.SetObject(new FieldsToPropertiesProxyTypeDescriptor(pr));
}
}
}
connectingPin = null;
}
private void ShowAllocatorRequirements(object sender, EventArgs e)
{
if (connectingPin != null)
{
IMemInputPin imip = connectingPin.IPin as IMemInputPin;
if (imip != null)
{
try
{
AllocatorProperties pr = new AllocatorProperties();
int hr = imip.GetAllocatorRequirements(out pr);
DsError.ThrowExceptionForHR(hr);
if (pr != null)
Program.mainform.propform.SetObject(new FieldsToPropertiesProxyTypeDescriptor(pr));
}
catch (COMException ex)
{
Graph.ShowCOMException(ex, "Can't get requirements");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception caught in IMemInputPin::GetAllocatorRequirements");
}
}
}
connectingPin = null;
}
Filter movingFilter, rightClickedFilter;
Point movingStart; //click point in pixels
Pin connectingPin, otherPin;
Point mousepos;
bool selecting = false;
public Point MousePos { get { return mousepos; } }
private void OnLButtonDown()
{
movingFilter = null;
connectingPin = null;
Filter filter = graph.FilterInPoint(mousepos);
if (filter != null)
{
Pin pin = filter.PinInPoint(mousepos);
if (pin != null && pin.Connection == null) //pin clicked
{
movingStart = mousepos;
connectingPin = pin;
}
else
{ //filter clicked
movingStart = mousepos;
movingFilter = filter;
movingFilter.movingStartCoords = movingFilter.Coords;
graph.PlaceFilter(movingFilter, false); //clear
if (ModifierKeys != Keys.Shift)
{
graph.ClearFiltersSelection();
Program.mainform.propform.SetObject(movingFilter.filterProps);
}
graph.SelectFilter(movingFilter, true);
Invalidate();
}
}
else //no filter clicked
{
int con_id = HoveredConnectionID();// graph.ownersmap[mousepos.X / graph.cellsize, mousepos.Y / graph.cellsize];
graph.ClearFiltersSelection();
if (con_id > 0)
graph.SelectConnection(con_id);
else //click on empty place
{
movingStart = mousepos;
selecting = true;
}
Invalidate();
}
}
private void OnRButtonDown(Point eLocation)
{
Filter filter = graph.FilterInPoint(mousepos);
if (filter != null)
{
Pin pin = filter.PinInPoint(mousepos);
if (pin != null)
{
movingStart = mousepos;
connectingPin = pin;
}
else //filter right click
{
rightClickedFilter = filter;
ContextMenu menu = new ContextMenu();
if (FilterGraphTools.HasPropertyPages(filter.BaseFilter))
menu.MenuItems.Add("Property page", ShowPropertyPage);
IAMVfwCompressDialogs vfw = filter.BaseFilter as IAMVfwCompressDialogs;
if (vfw != null)
{
if (vfw.ShowDialog(VfwCompressDialogs.QueryConfig, Handle) == 0)
menu.MenuItems.Add("VfW compressor: Config", VfWConfig);
if (vfw.ShowDialog(VfwCompressDialogs.QueryAbout, Handle) == 0)
menu.MenuItems.Add("VfW compressor: About", VfWAbout);
}
if ((filter.BaseFilter as ISampleGrabber) != null)
{
menu.MenuItems.Add("Set media type", SetSGMediaType);
menu.MenuItems.Add("Watch grabbed samples", WatchSampleGrabber);
}
menu.MenuItems.Add("Scan interfaces", ScanInterfaces);
if (filter.filterProps.DisplayName.Length > 0)
{
menu.MenuItems.Add("Add to favorites", AddToFavorites);
menu.MenuItems.Add("Find this filter in the list", FindFilterInList);
}
if ((filter.BaseFilter as IPersistStream) != null)
{
menu.MenuItems.Add("Save state to C++ code", SaveFilterStateToCode);
menu.MenuItems.Add("Save state to C# code", SaveFilterStateToCodeCS);
}
menu.Show(this, eLocation);
}
}
else //out of filter right click
{
ContextMenu menu = new ContextMenu();
menu.MenuItems.Add("Render file...", RenderFile);
menu.MenuItems.Add("Add source filter...", AddSourceFilter);
menu.MenuItems.Add("Load graph...", LoadGraph);
if (savedFileName != null)
menu.MenuItems.Add("Save graph", SaveGraph);
menu.MenuItems.Add("Save graph as...", SaveGraphAs);
menu.MenuItems.Add("See event log...", ShowEventLog);
menu.MenuItems.Add("Arrange filters", delegate
{
graph.LayoutFilters();
graph.RecalcPaths();
Invalidate();
});
menu.MenuItems.Add("Refresh graph", delegate { graph.ReloadGraph(); Invalidate(); });
menu.Show(this, eLocation);
}
}
private void GraphForm_MouseDown(object sender, MouseEventArgs e)
{
mousepos = e.Location;
mousepos.X += hScrollBar.Value;
mousepos.Y += vScrollBar.Value - toolStripHeight;
if (e.Button == MouseButtons.Left)
OnLButtonDown();
if (e.Button == MouseButtons.Right)
OnRButtonDown(e.Location);
Focus();
}
private void OnLButtonUp()
{
if (movingFilter != null)
foreach (Filter f in graph.SelectedFilters)
f.movingStartCoords = f.Coords;
movingFilter = null;
if (connectingPin != null)
{
if (mousepos == movingStart) //just click on pin
{
if (connectingPin.Connection != null)
{
AMMediaType mt = new AMMediaType();
connectingPin.IPin.ConnectionMediaType(mt);
MediaTypeProps mtp = MediaTypeProps.CreateMTProps(mt); //new MediaTypeProps(mt);
Program.mainform.propform.SetObject(mtp);
}
else
{
IEnumMediaTypes mtenum;
if (connectingPin.IPin.EnumMediaTypes(out mtenum) >= 0)
{
AMMediaType[] mts = new AMMediaType[1];
List<MediaTypeProps> mtypes = new List<MediaTypeProps>();
IntPtr fetched = Marshal.AllocHGlobal(4);
while (mtenum.Next(1, mts, fetched) == 0)
mtypes.Add(MediaTypeProps.CreateMTProps(mts[0]));
Marshal.FreeHGlobal(fetched);
Program.mainform.propform.SetObject(mtypes.ToArray());
}
}
}
else
{
if (otherPin != null)
{
Pin inpin, outpin;
if (connectingPin.Direction == PinDirection.Input)
{
inpin = connectingPin;
outpin = otherPin;
}
else
{
inpin = otherPin;
outpin = connectingPin;
}
graph.Connect(outpin, inpin, true);
}
}
Invalidate();
}
if (selecting)
{
Rectangle rc = new Rectangle(Math.Min(mousepos.X, movingStart.X), Math.Min(mousepos.Y, movingStart.Y),
Math.Abs(mousepos.X - movingStart.X), Math.Abs(mousepos.Y - movingStart.Y));
if (ModifierKeys != Keys.Shift)
graph.ClearFiltersSelection();
graph.SelectSeveralFilters(rc);
selecting = false;
Invalidate();
}
connectingPin = null;
otherPin = null;
}
private void OnRButtonUp(Point eLocation)
{
if (connectingPin != null)
{
if (mousepos == movingStart) //pin right click
{
ContextMenu menu = new ContextMenu();
string pincat = connectingPin.GetPinCategory();
if (pincat != null)
{
menu.MenuItems.Add("Pin category: " + pincat, VoidMenuAction);
menu.MenuItems.Add("-");
}
if (connectingPin.Direction == PinDirection.Output)
menu.MenuItems.Add("Render pin", RenderPin);
if (connectingPin.HasPropertyPage())
menu.MenuItems.Add("Property page", ShowPropertyPage);
menu.MenuItems.Add("Scan interfaces", ScanInterfaces);
menu.MenuItems.Add("Show matching filters", ShowMatchingFilters);
if ((connectingPin.IPin as IAMStreamConfig) != null)
{
menu.MenuItems.Add("IAMStreamConfig::SetFormat", ConfigStream);
menu.MenuItems.Add("IAMStreamConfig::GetStreamCaps", GetStreamCaps);
}
if ((connectingPin.IPin as IMemInputPin) != null)
{
menu.MenuItems.Add("See allocator properties", ShowAllocatorProperties);
menu.MenuItems.Add("See allocator requirements", ShowAllocatorRequirements);
}
menu.Show(this, eLocation);
return;
}
if (otherPin != null) //direct connect
{
Pin inpin, outpin;
if (connectingPin.Direction == PinDirection.Input)
{
inpin = connectingPin;
outpin = otherPin;
}
else
{
inpin = otherPin;
outpin = connectingPin;
}
graph.Connect(outpin, inpin, false);
}
}
connectingPin = null;
otherPin = null;
Invalidate();
}
private void GraphForm_MouseUp(object sender, MouseEventArgs e)
{
mousepos = e.Location;
mousepos.X += hScrollBar.Value;
mousepos.Y += vScrollBar.Value - toolStripHeight;
if (e.Button == MouseButtons.Left)
OnLButtonUp();
if (e.Button == MouseButtons.Right)
OnRButtonUp(e.Location);
}
private void GraphForm_MouseMove(object sender, MouseEventArgs e)
{
mousepos = e.Location;
mousepos.X += hScrollBar.Value;
mousepos.Y += vScrollBar.Value - toolStripHeight;
if (movingFilter != null)
{
int dx = (mousepos.X - movingStart.X) / graph.cellsize;
int dy = (mousepos.Y - movingStart.Y) / graph.cellsize;
if (dx != 0 || dy != 0)
{
Point c = movingFilter.movingStartCoords;
c.X += dx;
c.Y += dy;
c.X = Math.Max(c.X, 1);
c.Y = Math.Max(c.Y, 0);
if (c != movingFilter.Coords)
{
foreach(Filter f in graph.SelectedFilters)
graph.PlaceFilter(f, false);
bool canplace = true;
foreach (Filter f in graph.SelectedFilters)
{
c = f.movingStartCoords;
c.X += dx;
c.Y += dy;
c.X = Math.Max(c.X, 1);
c.Y = Math.Max(c.Y, 0);
if (!graph.CanPlaceFilter(c, f))
{
canplace = false;
break;
}
}
if (canplace)
{
foreach (Filter f in graph.SelectedFilters)
{
c = f.movingStartCoords;
c.X += dx;
c.Y += dy;
c.X = Math.Max(c.X, 1);
c.Y = Math.Max(c.Y, 0);
f.Coords = c;
graph.PlaceFilter(f, true);
}
graph.RecalcPaths();
RecalcScrolls();
Invalidate();
}
else
foreach (Filter f in graph.SelectedFilters)
graph.PlaceFilter(f, true);
}
}
}
if (connectingPin != null && connectingPin.Connection==null)
{
otherPin = null;
Filter f = graph.FilterInPoint(mousepos);
if (f != null)
{
Pin p = f.PinInPoint(mousepos);
if (p != null && p.Direction != connectingPin.Direction && p.Connection==null)
otherPin = p;
}
Invalidate();
}
if (selecting)
{
Invalidate();
}
DescribeActions();
}
void AddToAnimated(Animated a, DateTime t)
{
if (a.OnMouseOver(t) && !animated_objects.Contains(a))
animated_objects.Add(a);
}
public void StopAnimation(Animated a)
{
animated_objects.Remove(a);
}
public int HoveredConnectionID()
{
return graph.ownersmap[mousepos.X / graph.cellsize, mousepos.Y / graph.cellsize];
}
void DescribeActions()
{
StringBuilder sb = new StringBuilder();
DateTime t = DateTime.Now;
if (movingFilter == null && connectingPin == null) //no action yet
{
sb.Append("Right click for menu. ");
Filter filter = graph.FilterInPoint(mousepos);
if (filter != null)
{
Pin pin = filter.PinInPoint(mousepos);
if (pin != null)
{
if (pin.Connection == null)
sb.Append("Drag with left button down for intelligent connect, with right button for direct connect, left click to see media types. ");
AddToAnimated(pin, t);
} else
sb.Append("Drag with left button down to move filter, left click to select and see properties. Shift+click to add to selection. ");
AddToAnimated(filter, t);
} else {
int con_id = HoveredConnectionID();
if (con_id > 0)
{
sb.Append("Left click to see connection mediatype. ");
if (graph.SelectedConnection != null && graph.SelectedConnection.ID == con_id)
sb.Append("Press Del to remove connection. ");
PinConnection con = graph.ConnectionWithID(con_id);
if (con != null) AddToAnimated(con, t);
}
else
if (selecting)
sb.Append("Release mouse button to select filters in rectangle. ");
else
if (graph.HasFilters)
sb.Append("Drag mouse with left button down to select several filters. ");
}
}
if (movingFilter != null)
sb.Append("Release mouse button to stop moving filters. ");
if (graph.SelectedFilters.Count > 0)
sb.Append("Press Del to remove selected filters. ");
if (connectingPin != null)
if (otherPin != null)
sb.Append("Release mouse button to attempt connection. ");
else
sb.Append("Move mouse to the pin you want to connect to. ");
if (RegistryChecker.R[1]==0 && RegistryChecker.R[0] != 0)
sb.AppendFormat("{0} days to evaluate. ", RegistryChecker.R[93]);
//sb.AppendFormat("R {0} {1}", RegistryChecker.R[0], RegistryChecker.R[1]);
//sb.AppendFormat(" {0} animated", animated_objects.Count);
Program.mainform.SetHint(sb.ToString());
}
private void GraphForm_KeyDown(object sender, KeyEventArgs e)
{
int k = e.KeyValue;
//MessageBox.Show(k.ToString());
if (k == 46) //Del button
{
graph.Stop();
if (graph.SelectedFilters.Count > 0)
{
foreach (Filter f in graph.SelectedFilters)
graph.RemoveFilter(f, false);
graph.ClearFiltersSelection();
graph.RecalcPaths();
Invalidate();
}
PinConnection con = graph.SelectedConnection;
if (con != null)
{
graph.SelectedConnection = null;
graph.RemoveConnection(con, true);
Invalidate();
}
e.Handled = true;
}
}
public delegate Form ShowCodeDel(string code);
ShowCodeDel[] showCode = new ShowCodeDel[2];
void RecalcScrolls()
{
Point sz = graph.GetRealGraphSize();
Size cs = ClientSize;
hScrollBar.Maximum = (sz.X+1) * graph.cellsize;
vScrollBar.Maximum = (sz.Y+1) * graph.cellsize;
hScrollBar.Visible = (hScrollBar.Maximum > cs.Width || hScrollBar.Value > 0);
vScrollBar.Visible = (vScrollBar.Maximum > cs.Height || vScrollBar.Value > 0);
hScrollBar.LargeChange = hScrollBar.Maximum / 10;
hScrollBar.SmallChange = hScrollBar.Maximum / 20;
vScrollBar.LargeChange = vScrollBar.Maximum / 10;
vScrollBar.SmallChange = vScrollBar.Maximum / 20;
}
private void hScrollBar_ValueChanged(object sender, EventArgs e)
{
Invalidate();
}
private void vScrollBar_ValueChanged(object sender, EventArgs e)
{
Invalidate();
}
private void GraphForm_SizeChanged(object sender, EventArgs e)
{
RecalcScrolls();
}
public void SaveGraphAs(object sender, EventArgs e)
{
using (var fd = new SaveFileDialog())
{
fd.DefaultExt = "*.grf";
fd.Filter = "Graph files (*.grf)|*.grf|All files (*.*)|*.*";
if (fd.ShowDialog() == DialogResult.OK)
{
graph.SaveGraph(fd.FileName);
savedFileName = fd.FileName;
Text = savedFileName;
}
}
}
public void LoadGraph(object sender, EventArgs e)
{
using (var fd = new OpenFileDialog())
{
fd.DefaultExt = "*.grf";
fd.Filter = "Graph files (*.grf)|*.grf|All files (*.*)|*.*";
if (fd.ShowDialog() == DialogResult.OK)
DoLoad(fd.FileName);
}
}
public void DoLoad(string file)
{
if (graph.LoadGraph(file, delegate() { Text = file; }))
{
RecalcScrolls();
Invalidate();
savedFileName = file;
}
}
public void SaveGraph(object sender, EventArgs e)
{
if (savedFileName == null)
SaveGraphAs(sender, e);
else
graph.SaveGraph(savedFileName);
}
private void GraphForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (eventlogform != null)
eventlogform.Close();
graph.Close();
//graph.Dispose();
Program.mainform.ActiveGraphForm = null;
Program.mainform.Text = "GraphEditPlus";
}
Timer regtimer = new Timer();
private void GraphForm_Load(object sender, EventArgs e)
{
int n = Math.Min(ngraphs, 15);
Location = new Point(300 + n * 10, (n-1) * 30);
int w = MdiParent.ClientSize.Width - 400, h = MdiParent.ClientSize.Height*3/4;
Size = new Size(w, h);
zoomCombo.Items.Add("25%");
zoomCombo.Items.Add("50%");
zoomCombo.Items.Add("75%");
int i = zoomCombo.Items.Add("100%");
zoomCombo.SelectedIndex = i;
regtimer.Interval = 250;
regtimer.Tick += delegate{
if (RegistryChecker.R[0] == 0) return;
regtimer.Stop();
if (RegistryChecker.R[1] < 1 && RegistryChecker.R[93] < 1)
{
MessageBox.Show("Evaluation period has expired. Register the program to continue using it.");
Close();
}
};
regtimer.Start();
toolStripHeight = toolStrip.Size.Height;
graph.SetEventWindow(Handle);
timer.Interval = 380;
timer.Tick += OnTimer;
timer.Start();
animTimer.Interval = 50;
animTimer.Tick += OnAnimationTimer;
animTimer.Start();
toolStrip.Renderer = new SickToolStripRenderer(graph);
}
public void SetScale(int _scale) //0..3
{
graph.cellsize = (_scale + 1) * 4;
Invalidate();
}
private void OnZoomChanged(object sender, EventArgs e)
{
SetScale(zoomCombo.SelectedIndex);
Focus();
}
private void OnPlay(object sender, EventArgs e)
{
graph.Run();
}
private void OnPause(object sender, EventArgs e)
{
graph.Pause();
}
private void OnStop(object sender, EventArgs e)
{
graph.Stop();
}
private void OnTimer(Object myObject, EventArgs myEventArgs)
{
graph.UpdateState();
labelState.Text = graph.State;
labelPosition.Text = graph.Positions;
Invalidate();
}
List<Animated> animated_objects = new List<Animated>();
private void OnAnimationTimer(Object myObject, EventArgs myEventArgs)
{
DateTime t = DateTime.Now;
List<Animated> nextlist = new List<Animated>();
foreach (Animated anim in animated_objects)
if (anim.Animate(t))
nextlist.Add(anim);
animated_objects = nextlist;
}
bool sliding = false;
private void OnToolStripMouseDown(object sender, MouseEventArgs e)
{
Slide(e);
}
private void OnToolStripMouseMove(object sender, MouseEventArgs e)
{