As-yet uncommitted changes from end of summer. General code cleanup Mac-side, removed some unnecessary NSAutoreleasePool guards, etc. By no means complete -- just wanted to get this in and do a fresh checkout on another machine.
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
*/
|
||||
/**
|
||||
* @file GHOST_ISystem.h
|
||||
* Main interface file for C++ Api with declaration of GHOST_ISystem interface
|
||||
* Main interface file for C++ API with declaration of GHOST_ISystem interface
|
||||
* class.
|
||||
* Contains the doxygen documentation main page.
|
||||
*/
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "GHOST_Buttons.h"
|
||||
|
||||
|
||||
|
||||
GHOST_Buttons::GHOST_Buttons()
|
||||
{
|
||||
clear();
|
||||
@@ -39,37 +38,37 @@ GHOST_Buttons::~GHOST_Buttons() {}
|
||||
|
||||
bool GHOST_Buttons::get(GHOST_TButtonMask mask) const
|
||||
{
|
||||
switch (mask) {
|
||||
case GHOST_kButtonMaskLeft:
|
||||
return m_ButtonLeft;
|
||||
case GHOST_kButtonMaskMiddle:
|
||||
return m_ButtonMiddle;
|
||||
case GHOST_kButtonMaskRight:
|
||||
return m_ButtonRight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
switch (mask) {
|
||||
case GHOST_kButtonMaskLeft:
|
||||
return m_ButtonLeft;
|
||||
case GHOST_kButtonMaskMiddle:
|
||||
return m_ButtonMiddle;
|
||||
case GHOST_kButtonMaskRight:
|
||||
return m_ButtonRight;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void GHOST_Buttons::set(GHOST_TButtonMask mask, bool down)
|
||||
{
|
||||
switch (mask) {
|
||||
case GHOST_kButtonMaskLeft:
|
||||
m_ButtonLeft = down; break;
|
||||
case GHOST_kButtonMaskMiddle:
|
||||
m_ButtonMiddle = down; break;
|
||||
case GHOST_kButtonMaskRight:
|
||||
m_ButtonRight = down; break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
switch (mask) {
|
||||
case GHOST_kButtonMaskLeft:
|
||||
m_ButtonLeft = down; break;
|
||||
case GHOST_kButtonMaskMiddle:
|
||||
m_ButtonMiddle = down; break;
|
||||
case GHOST_kButtonMaskRight:
|
||||
m_ButtonRight = down; break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GHOST_Buttons::clear()
|
||||
{
|
||||
m_ButtonLeft = false;
|
||||
m_ButtonMiddle = false;
|
||||
m_ButtonRight = false;
|
||||
m_ButtonLeft = false;
|
||||
m_ButtonMiddle = false;
|
||||
m_ButtonRight = false;
|
||||
}
|
||||
|
||||
bool GHOST_Buttons::anyDown() const
|
||||
|
||||
@@ -21,13 +21,14 @@
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): Maarten Gribnau 05/2001
|
||||
* Damien Plisson 09/2009
|
||||
* Contributor(s): Maarten Gribnau 05/2001
|
||||
* Damien Plisson 09/2009
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file GHOST_SystemCocoa.h
|
||||
* @file GHOST_SystemCocoa.h
|
||||
* Declaration of GHOST_SystemCocoa class.
|
||||
*/
|
||||
|
||||
@@ -44,20 +45,20 @@ class GHOST_EventCursor;
|
||||
class GHOST_EventKey;
|
||||
class GHOST_EventWindow;
|
||||
class GHOST_WindowCocoa;
|
||||
|
||||
class NSAutoreleasePool; // actually Obj-C, but GHOST_ISystem.cpp doesn't understand @class syntax
|
||||
|
||||
class GHOST_SystemCocoa : public GHOST_System {
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
GHOST_SystemCocoa();
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~GHOST_SystemCocoa();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
GHOST_SystemCocoa();
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
~GHOST_SystemCocoa();
|
||||
|
||||
/***************************************************************************************
|
||||
** Time(r) functionality
|
||||
***************************************************************************************/
|
||||
@@ -68,7 +69,7 @@ public:
|
||||
* Based on ANSI clock() routine.
|
||||
* @return The number of milliseconds.
|
||||
*/
|
||||
virtual GHOST_TUns64 getMilliSeconds() const;
|
||||
GHOST_TUns64 getMilliSeconds() const;
|
||||
|
||||
/***************************************************************************************
|
||||
** Display/window management functionality
|
||||
@@ -78,31 +79,30 @@ public:
|
||||
* Returns the number of displays on this system.
|
||||
* @return The number of displays.
|
||||
*/
|
||||
virtual GHOST_TUns8 getNumDisplays() const;
|
||||
GHOST_TUns8 getNumDisplays() const;
|
||||
|
||||
/**
|
||||
* Returns the dimensions of the main display on this system.
|
||||
* @return The dimension of the main display.
|
||||
*/
|
||||
virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
|
||||
|
||||
void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
|
||||
|
||||
/**
|
||||
* Create a new window.
|
||||
* The new window is added to the list of windows managed.
|
||||
* The new window is added to the list of windows managed.
|
||||
* Never explicitly delete the window, use disposeWindow() instead.
|
||||
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
|
||||
* @param left The coordinate of the left edge of the window.
|
||||
* @param top The coordinate of the top edge of the window.
|
||||
* @param width The width the window.
|
||||
* @param height The height the window.
|
||||
* @param state The state of the window when opened.
|
||||
* @param type The type of drawing context installed in this window.
|
||||
* @param stereoVisual Stereo visual for quad buffered stereo.
|
||||
* @param numOfAASamples Number of samples used for AA (zero if no AA)
|
||||
* @param parentWindow Parent (embedder) window
|
||||
* @return The new window (or 0 if creation failed).
|
||||
* @param title The name of the window (displayed in the title bar of the window if the OS supports it).
|
||||
* @param left The coordinate of the left edge of the window.
|
||||
* @param top The coordinate of the top edge of the window.
|
||||
* @param width The width the window.
|
||||
* @param height The height the window.
|
||||
* @param state The state of the window when opened.
|
||||
* @param type The type of drawing context installed in this window.
|
||||
* @param stereoVisual Stereo visual for quad buffered stereo.
|
||||
* @param numOfAASamples Number of samples used for AA (zero if no AA)
|
||||
* @param parentWindow Parent (embedder) window
|
||||
* @return The new window (or 0 if creation failed).
|
||||
*/
|
||||
virtual GHOST_IWindow* createWindow(
|
||||
GHOST_IWindow* createWindow(
|
||||
const STR_String& title,
|
||||
GHOST_TInt32 left,
|
||||
GHOST_TInt32 top,
|
||||
@@ -114,166 +114,166 @@ public:
|
||||
const GHOST_TUns16 numOfAASamples = 0,
|
||||
const GHOST_TEmbedderWindowID parentWindow = 0
|
||||
);
|
||||
|
||||
virtual GHOST_TSuccess beginFullScreen(
|
||||
|
||||
GHOST_TSuccess beginFullScreen(
|
||||
const GHOST_DisplaySetting& setting,
|
||||
GHOST_IWindow** window,
|
||||
const bool stereoVisual
|
||||
);
|
||||
|
||||
virtual GHOST_TSuccess endFullScreen( void );
|
||||
|
||||
|
||||
GHOST_TSuccess endFullScreen( void );
|
||||
|
||||
/***************************************************************************************
|
||||
** Event management functionality
|
||||
***************************************************************************************/
|
||||
|
||||
/**
|
||||
* Gets events from the system and stores them in the queue.
|
||||
* @param waitForEvent Flag to wait for an event (or return immediately).
|
||||
* @return Indication of the presence of events.
|
||||
* @param waitForEvent Flag to wait for an event (or return immediately).
|
||||
* @return Indication of the presence of events.
|
||||
*/
|
||||
virtual bool processEvents(bool waitForEvent);
|
||||
|
||||
bool processEvents(bool waitForEvent);
|
||||
|
||||
/**
|
||||
* Handle User request to quit, from Menu bar Quit, and Cmd+Q
|
||||
* Display alert panel if changes performed since last save
|
||||
*/
|
||||
GHOST_TUns8 handleQuitRequest();
|
||||
|
||||
|
||||
/**
|
||||
* Handle Cocoa openFile event
|
||||
* Display confirmation request panel if changes performed since last save
|
||||
*/
|
||||
bool handleOpenDocumentRequest(void *filepathStr);
|
||||
|
||||
bool handleOpenDocumentRequest(void *filepathStr);
|
||||
|
||||
/**
|
||||
* Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
|
||||
* @param eventType The type of drag'n'drop event
|
||||
* @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image)
|
||||
* @param mouseX x mouse coordinate (in cocoa base window coordinates)
|
||||
* @param mouseY y mouse coordinate
|
||||
* @param window The window on which the event occurred
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
* Handles a drag'n'drop destination event. Called by GHOST_WindowCocoa window subclass
|
||||
* @param eventType The type of drag'n'drop event
|
||||
* @param draggedObjectType The type object concerned (currently array of file names, string, TIFF image)
|
||||
* @param mouseX x mouse coordinate (in cocoa base window coordinates)
|
||||
* @param mouseY y mouse coordinate
|
||||
* @param window The window on which the event occurred
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleDraggingEvent(GHOST_TEventType eventType, GHOST_TDragnDropTypes draggedObjectType,
|
||||
GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data);
|
||||
|
||||
GHOST_WindowCocoa* window, int mouseX, int mouseY, void* data);
|
||||
|
||||
/***************************************************************************************
|
||||
** Cursor management functionality
|
||||
***************************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the current location of the cursor (location in screen coordinates)
|
||||
* @param x The x-coordinate of the cursor.
|
||||
* @param y The y-coordinate of the cursor.
|
||||
* @return Indication of success.
|
||||
* @param x The x-coordinate of the cursor.
|
||||
* @param y The y-coordinate of the cursor.
|
||||
* @return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
|
||||
GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
|
||||
|
||||
/**
|
||||
* Updates the location of the cursor (location in screen coordinates).
|
||||
* @param x The x-coordinate of the cursor.
|
||||
* @param y The y-coordinate of the cursor.
|
||||
* @return Indication of success.
|
||||
* @param x The x-coordinate of the cursor.
|
||||
* @param y The y-coordinate of the cursor.
|
||||
* @return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
|
||||
|
||||
GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y);
|
||||
|
||||
/***************************************************************************************
|
||||
** Access to mouse button and keyboard states.
|
||||
***************************************************************************************/
|
||||
|
||||
/**
|
||||
* Returns the state of all modifier keys.
|
||||
* @param keys The state of all modifier keys (true == pressed).
|
||||
* @return Indication of success.
|
||||
* @param keys The state of all modifier keys (true == pressed).
|
||||
* @return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
|
||||
GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
|
||||
|
||||
/**
|
||||
* Returns the state of the mouse buttons (ouside the message queue).
|
||||
* @param buttons The state of the buttons.
|
||||
* @return Indication of success.
|
||||
* @param buttons The state of the buttons.
|
||||
* @return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
|
||||
GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
|
||||
|
||||
/**
|
||||
* Returns Clipboard data
|
||||
* @param selection Indicate which buffer to return
|
||||
* @return Returns the selected buffer
|
||||
* @param selection Indicate which buffer to return
|
||||
* @return Returns the selected buffer
|
||||
*/
|
||||
virtual GHOST_TUns8* getClipboard(bool selection) const;
|
||||
|
||||
GHOST_TUns8* getClipboard(bool selection) const;
|
||||
|
||||
/**
|
||||
* Puts buffer to system clipboard
|
||||
* @param buffer The buffer to be copied
|
||||
* @param selection Indicates which buffer to copy too, only used on X11
|
||||
* @param buffer The buffer to be copied
|
||||
* @param selection Indicates which buffer to copy too, only used on X11
|
||||
*/
|
||||
virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
|
||||
void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
|
||||
|
||||
/**
|
||||
* Determine the base dir in which shared resources are located. It will first try to use
|
||||
* "unpack and run" path, then look for properly installed path, not including versioning.
|
||||
* @return Unsigned char string pointing to system dir (eg /usr/share/blender/).
|
||||
*/
|
||||
virtual const GHOST_TUns8* getSystemDir() const;
|
||||
const GHOST_TUns8* getSystemDir() const;
|
||||
|
||||
/**
|
||||
* Determine the base dir in which user configuration is stored, not including versioning.
|
||||
* If needed, it will create the base directory.
|
||||
* @return Unsigned char string pointing to user dir (eg ~/.blender/).
|
||||
*/
|
||||
virtual const GHOST_TUns8* getUserDir() const;
|
||||
const GHOST_TUns8* getUserDir() const;
|
||||
|
||||
/**
|
||||
* Determine the directory of the current binary
|
||||
* @return Unsigned char string pointing to the binary dir
|
||||
*/
|
||||
virtual const GHOST_TUns8* getBinaryDir() const;
|
||||
* Determine the directory of the current binary
|
||||
* @return Unsigned char string pointing to the binary dir
|
||||
*/
|
||||
const GHOST_TUns8* getBinaryDir() const;
|
||||
|
||||
/**
|
||||
* Handles a window event. Called by GHOST_WindowCocoa window delegate
|
||||
* @param eventType The type of window event
|
||||
* @param window The window on which the event occurred
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window);
|
||||
* Handles a window event. Called by GHOST_WindowCocoa window delegate
|
||||
* @param eventType The type of window event
|
||||
* @param window The window on which the event occurred
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleWindowEvent(GHOST_TEventType eventType, GHOST_WindowCocoa* window);
|
||||
|
||||
/**
|
||||
* Handles the Cocoa event telling the application has become active (again)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleApplicationBecomeActiveEvent();
|
||||
* Handles the Cocoa event telling the application has become active (again)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleApplicationBecomeActiveEvent();
|
||||
|
||||
/**
|
||||
* External objects should call this when they send an event outside processEvents.
|
||||
*/
|
||||
* External objects should call this when they send an event outside processEvents.
|
||||
*/
|
||||
void notifyExternalEventProcessed();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Initializes the system.
|
||||
* For now, it justs registers the window class (WNDCLASS).
|
||||
* @return A success value.
|
||||
* @return A success value.
|
||||
*/
|
||||
virtual GHOST_TSuccess init();
|
||||
GHOST_TSuccess init();
|
||||
|
||||
/**
|
||||
* Handles a tablet pen event.
|
||||
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleTabletEvent(void *eventPtr);
|
||||
|
||||
/**
|
||||
* Helps handleTabletEvent function.
|
||||
*/
|
||||
/**
|
||||
* Handles a tablet pen event.
|
||||
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleTabletEvent(void *eventPtr);
|
||||
|
||||
/**
|
||||
* Helps handleTabletEvent function.
|
||||
*/
|
||||
void fillTabletData(GHOST_TabletData& tablet, void* event_ptr);
|
||||
|
||||
/**
|
||||
* Handles a tablet proximity event. Sets pen or mouse ID for later events.
|
||||
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
* Handles a tablet proximity event. Sets pen or mouse ID for later events.
|
||||
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleTabletProximity(void *eventPtr);
|
||||
|
||||
/** Tablet Mouse and Pen IDs, used to correlate events with the tool that caused them. */
|
||||
@@ -286,24 +286,24 @@ protected:
|
||||
GHOST_TTabletMode m_tablet_pen_mode;
|
||||
|
||||
/**
|
||||
* Handles a mouse event.
|
||||
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleMouseEvent(void *eventPtr);
|
||||
* Handles a mouse event.
|
||||
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleMouseEvent(void *eventPtr);
|
||||
|
||||
/**
|
||||
* Handles a key event.
|
||||
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleKeyEvent(void *eventPtr);
|
||||
|
||||
/**
|
||||
* Handles a key event.
|
||||
* @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
|
||||
* @return Indication whether the event was handled.
|
||||
*/
|
||||
GHOST_TSuccess handleKeyEvent(void *eventPtr);
|
||||
|
||||
/**
|
||||
* Performs the actual cursor position update (location in screen coordinates).
|
||||
* @param x The x-coordinate of the cursor.
|
||||
* @param y The y-coordinate of the cursor.
|
||||
* @return Indication of success.
|
||||
* @param x The x-coordinate of the cursor.
|
||||
* @param y The y-coordinate of the cursor.
|
||||
* @return Indication of success.
|
||||
*/
|
||||
GHOST_TSuccess setMouseCursorPosition(float x, float y);
|
||||
|
||||
@@ -313,29 +313,31 @@ protected:
|
||||
|
||||
/** Event has been processed directly by Cocoa (or NDOF manager) and has sent a ghost event to be dispatched */
|
||||
bool m_outsideLoopEventProcessed;
|
||||
|
||||
|
||||
/** Raised window is not yet known by the window manager, so delay application become active event handling */
|
||||
bool m_needDelayedApplicationBecomeActiveEventProcessing;
|
||||
|
||||
|
||||
/** Mouse buttons state */
|
||||
GHOST_TUns32 m_pressedMouseButtons;
|
||||
|
||||
/** State of the modifiers. */
|
||||
GHOST_TUns32 m_modifierMask;
|
||||
|
||||
/** Ignores window size messages (when window is dragged). */
|
||||
bool m_ignoreWindowSizedMessages;
|
||||
|
||||
/** State of the modifiers. */
|
||||
GHOST_TUns32 m_modifierMask;
|
||||
|
||||
/** Ignores window size messages (when window is dragged). */
|
||||
bool m_ignoreWindowSizedMessages;
|
||||
|
||||
/** Stores the mouse cursor delta due to setting a new cursor position
|
||||
* Needed because cocoa event delta cursor move takes setCursorPosition changes too.
|
||||
*/
|
||||
GHOST_TInt32 m_cursorDelta_x, m_cursorDelta_y;
|
||||
|
||||
|
||||
/** Multitouch trackpad availability */
|
||||
bool m_hasMultiTouchTrackpad;
|
||||
|
||||
|
||||
/** Multitouch gesture in progress, useful to distinguish trackpad from mouse scroll events */
|
||||
bool m_isGestureInProgress;
|
||||
|
||||
NSAutoreleasePool* m_pool;
|
||||
};
|
||||
|
||||
#endif // _GHOST_SYSTEM_COCOA_H_
|
||||
|
||||
@@ -466,19 +466,12 @@ extern "C" {
|
||||
struct bContext;
|
||||
struct wmOperator;
|
||||
extern int fromcocoa_request_qtcodec_settings(bContext *C, wmOperator *op);
|
||||
|
||||
|
||||
int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
|
||||
{
|
||||
int result;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
result = fromcocoa_request_qtcodec_settings(C, op);
|
||||
|
||||
[pool drain];
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
|
||||
{
|
||||
return fromcocoa_request_qtcodec_settings(C, op);
|
||||
}
|
||||
} // "C"
|
||||
#endif
|
||||
|
||||
|
||||
@@ -541,6 +534,8 @@ int cocoa_request_qtcodec_settings(bContext *C, wmOperator *op)
|
||||
|
||||
GHOST_SystemCocoa::GHOST_SystemCocoa()
|
||||
{
|
||||
m_pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
int mib[2];
|
||||
struct timeval boottime;
|
||||
size_t len;
|
||||
@@ -556,7 +551,7 @@ GHOST_SystemCocoa::GHOST_SystemCocoa()
|
||||
m_tablet_pen_mode = GHOST_kTabletModeNone;
|
||||
m_outsideLoopEventProcessed = false;
|
||||
m_needDelayedApplicationBecomeActiveEventProcessing = false;
|
||||
m_displayManager = new GHOST_DisplayManagerCocoa ();
|
||||
m_displayManager = new GHOST_DisplayManagerCocoa;
|
||||
GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): m_displayManager==0\n");
|
||||
m_displayManager->initialize();
|
||||
|
||||
@@ -602,7 +597,6 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
|
||||
|
||||
m_ndofManager = new GHOST_NDOFManagerCocoa(*this);
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
if (NSApp == nil) {
|
||||
[NSApplication sharedApplication];
|
||||
|
||||
@@ -666,8 +660,6 @@ GHOST_TSuccess GHOST_SystemCocoa::init()
|
||||
}
|
||||
|
||||
[NSApp finishLaunching];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
return success;
|
||||
}
|
||||
@@ -696,18 +688,12 @@ GHOST_TUns8 GHOST_SystemCocoa::getNumDisplays() const
|
||||
{
|
||||
//Note that OS X supports monitor hot plug
|
||||
// We do not support multiple monitors at the moment
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
GHOST_TUns8 count = [[NSScreen screens] count];
|
||||
|
||||
[pool drain];
|
||||
return count;
|
||||
return [[NSScreen screens] count];
|
||||
}
|
||||
|
||||
|
||||
void GHOST_SystemCocoa::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
//Get visible frame, that is frame excluding dock and top menu bar
|
||||
NSRect frame = [[NSScreen mainScreen] visibleFrame];
|
||||
|
||||
@@ -717,8 +703,6 @@ void GHOST_SystemCocoa::getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns
|
||||
|
||||
width = contentRect.size.width;
|
||||
height = contentRect.size.height;
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
|
||||
@@ -735,7 +719,6 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
|
||||
const GHOST_TEmbedderWindowID parentWindow
|
||||
)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
GHOST_IWindow* window = 0;
|
||||
|
||||
//Get the available rect for including window contents
|
||||
@@ -768,7 +751,6 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
|
||||
else {
|
||||
GHOST_PRINT("GHOST_SystemCocoa::createWindow(): could not create window\n");
|
||||
}
|
||||
[pool drain];
|
||||
return window;
|
||||
}
|
||||
|
||||
@@ -789,8 +771,6 @@ GHOST_TSuccess GHOST_SystemCocoa::endFullScreen(void)
|
||||
|
||||
return currentWindow->setState(GHOST_kWindowStateNormal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @note : returns coordinates in Cocoa screen coordinates
|
||||
@@ -835,7 +815,7 @@ GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(float xf, float yf)
|
||||
GHOST_WindowCocoa* window = (GHOST_WindowCocoa*)m_windowManager->getActiveWindow();
|
||||
if (!window) return GHOST_kFailure;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSScreen *windowScreen = window->getScreen();
|
||||
NSRect screenRect = [windowScreen frame];
|
||||
|
||||
@@ -848,7 +828,7 @@ GHOST_TSuccess GHOST_SystemCocoa::setMouseCursorPosition(float xf, float yf)
|
||||
|
||||
CGDisplayMoveCursorToPoint((CGDirectDisplayID)[[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf));
|
||||
|
||||
[pool drain];
|
||||
// [pool drain];
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -995,8 +975,6 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
|
||||
}
|
||||
} while (event != nil);
|
||||
|
||||
[pool drain];
|
||||
|
||||
if (m_needDelayedApplicationBecomeActiveEventProcessing)
|
||||
handleApplicationBecomeActiveEvent();
|
||||
|
||||
@@ -1005,6 +983,9 @@ bool GHOST_SystemCocoa::processEvents(bool waitForEvent)
|
||||
return true;
|
||||
}
|
||||
|
||||
[pool drain]; // for this event processing thread
|
||||
[m_pool drain]; // for main thread
|
||||
|
||||
return anyProcessed;
|
||||
}
|
||||
|
||||
@@ -1404,9 +1385,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletProximity(void *eventPtr)
|
||||
return GHOST_kFailure;
|
||||
}
|
||||
|
||||
// don't involve the window!
|
||||
// GHOST_TabletData& ct = window->GetCocoaTabletData();
|
||||
|
||||
GHOST_TTabletMode active_tool;
|
||||
int* tool_id_ptr;
|
||||
|
||||
@@ -1438,11 +1416,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletProximity(void *eventPtr)
|
||||
|
||||
m_tablet_pen_mode = active_tool;
|
||||
|
||||
// ct.Active = active_tool;
|
||||
// ct.Pressure = (active_tool == GHOST_kTabletModeNone) ? /*mouse*/ 1 : /*pen*/ 0;
|
||||
// ct.Xtilt = 0;
|
||||
// ct.Ytilt = 0;
|
||||
|
||||
// this is a good place to remember the tool's capabilities
|
||||
}
|
||||
else {
|
||||
@@ -1450,11 +1423,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletProximity(void *eventPtr)
|
||||
*tool_id_ptr = TOOL_ID_NONE;
|
||||
|
||||
m_tablet_pen_mode = GHOST_kTabletModeNone;
|
||||
|
||||
// ct.Active = GHOST_kTabletModeNone;
|
||||
// ct.Pressure = 0;
|
||||
// ct.Xtilt = 0;
|
||||
// ct.Ytilt = 0;
|
||||
}
|
||||
|
||||
return GHOST_kSuccess;
|
||||
@@ -1485,16 +1453,6 @@ GHOST_TSuccess GHOST_SystemCocoa::handleTabletEvent(void *eventPtr)
|
||||
return GHOST_kFailure;
|
||||
}
|
||||
|
||||
/*
|
||||
// don't involve the window!
|
||||
GHOST_TabletData& ct = window->GetCocoaTabletData();
|
||||
|
||||
ct.Pressure = [event pressure];
|
||||
NSPoint tilt = [event tilt];
|
||||
ct.Xtilt = tilt.x;
|
||||
ct.Ytilt = tilt.y;
|
||||
*/
|
||||
|
||||
switch ([event type])
|
||||
{
|
||||
case NSLeftMouseDown:
|
||||
@@ -1814,12 +1772,9 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
|
||||
GHOST_TUns8 * temp_buff;
|
||||
size_t pastedTextSize;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
|
||||
|
||||
if (pasteBoard == nil) {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1830,14 +1785,12 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
|
||||
availableTypeFromArray:supportedTypes];
|
||||
|
||||
if (bestType == nil) {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
NSString * textPasted = [pasteBoard stringForType:NSStringPboardType];
|
||||
|
||||
if (textPasted == nil) {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1846,7 +1799,6 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
|
||||
temp_buff = (GHOST_TUns8*) malloc(pastedTextSize+1);
|
||||
|
||||
if (temp_buff == NULL) {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1854,8 +1806,6 @@ GHOST_TUns8* GHOST_SystemCocoa::getClipboard(bool selection) const
|
||||
|
||||
temp_buff[pastedTextSize] = '\0';
|
||||
|
||||
[pool drain];
|
||||
|
||||
if(temp_buff) {
|
||||
return temp_buff;
|
||||
} else {
|
||||
@@ -1869,12 +1819,9 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
|
||||
|
||||
if(selection) {return;} // for copying the selection, used on X11
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
|
||||
|
||||
if (pasteBoard == nil) {
|
||||
[pool drain];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1885,8 +1832,6 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
|
||||
textToCopy = [NSString stringWithCString:buffer encoding:NSISOLatin1StringEncoding];
|
||||
|
||||
[pasteBoard setString:textToCopy forType:NSStringPboardType];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
#pragma mark Base directories retrieval
|
||||
@@ -1894,7 +1839,6 @@ void GHOST_SystemCocoa::putClipboard(GHOST_TInt8 *buffer, bool selection) const
|
||||
const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
|
||||
{
|
||||
static GHOST_TUns8 tempPath[512] = "";
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString *basePath;
|
||||
NSArray *paths;
|
||||
|
||||
@@ -1903,20 +1847,17 @@ const GHOST_TUns8* GHOST_SystemCocoa::getSystemDir() const
|
||||
if ([paths count] > 0)
|
||||
basePath = [paths objectAtIndex:0];
|
||||
else {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
|
||||
[pool drain];
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
|
||||
{
|
||||
static GHOST_TUns8 tempPath[512] = "";
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString *basePath;
|
||||
NSArray *paths;
|
||||
|
||||
@@ -1925,31 +1866,26 @@ const GHOST_TUns8* GHOST_SystemCocoa::getUserDir() const
|
||||
if ([paths count] > 0)
|
||||
basePath = [paths objectAtIndex:0];
|
||||
else {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
|
||||
[pool drain];
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
const GHOST_TUns8* GHOST_SystemCocoa::getBinaryDir() const
|
||||
{
|
||||
static GHOST_TUns8 tempPath[512] = "";
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString *basePath;
|
||||
|
||||
basePath = [[NSBundle mainBundle] bundlePath];
|
||||
|
||||
if (basePath == nil) {
|
||||
[pool drain];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strcpy((char*)tempPath, [basePath cStringUsingEncoding:NSASCIIStringEncoding]);
|
||||
|
||||
[pool drain];
|
||||
return tempPath;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file GHOST_WindowCocoa.h
|
||||
* Declaration of GHOST_WindowCocoa class.
|
||||
@@ -34,13 +35,14 @@
|
||||
#define _GHOST_WINDOW_COCOA_H_
|
||||
|
||||
#ifndef __APPLE__
|
||||
#error Apple OSX only!
|
||||
#endif // __APPLE__
|
||||
#error Apple OSX only!
|
||||
#endif
|
||||
|
||||
#include "GHOST_Window.h"
|
||||
#include "STR_String.h"
|
||||
|
||||
@class CocoaWindow;
|
||||
@class NSAutoreleasePool;
|
||||
|
||||
class GHOST_SystemCocoa;
|
||||
|
||||
@@ -52,8 +54,8 @@ class GHOST_SystemCocoa;
|
||||
* which is called the gutter.
|
||||
* When OpenGL contexts are active, GHOST will use AGL_BUFFER_RECT to prevent
|
||||
* OpenGL drawing outside the reduced client rectangle.
|
||||
* @author Maarten Gribnau
|
||||
* @date May 23, 2001
|
||||
* @author Maarten Gribnau
|
||||
* @date May 23, 2001
|
||||
*/
|
||||
class GHOST_WindowCocoa : public GHOST_Window {
|
||||
public:
|
||||
@@ -61,16 +63,16 @@ public:
|
||||
* Constructor.
|
||||
* Creates a new window and opens it.
|
||||
* To check if the window was created properly, use the getValid() method.
|
||||
* @param systemCocoa The associated system class to forward events to
|
||||
* @param title The text shown in the title bar of the window.
|
||||
* @param left The coordinate of the left edge of the window.
|
||||
* @param top The coordinate of the top edge of the window.
|
||||
* @param width The width the window.
|
||||
* @param height The height the window.
|
||||
* @param state The state the window is initially opened with.
|
||||
* @param type The type of drawing context installed in this window.
|
||||
* @param stereoVisual Stereo visual for quad buffered stereo.
|
||||
* @param numOfAASamples Number of samples used for AA (zero if no AA)
|
||||
* @param systemCocoa The associated system class to forward events to
|
||||
* @param title The text shown in the title bar of the window.
|
||||
* @param left The coordinate of the left edge of the window.
|
||||
* @param top The coordinate of the top edge of the window.
|
||||
* @param width The width the window.
|
||||
* @param height The height the window.
|
||||
* @param state The state the window is initially opened with.
|
||||
* @param type The type of drawing context installed in this window.
|
||||
* @param stereoVisual Stereo visual for quad buffered stereo.
|
||||
* @param numOfAASamples Number of samples used for AA (zero if no AA)
|
||||
*/
|
||||
GHOST_WindowCocoa(
|
||||
GHOST_SystemCocoa *systemCocoa,
|
||||
@@ -89,121 +91,121 @@ public:
|
||||
* Destructor.
|
||||
* Closes the window and disposes resources allocated.
|
||||
*/
|
||||
virtual ~GHOST_WindowCocoa();
|
||||
~GHOST_WindowCocoa();
|
||||
|
||||
/**
|
||||
* Returns indication as to whether the window is valid.
|
||||
* @return The validity of the window.
|
||||
*/
|
||||
virtual bool getValid() const;
|
||||
bool getValid() const;
|
||||
|
||||
/**
|
||||
* Returns the associated NSWindow object
|
||||
* @return The associated NSWindow object
|
||||
*/
|
||||
virtual void* getOSWindow() const;
|
||||
void* getOSWindow() const;
|
||||
|
||||
/**
|
||||
* Sets the title displayed in the title bar.
|
||||
* @param title The title to display in the title bar.
|
||||
*/
|
||||
virtual void setTitle(const STR_String& title);
|
||||
void setTitle(const STR_String& title);
|
||||
|
||||
/**
|
||||
* Returns the title displayed in the title bar.
|
||||
* @param title The title displayed in the title bar.
|
||||
*/
|
||||
virtual void getTitle(STR_String& title) const;
|
||||
void getTitle(STR_String& title) const;
|
||||
|
||||
/**
|
||||
* Returns the window rectangle dimensions.
|
||||
* The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
|
||||
* @param bounds The bounding rectangle of the window.
|
||||
*/
|
||||
virtual void getWindowBounds(GHOST_Rect& bounds) const;
|
||||
|
||||
void getWindowBounds(GHOST_Rect& bounds) const;
|
||||
|
||||
/**
|
||||
* Returns the client rectangle dimensions.
|
||||
* The left and top members of the rectangle are always zero.
|
||||
* @param bounds The bounding rectangle of the cleient area of the window.
|
||||
*/
|
||||
virtual void getClientBounds(GHOST_Rect& bounds) const;
|
||||
void getClientBounds(GHOST_Rect& bounds) const;
|
||||
|
||||
/**
|
||||
* Resizes client rectangle width.
|
||||
* @param width The new width of the client area of the window.
|
||||
*/
|
||||
virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
|
||||
GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
|
||||
|
||||
/**
|
||||
* Resizes client rectangle height.
|
||||
* @param height The new height of the client area of the window.
|
||||
*/
|
||||
virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
|
||||
GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
|
||||
|
||||
/**
|
||||
* Resizes client rectangle.
|
||||
* @param width The new width of the client area of the window.
|
||||
* @param height The new height of the client area of the window.
|
||||
* @param width The new width of the client area of the window.
|
||||
* @param height The new height of the client area of the window.
|
||||
*/
|
||||
virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
|
||||
GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
|
||||
|
||||
/**
|
||||
* Returns the state of the window (normal, minimized, maximized).
|
||||
* @return The state of the window.
|
||||
*/
|
||||
virtual GHOST_TWindowState getState() const;
|
||||
GHOST_TWindowState getState() const;
|
||||
|
||||
/**
|
||||
* Sets the window "modified" status, indicating unsaved changes
|
||||
* @param isUnsavedChanges Unsaved changes or not
|
||||
* @return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess setModifiedState(bool isUnsavedChanges);
|
||||
|
||||
/**
|
||||
* Converts a point in screen coordinates to client rectangle coordinates
|
||||
* @param inX The x-coordinate on the screen.
|
||||
* @param inY The y-coordinate on the screen.
|
||||
* @param outX The x-coordinate in the client rectangle.
|
||||
* @param outY The y-coordinate in the client rectangle.
|
||||
*/
|
||||
virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
|
||||
GHOST_TSuccess setModifiedState(bool isUnsavedChanges);
|
||||
|
||||
/**
|
||||
* Converts a point in screen coordinates to client rectangle coordinates
|
||||
* @param inX The x-coordinate in the client rectangle.
|
||||
* @param inY The y-coordinate in the client rectangle.
|
||||
* @param outX The x-coordinate on the screen.
|
||||
* @param outY The y-coordinate on the screen.
|
||||
* @param inX The x-coordinate on the screen.
|
||||
* @param inY The y-coordinate on the screen.
|
||||
* @param outX The x-coordinate in the client rectangle.
|
||||
* @param outY The y-coordinate in the client rectangle.
|
||||
*/
|
||||
virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
|
||||
void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
|
||||
|
||||
/**
|
||||
* Converts a point in screen coordinates to client rectangle coordinates
|
||||
* @param inX The x-coordinate in the client rectangle.
|
||||
* @param inY The y-coordinate in the client rectangle.
|
||||
* @param outX The x-coordinate on the screen.
|
||||
* @param outY The y-coordinate on the screen.
|
||||
*/
|
||||
void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
|
||||
|
||||
/**
|
||||
* Gets the screen the window is displayed in
|
||||
* @return The NSScreen object
|
||||
*/
|
||||
NSScreen* getScreen();
|
||||
|
||||
|
||||
/**
|
||||
* Sets the state of the window (normal, minimized, maximized).
|
||||
* @param state The state of the window.
|
||||
* @return Indication of success.
|
||||
* @param state The state of the window.
|
||||
* @return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess setState(GHOST_TWindowState state);
|
||||
GHOST_TSuccess setState(GHOST_TWindowState state);
|
||||
|
||||
/**
|
||||
* Sets the order of the window (bottom, top).
|
||||
* @param order The order of the window.
|
||||
* @return Indication of success.
|
||||
* @param order The order of the window.
|
||||
* @return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
|
||||
GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
|
||||
|
||||
/**
|
||||
* Swaps front and back buffers of a window.
|
||||
* @return A boolean success indicator.
|
||||
* @return A boolean success indicator.
|
||||
*/
|
||||
virtual GHOST_TSuccess swapBuffers();
|
||||
GHOST_TSuccess swapBuffers();
|
||||
|
||||
/**
|
||||
* Updates the drawing context of this window. Needed
|
||||
@@ -216,87 +218,84 @@ public:
|
||||
* Activates the drawing context of this window.
|
||||
* @return A boolean success indicator.
|
||||
*/
|
||||
virtual GHOST_TSuccess activateDrawingContext();
|
||||
GHOST_TSuccess activateDrawingContext();
|
||||
|
||||
virtual void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
|
||||
|
||||
|
||||
const GHOST_TabletData* GetTabletData()
|
||||
{ return NULL; }
|
||||
void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
|
||||
|
||||
/**
|
||||
* Sets the progress bar value displayed in the window/application icon
|
||||
* @param progress The progress % (0.0 to 1.0)
|
||||
* @param progress The progress % (0.0 to 1.0)
|
||||
*/
|
||||
virtual GHOST_TSuccess setProgressBar(float progress);
|
||||
|
||||
GHOST_TSuccess setProgressBar(float progress);
|
||||
|
||||
/**
|
||||
* Hides the progress bar icon
|
||||
*/
|
||||
virtual GHOST_TSuccess endProgressBar();
|
||||
GHOST_TSuccess endProgressBar();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Tries to install a rendering context in this window.
|
||||
* @param type The type of rendering context installed.
|
||||
* @return Indication as to whether installation has succeeded.
|
||||
* @param type The type of rendering context installed.
|
||||
* @return Indication as to whether installation has succeeded.
|
||||
*/
|
||||
virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
|
||||
GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
|
||||
|
||||
/**
|
||||
* Removes the current drawing context.
|
||||
* @return Indication as to whether removal has succeeded.
|
||||
* @return Indication as to whether removal has succeeded.
|
||||
*/
|
||||
virtual GHOST_TSuccess removeDrawingContext();
|
||||
GHOST_TSuccess removeDrawingContext();
|
||||
|
||||
/**
|
||||
* Invalidates the contents of this window.
|
||||
* @return Indication of success.
|
||||
* @return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess invalidate();
|
||||
GHOST_TSuccess invalidate();
|
||||
|
||||
/**
|
||||
* Sets the cursor visibility on the window using
|
||||
* native window system calls.
|
||||
*/
|
||||
virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
|
||||
|
||||
GHOST_TSuccess setWindowCursorVisibility(bool visible);
|
||||
|
||||
/**
|
||||
* Sets the cursor grab on the window using
|
||||
* native window system calls.
|
||||
*/
|
||||
virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
|
||||
|
||||
/**
|
||||
* Sets the cursor shape on the window using
|
||||
* native window system calls.
|
||||
*/
|
||||
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
|
||||
GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode);
|
||||
|
||||
/**
|
||||
* Sets the cursor shape on the window using
|
||||
* native window system calls.
|
||||
*/
|
||||
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
|
||||
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
|
||||
|
||||
virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
|
||||
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
|
||||
|
||||
/**
|
||||
* Sets the cursor shape on the window using
|
||||
* native window system calls.
|
||||
*/
|
||||
GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
|
||||
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
|
||||
|
||||
GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
|
||||
|
||||
/** The window containing the OpenGL view */
|
||||
CocoaWindow *m_window;
|
||||
|
||||
/** The openGL view */
|
||||
/** The window containing the OpenGL view */
|
||||
CocoaWindow *m_window;
|
||||
|
||||
/** The OpenGL view */
|
||||
NSOpenGLView *m_openGLView;
|
||||
|
||||
/** The opgnGL drawing context */
|
||||
/** The OpenGL drawing context */
|
||||
NSOpenGLContext *m_openGLContext;
|
||||
|
||||
/** The mother SystemCocoa class to send events */
|
||||
GHOST_SystemCocoa *m_systemCocoa;
|
||||
|
||||
|
||||
/** The first created OpenGL context (for sharing display lists) */
|
||||
static NSOpenGLContext *s_firstOpenGLcontext;
|
||||
|
||||
NSCursor* m_customCursor;
|
||||
|
||||
/** The mother SystemCocoa class to send events */
|
||||
GHOST_SystemCocoa *m_ghostSystem;
|
||||
|
||||
NSCursor* m_customCursor;
|
||||
};
|
||||
|
||||
#endif // _GHOST_WINDOW_COCOA_H_
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
*
|
||||
* The Original Code is: all of this file.
|
||||
*
|
||||
* Contributor(s): Maarten Gribnau 05/2001
|
||||
Damien Plisson 10/2009
|
||||
* Contributor(s): Maarten Gribnau 05/2001
|
||||
Damien Plisson 10/2009
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
@@ -30,15 +30,11 @@
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#ifndef MAC_OS_X_VERSION_10_6
|
||||
//Use of the SetSystemUIMode function (64bit compatible)
|
||||
#include <Carbon/Carbon.h>
|
||||
//Use of the SetSystemUIMode function (64bit compatible)
|
||||
#include <Carbon/Carbon.h>
|
||||
#endif
|
||||
|
||||
#include <OpenGL/gl.h>
|
||||
/***** Multithreaded opengl code : uncomment for enabling
|
||||
#include <OpenGL/OpenGL.h>
|
||||
*/
|
||||
|
||||
|
||||
#include "GHOST_WindowCocoa.h"
|
||||
#include "GHOST_SystemCocoa.h"
|
||||
@@ -56,17 +52,18 @@ extern "C" {
|
||||
extern void wm_event_do_handlers(bContext *C);
|
||||
extern void wm_event_do_notifiers(bContext *C);
|
||||
extern void wm_draw_update(bContext *C);
|
||||
};*/
|
||||
}*/
|
||||
|
||||
@interface CocoaWindowDelegate : NSObject
|
||||
#ifdef MAC_OS_X_VERSION_10_6
|
||||
<NSWindowDelegate>
|
||||
<NSWindowDelegate>
|
||||
#endif
|
||||
{
|
||||
GHOST_SystemCocoa *systemCocoa;
|
||||
GHOST_WindowCocoa *associatedWindow;
|
||||
GHOST_SystemCocoa *ghostSystem;
|
||||
GHOST_WindowCocoa *ghostWindow;
|
||||
}
|
||||
|
||||
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
|
||||
- (void)setSystem:(GHOST_SystemCocoa *)sysCocoa ghostWindow:(GHOST_WindowCocoa *)winCocoa;
|
||||
- (void)windowWillClose:(NSNotification *)notification;
|
||||
- (void)windowDidBecomeKey:(NSNotification *)notification;
|
||||
- (void)windowDidResignKey:(NSNotification *)notification;
|
||||
@@ -77,40 +74,40 @@ extern "C" {
|
||||
@end
|
||||
|
||||
@implementation CocoaWindowDelegate : NSObject
|
||||
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
|
||||
- (void)setSystem:(GHOST_SystemCocoa *)sys ghostWindow:(GHOST_WindowCocoa *)win
|
||||
{
|
||||
systemCocoa = sysCocoa;
|
||||
associatedWindow = winCocoa;
|
||||
ghostSystem = sys;
|
||||
ghostWindow = win;
|
||||
}
|
||||
|
||||
- (void)windowWillClose:(NSNotification *)notification
|
||||
{
|
||||
systemCocoa->handleWindowEvent(GHOST_kEventWindowClose, associatedWindow);
|
||||
ghostSystem->handleWindowEvent(GHOST_kEventWindowClose, ghostWindow);
|
||||
}
|
||||
|
||||
- (void)windowDidBecomeKey:(NSNotification *)notification
|
||||
{
|
||||
systemCocoa->handleWindowEvent(GHOST_kEventWindowActivate, associatedWindow);
|
||||
ghostSystem->handleWindowEvent(GHOST_kEventWindowActivate, ghostWindow);
|
||||
}
|
||||
|
||||
- (void)windowDidResignKey:(NSNotification *)notification
|
||||
{
|
||||
systemCocoa->handleWindowEvent(GHOST_kEventWindowDeactivate, associatedWindow);
|
||||
ghostSystem->handleWindowEvent(GHOST_kEventWindowDeactivate, ghostWindow);
|
||||
}
|
||||
|
||||
- (void)windowDidExpose:(NSNotification *)notification
|
||||
{
|
||||
systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);
|
||||
ghostSystem->handleWindowEvent(GHOST_kEventWindowUpdate, ghostWindow);
|
||||
}
|
||||
|
||||
- (void)windowDidMove:(NSNotification *)notification
|
||||
{
|
||||
systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
|
||||
ghostSystem->handleWindowEvent(GHOST_kEventWindowMove, ghostWindow);
|
||||
}
|
||||
|
||||
- (void)windowWillMove:(NSNotification *)notification
|
||||
{
|
||||
systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
|
||||
ghostSystem->handleWindowEvent(GHOST_kEventWindowMove, ghostWindow);
|
||||
}
|
||||
|
||||
- (void)windowDidResize:(NSNotification *)notification
|
||||
@@ -119,13 +116,13 @@ extern "C" {
|
||||
//if (![[notification object] inLiveResize]) {
|
||||
//Send event only once, at end of resize operation (when user has released mouse button)
|
||||
#endif
|
||||
systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, associatedWindow);
|
||||
ghostSystem->handleWindowEvent(GHOST_kEventWindowSize, ghostWindow);
|
||||
#ifdef MAC_OS_X_VERSION_10_6
|
||||
//}
|
||||
#endif
|
||||
/* Live resize ugly patch. Needed because live resize runs in a modal loop, not letting main loop run
|
||||
if ([[notification object] inLiveResize]) {
|
||||
systemCocoa->dispatchEvents();
|
||||
if ([[notification object] inLiveResize]) {
|
||||
ghostSystem->dispatchEvents();
|
||||
wm_window_timer(ghostC);
|
||||
wm_event_do_handlers(ghostC);
|
||||
wm_event_do_notifiers(ghostC);
|
||||
@@ -138,17 +135,17 @@ extern "C" {
|
||||
//We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events)
|
||||
@interface CocoaWindow: NSWindow
|
||||
{
|
||||
GHOST_SystemCocoa *systemCocoa;
|
||||
GHOST_WindowCocoa *associatedWindow;
|
||||
GHOST_SystemCocoa *ghostSystem;
|
||||
GHOST_WindowCocoa *ghostWindow;
|
||||
GHOST_TDragnDropTypes m_draggedObjectType;
|
||||
}
|
||||
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
|
||||
- (void)setSystem:(GHOST_SystemCocoa *)sys ghostWindow:(GHOST_WindowCocoa *)win;
|
||||
@end
|
||||
@implementation CocoaWindow
|
||||
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
|
||||
- (void)setSystem:(GHOST_SystemCocoa *)sys ghostWindow:(GHOST_WindowCocoa *)win
|
||||
{
|
||||
systemCocoa = sysCocoa;
|
||||
associatedWindow = winCocoa;
|
||||
ghostSystem = sys;
|
||||
ghostWindow = win;
|
||||
}
|
||||
|
||||
-(BOOL)canBecomeKeyWindow
|
||||
@@ -162,13 +159,18 @@ extern "C" {
|
||||
NSPoint mouseLocation = [sender draggingLocation];
|
||||
NSPasteboard *draggingPBoard = [sender draggingPasteboard];
|
||||
|
||||
if ([[draggingPBoard types] containsObject:NSTIFFPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeBitmap;
|
||||
else if ([[draggingPBoard types] containsObject:NSFilenamesPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeFilenames;
|
||||
else if ([[draggingPBoard types] containsObject:NSStringPboardType]) m_draggedObjectType = GHOST_kDragnDropTypeString;
|
||||
else return NSDragOperationNone;
|
||||
if ([[draggingPBoard types] containsObject:NSTIFFPboardType])
|
||||
m_draggedObjectType = GHOST_kDragnDropTypeBitmap;
|
||||
else if ([[draggingPBoard types] containsObject:NSFilenamesPboardType])
|
||||
m_draggedObjectType = GHOST_kDragnDropTypeFilenames;
|
||||
else if ([[draggingPBoard types] containsObject:NSStringPboardType])
|
||||
m_draggedObjectType = GHOST_kDragnDropTypeString;
|
||||
else
|
||||
return NSDragOperationNone;
|
||||
|
||||
ghostWindow->setAcceptDragOperation(TRUE); //Drag operation is accepted by default
|
||||
ghostSystem->handleDraggingEvent(GHOST_kEventDraggingEntered, m_draggedObjectType, ghostWindow, mouseLocation.x, mouseLocation.y, nil);
|
||||
|
||||
associatedWindow->setAcceptDragOperation(TRUE); //Drag operation is accepted by default
|
||||
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingEntered, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil);
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
|
||||
@@ -181,22 +183,19 @@ extern "C" {
|
||||
{
|
||||
NSPoint mouseLocation = [sender draggingLocation];
|
||||
|
||||
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingUpdated, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil);
|
||||
return associatedWindow->canAcceptDragOperation()?NSDragOperationCopy:NSDragOperationNone;
|
||||
ghostSystem->handleDraggingEvent(GHOST_kEventDraggingUpdated, m_draggedObjectType, ghostWindow, mouseLocation.x, mouseLocation.y, nil);
|
||||
return ghostWindow->canAcceptDragOperation()?NSDragOperationCopy:NSDragOperationNone;
|
||||
}
|
||||
|
||||
- (void)draggingExited:(id < NSDraggingInfo >)sender
|
||||
{
|
||||
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingExited, m_draggedObjectType, associatedWindow, 0, 0, nil);
|
||||
ghostSystem->handleDraggingEvent(GHOST_kEventDraggingExited, m_draggedObjectType, ghostWindow, 0, 0, nil);
|
||||
m_draggedObjectType = GHOST_kDragnDropTypeUnknown;
|
||||
}
|
||||
|
||||
- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender
|
||||
{
|
||||
if (associatedWindow->canAcceptDragOperation())
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
return ghostWindow->canAcceptDragOperation();
|
||||
}
|
||||
|
||||
- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender
|
||||
@@ -224,7 +223,7 @@ extern "C" {
|
||||
return NO;
|
||||
break;
|
||||
}
|
||||
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingDropDone, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, (void*)data);
|
||||
ghostSystem->handleDraggingEvent(GHOST_kEventDraggingDropDone, m_draggedObjectType, ghostWindow, mouseLocation.x, mouseLocation.y, (void*)data);
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -234,11 +233,11 @@ extern "C" {
|
||||
|
||||
#pragma mark NSOpenGLView subclass
|
||||
//We need to subclass it in order to give Cocoa the feeling key events are trapped
|
||||
@interface CocoaOpenGLView : NSOpenGLView
|
||||
@interface BlenderGLView : NSOpenGLView
|
||||
{
|
||||
}
|
||||
@end
|
||||
@implementation CocoaOpenGLView
|
||||
@implementation BlenderGLView
|
||||
|
||||
- (BOOL)acceptsFirstResponder
|
||||
{
|
||||
@@ -288,7 +287,7 @@ extern "C" {
|
||||
NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;
|
||||
|
||||
GHOST_WindowCocoa::GHOST_WindowCocoa(
|
||||
GHOST_SystemCocoa *systemCocoa,
|
||||
GHOST_SystemCocoa *ghostSystem,
|
||||
const STR_String& title,
|
||||
GHOST_TInt32 left,
|
||||
GHOST_TInt32 top,
|
||||
@@ -297,48 +296,43 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
|
||||
GHOST_TWindowState state,
|
||||
GHOST_TDrawingContextType type,
|
||||
const bool stereoVisual, const GHOST_TUns16 numOfAASamples
|
||||
) :
|
||||
GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual, numOfAASamples),
|
||||
m_customCursor(0)
|
||||
)
|
||||
: GHOST_Window(title, left, top, width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual, numOfAASamples)
|
||||
, m_ghostSystem(ghostSystem)
|
||||
, m_customCursor(0)
|
||||
{
|
||||
NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[40];
|
||||
NSOpenGLPixelFormat *pixelFormat = nil;
|
||||
int i;
|
||||
// m_pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
m_systemCocoa = systemCocoa;
|
||||
m_fullScreen = false;
|
||||
|
||||
NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[20];
|
||||
NSOpenGLPixelFormat *pixelFormat = nil;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
//Creates the window
|
||||
NSRect rect;
|
||||
NSSize minSize;
|
||||
|
||||
rect.origin.x = left;
|
||||
rect.origin.y = top;
|
||||
rect.size.width = width;
|
||||
rect.size.height = height;
|
||||
NSRect rect = NSMakeRect(left,top,width,height);
|
||||
|
||||
m_window = [[CocoaWindow alloc] initWithContentRect:rect
|
||||
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask
|
||||
backing:NSBackingStoreBuffered defer:NO];
|
||||
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask
|
||||
backing:NSBackingStoreBuffered defer:NO];
|
||||
if (m_window == nil) {
|
||||
[pool drain];
|
||||
return;
|
||||
}
|
||||
|
||||
[m_window setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
|
||||
[m_window setSystemAndWindowCocoa:ghostSystem windowCocoa:this];
|
||||
|
||||
//Forbid to resize the window below the blender defined minimum one
|
||||
minSize.width = 320;
|
||||
minSize.height = 240;
|
||||
[m_window setContentMinSize:minSize];
|
||||
// Forbid to resize the window below the blender defined minimum one
|
||||
[m_window setContentMinSize:NSMakeSize(320,240)];
|
||||
|
||||
// simplify drawing since each window contains only our OpenGL view
|
||||
[m_window useOptimizedDrawing:YES];
|
||||
|
||||
setTitle(title);
|
||||
|
||||
|
||||
// Pixel Format Attributes for the windowed NSOpenGLContext
|
||||
i=0;
|
||||
int i = 0;
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
|
||||
|
||||
// Guarantees the back buffer contents to be valid after a call to NSOpenGLContext object’s flushBuffer
|
||||
@@ -346,14 +340,14 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore;
|
||||
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
|
||||
//pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,; // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
|
||||
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFADepthSize;
|
||||
pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
|
||||
|
||||
|
||||
if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
|
||||
|
||||
int firstMultiSampleAttribute = i;
|
||||
|
||||
if (numOfAASamples>0) {
|
||||
// Multisample anti-aliasing
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFAMultisample;
|
||||
@@ -374,25 +368,8 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
|
||||
|
||||
//Fall back to no multisampling if Antialiasing init failed
|
||||
if (pixelFormat == nil) {
|
||||
i=0;
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
|
||||
|
||||
// Guarantees the back buffer contents to be valid after a call to NSOpenGLContext object’s flushBuffer
|
||||
// needed for 'Draw Overlap' drawing method
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore;
|
||||
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
|
||||
//pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,; // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
|
||||
|
||||
pixelFormatAttrsWindow[i++] = NSOpenGLPFADepthSize;
|
||||
pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
|
||||
|
||||
if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
|
||||
|
||||
pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
|
||||
|
||||
pixelFormatAttrsWindow[firstMultiSampleAttribute] = (NSOpenGLPixelFormatAttribute) 0;
|
||||
pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
|
||||
|
||||
}
|
||||
|
||||
if (numOfAASamples>0) { //Set m_numOfAASamples to the actual value
|
||||
@@ -405,8 +382,7 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
|
||||
}
|
||||
|
||||
//Creates the OpenGL View inside the window
|
||||
m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect
|
||||
pixelFormat:pixelFormat];
|
||||
m_openGLView = [[BlenderGLView alloc] initWithFrame:rect pixelFormat:pixelFormat];
|
||||
|
||||
[pixelFormat release];
|
||||
|
||||
@@ -424,13 +400,13 @@ GHOST_WindowCocoa::GHOST_WindowCocoa(
|
||||
activateDrawingContext();
|
||||
|
||||
CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];
|
||||
[windowDelegate setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
|
||||
[windowDelegate setSystemAndWindowCocoa:ghostSystem windowCocoa:this];
|
||||
[m_window setDelegate:windowDelegate];
|
||||
|
||||
[m_window setAcceptsMouseMovedEvents:YES];
|
||||
|
||||
[m_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
|
||||
NSStringPboardType, NSTIFFPboardType, nil]];
|
||||
[m_window registerForDraggedTypes:[NSArray arrayWithObjects:
|
||||
NSFilenamesPboardType, NSStringPboardType, NSTIFFPboardType, nil]];
|
||||
|
||||
if (state == GHOST_kWindowStateFullScreen)
|
||||
setState(GHOST_kWindowStateFullScreen);
|
||||
@@ -443,7 +419,7 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
|
||||
{
|
||||
if (m_customCursor) delete m_customCursor;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
[m_openGLView release];
|
||||
|
||||
if (m_window) {
|
||||
@@ -458,7 +434,8 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
|
||||
if ([windowsList count]) {
|
||||
[[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
|
||||
}
|
||||
[pool drain];
|
||||
|
||||
// [pool drain];
|
||||
}
|
||||
|
||||
#pragma mark accessors
|
||||
@@ -479,21 +456,18 @@ void GHOST_WindowCocoa::setTitle(const STR_String& title)
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSString *windowTitle = [[NSString alloc] initWithUTF8String:title];
|
||||
|
||||
|
||||
//Set associated file if applicable
|
||||
if ([windowTitle hasPrefix:@"Blender"])
|
||||
{
|
||||
NSRange fileStrRange;
|
||||
NSString *associatedFileName;
|
||||
int len;
|
||||
|
||||
|
||||
fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;
|
||||
len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;
|
||||
|
||||
if (len >0)
|
||||
{
|
||||
int len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;
|
||||
|
||||
if (len >0) {
|
||||
fileStrRange.length = len;
|
||||
associatedFileName = [windowTitle substringWithRange:fileStrRange];
|
||||
NSString* associatedFileName = [windowTitle substringWithRange:fileStrRange];
|
||||
@try {
|
||||
[m_window setRepresentedFilename:associatedFileName];
|
||||
}
|
||||
@@ -506,13 +480,11 @@ void GHOST_WindowCocoa::setTitle(const STR_String& title)
|
||||
[m_window setTitle:windowTitle];
|
||||
[m_window setRepresentedFilename:@""];
|
||||
}
|
||||
|
||||
} else {
|
||||
[m_window setTitle:windowTitle];
|
||||
[m_window setRepresentedFilename:@""];
|
||||
}
|
||||
|
||||
|
||||
[windowTitle release];
|
||||
[pool drain];
|
||||
}
|
||||
@@ -520,16 +492,20 @@ void GHOST_WindowCocoa::setTitle(const STR_String& title)
|
||||
|
||||
void GHOST_WindowCocoa::getTitle(STR_String& title) const
|
||||
{
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid")
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
/*
|
||||
NSString *windowTitle = [m_window title];
|
||||
|
||||
if (windowTitle != nil) {
|
||||
title = [windowTitle UTF8String];
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
title = [[m_window title] UTF8String];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
@@ -539,8 +515,6 @@ void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const
|
||||
NSRect rect;
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid")
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSRect screenSize = [[m_window screen] visibleFrame];
|
||||
|
||||
rect = [m_window frame];
|
||||
@@ -549,28 +523,23 @@ void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const
|
||||
bounds.m_l = rect.origin.x -screenSize.origin.x;
|
||||
bounds.m_r = rect.origin.x-screenSize.origin.x + rect.size.width;
|
||||
bounds.m_t = screenSize.size.height - (rect.origin.y + rect.size.height -screenSize.origin.y);
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
|
||||
void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const
|
||||
{
|
||||
NSRect rect;
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid")
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
if (!m_fullScreen)
|
||||
{
|
||||
NSRect screenSize = [[m_window screen] visibleFrame];
|
||||
|
||||
//Max window contents as screen size (excluding title bar...)
|
||||
NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize
|
||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
|
||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
|
||||
|
||||
NSRect rect = [m_window contentRectForFrameRect:[m_window frame]];
|
||||
|
||||
rect = [m_window contentRectForFrameRect:[m_window frame]];
|
||||
|
||||
bounds.m_b = contentRect.size.height - (rect.origin.y -contentRect.origin.y);
|
||||
bounds.m_l = rect.origin.x -contentRect.origin.x;
|
||||
bounds.m_r = rect.origin.x-contentRect.origin.x + rect.size.width;
|
||||
@@ -578,20 +547,19 @@ void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const
|
||||
}
|
||||
else {
|
||||
NSRect screenSize = [[m_window screen] frame];
|
||||
|
||||
|
||||
bounds.m_b = screenSize.origin.y + screenSize.size.height;
|
||||
bounds.m_l = screenSize.origin.x;
|
||||
bounds.m_r = screenSize.origin.x + screenSize.size.width;
|
||||
bounds.m_t = screenSize.origin.y;
|
||||
}
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)
|
||||
{
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid")
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
GHOST_Rect cBnds, wBnds;
|
||||
getClientBounds(cBnds);
|
||||
if (((GHOST_TUns32)cBnds.getWidth()) != width) {
|
||||
@@ -600,7 +568,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)
|
||||
size.height=cBnds.getHeight();
|
||||
[m_window setContentSize:size];
|
||||
}
|
||||
[pool drain];
|
||||
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -608,7 +576,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)
|
||||
{
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid")
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
GHOST_Rect cBnds, wBnds;
|
||||
getClientBounds(cBnds);
|
||||
if (((GHOST_TUns32)cBnds.getHeight()) != height) {
|
||||
@@ -617,7 +585,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)
|
||||
size.height=height;
|
||||
[m_window setContentSize:size];
|
||||
}
|
||||
[pool drain];
|
||||
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -625,7 +593,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)
|
||||
{
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid")
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
GHOST_Rect cBnds, wBnds;
|
||||
getClientBounds(cBnds);
|
||||
if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||
|
||||
@@ -635,7 +603,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32
|
||||
size.height=height;
|
||||
[m_window setContentSize:size];
|
||||
}
|
||||
[pool drain];
|
||||
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -665,15 +633,11 @@ GHOST_TWindowState GHOST_WindowCocoa::getState() const
|
||||
void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
|
||||
{
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid")
|
||||
|
||||
NSPoint screenCoord;
|
||||
NSPoint baseCoord;
|
||||
|
||||
screenCoord.x = inX;
|
||||
screenCoord.y = inY;
|
||||
|
||||
baseCoord = [m_window convertScreenToBase:screenCoord];
|
||||
|
||||
|
||||
NSPoint screenCoord = {inX, inY};
|
||||
|
||||
NSPoint baseCoord = [m_window convertScreenToBase:screenCoord];
|
||||
|
||||
outX = baseCoord.x;
|
||||
outY = baseCoord.y;
|
||||
}
|
||||
@@ -682,15 +646,11 @@ void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST
|
||||
void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
|
||||
{
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid")
|
||||
|
||||
NSPoint screenCoord;
|
||||
NSPoint baseCoord;
|
||||
|
||||
baseCoord.x = inX;
|
||||
baseCoord.y = inY;
|
||||
|
||||
screenCoord = [m_window convertBaseToScreen:baseCoord];
|
||||
|
||||
|
||||
NSPoint baseCoord = {inX, inY};
|
||||
|
||||
NSPoint screenCoord = [m_window convertBaseToScreen:baseCoord];
|
||||
|
||||
outX = screenCoord.x;
|
||||
outY = screenCoord.y;
|
||||
}
|
||||
@@ -710,19 +670,18 @@ NSScreen* GHOST_WindowCocoa::getScreen()
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
|
||||
{
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid")
|
||||
switch (state) {
|
||||
switch (state) {
|
||||
case GHOST_kWindowStateMinimized:
|
||||
[m_window miniaturize:nil];
|
||||
break;
|
||||
[m_window miniaturize:nil];
|
||||
break;
|
||||
case GHOST_kWindowStateMaximized:
|
||||
[m_window zoom:nil];
|
||||
break;
|
||||
|
||||
case GHOST_kWindowStateFullScreen:
|
||||
if (!m_fullScreen)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
//This status change needs to be done before Cocoa call to enter fullscreen mode
|
||||
//to give window delegate hint not to forward its deactivation to ghost wm that doesn't know view/window difference
|
||||
m_fullScreen = true;
|
||||
@@ -759,10 +718,10 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
|
||||
[tmpWindow setReleasedWhenClosed:NO];
|
||||
[tmpWindow setAcceptsMouseMovedEvents:YES];
|
||||
[tmpWindow setDelegate:[m_window delegate]];
|
||||
|
||||
|
||||
//Assign the openGL view to the new window
|
||||
[tmpWindow setContentView:m_openGLView];
|
||||
|
||||
|
||||
//Show the new window
|
||||
[tmpWindow makeKeyAndOrderFront:nil];
|
||||
//Close and release old window
|
||||
@@ -771,10 +730,9 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
|
||||
[m_window release];
|
||||
m_window = tmpWindow;
|
||||
#endif
|
||||
|
||||
//Tell WM of view new size
|
||||
m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
|
||||
|
||||
m_ghostSystem->handleWindowEvent(GHOST_kEventWindowSize, this);
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
break;
|
||||
@@ -807,20 +765,20 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
|
||||
}
|
||||
//Create a fullscreen borderless window
|
||||
CocoaWindow *tmpWindow = [[CocoaWindow alloc]
|
||||
initWithContentRect:[[m_window screen] frame]
|
||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES];
|
||||
initWithContentRect:[[m_window screen] frame]
|
||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES];
|
||||
//Copy current window parameters
|
||||
[tmpWindow setTitle:[m_window title]];
|
||||
[tmpWindow setRepresentedFilename:[m_window representedFilename]];
|
||||
[tmpWindow setReleasedWhenClosed:NO];
|
||||
[tmpWindow setAcceptsMouseMovedEvents:YES];
|
||||
[tmpWindow setDelegate:[m_window delegate]];
|
||||
|
||||
|
||||
//Assign the openGL view to the new window
|
||||
[tmpWindow setContentView:m_openGLView];
|
||||
|
||||
|
||||
//Show the new window
|
||||
[tmpWindow makeKeyAndOrderFront:nil];
|
||||
//Close and release old window
|
||||
@@ -829,53 +787,51 @@ GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
|
||||
[m_window release];
|
||||
m_window = tmpWindow;
|
||||
#endif
|
||||
|
||||
//Tell WM of view new size
|
||||
m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
|
||||
|
||||
m_ghostSystem->handleWindowEvent(GHOST_kEventWindowSize, this);
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
else if ([m_window isMiniaturized])
|
||||
else if ([m_window isMiniaturized])
|
||||
[m_window deminiaturize:nil];
|
||||
else if ([m_window isZoomed])
|
||||
[m_window zoom:nil];
|
||||
break;
|
||||
}
|
||||
return GHOST_kSuccess;
|
||||
break;
|
||||
}
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
[m_window setDocumentEdited:isUnsavedChanges];
|
||||
|
||||
|
||||
[pool drain];
|
||||
|
||||
return GHOST_Window::setModifiedState(isUnsavedChanges);
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid")
|
||||
if (order == GHOST_kWindowOrderTop) {
|
||||
if (order == GHOST_kWindowOrderTop) {
|
||||
[m_window makeKeyAndOrderFront:nil];
|
||||
}
|
||||
else {
|
||||
NSArray *windowsList;
|
||||
|
||||
}
|
||||
else {
|
||||
[m_window orderBack:nil];
|
||||
|
||||
|
||||
//Check for other blender opened windows and make the frontmost key
|
||||
windowsList = [NSApp orderedWindows];
|
||||
NSArray* windowsList = [NSApp orderedWindows];
|
||||
if ([windowsList count]) {
|
||||
[[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
return GHOST_kSuccess;
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
#pragma mark Drawing context
|
||||
@@ -884,15 +840,19 @@ GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()
|
||||
{
|
||||
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
|
||||
if (m_openGLContext != nil) {
|
||||
GHOST_TSuccess success = GHOST_kFailure;
|
||||
|
||||
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
|
||||
if (m_openGLContext != nil) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
[m_openGLContext flushBuffer];
|
||||
[pool drain];
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
}
|
||||
return GHOST_kFailure;
|
||||
success = GHOST_kSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
// [m_pool drain]; // needed to put this in a function that is called regularly
|
||||
return success;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()
|
||||
@@ -912,12 +872,12 @@ GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
|
||||
{
|
||||
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
|
||||
if (m_openGLContext != nil) {
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
[m_openGLContext makeCurrentContext];
|
||||
|
||||
|
||||
// Disable AA by default
|
||||
if (m_numOfAASamples > 0) glDisable(GL_MULTISAMPLE_ARB);
|
||||
[pool drain];
|
||||
// [pool drain];
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
}
|
||||
@@ -928,35 +888,34 @@ GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
|
||||
GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)
|
||||
{
|
||||
GHOST_TSuccess success = GHOST_kFailure;
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSOpenGLPixelFormat *pixelFormat;
|
||||
NSOpenGLContext *tmpOpenGLContext;
|
||||
|
||||
|
||||
/***** Multithreaded opengl code : uncomment for enabling
|
||||
CGLContextObj cglCtx;
|
||||
*/
|
||||
|
||||
|
||||
switch (type) {
|
||||
case GHOST_kDrawingContextTypeOpenGL:
|
||||
if (!getValid()) break;
|
||||
|
||||
|
||||
pixelFormat = [m_openGLView pixelFormat];
|
||||
tmpOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
|
||||
shareContext:s_firstOpenGLcontext];
|
||||
shareContext:s_firstOpenGLcontext];
|
||||
if (tmpOpenGLContext == nil) {
|
||||
success = GHOST_kFailure;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//Switch openGL to multhreaded mode
|
||||
/******* Multithreaded opengl code : uncomment for enabling
|
||||
/******* Multithreaded opengl code : uncomment for enabling */
|
||||
cglCtx = (CGLContextObj)[tmpOpenGLContext CGLContextObj];
|
||||
if (CGLEnable(cglCtx, kCGLCEMPEngine) == kCGLNoError)
|
||||
printf("\nSwitched openGL to multithreaded mode");
|
||||
*/
|
||||
|
||||
|
||||
if (!s_firstOpenGLcontext) s_firstOpenGLcontext = tmpOpenGLContext;
|
||||
#ifdef WAIT_FOR_VSYNC
|
||||
{
|
||||
@@ -967,25 +926,25 @@ GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextTyp
|
||||
#endif
|
||||
[m_openGLView setOpenGLContext:tmpOpenGLContext];
|
||||
[tmpOpenGLContext setView:m_openGLView];
|
||||
|
||||
|
||||
m_openGLContext = tmpOpenGLContext;
|
||||
break;
|
||||
|
||||
|
||||
case GHOST_kDrawingContextTypeNone:
|
||||
success = GHOST_kSuccess;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
[pool drain];
|
||||
// [pool drain];
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
switch (m_drawingContextType) {
|
||||
case GHOST_kDrawingContextTypeOpenGL:
|
||||
if (m_openGLContext)
|
||||
@@ -994,14 +953,14 @@ GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()
|
||||
if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil;
|
||||
m_openGLContext = nil;
|
||||
}
|
||||
[pool drain];
|
||||
// [pool drain];
|
||||
return GHOST_kSuccess;
|
||||
case GHOST_kDrawingContextTypeNone:
|
||||
[pool drain];
|
||||
// [pool drain];
|
||||
return GHOST_kSuccess;
|
||||
break;
|
||||
default:
|
||||
[pool drain];
|
||||
// [pool drain];
|
||||
return GHOST_kFailure;
|
||||
}
|
||||
}
|
||||
@@ -1010,9 +969,9 @@ GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()
|
||||
GHOST_TSuccess GHOST_WindowCocoa::invalidate()
|
||||
{
|
||||
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::invalidate(): window invalid")
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
[m_openGLView setNeedsDisplay:YES];
|
||||
[pool drain];
|
||||
// [pool drain];
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -1021,36 +980,36 @@ GHOST_TSuccess GHOST_WindowCocoa::invalidate()
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setProgressBar(float progress)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
if ((progress >=0.0) && (progress <=1.0)) {
|
||||
NSImage* dockIcon = [[NSImage alloc] initWithSize:NSMakeSize(128,128)];
|
||||
|
||||
[dockIcon lockFocus];
|
||||
NSRect progressBox = {{4, 4}, {120, 16}};
|
||||
|
||||
[[NSImage imageNamed:@"NSApplicationIcon"] dissolveToPoint:NSZeroPoint fraction:1.0];
|
||||
|
||||
// Track & Outline
|
||||
[[NSColor blackColor] setFill];
|
||||
NSRectFill(progressBox);
|
||||
|
||||
[[NSColor whiteColor] set];
|
||||
NSFrameRect(progressBox);
|
||||
|
||||
// Progress fill
|
||||
progressBox = NSInsetRect(progressBox, 1, 1);
|
||||
[[NSColor knobColor] setFill];
|
||||
progressBox.size.width = progressBox.size.width * progress;
|
||||
[dockIcon lockFocus];
|
||||
NSRect progressBox = {{4, 4}, {120, 16}};
|
||||
|
||||
[[NSImage imageNamed:@"NSApplicationIcon"] dissolveToPoint:NSZeroPoint fraction:1.0];
|
||||
|
||||
// Track & Outline
|
||||
[[NSColor blackColor] setFill];
|
||||
NSRectFill(progressBox);
|
||||
|
||||
|
||||
[[NSColor whiteColor] set];
|
||||
NSFrameRect(progressBox);
|
||||
|
||||
// Progress fill
|
||||
progressBox = NSInsetRect(progressBox, 1, 1);
|
||||
[[NSColor knobColor] setFill];
|
||||
progressBox.size.width = progressBox.size.width * progress;
|
||||
NSRectFill(progressBox);
|
||||
|
||||
[dockIcon unlockFocus];
|
||||
|
||||
|
||||
[NSApp setApplicationIconImage:dockIcon];
|
||||
[dockIcon release];
|
||||
|
||||
|
||||
m_progressBarVisible = true;
|
||||
}
|
||||
|
||||
|
||||
[pool drain];
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
@@ -1060,16 +1019,16 @@ GHOST_TSuccess GHOST_WindowCocoa::endProgressBar()
|
||||
{
|
||||
if (!m_progressBarVisible) return GHOST_kFailure;
|
||||
m_progressBarVisible = false;
|
||||
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
NSImage* dockIcon = [[NSImage alloc] initWithSize:NSMakeSize(128,128)];
|
||||
[dockIcon lockFocus];
|
||||
[[NSImage imageNamed:@"NSApplicationIcon"] dissolveToPoint:NSZeroPoint fraction:1.0];
|
||||
[dockIcon unlockFocus];
|
||||
[NSApp setApplicationIconImage:dockIcon];
|
||||
[dockIcon release];
|
||||
|
||||
|
||||
[pool drain];
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
@@ -1081,9 +1040,9 @@ GHOST_TSuccess GHOST_WindowCocoa::endProgressBar()
|
||||
void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) const
|
||||
{
|
||||
static bool systemCursorVisible = true;
|
||||
|
||||
|
||||
NSCursor *tmpCursor =nil;
|
||||
|
||||
|
||||
if (visible != systemCursorVisible) {
|
||||
if (visible) {
|
||||
[NSCursor unhide];
|
||||
@@ -1126,6 +1085,7 @@ void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) c
|
||||
case GHOST_kStandardCursorRightSide:
|
||||
tmpCursor = [NSCursor resizeRightCursor];
|
||||
break;
|
||||
#if 0 // illustrative code -- no need to compile
|
||||
case GHOST_kStandardCursorRightArrow:
|
||||
case GHOST_kStandardCursorInfo:
|
||||
case GHOST_kStandardCursorLeftArrow:
|
||||
@@ -1139,10 +1099,11 @@ void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) c
|
||||
case GHOST_kStandardCursorBottomLeftCorner:
|
||||
case GHOST_kStandardCursorCopy:
|
||||
case GHOST_kStandardCursorDefault:
|
||||
#endif
|
||||
default:
|
||||
tmpCursor = [NSCursor arrowCursor];
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
[tmpCursor set];
|
||||
}
|
||||
@@ -1151,13 +1112,10 @@ void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) c
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorVisibility(bool visible)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
|
||||
|
||||
if ([m_window isVisible]) {
|
||||
loadCursor(visible, getCursorShape());
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -1165,30 +1123,27 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorVisibility(bool visible)
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
|
||||
{
|
||||
GHOST_TSuccess err = GHOST_kSuccess;
|
||||
|
||||
|
||||
if (mode != GHOST_kGrabDisable)
|
||||
{
|
||||
//No need to perform grab without warp as it is always on in OS X
|
||||
if(mode != GHOST_kGrabNormal) {
|
||||
GHOST_TInt32 x_old,y_old;
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
m_systemCocoa->getCursorPosition(x_old,y_old);
|
||||
m_ghostSystem->getCursorPosition(x_old,y_old);
|
||||
screenToClient(x_old, y_old, m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
|
||||
//Warp position is stored in client (window base) coordinates
|
||||
setCursorGrabAccum(0, 0);
|
||||
|
||||
|
||||
if(mode == GHOST_kGrabHide) {
|
||||
setWindowCursorVisibility(false);
|
||||
}
|
||||
|
||||
|
||||
//Make window key if it wasn't to get the mouse move events
|
||||
[m_window makeKeyWindow];
|
||||
|
||||
|
||||
//Dissociate cursor position even for warp mode, to allow mouse acceleration to work even when warping the cursor
|
||||
err = CGAssociateMouseAndMouseCursorPosition(false) == kCGErrorSuccess ? GHOST_kSuccess : GHOST_kFailure;
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -1197,7 +1152,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode
|
||||
//No need to set again cursor position, as it has not changed for Cocoa
|
||||
setWindowCursorVisibility(true);
|
||||
}
|
||||
|
||||
|
||||
err = CGAssociateMouseAndMouseCursorPosition(true) == kCGErrorSuccess ? GHOST_kSuccess : GHOST_kFailure;
|
||||
/* Almost works without but important otherwise the mouse GHOST location can be incorrect on exit */
|
||||
setCursorGrabAccum(0, 0);
|
||||
@@ -1205,11 +1160,9 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor shape)
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
if (m_customCursor) {
|
||||
[m_customCursor release];
|
||||
m_customCursor = nil;
|
||||
@@ -1218,8 +1171,7 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor sha
|
||||
if ([m_window isVisible]) {
|
||||
loadCursor(getCursorVisibility(), shape);
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -1245,7 +1197,7 @@ static GHOST_TUns16 uns16ReverseBits(GHOST_TUns16 shrt)
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
|
||||
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color)
|
||||
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color)
|
||||
{
|
||||
int y,nbUns16;
|
||||
NSPoint hotSpotPoint;
|
||||
@@ -1253,31 +1205,29 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 *bitmap
|
||||
NSImage *cursorImage;
|
||||
NSSize imSize;
|
||||
GHOST_TUns16 *cursorBitmap;
|
||||
|
||||
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
|
||||
if (m_customCursor) {
|
||||
[m_customCursor release];
|
||||
m_customCursor = nil;
|
||||
}
|
||||
|
||||
|
||||
cursorImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
|
||||
pixelsWide:sizex
|
||||
pixelsHigh:sizey
|
||||
bitsPerSample:1
|
||||
samplesPerPixel:2
|
||||
hasAlpha:YES
|
||||
isPlanar:YES
|
||||
colorSpaceName:NSDeviceWhiteColorSpace
|
||||
bytesPerRow:(sizex/8 + (sizex%8 >0 ?1:0))
|
||||
bitsPerPixel:1];
|
||||
|
||||
|
||||
cursorImageRep = [[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes:nil
|
||||
pixelsWide:sizex
|
||||
pixelsHigh:sizey
|
||||
bitsPerSample:1
|
||||
samplesPerPixel:2
|
||||
hasAlpha:YES
|
||||
isPlanar:YES
|
||||
colorSpaceName:NSDeviceWhiteColorSpace
|
||||
bytesPerRow:(sizex/8 + (sizex%8 >0 ?1:0))
|
||||
bitsPerPixel:1];
|
||||
|
||||
cursorBitmap = (GHOST_TUns16*)[cursorImageRep bitmapData];
|
||||
nbUns16 = [cursorImageRep bytesPerPlane]/2;
|
||||
|
||||
|
||||
for (y=0; y<nbUns16; y++) {
|
||||
#if !defined(__LITTLE_ENDIAN__)
|
||||
cursorBitmap[y] = ~uns16ReverseBits((bitmap[2*y]<<0) | (bitmap[2*y+1]<<8));
|
||||
@@ -1286,34 +1236,33 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 *bitmap
|
||||
cursorBitmap[y] = ~uns16ReverseBits((bitmap[2*y+1]<<0) | (bitmap[2*y]<<8));
|
||||
cursorBitmap[nbUns16+y] = uns16ReverseBits((mask[2*y+1]<<0) | (mask[2*y]<<8));
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
imSize.width = sizex;
|
||||
imSize.height= sizey;
|
||||
cursorImage = [[NSImage alloc] initWithSize:imSize];
|
||||
[cursorImage addRepresentation:cursorImageRep];
|
||||
|
||||
|
||||
hotSpotPoint.x = hotX;
|
||||
hotSpotPoint.y = hotY;
|
||||
|
||||
|
||||
//foreground and background color parameter is not handled for now (10.6)
|
||||
m_customCursor = [[NSCursor alloc] initWithImage:cursorImage
|
||||
hotSpot:hotSpotPoint];
|
||||
|
||||
hotSpot:hotSpotPoint];
|
||||
|
||||
[cursorImageRep release];
|
||||
[cursorImage release];
|
||||
|
||||
|
||||
if ([m_window isVisible]) {
|
||||
loadCursor(getCursorVisibility(), GHOST_kStandardCursorCustom);
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2],
|
||||
GHOST_TUns8 mask[16][2], int hotX, int hotY)
|
||||
GHOST_TUns8 mask[16][2], int hotX, int hotY)
|
||||
{
|
||||
return setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*) mask, 16, 16, hotX, hotY, 0, 1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user