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 / GLUE.C next >
C/C++ Source or Header  |  1980-01-05  |  5KB  |  196 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.  * Special glue for demonstration purposes.
  25.  * Unlike normal glue, we display the glue shape and actual size
  26.  * when a button is clicked.
  27.  */
  28.  
  29. #include <InterViews/interactor.h>
  30. #include <InterViews/sensor.h>
  31. #include <InterViews/shape.h>
  32. #include <InterViews/painter.h>
  33. #include <stdio.h>
  34.  
  35. class Glue : public Interactor {
  36. protected:
  37.     Glue();
  38.     Glue(const char*);
  39.     Glue(Painter* bg);
  40.  
  41.     virtual void Redraw(Coord, Coord, Coord, Coord);
  42. private:
  43.     void Init();
  44. };
  45.  
  46. class HGlue : public Glue {
  47. public:
  48.     HGlue(int natural = 0, int stretch = hfil);
  49.     HGlue(const char*, int natural = 0, int stretch = hfil);
  50.     HGlue(int natural, int shrink, int stretch);
  51.     HGlue(const char*, int natural, int shrink, int stretch);
  52.     HGlue(Painter* bg, int natural = 0, int stretch = hfil);
  53.     HGlue(Painter* bg, int natural, int shrink, int stretch);
  54.  
  55.     virtual void Handle(Event&);
  56. private:
  57.     void Init(int nat, int shrink, int stretch);
  58. };
  59.  
  60. class VGlue : public Glue {
  61. public:
  62.     VGlue(int natural = 0, int stretch = vfil);
  63.     VGlue(const char*, int natural = 0, int stretch = vfil);
  64.     VGlue(int natural, int shrink, int stretch);
  65.     VGlue(const char*, int natural, int shrink, int stretch);
  66.     VGlue(Painter* bg, int natural = 0, int stretch = vfil);
  67.     VGlue(Painter* bg, int natural, int shrink, int stretch);
  68.  
  69.     virtual void Handle(Event&);
  70. private:
  71.     void Init(int nat, int shrink, int stretch);
  72. };
  73.  
  74. Glue::Glue () {
  75.     Init();
  76. }
  77.  
  78. Glue::Glue (const char* name) {
  79.     SetInstance(name);
  80.     Init();
  81. }
  82.  
  83. Glue::Glue (Painter* bg) : (nil, bg) {
  84.     Init();
  85. }
  86.  
  87. void Glue::Init () {
  88.     SetClassName("Glue");
  89.     input = updownEvents;
  90.     input->Reference();
  91. }
  92.  
  93. void Glue::Redraw (Coord x1, Coord y1, Coord x2, Coord y2) {
  94.     output->ClearRect(canvas, x1, y1, x2, y2);
  95. }
  96.  
  97. HGlue::HGlue (int nat, int str) {
  98.     Init(nat, nat, str);
  99. }
  100.  
  101. HGlue::HGlue (const char* name, int nat, int str) : (name) {
  102.     Init(nat, nat, str);
  103. }
  104.  
  105. HGlue::HGlue (int nat, int shr, int str) {
  106.     Init(nat, shr, str);
  107. }
  108.  
  109. HGlue::HGlue (const char* name, int nat, int shr, int str) : (name) {
  110.     Init(nat, shr, str);
  111. }
  112.  
  113. HGlue::HGlue (Painter* bg, int nat, int str) : (bg) {
  114.     Init(nat, nat, str);
  115. }
  116.  
  117. HGlue::HGlue (Painter* bg, int nat, int shr, int str) : (bg) {
  118.     Init(nat, shr, str);
  119. }
  120.  
  121. void HGlue::Init (int nat, int shr, int str) {
  122.     SetClassName("HGlue");
  123.     shape->width = nat;
  124.     shape->height = 0;
  125.     shape->Rigid(shr, str, vfil, vfil);
  126. }
  127.  
  128. VGlue::VGlue (int nat, int str) {
  129.     Init(nat, nat, str);
  130. }
  131.  
  132. VGlue::VGlue (const char* name, int nat, int str) : (name) {
  133.     Init(nat, nat, str);
  134. }
  135.  
  136. VGlue::VGlue (int nat, int shr, int str) {
  137.     Init(nat, shr, str);
  138. }
  139.  
  140. VGlue::VGlue (const char* name, int nat, int shr, int str) : (name) {
  141.     Init(nat, shr, str);
  142. }
  143.  
  144. VGlue::VGlue (Painter* bg, int nat, int str) : (bg) {
  145.     Init(nat, nat, str);
  146. }
  147.  
  148. VGlue::VGlue (Painter* bg, int nat, int shr, int str) : (bg) {
  149.     Init(nat, shr, str);
  150. }
  151.  
  152. void VGlue::Init (int nat, int shr, int str) {
  153.     SetClassName("VGlue");
  154.     shape->width = 0;
  155.     shape->height = nat;
  156.     shape->Rigid(hfil, hfil, shr, str);
  157. }
  158.  
  159. /*
  160.  * Differences from standard glue -- handle events differently.
  161.  */
  162.  
  163. void HGlue::Handle (Event& e) {
  164.     if (e.eventType == DownEvent) {
  165.     char buf[100];
  166.  
  167.     sprintf(
  168.         buf, "HGlue[%d], natural (%d,%d,%d)",
  169.         xmax+1, shape->width, shape->hstretch, shape->hshrink
  170.     );
  171.     output->SetColors(output->GetBgColor(), output->GetFgColor());
  172.     output->ClearRect(canvas, 0, 0, xmax, ymax);
  173.     output->Text(canvas, buf, 0, 0);
  174.     output->SetColors(output->GetBgColor(), output->GetFgColor());
  175.     } else if (e.eventType == UpEvent) {
  176.     Draw();
  177.     }
  178. }
  179.  
  180. void VGlue::Handle (Event& e) {
  181.     if (e.eventType == DownEvent) {
  182.     char buf[100];
  183.  
  184.     sprintf(
  185.         buf, "VGlue[%d], natural (%d,%d,%d)",
  186.         ymax+1, shape->height, shape->vstretch, shape->vshrink
  187.     );
  188.     output->SetColors(output->GetBgColor(), output->GetFgColor());
  189.     output->ClearRect(canvas, 0, 0, xmax, ymax);
  190.     output->Text(canvas, buf, 0, 0);
  191.     output->SetColors(output->GetBgColor(), output->GetFgColor());
  192.     } else if (e.eventType == UpEvent) {
  193.     Draw();
  194.     }
  195. }
  196.