Compare commits

..

2 Commits

Author SHA1 Message Date
e98b19d87b make DrawTexture(texture, x, y) function 2023-07-26 13:49:48 -04:00
7ce97438ae add stars to the thumbnail view 2023-07-26 13:10:19 -04:00

View File

@ -518,7 +518,10 @@ public static class Util {
} }
public static Texture RenderStar(float radius, bool filled) { public static Texture RenderStar(float radius, bool filled) {
IPath path = new Star(x: radius, y: radius, prongs: 5, innerRadii: radius * 0.4f, outerRadii: radius, angle: Util.PI); IPath path = new Star(x: radius, y: radius, prongs: 5, innerRadii: radius * 0.45f, 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...
Image<Rgba32> image = MakeImage(path.Bounds.Width + 2, path.Bounds.Height + 2); Image<Rgba32> image = MakeImage(path.Bounds.Width + 2, path.Bounds.Height + 2);
IBrush brush = Brushes.Solid(Color.White); IBrush brush = Brushes.Solid(Color.White);
IPen pen = Pens.Solid(Color.White, 1.5f); IPen pen = Pens.Solid(Color.White, 1.5f);
@ -538,7 +541,8 @@ public class Game : GameWindow {
private static Texture TEXTURE_WHITE = new(new Image<Rgba32>(1, 1, new Rgba32(255, 255, 255))); private static Texture TEXTURE_WHITE = new(new Image<Rgba32>(1, 1, new Rgba32(255, 255, 255)));
private static Texture TEXTURE_BLACK = new(new Image<Rgba32>(1, 1, new Rgba32(0, 0, 0))); private static Texture TEXTURE_BLACK = new(new Image<Rgba32>(1, 1, new Rgba32(0, 0, 0)));
private static Texture STAR_FILLED = Util.RenderStar(20, true); private static Texture STAR_FILLED = Util.RenderStar(20, true);
private static Texture STAR_EMPTY= Util.RenderStar(20, false); private static Texture STAR_EMPTY = Util.RenderStar(20, false);
private static Texture STAR_SMALL = Util.RenderStar(6, true);
UiGeometry geometry = new(); UiGeometry geometry = new();
FpsCounter fpsCounter = new(); FpsCounter fpsCounter = new();
@ -794,7 +798,7 @@ public class Game : GameWindow {
DrawTexture(active, photoBox); DrawTexture(active, photoBox);
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY; Texture star = (activePhoto.Rating > i) ? STAR_FILLED : STAR_EMPTY;
DrawTexture(star, Util.MakeBox((star.Size.X + 10) * i + 10, 10, star.Size.X, star.Size.Y)); DrawTexture(star, (star.Size.X + 10) * i + 10, 10);
} }
// Draw thumbnail boxes. // Draw thumbnail boxes.
@ -804,8 +808,12 @@ public class Game : GameWindow {
if (ribbonIndex + i >= photos.Count) { if (ribbonIndex + i >= photos.Count) {
break; break;
} }
Photo photo = photos[ribbonIndex + i];
Box2i box = geometry.ThumbnailBoxes[i]; Box2i box = geometry.ThumbnailBoxes[i];
DrawTexture(photos[ribbonIndex + i].Texture(), box); DrawTexture(photo.Texture(), box);
for (int j = 0; j < photo.Rating; j++) {
DrawTexture(STAR_SMALL, box.Min.X + 8 + ((STAR_SMALL.Size.X + 2) * j), box.Min.Y + 8);
}
if (ribbonIndex + i == photoIndex) { if (ribbonIndex + i == photoIndex) {
DrawBox(box, 5, Color4.Black); DrawBox(box, 5, Color4.Black);
DrawBox(box, 3, Color4.White); DrawBox(box, 3, Color4.White);
@ -825,6 +833,10 @@ public class Game : GameWindow {
SwapBuffers(); SwapBuffers();
} }
void DrawTexture(Texture texture, int x, int y) {
DrawTexture(texture, Util.MakeBox(x, y, texture.Size.X, texture.Size.Y));
}
void DrawTexture(Texture texture, Box2i box) { void DrawTexture(Texture texture, Box2i box) {
DrawTexture(texture, box, Color4.White); DrawTexture(texture, box, Color4.White);
} }
@ -850,7 +862,7 @@ public class Game : GameWindow {
void DrawText(string text, int x, int y) { void DrawText(string text, int x, int y) {
Texture label = Util.RenderText(text); Texture label = Util.RenderText(text);
DrawTexture(label, Util.MakeBox(x, y, label.Size.X, label.Size.Y)); DrawTexture(label, x, y);
label.Dispose(); label.Dispose();
} }