protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { DrawInternalBackground(e, true); Image image = null; if (!string.IsNullOrEmpty(m_ImageName)) { image = (Bitmap)GUIUtilities.RM.GetObject(m_ImageName); } else if (m_eVerb != Codes.None) { image = GUIUtilities.VariableSizeImage("Verb", "_" + m_eVerb, this.Width - EXCESSSIZE); } if (m_Image != null) { image = m_Image; } if (image != null) { DrawStandardImage(e.Graphics, image); if (image != m_Image) { image.Dispose(); } } DrawHighlightAndKey(e); }
public override void DrawImage(string resourceName, int preferredSize, RectangleF destination, RectangleF sourceRect, System.Drawing.Imaging.ImageAttributes attributes = null) { Image image = GUIUtilities.VariableSizeImage(resourceName, "", preferredSize); string ID = PrepareImage((Bitmap)image, resourceName.GetHashCode(), sourceRect); SimpleImage(ID, sourceRect.Size, destination); }
public Image GetNetImage(int sizeIfResource = 32) { // once the image is created it is not disposed at the moment. If it is being drawn on-screen it will be needed repeatedly if (!string.IsNullOrEmpty(m_ResourceName)) { return(GUIUtilities.VariableSizeImage(m_ResourceName, "", sizeIfResource)); // RM.GetObject(m_strResourceName) } return(m_Image.GetNetImage()); }
public Bitmap CreateSampleImage(int size = 32) { string resourceID = GetSampleImageResourceID(size); if (!string.IsNullOrEmpty(resourceID)) { return((Bitmap)GUIUtilities.VariableSizeImage(resourceID, "", size)); // RM.GetObject(strResourceID) } return(CreateSampleImage2(size)); }
public override void DrawImage(string resourceName, int preferredSize, PointF[] destinationPoints, RectangleF sourceRect, ImageAttributes attributes = null) { Image image = GUIUtilities.VariableSizeImage(resourceName, "", preferredSize); if (image == null) { image = GUIUtilities.VariableSizeImage("GreyQuestion", "", preferredSize); Globals.Root.Log.WriteLine("Cannot find resource image: " + resourceName); } gr.DrawImage(image, destinationPoints, sourceRect, GraphicsUnit.Pixel, attributes); }
private Bitmap m_bmpMore = null; // the image to use for the more button; created as the colour changes; not displayed if nothing private void ColourPanel_Paint(object sender, PaintEventArgs e) { if (this.DesignMode && m_Colours.Count == 0) { SetStandard18Colours(); } //ButtonPanel.BlendPanelBackground(Me, e.Graphics, m_eBlend) if (m_BackgroundHatching) { using (HatchBrush br = new HatchBrush(HatchStyle.LargeGrid, Color.LightGray, BackColor)) { int Y = m_Colours.Count / m_Columns * m_SizeAndSpacing + m_Spacing; e.Graphics.FillRectangle(br, new Rectangle(0, 0, m_Columns * m_SizeAndSpacing + m_Spacing, Y)); } } // draw the selection borders first... if (m_OldSelection >= 0 && m_SelectionBalance < 100) { PaintSelectionBorder(e.Graphics, m_OldSelection, 100 - m_SelectionBalance); } if (SelectionIndex >= 0 && m_SelectionBalance > 0) { PaintSelectionBorder(e.Graphics, SelectionIndex, m_SelectionBalance); } Pen border = new Pen(Color.DarkGray); Rectangle colour; for (int index = 0; index <= m_Colours.Count - 1; index++) { colour = ColourRectangle(index); if (m_Colours[index].IsEmpty) { // leave it at the background colour of the control, and we add a red x in the middle... Image image = m_BlackWhite ? Resources.AM.BlackWhiteText : GUIUtilities.VariableSizeImage("Transparent", "", colour.Width); // My.Resources.AM.RedCross) if (image != null && m_Applicable) { e.Graphics.DrawImage(image, colour); image.Dispose(); } } else { // if not applicable, colour is drawn but at low alpha using (SolidBrush br = new SolidBrush(Color.FromArgb(m_Colours[index].A / (m_Applicable ? 1 : INAPPLICABLEALPHADIVISION), m_Colours[index]))) { e.Graphics.FillRectangle(br, colour); } e.Graphics.DrawRectangle(border, colour); } } if (DisplayAdvanced) // must use the public property, not the private variable to check the configuration { // The vertical dividing line e.Graphics.DrawLine(border, m_Columns * m_SizeAndSpacing + m_Spacing, 2, m_Columns * m_SizeAndSpacing + m_Spacing, Height - 2); // the special buttons... if (m_bmpMore != null) { colour = ColourRectangle(MOREBUTTON); e.Graphics.DrawImage(m_bmpMore, colour, m_Applicable ? null : GUIUtilities.DrawImage40Percent); } if (AllowTransparent) { colour = ColourRectangle(TRANSPARENTBUTTON); // this only starts from alpha=200, because even that looks pretty solid. Starting at solid tends to make the whole button look too solid // uses max alpha = 50 when not applicable using (LinearGradientBrush transparent = new LinearGradientBrush(colour, Color.FromArgb(m_Applicable ? 200 : 50, m_Current), Color.FromArgb(0, m_Current), LinearGradientMode.ForwardDiagonal)) { e.Graphics.FillRectangle(transparent, colour); } e.Graphics.DrawRectangle(border, colour); } } border.Dispose(); }
int m_SelectionDisplayPercentage; // unlike RoundButton this really is a percentage protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); ButtonPanel.BlendPanelBackground(this, e.Graphics, m_Blend); Rectangle border = new Rectangle(INSET, INSET, Width - INSET * 2, Height - INSET * 2); if (Enabled) { if (m_SelectionDisplayPercentage == 0 && !m_Hover && !Focused) { using (SolidBrush br = new SolidBrush(Color.FromKnownColor(KnownColor.Control))) { e.Graphics.FillRectangle(br, border); } } else { // both hover and selection use a gradient brush Color light; Color dark; if (m_Hover || Focused) // choose the colour without any selection percentage, and then mix in the selection percentage { light = Color.White; dark = Color.FromArgb(210, 230, 255); } else { light = Color.White; dark = Color.FromKnownColor(KnownColor.Control); } if (m_SelectionDisplayPercentage > 0) { light = Color.FromArgb(255, 237, 217).MixWith(light, m_SelectionDisplayPercentage); dark = Color.FromArgb(246, 195, 92).MixWith(dark, m_SelectionDisplayPercentage); } // the gradient brush it doesn't reach right to the edges, so we need to fill the rectangle with the background colour first using (SolidBrush br = new SolidBrush(dark)) { e.Graphics.FillRectangle(br, border); } using (Brush br = CreateGradientBrush(Width - INSET * 2, light, dark)) { e.Graphics.FillRectangle(br, border); } } } using (Pen pnBorder = new Pen(Color.FromKnownColor(KnownColor.ControlDark))) { e.Graphics.DrawRectangle(pnBorder, border); } if (Focused) { border.Inflate(2, 2); e.Graphics.DrawRectangle(GUIUtilities.FocusPen, border); border.Inflate(-2, -2); } Image image; if (m_SelectionDisplayPercentage == 100) { if (m_LargeImage == null && !string.IsNullOrEmpty(m_VariableImage) && !this.DesignMode) { m_LargeImage = GUIUtilities.VariableSizeImage(m_VariableImage, "", this.Width - 8); } image = m_LargeImage ?? m_Image; // no point creating m_Image using variablesize - if large failed then so would small. Condition only useful for when no variablesize name is given } else { if (m_Image == null && !string.IsNullOrEmpty(m_VariableImage) && !this.DesignMode) { m_Image = GUIUtilities.VariableSizeImage(m_VariableImage, "", this.Width - 24); } image = m_Image ?? m_LargeImage; } if (image != null) { border.Inflate(-2, -2); // this is now where the image goes when not selected if (m_SelectionDisplayPercentage == 100) { border = new Rectangle(0, 0, Width - 1, Height - 1); } else if (m_SelectionDisplayPercentage > 0) { // interpolate the size float inversePercentage = (100 - m_SelectionDisplayPercentage) / 100f; // it is mostly this we need in the line below, and this makes it more readable border = new RectangleF(border.X * inversePercentage, border.Y * inversePercentage, border.Width * inversePercentage + Width * m_SelectionDisplayPercentage / 100f, border.Height * inversePercentage + Height * m_SelectionDisplayPercentage / 100f).ToRectangle(); } if (Enabled) { e.Graphics.DrawImage(image, border, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel); } else { e.Graphics.DrawImage(image, border, GUIUtilities.DrawImageDisableNearGrey); } } //if (!string.IsNullOrEmpty(ShortcutDisplay) && !Checked && Enabled && !this.DesignMode) //{ // if (!Utilities.Low_Graphics_Safe()) // e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; // SizeF textSize = e.Graphics.MeasureString(ShortcutDisplay, GUIUtilities.ShortcutFont, 1000, GUIUtilities.ShortcutFormat); // Rectangle shortcut = new Rectangle(0, 0, Width - 1, (int)textSize.Height); // using (SolidBrush br2 = new SolidBrush(Color.FromArgb(180, Color.White))) // { // e.Graphics.FillRectangle(br2, shortcut); // } // e.Graphics.DrawString(ShortcutDisplay, GUIUtilities.ShortcutFont, Brushes.Green, shortcut, GUIUtilities.ShortcutFormat); //} }