优化拾色器
This commit is contained in:
@@ -13,7 +13,7 @@ namespace GeekDesk.Control.Windows
|
||||
/// </summary>
|
||||
public partial class GlobalColorPickerWindow : IWindowCommon
|
||||
{
|
||||
PixelColorPickerWindow colorPickerWindow;
|
||||
PixelColorPickerWindow colorPickerWindow = null;
|
||||
public GlobalColorPickerWindow()
|
||||
{
|
||||
this.Topmost = true;
|
||||
@@ -60,10 +60,12 @@ namespace GeekDesk.Control.Windows
|
||||
|
||||
|
||||
private void MyColorPicker_Checked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
{
|
||||
this.Hide();
|
||||
colorPickerWindow = new PixelColorPickerWindow(MyColorPicker);
|
||||
if (colorPickerWindow == null || !colorPickerWindow.Activate())
|
||||
{
|
||||
colorPickerWindow = new PixelColorPickerWindow(MyColorPicker);
|
||||
}
|
||||
colorPickerWindow.Show();
|
||||
}
|
||||
|
||||
@@ -73,6 +75,22 @@ namespace GeekDesk.Control.Windows
|
||||
}
|
||||
|
||||
private static System.Windows.Window window = null;
|
||||
|
||||
public static void CreateNoShow()
|
||||
{
|
||||
if (window == null || !window.Activate())
|
||||
{
|
||||
window = new GlobalColorPickerWindow();
|
||||
}
|
||||
window.Hide();
|
||||
GlobalColorPickerWindow thisWindow = (GlobalColorPickerWindow)window;
|
||||
if (thisWindow.colorPickerWindow == null || !thisWindow.colorPickerWindow.Activate())
|
||||
{
|
||||
thisWindow.colorPickerWindow = new PixelColorPickerWindow(thisWindow.MyColorPicker);
|
||||
}
|
||||
thisWindow.colorPickerWindow.Show();
|
||||
}
|
||||
|
||||
public static void Show()
|
||||
{
|
||||
if (window == null || !window.Activate())
|
||||
@@ -83,6 +101,20 @@ namespace GeekDesk.Control.Windows
|
||||
Keyboard.Focus(window);
|
||||
}
|
||||
|
||||
public static void ShowOrHide()
|
||||
{
|
||||
if (window == null || !window.Activate())
|
||||
{
|
||||
window = new GlobalColorPickerWindow();
|
||||
window.Show();
|
||||
Keyboard.Focus(window);
|
||||
}
|
||||
else
|
||||
{
|
||||
window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void MyColorPicker_SelectedColorChanged(object sender, HandyControl.Data.FunctionEventArgs<Color> e)
|
||||
{
|
||||
Show();
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
xml:lang="zh-CN"
|
||||
WindowStyle="None"
|
||||
AllowsTransparency="True"
|
||||
Background="Black"
|
||||
PreviewMouseMove="Window_PreviewMouseMove"
|
||||
MouseLeftButtonDown="Window_MouseLeftButtonDown"
|
||||
MouseWheel="Window_MouseWheel"
|
||||
@@ -19,11 +20,8 @@
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<Grid x:Name="DesktopBG">
|
||||
<Grid.Background>
|
||||
<ImageBrush Stretch="Fill"/>
|
||||
</Grid.Background>
|
||||
</Grid>
|
||||
<Image x:Name="DesktopBG" RenderOptions.BitmapScalingMode="HighQuality"/>
|
||||
|
||||
<Canvas HorizontalAlignment="Left" VerticalAlignment="Top" Background="Transparent">
|
||||
<Canvas x:Name="ColorCanvas"
|
||||
Width="185"
|
||||
@@ -47,6 +45,7 @@
|
||||
VerticalAlignment="Center"
|
||||
Width="70"
|
||||
Height="70"
|
||||
Background="Black"
|
||||
BorderBrush="Black"
|
||||
BorderThickness="1"
|
||||
Margin="20,0,0,0"
|
||||
|
||||
@@ -66,16 +66,13 @@ namespace GeekDesk.Control.Windows
|
||||
bgBitmap.Size
|
||||
);
|
||||
}
|
||||
|
||||
BitmapSource bs = Imaging.CreateBitmapSourceFromHBitmap(
|
||||
bgBitmap.GetHbitmap(),
|
||||
IntPtr.Zero,
|
||||
Int32Rect.Empty,
|
||||
BitmapSizeOptions.FromEmptyOptions()
|
||||
);
|
||||
ImageBrush ib = (ImageBrush)DesktopBG.Background;
|
||||
ib.ImageSource = bs;
|
||||
|
||||
DesktopBG.Source = bs;
|
||||
VisualBrush b = (VisualBrush)PixelBG.Fill;
|
||||
b.Visual = DesktopBG;
|
||||
Mouse.OverrideCursor = Cursors.Cross;
|
||||
@@ -83,10 +80,6 @@ namespace GeekDesk.Control.Windows
|
||||
}
|
||||
|
||||
|
||||
[DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
|
||||
public static extern int BitBlt(IntPtr hDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);
|
||||
|
||||
|
||||
public void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key == Key.Escape)
|
||||
@@ -98,13 +91,13 @@ namespace GeekDesk.Control.Windows
|
||||
|
||||
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
Mouse.OverrideCursor = null;
|
||||
Point pos = e.MouseDevice.GetPosition(DesktopBG);
|
||||
System.Drawing.Color colorD = bgBitmap.GetPixel((int)pos.X, (int)pos.Y);
|
||||
colorPicker.SelectedBrush = new SolidColorBrush(Color.FromArgb(colorD.A, colorD.R, colorD.G, colorD.B));
|
||||
DeleteObject(bgBitmap.GetHbitmap());
|
||||
this.Close();
|
||||
ClickColorPickerToggleButton(colorPicker);
|
||||
|
||||
}
|
||||
|
||||
public void ClickColorPickerToggleButton(ColorPicker colorPicker)
|
||||
@@ -121,13 +114,7 @@ namespace GeekDesk.Control.Windows
|
||||
mi.Invoke(colorPicker, new object[] { null, null });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Window_MouseEnter(object sender, MouseEventArgs e)
|
||||
{
|
||||
Mouse.OverrideCursor = Cursors.Cross;
|
||||
}
|
||||
|
||||
|
||||
private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
SetPixelAbout(e);
|
||||
|
||||
Reference in New Issue
Block a user