window.hpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once


#include <planet/sdl/renderer.hpp>
#include <planet/events/mouse.hpp>
#include <planet/ui/baseplate.hpp>

#include <felspar/coro/starter.hpp>

#include <SDL.h>
#undef main

#include <cstdint>


namespace planet::sdl {


    class init;


    class window final {
        handle<SDL_Window, SDL_DestroyWindow> pw;
        affine::extents2d size;
        felspar::coro::starter<> processes;

      public:
        window(init &,
               const char *name,
               int posx,
               int posy,
               int width,
               int height,
               std::uint32_t flags = {});
        window(init &,
               const char *name,
               std::size_t width,
               std::size_t height,
               std::uint32_t flags = {});
        window(init &,
               const char *name,
               std::uint32_t flags = SDL_WINDOW_FULLSCREEN_DESKTOP);

        SDL_Window *get() const noexcept { return pw.get(); }

        sdl::renderer renderer;
        ui::baseplate baseplate;

Current inner window size

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
        affine::extents2d const &extents() const noexcept { return size; }
        affine::rectangle2d rectangle() const noexcept {
            return {{0, 0}, size};
        }
        std::size_t uzwidth() const noexcept { return size.uzwidth(); }
        std::size_t uzheight() const noexcept { return size.uzheight(); }
        float width() const noexcept { return size.width; }
        float height() const noexcept { return size.height; }

        using constrained_type = ui::constrained2d<float>;
        constrained_type constraints() const {
            return {{size.width, 0, size.width}, {size.height, 0, size.height}};
        }
    };


}