# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1616294257 0 # Node ID 41a04e6b3e8eb98693e1504bd2300bb564f49f31 # Parent 3777ea1cccdb7cf568c56a31f609bf7e895fd07f iOS: More conversion... mostly drawing related changes. diff -r 3777ea1cccdb -r 41a04e6b3e8e ios/dw.m --- a/ios/dw.m Sat Mar 20 21:53:56 2021 +0000 +++ b/ios/dw.m Sun Mar 21 02:37:37 2021 +0000 @@ -264,7 +264,7 @@ void _handle_resize_events(Box *thisbox); int _remove_userdata(UserData **root, const char *varname, int all); int _dw_main_iteration(NSDate *date); -CGContextRef _dw_draw_context(UIImage *image); +CGContextRef _dw_draw_context(UIImage *image, bool antialias); typedef id (*DWIMP)(id, SEL, ...); /* Internal function to queue a window redraw */ @@ -883,7 +883,7 @@ } if([bltdest isMemberOfClass:[UIImage class]]) { - UIGraphicsPushContext(_dw_draw_context(bltdest)); + _dw_draw_context(bltdest, NO); } if(bltdest && [bltsrc isMemberOfClass:[UIImage class]]) { @@ -908,7 +908,7 @@ } if([bltdest isMemberOfClass:[UIImage class]]) { - UIGraphicsPopContext(); + UIGraphicsEndImageContext(); } free(bltinfo); } @@ -3581,8 +3581,9 @@ [slider setMaximumValue:(double)increments]; [slider setMinimumValue:0]; [slider setContinuous:YES]; - [slider setTarget:slider]; - [slider setAction:@selector(sliderChanged:)]; + [slider addTarget:slider + action:@selector(sliderChanged:) + forControlEvents:UIControlEventValueChanged]; [slider setTag:cid]; return slider; } @@ -4592,9 +4593,14 @@ return value; } -CGContextRef _dw_draw_context(UIImage *image) -{ - return [NSGraphicsContext graphicsContextWithCGContext:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext] flipped:YES]; +CGContextRef _dw_draw_context(UIImage *image, bool antialiased) +{ + CGContextRef context; + + UIGraphicsBeginImageContext(image.size); + context = UIGraphicsGetCurrentContext(); + CGContextSetAllowsAntialiasing(context, antialiased); + return context; } /* Draw a point on a window (preferably a render window). @@ -4628,21 +4634,20 @@ } if(bi) { - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)]; + _dw_draw_context(bi, NO); } if(bCanDraw == YES) { - NSBezierPath* aPath = [NSBezierPath bezierPath]; + UIBezierPath* aPath = [UIBezierPath bezierPath]; [aPath setLineWidth: 0.5]; UIColor *color = pthread_getspecific(_dw_fg_color_key); [color set]; - [aPath moveToPoint:NSMakePoint(x, y)]; + [aPath moveToPoint:CGPointMake(x, y)]; [aPath stroke]; } if(bi) - [NSGraphicsContext restoreGraphicsState]; + UIGraphicsEndImageContext(); DW_LOCAL_POOL_OUT; DW_FUNCTION_RETURN_NOTHING; } @@ -4680,22 +4685,21 @@ } if(bi) { - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)]; + _dw_draw_context(bi, NO); } if(bCanDraw == YES) { - NSBezierPath* aPath = [NSBezierPath bezierPath]; + UIBezierPath* aPath = [UIBezierPath bezierPath]; UIColor *color = pthread_getspecific(_dw_fg_color_key); [color set]; - [aPath moveToPoint:NSMakePoint(x1 + 0.5, y1 + 0.5)]; - [aPath lineToPoint:NSMakePoint(x2 + 0.5, y2 + 0.5)]; + [aPath moveToPoint:CGPointMake(x1 + 0.5, y1 + 0.5)]; + [aPath lineToPoint:CGPointMake(x2 + 0.5, y2 + 0.5)]; [aPath stroke]; } if(bi) - [NSGraphicsContext restoreGraphicsState]; + UIGraphicsEndImageContext(); DW_LOCAL_POOL_OUT; DW_FUNCTION_RETURN_NOTHING; } @@ -4741,8 +4745,7 @@ } if(bi) { - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)]; + _dw_draw_context(bi, NO); } if(bCanDraw == YES) @@ -4753,13 +4756,13 @@ if(bgcolor) [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName]; if(font) - [dict setValue:font forKey:UIFontAttributeName]; - [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; + [dict setValue:font forKey:NSFontAttributeName]; + [nstr drawAtPoint:CGPointMake(x, y) withAttributes:dict]; [dict release]; } if(bi) - [NSGraphicsContext restoreGraphicsState]; + UIGraphicsEndImageContext(); DW_LOCAL_POOL_OUT; DW_FUNCTION_RETURN_NOTHING; } @@ -4796,7 +4799,7 @@ /* If we got a font... add it to the dictionary */ if(font) { - [dict setValue:font forKey:UIFontAttributeName]; + [dict setValue:font forKey:NSFontAttributeName]; } /* Calculate the size of the string */ CGSize size = [nstr sizeWithAttributes:dict]; @@ -4813,18 +4816,6 @@ DW_LOCAL_POOL_OUT; } -/* Internal function to create an image graphics context... - * with or without antialiasing enabled. - */ -id _create_gc(id image, bool antialiased) -{ - CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext]; - NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:context flipped:YES]; - [gc setShouldAntialias:antialiased]; - CGContextSetAllowsAntialiasing(context, antialiased); - return gc; -} - /* Draw a polygon on a window (preferably a render window). * Parameters: * handle: Handle to the window. @@ -4860,32 +4851,29 @@ } if(bi) { - id gc = _create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES); - [NSGraphicsContext saveGraphicsState]; - [NSGraphicsContext setCurrentContext:gc]; + _dw_draw_context(bi, flags & DW_DRAW_NOAA ? NO : YES); } if(bCanDraw == YES) { - NSBezierPath* aPath = [NSBezierPath bezierPath]; + UIBezierPath* aPath = [UIBezierPath bezierPath]; UIColor *color = pthread_getspecific(_dw_fg_color_key); [color set]; - [aPath moveToPoint:NSMakePoint(*x + 0.5, *y + 0.5)]; + [aPath moveToPoint:CGPointMake(*x + 0.5, *y + 0.5)]; for(z=1;z 1) - { - newpos = 1; - } - [scrollbar setFloatValue:newpos]; + offset.y = offset.y + [sv visibleSize].height; break; } } + if(offset.y < 0) + offset.y = 0; + [sv setContentOffset:offset]; DW_FUNCTION_RETURN_NOTHING; } @@ -6261,6 +6257,8 @@ if(name && (name++)) { + UIFontDescriptorSymbolicTraits traits = 0; + UIFontDescriptor* fd; int size = atoi(fontname); char *Italic = strstr(name, " Italic"); char *Bold = strstr(name, " Bold"); @@ -6269,11 +6267,19 @@ memset(newname, 0, len+1); strncpy(newname, name, len); - - font = [DWFontManager fontWithFamily:[NSString stringWithUTF8String:newname] - traits:(Italic ? NSItalicFontMask : 0)|(Bold ? NSBoldFontMask : 0) - weight:5 - size:(float)size]; + + if(Bold) + traits |= UIFontDescriptorTraitBold; + if(Italic) + traits |= UIFontDescriptorTraitItalic; + + fd = [UIFontDescriptor + fontDescriptorWithFontAttributes:@{UIFontDescriptorFamilyAttribute:[NSString stringWithUTF8String:newname], + UIFontDescriptorTraitsAttribute: @{UIFontSymbolicTrait:[NSNumber numberWithInteger:traits]}}]; + NSArray* matches = [fd matchingFontDescriptorsWithMandatoryKeys: + [NSSet setWithObjects:UIFontDescriptorFamilyAttribute, UIFontDescriptorTraitsAttribute, nil]]; + if(matches.count != 0) + font = [UIFont fontWithDescriptor:matches[0] size:size]; } } return font; @@ -6291,9 +6297,6 @@ { DW_FUNCTION_INIT; UIImageView *bitmap = [[UIImageView alloc] init]; - [bitmap setImageFrameStyle:UIImageFrameNone]; - [bitmap setImageScaling:UIImageScaleNone]; - [bitmap setEditable:NO]; [bitmap setTag:cid]; DW_FUNCTION_RETURN_THIS(bitmap); } @@ -6310,24 +6313,20 @@ */ HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) { - HPIXMAP pixmap; - - if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) - return NULL; - pixmap->width = width; - pixmap->height = height; - pixmap->handle = handle; - pixmap->image = [[UIImage alloc] - initWithBitmapDataPlanes:NULL - pixelsWide:width - pixelsHigh:height - bitsPerSample:8 - samplesPerPixel:4 - hasAlpha:YES - isPlanar:NO - colorSpaceName:NSDeviceRGBColorSpace - bytesPerRow:0 - bitsPerPixel:0]; + HPIXMAP pixmap = NULL; + + if((pixmap = calloc(1,sizeof(struct _hpixmap)))) + { + CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); + CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, calloc(width*height, 4), width*height*32, NULL); + CGImageRef image = CGImageCreate(width, height, 8, 32, 32 * width, + rgb, kCGBitmapByteOrderDefault | kCGImageAlphaLast, + provider, NULL, false, kCGRenderingIntentDefault); + pixmap->width = width; + pixmap->height = height; + pixmap->handle = handle; + pixmap->image = [[[UIImage alloc] initWithCGImage:image] retain]; + } return pixmap; } @@ -6365,7 +6364,7 @@ return NULL; } pixmap->width = [tmpimage size].width; - pixmap->height = [tmpimage size]size.height; + pixmap->height = [tmpimage size].height; pixmap->image = tmpimage; pixmap->handle = handle; DW_LOCAL_POOL_OUT; @@ -6445,7 +6444,7 @@ NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid]; UIImage *tmpimage = [[UIImage alloc] initWithContentsOfFile:filepath]; - if(temp) + if(tmpimage) { pixmap->width = [tmpimage size].width; pixmap->height = [tmpimage size].height;