Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help in Sketch Example



   Hai,
I have made some changes in sketch example. I am  a beginner in cocoa. Our
    desired out put is to display the width of text at the mid point of a
line.
    I gave these in the Line.m of sketch
     - (NSBezierPath *)bezierPath {
       NSBezierPath *path=[NSBezierPath bezierPath];
        NSRect bounds = [self bounds];
        //if(keyDown)
        //{
        if ([self startsAtLowerLeft])
        {
            [path moveToPoint:NSMakePoint(NSMinX(bounds), NSMaxY(bounds))];
            x1=NSMinX(bounds);
            y1=NSMaxY(bounds);
            [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMinY(bounds))];
            x2=NSMaxX(bounds);
            y2=NSMinY(bounds);
        }
        else{
            [path moveToPoint:NSMakePoint(NSMinX(bounds), NSMinY(bounds))];
            x1=NSMinX(bounds);

- Ignored:
            y1=NSMinY(bounds);
            [path lineToPoint:NSMakePoint(NSMaxX(bounds), NSMaxY(bounds))];
            x2=NSMaxX(bounds);
            y2=NSMaxY(bounds);
        //    [self TextDisplay];
        }      
        //}    
           NSPoint midPoint;//,locationText;
            width=sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
            midx = (x1+x2)/2;
            midy = (y1+y2)/2;
            midPoint.x=midx;
            midPoint.y=midx;
         NSLog(@"width is:%i \t x1,y1==%i,%i \t x2,y2==%i,%i
    ",width,x1,y1,x2,y2);
         NSLog(@"Middle point is:%i ,%i",midx,midy);
          [self drawRect:bounds];
          /*
        
        NSPoint midPoint,locationText;
                width=sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
                midx = (x1+x2)/2;
                midy = (y1+y2)/2;
                midPoint.x=midx;
                midPoint.y=midx;
                NSLog(@"width is:%i \t x1,y1==%i,%i \t x2,y2==%i,%i
    ",width,x1,y1,x2,y2);
                NSLog(@"Middle point is:%i ,%i",midx,midy);
        
        */
        return path;
    }
    -(void)drawRect:(NSRect)rect
    {
        NSString *message= [NSString stringWithString:@"Hai"];
        NSMutableDictionary *attributes = [ NSMutableDictionary dictonary];
        NSRect textBounds=NSZeroRect;
        NSRect bds = [self bounds];
        textBounds.size=[message sizeWithAttributes:attributes];
        
    
textBounds.origin=NSMakePoint((bds.size.width-textBounds.size.width)/2.0,(bd
    s.size.height - textBounds.size.height) /2.0);
        [message drawAtPoint:textBounds.origin withAttributes:attributes];
    
    }
    
-- 
With Regards,
             Anoop


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.