💿🐜 Antkeeper source code https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
4.9 KiB

  1. /*
  2. * Copyright (C) 2023 Christopher J. Howard
  3. *
  4. * This file is part of Antkeeper source code.
  5. *
  6. * Antkeeper source code is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Antkeeper source code is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef ANTKEEPER_APP_DISPLAY_HPP
  20. #define ANTKEEPER_APP_DISPLAY_HPP
  21. #include "app/display-orientation.hpp"
  22. #include "app/display-events.hpp"
  23. #include "geom/primitive/rectangle.hpp"
  24. #include "event/publisher.hpp"
  25. #include <string>
  26. namespace app {
  27. /**
  28. * Virtual display.
  29. */
  30. class display
  31. {
  32. public:
  33. /**
  34. * Sets the index of the display.
  35. *
  36. * @param index Index of the display.
  37. */
  38. inline void set_index(int index) noexcept
  39. {
  40. this->index = index;
  41. }
  42. /**
  43. * Sets the name of the display.
  44. *
  45. * @param name Name of the display.
  46. */
  47. inline void set_name(const std::string& name) noexcept
  48. {
  49. this->name = name;
  50. }
  51. /**
  52. * Sets the bounds of the display.
  53. *
  54. * @param bounds Bounds of the display, in display units.
  55. */
  56. inline void set_bounds(const geom::primitive::rectangle<int>& bounds) noexcept
  57. {
  58. this->bounds = bounds;
  59. }
  60. /**
  61. * Sets the usable bounds of the display, which excludes areas reserved by the OS for things like menus or docks.
  62. */
  63. inline void set_usable_bounds(const geom::primitive::rectangle<int>& bounds) noexcept
  64. {
  65. this->usable_bounds = bounds;
  66. }
  67. /**
  68. * Sets the refresh rate of the display.
  69. *
  70. * @param rate Refresh rate, in Hz.
  71. */
  72. inline void set_refresh_rate(int rate) noexcept
  73. {
  74. this->refresh_rate = rate;
  75. }
  76. /**
  77. * Sets the DPI of the display.
  78. *
  79. * @param dpi DPI.
  80. */
  81. inline void set_dpi(float dpi) noexcept
  82. {
  83. this->dpi = dpi;
  84. }
  85. /**
  86. * Sets the orientation of the display.
  87. *
  88. * @param orientation Display orientation.
  89. */
  90. inline void set_orientation(display_orientation orientation) noexcept
  91. {
  92. this->orientation = orientation;
  93. }
  94. /// Returns the index of the display.
  95. [[nodiscard]] inline const int& get_index() const noexcept
  96. {
  97. return index;
  98. }
  99. /// Returns the name of the display.
  100. [[nodiscard]] inline const std::string& get_name() const noexcept
  101. {
  102. return name;
  103. }
  104. /// Returns the bounds of the display, in display units.
  105. [[nodiscard]] inline const geom::primitive::rectangle<int>& get_bounds() const noexcept
  106. {
  107. return bounds;
  108. }
  109. /// Returns the usable bounds of the display, which excludes areas reserved by the OS for things like menus or docks, in display units.
  110. [[nodiscard]] inline const geom::primitive::rectangle<int>& get_usable_bounds() const noexcept
  111. {
  112. return usable_bounds;
  113. }
  114. /// Returns the refresh rate of the display, in Hz.
  115. [[nodiscard]] inline const int& get_refresh_rate() const noexcept
  116. {
  117. return refresh_rate;
  118. }
  119. /// Returns the DPI of the display.
  120. [[nodiscard]] inline const float& get_dpi() const noexcept
  121. {
  122. return dpi;
  123. }
  124. /// Returns the current orientation of the display.
  125. [[nodiscard]] inline const display_orientation& get_orientation() const noexcept
  126. {
  127. return orientation;
  128. }
  129. /// Returns `true` if the display is connected, `false` otherwise.
  130. [[nodiscard]] inline const bool& is_connected() const noexcept
  131. {
  132. return connected;
  133. }
  134. /// Returns the channel through which display connected events are published.
  135. [[nodiscard]] inline event::channel<display_connected_event>& get_connected_channel() noexcept
  136. {
  137. return connected_publisher.channel();
  138. }
  139. /// Returns the channel through which display disconnected events are published.
  140. [[nodiscard]] inline event::channel<display_disconnected_event>& get_disconnected_channel() noexcept
  141. {
  142. return disconnected_publisher.channel();
  143. }
  144. /// Returns the channel through which display orientation changed events are published.
  145. [[nodiscard]] inline event::channel<display_orientation_changed_event>& get_orientation_changed_channel() noexcept
  146. {
  147. return orientation_changed_publisher.channel();
  148. }
  149. private:
  150. friend class window_manager;
  151. friend class sdl_window_manager;
  152. int index;
  153. std::string name;
  154. geom::primitive::rectangle<int> bounds;
  155. geom::primitive::rectangle<int> usable_bounds;
  156. int refresh_rate;
  157. float dpi;
  158. display_orientation orientation;
  159. bool connected;
  160. event::publisher<display_connected_event> connected_publisher;
  161. event::publisher<display_disconnected_event> disconnected_publisher;
  162. event::publisher<display_orientation_changed_event> orientation_changed_publisher;
  163. };
  164. } // namespace app
  165. #endif // ANTKEEPER_APP_DISPLAY_HPP