window centering stuff for OSX tinydisplay

This commit is contained in:
rdb 2009-12-16 14:28:21 +00:00
parent 85fda457fa
commit 9426525fcc

View File

@ -36,8 +36,7 @@
//////////////////////////////////// ////////////////////////////////////
\ \
Mutex & OSXGloablMutex() Mutex & OSXGloablMutex() {
{
static Mutex m("OSXWIN_Mutex"); static Mutex m("OSXWIN_Mutex");
return m; return m;
} }
@ -49,8 +48,7 @@ struct work1
}; };
#define PANDA_CREATE_WINDOW 101 #define PANDA_CREATE_WINDOW 101
static void Post_Event_Wiait(unsigned short type, unsigned int data1 , unsigned int data2 , int target_window ) static void Post_Event_Wiait(unsigned short type, unsigned int data1 , unsigned int data2 , int target_window ) {
{
work1 w; work1 w;
w.work_done = false; w.work_done = false;
NSEvent *ev = [NSEvent otherEventWithType:NSApplicationDefined NSEvent *ev = [NSEvent otherEventWithType:NSApplicationDefined
@ -84,22 +82,18 @@ TinyOsxGraphicsWindow * TinyOsxGraphicsWindow::FullScreenWindow = NULL;
#ifdef USER_CONTAINER #ifdef USER_CONTAINER
std::set< WindowRef > MyWindows; std::set< WindowRef > MyWindows;
void AddAWindow( WindowRef window) void AddAWindow( WindowRef window) {
{
MyWindows.insert(window); MyWindows.insert(window);
} }
bool checkmywindow(WindowRef window) bool checkmywindow(WindowRef window) {
{
return MyWindows.find(window) != MyWindows.end(); return MyWindows.find(window) != MyWindows.end();
} }
#else #else
void AddAWindow( WindowRef window) void AddAWindow( WindowRef window) {
{
} }
bool checkmywindow(WindowRef window) bool checkmywindow(WindowRef window) {
{
return true; return true;
} }
@ -113,8 +107,7 @@ bool checkmywindow(WindowRef window)
// Description: How to find the active window for events on osx.. // Description: How to find the active window for events on osx..
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
TinyOsxGraphicsWindow* TinyOsxGraphicsWindow::GetCurrentOSxWindow(WindowRef window) TinyOsxGraphicsWindow* TinyOsxGraphicsWindow::GetCurrentOSxWindow(WindowRef window) {
{
if (FullScreenWindow != NULL) if (FullScreenWindow != NULL)
return FullScreenWindow; return FullScreenWindow;
@ -128,8 +121,7 @@ TinyOsxGraphicsWindow* TinyOsxGraphicsWindow::GetCurrentOSxWindow(WindowRef wind
} }
if (window && checkmywindow(window)) if (window && checkmywindow(window))
//if (window ) //if (window ) {
{
return (TinyOsxGraphicsWindow *)GetWRefCon (window); return (TinyOsxGraphicsWindow *)GetWRefCon (window);
} }
else else
@ -142,8 +134,7 @@ TinyOsxGraphicsWindow* TinyOsxGraphicsWindow::GetCurrentOSxWindow(WindowRef wind
// Description: The standard window event handler for non-fullscreen // Description: The standard window event handler for non-fullscreen
// windows. // windows.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
OSStatus TinyOsxGraphicsWindow::event_handler(EventHandlerCallRef myHandler, EventRef event) OSStatus TinyOsxGraphicsWindow::event_handler(EventHandlerCallRef myHandler, EventRef event) {
{
OSStatus result = eventNotHandledErr; OSStatus result = eventNotHandledErr;
UInt32 the_class = GetEventClass(event); UInt32 the_class = GetEventClass(event);
@ -152,13 +143,11 @@ OSStatus TinyOsxGraphicsWindow::event_handler(EventHandlerCallRef myHandler, Eve
WindowRef window = NULL; WindowRef window = NULL;
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
if (tinydisplay_cat.is_spam()) if (tinydisplay_cat.is_spam()) {
{
tinydisplay_cat.spam() << ClockObject::get_global_clock()->get_real_time() << " event_handler: " << (void *)this << ", " << window << ", " << the_class << ", " << kind << "\n"; tinydisplay_cat.spam() << ClockObject::get_global_clock()->get_real_time() << " event_handler: " << (void *)this << ", " << window << ", " << the_class << ", " << kind << "\n";
} }
switch (the_class) switch (the_class) {
{
case kEventClassMouse: case kEventClassMouse:
result = handleWindowMouseEvents (myHandler, event); result = handleWindowMouseEvents (myHandler, event);
break; break;
@ -224,16 +213,12 @@ OSStatus TinyOsxGraphicsWindow::event_handler(EventHandlerCallRef myHandler, Eve
// instance with Cmd-W, or by clicking on the close // instance with Cmd-W, or by clicking on the close
// button. // button.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::user_close_request() void TinyOsxGraphicsWindow::user_close_request() {
{
string close_request_event = get_close_request_event(); string close_request_event = get_close_request_event();
if (!close_request_event.empty()) if (!close_request_event.empty()) {
{
// In this case, the app has indicated a desire to intercept the request and process it directly. // In this case, the app has indicated a desire to intercept the request and process it directly.
throw_event(close_request_event); throw_event(close_request_event);
} } else {
else
{
// In this case, the default case, the app does not intend to service the request, so we do by closing the window. // In this case, the default case, the app does not intend to service the request, so we do by closing the window.
close_window(); close_window();
} }
@ -245,8 +230,7 @@ void TinyOsxGraphicsWindow::user_close_request()
// Description: The Windows is closed by a OS resource not by a internal request // Description: The Windows is closed by a OS resource not by a internal request
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::SystemCloseWindow() void TinyOsxGraphicsWindow::SystemCloseWindow() {
{
if (tinydisplay_cat.is_debug()) if (tinydisplay_cat.is_debug())
tinydisplay_cat.debug() << "System Closing Window \n"; tinydisplay_cat.debug() << "System Closing Window \n";
ReleaseSystemResources(); ReleaseSystemResources();
@ -261,8 +245,7 @@ void TinyOsxGraphicsWindow::SystemCloseWindow()
// handle system window events.. // handle system window events..
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
static pascal OSStatus windowEvtHndlr(EventHandlerCallRef myHandler, EventRef event, void *userData) static pascal OSStatus windowEvtHndlr(EventHandlerCallRef myHandler, EventRef event, void *userData) {
{
#pragma unused (userData) #pragma unused (userData)
// volatile().lock(); // volatile().lock();
@ -270,11 +253,9 @@ static pascal OSStatus windowEvtHndlr(EventHandlerCallRef myHandler, EventRef ev
WindowRef window = NULL; WindowRef window = NULL;
GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); GetEventParameter(event, kEventParamDirectObject, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
if (window != NULL) if (window != NULL) {
{
TinyOsxGraphicsWindow *osx_win = TinyOsxGraphicsWindow::GetCurrentOSxWindow(window); TinyOsxGraphicsWindow *osx_win = TinyOsxGraphicsWindow::GetCurrentOSxWindow(window);
if (osx_win != (TinyOsxGraphicsWindow *)NULL) if (osx_win != (TinyOsxGraphicsWindow *)NULL) {
{
//OSXGloablMutex().release(); //OSXGloablMutex().release();
return osx_win->event_handler(myHandler, event); return osx_win->event_handler(myHandler, event);
} }
@ -292,14 +273,11 @@ static pascal OSStatus windowEvtHndlr(EventHandlerCallRef myHandler, EventRef ev
// We only hook this up for none fullscreen window... so we only handle system window events.. // We only hook this up for none fullscreen window... so we only handle system window events..
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::DoResize(void) {
void TinyOsxGraphicsWindow::DoResize(void)
{
tinydisplay_cat.info() << "In Resize....." << _properties << "\n"; tinydisplay_cat.info() << "In Resize....." << _properties << "\n";
// only in window mode .. not full screen // only in window mode .. not full screen
if(_osx_window != NULL && !_is_fullscreen && _properties.has_size()) if (_osx_window != NULL && !_is_fullscreen && _properties.has_size()) {
{
Rect rectPort = {0,0,0,0}; Rect rectPort = {0,0,0,0};
CGRect viewRect = {{0.0f, 0.0f}, {0.0f, 0.0f}}; CGRect viewRect = {{0.0f, 0.0f}, {0.0f, 0.0f}};
@ -313,9 +291,9 @@ void TinyOsxGraphicsWindow::DoResize(void)
system_changed_properties(properties); system_changed_properties(properties);
ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size()); ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size());
if (tinydisplay_cat.is_debug()) if (tinydisplay_cat.is_debug()) {
tinydisplay_cat.debug() << " Resizing Window " << viewRect.size.width << " " << viewRect.size.height << "\n"; tinydisplay_cat.debug() << " Resizing Window " << viewRect.size.width << " " << viewRect.size.height << "\n";
}
} }
}; };
@ -327,9 +305,7 @@ void TinyOsxGraphicsWindow::DoResize(void)
// Hooked once for application // Hooked once for application
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
static pascal OSStatus appEvtHndlr (EventHandlerCallRef myHandler, EventRef event, void* userData) {
static pascal OSStatus appEvtHndlr (EventHandlerCallRef myHandler, EventRef event, void* userData)
{
#pragma unused (myHandler) #pragma unused (myHandler)
OSStatus result = eventNotHandledErr; OSStatus result = eventNotHandledErr;
{ {
@ -343,17 +319,16 @@ static pascal OSStatus appEvtHndlr (EventHandlerCallRef myHandler, EventRef even
GetEventParameter(event, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, (void*) &window); GetEventParameter(event, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, (void*) &window);
osx_win = TinyOsxGraphicsWindow::GetCurrentOSxWindow(window); osx_win = TinyOsxGraphicsWindow::GetCurrentOSxWindow(window);
if (osx_win == NULL) if (osx_win == NULL) {
{
//OSXGloablMutex().release(); //OSXGloablMutex().release();
return eventNotHandledErr; return eventNotHandledErr;
} }
switch (the_class) switch (the_class) {
{
case kEventClassTextInput: case kEventClassTextInput:
if(kind == kEventTextInputUnicodeForKeyEvent) if (kind == kEventTextInputUnicodeForKeyEvent) {
osx_win->handleTextInput(myHandler, event); osx_win->handleTextInput(myHandler, event);
}
//result = noErr; //result = noErr;
// //
// can not report handled .. the os will not sent the raw key strokes then // can not report handled .. the os will not sent the raw key strokes then
@ -374,8 +349,7 @@ static pascal OSStatus appEvtHndlr (EventHandlerCallRef myHandler, EventRef even
{ {
UInt32 newModifiers; UInt32 newModifiers;
OSStatus error = GetEventParameter(event, kEventParamKeyModifiers,typeUInt32, NULL,sizeof(UInt32), NULL, &newModifiers); OSStatus error = GetEventParameter(event, kEventParamKeyModifiers,typeUInt32, NULL,sizeof(UInt32), NULL, &newModifiers);
if(error == noErr) if (error == noErr) {
{
osx_win->HandleModifireDeleta(newModifiers); osx_win->HandleModifireDeleta(newModifiers);
result = noErr; result = noErr;
} }
@ -406,24 +380,25 @@ static pascal OSStatus appEvtHndlr (EventHandlerCallRef myHandler, EventRef even
// //
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
OSStatus TinyOsxGraphicsWindow::handleTextInput (EventHandlerCallRef myHandler, EventRef theTextEvent) OSStatus TinyOsxGraphicsWindow::handleTextInput (EventHandlerCallRef myHandler, EventRef theTextEvent) {
{
UniChar *text = NULL; UniChar *text = NULL;
UInt32 actualSize = 0; UInt32 actualSize = 0;
OSStatus ret = GetEventParameter (theTextEvent, kEventParamTextInputSendText, typeUnicodeText, NULL, 0, &actualSize, NULL); OSStatus ret = GetEventParameter (theTextEvent, kEventParamTextInputSendText, typeUnicodeText, NULL, 0, &actualSize, NULL);
if(ret != noErr) if (ret != noErr) {
return ret; return ret;
}
text = (UniChar*)NewPtr(actualSize); text = (UniChar*)NewPtr(actualSize);
if(text!= NULL) if (text!= NULL) {
{
ret = GetEventParameter (theTextEvent, kEventParamTextInputSendText,typeUnicodeText, NULL, actualSize, NULL, text); ret = GetEventParameter (theTextEvent, kEventParamTextInputSendText,typeUnicodeText, NULL, actualSize, NULL, text);
if(ret != noErr) if (ret != noErr) {
return ret; return ret;
}
for(unsigned int x = 0; x < actualSize/sizeof(UniChar); ++x) for (unsigned int x = 0; x < actualSize/sizeof(UniChar); ++x) {
_input_devices[0].keystroke(text[x]); _input_devices[0].keystroke(text[x]);
}
DisposePtr((char *)text); DisposePtr((char *)text);
} }
@ -434,10 +409,8 @@ OSStatus TinyOsxGraphicsWindow::handleTextInput (EventHandlerCallRef myHandler,
// Access: private.. // Access: private..
// Description: Clean up the OS level messes.. // Description: Clean up the OS level messes..
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::ReleaseSystemResources() void TinyOsxGraphicsWindow::ReleaseSystemResources() {
{ if (_is_fullscreen) {
if (_is_fullscreen)
{
_is_fullscreen = false; _is_fullscreen = false;
FullScreenWindow = NULL; FullScreenWindow = NULL;
@ -449,8 +422,7 @@ void TinyOsxGraphicsWindow::ReleaseSystemResources()
_originalMode = NULL; _originalMode = NULL;
} }
if(_osx_window != NULL) if (_osx_window != NULL) {
{
SetWRefCon (_osx_window, (long int) NULL); SetWRefCon (_osx_window, (long int) NULL);
HideWindow (_osx_window); HideWindow (_osx_window);
DisposeWindow(_osx_window); DisposeWindow(_osx_window);
@ -498,8 +470,7 @@ TinyOsxGraphicsWindow::TinyOsxGraphicsWindow(GraphicsEngine *engine, GraphicsPip
_pending_icon(NULL), _pending_icon(NULL),
_current_icon(NULL), _current_icon(NULL),
_originalMode(NULL), _originalMode(NULL),
_ID(id_seed++) _ID(id_seed++) {
{
GraphicsWindowInputDevice device = GraphicsWindowInputDevice device =
GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard/mouse"); GraphicsWindowInputDevice::pointer_and_keyboard(this, "keyboard/mouse");
_input_devices.push_back(device); _input_devices.push_back(device);
@ -523,8 +494,7 @@ TinyOsxGraphicsWindow::TinyOsxGraphicsWindow(GraphicsEngine *engine, GraphicsPip
// Access: Public, Virtual // Access: Public, Virtual
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
TinyOsxGraphicsWindow::~TinyOsxGraphicsWindow() TinyOsxGraphicsWindow::~TinyOsxGraphicsWindow() {
{
if (tinydisplay_cat.is_debug()) if (tinydisplay_cat.is_debug())
tinydisplay_cat.debug() << "TinyOsxGraphicsWindow::~TinyOsxGraphicsWindow() -" <<_ID << "\n"; tinydisplay_cat.debug() << "TinyOsxGraphicsWindow::~TinyOsxGraphicsWindow() -" <<_ID << "\n";
@ -544,8 +514,7 @@ TinyOsxGraphicsWindow::~TinyOsxGraphicsWindow()
// be applied to the window. Returns true on success, // be applied to the window. Returns true on success,
// false on failure. // false on failure.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool TinyOsxGraphicsWindow::set_icon_filename(const Filename &icon_filename) bool TinyOsxGraphicsWindow::set_icon_filename(const Filename &icon_filename) {
{
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr(); VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
Filename icon_pathname = icon_filename; Filename icon_pathname = icon_filename;
@ -562,21 +531,18 @@ bool TinyOsxGraphicsWindow::set_icon_filename(const Filename &icon_filename)
PNMImage pnmimage; PNMImage pnmimage;
if (!pnmimage.read(icon_pathname)) if (!pnmimage.read(icon_pathname)) {
{
tinydisplay_cat.warning() tinydisplay_cat.warning()
<< "Could not read icon filename " << icon_pathname << "\n"; << "Could not read icon filename " << icon_pathname << "\n";
return false; return false;
} }
CGImageRef icon_image = TinyOsxGraphicsPipe::create_cg_image(pnmimage); CGImageRef icon_image = TinyOsxGraphicsPipe::create_cg_image(pnmimage);
if (icon_image == NULL) if (icon_image == NULL) {
{
return false; return false;
} }
if (_pending_icon != NULL) if (_pending_icon != NULL) {
{
CGImageRelease(_pending_icon); CGImageRelease(_pending_icon);
_pending_icon = NULL; _pending_icon = NULL;
} }
@ -591,8 +557,7 @@ bool TinyOsxGraphicsWindow::set_icon_filename(const Filename &icon_filename)
// window. // window.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow:: void TinyOsxGraphicsWindow::
set_pointer_in_window(int x, int y) set_pointer_in_window(int x, int y) {
{
_input_devices[0].set_pointer_in_window(x, y); _input_devices[0].set_pointer_in_window(x, y);
if (_cursor_hidden != _display_hide_cursor) { if (_cursor_hidden != _display_hide_cursor) {
@ -632,14 +597,12 @@ set_pointer_out_of_window() {
// if the frame should be rendered, or false if it // if the frame should be rendered, or false if it
// should be skipped. // should be skipped.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool TinyOsxGraphicsWindow::begin_frame(FrameMode mode, Thread *current_thread) bool TinyOsxGraphicsWindow::begin_frame(FrameMode mode, Thread *current_thread) {
{
PStatTimer timer(_make_current_pcollector); PStatTimer timer(_make_current_pcollector);
begin_frame_spam(mode); begin_frame_spam(mode);
if (_gsg == (GraphicsStateGuardian *)NULL || if (_gsg == (GraphicsStateGuardian *)NULL ||
(_osx_window == NULL && !_is_fullscreen)) (_osx_window == NULL && !_is_fullscreen)) {
{
// not powered up .. just abort.. // not powered up .. just abort..
return false; return false;
} }
@ -647,16 +610,13 @@ bool TinyOsxGraphicsWindow::begin_frame(FrameMode mode, Thread *current_thread)
// Now is a good time to apply the icon change that may have // Now is a good time to apply the icon change that may have
// recently been requested. By this point, we should be able to get // recently been requested. By this point, we should be able to get
// a handle to the dock context. // a handle to the dock context.
if (_pending_icon != NULL) if (_pending_icon != NULL) {
{
CGContextRef context = BeginCGContextForApplicationDockTile(); CGContextRef context = BeginCGContextForApplicationDockTile();
if (context != NULL) if (context != NULL) {
{
SetApplicationDockTileImage(_pending_icon); SetApplicationDockTileImage(_pending_icon);
EndCGContextForApplicationDockTile(context); EndCGContextForApplicationDockTile(context);
if (_current_icon != NULL) if (_current_icon != NULL) {
{
CGImageRelease(_current_icon); CGImageRelease(_current_icon);
_current_icon = NULL; _current_icon = NULL;
} }
@ -682,8 +642,7 @@ bool TinyOsxGraphicsWindow::begin_frame(FrameMode mode, Thread *current_thread)
// after rendering is completed for a given frame. It // after rendering is completed for a given frame. It
// should do whatever finalization is required. // should do whatever finalization is required.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::end_frame(FrameMode mode, Thread *current_thread) void TinyOsxGraphicsWindow::end_frame(FrameMode mode, Thread *current_thread) {
{
end_frame_spam(mode); end_frame_spam(mode);
_gsg->end_frame(current_thread); _gsg->end_frame(current_thread);
@ -714,8 +673,7 @@ void TinyOsxGraphicsWindow::end_frame(FrameMode mode, Thread *current_thread)
// end_flip(), to make it easier to flip all of the // end_flip(), to make it easier to flip all of the
// windows at the same time. // windows at the same time.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::begin_flip() void TinyOsxGraphicsWindow::begin_flip() {
{
if (_osx_window == NULL) { if (_osx_window == NULL) {
return; return;
} }
@ -765,8 +723,7 @@ void TinyOsxGraphicsWindow::begin_flip()
// Description: Closes the window right now. Called from the window // Description: Closes the window right now. Called from the window
// thread. // thread.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::close_window() void TinyOsxGraphicsWindow::close_window() {
{
SystemCloseWindow(); SystemCloseWindow();
WindowProperties properties; WindowProperties properties;
@ -803,8 +760,7 @@ void TinyOsxGraphicsWindow::close_window()
// thread. Returns true if the window is successfully // thread. Returns true if the window is successfully
// opened, or false if there was a problem. // opened, or false if there was a problem.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool TinyOsxGraphicsWindow::open_window() bool TinyOsxGraphicsWindow::open_window() {
{
// GSG Creation/Initialization // GSG Creation/Initialization
TinyGraphicsStateGuardian *tinygsg; TinyGraphicsStateGuardian *tinygsg;
if (_gsg == 0) { if (_gsg == 0) {
@ -838,23 +794,18 @@ bool TinyOsxGraphicsWindow::open_window()
} }
bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties) bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties) {
{
OSErr err = noErr; OSErr err = noErr;
if (_current_icon != NULL && _pending_icon == NULL) if (_current_icon != NULL && _pending_icon == NULL) {
{
// If we already have an icon specified, we'll need to reapply it // If we already have an icon specified, we'll need to reapply it
// when the window is succesfully created. // when the window is succesfully created.
_pending_icon = _current_icon; _pending_icon = _current_icon;
_current_icon = NULL; _current_icon = NULL;
} }
static bool GlobalInits = false; static bool GlobalInits = false;
if (!GlobalInits) if (!GlobalInits) {
{
// //
// one time aplication inits.. to get a window open from a standalone aplication.. // one time aplication inits.. to get a window open from a standalone aplication..
@ -917,30 +868,24 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties)
SetFrontProcess(&psn); SetFrontProcess(&psn);
} }
if (req_properties.has_fullscreen() && req_properties.get_fullscreen()) if (req_properties.has_fullscreen() && req_properties.get_fullscreen()) {
{
tinydisplay_cat.info() << "Creating full screen\n"; tinydisplay_cat.info() << "Creating full screen\n";
// capture the main display // capture the main display
CGDisplayCapture(kCGDirectMainDisplay); CGDisplayCapture(kCGDirectMainDisplay);
// if sized try and switch it.. // if sized try and switch it..
if (req_properties.has_size()) if (req_properties.has_size()) {
{
_originalMode = CGDisplayCurrentMode(kCGDirectMainDisplay); _originalMode = CGDisplayCurrentMode(kCGDirectMainDisplay);
CFDictionaryRef newMode = CGDisplayBestModeForParameters(kCGDirectMainDisplay, 32, req_properties.get_x_size(), req_properties.get_y_size(), 0); CFDictionaryRef newMode = CGDisplayBestModeForParameters(kCGDirectMainDisplay, 32, req_properties.get_x_size(), req_properties.get_y_size(), 0);
if (newMode == NULL) if (newMode == NULL) {
{
tinydisplay_cat.error() tinydisplay_cat.error()
<< "Invalid fullscreen size: " << req_properties.get_x_size() << "Invalid fullscreen size: " << req_properties.get_x_size()
<< ", " << req_properties.get_y_size() << ", " << req_properties.get_y_size()
<< "\n"; << "\n";
} } else {
else
{
CGDisplaySwitchToMode(kCGDirectMainDisplay, newMode); CGDisplaySwitchToMode(kCGDirectMainDisplay, newMode);
// Set our new window size according to the size we actually got. // Set our new window size according to the size we actually got.
SInt32 width, height; SInt32 width, height;
CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(newMode, kCGDisplayWidth), kCFNumberSInt32Type, &width); CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(newMode, kCGDisplayWidth), kCFNumberSInt32Type, &width);
CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(newMode, kCGDisplayHeight), kCFNumberSInt32Type, &height); CFNumberGetValue((CFNumberRef)CFDictionaryGetValue(newMode, kCGDisplayHeight), kCFNumberSInt32Type, &height);
@ -953,35 +898,52 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties)
_is_fullscreen = true; _is_fullscreen = true;
FullScreenWindow = this; FullScreenWindow = this;
req_properties.clear_fullscreen(); req_properties.clear_fullscreen();
} } else {
else
{
Rect r; Rect r;
if (req_properties.has_origin()) if (req_properties.has_origin()) {
{
r.top = req_properties.get_y_origin(); r.top = req_properties.get_y_origin();
r.left = req_properties.get_x_origin(); r.left = req_properties.get_x_origin();
// A coordinate of -2 means to center the window on screen.
if (r.top == -2 || r.left == -2) {
if (req_properties.has_size()) {
if (r.top == -2) {
r.top = 0.5 * (_pipe->get_display_height() - req_properties.get_y_size());
} }
else if (r.left == -2) {
{ r.left = 0.5 * (_pipe->get_display_width() - req_properties.get_x_size());
}
} else {
if (r.top == -2) {
r.top = 0.5 * (_pipe->get_display_height() - req_properties.get_y_size());
}
if (r.left == -2) {
r.left = 0.5 * (_pipe->get_display_width() - req_properties.get_x_size());
}
}
_properties.set_origin(r.left, r.top);
}
if (r.top == -1) {
r.top = 50;
}
if (r.left == -1) {
r.left = 10;
}
} else {
r.top = 50; r.top = 50;
r.left = 10; r.left = 10;
} }
if (req_properties.has_size()) if (req_properties.has_size()) {
{
r.right = r.left + req_properties.get_x_size(); r.right = r.left + req_properties.get_x_size();
r.bottom = r.top + req_properties.get_y_size(); r.bottom = r.top + req_properties.get_y_size();
} } else {
else
{
r.right = r.left + 512; r.right = r.left + 512;
r.bottom = r.top + 512; r.bottom = r.top + 512;
} }
/* /*
if (req_properties.has_parent_window()) if (req_properties.has_parent_window()) {
{
tinydisplay_cat.info() << "Creating child window\n"; tinydisplay_cat.info() << "Creating child window\n";
CreateNewWindow(kSimpleWindowClass, kWindowNoAttributes, &r, &_osx_window); CreateNewWindow(kSimpleWindowClass, kWindowNoAttributes, &r, &_osx_window);
@ -992,9 +954,7 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties)
} }
else */ else */
{ {
if (req_properties.has_undecorated() && req_properties.get_undecorated()) if (req_properties.has_undecorated() && req_properties.get_undecorated()) { // create a unmovable .. no edge window..
{ // create a unmovable .. no edge window..
tinydisplay_cat.info() << "Creating undecorated window\n"; tinydisplay_cat.info() << "Creating undecorated window\n";
CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowNoTitleBarAttribute, &r, &_osx_window); CreateNewWindow(kDocumentWindowClass, kWindowStandardDocumentAttributes | kWindowNoTitleBarAttribute, &r, &_osx_window);
@ -1019,8 +979,7 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties)
} }
if (_osx_window) if (_osx_window) {
{
EventHandlerUPP gWinEvtHandler; // window event handler EventHandlerUPP gWinEvtHandler; // window event handler
EventTypeSpec list[] = EventTypeSpec list[] =
@ -1073,14 +1032,12 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties)
} */ } */
if (req_properties.has_fullscreen()) if (req_properties.has_fullscreen()) {
{
_properties.set_fullscreen(false); _properties.set_fullscreen(false);
req_properties.clear_fullscreen(); req_properties.clear_fullscreen();
} }
if (req_properties.has_undecorated()) if (req_properties.has_undecorated()) {
{
_properties.set_undecorated(req_properties.get_undecorated()); _properties.set_undecorated(req_properties.get_undecorated());
req_properties.clear_undecorated(); req_properties.clear_undecorated();
} }
@ -1090,13 +1047,15 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties)
// actually ended up with. // actually ended up with.
Rect rectPort = {0,0,0,0}; Rect rectPort = {0,0,0,0};
GetWindowPortBounds (_osx_window, &rectPort); GetWindowPortBounds (_osx_window, &rectPort);
_properties.set_origin((int) rectPort.left, (int) rectPort.top);
_properties.set_size((int) (rectPort.right - rectPort.left), (int) (rectPort.bottom - rectPort.top)); _properties.set_size((int) (rectPort.right - rectPort.left), (int) (rectPort.bottom - rectPort.top));
req_properties.clear_size(); req_properties.clear_size();
req_properties.clear_origin(); req_properties.clear_origin();
} }
if (req_properties.has_icon_filename()) if (req_properties.has_icon_filename()) {
set_icon_filename(req_properties.get_icon_filename()); set_icon_filename(req_properties.get_icon_filename());
}
_properties.set_foreground(true); _properties.set_foreground(true);
_properties.set_minimized(false); _properties.set_minimized(false);
@ -1116,19 +1075,16 @@ bool TinyOsxGraphicsWindow::OSOpenWindow(WindowProperties &req_properties)
// back into panda // back into panda
// //
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::process_events() void TinyOsxGraphicsWindow::process_events() {
{
GraphicsWindow::process_events(); GraphicsWindow::process_events();
if (!osx_disable_event_loop) if (!osx_disable_event_loop) {
{
EventRef theEvent; EventRef theEvent;
EventTargetRef theTarget = GetEventDispatcherTarget(); EventTargetRef theTarget = GetEventDispatcherTarget();
/*if (!_properties.has_parent_window())*/ /*if (!_properties.has_parent_window())*/
{ {
while (ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &theEvent)== noErr) while (ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &theEvent)== noErr) {
{
SendEventToEventTarget (theEvent, theTarget); SendEventToEventTarget (theEvent, theTarget);
ReleaseEvent(theEvent); ReleaseEvent(theEvent);
} }
@ -1165,7 +1121,6 @@ supports_pixel_zoom() const {
// key input handler // key input handler
OSStatus TinyOsxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown) { OSStatus TinyOsxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, EventRef event, Boolean keyDown) {
if (tinydisplay_cat.is_debug()) { if (tinydisplay_cat.is_debug()) {
UInt32 keyCode; UInt32 keyCode;
GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode); GetEventParameter (event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode);
@ -1186,19 +1141,17 @@ OSStatus TinyOsxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, E
// function in the first place. // function in the first place.
UInt32 newModifiers = 0; UInt32 newModifiers = 0;
OSStatus error = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &newModifiers); OSStatus error = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &newModifiers);
if(error == noErr) if (error == noErr) {
HandleModifireDeleta(newModifiers); HandleModifireDeleta(newModifiers);
}
UInt32 keyCode; UInt32 keyCode;
GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode); GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, sizeof(UInt32), NULL, &keyCode);
ButtonHandle button = OSX_TranslateKey(keyCode, event); ButtonHandle button = OSX_TranslateKey(keyCode, event);
if (keyDown) if (keyDown) {
{ if ((newModifiers & cmdKey) != 0) {
if ((newModifiers & cmdKey) != 0) if (button == KeyboardButton::ascii_key("q") || button == KeyboardButton::ascii_key("w")) {
{
if (button == KeyboardButton::ascii_key("q") || button == KeyboardButton::ascii_key("w"))
{
// Command-Q or Command-W: quit the application or close the // Command-Q or Command-W: quit the application or close the
// window, respectively. For now, we treat them both the // window, respectively. For now, we treat them both the
// same: close the window. // same: close the window.
@ -1206,9 +1159,7 @@ OSStatus TinyOsxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, E
} }
} }
SendKeyEvent(button, true); SendKeyEvent(button, true);
} } else {
else
{
SendKeyEvent(button, false); SendKeyEvent(button, false);
} }
return CallNextEventHandler(myHandler, event); return CallNextEventHandler(myHandler, event);
@ -1220,8 +1171,7 @@ OSStatus TinyOsxGraphicsWindow::handleKeyInput (EventHandlerCallRef myHandler, E
// Access: // Access:
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::SystemSetWindowForground(bool forground) void TinyOsxGraphicsWindow::SystemSetWindowForground(bool forground) {
{
WindowProperties properties; WindowProperties properties;
properties.set_foreground(forground); properties.set_foreground(forground);
system_changed_properties(properties); system_changed_properties(properties);
@ -1232,10 +1182,8 @@ void TinyOsxGraphicsWindow::SystemSetWindowForground(bool forground)
// Access: // Access:
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint) void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint) {
{ if (_osx_window != NULL) {
if(_osx_window != NULL)
{
GrafPtr savePort; GrafPtr savePort;
Boolean portChanged = QDSwapPort(GetWindowPort(_osx_window), &savePort); Boolean portChanged = QDSwapPort(GetWindowPort(_osx_window), &savePort);
@ -1251,9 +1199,7 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
// Access: // Access:
// Description: // Description:
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
OSStatus TinyOsxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event) {
OSStatus TinyOsxGraphicsWindow::handleWindowMouseEvents (EventHandlerCallRef myHandler, EventRef event)
{
WindowRef window = NULL; WindowRef window = NULL;
OSStatus result = eventNotHandledErr; OSStatus result = eventNotHandledErr;
UInt32 kind = GetEventKind (event); UInt32 kind = GetEventKind (event);
@ -1271,8 +1217,7 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
GetEventParameter(event, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window); GetEventParameter(event, kEventParamWindowRef, typeWindowRef, NULL, sizeof(WindowRef), NULL, &window);
if (!_is_fullscreen && (window == NULL || window != _osx_window )) { if (!_is_fullscreen && (window == NULL || window != _osx_window )) {
if (kind == kEventMouseMoved) if (kind == kEventMouseMoved) {
{
set_pointer_out_of_window(); set_pointer_out_of_window();
} }
return eventNotHandledErr; return eventNotHandledErr;
@ -1283,8 +1228,7 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
GetWindowPortBounds (window, &rectPort); GetWindowPortBounds (window, &rectPort);
// result = CallNextEventHandler(myHandler, event); // result = CallNextEventHandler(myHandler, event);
// if (eventNotHandledErr == result) // if (eventNotHandledErr == result) { // only handle events not already handled (prevents wierd resize interaction)
{ // only handle events not already handled (prevents wierd resize interaction)
switch (kind) { switch (kind) {
// Whenever mouse button state changes, generate the // Whenever mouse button state changes, generate the
// appropriate Panda down/up events to represent the // appropriate Panda down/up events to represent the
@ -1294,8 +1238,7 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
case kEventMouseUp: case kEventMouseUp:
{ {
GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers); GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, sizeof(UInt32), NULL, &modifiers);
if (_properties.get_mouse_mode() == WindowProperties::M_relative) if (_properties.get_mouse_mode() == WindowProperties::M_relative) {
{
GetEventParameter(event, kEventParamMouseDelta,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint); GetEventParameter(event, kEventParamMouseDelta,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint);
MouseData currMouse = get_pointer(0); MouseData currMouse = get_pointer(0);
qdGlobalPoint.h += currMouse.get_x(); qdGlobalPoint.h += currMouse.get_x();
@ -1317,16 +1260,13 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
case kEventMouseMoved: case kEventMouseMoved:
case kEventMouseDragged: case kEventMouseDragged:
if(_properties.get_mouse_mode()==WindowProperties::M_relative) if (_properties.get_mouse_mode()==WindowProperties::M_relative) {
{
GetEventParameter(event, kEventParamMouseDelta,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint); GetEventParameter(event, kEventParamMouseDelta,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint);
MouseData currMouse=get_pointer(0); MouseData currMouse=get_pointer(0);
qdGlobalPoint.h+=currMouse.get_x(); qdGlobalPoint.h+=currMouse.get_x();
qdGlobalPoint.v+=currMouse.get_y(); qdGlobalPoint.v+=currMouse.get_y();
} } else {
else
{
GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint); GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint);
SystemPointToLocalPoint(qdGlobalPoint); SystemPointToLocalPoint(qdGlobalPoint);
} }
@ -1348,8 +1288,7 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint); GetEventParameter(event, kEventParamMouseLocation,typeQDPoint, NULL, sizeof(Point),NULL , (void*) &qdGlobalPoint);
SystemPointToLocalPoint(qdGlobalPoint); SystemPointToLocalPoint(qdGlobalPoint);
if (wheelAxis == kEventMouseWheelAxisY) if (wheelAxis == kEventMouseWheelAxisY) {
{
set_pointer_in_window((int)qdGlobalPoint.h, (int)qdGlobalPoint.v); set_pointer_in_window((int)qdGlobalPoint.h, (int)qdGlobalPoint.v);
_wheel_delta += this_wheel_delta; _wheel_delta += this_wheel_delta;
SInt32 wheel_scale = osx_mouse_wheel_scale; SInt32 wheel_scale = osx_mouse_wheel_scale;
@ -1370,7 +1309,6 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
//result = noErr; //result = noErr;
} }
return result; return result;
} }
@ -1379,13 +1317,10 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
// Access: Private // Access: Private
// Description: MAC Key Codes to Panda Key Codes // Description: MAC Key Codes to Panda Key Codes
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
ButtonHandle TinyOsxGraphicsWindow::OSX_TranslateKey(UInt32 key, EventRef event) ButtonHandle TinyOsxGraphicsWindow::OSX_TranslateKey(UInt32 key, EventRef event) {
{
ButtonHandle nk = ButtonHandle::none(); ButtonHandle nk = ButtonHandle::none();
switch ( key ) switch ( key ) {
{
case 0: nk = KeyboardButton::ascii_key('a'); break; case 0: nk = KeyboardButton::ascii_key('a'); break;
case 11: nk = KeyboardButton::ascii_key('b'); break; case 11: nk = KeyboardButton::ascii_key('b'); break;
case 8: nk = KeyboardButton::ascii_key('c'); break; case 8: nk = KeyboardButton::ascii_key('c'); break;
@ -1511,8 +1446,7 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
// Access: Private // Access: Private
// Description: Used to emulate key events for the MAC key Modifiers.. // Description: Used to emulate key events for the MAC key Modifiers..
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::HandleModifireDeleta(UInt32 newModifiers) void TinyOsxGraphicsWindow::HandleModifireDeleta(UInt32 newModifiers) {
{
UInt32 changed = _last_key_modifiers ^ newModifiers; UInt32 changed = _last_key_modifiers ^ newModifiers;
if ((changed & (shiftKey | rightShiftKey)) != 0) if ((changed & (shiftKey | rightShiftKey)) != 0)
@ -1533,7 +1467,6 @@ void TinyOsxGraphicsWindow::SystemPointToLocalPoint(Point &qdGlobalPoint)
// save current state // save current state
_last_key_modifiers = newModifiers; _last_key_modifiers = newModifiers;
}; };
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -1582,21 +1515,21 @@ HandleButtonDelta(UInt32 new_buttons) {
// may fail if the mouse is not currently within the // may fail if the mouse is not currently within the
// window, or if the API doesn't support this operation. // window, or if the API doesn't support this operation.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool TinyOsxGraphicsWindow::move_pointer(int device, int x, int y) bool TinyOsxGraphicsWindow::move_pointer(int device, int x, int y) {
{ if (_osx_window == NULL) {
if(_osx_window == NULL)
return false; return false;
}
if (tinydisplay_cat.is_debug()) if (tinydisplay_cat.is_debug()) {
tinydisplay_cat.debug() << "move_pointer " << device <<" "<< x <<" "<< y <<"\n"; tinydisplay_cat.debug() << "move_pointer " << device <<" "<< x <<" "<< y <<"\n";
}
Point pt = {0, 0}; Point pt = {0, 0};
pt.h = x; pt.h = x;
pt.v = y; pt.v = y;
set_pointer_in_window(x, y); set_pointer_in_window(x, y);
if(_properties.get_mouse_mode()==WindowProperties::M_absolute) if (_properties.get_mouse_mode() == WindowProperties::M_absolute) {
{
LocalPointToSystemPoint(pt); LocalPointToSystemPoint(pt);
CGPoint newCursorPosition = {0, 0}; CGPoint newCursorPosition = {0, 0};
newCursorPosition.x = pt.h; newCursorPosition.x = pt.h;
@ -1609,19 +1542,34 @@ if (tinydisplay_cat.is_debug())
return true; return true;
}; };
bool TinyOsxGraphicsWindow::do_reshape_request(int x_origin, int y_origin, bool has_origin,int x_size, int y_size) bool TinyOsxGraphicsWindow::do_reshape_request(int x_origin, int y_origin, bool has_origin, int x_size, int y_size) {
{
tinydisplay_cat.info() << "Do Reshape\n"; tinydisplay_cat.info() << "Do Reshape\n";
if (_properties.get_fullscreen()) { if (_properties.get_fullscreen()) {
return false; return false;
} }
// A coordinate of -2 means to center the window on screen.
if (x_origin == -2 || y_origin == -2) {
if (y_origin == -2) {
y_origin = 0.5 * (_pipe->get_display_height() - y_size);
}
if (x_origin == -2) {
x_origin = 0.5 * (_pipe->get_display_width() - x_size);
}
if (r.top == -1) {
r.top = 50;
}
if (r.left == -1) {
r.left = 10;
}
_properties.set_origin(x_origin, y_origin);
system_changed_properties(_properties);
}
/* /*
if (_properties.has_parent_window()) if (_properties.has_parent_window()) {
{ if (has_origin) {
if (has_origin)
{
NSWindow* parentWindow = (NSWindow *)_properties.get_parent_window(); NSWindow* parentWindow = (NSWindow *)_properties.get_parent_window();
NSRect parentFrame = [parentWindow frame]; NSRect parentFrame = [parentWindow frame];
@ -1639,8 +1587,7 @@ bool TinyOsxGraphicsWindow::do_reshape_request(int x_origin, int y_origin, bool
} }
} }
if (!_properties.get_undecorated()) if (!_properties.get_undecorated()) {
{
// Constrain the window to the available desktop size. // Constrain the window to the available desktop size.
Rect bounds; Rect bounds;
GetAvailableWindowPositioningBounds(GetMainDevice(), &bounds); GetAvailableWindowPositioningBounds(GetMainDevice(), &bounds);
@ -1675,10 +1622,8 @@ bool TinyOsxGraphicsWindow::do_reshape_request(int x_origin, int y_origin, bool
// because the underlying interface does not support // because the underlying interface does not support
// changing that property on an open window). // changing that property on an open window).
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::set_properties_now(WindowProperties &properties) void TinyOsxGraphicsWindow::set_properties_now(WindowProperties &properties) {
{ if (tinydisplay_cat.is_debug()) {
if (tinydisplay_cat.is_debug())
{
tinydisplay_cat.debug() tinydisplay_cat.debug()
<< "------------------------------------------------------\n"; << "------------------------------------------------------\n";
tinydisplay_cat.debug() tinydisplay_cat.debug()
@ -1778,42 +1723,34 @@ void TinyOsxGraphicsWindow::set_properties_now(WindowProperties &properties)
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::LocalPointToSystemPoint(Point &qdLocalPoint) {
void TinyOsxGraphicsWindow::LocalPointToSystemPoint(Point &qdLocalPoint) if (_osx_window != NULL) {
{
if(_osx_window != NULL)
{
GrafPtr savePort; GrafPtr savePort;
Boolean portChanged = QDSwapPort(GetWindowPort(_osx_window), &savePort); Boolean portChanged = QDSwapPort(GetWindowPort(_osx_window), &savePort);
LocalToGlobal( &qdLocalPoint ); LocalToGlobal( &qdLocalPoint );
if (portChanged) if (portChanged) {
QDSwapPort(savePort, NULL); QDSwapPort(savePort, NULL);
} }
} }
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: TinyOsxGraphicsWindow::mouse_mode_relative // Function: TinyOsxGraphicsWindow::mouse_mode_relative
// Access: Protected, Virtual // Access: Protected, Virtual
// Description: detaches mouse. Only mouse delta from now on. // Description: Detaches mouse. Only mouse delta from now on.
//
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::mouse_mode_relative() void TinyOsxGraphicsWindow::mouse_mode_relative() {
{
CGAssociateMouseAndMouseCursorPosition(false); CGAssociateMouseAndMouseCursorPosition(false);
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: TinyOsxGraphicsWindow::mouse_mode_absolute // Function: TinyOsxGraphicsWindow::mouse_mode_absolute
// Access: Protected, Virtual // Access: Protected, Virtual
// Description: reattaches mouse to location // Description: Reattaches mouse to location
//
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void TinyOsxGraphicsWindow::mouse_mode_absolute() void TinyOsxGraphicsWindow::mouse_mode_absolute() {
{
CGAssociateMouseAndMouseCursorPosition(true); CGAssociateMouseAndMouseCursorPosition(true);
} }