home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xhyper10.zip / XHyper_v1.0 / src / PageButton.c < prev    next >
C/C++ Source or Header  |  1992-12-08  |  4KB  |  123 lines

  1. /*
  2.  * Copyright (c) 1991 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.  * page button Telltale
  25.  */
  26.  
  27. #include "PageButton.h"
  28.  
  29. #include <InterViews/background.h>
  30. #include <InterViews/bitmap.h>
  31. #include <InterViews/box.h>
  32. #include <InterViews/canvas.h>
  33. #include <InterViews/color.h>
  34. #include <InterViews/center.h>
  35. #include <InterViews/shapeof.h>
  36. #include <InterViews/stencil.h>
  37. #include <InterViews/target.h>
  38. #include <InterViews/world.h>
  39.  
  40. #include "pagePlain.bm"
  41. #include "pageHit.bm"
  42. #include "pageChosen.bm"
  43. #include "pageBoth.bm"
  44.  
  45. static void wash(Canvas* c, const Color* color, const Allocation& a) {
  46.     c->fill_rect(a.left(), a.bottom(), a.right(), a.top(), color);
  47. }
  48.  
  49. Color* PageButton::__fade;
  50. Bitmap* PageButton::__plain;
  51. Bitmap* PageButton::__hit;
  52. Bitmap* PageButton::__chosen;
  53. Bitmap* PageButton::__both;
  54.  
  55. PageButton::PageButton(Glyph* label, const Color* c) : Telltale(nil) {
  56.     if (__fade == nil) {
  57.     World* w = World::current();
  58.     ColorIntensity r, g, b;
  59.     w->background()->intensities(w->display(), r, g, b);
  60.         __fade = new Color(r, g, b, 0.5);
  61.         __fade->ref();
  62.     }
  63.     if (__plain == nil) {
  64.         __plain = new Bitmap(
  65.             pagePlain_bits, pagePlain_width, pagePlain_height,
  66.             pagePlain_x_hot, pagePlain_y_hot
  67.         );
  68.         __plain->ref();
  69.         __hit = new Bitmap(
  70.             pageHit_bits, pageHit_width, pageHit_height,
  71.             pageHit_x_hot, pageHit_y_hot
  72.         );
  73.         __hit->ref();
  74.         __chosen = new Bitmap(
  75.             pageChosen_bits, pageChosen_width, pageChosen_height,
  76.             pageChosen_x_hot, pageChosen_y_hot
  77.         );
  78.         __chosen->ref();
  79.         __both = new Bitmap(
  80.             pageBoth_bits, pageBoth_width, pageBoth_height,
  81.             pageBoth_x_hot, pageBoth_y_hot
  82.         );
  83.         __both->ref();
  84.     }
  85.     color_ = c;
  86.     if (color_ != nil) {
  87.     color_->ref();
  88.     }
  89.     body(
  90.         new Target(
  91.             new Overlay(
  92.                 new ShapeOf(new Stencil(__plain, color_)),
  93.                 new HCenter(label)
  94.             ),
  95.             TargetPrimitiveHit
  96.         )
  97.     );
  98. }
  99.  
  100. PageButton::~PageButton() {
  101.     Resource::unref(color_);
  102. }
  103.  
  104. void PageButton::draw(Canvas* c, const Allocation& allocation) const {
  105.     Telltale::draw(c, allocation);
  106.     if (c != nil) {
  107.         Coord x = allocation.x();
  108.         Coord y = allocation.y();
  109.     Bitmap* b = __plain;
  110.         if (highlighted() && !chosen()) {
  111.             b = __hit;
  112.         } else if (!highlighted() && chosen()) {
  113.             b = __chosen;
  114.         } else if (highlighted() && chosen()) {
  115.             b = __both;
  116.         }
  117.     c->stencil(b, color_, x, y);
  118.         if (!enabled()) {
  119.             wash(c, __fade, allocation);
  120.         }
  121.     }
  122. }
  123.