~sircmpwn/xrgears

ref: 04a78fdd25967ed8f104e5c0b1e0589588d6c776 xrgears/vitamin-k/window/vikWindow.hpp -rw-r--r-- 2.5 KiB
04a78fdd — Lubosz Sarnecki overlay: fix validation warnings. 4 years ago
                                                                                
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * vitamin-k
 *
 * Copyright 2017-2018 Collabora Ltd.
 *
 * Authors: Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
 * SPDX-License-Identifier: MIT
 */

#pragma once

#include <functional>
#include <string>
#include <vector>

#include "../render/vikSwapChain.hpp"
#include "../input/vikInput.hpp"
#include "../system/vikSettings.hpp"

namespace vik {
class Window {
 public:
  std::string name;

  std::function<void()> quit_cb;

  std::function<void()> render_frame_cb;

  std::function<void(double x, double y)>
    pointer_motion_cb = [](double x, double y) {};
  std::function<void(Input::MouseButton button, bool state)>
    pointer_button_cb = [](Input::MouseButton button, bool state) {};
  std::function<void(Input::MouseScrollAxis axis, double value)>
    pointer_axis_cb = [](Input::MouseScrollAxis axis, double value) {};
  std::function<void(Input::Key key, bool state)>
    keyboard_key_cb = [](Input::Key key, bool state) {};

  std::function<void(uint32_t width, uint32_t height)> dimension_cb;
  std::function<void(uint32_t width, uint32_t height)> size_only_cb;

  Settings *settings;

  explicit Window(Settings *s) {
    settings = s;
  }

  virtual ~Window() {}


  void set_render_frame_cb(std::function<void()> cb) {
    render_frame_cb = cb;
  }

  void set_quit_cb(std::function<void()> cb) {
    quit_cb = cb;
  }

  void set_pointer_motion_cb(std::function<void(double x, double y)> cb) {
    pointer_motion_cb = cb;
  }

  void set_pointer_button_cb(std::function<void(Input::MouseButton button,
                                                bool state)> cb) {
    pointer_button_cb = cb;
  }

  void set_pointer_axis_cb(std::function<void(
                             Input::MouseScrollAxis axis,
                             double value)> cb) {
    pointer_axis_cb = cb;
  }

  void set_keyboard_key_cb(std::function<void(
                             Input::Key key, bool state)> cb) {
    keyboard_key_cb = cb;
  }

  void set_dimension_cb(std::function<void(uint32_t width, uint32_t height)> cb) {
    dimension_cb = cb;
  }

  void set_size_only_cb(std::function<void(uint32_t width, uint32_t height)> cb) {
    size_only_cb = cb;
  }

  virtual SwapChain* get_swap_chain() = 0;

  virtual void iterate() = 0;
  virtual void init_swap_chain(uint32_t width, uint32_t height) = 0;

  virtual int init() = 0;

  virtual const std::vector<const char*> required_extensions() = 0;
  virtual void update_window_title(const std::string& title) = 0;
  virtual VkBool32 check_support(VkPhysicalDevice physical_device) = 0;
};
}  // namespace vik