use Box2i instead of Rectangle

This commit is contained in:
Colin McMillen 2023-07-06 23:48:12 -04:00
parent c7bb0deb0c
commit 5b135bc889

View File

@ -288,6 +288,10 @@ public class Game : GameWindow {
base.OnUnload(); base.OnUnload();
} }
private static Box2i makeBox(int left, int top, int width, int height) {
return new Box2i(left, top, left + width, top + height);
}
protected override void OnRenderFrame(FrameEventArgs e) { protected override void OnRenderFrame(FrameEventArgs e) {
base.OnRenderFrame(e); base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit); GL.Clear(ClearBufferMask.ColorBufferBit);
@ -302,9 +306,9 @@ public class Game : GameWindow {
int photoWidth = (int) (1.0 * windowHeight / active.Height * active.Width); int photoWidth = (int) (1.0 * windowHeight / active.Height * active.Width);
int letterboxWidth = (maxPhotoWidth - photoWidth) / 2; int letterboxWidth = (maxPhotoWidth - photoWidth) / 2;
DrawTexture(active, new Rectangle(letterboxWidth, 0, photoWidth, windowHeight)); DrawTexture(active, makeBox(letterboxWidth, 0, photoWidth, windowHeight));
for (int i = 0; i < textures.Count; i++) { for (int i = 0; i < textures.Count; i++) {
Rectangle box = new Rectangle(windowWidth - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight); Box2i box = makeBox(windowWidth - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight);
DrawTexture(textures[i], box); DrawTexture(textures[i], box);
if (i == textureIndex) { if (i == textureIndex) {
DrawBox(box, 3, Color4.GreenYellow); DrawBox(box, 3, Color4.GreenYellow);
@ -314,23 +318,23 @@ public class Game : GameWindow {
SwapBuffers(); SwapBuffers();
} }
void DrawTexture(Texture texture, Rectangle box) { void DrawTexture(Texture texture, Box2i box) {
DrawTexture(texture, box, Color4.White); DrawTexture(texture, box, Color4.White);
} }
void DrawTexture(Texture texture, Rectangle box, Color4 color) { void DrawTexture(Texture texture, Box2i box, Color4 color) {
GL.Uniform4(shader.GetUniformLocation("color"), color.R, color.G, color.B, color.A); GL.Uniform4(shader.GetUniformLocation("color"), color.R, color.G, color.B, color.A);
SetVertices(box.Left, box.Top, box.Width, box.Height); SetVertices(box.Min.X, box.Min.Y, box.Size.X, box.Size.Y);
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw); GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
GL.BindTexture(TextureTarget.Texture2D, texture.Handle); GL.BindTexture(TextureTarget.Texture2D, texture.Handle);
GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0); GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
} }
void DrawBox(Rectangle box, int thickness, Color4 color) { void DrawBox(Box2i box, int thickness, Color4 color) {
DrawTexture(TEXTURE_WHITE, new Rectangle(box.Left, box.Top, box.Width, thickness), color); DrawTexture(TEXTURE_WHITE, makeBox(box.Min.X, box.Min.Y, box.Size.X, thickness), color);
DrawTexture(TEXTURE_WHITE, new Rectangle(box.Left, box.Top, thickness, box.Height), color); DrawTexture(TEXTURE_WHITE, makeBox(box.Min.X, box.Min.Y, thickness, box.Size.Y), color);
DrawTexture(TEXTURE_WHITE, new Rectangle(box.Left, box.Top + box.Height - thickness, box.Width, thickness), color); DrawTexture(TEXTURE_WHITE, makeBox(box.Min.X, box.Max.Y - thickness, box.Size.X, thickness), color);
DrawTexture(TEXTURE_WHITE, new Rectangle(box.Left + box.Width - thickness, box.Top, thickness, box.Height), color); DrawTexture(TEXTURE_WHITE, makeBox(box.Max.X - thickness, box.Min.Y, thickness, box.Size.Y), color);
} }
protected override void OnResize(ResizeEventArgs e) { protected override void OnResize(ResizeEventArgs e) {