ftp.nice.ch/Attic/openStep/developer/resources/MiscKit.2.0.5.s.gnutar.gz#/MiscKit2/Frameworks/MiscAppKit/MiscTreeDiagram.subproj/MiscHorizontalArrowShape.m

This is MiscHorizontalArrowShape.m in view mode; [Download] [Up]

/*	MiscHorizontalArrowShape.m

	Copyright 1996 Uwe Hoffmann.

	This notice may not be removed from this source code.
	The use and distribution of this software is governed by the
	terms of the MiscKit license agreement.  Refer to the license
	document included with the MiscKit distribution for the terms.

	Version 2 (August 1996)
*/

#import <Foundation/Foundation.h>

#import "MiscHorizontalArrowShape.h"
#import "MiscUserPath.h"
#import "MiscHitPath.h"
#import "MiscTDUtils.h"

@implementation MiscHorizontalArrowShape 

- (NSRect)innerBounds
{
	NSRect ir,b;
	
	b = [path bounds];
        if(!hR)
		ir.origin.x = b.origin.x;
        else
            	ir.origin.x = b.origin.x + b.size.width / 5;
	ir.origin.y = b.origin.y + b.size.height / 4;
	ir.size.width = b.size.width * 4 / 5;
	ir.size.height = b.size.height / 2;
	return ir;
}

- (MiscShapeType)shapeType
{
	return MiscHorizontalArrowShapeType;
}

- (void)calcIntersection:(NSPoint *)ip angle:(float *)alpha toPoint:(NSPoint)aPoint
{
	NSPoint middle,l1,l2,pos;
	float s,width,height,*bbox, ausdruck;
	
	bbox = [path bbox];
	pos.x = bbox[0];
	pos.y = bbox[1];
	width = bbox[2] - bbox[0];
	height = bbox[3] - bbox[1];	middle.x = pos.x + width / 2;
	middle.y = pos.y + height / 2;
        if(aPoint.y == middle.y){
                  ip->y = middle.y;
                  if(aPoint.x > middle.x){
                          *alpha = 0;		
                          ip->x = pos.x + width;
                  } else {
                          *alpha = 180;
                          ip->x = pos.x;
                  }
                  return;
        }
	if(aPoint.x == middle.x){
		ip->x = middle.x;
		if(aPoint.y > middle.y){
			ip->y = pos.y + height * 3 / 4;
			*alpha = 90;
		} else {
			ip->y = pos.y + height / 4;
			*alpha = -90;
		}
		return;
	}
	s = (aPoint.y - middle.y) / (aPoint.x - middle.x);
	*alpha = 57.29577951 * atan(s);
        if(!hR){
            if(aPoint.y > middle.y){
                    if(aPoint.x > middle.x){ 						// I. quadrant
                            l1.x = pos.x + width;
                            l1.y = middle.y;
                            l2.x = pos.x + width * 3 / 5;
                            l2.y = pos.y + height;
                            if(miscTD_straddles(l1, l2, middle, aPoint)){
                                ausdruck = (l2.y - l1.y) / (l2.x - l1.x);
                                ip->x = (middle.y + ausdruck * l1.x - s * middle.x - l1.y) / (ausdruck - s);
                                ip->y = middle.y + s * (ip->x - middle.x);
                            } else {
                                ip->y = pos.y + height * 3 / 4;
                                ip->x = middle.x + (ip->y - middle.y) / s;
                            }
                    } else { 										// II. quadrant
                            l1.x = middle.x;
                            l1.y = l2.y = pos.y + height * 3 / 4;
                            l2.x = pos.x;
                            if(miscTD_straddles(l1, l2, middle, aPoint)){
                                    ip->y = l1.y;
                                    ip->x = middle.x + (ip->y - middle.y) / s;
                            } else {
                                    ip->x = l2.x;
                                    ip->y = middle.y + s * (ip->x - middle.x);
                            }
                            *alpha += 180;
                    }
            } else {
                    if(aPoint.x > middle.x){ 						// IV. quadrant
                            l1.x = pos.x + width;
                            l1.y = middle.y;
                            l2.x = pos.x + width * 3 / 5;
                            l2.y = pos.y;
                            if(miscTD_straddles(l1, l2, middle, aPoint)){
                                ausdruck = (l2.y - l1.y) / (l2.x - l1.x);
                                ip->x = (middle.y + ausdruck * l1.x - s * middle.x - l1.y) / (ausdruck - s);
                                ip->y = middle.y + s * (ip->x - middle.x);
                            } else {
                                ip->y = pos.y + height / 4;
                                ip->x = middle.x + (ip->y - middle.y) / s;
                            }
                    } else { 										// III. quadrant
                            l1.x = middle.x;
                            l1.y = l2.y = pos.y + height / 4;
                            l2.x = pos.x;
                            if(miscTD_straddles(l1, l2, middle, aPoint)){
                                    ip->y = l1.y;
                                    ip->x = middle.x + (ip->y - middle.y) / s;
                            } else {
                                    ip->x = l2.x;
                                    ip->y = middle.y + s * (ip->x - middle.x);
                            }
                            *alpha += 180;
                    }
            }
        } else {
            if(aPoint.y > middle.y){
                    if(aPoint.x > middle.x){ 						// I. quadrant
                            l1.x = middle.x;
                            l1.y = l2.y = pos.y + height * 3 / 4;
                            l2.x = pos.x + width;
                            if(miscTD_straddles(l1, l2, middle, aPoint)){
                                ip->y = l1.y;
                                ip->x = middle.x + (ip->y - middle.y) / s;
                            } else {
                                ip->x = l2.x;
                                ip->y = middle.y + s * (ip->x - middle.x);
                            }
                    } else { 										// II. quadrant
                            l1.x = pos.x;
                            l1.y = middle.y;
                            l2.x = pos.x + width * 2 / 5;
                            l2.y = pos.y + height;
                            if(miscTD_straddles(l1, l2, middle, aPoint)){
                                ausdruck = (l2.y - l1.y) / (l2.x - l1.x);
                                ip->x = (middle.y + ausdruck * l1.x - s * middle.x - l1.y) / (ausdruck - s);
                                ip->y = middle.y + s * (ip->x - middle.x);
                            } else {
                                ip->y = pos.y + height * 3 / 4;
                                ip->x = middle.x + (ip->y - middle.y) / s;
                            }
                            *alpha += 180;
                    }
            } else {
                    if(aPoint.x > middle.x){ 						// IV. quadrant
                            l1.x = middle.x;
                            l1.y = l2.y = pos.y + height / 4;
                            l2.x = pos.x + width;
                            if(miscTD_straddles(l1, l2, middle, aPoint)){
                                ip->y = l1.y;
                                ip->x = middle.x + (ip->y - middle.y) / s;
                            } else {
                                ip->x = l2.x;
                                ip->y = middle.y + s * (ip->x - middle.x);
                            }
                    } else { 										// III. quadrant
                            l1.x = pos.x;
                            l1.y = middle.y;
                            l2.x = pos.x + width * 2 / 5;
                            l2.y = pos.y;
                            if(miscTD_straddles(l1, l2, middle, aPoint)){
                                ausdruck = (l2.y - l1.y) / (l2.x - l1.x);
                                ip->x = (middle.y + ausdruck * l1.x - s * middle.x - l1.y) / (ausdruck - s);
                                ip->y = middle.y + s * (ip->x - middle.x);
                            } else {
                                ip->y = pos.y + height / 4;
                                ip->x = middle.x + (ip->y - middle.y) / s;
                            }
                            *alpha += 180;
                    }
            }
        }
}


- (void)makePathWithBounds:(NSRect)aRect
{
    	if(!hR){
            [path moveto:aRect.origin.x :aRect.origin.y + aRect.size.height / 4];
            [path rlineto:aRect.size.width * 3 / 5 :0.0];
            [path rlineto:0.0 :-aRect.size.height / 4];
            [path rlineto:aRect.size.width * 2 / 5 :aRect.size.height / 2];
            [path rlineto:-aRect.size.width * 2 / 5 :aRect.size.height / 2];
            [path rlineto:0.0 :-aRect.size.height / 4];
            [path rlineto:-aRect.size.width * 3 / 5 :0.0];
        } else {
            [path moveto:aRect.origin.x :aRect.origin.y + aRect.size.height / 2];
            [path rlineto:aRect.size.width * 2 / 5 :-aRect.size.height / 2];
            [path rlineto:0.0 :aRect.size.height / 4];
            [path rlineto:aRect.size.width * 3 / 5 :0.0];
            [path rlineto:0.0 :aRect.size.height / 2];
            [path rlineto:-aRect.size.width * 3 / 5 :0.0];
            [path rlineto:0.0 :aRect.size.height / 4];
        }
	[path closepath];
}
			
- (void)fillParamsWithBounds:(NSRect)aRect
{
	float *params, *bbox;
	
	params = [path params];
	bbox = [path bbox];
	bbox[0] = aRect.origin.x;
	bbox[1] = aRect.origin.y;
	bbox[2] = aRect.origin.x + aRect.size.width;
	bbox[3] = aRect.origin.y + aRect.size.height;
        if(!hR){
            params[0] = aRect.origin.x;
            params[1] = aRect.origin.y + aRect.size.height / 4;
            params[2] = aRect.size.width * 3 / 5;
            params[3] = 0.0;
            params[4] = 0.0;
            params[5] = -aRect.size.height / 4;
            params[6] = aRect.size.width * 2 / 5;
            params[7] = aRect.size.height / 2;
            params[8] = -aRect.size.width * 2 / 5;
            params[9] = aRect.size.height / 2;
            params[10] = 0.0;
            params[11] = -aRect.size.height / 4;
            params[12] = -aRect.size.width * 3 / 5;
            params[13] = 0.0;
        } else {
            params[0] = aRect.origin.x;
            params[1] = aRect.origin.y + aRect.size.height / 2;
            params[2] = aRect.size.width * 2 / 5;
            params[3] = -aRect.size.height / 2;
            params[4] = 0.0;
            params[5] = aRect.size.height / 4;
            params[6] = aRect.size.width * 3 / 5;
            params[7] = 0.0;
            params[8] = 0.0;
            params[9] = aRect.size.height / 2;
            params[10] = -aRect.size.width * 3 / 5;
            params[11] = 0.0;
            params[12] = 0.0;
            params[13] = aRect.size.height / 4;
        }
}

+ (NSSize)calcSizeForInnerSize:(NSSize)aSize
{
	NSSize os;
	
	os.width = aSize.width * 5 / 4;
	os.height = aSize.height * 2;
	return os;
}
		              
@end


	

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.