Luna Stadler лет назад: 4
Родитель
Сommit
ca8fd48d92
1 измененных файлов с 5 добавлено и 4 удалено
  1. 5 4
      zig/sdl/hello_sdl.zig

+ 5 - 4
zig/sdl/hello_sdl.zig

@ -50,8 +50,8 @@ pub fn main() !void {
50 50
    }
51 51
    var glyph_height = c.TTF_FontLineSkip(font);
52 52
53
    const window_width = glyph_width * 100;
54
    const window_height = glyph_height * 20;
53
    var window_width = glyph_width * 100;
54
    var window_height = glyph_height * 20;
55 55
    const screen = c.SDL_CreateWindow("hello fonts", c.SDL_WINDOWPOS_CENTERED, c.SDL_WINDOWPOS_CENTERED, window_width, window_height, c.SDL_WINDOW_BORDERLESS) orelse {
56 56
        c.SDL_Log("Unable to create window: %s", c.SDL_GetError());
57 57
        return error.SDLInitializationFailed;
@ -82,7 +82,8 @@ pub fn main() !void {
82 82
                c.SDL_WINDOWEVENT => {
83 83
                    switch (event.window.event) {
84 84
                        c.SDL_WINDOWEVENT_SIZE_CHANGED => {
85
                            surface = c.SDL_GetWindowSurface(screen);
85
                            window_width = event.window.data1;
86
                            window_height = event.window.data2;
86 87
                        },
87 88
                        else => {},
88 89
                    }
@ -147,7 +148,7 @@ pub fn main() !void {
147 148
        const text = c.TTF_RenderUTF8_Shaded(font, &msg, white, black);
148 149
        const texture = c.SDL_CreateTextureFromSurface(renderer, text);
149 150
        c.SDL_FreeSurface(text);
150
        _ = c.SDL_RenderCopy(renderer, texture, null, &c.SDL_Rect{ .x = 0, .y = 0, .w = window_width, .h = glyph_height });
151
        _ = c.SDL_RenderCopy(renderer, texture, null, &c.SDL_Rect{ .x = 0, .y = 0, .w = @intCast(c_int, msg.len) * glyph_width, .h = glyph_height });
151 152
152 153
        var i: c_int = 1;
153 154
        var lines = std.mem.split(result, "\n");