protected override void OnRenderItemCheck(ToolStripItemImageRenderEventArgs e) { if (ThemeConfig.EffectiveTheme != PdnTheme.Aero) { base.OnRenderItemCheck(e); } else { Rectangle imageRectangle = e.ImageRectangle; ToolStripItem item = e.Item; Image image = item.Image; ToolStripMenuItem item2 = item as ToolStripMenuItem; if (item2 != null) { Rectangle rect = imageRectangle; rect.Inflate(2, 2); HighlightState state = item.Enabled ? HighlightState.Hover : HighlightState.Disabled; SelectionHighlight.DrawBackground(e.Graphics, this.penBrushCache, rect, state); bool flag = false; if ((image == null) && item2.Checked) { Image reference = PdnResources.GetImageResource("Icons.ToolStrip.Checked.png").Reference; if (item.Enabled) { image = reference; flag = false; } else { image = ToolStripRenderer.CreateDisabledImage(reference); flag = true; } } if (image != null) { Rectangle srcRect = new Rectangle(Point.Empty, image.Size); e.Graphics.DrawImage(image, imageRectangle, srcRect, GraphicsUnit.Pixel); } if (flag) { image.Dispose(); image = null; } } } }
private void RenderAeroButtonBackground(Graphics g, Rectangle rect, bool isEnabled, bool isSelected, bool isPressed, bool isChecked) { HighlightState hover; if (isPressed) { if (isEnabled) { hover = HighlightState.Checked; } else { hover = HighlightState.Default; } } else if (isSelected) { if (isEnabled) { hover = HighlightState.Hover; } else { hover = HighlightState.Disabled; } } else if (isChecked) { if (isEnabled) { hover = HighlightState.Checked; } else { hover = HighlightState.Disabled; } } else { hover = HighlightState.Default; } SelectionHighlight.DrawBackground(g, this.penBrushCache, rect, hover); }
private void OnComboBoxDrawItem(object sender, DrawItemEventArgs e) { if (e.Index != -1) { RectInt32 rect = e.Bounds.ToRectInt32(); using (IDrawingContext context = DrawingContextUtil.FromGraphics(e.Graphics, rect, false, FactorySource.PerThread)) { using (context.UseTranslateTransform((float)e.Bounds.X, (float)e.Bounds.Y, MatrixMultiplyOrder.Prepend)) { HighlightState hover; RectInt32 num2 = new RectInt32(0, 0, rect.Width, rect.Height); Item item = (Item)this.comboBox.Items[e.Index]; if ((e.State & DrawItemState.Selected) > DrawItemState.None) { hover = HighlightState.Hover; } else { hover = HighlightState.Default; } Color embeddedTextColor = SelectionHighlight.GetEmbeddedTextColor(hover); context.FillRectangle(num2, PaintDotNet.UI.Media.SystemBrushes.Window); this.selectionHighlightRenderer.HighlightState = hover; this.selectionHighlightRenderer.RenderBackground(context, num2); int extent = 0; if ((item.Image != null) && (item.Image.PixelFormat != System.Drawing.Imaging.PixelFormat.Undefined)) { extent = this.dropShadowRenderer.GetRecommendedExtent(item.Image.Size.ToSizeInt32()); RectInt32 num4 = new RectInt32((this.imageXInset + extent) + ((this.maxImageSize.Width - item.Image.Width) / 2), (this.imageYInset + extent) + ((this.maxImageSize.Height - item.Image.Height) / 2), item.Image.Width, item.Image.Height); context.DrawBitmap(item.DeviceImage, new RectDouble?(num4), 1.0, BitmapInterpolationMode.Linear, null); this.dropShadowRenderer.RenderOutside(context, num4, extent); } TextLayout resourceSource = UIText.CreateLayout(context, item.Name, this.Font, null, HotkeyRenderMode.Ignore, (double)e.Bounds.Width, (double)e.Bounds.Height); ITextLayout cachedOrCreateResource = context.GetCachedOrCreateResource <ITextLayout>(resourceSource); int num5 = ((((this.imageXInset + extent) + this.maxImageSize.Width) + extent) + this.imageXInset) + this.textLeftMargin; int num6 = (this.itemSize.Height - ((int)cachedOrCreateResource.Metrics.Height)) / 2; context.DrawTextLayout((double)num5, (double)num6, resourceSource, this.selectionHighlightRenderer.EmbeddedTextBrush, DrawTextOptions.None); } } } }
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) { if (ThemeConfig.EffectiveTheme != PdnTheme.Aero) { base.OnRenderMenuItemBackground(e); } else { HighlightState disabled; ToolStripItem item = e.Item; Rectangle rect = new Rectangle(0, 0, item.Width, item.Height); if (item.IsOnDropDown) { rect = Rectangle.Inflate(rect, -1, -1); rect.X += 2; rect.Width -= 3; } if (!e.Item.Enabled && e.Item.Selected) { disabled = HighlightState.Disabled; } else if (e.Item.Pressed && e.Item.IsOnDropDown) { disabled = HighlightState.Hover; } else if (e.Item.Pressed) { disabled = HighlightState.Hover; } else if (e.Item.Selected) { disabled = HighlightState.Hover; } else { disabled = HighlightState.Default; } SelectionHighlight.DrawBackground(e.Graphics, this.penBrushCache, rect, disabled); } }
private void DrawComboBoxItem(DrawItemEventArgs e) { HighlightState hover; string fontName = (string)base.ComboBox.Items[e.Index]; bool flag = (e.State & DrawItemState.Selected) > DrawItemState.None; bool flag2 = this.hasBeenShown && (e.Bounds.Width >= (base.ComboBox.DropDownWidth / 2)); if (!flag2) { hover = HighlightState.Default; } else if (flag) { hover = HighlightState.Hover; } else { hover = HighlightState.Default; } Color selectionBackColor = SelectionHighlight.GetSelectionBackColor(hover); int num = UIUtil.ScaleWidth(3); int num2 = num; int num3 = -1; this.selectionHighlightRenderer.HighlightState = hover; using (IDrawingContext context = DrawingContextUtil.FromGraphics(e.Graphics, e.Bounds, false, FactorySource.PerThread)) { RenderLayer layer = new RenderLayer(); context.Clear(new ColorRgba128Float?((ColorRgba128Float)PaintDotNet.Imaging.SystemColors.Window)); this.selectionHighlightRenderer.RenderBackground(context, e.Bounds.ToRectFloat()); SizedFontProperties menu = this.systemFonts.Menu; PaintDotNet.UI.Media.Brush textBrush = this.selectionHighlightRenderer.EmbeddedTextBrush; TextLayout textLayout = UIText.CreateLayout(context, fontName, menu, null, HotkeyRenderMode.Ignore, (double)(e.Bounds.Width - num2), (double)e.Bounds.Height); textLayout.ParagraphAlignment = ParagraphAlignment.Center; textLayout.WordWrapping = WordWrapping.NoWrap; int num5 = num + e.Bounds.X; context.DrawTextLayout((double)num5, (double)(e.Bounds.Y + num3), textLayout, textBrush, DrawTextOptions.None); ITextLayout cachedOrCreateResource = context.GetCachedOrCreateResource <ITextLayout>(textLayout); int num4 = (int)Math.Ceiling((double)(num5 + cachedOrCreateResource.Metrics.WidthMax)); PlacedBitmap bitmap = this.TryGetFontPreview(fontName, 16f, textBrush); if (bitmap == null) { IntPtr listHwnd = UIUtil.GetListBoxHwnd(base.ComboBox); Action callback = delegate { try { PlacedBitmap bitmap = this.GetOrCreateFontPreview(fontName, 16f, textBrush); if (listHwnd != IntPtr.Zero) { this.ComboBox.BeginInvoke(() => UIUtil.InvalidateHwnd(listHwnd)); } } catch (Exception) { } }; if (this.backgroundThread == null) { this.backgroundThread = new ThreadDispatcher(ApartmentState.MTA); } this.backgroundThread.Enqueue(QueueSide.Front, callback).Observe(); } if (flag2 && (bitmap != null)) { PaintDotNet.UI.Media.Brush brush; RectFloat num7; RectFloat num6 = new RectFloat((float)((e.Bounds.Right - num) - bitmap.Bitmap.Size.Width), num3 + ((float)Math.Floor((double)((e.Bounds.Y + ((e.Bounds.Height - bitmap.LayoutRect.Height) / 2.0)) - bitmap.LayoutRect.Top))), (float)bitmap.Bitmap.Size.Width, (float)bitmap.Bitmap.Size.Height); if (num6.Left > num4) { num7 = num6; brush = null; } else { num7 = num6; num7.X += num4 - num6.X; num7.X = (float)Math.Ceiling((double)num7.X); LinearGradientBrush brush2 = new LinearGradientBrush { ColorInterpolationMode = ColorInterpolationMode.SRgbLinearInterpolation, SpreadMethod = GradientSpreadMethod.Pad }; brush2.GradientStops.Add(new GradientStop(Color.White, 0.0)); brush2.GradientStops.Add(new GradientStop(Color.White, ((double)(e.Bounds.Width - UIUtil.ScaleWidth(0x18))) / ((double)e.Bounds.Width))); brush2.GradientStops.Add(new GradientStop(Color.Transparent, 1.0)); brush2.EndPoint = new PointDouble((double)e.Bounds.Width, 0.0); brush = brush2; } using (context.CreateLayer(null)) { context.PushLayer(layer, new RectDouble?(num7), null, AntialiasMode.Aliased, new Matrix3x2Double?(Matrix3x2Float.Identity), 1.0, brush, LayerOptions.None); context.DrawBitmap(bitmap.DeviceBitmap, new RectDouble?(num7), 1.0, BitmapInterpolationMode.Linear, null); context.PopLayer(); } } } }
private void OnPaintButtonImpl(Graphics g, PdnPushButtonState state, bool drawFocusCues, bool drawKeyboardCues) { HighlightState hover; Color black; Color white; PointF tf; PointF tf2; PointF tf3; switch (state) { case PdnPushButtonState.Normal: case PdnPushButtonState.Default: case PdnPushButtonState.DefaultAnimate: hover = HighlightState.Default; black = Color.Black; white = Color.White; break; case PdnPushButtonState.Hot: hover = HighlightState.Hover; black = Color.Blue; white = Color.White; break; case PdnPushButtonState.Pressed: hover = HighlightState.Checked; black = Color.Blue; white = Color.White; break; case PdnPushButtonState.Disabled: hover = HighlightState.Disabled; black = Color.Gray; white = Color.Black; break; default: throw ExceptionUtil.InvalidEnumArgumentException <PdnPushButtonState>(state, "state"); } if (!base.GetStyle(ControlStyles.SupportsTransparentBackColor) || (this.BackColor.A >= 0xff)) { g.FillRectangle(this.penBrushCache.GetSolidBrush(this.BackColor), base.ClientRectangle); } SelectionHighlight.DrawBackground(g, this.penBrushCache, base.ClientRectangle, hover); g.SmoothingMode = SmoothingMode.AntiAlias; int num = Math.Min((int)(base.ClientSize.Width - 6), (int)(base.ClientSize.Height - 6)) - 1; switch (this.arrowDirection) { case System.Windows.Forms.ArrowDirection.Right: tf = new PointF((float)(base.ClientSize.Width - 3), (float)(base.ClientSize.Height / 2)); tf2 = new PointF(3f, (float)((base.ClientSize.Height - num) / 2)); tf3 = new PointF(3f, (float)((base.ClientSize.Height + num) / 2)); break; case System.Windows.Forms.ArrowDirection.Down: tf = new PointF((float)(base.ClientSize.Width / 2), (float)((base.ClientSize.Height + num) / 2)); tf2 = new PointF((float)((base.ClientSize.Width - num) / 2), (float)((base.ClientSize.Height - num) / 2)); tf3 = new PointF((float)((base.ClientSize.Width + num) / 2), (float)((base.ClientSize.Height - num) / 2)); break; case System.Windows.Forms.ArrowDirection.Left: tf = new PointF(3f, (float)(base.ClientSize.Height / 2)); tf2 = new PointF((float)(base.ClientSize.Width - 3), (float)((base.ClientSize.Height - num) / 2)); tf3 = new PointF((float)(base.ClientSize.Width - 3), (float)((base.ClientSize.Height + num) / 2)); break; case System.Windows.Forms.ArrowDirection.Up: tf = new PointF((float)(base.ClientSize.Width / 2), (float)((base.ClientSize.Height - num) / 2)); tf2 = new PointF((float)((base.ClientSize.Width - num) / 2), (float)((base.ClientSize.Height + num) / 2)); tf3 = new PointF((float)((base.ClientSize.Width + num) / 2), (float)((base.ClientSize.Height + num) / 2)); break; default: throw ExceptionUtil.InvalidEnumArgumentException <System.Windows.Forms.ArrowDirection>(this.arrowDirection, "this.arrowDirection"); } if (((this.arrowDirection == System.Windows.Forms.ArrowDirection.Down) && this.showVectorChevron) && (this.arrowImage == null)) { SmoothingMode smoothingMode = g.SmoothingMode; g.SmoothingMode = SmoothingMode.None; float y = tf2.Y - 2f; float x = tf2.X; float num4 = tf3.X; int num5 = (int)((num4 - x) / 3f); Brush solidBrush = this.penBrushCache.GetSolidBrush(black); g.FillRectangle(solidBrush, x, y, (num4 - x) + 1f, 3f); x++; Brush brush = this.penBrushCache.GetSolidBrush(white); while (x < num4) { RectangleF rect = new RectangleF(x, y + 1f, 1f, 1f); g.FillRectangle(brush, rect); x += 2f; } tf.Y += 2f; tf2.Y += 2f; tf3.Y += 2f; g.SmoothingMode = smoothingMode; } if (this.arrowImage == null) { if (this.reverseArrowColors) { ObjectUtil.Swap <Color>(ref black, ref white); } PointF[] points = new PointF[] { tf, tf2, tf3 }; g.FillPolygon(this.penBrushCache.GetSolidBrush(black), points); PointF[] tfArray2 = new PointF[] { tf, tf2, tf3 }; g.DrawPolygon(this.penBrushCache.GetPen(white, this.arrowOutlineWidth), tfArray2); } else { int num6 = (int)Math.Min(tf.Y, Math.Min(tf2.Y, tf3.Y)); float num7 = Math.Min(tf.X, Math.Min(tf2.X, tf3.X)); float num8 = Math.Max(tf.X, Math.Max(tf2.X, tf3.X)); float num9 = (num7 + num8) / 2f; int width = UIUtil.ScaleWidth(this.arrowImage.Width); int num11 = (int)(num9 - (((float)width) / 2f)); Rectangle destRect = new Rectangle(num11, num6, width, UIUtil.ScaleHeight(this.arrowImage.Height)); g.DrawImage(this.arrowImage, destRect, new Rectangle(Point.Empty, this.arrowImage.Size), GraphicsUnit.Pixel); } }