const std = @import("std"); const sdl = @cImport(@cInclude("SDL2/SDL.h")); pub const instance = struct { renderer: ?*sdl.SDL_Renderer, window: ?*sdl.SDL_Window, }; pub fn init() instance { _ = sdl.SDL_Init(sdl.SDL_INIT_VIDEO); var window = sdl.SDL_CreateWindow( "main", sdl.SDL_WINDOWPOS_UNDEFINED, sdl.SDL_WINDOWPOS_UNDEFINED, 500, 500, sdl.SDL_WINDOW_SHOWN, ); var renderer = sdl.SDL_CreateRenderer( window, -1, sdl.SDL_RENDERER_ACCELERATED, ); return instance{ .window = window, .renderer = renderer, }; } pub fn draw_line(i: instance, p1: []f32, p2: []f32) void { _ = sdl.SDL_RenderDrawLineF(i.renderer, p1[0], p1[1], p2[0], p2[1]); } pub fn delay(t: u32) void { sdl.SDL_Delay(t); } pub fn draw_color(i: instance, r: u8, g: u8, b: u8, a: u8) void { _ = sdl.SDL_SetRenderDrawColor(i.renderer, r, g, b, a); } pub fn clear(i: instance) void { _ = sdl.SDL_RenderClear(i.renderer); } pub fn present(i: instance) void { sdl.SDL_RenderPresent(i.renderer); } pub fn get_event() event { var e: sdl.SDL_Event = undefined; _ = sdl.SDL_PollEvent(&e); var key = keys.none; var mode = modes.mouse; //var key = @intToEnum(keys, e.key.keysym.sym); //var mode = @intToEnum(modes, e.type); var r: event = event{ .key = key, .mode = mode, }; return r; } const event = struct { key: keys, mode: modes, }; pub const modes = enum(u32) { mouse = sdl.SDL_MOUSEMOTION, window = sdl.SDL_WINDOWEVENT, quit = sdl.SDL_QUIT, key = sdl.SDL_KEYDOWN, }; pub fn quit(i: instance) void { sdl.SDL_DestroyRenderer(i.renderer); sdl.SDL_DestroyWindow(i.window); sdl.SDL_Quit(); } pub const keys = enum(i32) { none = sdl.SDLK_UNKNOWN, w = sdl.SDLK_w, s = sdl.SDLK_s, q = sdl.SDLK_q, up = sdl.SDLK_UP, down = sdl.SDLK_DOWN, left = sdl.SDLK_LEFT, right = sdl.SDLK_RIGHT, };