/**** * * Class IdrawInterface is a View class that defines a programmatic interface * to the full idraw editor. IdrawInterface provides public functions that * correspond one-for-one with the functions that are accesible to the idraw * end user through the command menus and drawing tools palette. * * IdrawInterface provides two categories of functions -- output and input. * Output functions modify the drawing area and/or set some value in the * drawing state. For example, the DrawRect output function draws a rectangle * on the drawing area. It is the output functions that correspond one-for-one * to the end-user menu and tool palette commands. * * IdrawInterface input functions provide the means to track user mouse * movements with a transient shape that follows the user's input. For * example, TrackRectangle follows the user's movement with a growing/shrinking * rectangle as the user moves the mouse. These input functions provide * programmatic access to the range of input gestures that the end user can * perform in an idraw edit window. Input functions produce no drawing output. * Rather, the transient shapes disappear when the user releases the mouse * button. To provide programmatic feedback, the tracking input functions * return the location and size of the finished tracked shape when the user * completes the input. * * From the external UI perspective, an instance of IdrawInterface differs from * and instance if Idraw in that the IdrawInterface window does not include an * attached menubar and drawing tools palette. Otherwise, an IdrawInterface * behaves exactly the same as an Idraw in that calls to public IdrawInterface * functions perform the same operations as user-invoked menu and tool palette * functions. * */ #ifndef idrawinterfaceIncluded #define idrawinterfaceIncluded #include "drawing.h" #include "idraw.h" #include "editor.h" #include "selection.h" #include "listselectn.h" #include "view.h" #include class Editor; class Selection; class SelectionList; class IdrawInterface : public Idraw { public: /** * Functions to interface to underlying idraw support layer. */ IdrawInterface(Screen* s); IdrawInterface(Screen* s, int argc, char** argv); virtual ~IdrawInterface(); void Show(); void Run(); void Handle(Event&); void Update(); Drawing* GetDrawing(); /** * Tool palette functions. */ void Select(Selection* s); void SelectMultiple(SelectionList* sl); void Unselect(Selection* s); void UnselectMultiple(SelectionList* s); void Move(Coord l, Coord b); void Move(Selection* s, Coord l, Coord b); void Scale(float factor); void Scale(Selection* s, float factor); void Stretch(Alignment side, float amount); void Stretch(Selection* s, Alignment side, float amount); void Rotate(float degrees); void Rotate(Selection* s, float radians); void Reshape(Coord x0, Coord y0, Coord x1, Coord y1); void Reshape(Selection* s, Coord x0, int index, Coord y0, Coord x1, Coord y1); void Magnify(Coord x0, Coord y0, Coord x1, Coord y1); void Magnify(Selection* s, Coord x0, Coord y0, Coord x1, Coord y1); Selection* DrawText(Coord l, Coord b, char* text); Selection* DrawLine(Coord x0, Coord y0, Coord x1, Coord y1); Selection* DrawMultiLine(Coord* x, Coord* y, int n); Selection* DrawOpenSpline(Coord* x, Coord* y, int n); Selection* DrawEllipse(Coord cx, Coord cy, Coord xr, Coord yr); Selection* DrawRect(Coord l, Coord b, Coord r, Coord t); Selection* DrawPolygon(Coord* x, Coord* y, int n); Selection* DrawClosedSpline(Coord* x, Coord* y, int n); /** * File menu functions. */ void FileNew(int width, int height, int x, int y); void FileRevert(); void FileOpen(const char* filename); void FileSave(); void FileSaveAs(char* filenname); void FilePrint(char* command); void FileQuit(); /** * Edit menu functions. */ void EditUndo(); void EditRedo(); void EditCut(); void EditCopy(); void EditPaste(); void EditDuplicate(); void EditDelete(); void EditSelectAll(); void EditUnselectAll(); void EditFlipHorizontal(); void EditFlipVertical(); void Edit90Clockwise(); void Edit90CounterClockwise(); void EditPreciseMove(int x, int y); void EditPreciseScale(float factor); void EditPreciseRotate(float degrees); /** * Structure menu functions. */ Selection* StructureGroup(); Selection* StructureUngroup(); void StructureBringToFront(); void StructureSendToBack(); int StructureNumberOfGraphics(); /** * Font menu function. */ void FontSelect(int fontnumber); /** * Brush menu function. */ void BrushSelect(int brushnumber); /** * Pattern menu function. */ void PatternSelect(int patternhnumber); /** * Foreground color menu function. */ void FgColorSelect(int colornnumber); /** * Background color menu function. */ void BgColorSelect(int colornnumber); /** * Align menu functions. */ void AlignLeftSides(); void AlignRightSides(); void AlignBottoms(); void AlignTops(); void AlignVertCenters(); void AlignHorizCenters(); void AlignCenters(); void AlignLeftToRight(); void AlignRightToLeft(); void AlignBottomToTop(); void AlignTopToBottom(); void AlignToGrid(); /** * Option menu functions. */ void OptionReduce(); void OptionEnlarge(); void OptionNormalSize(); void OptionReduceToFit(); void OptionShrinkWrap(); void OptionCenterPage(); void OptionRedrawPage(); void OptionGriddingOnOff(bool on); void OptionGridVisibleInvisible(bool visible); void OptionGridSpacing(int gridsize); void OptionOrientation(); /** * Low-level text editing functions. */ void TextInsert(char* text); void TextSelect(int starpos, int endpos); void TextDelete(); void TextForwardChar(); void TextBackwardChar(); void TextNextLine(); void TextPreviousLine(); void TextBeginningOfLine(); void TextEndOfLine(); void TextBeginningOfText(); void TextEndOfText(); void TextPutCursor(int charpos); /** * User input functions. * * The first five functions below track the effects of an operation on an * existing Selection. These five functions provide exactly the same kind * of input feedback as the Move, Scale, Stretch, Rotate, and Reshape * commands on the idraw tool palette. The functions wait for a left mouse * click. If the click occurs on an existing selection, the tracking * commences and continues until the left mouse is released by the user. * The affected Selection is returned as the function return value; the * size and location of the tracked rectangle is returned in the l,b,r,t * reference parameters. If the left mouse click occurs outside of any * selection, no tracking is performed and NULL is returned. * * The last four functions below track a new transient object of changing * size. These four functions provide exactly the same kind of input * feedback as the Line, MultiLine, Ellipse, and Rectangle commands on the * idraw tool palette. (Note that the multiline-style input tracking is * also used for input of b-spline and polygon shapes.) The functions wait * for a left mouse down click anywhere in the drawing area. The tracking * commences and continues until the left mouse is release, or in the case * of the multiline, until the middle mouse is clicked after a series of * left mouse clicks. The size and location of the tracked shape is * returned in the reference parameters. TrackLine returns the x0,x1, * y0,y1 start- and end-point coordinates. TrackRectangle returns the * l,b,r,t coordinates that define the extent of the rectangle. * TrackEllipse return the cx,cy, xr,yr coordinates that define center and * radius of the ellipse. TrackMultiLine returns two arrays of x,y * coordinates and an integer that defines the number of points in the * arrays. * * The constrained flag specifies a shape-specific movement constraint. * For line and multiline, constrained = true constrains tracking to * horizontal and vertical lines only. For ellipse, constrained = true * contrains tracking to circular shape only. For rectangle, constrained = * true constrains tracking to a square shape. */ Selection* TrackMove(Coord& l, Coord& b, Coord& r, Coord& t); Selection* TrackScale(Coord& l, Coord& b, Coord& r, Coord& t); Selection* TrackStretch(Coord& l, Coord& b, Coord& r, Coord& t); Selection* TrackRotate(Coord& l, Coord& b, Coord& r, Coord& t); Selection* TrackReshape(Coord& l, Coord& b, Coord& r, Coord& t); void TrackLine(Coord& x0, Coord& x1, Coord& y0, Coord& y1, bool constrained = false); void TrackMultiLine(Coord*& x, Coord*& y, int& n, bool constrained = false); void TrackEllipse(Coord& cx, Coord& cy, Coord& rx, Coord& ry, bool constrained = false); void TrackRectangle(Coord& l, Coord& b, Coord& r, Coord& t, bool constrained = false); /* * The WaitForLeftMouseDown function wait until the user clicks the left * mouse down somewhere in the drawing area, and then returns the * InterViews Event structure that shows where the event occurred. See the * InterViews reference manual for further information about the Event * class. */ void WaitForLeftMouseDown(Event& e); protected: void ParseArgs(int, char**); void Init(); Screen* s; // screen used by Show friend class Editor; // bad style -- so sue me }; #endif