Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980const std = @import("std");const z2d = @import("z2d");const Client = @import("Client.zig");
pub fn main() !void { std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
var debug_alloc = std.heap.DebugAllocator(.{}).init; const alloc = debug_alloc.allocator();
var client: Client = undefined; try client.init(alloc);
std.log.debug("(app) client initialized.", .{});
const window = client.createWindow("Hello World!"); defer window.deinit(); try window.show(400, 500); std.log.debug("(app) Window shown", .{});
try redraw(window); try window.submit();
while (window.is_open) { std.log.info("tick", .{}); if (client.display.dispatch() != .SUCCESS) return; if (window.need_redraw) { try redraw(window); } }}
fn redraw(window: *Client.Window) !void { var surface = window.surface() orelse { window.is_open = false; return; }; try rect(window.alloc, &surface, 0, 0, 100, 100, .rgb(1, 0, 0)); std.log.info("(app) width: {d}", .{window.width}); try rect( window.alloc, &surface, @as(f64, @floatFromInt(window.width)) - 100, @as(f64, @floatFromInt(window.height)) - 100, // 50, // 50, 100, 100, .rgb(0, 0, 1), ); try window.submit();}
/// For converting to Wayland color space.const Color = struct { r: f64, g: f64, b: f64, pub fn rgb(r: f64, g: f64, b: f64) Color { return .{ .r = r, .g = g, .b = b }; } fn toPixel(color: Color) z2d.Pixel { return .{ .rgb = .fromClamped(color.b, color.g, color.r) }; } fn toPattern(color: Color) z2d.Pattern { return .{ .opaque_pattern = .{ .pixel = toPixel(color) } }; }};
fn rect(alloc: std.mem.Allocator, surface: *z2d.Surface, x: f64, y: f64, width: f64, height: f64, color: Color) !void { var path: z2d.StaticPath(6) = .{}; path.init(); path.moveTo(x, y); path.relLineTo(width, 0); path.relLineTo(0, height); path.relLineTo(-width, 0); path.close(); try z2d.painter.fill(alloc, surface, &color.toPattern(), &path.nodes, .{});}