aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Controls
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.WinForms/Controls')
-rw-r--r--ShiftOS.WinForms/Controls/ColorControl.Designer.cs69
-rw-r--r--ShiftOS.WinForms/Controls/ColorControl.cs243
-rw-r--r--ShiftOS.WinForms/Controls/ShiftedProgressBar.Designer.cs36
-rw-r--r--ShiftOS.WinForms/Controls/ShiftedProgressBar.cs123
-rw-r--r--ShiftOS.WinForms/Controls/TerminalBox.cs33
5 files changed, 504 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/Controls/ColorControl.Designer.cs b/ShiftOS.WinForms/Controls/ColorControl.Designer.cs
new file mode 100644
index 0000000..ca6b1a7
--- /dev/null
+++ b/ShiftOS.WinForms/Controls/ColorControl.Designer.cs
@@ -0,0 +1,69 @@
+using System.Windows.Forms;
+
+namespace ShiftOS.WinForms.Controls
+{
+ partial class ColorControl
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ this.pnlcolorbox = new Canvas();
+ this.SuspendLayout();
+ //
+ // pnlcolorbox
+ //
+ this.pnlcolorbox.Location = new System.Drawing.Point(37, 18);
+ this.pnlcolorbox.Name = "pnlcolorbox";
+ this.pnlcolorbox.Size = new System.Drawing.Size(255, 255);
+ this.pnlcolorbox.TabIndex = 0;
+ //
+ // ColorPicker
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.BackColor = System.Drawing.Color.Black;
+ this.Controls.Add(this.pnlcolorbox);
+ this.ForeColor = System.Drawing.Color.White;
+ this.Name = "ColorPicker";
+ this.Size = new System.Drawing.Size(332, 520);
+ this.Load += new System.EventHandler(this.ColorPicker_Load);
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private Canvas pnlcolorbox;
+ }
+
+ internal class Canvas : Panel
+ {
+ public Canvas() : base()
+ {
+ DoubleBuffered = true;
+ }
+ }
+}
diff --git a/ShiftOS.WinForms/Controls/ColorControl.cs b/ShiftOS.WinForms/Controls/ColorControl.cs
new file mode 100644
index 0000000..09b4c34
--- /dev/null
+++ b/ShiftOS.WinForms/Controls/ColorControl.cs
@@ -0,0 +1,243 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing;
+using System.Data;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using ShiftOS.WinForms.Tools;
+
+namespace ShiftOS.WinForms.Controls
+{
+ public partial class ColorControl : UserControl
+ {
+ public ColorControl()
+ {
+ InitializeComponent();
+ this.DoubleBuffered = true;
+ }
+
+ public Color SelectedForeground = Color.Black;
+
+ public Color GetColorFromCoords(Point pt)
+ {
+ for (int r = 0; r <= 255; r++)
+ {
+ //As we move to the right of the panel things should get more blue...
+ //and as we go down, more red
+ //and as we go down AND to the right, green.
+ for (int b = 0; b <= 255; b++)
+ {
+ int xy = LinearInterpolate(0, 255 * 255, pt.X * pt.Y, 0, 255);
+ int g = LinearInterpolate(0, 255 * 255, r * b, 0, 255);
+ if (pt.X == b && pt.Y == r && g == xy)
+ return Color.FromArgb(r, g, b);
+ }
+ }
+
+ return Color.Empty;
+ }
+
+ public Color SelectedColor
+ {
+ get
+ {
+ return SelectedForeground;
+ }
+ set
+ {
+ SelectedForeground = value;
+ }
+ }
+
+ int LastX, LastY = 0;
+
+ private void ColorPicker_Load(object sender, EventArgs e)
+ {
+ pnlcolorbox.MouseMove += (o, a) =>
+ {
+ if (a.Button == MouseButtons.Left)
+ {
+ SelectedColor = GetColorFromCoords(a.Location);
+ LastX = a.Location.X;
+ LastY = a.Location.Y;
+ DrawEverything();
+ }
+
+ };
+ pnlcolorbox.Paint += (o, a) =>
+ {
+
+ float selectedX = 0;
+ float selectedY = 0;
+ float width = 5;
+ float height = 5;
+
+ for (int r = 0; r <= 255; r++)
+ {
+ //As we move to the right of the panel things should get more blue...
+ //and as we go down, more red
+ //and as we go down AND to the right, green.
+ for (int b = 0; b <= 255; b++)
+ {
+ int g = LinearInterpolate(0, 255 * 255, r * b, 0, 255);
+ var c = Color.FromArgb(r, g, b);
+ a.Graphics.FillRectangle(new SolidBrush(c), b, r, 1, 1);
+ if (SelectedColor == c)
+ {
+ selectedX = b - 2;
+ selectedY = r - 2;
+ }
+ }
+ }
+
+ int selectedg = LinearInterpolate(0, 255 * 255, (int)(selectedX + 2 * selectedY + 2), 0, 255);
+ var inverted = InvertColor((int)selectedX + 2, selectedg, (int)selectedY + 2);
+ a.Graphics.DrawEllipse(new Pen(new SolidBrush(inverted), 1), selectedX, selectedY, width, height);
+
+ };
+
+ red.Width = 255;
+ red.Left = pnlcolorbox.Left;
+ red.Top = pnlcolorbox.Top + pnlcolorbox.Height + 5;
+ red.Height = 20;
+ red.TextChanged += (o, a) =>
+ {
+ if(red.Text != SelectedColor.R.ToString())
+ {
+ try
+ {
+ SelectedColor = Color.FromArgb(SelectedColor.A, Convert.ToInt32(red.Text), SelectedColor.G, SelectedColor.B);
+ DrawEverything();
+ }
+ catch
+ {
+ red.Text = SelectedColor.R.ToString();
+ }
+ }
+ };
+ this.Controls.Add(red);
+ red.Show();
+
+ green.Width = 255;
+ green.Left = pnlcolorbox.Left;
+ green.Top = red.Top + red.Height + 5;
+ green.Height = 20;
+ green.TextChanged += (o, a) =>
+ {
+ if (green.Text != SelectedColor.G.ToString())
+ {
+ try
+ {
+ SelectedColor = Color.FromArgb(SelectedColor.A, SelectedColor.R, Convert.ToInt32(green.Text), SelectedColor.B);
+ DrawEverything();
+ }
+ catch
+ {
+ green.Text = SelectedColor.G.ToString();
+ }
+ }
+ };
+ this.Controls.Add(green);
+ green.Show();
+
+ blue.Width = 255;
+ blue.Left = pnlcolorbox.Left;
+ blue.Top = green.Top + red.Height + 5;
+ blue.Height = 20;
+ blue.TextChanged += (o, a) =>
+ {
+ if (blue.Text != SelectedColor.B.ToString())
+ {
+ try
+ {
+ SelectedColor = Color.FromArgb(SelectedColor.A, SelectedColor.R, SelectedColor.G, Convert.ToInt32(blue.Text));
+ DrawEverything();
+ }
+ catch
+ {
+ blue.Text = SelectedColor.B.ToString();
+ }
+ }
+ };
+ this.Controls.Add(blue);
+ blue.Show();
+
+ alpha.Width = 255;
+ alpha.Left = pnlcolorbox.Left;
+ alpha.Top = blue.Top + red.Height + 5;
+ alpha.Height = 20;
+ alpha.TextChanged += (o, a) =>
+ {
+ if (alpha.Text != SelectedColor.A.ToString())
+ {
+ try
+ {
+ SelectedColor = Color.FromArgb(Convert.ToInt32(alpha.Text), SelectedColor.R, SelectedColor.G, SelectedColor.B);
+ DrawEverything();
+ }
+ catch
+ {
+ alpha.Text = SelectedColor.A.ToString();
+ }
+ }
+ }; this.Controls.Add(alpha);
+ alpha.Show();
+
+ preview.Width = 255;
+ preview.Left = pnlcolorbox.Left;
+ preview.Top = alpha.Top + red.Height + 5;
+ preview.Height = 20;
+ preview.Paint += (o, a) =>
+ {
+ int width = preview.Width / 2;
+ int height = preview.Height;
+ a.Graphics.FillRectangle(new SolidBrush(SelectedForeground), 0, 0, width * 2, height);
+ };
+ this.Controls.Add(preview);
+ preview.Show();
+
+ ControlManager.SetupControl(red);
+ ControlManager.SetupControl(green);
+ ControlManager.SetupControl(blue);
+ ControlManager.SetupControl(alpha);
+
+
+ DrawEverything();
+ }
+
+
+ TextBox red = new TextBox();
+ TextBox green = new TextBox();
+ TextBox blue = new TextBox();
+ TextBox alpha = new TextBox();
+ Panel preview = new Panel();
+
+
+ public Color InvertColor(int r, int g, int b)
+ {
+ return Color.FromArgb(255 - r, 255 - g, 255 - b);
+ }
+
+ public void DrawEverything()
+ {
+ pnlcolorbox.Refresh();
+ red.Text = SelectedColor.R.ToString();
+ green.Text = SelectedColor.G.ToString();
+ blue.Text = SelectedColor.B.ToString();
+ alpha.Text = SelectedColor.A.ToString();
+ preview.Refresh();
+ }
+
+ public int LinearInterpolate(int input_start, int input_end, int input, int output_start, int output_end)
+ {
+ int input_range = input_end - input_start;
+ int output_range = output_end - output_start;
+
+ return (input - input_start) * output_range / input_range + output_start;
+ }
+
+ }
+}
diff --git a/ShiftOS.WinForms/Controls/ShiftedProgressBar.Designer.cs b/ShiftOS.WinForms/Controls/ShiftedProgressBar.Designer.cs
new file mode 100644
index 0000000..a59a09c
--- /dev/null
+++ b/ShiftOS.WinForms/Controls/ShiftedProgressBar.Designer.cs
@@ -0,0 +1,36 @@
+namespace ShiftOS.WinForms.Controls
+{
+ partial class ShiftedProgressBar
+ {
+ /// <summary>
+ /// Required designer variable.
+ /// </summary>
+ private System.ComponentModel.IContainer components = null;
+
+ /// <summary>
+ /// Clean up any resources being used.
+ /// </summary>
+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Component Designer generated code
+
+ /// <summary>
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ /// </summary>
+ private void InitializeComponent()
+ {
+ components = new System.ComponentModel.Container();
+ }
+
+ #endregion
+ }
+}
diff --git a/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs b/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs
new file mode 100644
index 0000000..4707541
--- /dev/null
+++ b/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs
@@ -0,0 +1,123 @@
+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 ShiftOS.WinForms.Controls
+{
+ public partial class ShiftedProgressBar : Control
+ {
+ public ShiftedProgressBar()
+ {
+ this.SizeChanged += (o, a) =>
+ {
+ this.Refresh();
+ };
+ var t = new Timer();
+ t.Interval = 100;
+ t.Tick += (o, a) =>
+ {
+ if(this._style == ProgressBarStyle.Marquee)
+ {
+ if(_marqueePos >= this.Width)
+ {
+ _marqueePos = 0 - (this.Width / 4);
+ }
+ else
+ {
+ _marqueePos++;
+ }
+ this.Refresh();
+ }
+ };
+ t.Start();
+ }
+
+ private int _value = 0;
+ private int _max = 100;
+ public int Value
+ {
+ get
+ {
+ return _value;
+ }
+ set
+ {
+ _value = value;
+ this.Refresh();
+ }
+ }
+ public int Maximum
+ {
+ get
+ {
+ return _max;
+ }
+ set
+ {
+ _max = value;
+ this.Refresh();
+ }
+ }
+
+ public ProgressBarStyle _style = ProgressBarStyle.Continuous;
+
+ public ProgressBarStyle Style
+ {
+ get { return _style; }
+ set { _style = value; this.Refresh(); }
+ }
+
+ private int _blocksize = 5;
+
+ public int BlockSize
+ {
+ get { return _blocksize; }
+ set
+ {
+ _blocksize = value;
+ this.Refresh();
+ }
+ }
+
+ protected override void OnPaint(PaintEventArgs pe)
+ {
+ pe.Graphics.Clear(this.BackColor);
+ switch (_style)
+ {
+ case ProgressBarStyle.Continuous:
+ double width = linear(this.Value, 0, this.Maximum, 0, this.Width);
+ pe.Graphics.FillRectangle(new SolidBrush(Color.Green), new RectangleF(0, 0, (float)width, this.Height));
+ break;
+ case ProgressBarStyle.Blocks:
+ int block_count = this.Width / (this._blocksize + 2);
+ int blocks = (int)linear(this.Value, 0, this.Maximum, 0, block_count);
+ for(int i = 0; i < blocks - 1; i++)
+ {
+ int position = i * (_blocksize + 2);
+ pe.Graphics.FillRectangle(new SolidBrush(Color.Green), new Rectangle(position, 0, _blocksize, this.Height));
+ }
+ break;
+ case ProgressBarStyle.Marquee:
+ pe.Graphics.FillRectangle(new SolidBrush(Color.Green), new Rectangle(_marqueePos, 0, this.Width / 4, this.Height));
+ break;
+ }
+ }
+
+ private int _marqueePos = 0;
+
+ static private double linear(double x, double x0, double x1, double y0, double y1)
+ {
+ if ((x1 - x0) == 0)
+ {
+ return (y0 + y1) / 2;
+ }
+ return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
+ }
+ }
+}
diff --git a/ShiftOS.WinForms/Controls/TerminalBox.cs b/ShiftOS.WinForms/Controls/TerminalBox.cs
new file mode 100644
index 0000000..e0745d4
--- /dev/null
+++ b/ShiftOS.WinForms/Controls/TerminalBox.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using ShiftOS.Engine;
+
+namespace ShiftOS.WinForms.Controls
+{
+ public class TerminalBox : RichTextBox, ITerminalWidget
+ {
+ public void SelectBottom()
+ {
+ try
+ {
+ this.Select(this.Text.Length, 0);
+ this.ScrollToCaret();
+ }
+ catch { }
+ }
+
+ public void Write(string text)
+ {
+ this.Text += Localization.Parse(text);
+ }
+
+ public void WriteLine(string text)
+ {
+ this.Text += Localization.Parse(text) + Environment.NewLine;
+ }
+ }
+}