comparison mac/dw.m @ 1946:42f1e323849c

Mac: Massive rewrite to the drawing code in an attempt to get NSView rendering to work using the 10.14 AppKit... doesn't quite work yet.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 06 Jul 2019 15:57:53 +0000
parents 7af41bfd5190
children 3aef9be654ce
comparison
equal deleted inserted replaced
1945:7af41bfd5190 1946:42f1e323849c
660 -(void)setCheck:(int)input; 660 -(void)setCheck:(int)input;
661 -(int)check; 661 -(int)check;
662 -(void)dealloc; 662 -(void)dealloc;
663 @end 663 @end
664 664
665 @implementation DWObject
666 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ }
667 -(void)synchronizeThread:(id)param
668 {
669 pthread_mutex_unlock(DWRunMutex);
670 pthread_mutex_lock(DWThreadMutex2);
671 pthread_mutex_unlock(DWThreadMutex2);
672 pthread_mutex_lock(DWRunMutex);
673 }
674 -(void)menuHandler:(id)param
675 {
676 DWMenuItem *item = param;
677 if([item check])
678 {
679 if([item state] == DWControlStateValueOn)
680 [item setState:DWControlStateValueOff];
681 else
682 [item setState:DWControlStateValueOn];
683 }
684 _event_handler(param, nil, 8);
685 }
686 -(void)doBitBlt:(id)param
687 {
688 NSValue *bi = (NSValue *)param;
689 DWBitBlt *bltinfo = (DWBitBlt *)[bi pointerValue];
690 id bltdest = bltinfo->dest;
691 id bltsrc = bltinfo->src;
692
693 if([bltdest isMemberOfClass:[NSBitmapImageRep class]])
694 {
695 [NSGraphicsContext saveGraphicsState];
696 [NSGraphicsContext setCurrentContext:_dw_draw_context(bltdest)];
697 [[[NSDictionary alloc] initWithObjectsAndKeys:bltdest, NSGraphicsContextDestinationAttributeName, nil] autorelease];
698 }
699 else
700 {
701 if([bltdest lockFocusIfCanDraw] == NO)
702 {
703 free(bltinfo);
704 return;
705 }
706 _DWLastDrawable = bltinfo->dest;
707 }
708 if([bltsrc isMemberOfClass:[NSBitmapImageRep class]])
709 {
710 NSBitmapImageRep *rep = bltsrc;
711 NSImage *image = [NSImage alloc];
712 SEL siwc = NSSelectorFromString(@"initWithCGImage");
713 NSCompositingOperation op = DWCompositingOperationSourceOver;
714
715 if([image respondsToSelector:siwc])
716 {
717 IMP iiwc = [image methodForSelector:siwc];
718 image = iiwc(image, siwc, [rep CGImage], NSZeroSize);
719 }
720 else
721 {
722 image = [image initWithSize:[rep size]];
723 [image addRepresentation:rep];
724 }
725 if(bltinfo->srcwidth != -1)
726 {
727 [image drawInRect:NSMakeRect(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height)
728 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->srcwidth, bltinfo->srcheight)
729 operation:op fraction:1.0];
730 }
731 else
732 {
733 [image drawAtPoint:NSMakePoint(bltinfo->xdest, bltinfo->ydest)
734 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height)
735 operation:op fraction:1.0];
736 }
737 [bltsrc release];
738 [image release];
739 }
740 if([bltdest isMemberOfClass:[NSBitmapImageRep class]])
741 {
742 [NSGraphicsContext restoreGraphicsState];
743 }
744 else
745 {
746 [bltdest unlockFocus];
747 }
748 free(bltinfo);
749 }
750 -(void)doFlush:(id)param
751 {
752 #ifndef BUILDING_FOR_MOJAVE
753 if(_DWLastDrawable)
754 {
755 id object = _DWLastDrawable;
756 NSWindow *window = [object window];
757 [window flushWindow];
758 }
759 #endif
760 }
761 -(void)doWindowFunc:(id)param
762 {
763 NSValue *v = (NSValue *)param;
764 void **params = (void **)[v pointerValue];
765 void (* windowfunc)(void *);
766
767 if(params)
768 {
769 windowfunc = params[0];
770 if(windowfunc)
771 {
772 windowfunc(params[1]);
773 }
774 }
775 }
776 @end
777
778 DWObject *DWObj;
779
780 /* So basically to implement our event handlers... 665 /* So basically to implement our event handlers...
781 * it looks like we are going to have to subclass 666 * it looks like we are going to have to subclass
782 * basically everything. Was hoping to add methods 667 * basically everything. Was hoping to add methods
783 * to the superclasses but it looks like you can 668 * to the superclasses but it looks like you can
784 * only add methods and no variables, which isn't 669 * only add methods and no variables, which isn't
946 @interface DWRender : NSControl 831 @interface DWRender : NSControl
947 { 832 {
948 void *userdata; 833 void *userdata;
949 NSFont *font; 834 NSFont *font;
950 NSSize size; 835 NSSize size;
836 #ifdef BUILDING_FOR_MOJAVE
837 NSBitmapImageRep *cachedDrawingRep;
838 #endif
951 } 839 }
952 -(void *)userdata; 840 -(void *)userdata;
953 -(void)setUserdata:(void *)input; 841 -(void)setUserdata:(void *)input;
954 -(void)setFont:(NSFont *)input; 842 -(void)setFont:(NSFont *)input;
955 -(NSFont *)font; 843 -(NSFont *)font;
956 -(void)setSize:(NSSize)input; 844 -(void)setSize:(NSSize)input;
957 -(NSSize)size; 845 -(NSSize)size;
846 #ifdef BUILDING_FOR_MOJAVE
847 -(NSBitmapImageRep *)cachedDrawingRep;
848 #endif
958 -(void)mouseDown:(NSEvent *)theEvent; 849 -(void)mouseDown:(NSEvent *)theEvent;
959 -(void)mouseUp:(NSEvent *)theEvent; 850 -(void)mouseUp:(NSEvent *)theEvent;
960 -(NSMenu *)menuForEvent:(NSEvent *)theEvent; 851 -(NSMenu *)menuForEvent:(NSEvent *)theEvent;
961 -(void)rightMouseUp:(NSEvent *)theEvent; 852 -(void)rightMouseUp:(NSEvent *)theEvent;
962 -(void)otherMouseDown:(NSEvent *)theEvent; 853 -(void)otherMouseDown:(NSEvent *)theEvent;
971 -(void)setUserdata:(void *)input { userdata = input; } 862 -(void)setUserdata:(void *)input { userdata = input; }
972 -(void)setFont:(NSFont *)input { [font release]; font = input; [font retain]; } 863 -(void)setFont:(NSFont *)input { [font release]; font = input; [font retain]; }
973 -(NSFont *)font { return font; } 864 -(NSFont *)font { return font; }
974 -(void)setSize:(NSSize)input { size = input; } 865 -(void)setSize:(NSSize)input { size = input; }
975 -(NSSize)size { return size; } 866 -(NSSize)size { return size; }
867 #ifdef BUILDING_FOR_MOJAVE
868 -(NSBitmapImageRep *)cachedDrawingRep {
869 if(!cachedDrawingRep)
870 cachedDrawingRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
871 return cachedDrawingRep;
872 }
873 #endif
976 -(void)mouseDown:(NSEvent *)theEvent 874 -(void)mouseDown:(NSEvent *)theEvent
977 { 875 {
978 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & DWEventModifierFlagControl)) 876 if(![theEvent isMemberOfClass:[NSEvent class]] || !([theEvent modifierFlags] & DWEventModifierFlagControl))
979 _event_handler(self, theEvent, 3); 877 _event_handler(self, theEvent, 3);
980 } 878 }
982 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } 880 -(NSMenu *)menuForEvent:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; }
983 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } 881 -(void)rightMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); }
984 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); } 882 -(void)otherMouseDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 3); }
985 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); } 883 -(void)otherMouseUp:(NSEvent *)theEvent { _event_handler(self, theEvent, 4); }
986 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); } 884 -(void)mouseDragged:(NSEvent *)theEvent { _event_handler(self, theEvent, 5); }
987 -(void)drawRect:(NSRect)rect { _event_handler(self, nil, 7); } 885 -(void)drawRect:(NSRect)rect {
886 _event_handler(self, nil, 7);
887 #ifdef BUILDING_FOR_MOJAVE
888 if (cachedDrawingRep)
889 [cachedDrawingRep drawInRect:self.bounds];
890 #endif
891 }
988 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); } 892 -(void)keyDown:(NSEvent *)theEvent { _event_handler(self, theEvent, 2); }
989 -(BOOL)isFlipped { return YES; } 893 -(BOOL)isFlipped { return YES; }
990 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; dw_signal_disconnect_by_window(self); [super dealloc]; } 894 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [font release]; dw_signal_disconnect_by_window(self); [super dealloc]; [cachedDrawingRep release]; }
991 -(BOOL)acceptsFirstResponder { return YES; } 895 -(BOOL)acceptsFirstResponder { return YES; }
992 @end 896 @end
897
898 @implementation DWObject
899 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ }
900 -(void)synchronizeThread:(id)param
901 {
902 pthread_mutex_unlock(DWRunMutex);
903 pthread_mutex_lock(DWThreadMutex2);
904 pthread_mutex_unlock(DWThreadMutex2);
905 pthread_mutex_lock(DWRunMutex);
906 }
907 -(void)menuHandler:(id)param
908 {
909 DWMenuItem *item = param;
910 if([item check])
911 {
912 if([item state] == DWControlStateValueOn)
913 [item setState:DWControlStateValueOff];
914 else
915 [item setState:DWControlStateValueOn];
916 }
917 _event_handler(param, nil, 8);
918 }
919 -(void)doBitBlt:(id)param
920 {
921 NSValue *bi = (NSValue *)param;
922 DWBitBlt *bltinfo = (DWBitBlt *)[bi pointerValue];
923 id bltdest = bltinfo->dest;
924 id bltsrc = bltinfo->src;
925
926 #ifdef BUILDING_FOR_MOJAVE
927 if([bltdest isMemberOfClass:[DWRender class]])
928 {
929 DWRender *render = bltdest;
930
931 bltdest = [render cachedDrawingRep];
932 }
933 #endif
934 if([bltdest isMemberOfClass:[NSBitmapImageRep class]])
935 {
936 [NSGraphicsContext saveGraphicsState];
937 [NSGraphicsContext setCurrentContext:_dw_draw_context(bltdest)];
938 [[[NSDictionary alloc] initWithObjectsAndKeys:bltdest, NSGraphicsContextDestinationAttributeName, nil] autorelease];
939 }
940 #ifndef BUILDING_FOR_MOJAVE
941 else
942 {
943 if([bltdest lockFocusIfCanDraw] == NO)
944 {
945 free(bltinfo);
946 return;
947 }
948 _DWLastDrawable = bltinfo->dest;
949 }
950 #endif
951 if([bltsrc isMemberOfClass:[NSBitmapImageRep class]])
952 {
953 NSBitmapImageRep *rep = bltsrc;
954 NSImage *image = [NSImage alloc];
955 SEL siwc = NSSelectorFromString(@"initWithCGImage");
956 NSCompositingOperation op = DWCompositingOperationSourceOver;
957
958 if([image respondsToSelector:siwc])
959 {
960 IMP iiwc = [image methodForSelector:siwc];
961 image = iiwc(image, siwc, [rep CGImage], NSZeroSize);
962 }
963 else
964 {
965 image = [image initWithSize:[rep size]];
966 [image addRepresentation:rep];
967 }
968 if(bltinfo->srcwidth != -1)
969 {
970 [image drawInRect:NSMakeRect(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height)
971 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->srcwidth, bltinfo->srcheight)
972 operation:op fraction:1.0];
973 }
974 else
975 {
976 [image drawAtPoint:NSMakePoint(bltinfo->xdest, bltinfo->ydest)
977 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height)
978 operation:op fraction:1.0];
979 }
980 [bltsrc release];
981 [image release];
982 }
983 if([bltdest isMemberOfClass:[NSBitmapImageRep class]])
984 {
985 [NSGraphicsContext restoreGraphicsState];
986 }
987 #ifndef BUILDING_FOR_MOJAVE
988 else
989 {
990 [bltdest unlockFocus];
991 }
992 #endif
993 free(bltinfo);
994 }
995 -(void)doFlush:(id)param
996 {
997 #ifndef BUILDING_FOR_MOJAVE
998 if(_DWLastDrawable)
999 {
1000 id object = _DWLastDrawable;
1001 NSWindow *window = [object window];
1002 [window flushWindow];
1003 }
1004 #endif
1005 }
1006 -(void)doWindowFunc:(id)param
1007 {
1008 NSValue *v = (NSValue *)param;
1009 void **params = (void **)[v pointerValue];
1010 void (* windowfunc)(void *);
1011
1012 if(params)
1013 {
1014 windowfunc = params[0];
1015 if(windowfunc)
1016 {
1017 windowfunc(params[1]);
1018 }
1019 }
1020 }
1021 @end
1022
1023 DWObject *DWObj;
993 1024
994 /* Subclass for the application class */ 1025 /* Subclass for the application class */
995 @interface DWAppDel : NSObject 1026 @interface DWAppDel : NSObject
996 #ifdef BUILDING_FOR_SNOW_LEOPARD 1027 #ifdef BUILDING_FOR_SNOW_LEOPARD
997 <NSApplicationDelegate> 1028 <NSApplicationDelegate>
5946 { 5977 {
5947 int _locked_by_me = FALSE; 5978 int _locked_by_me = FALSE;
5948 DW_LOCAL_POOL_IN; 5979 DW_LOCAL_POOL_IN;
5949 DW_MUTEX_LOCK; 5980 DW_MUTEX_LOCK;
5950 id image = handle; 5981 id image = handle;
5982 NSBitmapImageRep *bi = nil;
5983
5951 if(pixmap) 5984 if(pixmap)
5952 { 5985 bi = image = (id)pixmap->image;
5953 image = (id)pixmap->image;
5954 [NSGraphicsContext saveGraphicsState];
5955 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)];
5956 }
5957 else 5986 else
5958 { 5987 {
5988 #ifdef BUILDING_FOR_MOJAVE
5989 if([image isMemberOfClass:[DWRender class]])
5990 {
5991 DWRender *render = image;
5992
5993 bi = [render cachedDrawingRep];
5994 }
5995 #else
5959 if([image lockFocusIfCanDraw] == NO) 5996 if([image lockFocusIfCanDraw] == NO)
5960 { 5997 {
5961 DW_MUTEX_UNLOCK; 5998 DW_MUTEX_UNLOCK;
5962 DW_LOCAL_POOL_OUT; 5999 DW_LOCAL_POOL_OUT;
5963 return; 6000 return;
5964 } 6001 }
5965 _DWLastDrawable = handle; 6002 _DWLastDrawable = handle;
6003 #endif
6004 }
6005 if(bi)
6006 {
6007 [NSGraphicsContext saveGraphicsState];
6008 [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)];
5966 } 6009 }
5967 NSBezierPath* aPath = [NSBezierPath bezierPath]; 6010 NSBezierPath* aPath = [NSBezierPath bezierPath];
5968 [aPath setLineWidth: 0.5]; 6011 [aPath setLineWidth: 0.5];
5969 NSColor *color = pthread_getspecific(_dw_fg_color_key); 6012 NSColor *color = pthread_getspecific(_dw_fg_color_key);
5970 [color set]; 6013 [color set];
5971 6014
5972 [aPath moveToPoint:NSMakePoint(x, y)]; 6015 [aPath moveToPoint:NSMakePoint(x, y)];
5973 [aPath stroke]; 6016 [aPath stroke];
5974 if(pixmap) 6017 if(bi)
5975 {
5976 [NSGraphicsContext restoreGraphicsState]; 6018 [NSGraphicsContext restoreGraphicsState];
5977 } 6019 #ifndef BUILDING_FOR_MOJAVE
5978 else 6020 if(!pixmap)
5979 {
5980 [image unlockFocus]; 6021 [image unlockFocus];
5981 } 6022 #endif
5982 DW_MUTEX_UNLOCK; 6023 DW_MUTEX_UNLOCK;
5983 DW_LOCAL_POOL_OUT; 6024 DW_LOCAL_POOL_OUT;
5984 } 6025 }
5985 6026
5986 /* Draw a line on a window (preferably a render window). 6027 /* Draw a line on a window (preferably a render window).
5996 { 6037 {
5997 int _locked_by_me = FALSE; 6038 int _locked_by_me = FALSE;
5998 DW_LOCAL_POOL_IN; 6039 DW_LOCAL_POOL_IN;
5999 DW_MUTEX_LOCK; 6040 DW_MUTEX_LOCK;
6000 id image = handle; 6041 id image = handle;
6042 NSBitmapImageRep *bi = nil;
6043
6001 if(pixmap) 6044 if(pixmap)
6002 { 6045 bi = image = (id)pixmap->image;
6003 image = (id)pixmap->image;
6004 [NSGraphicsContext saveGraphicsState];
6005 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)];
6006 }
6007 else 6046 else
6008 { 6047 {
6048 #ifdef BUILDING_FOR_MOJAVE
6049 if([image isMemberOfClass:[DWRender class]])
6050 {
6051 DWRender *render = image;
6052
6053 bi = [render cachedDrawingRep];
6054 }
6055 #else
6009 if([image lockFocusIfCanDraw] == NO) 6056 if([image lockFocusIfCanDraw] == NO)
6010 { 6057 {
6011 DW_MUTEX_UNLOCK; 6058 DW_MUTEX_UNLOCK;
6012 DW_LOCAL_POOL_OUT; 6059 DW_LOCAL_POOL_OUT;
6013 return; 6060 return;
6014 } 6061 }
6015 _DWLastDrawable = handle; 6062 _DWLastDrawable = handle;
6063 #endif
6064 }
6065 if(bi)
6066 {
6067 [NSGraphicsContext saveGraphicsState];
6068 [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)];
6016 } 6069 }
6017 NSBezierPath* aPath = [NSBezierPath bezierPath]; 6070 NSBezierPath* aPath = [NSBezierPath bezierPath];
6018 NSColor *color = pthread_getspecific(_dw_fg_color_key); 6071 NSColor *color = pthread_getspecific(_dw_fg_color_key);
6019 [color set]; 6072 [color set];
6020 6073
6021 [aPath moveToPoint:NSMakePoint(x1 + 0.5, y1 + 0.5)]; 6074 [aPath moveToPoint:NSMakePoint(x1 + 0.5, y1 + 0.5)];
6022 [aPath lineToPoint:NSMakePoint(x2 + 0.5, y2 + 0.5)]; 6075 [aPath lineToPoint:NSMakePoint(x2 + 0.5, y2 + 0.5)];
6023 [aPath stroke]; 6076 [aPath stroke];
6024 6077
6025 if(pixmap) 6078 if(bi)
6026 {
6027 [NSGraphicsContext restoreGraphicsState]; 6079 [NSGraphicsContext restoreGraphicsState];
6028 } 6080 #ifndef BUILDING_FOR_MOJAVE
6029 else 6081 if(!pixmap)
6030 {
6031 [image unlockFocus]; 6082 [image unlockFocus];
6032 } 6083 #endif
6033 DW_MUTEX_UNLOCK; 6084 DW_MUTEX_UNLOCK;
6034 DW_LOCAL_POOL_OUT; 6085 DW_LOCAL_POOL_OUT;
6035 } 6086 }
6036 6087
6037 /* Draw text on a window (preferably a render window). 6088 /* Draw text on a window (preferably a render window).
6047 int _locked_by_me = FALSE; 6098 int _locked_by_me = FALSE;
6048 DW_LOCAL_POOL_IN; 6099 DW_LOCAL_POOL_IN;
6049 DW_MUTEX_LOCK; 6100 DW_MUTEX_LOCK;
6050 id image = handle; 6101 id image = handle;
6051 NSString *nstr = [ NSString stringWithUTF8String:text ]; 6102 NSString *nstr = [ NSString stringWithUTF8String:text ];
6052 if(image) 6103 NSBitmapImageRep *bi = nil;
6053 { 6104 NSFont *font = nil;
6054 if([image isMemberOfClass:[DWRender class]]) 6105 DWRender *render;
6055 { 6106 #ifndef BUILDING_FOR_MOJAVE
6056 DWRender *render = handle; 6107 bool canDraw = NO;
6057 NSFont *font = [render font]; 6108 #endif
6058 if([image lockFocusIfCanDraw] == NO) 6109
6059 { 6110 if(pixmap)
6060 DW_MUTEX_UNLOCK; 6111 {
6061 DW_LOCAL_POOL_OUT; 6112 bi = image = (id)pixmap->image;
6062 return; 6113 font = pixmap->font;
6063 } 6114 render = pixmap->handle;
6064 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key); 6115 if(!font && [render isMemberOfClass:[DWRender class]])
6065 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key); 6116 {
6066 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; 6117 font = [render font];
6067 if(bgcolor) 6118 }
6068 { 6119 image = (id)pixmap->image;
6069 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName]; 6120 }
6070 } 6121 else if(image && [image isMemberOfClass:[DWRender class]])
6071 if(font) 6122 {
6072 { 6123 render = image;
6073 [dict setValue:font forKey:NSFontAttributeName]; 6124 font = [render font];
6074 } 6125 #ifdef BUILDING_FOR_MOJAVE
6075 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; 6126 bi = [render cachedDrawingRep];
6076 [image unlockFocus]; 6127 #else
6077 [dict release]; 6128 canDraw = [image lockFocusIfCanDraw];
6129 if(canDraw == NO)
6130 {
6131 DW_MUTEX_UNLOCK;
6132 DW_LOCAL_POOL_OUT;
6133 return;
6078 } 6134 }
6079 _DWLastDrawable = handle; 6135 _DWLastDrawable = handle;
6080 } 6136 #endif
6081 if(pixmap) 6137 }
6082 { 6138 if(bi)
6083 NSFont *font = pixmap->font; 6139 {
6084 DWRender *render = pixmap->handle;
6085 if(!font && [render isMemberOfClass:[DWRender class]])
6086 {
6087 font = [render font];
6088 }
6089 image = (id)pixmap->image;
6090 [NSGraphicsContext saveGraphicsState]; 6140 [NSGraphicsContext saveGraphicsState];
6091 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)]; 6141 [NSGraphicsContext setCurrentContext:_dw_draw_context(bi)];
6092 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key); 6142 }
6093 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key); 6143
6094 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil]; 6144 NSColor *fgcolor = pthread_getspecific(_dw_fg_color_key);
6095 if(bgcolor) 6145 NSColor *bgcolor = pthread_getspecific(_dw_bg_color_key);
6096 { 6146 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:fgcolor, NSForegroundColorAttributeName, nil];
6097 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName]; 6147 if(bgcolor)
6098 } 6148 [dict setValue:bgcolor forKey:NSBackgroundColorAttributeName];
6099 if(font) 6149 if(font)
6100 { 6150 [dict setValue:font forKey:NSFontAttributeName];
6101 [dict setValue:font forKey:NSFontAttributeName]; 6151 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict];
6102 } 6152 [dict release];
6103 [nstr drawAtPoint:NSMakePoint(x, y) withAttributes:dict]; 6153
6154 if(bi)
6104 [NSGraphicsContext restoreGraphicsState]; 6155 [NSGraphicsContext restoreGraphicsState];
6105 [dict release]; 6156 #ifndef BUILDING_FOR_MOJAVE
6106 } 6157 if(canDraw == YES)
6158 [image unlockFocus];
6159 #endif
6107 DW_MUTEX_UNLOCK; 6160 DW_MUTEX_UNLOCK;
6108 DW_LOCAL_POOL_OUT; 6161 DW_LOCAL_POOL_OUT;
6109 } 6162 }
6110 6163
6111 /* Query the width and height of a text string. 6164 /* Query the width and height of a text string.
6188 { 6241 {
6189 int _locked_by_me = FALSE; 6242 int _locked_by_me = FALSE;
6190 DW_LOCAL_POOL_IN; 6243 DW_LOCAL_POOL_IN;
6191 DW_MUTEX_LOCK; 6244 DW_MUTEX_LOCK;
6192 id image = handle; 6245 id image = handle;
6246 NSBitmapImageRep *bi = nil;
6193 int z; 6247 int z;
6248
6194 if(pixmap) 6249 if(pixmap)
6195 { 6250 bi = image = (id)pixmap->image;
6196 image = (id)pixmap->image; 6251 else
6252 {
6253 #ifdef BUILDING_FOR_MOJAVE
6254 if([image isMemberOfClass:[DWRender class]])
6255 {
6256 DWRender *render = image;
6257
6258 bi = [render cachedDrawingRep];
6259 }
6260 #else
6261 if([image lockFocusIfCanDraw] == NO)
6262 {
6263 DW_MUTEX_UNLOCK;
6264 DW_LOCAL_POOL_OUT;
6265 return;
6266 }
6267 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
6268 _DWLastDrawable = handle;
6269 #endif
6270 }
6271 if(bi)
6272 {
6197 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES); 6273 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES);
6198 [NSGraphicsContext saveGraphicsState]; 6274 [NSGraphicsContext saveGraphicsState];
6199 [NSGraphicsContext setCurrentContext:gc]; 6275 [NSGraphicsContext setCurrentContext:gc];
6200 } 6276 }
6201 else 6277
6202 {
6203 if([image lockFocusIfCanDraw] == NO)
6204 {
6205 DW_MUTEX_UNLOCK;
6206 DW_LOCAL_POOL_OUT;
6207 return;
6208 }
6209 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
6210 _DWLastDrawable = handle;
6211 }
6212 NSBezierPath* aPath = [NSBezierPath bezierPath]; 6278 NSBezierPath* aPath = [NSBezierPath bezierPath];
6213 NSColor *color = pthread_getspecific(_dw_fg_color_key); 6279 NSColor *color = pthread_getspecific(_dw_fg_color_key);
6214 [color set]; 6280 [color set];
6215 6281
6216 [aPath moveToPoint:NSMakePoint(*x + 0.5, *y + 0.5)]; 6282 [aPath moveToPoint:NSMakePoint(*x + 0.5, *y + 0.5)];
6222 if(flags & DW_DRAW_FILL) 6288 if(flags & DW_DRAW_FILL)
6223 { 6289 {
6224 [aPath fill]; 6290 [aPath fill];
6225 } 6291 }
6226 [aPath stroke]; 6292 [aPath stroke];
6227 if(pixmap) 6293 if(bi)
6228 {
6229 [NSGraphicsContext restoreGraphicsState]; 6294 [NSGraphicsContext restoreGraphicsState];
6230 } 6295 #ifndef BUILDING_FOR_MOJAVE
6231 else 6296 if(!pixmap)
6232 {
6233 [image unlockFocus]; 6297 [image unlockFocus];
6234 } 6298 #endif
6235 DW_MUTEX_UNLOCK; 6299 DW_MUTEX_UNLOCK;
6236 DW_LOCAL_POOL_OUT; 6300 DW_LOCAL_POOL_OUT;
6237 } 6301 }
6238 6302
6239 /* Draw a rectangle on a window (preferably a render window). 6303 /* Draw a rectangle on a window (preferably a render window).
6250 { 6314 {
6251 int _locked_by_me = FALSE; 6315 int _locked_by_me = FALSE;
6252 DW_LOCAL_POOL_IN; 6316 DW_LOCAL_POOL_IN;
6253 DW_MUTEX_LOCK; 6317 DW_MUTEX_LOCK;
6254 id image = handle; 6318 id image = handle;
6319 NSBitmapImageRep *bi = nil;
6320
6255 if(pixmap) 6321 if(pixmap)
6256 { 6322 bi = image = (id)pixmap->image;
6257 image = (id)pixmap->image; 6323 else
6324 {
6325 #ifdef BUILDING_FOR_MOJAVE
6326 if([image isMemberOfClass:[DWRender class]])
6327 {
6328 DWRender *render = image;
6329
6330 bi = [render cachedDrawingRep];
6331 }
6332 #else
6333 if([image lockFocusIfCanDraw] == NO)
6334 {
6335 DW_MUTEX_UNLOCK;
6336 DW_LOCAL_POOL_OUT;
6337 return;
6338 }
6339 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
6340 _DWLastDrawable = handle;
6341 #endif
6342 }
6343 if(bi)
6344 {
6258 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES); 6345 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES);
6259 [NSGraphicsContext saveGraphicsState]; 6346 [NSGraphicsContext saveGraphicsState];
6260 [NSGraphicsContext setCurrentContext:gc]; 6347 [NSGraphicsContext setCurrentContext:gc];
6261 } 6348 }
6262 else 6349
6263 {
6264 if([image lockFocusIfCanDraw] == NO)
6265 {
6266 DW_MUTEX_UNLOCK;
6267 DW_LOCAL_POOL_OUT;
6268 return;
6269 }
6270 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
6271 _DWLastDrawable = handle;
6272 }
6273 NSColor *color = pthread_getspecific(_dw_fg_color_key); 6350 NSColor *color = pthread_getspecific(_dw_fg_color_key);
6274 [color set]; 6351 [color set];
6275 6352
6276 if(flags & DW_DRAW_FILL) 6353 if(flags & DW_DRAW_FILL)
6277 [NSBezierPath fillRect:NSMakeRect(x, y, width, height)]; 6354 [NSBezierPath fillRect:NSMakeRect(x, y, width, height)];
6278 else 6355 else
6279 [NSBezierPath strokeRect:NSMakeRect(x, y, width, height)]; 6356 [NSBezierPath strokeRect:NSMakeRect(x, y, width, height)];
6280 if(pixmap) 6357 if(bi)
6281 {
6282 [NSGraphicsContext restoreGraphicsState]; 6358 [NSGraphicsContext restoreGraphicsState];
6283 } 6359 #ifndef BUILDING_FOR_MOJAVE
6284 else 6360 if(!pixmap)
6285 {
6286 [image unlockFocus]; 6361 [image unlockFocus];
6287 } 6362 #endif
6288 DW_MUTEX_UNLOCK; 6363 DW_MUTEX_UNLOCK;
6289 DW_LOCAL_POOL_OUT; 6364 DW_LOCAL_POOL_OUT;
6290 } 6365 }
6291 6366
6292 /* Draw an arc on a window (preferably a render window). 6367 /* Draw an arc on a window (preferably a render window).
6306 { 6381 {
6307 int _locked_by_me = FALSE; 6382 int _locked_by_me = FALSE;
6308 DW_LOCAL_POOL_IN; 6383 DW_LOCAL_POOL_IN;
6309 DW_MUTEX_LOCK; 6384 DW_MUTEX_LOCK;
6310 id image = handle; 6385 id image = handle;
6311 6386 NSBitmapImageRep *bi = nil;
6387
6312 if(pixmap) 6388 if(pixmap)
6313 { 6389 bi = image = (id)pixmap->image;
6314 image = (id)pixmap->image; 6390 else
6391 {
6392 #ifdef BUILDING_FOR_MOJAVE
6393 if([image isMemberOfClass:[DWRender class]])
6394 {
6395 DWRender *render = image;
6396
6397 bi = [render cachedDrawingRep];
6398 }
6399 #else
6400 if([image lockFocusIfCanDraw] == NO)
6401 {
6402 DW_MUTEX_UNLOCK;
6403 DW_LOCAL_POOL_OUT;
6404 return;
6405 }
6406 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
6407 _DWLastDrawable = handle;
6408 #endif
6409 }
6410 if(bi)
6411 {
6315 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES); 6412 id gc = _create_gc(image, flags & DW_DRAW_NOAA ? NO : YES);
6316 [NSGraphicsContext saveGraphicsState]; 6413 [NSGraphicsContext saveGraphicsState];
6317 [NSGraphicsContext setCurrentContext:gc]; 6414 [NSGraphicsContext setCurrentContext:gc];
6318 } 6415 }
6319 else 6416
6320 {
6321 if([image lockFocusIfCanDraw] == NO)
6322 {
6323 DW_MUTEX_UNLOCK;
6324 DW_LOCAL_POOL_OUT;
6325 return;
6326 }
6327 [[NSGraphicsContext currentContext] setShouldAntialias:(flags & DW_DRAW_NOAA ? NO : YES)];
6328 _DWLastDrawable = handle;
6329 }
6330 NSBezierPath* aPath = [NSBezierPath bezierPath]; 6417 NSBezierPath* aPath = [NSBezierPath bezierPath];
6331 NSColor *color = pthread_getspecific(_dw_fg_color_key); 6418 NSColor *color = pthread_getspecific(_dw_fg_color_key);
6332 [color set]; 6419 [color set];
6333 6420
6334 /* Special case of a full circle/oval */ 6421 /* Special case of a full circle/oval */
6357 { 6444 {
6358 [aPath fill]; 6445 [aPath fill];
6359 } 6446 }
6360 /* Actually do the drawing */ 6447 /* Actually do the drawing */
6361 [aPath stroke]; 6448 [aPath stroke];
6362 if(pixmap) 6449 if(bi)
6363 {
6364 [NSGraphicsContext restoreGraphicsState]; 6450 [NSGraphicsContext restoreGraphicsState];
6365 } 6451 #ifndef BUILDING_FOR_MOJAVE
6366 else 6452 if(!pixmap)
6367 {
6368 [image unlockFocus]; 6453 [image unlockFocus];
6369 } 6454 #endif
6370 DW_MUTEX_UNLOCK; 6455 DW_MUTEX_UNLOCK;
6371 DW_LOCAL_POOL_OUT; 6456 DW_LOCAL_POOL_OUT;
6372 } 6457 }
6373 6458
6374 /* 6459 /*