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 / SQUARES / VIEW.C < prev    next >
C/C++ Source or Header  |  1980-01-05  |  2KB  |  66 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. /*
  24.  * Implementation of squares view.
  25.  */
  26.  
  27. #include "squares.h"
  28. #include "view.h"
  29. #include <InterViews/painter.h>
  30. #include <InterViews/sensor.h>
  31. #include <InterViews/shape.h>
  32.  
  33. SquaresView::SquaresView (Squares* s) {
  34.     subject = s;
  35.     subject->Attach(this);
  36.     shape->width = 200;
  37.     shape->height = 200;
  38.     shape->hunits = 20;
  39.     shape->vunits = 20;
  40. }
  41.  
  42. SquaresView::~SquaresView () {
  43.     subject->Detach(this);
  44. }
  45.  
  46. void SquaresView::Redraw (Coord x1, Coord y1, Coord x2, Coord y2) {
  47.     register SquareData* s;
  48.     Coord x, y;
  49.     int w, h;
  50.  
  51.     output->ClearRect(canvas, x1, y1, x2, y2);
  52.     for (s = subject->Head(); s != nil; s = s->next) {
  53.         w = round(xmax * s->size) / 2;
  54.         h = round(ymax * s->size) / 2;
  55.         x = round(xmax * s->cx);
  56.         y = round(ymax * s->cy);
  57.         if (x1 <= x + w && x2 >= x - w && y1 <= y + h && y2 >= y - h) {
  58.             output->Rect(canvas, x - w, y - h, x + w, y + h);
  59.         }
  60.     }
  61. }
  62.  
  63. void SquaresView::Update () {
  64.     Draw();
  65. }
  66.