Browse Source

use Box2i instead of Rectangle

main
Colin McMillen 1 year ago
parent
commit
5b135bc889
  1. 24
      Program.cs

24
Program.cs

@ -288,6 +288,10 @@ public class Game : GameWindow {
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) {
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit);
@ -302,9 +306,9 @@ public class Game : GameWindow {
int photoWidth = (int) (1.0 * windowHeight / active.Height * active.Width);
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++) {
Rectangle box = new Rectangle(windowWidth - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight);
Box2i box = makeBox(windowWidth - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight);
DrawTexture(textures[i], box);
if (i == textureIndex) {
DrawBox(box, 3, Color4.GreenYellow);
@ -314,23 +318,23 @@ public class Game : GameWindow {
SwapBuffers();
}
void DrawTexture(Texture texture, Rectangle box) {
void DrawTexture(Texture texture, Box2i box) {
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);
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.BindTexture(TextureTarget.Texture2D, texture.Handle);
GL.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
}
void DrawBox(Rectangle box, int thickness, Color4 color) {
DrawTexture(TEXTURE_WHITE, new Rectangle(box.Left, box.Top, box.Width, thickness), color);
DrawTexture(TEXTURE_WHITE, new Rectangle(box.Left, box.Top, thickness, box.Height), color);
DrawTexture(TEXTURE_WHITE, new Rectangle(box.Left, box.Top + box.Height - thickness, box.Width, thickness), color);
DrawTexture(TEXTURE_WHITE, new Rectangle(box.Left + box.Width - thickness, box.Top, thickness, box.Height), color);
void DrawBox(Box2i box, int thickness, Color4 color) {
DrawTexture(TEXTURE_WHITE, makeBox(box.Min.X, box.Min.Y, box.Size.X, thickness), color);
DrawTexture(TEXTURE_WHITE, makeBox(box.Min.X, box.Min.Y, thickness, box.Size.Y), color);
DrawTexture(TEXTURE_WHITE, makeBox(box.Min.X, box.Max.Y - thickness, box.Size.X, thickness), color);
DrawTexture(TEXTURE_WHITE, makeBox(box.Max.X - thickness, box.Min.Y, thickness, box.Size.Y), color);
}
protected override void OnResize(ResizeEventArgs e) {

Loading…
Cancel
Save