aboutsummaryrefslogtreecommitdiff
path: root/Histacom2.Engine/UI/ClassicStartMenuItem.cs
blob: 5e3a3a702dc8ebcc1ecd01328036cf2bd4433827 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Histacom2.Engine.UI
{
    public class ClassicStartMenuItem : ToolStripMenuItem
    {
        private ClassicStartMenuItemLayout layout;
        public ClassicStartMenuItemLayout LayoutStyle {
            get
            {
                return layout;
            }
            set
            {
                layout = value;
                Invalidate();
            }
        }

        private string subtext = "Subtitle";
        public string SubTitle
        {
            get
            {
                return subtext;
            }
            set
            {
                subtext = value;
                Invalidate();
            }
        }

        public bool DoBackColorAdapt { get; set; }

        public ClassicStartMenuItem()
        {
            AutoSize = false;
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (SaveSystem.currentTheme != null && DoBackColorAdapt) e.Graphics.Clear(SaveSystem.currentTheme.threeDObjectsColor);
            else if (BackColor != Color.Transparent) e.Graphics.FillRectangle(new SolidBrush(BackColor), new Rectangle(0, 0, Width, Height));

            e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
            if (BackgroundImage != null)
            {
                if (BackgroundImageLayout == ImageLayout.Stretch) e.Graphics.DrawImage(BackgroundImage, new Rectangle(0, 0, Width, Height + 9));
            }
            int imgWidth = 0;
            if (Image != null)
            {
                if (Selected)
            {
                if (SaveSystem.currentTheme != null && DoBackColorAdapt) e.Graphics.FillRectangle(new SolidBrush(SaveSystem.currentTheme.selectedBackColor), new Rectangle(0, 0, Width, Image.Height));
                else e.Graphics.FillRectangle(Brushes.Navy, new Rectangle(0, 0, Width, Image.Height));
            }

            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
            
            e.Graphics.DrawImage(Image, 0 + Padding.Left - Padding.Right, 0); imgWidth = Image.Width; }
            //if (Image != null) if (Height != Image.Height) if (layout == ClassicStartMenuItemLayout.CloseTitleWithLightSubtitle && Height != Image.Height + 8) { Height = Image.Height; }

            StringFormat sf = new StringFormat();
            sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

            if (!Selected) {
                switch (layout) {
                    case ClassicStartMenuItemLayout.DistancedTitle:
                        e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), imgWidth + 6, getYForString(), sf);
                        break;
                    case ClassicStartMenuItemLayout.CloseTitle:
                        e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), imgWidth + 2, getYForString(), sf);
                        break;
                    case ClassicStartMenuItemLayout.CloseTitleWithLightSubtitle:
                        e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), imgWidth + 2, 3, sf);
                        e.Graphics.DrawString(subtext, new Font(Font, FontStyle.Regular), Brushes.Gray, imgWidth + 2, 16, sf);
                        //if (Image != null) if (Height != Image.Height + 8) Height = Image.Height + 8;
                        break;
                }

                if (DropDownItems.Count > 0)
                {
                    e.Graphics.DrawPolygon(new Pen(ForeColor), new Point[] { new Point(Width - 16, 11), new Point(Width - 13, 14), new Point(Width - 16, 17) });
                    e.Graphics.FillPolygon(new SolidBrush(ForeColor), new Point[] { new Point(Width - 16, 11), new Point(Width - 13, 14), new Point(Width - 16, 17) });
                }
            } else
            {
                if (SaveSystem.currentTheme != null)
                {
                    switch (layout)
                    {
                        case ClassicStartMenuItemLayout.DistancedTitle:
                            e.Graphics.DrawString(Text, Font, new SolidBrush(SaveSystem.currentTheme.selectedTextColor), imgWidth + 6, getYForString(), sf);
                            break;
                        case ClassicStartMenuItemLayout.CloseTitle:
                            e.Graphics.DrawString(Text, Font, new SolidBrush(SaveSystem.currentTheme.selectedTextColor), imgWidth + 2, getYForString(), sf);
                            break;
                        case ClassicStartMenuItemLayout.CloseTitleWithLightSubtitle:
                            e.Graphics.DrawString(Text, Font, new SolidBrush(SaveSystem.currentTheme.selectedTextColor), imgWidth + 2, 3, sf);
                            //if (Image != null) if (Height != Image.Height + 8) Height = Image.Height + 8;
                            break;
                    }

                    if (DropDownItems.Count > 0)
                    {
                        e.Graphics.DrawPolygon(new Pen(SaveSystem.currentTheme.selectedTextColor), new Point[] { new Point(121, 11), new Point(124, 14), new Point(121, 17) });
                        e.Graphics.FillPolygon(new SolidBrush(SaveSystem.currentTheme.selectedTextColor), new Point[] { new Point(121, 11), new Point(124, 14), new Point(121, 17) });
                    }
                }
            }
        }

        private int getYForString()
        {
            if (Image != null)
            {
                if (Image.Height == 32) return 9;
                if (Image.Height == 24) return 6;
            }
            return 0;
        }
    }
    public enum ClassicStartMenuItemLayout
    {
        DistancedTitle,
        CloseTitle,
        //CloseTitleWithTwoLines,
        CloseTitleWithLightSubtitle
    }
}