multiple items and debug draw
This commit is contained in:
parent
5148d4a040
commit
474cf08b3c
1 changed files with 34 additions and 13 deletions
47
src/main.zig
47
src/main.zig
|
@ -12,7 +12,7 @@ pub fn main() !void {
|
|||
scales.recalculate();
|
||||
|
||||
global_font = raylib.LoadFontEx("font/SCE-PS3-RD-R-LATIN.TTF", 32, 0, 250);
|
||||
raylib.SetTextureFilter(global_font.texture, raylib.TEXTURE_FILTER_TRILINEAR);
|
||||
raylib.SetTextureFilter(global_font.texture, raylib.TEXTURE_FILTER_BILINEAR);
|
||||
|
||||
var background = Background.init();
|
||||
var column = Column.init(
|
||||
|
@ -22,12 +22,30 @@ pub fn main() !void {
|
|||
);
|
||||
defer column.deinit();
|
||||
|
||||
var item = Item.init(
|
||||
var item1 = Item.init(
|
||||
raylib.LoadTexture("menu/game/CometCrash/ICON0.PNG"),
|
||||
"Comet Crash",
|
||||
"",
|
||||
);
|
||||
try column.appendItem(&item);
|
||||
var item2 = Item.init(
|
||||
raylib.LoadTexture("menu/game/LBP1/ICON0.PNG"),
|
||||
"LittleBigPlanet",
|
||||
"",
|
||||
);
|
||||
var item3 = Item.init(
|
||||
raylib.LoadTexture("menu/game/LBP2/ICON0.PNG"),
|
||||
"LittleBigPlanet 2",
|
||||
"",
|
||||
);
|
||||
var item4 = Item.init(
|
||||
raylib.LoadTexture("menu/game/LBP3/ICON0.PNG"),
|
||||
"LittleBigPlanet 3",
|
||||
"",
|
||||
);
|
||||
try column.appendItem(&item1);
|
||||
try column.appendItem(&item2);
|
||||
try column.appendItem(&item3);
|
||||
try column.appendItem(&item4);
|
||||
|
||||
raylib.SetTargetFPS(120);
|
||||
while (!raylib.WindowShouldClose()) {
|
||||
|
@ -37,7 +55,7 @@ pub fn main() !void {
|
|||
scales.recalculate();
|
||||
}
|
||||
if (raylib.IsKeyPressed('D')) debug_draw = !debug_draw;
|
||||
if (raylib.IsKeyPressed('Z')) item.setBig(!item.large);
|
||||
if (raylib.IsKeyPressed('Z')) item1.setLarge(!item1.large);
|
||||
if (raylib.IsKeyPressed('S')) raylib.TakeScreenshot("screenshot.png");
|
||||
|
||||
raylib.BeginDrawing();
|
||||
|
@ -67,8 +85,8 @@ var scales: Scales = undefined;
|
|||
pub const Scales = struct {
|
||||
item_icon_small_width: f32,
|
||||
item_icon_small_height: f32,
|
||||
// item_icon_small_scale: f32,
|
||||
// item_icon_large_scale: f32,
|
||||
item_icon_large_width: f32,
|
||||
item_icon_large_height: f32,
|
||||
item_title_font_size: f32,
|
||||
item_subtitle_font_size: f32,
|
||||
|
||||
|
@ -76,13 +94,14 @@ pub const Scales = struct {
|
|||
column_title_font_size: f32,
|
||||
column_position_center: raylib.Vector2,
|
||||
column_position_spacing: f32,
|
||||
column_item_spacing: f32,
|
||||
|
||||
/// Recalculate scales after screen resize.
|
||||
pub fn recalculate(self: *Scales) void {
|
||||
self.item_icon_small_width = 67;
|
||||
self.item_icon_small_height = 48;
|
||||
// self.item_icon_small_scale = 0.272727;
|
||||
// self.item_icon_large_scale = 0.272727;
|
||||
self.item_icon_large_width = 67;
|
||||
self.item_icon_large_height = 48;
|
||||
self.item_title_font_size = 16;
|
||||
|
||||
self.column_icon_scale = 0.75;
|
||||
|
@ -92,6 +111,7 @@ pub const Scales = struct {
|
|||
.y = std.math.lerp(0.0, screen_height, 0.15),
|
||||
};
|
||||
self.column_position_spacing = 64;
|
||||
self.column_item_spacing = 16;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -133,11 +153,11 @@ pub const Column = struct {
|
|||
.y = icon.box.y + icon.box.h + 6,
|
||||
};
|
||||
|
||||
var y: f32 = scales.column_position_center.y + icon.box.h + title_size.y + 24;
|
||||
var y: f32 = scales.column_position_center.y + icon.box.h + title_size.y + scales.column_item_spacing;
|
||||
for (self.items.items) |item| {
|
||||
item.position = .{ .x = scales.column_position_center.x, .y = y };
|
||||
item.draw();
|
||||
y += 64;
|
||||
y += scales.item_icon_small_height + scales.column_item_spacing;
|
||||
}
|
||||
|
||||
icon.draw();
|
||||
|
@ -166,7 +186,7 @@ pub const Item = struct {
|
|||
icon: raylib.Texture2D,
|
||||
title: []const u8,
|
||||
subtitle: []const u8,
|
||||
large: bool = true,
|
||||
large: bool = false,
|
||||
|
||||
pub fn init(texture: raylib.Texture2D, title: []const u8, subtitle: []const u8) Item {
|
||||
raylib.SetTextureFilter(texture, raylib.TEXTURE_FILTER_BILINEAR);
|
||||
|
@ -207,8 +227,8 @@ pub const Item = struct {
|
|||
raylib.DrawTextEx(global_font, @ptrCast(self.title), title_position, scales.item_title_font_size, 1, raylib.WHITE);
|
||||
}
|
||||
|
||||
pub fn setBig(self: *Item, big: bool) void {
|
||||
self.large = big;
|
||||
pub fn setLarge(self: *Item, large: bool) void {
|
||||
self.large = large;
|
||||
// self.time = 0;
|
||||
// self.start_scale = self.icon_scale;
|
||||
}
|
||||
|
@ -302,6 +322,7 @@ pub const BoundingBox = struct {
|
|||
};
|
||||
|
||||
/// A texture within a bounding box. Positions and scales based on configurable parameters.
|
||||
/// Will not crop texture if using `Mode.original`.
|
||||
pub const Image = struct {
|
||||
box: BoundingBox,
|
||||
texture: raylib.Texture2D,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue