using System; using System.Collections.Generic; using System.Text; using Orvid.Graphics; using OForms.Windows; namespace Orvid.Graphics { /// /// This class is describes a single monitor, /// and also handles graphics driver wrangling. /// public class Monitor { /// /// This is the image that contains the background, /// It is the lowest on the stack that we pull pixels from. /// public Image Background; /// /// This layer holds all of the desktop icons. /// public Image DesktopIcons; /// /// This layer contains all of the windows. /// public LinkedList Windows = new LinkedList(); /// /// This image contains the taskbar. /// public Image Taskbar; /// /// This image contains the mouse. /// public Image Mouse; /// /// The current graphics driver. /// private GraphicsDriver curdriver; /// /// The current graphics driver. /// public GraphicsDriver CurrentDriver { get { return curdriver; } } /// /// This is the width of the monitor. /// public int Width; /// /// This is the height of the monitor. /// public int Height; public uint MouseX = 0; public uint MouseY = 0; public Monitor() { int width = 320; int height = 200; Background = new Image(width, height); DesktopIcons = new Image(width, height); Taskbar = new Image(width, height); Mouse = new Image(width, height); this.curdriver = new Drivers.VGADriver(); //this.curdriver.Initialize(); this.Width = width; this.Height = height; InitializeMouse(); Taskbar.Clear(1); // this should clear the screen white. CurrentDriver.Update(Taskbar); } public void Update() { DrawCursor(); //uint i = 0; //uint yPixBase = 0; //for (uint y = 0; y < Taskbar.Height; y++) //{ // yPixBase = y * 320; // for (uint x = 0; x < Taskbar.Width; x++) // { // Cosmos.System.Global.Console.WriteLine("The value at (" + x.ToString() + ", " + y.ToString() + ") is '" + Taskbar.GetPixel(x, y).ToString() + "'"); // if (i >= 24) // { // Cosmos.System.Global.Console.Y = 0; // Cosmos.System.Global.Console.X = 0; // i = 0; // } // i++; // } //} CurrentDriver.Update(GetEffectiveImage()); // Now we need to restore what was behind the mouse. Vec2 v = new Vec2((int)MouseX, (int)MouseY); Taskbar.DrawImage(v, behindMouseImage); } #region Mouse Functions /// /// This image contains everything that is behind the mouse. /// private Image behindMouseImage = new Image(4, 4); // This means max mouse size is 4x4 private Image MouseImage = new Image(4, 4); private void DrawCursor() { #region SaveBehindMouse behindMouseImage.SetPixel(0, 0, Taskbar.GetPixel(MouseX, MouseY)); behindMouseImage.SetPixel(1, 0, Taskbar.GetPixel(MouseX + 1, MouseY)); behindMouseImage.SetPixel(2, 0, Taskbar.GetPixel(MouseX + 2, MouseY)); behindMouseImage.SetPixel(3, 0, Taskbar.GetPixel(MouseX + 3, MouseY)); behindMouseImage.SetPixel(0, 1, Taskbar.GetPixel(MouseX, MouseY + 1)); behindMouseImage.SetPixel(1, 1, Taskbar.GetPixel(MouseX + 1, MouseY + 1)); behindMouseImage.SetPixel(2, 1, Taskbar.GetPixel(MouseX + 2, MouseY + 1)); behindMouseImage.SetPixel(3, 1, Taskbar.GetPixel(MouseX + 3, MouseY + 1)); behindMouseImage.SetPixel(0, 2, Taskbar.GetPixel(MouseX, MouseY + 2)); behindMouseImage.SetPixel(1, 2, Taskbar.GetPixel(MouseX + 1, MouseY + 2)); behindMouseImage.SetPixel(2, 2, Taskbar.GetPixel(MouseX + 2, MouseY + 2)); behindMouseImage.SetPixel(3, 2, Taskbar.GetPixel(MouseX + 3, MouseY + 2)); behindMouseImage.SetPixel(0, 3, Taskbar.GetPixel(MouseX, MouseY + 3)); behindMouseImage.SetPixel(1, 3, Taskbar.GetPixel(MouseX + 1, MouseY + 3)); behindMouseImage.SetPixel(2, 3, Taskbar.GetPixel(MouseX + 2, MouseY + 3)); behindMouseImage.SetPixel(3, 3, Taskbar.GetPixel(MouseX + 3, MouseY + 3)); #endregion #region Draw Mouse Vec2 v = new Vec2((int)MouseX, (int)MouseY); Taskbar.DrawImage(v, MouseImage); #endregion } private void InitializeMouse() { // Now we need to setup the mouse // The color 255 is black, and 1 is white. MouseImage.SetPixel(0, 0, 255); MouseImage.SetPixel(1, 0, 255); MouseImage.SetPixel(2, 0, 255); MouseImage.SetPixel(3, 0, 255); MouseImage.SetPixel(0, 1, 255); MouseImage.SetPixel(1, 1, 1); MouseImage.SetPixel(2, 1, 1); MouseImage.SetPixel(3, 1, 255); MouseImage.SetPixel(0, 2, 255); MouseImage.SetPixel(1, 2, 1); MouseImage.SetPixel(2, 2, 1); MouseImage.SetPixel(3, 2, 255); MouseImage.SetPixel(0, 3, 255); MouseImage.SetPixel(1, 3, 255); MouseImage.SetPixel(2, 3, 255); MouseImage.SetPixel(3, 3, 255); } #endregion public Image GetEffectiveImage() { // Image i = new Image(Width, Height); // Vec2 v = new Vec2(0,0); // i.DrawImage(v, Background); // i.DrawImage(v, DesktopIcons); //#warning TODO: Draw the windows here. // i.DrawImage(v, Taskbar); // i.DrawImage(v, Mouse); return Taskbar; } } //public class Screen //{ // // The arrays are in the format Y,X // public byte[][] Data; // public bool[][] Filled; // public Screen(int height, int width) // { // //Data = new byte[height, width]; // //Filled = new bool[height, width]; // } // public bool IsFilled(int X, int Y) // { // return Filled[Y][X]; // } //} //public class LayeredScreen //{ // LinkedList Screens = new LinkedList(); // int Height = 200; // int Width = 480; // public LayeredScreen(int height, int width) // { // this.Height = height; // this.Width = width; // Screen s = new Screen(height, width); // Screens.AddFirst(s); // } // public void SendToBack(Screen scrn) // { // Screens.Remove(scrn); // Screens.AddLast(scrn); // } // public void BringToFront(Screen scrn) // { // Screens.Remove(scrn); // Screens.AddFirst(scrn); // } // public byte[][] GetEffectiveScreen() // { // Screen scrn = new Screen(Height, Width); // LinkedList ToReturn = new LinkedList(); // bool HaveAll = false; // while (!HaveAll) // { // Screen s = Screens.First.Value; // Screens.RemoveFirst(); // for (int y = 0; y < Height; y++) // { // for (int x = 0; x < Width; x++) // { // if (!scrn.IsFilled(x, y)) // { // if (s.IsFilled(x, y)) // { // byte val = s.Data[y][x]; // scrn.Data[y][x] = val; // scrn.Filled[y][x] = true; // } // } // } // } // ToReturn.AddFirst(s); // // Check if we've run out of screens // if (Screens.Count < 1) // { // break; // } // // Otherwise we need to check if we have everything we need. // // // // TODO: Make this more efficient by only checking the lines // // we still need. // else // { // bool haveall = true; // for (int y = 0; y < Height; y++) // { // for (int x = 0; x < Width; x++) // { // if (s.Filled[y][x] == false) // { // haveall = false; // break; // } // } // if (!haveall) // { // break; // } // } // HaveAll = haveall; // } // } // // Now we need to add the screens back in. // int nmb = ToReturn.Count; // for (int i = 0; i < nmb; i++) // { // Screen scrn1 = ToReturn.First.Value; // ToReturn.RemoveFirst(); // Screens.AddFirst(scrn1); // } // return scrn.Data; // } //} }