home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / AppKit / Draw / Graphic.h < prev    next >
Text File  |  1992-07-20  |  9KB  |  309 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 : Object
  50. {
  51.     NXRect bounds;            /* the bounds */
  52.     float linewidth;            /* linewidth */
  53.     struct _gFlags {
  54.     unsigned int selected:1;    /* whether selected */
  55.     unsigned int active:1;        /* whether to really draw in draw: */
  56.     unsigned int eofill:1;        /* whether eofilled */
  57.     unsigned int fillColorSet:1;    /* whether to put frame around fill */
  58.     unsigned int downhill:1;    /* Line: direction line goes */
  59.     unsigned int initialized:1;    /* subclass specific */
  60.     unsigned int linewidthSet:1;    /* used when archiving only */
  61.     unsigned int lineColorSet:1;    RWsed when archiving only */
  62.     unsigned int linejoin:2;    /* line join */
  63.     unsigned int linecap:2;        /* line cap */
  64.     unsigned int fill:1;        /* whether filled */
  65.     unsigned int locked:1;        /* locked down? */
  66.     unsigned int arrow:2;        /* arrow position */
  67.     unsigned int nooutline:1;    /* whether the graphic is outlined */
  68.     unsigned int isFormEntry:1;    /* whether the graphic is a form entry (TextGraphic only) */
  69.     unsigned int localizeFormEntry:1; /* whether to localize a form entry (TextGraphic only) */
  70.     unsigned int mightBeLinked:1;    /* set if Graphic has ever had a link associated with it */
  71.     unsigned int padding:12;
  72.     } gFlags;
  73.     NXColor *lineColor;
  74.     NXColor *fillColor;
  75.     int identifier;            /* unique identifier */
  76. }
  77.  
  78. /* Factory methods */
  79.  
  80. + showFastKnobFills;
  81. + initialize;
  82. + (BOOL)isEditable;
  83. + cursor;
  84.  
  85. + (int)currentGraphicIdentifier;
  86. + updateCurrentGraphicIdentifier:(int)newMaxIdentifier;
  87.  
  88. /* Initialization method */
  89.  
  90. - init;
  91.  
  92. /* Called when a GraphicView is unarchived */
  93.  
  94. - awake;
  95.  
  96. /* Private methods (for subclassers only) */
  97.  
  98. - setGraphicsState;
  99. - setLineColor;
  100. - setFillColor;
  101. - (int)cornerMask;
  102.  
  103. /* Data link methods */
  104.  
  105. - setLink:(NXDataLink *)aLink;
  106. - (NXDataLink *)link;
  107. - (Graphic *)graphicLinkedBy:(NXDataLink *)aLink;
  108. - reviveLink:(NXDataLinkManager *)linkManager;
  109. - (NXSelection *)selection;
  110. - (BOOL)mightBeLinked;
  111.  
  112. /* Notification from GraphicView */
  113.  
  114. - wasRemovedFrom:(GraphicView *)sender;
  115. - wasAddedTo:(GraphicView *)sender;
  116.  
  117. /* Methods for uniquely identifying a Graphic. */
  118.  
  119. - resetIdentifier;
  120. - (int)identifier;
  121. - writeIdentifierTo:(char *)buffer;
  122. - (Graphic *)graphicIdentifiedBy:(int)anIdentifier;
  123.  
  124. /* Event handling */
  125.  
  126. - (BOOL)handleEvent:(NXEvent *)event at:(const NXPoint *)p inView:(View *)view;
  127.  
  128. /* Number of Graphics this Graphic represents (1 for non-Group). */
  129.  
  130. - (int)graphicCount;
  131.  
  132. /* Public routines (called mostly by a GraphicView or subclassers). */
  133.  
  134. - (const char *)title;
  135. - (BOOL)isSelected;
  136. - (BOOL)isActive;
  137. - (BOOL)isLocked;
  138. - select;
  139. - deselect;
  140. - activate;
  141. - deactivate;
  142. - lock;
  143. - unlock;
  144.  
  145. - (BOOL)isFormEntry;
  146. - setFormEntry:(int)flag;
  147. - (BOOL)hasFormEntries;
  148. - (BOOL)writeFormEntryToStream:(NXStream *)stream;
  149.  
  150. - setCacheable:(BOOL)flag;
  151. - (BOOL)isCacheable;
  152.  
  153. - getBounds:(NXRect *)theRect;
  154. - setBounds:(const NXRect *)aRect;
  155. - (NXRect *)getExtendedBounds:(NXRect *)theRect;
  156.  
  157. - (int)knobHit:(coRW    NXPoint *)point;
  158.  
  159. - draw:(const NXRect *)rect;
  160.  
  161. - (BOOL)canEmitEPS;
  162. - (BOOL)canEmitTIFF;
  163.  
  164. - moveLeftEdgeTo:(const NXCoord *)x;
  165. - moveRightEdgeTo:(const NXCoord *)x;
  166. - moveTopEdgeTo:(const NXCoord *)y;
  167. - moveBottomEdgeTo:(const NXCoord *)y;
  168. - moveHorizontalCenterTo:(const NXCoord *)x;
  169. - moveVerticalCenterTo:(const NXCoord *)y;
  170. - moveBaselineTo:(const NXCoord *)y;
  171. - (NXCoord)baseline;
  172.  
  173. - moveBy:(const NXPoint *)offset;
  174. - moveTo:(const NXPoint *)p;
  175. - centerAt:(const NXPoint *)center;
  176. - sizeTo:(const NXSize *)size;
  177. - sizeToNaturalAspectRatio;
  178. - alignToGrid:(GraphicView *)graphicView;
  179. - sizeToGrid:(GraphicView *)graphicView;
  180.  
  181. /* Compatibility methods */
  182.  
  183. - replaceWithImage;
  184.  
  185. /* Public routines (called mostly by inspectors and the like). */
  186.  
  187. - setLineWidth:(const float *)value;
  188. - (float)lineWidth;
  189. - setLineColor:(const NXColor *)color;
  190. - (Graphic *)colorAcceptorAt:(const NXPoint *)point;
  191. - (NXColor)lineColor;
  192. - setFillColor:(const NXColor *)color;
  193. - (NXColor)fillColor;
  194. - changeFont:sender;
  195. - (Font *)font;
  196. - setGray:(const float *)value;
  197. - (float)gray;
  198. - setFill:(int)mode;
  199. - (int)fill;
  200. - setOutlined:(BOOL)outlinedFlag;
  201. - (BOOL)isOutlined;
  202. - setLineCap:(int)capValue;
  203. - (int)lineCap;
  204. - setLineArrow:(int)arrowValue;
  205. - (int)lineArrow;
  206. - setLineJoin:(int)joinValue;
  207. - (int)lineJoin;
  208.  
  209. /* Archiving (must be overridden by subclasses with instance variables) */
  210.  
  211. - write:(NXTypedStream *)stream;
  212. - read:(NXTypedStream *)stream;
  213.  
  214. /* Routines intended to be subclassed for different types of Graphics. */
  215.  
  216. /*
  217.  * Can be overridden to provide more sophisticated size constraining
  218.  * than an aspect ratio (though that is almost always sufficient).
  219.  * For example, Line overrides this to constrain to closes 15 degree angle.
  220.  * constrainByDefault says whether constraining is the default or not for
  221.  * the receiving kind of Graphic.
  222.  */
  223.  
  224. - (BOOL)constrainByDefault;
  225. - constrainCorner:(int)corner toAspectRatio:(float)aspect;
  226.  
  227. /*
  228.  * Can be overridden to resize the Graphic differently than the
  229.  * default (which is to drag out the bounds), or to do something
  230.  * before and/or after the subclass is resized.  This is called
  231.  * during the default creation method as well (create:in:).
  232.  */
  233.  
  234. - resize:(NXEvent *)event by:(int)corner in:(GraphicView *)view;
  235.  
  236. /*
  237.  * Possible override candidate for different types of Graphics.
  238.  * Should return YES if the GRWic got created okay.
  239.  * The most common need to override this method is if the creation
  240.  * of the Graphic requires multiple mouseUps and mouseDowns (for
  241.  * an arbitrary arc, for example).
  242.  */
  243.  
  244. - (BOOL)create:(NXEvent *)event in:(GraphicView *)view;
  245.  
  246. /*
  247.  * Override hit: if you want your subclass to only get selected when the
  248.  * mouse goes down in certain parts of the bounds (not the whole bounds).
  249.  * e.g. Lines only get selected if you click close to them.
  250.  */
  251.  
  252. - (BOOL)hit:(const NXPoint *)point;
  253.  
  254. /*
  255.  * Returns YES if this Graphic can't be seen through.
  256.  * Default behaviour is to return YES if the Graphic isFilled.
  257.  */
  258.  
  259. - (BOOL)isOpaque;
  260.  
  261. /*
  262.  * Returns YES if the Graphic is properly formed (usually this just
  263.  * refers to whether it is big enough to be a real graphic during creation).
  264.  * This is called by create:in:.  By default it returns YES if the Graphic
  265.  * is at least 10.0 by 10.0 pixels in size.
  266.  */
  267.  
  268. - (BOOL)isValid;
  269.  
  270. /*
  271.  * This is the Graphic's natural aspect ratio.  If it doesn't have a natural
  272.  * aspect ratio, then this method should return zero (the default return).
  273.  */
  274.  
  275. - (float)naturalAspectRatio;
  276.  
  277. /*
  278.  * Called repeatedly as the user drags the mouse to create or resize
  279.  * the Graphic.  The default implementation does the right thing.
  280.  * The specified corner should be moved to the specified point.
  281.  */
  282.  
  283. - (int)moveCorner:(int)corner to:(const NXPoint *)point constrain:(BOOL)flag;
  284.  
  285. /*
  286.  * This routine actually draws the graphic.  It should be draw to fit the
  287.  * bounds instance variable.  Be sure to use all the parameters listed in
  288.  * the instance variable list (e.g. linewidth, fillgray, etc.) that are
  289.  * appropriate to this object.  It is probably a good idea to do a newpath
  290.  * and a closepath at the beginning and the end of draw.
  291.  * If a sublcass just wants to draw a unit-sized version of itself
  292.  * (i.e. it draws itself in a bounding box of {{0.0,0.0},{1.0,1.0}})
  293.  * it can just override unitDraw (and not draw).
  294.  */
  295.  
  296. - unitDraw;
  297. - draw;
  298.  
  299. /*
  300.  * Should return YES iff the Graphic can be "edited."  It is up to the
  301.  * subclass of Graphic to determine what this means for it.  Usually
  302.  * it means that it has text and allows that text to be edited by the
  303.  * user (e.g. TextGraphic).  Default is to do nothing and return NO.
  304.  */
  305.  
  306. - (BOOL)edit:(NXEvent *)event in:(View *)view;
  307.  
  308. @end
  309.