Esempio n. 1
0
 /// <summary>
 /// Handles the Make Borderless event of the menu.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
 private void menu_makeBorderless(object sender, System.EventArgs e)
 {
     base.RecordUndoEvent("Button Style Change");
     this.bs = buttonStyle.Borderless;
     this.UpdateMenu();
     this.ExpireSolution(true);
 }
Esempio n. 2
0
    public Button(Vector2 p, float w, float h, string t, AssetManager a, buttonStyle s, int ts, void_function_Button f)
    {
        function_button_action = f;


        init(p, w, h, t, a, s, ts);
    }
Esempio n. 3
0
 void imageButton_MouseDown(object sender, MouseEventArgs e)
 {
     if (Enabled)
     {
         BackgroundImage = clickImage;
         _buttonStyle    = buttonStyle.hover;
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Read all required data for deserialization from an IO archive. - In this case just the button style.
        /// </summary>
        /// <param name="reader">Object to read with.</param>
        /// <returns>
        /// True on success, false on failure.
        /// </returns>
        public override bool Read(GH_IReader reader)
        {
            int readVal = -1;

            reader.TryGetInt32("ButtonStyle", ref readVal);
            bs = (buttonStyle)readVal;
            this.UpdateMenu();
            return(base.Read(reader));
        }
Esempio n. 5
0
 public void init(Vector2 p, float w, float h, string t, AssetManager a, buttonStyle s, int ts)
 {
     assets   = a;
     textSize = ts;
     position = p;
     width    = w;
     height   = h;
     text     = t;
     content  = new GUIContent();
     style    = s;
 }
Esempio n. 6
0
        /// <summary>
        /// 绘制圆角按钮
        /// </summary>
        /// <param name="Text">要绘制的文字</param>
        /// <param name="g">Graphics 对象</param>
        /// <param name="rect">要填充的矩形</param>
        /// <param name="btnStyle"></param>
        public void DrawRoundButton(string Text, Graphics g, Rectangle rect, buttonStyle btnStyle)
        {
            //g.Clear(Color.White);
            g.SmoothingMode = SmoothingMode.AntiAlias;//消除锯齿
            Rectangle rectangle = rect;
            Brush     b         = new SolidBrush(Color.Black);

            OverColor = SystemColors.Highlight;
            if (btnStyle == buttonStyle.ButtonFocuse)
            {
                b = new SolidBrush(ColorTranslator.FromHtml("#338FCC"));
            }
            else if (btnStyle == buttonStyle.ButtonMouseOver)
            {
                b = new SolidBrush(ColorTranslator.FromHtml("#C6A300"));
            }
            else if (btnStyle == buttonStyle.ButtonFocuseAndMouseOver)
            {
                b = new SolidBrush(ColorTranslator.FromHtml("#C6A300"));
            }
            else
            {
                OverColor = Color.Black;
            }

            Pen p = new Pen(Color.Black, 0.5f);

            p.DashStyle = DashStyle.Dash;
            if (btnStyle == buttonStyle.ButtonFocuse || btnStyle == buttonStyle.ButtonFocuseAndMouseOver)
            {
                var BackBrush = new SolidBrush(Color.FromArgb(90, OverColor));
                g.FillRectangle(BackBrush, 0, rect.Y, Width, rect.Height - 1);
                //g.FillRectangles(p, rectangle);//虚线框
            }

            StringFormat sf = new StringFormat();

            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(Text, this.Font, new SolidBrush(Color.FromArgb(90, OverColor)), rectangle, sf);
            p.Dispose();
            b.Dispose();
            g.SmoothingMode = SmoothingMode.Default;
        }
Esempio n. 7
0
 //create a non-functional button.
 public Button(Vector2 p, float w, float h, string t, AssetManager a, buttonStyle s, int ts)
 {
     init(p, w, h, t, a, s, ts);
 }
Esempio n. 8
0
 public void setStyle(buttonStyle newStyle)
 {
     style = newStyle;
 }
Esempio n. 9
0
        protected static void SetupButton(string name, string imagePath, bool hasText, bool hasIcon, Button btn, buttonStyle bs)
        {
            //Initialize a stackPanel to be contained inside the button
            StackPanel sp = new StackPanel();

            sp.Orientation = Orientation.Horizontal;
            if (hasIcon)
            {
                //get img from file path, and if the button has an icon, add the image to the stack panel.
                Image       img      = new Image();
                Uri         filePath = new Uri(imagePath);
                BitmapImage bi       = new BitmapImage(filePath);
                img.Source = bi;
                sp.Children.Add(img);
            }
            if (hasText)
            {
                //if the button has associated text, create a text block and add it to the stack panel
                TextBlock l = new TextBlock();
                l.Text = name;
                sp.Children.Add(l);
            }
            //put the stack panel inside the button
            btn.Content = sp;


            //Retrieve the MahApps.Metro style dictionary
            ResourceDictionary ControlsResDict = new ResourceDictionary();

            ControlsResDict.Source =
                new Uri("/MahApps.Metro;component/Styles/Controls.xaml", UriKind.RelativeOrAbsolute);

            //based on the user selected button style, assign the appropriate style to the button
            switch (bs)
            {
            case buttonStyle.Default:
                btn.Style = new Style(typeof(Button), (Style)ControlsResDict["MetroButton"]);
                break;

            case buttonStyle.Square:
                btn.Style = new Style(typeof(Button), (Style)ControlsResDict["SquareButtonStyle"]);
                break;

            case buttonStyle.Circle:
                btn.Style = new Style(typeof(Button), (Style)ControlsResDict["MetroCircleButtonStyle"]);
                break;

            case buttonStyle.Borderless:
                // this one could probably be made to look a little better. I'm using a cheap trick that basically
                // insets the padding by two pixels in order to hide the border.
                btn.Margin          = new Thickness(0);
                btn.Padding         = new Thickness(-2);
                btn.BorderThickness = new Thickness(0);
                btn.BorderBrush     = Brushes.Transparent;
                break;
            }

            //Measure the size of the stackpanel inside the button, size button accordingly
            Size size = new Size(double.PositiveInfinity, double.PositiveInfinity);

            sp.Measure(size);
            sp.Margin  = new Thickness(2);
            btn.Width  = sp.DesiredSize.Width + 20;
            btn.Margin = new Thickness(4);
        }
Esempio n. 10
0
        /// <summary>
        /// 繪製圓角按鈕
        /// </summary>
        /// <param name="Text">要繪製的文字</param>
        /// <param name="g">Graphics 對象</param>
        /// <param name="rect">要填充的矩形</param>
        /// <param name="btnStyle"></param>
        public static void DrawRoundButton(Font font, string Text, Graphics g, Rectangle rect, buttonStyle btnStyle)
        {
            int 角度 = 10;

            g.SmoothingMode = SmoothingMode.AntiAlias;//消除鋸齒
            Brush b = b = new SolidBrush(Color.White);

            if (btnStyle == buttonStyle.ButtonFocuse)
            {
                b = new SolidBrush(ColorTranslator.FromHtml("#FFCC99"));
            }
            else if (btnStyle == buttonStyle.ButtonMouseOver)
            {
                b = new SolidBrush(ColorTranslator.FromHtml("#C6A300"));
            }
            else if (btnStyle == buttonStyle.ButtonFocuseAndMouseOver)
            {
                b = new SolidBrush(ColorTranslator.FromHtml("#C6A300"));
            }
            Pen p  = new Pen(Color.Black, 0.5f);
            Pen p2 = new Pen(b);

            //繪製矩形
            g.DrawPath(p, GetRoundRectangle(rect, 角度));
            //填滿矩形
            g.FillPath(b, GetRoundRectangle(rect, 角度));

            rect = new Rectangle(rect.X, rect.Y + Convert.ToInt32(font.Size / 8), rect.Width, rect.Height);


            #region 字形顏色
            Brush FontColor = new SolidBrush(Color.Black);
            if (btnStyle == buttonStyle.ButtonEnableFalse)
            {
                FontColor = new SolidBrush(Color.Gray);
            }
            #endregion
            #region 字型
            StringFormat sf = new StringFormat();
            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            g.DrawString(Text, font, FontColor, rect, sf);
            #endregion

            p.Dispose();
            b.Dispose();
            g.SmoothingMode = SmoothingMode.Default;
        }
Esempio n. 11
0
        /// <summary>
        /// 繪製圓形按鈕(用法同矩形按鈕)
        /// </summary>
        /// <param name="text"></param>
        /// <param name="g"></param>
        /// <param name="Location"></param>
        /// <param name="r"></param>
        /// <param name="btnStyle"></param>
        public static void DrawCircleButton(string text, Graphics g, Point Location, int r, buttonStyle btnStyle)
        {
            Graphics  Gcircle = g;
            Rectangle rect    = new Rectangle(Location.X, Location.Y, r, r);
            Pen       p       = new Pen(new SolidBrush(Color.Black));

            Gcircle.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Gcircle.DrawEllipse(p, rect);
            if (btnStyle == buttonStyle.ButtonFocuse)
            {
                Gcircle.FillEllipse(new SolidBrush(ColorTranslator.FromHtml("#338FCC")), rect);
            }
            else if (btnStyle == buttonStyle.ButtonMouseOver)
            {
                Gcircle.FillEllipse(new SolidBrush(ColorTranslator.FromHtml("#EAC100")), rect);
            }
            else if (btnStyle == buttonStyle.ButtonFocuseAndMouseOver)
            {
                Gcircle.FillEllipse(new SolidBrush(ColorTranslator.FromHtml("#EAC100")), rect);
            }

            p.DashStyle = DashStyle.Dash;
            if (btnStyle != buttonStyle.ButtonNormal)
            {
                Gcircle.DrawEllipse(p, new Rectangle(rect.X + 2, rect.Y + 2, rect.Width - 4, rect.Height - 4));//虛綫框
            }
            Gcircle.FillEllipse(new SolidBrush(Color.WhiteSmoke), new Rectangle(rect.X + 3, rect.Y + 3, rect.Width - 6, rect.Height - 6));

            #region 字型
            StringFormat sf = new StringFormat();
            sf.Alignment     = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;
            Gcircle.DrawString(text, new Font("宋體", 10), new SolidBrush(Color.Black), rect, sf);
            #endregion

            p.Dispose();
        }