modules/graphics/src/main/native-glass/mac/GlassView2D.m

Print this page




 355     CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];
 356     {
 357 #if 0
 358         [[NSColor blackColor] setStroke];
 359         NSBezierPath *path = [NSBezierPath bezierPath];
 360         [path moveToPoint:NSMakePoint(0.0f, 0.0f)];
 361         [path lineToPoint:NSMakePoint([self bounds].size.width, [self bounds].size.height)];
 362         [path moveToPoint:NSMakePoint(0.0f, [self bounds].size.height)];
 363         [path lineToPoint:NSMakePoint([self bounds].size.width, 0.0f)];
 364         [path stroke];
 365 #endif
 366 #if 0
 367         CGContextFillRect(cgContext, CGRectMake(0, 0, 128, 128));
 368 #endif
 369 
 370         CGContextFlush(cgContext);
 371     }
 372     CGContextRestoreGState(cgContext);
 373 }
 374 
 375 - (void)pushPixels:(void*)pixels withWidth:(GLuint)width withHeight:(GLuint)height withScale:(GLfloat)scale withEnv:(JNIEnv *)env
 376 {
 377     assert([NSGraphicsContext currentContext] != nil);
 378 
 379     CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];
 380     {
 381         CGImageRef cgImage = NULL;
 382         CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
 383         {
 384             CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, width*height*4, NULL);
 385             {
 386                 cgImage = CGImageCreate(width, height, 8, 32, 4*width, colorSpace, kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Little, provider, NULL, true, kCGRenderingIntentDefault);
 387                 {
 388                     NSSize size = [self bounds].size;
 389                     if ((size.width != width) || (size.height != height))
 390                     {
 391                         //NSLog(@"Glass View2D size: %dx%d, but pixels size: %dx%d", (int)size.width, (int)size.height, width, height);
 392                         //CGContextClearRect(cgContext, CGRectMake(0, 0, size.width, size.height));
 393                     }
 394 
 395                     CGContextSaveGState(cgContext);
 396                     {
 397                         CGContextTranslateCTM(cgContext, 0, size.height);
 398                         CGContextScaleCTM(cgContext, 1, -1);
 399                         CGContextSetBlendMode(cgContext, kCGBlendModeCopy);
 400                         CGContextDrawImage(cgContext, CGRectMake(0, 0, width/scale, height/scale), cgImage);
 401                     }
 402                     CGContextRestoreGState(cgContext);
 403                 }
 404                 CGImageRelease(cgImage);
 405             }
 406             CGDataProviderRelease(provider);
 407         }
 408         CGColorSpaceRelease(colorSpace);
 409     }
 410     CGContextFlush(cgContext); // implicit flush
 411 }
 412 
 413 - (GlassViewDelegate*)delegate
 414 {
 415     return self->delegate;
 416 }
 417 
 418 - (void)setInputMethodEnabled:(BOOL)enabled
 419 {
 420     // Just a no-op here, GlassView2D does not support the IM interface


 355     CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];
 356     {
 357 #if 0
 358         [[NSColor blackColor] setStroke];
 359         NSBezierPath *path = [NSBezierPath bezierPath];
 360         [path moveToPoint:NSMakePoint(0.0f, 0.0f)];
 361         [path lineToPoint:NSMakePoint([self bounds].size.width, [self bounds].size.height)];
 362         [path moveToPoint:NSMakePoint(0.0f, [self bounds].size.height)];
 363         [path lineToPoint:NSMakePoint([self bounds].size.width, 0.0f)];
 364         [path stroke];
 365 #endif
 366 #if 0
 367         CGContextFillRect(cgContext, CGRectMake(0, 0, 128, 128));
 368 #endif
 369 
 370         CGContextFlush(cgContext);
 371     }
 372     CGContextRestoreGState(cgContext);
 373 }
 374 
 375 - (void)pushPixels:(void*)pixels withWidth:(GLuint)width withHeight:(GLuint)height withScaleX:(GLfloat)scalex withScaleY:(GLfloat)scaley withEnv:(JNIEnv *)env
 376 {
 377     assert([NSGraphicsContext currentContext] != nil);
 378 
 379     CGContextRef cgContext = [[NSGraphicsContext currentContext] graphicsPort];
 380     {
 381         CGImageRef cgImage = NULL;
 382         CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
 383         {
 384             CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, pixels, width*height*4, NULL);
 385             {
 386                 cgImage = CGImageCreate(width, height, 8, 32, 4*width, colorSpace, kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Little, provider, NULL, true, kCGRenderingIntentDefault);
 387                 {
 388                     NSSize size = [self bounds].size;
 389                     if ((size.width != width) || (size.height != height))
 390                     {
 391                         //NSLog(@"Glass View2D size: %dx%d, but pixels size: %dx%d", (int)size.width, (int)size.height, width, height);
 392                         //CGContextClearRect(cgContext, CGRectMake(0, 0, size.width, size.height));
 393                     }
 394 
 395                     CGContextSaveGState(cgContext);
 396                     {
 397                         CGContextTranslateCTM(cgContext, 0, size.height);
 398                         CGContextScaleCTM(cgContext, 1, -1);
 399                         CGContextSetBlendMode(cgContext, kCGBlendModeCopy);
 400                         CGContextDrawImage(cgContext, CGRectMake(0, 0, width/scalex, height/scaley), cgImage);
 401                     }
 402                     CGContextRestoreGState(cgContext);
 403                 }
 404                 CGImageRelease(cgImage);
 405             }
 406             CGDataProviderRelease(provider);
 407         }
 408         CGColorSpaceRelease(colorSpace);
 409     }
 410     CGContextFlush(cgContext); // implicit flush
 411 }
 412 
 413 - (GlassViewDelegate*)delegate
 414 {
 415     return self->delegate;
 416 }
 417 
 418 - (void)setInputMethodEnabled:(BOOL)enabled
 419 {
 420     // Just a no-op here, GlassView2D does not support the IM interface