home *** CD-ROM | disk | FTP | other *** search
- // ┌───────┐
- // ─────────>│ AVNER │
- // ─────────>│ BEN │──────> Software Engineering Method
- // └───────┘
- // 10 Dov-Hoz st. Tel-Aviv 63416 Israel tel. 972-3-221535
-
- // The Screen NAVigator, ver 1.10 April 1990
- // Copyright (c) 1989 by Avner Ben
- // Snav is not, and never was, free software.
- // for conditions for use refer to file "copyrigh.txt"
-
- // The Screen Navigator is an object-oriented device-independent
- // character-graphics driver package, written in the C++ language,
- // distributed in the form of C++ source code.
- // For further information refer to the documentation files.
-
- // The user may not omit this text, from the beginning of the file, to
- // the line of asterisks below.
-
- /***************************************************************************/
-
- // package nucleus part 1 - headers.
- // This file defines the basic terms of "character geometry", to be used
- // in the more specific other parts.
- // for data-structure logic, refer to file "article".
-
- // History:
- // 25.3.89 avner ben coded.
- // 28.7.89 avner ben - classified.
- /////// snav v1.1
- // 5.3.90 avner ben - C++ v2.0 upgrade.
- // 26.3.90 avner ben - removed some inline code to implementation
-
- // Site history (of this copy):
- // __.__.__ ____________ : __________________.
-
- #include <stdio.h>
- #ifndef SNAV0_H
- #define SNAV0_H
-
- #ifndef TRUE
- typedef int boolean;
- #define TRUE 1
- #define FALSE 0
- #endif
-
- #define ENV_MODIFY // governs the behaviour of some full-screen methods.
-
- enum connective {
- // the order reflects the natural order of reading a
- // decision tree in english, horizontally oriented.
- // note: the direction a character connects at is often
- // opposite the one it "points" at!
- NODIR, // not a semigraphic
- RTDIR, // char connects right (bit 1 on)
- UPDIR, // char connects up (bit 2 on)
- LTDIR=4, // char connects left (bit 3 on)
- DNDIR=8 // char connects down (bit 4 on)
- };
-
- class direction
- { // which way are we going?
-
- friend class intersection;
- friend class axis;
-
- private :
- connective where;
-
- public :
- direction(connective initdir=(connective)0x0001)
- // by default, RTDIR
- { where=initdir; }
- direction(int initdir) // c++ v1.0 compatibility
- { where=(connective)initdir; }
- direction(char c);
- // construct direction from letter code
- connective whereto(void)
- { return(where); }
-
- // internal states:
- connective reset(void)
- { return (where=(connective)0x0001); }
- connective next(void)
- // next direction in sequence, or NODIR
- // RTDIR.next()==>UPDIR.
- { return((where=(connective)(where<<1 & 0x000f))); }
- connective prev(void)
- // previous direction in sequence, or NODIR
- // DNDIR.prev()==>LTDIR
- { return((where>>=1)); }
- connective opposite(void);
- // "opposite" direction. other direction on same axis
- // RTDIR.opposite()==>LTDIR
- direction &operator++(void)
- // fancy version of next()
- { where=(connective)(where<<1 & 0x000f); return *this; }
- direction &operator--(void)
- // fancy version of prev()
- { where>>=1; return *this; }
- friend direction operator~(const direction &dir);
- // non-destructive opposite() - (temporary result)
-
- // miscelanous
- connective operator()(void)
- // fancy version of whereto
- { return(where); }
- boolean operator==(const direction &other)
- { return(where==other.where); }
- boolean operator!=(const direction &other)
- { return(where!=other.where); }
- connective clockwise(void);
- // circular movement clockwise
- char *name(void);
- // decode direction name, capitalized.
- // RTDIR.name()==>"Right"
- char code(void);
- // decode direction letter. first char returned by name().
- // RTDIR.code()==>'R' */
- int serial(void);
- // serial number of direction 1,2,3,4.
- // DNDIR.serial()==>4
- };
-
- #ifndef SNAV0_C
- extern const direction // intended to be read only!
- nodir,
- rt,
- up,
- lt,
- dn;
- #endif
-
- enum intersection_type {
- J_NUL, // no directions. not semigraphic
- J_ARROW, // 1 direction. terminal char
- J_LINE, // 2 directions, complementary.
- J_CORNER, // 2 directions, at right angle
- J_FORK, // 3 directions
- J_CROSS // all 4 directions
- };
-
- class intersection
- { // where can we go from here?
-
- protected :
- int value;
-
- public :
- intersection(int dir_set=0x000f)
- // by default, the whole range
- { value=dir_set; }
- intersection(connective onedir)
- { value=(int)onedir; }
- intersection(char *name);
- // construct by name (as obtained from name()), case sensitive.
- int whereto(void) { return(value); }
-
- // internal states:
- int include(const direction &dir)
- // add direction to set
- { return((value|=dir.where)); }
- int exclude(const direction &dir)
- // subtract direction from set
- { return((value^=(value&dir.where))); }
- int intersect(const intersection &other)
- // isolate directions included in both sets
- // RTDIR+UPDIR+DNDIR.intersect(RTDIR+LTDIR)==>RTDIR
- { return((value&=other.value)); }
- intersection &operator+=(const direction &dir)
- // fancy version of include
- { value|=dir.where; return *this; }
- intersection &operator-=(const direction &dir)
- // fancy version of exclude
- { value^=(value&dir.where); return *this; }
- intersection &operator*=(const intersection &other)
- // fancy version of intersect
- { value&=other.value; return(*this); }
-
- // test inclusion:
- boolean includes(const direction &member);
- // test if direction is included
- // RTDIR+LTDIR+UPDIR+DNDIR.includes(RTDIR)==>TRUE */
- boolean includes(const intersection &subset);
- // test if all target directions are included
- // RTDIR+UPDIR+DNDIR.includes(RTDIR+LTDIR)==>FALSE
- boolean intersects(const intersection ¶lel);
- // test if at least one of the target directions is included
- // RTDIR+UPDIR+DNDIR.intersects(RTDIR+LTDIR)==>TRUE
- boolean operator>=(const direction &member)
- // fancy version of includes()
- { return(includes(member)); }
- boolean operator>=(const intersection &subset)
- // fancy version of includes()
- { return(includes(subset)); }
-
- // miscelanous:
- int operator()(void)
- // fancy version of whereto
- { return(value); }
- boolean operator==(const intersection &other)
- { return(value==other.value); }
- boolean operator!=(const intersection &other)
- { return(value!=other.value); }
- boolean unary(void);
- // test if direction set includes only one direction
- // (RTDIR+LTDIR).unary()==>FALSE;
- direction ask_first(void);
- // find lowest order member - temporary result
- direction get_first(void);
- // extract lowest order member - temporary result
- char *names(void);
- // decode directions using direction.name(), comma seperated.
- // (RTDIR+UPDIR).names()==>"Right,Up"
- intersection_type type(void);
- // tell intersection type
- // (RTDIR+UPDIR).type()==>J_CORNER
- char *name(void);
- // decode intersection name
- // (RTDIR+UPDIR+LTDIR).name()==>"Ufork"
- };
-
- enum biconnective {
- NODIM,
- HDIM, // "horizontal", panel=row, cartesian=y
- VDIM // "vertical", panel=column, cartesian=x
- };
-
- class axis : public intersection {
- // dimension on the plain
-
- friend class weight_d;
-
- protected :
- biconnective where;
-
- public :
- void set_dirs(biconnective newdim);
- axis(biconnective newdim=NODIM)
- { set_dirs(newdim); }
- axis(int newdim) // c++ v1.0 compatibility
- { set_dirs((biconnective)newdim); }
- axis(const direction &dir);
- // generalize direction
- // axis(RTDIR)==>HDIM */
- biconnective wherein(void)
- { return(where); }
- intersection directions(void);
- // copy pending direction set - temporary result
- biconnective operator()(void)
- // fancy version of wherein
- { return(where); }
- boolean operator==(const axis &other)
- { return(where==other.where); }
- boolean operator!=(const axis &other)
- { return(where!=other.where); }
- biconnective opposite(void);
- // turn the other dimension
- // HDIM.opposite()==>VDIM
- friend axis operator~(const axis &other);
- // non-destructive opposite - temporary result
- char *name(void);
- // decode dimension name
- // HDIM.name()==>"Horizontal"
- char code(void);
- // dimension "code" - first character returned by name()
- // HDIM.code()==>"H"
- };
-
- #ifndef SNAV0_C
- // predefined instances ("figurative constants")
- extern const axis // intended to be read only!
- nodim,
- hdim,
- vdim;
- extern const intersection
- nodirs,
- hdirs,
- vdirs,
- alldirs;
- #endif
- #define NUMDIMS 2 // number of dimensions (not extendable!)
-
- class axis_wgt : public axis {
-
- friend class weight_d; // technical, for internal use only
-
- protected :
- int width;
-
- public:
- axis_wgt(void) { width=0; }
- void set_axis(biconnective dirs) { axis::set_dirs(dirs); }
- } ;
-
- class weight_d {
- // character weight distributed on the two axises of the plane
-
- private:
- int value;
- axis_wgt wgt[NUMDIMS+1]; // axis 0 is dummi
-
- public:
- weight_d(int hwidth, int vwidth)
- // the standard constructor assumes two dimensions
- { wgt[HDIM].width=hwidth; wgt[HDIM].set_axis(HDIM);
- wgt[VDIM].width=vwidth; wgt[HDIM].set_axis(VDIM);
- // bitwise operation assumes 2 dimensions
- value=hwidth|(vwidth<<2);
- }
- weight_d(int weight_combi=0);
- // default typewriter-graphics
- weight_d(const weight_d &other);
- int operator()(void)
- // the unedited combination
- { return value; }
- int y(void)
- // extract horizontal width
- { return wgt[HDIM].width; }
- int x(void)
- // extract vertical width
- { return wgt[VDIM].width; }
- int width(axis dim)
- // extract width on axis
- { return wgt[dim()].width; }
- int replace(const axis &dim, int width);
- // replace width on one axis
- weight_d &mask(const weight_d &other);
- };
-
- #ifndef SNAV0_C
- // predefined instances
- extern const weight_d // intended to be read only!
- twgwgt, // 0:0 (TypeWriter Graphics)
- h1v1,
- h1v2,
- h2v1,
- h2v2,
- fullwgt; // 3:3 (full pixel block)
- #endif
-
- #endif
-
-