os_winrt.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*************************************************************************/
  2. /* OSWinrt.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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 OSWinrt_H
  30. #define OSWinrt_H
  31. #include "os/input.h"
  32. #include "os/os.h"
  33. #include "servers/visual_server.h"
  34. #include "servers/visual/rasterizer.h"
  35. #include "servers/physics/physics_server_sw.h"
  36. #include "servers/audio/audio_server_sw.h"
  37. #include "servers/audio/sample_manager_sw.h"
  38. #include "servers/spatial_sound/spatial_sound_server_sw.h"
  39. #include "servers/spatial_sound_2d/spatial_sound_2d_server_sw.h"
  40. #include "servers/physics_2d/physics_2d_server_sw.h"
  41. #include "servers/audio/audio_driver_dummy.h"
  42. #include "gl_context_egl.h"
  43. #include <windows.h>
  44. #include <io.h>
  45. #include <fcntl.h>
  46. #include <stdio.h>
  47. /**
  48. @author Juan Linietsky <reduzio@gmail.com>
  49. */
  50. class OSWinrt : public OS {
  51. enum {
  52. JOYSTICKS_MAX = 8,
  53. JOY_AXIS_COUNT = 6,
  54. MAX_JOY_AXIS = 32768, // I've no idea
  55. KEY_EVENT_BUFFER_SIZE=512
  56. };
  57. FILE *stdo;
  58. struct KeyEvent {
  59. InputModifierState mod_state;
  60. UINT uMsg;
  61. WPARAM wParam;
  62. LPARAM lParam;
  63. };
  64. KeyEvent key_event_buffer[KEY_EVENT_BUFFER_SIZE];
  65. int key_event_pos;
  66. uint64_t ticks_start;
  67. uint64_t ticks_per_second;
  68. bool minimized;
  69. bool old_invalid;
  70. bool outside;
  71. int old_x,old_y;
  72. Point2i center;
  73. unsigned int last_id;
  74. VisualServer *visual_server;
  75. Rasterizer *rasterizer;
  76. PhysicsServer *physics_server;
  77. Physics2DServer *physics_2d_server;
  78. int pressrc;
  79. ContextEGL* gl_context;
  80. struct Joystick {
  81. int id;
  82. bool attached;
  83. DWORD last_axis[JOY_AXIS_COUNT];
  84. DWORD last_buttons;
  85. DWORD last_pov;
  86. String name;
  87. Joystick() {
  88. id = -1;
  89. attached = false;
  90. for (int i=0; i<JOY_AXIS_COUNT; i++) {
  91. last_axis[i] = 0;
  92. };
  93. last_buttons = 0;
  94. last_pov = 0;
  95. };
  96. };
  97. List<Joystick> joystick_change_queue;
  98. int joystick_count;
  99. Joystick joysticks[JOYSTICKS_MAX];
  100. VideoMode video_mode;
  101. MainLoop *main_loop;
  102. AudioDriverDummy audio_driver;
  103. AudioServerSW *audio_server;
  104. SampleManagerMallocSW *sample_manager;
  105. SpatialSoundServerSW *spatial_sound_server;
  106. SpatialSound2DServerSW *spatial_sound_2d_server;
  107. MouseMode mouse_mode;
  108. bool alt_mem;
  109. bool gr_mem;
  110. bool shift_mem;
  111. bool control_mem;
  112. bool meta_mem;
  113. bool force_quit;
  114. uint32_t last_button_state;
  115. CursorShape cursor_shape;
  116. InputDefault *input;
  117. void _post_dpad(DWORD p_dpad, int p_device, bool p_pressed);
  118. void _drag_event(int idx,UINT uMsg, WPARAM wParam, LPARAM lParam);
  119. void _touch_event(int idx, UINT uMsg, WPARAM wParam, LPARAM lParam);
  120. // functions used by main to initialize/deintialize the OS
  121. protected:
  122. virtual int get_video_driver_count() const;
  123. virtual const char * get_video_driver_name(int p_driver) const;
  124. virtual VideoMode get_default_video_mode() const;
  125. virtual int get_audio_driver_count() const;
  126. virtual const char * get_audio_driver_name(int p_driver) const;
  127. virtual void initialize_core();
  128. virtual void initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver);
  129. virtual void set_main_loop( MainLoop * p_main_loop );
  130. virtual void delete_main_loop();
  131. virtual void finalize();
  132. virtual void finalize_core();
  133. void process_events();
  134. void probe_joysticks();
  135. void process_joysticks();
  136. void process_key_events();
  137. public:
  138. void print_error(const char* p_function,const char* p_file,int p_line,const char *p_code,const char*p_rationale,ErrorType p_type);
  139. virtual void vprint(const char *p_format, va_list p_list, bool p_stderr=false);
  140. virtual void alert(const String& p_alert,const String& p_title="ALERT!");
  141. String get_stdin_string(bool p_block);
  142. void set_mouse_mode(MouseMode p_mode);
  143. MouseMode get_mouse_mode() const;
  144. virtual Point2 get_mouse_pos() const;
  145. virtual int get_mouse_button_state() const;
  146. virtual void set_window_title(const String& p_title);
  147. virtual void set_video_mode(const VideoMode& p_video_mode,int p_screen=0);
  148. virtual VideoMode get_video_mode(int p_screen=0) const;
  149. virtual void get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen=0) const;
  150. virtual MainLoop *get_main_loop() const;
  151. virtual String get_name();
  152. virtual Date get_date() const;
  153. virtual Time get_time() const;
  154. virtual uint64_t get_unix_time() const;
  155. virtual bool can_draw() const;
  156. virtual Error set_cwd(const String& p_cwd);
  157. virtual void delay_usec(uint32_t p_usec) const;
  158. virtual uint64_t get_ticks_usec() const;
  159. virtual Error execute(const String& p_path, const List<String>& p_arguments,bool p_blocking,ProcessID *r_child_id=NULL,String* r_pipe=NULL,int *r_exitcode=NULL);
  160. virtual Error kill(const ProcessID& p_pid);
  161. virtual bool has_environment(const String& p_var) const;
  162. virtual String get_environment(const String& p_var) const;
  163. virtual void set_clipboard(const String& p_text);
  164. virtual String get_clipboard() const;
  165. void set_cursor_shape(CursorShape p_shape);
  166. void set_icon(const Image& p_icon);
  167. virtual String get_executable_path() const;
  168. virtual String get_locale() const;
  169. virtual void move_window_to_foreground();
  170. virtual String get_data_dir() const;
  171. void set_gl_context(ContextEGL* p_context);
  172. void screen_size_changed();
  173. virtual void release_rendering_thread();
  174. virtual void make_rendering_thread();
  175. virtual void swap_buffers();
  176. virtual bool has_touchscreen_ui_hint() const { return true; };
  177. virtual Error shell_open(String p_uri);
  178. void run();
  179. virtual bool get_swap_ok_cancel() { return true; }
  180. void input_event(InputEvent &p_event);
  181. OSWinrt();
  182. ~OSWinrt();
  183. };
  184. #endif