From 78917c9c12d8470737acf1c26b07ab731610cb24 Mon Sep 17 00:00:00 2001 From: Lorenz Cuno Klopfenstein Date: Wed, 30 Jun 2010 22:02:04 +0200 Subject: [PATCH] Added modular Side Panel system. Refactored region selection box as Side Panel implementation. Added icons to region selection panel. --- OnTopReplica/Assets/xiao_add.png | Bin 0 -> 753 bytes OnTopReplica/Assets/xiao_delete.png | Bin 0 -> 715 bytes OnTopReplica/Assets/xiao_ok.png | Bin 0 -> 752 bytes OnTopReplica/FocusedTextBox.cs | 5 +- OnTopReplica/MainForm.Designer.cs | 3 +- OnTopReplica/MainForm.cs | 283 ++++++++++-------- OnTopReplica/OnTopReplica.csproj | 18 +- OnTopReplica/Properties/Resources.Designer.cs | 21 ++ OnTopReplica/Properties/Resources.resx | 123 ++++---- OnTopReplica/RegionBox.cs | 187 ------------ OnTopReplica/SidePanel.cs | 49 +++ .../RegionPanel.Designer.cs} | 99 +++--- OnTopReplica/SidePanels/RegionPanel.cs | 212 +++++++++++++ .../RegionPanel.resx} | 0 OnTopReplica/StoredRegionArray.cs | 4 +- OnTopReplica/StoredRegionComparer.cs | 28 ++ OnTopReplica/WindowListHelper.cs | 1 - 17 files changed, 612 insertions(+), 421 deletions(-) create mode 100644 OnTopReplica/Assets/xiao_add.png create mode 100644 OnTopReplica/Assets/xiao_delete.png create mode 100644 OnTopReplica/Assets/xiao_ok.png delete mode 100644 OnTopReplica/RegionBox.cs create mode 100644 OnTopReplica/SidePanel.cs rename OnTopReplica/{RegionBox.Designer.cs => SidePanels/RegionPanel.Designer.cs} (78%) create mode 100644 OnTopReplica/SidePanels/RegionPanel.cs rename OnTopReplica/{RegionBox.resx => SidePanels/RegionPanel.resx} (100%) create mode 100644 OnTopReplica/StoredRegionComparer.cs diff --git a/OnTopReplica/Assets/xiao_add.png b/OnTopReplica/Assets/xiao_add.png new file mode 100644 index 0000000000000000000000000000000000000000..36b1f0307023fbd081178e4701616f723bd1f404 GIT binary patch literal 753 zcmV(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZ;cS%G+RCwB?lS@dHQ5c4wGymu~-o^{%9Z8G8RD>C{XwgncqBfG!#+_k7tEi1D zaZ|Jk3KBPMLc>iN25wqtl%OzpB|$;*j?;{D{m+^IpVLBTGNo1T?)}a=58wItUZJ%{ z2tit16HVDbFVG2GJ1&0%#(<&Gjs=yztF=a)1awU_^%}x>(^%a`ZACprrNsb*0zo!* z)>zz}!PfTu(T;_oGl09F8Xpw6J+In*olt0#Ac}xH&3WYjuvDtAq0)!U zi4chgkW!+gWVm&T;npdXlt?L$&T=9&RQj+~st>>c;1Hs_yrhPZ8NgH~^DBPlSNxg5 zroE|5LS}&Sk{TRBbRT^W5KiIEayf~{!=$hoZk^(!(tdEOha?t7?lOc^cryTiq-7yx z0vnru$&?8Uhk-(Y*2xSYnXs4Qu~A9nzFarpy4#sj#GToP8Cq?uaH%pkTO zA3q50;!5R_R0^d`lrl4q(mtsau2dce!Chke@p0gI4@yKu_q*optF`THT5CjAh!py- z_8kcFvx}&9*7JR1l97A!mHL<7aR3k`u(uo<@NZ31Zd{-^s|-Usv26?6wlK7l;;b^t zjSKjoe&imy2qjQ%EZg{G4F9L+Oj j0yqSsz}YnZkA4pT#uh|15Y85r00000NkvXXu0mjfEy_$d literal 0 HcmV?d00001 diff --git a/OnTopReplica/Assets/xiao_delete.png b/OnTopReplica/Assets/xiao_delete.png new file mode 100644 index 0000000000000000000000000000000000000000..4f7e3c06c7072ab8bd2992ec1db3040dde5bb9ff GIT binary patch literal 715 zcmV;+0yO=JP)(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZ;QAtEWRCwB?lRr#TaS+Ep?@wES8fe1+O&LfK8xlI{8g*x!>LAes`A> z9LM3)^m+c07Z?Ms02iyicfd2?5un!sqjMjSsn?hwN=semVg$QSL$JN#RSsjy*PU4M zg$#jkH;MS`5#XK-AWPza?D1e{a$uW;Z@p*; zu%AqWVIl`Y$dWivH$=zKDVJ2ROqyt{vZf+RG9ImjW7&oaP<3-lEf%8ywyyDW{wn{H z*mM$8RnaVa*9D|=>Pjx1injXwl=E3|?8e!G$cZ*T`E-hOPF-=gFuA<5c(@(MYHkN# z3x;7}=;eAd4DhvJHMeuP9cOZRXVC>@AiJ4VW>V{G$Q?b%!4Qt*#j;E+%fykq$iWbD zM-Qp>H8zvVOa`)U3ma2|djEWU_Tgp2ccG--2%d`K>x>}F0^nd;0;Qb7_qVIO|MKJR z_-bNyV`@;Z+X7G=UrpSG#M3*MQrG)BTVq{;mL7oAQE_i;KmY3H%WwCAJ)r20<@h!B x&&R!hA7}-4qZ*J0e$^`1u2FCthyT&<0RU|@782+2Qd0l`002ovPDHLkV1n3wH?;r& literal 0 HcmV?d00001 diff --git a/OnTopReplica/Assets/xiao_ok.png b/OnTopReplica/Assets/xiao_ok.png new file mode 100644 index 0000000000000000000000000000000000000000..fc5029a25f4417ad92afa7489f464874dc3318df GIT binary patch literal 752 zcmV(_`g8%^e{{R4h=>PzAFaQARU;qF*m;eA5Z<1fd zMgRZ;c1c7*RCwB?lTAoeQ5c4wGk2VE(s3N6G)+pYjcFT2iI8xUB#|3YcWp$mz?IZO zSK_9YK}q7KU52X+0|{Dagx0{|UpUcV)RYchW}N?f?%cU8)Qh9bUicR0<@+Aa$2qSs zO%ovmN9vt#bN~ZDH*n+7{tV0lQ!|}w@~GD|O~i3P?|kEcB9xa67h1V^{xYTIUI3zM zgr9$Zu>N})!!!nGI@hL70eapwJaD@_&u=$(Ly19}1X(ly>^N~z3^9d;ud~F{`w!pT zU4LN#`rco6C_>ThwcaOPvX5rOG0B$zoQfM)%){H|R~V+@e0^tC+5oaLH&kEMj8+&Y zo>I{?4SAxz_?KDoeLyRWQ(x6gR_2BPYydVP`YOw6h-OqWGJ__yyjuO{XS!vP>6S&J z8I{Vi8f-%J9jpfkyJ#wK+DW8h1Vi7gYhS9aV>=XNx@FPw5~&!at_p-*G+6)uJ)1?- z(s|AOD{Xn_v0x91O+g~TG<9nQJ#B2Hl1Xwo7}@Hw296JpY;}>*HF8-PHw$PUh25xSHNuXW_T!0=iJQfAPl#F;B%FS0{2oSL%$3!~eU0o9M&@Z!LQE_DWd z?Enn=+R>y$mpTqyxD77>)z8A{_M`D41p*Tjn=VLbQG(G8e)-fVpTKKLdh5@*oN)!gMGHPz-ng*P)jN i_JIU&I*tFMe**wrqevEjZknS20000(Thumbnail_CloneClick); Controls.Add(_thumbnailPanel); - //Region box - _regionBox = new RegionBox { + //Side panel + _sidePanelContainer = new Panel { Location = new Point(ClientSize.Width, 0), Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom, Enabled = false, - Visible = false + Visible = false, + Size = new Size(100, ClientSize.Height), + Padding = new Padding(4) }; - _regionBox.Size = new Size(_regionBox.Width, ClientSize.Height); - _regionBox.RequestClosing += new EventHandler(RegionBox_RequestClosing); - _regionBox.RequestRegionReset += new EventHandler(RegionBox_RequestRegionReset); - _regionBox.RegionSet += new RegionBox.RegionSetHandler(RegionBox_RegionChanged); - Controls.Add(_regionBox); + Controls.Add(_sidePanelContainer); //Set native renderer on context menus Asztal.Szótár.NativeToolStripRenderer.SetToolStripRenderer( @@ -68,97 +66,123 @@ namespace OnTopReplica { #region Child forms & controls events - void RegionBox_RegionChanged(object sender, Rectangle region) { - _thumbnailPanel.SelectedRegion = region; - SetAspectRatio(region.Size); - } + EventHandler RequestClosingHandler; - void RegionBox_RequestRegionReset(object sender, EventArgs e) { - _thumbnailPanel.ConstrainToRegion = false; - SetAspectRatio(_thumbnailPanel.ThumbnailOriginalSize); - } + const int SidePanelMargin = 2; + const int ScreenBorderMargin = 10; - void Thumbnail_RegionDrawn(object sender, Rectangle region) { - _regionBox.SetRegion(region); - } + bool _sidePanelDidMoveForm = false; + Point _sidePanelPreviousFormLocation; + + /// + /// Opens a new side panel. + /// + /// The side panel to embed. + public void SetSidePanel(SidePanel panel) { + if (_currentSidePanel != null) + CloseSidePanel(); + + _currentSidePanel = panel; + _currentSidePanel.OnFirstShown(this); + + //Add and show + _sidePanelContainer.Controls.Add(panel); + _sidePanelContainer.Visible = _sidePanelContainer.Enabled = true; + panel.Show(); + + int intHorzMargin = panel.Margin.Horizontal + _sidePanelContainer.Padding.Horizontal; //internal margins for sidepanel + int intVertMargin = panel.Margin.Vertical + _sidePanelContainer.Padding.Vertical; + + //Resize container + _sidePanelContainer.ClientSize = new Size( + panel.Width + intHorzMargin, + ClientSize.Height + ); + + int rightHorzMargin = _sidePanelContainer.Width + SidePanelMargin; //horz margin between the two controls + + //Resize rest + ClientSize = new Size( + ClientSize.Width + rightHorzMargin, + ClientSize.Height + ); + ExtraPadding = new Padding(0, 0, rightHorzMargin, 0); + _thumbnailPanel.Size = new Size( + ClientSize.Width - rightHorzMargin, + ClientSize.Height + ); + _sidePanelContainer.Location = new Point( + ClientSize.Width - rightHorzMargin, + 0 + ); + MinimumSize = new Size( + 20 + panel.MinimumSize.Width + SidePanelMargin + intHorzMargin, + panel.MinimumSize.Height + intVertMargin + ); + + //Move window if needed + var screenCurr = Screen.FromControl(this); + int pRight = Location.X + Width + ScreenBorderMargin; + if (pRight >= screenCurr.Bounds.Width) { + _sidePanelPreviousFormLocation = Location; + _sidePanelDidMoveForm = true; + + Location = new Point(screenCurr.WorkingArea.Width - Width - ScreenBorderMargin, Location.Y); + } + else { + _sidePanelDidMoveForm = false; + } + + //Hook event listener + if (RequestClosingHandler == null) + RequestClosingHandler = new EventHandler(SidePanel_RequestClosing); + panel.RequestClosing += RequestClosingHandler; + } + + /// + /// Closes the current side panel. + /// + public void CloseSidePanel() { + if (_currentSidePanel == null) + return; + + //Unhook listener + _currentSidePanel.RequestClosing -= RequestClosingHandler; + + //Remove side panel + _currentSidePanel.OnClosing(this); + _sidePanelContainer.Controls.Clear(); + _sidePanelContainer.Visible = _sidePanelContainer.Enabled = false; + _currentSidePanel = null; + + //Resize + MinimumSize = new Size(20, 20); + ClientSize = new Size( + ClientSize.Width - _sidePanelContainer.Width - SidePanelMargin, + ClientSize.Height + ); + ExtraPadding = new Padding(0); + _thumbnailPanel.Size = ClientSize; + + //Move window back if needed + if (_sidePanelDidMoveForm) { + Location = _sidePanelPreviousFormLocation; + _sidePanelDidMoveForm = false; + } + } + + void SidePanel_RequestClosing(object sender, EventArgs e) { + CloseSidePanel(); + } void Thumbnail_CloneClick(object sender, CloneClickEventArgs e) { //TODO: handle other mouse buttons Win32Helper.InjectFakeMouseClick(_lastWindowHandle.Handle, e.ClientClickLocation, e.IsDoubleClick); } - void RegionBox_RequestClosing(object sender, EventArgs e) { - RegionBoxShowing = false; - } - #endregion - #region Side "Region box" events - - const int cWindowBoundary = 10; - - bool _regionBoxShowing = false; - bool _regionBoxDidMoveForm = false; - Point _regionBoxPrevFormLocation; - - public bool RegionBoxShowing { - get { - return _regionBoxShowing; - } - set { - if (_regionBoxShowing != value) { - //Show box - _regionBoxShowing = value; - _regionBox.Visible = value; - _regionBox.Enabled = value; - - //Enable region drawing on thumbnail - _thumbnailPanel.DrawMouseRegions = value; - - //Pad form and resize it - ClientSize = new Size { - Width = ClientSize.Width + ((value) ? _regionBox.Width : -_regionBox.Width), - Height = Math.Max(ClientSize.Height, _regionBox.ClientSize.Height) - }; - ExtraPadding = (value) ? new Padding(0, 0, _regionBox.Width, 0) : new Padding(0); - - //Resize and move panels - _thumbnailPanel.Size = new Size { - Width = (value) ? (ClientSize.Width - _regionBox.Width) : ClientSize.Width, - Height = ClientSize.Height - }; - _regionBox.Location = new Point { - X = (value) ? (ClientSize.Width - _regionBox.Width) : ClientSize.Width, - Y = 0 - }; - _regionBox.Size = new Size(_regionBox.Width, ClientSize.Height); - - //Check form boundaries and move form if necessary (if it crosses the right screen border) - if (value) { - var screenCurr = Screen.FromControl(this); - int pRight = Location.X + Size.Width + cWindowBoundary; - if (pRight >= screenCurr.Bounds.Width) { - _regionBoxPrevFormLocation = Location; - _regionBoxDidMoveForm = true; - - Location = new Point(screenCurr.WorkingArea.Width - Size.Width - cWindowBoundary, Location.Y); - } - else - _regionBoxDidMoveForm = false; - } - else { - if (_regionBoxDidMoveForm) { - Location = _regionBoxPrevFormLocation; - _regionBoxDidMoveForm = false; - } - } - } - } - } - - #endregion - - #region Event override + #region Event override protected override void OnShown(EventArgs e) { base.OnShown(e); @@ -179,8 +203,8 @@ namespace OnTopReplica { protected override void OnResize(EventArgs e) { base.OnResize(e); - this.GlassMargins = (_regionBoxShowing) ? - new Margins(ClientSize.Width - _regionBox.Width, 0, 0, 0) : + this.GlassMargins = (_currentSidePanel != null) ? + new Margins(ClientSize.Width - _sidePanelContainer.Width, 0, 0, 0) : new Margins(-1); } @@ -238,15 +262,8 @@ namespace OnTopReplica { } private void Menu_opening(object sender, CancelEventArgs e) { - //Cancel if currently in "fullscreen" mode - if (IsFullscreen) { - e.Cancel = true; - return; - } - - //Close region box if opened - if (RegionBoxShowing) { - RegionBoxShowing = false; + //Cancel if currently in "fullscreen" mode or a side panel is open + if (IsFullscreen || _currentSidePanel != null) { e.Cancel = true; return; } @@ -299,9 +316,7 @@ namespace OnTopReplica { } var selectionData = (WindowListHelper.WindowSelectionData)tsi.Tag; - if (_windowManager != null) { - SetThumbnail(selectionData.Handle, selectionData.Region); - } + SetThumbnail(selectionData.Handle, selectionData.Region); } private void Menu_Switch_click(object sender, EventArgs e) { @@ -357,7 +372,7 @@ namespace OnTopReplica { } private void Menu_Region_click(object sender, EventArgs e) { - RegionBoxShowing = true; + SetSidePanel(new OnTopReplica.SidePanels.RegionPanel()); } private void Menu_Resize_opening(object sender, CancelEventArgs e) { @@ -522,7 +537,7 @@ namespace OnTopReplica { if (IsFullscreen == value) return; - RegionBoxShowing = false; //on switch, always hide region box + CloseSidePanel(); //on switch, always hide side panels GlassEnabled = !value; FormBorderStyle = (value) ? FormBorderStyle.None : FormBorderStyle.Sizable; TopMost = !value; @@ -557,19 +572,16 @@ namespace OnTopReplica { public void SetThumbnail(WindowHandle handle, StoredRegion region) { try { _lastWindowHandle = handle; - _thumbnailPanel.SetThumbnailHandle(handle); + if (region != null) + _thumbnailPanel.SelectedRegion = region.Rect; + else + _thumbnailPanel.ConstrainToRegion = false; } catch (Exception ex) { ThumbnailError(ex, false, Strings.ErrorUnableToCreateThumbnail); } - //Update region to show - if (region == null) - _regionBox.Reset(); - else - _regionBox.SetRegion(region); - //Set aspect ratio (this will resize the form) SetAspectRatio(_thumbnailPanel.ThumbnailOriginalSize); } @@ -582,13 +594,44 @@ namespace OnTopReplica { _lastWindowHandle = null; _thumbnailPanel.UnsetThumbnail(); - //Reset regions - _regionBox.Reset(); - //Disable aspect ratio KeepAspectRatio = false; } + /// + /// Gets or sets the region displayed of the current thumbnail. + /// + public Rectangle? SelectedThumbnailRegion { + get { + if (!_thumbnailPanel.IsShowingThumbnail || !_thumbnailPanel.ConstrainToRegion) + return null; + + return _thumbnailPanel.SelectedRegion; + } + set { + if (!_thumbnailPanel.IsShowingThumbnail) + return; + + if (value.HasValue) { + _thumbnailPanel.SelectedRegion = value.Value; + SetAspectRatio(value.Value.Size); + } + else { + _thumbnailPanel.ConstrainToRegion = false; + SetAspectRatio(_thumbnailPanel.ThumbnailOriginalSize); + } + } + } + + /// + /// Gets the form's thumbnail panel. + /// + public ThumbnailPanel ThumbnailPanel { + get { + return _thumbnailPanel; + } + } + private void ThumbnailError(Exception ex, bool suppress, string title){ if (!suppress) { ShowErrorDialog(title, Strings.ErrorGenericThumbnailHandleError, ex.Message); @@ -710,7 +753,7 @@ namespace OnTopReplica { public void ResetMainForm() { //Reset form settings UnsetThumbnail(); - RegionBoxShowing = false; + CloseSidePanel(); //Reset location and size (edge of the screen, min size) Point nuLoc = Screen.PrimaryScreen.WorkingArea.Location; diff --git a/OnTopReplica/OnTopReplica.csproj b/OnTopReplica/OnTopReplica.csproj index 7e4cd7c..0906b05 100644 --- a/OnTopReplica/OnTopReplica.csproj +++ b/OnTopReplica/OnTopReplica.csproj @@ -110,6 +110,7 @@ + @@ -137,6 +138,10 @@ + + UserControl + + @@ -201,8 +206,8 @@ Resources.Designer.cs Designer - - RegionBox.cs + + RegionPanel.cs Designer @@ -224,11 +229,11 @@ Settings.settings True - + UserControl - - RegionBox.cs + + RegionPanel.cs @@ -268,6 +273,9 @@ + + + Designer diff --git a/OnTopReplica/Properties/Resources.Designer.cs b/OnTopReplica/Properties/Resources.Designer.cs index a502df3..f159303 100644 --- a/OnTopReplica/Properties/Resources.Designer.cs +++ b/OnTopReplica/Properties/Resources.Designer.cs @@ -235,6 +235,20 @@ namespace OnTopReplica.Properties { } } + internal static System.Drawing.Bitmap xiao_add { + get { + object obj = ResourceManager.GetObject("xiao_add", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + internal static System.Drawing.Bitmap xiao_delete { + get { + object obj = ResourceManager.GetObject("xiao_delete", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + internal static System.Drawing.Bitmap xiao_down { get { object obj = ResourceManager.GetObject("xiao_down", resourceCulture); @@ -242,6 +256,13 @@ namespace OnTopReplica.Properties { } } + internal static System.Drawing.Bitmap xiao_ok { + get { + object obj = ResourceManager.GetObject("xiao_ok", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + internal static System.Drawing.Bitmap xiao_up { get { object obj = ResourceManager.GetObject("xiao_up", resourceCulture); diff --git a/OnTopReplica/Properties/Resources.resx b/OnTopReplica/Properties/Resources.resx index 52e4f33..c0124f7 100644 --- a/OnTopReplica/Properties/Resources.resx +++ b/OnTopReplica/Properties/Resources.resx @@ -118,86 +118,95 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Assets\ok.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\icon.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\component.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Assets\flag_ita.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Assets\flag_usa.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\thumbs_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\window_multiple16.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\back.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\reduce.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\pos_bottomleft.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Assets\window_opacity16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Assets\window16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\pos_topleft.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\window_switch.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\xiao_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Assets\x-oblique.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Assets\pos_topright.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Assets\window_border16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\pos_null.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\xiao_down.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Assets\25.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a ..\Assets\window_multiple16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Assets\pos_bottomright.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\25.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - - ..\Assets\icon.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - ..\Assets\regions.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Assets\pos_null.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\thumbs_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\pos_topleft.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\pos_bottomleft.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\icon.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\back.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\xiao_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\ok.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\window16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Assets\flag_czech.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - + + ..\Assets\pos_bottomright.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\window_switch.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\icon.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + ..\Assets\flag_danish.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Assets\reduce.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\xiao_ok.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\window_multiple16.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\component.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\xiao_down.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\window_border16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\flag_usa.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + + ..\Assets\xiao_add.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Assets\xiao_delete.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + \ No newline at end of file diff --git a/OnTopReplica/RegionBox.cs b/OnTopReplica/RegionBox.cs deleted file mode 100644 index 7059751..0000000 --- a/OnTopReplica/RegionBox.cs +++ /dev/null @@ -1,187 +0,0 @@ -using System; -using System.Drawing; -using System.Windows.Forms; -using OnTopReplica.Properties; - -namespace OnTopReplica { - public partial class RegionBox : UserControl { - - public RegionBox() { - InitializeComponent(); - - //Copy settings into combo box - if (Settings.Default.SavedRegions != null) { - foreach (object o in Settings.Default.SavedRegions) { - comboBox1.Items.Add(o); - } - } - } - - public void SetRegion(StoredRegion region) { - if (region == null) { - Reset(); - return; - } - - SetRegion(region.Rect); - - //Select right combobox - if (comboBox1.Items.Contains(region)) { - comboBox1.SelectedItem = region; - } - } - - public void SetRegion(Rectangle region) { - try { - _ignoreValueChanges = true; - - numX.Enabled = numY.Enabled = numW.Enabled = numH.Enabled = true; - - numX.Value = region.Left; - numY.Value = region.Top; - numW.Value = region.Width; - numH.Value = region.Height; - } - finally { - _ignoreValueChanges = false; - } - - OnRegionSet(region); - } - - public void Reset() { - try { - _ignoreValueChanges = true; - - numX.Value = numY.Value = numW.Value = numH.Value = 0; - - numX.Enabled = numY.Enabled = numW.Enabled = numH.Enabled = false; - - buttonSave.Enabled = false; - - comboBox1.SelectedIndex = -1; - } - finally { - _ignoreValueChanges = false; - } - } - - public event EventHandler RequestClosing; - - protected virtual void OnRequestClosing() { - if (RequestClosing != null) - RequestClosing(this, EventArgs.Empty); - } - - private void CloseClick(object sender, EventArgs e) { - OnRequestClosing(); - } - - public event EventHandler RequestRegionReset; - - protected virtual void OnRequestRegionReset() { - if (RequestRegionReset != null) - RequestRegionReset(this, EventArgs.Empty); - } - - private void ResetClick(object sender, EventArgs e) { - Reset(); - - OnRequestRegionReset(); - } - - private void DeleteClick(object sender, EventArgs e) { - if (comboBox1.SelectedIndex < 0) - return; - - var origIndex = comboBox1.SelectedIndex; - Settings.Default.SavedRegions.RemoveAt(origIndex); - comboBox1.Items.RemoveAt(origIndex); - - if (comboBox1.Items.Count > 0) - comboBox1.SelectedIndex = 0; - } - - private void SaveClick(object sender, EventArgs e) { - //Display textbox instead of button - buttonSave.Visible = false; - textRegionName.Visible = true; - textRegionName.Focus(); - } - - private void Save_confirm(object sender, EventArgs e) { - if (!string.IsNullOrEmpty(textRegionName.Text)) { - AddRegion(new Rectangle((int)numX.Value, (int)numY.Value, (int)numW.Value, (int)numH.Value), textRegionName.Text); - } - - //Hide textbox and show button again - textRegionName.Visible = false; - textRegionName.Text = string.Empty; - - buttonSave.Visible = true; - buttonSave.Enabled = false; - } - - private void Save_lost(object sender, EventArgs e) { - //Reset textbox - textRegionName.Visible = false; - - buttonSave.Visible = true; - buttonSave.Focus(); - } - - private void AddRegion(Rectangle rectangle, string p) { - var region = new StoredRegion(rectangle, p); - - int index = comboBox1.Items.Add(region); - comboBox1.SelectedIndex = index; - - if (Settings.Default.SavedRegions == null) - Settings.Default.SavedRegions = new StoredRegionArray(); - Settings.Default.SavedRegions.Add(region); - } - - public delegate void RegionSetHandler(object sender, Rectangle region); - - public event RegionSetHandler RegionSet; - - protected virtual void OnRegionSet(Rectangle region){ - var evt = RegionSet; - if (evt != null) - evt(this, region); - - buttonSave.Enabled = true; - } - - /// - /// Used to signal to the value change handler that all events should be temporarily ignored. - /// - /// - /// Must be used if the RegionBox is updating the values of the NumericUpDown controls - /// internally and the handler should not raise any event. - /// - bool _ignoreValueChanges = false; - - private void RegionValueChanged(object sender, EventArgs e) { - if (_ignoreValueChanges) - return; - - OnRegionSet(new Rectangle((int)numX.Value, (int)numY.Value, (int)numW.Value, (int)numH.Value)); - } - - private void RegionCombo_index(object sender, EventArgs e) { - buttonDelete.Enabled = (comboBox1.SelectedIndex >= 0); - - if (comboBox1.SelectedIndex >= 0) { - //Load region - var region = comboBox1.SelectedItem as StoredRegion; - - if (region == null) - return; - - SetRegion(region.Rect); - } - } - - } -} diff --git a/OnTopReplica/SidePanel.cs b/OnTopReplica/SidePanel.cs new file mode 100644 index 0000000..d3928cb --- /dev/null +++ b/OnTopReplica/SidePanel.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace OnTopReplica { + + /// + /// Represents a side panel that can be embedded in OnTopReplica. + /// + class SidePanel : UserControl { + + public SidePanel() { + Dock = DockStyle.Fill; + } + + /// + /// Gets the panel's parent form. + /// + protected MainForm ParentForm { get; private set; } + + /// + /// Raised when the side panel requests to be closed. + /// + public event EventHandler RequestClosing; + + protected virtual void OnRequestClosing() { + var evt = RequestClosing; + if (evt != null) + evt(this, EventArgs.Empty); + } + + /// + /// Is called when the side panel is embedded and first shown. + /// + /// Parent form that is embedding the side panel. + public virtual void OnFirstShown(MainForm form) { + ParentForm = form; + } + + /// + /// Is called before removing the side panel. + /// + /// Parent form that is embedding the side panel. + public virtual void OnClosing(MainForm form) { + } + + } +} diff --git a/OnTopReplica/RegionBox.Designer.cs b/OnTopReplica/SidePanels/RegionPanel.Designer.cs similarity index 78% rename from OnTopReplica/RegionBox.Designer.cs rename to OnTopReplica/SidePanels/RegionPanel.Designer.cs index 0776b64..a803575 100644 --- a/OnTopReplica/RegionBox.Designer.cs +++ b/OnTopReplica/SidePanels/RegionPanel.Designer.cs @@ -1,5 +1,5 @@ -namespace OnTopReplica { - partial class RegionBox { +namespace OnTopReplica.SidePanels { + partial class RegionPanel { /// /// Required designer variable. /// @@ -38,7 +38,7 @@ this.label1 = new System.Windows.Forms.Label(); this.buttonDelete = new System.Windows.Forms.Button(); this.buttonSave = new System.Windows.Forms.Button(); - this.comboBox1 = new VistaControls.ComboBox(); + this.comboRegions = new VistaControls.ComboBox(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numH)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numW)).BeginInit(); @@ -62,11 +62,11 @@ this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.buttonDelete); this.groupBox1.Controls.Add(this.buttonSave); - this.groupBox1.Controls.Add(this.comboBox1); + this.groupBox1.Controls.Add(this.comboRegions); this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill; - this.groupBox1.Location = new System.Drawing.Point(4, 4); + this.groupBox1.Location = new System.Drawing.Point(0, 0); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(167, 229); + this.groupBox1.Size = new System.Drawing.Size(184, 189); this.groupBox1.TabIndex = 0; this.groupBox1.TabStop = false; this.groupBox1.Text = "Regions"; @@ -77,14 +77,13 @@ | System.Windows.Forms.AnchorStyles.Right))); this.textRegionName.BackColor = System.Drawing.SystemColors.ActiveCaption; this.textRegionName.ForeColor = System.Drawing.SystemColors.ActiveCaptionText; - this.textRegionName.Location = new System.Drawing.Point(6, 48); + this.textRegionName.Location = new System.Drawing.Point(6, 46); this.textRegionName.Name = "textRegionName"; - this.textRegionName.Size = new System.Drawing.Size(90, 20); - this.textRegionName.TabIndex = 2; + this.textRegionName.Size = new System.Drawing.Size(119, 20); + this.textRegionName.TabIndex = 11; this.textRegionName.Visible = false; this.textRegionName.ConfirmInput += new System.EventHandler(this.Save_confirm); this.textRegionName.AbortInput += new System.EventHandler(this.Save_lost); - this.textRegionName.Leave += new System.EventHandler(this.Save_lost); // // numH // @@ -103,7 +102,7 @@ this.numH.Name = "numH"; this.numH.Size = new System.Drawing.Size(43, 20); this.numH.TabIndex = 7; - this.numH.ValueChanged += new System.EventHandler(this.RegionValueChanged); + this.numH.ValueChanged += new System.EventHandler(this.RegionValueSpinner_value_change); // // numW // @@ -122,7 +121,7 @@ this.numW.Name = "numW"; this.numW.Size = new System.Drawing.Size(43, 20); this.numW.TabIndex = 6; - this.numW.ValueChanged += new System.EventHandler(this.RegionValueChanged); + this.numW.ValueChanged += new System.EventHandler(this.RegionValueSpinner_value_change); // // numY // @@ -141,7 +140,7 @@ this.numY.Name = "numY"; this.numY.Size = new System.Drawing.Size(43, 20); this.numY.TabIndex = 5; - this.numY.ValueChanged += new System.EventHandler(this.RegionValueChanged); + this.numY.ValueChanged += new System.EventHandler(this.RegionValueSpinner_value_change); // // numX // @@ -160,29 +159,32 @@ this.numX.Name = "numX"; this.numX.Size = new System.Drawing.Size(43, 20); this.numX.TabIndex = 4; - this.numX.ValueChanged += new System.EventHandler(this.RegionValueChanged); + this.numX.ValueChanged += new System.EventHandler(this.RegionValueSpinner_value_change); // // buttonDone // - this.buttonDone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDone.Location = new System.Drawing.Point(101, 200); + this.buttonDone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDone.Image = global::OnTopReplica.Properties.Resources.xiao_ok; + this.buttonDone.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.buttonDone.Location = new System.Drawing.Point(108, 158); this.buttonDone.Name = "buttonDone"; - this.buttonDone.Size = new System.Drawing.Size(60, 23); + this.buttonDone.Size = new System.Drawing.Size(70, 23); this.buttonDone.TabIndex = 9; this.buttonDone.Text = global::OnTopReplica.Strings.RegionsDoneButton; + this.buttonDone.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageBeforeText; this.buttonDone.UseVisualStyleBackColor = true; - this.buttonDone.Click += new System.EventHandler(this.CloseClick); + this.buttonDone.Click += new System.EventHandler(this.Close_click); // // buttonReset // - this.buttonReset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonReset.Location = new System.Drawing.Point(6, 200); + this.buttonReset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.buttonReset.Location = new System.Drawing.Point(32, 158); this.buttonReset.Name = "buttonReset"; - this.buttonReset.Size = new System.Drawing.Size(60, 23); + this.buttonReset.Size = new System.Drawing.Size(70, 23); this.buttonReset.TabIndex = 8; this.buttonReset.Text = global::OnTopReplica.Strings.RegionsResetButton; this.buttonReset.UseVisualStyleBackColor = true; - this.buttonReset.Click += new System.EventHandler(this.ResetClick); + this.buttonReset.Click += new System.EventHandler(this.Reset_click); // // label6 // @@ -238,47 +240,48 @@ // this.buttonDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonDelete.Enabled = false; - this.buttonDelete.Location = new System.Drawing.Point(101, 46); + this.buttonDelete.Image = global::OnTopReplica.Properties.Resources.xiao_delete; + this.buttonDelete.Location = new System.Drawing.Point(155, 43); this.buttonDelete.Name = "buttonDelete"; - this.buttonDelete.Size = new System.Drawing.Size(60, 23); + this.buttonDelete.Size = new System.Drawing.Size(23, 23); this.buttonDelete.TabIndex = 3; - this.buttonDelete.Text = global::OnTopReplica.Strings.RegionsDeleteButton; this.buttonDelete.UseVisualStyleBackColor = true; - this.buttonDelete.Click += new System.EventHandler(this.DeleteClick); + this.buttonDelete.Click += new System.EventHandler(this.Delete_click); // // buttonSave // + this.buttonSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.buttonSave.Enabled = false; - this.buttonSave.Location = new System.Drawing.Point(6, 46); + this.buttonSave.Image = global::OnTopReplica.Properties.Resources.xiao_add; + this.buttonSave.Location = new System.Drawing.Point(131, 43); this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(60, 23); + this.buttonSave.Size = new System.Drawing.Size(23, 23); this.buttonSave.TabIndex = 1; - this.buttonSave.Text = global::OnTopReplica.Strings.RegionsSaveButton; this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.SaveClick); + this.buttonSave.Click += new System.EventHandler(this.Save_click); // - // comboBox1 + // comboRegions // - this.comboBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + this.comboRegions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.comboBox1.CueBannerText = global::OnTopReplica.Strings.RegionsStoredRegions; - this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox1.FlatStyle = System.Windows.Forms.FlatStyle.System; - this.comboBox1.FormattingEnabled = true; - this.comboBox1.Location = new System.Drawing.Point(6, 19); - this.comboBox1.Name = "comboBox1"; - this.comboBox1.Size = new System.Drawing.Size(156, 21); - this.comboBox1.TabIndex = 0; - this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.RegionCombo_index); + this.comboRegions.CueBannerText = global::OnTopReplica.Strings.RegionsStoredRegions; + this.comboRegions.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboRegions.FlatStyle = System.Windows.Forms.FlatStyle.System; + this.comboRegions.FormattingEnabled = true; + this.comboRegions.Location = new System.Drawing.Point(6, 19); + this.comboRegions.Name = "comboRegions"; + this.comboRegions.Size = new System.Drawing.Size(173, 21); + this.comboRegions.TabIndex = 0; + this.comboRegions.SelectedIndexChanged += new System.EventHandler(this.RegionCombo_index_change); // - // RegionBox + // RegionPanel // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.groupBox1); - this.MinimumSize = new System.Drawing.Size(160, 180); - this.Name = "RegionBox"; - this.Size = new System.Drawing.Size(175, 237); + this.MinimumSize = new System.Drawing.Size(184, 189); + this.Name = "RegionPanel"; + this.Size = new System.Drawing.Size(184, 189); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numH)).EndInit(); @@ -294,7 +297,7 @@ private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button buttonDelete; private System.Windows.Forms.Button buttonSave; - private VistaControls.ComboBox comboBox1; + private VistaControls.ComboBox comboRegions; private System.Windows.Forms.Button buttonDone; private System.Windows.Forms.Button buttonReset; private System.Windows.Forms.Label label6; @@ -305,7 +308,7 @@ private System.Windows.Forms.NumericUpDown numH; private System.Windows.Forms.NumericUpDown numW; private System.Windows.Forms.NumericUpDown numY; - private System.Windows.Forms.NumericUpDown numX; - private FocusedTextBox textRegionName; + private System.Windows.Forms.NumericUpDown numX; + private FocusedTextBox textRegionName; } } diff --git a/OnTopReplica/SidePanels/RegionPanel.cs b/OnTopReplica/SidePanels/RegionPanel.cs new file mode 100644 index 0000000..0d0f5f1 --- /dev/null +++ b/OnTopReplica/SidePanels/RegionPanel.cs @@ -0,0 +1,212 @@ +using System; +using System.Drawing; +using System.Windows.Forms; +using OnTopReplica.Properties; + +namespace OnTopReplica.SidePanels { + partial class RegionPanel : SidePanel { + + public RegionPanel() { + InitializeComponent(); + + //Copy settings into combo box + if (Settings.Default.SavedRegions != null) { + foreach (object o in Settings.Default.SavedRegions) { + comboRegions.Items.Add(o); + } + } + } + + public override void OnFirstShown(MainForm form) { + base.OnFirstShown(form); + + //Init shown region if needed + if (form.SelectedThumbnailRegion.HasValue) + SetRegion(form.SelectedThumbnailRegion.Value); + + form.ThumbnailPanel.DrawMouseRegions = true; + form.ThumbnailPanel.RegionDrawn += new ThumbnailPanel.RegionDrawnHandler(ThumbnailPanel_RegionDrawn); + } + + public override void OnClosing(MainForm form) { + base.OnClosing(form); + + form.ThumbnailPanel.DrawMouseRegions = false; + } + + void ThumbnailPanel_RegionDrawn(object sender, Rectangle region) { + SetRegion(region); + } + + #region Interface + + /// + /// Sets the current selected region to a specific instance of a stored region. + /// + /// A stored region instance or null to reset. + public void SetRegion(StoredRegion region) { + if (region == null) { + Reset(); + return; + } + + SetRegion(region.Rect); + + //Select right combobox + if (comboRegions.Items.Contains(region)) { + comboRegions.SelectedItem = region; + } + } + + /// + /// Sets the current selected region to a specific region rectangle. + /// + /// The region boundaries. + public void SetRegion(Rectangle region) { + try { + _ignoreValueChanges = true; + + numX.Enabled = numY.Enabled = numW.Enabled = numH.Enabled = true; + + numX.Value = region.Left; + numY.Value = region.Top; + numW.Value = region.Width; + numH.Value = region.Height; + } + finally { + _ignoreValueChanges = false; + } + + OnRegionSet(region); + } + + /// + /// Resets the selected region and disables the num spinners. + /// + public void Reset() { + try { + _ignoreValueChanges = true; + + numX.Value = numY.Value = numW.Value = numH.Value = 0; + numX.Enabled = numY.Enabled = numW.Enabled = numH.Enabled = false; + + buttonSave.Enabled = false; + + comboRegions.SelectedIndex = -1; + } + finally { + _ignoreValueChanges = false; + } + } + + #endregion + + /// + /// Adds a new stored region. + /// + /// Region bounds. + /// Name of the region. + private void AddRegion(Rectangle rectangle, string regionName) { + var region = new StoredRegion(rectangle, regionName); + + int index = comboRegions.Items.Add(region); + comboRegions.SelectedIndex = index; + + if (Settings.Default.SavedRegions == null) + Settings.Default.SavedRegions = new StoredRegionArray(); + Settings.Default.SavedRegions.Add(region); + } + + /// + /// Internal event raised when a change occurs in the selected region. + /// + /// Region bounds. + protected virtual void OnRegionSet(Rectangle regionBounds) { + //Forward region to thumbnail + ParentForm.SelectedThumbnailRegion = regionBounds; + + buttonSave.Enabled = true; + } + + #region GUI event handlers + + private void Close_click(object sender, EventArgs e) { + OnRequestClosing(); + } + + private void Reset_click(object sender, EventArgs e) { + Reset(); + ParentForm.SelectedThumbnailRegion = null; + } + + private void Delete_click(object sender, EventArgs e) { + if (comboRegions.SelectedIndex < 0) + return; + + var origIndex = comboRegions.SelectedIndex; + Settings.Default.SavedRegions.RemoveAt(origIndex); + comboRegions.Items.RemoveAt(origIndex); + + if (comboRegions.Items.Count > 0) + comboRegions.SelectedIndex = 0; + } + + private void Save_click(object sender, EventArgs e) { + //Display textbox instead of button + buttonSave.Enabled = buttonDelete.Enabled = false; + textRegionName.Visible = true; + textRegionName.Focus(); + } + + private void Save_confirm(object sender, EventArgs e) { + if (!string.IsNullOrEmpty(textRegionName.Text)) { + AddRegion( + new Rectangle((int)numX.Value, (int)numY.Value, (int)numW.Value, (int)numH.Value), + textRegionName.Text + ); + } + + //Hide textbox and show button again + textRegionName.Visible = false; + textRegionName.Text = string.Empty; + + buttonSave.Enabled = buttonDelete.Enabled = true; + } + + private void Save_lost(object sender, EventArgs e) { + //Reset textbox + textRegionName.Visible = false; + textRegionName.Text = string.Empty; + + buttonSave.Enabled = buttonDelete.Enabled = true; + buttonSave.Focus(); + } + + // Used to signal to the value change handler that all events should be temporarily ignored. + bool _ignoreValueChanges = false; + + private void RegionValueSpinner_value_change(object sender, EventArgs e) { + if (_ignoreValueChanges) + return; + + OnRegionSet(new Rectangle((int)numX.Value, (int)numY.Value, (int)numW.Value, (int)numH.Value)); + } + + private void RegionCombo_index_change(object sender, EventArgs e) { + buttonDelete.Enabled = (comboRegions.SelectedIndex >= 0); + + if (comboRegions.SelectedIndex >= 0) { + //Load region + var region = comboRegions.SelectedItem as StoredRegion; + + if (region == null) + return; + + SetRegion(region.Rect); + } + } + + #endregion + + } +} diff --git a/OnTopReplica/RegionBox.resx b/OnTopReplica/SidePanels/RegionPanel.resx similarity index 100% rename from OnTopReplica/RegionBox.resx rename to OnTopReplica/SidePanels/RegionPanel.resx diff --git a/OnTopReplica/StoredRegionArray.cs b/OnTopReplica/StoredRegionArray.cs index ee4a74e..1a948c6 100644 --- a/OnTopReplica/StoredRegionArray.cs +++ b/OnTopReplica/StoredRegionArray.cs @@ -7,7 +7,8 @@ using System.Xml.Serialization; namespace OnTopReplica { public class StoredRegionArray : ArrayList, IXmlSerializable { - #region IXmlSerializable Members + + #region IXmlSerializable Members public System.Xml.Schema.XmlSchema GetSchema() { return null; @@ -32,6 +33,7 @@ namespace OnTopReplica { } #endregion + } } diff --git a/OnTopReplica/StoredRegionComparer.cs b/OnTopReplica/StoredRegionComparer.cs new file mode 100644 index 0000000..cfc9438 --- /dev/null +++ b/OnTopReplica/StoredRegionComparer.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Collections; + +namespace OnTopReplica { + + /// + /// Compares two StoredRegions based on their name. + /// + class StoredRegionComparer : IComparer { + + #region IComparer Members + + public int Compare(object x, object y) { + StoredRegion a = x as StoredRegion; + StoredRegion b = y as StoredRegion; + + if (a == null || b == null) + return -1; //this is wrong, but anyway + + return a.Name.CompareTo(b.Name); + } + + #endregion + + } +} diff --git a/OnTopReplica/WindowListHelper.cs b/OnTopReplica/WindowListHelper.cs index bcd153b..e61c757 100644 --- a/OnTopReplica/WindowListHelper.cs +++ b/OnTopReplica/WindowListHelper.cs @@ -78,7 +78,6 @@ namespace OnTopReplica { }; nullRegionItem.Image = Resources.regions; nullRegionItem.Click += clickHandler; - tsi.DropDownItems.Add(nullRegionItem); foreach (StoredRegion region in regions) {