public static Rectangle FRectToRect(FRect r) { int width = ((int)(r.width / 2f) * Screen.Width); int height = ((int)(r.height / 2f) * Screen.Height); int x = ((int)(r.left / 2f) * Screen.Width); int y = ((int)(((1f - r.top)) / 2f) * Screen.Height); return(new Rectangle()); }
/// <summary> /// Converts a rectangle with integer values coresponding to the Window width and Height in pixels /// to an aspect ratio adjusted Screen Cooridnate that can be used with OpenGL /// </summary> /// <param name="r"> Rectangle in pixel coordinates </param> /// <returns> Screen Coordinate FRect adjusted to the aspect ratio </returns> public static FRect RectToFRect(Rectangle r) { float width = ((float)r.Width / (float)Program.mainWindow.Width) * 2f; float height = (((float)r.Height / (float)Program.mainWindow.Height) * 2f); float left = (((float)r.X / (float)Screen.Width) * 2f) - 1f; float top = ((1f - ((float)r.Y / (float)Screen.Height) * 2f) - height); FRect rect = new FRect(left, top, width, height, false); return(rect); }
public static bool FisMouseInRect(FRect rect) { float x = FmouseX(); float y = FmouseY(); FRect r = !rect.shouldAdjustToAspect ? Coordinates.RemoveAspect(rect) : rect; if (x > r.left && x < r.left + r.width && y > r.top && y < r.top + r.height) { return(true); } return(false); }
public static void DrawString(Vector2 pos, float size, string s, Color c) { float x = pos.X; for (int i = 0; i < s.Length; i++) { FRect UV = GetUVForChar(s[i]); float w = UV.width * size; float h = UV.height * size; Renderer.DrawTexture(new FRect(x, pos.Y, w, h), fullAtlas, UV, c); x += w; } }
public static FRect DrawStringR(Vector2 pos, float size, string s, Color c) { float x = pos.X; for (int i = 0; i < s.Length; i++) { FRect UV = GetUVForChar(s[i]); float w = UV.width * size; float h = UV.height * size * 2; Renderer.DrawTexture(new FRect(x, pos.Y, w, h), fullAtlas, UV, c); x += w; } return(new FRect(pos.X, pos.Y, x - pos.X, (1f / 16f) * size * 2f)); }
//draws a rectangle with two triangles because apparently quads were deprecated or something i dont know. public static void drawRect(FRect rect, Color c) { FRect r = rect.shouldAdjustToAspect ? Coordinates.ApplyAspect(rect) : rect; GL.Begin(PrimitiveType.Triangles); GL.Color3(c); GL.Vertex2(new Vector2(r.left, r.top)); GL.Vertex2(new Vector2(r.left + r.width, r.top + r.height)); GL.Vertex2(new Vector2(r.left, r.top + r.height)); GL.Vertex2(new Vector2(r.left, r.top)); GL.Vertex2(new Vector2(r.left + r.width, r.top)); GL.Vertex2(new Vector2(r.left + r.width, r.top + r.height)); GL.Color3(Color.White); GL.End(); }
public static void DrawTexture(FRect position, Texture2D tex, FRect UV, Color color) { Vector2[] points = Coordinates.ApplyAspect(position).GetCorners(); Vector2[] texCoords = { UV.GetCorner(3), UV.GetCorner(2), UV.GetCorner(1), UV.GetCorner(0) }; GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.BindTexture(TextureTarget.Texture2D, tex.id); GL.Enable(EnableCap.Texture2D); GL.Begin(PrimitiveType.Triangles); GL.Color3(color); GL.TexCoord2(texCoords[0]); GL.Vertex2(points[0]); GL.TexCoord2(texCoords[1]); GL.Vertex2(points[1]); GL.TexCoord2(texCoords[2]); GL.Vertex2(points[2]); GL.TexCoord2(texCoords[0]); GL.Vertex2(points[0]); GL.TexCoord2(texCoords[2]); GL.Vertex2(points[2]); GL.TexCoord2(texCoords[3]); GL.Vertex2(points[3]); GL.Color3(Color.White); GL.End(); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Texture2D); }
public static bool isMouseInRect(Rectangle rectangle) { FRect r = Coordinates.RectToFRect(rectangle); return(FisMouseInRect(r)); }
public static FRect RemoveAspect(FRect rect) { return(new FRect(rect.left / aspectX, rect.top, rect.width / aspectX, rect.height)); }
/// <summary> /// Takes a Screen Coordinate FRect and adjusts its x position and width to remain consistant /// </summary> /// <param name="rect"></param> /// <returns></returns> public static FRect ApplyAspect(FRect rect) { return(new FRect(rect.left * aspectX, rect.top, rect.width * aspectX, rect.height)); }
public void Render() { int mouseX = IM.MouseX(); int mouseY = IM.MouseY(); Renderer.drawRect(new FRect(-1f, -1f, 2f, 2f, false), backgroundColor); Renderer.drawLine(screenBoundPoints, Color.Black); Renderer.drawLine(screenBound2Points, Color.Black); Rectangle rt = new Rectangle(100, 100, 200, 50); FRect fr = Coordinates.RectToFRect(rt); FRect r = fr.shouldAdjustToAspect ? Coordinates.ApplyAspect(fr) : fr; Renderer.LineCircle(new Vector2(r.left, r.top), 0.01f, 10, Color.BlueViolet); //FlatUI.GUI.OutlineBox(Text.DrawStringR(new Vector2(-0.5f, 0f), 0.5f, "Make a good rect for me here! ♥", Color.Crimson)); if (FlatUI.button(rt, "test button")) { Random ra = new Random(); backgroundColor = Color.FromArgb(ra.Next(0, 255), ra.Next(0, 255), ra.Next(0, 255)); } Text.DrawString(new Vector2(-0.3f, -0.5f), 0.5f, "Hello this is a test"); Text.DrawString(new Vector2(-0.3f, -0.6f), 0.5f, "Please work as intended"); Text.DrawString(new Vector2(-0.3f, 0.6f), 0.5f, "Mouse Left: " + IM.GetMouseButton(MouseButton.Left).ToString()); Text.DrawString(new Vector2(-0.3f, 0.7f), 0.5f, "Mouse Left Down: " + IM.MouseButtonDown(MouseButton.Left).ToString()); Text.DrawString(new Vector2(-0.3f, 0.8f), 0.5f, "Mouse Left Up: " + IM.MouseButtonUp(MouseButton.Left).ToString()); Text.DrawString(IM.FmouseVec(), 0.5f, "(" + Math.Round(IM.FmouseX(), 2).ToString() + "," + Math.Round(IM.FmouseY(), 2).ToString() + ")"); if (stampLetter.stamps.Count > 0) { foreach (stampLetter s in stampLetter.stamps) { Text.DrawString(s.pos, 0.05f, s.value.ToString()); } } Color c = Color.Black; if (IM.GetMouseButton(MouseButton.Left)) { c = Color.Red; } else { foreach (Line l in d.getLines()) { foreach (Spline s in l.splines) { if (IM.FisMouseInRect(new FRect(s.position, 0.04f)) || IM.FisMouseInRect(new FRect(s.leftPos, 0.04f)) || IM.FisMouseInRect(new FRect(s.rightPos, 0.04f))) { c = Color.Magenta; } } } } Renderer.LineCircle(IM.FmouseVec(), 0.004f, 20, c); if (!hide) { Line[] array = d.getLines(); for (int i = 0; i < array.Length; i++) { Line l = array[i]; if (i == lineIndex) { foreach (Spline s in l.splines) { Renderer.drawSpline(s, Color.Black); } } else { foreach (Spline s in l.splines) { Renderer.drawSpline(s, Color.Gray); } } } } foreach (Line l in d.getLines()) { Renderer.drawLineCurve(l, 40, Color.Black); } }