Fix for the High-DPI problems with the color dialog.

This commit is contained in:
Robin 2018-06-05 11:21:52 +02:00
commit 3697675310
2 changed files with 42 additions and 16 deletions

View file

@ -65,6 +65,8 @@ namespace Greenshot.Addon.LegacyEditor.Controls {
this.labelAlpha = new Greenshot.Addons.Controls.GreenshotLabel();
this.btnApply = new Greenshot.Addons.Controls.GreenshotButton();
this.pipette = new Greenshot.Addon.LegacyEditor.Controls.Pipette();
this.panelColors = new System.Windows.Forms.Panel();
this.panelRecentColors = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// btnTransparent
@ -184,7 +186,7 @@ namespace Greenshot.Addon.LegacyEditor.Controls {
// labelRecentColors
//
this.labelRecentColors.LanguageKey = "colorpicker_recentcolors";
this.labelRecentColors.Location = new System.Drawing.Point(0, 335);
this.labelRecentColors.Location = new System.Drawing.Point(0, 337);
this.labelRecentColors.Name = "labelRecentColors";
this.labelRecentColors.Size = new System.Drawing.Size(411, 30);
this.labelRecentColors.TabIndex = 10;
@ -239,11 +241,27 @@ namespace Greenshot.Addon.LegacyEditor.Controls {
this.pipette.TabIndex = 13;
this.pipette.PipetteUsed += new System.EventHandler<Greenshot.Addon.LegacyEditor.Controls.PipetteUsedArgs>(this.PipetteUsed);
//
// panelColors
//
this.panelColors.Location = new System.Drawing.Point(5, 7);
this.panelColors.Name = "panelColors";
this.panelColors.Size = new System.Drawing.Size(406, 328);
this.panelColors.TabIndex = 14;
//
// panelRecentColors
//
this.panelRecentColors.Location = new System.Drawing.Point(5, 366);
this.panelRecentColors.Name = "panelRecentColors";
this.panelRecentColors.Size = new System.Drawing.Size(406, 30);
this.panelRecentColors.TabIndex = 15;
//
// ColorDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(584, 404);
this.Controls.Add(this.panelRecentColors);
this.Controls.Add(this.panelColors);
this.Controls.Add(this.pipette);
this.Controls.Add(this.btnApply);
this.Controls.Add(this.textBoxAlpha);
@ -289,5 +307,7 @@ namespace Greenshot.Addon.LegacyEditor.Controls {
private System.Windows.Forms.Panel colorPanel;
private GreenshotButton btnTransparent;
private Pipette pipette;
}
private System.Windows.Forms.Panel panelColors;
private System.Windows.Forms.Panel panelRecentColors;
}
}

View file

@ -45,7 +45,6 @@ namespace Greenshot.Addon.LegacyEditor.Controls
private readonly IEditorConfiguration _editorConfiguration;
private readonly ToolTip _toolTip = new ToolTip();
private bool _updateInProgress;
private IList<Control> _recentColorButtons;
public ColorDialog(
IEditorConfiguration editorConfiguration,
@ -60,15 +59,16 @@ namespace Greenshot.Addon.LegacyEditor.Controls
private void DrawButtons()
{
int pos = FormDpiHandler.ScaleWithCurrentDpi(5);
int size = FormDpiHandler.ScaleWithCurrentDpi(15);
var buttons = CreateColorPalette(pos, pos, size, size);
int lastColorY = FormDpiHandler.ScaleWithCurrentDpi(185);
_recentColorButtons = CreateLastUsedColorButtonRow(pos, lastColorY, size, size);
UpdateRecentColorsButtonRow();
var buttons = CreateColorPalette(size, size);
var recentColorButtons = CreateLastUsedColorButtonRow(size, size);
SuspendLayout();
Controls.AddRange(buttons.ToArray());
Controls.AddRange(_recentColorButtons.ToArray());
panelColors.Controls.Clear();
panelColors.Controls.AddRange(buttons.ToArray());
panelRecentColors.Controls.Clear();
panelRecentColors.Controls.AddRange(recentColorButtons.ToArray());
UpdateRecentColorsButtonRow();
ResumeLayout();
}
@ -103,9 +103,12 @@ namespace Greenshot.Addon.LegacyEditor.Controls
#region user interface generation
private IList<Control> CreateColorPalette(int x, int y, int w, int h)
private IList<Control> CreateColorPalette(int w, int h)
{
IList<Control> colorButtons = new List<Control>();
int x = 0;
int y = 0;
IList<Control> colorButtons = new List<Control>();
CreateColorButtonColumn(colorButtons, 255, 0, 0, x, y, w, h, 11);
x += w;
CreateColorButtonColumn(colorButtons, 255, 255 / 2, 0, x, y, w, h, 11);
@ -170,9 +173,12 @@ namespace Greenshot.Addon.LegacyEditor.Controls
return b;
}
private IList<Control> CreateLastUsedColorButtonRow(int x, int y, int w, int h)
private IList<Control> CreateLastUsedColorButtonRow(int w, int h)
{
IList<Control> recentColorButtons = new List<Control>();
int x = 0;
int y = 0;
IList<Control> recentColorButtons = new List<Control>();
for (var i = 0; i < 12; i++)
{
@ -193,8 +199,8 @@ namespace Greenshot.Addon.LegacyEditor.Controls
{
for (var i = 0; i < _editorConfiguration.RecentColors.Count && i < 12; i++)
{
_recentColorButtons[i].BackColor = _editorConfiguration.RecentColors[i];
_recentColorButtons[i].Enabled = true;
panelRecentColors.Controls[i].BackColor = _editorConfiguration.RecentColors[i];
panelRecentColors.Controls[i].Enabled = true;
}
}