src/video/cocoa/SDL_cocoawindow.m
changeset 12339 86dcfbbcacaf
parent 12239 55489adbb75c
child 12404 eb60e952b13f
equal deleted inserted replaced
12338:a02aa66a76d8 12339:86dcfbbcacaf
   630     }
   630     }
   631 
   631 
   632     const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
   632     const unsigned int newflags = [NSEvent modifierFlags] & NSEventModifierFlagCapsLock;
   633     _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
   633     _data->videodata->modifierFlags = (_data->videodata->modifierFlags & ~NSEventModifierFlagCapsLock) | newflags;
   634     SDL_ToggleModState(KMOD_CAPS, newflags != 0);
   634     SDL_ToggleModState(KMOD_CAPS, newflags != 0);
   635 
       
   636     ScheduleContextUpdates(_data);
       
   637 }
   635 }
   638 
   636 
   639 - (void)windowDidResignKey:(NSNotification *)aNotification
   637 - (void)windowDidResignKey:(NSNotification *)aNotification
   640 {
   638 {
   641     SDL_Mouse *mouse = SDL_GetMouse();
   639     SDL_Mouse *mouse = SDL_GetMouse();
  1143 /* The default implementation doesn't pass rightMouseDown to responder chain */
  1141 /* The default implementation doesn't pass rightMouseDown to responder chain */
  1144 - (void)rightMouseDown:(NSEvent *)theEvent;
  1142 - (void)rightMouseDown:(NSEvent *)theEvent;
  1145 - (BOOL)mouseDownCanMoveWindow;
  1143 - (BOOL)mouseDownCanMoveWindow;
  1146 - (void)drawRect:(NSRect)dirtyRect;
  1144 - (void)drawRect:(NSRect)dirtyRect;
  1147 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
  1145 - (BOOL)acceptsFirstMouse:(NSEvent *)theEvent;
       
  1146 - (BOOL)wantsUpdateLayer;
       
  1147 - (void)updateLayer;
  1148 @end
  1148 @end
  1149 
  1149 
  1150 @implementation SDLView
  1150 @implementation SDLView
       
  1151 
  1151 - (void)setSDLWindow:(SDL_Window*)window
  1152 - (void)setSDLWindow:(SDL_Window*)window
  1152 {
  1153 {
  1153     _sdlWindow = window;
  1154     _sdlWindow = window;
  1154 }
  1155 }
  1155 
  1156 
       
  1157 /* this is used on older macOS revisions. 10.8 and later use updateLayer. */
  1156 - (void)drawRect:(NSRect)dirtyRect
  1158 - (void)drawRect:(NSRect)dirtyRect
  1157 {
  1159 {
  1158     /* Force the graphics context to clear to black so we don't get a flash of
  1160     /* Force the graphics context to clear to black so we don't get a flash of
  1159        white until the app is ready to draw. In practice on modern macOS, this
  1161        white until the app is ready to draw. In practice on modern macOS, this
  1160        only gets called for window creation and other extraordinary events. */
  1162        only gets called for window creation and other extraordinary events. */
  1161     [[NSColor blackColor] setFill];
  1163     [[NSColor blackColor] setFill];
  1162     NSRectFill(dirtyRect);
  1164     NSRectFill(dirtyRect);
       
  1165     SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
       
  1166 }
       
  1167 
       
  1168 -(BOOL) wantsUpdateLayer
       
  1169 {
       
  1170     return YES;
       
  1171 }
       
  1172 
       
  1173 -(void) updateLayer
       
  1174 {
       
  1175     /* Force the graphics context to clear to black so we don't get a flash of
       
  1176        white until the app is ready to draw. In practice on modern macOS, this
       
  1177        only gets called for window creation and other extraordinary events. */
       
  1178     self.layer.backgroundColor = NSColor.blackColor.CGColor;
       
  1179     ScheduleContextUpdates((SDL_WindowData *) _sdlWindow->driverdata);
  1163     SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
  1180     SDL_SendWindowEvent(_sdlWindow, SDL_WINDOWEVENT_EXPOSED, 0, 0);
  1164 }
  1181 }
  1165 
  1182 
  1166 - (void)rightMouseDown:(NSEvent *)theEvent
  1183 - (void)rightMouseDown:(NSEvent *)theEvent
  1167 {
  1184 {
  1343     if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
  1360     if (window->flags & SDL_WINDOW_ALLOW_HIGHDPI) {
  1344         if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
  1361         if ([contentView respondsToSelector:@selector(setWantsBestResolutionOpenGLSurface:)]) {
  1345             [contentView setWantsBestResolutionOpenGLSurface:YES];
  1362             [contentView setWantsBestResolutionOpenGLSurface:YES];
  1346         }
  1363         }
  1347     }
  1364     }
       
  1365 
  1348 #if SDL_VIDEO_OPENGL_ES2
  1366 #if SDL_VIDEO_OPENGL_ES2
  1349 #if SDL_VIDEO_OPENGL_EGL
  1367 #if SDL_VIDEO_OPENGL_EGL
  1350     if ((window->flags & SDL_WINDOW_OPENGL) &&
  1368     if ((window->flags & SDL_WINDOW_OPENGL) &&
  1351         _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
  1369         _this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) {
  1352         [contentView setWantsLayer:TRUE];
  1370         [contentView setWantsLayer:TRUE];