Compare commits

...

5 commits

6 changed files with 40 additions and 11 deletions

View file

@ -31,7 +31,11 @@ pub fn build(b: *std.Build) void {
// exe.linkSystemLibrary("raylib");
exe.linkSystemLibrary("curl");
exe.addObjectFile(.{
.cwd_relative = "/opt/homebrew/Cellar/raylib/5.0/lib/libraylib.a",
.cwd_relative = switch (target.result.os.tag) {
.macos => "/opt/homebrew/Cellar/raylib/5.0/lib/libraylib.a",
.linux => "./libraylib.a",
else => @panic("Unsupported platform"),
},
});
// exe.addObjectFile(.{
// .cwd_relative = "/opt/homebrew/Cellar/curl/8.5.0/lib/libcurl.a",
@ -40,12 +44,20 @@ pub fn build(b: *std.Build) void {
.cwd_relative = "/opt/homebrew/Cellar/raylib/5.0/include",
});
// Raylib dependencies
exe.linkFramework("Foundation");
exe.linkFramework("CoreVideo");
exe.linkFramework("IOKit");
exe.linkFramework("Cocoa");
exe.linkFramework("GLUT");
exe.linkFramework("OpenGL");
switch (target.result.os.tag) {
.macos => {
exe.linkFramework("Foundation");
exe.linkFramework("CoreVideo");
exe.linkFramework("IOKit");
exe.linkFramework("Cocoa");
exe.linkFramework("GLUT");
exe.linkFramework("OpenGL");
},
.linux => {
exe.linkSystemLibrary("c");
},
else => @panic("Unsupported platform"),
}
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default

View file

@ -4,7 +4,7 @@ const rl = raylib.rl;
const AppState = @import("state.zig");
const Curl = @import("curl.zig");
const C = @cImport({
@cDefine("_XOPEN_SOURE", "");
@cDefine("_XOPEN_SOURCE", "");
@cInclude("time.h");
});
@ -65,6 +65,8 @@ fn fetchThread(state: *AppState) !void {
defer result.deinit();
_ = curl.setopt(.write_function, Curl.Utils.array_list_append);
_ = curl.setopt(.write_data, &result);
_ = curl.setopt(.low_speed_limit, @as(c_long, 128));
_ = curl.setopt(.low_speed_time, @as(c_long, 5));
const code = curl.perform();
std.debug.print("[departure/fetchThread] cURL Code: {}\n", .{code});
@ -434,7 +436,7 @@ fn draw_ns(state: *AppState) !void {
const header_height = rl.MeasureTextEx(font, "Vertrek", header_fs, 1).y;
rl.DrawRectangle(0, 0, rl.GetScreenWidth(), 4 + @as(c_int, @intFromFloat(header_height)) + 4, ns_bg2);
raylib.DrawTextEx(font, if (language == 0) "Vertrek" else "Depart", 8, 4, header_fs, 1, ns_fg1);
raylib.DrawTextEx(font, if (language == 0) "Naar/Opmerking" else "To/Via", 8 + col1w + 8, 4, header_fs, 1, ns_fg1);
raylib.DrawTextEx(font, if (language == 0) "Naar/Opmerking" else "To/Remarks", 8 + col1w + 8, 4, header_fs, 1, ns_fg1);
raylib.DrawTextEx(font, if (language == 0) "Spoor" else "Platform", @floatFromInt(rl.GetScreenWidth() - 200), 4, header_fs, 1, ns_fg1);
var y = header_height + 8 + 2;

View file

@ -44,6 +44,8 @@ fn fetchThread(state: *AppState) !void {
defer result.deinit();
_ = curl.setopt(.write_function, Curl.Utils.array_list_append);
_ = curl.setopt(.write_data, &result);
_ = curl.setopt(.low_speed_limit, @as(c_long, 128));
_ = curl.setopt(.low_speed_time, @as(c_long, 5));
const code = curl.perform();
std.debug.print("[home/fetchThread] cURL Code: {}\n", .{code});
@ -70,6 +72,8 @@ fn fetchThread(state: *AppState) !void {
}
}
}
state.home_screen_state.mutex.lock();
defer state.home_screen_state.mutex.unlock();
if (state.home_screen_state.suggestions.len > 0) {
for (state.home_screen_state.suggestions) |suggestion| {
allocator.free(suggestion.id);
@ -92,8 +96,14 @@ pub fn render(state: *AppState) !void {
}
while (raylib.GetCharPressed()) |char| {
hs.station_name.appendAssumeCapacity(@intCast(char));
if (hs.station_name.items.len < hs.station_name_max_len) {
hs.station_name.appendAssumeCapacity(@intCast(char));
}
}
state.home_screen_state.mutex.lock();
defer state.home_screen_state.mutex.unlock();
while (raylib.GetKeyPressed()) |key| {
switch (key) {
rl.KEY_BACKSPACE => {

View file

@ -5,6 +5,8 @@ const home = @import("home.zig");
const departure = @import("departure.zig");
const AppState = @import("state.zig");
const noto = @embedFile("./noto.ttf");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
@ -25,11 +27,12 @@ pub fn main() !void {
var station_id_buffer: [10]u8 = .{0} ** 10;
var appState = AppState{
.allocator = allocator,
.font = rl.LoadFontEx("./noto.ttf", 64, cp, cp_cnt),
.font = rl.LoadFontFromMemory(".ttf", noto, noto.len, 64, cp, cp_cnt),
.db_font = raylib.LoadFontEx("./private/db.ttf", 64, cp, cp_cnt),
.ns_font = raylib.LoadFontEx("./private/ns.ttf", 64, cp, cp_cnt),
.home_screen_state = .{
.station_name = std.ArrayListUnmanaged(u8).initBuffer(&station_name_buffer),
.station_name_max_len = station_name_buffer.len - 1,
},
.departure_screen_state = .{
.platform = std.ArrayListUnmanaged(u8).initBuffer(&platform_buffer),

View file

@ -13,7 +13,9 @@ pub const HSSuggestion = struct {
};
pub const HomeScreenState = struct {
mutex: std.Thread.Mutex = .{},
station_name: std.ArrayListUnmanaged(u8),
station_name_max_len: usize,
fetch_thread: ?std.Thread = null,
suggestions: []HSSuggestion = &.{},
selection_idx: i8 = 0,