Przeglądaj źródła

Fix window resize

Luna Stadler 4 lat temu
rodzic
commit
ca8fd48d92
1 zmienionych plików z 5 dodań i 4 usunięć
  1. 5 4
      zig/sdl/hello_sdl.zig

+ 5 - 4
zig/sdl/hello_sdl.zig

50
    }
50
    }
51
    var glyph_height = c.TTF_FontLineSkip(font);
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
    const screen = c.SDL_CreateWindow("hello fonts", c.SDL_WINDOWPOS_CENTERED, c.SDL_WINDOWPOS_CENTERED, window_width, window_height, c.SDL_WINDOW_BORDERLESS) orelse {
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
        c.SDL_Log("Unable to create window: %s", c.SDL_GetError());
56
        c.SDL_Log("Unable to create window: %s", c.SDL_GetError());
57
        return error.SDLInitializationFailed;
57
        return error.SDLInitializationFailed;
82
                c.SDL_WINDOWEVENT => {
82
                c.SDL_WINDOWEVENT => {
83
                    switch (event.window.event) {
83
                    switch (event.window.event) {
84
                        c.SDL_WINDOWEVENT_SIZE_CHANGED => {
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
                        else => {},
88
                        else => {},
88
                    }
89
                    }
147
        const text = c.TTF_RenderUTF8_Shaded(font, &msg, white, black);
148
        const text = c.TTF_RenderUTF8_Shaded(font, &msg, white, black);
148
        const texture = c.SDL_CreateTextureFromSurface(renderer, text);
149
        const texture = c.SDL_CreateTextureFromSurface(renderer, text);
149
        c.SDL_FreeSurface(text);
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
        var i: c_int = 1;
153
        var i: c_int = 1;
153
        var lines = std.mem.split(result, "\n");
154
        var lines = std.mem.split(result, "\n");