tinyOsxGraphicsWindow.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 tinyOsxGraphicsWindow.h
  10. * @author drose
  11. * @date 2008-05-12
  12. */
  13. #ifndef TINYOSXGRAPHICSWINDOW_H
  14. #define TINYOSXGRAPHICSWINDOW_H
  15. #include "pandabase.h"
  16. #if defined(IS_OSX) && !defined(BUILD_IPHONE) && defined(HAVE_CARBON) && !__LP64__
  17. #include <Carbon/Carbon.h>
  18. #include "graphicsWindow.h"
  19. #include "buttonHandle.h"
  20. #include "tinyGraphicsStateGuardian.h"
  21. /**
  22. * Opens a window on OS X to display the TinyPanda software rendering.
  23. */
  24. class TinyOsxGraphicsWindow : public GraphicsWindow {
  25. public:
  26. TinyOsxGraphicsWindow(GraphicsEngine *engine, GraphicsPipe *pipe,
  27. const std::string &name,
  28. const FrameBufferProperties &fb_prop,
  29. const WindowProperties &win_prop,
  30. int flags,
  31. GraphicsStateGuardian *gsg,
  32. GraphicsOutput *host);
  33. virtual ~TinyOsxGraphicsWindow();
  34. virtual bool move_pointer(int device, int x, int y);
  35. virtual bool begin_frame(FrameMode mode, Thread *current_thread);
  36. virtual void end_frame(FrameMode mode, Thread *current_thread);
  37. virtual void begin_flip();
  38. virtual void process_events();
  39. virtual bool supports_pixel_zoom() const;
  40. virtual bool do_reshape_request(int x_origin, int y_origin, bool has_origin,
  41. int x_size, int y_size);
  42. virtual void mouse_mode_absolute();
  43. virtual void mouse_mode_relative();
  44. virtual void set_properties_now(WindowProperties &properties);
  45. private:
  46. void ReleaseSystemResources();
  47. inline void SendKeyEvent( ButtonHandle key, bool down);
  48. protected:
  49. virtual void close_window();
  50. virtual bool open_window();
  51. private:
  52. bool OSOpenWindow(WindowProperties &properties);
  53. // a singleton .. for the events to find the right pipe to push the event
  54. // into
  55. public: // do not call direct ..
  56. OSStatus handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown);
  57. OSStatus handleTextInput (EventHandlerCallRef myHandler, EventRef event);
  58. OSStatus handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event);
  59. ButtonHandle OSX_TranslateKey( UInt32 key, EventRef event );
  60. static TinyOsxGraphicsWindow * GetCurrentOSxWindow (WindowRef hint);
  61. void HandleModifireDeleta(UInt32 modifiers);
  62. void HandleButtonDelta(UInt32 new_buttons);
  63. void DoResize(void);
  64. OSStatus event_handler(EventHandlerCallRef myHandler, EventRef event);
  65. virtual void user_close_request();
  66. void SystemCloseWindow();
  67. void SystemSetWindowForground(bool forground);
  68. void SystemPointToLocalPoint(Point &qdGlobalPoint);
  69. void LocalPointToSystemPoint(Point &qdLocalPoint);
  70. bool set_icon_filename(const Filename &icon_filename);
  71. void set_pointer_in_window(int x, int y);
  72. void set_pointer_out_of_window();
  73. private:
  74. void create_frame_buffer();
  75. private:
  76. ZBuffer *_frame_buffer;
  77. private:
  78. UInt32 _last_key_modifiers;
  79. UInt32 _last_buttons;
  80. WindowRef _osx_window;
  81. bool _is_fullscreen;
  82. CGImageRef _pending_icon;
  83. CGImageRef _current_icon;
  84. int _ID;
  85. static TinyOsxGraphicsWindow *FullScreenWindow;
  86. CFDictionaryRef _originalMode;
  87. // True if _properties.get_cursor_hidden() is true.
  88. bool _cursor_hidden;
  89. // True if the cursor is actually hidden right now via system calls.
  90. bool _display_hide_cursor;
  91. SInt32 _wheel_delta;
  92. public:
  93. static TypeHandle get_class_type() {
  94. return _type_handle;
  95. }
  96. static void init_type() {
  97. GraphicsWindow::init_type();
  98. register_type(_type_handle, "TinyOsxGraphicsWindow",
  99. GraphicsWindow::get_class_type());
  100. }
  101. virtual TypeHandle get_type() const {
  102. return get_class_type();
  103. }
  104. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  105. private:
  106. static TypeHandle _type_handle;
  107. };
  108. #include "tinyOsxGraphicsWindow.I"
  109. #endif // IS_OSX
  110. #endif