Added modular Side Panel system.

Refactored region selection box as Side Panel implementation.
Added icons to region selection panel.
This commit is contained in:
Lorenz Cuno Klopfenstein 2010-06-30 22:02:04 +02:00
parent 66023053c3
commit 78917c9c12
17 changed files with 612 additions and 421 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 753 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 715 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 752 B

View file

@ -17,12 +17,15 @@ namespace OnTopReplica {
protected override void OnKeyUp(KeyEventArgs e) {
if (e.KeyCode == Keys.Return) {
OnConfirmInput();
if(!string.IsNullOrEmpty(Text))
OnConfirmInput();
e.Handled = true;
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.Escape) {
OnAbortInput();
e.Handled = true;
e.SuppressKeyPress = true;
}

View file

@ -169,6 +169,7 @@
this.toolStripMenuItem3,
this.toolStripMenuItem4});
this.menuOpacity.Name = "menuOpacity";
this.menuOpacity.OwnerItem = this.menuContextOpacity;
this.menuOpacity.ShowCheckMargin = true;
this.menuOpacity.ShowImageMargin = false;
this.menuOpacity.Size = new System.Drawing.Size(154, 92);
@ -430,7 +431,7 @@
this.ControlBox = false;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimumSize = new System.Drawing.Size(200, 210);
this.MinimumSize = new System.Drawing.Size(20, 20);
this.Name = "MainForm";
this.TopMost = true;
this.menuContext.ResumeLayout(false);

View file

@ -8,11 +8,12 @@ using VistaControls.TaskDialog;
namespace OnTopReplica {
public partial class MainForm : AspectRatioForm {
partial class MainForm : AspectRatioForm {
//GUI
//GUI elements
ThumbnailPanel _thumbnailPanel;
RegionBox _regionBox;
SidePanel _currentSidePanel = null;
Panel _sidePanelContainer;
//Window manager
WindowManager _windowManager = new WindowManager();
@ -31,22 +32,19 @@ namespace OnTopReplica {
Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right,
Size = ClientSize
};
_thumbnailPanel.RegionDrawn += new ThumbnailPanel.RegionDrawnHandler(Thumbnail_RegionDrawn);
_thumbnailPanel.CloneClick += new EventHandler<CloneClickEventArgs>(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;
/// <summary>
/// Opens a new side panel.
/// </summary>
/// <param name="panel">The side panel to embed.</param>
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;
}
/// <summary>
/// Closes the current side panel.
/// </summary>
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;
}
/// <summary>
/// Gets or sets the region displayed of the current thumbnail.
/// </summary>
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);
}
}
}
/// <summary>
/// Gets the form's thumbnail panel.
/// </summary>
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;

View file

@ -110,6 +110,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
@ -137,6 +138,10 @@
<Compile Include="MessagePumpProcessors\BaseMessagePumpProcessor.cs" />
<Compile Include="Native\HookMethods.cs" />
<Compile Include="Native\HotKeyMethods.cs" />
<Compile Include="SidePanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="StoredRegionComparer.cs" />
<Compile Include="WindowsSevenMethods.cs" />
<None Include="CommonControls.cs" />
<Compile Include="EnumerationExtensions.cs" />
@ -201,8 +206,8 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="RegionBox.resx">
<DependentUpon>RegionBox.cs</DependentUpon>
<EmbeddedResource Include="SidePanels\RegionPanel.resx">
<DependentUpon>RegionPanel.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Strings.resx">
@ -224,11 +229,11 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="RegionBox.cs">
<Compile Include="SidePanels\RegionPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="RegionBox.Designer.cs">
<DependentUpon>RegionBox.cs</DependentUpon>
<Compile Include="SidePanels\RegionPanel.Designer.cs">
<DependentUpon>RegionPanel.cs</DependentUpon>
</Compile>
<Compile Include="StoredRegion.cs" />
<Compile Include="StoredRegionArray.cs" />
@ -268,6 +273,9 @@
<None Include="Assets\reduce.png" />
</ItemGroup>
<ItemGroup>
<None Include="Assets\xiao_delete.png" />
<None Include="Assets\xiao_add.png" />
<None Include="Assets\xiao_ok.png" />
<None Include="OnTopReplica.exe.manifest">
<SubType>Designer</SubType>
</None>

View file

@ -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);

View file

@ -118,86 +118,95 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="ok" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\ok.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\icon.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="component" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\component.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="flag_ita" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\flag_ita.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="flag_usa" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\flag_usa.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="thumbs_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\thumbs_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window_multiple161" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window_multiple16.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="back" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\back.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="reduce" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\reduce.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pos_bottomleft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_bottomleft.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window_opacity16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window_opacity16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pos_topleft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_topleft.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window_switch" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window_switch.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="xiao_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\xiao_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="close_new" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\x-oblique.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pos_topright" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_topright.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window_border16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window_border16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pos_null" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_null.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="xiao_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\xiao_down.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="refresh" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\25.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window_multiple16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window_multiple16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pos_bottomright" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_bottomright.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="refresh" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\25.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="main_icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\icon.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="regions" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\regions.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pos_null" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_null.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="thumbs_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\thumbs_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pos_topleft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_topleft.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="pos_bottomleft" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_bottomleft.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\icon.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="back" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\back.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="xiao_up" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\xiao_up.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ok" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\ok.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="flag_czech" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\flag_czech.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="pos_bottomright" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\pos_bottomright.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window_switch" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window_switch.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="main_icon" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\icon.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="flag_danish" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\flag_danish.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="reduce" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\reduce.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="xiao_ok" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\xiao_ok.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window_multiple161" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window_multiple16.ico;System.Drawing.Icon, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="component" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\component.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="xiao_down" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\xiao_down.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="window_border16" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\window_border16.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="flag_usa" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\flag_usa.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="xiao_add" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\xiao_add.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="xiao_delete" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Assets\xiao_delete.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View file

@ -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;
}
/// <summary>
/// Used to signal to the value change handler that all events should be temporarily ignored.
/// </summary>
/// <remarks>
/// Must be used if the RegionBox is updating the values of the NumericUpDown controls
/// internally and the handler should not raise any event.
/// </remarks>
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);
}
}
}
}

49
OnTopReplica/SidePanel.cs Normal file
View file

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace OnTopReplica {
/// <summary>
/// Represents a side panel that can be embedded in OnTopReplica.
/// </summary>
class SidePanel : UserControl {
public SidePanel() {
Dock = DockStyle.Fill;
}
/// <summary>
/// Gets the panel's parent form.
/// </summary>
protected MainForm ParentForm { get; private set; }
/// <summary>
/// Raised when the side panel requests to be closed.
/// </summary>
public event EventHandler RequestClosing;
protected virtual void OnRequestClosing() {
var evt = RequestClosing;
if (evt != null)
evt(this, EventArgs.Empty);
}
/// <summary>
/// Is called when the side panel is embedded and first shown.
/// </summary>
/// <param name="form">Parent form that is embedding the side panel.</param>
public virtual void OnFirstShown(MainForm form) {
ParentForm = form;
}
/// <summary>
/// Is called before removing the side panel.
/// </summary>
/// <param name="form">Parent form that is embedding the side panel.</param>
public virtual void OnClosing(MainForm form) {
}
}
}

View file

@ -1,5 +1,5 @@
namespace OnTopReplica {
partial class RegionBox {
namespace OnTopReplica.SidePanels {
partial class RegionPanel {
/// <summary>
/// Required designer variable.
/// </summary>
@ -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;
}
}

View file

@ -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
/// <summary>
/// Sets the current selected region to a specific instance of a stored region.
/// </summary>
/// <param name="region">A stored region instance or null to reset.</param>
public void SetRegion(StoredRegion region) {
if (region == null) {
Reset();
return;
}
SetRegion(region.Rect);
//Select right combobox
if (comboRegions.Items.Contains(region)) {
comboRegions.SelectedItem = region;
}
}
/// <summary>
/// Sets the current selected region to a specific region rectangle.
/// </summary>
/// <param name="region">The region boundaries.</param>
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);
}
/// <summary>
/// Resets the selected region and disables the num spinners.
/// </summary>
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
/// <summary>
/// Adds a new stored region.
/// </summary>
/// <param name="rectangle">Region bounds.</param>
/// <param name="regionName">Name of the region.</param>
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);
}
/// <summary>
/// Internal event raised when a change occurs in the selected region.
/// </summary>
/// <param name="regionBounds">Region bounds.</param>
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
}
}

View file

@ -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
}
}

View file

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace OnTopReplica {
/// <summary>
/// Compares two StoredRegions based on their name.
/// </summary>
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
}
}

View file

@ -78,7 +78,6 @@ namespace OnTopReplica {
};
nullRegionItem.Image = Resources.regions;
nullRegionItem.Click += clickHandler;
tsi.DropDownItems.Add(nullRegionItem);
foreach (StoredRegion region in regions) {