home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Draw / Curve.m < prev    next >
Text File  |  1995-09-04  |  2KB  |  76 lines

  1. #import "draw.h"
  2.  
  3. /*
  4.  * This line is just a stub to get genstrings to generate
  5.  * a .strings file entry for the name of this type of Graphic.
  6.  * The name is used in the Undo New <Whatever> menu item.
  7.  *
  8.  * NSLocalString("Curve", NULL, "Name of the tool that draws curves, i.e., the %@ of the New %@ operation.")
  9.  */
  10.  
  11. @implementation Curve
  12.  
  13. /* Curve is a silly class that just draws a stupid curved line. */
  14.  
  15. - (float)arrowAngle:(int)corner
  16. /*
  17.  * Since our control points are at a 90 degree angle, we'll draw our arrows
  18.  * at 90 degree angles (however, this method breaks down a bit as the bounds
  19.  * get very skinny--perhaps a better one could be found).
  20.  */
  21. {
  22.     if (gFlags.downhill) {
  23.     switch (corner) {
  24.         case UPPER_LEFT: return 180.0;
  25.         case LOWER_RIGHT: return - 90.0;
  26.     }
  27.     } else {
  28.     switch (corner) {
  29.         case UPPER_RIGHT: return 0.0;
  30.         case LOWER_LEFT: return -90.0;
  31.     }
  32.     }
  33.     return 0.0;
  34. }
  35.  
  36. - (void)drawLine
  37. /*
  38.  * Overridden from our superclass (Line).
  39.  * This is called from the draw method to actually do the drawing of the line,
  40.  * that way, we can inherit the arrow drawing, etc ...
  41.  */
  42. {
  43.     if (gFlags.downhill) {
  44.     PSCurve(bounds.origin.x, bounds.origin.y + bounds.size.height,
  45.         bounds.origin.x + bounds.size.width,
  46.         bounds.origin.y + bounds.size.height,
  47.         bounds.origin.x + bounds.size.width,
  48.         bounds.origin.y + bounds.size.height,
  49.             bounds.origin.x + bounds.size.width, bounds.origin.y);
  50.     } else {
  51.     PSCurve(bounds.origin.x, bounds.origin.y,
  52.         bounds.origin.x,
  53.         bounds.origin.y + bounds.size.height,
  54.             bounds.origin.x,
  55.         bounds.origin.y + bounds.size.height,
  56.             bounds.origin.x + bounds.size.width,
  57.         bounds.origin.y + bounds.size.height);
  58.     } 
  59. }
  60.  
  61. - (BOOL)hit:(NSPoint)p
  62. /*
  63.  * Line only gets a hit if the mouse is within some tolerance of the line.
  64.  * Obviously that algorithm doesn't work for a curve.  We could come up
  65.  * with the proper algorithm to only hit a curve if it is within a tolerance,
  66.  * but that would be complicated so we take the easy way out and just
  67.  * get a hit if it is anywhere in the bounds.  It is unfortunate that we
  68.  * have to copy code from Graphic to accomplish this.  Perhaps a better
  69.  * way exists?
  70.  */
  71. {
  72.     return (!gFlags.locked && gFlags.active && NSMouseInRect(p, bounds, NO));
  73. }
  74.  
  75. @end
  76.