From 75aa7829f8a05f60d8dccca0b3f2152b8eba7d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Concei=C3=A7=C3=A3o?= Date: Sat, 12 Sep 2020 17:35:10 +0100 Subject: [PATCH] Layer overlay tooltip is now semi-transparent --- CHANGELOG.md | 1 + UVtools.GUI/Controls/TransparentLabel.cs | 87 ++++++++++++++++++++++++ UVtools.GUI/FrmMain.Designer.cs | 34 +++++---- UVtools.GUI/FrmMain.cs | 29 -------- UVtools.GUI/FrmMain.resx | 2 +- UVtools.GUI/UVtools.GUI.csproj | 3 + 6 files changed, 111 insertions(+), 45 deletions(-) create mode 100644 UVtools.GUI/Controls/TransparentLabel.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 9027ab7..44b5e27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * (Change) Layer status bar: Pixel picker text to button - Click to center in point * (Change) Layer status bar: Resolution text to button - Click to zoom to fit * (Change) Customized cursor for Pixel Edit mode (#51) +* (Change) Layer overlay tooltip is now semi-transparent * (Fix) Misc. text cleanup (#52) ## 12/09/2020 - v0.8.1.0 diff --git a/UVtools.GUI/Controls/TransparentLabel.cs b/UVtools.GUI/Controls/TransparentLabel.cs new file mode 100644 index 0000000..0119179 --- /dev/null +++ b/UVtools.GUI/Controls/TransparentLabel.cs @@ -0,0 +1,87 @@ +/* + * GNU AFFERO GENERAL PUBLIC LICENSE + * Version 3, 19 November 2007 + * Copyright (C) 2007 Free Software Foundation, Inc. + * Everyone is permitted to copy and distribute verbatim copies + * of this license document, but changing it is not allowed. + */ +// https://stackoverflow.com/questions/34335157/show-a-label-with-semi-transparent-backcolor-above-other-controls + +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; + +namespace UVtools.GUI.Controls +{ + public class TransparentLabel : Label + { + public TransparentLabel() + { + transparentBackColor = Color.Blue; + opacity = 50; + BackColor = Color.Transparent; + DoubleBuffered = true; + } + + protected override void OnPaint(PaintEventArgs e) + { + if (Parent == null) return; + using (var bmp = new Bitmap(Parent.Width, Parent.Height)) + { + Parent.Controls.Cast() + .Where(c => Parent.Controls.GetChildIndex(c) > Parent.Controls.GetChildIndex(this)) + .Where(c => c.Bounds.IntersectsWith(Bounds)) + .OrderByDescending(c => Parent.Controls.GetChildIndex(c)) + .ToList() + .ForEach(c => c.DrawToBitmap(bmp, c.Bounds)); + + + e.Graphics.DrawImage(bmp, -Left, -Top); + using (var b = new SolidBrush(Color.FromArgb(Opacity, TransparentBackColor))) + { + e.Graphics.FillRectangle(b, ClientRectangle); + } + e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; + var rectangle = ClientRectangle; + rectangle.X += Padding.Left; + //rectangle.Y += Padding.Top; + //rectangle.Width -= Padding.Left - Padding.Right; + //rectangle.Height -= Padding.Top - Padding.Bottom; + TextRenderer.DrawText(e.Graphics, Text, Font, rectangle, ForeColor, Color.Transparent, TextFormatFlags.VerticalCenter); + } + } + + private int opacity; + public int Opacity + { + get => opacity; + set + { + if (value >= 0 && value <= 255) + opacity = value; + Invalidate(); + } + } + + private Color transparentBackColor; + public Color TransparentBackColor + { + get => transparentBackColor; + set + { + transparentBackColor = value; + Invalidate(); + } + } + + [Browsable(false)] + public override Color BackColor + { + get => Color.Transparent; + set => base.BackColor = Color.Transparent; + } + } +} diff --git a/UVtools.GUI/FrmMain.Designer.cs b/UVtools.GUI/FrmMain.Designer.cs index fbc3110..920f59c 100644 --- a/UVtools.GUI/FrmMain.Designer.cs +++ b/UVtools.GUI/FrmMain.Designer.cs @@ -61,7 +61,6 @@ namespace UVtools.GUI this.statusBar = new System.Windows.Forms.StatusStrip(); this.mainTable = new System.Windows.Forms.TableLayoutPanel(); this.scCenter = new System.Windows.Forms.SplitContainer(); - this.lbLayerImageOverlay = new System.Windows.Forms.Label(); this.pbLayer = new Cyotek.Windows.Forms.ImageBox(); this.tsLayer = new System.Windows.Forms.ToolStrip(); this.btnLayerImageExport = new System.Windows.Forms.ToolStripSplitButton(); @@ -259,6 +258,7 @@ namespace UVtools.GUI this.toolTipInformation = new System.Windows.Forms.ToolTip(this.components); this.layerScrollTimer = new System.Windows.Forms.Timer(this.components); this.mouseHoldTimer = new System.Windows.Forms.Timer(this.components); + this.lbLayerImageOverlay = new UVtools.GUI.Controls.TransparentLabel(); this.tbLayer = new UVtools.GUI.Controls.TrackBarEx(); this.menu.SuspendLayout(); this.mainTable.SuspendLayout(); @@ -608,19 +608,6 @@ namespace UVtools.GUI this.scCenter.SplitterDistance = 730; this.scCenter.TabIndex = 4; // - // lbLayerImageOverlay - // - this.lbLayerImageOverlay.AutoSize = true; - this.lbLayerImageOverlay.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); - this.lbLayerImageOverlay.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.lbLayerImageOverlay.Location = new System.Drawing.Point(13, 37); - this.lbLayerImageOverlay.Name = "lbLayerImageOverlay"; - this.lbLayerImageOverlay.Padding = new System.Windows.Forms.Padding(5); - this.lbLayerImageOverlay.Size = new System.Drawing.Size(70, 30); - this.lbLayerImageOverlay.TabIndex = 8; - this.lbLayerImageOverlay.Text = "Overlay"; - this.lbLayerImageOverlay.Visible = false; - // // pbLayer // this.pbLayer.AllowDoubleClick = true; @@ -2856,6 +2843,23 @@ namespace UVtools.GUI this.mouseHoldTimer.Interval = 1000; this.mouseHoldTimer.Tick += new System.EventHandler(this.EventTimerTick); // + // lbLayerImageOverlay + // + this.lbLayerImageOverlay.AutoSize = true; + this.lbLayerImageOverlay.BackColor = System.Drawing.Color.Transparent; + this.lbLayerImageOverlay.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.lbLayerImageOverlay.CausesValidation = false; + this.lbLayerImageOverlay.Location = new System.Drawing.Point(13, 37); + this.lbLayerImageOverlay.Name = "lbLayerImageOverlay"; + this.lbLayerImageOverlay.Opacity = 210; + this.lbLayerImageOverlay.Padding = new System.Windows.Forms.Padding(10); + this.lbLayerImageOverlay.Size = new System.Drawing.Size(80, 40); + this.lbLayerImageOverlay.TabIndex = 8; + this.lbLayerImageOverlay.Text = "Overlay"; + this.lbLayerImageOverlay.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + this.lbLayerImageOverlay.TransparentBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); + this.lbLayerImageOverlay.Visible = false; + // // tbLayer // this.tbLayer.Dock = System.Windows.Forms.DockStyle.Right; @@ -3204,7 +3208,7 @@ namespace UVtools.GUI private System.Windows.Forms.ToolStripSplitButton btnLayerImageActions; private System.Windows.Forms.ToolStripSeparator toolStripSeparator26; private System.Windows.Forms.ToolStripButton btnLogVerbose; - private System.Windows.Forms.Label lbLayerImageOverlay; + private TransparentLabel lbLayerImageOverlay; public Cyotek.Windows.Forms.ImageBox pbLayer; private System.Windows.Forms.ToolStripSeparator toolStripSeparator27; private System.Windows.Forms.ToolStripButton btnLayerROI; diff --git a/UVtools.GUI/FrmMain.cs b/UVtools.GUI/FrmMain.cs index 4da3d69..3f1365d 100644 --- a/UVtools.GUI/FrmMain.cs +++ b/UVtools.GUI/FrmMain.cs @@ -735,35 +735,6 @@ namespace UVtools.GUI ShowRunOperation(baseOperation.GetType()); return; } - if (!ReferenceEquals(menuItem.Tag, null)) - { - if (menuItem.Tag.GetType() == typeof(FileFormat.PrintParameterModifier)) - { - FileFormat.PrintParameterModifier modifier = (FileFormat.PrintParameterModifier) menuItem.Tag; - using (FrmInputBox inputBox = new FrmInputBox(modifier, - decimal.Parse(SlicerFile.GetValueFromPrintParameterModifier(modifier).ToString()))) - { - if (inputBox.ShowDialog() != DialogResult.OK) return; - var value = inputBox.NewValue; - - if (!SlicerFile.SetValueFromPrintParameterModifier(modifier, value)) - { - MessageBox.Show( - $"Unable to set '{modifier.Name}'. Value was not found, it may not yet be implemented.", - "Operation error", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - RefreshInfo(); - - menuFileSave.Enabled = - menuFileSaveAs.Enabled = true; - } - - return; - - } - } // About if (ReferenceEquals(menuItem, menuHelpAbout)) diff --git a/UVtools.GUI/FrmMain.resx b/UVtools.GUI/FrmMain.resx index cec6f7b..97158bb 100644 --- a/UVtools.GUI/FrmMain.resx +++ b/UVtools.GUI/FrmMain.resx @@ -174,7 +174,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABk - FAAAAk1TRnQBSQFMAgEBBgEAAaABCwGgAQsBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA + FAAAAk1TRnQBSQFMAgEBBgEAAfgBCwH4AQsBEAEAARABAAT/ASEBAAj/AUIBTQE2BwABNgMAASgDAAFA AwABIAMAAQEBAAEgBgABIC4AAxgBIgMwAUsDMAFMAzIBUDMAAQEDJAE2AysBQqwAAyIBMQNWAbkDXQHi AwAB/wMAAf8BKgEtASgB/gNTAawDTQGVAwABARgAAwkBDAMzAVIDUAGdA1cB6AMAAf4DKwH8Ay8BSqQA AyEBMANZAewBKwEuASkB+gNRAfcDUgH0A1MB8QNIAfYDQQH5AwAB/wNPAZsDAAEBCAADFQEdAz8BbgNV diff --git a/UVtools.GUI/UVtools.GUI.csproj b/UVtools.GUI/UVtools.GUI.csproj index 36123d7..ce2e5d3 100644 --- a/UVtools.GUI/UVtools.GUI.csproj +++ b/UVtools.GUI/UVtools.GUI.csproj @@ -281,6 +281,9 @@ Component + + Component +