add new Photo class
This commit is contained in:
parent
8600a7e490
commit
75e186c392
28
Program.cs
28
Program.cs
@ -138,6 +138,15 @@ void main() {
|
||||
|
||||
}
|
||||
|
||||
public class Photo {
|
||||
public Texture Texture;
|
||||
|
||||
public Photo(string filename) {
|
||||
Image<Rgba32> image = Image.Load<Rgba32>(filename);
|
||||
Texture = new Texture(image);
|
||||
}
|
||||
}
|
||||
|
||||
public class Texture : IDisposable {
|
||||
public int Handle;
|
||||
public Vector2i Size;
|
||||
@ -247,8 +256,8 @@ public class Game : GameWindow {
|
||||
int VertexBufferObject;
|
||||
int ElementBufferObject;
|
||||
int VertexArrayObject;
|
||||
List<Texture> textures = new();
|
||||
int textureIndex = 0;
|
||||
List<Photo> photos = new();
|
||||
int textureIndex = 0; // FIXME: rename to photoIndex
|
||||
Shader shader = new();
|
||||
Matrix4 projection;
|
||||
|
||||
@ -268,7 +277,7 @@ public class Game : GameWindow {
|
||||
for (int i = 0; i < geometry.ThumbnailBoxes.Count; i++) {
|
||||
Box2i box = geometry.ThumbnailBoxes[i];
|
||||
if (box.ContainsInclusive((Vector2i) MouseState.Position)) {
|
||||
if (0 <= i && i < textures.Count) {
|
||||
if (0 <= i && i < photos.Count) {
|
||||
textureIndex = i;
|
||||
}
|
||||
}
|
||||
@ -287,7 +296,7 @@ public class Game : GameWindow {
|
||||
|
||||
// FIXME: make a proper Model class for tracking the state of the controls?
|
||||
if (input.IsKeyPressed(Keys.Down) || now > downTimer) {
|
||||
if (textureIndex < textures.Count - 1) {
|
||||
if (textureIndex < photos.Count - 1) {
|
||||
downTimer = now + 10000 * 200;
|
||||
textureIndex++;
|
||||
}
|
||||
@ -338,9 +347,8 @@ public class Game : GameWindow {
|
||||
string[] files = Directory.GetFiles(@"c:\users\colin\pictures\photos\2023\07\14\");
|
||||
foreach (string file in files) {
|
||||
if (file.ToLower().EndsWith(".jpg")) {
|
||||
Image<Rgba32> image = Image.Load<Rgba32>(file);
|
||||
textures.Add(new Texture(image));
|
||||
if (textures.Count > 10) {
|
||||
photos.Add(new Photo(file));
|
||||
if (photos.Count > 10) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -357,7 +365,7 @@ public class Game : GameWindow {
|
||||
GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
|
||||
GL.ActiveTexture(TextureUnit.Texture0);
|
||||
|
||||
Texture active = textures[textureIndex];
|
||||
Texture active = photos[textureIndex].Texture;
|
||||
|
||||
// FIXME: make a function for scaling & centering one box on another.
|
||||
float scaleX = 1f * geometry.PhotoBox.Size.X / active.Size.X;
|
||||
@ -368,9 +376,9 @@ public class Game : GameWindow {
|
||||
Vector2i center = (Vector2i) geometry.PhotoBox.Center;
|
||||
Box2i photoBox = Util.makeBox(center.X - renderSize.X / 2, center.Y - renderSize.Y / 2, renderSize.X, renderSize.Y);
|
||||
DrawTexture(active, photoBox);
|
||||
for (int i = 0; i < textures.Count; i++) {
|
||||
for (int i = 0; i < photos.Count; i++) {
|
||||
Box2i box = geometry.ThumbnailBoxes[i];
|
||||
DrawTexture(textures[i], box);
|
||||
DrawTexture(photos[i].Texture, box);
|
||||
if (i == textureIndex) {
|
||||
DrawBox(box, 5, Color4.Black);
|
||||
DrawBox(box, 3, Color4.White);
|
||||
|
Loading…
Reference in New Issue
Block a user