K-Draw Report

download K-Draw Report

of 92

Transcript of K-Draw Report

  • 8/17/2019 K-Draw Report

    1/92

     

    K-DRAWSoftware aimed at facilitating easy and intuitive drawing with little training and a

    very shallow learning curve. 

    Submitted by

    KIRAN RAJMOHAN

    XII A

    BHAVAN’S VARUNA

    VIDYALAYA

  • 8/17/2019 K-Draw Report

    2/92

     

    Table of Contents

    ACKNOWLEDGEMENT .................................................................................................................................... 3

    INTRODUCTION .............................................................................................................................................. 4

    INTERFACE .................................................................................................................................................. 4

    NODES ........................................................................................................................................................ 4

    LINES .......................................................................................................................................................... 5

    RENDER ...................................................................................................................................................... 5

    OPTIONS ..................................................................................................................................................... 6

    RECURSIVE DRAW ...................................................................................................................................... 6

    SAVE ........................................................................................................................................................... 6

    OPEN .......................................................................................................................................................... 6

    EXIT ............................................................................................................................................................ 7

    MEMORY STATUS ....................................................................................................................................... 7

    HELP ........................................................................................................................................................... 7

    SOFTWARE ..................................................................................................................................................... 8

    GLOBAL OBJECT DECLARATION ................................................................................................................. 8

    PROGRAM EXECUTION and TERMINATION ............................................................................................... 8

    NODES and LINES ....................................................................................................................................... 8

    DIALOG BOXES ........................................................................................................................................... 9

    FILE STRUCTURE ....................................................................................................................................... 10

    CLASS HIERARCHY ........................................................................................................................................ 11

    K-DRAW.CPP ................................................................................................................................................ 14

    HEADERFILES ................................................................................................................................................ 17

    MYDEFINE.H ............................................................................................................................................. 17

    MYCLASS.H ............................................................................................................................................... 19

    MYMOUSE.H  ........................................................................................................................................ 27

  • 8/17/2019 K-Draw Report

    3/92

     

    MYNODES.H ............................................................................................................................................. 31

    MYLINE.H ................................................................................................................................................. 42

    MYLCOLOR.H ............................................................................................................................................ 47

    BU.H ......................................................................................................................................................... 50

    BUNB.H .................................................................................................................................................... 53

    MYDIALOG .H ........................................................................................................................................... 55

    MYFILE.H .................................................................................................................................................. 59

    MYSAVE.H ................................................................................................................................................ 61

    MYOPEN.H ............................................................................................................................................... 66

    MYEXIT.H.............................................................................................................................................. 69

    MYRENDER.H ........................................................................................................................................... 70

    MYOPT.H .................................................................................................................................................. 73

    MYTIME.H ................................................................................................................................................ 76

    MYHELP.H ................................................................................................................................................ 77

    MYSTR.H ................................................................................................................................................... 79

    MYMISC.H ................................................................................................................................................ 80

    SCREEN SHOTS ............................................................................................................................................. 82

    BIBLIOGRAPHY ............................................................................................................................................. 91

  • 8/17/2019 K-Draw Report

    4/92

     

     ACKNOWLEDGEMENT

    I gratefully acknowledge the support and guidance given to me by my teachers and friends.

    I would like to thank MrsSunitha, Principal , Bhavan’s Varuna Vidyalaya for giving me the opportunity to

    do this project work.I would like to acknowledge theable guidance and support I received fromMrs.

    Aleyamma George and MrsSheela, our Computer teachers. I thank my family members for supporting

    me throughout the development of this project right from the start. I thank my friends for their support

    and the interest they have shown in the completion of this project.

  • 8/17/2019 K-Draw Report

    5/92

     

    INTRODUCTION

    K-DRAW is a software aimed at facilitating easy and intuitive drawing with littletraining and a very

    shallow learning curve.

    The program uses a pseudo-threaded system which enables the user to use buttons and other features in

    a windows-like environment with mouse and keyboard shortcut support. Visual and textual cues have

    been incorporated to make the software easier to use and the save and open features ensure that your

    work can be resumed after stopping and can be backed up.

    INTERFACE

    The interface consists of mainlyfive areas.

      Top menu

    It consists of the four file and program management buttons, viz, SAVE, OPEN, OPTIONS and

    EXIT.

      Colour selector

    It displays the possible line colours that can be used. Clicking over any of the colour activates

    the colour.

      Node management and render

    It gives theuser the option to create, move and delete nodes and also to render the image toget the final picture.

      Help

    The help gives context sensitive tips on how to use the software.

      Work area

    It is the canvas in which all the drawing is done and is the largest and central area of the

    interface.

    NODES

    The basic concept behind the drawing system is the node. Nodes serve as movable anchor points to

    which lines can be attached. Each node can be moved separately or made immovable by locking them.

    The nodes are represented as small circles which change colour reflecting the status of the node. The

    nodes turn light blue when the mouse hovers over them. The nodes are moved by LEFT clicking over

    them. Upon LEFT click, the nodes turn green indicating active status and will follow the mouse anywhere

    over the workspace till another LEFT click which deactivates the node and frees the mouse. When

    activated, the mouse movement is restricted to the work area.

  • 8/17/2019 K-Draw Report

    6/92

     

    New nodes are created by entering the CREATE mode by clicking the button on the right of the screen.

    LEFT clicking creates a single new node at the point of click. If SHIFT key is pressed while clicking, the

    create mode remains activated enabling further uninterrupted creation of nodes until a node is created

    without the SHIFT key being pressed. The create mode can be exited at any time by RIGHT clicking

    anywhere on the work area. 

    Existing nodes are deleted by entering the DELETE mode by clicking the button on the right of the screen.

    The functioning is similar to the create mode, i.e. LEFT clicking on a node deletes it. Keeping the SHIFT

    key pressed chains the commands. RIGHT clicking exits the mode.

    RIGHT clicking on a node (when not activated) locks the node. This ensures that the node is not

    accidentally moved or deleted. It is also very handy when creating lines. RIGHT clicking again on any

    locked node unlocks it.

    The MOVE mode is automatically selected after returning from any of the modes. All node manipulations

    including line creation is done in this mode.

    LINES

    Lines are created between nodes.

    LEFT clicking on a node while pressing the SHIFT key initiates the line creation. The endpoint of the line is

    selected by clicking on another node. When selecting the second node, if SHIFT key is pressed, a line is

    created between the previous node and the present node and a new line is initiated from the present

    node. The mode is chained as long as SHIFT key is pressed during the clicks and is terminated when a

    node is selected without pressing the SHIFT key. The mode can also be terminated by RIGHT clicking

    anywhere in the work area. Note that locked nodes cannot serve as starting point of lines. However, a

    locked node can act as an endpoint and if the line creation is chained when clicking over a locked node, it

    can act as a new start point.

    The colour of the new lines created depends on the current colour selected. Any of the 16 colours

    supported by the compiler can be selected from the colour selector by clicking over the required colour.

    The selected colour turns solid while all other colours turn dotted.

    Lines are deleted just as they are created. While trying to create a line between two nodes, if a line

    already exists between them, the existing line is deleted else a new one is created. All the facilities

    associated with creating a line are available while deleting them too.

    If any node is moved, all associated lines are automatically updated to reflect their new positions.

    Whether only the immediate lines are updated or not depends on the RECURSIVE DRAW status which isexplained in the following sections.

    RENDER

    The final image is obtained by LEFT clicking the RENDER button. Upon rendering, a new screen is shown

    in which only the lines are displayed. All nodes and interface buttons are removed except for a new

    button, RETURN. Clicking the RETURN button exits the render mode and returns to work mode.

  • 8/17/2019 K-Draw Report

    7/92

     

    OPTIONS

    The options menu is aimed at providing a facility to the user to choose different performance options to

    enable maximum and smooth utilization of resources. Currently only one option, i.e. the recursive draw

    option is available. The option is enabled or disabled by checking or unchecking the check box using LEFT

    mouse click.

    RECURSIVE DRAW

    Recursive draw is an algorithm by which all associated nodes, not only the immediate associations but

    also the further connections are updated. This requires a lot of processing power depending on the

    picture draw and line branching.

    If recursive draw is disabled, moving a line over another node or line will erase the node or line

    temporarily. The image howeverwill update automaticallywhen any node is hovered over. If however the

    recursive draw is enabled, any line which is in any way connected to the activated node will be updated.

    This ensures a better working experience at the cost of a little processing power.

    SAVE

    The SAVE button found on the top left of the screen gives the user the option to save the current file in

    the .kdr format. The format is specially designed for use with K-DRAW and hence is currently not

    supported by any other software. The user may or may not add the extension to the file name. If the

    extension .kdr is already entered by the user, it will not be modified. If however the extension is not used

    or any other extension is used, a .kdr extension will be added to the filename automatically. The software

    also ensures that a file name entered is not of zero length (empty). If so, a message is displayed

    mentioning the same and waits for further action. The file name entry field supports BACKSPACE also.

    The dialog box has the options SAVE and CANCEL which have obvious actions associated with them.

    OPEN

    The OPEN dialog box gives the user the ability to open any previously saved .kdr file to continue, review

    or render the work. The user may enter the name of the file to be opened with or without the extension.

    If extension is not present, it will automatically be added. If file was previously saved in the current

    working session, then that file name willautomaticallyappearas the file name for opening. The empty file

    name message will be displayed here too as in the case of the SAVE dialog box.The file name entry field

    supports BACKSPACE also.

    The dialog box has the options OPEN and CANCEL which have obvious actions associated with them.

  • 8/17/2019 K-Draw Report

    8/92

     

    EXIT

    The EXIT button takes you to the EXIT dialog box which gives the user the option to either SAVE (and exit)

    or return to the program (CANCEL) or to exit the program without saving (EXIT). This ensures that the

    work is not lost due to unintentional exits.

    MEMORY STATUS

    The green/yellow/red circle just above the COLOUR SELECTOR is indicative of the amount of free memory

    (heap space) left. Green indicates that there is lots of space left. Yellow is a warning that the heap space

    is very limited and red indicates critical status. There is only enough space to just open a dialog box and

    save and exit the program. The user would either have to delete some nodes to free more space or quit

    the program if the red status is shown.

    HELP

    The help field displays essential tips required to work with K-DRAW depending upon the current mouse

    position and program mode.

  • 8/17/2019 K-Draw Report

    9/92

     

    SOFTWARE

    This section explains a few of the program’s main algorithms briefly. 

    All the classes are forward declared in the MYCLASS.H header file to allow bridged usage of the class as in

    the case of class nodes and class lines. Numerous #defined constants are declared in the MYDEFINE.H

    header file which makes the program far more readable than it would have been otherwise. Some

    macros also have been implemented to make the calls to the objects of nodes and lines as they are

    referenced and typecasted from object. Some facilities like scenes have been included into the file

    format to allow expandability in future stages. Since the format already incorporates the facility, the files

    would be cross compatible.

    The program has to be compiled with the LARGE memory model and container library and graphics

    library enabled.

    GLOBAL OBJECT DECLARATION

    Numerous global objects have been declared in the program. These need to be global and had to be

    declared with the class definitions as they are used in many other member functions. But these cannot

    initialize the variables with valid values until performing some manipulations using some graphics

    functions. Therefore the program calls default constructors which initializes the variables with dummy

    values. The true values are later supplied by creating a temporary instance local to a function and

    copying this data into the global object. This way, all the data can be initialized for a global object after

    entering the main.

    PROGRAM EXECUTION and TERMINATION

    The core part of the program is executed in an infinite loop. The loop starts as soon as all the

    initializations are done and the welcome message is displayed. The loop and hence the program is exited

    from the EXIT dialog box which uses exit() to terminate the program. The graphics termination function is

    automatically executed just before the exit by using the atexit() method.

    NODES and LINES

    The nodes and lines are managed using a modified version of the built in Container class ARRAY. The class

    MYARRAY is derived from ARRAY to utilize the reallocate() function used to reallocate memory spaces in

    the array to ensure optimum space utilization.

    The class ARRAY itself takes all the arguments of the object* type which is a virtual base class of ARRAY.

    In order to add, modify or delete the nodes or lines object to MYARRAY, it had to be of type object.

    Therefore, class NODES and LINES are derived from class QUEUE, another built-in container class, for the

  • 8/17/2019 K-Draw Report

    10/92

     

    sole purpose of making them derived from class OBJECT. The retrieved data of the object* type is then

    type casted and referenced to get back the actual objects that were stored, i.e. nodes or lines.

    This technique has many associated advantages.

      All the elements can be accessed using index or pointer.

      The Array size can be grown or reduced easily.

      The data is well managed since it is a built –in class.

      The size of the array can be readily retrieved .

      The array can be reallocated to change size and to ensure that all indices are properly filled.

      The system is very flexible as it can be migrated to most other container class as may be

    demanded by future development.

    The NODES class employs all the methods required for the creation, modification, deletion and for

    updating the on-screen appearance of a node. It also employs some static functions and data members

    to manage the overall status and working of the nodes.

    The function nodes::mouseact () is used to perform all nodes related changes. It manages the

    redistribution of control to various other functions related to node management depending on the

    program mode and node status.

    The line creation is called from nodeact() which manages the appearance, status and other parameters of

    the nodes.

    Each node has a pointer list which has a reference to all the lines that are directly connected to that node

    and each line in turn has two pointers which refer to the two endpoints of the line. This format ensures

    that the lines and nodes can be traversed through without any global ‘map’.  

    The lines and nodes are updated as per the status of the variable option::recursivedraw which decides

    whether all the connectionsfrom a node are traversed or whether just the immediate lines are updated.

    DIALOG BOXES

    The dialog boxes are manually implemented using the basic methods available in C++.

    The background is first captured using getimage () and is stored. This requires a lot of memory

    temporarily and hence the program has to be compiled in the LARGE memory model to allow access

    beyond 64kb memory segment. Then the background over that area is erased and the new data is

    displayed. After the dialog box’s need is over, the older image saved is returned using putimage ().

    Each dialog box can be easily created with upto 3 buttons which can be used for any input purpose.

    Further, the text input box implemented for the file access dialog boxes are empowered with backspace

  • 8/17/2019 K-Draw Report

    11/92

     

    capabilities implemented using bioskey(). The heading of the Dialog box is automatically centered and

    the text displayed is automatically divided into multiple lines while ensuring that no line is cut in the

    middle or overflows the boundaries of the box. The position of the box can also be easily specified.

    FILE STRUCTURE

    The .kdr format used for saving the pictures uses a format that is complete and comprehensive and yet

    easily accessible. The data is structured so that all data regarding a scene is directly accessible from the

    first line of the scene. The file also features a version variable which helps to ensure that only a

    compatible file version is readable. This is especially helpful when modifying the file structure to ensure

    that only the latest files are read by the program.

  • 8/17/2019 K-Draw Report

    12/92

     

    CLASS HIERARCHY

    This section pictorially represents the class inheritance patterns and the class members grouped

    by their access mode specifiers.

    Buttons and its derivatives

  • 8/17/2019 K-Draw Report

    13/92

     

    Dialog box and its derivatives

  • 8/17/2019 K-Draw Report

    14/92

     

    Other classes

  • 8/17/2019 K-Draw Report

    15/92

     

    K-DRAW.CPP//if not compiling DO: options->Linker->settings->//set container libraries & graphics//increase debugger->heap size to 640k

    //**************USE LARGE MEMORY MODEL**************///basic i/o & graphics#include #include #include #include #include #include #include #include #include #include

    //container class#include#include#include

    #include

    #include "mydefine.h"#include "myStr.h"#include "myClass.h"#include "myHelp.h"

    #include"MyTime.h"

    #include "mymouse.h"

    #include "bu1.h"

    #include "mynodes.h"#include "myline.h"#include "mydialog.h"#include "myfile.h"#include "mysave.h"#include "myopen.h"#include "myexit.h"#include "mylcolor.h"#include "myrender.h"#include "myopt.h"

    #include "myMisc.h"

  • 8/17/2019 K-Draw Report

    16/92

     

     void graphinit(void) //initialise graphics, close maunally{

    /* request auto detection */int gdriver = DETECT, gmode, errorcode;

    /* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");

    /* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{

    printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */

    }

    setviewport(0,0,getmaxx(),getmaxy(),1);setcolor(getmaxcolor());

    }

     void exitmanage(){

    closegraph();}

     void main(){

    clrscr();graphinit();

    ////////////PROGRAM STARTS/////////////////

    //initialise all basic objectsnodes::nodeinit();

     buttoninit(); //all buttonsm.mouseinit(); //mouseh.helpinit(); //help

    m.mouseon();

    initexitdiag();initopendiag();initsavediag();

    lc.disp(); //colour selector//initialisations over

    atexit(exitmanage); //runs at exit time

     welcomediag();

  • 8/17/2019 K-Draw Report

    17/92

     

     while(1){

    m.mousemodes(); //check mouse pos & find current mode

    memshow(); //memory status

    if (m.mousemode==bottom_menu){

    for (int i=0;iautomaticob.buttonact(); //openeb.buttonact(); //exitomb.buttonact(); //options

    if(sb.getstat()!=hover && ob.getstat()!=hover&& eb.getstat()!=hover && omb.getstat()!=hover )

    h.display();}else if(m.mousemode==top_menu)

    lc.act(); //color selectelse //work area{

    switch(nodebuttons::getmode()){case new_node:

    if (m.mousemode==work)nodes::newnode(); //call to make a new node

     break;case move_node:

    if (m.mousemode==work && nodes::last()>=0)nodes::mouseact(); //finds and does nodeactions

     break;case delete_node:

    h.display(H_delnode);if (m.mousemode==work)

    nodes::deletenode(); break;

    }}

    if(kbhit())getch(); //clear any unused characters in buffer

    }}

  • 8/17/2019 K-Draw Report

    18/92

     

    HEADERFILES

    MYDEFINE.H

    // All #define//mouse.h//----------------------------------------------------------//mouse clicks#define LCLICK 1#define RCLICK 2#define NOCLICK 0

    //mouse modes#define work 1 //side menu#define topbar 2#define bottom_menu 3#define top_menu 4

    //full area constants#define fullx1 1#define fullx2 635#define fully1 1#define fully2 476

    //side bottom menu area constants#define bmx1 550#define bmx2 635#define bmy1 190#define bmy2 466

    //side top menu area constants

    #define tmx1 550#define tmx2 635#define tmy1 21#define tmy2 190

    //top bar constants#define tbx1 1#define tbx2 500#define tby1 1#define tby2 20

    //work area#define wx1 27 //20+7 //to avoid crossing work area#define wx2 543 //500-7

    #define wy1 27 //20+7#define wy2 449 //476-7//-------------------------------------------------------//nodes.h//-------------------------------------------------------#define open 0 //movable#define hover 1 //mouse over#define active 2 //currently selected#define locked 3 //cannot move

  • 8/17/2019 K-Draw Report

    19/92

     

    #define del_hov 4 //when hover for delete#define linesel 5 //when shift is pressed when hovering

    #define wnode(i) ((nodes&)worknodes[(i)])#define conline(i) ((lines&)conlinesArr[(i)])#define nodecline(i) ((lines&)cline[(i)])//-------------------------------------------------------//buttons.h//-------------------------------------------------------#define off 0 //active &hover defined in mouse.h#define on 1//for myoptions->options#define exitb -2

    //work mode definitions#define node_work 0 //also are corresponding array index#define scene 1#define background 2

    #define new_node 0//BuNB.h //also are corresponding array index#define move_node 1

    #define delete_node 2

    #define button_out_color GREEN#define button_in_color BLACK#define button_act_text_color RED//-------------------------------------------------------//MYRENDER.H//-------------------------------------------------------#define renderb 3#define renderbe 4

    //-------------------------------------------------------//mydialog.h//--------------------------------------------------------//open-> 0 defined for nodes#define cancel 1#define ok 2#define save 3

    #define yes 2 //same as ok#define no 1 //same as cancel//-------------------------------------------------------//topbu.h//-------------------------------------------------------#define savebu 0//-------------------------------------------------------//mysave.h

    //-------------------------------------------------------#define iovar(var) (char*)&(var),sizeof(var)//-------------------------------------------------------//myoption.h//--------------------------------------------------------------------------#define options 5//-------------------------------------------------------//myIK.h//---------------------------------------------------------------------#define findlength(x1,y1,x2,y2) sqrt( ( (x2)-(x1) )*( (x2)-(x1) ) + ( (y2)-(y1) )*( (y2)-(y1) ))

  • 8/17/2019 K-Draw Report

    20/92

     

    MYCLASS.H

    //All class forward declarations/************************* MYTIME.H **********************************/class MyTime{

    int stat;double elapTicks;clock_t Begin, End; //initialize Begin and End for the timer

    public:MyTime();

     void start(); void stop();int status();float time();

    };/************************** MYTIME.H over ******************************/

    /************************** MYHELP.H **********************************/

    class help{

    int x,y,h,now;char *s[hstrnum];

    public :help();

     void helpinit(); //can do only after init of graphics void display (int code=-2);

    }h;/************************* MYHELP.H over ******************************/

    /************************* MYMOUSE.H *********************************/

    union REGS in,out;short range(int x,int y,int px,int py,int r);

    class mouse //class for mouse fuctions{private:

    int callmouse();int mousehide();

    public:int mousemode;

     void mouseinit();

     void mousemax(int x1,int x2,int y1,int y2); void mouseon()

    {callmouse();} void mouseoff()

    {mousehide();}

     void mouseposi(int &xpos,int &ypos,int &click );// return latest coords & click (single look)

    int pollmouse(int xcond,int ycond,int click);//look for a click at a point (single look)

  • 8/17/2019 K-Draw Report

    21/92

     

    int pollmouse(int xcond,int ycond,int click,int w,int h);int hovermouse(int x1,int y1,int w1,int h1);

    // look for hover over an area (single look) void mouseposi(int &xpos, int &ypos,int &click, int dummy);

    //look for any click and return click//type and coords (polled) ; dummy for overloading

     void mouseclick(int &xnew,int &ynew,int c=LCLICK);// find coords of a click (polled)

     void mousemodes();//update mousemode according to current posint ifclick(); //return any click anywhere

    }m;/********************* MYMOUSE.H over*************************************/

    /************************BU.H *****************************************/class buttons{protected:

    int x1,y1,x2,y2,id,stat,prestat;//id same as the corresponding workmode//stat= off/hover/active

    char text[20];

     void mouseover(); void buttonclick(); void button_active_draw();

    friend nodes;

    public: buttons(){} buttons(int x1t,int y1t,int x2t,int y2t,int idt,char textt[]);

     void drawbutton(); void reset();//stat off,draw buttonint getstat();friend void buttoninit(); //calls all button inits

    };/*********************** BU.H over ************************************/

    /********************* MYLINES.H **************************************/class lines:public Queue

    {static int arraysize();int recurstat;

    public:int color;

    nodes *p[2];//starting and ending nodeslines(){

    p[0]=NULL;

    p[1]=NULL;recurstat=0;

    }

    static int num;

  • 8/17/2019 K-Draw Report

    22/92

     

    static void lineact(nodes *p1);static void newline(int x1,int y1,int x2,int y2,int c);

    //to make lines automatically for openstatic void del_line(lines *l);static void empty();static lines* findcommon(nodes*n1 , nodes*n2);static void reset_recurstat();

     void drawline();//non recursive draws & initial nodes void drawline(nodes *n);//all recursive draw after 1st node

    };int lines::num=-1;/********************MYLINES.H over ************************************/

    /******************* MYLCOLOR.H ****************************************/class linecolor{

    int h,w;//height & width of each box;int x,y,th,tw;//total height & width

    public:

    linecolor();static int color;

     void disp(); void act();

    }lc;int linecolor::color=WHITE;/******************* MYLCOLOR.H over**********************************/

    /******************MYNODES.H *****************************************/class MyArray: public Array //to get reallocated function{public:

    MyArray(int a,int b,int c):Array(a,b,c){}

     void reallocate(int n){

     Array::reallocate(n);}

    };

    //----------------------------------------------------------------------------class nodes :public Queue

    {private:

    int x,y,stat,prex,prey,prestat;static int laste,activated,globalstat;

    //laste->saves last node;//activated->last elemet index for mouseact //globalstat->formouseact management

    int pahx,pahy; //store pre x,y pos to prevent continuous//change of state b/w active&hover

  • 8/17/2019 K-Draw Report

    23/92

     

    friend int findnode(int x,int y);//search and return 1 node(index) in//5 pixel range, -1 if not foundfriend nodes& latestnode();//return last added nodefriend void savescene(char *fname,int sceneid,int newf);

    //write node data to file

    friend lines; //to allow manipulationsint numlines; //num of lines per nodelines **cline; //all immidiately related lines

     void addline( lines *l); void deleteline( lines *l);

     void xy (int x1,int y1); //save old coords & put new coords

     void makenode(int x1, int y1); void nodeact(); //do mouse actions void drawnode();//called for updating status,calls recursions as needed void drawnode1(); //draws the nodes void drawnode(lines *l); //called only for 2nd level recursion

    static int delnodeclick(int &newx,int &newy,int &node);static int arraysize();

    MyTime T_l,T_l1; //T_l=> timer for locked mode

    public:

    nodes(); //default constructornodes(int dummy); //for creating dummy object without affecting laste

    static int last() //return last nodes index{return laste;}

     void del_all_lines(); //delete all lines connected to a node

    static void nodeinit(); //emptystatic void newnode(); //new node modestatic void newnode(int x1,int y1); //to automatically make node at x1,y1

    //(used by open dialog)static void deletenode(); //delete mode, finds node itselfstatic void empty(); //to delete all existing nodesstatic void mouseact(); //called from mainstatic void draw_all();

    ~nodes();};

    int nodes::laste=-1; //no nodesint nodes::activated=-1;int nodes::globalstat=open;/*********************** MYNODES.H over ******************************/

  • 8/17/2019 K-Draw Report

    24/92

     

    /*********************** MYSCENE *************************************/class scenedat{public:

    static int curscene;};int scenedat::curscene=1;

    /*********************** MYSCENE over ********************************/

    /*********************** MYDIALOG.H **********************************/class diagbutton:public buttons{public:

    static int mode;diagbutton(){} //for array

    diagbutton(int x1t,int y1t,int x2t,int y2t,int idt,char textt[]); void buttonact();

    static void resetmode(){mode=-1;}

    };int diagbutton::mode=-1;//----------------------------------------------------------------------------class dialog{

    int optionnum,numlines;char heading[20],**line;

     void far *buf;

    protected:int x1,y1,x2,y2;diagbutton b[3];

    public:dialog(){

    line=NULL; buf=NULL;

    }dialog(int x1t,int y1t,int x2t,int y2t,int optionnum,char **buttontextt,char headingt[20],char

    *text,int idt[3]); void show_diag(); void act_diag();

     void clear_diag();};/************************** MYDIALOG.H over *************************/

  • 8/17/2019 K-Draw Report

    25/92

     

    /************************** BUNB.H **********************************/class nodebuttons : public buttons //side bottom work buttons

    //only one active at a time{private:

    static void reset_last_active();static int lastactive;static int mode;

    public: void buttonclick(); virtual void buttonact();friend void nodebuttoninit();static int getmode();static void changemode(int to_mode)//change mode,button statsand redraw

    }nb[4]; //node buttons

    int nodebuttons::lastactive=new_node; //will be correct after 1st clickint nodebuttons::mode=new_node;/************************ BUNB.H over********************************/

    /***************** ****** MYFILE.H **********************************/class filediag:public dialog{

    protected:

    public:char oldfname[25]; //last used filename without extensionfilediag();filediag(int x1t,int y1t,int x2t,int y2t,int optionnumt,

    char **buttontextt,char headingt[20],char *textt,int idt[3]);

     void disp_diag();};/*********************** MYFILE.H over *******************************/

    /*********************** MYSAVE.H ************************************/class savediag:public filediag{

    public:static int firstsave;

    savediag();savediag(int x1t,int y1t,int x2t,int y2t,int optionnumt,

    char **buttontextt,char headingt[20],char *textt,int idt[3]);

    friend void savefile(char *fname,int sceneid,int newf); void disp_diag();

    }dsave;int savediag::firstsave=1; //1st save or not//--------------------------------------------------------------------------class savebutton:public diagbutton{public:

    savebutton()

  • 8/17/2019 K-Draw Report

    26/92

     

    {} void buttonact();friend void savebuttoninit();

    }sb;/********************** MYSAVE.H over *******************************/

    /**********************MYOPEN.H ************************************/class opendiag:public filediag{

    public:opendiag();opendiag(int x1t,int y1t,int x2t,int y2t,int optionnumt,

    char **buttontextt,char headingt[20],char *textt,int idt[3]);

    friend void openfile(char *fname); void disp_diag();

    }dopen;//-------------------------------------------------------------------------

    class openbutton:public diagbutton{public:

    openbutton(){}

     void buttonact();friend void openbuttoninit();

    }ob;/*********************MYOPEN.H over ***********************************/

    /********************* MYEXIT.H ****************************************/class exitdiag:public filediag{

    public:exitdiag();exitdiag(int x1t,int y1t,int x2t,int y2t,int optionnumt,

    char **buttontextt,char headingt[20],char *textt,int idt[3]);

    friend void exit(char *fname); void disp_diag();

    }dexit;//------------------------------------------------------------------------class exitbutton:public diagbutton{

    public:exitbutton()

    {} void buttonact();friend void exitbuttoninit();

    }eb;/*********************** MYEXIT.H over *********************************/

  • 8/17/2019 K-Draw Report

    27/92

     

    /*********************** MYRENDER.H ************************************/class renderbutton:public buttons{public:

    renderbutton(){}

    static void render();

     void buttonact();friend void renderbuttoninit();

    }rb;//-----------------------------------------------------------------------

    class renderexitbutton:public buttons{public:

    renderexitbutton(){}

     void disp();

    int buttonact();friend void renderbuttoninit();

    }reb;/********************* MYRENDER.H over *********************************/

    /********************* MYOPT.H *****************************************/class optionbutton{

    char *text;int stat,x,y,data;

    public:

    optionbutton(){

    text=NULL;}

    int getstat(){

    return stat;}

    optionbutton(int x1,int y1,char *text1,int dat);

     void draw(); void act();

    };

    //------------------------------------------------------------------------class option:public dialog{

    static int recursivedraw;optionbutton rd;

    friend lines;

    public:

  • 8/17/2019 K-Draw Report

    28/92

     

    option();

    option(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char *textt,int idt[3]);

    static int isrecursive(){

    return recursivedraw;}

     void disp();}opt;int option::recursivedraw=1;//------------------------------------------------------------------------class optionmenubutton:public buttons{

    public:optionmenubutton(){}

     void buttonact();friend void optionmenubuttoninit();

    }omb;/***************** MYOPT.H over************************************/

    MYMOUSE.H

    /*************************MYMOUSE.H***********************************union REGS in,out;short range(int x,int y,int px,int py,int r);

    class mouse //class for mouse fuctions{private:

    int callmouse();int mousehide();

    public:int mousemode;

     void mouseinit(); void mousemax(int x1,int x2,int y1,int y2);

     void mouseon(){callmouse();}

     void mouseoff(){mousehide();}

     void mouseposi(int &xpos,int &ypos,int &click );//return latest coords & click (single look)

    int pollmouse(int xcond,int ycond,int click);//look for a click at a point (single look)

    int pollmouse(int xcond,int ycond,int click,int w,int h);

  • 8/17/2019 K-Draw Report

    29/92

     

    int hovermouse(int x1,int y1,int w1,int h1);//look for hover over an area (single look)

     void mouseposi(int &xpos,int &ypos,int &click, int dummy);//look for any click and return click type and coords //(polled) ; dummyfor overloading

     void mouseclick(int &xnew,int &ynew,int c=LCLICK);// find coords of a click (polled)

     void mousemodes(); //update mousemode according to current posint ifclick(); //return any click anywhere

    }m;***************************************************************/int mouse::callmouse(){in.x.ax=1; //set interrupt valueint86(51,&in,&out); //call interruptreturn 1;

    }

    int mouse::mousehide(){

    in.x.ax=2;int86(51,&in,&out);return 1;

    }

    short range(int x,int y,int px,int py,int r)//if (x,y) is in +-r range of{ //(px,py) short to decrease size

    if( x > px-r && x < px+r && y > py-r && y < py+r)return 1;

    return 0;}

     void mouse::mouseinit() // set max vertical horizontal movement{in.x.ax=8;in.x.cx=0;in.x.dx=getmaxy();int86(51,&in,&out);

    in.x.ax=7;in.x.cx=0;in.x.dx=getmaxx();int86(51,&in,&out);

    }

     void mouse::mousemax(int x1,int x2,int y1,int y2){

    in.x.ax=7;in.x.cx=x1;in.x.dx=x2;int86(51,&in,&out);in.x.ax=8;in.x.cx=y1;in.x.dx=y2;int86(51,&in,&out);

    }

  • 8/17/2019 K-Draw Report

    30/92

     

    int defaultclick; //for giving default argument to mouseposi void mouse::mouseposi(int &xpos,int &ypos,int &click =defaultclick ){ //get coords and click

    in.x.ax=3;int86(51,&in,&out);click=out.x.bx;xpos=out.x.cx;

     ypos=out.x.dx;}

     void mouse::mouseposi(int &xpos, int &ypos,int &c, int dummy){

    int x1,y1,c1,flag=0;do{in.x.ax=3;

    int86(51,&in,&out);switch (out.x.bx){case RCLICK:

    case LCLICK:xpos=out.x.cx;

     ypos=out.x.dx;c=out.x.bx;flag=1;

     break;}

    }while(flag==0);}

    int mouse::pollmouse(int xcond,int ycond,int click){ //look for mouse click at a area

    int x1,y1,c=0;mouseposi (x1,y1,c);if ( x1>xcond-3 && x1ycond-3 && y1xcond-w/2 && x1ycond-h/2&& y1

  • 8/17/2019 K-Draw Report

    31/92

     

     void mouse::mouseclick(int &newx,int &newy,int c ) //default LCLICK . return{ //coords of a click.c ==>required clickint x1,y1,c1;do{mouseposi(x1,y1,c1);if (c1==c){newx=x1;newy=y1;

    }}while(c1!=c);

    }

    int mouse::hovermouse(int x1,int y1,int w1=6,int h1=6)//(x1,y1) is the center{ int x2,y2,w,h; w=w1/2;h=h1/2;in.x.ax=3;int86(51,&in,&out);

    x2=out.x.cx; y2=out.x.dx;if (x1>x2-w && x1y2-h && y1 wx1 && x1 < wx2 && y1 > wy1 && y1 < wy2)

    mousemode=work;else if ( x1 > tmx1 && x1 < tmx2 && y1> tmy1 && y1 < tmy2)

    mousemode=top_menu; //side bottom menuelse if ( x1 > bmx1 && x1 < bmx2 && y1> bmy1 && y1 < bmy2)

    mousemode=bottom_menu; //side bottom menuelse if ( x1 > tbx1 && x1 < tbx2 && y1 > tby1 && y1 < tby2)

    mousemode=topbar;}

  • 8/17/2019 K-Draw Report

    32/92

     

    MYNODES.H

    //wnode is macro in mydefine.h => #define wnode(i) ((nodes&)worknodes[(i)])

    /****************** MYNODES.H *****************************************class MyArray: public Array //to get reallocated function{public:

    MyArray(int a,int b,int c):Array(a,b,c){}

     void reallocate(int n){

     Array::reallocate(n);}

    };//----------------------------------------------------------------------------class nodes :public Queue{

    private:int x,y,stat,prex,prey,prestat;static int laste,activated,globalstat;

    //laste->saves last node;//activated->last elemet index for mouseact //globalstat->for mouseact managementint pahx,pahy; //store pre x,y pos to prevent continuous//change of state b/w active&hover

    friend int findnode(int x,int y);//search and return 1 node(index) in//5 pixel range, -1 if not found

    friend nodes& latestnode();//return last added nodefriend void savescene(char *fname,int sceneid,int newf);//write node data to file

    friend lines; //to allow manipulationsint numlines; //num of lines per nodelines **cline; //all immidiately related lines

     void addline( lines *l); void deleteline( lines *l);

     void xy (int x1,int y1); //save old coords & put new coords

     void makenode(int x1, int y1); void nodeact(); //do mouse actions void drawnode();//called for updating status,calls recursions as needed void drawnode1(); //draws the nodes

     void drawnode(lines *l); //called only for 2nd level recursionstatic int delnodeclick(int &newx,int &newy,int &node);static int arraysize();

    MyTime T_l,T_l1; //T_l=> timer for locked mode

    public:

    nodes(); //default constructornodes(int dummy); //for creating dummy object without affecting laste

  • 8/17/2019 K-Draw Report

    33/92

     

    static int last() //return last nodes index{return laste;}

     void del_all_lines(); //delete all lines connected to a node

    static void nodeinit(); //emptystatic void newnode(); //new node modestatic void newnode(int x1,int y1); //to automatically make node at x1,y1//(used by open dialog)static void deletenode(); //delete mode, finds node itselfstatic void empty(); //to delete all existing nodesstatic void mouseact(); //called from mainstatic void draw_all();

    ~nodes();};

    int nodes::laste=-1; //no nodesint nodes::activated=0;

    int nodes::globalstat=open;*********************** MYNODES.H over ******************************/

    MyArray worknodes(0,0,1);//initially-0 space. lowermost index=0.//if more than 1, new size= 2....

    // contructors and destructorsnodes::nodes()//default contructor

    {prestat=open;stat=globalstat=open;

    laste++; //update lastelem index each time a new node is created

    numlines=-1;cline=new lines*[0];

    }

    nodes::nodes(int dummy) //for creating dummy object without affecting laste{

    dummy=0;numlines=-1;cline=new lines*[0];

    }

    nodes::~nodes(){

    delete [] cline;

    }// contructors and destructors over

     void nodes::xy (int x1,int y1){

    prex=x;prey=y;x=x1;

     y=y1;}

  • 8/17/2019 K-Draw Report

    34/92

     

     void nodes::nodeinit(){}

    int nodes::arraysize() //returns reference to the last added node;{

    return(worknodes.arraySize()-1);//-1 so that it is element index}

     void nodes::makenode(int x1, int y1) //init values and draw new node at coords{

    stat=globalstat=open; //prex,prey for drawnode1() compatabilityx=x1;

     y=y1;prex=x;prey=y;

    drawnode1();}

     void nodes::newnode()

    {int x1=0,y1=0,c;

    m.mousemax(wx1,wx2,wy1,wy2); //restrict movement if node is selected

    if( laste< arraysize() ) worknodes.reallocate(laste+1);//remove vacant spaces

    //reallocate takes actual size(1->n)newnodeagain1: // to take care of lclick ouside work aream.mouseposi(x1,y1,c,0); //look till a click is recieved

    if (c==LCLICK ) //if left click, new node is created{

    if (m.mousemode==work){

     worknodes.add(* (new nodes));

     wnode(laste).makenode(x1,y1);//laste updated by contructor

     wnode(laste).stat=globalstat=open;

    if(! (bioskey(_KEYBRD_SHIFTSTATUS) & 0x03))//if shift is not pressed ,//dont make another new node

    nodebuttons::changemode(move_node);else

    delay(100);//to prevent continous nodes

    //over the previous node}else

    goto newnodeagain1;}else if(c==RCLICK)

    nodebuttons::changemode(move_node);m.mousemax(fullx1,fullx2,fully1,fully2); //remove movement restriction

    }

  • 8/17/2019 K-Draw Report

    35/92

     

     void nodes::newnode(int x1,int y1){

     worknodes.add(* (new nodes)); wnode(laste).makenode(x1,y1); //laste updated by contructor wnode(laste).stat=globalstat=open;

    }

    int findnode(int x,int y) //search and return 1 node in 5 pixel range{

    int nx,ny; //node's x & yfor (int i=0; i

  • 8/17/2019 K-Draw Report

    36/92

     

    {if (j1 != -1){

     wnode(j1).stat=globalstat=open; //last hovered node wnode(j1).drawnode(); j1=-1;node=-1;

    }return RCLICK;

    }}while(1);

    }

     void nodes::deletenode(){

    if (laste != -1)// if a node exists{deleteagain:

    int x1,y1,i,j;

     j=delnodeclick(x1,y1,i);

    if ( j == LCLICK){

    if (i != -1) //if node found{

    m.mouseoff(); // to properly draw

    setfillstyle(SOLID_FILL,0); //setcolor(getbkcolor()); //erase previous nodepieslice(wnode(i).prex,wnode(i).prey,0,360,5);

    //to ensure complete erase

    setfillstyle(SOLID_FILL,0);// erase node from screensetcolor(getbkcolor()); //

    pieslice(wnode(i).x,wnode(i).y,0,360,5);//

    m.mouseon(); //reset mouse

     wnode(i).del_all_lines();

     worknodes.detach(i); //detach and delete a node at click poslaste--; //one node deleted

    if(! (bioskey(_KEYBRD_SHIFTSTATUS) & 0x03))//if shift is not pressed ,exit delete mode

    nodebuttons::changemode(move_node);

    }}else if ( j == RCLICK) //if RCLICK anywhere

    nodebuttons::changemode(move_node);//cancel deletemodeelse

    goto deleteagain;}

    else

  • 8/17/2019 K-Draw Report

    37/92

     

    {nodebuttons::changemode(move_node);h.display(H_no_del);

    }}

     void nodes::empty(){

    m.mouseoff(); // to properly draw

     while(laste>=0){

    setfillstyle(SOLID_FILL,0);//setcolor(getbkcolor()); //erase previous node for complete erasepieslice(wnode(laste).prex,wnode(laste).prey,0,360,5);//

    setfillstyle(SOLID_FILL,0);//setcolor(getbkcolor());//erase node from screenpieslice(wnode(laste).x,wnode(laste).y,0,360,5);//

     wnode(laste).del_all_lines();

     worknodes.detach(laste); //detach and delete a node at click pos.

    laste--;}

     worknodes.reallocate(0);//reallocate to save spacem.mouseon(); //reset mouse

    }

     void nodes::drawnode(lines *l) //called only for 2nd level recursion{

    if(l!=NULL && option::isrecursive()){

    for (int i=0;idrawline(this);//if any line updated in this node//recur update automatically checked

    }}drawnode1();

    }

  • 8/17/2019 K-Draw Report

    38/92

     

     void nodes::drawnode()//called for updating status,decides and calls recursion{

    if(option::isrecursive() && stat==active){

    for (int i=0;idrawline(this);

    lines::reset_recurstat();}else{for (int i=0;idrawline();//draw all related lines without any other changes

    }drawnode1();

    } void nodes::drawnode1(){m.mouseoff(); //turn off cursor to remove drawing errors

    setlinestyle(SOLID_LINE,0,1);

    setfillstyle(SOLID_FILL,0); //setcolor(getbkcolor()); //erase previous nodepieslice(prex,prey,0,360,5); //setcolor(getmaxcolor());

    switch (stat){case open:

    setfillstyle(SOLID_FILL,BLACK);setcolor(getmaxcolor());pieslice(x,y,0,360,5);

     break;

    case active:setcolor(getmaxcolor());setfillstyle(SOLID_FILL,GREEN);pieslice(x,y,0,360,5);h.display(H_active);

     break;

    case locked:setfillstyle(SOLID_FILL,RED);pieslice(x,y,0,360,5);

     break;

    case hover:setfillstyle(SOLID_FILL,LIGHTBLUE);pieslice(x,y,0,360,5);h.display(H_hover);

     break;

    case del_hov:setfillstyle(SOLID_FILL,LIGHTRED);pieslice(x,y,0,360,5);

     break;

  • 8/17/2019 K-Draw Report

    39/92

     

    case linesel:setfillstyle(SOLID_FILL,LIGHTGRAY);pieslice(x,y,0,360,5);

     break;}m.mouseon();//turn on mouse

    }

     void nodes::nodeact(){int prestat=stat; //save current stat for checking redraw

    switch (stat){case open:

    pahx=pahy=0; //reset reentry pos to initialif (m.hovermouse(x,y))

    stat=globalstat=hover; break;

    case hover: if (m.hovermouse(x,y)==0) //if not hovering nowstat=globalstat=open;

    else if (m.pollmouse(x,y,RCLICK)){

    if (T_l1.status()==0 || (T_l1.status()==1 &&T_l1.time() > 0.3))

    {T_l.start();T_l1.stop();stat=globalstat=locked;

    }}else if(m.pollmouse(x,y,LCLICK) && !range(x,y,pahx,pahy,3)

    && globalstat!=active ){stat=globalstat=active;m.mousemax(wx1,wx2,wy1,wy2);//restrict movement if node

    //is selectedpahx=x;//save pos where it was clickedpahy=y;//prevent reentry to hover continously from active

    }else if(globalstat!=active &&

    (bioskey(_KEYBRD_SHIFTSTATUS) & 0x03) )//if right or left shift was pressed

    {//check only for 0x01 and/or 0x02stat=globalstat=linesel;

    } break;

    case active:int xa,ya,c=0;m.mouseposi (xa,ya,c); //get new coords

    xy(xa,ya);

  • 8/17/2019 K-Draw Report

    40/92

     

    if (c==LCLICK && !range(xa,ya,pahx,pahy,3) )//if clicked again and if node has moved //fromactivation pos

    {stat=globalstat=hover;m.mousemax(fullx1,fullx2,fully1,fully2);

    //remove movement restrictionpahx=x;//save pos where it was clickedpahy=y;//prevent continously reentring

    //active from hover}

    drawnode(); //update position break;

    case locked:h.display(H_locked);if(m.pollmouse(x,y,RCLICK))

    {if (T_l.status()==1 && T_l.time() > 0.3)

    {stat=globalstat=open;

    T_l.stop();T_l1.start();

    }}

     break;

    case linesel:if (m.hovermouse(x,y)==0) //if not hovering now

    stat=globalstat=open;else if(m.pollmouse(x,y,LCLICK) &&

    !range(x,y,pahx,pahy,3)&&globalstat!=active&& (bioskey(_KEYBRD_SHIFTSTATUS) & 0x03) )//if right or left shift was pressed

    {//check only for 0x01 and/or 0x02

    lines::lineact(this);stat=globalstat=open;

    }else if( m.hovermouse(x,y) &&

    !(bioskey(_KEYBRD_SHIFTSTATUS) & 0x03) )stat=globalstat=hover;

     break;}if(prestat!=stat) // if status changes or is locked

    {prestat=stat;drawnode();

    }}

  • 8/17/2019 K-Draw Report

    41/92

     

    4

     void nodes::mouseact(){

    int i,x1,y1;

    if( activated != -1 && wnode(activated).stat==active ){

     wnode(activated).nodeact();}else{

    //to redraw all when a node is deactivetedif( activated != -1 && wnode(activated).stat==off){

    draw_all();activated = -1;//an node was released,

    //so redraw everything}

    m.mouseposi(x1,y1);i=findnode(x1,y1); //find the node required

    if (i != -1) // if found{

     wnode(i).nodeact();

    if( wnode(i).stat==locked ){

     wnode(i).drawnode();delay(100);

    }

    activated=i;}

    for (int j=0;j

  • 8/17/2019 K-Draw Report

    42/92

     

    4

    //-----------------------------line related----------------------------------- void nodes::addline( lines *l){

    if(numlines==-1){

    delete [] cline;cline= new lines*[1];cline[0]=l;numlines=0;

    }else{

    lines **temp=new lines*[numlines+2]; //(numlines+1)+1for (int i=0;i0){

    lines **temp=new lines*[numlines]; //(numlines-1)+1

    for (int i=0,j=0;i

  • 8/17/2019 K-Draw Report

    43/92

     

    4

    MYLINE.H

    /*************************MYLINES.H *************************************class lines:public Queue

    {static int arraysize();int recurstat;

    public:int color;nodes *p[2];//starting and ending nodes

    lines()

    {

    p[0]=NULL;

    p[1]=NULL;recurstat=0;

    }

    static int num;

    static void lineact(nodes *p1);static void newline(int x1,int y1,int x2,int y2,int c);//to make lines automatically for openstatic void del_line(lines *l);static void empty();static lines* findcommon(nodes*n1 , nodes*n2);

    static void reset_recurstat();

     void drawline();//non recursive draws & initial nodes void drawline(nodes *n);//all recursive draw after 1st node

    };

    int lines::num=-1;***************************************************************************/

    MyArray conlinesArr(0,0,1);

    int lines::arraysize() //returns reference to the last added node;

    {return(conlinesArr.arraySize()-1);

    //-1 so that it can be used as element index}

     void lines::lineact(nodes *p1){

    int no_lineflag=1;//1 if no common lines exist

    if(nodes::last()>0) //if more than 1 node exists

  • 8/17/2019 K-Draw Report

    44/92

     

    4

    {m.mousemax(wx1,wx2,wy1,wy2);//restrict movement if node selected

    nodes *p2=NULL;

    int x,y,c=-1,i=-1,prei,j,k;

    again_new_line:

     while(p2==NULL){

    m.mouseposi(x,y,c);

    h.display(H_linenode);

    i=findnode(x,y);

    if(i!=-1)//if found{

    if(i!=prei &&&wnode(i)!=p1)//another node found

    //& it is not the start node{

    m.mouseoff();

    setcolor(getmaxcolor());setfillstyle(SOLID_FILL,BLACK);//hover

    pieslice(wnode(prei).x,wnode(prei).y,0,360,5);

    m.mouseon();

    prei=i;}if(&wnode(i)!=p1)//if both nodes (start & end)

    //are not the same{

    m.mouseoff();

    setcolor(getmaxcolor());setfillstyle(SOLID_FILL,LIGHTBLUE);//hover

    pieslice(wnode(i).x,wnode(i).y,0,360,5);

    m.mouseon();

    if( findnode(x,y)!= -1 && c==LCLICK)//if new node found and it is //not thestart node

    {

    p2=&wnode(i);}

    }}

    if (c==RCLICK)goto newline_exit;

    }

  • 8/17/2019 K-Draw Report

    45/92

     

    4

    for(j=0;jnumlines;j++)//iterate through all//lines to find common lines

    for (k=0;knumlines;k++)if( p1->cline[j]==p2->cline[k] && p1->cline[j]!=NULL){

    del_line(p1->cline[j]);//delete all common linesno_lineflag=0;

    }

    if(p1 != NULL && p2!=NULL && no_lineflag==1)//if no common lines//exist, make a new one

    {conlinesArr.add( * (new lines ) );

    num++;lines &latest=conline(num);

    latest.p[0]=p1;latest.p[1]=p2;

    latest.p[0]->addline(&conline(num));//associate//the nodes with this line

    latest.p[1]->addline(&conline(num));

    latest.color=linecolor::color;//currently selected//color

    latest.p[0]->drawnode1();latest.p[1]->drawnode1();

    latest.drawline();}

    if(bioskey(_KEYBRD_SHIFTSTATUS) & 0x03)//if right or//left shift was pressed

    {p1=p2; //use the last clicked node as the

    //starting of next linep2=NULL;goto again_new_line;

    }}

    newline_exit:m.mousemax(fullx1,fullx2,fully1,fully2); //remove movement restriction

    }

     void lines::newline(int x1,int y1,int x2,int y2,int c)//to make lines//automatically for open

    {nodes *p1=NULL,*p2=NULL;

  • 8/17/2019 K-Draw Report

    46/92

     

    4

    int i=findnode(x1,y1);if( i != -1 ) //if node found

    {p1=&wnode(i);

    }

    i=findnode(x2,y2);if( i != -1 && p1!=&wnode(i))//if node found and it

    //is not the start node{

    p2=&wnode(i);}

    if(p1 != NULL && p2!=NULL )//if no common lines exist, make a new one{

    if( num< arraysize() )conlinesArr.reallocate(num+1); //remove vacant spaces

    //reallocate takes actual size(1->n)

    conlinesArr.add( * (new lines ) );

    num++;lines &latest=conline(num);

    latest.p[0]=p1;latest.p[1]=p2;

    latest.p[0]->addline(&conline(num));//associate the nodes with this line

    latest.p[1]->addline(&conline(num));

    latest.color=c; //currently selected color

    latest.p[0]->drawnode();latest.p[1]->drawnode();

    latest.drawline();}

    }

     void lines::del_line(lines *l){

    if(l!=NULL&& num>=0){

    m.mouseoff();setcolor(getbkcolor());

    line(l->p[0]->x,l->p[0]->y,l->p[1]->x,l->p[1]->y);//draw new linem.mouseon();

    l->p[0]->deleteline(l);l->p[1]->deleteline(l);

    for(int i=0;i

  • 8/17/2019 K-Draw Report

    47/92

     

    4

    num--; break;

    }}

    }

     void lines::drawline() //non recursive draws{

    int x1=p[0]->x,y1=p[0]->y,x2=p[1]->x,y2=p[1]->y;

    m.mouseoff();

    setlinestyle(SOLID_LINE,0xFF,THICK_WIDTH);setcolor(getbkcolor());line(p[0]->prex,p[0]->prey,p[1]->prex,p[1]->prey);

    //clear prev linesetlinestyle(SOLID_LINE,0xFF,NORM_WIDTH);setcolor(color);line(x1,y1,x2,y2); //draw new line

    setcolor(WHITE);

    m.mouseon();}

     void lines::drawline(nodes *n) //only for recursive draws{

    if(recurstat==0){

    recurstat=1;drawline(); //update this line

    if(n==p[0] )p[1]->drawnode(this); //update the othernodea also

    else if(n==p[1] )p[0]->drawnode(this);

    }}

     void lines::empty(){

    m.mouseoff();

     while(num>=0){

    conlinesArr.detach(num);num--;

    }conlinesArr.reallocate(0);

    m.mouseon();}

     void lines::reset_recurstat(){

    for (int i=0;i

  • 8/17/2019 K-Draw Report

    48/92

     

    4

    }

    lines* lines::findcommon(nodes*n1 , nodes*n2){

    for(int j=0;jnumlines;j++) //iterate through all lines//to find common lines

    for (int k=0;knumlines;k++)if( n1->cline[j]==n2->cline[k] && n1->cline[j]!=NULL)

    return (n1->cline[j]);

    return NULL;//if none found}

    MYLCOLOR.H

    /************************* MYLCOLOR.H ****************************class linecolor{

    int h,w;//height & width of each box;

    int x,y,th,tw;//total height & width

    public:

    linecolor();static int color;

     void disp(); void act();

    }lc;int linecolor::color=WHITE;*****************************************************************/

    linecolor::linecolor(){x=tmx1;

     y=bmy1-110;tw=85;th=85;h=(th-1)/4;

     w=(tw-1)/4;}

     void linecolor::disp(){

    m.mouseoff();

    setcolor(WHITE);setlinestyle(SOLID_FILL,0,NORM_WIDTH);

    for(int i=0;i

  • 8/17/2019 K-Draw Report

    49/92

     

    4

    elsesetfillstyle(CLOSE_DOT_FILL,i*4+j);

    //all colours,one by one

     bar(x+(i*w),y+(j*h),x+(i*w)+w,y+(j*h)+h);rectangle(x+(i*w),y+(j*h),x+(i*w)+w,y+(j*h)+h);

    }

    setlinestyle(SOLID_FILL,0,NORM_WIDTH);m.mouseon();

    };

     void linecolor::act(){

    if(m.mousemode==top_menu){

    int x1=x,y1=y,c,cl=color;int prex1=x1,prey1=y1,precl=color;

    m.mouseposi(x1,y1,c);

    if( range(x1,y1,x+42,y+42,42) ){

    int j=(x1-x)/20;//integer division rounds//to nearest & smaller no. b/w 0 & 4

    int k=(y1-y)/20;

    if(range(x1,y1,x+(j*w)+9,y+(k*h)+9,9))//hovering over//a color

    {if(precl!=cl){

    m.mouseoff();

    setfillstyle(SOLID_FILL,j*4+k); bar(x+(j*w),y+(k*h),x+(j*w)+w,y+(k*h)+h);rectangle(x+(j*w),y+(k*h),x+(j*w)+w,y+(k*h)+h);

    prex1=x+(j*w);prey1=y+(k*h);

    precl=cl;cl=j*4+k;

    m.mouseon();}

    if(m.ifclick()) //select color{

    int x2=x + ( (color/4) * w);int y2=y + ( (color%4) * h);

    m.mouseoff();

    setfillstyle(SOLID_FILL,BLACK); bar(x2,y2,x2+w,y2+h); //clear existing

  • 8/17/2019 K-Draw Report

    50/92

     

    4

    setfillstyle(CLOSE_DOT_FILL,color); bar(x2,y2,x2+w,y2+h);rectangle(x2,y2,x2+w,y2+h);

    setfillstyle(SOLID_FILL,j*4+k); bar(x+(j*w),y+(k*h),x+(j*w)+w,y+(k*h)+h);rectangle(x+(j*w),y+(k*h),x+(j*w)+w,y+(k*h)+h);

    m.mouseon();

    color=j*4+k;

    }}

    if(precl!=cl){

    m.mouseoff();

    setfillstyle(SOLID_FILL,BLACK); bar(prex1,prey1,prex1+w,prey1+h);//clear existing

    setfillstyle(CLOSE_DOT_FILL,precl); bar(prex1,prey1,prex1+w,prey1+h);rectangle(prex1,prey1,prex1+w,prey1+h);

    m.mouseon();precl=cl;

    }

    }}

    }

  • 8/17/2019 K-Draw Report

    51/92

     

    BU.H

    /******************** BU.H *******************************class buttons{protected:

    int x1,y1,x2,y2,id,stat,prestat;//id is d same as the corresponding//workmode stat= off/hover/active

    char text[20];

     void mouseover(); void buttonclick();

     void button_active_draw();

    friend nodes;

    public: buttons(){}

     buttons(int x1t,int y1t,int x2t,int y2t,int idt,char textt[]);

     void drawbutton(); void reset();//stat off,draw buttonint getstat();

    friend void buttoninit(); //calls all button inits};*********************************************************/

     buttons::buttons(int x1t,int y1t,int x2t,int y2t,int idt,char textt[]){

    x1=x1t; y1=y1t;x2=x2t;

     y2=y2t;id=idt;strcpy(text,textt);

    }

     void buttons::reset() //stat off,draw button{

    stat=off;drawbutton();

    }

    int buttons::getstat(){

    return stat;

    }

     void buttons::button_active_draw(){

    int xmid=x1+(x2-x1)/2;int ymid=y1+(y2-y1)/2;int x3=xmid-1.2*textwidth(text)/2;int y3=ymid-1.5*textheight(text)/2;int x4=xmid+1.2*textwidth(text)/2;int y4=ymid+0.5*textheight(text)/2.0 ;

  • 8/17/2019 K-Draw Report

    52/92

     

    setcolor(button_out_color);setlinestyle(SOLID_LINE,0,3);setfillstyle(XHATCH_FILL,button_out_color);rectangle(x1,y1,x2,y2);floodfill(x1+2,y1+2,button_out_color); //outer

    setcolor(BLUE);setfillstyle(SOLID_FILL,button_in_color);rectangle(x3,y3,x4,y4);floodfill(x3+2,y3+2,BLUE);setcolor(button_in_color);rectangle(x3,y3,x4,y4);

    setlinestyle(SOLID_LINE,0,1);setcolor(button_act_text_color);settextjustify(CENTER_TEXT,CENTER_TEXT);outtextxy(x1+(x2-x1)/2,y1+(y2-y1)/2,text);setcolor(WHITE);

    }

     void buttons::drawbutton() //refresh a button according to present stat{m.mouseoff(); // to properly draw

    switch(stat){case off:

    if (prestat==active){

    setcolor(BLUE);setfillstyle(SOLID_FILL,BLACK);rectangle(x1,y1,x2,y2);floodfill(x1+2,y1+2,BLUE);

    }setcolor(WHITE);setlinestyle(SOLID_LINE,0,3);rectangle (x1,y1,x2,y2);setlinestyle (SOLID_LINE,0,1);settextjustify(CENTER_TEXT,CENTER_TEXT);outtextxy(x1+(x2-x1)/2,y1+(y2-y1)/2,text);

     break;

    case active: button_active_draw(); break;

    case hover:setcolor(YELLOW);setlinestyle(SOLID_LINE,0,3);rectangle (x1,y1,x2,y2);setlinestyle (SOLID_LINE,0,1);settextjustify(CENTER_TEXT,CENTER_TEXT);outtextxy(x1+(x2-x1)/2,y1+(y2-y1)/2,text);setcolor(WHITE);

     break;}

  • 8/17/2019 K-Draw Report

    53/92

     

    prestat=stat; //update prestatm.mouseon(); //reset mouse

    }

     void buttons::mouseover() //sense when mouse is over a button{if (stat!=active){

    if(m.hovermouse(x1+(x2-x1)/2,y1+(y2-y1)/2,x2-x1,y2-y1)) //look for hovering over buttonstat=hover;

    elsestat=off;

    }}

     void buttons::buttonclick() //set-reset Lclicks{

    in.x.ax=3;int86(51,&in,&out);

    int click=out.x.bx;if (click==LCLICK)if (stat==active)

    stat=off;else

    stat=active; //set active stat for this one

    }

    #if !defined(__BUNB_h)#include"BUNB.h"#endif

     void savebuttoninit(); void openbuttoninit(); void buttoninit(){

    nodebuttoninit(); //side bottom menusavebuttoninit();openbuttoninit();exitbuttoninit();renderbuttoninit();optionmenubuttoninit();

    //modebuttoninit(); //side top menu

    }

  • 8/17/2019 K-Draw Report

    54/92

     

    BUNB.H

    /******************* BUNB.H *****************************class nodebuttons : public buttons //side bottom work buttons .only one active at a time{private:

    static void reset_last_active();static int lastactive;static int mode;

    public: void buttonclick(); virtual void buttonact();friend void nodebuttoninit();static int getmode();static void changemode(int to_mode);

    //change mode,button stats and redraw}nb[4]; //node buttonsint nodebuttons::lastactive=new_node; //will be correct after 1st click

    int nodebuttons::mode=new_node;********************************************************/

     void nodebuttoninit(){

    nb[0].x1=bmx1;nb[0].y1=190;

    nb[0].x2=nb[0].x1+85;nb[0].y2=nb[0].y1+40;nb[0].id=new_node;nb[0].prestat=hover; //for complete redraw 1st timenb[0].stat=active; //initially active modestrcpy(nb[0].text,"CREATE");nb[0].drawbutton();

    nb[1].x1=bmx1;nb[1].y1=235;

    nb[1].x2=nb[1].x1+85;nb[1].y2=nb[1].y1+40;nb[1].id=move_node;nb[1].prestat=active; //for complete redraw 1st timenb[1].stat=off;strcpy(nb[1].text,"MOVE");

    nb[1].drawbutton();

    nb[2].x1=bmx1;nb[2].y1=280;

    nb[2].x2=nb[2].x1+85;

    nb[2].y2=nb[2].y1+40;nb[2].id=delete_node;nb[2].prestat=active; //for complete redraw 1st timenb[2].stat=off;strcpy(nb[2].text,"DELETE");

    nb[2].drawbutton();}

  • 8/17/2019 K-Draw Report

    55/92

     

    int nodebuttons::getmode(){

    return mode;}

     void nodebuttons::buttonclick() // reset last active when aonther is clicked{

    in.x.ax=3;int86(51,&in,&out);int click=out.x.bx;if (click==LCLICK){

    nodebuttons::reset_last_active();//reset last active button to defaultlastactive=id; //update last activestat=active; //set active stat for this oneprestat=off;

    }}

     void nodebuttons::changemode(int to_mode)

    {int from_mode=nodebuttons::mode; //save current active buttonnodebuttons::mode=to_mode; //update mode

    nb[from_mode].prestat=nb[from_mode].stat; //update button modesnb[from_mode].stat=off;

    nb[to_mode].prestat=nb[to_mode].stat;nb[to_mode].stat=active;

    nb[from_mode].drawbutton(); //redraw buttonsnb[to_mode].drawbutton();

    }

     void nodebuttons::reset_last_active(){

    nb[nodebuttons::lastactive].prestat=active;nb[nodebuttons::lastactive].stat=off; //reset statnb[nodebuttons::lastactive].drawbutton(); //redraw to reflect change

    }

     void nodebuttons::buttonact() // main function calling{

    prestat=stat; //store last recorded statmouseover(); //checks for hovering.updates statif (stat==hover) //if hovering

    { buttonclick(); //(virtual)check for click on button.

    //any click recieved here will be on the button

    if(id==new_node)h.display(H_newnodeb);

    else if( id==delete_node)h.display(H_delnodeb);

  • 8/17/2019 K-Draw Report

    56/92

     

    if (stat==active)//if clicked{

    mode=id; //set workmode//id is d same as the corresponding workmode

    }}if (prestat!=stat)

    drawbutton(); //redraw only if change in stat}

    MYDIALOG .H

    /************************************************************class diagbutton:public buttons{public:

    static int mode;diagbutton(){} //for array

    diagbutton(int x1t,int y1t,int x2t,int y2t,int idt,char textt[]); void buttonact();

    static void resetmode(){mode=-1;}

    };int diagbutton::mode=-1;************************************************************/diagbutton::diagbutton(int x1t,int y1t,int x2t,int y2t,int idt,char textt[])

    {x1=x1t;

     y1=y1t;x2=x2t;

     y2=y2t;strcpy(text,textt);id=idt;

    }

     void diagbutton::buttonact(){

    prestat=stat; //store last recorded statmouseover(); //checks for hovering.updates statif (stat==hover) //if hovering{

     buttonclick(); //(virtual)check for click on button.

    //any click recieved here will be on the buttonif (stat==active) //if clicked{

    mode=id;//set workmode//id is the same as the corresponding workmode

    }}if (prestat!=stat)

    drawbutton(); //redraw only if change in stat}

  • 8/17/2019 K-Draw Report

    57/92

     

    /*********************** CLASS DIALOG ******************************class dialog{int optionnum,numlines;char heading[20],**line;

     void far *buf;

    protected:int x1,y1,x2,y2;diagbutton b[3];

    public:dialog(){

    line=NULL; buf=NULL;

    }dialog(int x1t,int y1t,int x2t,int y2t,int optionnum,

    char **buttontextt,char headingt[20],char *text,int idt[3]); void show_diag(); void act_diag(); void clear_diag();

    };********************************************************************/

    dialog::dialog(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char *text,int idt[3])

    {x1=x1t;x2=x2t;

     y1=y1t; y2=y2t;optionnum=optionnumt;numlines=0; // default 1 line

    for(int k=0;k1) //2 buttons b[1]=diagbutton(x1t+90,y2t-30,x1t+170,y2t-10,

    idt[1],buttontextt[1]);if(optionnum>2)//3 buttons

     b[2]=diagbutton(x1t+180,y2t-30,x1t+270,y2t-10,idt[2],buttontextt[2]);

    strcpy(heading,headingt);

  • 8/17/2019 K-Draw Report

    58/92

     

    //split linesint i=0,j=0;

    char word[20];i=j=0;

    do{

    for (j=0;text[i]!=' ' && i

  • 8/17/2019 K-Draw Report

    59/92

     

    setcolor(WHITE);

    setlinestyle(SOLID_LINE,0,3); //draw outer linerectangle(x1,y1,x2,y2);setlinestyle(SOLID_LINE,0,1);

    settextstyle(DEFAULT_FONT,0,2); //bigger sizesettextjustify(CENTER_TEXT,CENTER_TEXT);outtextxy((x1+x2)/2, y1+textheight(heading) , heading);settextjustify(LEFT_TEXT,CENTER_TEXT);settextstyle(DEFAULT_FONT,0,1);//default size

    for (int i=0;i0) b[0].drawbutton();

    if(optionnum>1) //2 buttons b[1].drawbutton();

    if(optionnum>2)//3 buttons b[2].drawbutton();

    }

     void dialog::act_diag(){

    m.mouseon();

    for(int i=0;i

  • 8/17/2019 K-Draw Report

    60/92

     

    MYFILE.H

    /********************* MYFILE.H *******************************class filediag:public dialog{

    protected:

    public:char oldfname[25]; //last used filename without extensionfilediag();filediag(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char *textt,int idt[3]);

     void disp_diag();};***************************************************************/

    filediag::filediag():dialog(){

    strcpy(oldfname,"");}

    filediag::filediag(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char *textt,int idt[3]):dialog(x1t,y1t,x2t,y2t,optionnumt,buttontextt,headingt,textt,idt){

    strcpy(oldfname,"");}

     void filediag::disp_diag(){

    char fname[25]="";

    if ( strlen(oldfname)!=0 )strcpy(fname,oldfname);

    show_diag();

    diagbutton::resetmode();

    settextjustify(LEFT_TEXT,TOP_TEXT);outtextxy(x1+10,y1 + (y2-y1)*0.8+ textheight("F")/2 ,"File Name");settextjustify(LEFT_TEXT,CENTER_TEXT);

    rectangle(x1+textwidth("File Name")+15,y1+(y2-y1)*0.8, x2-30, y1+(y2-y1)*0.8 + 18);

    settextjustify(LEFT_TEXT,TOP_TEXT);outtextxy(x1+textwidth("File Name")+18,y1 + (y2-y1)*0.8+

    textheight("F")/2 ,fname);settextjustify(LEFT_TEXT,CENTER_TEXT);

     while(diagbutton::mode==-1){

    if(kbhit()){

    if(strlen(fname)

  • 8/17/2019 K-Draw Report

    61/92

     

    {int c=getch();if(c==8) //backspace{

    fname[strlen(fname)-1]='\0';//decrease one letter

    }else if(c==0) //special char

    getch(); //clear buffer of other charselse if(c==13) //enter

    diagbutton::mode=ok; //any +ve resultelse if(c==27) //escape

    diagbutton::mode=cancel;//any -ve resultelse if( isalnum( (char)c ) ){

    int l=strlen(fname);fname[l]=(char)c;fname[l+1]='\0';

    }

    setfillstyle(SOLID_FILL,BLACK); bar(x1+textwidth("File Name")+15,y1 + (y2-y1)*0.8 ,

    x2-30, y1 + (y2-y1)*0.8 + 18);rectangle(x1+textwidth("File Name")+15,y1 +

    (y2-y1)*0.8, x2-30, y1 + (y2-y1)*0.8 + 18);

    settextjustify(LEFT_TEXT,TOP_TEXT);outtextxy(x1+textwidth("File Name")+18,y1 +

    (y2-y1)*0.8+ textheight("F")/2 ,fname);settextjustify(LEFT_TEXT,CENTER_TEXT);

    }else if(strlen(fname)==20)//to allow to delete last letter{

    int c=getch();if(c==8) //backspace{

    fname[strlen(fname)-1]='\0';} //decrease one letter

    setfillstyle(SOLID_FILL,BLACK); bar(x1+textwidth("File Name")+15,y1 + (y2-y1)*0.8 ,

    x2-30, y1 + (y2-y1)*0.8 + 18);rectangle(x1+textwidth("File Name")+15,y1 +

    (y2-y1)*0.8 , x2-30, y1 + (y2-y1)*0.8 + 18);

    settextjustify(LEFT_TEXT,TOP_TEXT);outtextxy(x1+textwidth("File Name")+18,y1 +

    (y2-y1)*0.8+ textheight("F")/2 ,fname);settextjustify(LEFT_TEXT,CENTER_TEXT);

    }else

    getch();//empty buffer}

    act_diag();

  • 8/17/2019 K-Draw Report

    62/92

     

    if(diagbutton::mode!=-1 && diagbutton::mode!=cancel &&diagbutton::mode!=exitb && strlen(fname)==0 )

    {diagbutton::resetmode();

     b[0].reset();diagbutton::mode=-1;//do not save if name is emptyh.display(6);

    }

    }

    strcpy(oldfname,fname);

    clear_diag();

    /*NOTE:do this in overloaded function for actions

    if (diagbutton::mode==) //if save selected

    {action to be taken

    }*/

    }

    MYSAVE.H

    //#define iovar(var) (char*)&(var),sizeof(var) in mydefine.h

    struct nodexy{

    int x,y;}nxy;

    struct linedat{

    int x1,y1,x2,y2,c;}ld;

    struct fileheader{

    int version,numscenes;}fh;

    struct sceneheader{

    int numnodes,numlines;}sh;

    #define VERSION 3 //to ensure that only the correct format is read

  • 8/17/2019 K-Draw Report

    63/92

     

    /************************************************************File structure:

     ver-num numscenesnumnodes numlinesx yx yx yx1 y1 x2 y2x1 y1 x2 y2x1 y1 x2 y2numnodes numlines............**************************************************************/

    /*************************************************************class savediag:public filediag{

    public:

    static int firstsave;

    savediag();savediag(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char

    headingt[20],char *textt,int idt[3]);

    friend void savefile(char *fname,int sceneid,int newf); void disp_diag();

    }dsave;int savediag::firstsave=1; //1st save or not***********************************************************/

    savediag::savediag():filediag(){

    strcpy(oldfname,"");}

    savediag::savediag(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char *textt,int idt[3]):

    filediag(x1t,y1t,x2t,y2t,optionnumt,buttontextt,headingt,textt,idt){

    strcpy(oldfname,"");}

     void savediag::disp_diag(){

    filediag::disp_diag();if (diagbutton::mode==save || diagbutton::mode==ok){ //if save selected (->ok for ENTER key)savefile(oldfname,scenedat::curscene,savediag::firstsave);//newfile}

    }

  • 8/17/2019 K-Draw Report

    64/92

     

    //-------------------for accessing save dialog from program------------------/*************************************************************************class savebutton:public diagbutton{public:

    savebutton(){}

     void buttonact();friend void savebuttoninit();

    }sb;*************************************************************************/

     void savebutton::buttonact(){

    if(m.mousemode==topbar){

    prestat=stat; //store last recorded statmouseover(); //checks for hovering.updates statif (stat==hover) //if hovering{

    h.display(H_save);

     buttonclick(); //(virtual)check for click on button.//any click recieved here will be on the button

    if (stat==active) //if clicked{

    dsave.disp_diag();mode=id; //set workmode

    }}

    }if (prestat!=stat)

    drawbutton(); //redraw only if change in statif (stat==active)

    sb.reset();diagbutton::resetmode();

    }

     void savebuttoninit(){

    sb.x1=tbx1;sb.y1=tby1;sb.x2=tbx1+50;sb.y2=tby2;sb.id=save;sb.prestat=off; //for complete redraw 1st timesb.stat=off;strcpy(sb.text,"SAVE");sb.drawbutton();

    }

     void initsavediag(){

    char *s[2]={"SAVE","CANCEL"};int d[2]={save,cancel};

    dsave=savediag(100,100,400,400,2,s,"SAVE","Enter File Name",d);}//------------------------- dialog over--------------------------------

  • 8/17/2019 K-Draw Report

    65/92

     

    //------------------------ save start----------------------------------

     void savescene(char *fname,int sceneid,int newf=0){

    int scenes=1;

    if( strstr(fname,".kdr")==NULL )//no extentionstrcat(fname,".kdr");

    if(newf==1)remove(fname);//delete existing file

    fstream f(fname,ios::in|ios::out);

    if ( f.good() && newf || strcmpi(dsave.oldfname,fname)==0)//if new file{

    f.seekp(0,ios::beg);

    scenes=1;

    fh.version=VERSION;fh.numscenes=1;f.write( iovar(fh) );

    savediag::firstsave=0;}

    if(!f.good()){

    cout

  • 8/17/2019 K-Draw Report

    66/92

     

    else if (sceneid==scenes)//update current scene{

    for(int i=1;ix;ld.y2=conline(i).p[1]->y;ld.c =conline(i).color;

    f.write( iovar(ld) );} //write all lines

    f.close();

    //---------------write required scene-over------------------}

    }}

    }

     void savefile(char *fname,int sceneid=1,int newf=0) //save a particlar scene{

    if( strstr(fname,".kdr")==NULL )//no extentionstrcat(fname,".kdr");

    savescene(fname,sceneid,newf);}

    //------------------------- save over--------------------------------------

  • 8/17/2019 K-Draw Report

    67/92

     

    MYOPEN.H

    /************************************************************

    File structure:

     ver-num numscenesnumnodes numlinesx yx yx yx1 y1 x2 y2x1 y1 x2 y2x1 y1 x2 y2numnodes numlines............**************************************************************/

    //------------------------- dialog start------------------------------

    /*******************************************************************class opendiag:public filediag{

    public:opendiag();opendiag(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char *textt,int idt[3]);

    friend void openfile(char *fname); void disp_diag();

    }dopen;

    *****************************************************************/

    opendiag::opendiag():filediag(){

    strcpy(oldfname,"");}

    opendiag::opendiag(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char *textt,int idt[3]):

    filediag(x1t,y1t,x2t,y2t,optionnumt,buttontextt,headingt,textt,idt){

    strcpy(oldfname,"");}

     void opendiag::disp_diag(){

    filediag::disp_diag();

    if (diagbutton::mode==open || diagbutton::mode==ok) //if open selected{ //(->ok for ENTER key)

    nodes::empty();

  • 8/17/2019 K-Draw Report

    68/92

     

    lines::empty();

    m.mouseoff();setfillstyle(SOLID_FILL,BLACK);

     bar(wx1,wy1,wx2,wy2);m.mouseon();

    openfile(oldfname);}

    }

    // for accessing save dialog from program/**********************************************************************class openbutton:public diagbutton{public:

    openbutton(){}

     void buttonact();friend void openbuttoninit();

    }ob;***********************************************************************/

     void openbutton::buttonact(){

    if(m.mousemode==topbar){

    prestat=stat; //store last recorded statmouseover(); //checks for hovering.updates statif (stat==hover) //if hovering{

    h.display(H_open); buttonclick(); //(virtual)check for click on button.

    //any click recieved here will be on the buttonif (stat==active) //if clicked{

    dopen.disp_diag();mode=id; //set workmode

    }}

    }if (prestat!=stat)

    drawbutton(); //redraw only if change in statif (stat==active)

    ob.reset();diagbutton::resetmode();

    }

     void openbuttoninit(){

    ob.x1=tbx1+55;ob.y1=tby1;ob.x2=tbx1+105;ob.y2=tby2;ob.id=open;ob.prestat=off; //for complete redraw 1st timeob.stat=off;strcpy(ob.text,"OPEN");

  • 8/17/2019 K-Draw Report

    69/92

     

    ob.drawbutton();}

     void initopendiag(){

    char *s[2]={"OPEN","CANCEL"};int d[2]={open,cancel};

    dopen=opendiag(100,100,400,400,2,s,"OPEN","Enter File Name",d);}//------------------------- dialog over------------------------------//------------------------- open start-------------------------------

     void openfile(char *fname){

    int scenes=1;

    if( strstr(fname,".kdr")==NULL )//no extentionstrcat(fname,".kdr");

    fstream f(fname,ios::in|ios::nocreate|ios::binary);

    if(f.fail()){

    h.display(H_nofile);}else{

    //-------------skip to required scenef.seekg(0,ios::beg);

    if(f.read(iovar(fh)) && fh.version==VERSION ){

    scenes= fh.numscenes; //get no. of scenes

    for (int i=1;i

  • 8/17/2019 K-Draw Report

    70/92

     

    MYEXIT.H

    /****************************************************************************class exitdiag:public filediag{

    public:exitdiag();

    exitdiag(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char *textt,int idt[3]);

    friend void exit(char *fname); void disp_diag();

    }dexit;***************************************************************************/exitdiag::exitdiag():filediag()

    {strcpy(oldfname,"");

    }

    exitdiag::exitdiag(int x1t,int y1t,int x2t,int y2t,int optionnumt,char **buttontextt,char headingt[20],char*textt,int idt[3]):filediag(x1t,y1t,x2t,y2t,optionnumt,buttontextt,headingt,textt,idt)

    {strcpy(oldfname,"");

    }

     void exitdiag::disp_diag(){

    filediag::disp_diag();if (diagbutton::mode==save || diagbutton::mode==ok) //if save selected

    { //(->ok for ENTER key)

    savefile(oldfname,scenedat::curscene,savediag::firstsave);//newfileexit(0);//Exit Program properly}else if(diagbutton::mode==exitb)

    exit(0);//Exit Program properly}

    /**************************************************************************class exitbutton:public diagbutton{

    public:exitbutton(){}

     void buttonact();friend void exitbuttoninit();

    }eb;*************************************************************************/

     void exitbutton::buttonact(){

    if(m.mousemode==topbar){

    prestat=stat; //store last recorded statmouseover(); //checks for hovering.updates statif (stat==hover) //if hovering