"Fossies" - the Fresh Open Source Software Archive

Member "ivtools-ivtools-2.0.4/src/IV-2_6/adjuster2_6.c" (9 Oct 2020, 11881 Bytes) of package /linux/misc/ivtools-ivtools-2.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "adjuster2_6.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 1987, 1988, 1989, 1990, 1991 Stanford University
    3  * Copyright (c) 1991 Silicon Graphics, Inc.
    4  *
    5  * Permission to use, copy, modify, distribute, and sell this software and 
    6  * its documentation for any purpose is hereby granted without fee, provided
    7  * that (i) the above copyright notices and this permission notice appear in
    8  * all copies of the software and related documentation, and (ii) the names of
    9  * Stanford and Silicon Graphics may not be used in any advertising or
   10  * publicity relating to the software without the specific, prior written
   11  * permission of Stanford and Silicon Graphics.
   12  * 
   13  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
   14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
   15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
   16  *
   17  * IN NO EVENT SHALL STANFORD OR SILICON GRAPHICS BE LIABLE FOR
   18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
   19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
   20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
   21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
   22  * OF THIS SOFTWARE.
   23  */
   24 
   25 /*
   26  * Implementation of Adjuster and derived classes.
   27  */
   28 
   29 #include <InterViews/bitmap.h>
   30 #include <IV-2_6/InterViews/adjuster.h>
   31 #include <IV-2_6/InterViews/painter.h>
   32 #include <IV-2_6/InterViews/perspective.h>
   33 #include <IV-2_6/InterViews/sensor.h>
   34 #include <IV-2_6/InterViews/shape.h>
   35 
   36 #include <InterViews/Bitmaps/enlargeHit.bm>
   37 #include <InterViews/Bitmaps/enlargeMask.bm>
   38 #include <InterViews/Bitmaps/enlarge.bm>
   39 #include <InterViews/Bitmaps/reducerHit.bm>
   40 #include <InterViews/Bitmaps/reducerMask.bm>
   41 #include <InterViews/Bitmaps/reducer.bm>
   42 #include <InterViews/Bitmaps/lmoverHit.bm>
   43 #include <InterViews/Bitmaps/lmoverMask.bm>
   44 #include <InterViews/Bitmaps/lmover.bm>
   45 #include <InterViews/Bitmaps/rmoverHit.bm>
   46 #include <InterViews/Bitmaps/rmoverMask.bm>
   47 #include <InterViews/Bitmaps/rmover.bm>
   48 #include <InterViews/Bitmaps/umoverHit.bm>
   49 #include <InterViews/Bitmaps/umoverMask.bm>
   50 #include <InterViews/Bitmaps/umover.bm>
   51 #include <InterViews/Bitmaps/dmoverHit.bm>
   52 #include <InterViews/Bitmaps/dmoverMask.bm>
   53 #include <InterViews/Bitmaps/dmover.bm>
   54 
   55 #include <OS/math.h>
   56 
   57 #include <IV-2_6/_enter.h>
   58 
   59 Adjuster::Adjuster(Interactor* i, int d) {
   60     Init(i, d);
   61 }
   62 
   63 Adjuster::Adjuster(const char* name, Interactor* i, int d) {
   64     SetInstance(name);
   65     Init(i, d);
   66 }
   67 
   68 void Adjuster::Init(Interactor* i, int d) {
   69     SetClassName("Adjuster");
   70     view = i;
   71     highlighted = false;
   72     delay = d;
   73     timer = false;
   74     shown = new Perspective;
   75     plain = nil;
   76     hit = nil;
   77     mask = nil;
   78     input_ = new Sensor(onoffEvents);
   79     input_->Catch(UpEvent);
   80     input_->Catch(DownEvent);
   81 }    
   82 
   83 void Adjuster::Reconfig() {
   84     Painter* p = new Painter(output_);
   85     p->Reference();
   86     Unref(output_);
   87     output_ = p;
   88     shape->width = mask->Width();
   89     shape->height = mask->Height();
   90 }
   91 
   92 void Adjuster::AutoRepeat() {
   93     Event e;
   94     
   95     Poll(e);
   96     e.eventType = DownEvent;
   97     do {
   98     if (Check()) {
   99         Read(e);
  100         if (e.target == this) {
  101         switch (e.eventType) {
  102             case EnterEvent:
  103             Highlight(true);
  104             break;
  105             case LeaveEvent:
  106             Highlight(false);
  107             break;
  108             default:
  109             break;
  110         }
  111         }           
  112     } else if (highlighted) {
  113         Flash();
  114         AdjustView(e);
  115         Sync();
  116     }
  117     } while (e.eventType != UpEvent);
  118 }
  119 
  120 static const int USEC_PER_DELAY_UNIT = 100000;      // delay unit = 1/10 secs
  121 
  122 void Adjuster::HandlePress() {
  123     Event e;
  124     
  125     do {
  126     if (timer) {
  127         if (!Read(0, delay * USEC_PER_DELAY_UNIT, e)) {
  128         AutoRepeat();
  129         return;
  130         }
  131     } else {
  132         Read(e);
  133     }
  134     if (e.target == this) {
  135         switch (e.eventType) {
  136         case EnterEvent:
  137         TimerOn();
  138         Highlight(true);
  139         break;
  140         case LeaveEvent:
  141         TimerOff();
  142         Highlight(false);
  143         break;
  144         case UpEvent:
  145         if (highlighted) {
  146             AdjustView(e);
  147         }
  148         break;
  149         default:
  150         break;
  151         }
  152     }
  153     } while (e.eventType != UpEvent);
  154 }
  155 
  156 void Adjuster::Flash() {
  157     Highlight(false);
  158     Highlight(true);
  159 }
  160 
  161 void Adjuster::TimerOn() {
  162     if (delay >= 0) {
  163     timer = true;
  164     }
  165 }
  166 
  167 void Adjuster::TimerOff() {
  168     timer = false;
  169 }
  170 
  171 Adjuster::~Adjuster() {
  172     Unref(shown);
  173 }
  174 
  175 void Adjuster::Handle(Event& e) {
  176     if (e.eventType == DownEvent) {
  177     Highlight(true);
  178     TimerOn();
  179     if (delay == 0) {
  180         AutoRepeat();
  181     } else {
  182         HandlePress();
  183     }
  184     Highlight(false);
  185     TimerOff();
  186     }
  187 }
  188 
  189 void Adjuster::Redraw(IntCoord, IntCoord, IntCoord, IntCoord) {
  190     IntCoord x = (xmax+1 - mask->Width())/2;
  191     IntCoord y = (ymax+1 - mask->Height())/2;
  192     if (highlighted) {
  193         output_->Stencil(canvas, x, y, hit, mask);
  194     } else {
  195         output_->Stencil(canvas, x, y, plain, mask);
  196     }
  197 }
  198 
  199 void Adjuster::Reshape(Shape& s) {
  200     shape->Rigid(s.hshrink, s.hstretch, s.vshrink, s.vstretch);
  201 }
  202 
  203 void Adjuster::Highlight(boolean on) {
  204     if (highlighted != on) {
  205     highlighted = on;
  206         Draw();
  207     }
  208 }
  209 
  210 void Adjuster::AdjustView(Event&) {
  211     // nop default
  212 }
  213 
  214 Zoomer::Zoomer(Interactor* i, float f) : Adjuster(i, NO_AUTOREPEAT) {
  215     Init(f);
  216 }
  217 
  218 Zoomer::Zoomer(
  219     const char* name, Interactor* i, float f
  220 ) : Adjuster(name, i, NO_AUTOREPEAT) {
  221     Init(f);
  222 }
  223 
  224 Zoomer::~Zoomer() { }
  225 
  226 void Zoomer::Init(float f) {
  227     SetClassName("Zoomer");
  228     factor = f;
  229 }
  230 
  231 void Zoomer::AdjustView(Event&) {
  232     register Perspective* s = shown;
  233     IntCoord cx, cy;
  234 
  235     *s = *view->GetPerspective();
  236     cx = s->curx + s->curwidth/2;
  237     cy = s->cury + s->curheight/2;
  238     s->curwidth = Math::round(float(s->curwidth) / factor);
  239     s->curheight = Math::round(float(s->curheight) / factor);
  240     s->curx = cx - s->curwidth/2;
  241     s->cury = cy - s->curheight/2;
  242     view->Adjust(*s);    
  243 }
  244 
  245 inline Bitmap* MakeBitmap(void* bits, int width, int height) {
  246     Bitmap* b = new Bitmap(bits, width, height);
  247     b->Reference();
  248     return b;
  249 }
  250 
  251 static Bitmap* enlMask;
  252 static Bitmap* enlPlain;
  253 static Bitmap* enlHit;
  254 
  255 Enlarger::Enlarger(Interactor* i) : Zoomer(i, 2.0) {
  256     Init();
  257 }
  258 
  259 Enlarger::Enlarger(const char* name, Interactor* i) : Zoomer(name, i, 2.0) {
  260     Init();
  261 }
  262 
  263 Enlarger::~Enlarger() { }
  264 
  265 void Enlarger::Init() {
  266     SetClassName("Enlarger");
  267     if (enlMask == nil) {
  268         enlMask = MakeBitmap(
  269             enlarger_mask_bits, enlarger_mask_width, enlarger_mask_height
  270         );
  271         enlPlain = MakeBitmap(
  272             enlarger_plain_bits, enlarger_plain_width, enlarger_plain_height
  273         );
  274         enlHit = MakeBitmap(
  275             enlarger_hit_bits, enlarger_hit_width, enlarger_hit_height
  276         );
  277     }
  278     mask = enlMask;
  279     plain = enlPlain;
  280     hit = enlHit;
  281     shape->Rigid(shape->width/2, hfil, shape->height/2);
  282 }
  283 
  284 static Bitmap* redMask;
  285 static Bitmap* redPlain;
  286 static Bitmap* redHit;
  287 
  288 Reducer::Reducer(Interactor* i) : Zoomer(i, 0.5) {
  289     Init();
  290 }
  291 
  292 Reducer::Reducer(const char* name, Interactor* i) : Zoomer(name, i, 0.5) {
  293     Init();
  294 }
  295 
  296 Reducer::~Reducer() { }
  297 
  298 void Reducer::Init() {
  299     SetClassName("Reducer");
  300     if (redMask == nil) {
  301         redMask = MakeBitmap(
  302             reducer_mask_bits, reducer_mask_width, reducer_mask_height
  303         );
  304         redPlain = MakeBitmap(
  305             reducer_plain_bits, reducer_plain_width, reducer_plain_height
  306         );
  307         redHit = MakeBitmap(
  308             reducer_hit_bits, reducer_hit_width, reducer_hit_height
  309         );
  310     }
  311     mask = redMask;
  312     plain = redPlain;
  313     hit = redHit;
  314     shape->Rigid(shape->width/2, hfil, shape->height/2);
  315 }
  316 
  317 enum MoveType { 
  318     MOVE_LEFT, MOVE_RIGHT, MOVE_UP, MOVE_DOWN, MOVE_UNDEF
  319 };
  320 
  321 Mover::Mover(Interactor* i, int delay, int mt) : Adjuster(i, delay) {
  322     Init(mt);
  323 }
  324 
  325 Mover::Mover(
  326     const char* name, Interactor* i, int delay, int mt
  327 ) : Adjuster(name, i, delay) {
  328     Init(mt);
  329 }
  330 
  331 Mover::~Mover() { }
  332 
  333 void Mover::Init(int mt) {
  334     SetClassName("Mover");
  335     moveType = mt;
  336 }
  337 
  338 void Mover::AdjustView(Event& e) {
  339     register Perspective* s = shown;
  340     int amtx, amty;
  341 
  342     *s = *view->GetPerspective();
  343     amtx = e.shift ? s->lx : s->sx;
  344     amty = e.shift ? s->ly : s->sy;
  345 
  346     switch (moveType) {
  347     case MOVE_LEFT:     s->curx -= amtx; break;
  348     case MOVE_RIGHT:    s->curx += amtx; break;
  349     case MOVE_UP:       s->cury += amty; break;
  350     case MOVE_DOWN:     s->cury -= amty; break;
  351     default:        break;
  352     }
  353     view->Adjust(*s);    
  354 }
  355 
  356 static Bitmap* lmoverMask;
  357 static Bitmap* lmoverPlain;
  358 static Bitmap* lmoverHit;
  359 
  360 LeftMover::LeftMover(Interactor* i, int delay) : Mover(i, delay, MOVE_LEFT) {
  361     Init();
  362 }
  363 
  364 LeftMover::LeftMover(
  365     const char* name, Interactor* i, int delay
  366 ) : Mover(name, i, delay, MOVE_LEFT) {
  367     Init();
  368 }
  369 
  370 LeftMover::~LeftMover() { }
  371 
  372 void LeftMover::Init() {
  373     SetClassName("LeftMover");
  374     if (lmoverMask == nil) {
  375         lmoverMask = MakeBitmap(
  376             lmover_mask_bits, lmover_mask_width, lmover_mask_height
  377         );
  378         lmoverPlain = MakeBitmap(
  379             lmover_plain_bits, lmover_plain_width, lmover_plain_height
  380         );
  381         lmoverHit = MakeBitmap(
  382             lmover_hit_bits, lmover_hit_width, lmover_hit_height
  383         );
  384     }
  385     mask = lmoverMask;
  386     plain = lmoverPlain;
  387     hit = lmoverHit;
  388     shape->Rigid(shape->width/2, 0, shape->height/2, vfil);
  389 }
  390 
  391 static Bitmap* rmoverMask;
  392 static Bitmap* rmoverPlain;
  393 static Bitmap* rmoverHit;
  394 
  395 RightMover::RightMover(Interactor* i, int d) : Mover(i, d, MOVE_RIGHT) {
  396     Init();
  397 }
  398 
  399 RightMover::RightMover(
  400     const char* name, Interactor* i, int d
  401 ) : Mover(name, i, d, MOVE_RIGHT) {
  402     Init();
  403 }
  404 
  405 RightMover::~RightMover() { }
  406 
  407 void RightMover::Init() {
  408     SetClassName("RightMover");
  409     if (rmoverMask == nil) {
  410         rmoverMask = MakeBitmap(
  411             rmover_mask_bits, rmover_mask_width, rmover_mask_height
  412         );
  413         rmoverPlain = MakeBitmap(
  414             rmover_plain_bits, rmover_plain_width, rmover_plain_height
  415         );
  416         rmoverHit = MakeBitmap(
  417             rmover_hit_bits, rmover_hit_width, rmover_hit_height
  418         );
  419     }
  420     mask = rmoverMask;
  421     plain = rmoverPlain;
  422     hit = rmoverHit;
  423     shape->Rigid(shape->width/2, 0, shape->height/2, vfil);
  424 }
  425 
  426 static Bitmap* umoverMask;
  427 static Bitmap* umoverPlain;
  428 static Bitmap* umoverHit;
  429 
  430 UpMover::UpMover(Interactor* i, int d) : Mover(i, d, MOVE_UP) {
  431     Init();
  432 }
  433 
  434 UpMover::UpMover(
  435     const char* name, Interactor* i, int d
  436 ) : Mover(name, i, d, MOVE_UP) {
  437     Init();
  438 }
  439 
  440 UpMover::~UpMover() { }
  441 
  442 void UpMover::Init() {
  443     SetClassName("UpMover");
  444     if (umoverMask == nil) {
  445         umoverMask = MakeBitmap(
  446             umover_mask_bits, umover_mask_width, umover_mask_height
  447         );
  448         umoverPlain = MakeBitmap(
  449             umover_plain_bits, umover_plain_width, umover_plain_height
  450         );
  451         umoverHit = MakeBitmap(
  452             umover_hit_bits, umover_hit_width, umover_hit_height
  453         );
  454     }
  455     mask = umoverMask;
  456     plain = umoverPlain;
  457     hit = umoverHit;
  458     shape->Rigid(shape->width/2, hfil, shape->height/2);
  459 }
  460 
  461 static Bitmap* dmoverMask;
  462 static Bitmap* dmoverPlain;
  463 static Bitmap* dmoverHit;
  464 
  465 DownMover::DownMover(Interactor* i, int d) : Mover(i, d, MOVE_DOWN) {
  466     Init();
  467 }
  468 
  469 DownMover::DownMover(
  470     const char* name, Interactor* i, int d
  471 ) : Mover(name, i, d, MOVE_DOWN) {
  472     Init();
  473 }
  474 
  475 DownMover::~DownMover() { }
  476 
  477 void DownMover::Init() {
  478     SetClassName("DownMover");
  479     if (dmoverMask == nil) {
  480         dmoverMask = MakeBitmap(
  481             dmover_mask_bits, dmover_mask_width, dmover_mask_height
  482         );
  483         dmoverPlain = MakeBitmap(
  484             dmover_plain_bits, dmover_plain_width, dmover_plain_height
  485         );
  486         dmoverHit = MakeBitmap(
  487             dmover_hit_bits, dmover_hit_width, dmover_hit_height
  488         );
  489     }
  490     mask = dmoverMask;
  491     plain = dmoverPlain;
  492     hit = dmoverHit;
  493     shape->Rigid(shape->width/2, hfil, shape->height/2);
  494 }