Article View: comp.windows.interviews
Article #1394Re: manual.sty
From: Dirk Grunwald
Date: Wed, 29 May 1991 03:54
Date: Wed, 29 May 1991 03:54
317 lines
9067 bytes
9067 bytes
Here's a MonoGlyph that surrounds another Glyph with an oval border.
You specify the color and brush for the border, as well as the radius
in the x,y directions. The oval has quarter circles at each corner of
the contained glyph.
I'd be interested in hearing about other such gee-gaws that people
come up with.
#! /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, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: example.cc OvalBorder.cc OvalBorder.h
# Wrapped by grunwald@foobar.Colorado.EDU on Tue May 28 21:48:59 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'example.cc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'example.cc'\"
else
echo shar: Extracting \"'example.cc'\" \(1205 characters\)
sed "s/^X//" >'example.cc' <<'END_OF_FILE'
X#include "OvalBorder.h"
X#include "InterViews/character.h"
X#include "InterViews/font.h"
X#include "InterViews/color.h"
X#include "InterViews/brush.h"
X#include "InterViews/window.h"
X#include "InterViews/world.h"
X#include "InterViews/aggregate.h"
X#include "InterViews/box.h"
X#include "InterViews/margin.h"
X#include "InterViews/discretion.h"
X#include "InterViews/glue.h"
X#include "InterViews/shadow.h"
X
X#include "stream.h"
X#include "string.h"
X
X#include "OvalBorder.h"
X
XWorld *world;
X
Xmain(int argc, char **argv)
X{
X world = new World("Foo", argc, argv);
X
X Color *color = world -> foreground();
X Color *back = world -> background();
X Font *font = world -> font();
X
X char *s = "Hello, World";
X if ( argc > 1 ) {
X s = argv[1];
X }
X int len = strlen(s);
X
X LRBox *bx = new LRBox();
X
X while ( s && *s && *s != '\n' ) {
X Character *ch = new Character(*s, font, color);
X bx -> append(ch);
X if ( *s == ' ') {
X bx -> append(new HGlue());
X }
X s++;
X }
X
X Glyph *xx = new Margin(new OvalBorder(bx, color, new Brush(3)),
X 50, 50);
X
X TopLevelWindow *window = new TopLevelWindow(xx);
X
X window -> world(world);
X window -> map();
X
X world->Run();
X
X delete world;
X
X}
X
END_OF_FILE
if test 1205 -ne `wc -c <'example.cc'`; then
echo shar: \"'example.cc'\" unpacked with wrong size!
fi
# end of 'example.cc'
fi
if test -f 'OvalBorder.cc' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'OvalBorder.cc'\"
else
echo shar: Extracting \"'OvalBorder.cc'\" \(3705 characters\)
sed "s/^X//" >'OvalBorder.cc' <<'END_OF_FILE'
X#include <InterViews/canvas.h>
X#include <InterViews/color.h>
X#include <InterViews/brush.h>
X#include <InterViews/printer.h>
X#include "OvalBorder.h"
X
XOvalBorder::OvalBorder(Glyph* body, Color* c, Brush *b)
X : MonoGlyph(body)
X{
X color_ = c;
X if (color_ != nil) {
X color_->ref();
X }
X brush_ = b;
X if (brush_ != nil) {
X brush_->ref();
X rx_ = ry_ = brush_ -> width() * 2;
X } else {
X rx_ = 3;
X ry_ = 3;
X }
X}
X
XOvalBorder::OvalBorder(Glyph* body, Color* c, Brush *b, Coord x, Coord y)
X : MonoGlyph(body)
X{
X color_ = c;
X if (color_ != nil) {
X color_->ref();
X }
X brush_ = b;
X if (brush_ != nil) {
X brush_->ref();
X }
X rx_ = x;
X ry_ = y;
X}
X
XOvalBorder::~OvalBorder()
X{
X Resource::unref(color_);
X Resource::unref(brush_);
X}
X
Xvoid OvalBorder::request(Requisition& requisition)
X{
X //
X // let body make request
X //
X MonoGlyph::request(requisition);
X
X //
X // now add in our stuff
X //
X Requirement x = requisition.requirement(Dimension_X);
X if (x.defined()) {
X x.natural(x.natural() + 2 * rx_);
X }
X
X requisition.require(Dimension_X, x);
X Requirement y = requisition.requirement(Dimension_Y);
X if (y.defined()) {
X y.natural(y.natural() + 2 * ry_);
X }
X requisition.require(Dimension_Y, y);
X}
X
X
Xvoid
XOvalBorder::subAllocation(Allocation& a, Allocation& newa)
X{
X Allotment ox = a.allotment(Dimension_X);
X Allotment oy = a.allotment(Dimension_Y);
X
X newa.allot(Dimension_X,
X Allotment(ox.origin() + rx_,
X ox.span() - (2 * rx_),
X ox.alignment()
X ));
X
X newa.allot(Dimension_Y,
X Allotment(oy.origin() + ry_,
X oy.span() - (2 * ry_),
X oy.alignment()));
X}
X
Xvoid OvalBorder::allocate(Canvas* canvas, Allocation& a, Extension& ext)
X{
X Allocation newa;
X
X subAllocation(a, newa);
X MonoGlyph::allocate(canvas, newa, ext);
X ext.extend(a);
X}
X
Xvoid
XOvalBorder::ovalbox(Canvas* c, Allocation& a)
X{
X static float p0 = 1.00000000;
X static float p1 = 0.89657547;
X static float p2 = 0.70710678;
X static float p3 = 0.51763809;
X static float p4 = 0.26794919;
X
X Coord l = a.left();
X Coord r = a.right();
X Coord b = a.bottom();
X Coord t = a.top();
X
X Coord px0 = p0 * rx_, py0 = p0 * ry_;
X Coord px1 = p1 * rx_, py1 = p1 * ry_;
X Coord px2 = p2 * rx_, py2 = p2 * ry_;
X Coord px3 = p3 * rx_, py3 = p3 * ry_;
X Coord px4 = p4 * rx_, py4 = p4 * ry_;
X Coord x,y;
X
X c -> new_path();
X
X //
X // right side & top right quad
X c -> move_to(r, b + ry_);
X c -> line_to(r, t - ry_);
X x = r - rx_;
X y = t - ry_;
X c -> curve_to(x + px2, y + py2, x + px0, y + py4, x + px1, y + py3);
X c -> curve_to(x, y + ry_, x + px3, y + py1, x + px4, y + py0);
X
X //
X // top and top left quad
X //
X c -> line_to(l + rx_, t);
X x = l + rx_;
X y = t - ry_;
X c -> curve_to(x - px2, y + py2, x - px4, y + py0, x - px3, y + py1);
X c -> curve_to(x - rx_, y, x - px1, y + py3, x - px0, y + py4);
X
X //
X // left and bottom left quad
X c -> line_to(l, b + ry_);
X x = l + rx_;
X y = b + ry_;
X c -> curve_to(x - px2, y - py2, x - px0, y - py4, x - px1, y - py3);
X c -> curve_to(x, y - ry_, x - px3, y - py1, x - px4, y - py0);
X
X //
X // bottom and bottom right quad
X //
X c -> line_to(r-rx_, b);
X x = r - rx_;
X y = b + ry_;
X c -> curve_to(x + px2, y - py2, x + px4, y - py0, x + px3, y - py1);
X c -> curve_to(x + rx_, y, x + px1, y - py3, x + px0, y - py4);
X
X c -> close_path();
X c -> stroke(color_, brush_);
X}
X
Xvoid OvalBorder::draw(Canvas* canvas, Allocation& a)
X{
X if (canvas != nil) {
X Allocation newa;
X subAllocation(a, newa);
X MonoGlyph::draw(canvas, newa);
X ovalbox(canvas, a);
X }
X}
END_OF_FILE
if test 3705 -ne `wc -c <'OvalBorder.cc'`; then
echo shar: \"'OvalBorder.cc'\" unpacked with wrong size!
fi
# end of 'OvalBorder.cc'
fi
if test -f 'OvalBorder.h' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'OvalBorder.h'\"
else
echo shar: Extracting \"'OvalBorder.h'\" \(929 characters\)
sed "s/^X//" >'OvalBorder.h' <<'END_OF_FILE'
X#ifndef ivlook_ovalborder_h
X#define ivlook_ovalborder_h
X
X#include <InterViews/monoglyph.h>
X
Xclass Color;
Xclass Brush;
X
X//
X// OvalBorder is similar to Margin; it places an oval border around
X// a glyph. The corners have (x,y) radii of (rx,ry). The enclosed
X// glyph gets it's natural allotment, and the border is added on. The
X//
X
Xclass OvalBorder : public MonoGlyph {
Xpublic:
X OvalBorder(Glyph* body, Color*, Brush*);
X OvalBorder(Glyph* body, Color*, Brush*,
X Coord rx, Coord ry);
X
X virtual ~OvalBorder();
X
X virtual void request(Requisition& requisition);
X virtual void allocate(Canvas*, Allocation&, Extension&);
X virtual void draw(Canvas*, Allocation&);
X// virtual void print(Printer*, Allocation&);
X
Xprivate:
X virtual void subAllocation(Allocation&, Allocation&);
X virtual void ovalbox(Canvas *c, Allocation& a);
X Coord rx_;
X Coord ry_;
X Color* color_;
X Brush* brush_;
X};
X
X#endif
END_OF_FILE
if test 929 -ne `wc -c <'OvalBorder.h'`; then
echo shar: \"'OvalBorder.h'\" unpacked with wrong size!
fi
# end of 'OvalBorder.h'
fi
echo shar: End of shell archive.
exit 0
Technical Details
Message-ID:
<1991May29.035404.11309@colorado.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!zaphod.mps.ohio-state.edu!ncar!csn!boulder!news!grunwaldReferences:
<9105290155.AA10918@kurango.cs.flinders.oz.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!zaphod.mps.ohio-state.edu!ncar!csn!boulder!news!grunwald From: grunwald@foobar.colorado.edu (Dirk Grunwald) Newsgroups: comp.windows.interviews Subject: Re: manual.sty Message-ID: <1991May29.035404.11309@colorado.edu> Date: 29 May 91 03:54:04 GMT References: <9105290155.AA10918@kurango.cs.flinders.oz.au> Sender: news@colorado.edu (The Daily Planet) Reply-To: grunwald@foobar.colorado.edu Organization: University of Colorado at Boulder Lines: 317 In-Reply-To: cameron@cs.flinders.oz.au's message of 29 May 91 01:55:22 GMT Nntp-Posting-Host: foobar.colorado.edu