os_osx.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*************************************************************************/
  2. /* os_osx.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef OS_OSX_H
  30. #define OS_OSX_H
  31. #include "os/input.h"
  32. #include "drivers/unix/os_unix.h"
  33. #include "main/input_default.h"
  34. #include "servers/visual_server.h"
  35. #include "servers/visual/visual_server_wrap_mt.h"
  36. #include "servers/visual/rasterizer.h"
  37. #include "servers/physics_server.h"
  38. #include "servers/audio/audio_server_sw.h"
  39. #include "servers/audio/sample_manager_sw.h"
  40. #include "servers/spatial_sound/spatial_sound_server_sw.h"
  41. #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h"
  42. #include "drivers/rtaudio/audio_driver_rtaudio.h"
  43. #include "drivers/alsa/audio_driver_alsa.h"
  44. #include "servers/physics_2d/physics_2d_server_sw.h"
  45. #include "servers/physics_2d/physics_2d_server_wrap_mt.h"
  46. #include "platform/osx/audio_driver_osx.h"
  47. #include <ApplicationServices/ApplicationServices.h>
  48. //bitch
  49. #undef CursorShape
  50. /**
  51. @author Juan Linietsky <[email protected]>
  52. */
  53. class OS_OSX : public OS_Unix {
  54. public:
  55. bool force_quit;
  56. Rasterizer *rasterizer;
  57. VisualServer *visual_server;
  58. List<String> args;
  59. MainLoop *main_loop;
  60. unsigned int event_id;
  61. PhysicsServer *physics_server;
  62. Physics2DServer *physics_2d_server;
  63. IP_Unix *ip_unix;
  64. AudioDriverOSX audio_driver_osx;
  65. AudioServerSW *audio_server;
  66. SampleManagerMallocSW *sample_manager;
  67. SpatialSoundServerSW *spatial_sound_server;
  68. SpatialSound2DServerSW *spatial_sound_2d_server;
  69. InputDefault *input;
  70. /* objc */
  71. CGEventSourceRef eventSource;
  72. void process_events();
  73. void* framework;
  74. // pthread_key_t current;
  75. bool mouse_grab;
  76. Point2 mouse_pos;
  77. uint32_t last_id;
  78. id delegate;
  79. id window_delegate;
  80. id window_object;
  81. id window_view;
  82. id autoreleasePool;
  83. id cursor;
  84. id pixelFormat;
  85. id context;
  86. CursorShape cursor_shape;
  87. MouseMode mouse_mode;
  88. bool minimized;
  89. bool maximized;
  90. bool zoomed;
  91. Vector<Rect2> screens;
  92. Vector<int> screen_dpi;
  93. Size2 window_size;
  94. int current_screen;
  95. Rect2 restore_rect;
  96. float _mouse_scale(float p_scale) {
  97. if (display_scale>1.0)
  98. return p_scale;
  99. else
  100. return 1.0;
  101. }
  102. float display_scale;
  103. protected:
  104. virtual int get_video_driver_count() const;
  105. virtual const char * get_video_driver_name(int p_driver) const;
  106. virtual VideoMode get_default_video_mode() const;
  107. virtual void initialize_core();
  108. virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver);
  109. virtual void finalize();
  110. virtual void set_main_loop( MainLoop * p_main_loop );
  111. virtual void delete_main_loop();
  112. public:
  113. static OS_OSX* singleton;
  114. void wm_minimized(bool p_minimized);
  115. virtual String get_name();
  116. virtual void set_cursor_shape(CursorShape p_shape);
  117. virtual void set_mouse_show(bool p_show);
  118. virtual void set_mouse_grab(bool p_grab);
  119. virtual bool is_mouse_grab_enabled() const;
  120. virtual void warp_mouse_pos(const Point2& p_to);
  121. virtual Point2 get_mouse_pos() const;
  122. virtual int get_mouse_button_state() const;
  123. virtual void set_window_title(const String& p_title);
  124. virtual Size2 get_window_size() const;
  125. virtual void set_icon(const Image& p_icon);
  126. virtual MainLoop *get_main_loop() const;
  127. virtual bool can_draw() const;
  128. virtual void set_clipboard(const String& p_text);
  129. virtual String get_clipboard() const;
  130. virtual void release_rendering_thread();
  131. virtual void make_rendering_thread();
  132. virtual void swap_buffers();
  133. Error shell_open(String p_uri);
  134. void push_input(const InputEvent& p_event);
  135. String get_locale() const;
  136. virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0);
  137. virtual VideoMode get_video_mode(int p_screen=0) const;
  138. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
  139. virtual String get_executable_path() const;
  140. virtual LatinKeyboardVariant get_latin_keyboard_variant() const;
  141. virtual void move_window_to_foreground();
  142. virtual int get_screen_count() const;
  143. virtual int get_current_screen() const;
  144. virtual void set_current_screen(int p_screen);
  145. virtual Point2 get_screen_position(int p_screen=0) const;
  146. virtual Size2 get_screen_size(int p_screen=0) const;
  147. virtual int get_screen_dpi(int p_screen=0) const;
  148. virtual Point2 get_window_position() const;
  149. virtual void set_window_position(const Point2& p_position);
  150. virtual void set_window_size(const Size2 p_size);
  151. virtual void set_window_fullscreen(bool p_enabled);
  152. virtual bool is_window_fullscreen() const;
  153. virtual void set_window_resizable(bool p_enabled);
  154. virtual bool is_window_resizable() const;
  155. virtual void set_window_minimized(bool p_enabled);
  156. virtual bool is_window_minimized() const;
  157. virtual void set_window_maximized(bool p_enabled);
  158. virtual bool is_window_maximized() const;
  159. void run();
  160. void set_mouse_mode(MouseMode p_mode);
  161. MouseMode get_mouse_mode() const;
  162. OS_OSX();
  163. };
  164. #endif