优化拾色器

This commit is contained in:
liufei
2022-05-23 17:52:35 +08:00
parent 09ab951ccd
commit ddabf0a113
6 changed files with 67 additions and 44 deletions

View File

@@ -99,22 +99,8 @@ namespace GeekDesk.Control.Other
private void MyColorPickerClose(object sender)
{
ClickColorPickerToggleButton(sender as HandyControl.Controls.ColorPicker);
dialog.Close();
}
public void ClickColorPickerToggleButton(HandyControl.Controls.ColorPicker colorPicker)
{
if (toggleButton != null && toggleButton.IsChecked == true)
{
const BindingFlags InstanceBindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
Type type = colorPicker.GetType();
toggleButton.IsChecked = false;
MethodInfo mi = type.GetMethod("ToggleButtonDropper_Click", InstanceBindFlags);
mi.Invoke(colorPicker, new object[] { null, null });
}
}
}
}

View File

@@ -13,7 +13,7 @@ namespace GeekDesk.Control.Windows
/// </summary>
public partial class GlobalColorPickerWindow : IWindowCommon
{
PixelColorPickerWindow colorPickerWindow;
PixelColorPickerWindow colorPickerWindow = null;
public GlobalColorPickerWindow()
{
this.Topmost = true;
@@ -61,9 +61,11 @@ namespace GeekDesk.Control.Windows
private void MyColorPicker_Checked(object sender, RoutedEventArgs e)
{
this.Hide();
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();

View File

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

View File

@@ -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)
@@ -122,12 +115,6 @@ namespace GeekDesk.Control.Windows
}
}
private void Window_MouseEnter(object sender, MouseEventArgs e)
{
Mouse.OverrideCursor = Cursors.Cross;
}
private void Window_PreviewMouseMove(object sender, MouseEventArgs e)
{
SetPixelAbout(e);

View File

@@ -145,9 +145,10 @@
<uc:RightCardControl x:Name="RightCard" Grid.Row="1" Grid.Column="1"/>
<hc:NotifyIcon Icon="/Taskbar.ico" Click="NotifyIcon_Click" x:Name="BarIcon"
MouseRightButtonDown="BarIcon_MouseRightButtonDown"
Visibility="{Binding AppConfig.ShowBarIcon, Mode=TwoWay, Converter={StaticResource Boolean2VisibilityConverter}}">
<hc:NotifyIcon.ContextMenu>
<ContextMenu Width="130">
<ContextMenu Width="130" x:Name="TaskbarContextMenu">
<MenuItem Header="打开面板" Click="ShowApp"/>
<MenuItem Header="拾色器" Click="ColorPicker"/>
<MenuItem Header="隐藏图标" Click="CloseBarIcon"/>

View File

@@ -16,6 +16,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Animation;
using System.Windows.Threading;
using static GeekDesk.Util.ShowWindowFollowMouse;
namespace GeekDesk
@@ -243,7 +244,7 @@ namespace GeekDesk
{
if (MotionControl.hotkeyFinished)
{
ToDoInfoWindow.ShowOrHide();
ToDoWindow.ShowOrHide();
}
});
if (!first)
@@ -273,7 +274,6 @@ namespace GeekDesk
{
try
{
if (appData.AppConfig.ColorPickerHotkeyModifiers != 0)
{
//加载完毕注册热键
@@ -281,7 +281,7 @@ namespace GeekDesk
{
if (MotionControl.hotkeyFinished)
{
GlobalColorPickerWindow.Show();
GlobalColorPickerWindow.CreateNoShow();
}
});
if (!first)
@@ -432,6 +432,7 @@ namespace GeekDesk
if (RunTimeStatus.SEARCH_BOX_SHOW)
{
mainWindow.HidedSearchBox();
Thread t = new Thread(() =>
{
Thread.Sleep(100);
@@ -682,9 +683,26 @@ namespace GeekDesk
RunTimeStatus.MARGIN_HIDE_AND_OTHER_SHOW = false;
}
/// <summary>
/// 打开屏幕拾色器
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ColorPicker(object sender, RoutedEventArgs e)
{
GlobalColorPickerWindow.Show();
TaskbarContextMenu.Visibility = Visibility.Collapsed;
App.DoEvents();
GlobalColorPickerWindow.CreateNoShow();
}
/// <summary>
/// 防止点击拾色器后无法显示菜单的问题
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void BarIcon_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
TaskbarContextMenu.Visibility = Visibility.Visible;
}
}
}