osxGraphicsWindow.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file osxGraphicsWindow.h
  10. */
  11. #ifndef OSXGRAPHICSWINDOW_H
  12. #define OSXGRAPHICSWINDOW_H
  13. #include "pandabase.h"
  14. #include "graphicsWindow.h"
  15. #include "buttonHandle.h"
  16. #include <Carbon/Carbon.h>
  17. #define __glext_h_
  18. #include <OpenGL/gl.h>
  19. #include <AGL/agl.h>
  20. #define HACK_SCREEN_HASH_CONTEXT true
  21. OSStatus report_agl_error(const std::string &comment);
  22. /**
  23. * An interface to the osx/ system for managing GL windows under X.
  24. */
  25. class osxGraphicsWindow : public GraphicsWindow {
  26. public:
  27. osxGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
  28. const std::string &name,
  29. const FrameBufferProperties &fb_prop,
  30. const WindowProperties &win_prop,
  31. int flags,
  32. GraphicsStateGuardian *gsg,
  33. GraphicsOutput *host);
  34. virtual ~osxGraphicsWindow();
  35. virtual bool move_pointer(int device, int x, int y);
  36. virtual bool begin_frame(FrameMode mode, Thread *current_thread);
  37. virtual void end_frame(FrameMode mode, Thread *current_thread);
  38. virtual void begin_flip();
  39. virtual void end_flip();
  40. virtual void process_events();
  41. virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
  42. int x_size, int y_size);
  43. virtual void mouse_mode_absolute();
  44. virtual void mouse_mode_relative();
  45. virtual void set_properties_now(WindowProperties &properties);
  46. private:
  47. void release_system_resources(bool destructing);
  48. inline void send_key_event(ButtonHandle key, bool down);
  49. protected:
  50. virtual void close_window();
  51. virtual bool open_window();
  52. private:
  53. bool os_open_window(WindowProperties &properties);
  54. // a singleton .. for the events to find the right pipe to push the event
  55. // into
  56. public: // do not call direct ..
  57. OSStatus handle_key_input(EventHandlerCallRef myHandler, EventRef event,
  58. Boolean keyDown);
  59. OSStatus handle_text_input(EventHandlerCallRef myHandler, EventRef event);
  60. OSStatus handle_window_mouse_events(EventHandlerCallRef myHandler, EventRef event);
  61. ButtonHandle osx_translate_key(UInt32 key, EventRef event);
  62. static osxGraphicsWindow *get_current_osx_window(WindowRef hint);
  63. void handle_modifier_delta(UInt32 new_modifiers);
  64. void handle_button_delta(UInt32 new_buttons);
  65. void do_resize();
  66. OSStatus event_handler(EventHandlerCallRef myHandler, EventRef event);
  67. virtual void user_close_request();
  68. void system_close_window();
  69. void system_set_window_foreground(bool foreground);
  70. void system_point_to_local_point(Point &global_point);
  71. void local_point_to_system_point(Point &local_point);
  72. AGLContext get_gsg_context();
  73. AGLContext get_context();
  74. OSStatus build_gl(bool full_screen);
  75. bool set_icon_filename(const Filename &icon_filename);
  76. void set_pointer_in_window(int x, int y);
  77. void set_pointer_out_of_window();
  78. private:
  79. UInt32 _last_key_modifiers;
  80. UInt32 _last_buttons;
  81. WindowRef _osx_window;
  82. bool _is_fullscreen;
  83. CGImageRef _pending_icon;
  84. CGImageRef _current_icon;
  85. int _ID;
  86. static osxGraphicsWindow *full_screen_window;
  87. #ifdef HACK_SCREEN_HASH_CONTEXT
  88. AGLContext _holder_aglcontext;
  89. #endif
  90. CFDictionaryRef _originalMode;
  91. // True if _properties.get_cursor_hidden() is true.
  92. bool _cursor_hidden;
  93. // True if the cursor is actually hidden right now via system calls.
  94. bool _display_hide_cursor;
  95. SInt32 _wheel_hdelta;
  96. SInt32 _wheel_vdelta;
  97. public:
  98. static TypeHandle get_class_type() {
  99. return _type_handle;
  100. }
  101. static void init_type() {
  102. GraphicsWindow::init_type();
  103. register_type(_type_handle, "osxGraphicsWindow",
  104. GraphicsWindow::get_class_type());
  105. }
  106. virtual TypeHandle get_type() const {
  107. return get_class_type();
  108. }
  109. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  110. private:
  111. static TypeHandle _type_handle;
  112. };
  113. #include "osxGraphicsWindow.I"
  114. #endif