wrap long columns to 100 characters
This commit is contained in:
parent
3d507f3794
commit
c77183915b
79
Program.cs
79
Program.cs
@ -228,20 +228,26 @@ public class UiGeometry {
|
||||
|
||||
Console.WriteLine($"thumbnail size: {thumbnailWidth} x {thumbnailHeight}");
|
||||
for (int i = 0; i < numThumbnails; i++) {
|
||||
Box2i box = Util.MakeBox(WindowSize.X - thumbnailWidth, i * thumbnailHeight, thumbnailWidth, thumbnailHeight);
|
||||
Box2i box = Util.MakeBox(WindowSize.X - thumbnailWidth, i * thumbnailHeight,
|
||||
thumbnailWidth, thumbnailHeight);
|
||||
ThumbnailBoxes.Add(box);
|
||||
}
|
||||
|
||||
int statusBoxHeight = 40;
|
||||
int statusBoxPadding = 4;
|
||||
PhotoBox = new Box2i(0, 0, WindowSize.X - thumbnailWidth, WindowSize.Y - statusBoxHeight - statusBoxPadding);
|
||||
StatusBox = new Box2i(0, WindowSize.Y - statusBoxHeight, WindowSize.X - thumbnailWidth, WindowSize.Y);
|
||||
ThumbnailBox = new Box2i(ThumbnailBoxes[0].Min.X, ThumbnailBoxes[0].Min.Y, WindowSize.X, WindowSize.Y);
|
||||
PhotoBox = new Box2i(
|
||||
0, 0, WindowSize.X - thumbnailWidth, WindowSize.Y - statusBoxHeight - statusBoxPadding);
|
||||
StatusBox = new Box2i(
|
||||
0, WindowSize.Y - statusBoxHeight, WindowSize.X - thumbnailWidth, WindowSize.Y);
|
||||
ThumbnailBox = new Box2i(
|
||||
ThumbnailBoxes[0].Min.X, ThumbnailBoxes[0].Min.Y, WindowSize.X, WindowSize.Y);
|
||||
|
||||
int starSpacing = 10;
|
||||
int starBoxLeft = (int) (PhotoBox.Center.X - 2.5 * starSize - starSpacing * 2);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Box2i box = Util.MakeBox(starBoxLeft + i * (starSize + starSpacing), PhotoBox.Max.Y - starSize - 10, starSize, starSize);
|
||||
Box2i box = Util.MakeBox(
|
||||
starBoxLeft + i * (starSize + starSpacing), PhotoBox.Max.Y - starSize - 10,
|
||||
starSize, starSize);
|
||||
StarBoxes.Add(box);
|
||||
}
|
||||
}
|
||||
@ -321,7 +327,8 @@ public static class Util {
|
||||
}
|
||||
|
||||
public static Texture RenderStar(float radius, bool filled) {
|
||||
IPath path = new Star(x: radius, y: radius + 1, prongs: 5, innerRadii: radius * 0.4f, outerRadii: radius, angle: Util.PI);
|
||||
IPath path = new Star(x: radius, y: radius + 1, prongs: 5,
|
||||
innerRadii: radius * 0.4f, outerRadii: radius, angle: Util.PI);
|
||||
// We add a little bit to the width & height because the reported
|
||||
// path.Bounds are often a little tighter than they should be & a couple
|
||||
// pixels end up obviously missing...
|
||||
@ -342,7 +349,8 @@ public static class Util {
|
||||
|
||||
|
||||
public class Game : GameWindow {
|
||||
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) : base(gwSettings, nwSettings) {
|
||||
public Game(GameWindowSettings gwSettings, NativeWindowSettings nwSettings) :
|
||||
base(gwSettings, nwSettings) {
|
||||
activeTool = viewTool;
|
||||
}
|
||||
|
||||
@ -478,7 +486,8 @@ public class Game : GameWindow {
|
||||
|
||||
// Handle presses of the "rating" keys -- 0-5 and `.
|
||||
// A normal press just sets the rating of the current photo.
|
||||
// If the user is holding "shift", we instead filter to only show photos of that rating or higher.
|
||||
// If the user is holding "shift", we instead filter to only show photos
|
||||
// of that rating or higher.
|
||||
int rating = -1;
|
||||
|
||||
if (input.IsKeyPressed(Keys.D0) || input.IsKeyPressed(Keys.GraveAccent)) {
|
||||
@ -597,9 +606,11 @@ public class Game : GameWindow {
|
||||
ElementBufferObject = GL.GenBuffer();
|
||||
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.DynamicDraw);
|
||||
GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float),
|
||||
vertices, BufferUsageHint.DynamicDraw);
|
||||
GL.BindBuffer(BufferTarget.ElementArrayBuffer, ElementBufferObject);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint), indices, BufferUsageHint.DynamicDraw);
|
||||
GL.BufferData(BufferTarget.ElementArrayBuffer, indices.Length * sizeof(uint),
|
||||
indices, BufferUsageHint.DynamicDraw);
|
||||
|
||||
shader.Init();
|
||||
shader.Use();
|
||||
@ -609,14 +620,16 @@ public class Game : GameWindow {
|
||||
// This will now pass the new vertex array to the buffer.
|
||||
var vertexLocation = shader.GetAttribLocation("aPosition");
|
||||
GL.EnableVertexAttribArray(vertexLocation);
|
||||
GL.VertexAttribPointer(vertexLocation, 3, VertexAttribPointerType.Float, false, 5 * sizeof(float), 0);
|
||||
GL.VertexAttribPointer(vertexLocation, 3, VertexAttribPointerType.Float,
|
||||
false, 5 * sizeof(float), 0);
|
||||
|
||||
// Next, we also setup texture coordinates. It works in much the same way.
|
||||
// We add an offset of 3, since the texture coordinates comes after the position data.
|
||||
// We also change the amount of data to 2 because there's only 2 floats for texture coordinates.
|
||||
var texCoordLocation = shader.GetAttribLocation("aTexCoord");
|
||||
GL.EnableVertexAttribArray(texCoordLocation);
|
||||
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float, false, 5 * sizeof(float), 3 * sizeof(float));
|
||||
GL.VertexAttribPointer(texCoordLocation, 2, VertexAttribPointerType.Float,
|
||||
false, 5 * sizeof(float), 3 * sizeof(float));
|
||||
|
||||
// Load photos from a directory.
|
||||
string[] files = Directory.GetFiles(@"c:\users\colin\desktop\photos-test\");
|
||||
@ -668,8 +681,10 @@ public class Game : GameWindow {
|
||||
}
|
||||
}
|
||||
if (earliest != null) {
|
||||
Console.WriteLine($"loadedImages.Count: {loadedImages.Count}, evicting {earliest.Filename} @ {earliestTime}");
|
||||
// TODO: we have to free textures on the GL thread, but could we do that async'ly to keep the UI responsive?
|
||||
Console.WriteLine($"loadedImages.Count: {loadedImages.Count}, " +
|
||||
$"evicting {earliest.Filename} @ {earliestTime}");
|
||||
// TODO: we have to free textures on the GL thread, but could we do
|
||||
// that async'ly to keep the UI responsive?
|
||||
earliest.Unload();
|
||||
loadedImages.Remove(earliest);
|
||||
}
|
||||
@ -789,7 +804,8 @@ public class Game : GameWindow {
|
||||
DrawFilledBox(geometry.StatusBox, Color4.Black);
|
||||
// First line.
|
||||
int y = geometry.StatusBox.Min.Y + statusPadding;
|
||||
DrawText(String.Format("{0,4}/{1,-4}", photoIndex + 1, photos.Count), geometry.StatusBox.Min.X, y);
|
||||
DrawText(String.Format("{0,4}/{1,-4}", photoIndex + 1, photos.Count),
|
||||
geometry.StatusBox.Min.X, y);
|
||||
DrawText(activePhoto.Description(), geometry.StatusBox.Min.X + 88, y);
|
||||
|
||||
// Second line.
|
||||
@ -807,15 +823,18 @@ public class Game : GameWindow {
|
||||
return;
|
||||
}
|
||||
|
||||
Vector2i leftTop = transform.ImageToScreen(activePhoto.CropRectangle.Left, activePhoto.CropRectangle.Top);
|
||||
Vector2i rightBottom = transform.ImageToScreen(activePhoto.CropRectangle.Right, activePhoto.CropRectangle.Bottom);
|
||||
Vector2i leftTop = transform.ImageToScreen(activePhoto.CropRectangle.Left,
|
||||
activePhoto.CropRectangle.Top);
|
||||
Vector2i rightBottom = transform.ImageToScreen(activePhoto.CropRectangle.Right,
|
||||
activePhoto.CropRectangle.Bottom);
|
||||
var (left, top) = leftTop;
|
||||
var (right, bottom) = rightBottom;
|
||||
|
||||
Color4 shadeColor = new Color4(0, 0, 0, 0.75f);
|
||||
DrawFilledBox(new Box2i(0, 0, left, geometry.PhotoBox.Max.Y), shadeColor);
|
||||
DrawFilledBox(new Box2i(left, 0, geometry.PhotoBox.Max.X, top), shadeColor);
|
||||
DrawFilledBox(new Box2i(left, bottom, geometry.PhotoBox.Max.X, geometry.PhotoBox.Max.Y), shadeColor);
|
||||
DrawFilledBox(new Box2i(left, bottom, geometry.PhotoBox.Max.X, geometry.PhotoBox.Max.Y),
|
||||
shadeColor);
|
||||
DrawFilledBox(new Box2i(right, top, geometry.PhotoBox.Max.X, bottom), shadeColor);
|
||||
DrawBox(new Box2i(left - 1, top - 1, right + 1, bottom + 1), 1, Color4.White);
|
||||
if (active) {
|
||||
@ -837,7 +856,8 @@ public class Game : GameWindow {
|
||||
public void DrawTexture(Texture texture, Box2i box, Color4 color) {
|
||||
GL.Uniform4(shader.GetUniformLocation("color"), color);
|
||||
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.DrawElements(PrimitiveType.Triangles, indices.Length, DrawElementsType.UnsignedInt, 0);
|
||||
}
|
||||
@ -851,10 +871,14 @@ public class Game : GameWindow {
|
||||
}
|
||||
|
||||
public void DrawBox(Box2i box, int thickness, Color4 color) {
|
||||
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Min.X, box.Min.Y, box.Size.X, thickness), color);
|
||||
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Min.X, box.Min.Y, thickness, box.Size.Y), color);
|
||||
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Min.X, box.Max.Y - thickness, box.Size.X, thickness), color);
|
||||
DrawTexture(TEXTURE_WHITE, Util.MakeBox(box.Max.X - thickness, box.Min.Y, thickness, box.Size.Y), color);
|
||||
DrawTexture(TEXTURE_WHITE,
|
||||
Util.MakeBox(box.Min.X, box.Min.Y, box.Size.X, thickness), color);
|
||||
DrawTexture(TEXTURE_WHITE,
|
||||
Util.MakeBox(box.Min.X, box.Min.Y, thickness, box.Size.Y), color);
|
||||
DrawTexture(TEXTURE_WHITE,
|
||||
Util.MakeBox(box.Min.X, box.Max.Y - thickness, box.Size.X, thickness), color);
|
||||
DrawTexture(TEXTURE_WHITE,
|
||||
Util.MakeBox(box.Max.X - thickness, box.Min.Y, thickness, box.Size.Y), color);
|
||||
}
|
||||
|
||||
public void DrawFilledBox(Box2i box, Color4 color) {
|
||||
@ -923,7 +947,8 @@ static class Program {
|
||||
bestMonitor = monitor;
|
||||
}
|
||||
}
|
||||
Console.WriteLine($"best monitor: {bestMonitor.HorizontalResolution}x{bestMonitor.VerticalResolution}");
|
||||
Console.WriteLine(
|
||||
$"best monitor: {bestMonitor.HorizontalResolution}x{bestMonitor.VerticalResolution}");
|
||||
GameWindowSettings gwSettings = new();
|
||||
gwSettings.UpdateFrequency = 30.0;
|
||||
gwSettings.RenderFrequency = 30.0;
|
||||
@ -931,8 +956,10 @@ static class Program {
|
||||
NativeWindowSettings nwSettings = new();
|
||||
nwSettings.WindowState = WindowState.Normal;
|
||||
nwSettings.CurrentMonitor = bestMonitor.Handle;
|
||||
nwSettings.Location = new Vector2i(bestMonitor.WorkArea.Min.X + 1, bestMonitor.WorkArea.Min.Y + 31);
|
||||
// nwSettings.Size = new Vector2i(bestMonitor.WorkArea.Size.X - 2, bestMonitor.WorkArea.Size.Y - 32);
|
||||
nwSettings.Location = new Vector2i(bestMonitor.WorkArea.Min.X + 1,
|
||||
bestMonitor.WorkArea.Min.Y + 31);
|
||||
// nwSettings.Size = new Vector2i(bestMonitor.WorkArea.Size.X - 2,
|
||||
// bestMonitor.WorkArea.Size.Y - 32);
|
||||
nwSettings.Size = new Vector2i(1600, 900);
|
||||
nwSettings.MinimumSize = UiGeometry.MIN_WINDOW_SIZE;
|
||||
nwSettings.Title = "Totte";
|
||||
|
Loading…
Reference in New Issue
Block a user