aboutsummaryrefslogtreecommitdiff
path: root/ShiftOS.Frontend/GUI
diff options
context:
space:
mode:
Diffstat (limited to 'ShiftOS.Frontend/GUI')
-rw-r--r--ShiftOS.Frontend/GUI/Button.cs15
-rw-r--r--ShiftOS.Frontend/GUI/Control.cs53
-rw-r--r--ShiftOS.Frontend/GUI/PictureBox.cs33
-rw-r--r--ShiftOS.Frontend/GUI/ProgressBar.cs7
-rw-r--r--ShiftOS.Frontend/GUI/TextControl.cs21
-rw-r--r--ShiftOS.Frontend/GUI/TextInput.cs21
6 files changed, 52 insertions, 98 deletions
diff --git a/ShiftOS.Frontend/GUI/Button.cs b/ShiftOS.Frontend/GUI/Button.cs
index 551d0d4..7d6804a 100644
--- a/ShiftOS.Frontend/GUI/Button.cs
+++ b/ShiftOS.Frontend/GUI/Button.cs
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine;
+using ShiftOS.Frontend.GraphicsSubsystem;
namespace ShiftOS.Frontend.GUI
{
@@ -31,19 +32,17 @@ namespace ShiftOS.Frontend.GUI
}
}
- protected override void OnPaint(Graphics gfx)
+ protected override void OnPaint(GraphicsContext gfx)
{
- Color bgCol = SkinEngine.LoadedSkin.ButtonBackgroundColor;
- Color fgCol = SkinEngine.LoadedSkin.ControlTextColor;
+ var bgCol = SkinEngine.LoadedSkin.ButtonBackgroundColor.ToMonoColor();
+ var fgCol = SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor();
if (ContainsMouse)
- bgCol = SkinEngine.LoadedSkin.ButtonHoverColor;
+ bgCol = SkinEngine.LoadedSkin.ButtonHoverColor.ToMonoColor();
if (MouseLeftDown)
- bgCol = SkinEngine.LoadedSkin.ButtonPressedColor;
+ bgCol = SkinEngine.LoadedSkin.ButtonPressedColor.ToMonoColor();
- gfx.Clear(bgCol);
- gfx.DrawRectangle(new Pen(new SolidBrush(fgCol), SkinEngine.LoadedSkin.ButtonBorderWidth), new Rectangle(0, 0, Width, Height));
base.OnPaint(gfx);
-
+ base.OnPaint(gfx);
}
}
}
diff --git a/ShiftOS.Frontend/GUI/Control.cs b/ShiftOS.Frontend/GUI/Control.cs
index 32afecc..31a3dd0 100644
--- a/ShiftOS.Frontend/GUI/Control.cs
+++ b/ShiftOS.Frontend/GUI/Control.cs
@@ -362,9 +362,9 @@ namespace ShiftOS.Frontend.GUI
public virtual void MouseStateChanged() { }
- protected virtual void OnPaint(Graphics gfx)
+ protected virtual void OnPaint(GraphicsContext gfx)
{
- gfx.Clear(Engine.SkinEngine.LoadedSkin.ControlColor);
+ gfx.Clear(Engine.SkinEngine.LoadedSkin.ControlColor.ToMonoColor());
}
public void InvalidateTopLevel()
@@ -375,46 +375,29 @@ namespace ShiftOS.Frontend.GUI
parent.Invalidate();
}
- public void Paint(System.Drawing.Graphics gfx)
+ public void Paint(GraphicsContext gfx)
{
if (_visible == true)
{
- if (_invalidated)
+ OnPaint(gfx);
+ int draw_x = gfx.X;
+ int draw_y = gfx.Y;
+ int draw_width = gfx.Width;
+ int draw_height = gfx.Height;
+ foreach (var ctrl in _children)
{
- _texCache = new Bitmap(Width, Height);
- using (var cGfx = Graphics.FromImage(_texCache))
+ if (ctrl.Visible == true)
{
- OnPaint(cGfx);
+ gfx.X = draw_x + ctrl.X;
+ gfx.Y = draw_y + ctrl.Y;
+ gfx.Width = ctrl.Width;
+ gfx.Height = ctrl.Height;
+ ctrl.Paint(gfx);
}
- _invalidated = false;
+ gfx.Width = draw_width;
+ gfx.Height = draw_height;
}
- foreach (var child in _children)
- {
- if (child.Visible)
- {
- if (child._invalidated)
- {
- var cBmp = new Bitmap(child.Width, child.Height);
- child.Paint(System.Drawing.Graphics.FromImage(cBmp));
- cBmp.SetOpacity((float)child.Opacity);
- using(var cGfx = Graphics.FromImage(_texCache))
- {
- cGfx.DrawImage(child.TextureCache, child.X, child.Y);
- }
- child._invalidated = false;
- child._texCache = cBmp;
- gfx.DrawImage(cBmp, new System.Drawing.Point(child.X, child.Y));
-
-
-
- }
- else
- {
- gfx.DrawImage(child._texCache, child.X, child.Y);
- }
- }
- }
- gfx.DrawImage(_texCache, 0, 0);
+ _invalidated = false;
}
}
diff --git a/ShiftOS.Frontend/GUI/PictureBox.cs b/ShiftOS.Frontend/GUI/PictureBox.cs
index 9a234d4..91735aa 100644
--- a/ShiftOS.Frontend/GUI/PictureBox.cs
+++ b/ShiftOS.Frontend/GUI/PictureBox.cs
@@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using ShiftOS.Engine;
using System.Drawing.Imaging;
+using ShiftOS.Frontend.GraphicsSubsystem;
namespace ShiftOS.Frontend.GUI
{
@@ -50,38 +51,8 @@ namespace ShiftOS.Frontend.GUI
}
}
- protected override void OnPaint(Graphics gfx)
+ protected override void OnPaint(GraphicsContext gfx)
{
- if(img != null)
- switch (_layout)
- {
- case ImageLayout.None:
- //Just draw the image.
- gfx.DrawImage(img, new PointF(0, 0));
- break;
- case ImageLayout.Stretch:
- //Stretch the image, with no regard for aspect ratio.
- var stretched = ResizeImage(img, Width, Height);
- gfx.DrawImage(stretched, 0, 0);
- break;
- case ImageLayout.Fit:
- //Resize image to fit the control but keep aspect ratio.
- var fitted = FixedSize(img, Width, Height);
- gfx.DrawImage(fitted, 0, 0);
- break;
- case ImageLayout.Tile:
- //Keep original size but tile the image.
-
- for(int x = 0; x < Width; x += img.Width)
- {
- for (int y = 0; y < Height; y += img.Height)
- {
- gfx.DrawImage(img, x, y);
- }
- }
-
- break;
- }
}
//Again, thanks StackOverflow
diff --git a/ShiftOS.Frontend/GUI/ProgressBar.cs b/ShiftOS.Frontend/GUI/ProgressBar.cs
index e35dc27..a13bbf8 100644
--- a/ShiftOS.Frontend/GUI/ProgressBar.cs
+++ b/ShiftOS.Frontend/GUI/ProgressBar.cs
@@ -4,6 +4,7 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ShiftOS.Frontend.GraphicsSubsystem;
using static ShiftOS.Engine.SkinEngine;
namespace ShiftOS.Frontend.GUI
@@ -37,11 +38,11 @@ namespace ShiftOS.Frontend.GUI
}
}
- protected override void OnPaint(Graphics gfx)
+ protected override void OnPaint(GraphicsContext gfx)
{
- gfx.Clear(LoadedSkin.ProgressBarBackgroundColor);
+ gfx.Clear(LoadedSkin.ProgressBarBackgroundColor.ToMonoColor());
int w = (int)linear(_value, 0, _maximum, 0, Width);
- gfx.FillRectangle(new SolidBrush(LoadedSkin.ProgressColor), new Rectangle(0, 0, w, Height));
+ gfx.DrawRectangle(0, 0, w, Height, LoadedSkin.ProgressColor.ToMonoColor());
}
static public double linear(double x, double x0, double x1, double y0, double y1)
diff --git a/ShiftOS.Frontend/GUI/TextControl.cs b/ShiftOS.Frontend/GUI/TextControl.cs
index 9bc70e8..f1bbef1 100644
--- a/ShiftOS.Frontend/GUI/TextControl.cs
+++ b/ShiftOS.Frontend/GUI/TextControl.cs
@@ -4,6 +4,7 @@ using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ShiftOS.Frontend.GraphicsSubsystem;
namespace ShiftOS.Frontend.GUI
{
@@ -53,19 +54,19 @@ namespace ShiftOS.Frontend.GUI
set { _textAlign = value; }
}
- protected override void OnPaint(Graphics gfx)
+ protected override void OnPaint(GraphicsContext gfx)
{
var sMeasure = gfx.MeasureString(_text, _font, Width);
PointF loc = new PointF(2, 2);
- float centerH = (Width - sMeasure.Width) / 2;
- float centerV = (Height - sMeasure.Height) / 2;
+ float centerH = (Width - sMeasure.X) / 2;
+ float centerV = (Height - sMeasure.Y) / 2;
switch (_textAlign)
{
case TextAlign.TopCenter:
loc.X = centerH;
break;
case TextAlign.TopRight:
- loc.X = Width - sMeasure.Width;
+ loc.X = Width - sMeasure.X;
break;
case TextAlign.MiddleLeft:
loc.Y = centerV;
@@ -76,23 +77,23 @@ namespace ShiftOS.Frontend.GUI
break;
case TextAlign.MiddleRight:
loc.Y = centerV;
- loc.X = (Width - sMeasure.Width);
+ loc.X = (Width - sMeasure.Y);
break;
case TextAlign.BottomLeft:
- loc.Y = (Height - sMeasure.Height);
+ loc.Y = (Height - sMeasure.Y);
break;
case TextAlign.BottomCenter:
- loc.Y = (Height - sMeasure.Height);
+ loc.Y = (Height - sMeasure.Y);
loc.X = centerH;
break;
case TextAlign.BottomRight:
- loc.Y = (Height - sMeasure.Height);
- loc.X = (Width - sMeasure.Width);
+ loc.Y = (Height - sMeasure.Y);
+ loc.X = (Width - sMeasure.X);
break;
}
- gfx.DrawString(_text, _font, new SolidBrush(Engine.SkinEngine.LoadedSkin.ControlTextColor), new RectangleF(loc.X, loc.Y, sMeasure.Width, sMeasure.Height));
+ gfx.DrawString(_text, 0, 0, Engine.SkinEngine.LoadedSkin.ControlTextColor.ToMonoColor(), _font, this.Width);
}
}
diff --git a/ShiftOS.Frontend/GUI/TextInput.cs b/ShiftOS.Frontend/GUI/TextInput.cs
index 13ee596..73954ef 100644
--- a/ShiftOS.Frontend/GUI/TextInput.cs
+++ b/ShiftOS.Frontend/GUI/TextInput.cs
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
-using System.Drawing;
+
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -15,7 +15,7 @@ namespace ShiftOS.Frontend.GUI
private string _label = "Type here!";
private string _text = "";
private int _index = 0;
- private Font _font = new Font("Tahoma", 9f);
+ private System.Drawing.Font _font = new System.Drawing.Font("Tahoma", 9f);
public int Index
{
@@ -96,7 +96,7 @@ namespace ShiftOS.Frontend.GUI
protected void CalculateVisibleText()
{
- using(var gfx = Graphics.FromImage(new Bitmap(1, 1)))
+ using(var gfx = System.Drawing.Graphics.FromImage(new System.Drawing.Bitmap(1, 1)))
{
string toCaret = _text.Substring(0, _index);
var measure = gfx.MeasureString(toCaret, _font);
@@ -115,25 +115,24 @@ namespace ShiftOS.Frontend.GUI
private float _textDrawOffset = 0;
- protected override void OnPaint(Graphics gfx)
+ protected override void OnPaint(GraphicsContext gfx)
{
- gfx.Clear(LoadedSkin.ControlColor);
- gfx.DrawString(_text, _font, new SolidBrush(LoadedSkin.ControlTextColor), 2 - _textDrawOffset, 2);
+ gfx.Clear(LoadedSkin.ControlColor.ToMonoColor());
+ gfx.DrawString(_text, 2 - (int)Math.Floor(_textDrawOffset), 2, LoadedSkin.ControlTextColor.ToMonoColor(), _font);
if (IsFocusedControl)
{
//Draw caret.
- gfx.FillRectangle(new SolidBrush(LoadedSkin.ControlTextColor), new RectangleF(caretPos - _textDrawOffset, 2, 2, Height - 4));
+
+
+ gfx.DrawRectangle((int)(Math.Floor(caretPos) - Math.Floor(_textDrawOffset)), 2, 2, Height - 4, LoadedSkin.ControlTextColor.ToMonoColor());
}
else
{
if (string.IsNullOrEmpty(_text))
{
- gfx.DrawString(_label, _font, Brushes.Gray, 2, 2);
+ gfx.DrawString(_label, 2, 2, Color.Gray, _font);
}
}
- gfx.DrawRectangle(new Pen(new SolidBrush(LoadedSkin.ControlTextColor), 1), new System.Drawing.Rectangle(0, 0, Width - 1, Height - 1));
-
-
}
}
}