| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #import "SkNSView.h" | 9 #import "SkNSView.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 fRedrawRequestPending = false; | 43 fRedrawRequestPending = false; |
| 44 fWind = NULL; | 44 fWind = NULL; |
| 45 return self; | 45 return self; |
| 46 } | 46 } |
| 47 | 47 |
| 48 - (void)setUpWindow { | 48 - (void)setUpWindow { |
| 49 [[NSNotificationCenter defaultCenter] addObserver:self | 49 [[NSNotificationCenter defaultCenter] addObserver:self |
| 50 selector:@selector(backingPropertiesCh
anged:) | 50 selector:@selector(backingPropertiesCh
anged:) |
| 51 name:@"NSWindowDidChangeBackingPropert
iesNotification" | 51 name:@"NSWindowDidChangeBackingPropert
iesNotification" |
| 52 object:[self window]]; | 52 object:[self window]]; |
| 53 if (NULL != fWind) { | 53 if (fWind) { |
| 54 fWind->setVisibleP(true); | 54 fWind->setVisibleP(true); |
| 55 NSSize size = self.frame.size; | 55 NSSize size = self.frame.size; |
| 56 #if RETINA_API_AVAILABLE | 56 #if RETINA_API_AVAILABLE |
| 57 size = [self convertSizeToBacking:self.frame.size]; | 57 size = [self convertSizeToBacking:self.frame.size]; |
| 58 #endif | 58 #endif |
| 59 fWind->resize((int) size.width, (int) size.height, | 59 fWind->resize((int) size.width, (int) size.height, |
| 60 kN32_SkColorType); | 60 kN32_SkColorType); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // TODO: need a better way to force a refresh (that works). | 96 // TODO: need a better way to force a refresh (that works). |
| 97 // [fGLContext update] does not appear to update if the point size has not c
hanged, | 97 // [fGLContext update] does not appear to update if the point size has not c
hanged, |
| 98 // even if the backing size has changed. | 98 // even if the backing size has changed. |
| 99 [self setFrameSize:NSMakeSize(self.frame.size.width + 1, self.frame.size.hei
ght + 1)]; | 99 [self setFrameSize:NSMakeSize(self.frame.size.width + 1, self.frame.size.hei
ght + 1)]; |
| 100 } | 100 } |
| 101 | 101 |
| 102 - (void)resizeSkView:(NSSize)newSize { | 102 - (void)resizeSkView:(NSSize)newSize { |
| 103 #if RETINA_API_AVAILABLE | 103 #if RETINA_API_AVAILABLE |
| 104 newSize = [self convertSizeToBacking:newSize]; | 104 newSize = [self convertSizeToBacking:newSize]; |
| 105 #endif | 105 #endif |
| 106 if (NULL != fWind && | 106 if (fWind && (fWind->width() != newSize.width || fWind->height() != newSize
.height)) { |
| 107 (fWind->width() != newSize.width || | |
| 108 fWind->height() != newSize.height)) | |
| 109 { | |
| 110 fWind->resize((int) newSize.width, (int) newSize.height); | 107 fWind->resize((int) newSize.width, (int) newSize.height); |
| 111 if (NULL != fGLContext) { | 108 if (fGLContext) { |
| 112 glClear(GL_STENCIL_BUFFER_BIT); | 109 glClear(GL_STENCIL_BUFFER_BIT); |
| 113 [fGLContext update]; | 110 [fGLContext update]; |
| 114 } | 111 } |
| 115 } | 112 } |
| 116 } | 113 } |
| 117 | 114 |
| 118 - (void) setFrameSize:(NSSize)newSize { | 115 - (void) setFrameSize:(NSSize)newSize { |
| 119 [super setFrameSize:newSize]; | 116 [super setFrameSize:newSize]; |
| 120 [self resizeSkView:newSize]; | 117 [self resizeSkView:newSize]; |
| 121 } | 118 } |
| 122 | 119 |
| 123 - (void)dealloc { | 120 - (void)dealloc { |
| 124 delete fWind; | 121 delete fWind; |
| 125 self.fGLContext = nil; | 122 self.fGLContext = nil; |
| 126 self.fTitle = nil; | 123 self.fTitle = nil; |
| 127 [super dealloc]; | 124 [super dealloc]; |
| 128 } | 125 } |
| 129 | 126 |
| 130 //////////////////////////////////////////////////////////////////////////////// | 127 //////////////////////////////////////////////////////////////////////////////// |
| 131 | 128 |
| 132 - (void)drawSkia { | 129 - (void)drawSkia { |
| 133 fRedrawRequestPending = false; | 130 fRedrawRequestPending = false; |
| 134 if (NULL != fWind) { | 131 if (fWind) { |
| 135 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas()); | 132 SkAutoTUnref<SkCanvas> canvas(fWind->createCanvas()); |
| 136 fWind->draw(canvas); | 133 fWind->draw(canvas); |
| 137 #ifdef FORCE_REDRAW | 134 #ifdef FORCE_REDRAW |
| 138 fWind->inval(NULL); | 135 fWind->inval(NULL); |
| 139 #endif | 136 #endif |
| 140 } | 137 } |
| 141 } | 138 } |
| 142 | 139 |
| 143 - (void)setSkTitle:(const char *)title { | 140 - (void)setSkTitle:(const char *)title { |
| 144 self.fTitle = [NSString stringWithUTF8String:title]; | 141 self.fTitle = [NSString stringWithUTF8String:title]; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 skModi |= gModifierMasks[i].fSkModifierMask; | 258 skModi |= gModifierMasks[i].fSkModifierMask; |
| 262 } | 259 } |
| 263 } | 260 } |
| 264 return skModi; | 261 return skModi; |
| 265 } | 262 } |
| 266 | 263 |
| 267 - (void)mouseDown:(NSEvent *)event { | 264 - (void)mouseDown:(NSEvent *)event { |
| 268 NSPoint p = [event locationInWindow]; | 265 NSPoint p = [event locationInWindow]; |
| 269 unsigned modi = convertNSModifiersToSk([event modifierFlags]); | 266 unsigned modi = convertNSModifiersToSk([event modifierFlags]); |
| 270 | 267 |
| 271 if ([self mouse:p inRect:[self bounds]] && NULL != fWind) { | 268 if ([self mouse:p inRect:[self bounds]] && fWind) { |
| 272 NSPoint loc = [self convertPoint:p fromView:nil]; | 269 NSPoint loc = [self convertPoint:p fromView:nil]; |
| 273 #if RETINA_API_AVAILABLE | 270 #if RETINA_API_AVAILABLE |
| 274 loc = [self convertPointToBacking:loc]; //y-up | 271 loc = [self convertPointToBacking:loc]; //y-up |
| 275 loc.y = -loc.y; | 272 loc.y = -loc.y; |
| 276 #endif | 273 #endif |
| 277 fWind->handleClick((int) loc.x, (int) loc.y, | 274 fWind->handleClick((int) loc.x, (int) loc.y, |
| 278 SkView::Click::kDown_State, self, modi); | 275 SkView::Click::kDown_State, self, modi); |
| 279 } | 276 } |
| 280 } | 277 } |
| 281 | 278 |
| 282 - (void)mouseDragged:(NSEvent *)event { | 279 - (void)mouseDragged:(NSEvent *)event { |
| 283 NSPoint p = [event locationInWindow]; | 280 NSPoint p = [event locationInWindow]; |
| 284 unsigned modi = convertNSModifiersToSk([event modifierFlags]); | 281 unsigned modi = convertNSModifiersToSk([event modifierFlags]); |
| 285 | 282 |
| 286 if ([self mouse:p inRect:[self bounds]] && NULL != fWind) { | 283 if ([self mouse:p inRect:[self bounds]] && fWind) { |
| 287 NSPoint loc = [self convertPoint:p fromView:nil]; | 284 NSPoint loc = [self convertPoint:p fromView:nil]; |
| 288 #if RETINA_API_AVAILABLE | 285 #if RETINA_API_AVAILABLE |
| 289 loc = [self convertPointToBacking:loc]; //y-up | 286 loc = [self convertPointToBacking:loc]; //y-up |
| 290 loc.y = -loc.y; | 287 loc.y = -loc.y; |
| 291 #endif | 288 #endif |
| 292 fWind->handleClick((int) loc.x, (int) loc.y, | 289 fWind->handleClick((int) loc.x, (int) loc.y, |
| 293 SkView::Click::kMoved_State, self, modi); | 290 SkView::Click::kMoved_State, self, modi); |
| 294 } | 291 } |
| 295 } | 292 } |
| 296 | 293 |
| 297 - (void)mouseMoved:(NSEvent *)event { | 294 - (void)mouseMoved:(NSEvent *)event { |
| 298 NSPoint p = [event locationInWindow]; | 295 NSPoint p = [event locationInWindow]; |
| 299 unsigned modi = convertNSModifiersToSk([event modifierFlags]); | 296 unsigned modi = convertNSModifiersToSk([event modifierFlags]); |
| 300 | 297 |
| 301 if ([self mouse:p inRect:[self bounds]] && NULL != fWind) { | 298 if ([self mouse:p inRect:[self bounds]] && fWind) { |
| 302 NSPoint loc = [self convertPoint:p fromView:nil]; | 299 NSPoint loc = [self convertPoint:p fromView:nil]; |
| 303 #if RETINA_API_AVAILABLE | 300 #if RETINA_API_AVAILABLE |
| 304 loc = [self convertPointToBacking:loc]; //y-up | 301 loc = [self convertPointToBacking:loc]; //y-up |
| 305 loc.y = -loc.y; | 302 loc.y = -loc.y; |
| 306 #endif | 303 #endif |
| 307 fWind->handleClick((int) loc.x, (int) loc.y, | 304 fWind->handleClick((int) loc.x, (int) loc.y, |
| 308 SkView::Click::kMoved_State, self, modi); | 305 SkView::Click::kMoved_State, self, modi); |
| 309 } | 306 } |
| 310 } | 307 } |
| 311 | 308 |
| 312 - (void)mouseUp:(NSEvent *)event { | 309 - (void)mouseUp:(NSEvent *)event { |
| 313 NSPoint p = [event locationInWindow]; | 310 NSPoint p = [event locationInWindow]; |
| 314 unsigned modi = convertNSModifiersToSk([event modifierFlags]); | 311 unsigned modi = convertNSModifiersToSk([event modifierFlags]); |
| 315 | 312 |
| 316 if ([self mouse:p inRect:[self bounds]] && NULL != fWind) { | 313 if ([self mouse:p inRect:[self bounds]] && fWind) { |
| 317 NSPoint loc = [self convertPoint:p fromView:nil]; | 314 NSPoint loc = [self convertPoint:p fromView:nil]; |
| 318 #if RETINA_API_AVAILABLE | 315 #if RETINA_API_AVAILABLE |
| 319 loc = [self convertPointToBacking:loc]; //y-up | 316 loc = [self convertPointToBacking:loc]; //y-up |
| 320 loc.y = -loc.y; | 317 loc.y = -loc.y; |
| 321 #endif | 318 #endif |
| 322 fWind->handleClick((int) loc.x, (int) loc.y, | 319 fWind->handleClick((int) loc.x, (int) loc.y, |
| 323 SkView::Click::kUp_State, self, modi); | 320 SkView::Click::kUp_State, self, modi); |
| 324 } | 321 } |
| 325 } | 322 } |
| 326 | 323 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 [fGLContext release]; | 408 [fGLContext release]; |
| 412 fGLContext = nil; | 409 fGLContext = nil; |
| 413 } | 410 } |
| 414 | 411 |
| 415 - (void)present { | 412 - (void)present { |
| 416 if (nil != fGLContext) { | 413 if (nil != fGLContext) { |
| 417 [fGLContext flushBuffer]; | 414 [fGLContext flushBuffer]; |
| 418 } | 415 } |
| 419 } | 416 } |
| 420 @end | 417 @end |
| OLD | NEW |