aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.WinForms/Controls
diff options
context:
space:
mode:
authorMichael VanOverbeek <[email protected]>2017-05-21 13:05:31 +0000
committerMichael VanOverbeek <[email protected]>2017-05-21 13:05:31 +0000
commit68785f73f027b9dd4555b9f1ab7a22a1ca8794f8 (patch)
treef0c6dea13195bc516f90c2aa29cf85fa1488f6cf /ShiftOS.WinForms/Controls
parent76b54853ba726179f9fddb30c6f838991b7aa71a (diff)
parent9999324bd7751f536741c108322766421dae1a52 (diff)
downloadshiftos_thereturn-68785f73f027b9dd4555b9f1ab7a22a1ca8794f8.tar.gz
shiftos_thereturn-68785f73f027b9dd4555b9f1ab7a22a1ca8794f8.tar.bz2
shiftos_thereturn-68785f73f027b9dd4555b9f1ab7a22a1ca8794f8.zip
Merge branch 'master' of https://github.com/shiftos-game/ShiftOS
I should hire Ash Ketchum to do this for me. He'd do a better job.
Diffstat (limited to 'ShiftOS.WinForms/Controls')
-rw-r--r--ShiftOS.WinForms/Controls/ShiftedProgressBar.cs202
-rw-r--r--ShiftOS.WinForms/Controls/TerminalBox.cs261
2 files changed, 463 insertions, 0 deletions
diff --git a/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs b/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs
new file mode 100644
index 0000000..ceaff02
--- /dev/null
+++ b/ShiftOS.WinForms/Controls/ShiftedProgressBar.cs
@@ -0,0 +1,202 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+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;
+using ShiftOS.Engine;
+
+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
+ {
+ get
+ {
+ return SkinEngine.LoadedSkin.ProgressBarStyle;
+ }
+ }
+
+ public int BlockSize
+ {
+ get
+ {
+ return SkinEngine.LoadedSkin.ProgressBarBlockSize;
+ }
+ }
+
+ public Color RealBackColor
+ {
+ get
+ {
+ return SkinEngine.LoadedSkin.ProgressBarBackgroundColor;
+ }
+ }
+
+ public Image RealBackgroundImage
+ {
+ get
+ {
+ return SkinEngine.GetImage("progressbarbg");
+ }
+ }
+
+ public Image ProgressImage
+ {
+ get
+ {
+ return SkinEngine.GetImage("progress");
+ }
+ }
+
+ public Color ProgressColor
+ {
+ get
+ {
+ return SkinEngine.LoadedSkin.ProgressColor;
+ }
+ }
+
+ protected override void OnPaint(PaintEventArgs pe)
+ {
+ pe.Graphics.Clear(this.RealBackColor);
+ if(RealBackgroundImage != null)
+ {
+ pe.Graphics.FillRectangle(new TextureBrush(RealBackgroundImage), new Rectangle(0, 0, this.Width, this.Height));
+ }
+ switch (Style)
+ {
+ case ProgressBarStyle.Continuous:
+ double width = linear(this.Value, 0, this.Maximum, 0, this.Width);
+ if (ProgressImage != null)
+ {
+ pe.Graphics.FillRectangle(new TextureBrush(ProgressImage), new RectangleF(0, 0, (float)width, this.Height));
+ }
+ else
+ {
+ pe.Graphics.FillRectangle(new SolidBrush(ProgressColor), 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);
+ if (ProgressImage != null)
+ {
+ pe.Graphics.FillRectangle(new TextureBrush(ProgressImage), new Rectangle(position, 0, BlockSize, this.Height));
+
+ }
+ else
+ {
+ pe.Graphics.FillRectangle(new SolidBrush(ProgressColor), new Rectangle(position, 0, BlockSize, this.Height));
+ }
+ }
+ break;
+ case ProgressBarStyle.Marquee:
+ if (ProgressImage != null)
+ {
+ pe.Graphics.FillRectangle(new TextureBrush(ProgressImage), new Rectangle(_marqueePos, 0, this.Width / 4, this.Height));
+ }
+ else
+ {
+ pe.Graphics.FillRectangle(new SolidBrush(ProgressColor), 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..e95d038
--- /dev/null
+++ b/ShiftOS.WinForms/Controls/TerminalBox.cs
@@ -0,0 +1,261 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2017 Michael VanOverbeek and ShiftOS devs
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using ShiftOS.Engine;
+using ShiftOS.WinForms.Tools;
+
+namespace ShiftOS.WinForms.Controls
+{
+ public class TerminalBox : RichTextBox, ITerminalWidget
+ {
+ public void SelectBottom()
+ {
+ try
+ {
+ this.Select(this.Text.Length, 0);
+ this.ScrollToCaret();
+ }
+ catch { }
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing == true)
+ if(AppearanceManager.ConsoleOut == this)
+ AppearanceManager.ConsoleOut = null;
+ base.Dispose(disposing);
+ }
+
+ protected override void OnClick(EventArgs e)
+ {
+ base.OnClick(e);
+ this.Select(this.TextLength, 0);
+ }
+
+ public void Write(string text)
+ {
+ this.SuspendLayout();
+ this.HideSelection = true;
+ this.SelectionFont = ConstructFont();
+ this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor);
+ this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor);
+ this.AppendText(Localization.Parse(text));
+ this.HideSelection = false;
+ this.ResumeLayout();
+ }
+
+ private Font ConstructFont()
+ {
+ FontStyle fs = FontStyle.Regular;
+ if (ConsoleEx.Bold)
+ fs = fs | FontStyle.Bold;
+ if (ConsoleEx.Italic)
+ fs = fs | FontStyle.Italic;
+ if (ConsoleEx.Underline)
+ fs = fs | FontStyle.Underline;
+
+ return new Font(this.Font, fs);
+ }
+
+ public void WriteLine(string text)
+ {
+ this.SuspendLayout();
+ Engine.AudioManager.PlayStream(Properties.Resources.writesound);
+ this.HideSelection = true;
+ this.Select(this.TextLength, 0);
+ this.SelectionFont = ConstructFont();
+ this.SelectionColor = ControlManager.ConvertColor(ConsoleEx.ForegroundColor);
+ this.SelectionBackColor = ControlManager.ConvertColor(ConsoleEx.BackgroundColor);
+ this.AppendText(Localization.Parse(text) + Environment.NewLine);
+ this.HideSelection = false;
+ this.ResumeLayout();
+ }
+
+ bool quickCopying = false;
+
+ protected override void OnMouseDown(MouseEventArgs e)
+ {
+ //if right-clicking, then we initiate a quick-copy.
+ if (e.Button == MouseButtons.Right)
+ quickCopying = true;
+
+ //Override the mouse event so that it's a left-click at all times.
+ base.OnMouseDown(new MouseEventArgs(MouseButtons.Left, e.Clicks, e.X, e.Y, e.Delta));
+ }
+
+ protected override void OnMouseUp(MouseEventArgs mevent)
+ {
+ if(quickCopying == true)
+ {
+ if (!string.IsNullOrWhiteSpace(this.SelectedText))
+ {
+ this.Copy();
+ }
+ }
+ base.OnMouseUp(mevent);
+ }
+
+ protected override void OnKeyDown(KeyEventArgs e)
+ {
+ base.OnKeyDown(e);
+ if (!TerminalBackend.InStory)
+ {
+ switch (e.KeyCode) {
+ case Keys.Add:
+ case Keys.Alt:
+ case Keys.Apps:
+ case Keys.Attn:
+ case Keys.BrowserBack:
+ case Keys.BrowserFavorites:
+ case Keys.BrowserForward:
+ case Keys.BrowserHome:
+ case Keys.BrowserRefresh:
+ case Keys.BrowserSearch:
+ case Keys.BrowserStop:
+ case Keys.Cancel:
+ case Keys.Capital:
+ case Keys.Clear:
+ case Keys.Control:
+ case Keys.ControlKey:
+ case Keys.Crsel:
+ case Keys.Decimal:
+ case Keys.Divide:
+ case Keys.Down:
+ case Keys.End:
+ case Keys.Enter:
+ case Keys.EraseEof:
+ case Keys.Escape:
+ case Keys.Execute:
+ case Keys.Exsel:
+ case Keys.F1:
+ case Keys.F10:
+ case Keys.F11:
+ case Keys.F12:
+ case Keys.F13:
+ case Keys.F14:
+ case Keys.F15:
+ case Keys.F16:
+ case Keys.F17:
+ case Keys.F18:
+ case Keys.F19:
+ case Keys.F2:
+ case Keys.F20:
+ case Keys.F21:
+ case Keys.F22:
+ case Keys.F23:
+ case Keys.F24:
+ case Keys.F3:
+ case Keys.F4:
+ case Keys.F5:
+ case Keys.F6:
+ case Keys.F7:
+ case Keys.F8:
+ case Keys.F9:
+ case Keys.FinalMode:
+ case Keys.HanguelMode:
+ case Keys.HanjaMode:
+ case Keys.Help:
+ case Keys.Home:
+ case Keys.IMEAccept:
+ case Keys.IMEConvert:
+ case Keys.IMEModeChange:
+ case Keys.IMENonconvert:
+ case Keys.Insert:
+ case Keys.JunjaMode:
+ case Keys.KeyCode:
+ case Keys.LaunchApplication1:
+ case Keys.LaunchApplication2:
+ case Keys.LaunchMail:
+ case Keys.LButton:
+ case Keys.LControlKey:
+ case Keys.Left:
+ case Keys.LineFeed:
+ case Keys.LMenu:
+ case Keys.LShiftKey:
+ case Keys.LWin:
+ case Keys.MButton:
+ case Keys.MediaNextTrack:
+ case Keys.MediaPlayPause:
+ case Keys.MediaPreviousTrack:
+ case Keys.MediaStop:
+ case Keys.Menu:
+ case Keys.Modifiers:
+ case Keys.Multiply:
+ case Keys.Next:
+ case Keys.NoName:
+ case Keys.None:
+ case Keys.NumLock:
+ case Keys.Pa1:
+ case Keys.Packet:
+ case Keys.PageUp:
+ case Keys.Pause:
+ case Keys.Play:
+ case Keys.Print:
+ case Keys.PrintScreen:
+ case Keys.ProcessKey:
+ case Keys.RButton:
+ case Keys.RControlKey:
+ case Keys.Right:
+ case Keys.RMenu:
+ case Keys.RShiftKey:
+ case Keys.RWin:
+ case Keys.Scroll:
+ case Keys.Select:
+ case Keys.SelectMedia:
+ case Keys.Separator:
+ case Keys.Shift:
+ case Keys.ShiftKey:
+ case Keys.Sleep:
+ case Keys.Subtract:
+ case Keys.Tab:
+ case Keys.Up:
+ case Keys.VolumeDown:
+ case Keys.VolumeMute:
+ case Keys.VolumeUp:
+ case Keys.XButton1:
+ case Keys.XButton2:
+ case Keys.Zoom:
+
+ break;
+ default:
+ //Engine.AudioManager.PlayStream(Properties.Resources.typesound); // infernal beeping noise only enable for the trailers
+ break;
+ }
+ }
+ }
+
+ public TerminalBox() : base()
+ {
+ this.Tag = "keepbg keepfg keepfont";
+ }
+ }
+}