/// <summary> /// Constructor /// </summary> public MCheckBox() { InitializeComponent(); // Default variables _controlTimer = new Timer(); _controlTimer.Enabled = true; _controlTimer.Interval = 1; _controlTimer.Tick += new EventHandler(Update); _controlTimer.Start(); _state = false; _a = 0; _frame = 0; _hover = false; _hoverAlpha = 0; DoubleBuffered = true; AutoSize = false; DIP.GetGraphics(this); Height = DIP.Set(15); Font = new Font("Segoe UI", 7); Size = new Size(130, 36); // Redraw Invalidate(); }
/// <summary> /// Constructor /// </summary> public MItem() { // Default item height // Uses device independent pixels to provide best scaling // experience Height = DIP.Set(50); }
/// <summary> /// Draw item /// </summary> protected override void OnDrawItem(Graphics g, Rectangle bounds) { // Base call base.OnDrawItem(g, bounds); // Default height Height = DIP.Set(70); // String format // Converts alignment types StringFormat format = new StringFormat(); int lNum = (int)Math.Log((double)TextAlign, 2); format.LineAlignment = (StringAlignment)(lNum / 4); format.Alignment = (StringAlignment)(lNum % 4); // Creates color of secondary text Color color = (Owner.Component.SourceTheme.DARK_BASED) ? ColorExtensions.AddRGB(-120, Owner.Component.SourceTheme.COMPONENT_FOREGROUND.Normal) : ColorExtensions.AddRGB(100, Owner.Component.SourceTheme.COMPONENT_FOREGROUND.Normal); // Draws secondary text using (SolidBrush brush = new SolidBrush(color)) g.DrawString(SecondaryText, new Font("Segoe UI", 8), brush, new Rectangle(Bounds.X + 10, Bounds.Y + 12, Bounds.Width - 20, Bounds.Height), format); // Draws primary text using (SolidBrush brush = new SolidBrush(Selected ? Owner.Accent : Owner.Component.SourceTheme.COMPONENT_FOREGROUND.Normal.ToColor())) g.DrawString(PrimaryText, new Font("Segoe UI", 9), brush, new Rectangle(Bounds.X + 10, Bounds.Y - 12, Bounds.Width - 20, Bounds.Height), format); }
/// <summary> /// Constructor /// </summary> public MRadioButton() { InitializeComponent(); // Scaling DIP.GetGraphics(this); // Default variables _controlTimer = new Timer(); _controlTimer.Enabled = true; _controlTimer.Interval = 1; _controlTimer.Tick += new EventHandler(Update); _controlTimer.Start(); _state = false; _tintAlpha = 0; _radius = 0; _hoverAlpha = 0; _hover = false; _usedTheme = null; DoubleBuffered = true; AutoSize = false; Height = DIP.Set(20); Font = new Font("Segoe UI", 7); Size = new Size(130, 36); // Pass graphics to DIP class DIP.GetGraphics(this); // Redraw Invalidate(); }
/// <summary> /// Draw item /// </summary> public override void DrawItem(MListBox owner, Graphics g, Rectangle itemBounds) { // DIP DIP.GetGraphics(g); // Basic varibles Height = DIP.Set(70); Bounds = itemBounds; Graphics = g; // Handles control's source theme // Check if control has set own theme if (owner.UsedTheme != null) { // Set custom theme as source theme _sourceTheme = owner.UsedTheme; } else { // Control dont have its own theme // Try cast control's parent form to MForm try { MForm form = (MForm)owner.FindForm(); _sourceTheme = form.UsedTheme; } catch { // Control's parent form is not MForm type // Set application wide theme _sourceTheme = Minimal.UsedTheme; } } // Background g.FillRectangle(new SolidBrush(_sourceTheme.CONTROL_BACKGROUND.Normal.ToColor()), Bounds); // Item have focus || mouse hover if (Bounds.Contains(owner.MousePosition)) { // Partially transparent tint layer g.FillRectangle(new SolidBrush(Color.FromArgb(25, owner.Tint)), Bounds); } // Draw primary text StringFormat sfPrimary = new StringFormat(); sfPrimary.LineAlignment = StringAlignment.Center; g.DrawString(PrimaryText, new Font("Segoe UI", 9), new SolidBrush((Bounds.Contains(owner.MousePosition) ? owner.Tint : _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor())), new Rectangle(Bounds.X + 10, Bounds.Y + 5, Bounds.Width, Bounds.Height / 2 + 1), sfPrimary); // Draw secondary text StringFormat sfSecondary = new StringFormat(); sfSecondary.LineAlignment = StringAlignment.Center; Color textColor = (_sourceTheme.DARK_BASED) ? MColor.AddRGB(-120, _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()) : MColor.AddRGB(100, _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()); g.DrawString(SecondaryText, new Font("Segoe UI", 8), new SolidBrush(textColor), new Rectangle(Bounds.X + 10, Bounds.Y + Bounds.Height / 2 - 9, Bounds.Width, Bounds.Height / 2 + 5), sfSecondary); }
/// <summary> /// Draw /// </summary> public override void DrawItem(MListBox owner, Graphics g, Rectangle itemBounds) { // DIP DIP.GetGraphics(g); // Basic varibles Height = DIP.Set(50); Bounds = itemBounds; Graphics = g; // Handles control's source theme // Check if control has set own theme if (owner.UsedTheme != null) { // Set custom theme as source theme _sourceTheme = owner.UsedTheme; } else { // Control dont have its own theme // Try cast control's parent form to MForm try { MForm form = (MForm)owner.FindForm(); _sourceTheme = form.UsedTheme; } catch { // Control's parent form is not MForm type // Set application wide theme _sourceTheme = Minimal.UsedTheme; } } // Background g.FillRectangle(new SolidBrush(_sourceTheme.CONTROL_BACKGROUND.Normal.ToColor()), Bounds); // Item have focus || mouse hover if (Bounds.Contains(owner.MousePosition)) { // Partially transparent tint layer g.FillRectangle(new SolidBrush(Color.FromArgb(25, owner.Tint)), Bounds); } // Avatar g.FillRectangle(new SolidBrush(owner.Tint), new Rectangle(new Point(Bounds.X + 10, Bounds.Y + (Bounds.Height / 2) - 16), new Size(32, 32))); StringFormat sfAvatar = new StringFormat(); sfAvatar.LineAlignment = StringAlignment.Center; sfAvatar.Alignment = StringAlignment.Center; g.DrawString(PrimaryText[0].ToString(), new Font("Segoe UI Light", 12), new SolidBrush(Color.White), new Rectangle(new Point(Bounds.X + 10, Bounds.Y + (Bounds.Height / 2) - 16), new Size(32, 32)), sfAvatar); // Draw primary text StringFormat sfPrimary = new StringFormat(); sfPrimary.LineAlignment = StringAlignment.Center; g.DrawString(PrimaryText, new Font("Segoe UI", 9), new SolidBrush(_sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()), new Rectangle(Bounds.X + 48, Bounds.Y + 1, Bounds.Width + 50, Bounds.Height), sfPrimary); }
public override void DrawItem(MListBox owner, Graphics g, Rectangle itemBounds) { // DIP DIP.GetGraphics(g); // Basic varibles Height = DIP.Set(30); Bounds = itemBounds; Graphics = g; // Handles control's source theme // Check if control has set own theme if (owner.UsedTheme != null) { // Set custom theme as source theme _sourceTheme = owner.UsedTheme; } else { // Control dont have its own theme // Try cast control's parent form to MForm try { MForm form = (MForm)owner.FindForm(); _sourceTheme = form.UsedTheme; } catch { // Control's parent form is not MForm type // Set application wide theme _sourceTheme = Minimal.UsedTheme; } } // Background g.FillRectangle(new SolidBrush((_sourceTheme.DARK_BASED) ? MColor.AddRGB(5, _sourceTheme.CONTROL_BACKGROUND.Normal.ToColor()) : MColor.AddRGB(-5, _sourceTheme.CONTROL_BACKGROUND.Normal.ToColor())), Bounds); // Draw primary text Color color = _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor(); StringFormat sfPrimary = new StringFormat(); sfPrimary.LineAlignment = StringAlignment.Center; g.DrawString(PrimaryText, new Font("Segoe UI Semibold", 8), new SolidBrush(color), new Rectangle(Bounds.X + 10, Bounds.Y + 5, Bounds.Width, Bounds.Height / 2 + 5), sfPrimary); // Draw divider lines Color lineColor = (_sourceTheme.DARK_BASED) ? MColor.AddRGB(-150, _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()) : MColor.AddRGB(150, _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()); g.DrawLine(new Pen(lineColor), new Point(Bounds.X, Bounds.Y), new Point(Bounds.X + Bounds.Width, Bounds.Y)); g.DrawLine(new Pen(lineColor), new Point(Bounds.X, Bounds.Y + Bounds.Height - 1), new Point(Bounds.X + Bounds.Width, Bounds.Y + Bounds.Height - 1)); }
/// <summary> /// Constructor /// </summary> public TwoLineItem(string primaryText, string secondaryText, ContentAlignment textAlign = ContentAlignment.MiddleLeft) { // Primary text PrimaryText = primaryText; // Secondary text SecondaryText = secondaryText; // Alignment TextAlign = textAlign; // Default height Height = DIP.Set(70); }
/// <summary> /// Constructor /// </summary> public MRadioButton() { // Register a new component ComponentManager.RegisterComponent(this); // Initializes component InitializeComponent(); // Default variables _state = false; _tintAlpha = 0; _radius = 0; _hoverAlpha = 0; _hover = false; DoubleBuffered = true; AutoSize = false; Height = DIP.Set(20); Font = new Font("Segoe UI", 7); Size = new Size(130, 21); // Redraw Invalidate(); }
/// <summary> /// Constructor /// </summary> public MCheckBox() { // Register a new component ComponentManager.RegisterComponent(this); // Initialize InitializeComponent(); // Default variables _state = false; _a = 0; _frame = 0; _hover = false; _hoverAlpha = 0; DoubleBuffered = true; AutoSize = false; Height = DIP.Set(15); Font = new Font("Segoe UI", 7); Size = new Size(130, 21); // Redraw Invalidate(); }
/// <summary> /// Draw item method /// </summary> protected virtual void OnDrawItem(Graphics g, Rectangle bounds) { if (Owner == null) { return; } // If item is not in the view-port if (!ItemInView(this)) { // Go back return; } // Is item divider? if (Divider) { // Draws background using (SolidBrush brush = new SolidBrush(Owner.Component.SourceTheme.COMPONENT_BACKGROUND.Normal)) g.FillRectangle(brush, Bounds); // End return; } // Updates item's height property // Uses device independent pixels to provide best scaling // experience Height = DIP.Set(50); // Update bounds property Bounds = bounds; // Set clip region. Clip graphics canvas to the dimensions of // list item. g.Clip = new Region(bounds); // Draws background using (SolidBrush brush = new SolidBrush(Owner.Component.SourceTheme.COMPONENT_BACKGROUND.Normal)) g.FillRectangle(brush, Bounds); // If touch-controls are disabled if (!M.TouchEnabled) { // Shortcut variable for normal control background color Color bg = Owner.Component.SourceTheme.COMPONENT_BACKGROUND.Normal; // Draws partially transparent accent layer as background using (SolidBrush brush = new SolidBrush(ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, Owner.Accent), bg))) g.FillRectangle(brush, Bounds); // Turn on anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Reveal effect ellipse GraphicsPath ellipse = Draw.GetEllipsePath(_mousePosition, 150); // Path gradient brush PathGradientBrush pgb = new PathGradientBrush(ellipse); pgb.CenterPoint = _mousePosition; pgb.CenterColor = Color.FromArgb(55, Owner.Accent); pgb.SurroundColors = new Color[] { ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, Owner.Accent), bg) }; // Draw reveal effect if mouse is hovering over an item if (Hover) { g.FillPath(pgb, ellipse); } // Turn off anti-aliasing g.SmoothingMode = SmoothingMode.Default; // Draws partially transparent accent layer as overlay // to hide rest of reveal ellipse using (SolidBrush brush = new SolidBrush(ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, Owner.Accent), bg))) g.FillRectangle(brush, new Rectangle(Bounds.X + 2, Bounds.Y + 2, Bounds.Width - 4, Bounds.Height - 4)); } // Draws click effect DrawClick(g); }
/// <summary> /// Draw /// </summary> protected override void OnPaint(PaintEventArgs e) { // Base painting base.OnPaint(e); // Scaling DIP.GetGraphics(this); // Handles control's source theme // Check if control has set own theme if (_usedTheme != null) { // Set custom theme as source theme _sourceTheme = _usedTheme; } else { // Control don't have its own theme // Try cast control's parent form to MForm try { MForm form = (MForm)FindForm(); _sourceTheme = form.UsedTheme; } catch { // Control's parent form is not MForm type // Set application wide theme _sourceTheme = Minimal.UsedTheme; } } // Graphics Graphics g = e.Graphics; // Clear control g.Clear(Parent.BackColor); // Fill color, text and border Color fill = new Color(); Color border = new Color(); Color hover = new Color(); Color foreground = new Color(); if (Enabled) { // Enabled fill = _sourceTheme.CONTROL_BACKGROUND.Normal.ToColor(); border = _sourceTheme.CONTROL_BORDER.Normal.ToColor(); foreground = _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor(); hover = _sourceTheme.CONTROL_FILL.Hover.ToColor(); } else { // Disabled fill = _sourceTheme.CONTROL_BACKGROUND.Disabled.ToColor(); border = _sourceTheme.CONTROL_BORDER.Disabled.ToColor(); foreground = _sourceTheme.CONTROL_FOREGROUND.Disabled.ToColor(); hover = _sourceTheme.CONTROL_FILL.Disabled.ToColor(); } // Draw background g.FillPath(new SolidBrush(fill), Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set((10)))); // Antialiasing g.SmoothingMode = SmoothingMode.AntiAlias; // Draw border if (!_state) { g.DrawPath(new Pen(!Checked ? _sourceTheme.CONTROL_BORDER.Normal.ToColor() : _tint, 1), Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set(10))); } // Mouse hover g.FillPath(new SolidBrush(Color.FromArgb(_hoverAlpha, hover)), Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set(3))); // Animation - inner circle g.FillPath(new SolidBrush(Enabled ? _tint : _sourceTheme.CONTROL_FILL.Disabled.ToColor()), Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), Convert.ToInt32(_radius))); // Animation - border tint g.DrawEllipse(new Pen(MColor.Mix(Color.FromArgb(_tintAlpha, Enabled ? _tint : _sourceTheme.CONTROL_BORDER.Disabled.ToColor()), border)), new Rectangle(0, 0, DIP.Set(20), DIP.Set(20))); // Antialiasing g.SmoothingMode = SmoothingMode.Default; // Draw text g.DrawString(this.Text, this.Font, new SolidBrush(foreground), new Point(25 + DIP.Set(8), 2)); }
/// <summary> /// Draw /// </summary> protected override void OnPaint(PaintEventArgs e) { // Base call base.OnPaint(e); // Graphics Graphics g = e.Graphics; // Clear control g.Clear(Parent.BackColor); // Fill color, text and border Color fill = new Color(); Color border = new Color(); Color hover = new Color(); Color foreground = new Color(); if (Enabled) { // Enabled fill = Component.SourceTheme.COMPONENT_BACKGROUND.Normal.ToColor(); border = Component.SourceTheme.COMPONENT_BORDER.Normal.ToColor(); foreground = Component.SourceTheme.COMPONENT_FOREGROUND.Normal.ToColor(); hover = Component.SourceTheme.COMPONENT_FILL.Hover.ToColor(); } else { // Disabled fill = Component.SourceTheme.COMPONENT_BACKGROUND.Disabled.ToColor(); border = Component.SourceTheme.COMPONENT_BORDER.Disabled.ToColor(); foreground = Component.SourceTheme.COMPONENT_FOREGROUND.Disabled.ToColor(); hover = Component.SourceTheme.COMPONENT_FILL.Disabled.ToColor(); } // Draw background using (SolidBrush brush = new SolidBrush(fill)) g.FillPath(brush, Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set((10)))); // Anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Draw border if (!_state) { using (Pen pen = new Pen(!Checked ? Component.SourceTheme.COMPONENT_BORDER.Normal.ToColor() : Component.Accent, 1)) g.DrawPath(pen, Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set(10))); } // Draw mouse hover effect using (SolidBrush brush = new SolidBrush(Color.FromArgb(_hoverAlpha, hover))) g.FillPath(brush, Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), DIP.Set(3))); // Animation - inner circle using (SolidBrush brush = new SolidBrush(Enabled ? Component.Accent : Component.SourceTheme.COMPONENT_FILL.Disabled.ToColor())) g.FillPath(brush, Draw.GetEllipsePath(new Point(DIP.Set(10), DIP.Set(10)), Convert.ToInt32(_radius))); // Animation - border tint using (Pen pen = new Pen(ColorExtensions.Mix(Color.FromArgb(_tintAlpha, Enabled ? Component.Accent : Component.SourceTheme.COMPONENT_BORDER.Disabled.ToColor()), border))) g.DrawEllipse(pen, new Rectangle(0, 0, DIP.Set(20), DIP.Set(20))); // Anti-aliasing g.SmoothingMode = SmoothingMode.Default; // Draw text using (SolidBrush brush = new SolidBrush(foreground)) g.DrawString(Text, Font, brush, new Point(25 + DIP.Set(8), 2)); }
/// <summary> /// Draw /// </summary> public override void DrawItem(MListBox owner, Graphics g, Rectangle itemBounds) { // DIP DIP.GetGraphics(g); // Basic variables Height = DIP.Set(70); Bounds = itemBounds; Graphics = g; // Handles control's source theme // Check if control has set own theme if (owner.UsedTheme != null) { // Set custom theme as source theme _sourceTheme = owner.UsedTheme; } else { // Control don't have its own theme // Try cast control's parent form to MForm try { MForm form = (MForm)owner.FindForm(); _sourceTheme = form.UsedTheme; } catch { // Control's parent form is not MForm type // Set application wide theme _sourceTheme = Minimal.UsedTheme; } } // Background g.FillRectangle(new SolidBrush(_sourceTheme.CONTROL_BACKGROUND.Normal.ToColor()), Bounds); // Item have focus || mouse hover if (Bounds.Contains(owner.MousePosition)) { // Partially transparent tint layer g.FillRectangle(new SolidBrush(Color.FromArgb(25, owner.Tint)), Bounds); } // Draw primary text StringFormat sfPrimary = new StringFormat(); sfPrimary.LineAlignment = StringAlignment.Center; g.DrawString(PrimaryText, new Font("Segoe UI", 9), new SolidBrush(_sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()), new Rectangle(Bounds.X + 21, Bounds.Y + 6, Bounds.Width, Bounds.Height / 2 + 1), sfPrimary); // Draw secondary text StringFormat sfSecondary = new StringFormat(); sfSecondary.LineAlignment = StringAlignment.Center; Color textColor = (_sourceTheme.DARK_BASED) ? MColor.AddRGB(-120, _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()) : MColor.AddRGB(100, _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()); g.DrawString(SecondaryText, new Font("Segoe UI", 8), new SolidBrush(textColor), new Rectangle(Bounds.X + 21, Bounds.Y + Bounds.Height / 2 - 6, Bounds.Width, Bounds.Height / 2 + 5), sfSecondary); Color bad = new Hex("#F56C6C").ToColor(); Color medium = new Hex("#E6A23C").ToColor(); Color good = new Hex("#67C23A").ToColor(); string strength = ""; Color infoColor = Color.Beige; if (_passwordHash.Length >= 10) { infoColor = good; strength = "Strong"; } else if (_passwordHash.Length >= 6) { infoColor = medium; strength = "Good"; } else { infoColor = bad; strength = "Weak"; } // Draw password hash StringFormat sfPassword = new StringFormat(); sfPassword.LineAlignment = StringAlignment.Center; sfPassword.Alignment = StringAlignment.Far; Font passwordFont = new Font("Segoe UI", 9); SizeF size = g.MeasureString(strength, passwordFont); Color passwordColor = (_sourceTheme.DARK_BASED) ? MColor.AddRGB(-120, _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()) : MColor.AddRGB(100, _sourceTheme.CONTROL_FOREGROUND.Normal.ToColor()); g.DrawString(strength, passwordFont, new SolidBrush(infoColor), new Rectangle(Bounds.X, Bounds.Y, Convert.ToInt32(Bounds.Width - 20), Bounds.Height), sfPassword); // new Rectangle(Bounds.X + Bounds.Width - Convert.ToInt32(size.Width) - 21, Bounds.Y + Bounds.Height / 2 - Convert.ToInt32(size.Height/2), Bounds.Width, Bounds.Height / 2 - Convert.ToInt32(size.Height / 2)) }