2
0

App.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. #pragma once
  2. #include "Defines.h"
  3. #include "Input.h"
  4. #include "Monitor.h"
  5. #include "Signal.h"
  6. #include "Types.h"
  7. #include <memory>
  8. #include <string>
  9. namespace gameplay
  10. {
  11. class Config;
  12. class Cursor;
  13. class FileSystem;
  14. class Logging;
  15. class Renderer;
  16. class UI;
  17. class Window;
  18. /**
  19. * The main application.
  20. *
  21. * Controls the application runtime and main sub-systems.
  22. */
  23. class GP_API App
  24. {
  25. public:
  26. /**
  27. * Destructor.
  28. */
  29. ~App();
  30. /**
  31. * Gets the application instance.
  32. *
  33. * @return The application instance
  34. */
  35. static App* get_app();
  36. /**
  37. * Runs the main event loop and waits until exit() is called.
  38. *
  39. * @param argc The number of comand-line arguments passed.
  40. * @param argv The command-line arguement strings.
  41. */
  42. int exec(int argc, char** argv);
  43. /**
  44. * Exits the application.
  45. */
  46. void exit();
  47. /**
  48. * Set the current application running time (in seconds).
  49. *
  50. * @param time The time to be set (in seconds).
  51. */
  52. void set_time(double time);
  53. /**
  54. * Get the current application running time (in seconds).
  55. *
  56. * @return The current application running time (in seconds).
  57. */
  58. double get_time() const;
  59. /**
  60. * Gets the main applicaton window.
  61. *
  62. * @return The application main window.
  63. */
  64. Window* get_window() const;
  65. /**
  66. * Gets the primary monitor.
  67. *
  68. * @return The primary monitor.
  69. */
  70. Monitor* get_primary_monitor();
  71. /**
  72. * Gets the monitor the window occupies the most of.
  73. *
  74. * @param window The window to check against.
  75. * @return The monitor the window occupies the most of.
  76. */
  77. Monitor* get_monitor(Window* window);
  78. /**
  79. * Gets the monitors connected.
  80. *
  81. * @param monitorCount The number of monitors returned
  82. * @return The monitors connected.
  83. */
  84. Monitor** get_monitors(size_t* monitorCount);
  85. /**
  86. * Signals that a monitor has changed and been added or removed to the system.
  87. *
  88. * emits:
  89. * <Monitor*> The monitor being changed.
  90. * <MonitorChangeEvent> The change event.
  91. */
  92. Signal<Monitor*, MonitorChangeEvent> on_monitor_change;
  93. /**
  94. * Creates a cursor for the standard cursor shape.
  95. *
  96. * @param shape The (standard) cursor shape.
  97. * @return The cursor created.
  98. */
  99. std::shared_ptr<Cursor> create_cursor(CursorStandardShape shape);
  100. /**
  101. * Creates a cursor for an pixmap image data.
  102. *
  103. * @param image The pixmap image data to create the cursor from.
  104. * @param hotspotPos The top-left position of the exact click hotspot.\
  105. * @return The cursor created.
  106. */
  107. std::shared_ptr<Cursor> create_cursor(const Pixmap* image, Int2 hotspotPos);
  108. /**
  109. * Destroys a cursor.
  110. *
  111. * @param cursor The cursor to destroy.
  112. */
  113. void destroy_cursor(std::shared_ptr<Cursor> cursor);
  114. /**
  115. * Sets the system clipboard to the specified, utf-8 encoded string.
  116. *
  117. * @param str The utf8 encoded string, to be put into the system clipboard.
  118. */
  119. void set_clip_board_string(const char* str);
  120. /**
  121. * Gets the system clipboard to the specified, utf-8 encoded string.
  122. *
  123. * @return The utf8 encoded string, that is in the system clipboard.
  124. */
  125. const char* get_clipboard_string() const;
  126. /**
  127. * Gets the application file system.
  128. *
  129. * @return The application file system.
  130. */
  131. std::shared_ptr<FileSystem> get_file_system() const;
  132. /**
  133. * Gets the application config system.
  134. *
  135. * @return The application config system.
  136. */
  137. std::shared_ptr<Config> get_config() const;
  138. /**
  139. * Gets the application logging system.
  140. *
  141. * @return The application logging system.
  142. */
  143. std::shared_ptr<Logging> get_logging() const;
  144. /**
  145. * Gets the application renderer.
  146. *
  147. * @return The applications renderer.
  148. */
  149. std::shared_ptr<Renderer> get_renderer() const;
  150. /**
  151. * Gets the application user interface (UI) system.
  152. *
  153. * @return The applications user interface (UI) system.
  154. */
  155. std::shared_ptr<UI> get_ui() const;
  156. /**
  157. * sets a resource path for the specified alias.
  158. *
  159. * note: Resource paths may include other resource paths
  160. * that already exist.
  161. *
  162. * The system is populated with the following resource paths:
  163. *
  164. * @app.dir
  165. * @config.dir
  166. *
  167. * @param alias The alias to be set.
  168. * @param path The directory path for the alias to use.
  169. */
  170. void set_resource_path(const char* alias, const char* path);
  171. /**
  172. * Clears a resource path.
  173. *
  174. * @param alias The resource path to be cleared.
  175. */
  176. void clear_resource_path(const char* alias);
  177. /**
  178. * Resolves an application resource path in place
  179. *
  180. * Ex. @images/tree.png will replace the @images with the full resolved path from app.config
  181. *
  182. * This does not validate the paths exist. So you can also
  183. * resolve path that maybe intended for directory creation.
  184. *
  185. * @param path The resource path to be resolved.
  186. * @return true if the path can be resolved, false cannot be resolved due to missing tokens.
  187. */
  188. bool resolve_resource_path(std::string& path);
  189. /**
  190. * Signals the application has completed startup.
  191. *
  192. * emits:
  193. * <App*> The running application.
  194. */
  195. Signal<App*> on_startup;
  196. /**
  197. * Signals the application has started to shutdown.
  198. *
  199. * emits:
  200. * <App*> The running application.
  201. */
  202. Signal<App*> on_shutdown;
  203. private:
  204. App();
  205. struct Impl;
  206. std::unique_ptr<Impl> _impl;
  207. };
  208. }