"Fossies" - the Fresh Open Source Software Archive

Member "ivtools-ivtools-2.0.4/src/InterViews/adjust.c" (9 Oct 2020, 4451 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 "adjust.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (c) 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  * Adjustable - object to scroll and/or zoom
   27  */
   28 
   29 #include <InterViews/adjust.h>
   30 #include <InterViews/observe.h>
   31 #include <OS/math.h>
   32 
   33 struct AdjustableInfo {
   34 private:
   35     friend class Adjustable;
   36 
   37     Observable* observable_;
   38     Coord small_;
   39     Coord large_;
   40 };
   41 
   42 struct AdjustableImpl {
   43 private:
   44     friend class Adjustable;
   45 
   46     AdjustableInfo info_[CoordinateSpace::dimensions];
   47 };
   48 
   49 Adjustable::Adjustable() {
   50     impl_ = new AdjustableImpl;
   51     AdjustableImpl& a = *impl_;
   52     for (DimensionName d = 0; d < CoordinateSpace::dimensions; d++) {
   53     AdjustableInfo& i = a.info_[d];
   54     i.observable_ = new Observable;
   55     i.small_ = 1;
   56     i.large_ = 0;
   57     }
   58 }
   59 
   60 Adjustable::~Adjustable() {
   61     AdjustableImpl& a = *impl_;
   62     for (DimensionName d = 0; d < CoordinateSpace::dimensions; d++) {
   63     delete a.info_[d].observable_;
   64     }
   65     delete impl_;
   66 }
   67 
   68 Observable* Adjustable::observable(DimensionName d) const {
   69     return impl_->info_[d].observable_;
   70 }
   71 
   72 void Adjustable::attach(DimensionName d, Observer* o) {
   73     observable(d)->attach(o);
   74 }
   75 
   76 void Adjustable::detach(DimensionName d, Observer* o) {
   77     observable(d)->detach(o);
   78 }
   79 
   80 Coord Adjustable::lower(DimensionName) const { return 0; }
   81 Coord Adjustable::upper(DimensionName d) const { return lower(d) + length(d); }
   82 Coord Adjustable::length(DimensionName d) const { return upper(d) - lower(d); }
   83 Coord Adjustable::cur_lower(DimensionName) const { return 0; }
   84 
   85 Coord Adjustable::cur_upper(DimensionName d) const {
   86     return cur_lower(d) + cur_length(d);
   87 }
   88 
   89 Coord Adjustable::cur_length(DimensionName d) const {
   90     return cur_upper(d) - cur_lower(d);
   91 }
   92 
   93 void Adjustable::small_scroll(DimensionName d, Coord c) {
   94     impl_->info_[d].small_ = c;
   95 }
   96 
   97 Coord Adjustable::small_scroll(DimensionName d) const {
   98     return impl_->info_[d].small_;
   99 }
  100 
  101 void Adjustable::large_scroll(DimensionName d, Coord c) {
  102     impl_->info_[d].large_ = c;
  103 }
  104 
  105 Coord Adjustable::large_scroll(DimensionName d) const {
  106     Coord s = impl_->info_[d].large_;
  107     if (Math::equal(s, float(0), float(1e-4))) {
  108     s = cur_length(d) - 1;
  109     }
  110     return s;
  111 }
  112 
  113 void Adjustable::begin_adjustment(DimensionName) { }
  114 void Adjustable::commit_adjustment(DimensionName) { }
  115 void Adjustable::abort_adjustment(DimensionName) { }
  116 
  117 void Adjustable::scroll_forward(DimensionName d) {
  118     scroll_to(d, cur_lower(d) + small_scroll(d));
  119 }
  120 
  121 void Adjustable::scroll_backward(DimensionName d) {
  122     scroll_to(d, cur_lower(d) - small_scroll(d));
  123 }
  124 
  125 void Adjustable::page_forward(DimensionName d) {
  126     scroll_to(d, cur_lower(d) + large_scroll(d));
  127 }
  128 
  129 void Adjustable::page_backward(DimensionName d) {
  130     scroll_to(d, cur_lower(d) - large_scroll(d));
  131 }
  132 
  133 void Adjustable::scroll_to(DimensionName, Coord) { }
  134 void Adjustable::scale_to(DimensionName, Coord) { }
  135 void Adjustable::zoom_to(float) { }
  136 
  137 void Adjustable::constrain(DimensionName d, Coord& new_lower) const {
  138     Coord a = lower(d);
  139     Coord b = upper(d) - cur_length(d);
  140     if (new_lower < a) {
  141     new_lower = a;
  142     } else if (new_lower > b) {
  143     new_lower = b;
  144     }
  145 }
  146 
  147 void Adjustable::notify(DimensionName d) const {
  148     observable(d)->notify();
  149 }
  150 
  151 void Adjustable::notify_all() const {
  152     for (DimensionName d = 0; d < CoordinateSpace::dimensions; d++) {
  153     observable(d)->notify();
  154     }
  155 }