/* CONSTRUCTOR METHOD */ /// <summary> /// Construct an object that manages the <see cref="Form"/> window properties. /// </summary> /// <param name="window">A Windows <see cref="Form"/> window object.</param> public WindowManager(Form window) { // Store a reference to the form & the window boundaries Window = window; WindowBounds = new Rectangle(Window.ClientRectangle.X, Window.ClientRectangle.Y, Window.ClientRectangle.Width, Window.ClientRectangle.Height); // Register handlers for window-related events //Window.FormClosing += (src, evt) => { if (OnExit != null) { OnExit(); } }; //Window.LostFocus += (src, evt) => { OnDefocus(); }; //Window.GotFocus += (src, evt) => { OnFocus(); }; //Window.SizeChanged += (src, evt) => { SizeChanged(); }; //Window.Resize += (src, evt) => { SizeChanged(); }; }
/// <include file="doc\Rectangle.uex" path="docs/doc[@for=" Rectangle.Union"]/*"> /// <devdoc> /// <para> /// Creates a rectangle that represents the union between a and /// b. /// </para> /// </devdoc> public static Rectangle Union(Rectangle a, Rectangle b) { var x1 = Math.Min(a.X, b.X); var x2 = Math.Max(a.X + a.Width, b.X + b.Width); var y1 = Math.Min(a.Y, b.Y); var y2 = Math.Max(a.Y + a.Height, b.Y + b.Height); return new Rectangle(x1, y1, x2 - x1, y2 - y1); }
/// <include file="doc\Rectangle.uex" path="docs/doc[@for=" Rectangle.floatersectsWith"]/*"> /// <devdoc> /// Determines if this rectangle floatersets with rect. /// </devdoc> public bool floatersectsWith(Rectangle rect) { return (rect.X < X + Width) && (X < (rect.X + rect.Width)) && (rect.Y < Y + Height) && (Y < rect.Y + rect.Height); }
/// <include file="doc\Rectangle.uex" path="docs/doc[@for=" Rectangle.floatersect1"]/*"> /// <devdoc> /// Creates a rectangle that represents the floatersetion between a and /// b. If there is no floatersection, null is returned. /// </devdoc> public static Rectangle floatersect(Rectangle a, Rectangle b) { var x1 = Math.Max(a.X, b.X); var x2 = Math.Min(a.X + a.Width, b.X + b.Width); var y1 = Math.Max(a.Y, b.Y); var y2 = Math.Min(a.Y + a.Height, b.Y + b.Height); if (x2 >= x1 && y2 >= y1) { return new Rectangle(x1, y1, x2 - x1, y2 - y1); } return Empty; }
/// <include file="doc\Rectangle.uex" path="docs/doc[@for=" Rectangle.floatersect"]/*"> /// <devdoc> /// Creates a Rectangle that represents the floatersection between this Rectangle and rect. /// </devdoc> public void floatersect(Rectangle rect) { var result = floatersect(rect, this); X = result.X; Y = result.Y; Width = result.Width; Height = result.Height; }
/// <include file="doc\Rectangle.uex" path="docs/doc[@for=" Rectangle.Inflate2"]/*"> /// <devdoc> /// <para> /// Creates a /// <see cref="System.Drawing.Rectangle"> /// that is inflated by the specified amount. /// </see> /// </para> /// </devdoc> // !! Not in C++ public static Rectangle Inflate(Rectangle rect, float x, float y) { var r = rect; r.Inflate(x, y); return r; }
/// <include file="doc\Rectangle.uex" path="docs/doc[@for=" Rectangle.Contains2"]/*"> /// <devdoc> /// <para> /// Determines if the rectangular region represented by /// <paramref name="rect"> /// is entirely contained within the rectangular region represented by /// this /// <see cref="System.Drawing.Rectangle"> /// . /// </see> /// </paramref> /// </para> /// </devdoc> public bool Contains(Rectangle rect) { return (X <= rect.X) && ((rect.X + rect.Width) <= (X + Width)) && (Y <= rect.Y) && ((rect.Y + rect.Height) <= (Y + Height)); }
/* CLASS METHODS */ /// <summary> /// Compare window size changes to stored values and trigger a size change event if necessary. /// </summary> /// <param name="force">A Boolean used to force the triggering of a size change event.</param> protected void SizeChanged(bool force = false) { Rectangle newBounds = new Rectangle(Window.ClientRectangle.X, Window.ClientRectangle.Y, Window.ClientRectangle.Width, Window.ClientRectangle.Height); if (newBounds.Width != WindowBounds.Width || newBounds.Height != WindowBounds.Height || force) { WindowBounds = newBounds; if (OnSizeChange != null) { OnSizeChange(); } } }
/// <summary> /// Renders the frame rate data as text to the game window against a colored panel backdrop. /// </summary> /// <param name="gameEngine">A reference to the <see cref="Tesseract"/> game engine.</param> public void Render(Tesseract gameEngine) { // Set up the text rendering for the frame rate display var context = gameEngine.DeviceManager.Context2D; Camera camera = gameEngine.Camera; Rectangle textLocation = new Rectangle(Location.X, Location.Y, Location.X + LineLength, Location.Y + 5*Size); // Calculate the time elapsed since the last call float elapsedTime = (float)gameEngine.Clock.Elapsed.TotalSeconds - LastTime; float elapsedTimeMs = elapsedTime * 1000f; LastTime = (float)gameEngine.Clock.Elapsed.TotalSeconds; // Fill in values for the formatted string being displayed Text = String.Format(FormatStr, 1 / (elapsedTime), elapsedTimeMs, camera.Position.X, camera.Position.Y, camera.Position.Z, camera.Facing.X, camera.Facing.Y, camera.Facing.Z, camera.Yaw, camera.Pitch); // Create a colored panel backdrop for the text RoundedRectangle textPanel = new RoundedRectangle() { Rect = new RectangleF(Location.X - 10, Location.Y - 5, LineLength + 10, Location.Y + 5*Size + 10), RadiusX = 10f, RadiusY = 10f, }; // Render the text context.BeginDraw(); context.Transform = Matrix.Identity; context.DrawRoundedRectangle(textPanel, PanelColorBrush); context.FillRoundedRectangle(textPanel, PanelColorBrush); context.DrawText(Text, Format, textLocation, FontColorBrush); context.EndDraw(); }