home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Draw / Graphic.h < prev    next >
C/C++ Source or Header  |  1996-04-11  |  10KB  |  327 lines

  1. @class GraphicView;
  2.  
  3. #define KNOB_DY_ONCE  0x1
  4. #define KNOB_DY_TWICE 0x2
  5. #define KNOB_DX_ONCE  0x4
  6. #define KNOB_DX_TWICE 0x8
  7.  
  8. /* corners */
  9.  
  10. #define LOWER_LEFT    (0x10)
  11. #define LEFT_SIDE    (KNOB_DY_ONCE)
  12. #define UPPER_LEFT    (LEFT_SIDE|KNOB_DY_TWICE)
  13. #define TOP_SIDE    (UPPER_LEFT|KNOB_DX_ONCE)
  14. #define UPPER_RIGHT    (TOP_SIDE|KNOB_DX_TWICE)
  15. #define BOTTOM_SIDE    (KNOB_DX_ONCE)
  16. #define LOWER_RIGHT    (BOTTOM_SIDE|KNOB_DX_TWICE)
  17. #define RIGHT_SIDE    (LOWER_RIGHT|KNOB_DY_ONCE)
  18.  
  19. /* special corner which means upper right, but also note that we're creating */
  20.  
  21. #define CREATE        (0x20)
  22.  
  23. /* corner mask values */
  24.  
  25. #define LOWER_LEFT_MASK        (1 << LOWER_LEFT)
  26. #define LEFT_SIDE_MASK        (1 << LEFT_SIDE)
  27. #define UPPER_LEFT_MASK        (1 << UPPER_LEFT)
  28. #define TOP_SIDE_MASK        (1 << TOP_SIDE)
  29. #define UPPER_RIGHT_MASK    (1 << UPPER_RIGHT)
  30. #define BOTTOM_SIDE_MASK    (1 << BOTTOM_SIDE)
  31. #define LOWER_RIGHT_MASK    (1 << LOWER_RIGHT)
  32. #define RIGHT_SIDE_MASK        (1 << RIGHT_SIDE)
  33. #define ALL_CORNERS        0xffffffff
  34.  
  35. /* arrows */
  36.  
  37. #define ARROW_AT_START    1
  38. #define ARROW_AT_END    2
  39. #define ARROW_AT_BOTH    3
  40.  
  41. /* Fills - These must match up with the order in the PopUpList in the Inspector Panel */
  42.  
  43. #define FILL_NONE    0
  44. #define FILL_EO        1
  45. #define FILL_NZWR    2
  46.  
  47. extern id CrossCursor;
  48.  
  49. @interface Graphic : NSObject
  50. {
  51.     NSRect bounds;            /* the bounds */
  52.     float linewidth;            /* linewidth */
  53.     struct _gFlags {
  54. #ifdef __BIG_ENDIAN__
  55.     unsigned int selected:1;    /* whether selected */
  56.     unsigned int active:1;        /* whether to really draw in draw: */
  57.     unsigned int eofill:1;        /* whether eofilled */
  58.     unsigned int fillColorSet:1;    /* whether to put frame around fill */
  59.     unsigned int downhill:1;    /* Line: direction line goes */
  60.     unsigned int initialized:1;    /* subclass specific */
  61.     unsigned int linewidthSet:1;    /* used when archiving only */
  62.     unsigned int lineColorSet:1;    /* used when archiving only */
  63.     unsigned int linejoin:2;    /* line join */
  64.     unsigned int linecap:2;        /* line cap */
  65.     unsigned int fill:1;        /* whether filled */
  66.     unsigned int locked:1;        /* locked down? */
  67.     unsigned int arrow:2;        /* arrow position */
  68.     unsigned int nooutline:1;    /* whether the graphic is outlined */
  69.     unsigned int isFormEntry:1;    /* whether the graphic is a form entry (TextGraphic only) */
  70.     unsigned int localizeFormEntry:1; /* whether to localize a form entry (TextGraphic only) */
  71.     unsigned int mightBeLinked:1;    /* set if Graphic has ever had a link associated with it */
  72.         unsigned int notCached:1;    /* was the graphic view cached without this graphic in it? */
  73.     unsigned int padding:11;
  74. #else
  75.     unsigned int padding:11;
  76.         unsigned int notCached:1;    /* was the graphic view cached without this graphic in it? */
  77.     unsigned int mightBeLinked:1;    /* set if Graphic has ever had a link associated with it */
  78.     unsigned int localizeFormEntry:1; /* whether to localize a form entry (TextGraphic only) */
  79.     unsigned int isFormEntry:1;    /* whether the graphic is a form entry (TextGraphic only) */
  80.     unsigned int nooutline:1;    /* whether the graphic is outlined */
  81.     unsigned int arrow:2;        /* arrow position */
  82.     unsigned int locked:1;        /* locked down? */
  83.     unsigned int fill:1;        /* whether filled */
  84.     unsigned int linecap:2;        /* line cap */
  85.     unsigned int linejoin:2;    /* line join */
  86.     unsigned int lineColorSet:1;    /* used when archiving only */
  87.     unsigned int linewidthSet:1;    /* used when archiving only */
  88.     unsigned int initialized:1;    /* subclass specific */
  89.     unsigned int downhill:1;    /* Line: direction line goes */
  90.     unsigned int fillColorSet:1;    /* whether to put frame around fill */
  91.     unsigned int eofill:1;        /* whether eofilled */
  92.     unsigned int active:1;        /* whether to really draw in draw: */
  93.     unsigned int selected:1;    /* whether selected */
  94. #endif
  95.     } gFlags;
  96.     NSColor *lineColor;
  97.     NSColor *fillColor;
  98.     int identifier;            /* unique identifier */
  99. }
  100.  
  101. /* Factory methods */
  102.  
  103. + (void)showFastKnobFills;
  104. + (void)initClassVars;
  105. + (BOOL)isEditable;
  106. + (NSCursor *)cursor;
  107.  
  108. + (int)currentGraphicIdentifier;
  109. + (int)nextCurrentGraphicIdentifier;
  110. + (void)updateCurrentGraphicIdentifier:(int)newMaxIdentifier;
  111.  
  112. /* Initialization method */
  113.  
  114. - (id)init;
  115.  
  116.  
  117. /* Private methods (for subclassers only) */
  118.  
  119. - (void)setGraphicsState;
  120. - (void)setLineColor;
  121. - (void)setFillColor;
  122. - (int)cornerMask;
  123.  
  124. /* Data link methods */
  125.  
  126. - (void)setLink:(NSDataLink *)aLink;
  127. - (NSDataLink *)link;
  128. - (Graphic *)graphicLinkedBy:(NSDataLink *)aLink;
  129. - (void)reviveLink:(NSDataLinkManager *)linkManager;
  130. - (NSSelection *)selection;
  131. - (BOOL)mightBeLinked;
  132. - (void)readLinkFromPasteboard:(NSPasteboard *)pboard usingManager:(NSDataLinkManager *)linkManager useNewIdentifier:(BOOL)useNewIdentifier;
  133.  
  134. /* Notification from GraphicView */
  135.  
  136. - (void)wasRemovedFrom:(GraphicView *)sender;
  137. - (void)wasAddedTo:(GraphicView *)sender;
  138.  
  139. /* Methods for uniquely identifying a Graphic. */
  140.  
  141. - (void)resetIdentifier;
  142. - (int)identifier;
  143. - (NSString *)identifierString;
  144. - (Graphic *)graphicIdentifiedBy:(int)anIdentifier;
  145.  
  146. /* Event handling */
  147.  
  148. - (BOOL)handleEvent:(NSEvent *)event at:(NSPoint)p inView:(NSView *)view;
  149.  
  150. /* Public routines (called mostly by a GraphicView or subclassers). */
  151.  
  152. - (NSString *)title;
  153. - (BOOL)isSelected;
  154. - (BOOL)isActive;
  155. - (BOOL)isCached;
  156. - (BOOL)isLocked;
  157. - (void)select;
  158. - (void)deselect;
  159. - (void)activate;
  160. - (void)deactivate;
  161. - (void)lockGraphic;
  162. - (void)unlockGraphic;
  163.  
  164. - (BOOL)isFormEntry;
  165. - (void)setFormEntry:(int)flag;
  166. - (BOOL)hasFormEntries;
  167. - (BOOL)writeFormEntryToMutableString:(NSMutableString *)aString;
  168. - (BOOL)writesFiles;
  169. - (void)writeFilesToDirectory:(NSString *)directory;
  170.  
  171. - (void)setCacheable:(BOOL)flag;
  172. - (BOOL)isCacheable;
  173.  
  174. - (NSRect)bounds;
  175. - (void)setBounds:(NSRect)aRect;
  176. - (NSRect)extendedBounds;
  177.  
  178. - (int)knobHit:(NSPoint)point;
  179.  
  180. - (void)draw:(NSRect)rect;
  181.  
  182. - (BOOL)canEmitEPS;
  183. - (BOOL)canEmitTIFF;
  184.  
  185. - (void)moveLeftEdgeTo:(const float *)x;
  186. - (void)moveRightEdgeTo:(const float *)x;
  187. - (void)moveTopEdgeTo:(const float *)y;
  188. - (void)moveBottomEdgeTo:(const float *)y;
  189. - (void)moveHorizontalCenterTo:(const float *)x;
  190. - (void)moveVerticalCenterTo:(const float *)y;
  191. - (void)moveBaselineTo:(const float *)y;
  192. - (float)baseline;
  193.  
  194. - (void)moveBy:(const NSPoint *)offset;
  195. - (void)moveTo:(NSPoint)p;
  196. - (void)centerAt:(NSPoint)center;
  197. - (void)sizeTo:(const NSSize *)size;
  198. - (void)sizeToNaturalAspectRatio;
  199. - (void)alignToGrid:(GraphicView *)graphicView;
  200. - (void)sizeToGrid:(GraphicView *)graphicView;
  201.  
  202. /* Public routines (called mostly by inspectors and the like). */
  203.  
  204. - (void)setLineWidth:(const float *)value;
  205. - (float)lineWidth;
  206. - (void)setLineColor:(NSColor *)color;
  207. - (Graphic *)colorAcceptorAt:(NSPoint)point;
  208. - (NSColor *)lineColor;
  209. - (void)setFillColor:(NSColor *)color;
  210. - (NSColor *)fillColor;
  211. - (void)changeFont:(id)sender;
  212. - (NSFont *)font;
  213. - (void)setGray:(const float *)value;
  214. - (float)gray;
  215. - (void)setFill:(int)mode;
  216. - (int)fill;
  217. - (void)setOutlined:(BOOL)outlinedFlag;
  218. - (BOOL)isOutlined;
  219. - (void)setLineCap:(int)capValue;
  220. - (int)lineCap;
  221. - (void)setLineArrow:(int)arrowValue;
  222. - (int)lineArrow;
  223. - (void)setLineJoin:(int)joinValue;
  224. - (int)lineJoin;
  225.  
  226. /* Archiving (must be overridden by subclasses with instance variables) */
  227.  
  228. - (void)convertSelf:(ConversionDirection)direction propertyList:(id)plist;
  229. - (id)propertyList;
  230. - initFromPropertyList:(id)plist inDirectory:(NSString *)directory;
  231.  
  232. /* Routines intended to be subclassed for different types of Graphics. */
  233.  
  234. /*
  235.  * Can be overridden to provide more sophisticated size constraining
  236.  * than an aspect ratio (though that is almost always sufficient).
  237.  * For example, Line overrides this to constrain to closes 15 degree angle.
  238.  * constrainByDefault says whether constraining is the default or not for
  239.  * the receiving kind of Graphic.
  240.  */
  241.  
  242. - (BOOL)constrainByDefault;
  243. - (void)constrainCorner:(int)corner toAspectRatio:(float)aspect;
  244.  
  245. /*
  246.  * Can be overridden to resize the Graphic differently than the
  247.  * default (which is to drag out the bounds), or to do something
  248.  * before and/or after the subclass is resized.  This is called
  249.  * during the default creation method as well (create:in:).
  250.  */
  251.  
  252. - (void)resize:(NSEvent *)event by:(int)corner in:(GraphicView *)view;
  253.  
  254. /*
  255.  * Possible override candidate for different types of Graphics.
  256.  * Should return YES if the Graphic got created okay.
  257.  * The most common need to override this method is if the creation
  258.  * of the Graphic requires multiple mouseUps and mouseDowns (for
  259.  * an arbitrary arc, for example).
  260.  */
  261.  
  262. - (BOOL)create:(NSEvent *)event in:(GraphicView *)view;
  263.  
  264. /*
  265.  * Override hit: if you want your subclass to only get selected when the
  266.  * mouse goes down in certain parts of the bounds (not the whole bounds).
  267.  * e.g. Lines only get selected if you click close to them.
  268.  */
  269.  
  270. - (BOOL)hit:(NSPoint)point;
  271.  
  272. /*
  273.  * Returns YES if this Graphic can't be seen through.
  274.  * Default behaviour is to return YES if the Graphic isFilled.
  275.  */
  276.  
  277. - (BOOL)isOpaque;
  278.  
  279. /*
  280.  * Returns YES if the Graphic is properly formed (usually this just
  281.  * refers to whether it is big enough to be a real graphic during creation).
  282.  * This is called by create:in:.  By default it returns YES if the Graphic
  283.  * is at least 10.0 by 10.0 pixels in size.
  284.  */
  285.  
  286. - (BOOL)isValid;
  287.  
  288. /*
  289.  * This is the Graphic's natural aspect ratio.  If it doesn't have a natural
  290.  * aspect ratio, then this method should return zero (the default return).
  291.  */
  292.  
  293. - (float)naturalAspectRatio;
  294.  
  295. /*
  296.  * Called repeatedly as the user drags the mouse to create or resize
  297.  * the Graphic.  The default implementation does the right thing.
  298.  * The specified corner should be moved to the specified point.
  299.  */
  300.  
  301. - (int)moveCorner:(int)corner to:(NSPoint)point constrain:(BOOL)flag;
  302.  
  303. /*
  304.  * This routine actually draws the graphic.  It should be draw to fit the
  305.  * bounds instance variable.  Be sure to use all the parameters listed in
  306.  * the instance variable list (e.g. linewidth, fillgray, etc.) that are
  307.  * appropriate to this object.  It is probably a good idea to do a newpath
  308.  * and a closepath at the beginning and the end of draw.
  309.  * If a sublcass just wants to draw a unit-sized version of itself
  310.  * (i.e. it draws itself in a bounding box of {{0.0,0.0},{1.0,1.0}})
  311.  * it can just override unitDraw (and not draw).
  312.  */
  313.  
  314. - (void)unitDraw;
  315. - draw;
  316.  
  317. /*
  318.  * Should return YES iff the Graphic can be "edited."  It is up to the
  319.  * subclass of Graphic to determine what this means for it.  Usually
  320.  * it means that it has text and allows that text to be edited by the
  321.  * user (e.g. TextGraphic).  Default is to do nothing and return NO.
  322.  */
  323.  
  324. - (BOOL)edit:(NSEvent *)event in:(NSView *)view;
  325.  
  326. @end
  327.