aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Main/Apps/ShifterStuff/Shifter.cs
blob: 529e6034e9ba72444e421a0ef621fd49b3a8fbd7 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using ShiftOS.Engine.Misc;
using ShiftOS.Engine.WindowManager;
using ShiftOS.Main.Properties;
using Whoa;

namespace ShiftOS.Main.ShiftOS.Apps.ShifterStuff
{
	public partial class Shifter : UserControl
	{
        public static readonly ImageConverter imageConverter = new ImageConverter();
        public int ColorType; //This is a check to see what option was chosen.
		public Shifter()
		{
			InitializeComponent();
		}

		void button1_Click(object sender, EventArgs e)
		{
			ColorType = 1;
			ShiftWM.Init(new SelectColor(), "Select a color", Resources.iconColourPicker_fw);
		}

        /// <summary>
        /// Modifies the values in ShiftShiftSkinData.Colors.
        /// </summary>
        /// <param name="borderColor">The border color of the window.</param>
        /// <param name="btnClose">The close button color of the window.</param>
        /// <param name="btnCloseHover">The close button color of the window while hovering.</param>
        /// <param name="btnMax">The maximize button color of the window.</param>
        /// <param name="btnMaxHover">The maximize button color of the window while hovering.</param>
        /// <param name="btnMin">The minimize button color of the window.</param>
        /// <param name="btnMinHover">The minimize button color of the window while hovering.</param>
        void ModifyData(Color borderColor, Color btnClose, Color btnCloseHover, Color btnMax, Color btnMaxHover, Color btnMin, Color btnMinHover)
        {
            SetBorderColor(borderColor);
            ShiftSkinData.Colors.BtnCloseColor = btnClose;
            ShiftSkinData.Colors.BtnCloseHoverColor = btnCloseHover;
            ShiftSkinData.Colors.BtnMaxColor = btnMax;
            ShiftSkinData.Colors.BtnMaxHoverColor = btnMaxHover;
            ShiftSkinData.Colors.BtnMinColor = btnMin;
            ShiftSkinData.Colors.BtnMinHoverColor = btnMinHover;
        }

        // SetBorderColor
        public void SetBorderColor(Color borderColor)
        {
            ShiftSkinData.Colors.LeftTopCornerColor = borderColor;
            ShiftSkinData.Colors.TitleBarColor = borderColor;
            ShiftSkinData.Colors.RightTopCornerColor = borderColor;
            ShiftSkinData.Colors.LeftSideColor = borderColor;
            ShiftSkinData.Colors.RightSideColor = borderColor;
            ShiftSkinData.Colors.LeftBottomCornerColor = borderColor;
            ShiftSkinData.Colors.BottomSideColor = borderColor;
            ShiftSkinData.Colors.RightBottomCornerColor = borderColor;
        }

        void SetDefaultSkin(object sender, EventArgs e)
		{
            ModifyData(Color.FromArgb(64, 64, 64), Color.Black, Color.FromArgb(40, 40, 40), Color.Black, Color.FromArgb(40, 40, 40), Color.Black, Color.FromArgb(40, 40, 40));
            ApplySkin();
		}

		void SetColorSkin(object sender, EventArgs e)
		{
            ModifyData(Color.Blue, Color.Red, Color.FromArgb(255, 102, 102), Color.Yellow, Color.FromArgb(255, 255, 153), Color.Green, Color.FromArgb(102, 255, 102));
			ApplySkin();
		}

		void SetRandomSkin(object sender, EventArgs e)
		{
			var rnd = new Random();
            ModifyData(
                Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)), // Border Color
                Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)), // Close Button Color
                Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)), // Close Hover Color
                Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)), // Maximize Button Color
                Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)), // Maximize Hover Color
                Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255)), // Minimize Button Color
                Color.FromArgb(rnd.Next(255), rnd.Next(255), rnd.Next(255))); // Minimize Hover Color
			ApplySkin();
		}

		void ApplySkin()
		{
			foreach (var window in ShiftWM.Windows)
			{
				window.Invoke(new Action(() => window.titleBar.BackColor = ShiftSkinData.Colors.TitleBarColor));
				window.Invoke(new Action(() => window.leftTopCorner.BackColor = ShiftSkinData.Colors.LeftTopCornerColor));
				window.Invoke(new Action(() => window.rightTopCorner.BackColor = ShiftSkinData.Colors.RightTopCornerColor));
				window.Invoke(new Action(() => window.leftSide.BackColor = ShiftSkinData.Colors.LeftSideColor));
				window.Invoke(new Action(() => window.rightSide.BackColor = ShiftSkinData.Colors.RightSideColor));
				window.Invoke(new Action(() => window.leftBottomCorner.BackColor = ShiftSkinData.Colors.LeftBottomCornerColor));
				window.Invoke(new Action(() => window.bottomSide.BackColor = ShiftSkinData.Colors.BottomSideColor));
				window.Invoke(new Action(() => window.rightBottomCorner.BackColor = ShiftSkinData.Colors.RightBottomCornerColor));
				window.Invoke(new Action(() => window.btnClose.BackColor = ShiftSkinData.Colors.BtnCloseColor));
				window.Invoke(new Action(() => window.btnMax.BackColor = ShiftSkinData.Colors.BtnMaxColor));
				window.Invoke(new Action(() => window.btnMin.BackColor = ShiftSkinData.Colors.BtnMinColor));
			}
		}
        void ApplyTexturedSkin() //not implemented
        {
            throw new NotImplementedException("Not implemented.");

            /*foreach (var window in ShiftWM.Windows)
            {
                window.Invoke(new Action(() => window.titleBar.Height = ShiftSkinData.Images.TitleBarImage.Height));
                window.Invoke(new Action(() => window.leftTopCorner.Width = ShiftSkinData.Images.LeftTopCornerImage.Width));
                window.Invoke(new Action(() => window.rightTopCorner.Width = ShiftSkinData.Images.RightTopCornerImage.Width));
                window.Invoke(new Action(() => window.leftSide.Width = ShiftSkinData.Images.LeftSideImage.Width));
                window.Invoke(new Action(() => window.rightSide.Width = ShiftSkinData.Images.RightSideImage.Width));
                window.Invoke(new Action(() => window.leftBottomCorner.Width = ShiftSkinData.Images.LeftBottomCornerImage.Width));
                window.Invoke(new Action(() => window.bottomSide.Width = ShiftSkinData.Images.BottomSideImage.Width));
                window.Invoke(new Action(() => window.rightBottomCorner.Width = ShiftSkinData.Images.RightBottomCornerImage.Width));
                window.Invoke(new Action(() => window.btnClose.Width = ShiftSkinData.Images.BtnCloseImage.Width));
                window.Invoke(new Action(() => window.btnMax.Width = ShiftSkinData.Images.BtnMaxImage.Width));
                window.Invoke(new Action(() => window.btnMin.Width = ShiftSkinData.Images.BtnMinImage.Width));
                window.Invoke(new Action(() => window.titleBar.BackgroundImage = ShiftSkinData.Images.TitleBarImage));
                window.Invoke(new Action(() => window.leftTopCorner.BackgroundImage = ShiftSkinData.Images.LeftTopCornerImage));
                window.Invoke(new Action(() => window.rightTopCorner.BackgroundImage = ShiftSkinData.Images.RightTopCornerImage));
                window.Invoke(new Action(() => window.leftSide.BackgroundImage = ShiftSkinData.Images.LeftSideImage));
                window.Invoke(new Action(() => window.rightSide.BackgroundImage = ShiftSkinData.Images.RightSideImage));
                window.Invoke(new Action(() => window.leftBottomCorner.BackgroundImage = ShiftSkinData.Images.LeftBottomCornerImage));
                window.Invoke(new Action(() => window.bottomSide.BackgroundImage = ShiftSkinData.Images.BottomSideImage));
                window.Invoke(new Action(() => window.rightBottomCorner.BackgroundImage = ShiftSkinData.Images.RightBottomCornerImage));
                window.Invoke(new Action(() => window.btnClose.BackgroundImage = ShiftSkinData.Images.BtnCloseImage));
                window.Invoke(new Action(() => window.btnMax.BackgroundImage = ShiftSkinData.Images.BtnMaxImage));
                window.Invoke(new Action(() => window.btnMin.BackgroundImage = ShiftSkinData.Images.BtnMinImage));
            }*/
        }

		void btnSave_Click(object sender, EventArgs e)
		{
            Color[] shiftSkinColors = new Color[14];
            
            shiftSkinColors[0] = ShiftSkinData.Colors.LeftTopCornerColor;
            shiftSkinColors[1] = ShiftSkinData.Colors.TitleBarColor;
            shiftSkinColors[2] = ShiftSkinData.Colors.RightTopCornerColor;
            shiftSkinColors[3] = ShiftSkinData.Colors.LeftSideColor;
            shiftSkinColors[4] = ShiftSkinData.Colors.RightSideColor;
            shiftSkinColors[5] = ShiftSkinData.Colors.LeftBottomCornerColor;
            shiftSkinColors[6] = ShiftSkinData.Colors.BottomSideColor;
            shiftSkinColors[7] = ShiftSkinData.Colors.RightBottomCornerColor;
            shiftSkinColors[8] = ShiftSkinData.Colors.BtnCloseColor;
            shiftSkinColors[9] = ShiftSkinData.Colors.BtnCloseHoverColor;
            shiftSkinColors[10] = ShiftSkinData.Colors.BtnMaxColor;
            shiftSkinColors[11] = ShiftSkinData.Colors.BtnMaxHoverColor;
            shiftSkinColors[12] = ShiftSkinData.Colors.BtnMinColor;
            shiftSkinColors[13] = ShiftSkinData.Colors.BtnMinHoverColor;

            using (var fobj = File.OpenWrite(@"C:\Users\Public\Documents\Skin.whoa"))
                Whoa.Whoa.SerialiseObject(fobj, shiftSkinColors);

            InfoboxTemplate shiftWindow = ShiftWM.StartInfoboxSession(
				"Saved Skin",
				"Saved Skin to C:\\Users\\Public\\Documents\\Skin.whoa",
				InfoboxTemplate.ButtonType.Ok);
    
		}

        private void btnLoad_Click(object sender, EventArgs e)
        {
            Color[] shiftSkinColors = new Color[14];
            using (var fobj = File.OpenRead(@"C:\Users\Public\Documents\Skin.whoa"))
              shiftSkinColors  = Whoa.Whoa.DeserialiseObject<Color[]>(fobj);

            ShiftSkinData.Colors.LeftTopCornerColor = shiftSkinColors[0];
            ShiftSkinData.Colors.TitleBarColor = shiftSkinColors[1];
            ShiftSkinData.Colors.RightTopCornerColor = shiftSkinColors[2];
            ShiftSkinData.Colors.LeftSideColor = shiftSkinColors[3];
            ShiftSkinData.Colors.RightSideColor = shiftSkinColors[4];
            ShiftSkinData.Colors.LeftBottomCornerColor = shiftSkinColors[5];
            ShiftSkinData.Colors.BottomSideColor = shiftSkinColors[6];
            ShiftSkinData.Colors.RightBottomCornerColor = shiftSkinColors[7];
            ShiftSkinData.Colors.BtnCloseColor = shiftSkinColors[8];
            ShiftSkinData.Colors.BtnCloseHoverColor = shiftSkinColors[9];
            ShiftSkinData.Colors.BtnMaxColor = shiftSkinColors[10];
            ShiftSkinData.Colors.BtnMaxHoverColor = shiftSkinColors[11];
            ShiftSkinData.Colors.BtnMinColor = shiftSkinColors[12];
            ShiftSkinData.Colors.BtnMinHoverColor = shiftSkinColors[13];

            ApplySkin();
            ShiftWM.StartInfoboxSession(
    "Loaded Skin",
    "Loaded Skin from C:\\Users\\Public\\Documents\\Skin.whoa",
    InfoboxTemplate.ButtonType.Ok);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            ModifyData(
                Color.FromArgb(15, 29, 45),
                Color.FromArgb(15, 29, 78),
                Color.FromArgb(15, 29, 100),
                Color.FromArgb(15, 29, 130),
                Color.FromArgb(15, 29, 108),
                Color.FromArgb(15, 29, 130),
                Color.FromArgb(15, 29, 160));
            ApplySkin();
        }

        private void shiftButton1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("This was clicked.");
        }

        private void shiftButton2_Click(object sender, EventArgs e)
        {
           
        }
        public static Bitmap LoadImage(byte[] byteArray)
        {
            var bm = (Bitmap)imageConverter.ConvertFrom(byteArray);
            
            if (bm != null && (bm.HorizontalResolution != (int)bm.HorizontalResolution ||
                               bm.VerticalResolution != (int)bm.VerticalResolution))
            {
                bm.SetResolution((int)(bm.HorizontalResolution + 0.5f),
                                 (int)(bm.VerticalResolution + 0.5f));
            }
            return bm;
        }
    }
}