improve debug draw
This commit is contained in:
parent
7b73c7c18e
commit
e70efe55fa
1 changed files with 66 additions and 23 deletions
89
src/main.zig
89
src/main.zig
|
@ -71,18 +71,20 @@ pub fn main() !void {
|
||||||
background.draw();
|
background.draw();
|
||||||
column.draw();
|
column.draw();
|
||||||
|
|
||||||
raylib.DrawFPS(1, 1);
|
if (debug_draw) {
|
||||||
|
drawDebugGrid();
|
||||||
|
|
||||||
const debug_text = try std.fmt.allocPrint(allocator,
|
const debug_text = try std.fmt.allocPrint(allocator,
|
||||||
\\screen size = {d}x{d}
|
\\screen size = {d}x{d}
|
||||||
\\selected = {d}
|
\\selected = {d}
|
||||||
, .{
|
, .{
|
||||||
screen_width,
|
screen_width,
|
||||||
screen_height,
|
screen_height,
|
||||||
column.selected,
|
column.selected,
|
||||||
});
|
});
|
||||||
defer allocator.free(debug_text);
|
defer allocator.free(debug_text);
|
||||||
raylib.DrawText(@ptrCast(debug_text), 80, 2, 8, raylib.GREEN);
|
raylib.DrawText(@ptrCast(debug_text), 2, 2, 8, raylib.GREEN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +186,44 @@ pub const Scales = struct {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var debug_colors: DebugColors = .{};
|
||||||
|
|
||||||
|
pub const DebugColors = struct {
|
||||||
|
screen_grid_color: raylib.Color = .{ .r = 200, .g = 220, .b = 200, .a = 32 },
|
||||||
|
screen_text_color: raylib.Color = .{ .r = 255, .g = 255, .b = 255, .a = 90 },
|
||||||
|
};
|
||||||
|
|
||||||
|
fn drawDebugColorLegend() void {
|
||||||
|
const list = [_]struct {}{};
|
||||||
|
|
||||||
|
var y: c_int = @intFromFloat(screen_height);
|
||||||
|
for (list) |item| {
|
||||||
|
_ = item;
|
||||||
|
_ = &y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn drawDebugGrid() void {
|
||||||
|
const height: c_int = @intFromFloat(screen_height);
|
||||||
|
const width: c_int = @intFromFloat(screen_width);
|
||||||
|
|
||||||
|
var x: c_int = 0;
|
||||||
|
while (x < width) : (x += 25) raylib.DrawLine(x, 0, x, height, debug_colors.screen_grid_color);
|
||||||
|
var y: c_int = 0;
|
||||||
|
while (y < height) : (y += 25) raylib.DrawLine(0, y, width, y, debug_colors.screen_grid_color);
|
||||||
|
|
||||||
|
x = 100;
|
||||||
|
while (x < width) : (x += 100) {
|
||||||
|
var buf: [8]u8 = undefined;
|
||||||
|
const text = std.fmt.bufPrint(&buf, "{d}", .{x}) catch unreachable;
|
||||||
|
buf[text.len] = 0;
|
||||||
|
raylib.DrawText(@ptrCast(text), x + 1, height - 15, 10, debug_colors.screen_text_color);
|
||||||
|
|
||||||
|
const size = raylib.MeasureText(@ptrCast(text), 10);
|
||||||
|
raylib.DrawText(@ptrCast(text), width - 15 - size, x, 10, debug_colors.screen_text_color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO item actions
|
// TODO item actions
|
||||||
// TODO item groups
|
// TODO item groups
|
||||||
// TODO item group sort
|
// TODO item group sort
|
||||||
|
@ -455,18 +495,21 @@ pub const Background = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw(self: *Background) void {
|
pub fn draw(self: *Background) void {
|
||||||
raylib.DrawRectangleGradientEx(
|
if (debug_draw)
|
||||||
.{
|
raylib.ClearBackground(raylib.BLACK)
|
||||||
.x = 0,
|
else
|
||||||
.y = 0,
|
raylib.DrawRectangleGradientEx(
|
||||||
.width = screen_width,
|
.{
|
||||||
.height = screen_height,
|
.x = 0,
|
||||||
},
|
.y = 0,
|
||||||
self.top_left.toRaylib(),
|
.width = screen_width,
|
||||||
self.bottom_left.toRaylib(),
|
.height = screen_height,
|
||||||
self.top_right.toRaylib(),
|
},
|
||||||
self.bottom_right.toRaylib(),
|
self.top_left.toRaylib(),
|
||||||
);
|
self.bottom_left.toRaylib(),
|
||||||
|
self.top_right.toRaylib(),
|
||||||
|
self.bottom_right.toRaylib(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const Color = struct {
|
pub const Color = struct {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue