Article View: comp.windows.interviews
Article #554Glyph based scrollable glyph ... (source) : )
From: Chen Wang
Date: Fri, 28 Aug 1992 21:11
Date: Fri, 28 Aug 1992 21:11
424 lines
11680 bytes
11680 bytes
Due to popular demand and the fact that I lost a few addresses. I decide
to post the whole thing. It is in "shar" format.
Enjoy, I hope. :)
-- Chen Wang
Ps: Mail any problems to me and discussions to this mailing list.
---- Cut here ----
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, use "sh file -c".
# If this archive is complete, you will see the following message at the end:
# "End of shell archive."
#
# Contents:
# Imakefile README main.c scrollable.c scrollable.h
#
# Wrapped by wang@db.toronto.edu.toronto.edu on Fri Aug 28 17:02:58 1992
#
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Imakefile -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"Imakefile\"
else
echo shar: Extracting \"Imakefile\" \(229 characters\)
sed "s/^X//" >Imakefile <<'END_OF_Imakefile'
XXCOMM
XXCOMM alert - dialog box built from standard input
XXCOMM
X
X#ifdef InObjectCodeDir
X
XUse_libInterViews()
XComplexProgramTarget(alert)
X
XMakeObjectFromSrc(main)
XMakeObjectFromSrc(scrollable)
X
X#else
X
XMakeInObjectCodeDir()
X
X#endif
END_OF_Imakefile
if test 229 -ne `wc -c <Imakefile`; then
echo shar: \"Imakefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f README -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(612 characters\)
sed "s/^X//" >README <<'END_OF_README'
X-----------------------------------------------------------------------
X
X InterViews Scrollable Glyph
X
X Version 1.0T
X
X----------------------------------------------------------------------
X
XThis is a *trial* version only, the author bears no responsibility for
Xthe workability of this software.
X
X"Scrollable" only works on IV3.1b. Sorry 3.1a users.
X
XPlease see "main.c" for usage.
X
X -- Chen Wang
X
XPs: Please mail all problems to "chen@ie.toronto.edu", I will try to
X answer ASAP.
X
XOh yeah, this is public domain, which means anybody may modify or
Xchange this piece of code.
END_OF_README
if test 612 -ne `wc -c <README`; then
echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f main.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"main.c\"
else
echo shar: Extracting \"main.c\" \(1362 characters\)
sed "s/^X//" >main.c <<'END_OF_main.c'
X#include <IV-look/kit.h>
X#include <InterViews/background.h>
X#include <InterViews/layout.h>
X#include <InterViews/session.h>
X#include <InterViews/window.h>
X#include <InterViews/page.h>
X#include <InterViews/patch.h>
X#include <stdio.h>
X#include <InterViews/debug.h>
X
X#include "scrollable.h"
X
Xclass App {
Xpublic:
X void msg();
X};
X
XdeclareActionCallback(App)
XimplementActionCallback(App)
X
Xvoid App::msg() {
X printf("hi mom!\n");
X}
X
Xint main(int argc, char** argv) {
X Session* session = new Session("Himom", argc, argv);
X WidgetKit& kit = *WidgetKit::instance();
X const LayoutKit& layout = *LayoutKit::instance();
X App* a = new App;
X TelltaleGroup* group = new TelltaleGroup;
X
X Page* g = new Page(nil);
X g->insert(0,
X kit.push_button("Hi", new ActionCallback(App)(a, &App::msg))
X );
X g->move(0, 0, 100);
X g->show(0, true);
X
X Scrollable* s = new Scrollable(g, 300, 300);
X
X Glyph* g2 = layout.vcenter(layout.variable_span(
X layout.natural_span(s, 200, 200)), 1.0);
X
X session->run_window(
X new ApplicationWindow(
X new Background(
X layout.vbox(
X layout.hbox(
X g2,
X kit.vscroll_bar(s)
X ),
X kit.hscroll_bar(s),
X layout.hglue(5.0)
X ),
X kit.background()
X )
X )
X );
X}
END_OF_main.c
if test 1362 -ne `wc -c <main.c`; then
echo shar: \"main.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f scrollable.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"scrollable.c\"
else
echo shar: Extracting \"scrollable.c\" \(3406 characters\)
sed "s/^X//" >scrollable.c <<'END_OF_scrollable.c'
X
X#include "scrollable.h"
X
X#include <IV-look/kit.h>
X#include <InterViews/canvas.h>
X#include <InterViews/layout.h>
X#include <InterViews/hit.h>
X#include <InterViews/tformsetter.h>
X#include <InterViews/transformer.h>
X#include <InterViews/session.h>
X#include <OS/math.h>
X
XScrollable::Scrollable(Glyph* g, Coord w, Coord h)
X: Patch(xform_ = new TransformSetter(g)) {
X width_ = w;
X height_ = h;
X scale_ = 1.0;
X dx_ = dy_ = 0;
X const Transformer t(
X scale_, 0,
X 0, scale_,
X - dx_ * scale_, - dy_ * scale_
X );
X
X xform_->transformer(t);
X scroll_incr_ = 10;
X page_incr_ = 50;
X}
X
XScrollable::~Scrollable () {
X}
X
Xvoid Scrollable::request(Requisition& req) const {
X Scrollable* s = (Scrollable*) this;
X Patch::request(s->requisition_);
X Requirement& box_x = req.x_requirement();
X box_x.natural(width_);
X box_x.stretch(fil);
X box_x.shrink(width_);
X box_x.alignment(0.0);
X
X Requirement& box_y = req.y_requirement();
X box_y.natural(height_);
X box_y.stretch(fil);
X box_y.shrink(height_);
X box_y.alignment(0.0);
X}
X
Xvoid Scrollable::allocate(Canvas* c, const Allocation& a, Extension& ext) {
X Patch::allocate(c, a, ext);
X notify(Dimension_X);
X notify(Dimension_Y);
X}
X
Xvoid Scrollable::draw(Canvas* c, const Allocation& a) const {
X c->damage(0, 0, width_, height_);
X Extension e;
X e.set(c, a);
X c->push_clipping();
X c->push_transform();
X c->transformer(Transformer());
X c->clip_rect(e.left(), e.bottom(), e.right(), e.top());
X c->pop_transform();
X c->pop_clipping();
X Patch::draw(c, a);
X}
X
Xvoid Scrollable::reallocate() {
X Patch::reallocate();
X}
X
Xvoid Scrollable::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
X Patch::pick(c, a, depth, h);
X}
X
XCoord Scrollable::cur_lower(DimensionName d) const {
X if (d == Dimension_X) return dx_;
X else return dy_;
X}
XCoord Scrollable::cur_upper(DimensionName d) const {
X if (d == Dimension_X)
X return dx_ + scale_ * allocation().x_allotment().span();
X else
X return dy_ + scale_ * allocation().y_allotment().span();
X}
XCoord Scrollable::cur_length(DimensionName d) const {
X return scale_ * allocation().allotment(d).span();
X}
XCoord Scrollable::lower(DimensionName) const {
X return 0;
X}
XCoord Scrollable::upper(DimensionName d) const {
X if (d == Dimension_X) return width_;
X else return height_;
X}
XCoord Scrollable::length(DimensionName d) const {
X if (d == Dimension_X) return width_;
X else return height_;
X}
X
Xvoid Scrollable::scroll_to(DimensionName d, Coord lower) {
X Coord p = lower;
X constrain(d, p);
X if (p != cur_lower(d)) {
X if (d == Dimension_X) dx_ = p;
X else dy_ = p;
X Transformer t(
X scale_, 0,
X 0, scale_,
X - dx_ * scale_, - dy_ * scale_
X );
X
X redraw();
X xform_->transformer(t);
X reallocate();
X notify(d);
X redraw();
X };
X}
X
Xvoid Scrollable::scale_to(DimensionName, float fraction_visible) {
X zoom_to(fraction_visible);
X}
X
Xvoid Scrollable::zoom_to(float magnification) {
X if (magnification <= (1./16)) {
X magnification = 1./16;
X } else if (magnification > 16) {
X magnification = 16;
X }
X if (scale_ != magnification) {
X scale_ = magnification;
X Transformer t(
X scale_, 0,
X 0, scale_,
X - scale_ * dx_, - scale_ * dy_
X );
X redraw();
X xform_->transformer(t);
X reallocate();
X redraw();
X notify(Dimension_X);
X notify(Dimension_Y);
X }
X}
X
Xfloat Scrollable::scale() { return scale_; }
END_OF_scrollable.c
if test 3406 -ne `wc -c <scrollable.c`; then
echo shar: \"scrollable.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f scrollable.h -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"scrollable.h\"
else
echo shar: Extracting \"scrollable.h\" \(2338 characters\)
sed "s/^X//" >scrollable.h <<'END_OF_scrollable.h'
X
X#ifndef scrollable_h
X#define scrollable_h
X
X#include <InterViews/adjust.h>
X#include <InterViews/patch.h>
X#include <stdio.h>
X
Xclass TransformSetter;
X
Xclass Scrollable : public Patch, public Adjustable {
Xpublic:
X Scrollable(Glyph* g, Coord w, Coord h);
X virtual ~Scrollable();
X
X virtual void draw(Canvas*, const Allocation&) const;
X virtual void pick(Canvas*, const Allocation&, int depth, Hit&);
X virtual void reallocate();
X
X virtual void request(Requisition&) const;
X virtual void allocate(Canvas*, const Allocation&, Extension&);
X
X virtual Coord lower(DimensionName) const;
X virtual Coord upper(DimensionName) const;
X virtual Coord length(DimensionName) const;
X virtual Coord cur_lower(DimensionName) const;
X virtual Coord cur_upper(DimensionName) const;
X virtual Coord cur_length(DimensionName) const;
X
X virtual void scroll_to(DimensionName, Coord lower);
X virtual void scale_to(DimensionName, float fraction_visible);
X virtual void zoom_to(float magnification);
X
X virtual float scale();
X
X virtual void scroll_scr(Coord cnew) { scroll_incr_ = cnew; }
X virtual void page_scr(Coord cnew) { page_incr_ = cnew; }
X
X virtual void scroll_forward(DimensionName d) {
X Coord newpos;
X
X if (d == Dimension_X) {
X newpos = dx_ + scroll_incr_;
X } else {
X newpos = dy_ + scroll_incr_;
X };
X
X scroll_to(d, newpos);
X }
X
X virtual void scroll_backward(DimensionName d) {
X Coord newpos;
X
X if (d == Dimension_X) {
X newpos = dx_ - scroll_incr_;
X } else {
X newpos = dy_ - scroll_incr_;
X };
X
X scroll_to(d, newpos);
X }
X
X virtual void page_forward(DimensionName d) {
X Coord newpos;
X
X if (d == Dimension_X) {
X newpos = dx_ + page_incr_;
X } else {
X newpos = dy_ + page_incr_;
X };
X
X scroll_to(d, newpos);
X }
X
X virtual void page_backward(DimensionName d) {
X Coord newpos;
X
X if (d == Dimension_X) {
X newpos = dx_ - page_incr_;
X } else {
X newpos = dy_ - page_incr_;
X };
X
X scroll_to(d, newpos);
X }
X
X Coord width_, height_;
X Coord scale_;
X Coord dx_, dy_;
X Coord scroll_incr_;
X Coord page_incr_;
X
X Requisition requisition_;
X TransformSetter* xform_;
X};
X
X#endif
END_OF_scrollable.h
if test 2338 -ne `wc -c <scrollable.h`; then
echo shar: \"scrollable.h\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
Technical Details
Message-ID:
<9208282111.AA21407@ie.utoronto.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!IE.UTORONTO.CA!chenShow Full Headers
Complete Article Headers
Newsgroups: comp.windows.interviews Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!IE.UTORONTO.CA!chen From: chen@IE.UTORONTO.CA (Chen Wang) Subject: Glyph based scrollable glyph ... (source) : ) Message-ID: <9208282111.AA21407@ie.utoronto.ca> Sender: news@shelby.stanford.edu (USENET News System) Organization: Internet-USENET Gateway at Stanford University Date: Fri, 28 Aug 1992 21:11:58 GMT Lines: 425