home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / intrvews / xgrab.lha / xgrab / ui / myadjuster.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-24  |  5.4 KB  |  195 lines

  1. /**
  2.    GRAB Graph Layout and Browser System
  3.  
  4.    Copyright (c) 1987, 1988, 1989 Stanford University
  5.    Copyright (c) 1989, Tera Computer Company
  6.  **/
  7.  
  8.   /**
  9.      Nearly a direct ripoff of the InterViews 2.5 source for adjusters.
  10.      However, these adjusters have adjustable zoom factors 
  11.    **/
  12.  
  13. #include "myadjuster.h"
  14. #include <InterViews/adjuster.h>
  15. #include <InterViews/bitmap.h>
  16. #include <InterViews/painter.h>
  17. #include <InterViews/perspective.h>
  18. #include <InterViews/sensor.h>
  19. #include <InterViews/shape.h>
  20. #include <stdio.h>
  21.  
  22. MyZoomer::MyZoomer (Interactor* i, float f) : (i, NO_AUTOREPEAT) 
  23. {
  24.     Init(f);
  25. }
  26.  
  27. MyZoomer::MyZoomer (const char* name, Interactor* i, float f) 
  28.     : (name, i, NO_AUTOREPEAT) 
  29. {
  30.     Init(f);
  31. }
  32.  
  33. MyZoomer::MyZoomer (Interactor* i, float f, Painter* p) 
  34.     : (i, NO_AUTOREPEAT, p) 
  35. {
  36.     Init(f);
  37. }
  38.  
  39. void MyZoomer::Init (float f) 
  40. {
  41.     SetClassName("MyZoomer");
  42.     factor = f;
  43. }
  44.  
  45. void MyZoomer::AdjustView (Event&) 
  46. {
  47.     register Perspective* s = shown;
  48.     Coord cx, cy;
  49.  
  50.     *s = *view->GetPerspective();
  51.     cx = s->curx + s->curwidth/2;
  52.     cy = s->cury + s->curheight/2;
  53.     s->curwidth = round(float(s->curwidth) / factor);
  54.     s->curheight = round(float(s->curheight) / factor);
  55.     s->curx = cx - s->curwidth/2;
  56.     s->cury = cy - s->curheight/2;
  57.     view->Adjust(*s);    
  58. }
  59.  
  60. static const int enl_width = 25;
  61. static const int enl_height = 15;
  62. static unsigned char enl_mask[] = 
  63. {
  64.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
  65.    0x00, 0xfe, 0x00, 0x00, 0xc0, 0xff, 0x07, 0x00, 0xf0, 0xff, 0x1f, 0x00,
  66.    0xf0, 0xff, 0x1f, 0x00, 0xf8, 0xff, 0x3f, 0x00, 0xf8, 0xff, 0x3f, 0x00,
  67.    0xf8, 0xff, 0x3f, 0x00, 0xf8, 0xff, 0x3f, 0x00, 0xc0, 0xff, 0x07, 0x00,
  68.    0xc0, 0xff, 0x07, 0x00, 0xc0, 0xff, 0x07, 0x00, 0xc0, 0xff, 0x07, 0x00
  69. };
  70.  
  71. static unsigned char enl_plain[] = 
  72. {
  73.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74.    0x00, 0x38, 0x00, 0x00, 0x00, 0xc6, 0x00, 0x00, 0x80, 0x01, 0x03, 0x00,
  75.    0x60, 0x00, 0x0c, 0x00, 0x18, 0x00, 0x30, 0x00, 0xf8, 0x01, 0x3f, 0x00,
  76.    0x88, 0x00, 0x22, 0x00, 0x78, 0x00, 0x3c, 0x00, 0xc0, 0xff, 0x07, 0x00,
  77.    0x40, 0x00, 0x04, 0x00, 0x40, 0x00, 0x04, 0x00, 0xc0, 0xff, 0x07, 0x00
  78. };
  79.  
  80. static unsigned char enl_hit[] = 
  81. {
  82.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
  83.    0x00, 0xee, 0x00, 0x00, 0xc0, 0x01, 0x07, 0x00, 0x30, 0x00, 0x18, 0x00,
  84.    0xf0, 0x83, 0x1f, 0x00, 0x10, 0x01, 0x11, 0x00, 0xf0, 0xff, 0x1f, 0x00,
  85.    0x80, 0x00, 0x02, 0x00, 0x80, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  86.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  87. };
  88.  
  89. static Bitmap* enlMask;
  90. static Bitmap* enlPlain;
  91. static Bitmap* enlHit;
  92.  
  93. MyEnlarger::MyEnlarger (Interactor* i, float zg) : (i, zg) 
  94. {
  95.     Init();
  96. }
  97.  
  98. MyEnlarger::MyEnlarger (const char* name, Interactor* i, float zg) 
  99.     : (name, i, zg) 
  100. {
  101.     Init();
  102. }
  103.  
  104. MyEnlarger::MyEnlarger (Interactor* i, Painter* p, float zg) : (i, zg, p) 
  105. {
  106.     Init();
  107. }
  108.  
  109. void MyEnlarger::Init () 
  110. {
  111.     SetClassName("MyEnlarger");
  112.     if (enlMask == nil) {
  113.         enlMask = new Bitmap(enl_mask, enl_width, enl_height);
  114.         enlPlain = new Bitmap(enl_plain, enl_width, enl_height);
  115.         enlHit = new Bitmap(enl_hit, enl_width, enl_height);
  116.     }
  117.     mask = enlMask;
  118.     plain = enlPlain;
  119.     hit = enlHit;
  120.     shape->Rigid(shape->width/2, hfil, shape->height/2);
  121. }
  122.  
  123. void MyEnlarger::ChangeZGrad(float zg)
  124. {
  125.     factor = zg;
  126. }
  127.  
  128. static const int red_width = 25;
  129. static const int red_height = 15;
  130. static unsigned char red_mask[] = 
  131. {
  132.    0x00, 0x7c, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0xff, 0x01, 0x00,
  133.    0xf8, 0xff, 0x3f, 0x00, 0xf8, 0xff, 0x3f, 0x00, 0xff, 0xff, 0xff, 0x01,
  134.    0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x01, 0xff, 0xff, 0xff, 0x01,
  135.    0xfe, 0xff, 0xff, 0x00, 0xf8, 0xff, 0x3f, 0x00, 0xe0, 0xff, 0x0f, 0x00,
  136.    0x80, 0xff, 0x03, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00
  137. };
  138.  
  139. static unsigned char red_plain[] = 
  140. {
  141.    0x00, 0x7c, 0x00, 0x00, 0x00, 0x82, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
  142.    0xf8, 0x00, 0x3e, 0x00, 0x38, 0x00, 0x38, 0x00, 0xc8, 0x00, 0x26, 0x00,
  143.    0x08, 0x83, 0x21, 0x00, 0x30, 0x6c, 0x18, 0x00, 0xc0, 0x10, 0x06, 0x00,
  144.    0x00, 0x93, 0x01, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
  145.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  146. };
  147.  
  148. static unsigned char red_hit[] = 
  149. {
  150.    0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00,
  151.    0x80, 0x00, 0x02, 0x00, 0x40, 0x00, 0x04, 0x00, 0x3f, 0x00, 0xf8, 0x01,
  152.    0x07, 0x00, 0xc0, 0x01, 0x19, 0x00, 0x30, 0x01, 0x61, 0x00, 0x0c, 0x01,
  153.    0x86, 0x01, 0xc3, 0x00, 0x18, 0xc6, 0x30, 0x00, 0x60, 0x38, 0x0c, 0x00,
  154.    0x80, 0x11, 0x03, 0x00, 0x00, 0xd6, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00
  155. };
  156.  
  157. static Bitmap* redMask;
  158. static Bitmap* redPlain;
  159. static Bitmap* redHit;
  160.  
  161. MyReducer::MyReducer (Interactor* i, float zg) : (i, zg) 
  162. {
  163.     Init();
  164. }
  165.  
  166. MyReducer::MyReducer (const char* name, Interactor* i, float zg) : 
  167.     (name, i, zg) 
  168. {
  169.     Init();
  170. }
  171.  
  172. MyReducer::MyReducer (Interactor* i, Painter* p, float zg) : (i, zg, p) 
  173. {
  174.     Init();
  175. }
  176.  
  177. void MyReducer::Init () 
  178. {
  179.     SetClassName("MyReducer");
  180.     if (redMask == nil) {
  181.         redMask = new Bitmap(red_mask, red_width, red_height);
  182.         redPlain = new Bitmap(red_plain, red_width, red_height);
  183.         redHit = new Bitmap(red_hit, red_width, red_height);
  184.     }
  185.     mask = redMask;
  186.     plain = redPlain;
  187.     hit = redHit;
  188.     shape->Rigid(shape->width/2, hfil, shape->height/2);
  189. }
  190.  
  191. void MyReducer::ChangeZGrad(float zg)
  192. {
  193.     factor = zg;
  194. }
  195.