diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/SCsub | 6 | ||||
-rw-r--r-- | platform/android/detect.py | 6 | ||||
-rw-r--r-- | platform/android/godot_android.cpp | 31 | ||||
-rw-r--r-- | platform/android/java/res/drawable/icon.png | bin | 12574 -> 12525 bytes | |||
-rw-r--r-- | platform/android/java/src/org/godotengine/godot/Godot.java | 13 | ||||
-rw-r--r-- | platform/android/java/src/org/godotengine/godot/GodotLib.java | 1 | ||||
-rw-r--r-- | platform/android/java_glue.cpp | 11 | ||||
-rw-r--r-- | platform/android/java_glue.h | 1 | ||||
-rw-r--r-- | platform/android/os_android.cpp | 5 | ||||
-rw-r--r-- | platform/android/os_android.h | 1 | ||||
-rw-r--r-- | platform/osx/detect.py | 4 | ||||
-rw-r--r-- | platform/osx/export/export.cpp | 9 | ||||
-rw-r--r-- | platform/osx/os_osx.h | 19 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 126 | ||||
-rw-r--r-- | platform/windows/detect.py | 9 | ||||
-rw-r--r-- | platform/windows/godot.ico | bin | 370070 -> 370070 bytes | |||
-rw-r--r-- | platform/windows/os_windows.cpp | 109 | ||||
-rw-r--r-- | platform/windows/os_windows.h | 3 | ||||
-rw-r--r-- | platform/x11/detect.py | 4 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 165 | ||||
-rw-r--r-- | platform/x11/os_x11.h | 12 |
21 files changed, 488 insertions, 47 deletions
diff --git a/platform/android/SCsub b/platform/android/SCsub index fab8458b26..c8feac8690 100644 --- a/platform/android/SCsub +++ b/platform/android/SCsub @@ -65,17 +65,17 @@ for x in env.android_java_dirs: gradle_res_dirs_text="" for x in env.android_res_dirs: - gradle_res_dirs_text+=",'"+x+"'" + gradle_res_dirs_text+=",'"+x.replace("\\","/")+"'" gradle_aidl_dirs_text="" for x in env.android_aidl_dirs: - gradle_aidl_dirs_text+=",'"+x+"'" + gradle_aidl_dirs_text+=",'"+x.replace("\\","/")+"'" gradle_jni_dirs_text="" for x in env.android_jni_dirs: - gradle_jni_dirs_text+=",'"+x+"'" + gradle_jni_dirs_text+=",'"+x.replace("\\","/")+"'" gradle_asset_dirs_text="" diff --git a/platform/android/detect.py b/platform/android/detect.py index 11b14eb989..ba6b73a89f 100644 --- a/platform/android/detect.py +++ b/platform/android/detect.py @@ -168,11 +168,11 @@ def configure(env): env['neon_enabled']=False if env['android_arch']=='x86': - env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__GLIBC__ -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED') + env['CCFLAGS'] = string.split('-DNO_STATVFS -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__GLIBC__ -Wno-psabi -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED') elif env["android_arch"]=="armv6": - env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_6__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED') + env['CCFLAGS'] = string.split('-DNO_STATVFS -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_6__ -D__GLIBC__ -Wno-psabi -march=armv6 -mfpu=vfp -mfloat-abi=softfp -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED') elif env["android_arch"]=="armv7": - env['CCFLAGS'] = string.split('-DNO_STATVFS -MMD -MP -MF -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -D__GLIBC__ -Wno-psabi -march=armv7-a -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED') + env['CCFLAGS'] = string.split('-DNO_STATVFS -fpic -ffunction-sections -funwind-tables -fstack-protector -fvisibility=hidden -D__ARM_ARCH_7__ -D__ARM_ARCH_7A__ -D__GLIBC__ -Wno-psabi -march=armv7-a -mfloat-abi=softfp -ftree-vectorize -funsafe-math-optimizations -fno-strict-aliasing -DANDROID -Wa,--noexecstack -DGLES2_ENABLED') if env['android_neon']=='yes': env['neon_enabled']=True env.Append(CCFLAGS=['-mfpu=neon','-D__ARM_NEON__']) diff --git a/platform/android/godot_android.cpp b/platform/android/godot_android.cpp index f9feb3481f..edb051575f 100644 --- a/platform/android/godot_android.cpp +++ b/platform/android/godot_android.cpp @@ -313,6 +313,7 @@ struct engine { ASensorManager* sensorManager; const ASensor* accelerometerSensor; + const ASensor* magnetometerSensor; ASensorEventQueue* sensorEventQueue; bool display_active; @@ -736,15 +737,28 @@ static void engine_handle_cmd(struct android_app* app, int32_t cmd) { engine->accelerometerSensor, (1000L/60)*1000); } + // Also start monitoring the magnetometer. + if (engine->magnetometerSensor != NULL) { + ASensorEventQueue_enableSensor(engine->sensorEventQueue, + engine->magnetometerSensor); + // We'd like to get 60 events per second (in us). + ASensorEventQueue_setEventRate(engine->sensorEventQueue, + engine->magnetometerSensor, (1000L/60)*1000); + + } engine->animating = 1; break; case APP_CMD_LOST_FOCUS: - // When our app loses focus, we stop monitoring the accelerometer. + // When our app loses focus, we stop monitoring the sensors. // This is to avoid consuming battery while not being used. if (engine->accelerometerSensor != NULL) { ASensorEventQueue_disableSensor(engine->sensorEventQueue, engine->accelerometerSensor); } + if (engine->magnetometerSensor != NULL) { + ASensorEventQueue_disableSensor(engine->sensorEventQueue, + engine->magnetometerSensor); + } // Also stop animating. engine->animating = 0; engine_draw_frame(engine); @@ -768,10 +782,12 @@ void android_main(struct android_app* state) { FileAccessAndroid::asset_manager=state->activity->assetManager; - // Prepare to monitor accelerometer + // Prepare to monitor sensors engine.sensorManager = ASensorManager_getInstance(); engine.accelerometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager, - ASENSOR_TYPE_ACCELEROMETER); + ASENSOR_TYPE_ACCELEROMETER); + engine.magnetometerSensor = ASensorManager_getDefaultSensor(engine.sensorManager, + ASENSOR_TYPE_MAGNETIC_FIELD); engine.sensorEventQueue = ASensorManager_createEventQueue(engine.sensorManager, state->looper, LOOPER_ID_USER, NULL, NULL); @@ -812,16 +828,21 @@ void android_main(struct android_app* state) { // If a sensor has data, process it now. // LOGI("events\n"); if (ident == LOOPER_ID_USER) { - if (engine.accelerometerSensor != NULL) { + if (engine.accelerometerSensor != NULL || engine.magnetometerSensor != NULL) { ASensorEvent event; while (ASensorEventQueue_getEvents(engine.sensorEventQueue, &event, 1) > 0) { if (engine.os) { + if (event.acceleration != NULL) { engine.os->process_accelerometer(Vector3(event.acceleration.x, event.acceleration.y, event.acceleration.z)); - + } + if (event.magnetic != NULL) { + engine.os->process_magnetometer(Vector3(event.magnetic.x, event.magnetic.y, + event.magnetic.z)); + } } } diff --git a/platform/android/java/res/drawable/icon.png b/platform/android/java/res/drawable/icon.png Binary files differindex 013632ddf1..e334f5fa78 100644 --- a/platform/android/java/res/drawable/icon.png +++ b/platform/android/java/res/drawable/icon.png diff --git a/platform/android/java/src/org/godotengine/godot/Godot.java b/platform/android/java/src/org/godotengine/godot/Godot.java index 1f208f8fb6..c4ba2da751 100644 --- a/platform/android/java/src/org/godotengine/godot/Godot.java +++ b/platform/android/java/src/org/godotengine/godot/Godot.java @@ -206,6 +206,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC private SensorManager mSensorManager; private Sensor mAccelerometer; + private Sensor mMagnetometer; public FrameLayout layout; public RelativeLayout adLayout; @@ -374,6 +375,8 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME); + mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); + mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_GAME); result_callback = null; @@ -588,6 +591,7 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC mView.onResume(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); + mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_DELAY_NORMAL); GodotLib.focusin(); if(use_immersive && Build.VERSION.SDK_INT >= 19.0){ // check if the application runs on an android 4.4+ Window window = getWindow(); @@ -646,7 +650,14 @@ public class Godot extends Activity implements SensorEventListener, IDownloaderC float x = adjustedValues[0]; float y = adjustedValues[1]; float z = adjustedValues[2]; - GodotLib.accelerometer(x,y,z); + + int typeOfSensor = event.sensor.getType(); + if (typeOfSensor == event.sensor.TYPE_ACCELEROMETER) { + GodotLib.accelerometer(x,y,z); + } + if (typeOfSensor == event.sensor.TYPE_MAGNETIC_FIELD) { + GodotLib.magnetometer(x,y,z); + } } @Override public final void onAccuracyChanged(Sensor sensor, int accuracy) { diff --git a/platform/android/java/src/org/godotengine/godot/GodotLib.java b/platform/android/java/src/org/godotengine/godot/GodotLib.java index 7c5ac33c85..df181ae1bb 100644 --- a/platform/android/java/src/org/godotengine/godot/GodotLib.java +++ b/platform/android/java/src/org/godotengine/godot/GodotLib.java @@ -51,6 +51,7 @@ public class GodotLib { public static native void step(); public static native void touch(int what,int pointer,int howmany, int[] arr); public static native void accelerometer(float x, float y, float z); + public static native void magnetometer(float x, float y, float z); public static native void key(int p_scancode, int p_unicode_char, boolean p_pressed); public static native void joybutton(int p_device, int p_but, boolean p_pressed); public static native void joyaxis(int p_device, int p_axis, float p_value); diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp index b5beb8fa2c..1ea7cd7ebb 100644 --- a/platform/android/java_glue.cpp +++ b/platform/android/java_glue.cpp @@ -650,6 +650,7 @@ static bool resized_reload=false; static bool quit_request=false; static Size2 new_size; static Vector3 accelerometer; +static Vector3 magnetometer; static HashMap<String,JNISingleton*> jni_singletons; static jobject godot_io; @@ -1088,6 +1089,8 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv * env, jo os_android->process_accelerometer(accelerometer); + os_android->process_magnetometer(magnetometer); + if (os_android->main_loop_iterate()==true) { jclass cls = env->FindClass("org/godotengine/godot/Godot"); @@ -1488,6 +1491,14 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv } +JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv * env, jobject obj, jfloat x, jfloat y, jfloat z) { + + input_mutex->lock(); + magnetometer=Vector3(x,y,z); + input_mutex->unlock(); + +} + JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv * env, jobject obj){ if (!suspend_mutex) diff --git a/platform/android/java_glue.h b/platform/android/java_glue.h index 1d65d21251..f7916efe2c 100644 --- a/platform/android/java_glue.h +++ b/platform/android/java_glue.h @@ -49,6 +49,7 @@ extern "C" { JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(JNIEnv * env, jobject obj, jint p_device, jboolean p_connected, jstring p_name); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_audio(JNIEnv * env, jobject obj); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_accelerometer(JNIEnv * env, jobject obj, jfloat x, jfloat y, jfloat z); + JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_magnetometer(JNIEnv * env, jobject obj, jfloat x, jfloat y, jfloat z); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusin(JNIEnv * env, jobject obj); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_focusout(JNIEnv * env, jobject obj); JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_singleton(JNIEnv * env, jobject obj, jstring name,jobject p_object); diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp index 2ef28333be..4e6dfb2db2 100644 --- a/platform/android/os_android.cpp +++ b/platform/android/os_android.cpp @@ -609,6 +609,11 @@ void OS_Android::process_accelerometer(const Vector3& p_accelerometer) { input->set_accelerometer(p_accelerometer); } +void OS_Android::process_magnetometer(const Vector3& p_magnetometer) { + + input->set_magnetometer(p_magnetometer); +} + bool OS_Android::has_touchscreen_ui_hint() const { return true; diff --git a/platform/android/os_android.h b/platform/android/os_android.h index ec1f4119b4..843b3c4788 100644 --- a/platform/android/os_android.h +++ b/platform/android/os_android.h @@ -239,6 +239,7 @@ public: void process_accelerometer(const Vector3& p_accelerometer); + void process_magnetometer(const Vector3& p_magnetometer); void process_touch(int p_what,int p_pointer, const Vector<TouchPos>& p_points); void process_joy_event(JoystickEvent p_event); void process_event(InputEvent p_event); diff --git a/platform/osx/detect.py b/platform/osx/detect.py index 28bc42f6bb..d668509b90 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -58,8 +58,8 @@ def configure(env): if (env["freetype"]!="no"): env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) - env.Append(CPPPATH=['#tools/freetype']) - env.Append(CPPPATH=['#tools/freetype/freetype/include']) + env.Append(CPPPATH=['#drivers/freetype']) + env.Append(CPPPATH=['#drivers/freetype/freetype/include']) diff --git a/platform/osx/export/export.cpp b/platform/osx/export/export.cpp index 3bc4ebdb1a..2604c2c15a 100644 --- a/platform/osx/export/export.cpp +++ b/platform/osx/export/export.cpp @@ -32,6 +32,7 @@ class EditorExportPlatformOSX : public EditorExportPlatform { String signature; String copyright; bool use64; + bool useFat; bool high_resolution; Ref<ImageTexture> logo; @@ -95,6 +96,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 +132,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 +155,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 +293,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 +465,7 @@ EditorExportPlatformOSX::EditorExportPlatformOSX() { short_version="1.0"; version="1.0"; use64=false; + useFat=false; high_resolution=false; } 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..065fe52b09 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -202,10 +202,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 +291,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 +360,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 +419,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)); @@ -833,6 +869,7 @@ static int translateKey(unsigned int key) @implementation GodotWindow + - (BOOL)canBecomeKeyWindow { // Required for NSBorderlessWindowMask windows @@ -893,6 +930,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 +948,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 +957,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 +1104,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 +1387,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 +1419,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 +1433,29 @@ 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; }; 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 +1766,7 @@ OS_OSX::OS_OSX() { maximized = false; minimized = false; + window_size=Vector2(1024,600); zoomed = false; + display_scale=1.0; } diff --git a/platform/windows/detect.py b/platform/windows/detect.py index 56e8a5d45d..97d2461e58 100644 --- a/platform/windows/detect.py +++ b/platform/windows/detect.py @@ -204,8 +204,8 @@ def configure(env): if (env["freetype"]!="no"): env.Append(CCFLAGS=['/DFREETYPE_ENABLED']) - env.Append(CPPPATH=['#tools/freetype']) - env.Append(CPPPATH=['#tools/freetype/freetype/include']) + env.Append(CPPPATH=['#drivers/freetype']) + env.Append(CPPPATH=['#drivers/freetype/freetype/include']) if (env["target"]=="release"): @@ -352,8 +352,9 @@ def configure(env): if (env["freetype"]!="no"): env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) - env.Append(CPPPATH=['#tools/freetype']) - env.Append(CPPPATH=['#tools/freetype/freetype/include']) + env.Append(CPPPATH=['#drivers/freetype']) + env.Append(CPPPATH=['#drivers/freetype/freetype/include']) + env["CC"]=mingw_prefix+"gcc" env['AS']=mingw_prefix+"as" diff --git a/platform/windows/godot.ico b/platform/windows/godot.ico Binary files differindex e57ce36529..3e52f2e52f 100644 --- a/platform/windows/godot.ico +++ b/platform/windows/godot.ico diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index c9c7780a2a..4f2bfd46ae 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -724,6 +724,32 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { } } break; + case WM_DROPFILES: { + + HDROP hDropInfo = NULL; + hDropInfo = (HDROP) wParam; + const int buffsize=4096; + wchar_t buf[buffsize]; + + int fcount = DragQueryFileW(hDropInfo, 0xFFFFFFFF,NULL,0); + + Vector<String> files; + + for(int i=0;i<fcount;i++) { + + DragQueryFileW(hDropInfo, i, buf, buffsize); + String file=buf; + files.push_back(file); + } + + if (files.size() && main_loop) { + main_loop->drop_files(files,0); + } + + + } break; + + default: { @@ -748,6 +774,8 @@ LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { } + + void OS_Windows::process_key_events() { for(int i=0;i<key_event_pos;i++) { @@ -819,6 +847,75 @@ void OS_Windows::process_key_events() { key_event_pos=0; } +enum _MonitorDpiType +{ + MDT_Effective_DPI = 0, + MDT_Angular_DPI = 1, + MDT_Raw_DPI = 2, + MDT_Default = MDT_Effective_DPI +}; + + +static int QueryDpiForMonitor(HMONITOR hmon, _MonitorDpiType dpiType= MDT_Default) +{ + + + int dpiX = 96, dpiY = 96; + + static HMODULE Shcore = NULL; + typedef HRESULT (WINAPI* GetDPIForMonitor_t)(HMONITOR hmonitor, _MonitorDpiType dpiType, UINT *dpiX, UINT *dpiY); + static GetDPIForMonitor_t getDPIForMonitor = NULL; + + if (Shcore == NULL) + { + Shcore = LoadLibraryW(L"Shcore.dll"); + getDPIForMonitor = Shcore ? (GetDPIForMonitor_t)GetProcAddress(Shcore, "GetDpiForMonitor") : NULL; + + if ((Shcore == NULL) || (getDPIForMonitor == NULL)) + { + if (Shcore) + FreeLibrary(Shcore); + Shcore = (HMODULE)INVALID_HANDLE_VALUE; + } + } + + UINT x = 0, y = 0; + HRESULT hr = E_FAIL; + bool bSet = false; + if (hmon && (Shcore != (HMODULE)INVALID_HANDLE_VALUE)) + { + hr = getDPIForMonitor(hmon, dpiType/*MDT_Effective_DPI*/, &x, &y); + if (SUCCEEDED(hr) && (x > 0) && (y > 0)) + { + + dpiX = (int)x; + dpiY = (int)y; + } + } + else + { + static int overallX = 0, overallY = 0; + if (overallX <= 0 || overallY <= 0) + { + HDC hdc = GetDC(NULL); + if (hdc) + { + overallX = GetDeviceCaps(hdc, LOGPIXELSX); + overallY = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(NULL, hdc); + } + } + if (overallX > 0 && overallY > 0) + { + dpiX = overallX; dpiY = overallY; + } + } + + + return (dpiX+dpiY)/2; +} + + BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) { OS_Windows *self=(OS_Windows*)OS::get_singleton(); MonitorInfo minfo; @@ -829,6 +926,8 @@ BOOL CALLBACK OS_Windows::MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPR minfo.rect.size.x=lprcMonitor->right - lprcMonitor->left; minfo.rect.size.y=lprcMonitor->bottom - lprcMonitor->top; + minfo.dpi = QueryDpiForMonitor(hMonitor); + self->monitor_info.push_back(minfo); return TRUE; @@ -1035,6 +1134,8 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ _ensure_data_dir(); + DragAcceptFiles(hWnd,true); + } @@ -1338,6 +1439,14 @@ Size2 OS_Windows::get_screen_size(int p_screen) const{ return Vector2( monitor_info[p_screen].rect.size ); } + +int OS_Windows::get_screen_dpi(int p_screen) const { + + ERR_FAIL_INDEX_V(p_screen,monitor_info.size(),72); + UINT dpix,dpiy; + return monitor_info[p_screen].dpi; + +} Point2 OS_Windows::get_window_position() const{ RECT r; diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 810da1b3cd..6dd5b78bfd 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -172,6 +172,7 @@ protected: HMONITOR hMonitor; HDC hdcMonitor; Rect2 rect; + int dpi; }; @@ -213,6 +214,8 @@ public: 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 Size2 get_window_size() const; diff --git a/platform/x11/detect.py b/platform/x11/detect.py index 6b3f7147ef..5a43bf9323 100644 --- a/platform/x11/detect.py +++ b/platform/x11/detect.py @@ -143,8 +143,8 @@ def configure(env): if (env["freetype"]!="no"): env.Append(CCFLAGS=['-DFREETYPE_ENABLED']) if (env["freetype"]=="builtin"): - env.Append(CPPPATH=['#tools/freetype']) - env.Append(CPPPATH=['#tools/freetype/freetype/include']) + env.Append(CPPPATH=['#drivers/freetype']) + env.Append(CPPPATH=['#drivers/freetype/freetype/include']) env.Append(CPPFLAGS=['-DOPENGL_ENABLED','-DGLEW_ENABLED']) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 4d7532d637..66723c0295 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -105,6 +105,7 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi last_timestamp=0; last_mouse_pos_valid=false; last_keyrelease_time=0; + xdnd_version = 0; if (get_render_thread_mode()==RENDER_SEPARATE_THREAD) { XInitThreads(); @@ -415,6 +416,19 @@ void OS_X11::initialize(const VideoMode& p_desired,int p_video_driver,int p_audi } set_cursor_shape(CURSOR_BUSY); + //Set Xdnd (drag & drop) support + Atom XdndAware = XInternAtom(x11_display, "XdndAware", False); + Atom version=5; + XChangeProperty(x11_display, x11_window, XdndAware, XA_ATOM, 32, PropModeReplace, (unsigned char*)&version, 1); + + xdnd_enter = XInternAtom(x11_display, "XdndEnter", False); + xdnd_position = XInternAtom(x11_display, "XdndPosition", False); + xdnd_status = XInternAtom(x11_display, "XdndStatus", False); + xdnd_action_copy = XInternAtom(x11_display, "XdndActionCopy", False); + xdnd_drop = XInternAtom(x11_display, "XdndDrop", False); + xdnd_finished = XInternAtom(x11_display, "XdndFinished", False); + xdnd_selection = XInternAtom(x11_display, "XdndSelection", False); + requested = None; visual_server->init(); // @@ -1166,6 +1180,72 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { input->parse_input_event( event); } +struct Property +{ + unsigned char *data; + int format, nitems; + Atom type; +}; + +static Property read_property(Display* p_display, Window p_window, Atom p_property) { + + Atom actual_type; + int actual_format; + unsigned long nitems; + unsigned long bytes_after; + unsigned char *ret=0; + + int read_bytes = 1024; + + //Keep trying to read the property until there are no + //bytes unread. + do + { + if(ret != 0) + XFree(ret); + + XGetWindowProperty(p_display, p_window, p_property, 0, read_bytes, False, AnyPropertyType, + &actual_type, &actual_format, &nitems, &bytes_after, + &ret); + + read_bytes *= 2; + + }while(bytes_after != 0); + + Property p = {ret, actual_format, nitems, actual_type}; + + return p; +} + +static Atom pick_target_from_list(Display* p_display, Atom *p_list, int p_count) { + + static const char* target_type = "text/uri-list"; + + for (int i = 0; i < p_count; i++) { + + Atom atom = p_list[i]; + + if (atom != None && String(XGetAtomName(p_display, atom)) == target_type) + return atom; + } + return None; +} + +static Atom pick_target_from_atoms(Display* p_disp, Atom p_t1, Atom p_t2, Atom p_t3) { + + static const char* target_type = "text/uri-list"; + if (p_t1 != None && String(XGetAtomName(p_disp, p_t1)) == target_type) + return p_t1; + + if (p_t2 != None && String(XGetAtomName(p_disp, p_t2)) == target_type) + return p_t2; + + if (p_t3 != None && String(XGetAtomName(p_disp, p_t3)) == target_type) + return p_t3; + + return None; +} + void OS_X11::process_xevents() { //printf("checking events %i\n", XPending(x11_display)); @@ -1456,11 +1536,96 @@ void OS_X11::process_xevents() { XFlush (x11_display); } break; + case SelectionNotify: + + if (event.xselection.target == requested) { + + Property p = read_property(x11_display, x11_window, XInternAtom(x11_display, "PRIMARY", 0)); + + Vector<String> files = String((char *)p.data).split("\n", false); + for (int i = 0; i < files.size(); i++) { + files[i] = files[i].replace("file://", "").replace("%20", " ").strip_escapes(); + } + main_loop->drop_files(files); + + //Reply that all is well. + XClientMessageEvent m; + memset(&m, sizeof(m), 0); + m.type = ClientMessage; + m.display = x11_display; + m.window = xdnd_source_window; + m.message_type = xdnd_finished; + m.format=32; + m.data.l[0] = x11_window; + m.data.l[1] = 1; + m.data.l[2] = xdnd_action_copy; //We only ever copy. + + XSendEvent(x11_display, xdnd_source_window, False, NoEventMask, (XEvent*)&m); + } + break; case ClientMessage: if ((unsigned int)event.xclient.data.l[0]==(unsigned int)wm_delete) main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST); + + else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_enter) { + + //File(s) have been dragged over the window, check for supported target (text/uri-list) + xdnd_version = ( event.xclient.data.l[1] >> 24); + Window source = event.xclient.data.l[0]; + bool more_than_3 = event.xclient.data.l[1] & 1; + if (more_than_3) { + Property p = read_property(x11_display, source, XInternAtom(x11_display, "XdndTypeList", False)); + requested = pick_target_from_list(x11_display, (Atom*)p.data, p.nitems); + } + else + requested = pick_target_from_atoms(x11_display, event.xclient.data.l[2],event.xclient.data.l[3], event.xclient.data.l[4]); + } + else if ((unsigned int)event.xclient.message_type == (unsigned int )xdnd_position) { + + //xdnd position event, reply with an XDND status message + //just depending on type of data for now + XClientMessageEvent m; + memset(&m, sizeof(m), 0); + m.type = ClientMessage; + m.display = event.xclient.display; + m.window = event.xclient.data.l[0]; + m.message_type = xdnd_status; + m.format=32; + m.data.l[0] = x11_window; + m.data.l[1] = (requested != None); + m.data.l[2] = 0; //empty rectangle + m.data.l[3] = 0; + m.data.l[4] = xdnd_action_copy; + + XSendEvent(x11_display, event.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); + XFlush(x11_display); + } + else if ((unsigned int)event.xclient.message_type == (unsigned int)xdnd_drop) { + + if (requested != None) { + xdnd_source_window = event.xclient.data.l[0]; + if(xdnd_version >= 1) + XConvertSelection(x11_display, xdnd_selection, requested, XInternAtom(x11_display, "PRIMARY", 0), x11_window, event.xclient.data.l[2]); + else + XConvertSelection(x11_display, xdnd_selection, requested, XInternAtom(x11_display, "PRIMARY", 0), x11_window, CurrentTime); + } + else { + //Reply that we're not interested. + XClientMessageEvent m; + memset(&m, sizeof(m), 0); + m.type = ClientMessage; + m.display = event.xclient.display; + m.window = event.xclient.data.l[0]; + m.message_type = xdnd_finished; + m.format=32; + m.data.l[0] = x11_window; + m.data.l[1] = 0; + m.data.l[2] = None; //Failed. + XSendEvent(x11_display, event.xclient.data.l[0], False, NoEventMask, (XEvent*)&m); + } + } break; default: break; diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index d9a5b1688c..1369340b04 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -70,6 +70,17 @@ typedef struct { class OS_X11 : public OS_Unix { Atom wm_delete; + Atom xdnd_enter; + Atom xdnd_position; + Atom xdnd_status; + Atom xdnd_action_copy; + Atom xdnd_drop; + Atom xdnd_finished; + Atom xdnd_selection; + Atom requested; + + int xdnd_version; + #if defined(OPENGL_ENABLED) || defined(LEGACYGL_ENABLED) ContextGL_X11 *context_gl; #endif @@ -78,6 +89,7 @@ class OS_X11 : public OS_Unix { VideoMode current_videomode; List<String> args; Window x11_window; + Window xdnd_source_window; MainLoop *main_loop; ::Display* x11_display; char *xmbstring; |