home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 1.ddi / SNAV0111.ZIP / SNAV0.HPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-16  |  9.8 KB  |  344 lines

  1. //          ┌───────┐
  2. //    ─────────>│ AVNER │
  3. //    ─────────>│  BEN  │──────> Software Engineering Method
  4. //          └───────┘
  5. //    10 Dov-Hoz st. Tel-Aviv 63416 Israel tel. 972-3-221535
  6.  
  7. // The Screen NAVigator, ver 1.10 April 1990
  8. // Copyright (c) 1989 by Avner Ben
  9. // Snav is not, and never was, free software.
  10. // for conditions for use refer to file "copyrigh.txt"
  11.  
  12. // The Screen Navigator is an object-oriented device-independent
  13. // character-graphics driver package, written in the C++ language,
  14. // distributed in the form of C++ source code.
  15. // For further information refer to the documentation files.
  16.  
  17. // The user may not omit this text, from the beginning of the file, to
  18. // the line of asterisks below.
  19.  
  20. /***************************************************************************/
  21.  
  22. // package nucleus part 1 - headers.
  23. // This file defines the basic terms of "character geometry", to be used
  24. // in the more specific other parts.
  25. // for data-structure logic, refer to file "article".
  26.  
  27. // History:
  28. // 25.3.89 avner ben coded.
  29. // 28.7.89 avner ben - classified.
  30. /////// snav v1.1
  31. // 5.3.90  avner ben - C++ v2.0 upgrade.
  32. // 26.3.90 avner ben - removed some inline code to implementation
  33.  
  34. // Site history (of this copy):
  35. // __.__.__ ____________ : __________________.
  36.  
  37. #include <stdio.h>
  38. #ifndef SNAV0_H
  39. #define SNAV0_H
  40.  
  41. #ifndef TRUE
  42. typedef int    boolean;
  43. #define TRUE    1
  44. #define FALSE    0
  45. #endif
  46.  
  47. #define ENV_MODIFY    // governs the behaviour of some full-screen methods.
  48.  
  49. enum connective {
  50.     // the order reflects the natural order of reading a
  51.     // decision tree in english, horizontally oriented.
  52.     // note: the direction a character connects at is often
  53.     // opposite the one it "points" at!
  54.     NODIR,        // not a semigraphic
  55.     RTDIR,        // char connects right (bit 1 on)
  56.     UPDIR,        // char connects up (bit 2 on)
  57.     LTDIR=4,    // char connects left (bit 3 on)
  58.     DNDIR=8     // char connects down (bit 4 on)
  59. };
  60.  
  61. class direction
  62. { // which way are we going?
  63.  
  64.     friend class intersection;
  65.     friend class axis;
  66.  
  67.     private :
  68.         connective where;
  69.  
  70.     public :
  71.         direction(connective initdir=(connective)0x0001)
  72.         // by default, RTDIR
  73.         { where=initdir; }
  74.         direction(int initdir)             // c++ v1.0 compatibility
  75.         { where=(connective)initdir; }
  76.         direction(char c);
  77.         // construct direction from letter code
  78.         connective whereto(void)
  79.         { return(where); }
  80.  
  81.         // internal states:
  82.         connective reset(void)
  83.         { return (where=(connective)0x0001); }
  84.         connective next(void)
  85.         // next direction in sequence, or NODIR
  86.         // RTDIR.next()==>UPDIR.
  87.         { return((where=(connective)(where<<1 & 0x000f))); }
  88.         connective prev(void)
  89.         // previous direction in sequence, or NODIR
  90.         // DNDIR.prev()==>LTDIR
  91.         { return((where>>=1)); }
  92.         connective opposite(void);
  93.         // "opposite" direction. other direction on same axis
  94.         // RTDIR.opposite()==>LTDIR
  95.         direction &operator++(void)
  96.         // fancy version of next()
  97.         { where=(connective)(where<<1 & 0x000f); return *this; }
  98.         direction &operator--(void)
  99.         // fancy version of prev()
  100.         { where>>=1; return *this; }
  101.         friend direction operator~(const direction &dir);
  102.         // non-destructive opposite() - (temporary result)
  103.  
  104.         // miscelanous
  105.         connective operator()(void)
  106.         // fancy version of whereto
  107.         { return(where); }
  108.         boolean operator==(const direction &other)
  109.         { return(where==other.where); }
  110.         boolean operator!=(const direction &other)
  111.         { return(where!=other.where); }
  112.         connective clockwise(void);
  113.         // circular movement clockwise
  114.         char *name(void);
  115.         // decode direction name, capitalized.
  116.         // RTDIR.name()==>"Right"
  117.         char code(void);
  118.         // decode direction letter. first char returned by name().
  119.         // RTDIR.code()==>'R' */
  120.         int serial(void);
  121.         // serial number of direction 1,2,3,4.
  122.         // DNDIR.serial()==>4
  123. };
  124.  
  125. #ifndef SNAV0_C
  126. extern const direction        // intended to be read only!
  127.     nodir,
  128.     rt,
  129.     up,
  130.     lt,
  131.     dn;
  132. #endif
  133.  
  134. enum intersection_type {
  135.     J_NUL,        // no directions. not semigraphic
  136.     J_ARROW,    // 1 direction. terminal char
  137.     J_LINE,     // 2 directions, complementary.
  138.     J_CORNER,    // 2 directions, at right angle
  139.     J_FORK,     // 3 directions
  140.     J_CROSS     // all 4 directions
  141. };
  142.  
  143. class intersection
  144. { // where can we go from here?
  145.  
  146.     protected :
  147.         int value;
  148.  
  149.     public :
  150.         intersection(int dir_set=0x000f)
  151.         // by default, the whole range
  152.         { value=dir_set; }
  153.         intersection(connective onedir)
  154.         { value=(int)onedir; }
  155.         intersection(char *name);
  156.         // construct by name (as obtained from name()), case sensitive.
  157.         int whereto(void) { return(value); }
  158.  
  159.         // internal states:
  160.         int include(const direction &dir)
  161.         // add direction to set
  162.         { return((value|=dir.where)); }
  163.         int exclude(const direction &dir)
  164.         // subtract direction from set
  165.         { return((value^=(value&dir.where))); }
  166.         int intersect(const intersection &other)
  167.         // isolate directions included in both sets
  168.         // RTDIR+UPDIR+DNDIR.intersect(RTDIR+LTDIR)==>RTDIR
  169.         { return((value&=other.value)); }
  170.         intersection &operator+=(const direction &dir)
  171.         // fancy version of include
  172.         { value|=dir.where; return *this; }
  173.         intersection &operator-=(const direction &dir)
  174.         // fancy version of exclude
  175.         { value^=(value&dir.where); return *this; }
  176.         intersection &operator*=(const intersection &other)
  177.         // fancy version of intersect
  178.         { value&=other.value; return(*this); }
  179.  
  180.         // test inclusion:
  181.         boolean includes(const direction &member);
  182.         // test if direction is included
  183.         // RTDIR+LTDIR+UPDIR+DNDIR.includes(RTDIR)==>TRUE */
  184.         boolean includes(const intersection &subset);
  185.         // test if all target directions are included
  186.         // RTDIR+UPDIR+DNDIR.includes(RTDIR+LTDIR)==>FALSE
  187.         boolean intersects(const intersection ¶lel);
  188.         // test if at least one of the target directions is included
  189.         // RTDIR+UPDIR+DNDIR.intersects(RTDIR+LTDIR)==>TRUE
  190.         boolean operator>=(const direction &member)
  191.         // fancy version of includes()
  192.         { return(includes(member)); }
  193.         boolean operator>=(const intersection &subset)
  194.         // fancy version of includes()
  195.         { return(includes(subset)); }
  196.  
  197.         // miscelanous:
  198.         int operator()(void)
  199.         // fancy version of whereto
  200.         { return(value); }
  201.         boolean operator==(const intersection &other)
  202.         { return(value==other.value); }
  203.         boolean operator!=(const intersection &other)
  204.         { return(value!=other.value); }
  205.         boolean unary(void);
  206.         // test if direction set includes only one direction
  207.         // (RTDIR+LTDIR).unary()==>FALSE;
  208.         direction ask_first(void);
  209.         // find lowest order member - temporary result
  210.         direction get_first(void);
  211.         // extract lowest order member - temporary result
  212.         char *names(void);
  213.         // decode directions using direction.name(), comma seperated.
  214.         // (RTDIR+UPDIR).names()==>"Right,Up"
  215.         intersection_type type(void);
  216.         // tell intersection type
  217.         // (RTDIR+UPDIR).type()==>J_CORNER
  218.         char *name(void);
  219.         // decode intersection name
  220.         // (RTDIR+UPDIR+LTDIR).name()==>"Ufork"
  221. };
  222.  
  223. enum    biconnective {
  224.     NODIM,
  225.     HDIM,    // "horizontal", panel=row,    cartesian=y
  226.     VDIM    // "vertical",   panel=column, cartesian=x
  227. };
  228.  
  229. class axis : public intersection {
  230. // dimension on the plain
  231.  
  232.     friend class weight_d;
  233.  
  234.     protected :
  235.         biconnective where;
  236.  
  237.     public :
  238.         void set_dirs(biconnective newdim);
  239.         axis(biconnective newdim=NODIM)
  240.         { set_dirs(newdim); }
  241.         axis(int newdim)             // c++ v1.0 compatibility
  242.         { set_dirs((biconnective)newdim); }
  243.         axis(const direction &dir);
  244.         // generalize direction
  245.         // axis(RTDIR)==>HDIM */
  246.         biconnective wherein(void)
  247.         { return(where); }
  248.         intersection directions(void);
  249.         // copy pending direction set - temporary result
  250.         biconnective operator()(void)
  251.         // fancy version of wherein
  252.         { return(where); }
  253.         boolean operator==(const axis &other)
  254.         { return(where==other.where); }
  255.         boolean operator!=(const axis &other)
  256.         { return(where!=other.where); }
  257.         biconnective opposite(void);
  258.         // turn the other dimension
  259.         // HDIM.opposite()==>VDIM
  260.         friend axis operator~(const axis &other);
  261.         // non-destructive opposite - temporary result
  262.         char *name(void);
  263.         // decode dimension name
  264.         // HDIM.name()==>"Horizontal"
  265.         char code(void);
  266.         // dimension "code" - first character returned by name()
  267.         // HDIM.code()==>"H"
  268. };
  269.  
  270. #ifndef SNAV0_C
  271. // predefined instances ("figurative constants")
  272. extern const axis        // intended to be read only!
  273.     nodim,
  274.     hdim,
  275.     vdim;
  276. extern const intersection
  277.     nodirs,
  278.     hdirs,
  279.     vdirs,
  280.     alldirs;
  281. #endif
  282. #define NUMDIMS 2             // number of dimensions (not extendable!)
  283.  
  284. class axis_wgt : public axis {
  285.  
  286.     friend class weight_d;           // technical, for internal use only
  287.  
  288.     protected :
  289.         int width;
  290.  
  291.     public:
  292.         axis_wgt(void) { width=0; }
  293.         void set_axis(biconnective dirs) { axis::set_dirs(dirs); }
  294. } ;
  295.  
  296. class weight_d {
  297. // character weight distributed on the two axises of the plane
  298.  
  299.     private:
  300.         int value;
  301.         axis_wgt wgt[NUMDIMS+1]; // axis 0 is dummi
  302.  
  303.     public:
  304.         weight_d(int hwidth, int vwidth)
  305.         // the standard constructor assumes two dimensions
  306.         {    wgt[HDIM].width=hwidth; wgt[HDIM].set_axis(HDIM);
  307.             wgt[VDIM].width=vwidth; wgt[HDIM].set_axis(VDIM);
  308.             // bitwise operation assumes 2 dimensions
  309.             value=hwidth|(vwidth<<2);
  310.         }
  311.         weight_d(int weight_combi=0);
  312.         // default typewriter-graphics
  313.         weight_d(const weight_d &other);
  314.         int operator()(void)
  315.         // the unedited combination
  316.         { return value; }
  317.         int y(void)
  318.         // extract horizontal width
  319.         { return wgt[HDIM].width; }
  320.         int x(void)
  321.         // extract vertical width
  322.         { return wgt[VDIM].width; }
  323.         int width(axis dim)
  324.         // extract width on axis
  325.         { return wgt[dim()].width; }
  326.         int replace(const axis &dim, int width);
  327.         // replace width on one axis
  328.         weight_d &mask(const weight_d &other);
  329. };
  330.  
  331. #ifndef SNAV0_C
  332. // predefined instances
  333. extern const weight_d        // intended to be read only!
  334.     twgwgt,         // 0:0 (TypeWriter Graphics)
  335.     h1v1,
  336.     h1v2,
  337.     h2v1,
  338.     h2v2,
  339.     fullwgt;         // 3:3 (full pixel block)
  340. #endif
  341.  
  342. #endif
  343.  
  344.