2011-10-23 17:52:20 +00:00
|
|
|
/*
|
2009-09-30 08:47:39 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-09-30 08:47:39 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
2009-10-06 16:56:22 +00:00
|
|
|
* Contributor(s): Maarten Gribnau 05/2001
|
|
|
|
Damien Plisson 10/2009
|
2009-09-30 08:47:39 +00:00
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2009-09-30 08:47:39 +00:00
|
|
|
|
2012-12-15 11:15:05 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED <= 1050
|
2009-10-12 09:53:28 +00:00
|
|
|
//Use of the SetSystemUIMode function (64bit compatible)
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
|
|
|
|
2010-01-06 11:42:52 +00:00
|
|
|
#include <OpenGL/gl.h>
|
2011-12-19 14:23:08 +00:00
|
|
|
#include <OpenGL/CGLRenderers.h>
|
2009-10-20 08:13:12 +00:00
|
|
|
/***** Multithreaded opengl code : uncomment for enabling
|
|
|
|
#include <OpenGL/OpenGL.h>
|
|
|
|
*/
|
2010-01-06 11:42:52 +00:00
|
|
|
|
2009-10-20 08:13:12 +00:00
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
#include "GHOST_WindowCocoa.h"
|
2009-10-06 16:56:22 +00:00
|
|
|
#include "GHOST_SystemCocoa.h"
|
2009-09-30 08:47:39 +00:00
|
|
|
#include "GHOST_Debug.h"
|
|
|
|
|
2013-05-08 19:37:36 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
|
|
|
|
/* Lion style fullscreen support when building with the 10.6 SDK */
|
|
|
|
enum {
|
|
|
|
NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7,
|
|
|
|
NSFullScreenWindowMask = 1 << 14
|
|
|
|
};
|
|
|
|
#endif
|
2009-09-30 08:47:39 +00:00
|
|
|
|
2009-10-12 09:53:28 +00:00
|
|
|
#pragma mark Cocoa window delegate object
|
2013-05-25 14:08:56 +00:00
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
@interface CocoaWindowDelegate : NSObject
|
2009-10-19 10:49:45 +00:00
|
|
|
<NSWindowDelegate>
|
2009-10-06 16:56:22 +00:00
|
|
|
{
|
|
|
|
GHOST_SystemCocoa *systemCocoa;
|
|
|
|
GHOST_WindowCocoa *associatedWindow;
|
|
|
|
}
|
|
|
|
|
2009-10-19 10:49:45 +00:00
|
|
|
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
|
2009-10-06 16:56:22 +00:00
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notification;
|
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification;
|
2009-11-04 17:50:31 +00:00
|
|
|
- (void)windowDidExpose:(NSNotification *)notification;
|
2009-10-06 16:56:22 +00:00
|
|
|
- (void)windowDidResize:(NSNotification *)notification;
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
- (void)windowDidMove:(NSNotification *)notification;
|
|
|
|
- (void)windowWillMove:(NSNotification *)notification;
|
2012-12-21 11:56:02 +00:00
|
|
|
- (BOOL)windowShouldClose:(id)sender;
|
2013-01-12 17:07:49 +00:00
|
|
|
- (void)windowDidChangeBackingProperties:(NSNotification *)notification;
|
2009-10-06 16:56:22 +00:00
|
|
|
@end
|
|
|
|
|
2013-01-12 17:07:49 +00:00
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
@implementation CocoaWindowDelegate : NSObject
|
|
|
|
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
|
|
|
|
{
|
|
|
|
systemCocoa = sysCocoa;
|
|
|
|
associatedWindow = winCocoa;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventWindowActivate, associatedWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification
|
|
|
|
{
|
2009-11-04 17:50:31 +00:00
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventWindowDeactivate, associatedWindow);
|
2009-10-06 16:56:22 +00:00
|
|
|
}
|
|
|
|
|
2009-11-04 17:50:31 +00:00
|
|
|
- (void)windowDidExpose:(NSNotification *)notification
|
2009-10-06 16:56:22 +00:00
|
|
|
{
|
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
- (void)windowDidMove:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowWillMove:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventWindowMove, associatedWindow);
|
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
- (void)windowDidResize:(NSNotification *)notification
|
|
|
|
{
|
2012-12-15 11:15:05 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
2009-10-20 15:23:04 +00:00
|
|
|
//if (![[notification object] inLiveResize]) {
|
2009-10-19 10:49:45 +00:00
|
|
|
//Send event only once, at end of resize operation (when user has released mouse button)
|
2009-10-20 08:13:12 +00:00
|
|
|
#endif
|
2009-10-19 10:49:45 +00:00
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, associatedWindow);
|
2012-12-15 11:15:05 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
2009-10-20 15:23:04 +00:00
|
|
|
//}
|
2009-10-20 08:13:12 +00:00
|
|
|
#endif
|
2013-05-25 14:08:56 +00:00
|
|
|
/* Live resize, send event, gets handled in wm_window.c. Needed because live resize runs in a modal loop, not letting main loop run */
|
2009-10-19 10:49:45 +00:00
|
|
|
if ([[notification object] inLiveResize]) {
|
|
|
|
systemCocoa->dispatchEvents();
|
2013-05-25 14:08:56 +00:00
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
}
|
2012-12-21 11:56:02 +00:00
|
|
|
|
2013-01-12 17:07:49 +00:00
|
|
|
- (void)windowDidChangeBackingProperties:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventNativeResolutionChange, associatedWindow);
|
|
|
|
}
|
|
|
|
|
2012-12-21 11:56:02 +00:00
|
|
|
- (BOOL)windowShouldClose:(id)sender;
|
|
|
|
{
|
|
|
|
//Let Blender close the window rather than closing immediately
|
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventWindowClose, associatedWindow);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
@end
|
|
|
|
|
2009-10-12 09:53:28 +00:00
|
|
|
#pragma mark NSWindow subclass
|
|
|
|
//We need to subclass it to tell that even borderless (fullscreen), it can become key (receive user events)
|
|
|
|
@interface CocoaWindow: NSWindow
|
|
|
|
{
|
2009-11-10 12:56:46 +00:00
|
|
|
GHOST_SystemCocoa *systemCocoa;
|
|
|
|
GHOST_WindowCocoa *associatedWindow;
|
|
|
|
GHOST_TDragnDropTypes m_draggedObjectType;
|
2009-10-12 09:53:28 +00:00
|
|
|
}
|
2009-11-10 12:56:46 +00:00
|
|
|
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
|
2011-01-01 19:48:14 +00:00
|
|
|
- (GHOST_SystemCocoa*)systemCocoa;
|
2009-10-12 09:53:28 +00:00
|
|
|
@end
|
|
|
|
@implementation CocoaWindow
|
2009-11-10 12:56:46 +00:00
|
|
|
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
|
|
|
|
{
|
|
|
|
systemCocoa = sysCocoa;
|
|
|
|
associatedWindow = winCocoa;
|
|
|
|
}
|
2011-01-01 19:48:14 +00:00
|
|
|
- (GHOST_SystemCocoa*)systemCocoa
|
|
|
|
{
|
|
|
|
return systemCocoa;
|
|
|
|
}
|
2009-10-12 09:53:28 +00:00
|
|
|
|
|
|
|
-(BOOL)canBecomeKeyWindow
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2009-11-10 12:56:46 +00:00
|
|
|
//The drag'n'drop dragging destination methods
|
|
|
|
- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2010-05-03 17:02:49 +00:00
|
|
|
associatedWindow->setAcceptDragOperation(TRUE); //Drag operation is accepted by default
|
2009-11-10 12:56:46 +00:00
|
|
|
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingEntered, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil);
|
|
|
|
return NSDragOperationCopy;
|
|
|
|
}
|
|
|
|
|
2009-11-15 08:34:31 +00:00
|
|
|
- (BOOL)wantsPeriodicDraggingUpdates
|
|
|
|
{
|
|
|
|
return NO; //No need to overflow blender event queue. Events shall be sent only on changes
|
|
|
|
}
|
2009-11-10 12:56:46 +00:00
|
|
|
|
|
|
|
- (NSDragOperation)draggingUpdated:(id < NSDraggingInfo >)sender
|
|
|
|
{
|
|
|
|
NSPoint mouseLocation = [sender draggingLocation];
|
|
|
|
|
|
|
|
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingUpdated, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, nil);
|
2012-10-28 15:23:16 +00:00
|
|
|
return associatedWindow->canAcceptDragOperation() ? NSDragOperationCopy : NSDragOperationNone;
|
2009-11-10 12:56:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)draggingExited:(id < NSDraggingInfo >)sender
|
|
|
|
{
|
|
|
|
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingExited, m_draggedObjectType, associatedWindow, 0, 0, nil);
|
|
|
|
m_draggedObjectType = GHOST_kDragnDropTypeUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)prepareForDragOperation:(id < NSDraggingInfo >)sender
|
|
|
|
{
|
2009-11-19 08:56:26 +00:00
|
|
|
if (associatedWindow->canAcceptDragOperation())
|
2009-11-10 12:56:46 +00:00
|
|
|
return YES;
|
|
|
|
else
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender
|
|
|
|
{
|
|
|
|
NSPoint mouseLocation = [sender draggingLocation];
|
|
|
|
NSPasteboard *draggingPBoard = [sender draggingPasteboard];
|
2010-02-01 17:33:41 +00:00
|
|
|
NSImage *droppedImg;
|
2009-11-10 12:56:46 +00:00
|
|
|
id data;
|
|
|
|
|
|
|
|
switch (m_draggedObjectType) {
|
|
|
|
case GHOST_kDragnDropTypeBitmap:
|
2012-09-06 02:10:09 +00:00
|
|
|
if ([NSImage canInitWithPasteboard:draggingPBoard]) {
|
2010-02-01 17:33:41 +00:00
|
|
|
droppedImg = [[NSImage alloc]initWithPasteboard:draggingPBoard];
|
|
|
|
data = droppedImg; //[draggingPBoard dataForType:NSTIFFPboardType];
|
|
|
|
}
|
|
|
|
else return NO;
|
2009-11-10 12:56:46 +00:00
|
|
|
break;
|
|
|
|
case GHOST_kDragnDropTypeFilenames:
|
|
|
|
data = [draggingPBoard propertyListForType:NSFilenamesPboardType];
|
|
|
|
break;
|
|
|
|
case GHOST_kDragnDropTypeString:
|
2009-11-19 08:56:26 +00:00
|
|
|
data = [draggingPBoard stringForType:NSStringPboardType];
|
2009-11-10 12:56:46 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return NO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
systemCocoa->handleDraggingEvent(GHOST_kEventDraggingDropDone, m_draggedObjectType, associatedWindow, mouseLocation.x, mouseLocation.y, (void*)data);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2009-10-12 09:53:28 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
#pragma mark NSOpenGLView subclass
|
|
|
|
//We need to subclass it in order to give Cocoa the feeling key events are trapped
|
2011-11-23 07:39:59 +00:00
|
|
|
@interface CocoaOpenGLView : NSOpenGLView <NSTextInput>
|
2009-10-06 16:56:22 +00:00
|
|
|
{
|
2011-06-27 13:57:27 +00:00
|
|
|
GHOST_SystemCocoa *systemCocoa;
|
|
|
|
GHOST_WindowCocoa *associatedWindow;
|
2011-11-23 07:39:59 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
bool composing;
|
|
|
|
NSString *composing_text;
|
2009-10-06 16:56:22 +00:00
|
|
|
}
|
2011-06-27 13:57:27 +00:00
|
|
|
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa;
|
2009-10-06 16:56:22 +00:00
|
|
|
@end
|
|
|
|
@implementation CocoaOpenGLView
|
|
|
|
|
2011-06-27 13:57:27 +00:00
|
|
|
- (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
|
|
|
|
{
|
|
|
|
systemCocoa = sysCocoa;
|
|
|
|
associatedWindow = winCocoa;
|
2011-11-23 07:39:59 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
composing = false;
|
|
|
|
composing_text = nil;
|
2011-06-27 13:57:27 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
return YES;
|
2009-10-06 16:56:22 +00:00
|
|
|
}
|
|
|
|
|
2011-11-23 07:39:59 +00:00
|
|
|
// The trick to prevent Cocoa from complaining (beeping)
|
|
|
|
- (void)keyDown:(NSEvent *)event
|
|
|
|
{
|
2013-05-11 12:21:33 +00:00
|
|
|
systemCocoa->handleKeyEvent(event);
|
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
/* Start or continue composing? */
|
|
|
|
if ([[event characters] length] == 0 ||
|
|
|
|
[[event charactersIgnoringModifiers] length] == 0 ||
|
|
|
|
composing)
|
|
|
|
{
|
|
|
|
composing = YES;
|
2011-11-23 07:39:59 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
// interpret event to call insertText
|
|
|
|
NSMutableArray *events;
|
|
|
|
events = [[NSMutableArray alloc] initWithCapacity:1];
|
|
|
|
[events addObject:event];
|
|
|
|
[self interpretKeyEvents:events]; // calls insertText
|
|
|
|
[events removeObject:event];
|
|
|
|
[events release];
|
2013-05-11 12:21:33 +00:00
|
|
|
return;
|
2012-09-06 02:10:09 +00:00
|
|
|
}
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
|
2013-05-11 10:15:27 +00:00
|
|
|
- (void)keyUp:(NSEvent *)event
|
2009-12-02 15:02:29 +00:00
|
|
|
{
|
2013-05-11 10:15:27 +00:00
|
|
|
systemCocoa->handleKeyEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)flagsChanged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleKeyEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDown:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseUp:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)scrollWheel:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDown:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseUp:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)magnifyWithEvent:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rotateWithEvent:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)beginGestureWithEvent:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)endGestureWithEvent:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleMouseEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tabletPoint:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleTabletEvent(event,[event type]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tabletProximity:(NSEvent *)event
|
|
|
|
{
|
|
|
|
systemCocoa->handleTabletEvent(event,[event type]);
|
2009-12-02 15:02:29 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
- (BOOL)isOpaque
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
return YES;
|
2009-10-06 16:56:22 +00:00
|
|
|
}
|
|
|
|
|
2010-09-26 19:53:45 +00:00
|
|
|
- (void) drawRect:(NSRect)rect
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
if ([self inLiveResize]) {
|
|
|
|
/* Don't redraw while in live resize */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[super drawRect:rect];
|
|
|
|
systemCocoa->handleWindowEvent(GHOST_kEventWindowUpdate, associatedWindow);
|
|
|
|
}
|
2010-09-26 19:53:45 +00:00
|
|
|
}
|
|
|
|
|
2011-11-23 07:39:59 +00:00
|
|
|
// Text input
|
|
|
|
|
|
|
|
- (void)composing_free
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
composing = NO;
|
2011-11-23 07:39:59 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
if (composing_text) {
|
|
|
|
[composing_text release];
|
|
|
|
composing_text = nil;
|
|
|
|
}
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)insertText:(id)chars
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
[self composing_free];
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMarkedText:(id)chars selectedRange:(NSRange)range
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
[self composing_free];
|
|
|
|
if ([chars length] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// start composing
|
|
|
|
composing = YES;
|
|
|
|
composing_text = [chars copy];
|
2011-11-23 07:39:59 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
// if empty, cancel
|
|
|
|
if ([composing_text length] == 0)
|
|
|
|
[self composing_free];
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)unmarkText
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
[self composing_free];
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)hasMarkedText
|
|
|
|
{
|
2012-10-28 15:23:16 +00:00
|
|
|
return (composing) ? YES : NO;
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)doCommandBySelector:(SEL)selector
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isComposing
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
return composing;
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)conversationIdentifier
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
return (NSInteger)self;
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)range
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
return [NSAttributedString new]; // XXX does this leak?
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRange)markedRange
|
|
|
|
{
|
2012-10-28 15:23:16 +00:00
|
|
|
unsigned int length = (composing_text) ? [composing_text length] : 0;
|
2011-11-23 07:39:59 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
if (composing)
|
|
|
|
return NSMakeRange(0, length);
|
2011-11-23 07:39:59 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
return NSMakeRange(NSNotFound, 0);
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
|
2011-11-23 07:39:59 +00:00
|
|
|
- (NSRange)selectedRange
|
|
|
|
{
|
2012-10-28 15:23:16 +00:00
|
|
|
unsigned int length = (composing_text) ? [composing_text length] : 0;
|
2012-09-06 02:10:09 +00:00
|
|
|
return NSMakeRange(0, length);
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)firstRectForCharacterRange:(NSRange)range
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
return NSZeroRect;
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUInteger)characterIndexForPoint:(NSPoint)point
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
return NSNotFound;
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray*)validAttributesForMarkedText
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
return [NSArray array]; // XXX does this leak?
|
2011-11-23 07:39:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2009-10-06 16:56:22 +00:00
|
|
|
|
|
|
|
#pragma mark initialization / finalization
|
|
|
|
|
2013-01-08 17:27:11 +00:00
|
|
|
#if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
|
|
|
|
@interface NSView (NSOpenGLSurfaceResolution)
|
|
|
|
- (BOOL)wantsBestResolutionOpenGLSurface;
|
2013-01-09 11:25:16 +00:00
|
|
|
- (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag;
|
|
|
|
- (NSRect)convertRectToBacking:(NSRect)bounds;
|
2013-01-08 17:27:11 +00:00
|
|
|
@end
|
|
|
|
#endif
|
|
|
|
|
2009-10-12 16:51:36 +00:00
|
|
|
NSOpenGLContext* GHOST_WindowCocoa::s_firstOpenGLcontext = nil;
|
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
GHOST_WindowCocoa::GHOST_WindowCocoa(
|
2009-10-09 12:48:28 +00:00
|
|
|
GHOST_SystemCocoa *systemCocoa,
|
2009-09-30 08:47:39 +00:00
|
|
|
const STR_String& title,
|
|
|
|
GHOST_TInt32 left,
|
2011-06-23 19:55:47 +00:00
|
|
|
GHOST_TInt32 bottom,
|
2009-09-30 08:47:39 +00:00
|
|
|
GHOST_TUns32 width,
|
|
|
|
GHOST_TUns32 height,
|
|
|
|
GHOST_TWindowState state,
|
|
|
|
GHOST_TDrawingContextType type,
|
2010-01-06 11:42:52 +00:00
|
|
|
const bool stereoVisual, const GHOST_TUns16 numOfAASamples
|
2009-09-30 08:47:39 +00:00
|
|
|
) :
|
2013-04-02 19:18:38 +00:00
|
|
|
GHOST_Window(width, height, state, GHOST_kDrawingContextTypeNone, stereoVisual, false, numOfAASamples),
|
2009-10-09 12:48:28 +00:00
|
|
|
m_customCursor(0)
|
2009-09-30 08:47:39 +00:00
|
|
|
{
|
2009-10-26 08:43:24 +00:00
|
|
|
NSOpenGLPixelFormatAttribute pixelFormatAttrsWindow[40];
|
2010-01-06 11:42:52 +00:00
|
|
|
NSOpenGLPixelFormat *pixelFormat = nil;
|
2009-10-26 08:43:24 +00:00
|
|
|
int i;
|
2010-01-06 11:42:52 +00:00
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
m_systemCocoa = systemCocoa;
|
|
|
|
m_fullScreen = false;
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-09-30 08:47:39 +00:00
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
//Creates the window
|
|
|
|
NSRect rect;
|
2009-10-20 08:13:12 +00:00
|
|
|
NSSize minSize;
|
2009-10-09 12:48:28 +00:00
|
|
|
|
|
|
|
rect.origin.x = left;
|
2011-06-23 19:55:47 +00:00
|
|
|
rect.origin.y = bottom;
|
2009-10-09 12:48:28 +00:00
|
|
|
rect.size.width = width;
|
|
|
|
rect.size.height = height;
|
|
|
|
|
2009-10-12 09:53:28 +00:00
|
|
|
m_window = [[CocoaWindow alloc] initWithContentRect:rect
|
2009-10-09 12:48:28 +00:00
|
|
|
styleMask:NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask
|
|
|
|
backing:NSBackingStoreBuffered defer:NO];
|
|
|
|
if (m_window == nil) {
|
|
|
|
[pool drain];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-10 12:56:46 +00:00
|
|
|
[m_window setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
|
|
|
|
|
2009-10-20 08:13:12 +00:00
|
|
|
//Forbid to resize the window below the blender defined minimum one
|
2013-01-24 17:57:38 +00:00
|
|
|
minSize.width = 320;
|
|
|
|
minSize.height = 240;
|
2009-10-20 08:13:12 +00:00
|
|
|
[m_window setContentMinSize:minSize];
|
|
|
|
|
2009-10-15 08:27:31 +00:00
|
|
|
setTitle(title);
|
2009-10-09 12:48:28 +00:00
|
|
|
|
2009-10-26 08:43:24 +00:00
|
|
|
|
|
|
|
// Pixel Format Attributes for the windowed NSOpenGLContext
|
|
|
|
i=0;
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
|
2010-01-28 10:56:35 +00:00
|
|
|
|
2012-06-03 11:16:13 +00:00
|
|
|
// Guarantees the back buffer contents to be valid after a call to NSOpenGLContext object's flushBuffer
|
2010-01-28 10:56:35 +00:00
|
|
|
// needed for 'Draw Overlap' drawing method
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore;
|
|
|
|
|
2011-12-19 14:23:08 +00:00
|
|
|
// Force software OpenGL, for debugging
|
2012-09-06 02:10:09 +00:00
|
|
|
if (getenv("BLENDER_SOFTWAREGL")) {
|
2011-12-19 14:23:08 +00:00
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFARendererID;
|
|
|
|
pixelFormatAttrsWindow[i++] = kCGLRendererGenericID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
|
|
|
|
|
2009-10-26 08:43:24 +00:00
|
|
|
//pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,; // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2009-10-26 08:43:24 +00:00
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFADepthSize;
|
|
|
|
pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
|
|
|
|
|
2013-02-27 22:48:34 +00:00
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccumSize;
|
|
|
|
pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
|
2010-07-14 14:11:03 +00:00
|
|
|
|
2009-10-26 08:43:24 +00:00
|
|
|
if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
|
|
|
|
|
2012-08-11 22:12:32 +00:00
|
|
|
if (numOfAASamples > 0) {
|
2010-01-06 11:42:52 +00:00
|
|
|
// Multisample anti-aliasing
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFAMultisample;
|
|
|
|
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFASampleBuffers;
|
|
|
|
pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 1;
|
|
|
|
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFASamples;
|
|
|
|
pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) numOfAASamples;
|
|
|
|
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFANoRecovery;
|
|
|
|
}
|
|
|
|
|
2009-10-26 08:43:24 +00:00
|
|
|
pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
|
|
|
|
|
2010-01-06 11:42:52 +00:00
|
|
|
pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
|
2009-10-09 12:48:28 +00:00
|
|
|
|
2010-01-06 11:42:52 +00:00
|
|
|
|
|
|
|
//Fall back to no multisampling if Antialiasing init failed
|
|
|
|
if (pixelFormat == nil) {
|
|
|
|
i=0;
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFADoubleBuffer;
|
2010-01-28 10:56:35 +00:00
|
|
|
|
2012-06-03 11:16:13 +00:00
|
|
|
// Guarantees the back buffer contents to be valid after a call to NSOpenGLContext object's flushBuffer
|
2010-01-28 10:56:35 +00:00
|
|
|
// needed for 'Draw Overlap' drawing method
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFABackingStore;
|
|
|
|
|
2011-12-19 14:23:08 +00:00
|
|
|
// Force software OpenGL, for debugging
|
2012-09-06 02:10:09 +00:00
|
|
|
if (getenv("BLENDER_SOFTWAREGL")) {
|
2011-12-19 14:23:08 +00:00
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFARendererID;
|
|
|
|
pixelFormatAttrsWindow[i++] = kCGLRendererGenericID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccelerated;
|
|
|
|
|
2010-01-06 11:42:52 +00:00
|
|
|
//pixelFormatAttrsWindow[i++] = NSOpenGLPFAAllowOfflineRenderers,; // Removed to allow 10.4 builds, and 2 GPUs rendering is not used anyway
|
|
|
|
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFADepthSize;
|
|
|
|
pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
|
2013-02-27 22:48:34 +00:00
|
|
|
|
|
|
|
pixelFormatAttrsWindow[i++] = NSOpenGLPFAAccumSize;
|
|
|
|
pixelFormatAttrsWindow[i++] = (NSOpenGLPixelFormatAttribute) 32;
|
2010-01-06 11:42:52 +00:00
|
|
|
|
|
|
|
if (stereoVisual) pixelFormatAttrsWindow[i++] = NSOpenGLPFAStereo;
|
|
|
|
|
|
|
|
pixelFormatAttrsWindow[i] = (NSOpenGLPixelFormatAttribute) 0;
|
|
|
|
|
|
|
|
pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttrsWindow];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-08-11 22:12:32 +00:00
|
|
|
if (numOfAASamples > 0) { //Set m_numOfAASamples to the actual value
|
2010-01-06 11:42:52 +00:00
|
|
|
GLint gli;
|
|
|
|
[pixelFormat getValues:&gli forAttribute:NSOpenGLPFASamples forVirtualScreen:0];
|
|
|
|
if (m_numOfAASamples != (GHOST_TUns16)gli) {
|
|
|
|
m_numOfAASamples = (GHOST_TUns16)gli;
|
|
|
|
printf("GHOST_Window could be created with anti-aliasing of only %i samples\n",m_numOfAASamples);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Creates the OpenGL View inside the window
|
2009-10-09 12:48:28 +00:00
|
|
|
m_openGLView = [[CocoaOpenGLView alloc] initWithFrame:rect
|
|
|
|
pixelFormat:pixelFormat];
|
2011-06-27 13:57:27 +00:00
|
|
|
|
|
|
|
[m_openGLView setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
|
2009-10-09 12:48:28 +00:00
|
|
|
|
|
|
|
[pixelFormat release];
|
|
|
|
|
2009-10-12 16:51:36 +00:00
|
|
|
m_openGLContext = [m_openGLView openGLContext]; //This context will be replaced by the proper one just after
|
2009-10-09 12:48:28 +00:00
|
|
|
|
|
|
|
[m_window setContentView:m_openGLView];
|
|
|
|
[m_window setInitialFirstResponder:m_openGLView];
|
|
|
|
|
|
|
|
[m_window makeKeyAndOrderFront:nil];
|
|
|
|
|
|
|
|
setDrawingContextType(type);
|
|
|
|
updateDrawingContext();
|
|
|
|
activateDrawingContext();
|
2013-01-08 17:27:11 +00:00
|
|
|
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
if (m_systemCocoa->m_nativePixel) {
|
2013-01-08 17:27:11 +00:00
|
|
|
if ([m_openGLView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
|
|
|
|
[m_openGLView setWantsBestResolutionOpenGLSurface:YES];
|
|
|
|
|
|
|
|
NSRect backingBounds = [m_openGLView convertRectToBacking:[m_openGLView bounds]];
|
2013-01-12 17:07:49 +00:00
|
|
|
m_nativePixelSize = (float)backingBounds.size.width / (float)rect.size.width;
|
2013-01-08 17:27:11 +00:00
|
|
|
}
|
Holiday coding log :)
Nice formatted version (pictures soon):
http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.66/Usability
Short list of main changes:
- Transparent region option (over main region), added code to blend in/out such panels.
- Min size window now 640 x 480
- Fixed DPI for ui - lots of cleanup and changes everywhere. Icon image need correct size still, layer-in-use icon needs remake.
- Macbook retina support, use command line --no-native-pixels to disable it
- Timeline Marker label was drawing wrong
- Trackpad and magic mouse: supports zoom (hold ctrl)
- Fix for splash position: removed ghost function and made window size update after creation immediate
- Fast undo buffer save now adds UI as well. Could be checked for regular file save even...
Quit.blend and temp file saving use this now.
- Dixed filename in window on reading quit.blend or temp saves, and they now add a warning in window title: "(Recovered)"
- New Userpref option "Keep Session" - this always saves quit.blend, and loads on start.
This allows keeping UI and data without actual saves, until you actually save.
When you load startup.blend and quit, it recognises the quit.blend as a startup (no file name in header)
- Added 3D view copy/paste buffers (selected objects). Shortcuts ctrl-c, ctrl-v (OSX, cmd-c, cmd-v).
Coded partial file saving for it. Could be used for other purposes. Todo: use OS clipboards.
- User preferences (themes, keymaps, user settings) now can be saved as a separate file.
Old option is called "Save Startup File" the new one "Save User Settings".
To visualise this difference, the 'save startup file' button has been removed from user preferences window. That option is available as CTRL+U and in File menu still.
- OSX: fixed bug that stopped giving mouse events outside window.
This also fixes "Continuous Grab" for OSX. (error since 2009)
2012-12-12 18:58:11 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
m_tablet.Active = GHOST_kTabletModeNone;
|
|
|
|
|
|
|
|
CocoaWindowDelegate *windowDelegate = [[CocoaWindowDelegate alloc] init];
|
|
|
|
[windowDelegate setSystemAndWindowCocoa:systemCocoa windowCocoa:this];
|
|
|
|
[m_window setDelegate:windowDelegate];
|
|
|
|
|
|
|
|
[m_window setAcceptsMouseMovedEvents:YES];
|
|
|
|
|
2012-12-28 19:26:25 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
2012-12-28 19:10:21 +00:00
|
|
|
NSView *view = [m_window contentView];
|
|
|
|
[view setAcceptsTouchEvents:YES];
|
|
|
|
#endif
|
|
|
|
|
2009-11-10 12:56:46 +00:00
|
|
|
[m_window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
|
|
|
|
NSStringPboardType, NSTIFFPboardType, nil]];
|
2013-03-22 16:11:00 +00:00
|
|
|
|
2013-03-22 23:48:26 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
2013-03-23 16:08:02 +00:00
|
|
|
if (state != GHOST_kWindowStateFullScreen) {
|
|
|
|
[m_window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
|
|
|
}
|
2013-03-22 16:11:00 +00:00
|
|
|
#endif
|
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
if (state == GHOST_kWindowStateFullScreen)
|
|
|
|
setState(GHOST_kWindowStateFullScreen);
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_WindowCocoa::~GHOST_WindowCocoa()
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2011-05-23 15:56:26 +00:00
|
|
|
|
|
|
|
if (m_customCursor) {
|
|
|
|
[m_customCursor release];
|
|
|
|
m_customCursor = nil;
|
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_openGLView release];
|
|
|
|
|
|
|
|
if (m_window) {
|
|
|
|
[m_window close];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
2009-10-12 09:53:28 +00:00
|
|
|
|
2012-12-13 14:25:15 +00:00
|
|
|
// Check for other blender opened windows and make the frontmost key
|
|
|
|
// Note: for some reason the closed window is still in the list
|
2009-10-12 09:53:28 +00:00
|
|
|
NSArray *windowsList = [NSApp orderedWindows];
|
2012-12-13 14:25:15 +00:00
|
|
|
for (int a = 0; a < [windowsList count]; a++) {
|
|
|
|
if (m_window != (CocoaWindow *)[windowsList objectAtIndex:a]) {
|
2012-12-15 18:32:53 +00:00
|
|
|
[[windowsList objectAtIndex:a] makeKeyWindow];
|
2012-12-13 14:25:15 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-10-12 09:53:28 +00:00
|
|
|
}
|
2012-12-13 14:25:15 +00:00
|
|
|
m_window = nil;
|
|
|
|
|
2009-10-08 15:28:31 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
#pragma mark accessors
|
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
bool GHOST_WindowCocoa::getValid() const
|
|
|
|
{
|
2010-01-06 09:22:40 +00:00
|
|
|
return (m_window != 0);
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 19:18:36 +00:00
|
|
|
void* GHOST_WindowCocoa::getOSWindow() const
|
|
|
|
{
|
|
|
|
return (void*)m_window;
|
|
|
|
}
|
2009-09-30 08:47:39 +00:00
|
|
|
|
|
|
|
void GHOST_WindowCocoa::setTitle(const STR_String& title)
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setTitle(): window invalid");
|
2009-10-06 16:56:22 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2011-01-18 20:53:20 +00:00
|
|
|
NSString *windowTitle = [[NSString alloc] initWithCString:title encoding:NSUTF8StringEncoding];
|
2009-10-06 16:56:22 +00:00
|
|
|
|
2009-10-15 08:27:31 +00:00
|
|
|
//Set associated file if applicable
|
2012-09-06 02:10:09 +00:00
|
|
|
if (windowTitle && [windowTitle hasPrefix:@"Blender"]) {
|
2009-10-15 08:27:31 +00:00
|
|
|
NSRange fileStrRange;
|
|
|
|
NSString *associatedFileName;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
fileStrRange.location = [windowTitle rangeOfString:@"["].location+1;
|
|
|
|
len = [windowTitle rangeOfString:@"]"].location - fileStrRange.location;
|
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
if (len > 0) {
|
2009-10-15 08:27:31 +00:00
|
|
|
fileStrRange.length = len;
|
|
|
|
associatedFileName = [windowTitle substringWithRange:fileStrRange];
|
2010-10-02 09:17:32 +00:00
|
|
|
[m_window setTitle:[associatedFileName lastPathComponent]];
|
|
|
|
|
|
|
|
//Blender used file open/save functions converte file names into legal URL ones
|
2011-01-18 20:53:20 +00:00
|
|
|
associatedFileName = [associatedFileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
2009-10-15 08:27:31 +00:00
|
|
|
@try {
|
|
|
|
[m_window setRepresentedFilename:associatedFileName];
|
|
|
|
}
|
|
|
|
@catch (NSException * e) {
|
|
|
|
printf("\nInvalid file path given in window title");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[m_window setTitle:windowTitle];
|
|
|
|
[m_window setRepresentedFilename:@""];
|
|
|
|
}
|
|
|
|
|
2012-09-17 22:34:42 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-10-15 08:27:31 +00:00
|
|
|
[m_window setTitle:windowTitle];
|
|
|
|
[m_window setRepresentedFilename:@""];
|
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
|
|
|
|
[windowTitle release];
|
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GHOST_WindowCocoa::getTitle(STR_String& title) const
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getTitle(): window invalid");
|
2009-10-06 16:56:22 +00:00
|
|
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
NSString *windowTitle = [m_window title];
|
|
|
|
|
|
|
|
if (windowTitle != nil) {
|
2012-09-06 02:10:09 +00:00
|
|
|
title = [windowTitle UTF8String];
|
2009-10-06 16:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GHOST_WindowCocoa::getWindowBounds(GHOST_Rect& bounds) const
|
|
|
|
{
|
2009-10-06 16:56:22 +00:00
|
|
|
NSRect rect;
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getWindowBounds(): window invalid");
|
2009-10-06 16:56:22 +00:00
|
|
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
NSRect screenSize = [[m_window screen] visibleFrame];
|
|
|
|
|
|
|
|
rect = [m_window frame];
|
|
|
|
|
|
|
|
bounds.m_b = screenSize.size.height - (rect.origin.y -screenSize.origin.y);
|
|
|
|
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];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GHOST_WindowCocoa::getClientBounds(GHOST_Rect& bounds) const
|
|
|
|
{
|
2009-10-06 16:56:22 +00:00
|
|
|
NSRect rect;
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getClientBounds(): window invalid");
|
2009-10-06 16:56:22 +00:00
|
|
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-10-09 12:48:28 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
if (!m_fullScreen) {
|
2009-10-09 12:48:28 +00:00
|
|
|
NSRect screenSize = [[m_window screen] visibleFrame];
|
2009-09-30 08:47:39 +00:00
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
//Max window contents as screen size (excluding title bar...)
|
2009-10-12 09:53:28 +00:00
|
|
|
NSRect contentRect = [CocoaWindow contentRectForFrameRect:screenSize
|
|
|
|
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
|
2009-09-30 08:47:39 +00:00
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
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;
|
|
|
|
bounds.m_t = contentRect.size.height - (rect.origin.y + rect.size.height -contentRect.origin.y);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setClientWidth(GHOST_TUns32 width)
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientWidth(): window invalid");
|
2010-03-20 10:14:59 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-09-30 08:47:39 +00:00
|
|
|
GHOST_Rect cBnds, wBnds;
|
|
|
|
getClientBounds(cBnds);
|
|
|
|
if (((GHOST_TUns32)cBnds.getWidth()) != width) {
|
2009-10-06 16:56:22 +00:00
|
|
|
NSSize size;
|
|
|
|
size.width=width;
|
|
|
|
size.height=cBnds.getHeight();
|
|
|
|
[m_window setContentSize:size];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
2010-03-20 10:14:59 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setClientHeight(GHOST_TUns32 height)
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientHeight(): window invalid");
|
2010-03-20 10:14:59 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-09-30 08:47:39 +00:00
|
|
|
GHOST_Rect cBnds, wBnds;
|
|
|
|
getClientBounds(cBnds);
|
|
|
|
if (((GHOST_TUns32)cBnds.getHeight()) != height) {
|
2009-10-06 16:56:22 +00:00
|
|
|
NSSize size;
|
|
|
|
size.width=cBnds.getWidth();
|
|
|
|
size.height=height;
|
|
|
|
[m_window setContentSize:size];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
2010-03-20 10:14:59 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setClientSize(GHOST_TUns32 width, GHOST_TUns32 height)
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setClientSize(): window invalid");
|
2010-03-20 10:14:59 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-09-30 08:47:39 +00:00
|
|
|
GHOST_Rect cBnds, wBnds;
|
|
|
|
getClientBounds(cBnds);
|
2012-09-06 02:10:09 +00:00
|
|
|
if ((((GHOST_TUns32)cBnds.getWidth()) != width) ||
|
|
|
|
(((GHOST_TUns32)cBnds.getHeight()) != height))
|
|
|
|
{
|
2009-10-06 16:56:22 +00:00
|
|
|
NSSize size;
|
|
|
|
size.width=width;
|
|
|
|
size.height=height;
|
|
|
|
[m_window setContentSize:size];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
2010-03-20 10:14:59 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_TWindowState GHOST_WindowCocoa::getState() const
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::getState(): window invalid");
|
2009-10-06 16:56:22 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-09-30 08:47:39 +00:00
|
|
|
GHOST_TWindowState state;
|
2013-05-06 13:39:25 +00:00
|
|
|
|
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
|
|
|
NSUInteger masks = [m_window styleMask];
|
|
|
|
|
|
|
|
if (masks & NSFullScreenWindowMask) {
|
|
|
|
// Lion style fullscreen
|
|
|
|
state = GHOST_kWindowStateFullScreen;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2009-10-09 12:48:28 +00:00
|
|
|
if (m_fullScreen) {
|
|
|
|
state = GHOST_kWindowStateFullScreen;
|
|
|
|
}
|
|
|
|
else if ([m_window isMiniaturized]) {
|
2009-09-30 08:47:39 +00:00
|
|
|
state = GHOST_kWindowStateMinimized;
|
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
else if ([m_window isZoomed]) {
|
2009-09-30 08:47:39 +00:00
|
|
|
state = GHOST_kWindowStateMaximized;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
state = GHOST_kWindowStateNormal;
|
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GHOST_WindowCocoa::screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::screenToClient(): window invalid");
|
2011-06-25 02:10:13 +00:00
|
|
|
|
|
|
|
screenToClientIntern(inX, inY, outX, outY);
|
2011-06-23 19:55:47 +00:00
|
|
|
|
|
|
|
/* switch y to match ghost convention */
|
|
|
|
GHOST_Rect cBnds;
|
|
|
|
getClientBounds(cBnds);
|
|
|
|
outY = (cBnds.getHeight() - 1) - outY;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::clientToScreen(): window invalid");
|
2011-06-23 19:55:47 +00:00
|
|
|
|
|
|
|
/* switch y to match ghost convention */
|
|
|
|
GHOST_Rect cBnds;
|
|
|
|
getClientBounds(cBnds);
|
|
|
|
inY = (cBnds.getHeight() - 1) - inY;
|
2011-06-25 02:10:13 +00:00
|
|
|
|
|
|
|
clientToScreenIntern(inX, inY, outX, outY);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GHOST_WindowCocoa::screenToClientIntern(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
|
|
|
|
{
|
|
|
|
NSPoint screenCoord;
|
|
|
|
NSPoint baseCoord;
|
|
|
|
|
|
|
|
screenCoord.x = inX;
|
|
|
|
screenCoord.y = inY;
|
2009-10-06 16:56:22 +00:00
|
|
|
|
2011-06-25 02:10:13 +00:00
|
|
|
baseCoord = [m_window convertScreenToBase:screenCoord];
|
|
|
|
|
|
|
|
outX = baseCoord.x;
|
|
|
|
outY = baseCoord.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GHOST_WindowCocoa::clientToScreenIntern(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const
|
|
|
|
{
|
2009-10-06 16:56:22 +00:00
|
|
|
NSPoint screenCoord;
|
|
|
|
NSPoint baseCoord;
|
|
|
|
|
|
|
|
baseCoord.x = inX;
|
|
|
|
baseCoord.y = inY;
|
|
|
|
|
|
|
|
screenCoord = [m_window convertBaseToScreen:baseCoord];
|
|
|
|
|
|
|
|
outX = screenCoord.x;
|
|
|
|
outY = screenCoord.y;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 15:39:32 +00:00
|
|
|
|
|
|
|
NSScreen* GHOST_WindowCocoa::getScreen()
|
|
|
|
{
|
|
|
|
return [m_window screen];
|
|
|
|
}
|
|
|
|
|
2013-01-12 17:07:49 +00:00
|
|
|
/* called for event, when window leaves monitor to another */
|
|
|
|
void GHOST_WindowCocoa::setNativePixelSize(void)
|
|
|
|
{
|
2013-01-22 19:06:51 +00:00
|
|
|
/* make sure 10.6 keeps running */
|
|
|
|
if ([m_openGLView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
|
|
|
|
NSRect backingBounds = [m_openGLView convertRectToBacking:[m_openGLView bounds]];
|
|
|
|
|
|
|
|
GHOST_Rect rect;
|
|
|
|
getClientBounds(rect);
|
2013-01-12 17:07:49 +00:00
|
|
|
|
2013-01-22 19:06:51 +00:00
|
|
|
m_nativePixelSize = (float)backingBounds.size.width / (float)rect.getWidth();
|
|
|
|
}
|
2013-01-12 17:07:49 +00:00
|
|
|
}
|
2009-10-21 15:39:32 +00:00
|
|
|
|
2009-10-12 09:53:28 +00:00
|
|
|
/**
|
2012-09-06 02:10:09 +00:00
|
|
|
* \note Fullscreen switch is not actual fullscreen with display capture.
|
|
|
|
* As this capture removes all OS X window manager features.
|
|
|
|
*
|
2009-10-12 09:53:28 +00:00
|
|
|
* Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.
|
|
|
|
* Thus, process switch, exposé, spaces, ... still work in fullscreen mode
|
|
|
|
*/
|
2009-09-30 08:47:39 +00:00
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setState(GHOST_TWindowState state)
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setState(): window invalid");
|
2012-09-06 02:10:09 +00:00
|
|
|
switch (state) {
|
2009-10-09 12:48:28 +00:00
|
|
|
case GHOST_kWindowStateMinimized:
|
2012-09-06 02:10:09 +00:00
|
|
|
[m_window miniaturize:nil];
|
|
|
|
break;
|
2009-10-09 12:48:28 +00:00
|
|
|
case GHOST_kWindowStateMaximized:
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_window zoom:nil];
|
|
|
|
break;
|
2009-10-09 12:48:28 +00:00
|
|
|
|
2013-07-19 10:40:43 +00:00
|
|
|
case GHOST_kWindowStateFullScreen:
|
|
|
|
{
|
2013-05-06 13:39:25 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
|
|
|
NSUInteger masks = [m_window styleMask];
|
|
|
|
|
|
|
|
if (!m_fullScreen && !(masks & NSFullScreenWindowMask)) {
|
|
|
|
#else
|
2012-09-06 02:10:09 +00:00
|
|
|
if (!m_fullScreen) {
|
2013-05-06 13:39:25 +00:00
|
|
|
#endif
|
2009-10-09 12:48:28 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
/* 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. */
|
2009-10-09 12:48:28 +00:00
|
|
|
m_fullScreen = true;
|
|
|
|
|
2013-05-06 13:39:25 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
|
|
|
/* Disable toggle for Lion style fullscreen */
|
|
|
|
[m_window setCollectionBehavior:NSWindowCollectionBehaviorDefault];
|
|
|
|
#endif
|
|
|
|
|
2012-12-15 11:15:05 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
2009-10-12 09:53:28 +00:00
|
|
|
//10.6 provides Cocoa functions to autoshow menu bar, and to change a window style
|
2013-03-23 16:08:02 +00:00
|
|
|
//Hide menu & dock if on primary screen. else only menu
|
2012-09-06 02:10:09 +00:00
|
|
|
if ([[m_window screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) {
|
2013-03-23 16:08:02 +00:00
|
|
|
[NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
|
2009-10-12 09:53:28 +00:00
|
|
|
}
|
|
|
|
//Make window borderless and enlarge it
|
|
|
|
[m_window setStyleMask:NSBorderlessWindowMask];
|
|
|
|
[m_window setFrame:[[m_window screen] frame] display:YES];
|
2009-10-19 10:49:45 +00:00
|
|
|
[m_window makeFirstResponder:m_openGLView];
|
2009-10-12 09:53:28 +00:00
|
|
|
#else
|
|
|
|
//With 10.5, we need to create a new window to change its style to borderless
|
|
|
|
//Hide menu & dock if needed
|
2012-09-06 02:10:09 +00:00
|
|
|
if ([[m_window screen] isEqual:[[NSScreen screens] objectAtIndex:0]]) {
|
2009-10-12 09:53:28 +00:00
|
|
|
//Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:NO];
|
|
|
|
//One of the very few 64bit compatible Carbon function
|
|
|
|
SetSystemUIMode(kUIModeAllHidden,kUIOptionAutoShowMenuBar);
|
|
|
|
}
|
|
|
|
//Create a fullscreen borderless window
|
|
|
|
CocoaWindow *tmpWindow = [[CocoaWindow alloc]
|
|
|
|
initWithContentRect:[[m_window screen] frame]
|
|
|
|
styleMask:NSBorderlessWindowMask
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:YES];
|
|
|
|
//Copy current window parameters
|
|
|
|
[tmpWindow setTitle:[m_window title]];
|
2009-10-15 08:27:31 +00:00
|
|
|
[tmpWindow setRepresentedFilename:[m_window representedFilename]];
|
2009-10-12 09:53:28 +00:00
|
|
|
[tmpWindow setAcceptsMouseMovedEvents:YES];
|
|
|
|
[tmpWindow setDelegate:[m_window delegate]];
|
2011-01-01 19:48:14 +00:00
|
|
|
[tmpWindow setSystemAndWindowCocoa:[m_window systemCocoa] windowCocoa:this];
|
2010-12-04 14:26:45 +00:00
|
|
|
[tmpWindow registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
|
2012-09-06 02:10:09 +00:00
|
|
|
NSStringPboardType, NSTIFFPboardType, nil]];
|
2009-10-09 12:48:28 +00:00
|
|
|
|
2009-10-12 09:53:28 +00:00
|
|
|
//Assign the openGL view to the new window
|
|
|
|
[tmpWindow setContentView:m_openGLView];
|
|
|
|
|
|
|
|
//Show the new window
|
2010-12-04 14:26:45 +00:00
|
|
|
[tmpWindow makeKeyAndOrderFront:m_openGLView];
|
2009-10-12 09:53:28 +00:00
|
|
|
//Close and release old window
|
|
|
|
[m_window close];
|
|
|
|
m_window = tmpWindow;
|
|
|
|
#endif
|
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
//Tell WM of view new size
|
|
|
|
m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
|
|
|
|
|
|
|
|
[pool drain];
|
|
|
|
}
|
|
|
|
break;
|
2013-05-06 13:39:25 +00:00
|
|
|
}
|
2009-10-09 12:48:28 +00:00
|
|
|
case GHOST_kWindowStateNormal:
|
2012-09-06 02:10:09 +00:00
|
|
|
default:
|
2010-09-16 19:42:51 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2013-05-06 13:39:25 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
|
|
|
NSUInteger masks = [m_window styleMask];
|
|
|
|
|
|
|
|
if (masks & NSFullScreenWindowMask) {
|
|
|
|
// Lion style fullscreen
|
|
|
|
[m_window toggleFullScreen:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
2012-09-06 02:10:09 +00:00
|
|
|
if (m_fullScreen) {
|
2009-10-09 12:48:28 +00:00
|
|
|
m_fullScreen = false;
|
|
|
|
|
2013-05-06 13:39:25 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
|
|
|
/* Enable toggle for into Lion style fullscreen */
|
|
|
|
[m_window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
|
|
|
#endif
|
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
//Exit fullscreen
|
2012-12-15 11:15:05 +00:00
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
|
2009-10-12 09:53:28 +00:00
|
|
|
//Show again menu & dock if needed
|
2012-09-06 02:10:09 +00:00
|
|
|
if ([[m_window screen] isEqual:[NSScreen mainScreen]]) {
|
2009-10-12 09:53:28 +00:00
|
|
|
[NSApp setPresentationOptions:NSApplicationPresentationDefault];
|
|
|
|
}
|
|
|
|
//Make window normal and resize it
|
|
|
|
[m_window setStyleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)];
|
|
|
|
[m_window setFrame:[[m_window screen] visibleFrame] display:YES];
|
2009-11-04 17:50:31 +00:00
|
|
|
//TODO for 10.6 only : window title is forgotten after the style change
|
2009-10-19 10:49:45 +00:00
|
|
|
[m_window makeFirstResponder:m_openGLView];
|
2009-10-12 09:53:28 +00:00
|
|
|
#else
|
|
|
|
//With 10.5, we need to create a new window to change its style to borderless
|
|
|
|
//Show menu & dock if needed
|
2012-09-06 02:10:09 +00:00
|
|
|
if ([[m_window screen] isEqual:[NSScreen mainScreen]]) {
|
2009-10-12 09:53:28 +00:00
|
|
|
//Cocoa function in 10.5 does not allow to set the menu bar in auto-show mode [NSMenu setMenuBarVisible:YES];
|
|
|
|
SetSystemUIMode(kUIModeNormal, 0); //One of the very few 64bit compatible Carbon function
|
|
|
|
}
|
|
|
|
//Create a fullscreen borderless window
|
|
|
|
CocoaWindow *tmpWindow = [[CocoaWindow alloc]
|
|
|
|
initWithContentRect:[[m_window screen] frame]
|
|
|
|
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:YES];
|
|
|
|
//Copy current window parameters
|
|
|
|
[tmpWindow setTitle:[m_window title]];
|
2009-10-15 08:27:31 +00:00
|
|
|
[tmpWindow setRepresentedFilename:[m_window representedFilename]];
|
2009-10-12 09:53:28 +00:00
|
|
|
[tmpWindow setAcceptsMouseMovedEvents:YES];
|
|
|
|
[tmpWindow setDelegate:[m_window delegate]];
|
2011-01-01 19:48:14 +00:00
|
|
|
[tmpWindow setSystemAndWindowCocoa:[m_window systemCocoa] windowCocoa:this];
|
2010-12-04 14:26:45 +00:00
|
|
|
[tmpWindow registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,
|
|
|
|
NSStringPboardType, NSTIFFPboardType, nil]];
|
|
|
|
//Forbid to resize the window below the blender defined minimum one
|
2013-01-24 17:57:38 +00:00
|
|
|
[tmpWindow setContentMinSize:NSMakeSize(320, 240)];
|
2009-10-09 12:48:28 +00:00
|
|
|
|
2009-10-12 09:53:28 +00:00
|
|
|
//Assign the openGL view to the new window
|
|
|
|
[tmpWindow setContentView:m_openGLView];
|
2009-10-09 12:48:28 +00:00
|
|
|
|
2009-10-12 09:53:28 +00:00
|
|
|
//Show the new window
|
|
|
|
[tmpWindow makeKeyAndOrderFront:nil];
|
|
|
|
//Close and release old window
|
|
|
|
[m_window close];
|
|
|
|
m_window = tmpWindow;
|
|
|
|
#endif
|
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
//Tell WM of view new size
|
|
|
|
m_systemCocoa->handleWindowEvent(GHOST_kEventWindowSize, this);
|
|
|
|
}
|
2012-09-06 02:10:09 +00:00
|
|
|
else if ([m_window isMiniaturized])
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_window deminiaturize:nil];
|
|
|
|
else if ([m_window isZoomed])
|
|
|
|
[m_window zoom:nil];
|
2010-09-16 19:42:51 +00:00
|
|
|
[pool drain];
|
2012-09-06 02:10:09 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-09-16 19:42:51 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
return GHOST_kSuccess;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-05 12:55:16 +00:00
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setModifiedState(bool isUnsavedChanges)
|
|
|
|
{
|
2009-10-09 12:48:28 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_window setDocumentEdited:isUnsavedChanges];
|
2009-10-05 12:55:16 +00:00
|
|
|
|
2009-10-09 12:48:28 +00:00
|
|
|
[pool drain];
|
2009-10-05 12:55:16 +00:00
|
|
|
return GHOST_Window::setModifiedState(isUnsavedChanges);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setOrder(GHOST_TWindowOrder order)
|
|
|
|
{
|
2010-02-16 16:38:29 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::setOrder(): window invalid");
|
2012-09-06 02:10:09 +00:00
|
|
|
if (order == GHOST_kWindowOrderTop) {
|
2009-11-09 17:06:48 +00:00
|
|
|
[m_window makeKeyAndOrderFront:nil];
|
2012-09-06 02:10:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-11-09 17:06:48 +00:00
|
|
|
NSArray *windowsList;
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_window orderBack:nil];
|
2009-11-09 17:06:48 +00:00
|
|
|
|
|
|
|
//Check for other blender opened windows and make the frontmost key
|
|
|
|
windowsList = [NSApp orderedWindows];
|
|
|
|
if ([windowsList count]) {
|
|
|
|
[[windowsList objectAtIndex:0] makeKeyAndOrderFront:nil];
|
|
|
|
}
|
2012-09-06 02:10:09 +00:00
|
|
|
}
|
2010-02-16 16:38:29 +00:00
|
|
|
|
|
|
|
[pool drain];
|
2012-09-06 02:10:09 +00:00
|
|
|
return GHOST_kSuccess;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
#pragma mark Drawing context
|
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
/*#define WAIT_FOR_VSYNC 1*/
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::swapBuffers()
|
|
|
|
{
|
2012-09-06 02:10:09 +00:00
|
|
|
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
|
|
|
|
if (m_openGLContext != nil) {
|
2009-10-08 15:28:31 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_openGLContext flushBuffer];
|
2009-10-08 15:28:31 +00:00
|
|
|
[pool drain];
|
2012-09-06 02:10:09 +00:00
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GHOST_kFailure;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::updateDrawingContext()
|
|
|
|
{
|
|
|
|
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
|
2009-10-06 16:56:22 +00:00
|
|
|
if (m_openGLContext != nil) {
|
2009-10-08 15:28:31 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_openGLContext update];
|
2009-10-08 15:28:31 +00:00
|
|
|
[pool drain];
|
2009-10-06 16:56:22 +00:00
|
|
|
return GHOST_kSuccess;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
return GHOST_kFailure;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::activateDrawingContext()
|
|
|
|
{
|
|
|
|
if (m_drawingContextType == GHOST_kDrawingContextTypeOpenGL) {
|
2009-10-06 16:56:22 +00:00
|
|
|
if (m_openGLContext != nil) {
|
2009-10-08 15:28:31 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_openGLContext makeCurrentContext];
|
2010-01-06 15:34:49 +00:00
|
|
|
|
|
|
|
// Disable AA by default
|
|
|
|
if (m_numOfAASamples > 0) glDisable(GL_MULTISAMPLE_ARB);
|
2009-10-08 15:28:31 +00:00
|
|
|
[pool drain];
|
2009-10-06 16:56:22 +00:00
|
|
|
return GHOST_kSuccess;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
return GHOST_kFailure;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::installDrawingContext(GHOST_TDrawingContextType type)
|
|
|
|
{
|
|
|
|
GHOST_TSuccess success = GHOST_kFailure;
|
2009-10-06 16:56:22 +00:00
|
|
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
|
|
|
NSOpenGLPixelFormat *pixelFormat;
|
|
|
|
NSOpenGLContext *tmpOpenGLContext;
|
|
|
|
|
2009-10-20 08:13:12 +00:00
|
|
|
/***** Multithreaded opengl code : uncomment for enabling
|
|
|
|
CGLContextObj cglCtx;
|
|
|
|
*/
|
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
switch (type) {
|
|
|
|
case GHOST_kDrawingContextTypeOpenGL:
|
|
|
|
if (!getValid()) break;
|
2011-09-25 12:31:21 +00:00
|
|
|
|
2009-10-12 16:51:36 +00:00
|
|
|
pixelFormat = [m_openGLView pixelFormat];
|
|
|
|
tmpOpenGLContext = [[NSOpenGLContext alloc] initWithFormat:pixelFormat
|
|
|
|
shareContext:s_firstOpenGLcontext];
|
|
|
|
if (tmpOpenGLContext == nil) {
|
|
|
|
success = GHOST_kFailure;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-20 08:13:12 +00:00
|
|
|
//Switch openGL to multhreaded mode
|
|
|
|
/******* Multithreaded opengl code : uncomment for enabling
|
|
|
|
cglCtx = (CGLContextObj)[tmpOpenGLContext CGLContextObj];
|
|
|
|
if (CGLEnable(cglCtx, kCGLCEMPEngine) == kCGLNoError)
|
2012-08-28 13:43:20 +00:00
|
|
|
printf("\nSwitched openGL to multithreaded mode\n");
|
2009-10-20 08:13:12 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-12 16:51:36 +00:00
|
|
|
if (!s_firstOpenGLcontext) s_firstOpenGLcontext = tmpOpenGLContext;
|
2009-10-06 16:56:22 +00:00
|
|
|
#ifdef WAIT_FOR_VSYNC
|
2009-11-24 10:19:07 +00:00
|
|
|
{
|
|
|
|
GLint swapInt = 1;
|
2009-10-06 16:56:22 +00:00
|
|
|
/* wait for vsync, to avoid tearing artifacts */
|
2009-11-24 10:19:07 +00:00
|
|
|
[tmpOpenGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
|
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
#endif
|
2009-11-24 10:19:07 +00:00
|
|
|
[m_openGLView setOpenGLContext:tmpOpenGLContext];
|
|
|
|
[tmpOpenGLContext setView:m_openGLView];
|
|
|
|
|
|
|
|
m_openGLContext = tmpOpenGLContext;
|
2009-09-30 08:47:39 +00:00
|
|
|
break;
|
2009-11-24 10:19:07 +00:00
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
case GHOST_kDrawingContextTypeNone:
|
|
|
|
success = GHOST_kSuccess;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::removeDrawingContext()
|
|
|
|
{
|
2009-10-06 16:56:22 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-09-30 08:47:39 +00:00
|
|
|
switch (m_drawingContextType) {
|
|
|
|
case GHOST_kDrawingContextTypeOpenGL:
|
2012-09-06 02:10:09 +00:00
|
|
|
if (m_openGLContext) {
|
2009-10-12 16:51:36 +00:00
|
|
|
[m_openGLView clearGLContext];
|
|
|
|
if (s_firstOpenGLcontext == m_openGLContext) s_firstOpenGLcontext = nil;
|
|
|
|
m_openGLContext = nil;
|
|
|
|
}
|
2009-10-09 12:48:28 +00:00
|
|
|
[pool drain];
|
2009-10-06 16:56:22 +00:00
|
|
|
return GHOST_kSuccess;
|
2009-09-30 08:47:39 +00:00
|
|
|
case GHOST_kDrawingContextTypeNone:
|
2009-10-09 12:48:28 +00:00
|
|
|
[pool drain];
|
2009-10-06 16:56:22 +00:00
|
|
|
return GHOST_kSuccess;
|
2009-09-30 08:47:39 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-10-09 12:48:28 +00:00
|
|
|
[pool drain];
|
2009-10-06 16:56:22 +00:00
|
|
|
return GHOST_kFailure;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::invalidate()
|
|
|
|
{
|
2012-10-17 17:20:09 +00:00
|
|
|
GHOST_ASSERT(getValid(), "GHOST_WindowCocoa::invalidate(): window invalid");
|
2009-10-06 16:56:22 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-10-09 12:48:28 +00:00
|
|
|
[m_openGLView setNeedsDisplay:YES];
|
2009-10-06 16:56:22 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
|
2010-06-01 20:21:40 +00:00
|
|
|
#pragma mark Progress bar
|
|
|
|
|
|
|
|
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];
|
2012-09-06 02:10:09 +00:00
|
|
|
NSRect progressBox = {{4, 4}, {120, 16}};
|
|
|
|
|
2012-12-11 14:39:26 +00:00
|
|
|
[[NSImage imageNamed:@"NSApplicationIcon"] drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
|
2012-09-06 02:10:09 +00:00
|
|
|
|
|
|
|
// Track & Outline
|
|
|
|
[[NSColor blackColor] setFill];
|
|
|
|
NSRectFill(progressBox);
|
|
|
|
|
|
|
|
[[NSColor whiteColor] set];
|
|
|
|
NSFrameRect(progressBox);
|
|
|
|
|
|
|
|
// Progress fill
|
|
|
|
progressBox = NSInsetRect(progressBox, 1, 1);
|
|
|
|
|
|
|
|
progressBox.size.width = progressBox.size.width * progress;
|
|
|
|
NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[NSColor darkGrayColor] endingColor:[NSColor lightGrayColor]];
|
|
|
|
[gradient drawInRect:progressBox angle:90];
|
|
|
|
[gradient release];
|
2010-06-01 20:21:40 +00:00
|
|
|
|
|
|
|
[dockIcon unlockFocus];
|
|
|
|
|
|
|
|
[NSApp setApplicationIconImage:dockIcon];
|
|
|
|
[dockIcon release];
|
|
|
|
|
|
|
|
m_progressBarVisible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
[pool drain];
|
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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];
|
2012-12-11 14:39:26 +00:00
|
|
|
[[NSImage imageNamed:@"NSApplicationIcon"] drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
|
2010-06-01 20:21:40 +00:00
|
|
|
[dockIcon unlockFocus];
|
|
|
|
[NSApp setApplicationIconImage:dockIcon];
|
|
|
|
[dockIcon release];
|
|
|
|
|
|
|
|
[pool drain];
|
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
#pragma mark Cursor handling
|
2009-09-30 08:47:39 +00:00
|
|
|
|
|
|
|
void GHOST_WindowCocoa::loadCursor(bool visible, GHOST_TStandardCursor cursor) const
|
|
|
|
{
|
|
|
|
static bool systemCursorVisible = true;
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
NSCursor *tmpCursor =nil;
|
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
if (visible != systemCursorVisible) {
|
|
|
|
if (visible) {
|
2009-10-06 16:56:22 +00:00
|
|
|
[NSCursor unhide];
|
2009-09-30 08:47:39 +00:00
|
|
|
systemCursorVisible = true;
|
|
|
|
}
|
|
|
|
else {
|
2009-10-06 16:56:22 +00:00
|
|
|
[NSCursor hide];
|
2009-09-30 08:47:39 +00:00
|
|
|
systemCursorVisible = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cursor == GHOST_kStandardCursorCustom && m_customCursor) {
|
2009-10-06 16:56:22 +00:00
|
|
|
tmpCursor = m_customCursor;
|
2012-09-17 22:34:42 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-09-30 08:47:39 +00:00
|
|
|
switch (cursor) {
|
2009-10-06 16:56:22 +00:00
|
|
|
case GHOST_kStandardCursorDestroy:
|
|
|
|
tmpCursor = [NSCursor disappearingItemCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorText:
|
|
|
|
tmpCursor = [NSCursor IBeamCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorCrosshair:
|
|
|
|
tmpCursor = [NSCursor crosshairCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorUpDown:
|
|
|
|
tmpCursor = [NSCursor resizeUpDownCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorLeftRight:
|
|
|
|
tmpCursor = [NSCursor resizeLeftRightCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorTopSide:
|
|
|
|
tmpCursor = [NSCursor resizeUpCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorBottomSide:
|
|
|
|
tmpCursor = [NSCursor resizeDownCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorLeftSide:
|
|
|
|
tmpCursor = [NSCursor resizeLeftCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorRightSide:
|
|
|
|
tmpCursor = [NSCursor resizeRightCursor];
|
|
|
|
break;
|
|
|
|
case GHOST_kStandardCursorRightArrow:
|
|
|
|
case GHOST_kStandardCursorInfo:
|
|
|
|
case GHOST_kStandardCursorLeftArrow:
|
|
|
|
case GHOST_kStandardCursorHelp:
|
|
|
|
case GHOST_kStandardCursorCycle:
|
|
|
|
case GHOST_kStandardCursorSpray:
|
|
|
|
case GHOST_kStandardCursorWait:
|
|
|
|
case GHOST_kStandardCursorTopLeftCorner:
|
|
|
|
case GHOST_kStandardCursorTopRightCorner:
|
|
|
|
case GHOST_kStandardCursorBottomRightCorner:
|
|
|
|
case GHOST_kStandardCursorBottomLeftCorner:
|
Drag and drop 2.5 integration! Finally, slashdot regulars can use
Blender too now! :)
** Drag works as follows:
- drag-able items are defined by the standard interface ui toolkit
- each button can get this feature, via uiButSetDragXXX(but, ...).
There are calls to define drag-able images, ID blocks, RNA paths,
file paths, and so on. By default you drag an icon, exceptionally
an ImBuf
- Drag items are registered centrally in the WM, it allows more drag
items simultaneous too, but not implemented
** Drop works as follows:
- On mouse release, and if drag items exist in the WM, it converts
the mouse event to an EVT_DROP type. This event then gets the full
drag info as customdata
- drop regions are defined with WM_dropbox_add(), similar to keymaps
you can make a "drop map" this way, which become 'drop map handlers'
in the queues.
- next to that the UI kit handles some common button types (like
accepting ID or names) to be catching a drop event too.
- Every "drop box" has two callbacks:
- poll() = check if the event drag data is relevant for this box
- copy() = fill in custom properties in the dropbox to initialize
an operator
- The dropbox handler then calls its standard Operator with its
dropbox properties.
** Currently implemented
Drag items:
- ID icons in browse buttons
- ID icons in context menu of properties region
- ID icons in outliner and rna viewer
- FileBrowser icons
- FileBrowser preview images
Drag-able icons are subtly visualized by making them brighter a bit
on mouse-over. In case the icon is a button or UI element too (most
cases), the drag-able feature will make the item react to
mouse-release instead of mouse-press.
Drop options:
- UI buttons: ID and text buttons (paste name)
- View3d: Object ID drop copies object
- View3d: Material ID drop assigns to object under cursor
- View3d: Image ID drop assigns to object UV texture under cursor
- Sequencer: Path drop will add either Image or Movie strip
- Image window: Path drop will open image
** Drag and drop Notes:
- Dropping into another Blender window (from same application) works
too. I've added code that passes on mousemoves and clicks to other
windows, without activating them though. This does make using multi-window
Blender a bit friendler.
- Dropping a file path to an image, is not the same as dropping an
Image ID... keep this in mind. Sequencer for example wants paths to
be dropped, textures in 3d window wants an Image ID.
- Although drop boxes could be defined via Python, I suggest they're
part of the UI and editor design (= how we want an editor to work), and
not default offered configurable like keymaps.
- At the moment only one item can be dragged at a time. This is for
several reasons.... For one, Blender doesn't have a well defined
uniform way to define "what is selected" (files, outliner items, etc).
Secondly there's potential conflicts on what todo when you drop mixed
drag sets on spots. All undefined stuff... nice for later.
- Example to bypass the above: a collection of images that form a strip,
should be represented in filewindow as a single sequence anyway.
This then will fit well and gets handled neatly by design.
- Another option to check is to allow multiple options per drop... it
could show the operator as a sort of menu, allowing arrow or scrollwheel
to choose. For time being I'd prefer to try to design a singular drop
though, just offer only one drop action per data type on given spots.
- What does work already, but a tad slow, is to use a function that
detects an object (type) under cursor, so a drag item's option can be
further refined (like drop object on object = parent). (disabled)
** More notes
- Added saving for Region layouts (like split points for toolbar)
- Label buttons now handle mouse over
- File list: added full path entry for drop feature.
- Filesel bugfix: wm_operator_exec() got called there and fully handled,
while WM event code tried same. Added new OPERATOR_HANDLED flag for this.
Maybe python needs it too?
- Cocoa: added window move event, so multi-win setups work OK (didnt save).
- Interface_handlers.c: removed win->active
- Severe area copy bug: area handlers were not set to NULL
- Filesel bugfix: next/prev folder list was not copied on area copies
** Leftover todos
- Cocoa windows seem to hang on cases still... needs check
- Cocoa 'draw overlap' swap doesn't work
- Cocoa window loses focus permanently on using Spotlight
(for these reasons, makefile building has Carbon as default atm)
- ListView templates in UI cannot become dragged yet, needs review...
it consists of two overlapping UI elements, preventing handling icon clicks.
- There's already Ghost library code to handle dropping from OS
into Blender window. I've noticed this code is unfinished for Macs, but
seems to be complete for Windows. Needs test... currently, an external
drop event will print in console when succesfully delivered to Blender's WM.
2010-01-26 18:18:21 +00:00
|
|
|
case GHOST_kStandardCursorCopy:
|
2009-10-06 16:56:22 +00:00
|
|
|
case GHOST_kStandardCursorDefault:
|
|
|
|
default:
|
|
|
|
tmpCursor = [NSCursor arrowCursor];
|
|
|
|
break;
|
2009-09-30 08:47:39 +00:00
|
|
|
};
|
|
|
|
}
|
2009-10-06 16:56:22 +00:00
|
|
|
[tmpCursor set];
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorVisibility(bool visible)
|
|
|
|
{
|
2010-03-20 10:14:59 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
if ([m_window isVisible]) {
|
2009-09-30 08:47:39 +00:00
|
|
|
loadCursor(visible, getCursorShape());
|
|
|
|
}
|
|
|
|
|
2010-03-20 10:14:59 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
2009-10-09 14:42:36 +00:00
|
|
|
|
2009-10-09 17:42:31 +00:00
|
|
|
|
2009-10-19 10:49:45 +00:00
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorGrab(GHOST_TGrabCursorMode mode)
|
2009-10-09 17:42:31 +00:00
|
|
|
{
|
2009-10-19 10:49:45 +00:00
|
|
|
GHOST_TSuccess err = GHOST_kSuccess;
|
2009-10-09 17:42:31 +00:00
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
if (mode != GHOST_kGrabDisable) {
|
2009-10-09 17:42:31 +00:00
|
|
|
//No need to perform grab without warp as it is always on in OS X
|
2012-09-06 02:10:09 +00:00
|
|
|
if (mode != GHOST_kGrabNormal) {
|
2009-10-09 17:42:31 +00:00
|
|
|
GHOST_TInt32 x_old,y_old;
|
2010-02-01 11:20:01 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-10-09 17:42:31 +00:00
|
|
|
|
|
|
|
m_systemCocoa->getCursorPosition(x_old,y_old);
|
2011-06-25 02:10:13 +00:00
|
|
|
screenToClientIntern(x_old, y_old, m_cursorGrabInitPos[0], m_cursorGrabInitPos[1]);
|
2009-10-09 17:42:31 +00:00
|
|
|
//Warp position is stored in client (window base) coordinates
|
2009-10-19 10:49:45 +00:00
|
|
|
setCursorGrabAccum(0, 0);
|
|
|
|
|
2012-09-06 02:10:09 +00:00
|
|
|
if (mode == GHOST_kGrabHide) {
|
2009-10-19 10:49:45 +00:00
|
|
|
setWindowCursorVisibility(false);
|
|
|
|
}
|
|
|
|
|
2010-02-01 11:20:01 +00:00
|
|
|
//Make window key if it wasn't to get the mouse move events
|
|
|
|
[m_window makeKeyWindow];
|
|
|
|
|
2009-10-19 10:49:45 +00:00
|
|
|
//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;
|
2010-02-01 11:20:01 +00:00
|
|
|
|
|
|
|
[pool drain];
|
2009-10-09 14:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-09-06 02:10:09 +00:00
|
|
|
if (m_cursorGrab==GHOST_kGrabHide) {
|
2009-10-19 10:49:45 +00:00
|
|
|
//No need to set again cursor position, as it has not changed for Cocoa
|
2009-10-09 14:42:36 +00:00
|
|
|
setWindowCursorVisibility(true);
|
|
|
|
}
|
2009-10-19 10:49:45 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1; /* disable */
|
2009-10-09 14:42:36 +00:00
|
|
|
}
|
2009-10-19 10:49:45 +00:00
|
|
|
return err;
|
2009-10-09 14:42:36 +00:00
|
|
|
}
|
2009-09-30 08:47:39 +00:00
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setWindowCursorShape(GHOST_TStandardCursor shape)
|
|
|
|
{
|
2010-03-20 10:14:59 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
if (m_customCursor) {
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_customCursor release];
|
|
|
|
m_customCursor = nil;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
if ([m_window isVisible]) {
|
2009-09-30 08:47:39 +00:00
|
|
|
loadCursor(getCursorVisibility(), shape);
|
|
|
|
}
|
|
|
|
|
2010-03-20 10:14:59 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
|
2009-10-15 20:09:50 +00:00
|
|
|
/** Reverse the bits in a GHOST_TUns8
|
2009-09-30 08:47:39 +00:00
|
|
|
static GHOST_TUns8 uns8ReverseBits(GHOST_TUns8 ch)
|
|
|
|
{
|
2012-08-11 22:12:32 +00:00
|
|
|
ch= ((ch >> 1) & 0x55) | ((ch << 1) & 0xAA);
|
|
|
|
ch= ((ch >> 2) & 0x33) | ((ch << 2) & 0xCC);
|
|
|
|
ch= ((ch >> 4) & 0x0F) | ((ch << 4) & 0xF0);
|
2009-09-30 08:47:39 +00:00
|
|
|
return ch;
|
|
|
|
}
|
2009-10-15 20:09:50 +00:00
|
|
|
*/
|
2009-09-30 08:47:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** Reverse the bits in a GHOST_TUns16 */
|
|
|
|
static GHOST_TUns16 uns16ReverseBits(GHOST_TUns16 shrt)
|
|
|
|
{
|
2012-08-11 22:12:32 +00:00
|
|
|
shrt = ((shrt >> 1) & 0x5555) | ((shrt << 1) & 0xAAAA);
|
|
|
|
shrt = ((shrt >> 2) & 0x3333) | ((shrt << 2) & 0xCCCC);
|
|
|
|
shrt = ((shrt >> 4) & 0x0F0F) | ((shrt << 4) & 0xF0F0);
|
|
|
|
shrt = ((shrt >> 8) & 0x00FF) | ((shrt << 8) & 0xFF00);
|
2009-09-30 08:47:39 +00:00
|
|
|
return shrt;
|
|
|
|
}
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
|
2012-05-19 09:57:55 +00:00
|
|
|
int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color)
|
2009-09-30 08:47:39 +00:00
|
|
|
{
|
2009-10-15 20:09:50 +00:00
|
|
|
int y,nbUns16;
|
2009-10-06 16:56:22 +00:00
|
|
|
NSPoint hotSpotPoint;
|
2009-10-15 20:09:50 +00:00
|
|
|
NSBitmapImageRep *cursorImageRep;
|
2009-10-06 16:56:22 +00:00
|
|
|
NSImage *cursorImage;
|
2009-10-15 20:09:50 +00:00
|
|
|
NSSize imSize;
|
|
|
|
GHOST_TUns16 *cursorBitmap;
|
|
|
|
|
|
|
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-09-30 08:47:39 +00:00
|
|
|
|
|
|
|
if (m_customCursor) {
|
2009-10-06 16:56:22 +00:00
|
|
|
[m_customCursor release];
|
|
|
|
m_customCursor = nil;
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 20:09:50 +00:00
|
|
|
|
|
|
|
cursorImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
|
2011-09-25 12:31:21 +00:00
|
|
|
pixelsWide:sizex
|
2009-10-15 20:09:50 +00:00
|
|
|
pixelsHigh:sizey
|
|
|
|
bitsPerSample:1
|
|
|
|
samplesPerPixel:2
|
|
|
|
hasAlpha:YES
|
|
|
|
isPlanar:YES
|
2009-10-19 10:49:45 +00:00
|
|
|
colorSpaceName:NSDeviceWhiteColorSpace
|
2009-10-15 20:09:50 +00:00
|
|
|
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++) {
|
2009-09-30 08:47:39 +00:00
|
|
|
#if !defined(__LITTLE_ENDIAN__)
|
2009-10-19 10:49:45 +00:00
|
|
|
cursorBitmap[y] = ~uns16ReverseBits((bitmap[2*y]<<0) | (bitmap[2*y+1]<<8));
|
2009-10-15 20:09:50 +00:00
|
|
|
cursorBitmap[nbUns16+y] = uns16ReverseBits((mask[2*y]<<0) | (mask[2*y+1]<<8));
|
2009-09-30 08:47:39 +00:00
|
|
|
#else
|
2009-10-19 10:49:45 +00:00
|
|
|
cursorBitmap[y] = ~uns16ReverseBits((bitmap[2*y+1]<<0) | (bitmap[2*y]<<8));
|
2009-10-15 20:09:50 +00:00
|
|
|
cursorBitmap[nbUns16+y] = uns16ReverseBits((mask[2*y+1]<<0) | (mask[2*y]<<8));
|
2009-09-30 08:47:39 +00:00
|
|
|
#endif
|
2009-10-15 20:09:50 +00:00
|
|
|
|
2009-09-30 08:47:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-15 20:09:50 +00:00
|
|
|
imSize.width = sizex;
|
|
|
|
imSize.height= sizey;
|
|
|
|
cursorImage = [[NSImage alloc] initWithSize:imSize];
|
|
|
|
[cursorImage addRepresentation:cursorImageRep];
|
|
|
|
|
2009-10-06 16:56:22 +00:00
|
|
|
hotSpotPoint.x = hotX;
|
|
|
|
hotSpotPoint.y = hotY;
|
|
|
|
|
2009-10-15 20:09:50 +00:00
|
|
|
//foreground and background color parameter is not handled for now (10.6)
|
2009-10-06 16:56:22 +00:00
|
|
|
m_customCursor = [[NSCursor alloc] initWithImage:cursorImage
|
|
|
|
hotSpot:hotSpotPoint];
|
|
|
|
|
2009-10-15 20:09:50 +00:00
|
|
|
[cursorImageRep release];
|
2009-10-06 16:56:22 +00:00
|
|
|
[cursorImage release];
|
|
|
|
|
|
|
|
if ([m_window isVisible]) {
|
2009-09-30 08:47:39 +00:00
|
|
|
loadCursor(getCursorVisibility(), GHOST_kStandardCursorCustom);
|
|
|
|
}
|
2009-10-15 20:09:50 +00:00
|
|
|
[pool drain];
|
2009-09-30 08:47:39 +00:00
|
|
|
return GHOST_kSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2],
|
2012-05-19 09:57:55 +00:00
|
|
|
GHOST_TUns8 mask[16][2], int hotX, int hotY)
|
2009-09-30 08:47:39 +00:00
|
|
|
{
|
|
|
|
return setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*) mask, 16, 16, hotX, hotY, 0, 1);
|
|
|
|
}
|