Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0x5Bb3dbb6408C011e82DED83b236e1943c77c6600 #270

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Empty file.
Binary file added .vs/MaterialSkin/v16/Server/sqlite3/storage.ide
Binary file not shown.
24 changes: 19 additions & 5 deletions MaterialSkin/ColorScheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace MaterialSkin
{
public class ColorScheme
{
public readonly Color PrimaryColor, DarkPrimaryColor, LightPrimaryColor, AccentColor, TextColor;
public readonly Pen PrimaryPen, DarkPrimaryPen, LightPrimaryPen, AccentPen, TextPen;
public readonly Brush PrimaryBrush, DarkPrimaryBrush, LightPrimaryBrush, AccentBrush, TextBrush;
public readonly Color PrimaryColor, DarkPrimaryColor, LightPrimaryColor, AccentColor, TextColor, DangerColor, WarningColor, SuccessColor, LightGrayColor;
public readonly Pen PrimaryPen, DarkPrimaryPen, LightPrimaryPen, AccentPen, TextPen, DangerPen, WarningPen, SuccessPen, LightGrayPen;
public readonly Brush PrimaryBrush, DarkPrimaryBrush, LightPrimaryBrush, AccentBrush, TextBrush, DangerBrush, WarningBrush, SuccessBrush, LightGrayBrush;

/// <summary>
/// Defines the Color Scheme to be used for all forms.
Expand All @@ -16,28 +16,42 @@ public class ColorScheme
/// <param name="lightPrimary">A lighter version of the primary color, a -100 color is suggested here.</param>
/// <param name="accent">The accent color, a -200 color is suggested here.</param>
/// <param name="textShade">The text color, the one with the highest contrast is suggested.</param>
public ColorScheme(Primary primary, Primary darkPrimary, Primary lightPrimary, Accent accent, TextShade textShade)
public ColorScheme(Primary primary, Primary darkPrimary, Primary lightPrimary, Accent accent,
TextShade textShade, Accent danger = Accent.Red400, Accent warning = Accent.Orange400,
Accent success = Accent.Green700, Primary lightGray = Primary.Grey100)
{
//Color
PrimaryColor = ((int)primary).ToColor();
PrimaryColor = ((int)primary).ToColor();
DarkPrimaryColor = ((int)darkPrimary).ToColor();
LightPrimaryColor = ((int)lightPrimary).ToColor();
AccentColor = ((int)accent).ToColor();
TextColor = ((int)textShade).ToColor();
DangerColor = ((int)danger).ToColor();
WarningColor = ((int)warning).ToColor();
SuccessColor = ((int)success).ToColor();
LightGrayColor = ((int)lightGray).ToColor();

//Pen
PrimaryPen = new Pen(PrimaryColor);
DarkPrimaryPen = new Pen(DarkPrimaryColor);
LightPrimaryPen = new Pen(LightPrimaryColor);
AccentPen = new Pen(AccentColor);
TextPen = new Pen(TextColor);
DangerPen = new Pen(DangerColor);
WarningPen = new Pen(WarningColor);
SuccessPen = new Pen(SuccessColor);
LightGrayPen = new Pen(LightGrayColor);

//Brush
PrimaryBrush = new SolidBrush(PrimaryColor);
DarkPrimaryBrush = new SolidBrush(DarkPrimaryColor);
LightPrimaryBrush = new SolidBrush(LightPrimaryColor);
AccentBrush = new SolidBrush(AccentColor);
TextBrush = new SolidBrush(TextColor);
DangerBrush = new SolidBrush(DangerColor);
WarningBrush = new SolidBrush(WarningColor);
SuccessBrush = new SolidBrush(SuccessColor);
LightGrayBrush = new SolidBrush(LightGrayColor);
}
}

Expand Down
30 changes: 24 additions & 6 deletions MaterialSkin/Controls/MaterialCheckbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public bool Ripple
}
}

public Shades CheckShade { get; set; }
public Shades Shade { get; set; }

private readonly AnimationManager _animationManager;
private readonly AnimationManager _rippleAnimationManager;

Expand Down Expand Up @@ -88,7 +91,7 @@ public override Size GetPreferredSize(Size proposedSize)
}

private static readonly Point[] CheckmarkLine = { new Point(3, 8), new Point(7, 12), new Point(14, 5) };
private const int TEXT_OFFSET = 22;
private const int TEXT_OFFSET = 20;
protected override void OnPaint(PaintEventArgs pevent)
{
var g = pevent.Graphics;
Expand All @@ -105,8 +108,22 @@ protected override void OnPaint(PaintEventArgs pevent)
var colorAlpha = Enabled ? (int)(animationProgress * 255.0) : SkinManager.GetCheckBoxOffDisabledColor().A;
var backgroundAlpha = Enabled ? (int)(SkinManager.GetCheckboxOffColor().A * (1.0 - animationProgress)) : SkinManager.GetCheckBoxOffDisabledColor().A;

var brush = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? SkinManager.ColorScheme.AccentColor : SkinManager.GetCheckBoxOffDisabledColor()));
var brush3 = new SolidBrush(Enabled ? SkinManager.ColorScheme.AccentColor : SkinManager.GetCheckBoxOffDisabledColor());
var checkColor = SkinManager.ColorScheme.AccentColor;
if (CheckShade != Shades.None)
{
checkColor = MaterialSkinManager.GetMaterialColor(CheckShade);
}

var shadeBrush = SkinManager.GetCheckboxOffBrush();
var shadeColor = SkinManager.GetCheckboxOffColor();
if (Shade != Shades.None)
{
shadeBrush = MaterialSkinManager.GetMaterialBrush(Shade);
shadeColor = MaterialSkinManager.GetMaterialColor(Shade);
}

var brush = new SolidBrush(Color.FromArgb(colorAlpha, Enabled ? checkColor : SkinManager.GetCheckBoxOffDisabledColor()));
var brush3 = new SolidBrush(Enabled ? checkColor : SkinManager.GetCheckBoxOffDisabledColor());
var pen = new Pen(brush.Color);

// draw ripple animation
Expand All @@ -133,7 +150,7 @@ protected override void OnPaint(PaintEventArgs pevent)
var checkMarkLineFill = new Rectangle(_boxOffset, _boxOffset, (int)(17.0 * animationProgress), 17);
using (var checkmarkPath = DrawHelper.CreateRoundRect(_boxOffset, _boxOffset, 17, 17, 1f))
{
var brush2 = new SolidBrush(DrawHelper.BlendColor(Parent.BackColor, Enabled ? SkinManager.GetCheckboxOffColor() : SkinManager.GetCheckBoxOffDisabledColor(), backgroundAlpha));
var brush2 = new SolidBrush(DrawHelper.BlendColor(Parent.BackColor, Enabled ? shadeColor : SkinManager.GetCheckBoxOffDisabledColor(), backgroundAlpha));
var pen2 = new Pen(brush2.Color);
g.FillPath(brush2, checkmarkPath);
g.DrawPath(pen2, checkmarkPath);
Expand All @@ -159,12 +176,13 @@ protected override void OnPaint(PaintEventArgs pevent)
g.DrawImageUnscaledAndClipped(DrawCheckMarkBitmap(), checkMarkLineFill);
}

// draw checkbox text
// draw checkbox text

SizeF stringSize = g.MeasureString(Text, SkinManager.ROBOTO_MEDIUM_10);
g.DrawString(
Text,
SkinManager.ROBOTO_MEDIUM_10,
Enabled ? SkinManager.GetPrimaryTextBrush() : SkinManager.GetDisabledOrHintBrush(),
Enabled ? shadeBrush : SkinManager.GetDisabledOrHintBrush(),
_boxOffset + TEXT_OFFSET, Height / 2 - stringSize.Height / 2);

// dispose used paint objects
Expand Down
49 changes: 35 additions & 14 deletions MaterialSkin/Controls/MaterialFlatButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Windows.Forms;
using MaterialSkin.Animations;
Expand All @@ -17,6 +18,7 @@ public class MaterialFlatButton : Button, IMaterialControl
[Browsable(false)]
public MouseState MouseState { get; set; }
public bool Primary { get; set; }
public Shades Shade { get; set; }

private readonly AnimationManager _animationManager;
private readonly AnimationManager _hoverAnimationManager;
Expand Down Expand Up @@ -54,8 +56,8 @@ public MaterialFlatButton()
_hoverAnimationManager.OnAnimationProgress += sender => Invalidate();
_animationManager.OnAnimationProgress += sender => Invalidate();

AutoSizeMode = AutoSizeMode.GrowAndShrink;
AutoSize = true;
//AutoSizeMode = AutoSizeMode.GrowAndShrink;
//AutoSize = true;
Margin = new Padding(4, 6, 4, 6);
Padding = new Padding(0);
}
Expand All @@ -81,9 +83,13 @@ protected override void OnPaint(PaintEventArgs pevent)
g.Clear(Parent.BackColor);

//Hover
Color c = SkinManager.GetFlatButtonHoverBackgroundColor();
using (Brush b = new SolidBrush(Color.FromArgb((int)(_hoverAnimationManager.GetProgress() * c.A), c.RemoveAlpha())))
g.FillRectangle(b, ClientRectangle);
Color c = Shade != Shades.None
? MaterialSkinManager.GetMaterialColor(Shade)
: SkinManager.GetFlatButtonHoverBackgroundColor();
using (Brush b = Shade != Shades.None
? new SolidBrush(c)
: new SolidBrush(Color.FromArgb((int)(_hoverAnimationManager.GetProgress() * c.A), c.RemoveAlpha())))
// g.FillRectangle(b, ClientRectangle);

//Ripple
if (_animationManager.IsAnimating())
Expand All @@ -103,16 +109,24 @@ protected override void OnPaint(PaintEventArgs pevent)
g.SmoothingMode = SmoothingMode.None;
}

//Icon
var iconRect = new Rectangle(8, 6, 24, 24);

if (string.IsNullOrEmpty(Text))
// Center Icon
iconRect.X += 2;
//Icon

if (Icon != null)
g.DrawImage(Icon, iconRect);
{
var iconRect = new Rectangle(8, (Height/2)- Icon.Height/2, Icon.Width, Icon.Height);

//create a color matrix object & set the opacity
var matrix = new ColorMatrix { Matrix33 = Enabled ? (float) 0.75 : (float) 0.30 };

//set the color(opacity) of the image
var attributes = new ImageAttributes();
attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

// Draw the image
g.DrawImage(Icon, iconRect, 0, 0, Icon.Width, Icon.Height, GraphicsUnit.Pixel, attributes );
}

//Text
var textRect = ClientRectangle;

Expand All @@ -134,13 +148,20 @@ protected override void OnPaint(PaintEventArgs pevent)
textRect.X += 8 + 24 + 4;
}

var fontColor = Enabled
? (Primary ? SkinManager.ColorScheme.PrimaryBrush : SkinManager.GetPrimaryTextBrush())
: SkinManager.GetFlatButtonDisabledTextBrush();

if (Shade != Shades.None) fontColor = MaterialSkinManager.GetMaterialBrush(Shade);


g.DrawString(
Text.ToUpper(),
SkinManager.ROBOTO_MEDIUM_10,
Enabled ? (Primary ? SkinManager.ColorScheme.PrimaryBrush : SkinManager.GetPrimaryTextBrush()) : SkinManager.GetFlatButtonDisabledTextBrush(),
fontColor,
textRect,
new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }
);
new StringFormat { Alignment = MaterialRaisedButton.ContentToTextHAlignment(TextAlign), LineAlignment = MaterialRaisedButton.ContentToTextVAlignment(TextAlign) });

}

private Size GetPreferredSize()
Expand Down
76 changes: 69 additions & 7 deletions MaterialSkin/Controls/MaterialForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ public class MaterialForm : Form, IMaterialControl
public MouseState MouseState { get; set; }
public new FormBorderStyle FormBorderStyle { get { return base.FormBorderStyle; } set { base.FormBorderStyle = value; } }
public bool Sizable { get; set; }
public Image Logo { get; set; }
public bool ShowActionBar { get; set; } = true;

public Shades StatusBarColor
{
get => _statusBarColor;
set { _statusBarColor = value; Invalidate(new Rectangle(0,0,Width, STATUS_BAR_HEIGHT));}
}

public Shades ActionBarColor
{
get => _actionBarColor;
set { _actionBarColor = value; Invalidate(new Rectangle(0,STATUS_BAR_HEIGHT,Width, ACTION_BAR_HEIGHT));}
}

[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
Expand Down Expand Up @@ -79,8 +93,9 @@ public class MaterialForm : Form, IMaterialControl
};

private const int STATUS_BAR_BUTTON_WIDTH = STATUS_BAR_HEIGHT;
private const int STATUS_BAR_HEIGHT = 24;
private const int STATUS_BAR_HEIGHT = 36;
private const int ACTION_BAR_HEIGHT = 40;
private const int LOGO_SIZE = 32;

private const uint TPM_LEFTALIGN = 0x0000;
private const uint TPM_RETURNCMD = 0x0100;
Expand Down Expand Up @@ -128,6 +143,7 @@ private enum ResizeDirection
Right,
BottomRight,
Bottom,
Top,
None
}

Expand All @@ -149,11 +165,15 @@ private enum ButtonState
private Rectangle _xButtonBounds;
private Rectangle _actionBarBounds;
private Rectangle _statusBarBounds;
private Rectangle _textLabelBounds;
private Rectangle _logoBounds;

private bool _maximized;
private Size _previousSize;
private Point _previousLocation;
private bool _headerMouseDown;
private Shades _actionBarColor;
private Shades _statusBarColor;

public MaterialForm()
{
Expand Down Expand Up @@ -290,7 +310,12 @@ protected override void OnMouseMove(MouseEventArgs e)
//True if the mouse is hovering over a child control
var isChildUnderMouse = GetChildAtPoint(e.Location) != null;

if (e.Location.X < BORDER_WIDTH && e.Location.Y > Height - BORDER_WIDTH && !isChildUnderMouse && !_maximized)
if (e.Location.Y < BORDER_WIDTH && !isChildUnderMouse && !_maximized)
{
_resizeDir = ResizeDirection.Top;
Cursor = Cursors.SizeNS;
}
else if (e.Location.X < BORDER_WIDTH && e.Location.Y > Height - BORDER_WIDTH && !isChildUnderMouse && !_maximized)
{
_resizeDir = ResizeDirection.BottomLeft;
Cursor = Cursors.SizeNESW;
Expand Down Expand Up @@ -450,6 +475,9 @@ private void ResizeForm(ResizeDirection direction)
case ResizeDirection.Bottom:
dir = HTBOTTOM;
break;
case ResizeDirection.Top:
dir = HTTOP;
break;
}

ReleaseCapture();
Expand All @@ -468,16 +496,21 @@ protected override void OnResize(EventArgs e)
_xButtonBounds = new Rectangle((Width - SkinManager.FORM_PADDING / 2) - STATUS_BAR_BUTTON_WIDTH, 0, STATUS_BAR_BUTTON_WIDTH, STATUS_BAR_HEIGHT);
_statusBarBounds = new Rectangle(0, 0, Width, STATUS_BAR_HEIGHT);
_actionBarBounds = new Rectangle(0, STATUS_BAR_HEIGHT, Width, ACTION_BAR_HEIGHT);

_textLabelBounds = Logo != null
? new Rectangle(SkinManager.FORM_PADDING + LOGO_SIZE + 5, STATUS_BAR_HEIGHT, Width, ACTION_BAR_HEIGHT)
: new Rectangle(SkinManager.FORM_PADDING, STATUS_BAR_HEIGHT, Width, ACTION_BAR_HEIGHT);
_logoBounds = new Rectangle(0, _textLabelBounds.Y, _textLabelBounds.X + _textLabelBounds.Width, _textLabelBounds.Height);
}

protected override void OnPaint(PaintEventArgs e)
{
var g = e.Graphics;
g.TextRenderingHint = TextRenderingHint.AntiAlias;

g.Clear(SkinManager.GetApplicationBackgroundColor());
g.FillRectangle(SkinManager.ColorScheme.DarkPrimaryBrush, _statusBarBounds);
g.FillRectangle(SkinManager.ColorScheme.PrimaryBrush, _actionBarBounds);
g.FillRectangle(MaterialSkinManager.GetMaterialBrush(StatusBarColor), _statusBarBounds);
if (ShowActionBar) DrawActionBar(g);

//Draw border
using (var borderPen = new Pen(SkinManager.GetDividersColor(), 1))
Expand Down Expand Up @@ -561,8 +594,37 @@ protected override void OnPaint(PaintEventArgs e)
}
}

//Form title
g.DrawString(Text, SkinManager.ROBOTO_MEDIUM_12, SkinManager.ColorScheme.TextBrush, new Rectangle(SkinManager.FORM_PADDING, STATUS_BAR_HEIGHT, Width, ACTION_BAR_HEIGHT), new StringFormat { LineAlignment = StringAlignment.Center });
// Logo
if (Logo != null)
{
g.FillRectangle(SkinManager.ColorScheme.LightGrayBrush, _logoBounds);
int logoY = STATUS_BAR_HEIGHT + (ACTION_BAR_HEIGHT - LOGO_SIZE) / 2;
g.DrawImage(Logo,
new Rectangle( SkinManager.FORM_PADDING, logoY,Logo.Width, LOGO_SIZE),
new Rectangle(0,0,Logo.Width, Logo.Height), GraphicsUnit.Pixel);
}


// Form title
g.DrawString(Text, SkinManager.ROBOTO_REGULAR_11, SkinManager.ColorScheme.TextBrush, _textLabelBounds, new StringFormat { LineAlignment = StringAlignment.Center });
}

private void DrawActionBar(Graphics g)
{
g.FillRectangle(MaterialSkinManager.GetMaterialBrush(ActionBarColor), _actionBarBounds);
}

private void InitializeComponent()
{
this.SuspendLayout();
//
// MaterialForm
//
this.ClientSize = new System.Drawing.Size(284, 262);
this.ControlBox = false;
this.Name = "MaterialForm";
this.ResumeLayout(false);

}
}

Expand Down