home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / i / iv26_w_3.zip / EXAMPLES / IDRAW / IDRAW.C < prev    next >
C/C++ Source or Header  |  1992-01-17  |  6KB  |  190 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. // $Header: idraw.c,v 1.13 89/10/09 14:48:08 linton Exp $
  24. // implements class Idraw.
  25.  
  26. #include "commands.h"
  27. #include "drawing.h"
  28. #include "drawingview.h"
  29. #include "editor.h"
  30. #include "errhandler.h"
  31. #include "idraw.h"
  32. #include "istring.h"
  33. #include "mapkey.h"
  34. #include "state.h"
  35. #include "stateviews.h"
  36. #include "tools.h"
  37. #include <InterViews/Graphic/ppaint.h>
  38. #include <InterViews/border.h>
  39. #include <InterViews/box.h>
  40. #include <InterViews/cursor.h>
  41. #include <InterViews/event.h>
  42. #include <InterViews/frame.h>
  43. #include <InterViews/glue.h>
  44. #include <InterViews/panner.h>
  45. #include <InterViews/perspective.h>
  46. #include <InterViews/sensor.h>
  47. #include <InterViews/transformer.h>
  48. #include <InterViews/tray.h>
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51.  
  52. // Idraw parses its command line and initializes its members.
  53.  
  54. Idraw::Idraw (int argc, char** argv) {
  55.     ParseArgs(argc, argv);
  56.     InitPPaint();        // I keep forgetting to call this....
  57.     Init();
  58. }
  59.  
  60. // Free storage allocated for members not in Idraw's scene.
  61.  
  62. Idraw::~Idraw () {
  63.     delete drawing;
  64.     delete editor;
  65.     delete errhandler;
  66.     delete mapkey;
  67.     delete state;
  68. }
  69.  
  70. // Run opens the initial file if one was given before starting to run.
  71.  
  72. void Idraw::Run () {
  73.     if (initialfile != nil) {
  74.     SetCursor(hourglass);
  75. //    editor->Open(initialfile);
  76.     SetCursor(defaultCursor);
  77.     }
  78.  
  79.     Interactor::Run();
  80. }
  81.  
  82. // Handle routes keystrokes to their associated interactors.
  83.  
  84. void Idraw::Handle (Event& e) {
  85.     switch (e.eventType) {
  86.     case KeyEvent:
  87.     if (e.len > 0) {
  88.         Interactor* i = mapkey->LookUp(e.keystring[0]);
  89.         if (i != nil) {
  90.         i->Handle(e);
  91.         }
  92.     }
  93.     break;
  94.     default:
  95.     break;
  96.     }
  97. }
  98.  
  99. // Update gets the picture's total tranformation matrix whenever it
  100. // changes and stores it in State for creating new graphics.
  101.  
  102. void Idraw::Update () {
  103.     Transformer t;
  104.     drawing->GetPictureTT(t);
  105.     state->SetGraphicT(t);
  106. }
  107.  
  108. // ParseArgs stores the name of an initial file to open if any.
  109.  
  110. void Idraw::ParseArgs (int argc, char** argv) {
  111.     initialfile    = nil;
  112.     if (argc == 2) {
  113.     initialfile = argv[1];
  114.     } else if (argc > 2) {
  115.     fprintf(stderr, "too many arguments, usage: idraw [file]\n");
  116.     const int PARSINGERROR = 1;
  117.     exit(PARSINGERROR);
  118.     }
  119. }
  120.  
  121. // Init creates a sensor to catch keystrokes, creates members and
  122. // initializes links between them, and composes them into a view with
  123. // boxes, borders, glue, and frames.
  124.  
  125. void Idraw::Init () {
  126.     input = new Sensor;
  127.     input->Catch(KeyEvent);
  128.  
  129.     drawing    = new Drawing(8.5*inches, 11*inches, 0.05*inch);
  130.     drawingview    = new DrawingView(drawing->GetPage());
  131.     editor    = new Editor(this);
  132.     errhandler    = new ErrHandler;
  133.     mapkey    = new MapKey;
  134.     state    = new State(this, drawing->GetPage());
  135.     tools    = new Tools(editor, mapkey);
  136.  
  137.     drawingview->GetPerspective()->Attach(this);
  138.     drawingview->SetSelectionList(drawing->GetSelectionList());
  139.     drawingview->SetState(state);
  140.     drawingview->SetTools(tools);
  141.     editor->SetDrawing(drawing);
  142.     editor->SetDrawingView(drawingview);
  143.     editor->SetState(state);
  144.     errhandler->SetEditor(editor);
  145.     errhandler->Install();
  146.  
  147.     VBox* status = new VBox(
  148.         new HBox(
  149.             new ModifStatusView(state),
  150.             new DrawingNameView(state),
  151.             new GriddingView(state),
  152.             new FontView(state),
  153.             new MagnifView(state, drawingview)
  154.         ),
  155.         new HBorder
  156.     );
  157.     HBox* indics = new HBox(
  158.         new BrushView(state),
  159.         new VBorder,
  160.         new PatternView(state)
  161.     );
  162.     HBox* cmds = new HBox(
  163.         new Commands(editor, mapkey, state),
  164.         new HGlue
  165.     );
  166.     VBox* panel = new VBox(
  167.         tools,
  168.         new VGlue,
  169.         new HBorder,
  170.         new Panner(drawingview)
  171.     );
  172.     panel->Propagate(false);
  173.  
  174.     HBorder* hborder = new HBorder;
  175.     VBorder* vborder = new VBorder;
  176.  
  177.     Tray* t = new Tray;
  178.  
  179.     t->HBox(t, status, t);
  180.     t->HBox(t, indics, vborder, cmds, t);
  181.     t->HBox(t, hborder, t);
  182.     t->HBox(t, panel, vborder, drawingview, t);
  183.  
  184.     t->VBox(t, status, indics, hborder, panel, t);
  185.     t->VBox(t, status, vborder, t);
  186.     t->VBox(t, status, cmds, hborder, drawingview, t);
  187.  
  188.     Insert(new Frame(t, 1));
  189. }
  190.