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 3 - headers.
- // This file defines the generic "panel" (formatted output medium),
- // and the generic "shape" (character-graphic element to be charted
- // on the former). Also defined is the archetypal shape "oblong". For
- // example of more specific shapes, refer to demo-3.
-
- // History:
- // 25.10.89 avner ben coded.
- /////// snav v1.1
- // 22.1.90-11.4.90 avner ben:
-
- // C++ v2.0 upgrade * added to class panel language indicator, color,
- // window * added to panel data redundancy with fix mechanism, color and
- // cursor processing * added class square_pos * renamed class point
- // point_pos * renamed class curve stroke * * changed some query-functions
- // to return by value * added default increment/decrement to class point *
- // changed some point functions to return void * defined transparent
- // screen-driver allocator * removed some inline code to implementation *
- // in class curve, replaces offset with pendn toggle * moved iterator
- // methods from curve to shape * added last-curve pointer to shape * added
- // offset from base to class curve, for use by shape iterator * moved some
- // function from implementation screen driver * removed specific shape to
- // snav3
-
- // Site history (of this copy):
- // __.__.__ ____________ : __________________.
-
- #ifndef SNAV2_H
- #define SNAV2_H
-
- #include <string.h>
- #ifndef SNAV1_H
- #include "snav1.hpp"
- #endif
- #ifndef NULL
- #include <stdlib.h>
- #endif
-
- class point_pos {
- // position on bi-dimensional panel
-
- friend class square_pos;
- friend class panel;
-
- private :
- int ypos, xpos, //position
- yofst, xofst; // ofst for the increment operator
-
- public :
- point_pos(int y=1, int x=1)
- { ypos=y; xpos=x; yofst=0; xofst=1; }
- point_pos(int y, int x, const direction &dir);
- point_pos(const point_pos &other)
- { ypos=other.ypos; xpos=other.xpos;
- yofst=other.yofst; xofst=other.xofst; }
- point_pos &operator=(const point_pos &other)
- { ypos=other.ypos; xpos=other.xpos;
- yofst=other.yofst; xofst=other.xofst;
- return *this; }
- point_pos(const direction &dir, const point_pos &other);
- void move(const direction &dir, int len=1);
- // increment/decrement y/x positions as implied by direction
- void chg_dir(const direction &dir, int increment=1);
- // modify internal offset for ++ operator
- void chg_dir(int yoffset, int xoffset)
- // modify internal offset for ++ operator
- { yofst=yoffset; xofst=xoffset; }
- boolean operator==(const point_pos &other)
- { return(ypos==other.ypos && xpos==other.xpos); }
- boolean operator!=(const point_pos &other)
- { return(ypos!=other.ypos || xpos!=other.xpos); }
- int y(void) { return(ypos); }
- int x(void) { return(xpos); }
- void sety(int y) { ypos=y; }
- void setx(int x) { xpos=x; }
- point_pos &operator+=(const point_pos &offset);
- // shift by user-specified offset
- point_pos &operator-=(const point_pos &shifted);
- // shift conter to user-specified offset
- point_pos &operator++(void)
- // shift by internally-held offset
- { ypos+=yofst; xpos+=xofst; return(*this); }
- point_pos &operator--(void)
- // shift counter to internally-held offset
- { ypos-=yofst; xpos-=xofst; return(*this); }
- char *name(void);
- int how_far(const direction &dir);
- };
-
- class square_pos
- { // position measured by pair of extreme corners.
-
- private :
- point_pos top, // up-left corner
- bot; // right-down corner
- int curlen, curwd; // current dimensions
-
- public :
- square_pos(const point_pos &start, const point_pos &end) {
- top=start; bot=end;
- curlen=bot.ypos-top.ypos+1;
- curwd=bot.xpos-top.xpos+1;
- }
- void set_start(const point_pos &start);
- void set_end(const point_pos &end);
- void set_end_y(int len);
- void set_end_x(int wd);
- void move_limit(const direction &dir, int ofst=1);
- void set_limit(const direction &dir, int pos);
- void move(const direction &dir, int len=1);
- int len(const axis &dim);
- point_pos start(void) { return top; } // (temporary result)
- point_pos end(void) { return bot; } // (temporary result)
- int sty(void) { return top.ypos; }
- int eny(void) { return bot.ypos; }
- int stx(void) { return top.xpos; }
- int enx(void) { return bot.xpos; }
- char *name(void);
- };
-
- enum vd_attr {
- VD_OFF=0, // "void" - leave alone
- VD_HI=1, // to be ORed int an integer-set
- VD_UNDLN=2,
- VD_BLNK=4,
- VD_REV=8,
- VD_HID=16
- };
-
- enum vd_clr { // pc oriented ordering
- VD_BLK,
- VD_BLU,
- VD_GRN,
- VD_CYN,
- VD_RED,
- VD_PNK,
- VD_YLW,
- VD_WHT
- };
-
- struct color_ind
- { // visual attribute configuartion - ansi style
-
- int attr; // ORed combi
- vd_clr backgnd, forgnd;
- color_ind(int attrs=0, vd_clr for_color=VD_WHT, vd_clr back_color=VD_BLK)
- { attr=attrs; backgnd=back_color; forgnd=for_color; }
- void set_attr(int attrs) { attr=attrs; }
- void attr_on(vd_attr at) { attr|=at; }
- void attr_off(vd_attr at) { attr^=(attr&at); }
- boolean ask_attr(vd_attr at) { return attr&at; }
- void toggle_attr(vd_attr at);
- void set_for_clr(vd_clr color);
- void set_back_clr(vd_clr color);
- vd_clr ask_for_clr(void);
- vd_clr ask_back_clr(void);
- void normalize(void);
- boolean operator()(void);
- boolean operator==(const color_ind &other);
- boolean operator!=(const color_ind &other);
- };
-
- class panel {
- // the generic screen object
-
- // abstract class for specific driver(s) to be implemented by user,
- // using late binding.
- // important: assumed are only console facilities - no keyboard input.
- // 'get' and 'put' apply to the screen matrix storage!
-
- private :
- boolean takes_graph;
- boolean wrap_around;
-
- protected :
- square_pos win;
- point_pos cursor;
- color_ind color, def_color;
- int lang; // pending language. user-managed values
- direction curdir; // current cursor direction
- point_pos top, bot; // added for efficiency
- int hlen, vlen; // added for efficiency
-
- public :
- // note: arguments defaulting to NULL are requests from the
- // driver to use (and advance) the built-in cursor.
- // otherwise (arguments supplied) "direct cursor adressing"
- // is requested (and built-in cursor is not affected).
-
- panel(square_pos *wind,color_ind *default_clr, direction *dir=NULL,
- boolean ingraph=TRUE, boolean inwrap=FALSE);
- ~panel(void); // restores if needed, does not clear!
-
- // the following methods must be redefined by the user
- // to suit the specific device:
- virtual char get_c(point_pos *pt=NULL)=0;
- // get char in specified/cursor position
- virtual void put_c(char c, point_pos *pt=NULL, direction *dir=NULL)=0;
- // put char in specified/cursor position,
- // using pending color.
- // if cursor position, cursor is advanced one step
- // in specified/cursor direction.
- // wrap-around practiced, if enabled
- virtual void put_color(const color_ind &clr, point_pos *pt=NULL)=0;
- // set color in specified/cursor position
- virtual void put_attr(vd_attr at, point_pos *pt=NULL)=0;
- // toggle attribute in specified/cursor position
- virtual void put_background(vd_clr colornum, point_pos *pt=NULL)=0;
- // set background color in specified/cursor position
- virtual void put_forground(vd_clr colornum, point_pos *pt=NULL)=0;
- // set forground color in specified/cursor position
- virtual color_ind get_color(point_pos *pt=NULL)=0;
- // retrieve color in specified/cursor position
- virtual boolean get_attr(vd_attr at, point_pos *pt=NULL)=0;
- // toggle attribute in specified/cursor position
- virtual void posit(point_pos *pt=NULL)=0;
- // reposition to specified/internal-cursor position
- virtual void save(void)=0;
- // save whole window content (not stackable!)
- virtual void restore(void)=0;
- // restore window to state of last save operation, delete buff
- virtual unsigned int ask_cursor(void)=0;
- // user-managed values
- virtual void set_cursor(unsigned int cursor_type)=0;
- // user-managed values
- virtual unsigned int hide_cursor(void)=0;
- // retruns current shape
- virtual void fix(void);
- // fix controlled data redundancy
-
- // the following are "macros" based on the above having been
- // defined in the working object:
- boolean ask_legal(point_pos *pt);
- // tell if point_pos is within window range
- // (default implementation supplied)
- boolean next(direction *dir=NULL, point_pos *pt=NULL);
- // move cursor/specified-point_pos one position
- // in pending/specified direction, if movement possible
- boolean wpnext(direction *dir=NULL, point_pos *pt=NULL);
- // move cursor/specified-point_pos one position
- // in pending/specified direction. wrap-around, if movement
- // impossible (if enabled in panel setup)
- char next_c(direction *dir=NULL, point_pos *pt=NULL);
- // get neighbour of cursor/specified char,
- // in pending/specified direction, no movement.
- void clr_eol(point_pos *pt=NULL);
- // clear from specified/cursor position to end-of-line
- void clear(void);
- // clear whole screen and posit home
- void put_s(char *s, point_pos *pt=NULL, direction *dir=NULL);
- // write a string on screen starting at cursor/specified point.
- // if cursor, it is advanced, with wrap-around if enabled.
- // not cursor, wrap around not practiced.
- void home(void);
- // position to start corner of screen, depending on
- // pending cursor direction.
- int ask_limit(const direction &dir);
- // beginning/end of window - height/breadth
- void set_limit(const direction &dir, int pos);
- // modify window dimensions
- void move_limit(const direction &dir, int ofst=1);
- // modify window dimensions, relative
-
- // full screen operations and navigation
- void arclist(point_pos *pt, int len, const direction &dir,
- const weight_d &wgt, boolean tipped=FALSE, color_ind *clr=NULL);
- // the graphic primitive (simmilar to shape "arc").
- // draw straight line from y:x in direction and weight
- // specified, possibly tipped by arrowhead.
- // semigraphics intersected are "welded", where possible.
- // for "welding" logic, refer to computer_alphabet::carrw()
- // in snav-1.
- // warning: arc listing ignores cursor, and does not wrap!
- void arcclr(point_pos *pt, int len, const direction &dir);
- // clear space formerly occupied by arc
- boolean twg_c(point_pos *pt);
- // translate one typewriter graphic char to 1h1v semigraphic
- // ("full screen" algorithm)
- int twg(void);
- // translate panel from typewriter graphics to 1h1v semigraphics
- char *env(point_pos *pt=NULL);
- // returns string made of current char, followed
- // by the four sorrounding chars, in direction++ order.
- intersection gowhere(point_pos *junction, intersection *result=NULL);
- // directions of arcs available from specified point on screen
- // (if point is currently occupied by a semigraphic). if result
- // is null, one is allocated. based upon env().
- // for association logic see alph::ccont() in snav-1.
-
- // management
- void set_color(const color_ind &new_color);
- color_ind ask_color(void);
- color_ind ask_def_color(void);
- virtual void toggle_attr(vd_attr at);
- boolean ask_attr(vd_attr at);
- void reset_color(void);
- void set_def_color(const color_ind &clr);
- void set_def_attr(vd_attr at);
- void set_def_background(vd_clr color);
- void set_def_forground(vd_clr color);
- void paint_background(vd_clr colornum);
- point_pos ask_where(void) { return cursor; }
- boolean ask_grph(void);
- boolean ask_wrap(void);
- direction ask_dir(void) { return curdir; }
- void set_dir(const direction &dir);
- void turn(void);
- int ask_len(const axis &dim);
- int ask_lang(void);
- void set_lang(int inlang);
- point_pos ask_corner(const direction &dir);
- // current screen window corner - either top-left or bot-right
- square_pos ask_window(void);
-
- // misc
- boolean enframe(const weight_d &wgt=h1v1, char *title="\0",
- boolean centered=FALSE);
- // draw oblong around panel and contract
- void deframe(void);
- // expand (checks nothing)
- } ;
-
- class screen_driver_manager
- { // run-time panel-implementation selector
-
- private:
- int default_screen;
- public:
- screen_driver_manager(int def=0);
- int ask_default(void);
- void set_default(int def);
- panel *allocate(const square_pos &window, int typ=0);
- // to be implemented by user, reflecting the local driver repertory.
- // for example, see file "demo0.hpp"
- };
-
- class arc
- { // the straight line shape - the basic graphic primitive
-
- protected :
- int len;
- direction dir;
- weight_d wgt; // only relevant axis considered
- boolean tipped; // tipped with arrowhead
- color_ind *color;
-
- public :
- arc(int inlen, const direction &indir, const weight_d &inwgt=h1v1,
- boolean intip=FALSE, color_ind *incolor=NULL)
- { len=inlen; dir=indir; wgt=inwgt; tipped=intip; color=incolor; }
- void list(panel *scr, point_pos *pt);
- void clear(panel *scr, point_pos *pt);
-
- // info
- int ask_len(void) { return len; }
- direction ask_dir(void) { return dir; } // (temporary result)
- weight_d ask_wgt(void) { return wgt; } // (temporary result)
- boolean ask_tip(void) { return tipped; }
- color_ind *ask_color(void) { return color; }
-
- // management
- void contract(void);
- void expand(void);
- void turn(void);
- void invert(void);
- void toggle_tip(void);
- void set_len(int inlen);
- void set_dir(const direction &indir);
- void set_wgt(const weight_d &inwgt);
- void mask(const weight_d &other_wgt);
- } ;
-
- class stroke : public arc
- { // arc as list member
-
- friend class shape;
-
- private :
- stroke *next;
- boolean pendn;
- point_pos offset; // used by "shape" iterator
-
- public :
- stroke(arc *src, boolean pen_down=TRUE);
- stroke(int inlen, const direction &indir, const weight_d &inwgt=h1v1,
- boolean intip=FALSE, color_ind *incolor=NULL, boolean pendn=TRUE);
- stroke *get_next(void) { return next; }
- void toggle_pen(void);
- boolean pen_is_down(void);
- } ;
-
- class shape
- { // the generic shape
- // not an "abstract class" (may also be defined and used as is)
-
- protected :
- stroke *stsk, *ensk; // curve
- char *sname; // name for info
-
- public:
- shape(stroke *sk=NULL, char *inname="amorph");
- virtual void append_stroke(stroke *sk);
- void append_stroke(const point_pos &offset);
- ~shape(void);
- virtual void list(panel *scr, point_pos *pt, boolean stay=TRUE);
- // warning: the generic shape lists only arcs pre-allocated!
- // in a "regular" shape, the user should supply specific listing.
- virtual void clear(panel *scr, point_pos *pt, boolean stay=TRUE);
- // warning: the generic shape clears only arcs pre-allocated!
- // in a "regular" shape, the user should supply specific clearing.
- char *name(void) { return(sname); }
- stroke *ask_start(void) { return stsk; }
- } ;
-
- class tracing : public shape
- { // shape copied from the real world, stored as unnormalized sequential tracing
- // a "procedural" class, implementing a shape + its imitializing process.
- // once the constructor returns, the user has nothing to look for in the
- // private members.
-
- private :
- point_pos start; // scan-start address
- struct landmark { // list of turn points (fifo)
- point_pos pos; // node address
- intersection dirstart; // all available directions
- intersection dirleft; // directions left unexplored
- landmark *next;
- landmark(point_pos *pt, intersection *avdir);
- void proceed(point_pos *start, intersection *avdir,
- direction *curdir);
- // recommend next dirction left to go
- } *stmark;
-
- public:
- tracing(panel *scr, point_pos *cursor);
- // fully automatic "probe constructor". if the like of a shape
- // exists in the real world (screen), in the specified
- // coordinates (cursor), then do your best to copy it.
- // ambiguities are solved automatically, using direction++ order.
- ~tracing(void);
- landmark *append_stroke(panel *scr, point_pos *cursor, direction *curdir);
- // one phase of the probe-constructor. read arc. return
- // available directions at exit point_pos. cursor set to exit point.
- landmark *mark(point_pos *cursor, intersection *avdir);
- // locate node entry for cursor, append if not in list
- };
-
- class oblong : public shape
- { // sample "regular shape"
-
- private :
- int wd, hgt;
- weight_d wgt;
-
- public :
- oblong(int width, int height, const weight_d &wgt=h1v1);
- void list (panel *scr, point_pos *pt);
- // spcified is left up corner
- void clear (panel *scr, point_pos *pt);
- // spcified is left up corner
- } ;
-
- #endif
-