summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJuan Linietsky <reduz@Juans-MBP.fibertel.com.ar>2016-05-30 00:28:29 -0300
committerJuan Linietsky <reduz@Juans-MBP.fibertel.com.ar>2016-05-30 00:28:29 -0300
commit9b1f8230ec435d9289b53afa8da02367daf8b5af (patch)
treecaa9383d77d9865cfa8e41c0ca0e74318d2d9365 /platform
parentc7d24b7814b335fb9503f6a957ac5923a47da161 (diff)
-Some fixes to OSX retina scaling for window functions
-Implemented HiDPI detection and support for Godot Editor!
Diffstat (limited to 'platform')
-rw-r--r--platform/osx/os_osx.h19
-rw-r--r--platform/osx/os_osx.mm87
2 files changed, 81 insertions, 25 deletions
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..b614dd57aa 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);
@@ -324,7 +324,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 +383,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));
@@ -893,6 +893,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 +911,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 +920,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 +1067,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 +1350,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 +1382,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 +1396,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 +1729,7 @@ OS_OSX::OS_OSX() {
maximized = false;
minimized = false;
+ window_size=Vector2(1024,600);
zoomed = false;
+ display_scale=1.0;
}