summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/detect.py19
-rw-r--r--platform/osx/dir_access_osx.h46
-rw-r--r--platform/osx/dir_access_osx.mm309
-rw-r--r--platform/osx/export/export.cpp37
-rw-r--r--platform/osx/export/export.h30
-rw-r--r--platform/osx/os_osx.h19
-rw-r--r--platform/osx/os_osx.mm185
-rw-r--r--platform/osx/platform_config.h3
8 files changed, 241 insertions, 407 deletions
diff --git a/platform/osx/detect.py b/platform/osx/detect.py
index 1f176dc22a..1982beb10e 100644
--- a/platform/osx/detect.py
+++ b/platform/osx/detect.py
@@ -28,10 +28,9 @@ def get_opts():
def get_flags():
return [
- ('opengl', 'no'),
('legacygl', 'yes'),
('builtin_zlib', 'no'),
- ('freetype','builtin'), #use builtin freetype
+ ('glew', 'yes'),
]
@@ -56,21 +55,18 @@ def configure(env):
env.Append(CCFLAGS=['-g3', '-Wall','-DDEBUG_ENABLED','-DDEBUG_MEMORY_ENABLED'])
- if (env["freetype"]!="no"):
- env.Append(CCFLAGS=['-DFREETYPE_ENABLED'])
- env.Append(CPPPATH=['#tools/freetype'])
- env.Append(CPPPATH=['#tools/freetype/freetype/include'])
-
-
if (not os.environ.has_key("OSXCROSS_ROOT")):
#regular native build
if (env["bits"]=="64"):
env.Append(CCFLAGS=['-arch', 'x86_64'])
env.Append(LINKFLAGS=['-arch', 'x86_64'])
- else:
+ elif (env["bits"]=="32"):
env.Append(CCFLAGS=['-arch', 'i386'])
env.Append(LINKFLAGS=['-arch', 'i386'])
+ else:
+ env.Append(CCFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
+ env.Append(LINKFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
else:
#osxcross build
root=os.environ.get("OSXCROSS_ROOT",0)
@@ -91,11 +87,8 @@ def configure(env):
# env.Append(LIBPATH=['#platform/osx/lib'])
- #if env['opengl'] == 'yes':
- # env.Append(CPPFLAGS=['-DOPENGL_ENABLED','-DGLEW_ENABLED'])
-
env.Append(CPPFLAGS=["-DAPPLE_STYLE_KEYS"])
- env.Append(CPPFLAGS=['-DUNIX_ENABLED','-DGLES2_ENABLED','-DGLEW_ENABLED', '-DOSX_ENABLED'])
+ env.Append(CPPFLAGS=['-DUNIX_ENABLED','-DGLES2_ENABLED','-DOSX_ENABLED'])
env.Append(LIBS=['pthread'])
#env.Append(CPPFLAGS=['-F/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk', '-mmacosx-version-min=10.4'])
#env.Append(LINKFLAGS=['-mmacosx-version-min=10.4', '-isysroot', '/Developer/SDKs/MacOSX10.4u.sdk', '-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk'])
diff --git a/platform/osx/dir_access_osx.h b/platform/osx/dir_access_osx.h
index 8b742b64fa..d20eee1e2e 100644
--- a/platform/osx/dir_access_osx.h
+++ b/platform/osx/dir_access_osx.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* dir_access_unix.h */
+/* dir_access_osx.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -37,52 +37,16 @@
#include <dirent.h>
#include "os/dir_access.h"
+#include "drivers/unix/dir_access_unix.h"
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-class DirAccessOSX : public DirAccess {
+class DirAccessOSX : public DirAccessUnix {
+protected:
- DIR *dir_stream;
-
- static DirAccess *create_fs();
-
- String current_dir;
- bool _cisdir;
- bool _cishidden;
-
-public:
-
- virtual bool list_dir_begin(); ///< This starts dir listing
- virtual String get_next();
- virtual bool current_is_dir() const;
- virtual bool current_is_hidden() const;
-
- virtual void list_dir_end(); ///<
-
- virtual int get_drive_count();
- virtual String get_drive(int p_drive);
-
- virtual Error change_dir(String p_dir); ///< can be relative or absolute, return false on success
- virtual String get_current_dir(); ///< return current dir location
- virtual Error make_dir(String p_dir);
-
- virtual bool file_exists(String p_file);
- virtual bool dir_exists(String p_dir);
-
- virtual uint64_t get_modified_time(String p_file);
-
-
-
- virtual Error rename(String p_from, String p_to);
- virtual Error remove(String p_name);
-
- virtual size_t get_space_left();
-
-
- DirAccessOSX();
- ~DirAccessOSX();
+ virtual String fix_unicode_name(const char* p_name) const;
};
diff --git a/platform/osx/dir_access_osx.mm b/platform/osx/dir_access_osx.mm
index 20dc1df8f4..5615858262 100644
--- a/platform/osx/dir_access_osx.mm
+++ b/platform/osx/dir_access_osx.mm
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* dir_access_unix.cpp */
+/* dir_access_osx.mm */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -30,324 +30,21 @@
#if defined(UNIX_ENABLED) || defined(LIBC_FILEIO_ENABLED)
-#ifndef ANDROID_ENABLED
-#include <sys/statvfs.h>
-#endif
-
-#include <stdio.h>
-#include "os/memory.h"
-#include "print_string.h"
#include <errno.h>
#include <Foundation/NSString.h>
-DirAccess *DirAccessOSX::create_fs() {
-
- return memnew( DirAccessOSX );
-}
-
-bool DirAccessOSX::list_dir_begin() {
-
- list_dir_end(); //close any previous dir opening!
-
-
-// char real_current_dir_name[2048]; //is this enough?!
- //getcwd(real_current_dir_name,2048);
- //chdir(curent_path.utf8().get_data());
- dir_stream = opendir(current_dir.utf8().get_data());
- //chdir(real_current_dir_name);
- if (!dir_stream)
- return true; //error!
-
- return false;
-}
-
-bool DirAccessOSX::file_exists(String p_file) {
-
- GLOBAL_LOCK_FUNCTION
-
-
- if (p_file.is_rel_path())
- p_file=current_dir+"/"+p_file;
- else
- p_file=fix_path(p_file);
-
- struct stat flags;
- bool success = (stat(p_file.utf8().get_data(),&flags)==0);
-
- if (success && S_ISDIR(flags.st_mode)) {
- success=false;
- }
-
- return success;
-
-}
-
-bool DirAccessOSX::dir_exists(String p_dir) {
-
- GLOBAL_LOCK_FUNCTION
-
-
- if (p_dir.is_rel_path())
- p_dir=get_current_dir().plus_file(p_dir);
- else
- p_dir=fix_path(p_dir);
-
- struct stat flags;
- bool success = (stat(p_dir.utf8().get_data(),&flags)==0);
-
- if (success && S_ISDIR(flags.st_mode))
- return true;
-
- return false;
-
-}
-
-uint64_t DirAccessOSX::get_modified_time(String p_file) {
-
- if (p_file.is_rel_path())
- p_file=current_dir+"/"+p_file;
- else
- p_file=fix_path(p_file);
-
- struct stat flags;
- bool success = (stat(p_file.utf8().get_data(),&flags)==0);
- if (success) {
- return flags.st_mtime;
- } else {
-
- ERR_FAIL_V(0);
- };
- return 0;
-};
-
-
-String DirAccessOSX::get_next() {
-
- if (!dir_stream)
- return "";
- dirent *entry;
-
- entry=readdir(dir_stream);
-
- if (entry==NULL) {
-
- list_dir_end();
- return "";
- }
-
- //typedef struct stat Stat;
- struct stat flags;
+String DirAccessOSX::fix_unicode_name(const char* p_name) const {
String fname;
- NSString* nsstr = [[NSString stringWithUTF8String: entry->d_name] precomposedStringWithCanonicalMapping];
+ NSString* nsstr = [[NSString stringWithUTF8String: p_name] precomposedStringWithCanonicalMapping];
fname.parse_utf8([nsstr UTF8String]);
- //[nsstr autorelease];
-
- String f=current_dir+"/"+fname;
-
- if (stat(f.utf8().get_data(),&flags)==0) {
-
- if (S_ISDIR(flags.st_mode)) {
-
- _cisdir=true;
-
- } else {
-
- _cisdir=false;
- }
-
- } else {
-
- _cisdir=false;
-
- }
-
- _cishidden=(fname!="." && fname!=".." && fname.begins_with("."));
-
-
-
return fname;
-
-}
-
-bool DirAccessOSX::current_is_dir() const {
-
- return _cisdir;
-}
-
-bool DirAccessOSX::current_is_hidden() const {
-
- return _cishidden;
-}
-
-
-void DirAccessOSX::list_dir_end() {
-
- if (dir_stream)
- closedir(dir_stream);
- dir_stream=0;
- _cisdir=false;
-}
-
-int DirAccessOSX::get_drive_count() {
-
- return 0;
-}
-String DirAccessOSX::get_drive(int p_drive) {
-
- return "";
-}
-
-Error DirAccessOSX::make_dir(String p_dir) {
-
- GLOBAL_LOCK_FUNCTION
-
- p_dir=fix_path(p_dir);
-
- char real_current_dir_name[2048];
- getcwd(real_current_dir_name,2048);
- chdir(current_dir.utf8().get_data()); //ascii since this may be unicode or wathever the host os wants
-
- bool success=(mkdir(p_dir.utf8().get_data(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)==0);
- int err = errno;
-
- chdir(real_current_dir_name);
-
- if (success) {
- return OK;
- };
-
- if (err == EEXIST) {
- return ERR_ALREADY_EXISTS;
- };
-
- return ERR_CANT_CREATE;
}
-Error DirAccessOSX::change_dir(String p_dir) {
-
- GLOBAL_LOCK_FUNCTION
- p_dir=fix_path(p_dir);
-
-
- char real_current_dir_name[2048];
- getcwd(real_current_dir_name,2048);
- String prev_dir;
- if (prev_dir.parse_utf8(real_current_dir_name))
- prev_dir=real_current_dir_name; //no utf8, maybe latin?
-
- chdir(current_dir.utf8().get_data()); //ascii since this may be unicode or wathever the host os wants
- bool worked=(chdir(p_dir.utf8().get_data())==0); // we can only give this utf8
-#ifndef IPHONE_ENABLED
- String base = _get_root_path();
- if (base!="") {
-
- getcwd(real_current_dir_name,2048);
- String new_dir;
- new_dir.parse_utf8(real_current_dir_name);
- if (!new_dir.begins_with(base))
- worked=false;
- }
-#endif
- if (worked) {
-
- getcwd(real_current_dir_name,2048);
- if (current_dir.parse_utf8(real_current_dir_name))
- current_dir=real_current_dir_name; //no utf8, maybe latin?
- }
-
- chdir(prev_dir.utf8().get_data());
- return worked?OK:ERR_INVALID_PARAMETER;
-
-}
-
-String DirAccessOSX::get_current_dir() {
-
- String base = _get_root_path();
- if (base!="") {
-
- String bd = current_dir.replace_first(base,"");
- if (bd.begins_with("/"))
- return _get_root_string()+bd.substr(1,bd.length());
- else
- return _get_root_string()+bd;
-
- }
- return current_dir;
-}
-
-Error DirAccessOSX::rename(String p_path,String p_new_path) {
-
- if (p_path.is_rel_path())
- p_path=get_current_dir().plus_file(p_path);
- else
- p_path=fix_path(p_path);
-
- if (p_new_path.is_rel_path())
- p_new_path=get_current_dir().plus_file(p_new_path);
- else
- p_new_path=fix_path(p_new_path);
-
- return ::rename(p_path.utf8().get_data(),p_new_path.utf8().get_data())==0?OK:FAILED;
-}
-Error DirAccessOSX::remove(String p_path) {
-
- if (p_path.is_rel_path())
- p_path=get_current_dir().plus_file(p_path);
- else
- p_path=fix_path(p_path);
-
- struct stat flags;
- if ((stat(p_path.utf8().get_data(),&flags)!=0))
- return FAILED;
-
- if (S_ISDIR(flags.st_mode))
- return ::rmdir(p_path.utf8().get_data())==0?OK:FAILED;
- else
- return ::unlink(p_path.utf8().get_data())==0?OK:FAILED;
-}
-
-
-size_t DirAccessOSX::get_space_left() {
-
-#ifndef NO_STATVFS
- struct statvfs vfs;
- if (statvfs(current_dir.utf8().get_data(), &vfs) != 0) {
-
- return -1;
- };
-
- return vfs.f_bfree * vfs.f_bsize;
-#else
-#warning THIS IS BROKEN
- return 0;
-#endif
-};
-
-
-
-DirAccessOSX::DirAccessOSX() {
-
- dir_stream=0;
- current_dir=".";
- _cisdir=false;
-
- /* determine drive count */
-
- change_dir(current_dir);
-
-}
-
-
-DirAccessOSX::~DirAccessOSX() {
-
- list_dir_end();
-}
-
#endif //posix_enabled
diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp
index 3bc4ebdb1a..cb0514da9d 100644
--- a/platform/osx/export/export.cpp
+++ b/platform/osx/export/export.cpp
@@ -1,3 +1,31 @@
+/*************************************************************************/
+/* export.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
#include "version.h"
#include "export.h"
#include "tools/editor/editor_settings.h"
@@ -32,6 +60,7 @@ class EditorExportPlatformOSX : public EditorExportPlatform {
String signature;
String copyright;
bool use64;
+ bool useFat;
bool high_resolution;
Ref<ImageTexture> logo;
@@ -95,6 +124,8 @@ bool EditorExportPlatformOSX::_set(const StringName& p_name, const Variant& p_va
copyright=p_value;
else if (n=="application/64_bits")
use64=p_value;
+ else if (n=="application/fat_bits")
+ useFat=p_value;
else if (n=="display/high_res")
high_resolution=p_value;
else
@@ -129,6 +160,8 @@ bool EditorExportPlatformOSX::_get(const StringName& p_name,Variant &r_ret) cons
r_ret=copyright;
else if (n=="application/64_bits")
r_ret=use64;
+ else if (n=="application/fat_bits")
+ r_ret=useFat;
else if (n=="display/high_res")
r_ret=high_resolution;
else
@@ -150,6 +183,7 @@ void EditorExportPlatformOSX::_get_property_list( List<PropertyInfo> *p_list) co
p_list->push_back( PropertyInfo( Variant::STRING, "application/version") );
p_list->push_back( PropertyInfo( Variant::STRING, "application/copyright") );
p_list->push_back( PropertyInfo( Variant::BOOL, "application/64_bits") );
+ p_list->push_back( PropertyInfo( Variant::BOOL, "application/fat_bits") );
p_list->push_back( PropertyInfo( Variant::BOOL, "display/high_res") );
@@ -287,7 +321,7 @@ Error EditorExportPlatformOSX::export_project(const String& p_path, bool p_debug
io2.opaque=&dst_f;
zipFile dpkg=zipOpen2(p_path.utf8().get_data(),APPEND_STATUS_CREATE,NULL,&io2);
- String binary_to_use="godot_osx_"+String(p_debug?"debug":"release")+"."+String(use64?"64":"32");
+ String binary_to_use="godot_osx_"+String(p_debug?"debug":"release")+"."+String(useFat?"fat":use64?"64":"32");
print_line("binary: "+binary_to_use);
String pkg_name;
@@ -459,6 +493,7 @@ EditorExportPlatformOSX::EditorExportPlatformOSX() {
short_version="1.0";
version="1.0";
use64=false;
+ useFat=false;
high_resolution=false;
}
diff --git a/platform/osx/export/export.h b/platform/osx/export/export.h
index b149e482c9..8e0b83b457 100644
--- a/platform/osx/export/export.h
+++ b/platform/osx/export/export.h
@@ -1,3 +1,29 @@
-
-
+/*************************************************************************/
+/* export.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* http://www.godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
void register_osx_exporter();
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index d88dd89002..8d64686335 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -59,7 +59,7 @@ public:
bool force_quit;
Rasterizer *rasterizer;
VisualServer *visual_server;
- VideoMode current_videomode;
+
List<String> args;
MainLoop *main_loop;
unsigned int event_id;
@@ -104,9 +104,22 @@ public:
bool minimized;
bool maximized;
bool zoomed;
+
Vector<Rect2> screens;
+ Vector<int> screen_dpi;
+
+ Size2 window_size;
int current_screen;
Rect2 restore_rect;
+
+ float _mouse_scale(float p_scale) {
+ if (display_scale>1.0)
+ return p_scale;
+ else
+ return 1.0;
+ }
+
+ float display_scale;
protected:
virtual int get_video_driver_count() const;
@@ -173,6 +186,9 @@ public:
virtual int get_current_screen() const;
virtual void set_current_screen(int p_screen);
virtual Point2 get_screen_position(int p_screen=0) const;
+ virtual Size2 get_screen_size(int p_screen=0) const;
+ virtual int get_screen_dpi(int p_screen=0) const;
+
virtual Point2 get_window_position() const;
virtual void set_window_position(const Point2& p_position);
virtual void set_window_size(const Size2 p_size);
@@ -184,7 +200,6 @@ public:
virtual bool is_window_minimized() const;
virtual void set_window_maximized(bool p_enabled);
virtual bool is_window_maximized() const;
- Size2 get_screen_size(int p_screen=0) const;
void run();
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index c443fc2d0e..b5503fcd73 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -139,12 +139,10 @@ static int button_mask=0;
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
-/* _Godotwindow* window;
+ if (OS_OSX::singleton->get_main_loop())
+ OS_OSX::singleton->get_main_loop()->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
- for (window = _Godot.windowListHead; window; window = window->next)
- _GodotInputWindowCloseRequest(window);
-*/
- return NSTerminateCancel;
+ return NSTerminateCancel;
}
- (void)applicationDidHide:(NSNotification *)notification
@@ -202,10 +200,10 @@ static int button_mask=0;
[OS_OSX::singleton->context update];
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
- const NSRect fbRect = convertRectToBacking(contentRect);
+ const NSRect fbRect = contentRect;//convertRectToBacking(contentRect);
- OS_OSX::singleton->current_videomode.width=fbRect.size.width;
- OS_OSX::singleton->current_videomode.height=fbRect.size.height;
+ OS_OSX::singleton->window_size.width=fbRect.size.width*OS_OSX::singleton->display_scale;
+ OS_OSX::singleton->window_size.height=fbRect.size.height*OS_OSX::singleton->display_scale;
// _GodotInputFramebufferSize(window, fbRect.size.width, fbRect.size.height);
@@ -291,16 +289,52 @@ static int button_mask=0;
self = [super init];
trackingArea = nil;
[self updateTrackingAreas];
-
+ [self registerForDraggedTypes:[NSArray arrayWithObject:NSFilenamesPboardType]];
return self;
}
+
-(void)dealloc
{
[trackingArea release];
[super dealloc];
}
+- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender {
+ return NSDragOperationCopy;
+}
+
+- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
+ return NSDragOperationCopy;
+}
+
+- (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
+
+
+ NSPasteboard *pboard = [sender draggingPasteboard];
+ NSArray *filenames = [pboard propertyListForType:NSFilenamesPboardType];
+
+ Vector<String> files;
+ for(int i=0;i<filenames.count;i++) {
+ NSString *ns = [filenames objectAtIndex:i];
+ char *utfs = strdup([ns UTF8String]);
+ String ret;
+ ret.parse_utf8(utfs);
+ free(utfs);
+ files.push_back(ret);
+
+
+ }
+
+ if (files.size()) {
+ OS_OSX::singleton->main_loop->drop_files(files,0);
+ OS_OSX::singleton->move_window_to_foreground();
+ }
+
+ return NO;
+}
+
+
- (BOOL)isOpaque
{
return YES;
@@ -324,7 +358,7 @@ static int button_mask=0;
- (void)mouseDown:(NSEvent *)event
{
- print_line("mouse down:");
+ //print_line("mouse down:");
button_mask|=BUTTON_MASK_LEFT;
InputEvent ev;
ev.type=InputEvent::MOUSE_BUTTON;
@@ -383,14 +417,14 @@ static int button_mask=0;
prev_mouse_y=mouse_y;
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
const NSPoint p = [event locationInWindow];
- mouse_x = p.x * [[event window] backingScaleFactor];
- mouse_y = (contentRect.size.height - p.y) * [[event window] backingScaleFactor];
+ mouse_x = p.x * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
+ mouse_y = (contentRect.size.height - p.y) * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
ev.mouse_motion.x=mouse_x;
ev.mouse_motion.y=mouse_y;
ev.mouse_motion.global_x=mouse_x;
ev.mouse_motion.global_y=mouse_y;
- ev.mouse_motion.relative_x=[event deltaX] * [[event window] backingScaleFactor];
- ev.mouse_motion.relative_y=[event deltaY] * [[event window] backingScaleFactor];
+ ev.mouse_motion.relative_x=[event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
+ ev.mouse_motion.relative_y=[event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
ev.mouse_motion.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->input->set_mouse_pos(Point2(mouse_x,mouse_y));
@@ -736,20 +770,48 @@ static int translateKey(unsigned int key)
- (void)flagsChanged:(NSEvent *)event
{
- /* int action;
- unsigned int newModifierFlags =
- [event modifierFlags] & NSDeviceIndependentModifierFlagsMask;
+ InputEvent ev;
+ int key = [event keyCode];
+ int mod = [event modifierFlags];
- if (newModifierFlags > window->ns.modifierFlags)
- action = GLFW_PRESS;
- else
- action = GLFW_RELEASE;
+ ev.type=InputEvent::KEY;
- window->ns.modifierFlags = newModifierFlags;
+ if (key == 0x36 || key == 0x37) {
+ if (mod & NSCommandKeyMask) {
+ mod&= ~NSCommandKeyMask;
+ ev.key.pressed = true;
+ } else {
+ ev.key.pressed = false;
+ }
+ } else if (key == 0x38 || key == 0x3c) {
+ if (mod & NSShiftKeyMask) {
+ mod&= ~NSShiftKeyMask;
+ ev.key.pressed = true;
+ } else {
+ ev.key.pressed = false;
+ }
+ } else if (key == 0x3a || key == 0x3d) {
+ if (mod & NSAlternateKeyMask) {
+ mod&= ~NSAlternateKeyMask;
+ ev.key.pressed = true;
+ } else {
+ ev.key.pressed = false;
+ }
+ } else if (key == 0x3b || key == 0x3e) {
+ if (mod & NSControlKeyMask) {
+ mod&= ~NSControlKeyMask;
+ ev.key.pressed = true;
+ } else {
+ ev.key.pressed = false;
+ }
+ } else {
+ return;
+ }
- const int key = translateKey([event keyCode]);
- const int mods = translateFlags([event modifierFlags]);
- _glfwInputKey(window, key, [event keyCode], action, mods);*/
+ ev.key.mod=translateFlags(mod);
+ ev.key.scancode = latin_keyboard_keycode_convert(translateKey(key));
+
+ OS_OSX::singleton->push_input(ev);
}
- (void)keyUp:(NSEvent *)event
@@ -833,6 +895,7 @@ static int translateKey(unsigned int key)
@implementation GodotWindow
+
- (BOOL)canBecomeKeyWindow
{
// Required for NSBorderlessWindowMask windows
@@ -893,6 +956,15 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
kTISNotifySelectedKeyboardInputSourceChanged, NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
+ if (is_hidpi_allowed() && [[NSScreen mainScreen] respondsToSelector:@selector(backingScaleFactor)]) {
+ for (NSScreen *screen in [NSScreen screens]) {
+ float s = [screen backingScaleFactor];
+ if (s > display_scale) {
+ display_scale=s;
+ }
+ }
+ }
+
window_delegate = [[GodotWindowDelegate alloc] init];
// Don't use accumulation buffer support; it's not accelerated
@@ -902,7 +974,7 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
window_object = [[GodotWindow alloc]
- initWithContentRect:NSMakeRect(0, 0, p_desired.width, p_desired.height)
+ initWithContentRect:NSMakeRect(0, 0, p_desired.width/display_scale, p_desired.height/display_scale)
styleMask:styleMask
backing:NSBackingStoreBuffered
defer:NO];
@@ -911,15 +983,11 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
window_view = [[GodotContentView alloc] init];
- current_videomode = p_desired;
-
- // Adjust for display density
- const NSRect fbRect = convertRectToBacking(NSMakeRect(0, 0, p_desired.width, p_desired.height));
- current_videomode.width = fbRect.size.width;
- current_videomode.height = fbRect.size.height;
+ window_size.width = p_desired.width;
+ window_size.height = p_desired.height;
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1070
- if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6 && display_scale>1) {
[window_view setWantsBestResolutionOpenGLSurface:YES];
//if (current_videomode.resizable)
[window_object setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
@@ -1062,9 +1130,28 @@ void OS_OSX::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi
printf("nscreen count %i\n", (int)[screenArray count]);
for (int i=0; i<[screenArray count]; i++) {
+ float displayScale = 1.0;
+
+ if (display_scale>1.0 && [[screenArray objectAtIndex: i] respondsToSelector:@selector(backingScaleFactor)]) {
+ displayScale = [[screenArray objectAtIndex: i] backingScaleFactor];
+ }
+
NSRect nsrect = [[screenArray objectAtIndex: i] visibleFrame];
- screens.push_back(Rect2(nsrect.origin.x, nsrect.origin.y, nsrect.size.width, nsrect.size.height));
- printf("added screen %i\n", screens.size());
+ Rect2 rect = Rect2(nsrect.origin.x, nsrect.origin.y, nsrect.size.width, nsrect.size.height);
+ rect.pos*=displayScale;
+ rect.size*=displayScale;
+ screens.push_back(rect);
+
+ NSDictionary *description = [[screenArray objectAtIndex: i] deviceDescription];
+ NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
+ CGSize displayPhysicalSize = CGDisplayScreenSize(
+ [[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
+
+ //printf("width: %i pwidth %i rect width %i\n",int(displayPixelSize.width*displayScale),int(displayPhysicalSize.width*displayScale),int(nsrect.size.width));
+ int dpi = (displayPixelSize.width * 25.4f / displayPhysicalSize.width)*displayScale;
+
+ screen_dpi.push_back(dpi);
+
};
restore_rect = Rect2(get_window_position(), get_window_size());
}
@@ -1326,7 +1413,11 @@ void OS_OSX::set_video_mode(const VideoMode& p_video_mode,int p_screen) {
OS::VideoMode OS_OSX::get_video_mode(int p_screen) const {
- return current_videomode;
+ VideoMode vm;
+ vm.width=window_size.width;
+ vm.height=window_size.height;
+
+ return vm;
}
void OS_OSX::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const {
@@ -1354,6 +1445,12 @@ Point2 OS_OSX::get_screen_position(int p_screen) const {
return screens[p_screen].pos;
};
+int OS_OSX::get_screen_dpi(int p_screen) const {
+
+ ERR_FAIL_INDEX_V(p_screen, screens.size(), 72);
+ return screen_dpi[p_screen];
+}
+
Size2 OS_OSX::get_screen_size(int p_screen) const {
ERR_FAIL_INDEX_V(p_screen, screens.size(), Point2());
@@ -1362,24 +1459,30 @@ Size2 OS_OSX::get_screen_size(int p_screen) const {
Point2 OS_OSX::get_window_position() const {
- return Size2([window_object frame].origin.x, [window_object frame].origin.y);
+ Size2 wp([window_object frame].origin.x, [window_object frame].origin.y);
+ wp*=display_scale;
+ return wp;
};
void OS_OSX::set_window_position(const Point2& p_position) {
- [window_object setFrame:NSMakeRect(p_position.x, p_position.y, [window_object frame].size.width, [window_object frame].size.height) display:YES];
+ Point2 size=p_position;
+ size/=display_scale;
+ [window_object setFrame:NSMakeRect(size.x, size.y, [window_object frame].size.width, [window_object frame].size.height) display:YES];
};
Size2 OS_OSX::get_window_size() const {
- return Size2([window_object frame].size.width, [window_object frame].size.height);
+ return window_size;
+
};
void OS_OSX::set_window_size(const Size2 p_size) {
+ Size2 size=p_size;
NSRect frame = [window_object frame];
- [window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, p_size.x, p_size.y) display:YES];
+ [window_object setFrame:NSMakeRect(frame.origin.x, frame.origin.y, size.x, size.y) display:YES];
};
void OS_OSX::set_window_fullscreen(bool p_enabled) {
@@ -1690,5 +1793,7 @@ OS_OSX::OS_OSX() {
maximized = false;
minimized = false;
+ window_size=Vector2(1024,600);
zoomed = false;
+ display_scale=1.0;
}
diff --git a/platform/osx/platform_config.h b/platform/osx/platform_config.h
index 085f13df73..86505206ae 100644
--- a/platform/osx/platform_config.h
+++ b/platform/osx/platform_config.h
@@ -27,6 +27,5 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <alloca.h>
-#define GLES2_INCLUDE_H "gl_context/glew.h"
-#define GLES1_INCLUDE_H "gl_context/glew.h"
+#define GLES2_INCLUDE_H "gl_context/GL/glew.h"
#define PTHREAD_RENAME_SELF