summaryrefslogtreecommitdiffhomepage
path: root/main/app.cpp
blob: 33b892316c6658128d317e2b1188dce1e5c340a3 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <cstddef>
#include "app.hpp"
#include "compat/fpu.hpp"
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/ImGuiIntegration/Context.h>
#include <Magnum/ImGuiIntegration/Context.hpp>

namespace floormat {

app::app(const Arguments& arguments):
      Platform::Application{
          arguments,
          Configuration{}
              .setTitle("Test")
              .setSize({1024, 768}, dpi_policy::Physical)
              .setWindowFlags(Configuration::WindowFlag::Resizable),
          GLConfiguration{}
              .setSampleCount(4)
              .setFlags(GLConfiguration::Flag::GpuValidation)
      }
{
    set_fp_mask();
    reset_camera_offset();
    update_window_scale(windowSize());
    setMinimalLoopPeriod(5);
    _imgui = ImGuiIntegration::Context(Vector2{windowSize()}, windowSize(), framebufferSize());
    setup_menu();
    timeline.start();
}
void app::viewportEvent(Platform::Sdl2Application::ViewportEvent& event)
{
    update_window_scale(event.windowSize());
    GL::defaultFramebuffer.setViewport({{}, event.windowSize()});
    _imgui.relayout(Vector2{event.windowSize()}, event.windowSize(), event.framebufferSize());
}


void app::mousePressEvent(Platform::Sdl2Application::MouseEvent& event)
{
    if (_imgui.handleMousePressEvent(event))
        return event.setAccepted();
}

void app::mouseReleaseEvent(Platform::Sdl2Application::MouseEvent& event)
{
    if (_imgui.handleMouseReleaseEvent(event))
        return event.setAccepted();
}

void app::mouseMoveEvent(Platform::Sdl2Application::MouseMoveEvent& event)
{
    if (_imgui.handleMouseMoveEvent(event))
        return event.setAccepted();
}

void app::mouseScrollEvent(Platform::Sdl2Application::MouseScrollEvent& event)
{
    if (_imgui.handleMouseScrollEvent(event))
        return event.setAccepted();
}

void app::textInputEvent(Platform::Sdl2Application::TextInputEvent& event)
{
    if (_imgui.handleTextInputEvent(event))
        return keys = {}, event.setAccepted();
}

void app::update(float dt)
{
    do_camera(dt);
    if (keys[key::quit])
        Platform::Sdl2Application::exit(0);
}

} // namespace floormat