Improved region drawing on thumbnail.

Updated to version 2.9.3.
This commit is contained in:
Lorenz Cuno Klopfenstein 2010-05-10 01:27:07 +02:00
parent 8424f2f7fd
commit 812347fe8b
3 changed files with 57 additions and 20 deletions

View file

@ -49,8 +49,8 @@
<CreateWebPageOnPublish>true</CreateWebPageOnPublish> <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>publish.htm</WebPage> <WebPage>publish.htm</WebPage>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish> <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>2</ApplicationRevision> <ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>2.9.2.%2a</ApplicationVersion> <ApplicationVersion>2.9.3.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted> <PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
@ -224,7 +224,7 @@
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>.NET Framework Client Profile</ProductName> <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0"> <BootstrapperPackage Include="Microsoft.Net.Framework.2.0">

View file

@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.9.2.0")] [assembly: AssemblyVersion("2.9.3.0")]
[assembly: AssemblyFileVersion("2.9.2.0")] [assembly: AssemblyFileVersion("2.9.3.0")]

View file

@ -70,9 +70,7 @@ namespace OnTopReplica {
set { set {
_glassMode = value; _glassMode = value;
//Set correct backcolor: black if glass is on UpdateBackColor();
BackColor = (value || _fullscreenMode) ? Color.Black : SystemColors.Control;
UpdateRightClickLabels(); UpdateRightClickLabels();
} }
} }
@ -85,14 +83,14 @@ namespace OnTopReplica {
} }
set { set {
_fullscreenMode = value; _fullscreenMode = value;
UpdateBackColor();
//Set correct backcolor: black if fullscreen is on
BackColor = (value || _glassMode) ? Color.Black : SystemColors.Control;
UpdateRightClickLabels(); UpdateRightClickLabels();
} }
} }
/// <summary>
/// Gets or sets the region that is currently shown on the thumbnail. When set, enabled region showing.
/// </summary>
public Rectangle ShownRegion { public Rectangle ShownRegion {
get { get {
return _regionCurrent; return _regionCurrent;
@ -105,6 +103,9 @@ namespace OnTopReplica {
} }
} }
/// <summary>
/// Gets or sets whether the thumbnail is constrained to a region or not.
/// </summary>
public bool ShowRegion { public bool ShowRegion {
get { get {
return _regionEnabled; return _regionEnabled;
@ -118,6 +119,9 @@ namespace OnTopReplica {
bool _drawMouseRegions = false; bool _drawMouseRegions = false;
/// <summary>
/// Gets or sets whether the thumbnail allows region drawing.
/// </summary>
public bool DrawMouseRegions { public bool DrawMouseRegions {
get { get {
return _drawMouseRegions; return _drawMouseRegions;
@ -235,6 +239,13 @@ namespace OnTopReplica {
return ret; return ret;
} }
/// <summary>
/// Updates the background color.
/// </summary>
private void UpdateBackColor() {
BackColor = (FullscreenMode || GlassMode) ? Color.Black : SystemColors.Control;
}
/// <summary>Updates the right-click labels.</summary> /// <summary>Updates the right-click labels.</summary>
/// <remarks>If a thumbnail is shown no label will be visible. If no thumbnail is active, the correct label will be visible.</remarks> /// <remarks>If a thumbnail is shown no label will be visible. If no thumbnail is active, the correct label will be visible.</remarks>
private void UpdateRightClickLabels(){ private void UpdateRightClickLabels(){
@ -244,9 +255,6 @@ namespace OnTopReplica {
_labelNoGlass.Visible = false; _labelNoGlass.Visible = false;
} }
else { else {
//Update text (removed, can't draw regions behind non-transparent ThemedLabel control)
//_labelGlass.Text = _labelNoGlass.Text = (_drawMouseRegions) ? Strings.DrawRegions : Strings.RightClick;
//Update visibility //Update visibility
_labelGlass.Visible = _glassMode; _labelGlass.Visible = _glassMode;
_labelNoGlass.Visible = !_glassMode; _labelNoGlass.Visible = !_glassMode;
@ -272,6 +280,7 @@ namespace OnTopReplica {
} }
protected override void OnMouseClick(MouseEventArgs e) { protected override void OnMouseClick(MouseEventArgs e) {
//Raise clicking event to allow click forwarding
if (!_clickThrough && e.Button == MouseButtons.Left) { if (!_clickThrough && e.Button == MouseButtons.Left) {
if(_thumbnail != null) if(_thumbnail != null)
OnCloneClick(ScreenToThumbnail(e.Location), false); OnCloneClick(ScreenToThumbnail(e.Location), false);
@ -281,6 +290,7 @@ namespace OnTopReplica {
} }
protected override void OnMouseDoubleClick(MouseEventArgs e) { protected override void OnMouseDoubleClick(MouseEventArgs e) {
//Raise double clicking event to allow click forwarding
if (!_clickThrough && e.Button == MouseButtons.Left) { if (!_clickThrough && e.Button == MouseButtons.Left) {
if (_thumbnail != null) if (_thumbnail != null)
OnCloneClick(ScreenToThumbnail(e.Location), true); OnCloneClick(ScreenToThumbnail(e.Location), true);
@ -290,8 +300,10 @@ namespace OnTopReplica {
} }
protected override void OnMouseDown(MouseEventArgs e) { protected override void OnMouseDown(MouseEventArgs e) {
if (_drawMouseRegions && e.Button == MouseButtons.Left) { if (DrawMouseRegions && e.Button == MouseButtons.Left) {
//Start new region drawing
_drawingRegion = true; _drawingRegion = true;
_drawingSuspended = false;
_regionStartPoint = _regionLastPoint = e.Location; _regionStartPoint = _regionLastPoint = e.Location;
this.Invalidate(); this.Invalidate();
@ -302,8 +314,9 @@ namespace OnTopReplica {
protected override void OnMouseUp(MouseEventArgs e) { protected override void OnMouseUp(MouseEventArgs e) {
if (_drawMouseRegions && e.Button == MouseButtons.Left) { if (_drawMouseRegions && e.Button == MouseButtons.Left) {
//Region completed
_drawingRegion = false; _drawingRegion = false;
_drawingSuspended = false;
HandleRegionDrawn(_regionStartPoint, _regionLastPoint); HandleRegionDrawn(_regionStartPoint, _regionLastPoint);
this.Invalidate(); this.Invalidate();
@ -313,20 +326,30 @@ namespace OnTopReplica {
} }
protected override void OnMouseLeave(EventArgs e) { protected override void OnMouseLeave(EventArgs e) {
_drawingRegion = false; _drawingSuspended = true;
this.Invalidate(); this.Invalidate();
base.OnMouseLeave(e); base.OnMouseLeave(e);
} }
protected override void OnMouseEnter(EventArgs e) {
_drawingSuspended = false;
this.Invalidate();
base.OnMouseEnter(e);
}
protected override void OnMouseMove(MouseEventArgs e) { protected override void OnMouseMove(MouseEventArgs e) {
if (_drawingRegion && e.Button == MouseButtons.Left) { if (_drawingRegion && e.Button == MouseButtons.Left) {
//Continue drawing
_regionLastPoint = e.Location; _regionLastPoint = e.Location;
this.Invalidate(); this.Invalidate();
} }
else if(_drawMouseRegions && !_drawingRegion){ else if(DrawMouseRegions && !_drawingRegion){
//Keep track of region start point
_regionLastPoint = e.Location; _regionLastPoint = e.Location;
this.Invalidate(); this.Invalidate();
@ -339,6 +362,7 @@ namespace OnTopReplica {
protected override void OnPaint(PaintEventArgs e) { protected override void OnPaint(PaintEventArgs e) {
if (_drawingRegion) { if (_drawingRegion) {
//Is currently drawing, show rectangle
int left = Math.Min(_regionStartPoint.X, _regionLastPoint.X); int left = Math.Min(_regionStartPoint.X, _regionLastPoint.X);
int right = Math.Max(_regionStartPoint.X, _regionLastPoint.X); int right = Math.Max(_regionStartPoint.X, _regionLastPoint.X);
int top = Math.Min(_regionStartPoint.Y, _regionLastPoint.Y); int top = Math.Min(_regionStartPoint.Y, _regionLastPoint.Y);
@ -346,7 +370,8 @@ namespace OnTopReplica {
e.Graphics.DrawRectangle(penRed, left, top, right - left, bottom - top); e.Graphics.DrawRectangle(penRed, left, top, right - left, bottom - top);
} }
else if (_drawMouseRegions) { else if (DrawMouseRegions && ! _drawingSuspended) {
//Show cursor coordinates
e.Graphics.DrawLine(penRed, new Point(0, _regionLastPoint.Y), new Point(ClientSize.Width, _regionLastPoint.Y)); e.Graphics.DrawLine(penRed, new Point(0, _regionLastPoint.Y), new Point(ClientSize.Width, _regionLastPoint.Y));
e.Graphics.DrawLine(penRed, new Point(_regionLastPoint.X, 0), new Point(_regionLastPoint.X, ClientSize.Height)); e.Graphics.DrawLine(penRed, new Point(_regionLastPoint.X, 0), new Point(_regionLastPoint.X, ClientSize.Height));
} }
@ -356,7 +381,10 @@ namespace OnTopReplica {
#endregion #endregion
//Set if currently drawing a window (first click/drag was initiated)
bool _drawingRegion = false; bool _drawingRegion = false;
//Set if drawing was suspended because the mouse left the control
bool _drawingSuspended = false;
Point _regionStartPoint; Point _regionStartPoint;
Point _regionLastPoint; Point _regionLastPoint;
@ -390,11 +418,20 @@ namespace OnTopReplica {
} }
protected void HandleRegionDrawn(Point start, Point end) { protected void HandleRegionDrawn(Point start, Point end) {
if (thumbnailSize.Width == 0 || thumbnailSize.Height == 0) //causes DivBy0
return;
int left = Math.Min(start.X, end.X); int left = Math.Min(start.X, end.X);
int right = Math.Max(start.X, end.X); int right = Math.Max(start.X, end.X);
int top = Math.Min(start.Y, end.Y); int top = Math.Min(start.Y, end.Y);
int bottom = Math.Max(start.Y, end.Y); int bottom = Math.Max(start.Y, end.Y);
//Clip to boundaries
left = Math.Max(0, left);
right = Math.Min(thumbnailSize.Width, right);
top = Math.Max(0, top);
bottom = Math.Min(thumbnailSize.Height, bottom);
//Offset points of padding space around thumbnail //Offset points of padding space around thumbnail
left -= padWidth; left -= padWidth;
right -= padWidth; right -= padWidth;