1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
|
/*
Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004 Benhur Stein
This file is part of Paj.
Paj is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
Paj is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
for more details.
You should have received a copy of the GNU Lesser General Public License
along with Paj; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include "Shape.h"
#include <math.h>
// 19.ago.2004 BS creation
static void PSNoShape(NSBezierPath *path, NSRect rect) {}
//
// Shape Functions
//
// these functions should only make a path to be drawn later
// functions for PajeState entities' shapes
static void PSRect(NSBezierPath *path, NSRect rect)
{
[path appendBezierPathWithRect:rect];
}
// functions for PajeEvent entities' shapes
// x, y is the main point; w, h are the size of the shape
static void PSTriangle(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)+2)];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect)/2, -NSHeight(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect), 0)];
[path closePath];
}
static void PSFTriangle(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)-2)];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect)/2, NSHeight(rect))];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect), 0)];
[path closePath];
}
static void PSPin(NSBezierPath *path, NSRect rect)
{
float radius = NSWidth(rect) / 2;
float yCenter = NSMinY(rect) - (NSHeight(rect) - radius - 2);
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)+2)];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), yCenter)
radius:radius
startAngle:90.0
endAngle:450.0];
[path closePath];
}
static void PSFPin(NSBezierPath *path, NSRect rect)
{
float radius = NSWidth(rect) / 2;
float yCenter = NSMinY(rect) + (NSHeight(rect) - radius - 2);
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)-2)];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), yCenter)
radius:radius
startAngle:-90.0
endAngle:270.0];
[path closePath];
}
static void PSFlag(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)+2)];
[path relativeLineToPoint:NSMakePoint(0, -(NSHeight(rect) - NSWidth(rect)))];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect), 0)];
[path relativeLineToPoint:NSMakePoint(0, -NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect), 0)];
[path closePath];
}
static void PSFFlag(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)-2)];
[path relativeLineToPoint:NSMakePoint(0, NSHeight(rect))];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect), 0)];
[path relativeLineToPoint:NSMakePoint(0, -NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect), 0)];
[path closePath];
}
static void PSRFlag(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)+2)];
[path relativeLineToPoint:NSMakePoint(0, -NSHeight(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect), 0)];
[path relativeLineToPoint:NSMakePoint(0, NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect), 0)];
[path closePath];
}
static void PSFRFlag(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)-2)];
[path relativeLineToPoint:NSMakePoint(0, NSHeight(rect) - NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect), 0)];
[path relativeLineToPoint:NSMakePoint(0, NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect), 0)];
[path closePath];
}
static void PSSquare(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)+2)];
[path relativeLineToPoint:NSMakePoint(0, -(NSHeight(rect)-NSWidth(rect)))];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect)/2, 0)];
[path relativeLineToPoint:NSMakePoint(0, -NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect), 0)];
[path relativeLineToPoint:NSMakePoint(0, NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect)/2, 0)];
[path closePath];
}
static void PSFSquare(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect)-2)];
[path relativeLineToPoint:NSMakePoint(0, NSHeight(rect) - NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect)/2, 0)];
[path relativeLineToPoint:NSMakePoint(0, NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(-NSWidth(rect), 0)];
[path relativeLineToPoint:NSMakePoint(0, -NSWidth(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect)/2, 0)];
[path closePath];
}
static void PSOut(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMaxX(rect), NSMinY(rect))];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect))
radius:NSWidth(rect)
startAngle:0
endAngle:360];
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect))];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect))
radius:1
startAngle:0
endAngle:360];
}
static void PSIn(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMaxX(rect), NSMinY(rect))];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect))
radius:NSWidth(rect)
startAngle:0
endAngle:360];
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect) - NSWidth(rect)/2)];
[path relativeLineToPoint:NSMakePoint(0, NSWidth(rect))];
[path moveToPoint:NSMakePoint(NSMinX(rect) - NSWidth(rect)/2, NSMinY(rect))];
[path relativeLineToPoint:NSMakePoint(NSWidth(rect), 0)];
}
// functions for PajeLink entities' shapes
// x, y is the starting point; x+w, y+h is the ending point
// functions should not change line width
static void PSLine(NSBezierPath *path, NSRect rect)
{
[path moveToPoint:NSMakePoint(NSMinX(rect), NSMinY(rect))];
[path lineToPoint:NSMakePoint(NSMaxX(rect), NSMaxY(rect))];
}
static void PSArrow(NSBezierPath *path, NSRect rect)
{
float len;
float ang;
len = sqrt(NSWidth(rect)*NSWidth(rect) + NSHeight(rect)*NSHeight(rect));
if (len > 0) {
NSBezierPath *arrow;
arrow = [NSBezierPath bezierPath];
[arrow moveToPoint:NSMakePoint(-7, 0)];
[arrow lineToPoint:NSMakePoint(-7, 2.5)];
[arrow lineToPoint:NSMakePoint(0, 0)];
[arrow lineToPoint:NSMakePoint(-7, -2.5)];
[arrow lineToPoint:NSMakePoint(-7, 0)];
ang = atan2(NSHeight(rect), NSWidth(rect)) * 180 / M_PI;
NSAffineTransform *transform;
transform = [NSAffineTransform transform];
[transform translateXBy:NSMaxX(rect) yBy:NSMaxY(rect)];
[transform rotateByDegrees:ang];
[arrow transformUsingAffineTransform:transform];
[path appendBezierPath:arrow];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect))
radius:1.5
startAngle:ang
endAngle:ang+360];
}
}
static void PSOpenArrow(NSBezierPath *path, NSRect rect)
{
float len;
float ang;
len = sqrt(NSWidth(rect)*NSWidth(rect) + NSHeight(rect)*NSHeight(rect));
if (len > 0) {
NSBezierPath *arrow;
arrow = [NSBezierPath bezierPath];
[arrow moveToPoint:NSMakePoint(-7, 3)];
[arrow lineToPoint:NSMakePoint(0, 0)];
[arrow lineToPoint:NSMakePoint(-7, -3)];
[arrow moveToPoint:NSMakePoint(0, 0)];
ang = atan2(NSHeight(rect), NSWidth(rect)) * 180 / M_PI;
NSAffineTransform *transform;
transform = [NSAffineTransform transform];
[transform translateXBy:NSMaxX(rect) yBy:NSMaxY(rect)];
[transform rotateByDegrees:ang];
[arrow transformUsingAffineTransform:transform];
[path appendBezierPath:arrow];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect))
radius:1.5
startAngle:ang
endAngle:ang+360];
}
}
static void PSDoubleArrow(NSBezierPath *path, NSRect rect)
{
float len;
float ang;
len = sqrt(NSWidth(rect)*NSWidth(rect) + NSHeight(rect)*NSHeight(rect));
if (len <= 0) {
return;
}
NSBezierPath *arrow;
arrow = [NSBezierPath bezierPath];
[arrow moveToPoint:NSMakePoint(-12, 0)];
[arrow lineToPoint:NSMakePoint(-12, 2.5)];
[arrow lineToPoint:NSMakePoint(-7, 2.5*2/7)];
[arrow lineToPoint:NSMakePoint(-7, 2.5)];
[arrow lineToPoint:NSMakePoint(0, 0)];
[arrow lineToPoint:NSMakePoint(-7, -2.5)];
[arrow lineToPoint:NSMakePoint(-7, -2.5*2/7)];
[arrow lineToPoint:NSMakePoint(-12, -2.5)];
[arrow lineToPoint:NSMakePoint(-12, 0)];
ang = atan2(NSHeight(rect), NSWidth(rect)) * 180 / M_PI;
NSAffineTransform *transform;
transform = [NSAffineTransform transform];
[transform translateXBy:NSMaxX(rect) yBy:NSMaxY(rect)];
[transform rotateByDegrees:ang];
[arrow transformUsingAffineTransform:transform];
[path appendBezierPath:arrow];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect))
radius:1.5
startAngle:ang
endAngle:ang+360];
}
static void PSDiamondArrow(NSBezierPath *path, NSRect rect)
{
float len;
float ang;
len = sqrt(NSWidth(rect)*NSWidth(rect) + NSHeight(rect)*NSHeight(rect));
if (len <= 0) {
return;
}
NSBezierPath *arrow;
arrow = [NSBezierPath bezierPath];
[arrow moveToPoint:NSMakePoint(-14, 0)];
[arrow lineToPoint:NSMakePoint(-7, 2.5)];
[arrow lineToPoint:NSMakePoint(0, 0)];
[arrow lineToPoint:NSMakePoint(-7, -2.5)];
[arrow lineToPoint:NSMakePoint(-14, 0)];
ang = atan2(NSHeight(rect), NSWidth(rect)) * 180 / M_PI;
NSAffineTransform *transform;
transform = [NSAffineTransform transform];
[transform translateXBy:NSMaxX(rect) yBy:NSMaxY(rect)];
[transform rotateByDegrees:ang];
[arrow transformUsingAffineTransform:transform];
[path appendBezierPath:arrow];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect), NSMinY(rect))
radius:1.5
startAngle:ang
endAngle:ang+360];
}
// functions for PajeVariable entities' shapes
void PSCurveAvg(NSBezierPath *path, NSRect rect)
{
float xMax = NSMaxX(rect);
float xAvg = NSMidX(rect);
float yAvg = NSMidY(rect);
float yCur = [path currentPoint].y;
[path curveToPoint:NSMakePoint(xAvg, yAvg)
controlPoint1:NSMakePoint(xMax, yCur)
controlPoint2:NSMakePoint(xMax, yAvg)];
}
void PSCurve(NSBezierPath *path, NSRect rect)
{
float xMin = NSMinX(rect);
float xMax = NSMaxX(rect);
float x1 = xMin+2./3*(xMax-xMin);
float x2 = xMin+1./3*(xMax-xMin);
float yAvg = NSMidY(rect);
float yCur = [path currentPoint].y;
[path curveToPoint:NSMakePoint(xMin, yAvg)
controlPoint1:NSMakePoint(x1, yCur)
controlPoint2:NSMakePoint(x2, yAvg)];
}
void PSCurveMin2(NSBezierPath *path, NSRect rect)
{
float xMin = NSMinX(rect);
float xMax = NSMaxX(rect);
float xAvg = NSMidX(rect);
float yAvg = NSMidY(rect);
[path curveToPoint:NSMakePoint(xMin, yAvg)
controlPoint1:NSMakePoint(xMax, yAvg)
controlPoint2:NSMakePoint(xAvg, yAvg)];
}
void PSCurveMin(NSBezierPath *path, NSRect rect)
{
float xMin = NSMinX(rect);
float xAvg = NSMidX(rect);
float yAvg = NSMidY(rect);
float yCur = [path currentPoint].y;
[path curveToPoint:NSMakePoint(xMin, yAvg)
controlPoint1:NSMakePoint(xAvg, yCur)
controlPoint2:NSMakePoint(xAvg, yAvg)];
}
void PSBuilding(NSBezierPath *path, NSRect rect)
{
float xMin = NSMinX(rect);
float xMax = NSMaxX(rect);
float yAvg = NSMidY(rect);
[path lineToPoint:NSMakePoint(xMax, yAvg)];
[path lineToPoint:NSMakePoint(xMin, yAvg)];
}
void PSMountain(NSBezierPath *path, NSRect rect)
{
float xMin = NSMinX(rect);
float yAvg = NSMidY(rect);
[path lineToPoint:NSMakePoint(xMin, yAvg)];
}
void PSTimes(NSBezierPath *path, NSRect rect)
{
float xMin = NSMinX(rect);
float yAvg = NSMidY(rect);
[path moveToPoint:NSMakePoint(xMin-3, yAvg-3)];
[path lineToPoint:NSMakePoint(xMin+3, yAvg+3)];
[path moveToPoint:NSMakePoint(xMin+3, yAvg-3)];
[path lineToPoint:NSMakePoint(xMin-3, yAvg+3)];
}
void PSCrosses(NSBezierPath *path, NSRect rect)
{
float xMin = NSMinX(rect);
float yAvg = NSMidY(rect);
[path moveToPoint:NSMakePoint(xMin, yAvg-3)];
[path lineToPoint:NSMakePoint(xMin, yAvg+3)];
[path moveToPoint:NSMakePoint(xMin+3, yAvg)];
[path lineToPoint:NSMakePoint(xMin-3, yAvg)];
}
void PSDots(NSBezierPath *path, NSRect rect)
{
float xMin = NSMinX(rect);
float yAvg = NSMidY(rect);
[path appendBezierPathWithOvalInRect:NSMakeRect(xMin-1.5, yAvg-1.5, 3, 3)];
}
// functions for PajeContainer entities' shapes
/* none */
//
// Draw Functions
//
// these functions should draw an already made shape path
// using the current color
static void PSFill(NSBezierPath *path, NSColor *color)
{
if (color != nil){
[color set];
[path fill];
}
}
static void PSFrame(NSBezierPath *path, NSColor *color)
{
if (color != nil){
[color set];
} else {
[[NSColor blackColor] set];
}
[path stroke];
}
static void PSFillAndFrame(NSBezierPath *path, NSColor *color)
{
if (color != nil){
[color set];
[path fill];
} else {
[[NSColor blackColor] set];
}
[path stroke];
}
static void PSDashedStroke(NSBezierPath *path, NSColor *color)
{
CGFloat dash[] = {5, 3};
[path setLineDash:dash count:2 phase:0];
if (color == nil){
color = [NSColor blackColor];
}
[color set];
[path stroke];
}
static void PSFillAndFrameBlack(NSBezierPath *path, NSColor *color)
{
if (color != nil){
[color set];
[path fill];
}
[[NSColor blackColor] set];
[path stroke];
}
static void PSFillAndFrameGray(NSBezierPath *path, NSColor *color)
{
if (color != nil){
[color set];
[path fill];
}
[[NSColor grayColor] set];
[path stroke];
}
static void PSFillAndFrameWhite(NSBezierPath *path, NSColor *color)
{
if (color != nil){
[color set];
[path fill];
}
[[NSColor whiteColor] set];
[path stroke];
}
static void PSFrameWhite(NSBezierPath *path, NSColor *color)
{
[[NSColor whiteColor] set];
[path stroke];
}
static void PSFillAndDashedStrokeBlack(NSBezierPath *path, NSColor *color)
{
CGFloat dash[] = {5, 3};
[path setLineDash:dash count:2 phase:0];
if (color != nil) {
[color set];
[path fill];
}
[[NSColor blackColor] set];
[path stroke];
}
static void PS3DStroke(NSBezierPath *path, NSColor *color)
{
float lineWidth;
lineWidth = [path lineWidth];
if (lineWidth < 2) {
lineWidth = 2;
}
if (color == nil) {
color = [NSColor blackColor];
}
[color set];
[path stroke];
NSAffineTransform *transform = [NSAffineTransform transform];
[path setLineWidth:lineWidth + 4];
[[NSColor colorWithCalibratedWhite:0.2 alpha:0.1] set];
[transform translateXBy: 4.0 yBy: 6.0];
[path transformUsingAffineTransform: transform];
[path stroke];
[path setLineWidth:lineWidth];
[path stroke];
//[path setLineWidth:lineWidth - 2];
//[path stroke];
[transform translateXBy: -8.0 yBy: -12.0];
[path transformUsingAffineTransform: transform];
[transform translateXBy: 4.0 yBy: 6.0];
[path setLineWidth:lineWidth - 2];
[transform translateXBy: 1.0 yBy: 1.0]; // move +1,+1
[path transformUsingAffineTransform: transform]; // at +1,+1
[[color shadowWithLevel:0.3] set];
[path stroke];
[transform translateXBy: -3.0 yBy: -3.0]; // move -2,-2
[path transformUsingAffineTransform: transform]; // at -1,-1
[[color highlightWithLevel:0.3] set];
[path stroke];
[transform translateXBy: 3.0 yBy: 3.0]; // move +1,+1
[path transformUsingAffineTransform: transform]; // at 0,0
[color set];
[path stroke];
}
static void PS3DFill(NSBezierPath *path, NSColor *color)
{
float lineWidth;
lineWidth = [path lineWidth];
if (lineWidth < 2) {
lineWidth = 2;
}
if (color == nil) {
color = [NSColor blackColor];
}
[color set];
[path fill];
NSAffineTransform *transform = [NSAffineTransform transform];
[path setLineWidth:lineWidth + 4];
[[NSColor colorWithCalibratedWhite:0.2 alpha:0.1] set];
[transform translateXBy: 4.0 yBy: 6.0];
[path transformUsingAffineTransform: transform];
[path fill];
[path setLineWidth:lineWidth];
[path fill];
//[path setLineWidth:lineWidth - 2];
//[path stroke];
[transform translateXBy: -8.0 yBy: -12.0];
[path transformUsingAffineTransform: transform];
[transform translateXBy: 4.0 yBy: 6.0];
[path setLineWidth:lineWidth - 2];
[transform translateXBy: 1.0 yBy: 1.0]; // move +1,+1
[path transformUsingAffineTransform: transform]; // at +1,+1
[[color shadowWithLevel:0.3] set];
[path fill];
[transform translateXBy: -3.0 yBy: -3.0]; // move -2,-2
[path transformUsingAffineTransform: transform]; // at -1,-1
[[color highlightWithLevel:0.3] set];
[path fill];
[transform translateXBy: 3.0 yBy: 3.0]; // move +1,+1
[path transformUsingAffineTransform: transform]; // at 0,0
[color set];
[path fill];
}
@implementation ShapeFunction
static NSDictionary *stateShapeFunctionsDictionary;
static NSDictionary *eventShapeFunctionsDictionary;
static NSDictionary *linkShapeFunctionsDictionary;
static NSDictionary *variableShapeFunctionsDictionary;
static NSDictionary *containerShapeFunctionsDictionary;
+ (void)initialize
{
#define FUNCTION(n) [self shapeFunctionWithFunction:n name:@#n], @#n
#define EFUNCTION(n, a, b) [self shapeFunctionWithFunction:n \
name:@#n \
topExtension:a \
rightExtension:b], \
@#n
stateShapeFunctionsDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:
FUNCTION(PSRect),
nil] retain];
eventShapeFunctionsDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:
EFUNCTION(PSTriangle, 1, 0.5),
EFUNCTION(PSFTriangle, 0, 0.5),
EFUNCTION(PSPin, 1, 0.5),
EFUNCTION(PSFPin, 0, 0.5),
EFUNCTION(PSSquare, 1, 0.5),
EFUNCTION(PSFSquare, 0, 0.5),
EFUNCTION(PSFlag, 1, 0),
EFUNCTION(PSFFlag, 0, 0),
EFUNCTION(PSRFlag, 1, 1),
EFUNCTION(PSFRFlag, 0, 1),
EFUNCTION(PSOut, 0.5, 0.5),
EFUNCTION(PSIn, 0.5, 0.5),
nil] retain];
linkShapeFunctionsDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:
FUNCTION(PSArrow),
FUNCTION(PSOpenArrow),
FUNCTION(PSDoubleArrow),
FUNCTION(PSDiamondArrow),
FUNCTION(PSLine),
nil] retain];
variableShapeFunctionsDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:
FUNCTION(PSCurveAvg),
FUNCTION(PSCurve),
FUNCTION(PSCurveMin),
FUNCTION(PSCurveMin2),
FUNCTION(PSBuilding),
FUNCTION(PSMountain),
FUNCTION(PSTimes),
FUNCTION(PSCrosses),
FUNCTION(PSDots),
nil] retain];
containerShapeFunctionsDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:
FUNCTION(PSNoShape),
FUNCTION(PSRect),
nil] retain];
#undef FUNCTION
}
+ (ShapeFunction *)shapeFunctionWithName:(NSString *)n
{
ShapeFunction *f;
f = [stateShapeFunctionsDictionary objectForKey:n];
if (f != nil) return f;
f = [eventShapeFunctionsDictionary objectForKey:n];
if (f != nil) return f;
f = [linkShapeFunctionsDictionary objectForKey:n];
if (f != nil) return f;
f = [variableShapeFunctionsDictionary objectForKey:n];
if (f != nil) return f;
f = [containerShapeFunctionsDictionary objectForKey:n];
if (f != nil) return f;
return [self shapeFunctionWithName:@"PSNoShape"];
}
+ (NSArray *)shapeFunctionsForDrawingType:(PajeDrawingType)drawingType
{
switch (drawingType) {
case PajeStateDrawingType:
return [stateShapeFunctionsDictionary allValues];
case PajeEventDrawingType:
return [eventShapeFunctionsDictionary allValues];
case PajeLinkDrawingType:
return [linkShapeFunctionsDictionary allValues];
case PajeVariableDrawingType:
return [variableShapeFunctionsDictionary allValues];
case PajeContainerDrawingType:
return [containerShapeFunctionsDictionary allValues];
default:
return [NSArray array];
}
return [NSArray array];
}
+ (ShapeFunction *)shapeFunctionWithFunction:(shapefunction *)f
name:(NSString *)n
{
return [self shapeFunctionWithFunction:f
name:n
topExtension:0
rightExtension:0];
}
+ (ShapeFunction *)shapeFunctionWithFunction:(shapefunction *)f
name:(NSString *)n
topExtension:(float)top
rightExtension:(float)right
{
return [[[self alloc] initWithShapeFunction:f
name:n
topExtension:top
rightExtension:right] autorelease];
}
- (id)initWithShapeFunction:(shapefunction *)f
name:(NSString *)n
topExtension:(float)top
rightExtension:(float)right
{
self = [super init];
function = f;
name = [n retain];
topExtension = top;
rightExtension = right;
return self;
}
- (shapefunction *)function
{
return function;
}
- (NSString *)name
{
return name;
}
- (float)topExtension;
{
return topExtension;
}
- (float)rightExtension;
{
return rightExtension;
}
@end
@implementation DrawFunction
NSDictionary *drawFunctionsDictionary;
+ (void)initialize
{
#define FUNCTION(n, f) [self drawFunctionWithFunction:n name:@#n fillsPath:f], @#n
drawFunctionsDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:
FUNCTION(PSFill, YES),
FUNCTION(PSFrame, NO),
FUNCTION(PSFillAndFrame, YES),
FUNCTION(PSDashedStroke, NO),
FUNCTION(PSFillAndFrameBlack, YES),
FUNCTION(PSFillAndFrameGray, YES),
FUNCTION(PSFillAndFrameWhite, YES),
FUNCTION(PSFrameWhite, NO),
FUNCTION(PSFillAndDashedStrokeBlack, YES),
FUNCTION(PS3DStroke, NO),
FUNCTION(PS3DFill, YES),
nil] retain];
#undef FUNCTION
}
+ (DrawFunction *)drawFunctionWithName:(NSString *)n
{
DrawFunction *function;
function = [drawFunctionsDictionary objectForKey:n];
if (function == nil) {
function = [drawFunctionsDictionary objectForKey:@"PSFill"];
}
return function;
}
+ (NSArray *)drawFunctions
{
return [drawFunctionsDictionary allValues];
}
+ (DrawFunction *)drawFunctionWithFunction:(drawfunction *)f name:(NSString *)n fillsPath:(BOOL)fills
{
return [[[self alloc] initWithDrawFunction:f name:n fillsPath:fills] autorelease];
}
- (id)initWithDrawFunction:(drawfunction *)f name:(NSString *)n fillsPath:(BOOL)fills
{
self = [super init];
function = f;
name = [n retain];
fillsPath = fills;
return self;
}
- (drawfunction *)function;
{
return function;
}
- (NSString *)name
{
return name;
}
- (BOOL)fillsPath
{
return fillsPath;
}
@end
|