discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CGPoint support in NSValue


From: Fred Kiefer
Subject: Re: CGPoint support in NSValue
Date: Sat, 14 Mar 2015 22:22:02 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0

To summon this up, the proposed patch wont work because we don't have
CGPoint and CGRect defined in base at the moment. If we add these two
types to base in some way we could either add two separate definitions
and become incompatible to Cocoa. Or we make these typedef to the
Foundation types (or rather the other way around!) and wont need the
patch at all.

I would suggest that somebody comes up with a patch for a CGGeometry.h
file and we add that to base after some review from Richard. Any takers?

Fred


Am 11.03.2015 um 21:47 schrieb Ivan Vučica:
> Looks like this should give similar results to Mac then:
> 
> typedef struct _CGPoint                                                
>         
> {                                                                      
>         
>   float x, y;                                                          
>         
> } CGPoint;                                                              
>        
> typedef CGPoint NSPoint;                                                
>        
>                                                                        
>         
> int main()                                                              
>        
> {                                                                      
>         
>   printf("%s\n", @encode(NSPoint));                                    
>         
>   printf("%s\n", @encode(CGPoint));                                    
>         
> }                                                                      
>         
> 
> $ ./a.out 
> {_CGPoint=ff}
> {_CGPoint=ff}
> 
> 
> 
> On Wed, Mar 11, 2015 at 8:44 PM, Fred Kiefer <fredkiefer@gmx.de
> <mailto:fredkiefer@gmx.de>> wrote:
> 
>     I just run the line 
> 
>     NSLog(@"CGPoint %s NSPoint %s", @encode(CGPoint),  @encode(NSPoint));
> 
>     On my Mac and this gives me the same output, {CGPoint=dd}. The same
>     may not be true on GNUstep, but this could just mean we need to
>     corrcet this?
> 
>     Fred
> 
>     On the road
> 
>     Am 11.03.2015 um 19:14 schrieb Amr Aboelela <amraboelela@gmail.com
>     <mailto:amraboelela@gmail.com>>:
> 
>>     They hold the same data yes, but in CoreGraphics, UIKit, and
>>     CoreAnimation, it is called CGPoint and CGRect :)
>>     If we don't do that, then the KVC will not work right in the
>>     CoreAnimation for the CALayer
>>
>>     On Wed, Mar 11, 2015 at 1:39 AM, Fred Kiefer <fredkiefer@gmx.de
>>     <mailto:fredkiefer@gmx.de>> wrote:
>>
>>         Sorry, I am be a little confused here, what is the difference
>>         between @encode(CGPoint) and @encode(NSPoint)? Shouldn't these
>>         two yield the same result?
>>
>>         Fred
>>
>>         On the road
>>
>>         Am 11.03.2015 um 04:31 schrieb Amr Aboelela
>>         <amraboelela@gmail.com <mailto:amraboelela@gmail.com>>:
>>
>>>         To support CGPoint and CGRect in NSValue, the following needs
>>>         to be done:
>>>
>>>
>>>         *1. In GSObjCRuntime.m file:*
>>>
>>>         id GSObjCGetVal(NSObject *self, constchar*key, SELsel,
>>>
>>>                      constchar*type, unsignedsize, intoffset)
>>>
>>>         {
>>>
>>>         ...
>>>
>>>                     case_C_STRUCT_B:
>>>
>>>                         if(strcmp(@encode(CGPoint), type)==0) {
>>>
>>>                             DLog(@"@encode(CGPoint): %s",
>>>         @encode(CGPoint));
>>>
>>>                             CGPointv;
>>>
>>>                             if(sel == 0) {
>>>
>>>                                 memcpy((char*)&v, ((char*)self+
>>>         offset), sizeof(v));
>>>
>>>                             } else{
>>>
>>>                                 CGPoint(*imp)(id, SEL) =
>>>
>>>                                 (CGPoint (*)(id,
>>>         SEL))[selfmethodForSelector: sel];
>>>
>>>                                 v = (*imp)(self, sel);
>>>
>>>                             }
>>>
>>>                             val = [NSValue valueWithCGPoint:v];
>>>
>>>                         } elseif(strcmp(@encode(CGRect), type)==0) {
>>>
>>>                             DLog(@"@encode(CGRect): %s",
>>>         @encode(CGRect));
>>>
>>>                             CGRectv;
>>>
>>>                             if(sel == 0) {
>>>
>>>                                 memcpy((char*)&v, ((char*)self+
>>>         offset), sizeof(v));
>>>
>>>                             } else{
>>>
>>>                                 CGRect(*imp)(id, SEL) =
>>>
>>>                                 (CGRect (*)(id,
>>>         SEL))[selfmethodForSelector: sel];
>>>
>>>                                 v = (*imp)(self, sel);
>>>
>>>                             }
>>>
>>>                             val = [NSValue valueWithCGRect:v];
>>>
>>>                         }
>>>         elseif(GSSelectorTypesMatch(@encode(NSPoint), type))
>>>
>>>                         {
>>>
>>>         ...
>>>
>>>         }
>>>
>>>
>>>         void GSObjCSetVal(NSObject *self, constchar*key, idval, SELsel,
>>>
>>>                      constchar*type, unsignedsize, intoffset)
>>>
>>>         {
>>>
>>>           ...
>>>
>>>                     case_C_STRUCT_B:
>>>
>>>                         if(strcmp(@encode(CGPoint), type)==0) {
>>>
>>>                             DLog(@"@encode(CGPoint): %s",
>>>         @encode(CGPoint));
>>>
>>>                             CGPoint v = [val CGPointValue];
>>>
>>>                             if(sel == 0) {
>>>
>>>                                 CGPoint *ptr =
>>>         (CGPoint*)((char*)self+ offset);
>>>
>>>                                 *ptr = v;
>>>
>>>                             } else{
>>>
>>>                                 void(*imp)(id, SEL, CGPoint) =
>>>
>>>                                 (void(*)(id, SEL,
>>>         CGPoint))[selfmethodForSelector: sel];
>>>
>>>                                 (*imp)(self, sel, v);
>>>
>>>                             }
>>>
>>>                         } elseif(strcmp(@encode(CGRect), type)==0) {
>>>
>>>                             DLog(@"strcmp(@encode(CGRect): %s",
>>>         @encode(CGRect));
>>>
>>>                             CGRect v = [val CGRectValue];
>>>
>>>                             if(sel == 0) {
>>>
>>>                                 CGRect *ptr = (CGRect*)((char*)self+
>>>         offset);
>>>
>>>                                 *ptr = v;
>>>
>>>                             } else{
>>>
>>>                                 void(*imp)(id, SEL, CGRect) =
>>>
>>>                                 (void(*)(id, SEL,
>>>         CGRect))[selfmethodForSelector: sel];
>>>
>>>                                 (*imp)(self, sel, v);
>>>
>>>                             }
>>>
>>>                         }
>>>         elseif(GSSelectorTypesMatch(@encode(NSPoint), type))
>>>
>>>                         {
>>>
>>>         ...
>>>
>>>         }
>>>
>>>
>>>         *2. In NSValue.m file:*
>>>
>>>
>>>         + (Class) valueClassWithObjCType: (constchar*)type
>>>
>>>         {
>>>
>>>             ClasstheClass = concreteClass;
>>>
>>>             
>>>
>>>             /* Let someone else deal with this error */
>>>
>>>             if(!type)
>>>
>>>                 returntheClass;
>>>
>>>             
>>>
>>>             /* Try for an exact type match.
>>>
>>>              */
>>>
>>>             if(strcmp(@encode(id), type) == 0)
>>>
>>>                 theClass = nonretainedObjectValueClass;
>>>
>>>             elseif(strcmp(@encode(NSPoint), type) == 0)
>>>
>>>                 theClass = pointValueClass;
>>>
>>>             elseif(strcmp(@encode(void*), type) == 0)
>>>
>>>                 theClass = pointerValueClass;
>>>
>>>             elseif(strcmp(@encode(NSRange), type) == 0)
>>>
>>>                 theClass = rangeValueClass;
>>>
>>>             elseif(strcmp(@encode(NSRect), type) == 0)
>>>
>>>                 theClass = rectValueClass;
>>>
>>>             elseif(strcmp(@encode(NSSize), type) == 0)
>>>
>>>                 theClass = sizeValueClass;
>>>
>>>             
>>>
>>>             /* Try for equivalent types match.
>>>
>>>              */
>>>
>>>             /*else if (GSSelectorTypesMatch(@encode(id), type))
>>>
>>>                 theClass = nonretainedObjectValueClass;
>>>
>>>             else if (GSSelectorTypesMatch(@encode(NSPoint), type))
>>>
>>>                 theClass = pointValueClass;
>>>
>>>             else if (GSSelectorTypesMatch(@encode(void *), type))
>>>
>>>                 theClass = pointerValueClass;
>>>
>>>             else if (GSSelectorTypesMatch(@encode(NSRange), type))
>>>
>>>                 theClass = rangeValueClass;
>>>
>>>             else if (GSSelectorTypesMatch(@encode(NSRect), type))
>>>
>>>                 theClass = rectValueClass;
>>>
>>>             else if (GSSelectorTypesMatch(@encode(NSSize), type))
>>>
>>>                 theClass = sizeValueClass;*/
>>>
>>>             DLog(@"theClass: %@", theClass);
>>>
>>>             returntheClass;
>>>
>>>         }
>>>
>>>
>>>         Check full files here:
>>>
>>>         
>>> https://github.com/amraboelela/myos.frameworks/blob/master/Foundation/GSObjCRuntime-myos.m
>>>
>>>         
>>> https://github.com/amraboelela/myos.frameworks/blob/master/Foundation/NSValue-myos.m




reply via email to

[Prev in Thread] Current Thread [Next in Thread]