-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoBrowser.cs
1310 lines (1135 loc) · 47.7 KB
/
VideoBrowser.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
#region License
/*
VPKSoft.VisualComponents
Windows.Forms component collection to be used with a HTPC software.
Copyright © 2018 VPKSoft, Petteri Kautonen
Contact: vpksoft@vpksoft.net
This file is part of VPKSoft.VisualComponents.
VPKSoft.VisualComponents is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VPKSoft.VisualComponents is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VPKSoft.VisualComponents. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using VPKSoft.MessageHelper;
#pragma warning disable CS1587 // XML comment is not placed on a valid language element
/// <summary>
/// A name space for the VPKSoft.VideoBrowser control.
/// </summary>
namespace VPKSoft.VideoBrowser
#pragma warning restore CS1587 // XML comment is not placed on a valid language element
{
/// <summary>
/// A component which displays a list of videos with their still images and descriptions.
/// </summary>
[DefaultEvent("PlaybackRequested")]
public partial class VideoBrowser : UserControl
{
/// <summary>
/// A constructor for the VPKSoft.VideoBrowser control.
/// </summary>
public VideoBrowser()
{
InitializeComponent();
base.Padding = new Padding(0);
// set the fonts..
FontLarge = FontLarge;
FontMedium = FontMedium;
FontSmall = FontSmall;
// END: set the fonts..
ResizeButtons(); // scale the buttons..
DoubleBuffered = true; // try to avoid flickering..
UpdateHighlight(); // update the highlighted video details..
}
#region PrivateMembers
/// <summary>
/// A string to measure font sizes.
/// </summary>
private const string MeasureText = "ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖabcdefghijklmnopqrstuvwxyzåäö£€%[]$@ÂÊÎÔÛâêîôûÄËÏÖÜäëïöüÀÈÌÒÙàèìòùÁÉÍÓÚáéíóúÃÕãõ '|?+\\/{}½§01234567890+<>_-:;*&¤#\"!";
// a list of TableLayoutPanel class instances which indicates a video in the video list..
private List<TableLayoutPanel> panels = new List<TableLayoutPanel>();
// a list for the container panels on the control..
private List<Panel> containerPanels = null;
/// <summary>
/// Gets a list of the container panels on the control.
/// </summary>
private List<Panel> ContainerPanels
{
get
{
// if not assigned yet..
if (containerPanels == null)
{
// ..create a list of the container panels..
containerPanels = new List<Panel>(new Panel[] { pn01, pn02, pn03, pn04, pn05 });
}
// return the value..
return containerPanels;
}
}
#endregion
#region PublicEvents
/// <summary>
/// A delegate for the QueryPath event.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="e">QueryPathEventArgs class instance passed to the event.</param>
public delegate void OnQueryPath(object sender, QueryPathEventArgs e);
/// <summary>
/// An event that is raised if a user requests for more videos to be added to the collection.
/// </summary>
[Category("VideoBrowser")]
[Browsable(true)]
[Description("An event that is raised if a user requests for more videos to be added to the collection.")]
public event OnQueryPath QueryPath = null;
/// <summary>
/// A delegate for the DeleteRequested event.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="e">TBDbDetailExtArgs class instance passed to the event.</param>
public delegate void OnDeleteRequested(object sender, TBDbDetailExtArgs e);
/// <summary>
/// An event that is raised when a user requests an item to be deleted from the video collection.
/// </summary>
[Category("VideoBrowser")]
[Browsable(true)]
[Description("An event that is raised when a user requests an item to be deleted from the video collection.")]
public event OnDeleteRequested DeleteRequested = null;
/// <summary>
/// A delegate for the PlaybackRequested event.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="e">TBDbDetailExtArgs class instance passed to the event.</param>
public delegate void OnPlaybackRequested(object sender, TBDbDetailExtArgs e);
/// <summary>
/// An event that is raised if a user requests a selected video to be played.
/// </summary>
[Category("VideoBrowser")]
[Browsable(true)]
[Description("An event that is raised if a user requests a selected video to be played.")]
public event OnPlaybackRequested PlaybackRequested = null;
#endregion
#region HiddenProperties
/// <summary>
/// Gets or sets padding within the control.
/// </summary>
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public new Padding Padding // no padding is required/accepted..
{
get
{
return new Padding(0); // ..so it will always be read-only and tries to be hidden..
}
}
#endregion
#region GUILogic
/// <summary>
/// List the videos on the Videos collection visually.
/// </summary>
private void ListVideos()
{
ClearVideoControls(); // first clear the previous controls from the main TableLayout panel..
DisposeList(); // cleanup..
// loop though the Videos list..
foreach (TMDbDetailExt video in Videos)
{
// create a main TableLayoutPanel for an item in the list..
TableLayoutPanel moviePanel = new TableLayoutPanel
{
RowCount = 2, // two rows..
ColumnCount = 1, // one column..
Dock = DockStyle.Fill, // set to fill the area..
Cursor = Cursors.Hand, // indicate that the item is click-able..
Tag = video, // tag the control with the "meta data"..
};
// create row and column styles for the main TableLayoutPanel..
moviePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); // the first row will scale..
// measure the absolute height for the second row..
int fHeight = TextRenderer.MeasureText(MeasureText, FontSmall).Height;
moviePanel.RowStyles.Add(new RowStyle(SizeType.Absolute, fHeight)); // set the second row style..
moviePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 100)); // set the only column style..
//tlpPreviewLarge.RowStyles[1] = new RowStyle(SizeType.Absolute, fHeight);
// this is the border panel for the item..
Panel moviePanelImageBorder = new Panel
{
Dock = DockStyle.Fill, // dock to fill..
Padding = new Padding(6), // no border without padding..
BackColor = ItemBorderColor, // set the color for the border..
Margin = new Padding(0), // no margin..
Name = "Border", // indicate the border panel by giving it a name to help highlight it if it's selected..
Cursor = Cursors.Hand, // indicate that the item is click-able..
Tag = video, // tag the control with the "meta data"..
};
// this is the panel for the video's still image..
Panel moviePanelImage = new Panel
{
BackgroundImageLayout = ImageLayout.Zoom, // set the image to zoom..
Dock = DockStyle.Fill, // dock to fill..
BackgroundImage = video.Image, // set the image..
BackColor = Color.Black, // this one is black..
Cursor = Cursors.Hand, // indicate that the item is click-able..
Tag = video // tag the control with the "meta data"..
};
// add the video's still image panel to the border panel..
moviePanelImageBorder.Controls.Add(moviePanelImage);
// create a label for the video's title..
Label moviePanelLabel = new Label
{
Dock = DockStyle.Fill, // dock to fill..
TextAlign = ContentAlignment.MiddleCenter, // set the text's align..
Text = video.Title, // set the text..
AutoSize = false, // no auto size as the text's align is on the middle of the label..
AutoEllipsis = true, // set the auto ellipsis to true..
ForeColor = ColorSmallFont, // Set the font's color..
Font = FontSmall, // set the font..
Cursor = Cursors.Hand, // indicate that the item is click-able..
Tag = video // tag the control with the "meta data"..
};
// add the border panel to the main TableLayoutPanel..
moviePanel.Controls.Add(moviePanelImageBorder, 0, 0);
// add the title label to the main TableLayoutPanel..
moviePanel.Controls.Add(moviePanelLabel, 0, 1);
// add the main TableLayoutPanel control to the panels list..
panels.Add(moviePanel);
moviePanel.Click += MoviePanel_Click; // subscribe to mouse click event..
moviePanelImageBorder.Click += MoviePanel_Click;
moviePanelImage.Click += MoviePanel_Click;
moviePanelLabel.Click += MoviePanel_Click; // END: subscribe to mouse click event..
}
// list the panels which should be shown based on the indices..
UpdateList();
}
/// <summary>
/// Gets controls and sub-controls owned by a given control.
/// </summary>
/// <param name="mainControl">The control of which sub-controls to get.</param>
/// <returns>A list of Controls containing the main control and it's sub-controls.</returns>
private List<Control> GetControls(Control mainControl)
{
List<Control> result = new List<Control>
{
mainControl // the main control will also be in the list..
}; // the return value..
foreach (Control control in mainControl.Controls)
{
result.AddRange(GetControls(control)); // some recursion..
}
return result; // return the result..
}
/// <summary>
/// Detaches mouse click event handlers of given TableLayoutPanel control and it's sub-controls.
/// </summary>
/// <param name="panel">A TableLayoutPanel control to detach the event handlers from.</param>
private void DetachDetailClickHandlers(TableLayoutPanel panel)
{
List<Control> controls = GetControls(panel); // get all the controls on the TableLayoutPanel..
foreach (Control control in controls) // loop through the controls..
{
control.Click -= MoviePanel_Click; // detach mouse click event handlers..
}
}
// this is called when a video item in the list is clicked..
private void MoviePanel_Click(object sender, EventArgs e)
{
Control control = (Control)sender;
TMDbDetailExt detailExt = (TMDbDetailExt)control.Tag;
UpdateHighlight(detailExt); // highlight the clicked item and display it's details..
}
private int lastVideoIndex = -1; // the previous starting index of an item to display..
private int lastVideoDetailIndex = -1; // the previous item index of which details to display..
/// <summary>
/// Updates the list of visible videos on the control.
/// </summary>
private void UpdateList()
{
if (VideoIndex == -1) // nothing to do if the index is negative..
{
lastVideoIndex = VideoIndex;
return; // .. so just return..
}
pnPrevious.BackgroundImage = VideoDetailIndex <= 0 || VideoDetailIndex <= 0
? VisualUtils.UtilsMisc.MakeGrayscale3(_ImagePreviousButton)
: _ImagePreviousButton;
pnNext.BackgroundImage = VideoDetailIndex >= Videos.Count - 1 ? VisualUtils.UtilsMisc.MakeGrayscale3(_ImageNextButton) : _ImageNextButton;
// if the video index was changed from the previous time..
if (lastVideoIndex != VideoIndex)
{
SuspendLayout(); // avoid flickering..
int layOutIndex = 0; // the index to start to layout the video item panels..
ClearVideoControls(); // clear the previous detail panels..
for (int i = VideoIndex; i < VideoIndex + 5; i++) // only five video item panels will be visible at a time..
{
// don't allow "overflow" to happen..
if (i >= Videos.Count || i >= panels.Count || panels.Count == 0)
{
break;
}
// add the video item panel to the list..
ContainerPanels[layOutIndex++].Controls.Add(panels[i]);
// tlpMain.Controls.Add(panels[i], layOutIndex++, 2);
}
ResumeLayout(); // END: avoid flickering..
}
// if the last video detail index was changed from the previous time..
if (lastVideoDetailIndex != VideoDetailIndex)
{
UpdateHighlight(); // update the highlighted video and display it's details..
}
lastVideoDetailIndex = VideoDetailIndex; // save the previous detail index..
lastVideoIndex = VideoIndex; // save the previous index..
}
/// <summary>
/// Clears the highlighted (selected) video item details.
/// </summary>
private void ClearHighlight()
{
// just clear all..
lbDescriptionValue.Text = string.Empty;
pnPreviewImage.BackgroundImage = null;
lbPreviewImage.Text = string.Empty;
lbLengthCaptionAndValue.Text = string.Empty;
}
/// <summary>
/// Updates the highlighted (selected) video item and displays it's details.
/// </summary>
/// <param name="detailExt">An optional TMDbDetailExt class instance of which index to use.</param>
private void UpdateHighlight(TMDbDetailExt detailExt = null)
{
if (detailExt != null) // if the optional parameter was given..
{
VideoDetailIndex = Videos.IndexOf(detailExt); // get it's index..
}
// loop through the video detail panels on the control's video list..
for (int i = VideoIndex; i < VideoIndex + 5; i++)
{
// don't allow "overflow" to happen..
if (i >= Videos.Count || i >= panels.Count || panels.Count == 0)
{
break;
}
// find the border control..
Control[] controls = panels[i].Controls.Find("Border", false);
if (controls.Length > 0) // ..and if the border control was found..
{
Panel panel = (Panel)controls[0];
// set it's background color to match either highlight or normal border color..
panel.BackColor = i == VideoDetailIndex ? HighLilightColor : ItemBorderColor;
}
// if the highlighted index is in the collection..
if (VideoDetailIndex == i)
{
// display the details of the highlighted video..
pnPreviewImage.BackgroundImage = Videos[VideoDetailIndex].Image; // set the larger image..
lbPreviewImage.Text = Videos[VideoDetailIndex].Title; // set the title..
// set the description..
lbDescriptionValue.Text =
string.IsNullOrEmpty(Videos[VideoDetailIndex].DetailDescription) ?
Videos[VideoDetailIndex].Description : Videos[VideoDetailIndex].DetailDescription;
// display the video's length in hours and minutes..
lbLengthCaptionAndValue.Text = LengthCaption + " " + Videos[VideoDetailIndex].Duration.ToString(@"hh\:mm");
// indicate the state of video playback..
if (Videos[VideoDetailIndex].VideoPlaybackState == VideoPlaybackState.New)
{
// the video has never been played..
pbPlayBackState.Image = ImagePlaybackNew;
}
else if (Videos[VideoDetailIndex].VideoPlaybackState == VideoPlaybackState.Somewhere)
{
// the video playback was stopped somewhere in the middle..
pbPlayBackState.Image = ImagePlaybackMiddle;
}
else if (Videos[VideoDetailIndex].VideoPlaybackState == VideoPlaybackState.Played)
{
// the video was played to the end..
pbPlayBackState.Image = ImagePlaybackWatched;
}
}
}
}
/// <summary>
/// Clears the controls (the small video file images from the lower list).
/// </summary>
private void ClearVideoControls(bool suspend = false)
{
SuspendLayout(); // to avoid flickering..
foreach (Panel panel in ContainerPanels)
{
panel.Controls.Clear();
}
ResumeLayout(); // resume the layout again..
}
/// <summary>
/// If the control size is changed the do some re-layout..
/// </summary>
private void ResizeButtons()
{
pbCloseParentForm.Height = pbCloseParentForm.Width;
pbAddMovieRequest.Height = pbAddMovieRequest.Width;
pbDeleteMovie.Height = pbDeleteMovie.Width;
pbPlayBackState.Height = pbPlayBackState.Width;
}
// the control was resized..
private void VideoBrowser_Resize(object sender, EventArgs e)
{
ResizeButtons(); // ..so re-layout some child controls..
pnMain.Size = Size; // set the size the control's size..
// set the location for the main table layout panel..
tlpMain.Location = new Point(pnMain.Padding.Left, pnMain.Padding.Top);
// resize the main table layout panel..
Size size = new Size(new Point(pnMain.Size.Width - pnMain.Padding.Horizontal, pnMain.Size.Height - pnMain.Padding.Vertical));
tlpMain.Size = size;
}
/// <summary>
/// Unsubscribes the event handlers of the video list and clears the video list afterwards.
/// </summary>
public void DisposeList()
{
try
{
foreach (TableLayoutPanel panel in panels)
{
DetachDetailClickHandlers(panel);
}
panels.Clear(); // clear the panels list..
}
catch // just to be sure..
{
}
}
/// <summary>
/// A method to close the underlying form the control is on.
/// </summary>
private void CloseForm()
{
try
{
FindForm()?.Close(); // if found (!= null), then close..
DisposeList(); // cleanup..
}
catch // just to be sure..
{
}
}
/// <summary>
/// Override the WndProc to capture mouse wheel movement.
/// </summary>
/// <param name="m">A reference to a Message class instance.</param>
protected override void WndProc(ref Message m)
{
if (m.Msg == MessageHelper.MessageHelper.WM_MOUSEWHEEL) // only respond to mouse wheel movement..
{
if (m.WParamHiWord() > 0)
{
VideoDetailIndex += JumpAmount; // user requested the next video's details to be shown..
}
else
{
VideoDetailIndex -= JumpAmount; // user requested the previous video's details to be shown..
}
}
base.WndProc(ref m); // direct to base class..
}
/// <summary>
/// Override the OnPreviewKeyDown to capture keyboard events.
/// </summary>
/// <param name="e">A PreviewKeyDownEventArgs class instance.</param>
protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Left)
{
VideoDetailIndex -= JumpAmount; // user requested the previous video's details to be shown..
}
else if (e.KeyCode == Keys.Right)
{
VideoDetailIndex += JumpAmount; // user requested the next video's details to be shown..
}
else if (e.KeyCode == Keys.Escape)
{
CloseForm(); // user requested the form to be closed..
}
else if (e.KeyCode == Keys.Add || e.KeyValue == 187)
{
RaiseQueryPath(); // a user requested for a directory to be enumerated for video files..
}
else if (e.KeyCode == Keys.Delete)
{
RaiseDeleteRequested(); // a user requested for a deletion of a video file from the list..
}
else if (e.KeyCode == Keys.Return)
{
RaisePlaybackRequested(); // a user requested for a playback of the selected video file..
}
else
{
base.OnPreviewKeyDown(e);
}
}
private void pbCloseParentForm_Click(object sender, EventArgs e)
{
CloseForm(); // user requested the form to be closed..
}
private void pnNext_Click(object sender, EventArgs e)
{
VideoDetailIndex += JumpAmount; // user requested the next video's details to be shown..
}
private void pnPrevious_Click(object sender, EventArgs e)
{
VideoDetailIndex -= JumpAmount; // user requested the previous video's details to be shown..
}
private void pbAddMovieRequest_Click(object sender, EventArgs e)
{
RaiseQueryPath(); // a user requested for a directory to be enumerated for video files..
}
private void pbDeleteMovie_Click(object sender, EventArgs e)
{
RaiseDeleteRequested(); // a user requested for a deletion of a video file from the list..
}
private void playVideoClick(object sender, EventArgs e)
{
RaisePlaybackRequested(); // a user requested for a playback of the selected video file..
}
/// <summary>
/// Raises the QueryPath event.
/// </summary>
private void RaiseQueryPath()
{
QueryPathEventArgs e = new QueryPathEventArgs()
{
Context = this.Context
};
QueryPath?.Invoke(this, e);
if (!e.Cancel)
{
Videos.AddRange(e.TMDbDetails);
}
}
/// <summary>
/// Raises the DeleteRequested event.
/// </summary>
private void RaiseDeleteRequested()
{
if (VideoDetailIndex >= 0 && VideoDetailIndex < Videos.Count)
{
TBDbDetailExtArgs e = new TBDbDetailExtArgs()
{
TMDbDetailExt = Videos[VideoDetailIndex]
};
if (DeleteRequested != null)
{
DeleteRequested(this, e);
if (!e.Cancel)
{
Videos.Remove(e.TMDbDetailExt);
}
}
}
}
/// <summary>
/// Raises the PlaybackRequested event.
/// </summary>
private void RaisePlaybackRequested()
{
if (VideoDetailIndex >= 0 && VideoDetailIndex < Videos.Count)
{
TBDbDetailExtArgs e = new TBDbDetailExtArgs()
{
TMDbDetailExt = Videos[VideoDetailIndex],
Cancel = true
};
PlaybackRequested?.Invoke(this, e);
if (!e.Cancel) // the form the control is an was requested to be closed..
{
CloseForm(); // ..so close the form..
}
}
}
#endregion
#region PublicProperties
// a video detail index which detailed properties are shown..
private int _VideoDetailIndex = 2;
/// <summary>
/// Gets or sets the video detail index which detailed properties are shown.
/// </summary>
[Browsable(false)]
public int VideoDetailIndex
{
get
{
// some comparison is required so an invalid value won't be returned..
return _VideoDetailIndex >= Videos.Count ? Videos.Count - 1 : (_VideoDetailIndex == -1 && Videos.Count > 0 ? 0 : _VideoDetailIndex);
}
set
{
// save the previous value..
int lastValue = _VideoDetailIndex;
// if no change has occurred then return..
if (value == _VideoDetailIndex)
{
return;
}
// the value can't be larger than the amount of total video details in the list..
if (value >= Videos.Count)
{
_VideoDetailIndex = Videos.Count - 1;
}
else // ..otherwise the value will be accepted..
{
_VideoDetailIndex = value;
}
// don't allow negative values if there are videos in the list..
if (value < 0 && Videos.Count > 0)
{
_VideoDetailIndex = 0;
}
// don't allow larger values than there are videos in the list..
if (value >= Videos.Count)
{
return;
}
// indicate if the value is increasing or decreasing..
bool dec = lastValue > value;
// if decreasing and the display list's start index is larger than the detail index..
if (dec && VideoIndex > value)
{
VideoIndex -= JumpAmount; // ..then decrease the list's start index..
}
// if increasing and the display list's end index is smaller than the detail index..
else if (!dec && value >= VideoIndex + 5)
{
VideoIndex += JumpAmount; // ..then increase the list's start index..
}
// if the value was actually changed, update the list..
if (lastValue != value)
{
UpdateList();
}
if (_VideoDetailIndex == -1)
{
ClearHighlight(); // nothing to see with a negative index..
}
}
}
// a start index from where the video list is shown..
private int _VideoIndex = 0;
/// <summary>
/// Gets or sets a start index from where the video list is shown.
/// </summary>
[Browsable(false)]
public int VideoIndex
{
get
{
// some comparison is required so an invalid value won't be returned..
return _VideoIndex >= Videos.Count ? Videos.Count - 1 : (_VideoIndex == -1 && Videos.Count > 0 ? 0 : _VideoIndex);
}
set
{
// save the previous value..
int lastValue = _VideoIndex;
// if no change has occurred then return..
if (value == _VideoIndex)
{
return;
}
// don't allow values larger than the amount of videos + five in the list..
if (value + 5 > Videos.Count)
{
return;
}
// don't allow negative values if there are videos in the list..
if (value < 0 && Videos.Count > 0)
{
return;
}
// don't allow larger values than there are videos in the list..
if (value >= Videos.Count)
{
_VideoIndex = Videos.Count - 1;
}
// set the video index..
else
{
_VideoIndex = value;
}
// if the value was actually changed, update the list..
if (lastValue != value)
{
UpdateList();
}
}
}
// a list of TMDbDetailExt class instances to act as a video list..
private List<TMDbDetailExt> _Videos = new List<TMDbDetailExt>();
/// <summary>
/// A list of TMDbDetailExt class instances for items to be shown on the control.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public List<TMDbDetailExt> Videos
{
get
{
return _Videos;
}
set
{
_Videos = value;
ListVideos();
}
}
// the value of how many items to jump forward or backward in the list when the list is scrolled..
private int _JumpAmount = 1;
/// <summary>
/// Gets or set the value of how many items to jump forward or backward in the list when the list is scrolled.
/// </summary>
[Browsable(true)]
[Description("Gets or set the value of how many items to jump forward or backward in the list when the list is scrolled.")]
[Category("Behavior")]
[DefaultValue(1)]
public int JumpAmount
{
get
{
// return the current value..
return _JumpAmount;
}
set
{
// raise an exception if the value is not withing valid range which is from 1 to 5..
if (value < 0 || value > 5)
{
// an ArgumentOutOfRangeException seems suitable exception for this..
throw new ArgumentOutOfRangeException("The value must be in the range of 1 to 5.");
}
// set the value..
_JumpAmount = value;
}
}
/// <summary>
/// Gets or sets a voluntary context string which is passed as property QueryPathEventArgs.Context value on the QueryPath event.
/// </summary>
[Browsable(true)]
[Description("Gets or sets a voluntary context string which is passed as property QueryPathEventArgs.Context value on the QueryPath event.")]
[Category("Behavior")]
public string Context { get; set; } = string.Empty; // nothing is the default..
// a caption used to display the length of a video in hours and minutes..
private string _LengthCaption = "Length:";
/// <summary>
/// Gets or sets the caption used to display the length of a video in hours and minutes.
/// </summary>
[Browsable(true)]
[Description("Gets or sets the caption used to display the length of a video in hours and minutes.")]
[Category("Appearance")]
[DefaultValue("Length:")]
public string LengthCaption
{
get => _LengthCaption;
set
{
if (value != _LengthCaption)
{
_LengthCaption = value;
UpdateHighlight();
}
}
}
// the caption used for a video description..
private string _DescriptionCaption = "Description";
/// <summary>
/// Gets or sets the caption used for a video description.
/// </summary>
[Browsable(true)]
[Description("Gets or sets the caption used for a video's description.")]
[Category("Appearance")]
[DefaultValue("Description")]
public string DescriptionCaption
{
get => _DescriptionCaption;
set
{
if (value != _DescriptionCaption)
{
_DescriptionCaption = value;
lbDescriptionCaption.Text = value;
}
}
}
// the font used on the control for small text..
private Font fontSmall = null;
/// <summary>
/// Gets or sets the font used on the control for small text, such as the small name description in the video file list.
/// </summary>
[Browsable(true)]
[Description("Gets or sets the font used on the control for small text, such as the small name description in the video file list.")]
[Category("Appearance")]
public Font FontSmall
{
get
{
if (fontSmall == null)
{
fontSmall = base.Font;
}
return fontSmall;
}
set
{
base.Font = value;
if (value != fontSmall)
{
ListVideos();
}
fontSmall = value;
}
}
private Color _ColorSmallFont = Color.White;
/// <summary>
/// Gets or sets the color of the SmallFont property.
/// </summary>
[Description("Gets or sets the border color of items in on the control.")]
[Category("Appearance")]
[DefaultValue(typeof(Color), "White")] // the default value..
[Browsable(true)]
public Color ColorSmallFont
{
get => _ColorSmallFont;
set
{
if (value != _ColorSmallFont)
{
_ColorSmallFont = value;
ListVideos();
}
}
}
/// <summary>
/// Gets or sets the font of the text displayed by the control. This is the synonym for the FontSmall property.
/// </summary>
[Browsable(true)]
[Description("Gets or sets the font of the text displayed by the control.")]
[Category("Appearance")]
public override Font Font { get => base.Font; set => FontSmall = value; }
// the font used on the control for large text..
private Font fontLarge = null;
/// <summary>
/// Gets or sets the font used on the control for large text, the length of the video, the description text caption and the title caption.
/// </summary>
[Description("Gets or sets the font used on the control for large text.")]
[Category("Appearance")]
[Browsable(true)]
public Font FontLarge
{
get
{
if (fontLarge == null)
{
fontLarge = new Font(base.Font.FontFamily, Font.SizeInPoints * 2, Font.Style, GraphicsUnit.Point);
}
return fontLarge;
}
set
{
if (value != fontLarge)
{
fontLarge = value;
int fHeight = System.Windows.Forms.TextRenderer.MeasureText(MeasureText, value).Height;
tlpPreviewLarge.RowStyles[1] = new RowStyle(SizeType.Absolute, fHeight + lbPreviewImage.Padding.Size.Height);
tlpDetailHolder.RowStyles[0] = new RowStyle(SizeType.Absolute, fHeight);
tlpDetailHolder.RowStyles[9] = new RowStyle(SizeType.Absolute, fHeight);
lbPreviewImage.Font = value;
lbDescriptionCaption.Font = value;
lbLengthCaptionAndValue.Font = value;
}
}
}
// the font used on the control for medium text..
private Font fontMedium = null;
/// <summary>
/// Gets or sets the font used on the control for medium text, the video's description.
/// </summary>
[Description("Gets or sets the font used on the control for medium text, the video's description.")]