summaryrefslogtreecommitdiff
path: root/love2dToAPK/Forms/baseForm.cs
blob: 31b92a226520bafb9e24de0e4bcb9309ed8b38fc (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace love2dToAPK.Forms {

    public partial class baseForm : Form {

        #region localVariables
        Panel overlayPanel;
        #endregion

        #region properties
        public string WindowTitle {
            get { return lblTitle.Text; }
            set { lblTitle.Text = value; }
        }

        public bool MinimizeAble {
            get { return btnMinimize.Enabled; }
            set {
                if (value) {
                    btnMinimize.Enabled = true;
                    btnMinimize.Show();
                }
                else {
                    btnMinimize.Enabled = false;
                    btnMinimize.Hide();
                }
            }
        }
        #endregion

        #region formShadow
        protected override CreateParams CreateParams {
            get {
                const int CS_DROPSHADOW = 0x20000;
                CreateParams cp = base.CreateParams;
                cp.ClassStyle |= CS_DROPSHADOW;
                return cp;
            }
        }
        #endregion

        #region formMove
        /* This region contains the code needed to make the form moveable */
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int HT_CAPTION = 0x2;

        [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        [System.Runtime.InteropServices.DllImportAttribute("user32.dll")]
        public static extern bool ReleaseCapture();

        private void baseForm_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
            if (e.Button == MouseButtons.Left) {
                ReleaseCapture();
                SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
            }
        }
        #endregion

        public baseForm() {
            InitializeComponent();

            /* Add event handlers */
            // These ones are for moving the form
            this.MouseDown += baseForm_MouseDown;
            pnlTitleBar.MouseDown += baseForm_MouseDown;
            pnlFormActions.MouseDown += baseForm_MouseDown;
            lblTitle.MouseDown += baseForm_MouseDown;
            // These are for the button hover effect on the action buttons
            btnClose.MouseEnter += btn_mouseEnter;
            btnClose.MouseLeave += btn_mouseLeave;
            btnMinimize.MouseEnter += btn_mouseEnter;
            btnMinimize.MouseLeave += btn_mouseLeave;
            // These are for the actionButtons
            btnClose.Click += btnClose_Click;
            btnMinimize.Click += btnMinimize_Click;
            // This make the form gray when onactive
            this.EnabledChanged += baseForm_onEnabledChanged;
        }

        #region EventHandlers
        private void btnClose_Click(object sender, EventArgs e) {
            /* Handles the exit-button click */
            this.Close();
        }

        private void btnMinimize_Click(object sender, EventArgs e) {
            /* Handles the minimize-button click */
            this.WindowState = FormWindowState.Minimized;
        }

        private void baseForm_onEnabledChanged(object sender, EventArgs e) {
            /* Handles the enable/disable event */
            if (Enabled) {
                this.Controls.Remove(overlayPanel);
                overlayPanel.Dispose();
                overlayPanel = null;
            }
            else {
                overlayPanel = new Panel();
                overlayPanel.Location = new Point(0, 0);
                overlayPanel.Size = new Size(this.Width, this.Height);
                overlayPanel.BackColor = Color.FromArgb(0, 255, 255, 255);
                this.Controls.Add(overlayPanel);
                //overlayPanel.BringToFront();
                this.Invalidate();
            }
        }
        #endregion

        #region ButtonHoverEffect
        public void btn_mouseEnter(object sender, System.EventArgs e) {
            /* This method handles mouseOver event on buttons */
            if (sender is Label) {
                Label thisLabel = (Label)sender;
                //thisLabel.BackColor = Program.UiTheme(thisLabel.Name + "_backgroundHover");
            }
            else if (sender is PictureBox) {
                PictureBox thisPicture = (PictureBox)sender;
                //thisPicture.BackColor = Program.UiTheme(thisPicture.Name + "_backgroundHover");
            }
        }

        public void btn_mouseLeave(object sender, System.EventArgs e) {
            /* This method handles mouseOver event on buttons */
            if (sender is Label) {
                Label thisLabel = (Label)sender;
                //thisLabel.BackColor = Program.UiTheme(thisLabel.Name + "_background");
            }
            else if (sender is PictureBox) {
                PictureBox thisPicture = (PictureBox)sender;
                //thisPicture.BackColor = Program.UiTheme(thisPicture.Name + "_background");
            }
        }
        #endregion

        private void baseForm_Load(object sender, EventArgs e) {
            btnClose.BackgroundColor = ColorTranslator.FromHtml("#ea316e");
            btnMinimize.BackgroundColor = ColorTranslator.FromHtml("#ea316e");
        }

        public virtual void setColor(Color color) {
            pnlTitleBar.BackColor = color;
            pnlFormActions.BackColor = color;
            btnClose.BackgroundColor = color;
            btnMinimize.BackgroundColor = color;
        }
    }

}