mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1657 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
98 lines
3.1 KiB
C#
98 lines
3.1 KiB
C#
/*
|
|
* Greenshot - a free and open source screenshot tool
|
|
* Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom
|
|
*
|
|
* For more information see: http://getgreenshot.org/
|
|
* The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 1 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
using System;
|
|
using System.Windows.Forms;
|
|
using System.Drawing;
|
|
using GreenshotPlugin.UnmanagedHelpers;
|
|
|
|
namespace Greenshot.Forms {
|
|
/// <summary>
|
|
/// This code was supplied by Hi-Coder as a patch for Greenshot
|
|
/// Needed some modifications to be stable.
|
|
/// </summary>
|
|
public partial class Zoomer : Form {
|
|
public Color color {
|
|
get {
|
|
return preview.BackColor;
|
|
}
|
|
}
|
|
|
|
public Zoomer() {
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void setHotSpot(int x, int y) {
|
|
Color c = GetPixelColor(x, y);
|
|
preview.BackColor = c;
|
|
html.Text = "#" + c.Name.Substring(2).ToUpper();
|
|
red.Text = "" + c.R;
|
|
blue.Text = "" + c.B;
|
|
green.Text = "" + c.G;
|
|
alpha.Text = "" + c.A;
|
|
|
|
Size cursorSize = Cursor.Current.Size;
|
|
Point hotspot = Cursor.Current.HotSpot;
|
|
|
|
Point zoomerLocation = new Point(x, y);
|
|
zoomerLocation.X += cursorSize.Width + 5 - hotspot.X;
|
|
zoomerLocation.Y += cursorSize.Height + 5 - hotspot.Y;
|
|
|
|
foreach (Screen screen in Screen.AllScreens) {
|
|
Rectangle screenRectangle = screen.Bounds;
|
|
if (screen.Bounds.Contains(x, y)) {
|
|
if (zoomerLocation.X < screenRectangle.X) {
|
|
zoomerLocation.X = screenRectangle.X;
|
|
} else if (zoomerLocation.X + Width > screenRectangle.X + screenRectangle.Width) {
|
|
zoomerLocation.X = x - Width - 5 - hotspot.X;
|
|
}
|
|
|
|
if (zoomerLocation.Y < screenRectangle.Y) {
|
|
zoomerLocation.Y = screenRectangle.Y;
|
|
} else if (zoomerLocation.Y + Height > screenRectangle.Y + screenRectangle.Height) {
|
|
zoomerLocation.Y = y - Height - 5 - hotspot.Y;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
Location = zoomerLocation;
|
|
Update();
|
|
}
|
|
|
|
public void setHotSpot(Point screenCoordinates) {
|
|
setHotSpot(screenCoordinates.X, screenCoordinates.Y);
|
|
}
|
|
|
|
static private Color GetPixelColor(int x, int y) {
|
|
IntPtr hdc = User32.GetDC(IntPtr.Zero);
|
|
try {
|
|
uint pixel = GDI32.GetPixel(hdc, x, y);
|
|
Color color = Color.FromArgb(255, (int)(pixel & 0xFF), (int)(pixel & 0xFF00) >> 8, (int)(pixel & 0xFF0000) >> 16);
|
|
return color;
|
|
} catch (Exception) {
|
|
return Color.Empty;
|
|
} finally {
|
|
if (hdc != IntPtr.Zero) {
|
|
User32.ReleaseDC(IntPtr.Zero, hdc);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|