Mercurial > dwindows
comparison ios/dw.m @ 2382:41a04e6b3e8e
iOS: More conversion... mostly drawing related changes.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 21 Mar 2021 02:37:37 +0000 |
parents | 3777ea1cccdb |
children | a410d42d9e36 |
comparison
equal
deleted
inserted
replaced
2381:3777ea1cccdb | 2382:41a04e6b3e8e |
---|---|
262 /* Some internal prototypes */ | 262 /* Some internal prototypes */ |
263 static void _do_resize(Box *thisbox, int x, int y); | 263 static void _do_resize(Box *thisbox, int x, int y); |
264 void _handle_resize_events(Box *thisbox); | 264 void _handle_resize_events(Box *thisbox); |
265 int _remove_userdata(UserData **root, const char *varname, int all); | 265 int _remove_userdata(UserData **root, const char *varname, int all); |
266 int _dw_main_iteration(NSDate *date); | 266 int _dw_main_iteration(NSDate *date); |
267 CGContextRef _dw_draw_context(UIImage *image); | 267 CGContextRef _dw_draw_context(UIImage *image, bool antialias); |
268 typedef id (*DWIMP)(id, SEL, ...); | 268 typedef id (*DWIMP)(id, SEL, ...); |
269 | 269 |
270 /* Internal function to queue a window redraw */ | 270 /* Internal function to queue a window redraw */ |
271 void _dw_redraw(id window, int skip) | 271 void _dw_redraw(id window, int skip) |
272 { | 272 { |
881 | 881 |
882 bltdest = [render cachedDrawingRep]; | 882 bltdest = [render cachedDrawingRep]; |
883 } | 883 } |
884 if([bltdest isMemberOfClass:[UIImage class]]) | 884 if([bltdest isMemberOfClass:[UIImage class]]) |
885 { | 885 { |
886 UIGraphicsPushContext(_dw_draw_context(bltdest)); | 886 _dw_draw_context(bltdest, NO); |
887 } | 887 } |
888 if(bltdest && [bltsrc isMemberOfClass:[UIImage class]]) | 888 if(bltdest && [bltsrc isMemberOfClass:[UIImage class]]) |
889 { | 889 { |
890 UIImage *rep = bltsrc; | 890 UIImage *rep = bltsrc; |
891 UIImage *image = [[UIImage alloc] initWithCGImage:[rep CGImage]]; | 891 UIImage *image = [[UIImage alloc] initWithCGImage:[rep CGImage]]; |
906 [bltsrc release]; | 906 [bltsrc release]; |
907 [image release]; | 907 [image release]; |
908 } | 908 } |
909 if([bltdest isMemberOfClass:[UIImage class]]) | 909 if([bltdest isMemberOfClass:[UIImage class]]) |
910 { | 910 { |
911 UIGraphicsPopContext(); | 911 UIGraphicsEndImageContext(); |
912 } | 912 } |
913 free(bltinfo); | 913 free(bltinfo); |
914 } | 914 } |
915 -(void)doFlush:(id)param | 915 -(void)doFlush:(id)param |
916 { | 916 { |
3579 { | 3579 { |
3580 DWSlider *slider = [[DWSlider alloc] init]; | 3580 DWSlider *slider = [[DWSlider alloc] init]; |
3581 [slider setMaximumValue:(double)increments]; | 3581 [slider setMaximumValue:(double)increments]; |
3582 [slider setMinimumValue:0]; | 3582 [slider setMinimumValue:0]; |
3583 [slider setContinuous:YES]; | 3583 [slider setContinuous:YES]; |
3584 [slider setTarget:slider]; | 3584 [slider addTarget:slider |
3585 [slider setAction:@selector(sliderChanged:)]; | 3585 action:@selector(sliderChanged:) |
3586 forControlEvents:UIControlEventValueChanged]; | |
3586 [slider setTag:cid]; | 3587 [slider setTag:cid]; |
3587 return slider; | 3588 return slider; |
3588 } | 3589 } |
3589 | 3590 |
3590 /* | 3591 /* |
4590 DW_LOCAL_POOL_OUT; | 4591 DW_LOCAL_POOL_OUT; |
4591 #endif | 4592 #endif |
4592 return value; | 4593 return value; |
4593 } | 4594 } |
4594 | 4595 |
4595 CGContextRef _dw_draw_context(UIImage *image) | 4596 CGContextRef _dw_draw_context(UIImage *image, bool antialiased) |
4596 { | 4597 { |
4597 return [NSGraphicsContext graphicsContextWithCGContext:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext] flipped:YES]; | 4598 CGContextRef context; |
4599 | |
4600 UIGraphicsBeginImageContext(image.size); | |
4601 context = UIGraphicsGetCurrentContext(); | |
4602 CGContextSetAllowsAntialiasing(context, antialiased); | |
4603 return context; | |
4598 } | 4604 } |
4599 | 4605 |
4600 /* Draw a point on a window (preferably a render window). | 4606 /* Draw a point on a window (preferably a render window). |
4601 * Parameters: | 4607 * Parameters: |
4602 * handle: Handle to the window. | 4608 * handle: Handle to the window. |
4626 bi = [render cachedDrawingRep]; | 4632 bi = [render cachedDrawingRep]; |
4627 } | 4633 } |
4628 } | 4634 } |
4629 if(bi) | 4635 if(bi) |
4630 { | 4636 { |
4631 [NSGraphicsContext saveGraphicsState]; | 4637 _dw_draw_context(bi, NO); |
4632 [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)]; | |
4633 } | 4638 } |
4634 if(bCanDraw == YES) | 4639 if(bCanDraw == YES) |
4635 { | 4640 { |
4636 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 4641 UIBezierPath* aPath = [UIBezierPath bezierPath]; |
4637 [aPath setLineWidth: 0.5]; | 4642 [aPath setLineWidth: 0.5]; |
4638 UIColor *color = pthread_getspecific(_dw_fg_color_key); | 4643 UIColor *color = pthread_getspecific(_dw_fg_color_key); |
4639 [color set]; | 4644 [color set]; |
4640 | 4645 |
4641 [aPath moveToPoint:NSMakePoint(x, y)]; | 4646 [aPath moveToPoint:CGPointMake(x, y)]; |
4642 [aPath stroke]; | 4647 [aPath stroke]; |
4643 } | 4648 } |
4644 if(bi) | 4649 if(bi) |
4645 [NSGraphicsContext restoreGraphicsState]; | 4650 UIGraphicsEndImageContext(); |
4646 DW_LOCAL_POOL_OUT; | 4651 DW_LOCAL_POOL_OUT; |
4647 DW_FUNCTION_RETURN_NOTHING; | 4652 DW_FUNCTION_RETURN_NOTHING; |
4648 } | 4653 } |
4649 | 4654 |
4650 /* Draw a line on a window (preferably a render window). | 4655 /* Draw a line on a window (preferably a render window). |
4678 bi = [render cachedDrawingRep]; | 4683 bi = [render cachedDrawingRep]; |
4679 } | 4684 } |
4680 } | 4685 } |
4681 if(bi) | 4686 if(bi) |
4682 { | 4687 { |
4683 [NSGraphicsContext saveGraphicsState]; | 4688 _dw_draw_context(bi, NO); |
4684 [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)]; | |
4685 } | 4689 } |
4686 if(bCanDraw == YES) | 4690 if(bCanDraw == YES) |
4687 { | 4691 { |
4688 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 4692 UIBezierPath* aPath = [UIBezierPath bezierPath]; |
4689 UIColor *color = pthread_getspecific(_dw_fg_color_key); | 4693 UIColor *color = pthread_getspecific(_dw_fg_color_key); |
4690 [color set]; | 4694 [color set]; |
4691 | 4695 |
4692 [aPath moveToPoint:NSMakePoint(x1 + 0.5, y1 + 0.5)]; | 4696 [aPath moveToPoint:CGPointMake(x1 + 0.5, y1 + 0.5)]; |
4693 [aPath lineToPoint:NSMakePoint(x2 + 0.5, y2 + 0.5)]; | 4697 [aPath lineToPoint:CGPointMake(x2 + 0.5, y2 + 0.5)]; |
4694 [aPath stroke]; | 4698 [aPath stroke]; |
4695 } | 4699 } |
4696 | 4700 |
4697 if(bi) | 4701 if(bi) |
4698 [NSGraphicsContext restoreGraphicsState]; | 4702 UIGraphicsEndImageContext(); |
4699 DW_LOCAL_POOL_OUT; | 4703 DW_LOCAL_POOL_OUT; |
4700 DW_FUNCTION_RETURN_NOTHING; | 4704 DW_FUNCTION_RETURN_NOTHING; |
4701 } | 4705 } |
4702 | 4706 |
4703 /* Draw text on a window (preferably a render window). | 4707 /* Draw text on a window (preferably a render window). |
4739 font = [render font]; | 4743 font = [render font]; |
4740 bi = [render cachedDrawingRep]; | 4744 bi = [render cachedDrawingRep]; |
4741 } | 4745 } |
4742 if(bi) | 4746 if(bi) |
4743 { | 4747 { |
4744 [NSGraphicsContext saveGraphicsState]; | 4748 _dw_draw_context(bi, NO); |
4745 [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)]; | |
4746 } | 4749 } |
4747 | 4750 |
4748 if(bCanDraw == YES) | 4751 if(bCanDraw == YES) |
4749 { | 4752 { |
4750 UIColor *fgcolor = pthread_getspecific(_dw_fg_color_key); | 4753 UIColor *fgcolor = pthread_getspecific(_dw_fg_color_key); |
4751 UIColor *bgcolor = pthread_getspecific(_dw_bg_color_key); | 4754 UIColor *bgcolor = pthread_getspecific(_dw_bg_color_key); |
4752 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; | 4755 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; |
4753 if(bgcolor) | 4756 if(bgcolor) |
4754 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName]; | 4757 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName]; |
4755 if(font) | 4758 if(font) |
4756 [dict setValue:font forKey:UIFontAttributeName]; | 4759 [dict setValue:font forKey:NSFontAttributeName]; |
4757 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; | 4760 [nstr drawAtPoint:CGPointMake(x, y) withAttributes:dict]; |
4758 [dict release]; | 4761 [dict release]; |
4759 } | 4762 } |
4760 | 4763 |
4761 if(bi) | 4764 if(bi) |
4762 [NSGraphicsContext restoreGraphicsState]; | 4765 UIGraphicsEndImageContext(); |
4763 DW_LOCAL_POOL_OUT; | 4766 DW_LOCAL_POOL_OUT; |
4764 DW_FUNCTION_RETURN_NOTHING; | 4767 DW_FUNCTION_RETURN_NOTHING; |
4765 } | 4768 } |
4766 | 4769 |
4767 /* Query the width and height of a text string. | 4770 /* Query the width and height of a text string. |
4794 font = [object font]; | 4797 font = [object font]; |
4795 } | 4798 } |
4796 /* If we got a font... add it to the dictionary */ | 4799 /* If we got a font... add it to the dictionary */ |
4797 if(font) | 4800 if(font) |
4798 { | 4801 { |
4799 [dict setValue:font forKey:UIFontAttributeName]; | 4802 [dict setValue:font forKey:NSFontAttributeName]; |
4800 } | 4803 } |
4801 /* Calculate the size of the string */ | 4804 /* Calculate the size of the string */ |
4802 CGSize size = [nstr sizeWithAttributes:dict]; | 4805 CGSize size = [nstr sizeWithAttributes:dict]; |
4803 [dict release]; | 4806 [dict release]; |
4804 /* Return whatever information we can */ | 4807 /* Return whatever information we can */ |
4809 if(height) | 4812 if(height) |
4810 { | 4813 { |
4811 *height = size.height; | 4814 *height = size.height; |
4812 } | 4815 } |
4813 DW_LOCAL_POOL_OUT; | 4816 DW_LOCAL_POOL_OUT; |
4814 } | |
4815 | |
4816 /* Internal function to create an image graphics context... | |
4817 * with or without antialiasing enabled. | |
4818 */ | |
4819 id _create_gc(id image, bool antialiased) | |
4820 { | |
4821 CGContextRef context = (CGContextRef)[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext]; | |
4822 NSGraphicsContext *gc = [NSGraphicsContext graphicsContextWithCGContext:context flipped:YES]; | |
4823 [gc setShouldAntialias:antialiased]; | |
4824 CGContextSetAllowsAntialiasing(context, antialiased); | |
4825 return gc; | |
4826 } | 4817 } |
4827 | 4818 |
4828 /* Draw a polygon on a window (preferably a render window). | 4819 /* Draw a polygon on a window (preferably a render window). |
4829 * Parameters: | 4820 * Parameters: |
4830 * handle: Handle to the window. | 4821 * handle: Handle to the window. |
4858 bi = [render cachedDrawingRep]; | 4849 bi = [render cachedDrawingRep]; |
4859 } | 4850 } |
4860 } | 4851 } |
4861 if(bi) | 4852 if(bi) |
4862 { | 4853 { |
4863 id gc = _create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES); | 4854 _dw_draw_context(bi, flags & DW_DRAW_NOAA ? NO : YES); |
4864 [NSGraphicsContext saveGraphicsState]; | |
4865 [NSGraphicsContext setCurrentContext:gc]; | |
4866 } | 4855 } |
4867 | 4856 |
4868 if(bCanDraw == YES) | 4857 if(bCanDraw == YES) |
4869 { | 4858 { |
4870 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 4859 UIBezierPath* aPath = [UIBezierPath bezierPath]; |
4871 UIColor *color = pthread_getspecific(_dw_fg_color_key); | 4860 UIColor *color = pthread_getspecific(_dw_fg_color_key); |
4872 [color set]; | 4861 [color set]; |
4873 | 4862 |
4874 [aPath moveToPoint:NSMakePoint(*x + 0.5, *y + 0.5)]; | 4863 [aPath moveToPoint:CGPointMake(*x + 0.5, *y + 0.5)]; |
4875 for(z=1;z<npoints;z++) | 4864 for(z=1;z<npoints;z++) |
4876 { | 4865 { |
4877 [aPath lineToPoint:NSMakePoint(x[z] + 0.5, y[z] + 0.5)]; | 4866 [aPath addLineToPoint:CGPointMake(x[z] + 0.5, y[z] + 0.5)]; |
4878 } | 4867 } |
4879 [aPath closePath]; | 4868 [aPath closePath]; |
4880 if(flags & DW_DRAW_FILL) | 4869 if(flags & DW_DRAW_FILL) |
4881 { | |
4882 [aPath fill]; | 4870 [aPath fill]; |
4883 } | 4871 else |
4884 [aPath stroke]; | 4872 [aPath stroke]; |
4885 } | 4873 } |
4886 | 4874 |
4887 if(bi) | 4875 if(bi) |
4888 [NSGraphicsContext restoreGraphicsState]; | 4876 UIGraphicsEndImageContext(); |
4889 DW_LOCAL_POOL_OUT; | 4877 DW_LOCAL_POOL_OUT; |
4890 DW_FUNCTION_RETURN_NOTHING; | 4878 DW_FUNCTION_RETURN_NOTHING; |
4891 } | 4879 } |
4892 | 4880 |
4893 /* Draw a rectangle on a window (preferably a render window). | 4881 /* Draw a rectangle on a window (preferably a render window). |
4922 bi = [render cachedDrawingRep]; | 4910 bi = [render cachedDrawingRep]; |
4923 } | 4911 } |
4924 } | 4912 } |
4925 if(bi) | 4913 if(bi) |
4926 { | 4914 { |
4927 id gc = _create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES); | 4915 _dw_draw_context(bi, flags & DW_DRAW_NOAA ? NO : YES); |
4928 [NSGraphicsContext saveGraphicsState]; | |
4929 [NSGraphicsContext setCurrentContext:gc]; | |
4930 } | 4916 } |
4931 | 4917 |
4932 if(bCanDraw == YES) | 4918 if(bCanDraw == YES) |
4933 { | 4919 { |
4934 UIColor *color = pthread_getspecific(_dw_fg_color_key); | 4920 UIColor *color = pthread_getspecific(_dw_fg_color_key); |
4921 UIBezierPath *bp = [UIBezierPath bezierPathWithRect:CGRectMake(x, y, width, height)];; | |
4922 | |
4935 [color set]; | 4923 [color set]; |
4936 | 4924 |
4937 if(flags & DW_DRAW_FILL) | 4925 if(flags & DW_DRAW_FILL) |
4938 [NSBezierPath fillRect:NSMakeRect(x, y, width, height)]; | 4926 [bp fill]; |
4939 else | 4927 else |
4940 [NSBezierPath strokeRect:NSMakeRect(x, y, width, height)]; | 4928 [bp stroke]; |
4941 } | 4929 } |
4942 | 4930 |
4943 if(bi) | 4931 if(bi) |
4944 [NSGraphicsContext restoreGraphicsState]; | 4932 UIGraphicsEndImageContext(); |
4945 DW_LOCAL_POOL_OUT; | 4933 DW_LOCAL_POOL_OUT; |
4946 DW_FUNCTION_RETURN_NOTHING; | 4934 DW_FUNCTION_RETURN_NOTHING; |
4947 } | 4935 } |
4948 | 4936 |
4949 /* Draw an arc on a window (preferably a render window). | 4937 /* Draw an arc on a window (preferably a render window). |
4981 bi = [render cachedDrawingRep]; | 4969 bi = [render cachedDrawingRep]; |
4982 } | 4970 } |
4983 } | 4971 } |
4984 if(bi) | 4972 if(bi) |
4985 { | 4973 { |
4986 id gc = _create_gc(bi, flags & DW_DRAW_NOAA ? NO : YES); | 4974 _dw_draw_context(bi, flags & DW_DRAW_NOAA ? NO : YES); |
4987 [NSGraphicsContext saveGraphicsState]; | |
4988 [NSGraphicsContext setCurrentContext:gc]; | |
4989 } | 4975 } |
4990 | 4976 |
4991 if(bCanDraw) | 4977 if(bCanDraw) |
4992 { | 4978 { |
4993 NSBezierPath* aPath = [NSBezierPath bezierPath]; | 4979 UIBezierPath* aPath; |
4994 UIColor *color = pthread_getspecific(_dw_fg_color_key); | 4980 UIColor *color = pthread_getspecific(_dw_fg_color_key); |
4995 [color set]; | 4981 [color set]; |
4996 | 4982 |
4997 /* Special case of a full circle/oval */ | 4983 /* Special case of a full circle/oval */ |
4998 if(flags & DW_DRAW_FULL) | 4984 if(flags & DW_DRAW_FULL) |
4999 { | 4985 aPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(x1, y1, x2 - x1, y2 - y1)]; |
5000 [aPath appendBezierPathWithOvalInRect:NSMakeRect(x1, y1, x2 - x1, y2 - y1)]; | |
5001 } | |
5002 else | 4986 else |
5003 { | 4987 { |
5004 double a1 = atan2((y1-yorigin), (x1-xorigin)); | 4988 double a1 = atan2((y1-yorigin), (x1-xorigin)); |
5005 double a2 = atan2((y2-yorigin), (x2-xorigin)); | 4989 double a2 = atan2((y2-yorigin), (x2-xorigin)); |
5006 double dx = xorigin - x1; | 4990 double dx = xorigin - x1; |
5010 /* Convert to degrees */ | 4994 /* Convert to degrees */ |
5011 a1 *= (180.0 / M_PI); | 4995 a1 *= (180.0 / M_PI); |
5012 a2 *= (180.0 / M_PI); | 4996 a2 *= (180.0 / M_PI); |
5013 | 4997 |
5014 /* Prepare to draw */ | 4998 /* Prepare to draw */ |
5015 [aPath appendBezierPathWithArcWithCenter:NSMakePoint(xorigin, yorigin) | 4999 aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(xorigin, yorigin) |
5016 radius:r startAngle:a1 endAngle:a2]; | 5000 radius:r startAngle:a1 endAngle:a2 clockwise:NO]; |
5017 } | 5001 } |
5018 /* If the fill flag is passed */ | 5002 /* If the fill flag is passed */ |
5019 if(flags & DW_DRAW_FILL) | 5003 if(flags & DW_DRAW_FILL) |
5020 { | |
5021 [aPath fill]; | 5004 [aPath fill]; |
5022 } | 5005 else |
5023 /* Actually do the drawing */ | 5006 [aPath stroke]; |
5024 [aPath stroke]; | |
5025 } | 5007 } |
5026 | 5008 |
5027 if(bi) | 5009 if(bi) |
5028 [NSGraphicsContext restoreGraphicsState]; | 5010 UIGraphicsEndImageContext(); |
5029 DW_LOCAL_POOL_OUT; | 5011 DW_LOCAL_POOL_OUT; |
5030 DW_FUNCTION_RETURN_NOTHING; | 5012 DW_FUNCTION_RETURN_NOTHING; |
5031 } | 5013 } |
5032 | 5014 |
5033 /* | 5015 /* |
5213 DW_FUNCTION_RETURN(dw_container_new, HWND) | 5195 DW_FUNCTION_RETURN(dw_container_new, HWND) |
5214 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, multi, int) | 5196 DW_FUNCTION_RESTORE_PARAM2(cid, ULONG, multi, int) |
5215 { | 5197 { |
5216 DW_FUNCTION_INIT; | 5198 DW_FUNCTION_INIT; |
5217 DWContainer *cont = _dw_cont_new(cid, multi); | 5199 DWContainer *cont = _dw_cont_new(cid, multi); |
5218 UIScrollView *scrollview = [cont scrollview]; | 5200 /* TODO: Switch to new action system |
5219 [scrollview setHasHorizontalScroller:YES]; | 5201 [cont setDoubleAction:@selector(doubleClicked:)];*/ |
5220 NSTableHeaderView *header = [[[NSTableHeaderView alloc] init] autorelease]; | |
5221 [cont setHeaderView:header]; | |
5222 [cont setTarget:cont]; | |
5223 [cont setDoubleAction:@selector(doubleClicked:)]; | |
5224 DW_FUNCTION_RETURN_THIS(cont); | 5202 DW_FUNCTION_RETURN_THIS(cont); |
5225 } | 5203 } |
5226 | 5204 |
5227 /* | 5205 /* |
5228 * Sets up the container columns. | 5206 * Sets up the container columns. |
5245 | 5223 |
5246 [cont setup]; | 5224 [cont setup]; |
5247 | 5225 |
5248 for(z=0;z<count;z++) | 5226 for(z=0;z<count;z++) |
5249 { | 5227 { |
5228 #if 0 /* TODO: Convert this to simulate columns */ | |
5250 NSString *title = [NSString stringWithUTF8String:titles[z]]; | 5229 NSString *title = [NSString stringWithUTF8String:titles[z]]; |
5251 NSTableColumn *column = [[NSTableColumn alloc] initWithIdentifier:title]; | |
5252 [column setTitle:title]; | |
5253 /* Defaults to left justified so just handle right and center */ | 5230 /* Defaults to left justified so just handle right and center */ |
5254 if(flags[z] & DW_CFA_RIGHT) | 5231 #endif |
5255 [(NSCell *)[column headerCell] setAlignment:DWTextAlignmentRight]; | |
5256 else if(flags[z] & DW_CFA_CENTER) | |
5257 [(NSCell *)[column headerCell] setAlignment:DWTextAlignmentCenter]; | |
5258 [column setEditable:NO]; | |
5259 [cont addTableColumn:column]; | |
5260 [cont addColumn:column andType:(int)flags[z]]; | |
5261 [column release]; | |
5262 } | 5232 } |
5263 DW_FUNCTION_RETURN_THIS(retval); | 5233 DW_FUNCTION_RETURN_THIS(retval); |
5264 } | 5234 } |
5265 | 5235 |
5266 /* | 5236 /* |
5403 } | 5373 } |
5404 | 5374 |
5405 id object = [cont getRow:(row+lastadd) and:column]; | 5375 id object = [cont getRow:(row+lastadd) and:column]; |
5406 | 5376 |
5407 /* If it is a cell, change the content of the cell */ | 5377 /* If it is a cell, change the content of the cell */ |
5408 if([object isMemberOfClass:[NSTableCellView class]]) | 5378 if([object isMemberOfClass:[UITableViewCell class]]) |
5409 { | 5379 { |
5410 NSTableCellView *cell = object; | 5380 UITableViewCell *cell = object; |
5381 | |
5411 if(icon) | 5382 if(icon) |
5412 [[cell imageView] setImage:icon]; | 5383 { |
5384 if(@available(iOS 14.0, *)) | |
5385 { | |
5386 UIListContentConfiguration *content = [cell defaultContentConfiguration]; | |
5387 | |
5388 [content setImage:icon]; | |
5389 } | |
5390 else | |
5391 { | |
5392 [cell setImage:icon]; | |
5393 } | |
5394 } | |
5413 else | 5395 else |
5414 [[cell textField] setStringValue:text]; | 5396 { |
5397 if(@available(iOS 14.0, *)) | |
5398 { | |
5399 UIListContentConfiguration *content = [cell defaultContentConfiguration]; | |
5400 | |
5401 [content setText:text]; | |
5402 } | |
5403 else | |
5404 { | |
5405 [cell setText:text]; | |
5406 } | |
5407 } | |
5415 } | 5408 } |
5416 else /* Otherwise replace it with a new cell */ | 5409 else /* Otherwise replace it with a new cell */ |
5417 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:column]; | 5410 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:column]; |
5418 [cont setNeedsDisplay]; | 5411 [cont setNeedsDisplay]; |
5419 DW_FUNCTION_RETURN_NOTHING; | 5412 DW_FUNCTION_RETURN_NOTHING; |
5483 lastadd = [cont lastAddPoint]; | 5476 lastadd = [cont lastAddPoint]; |
5484 | 5477 |
5485 id object = [cont getRow:(row+lastadd) and:0]; | 5478 id object = [cont getRow:(row+lastadd) and:0]; |
5486 | 5479 |
5487 /* If it is a cell, change the content of the cell */ | 5480 /* If it is a cell, change the content of the cell */ |
5488 if([object isMemberOfClass:[NSTableCellView class]]) | 5481 if([object isMemberOfClass:[UITableViewCell class]]) |
5489 { | 5482 { |
5490 NSTableCellView *cell = object; | 5483 UITableViewCell *cell = object; |
5491 | 5484 |
5492 if(icon) | 5485 if(icon) |
5493 [[cell imageView] setImage:icon]; | 5486 { |
5487 if(@available(iOS 14.0, *)) | |
5488 { | |
5489 UIListContentConfiguration *content = [cell defaultContentConfiguration]; | |
5490 | |
5491 [content setImage:icon]; | |
5492 } | |
5493 else | |
5494 { | |
5495 [cell setImage:icon]; | |
5496 } | |
5497 } | |
5494 if(text) | 5498 if(text) |
5495 [[cell textField] setStringValue:text]; | 5499 { |
5500 if(@available(iOS 14.0, *)) | |
5501 { | |
5502 UIListContentConfiguration *content = [cell defaultContentConfiguration]; | |
5503 | |
5504 [content setText:text]; | |
5505 } | |
5506 else | |
5507 { | |
5508 [cell setText:text]; | |
5509 } | |
5510 } | |
5496 } | 5511 } |
5497 else /* Otherwise replace it with a new cell */ | 5512 else /* Otherwise replace it with a new cell */ |
5498 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:0]; | 5513 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:0]; |
5499 [cont setNeedsDisplay]; | 5514 [cont setNeedsDisplay]; |
5500 DW_FUNCTION_RETURN_NOTHING; | 5515 DW_FUNCTION_RETURN_NOTHING; |
5581 * Parameters: | 5596 * Parameters: |
5582 * handle: Handle to window (widget) of container. | 5597 * handle: Handle to window (widget) of container. |
5583 * column: Zero based column of width being set. | 5598 * column: Zero based column of width being set. |
5584 * width: Width of column in pixels. | 5599 * width: Width of column in pixels. |
5585 */ | 5600 */ |
5586 DW_FUNCTION_DEFINITION(dw_container_set_column_width, void, HWND handle, int column, int width) | 5601 void API dw_container_set_column_width(HWND handle, int column, int width) |
5587 DW_FUNCTION_ADD_PARAM3(handle, column, width) | 5602 { |
5588 DW_FUNCTION_NO_RETURN(dw_container_set_column_width) | |
5589 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, column, int, width, int) | |
5590 { | |
5591 DW_FUNCTION_INIT; | |
5592 DWContainer *cont = handle; | |
5593 if([cont filesystem]) | |
5594 column++; | |
5595 NSTableColumn *col = [cont getColumn:column]; | |
5596 | |
5597 [col setWidth:width]; | |
5598 DW_FUNCTION_RETURN_NOTHING; | |
5599 } | 5603 } |
5600 | 5604 |
5601 /* | 5605 /* |
5602 * Sets the title of a row in the container. | 5606 * Sets the title of a row in the container. |
5603 * Parameters: | 5607 * Parameters: |
5748 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, direction, int, rows, long) | 5752 DW_FUNCTION_RESTORE_PARAM3(handle, HWND, direction, int, rows, long) |
5749 { | 5753 { |
5750 DW_FUNCTION_INIT; | 5754 DW_FUNCTION_INIT; |
5751 DWContainer *cont = handle; | 5755 DWContainer *cont = handle; |
5752 UIScrollView *sv = [cont scrollview]; | 5756 UIScrollView *sv = [cont scrollview]; |
5753 NSScroller *scrollbar = [sv verticalScroller]; | |
5754 int rowcount = (int)[cont numberOfRowsInTableView:cont]; | 5757 int rowcount = (int)[cont numberOfRowsInTableView:cont]; |
5755 float currpos = [scrollbar floatValue]; | 5758 CGPoint offset = [sv contentOffset]; |
5756 float change; | 5759 float change; |
5757 | 5760 |
5758 /* Safety check */ | 5761 /* Safety check */ |
5759 if(rowcount < 1) | 5762 if(rowcount < 1) |
5760 { | 5763 { |
5765 | 5768 |
5766 switch(direction) | 5769 switch(direction) |
5767 { | 5770 { |
5768 case DW_SCROLL_TOP: | 5771 case DW_SCROLL_TOP: |
5769 { | 5772 { |
5770 [scrollbar setFloatValue:0]; | 5773 offset.y = 0; |
5771 break; | 5774 break; |
5772 } | 5775 } |
5773 case DW_SCROLL_BOTTOM: | 5776 case DW_SCROLL_BOTTOM: |
5774 { | 5777 { |
5775 [scrollbar setFloatValue:1]; | 5778 offset.y = [sv contentSize].height - [sv visibleSize].height; |
5776 break; | 5779 break; |
5777 } | 5780 } |
5778 case DW_SCROLL_UP: | 5781 case DW_SCROLL_UP: |
5779 { | 5782 { |
5780 float newpos = currpos - change; | 5783 offset.y = offset.y - [sv visibleSize].height; |
5781 if(newpos < 0) | |
5782 { | |
5783 newpos = 0; | |
5784 } | |
5785 [scrollbar setFloatValue:newpos]; | |
5786 break; | 5784 break; |
5787 } | 5785 } |
5788 case DW_SCROLL_DOWN: | 5786 case DW_SCROLL_DOWN: |
5789 { | 5787 { |
5790 float newpos = currpos + change; | 5788 offset.y = offset.y + [sv visibleSize].height; |
5791 if(newpos > 1) | |
5792 { | |
5793 newpos = 1; | |
5794 } | |
5795 [scrollbar setFloatValue:newpos]; | |
5796 break; | 5789 break; |
5797 } | 5790 } |
5798 } | 5791 } |
5792 if(offset.y < 0) | |
5793 offset.y = 0; | |
5794 [sv setContentOffset:offset]; | |
5799 DW_FUNCTION_RETURN_NOTHING; | 5795 DW_FUNCTION_RETURN_NOTHING; |
5800 } | 5796 } |
5801 | 5797 |
5802 /* | 5798 /* |
5803 * Starts a new query of a container. | 5799 * Starts a new query of a container. |
6259 { | 6255 { |
6260 char *name = strchr(fontname, '.'); | 6256 char *name = strchr(fontname, '.'); |
6261 | 6257 |
6262 if(name && (name++)) | 6258 if(name && (name++)) |
6263 { | 6259 { |
6260 UIFontDescriptorSymbolicTraits traits = 0; | |
6261 UIFontDescriptor* fd; | |
6264 int size = atoi(fontname); | 6262 int size = atoi(fontname); |
6265 char *Italic = strstr(name, " Italic"); | 6263 char *Italic = strstr(name, " Italic"); |
6266 char *Bold = strstr(name, " Bold"); | 6264 char *Bold = strstr(name, " Bold"); |
6267 size_t len = (Italic ? (Bold ? (Italic > Bold ? (Bold - name) : (Italic - name)) : (Italic - name)) : (Bold ? (Bold - name) : strlen(name))); | 6265 size_t len = (Italic ? (Bold ? (Italic > Bold ? (Bold - name) : (Italic - name)) : (Italic - name)) : (Bold ? (Bold - name) : strlen(name))); |
6268 char *newname = alloca(len+1); | 6266 char *newname = alloca(len+1); |
6269 | 6267 |
6270 memset(newname, 0, len+1); | 6268 memset(newname, 0, len+1); |
6271 strncpy(newname, name, len); | 6269 strncpy(newname, name, len); |
6272 | 6270 |
6273 font = [DWFontManager fontWithFamily:[NSString stringWithUTF8String:newname] | 6271 if(Bold) |
6274 traits:(Italic ? NSItalicFontMask : 0)|(Bold ? NSBoldFontMask : 0) | 6272 traits |= UIFontDescriptorTraitBold; |
6275 weight:5 | 6273 if(Italic) |
6276 size:(float)size]; | 6274 traits |= UIFontDescriptorTraitItalic; |
6275 | |
6276 fd = [UIFontDescriptor | |
6277 fontDescriptorWithFontAttributes:@{UIFontDescriptorFamilyAttribute:[NSString stringWithUTF8String:newname], | |
6278 UIFontDescriptorTraitsAttribute: @{UIFontSymbolicTrait:[NSNumber numberWithInteger:traits]}}]; | |
6279 NSArray* matches = [fd matchingFontDescriptorsWithMandatoryKeys: | |
6280 [NSSet setWithObjects:UIFontDescriptorFamilyAttribute, UIFontDescriptorTraitsAttribute, nil]]; | |
6281 if(matches.count != 0) | |
6282 font = [UIFont fontWithDescriptor:matches[0] size:size]; | |
6277 } | 6283 } |
6278 } | 6284 } |
6279 return font; | 6285 return font; |
6280 } | 6286 } |
6281 | 6287 |
6289 DW_FUNCTION_RETURN(dw_bitmap_new, HWND) | 6295 DW_FUNCTION_RETURN(dw_bitmap_new, HWND) |
6290 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) | 6296 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) |
6291 { | 6297 { |
6292 DW_FUNCTION_INIT; | 6298 DW_FUNCTION_INIT; |
6293 UIImageView *bitmap = [[UIImageView alloc] init]; | 6299 UIImageView *bitmap = [[UIImageView alloc] init]; |
6294 [bitmap setImageFrameStyle:UIImageFrameNone]; | |
6295 [bitmap setImageScaling:UIImageScaleNone]; | |
6296 [bitmap setEditable:NO]; | |
6297 [bitmap setTag:cid]; | 6300 [bitmap setTag:cid]; |
6298 DW_FUNCTION_RETURN_THIS(bitmap); | 6301 DW_FUNCTION_RETURN_THIS(bitmap); |
6299 } | 6302 } |
6300 | 6303 |
6301 /* | 6304 /* |
6308 * Returns: | 6311 * Returns: |
6309 * A handle to a pixmap or NULL on failure. | 6312 * A handle to a pixmap or NULL on failure. |
6310 */ | 6313 */ |
6311 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) | 6314 HPIXMAP API dw_pixmap_new(HWND handle, unsigned long width, unsigned long height, int depth) |
6312 { | 6315 { |
6313 HPIXMAP pixmap; | 6316 HPIXMAP pixmap = NULL; |
6314 | 6317 |
6315 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6318 if((pixmap = calloc(1,sizeof(struct _hpixmap)))) |
6316 return NULL; | 6319 { |
6317 pixmap->width = width; | 6320 CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB(); |
6318 pixmap->height = height; | 6321 CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, calloc(width*height, 4), width*height*32, NULL); |
6319 pixmap->handle = handle; | 6322 CGImageRef image = CGImageCreate(width, height, 8, 32, 32 * width, |
6320 pixmap->image = [[UIImage alloc] | 6323 rgb, kCGBitmapByteOrderDefault | kCGImageAlphaLast, |
6321 initWithBitmapDataPlanes:NULL | 6324 provider, NULL, false, kCGRenderingIntentDefault); |
6322 pixelsWide:width | 6325 pixmap->width = width; |
6323 pixelsHigh:height | 6326 pixmap->height = height; |
6324 bitsPerSample:8 | 6327 pixmap->handle = handle; |
6325 samplesPerPixel:4 | 6328 pixmap->image = [[[UIImage alloc] initWithCGImage:image] retain]; |
6326 hasAlpha:YES | 6329 } |
6327 isPlanar:NO | |
6328 colorSpaceName:NSDeviceRGBColorSpace | |
6329 bytesPerRow:0 | |
6330 bitsPerPixel:0]; | |
6331 return pixmap; | 6330 return pixmap; |
6332 } | 6331 } |
6333 | 6332 |
6334 /* | 6333 /* |
6335 * Creates a pixmap from a file. | 6334 * Creates a pixmap from a file. |
6363 { | 6362 { |
6364 DW_LOCAL_POOL_OUT; | 6363 DW_LOCAL_POOL_OUT; |
6365 return NULL; | 6364 return NULL; |
6366 } | 6365 } |
6367 pixmap->width = [tmpimage size].width; | 6366 pixmap->width = [tmpimage size].width; |
6368 pixmap->height = [tmpimage size]size.height; | 6367 pixmap->height = [tmpimage size].height; |
6369 pixmap->image = tmpimage; | 6368 pixmap->image = tmpimage; |
6370 pixmap->handle = handle; | 6369 pixmap->handle = handle; |
6371 DW_LOCAL_POOL_OUT; | 6370 DW_LOCAL_POOL_OUT; |
6372 return pixmap; | 6371 return pixmap; |
6373 } | 6372 } |
6443 NSBundle *bundle = [NSBundle mainBundle]; | 6442 NSBundle *bundle = [NSBundle mainBundle]; |
6444 NSString *respath = [bundle resourcePath]; | 6443 NSString *respath = [bundle resourcePath]; |
6445 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid]; | 6444 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid]; |
6446 UIImage *tmpimage = [[UIImage alloc] initWithContentsOfFile:filepath]; | 6445 UIImage *tmpimage = [[UIImage alloc] initWithContentsOfFile:filepath]; |
6447 | 6446 |
6448 if(temp) | 6447 if(tmpimage) |
6449 { | 6448 { |
6450 pixmap->width = [tmpimage size].width; | 6449 pixmap->width = [tmpimage size].width; |
6451 pixmap->height = [tmpimage size].height; | 6450 pixmap->height = [tmpimage size].height; |
6452 pixmap->image = tmpimage; | 6451 pixmap->image = tmpimage; |
6453 pixmap->handle = handle; | 6452 pixmap->handle = handle; |