$(document).ready(function() { $('pre code').each(function(i, block) { hljs.highlightBlock(block); }); });

Graphics Programs

/*Mouse Handling functions for C*/
#include"dos.h"

union REGS i,o;
struct SREGS s;

InitiateMouse();
void ShowPtr();
void HidePtr();
void GetMousePos(int *,int *,int *);
void SetMousePos(int *,int *);
void RestrictPtr(int X1,int Y1,int X2,int Y2);
void ChangeCursor(int *);

int cursor[32]={
//Arrow Mask----------------
0x3fff,0x1fff,0x0fff,0x07ff,
0x03ff,0x01ff,0x00ff,0x007f,
0x003f,0x001f,0x000f,0x0007,
0x00ff,0x007f,0x187f,0x3c7f,

//Screeen Mask--------------
0x0000,0x4000,0x6000,0x7000,
0x7800,0x7c00,0x7e00,0x7f00,
0x7f80,0x7fc0,0x7fe0,0x7c00,
0x7e00,0x6700,0x4300,0x0000,
};

InitMouse()
{
i.x.ax=0;
int86(0x33,&i,&o);
return(o.x.ax);
}

void ShowPtr()
{
i.x.ax=1;
int86(0x33,&i,&o);
}

void HidePtr()
{
i.x.ax=2;
int86(0x33,&i,&o);
}

void GetMousePos(int *button,int *X,int *Y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx;
*X=o.x.cx;
*Y=o.x.dx;
}

void SetMousePos(int *X,int *Y)
{
i.x.ax=4;
int86(0x33,&i,&o);
o.x.cx=*X;
o.x.dx=*Y;
}

void ChangeCursor(int *shape)
{
i.x.ax=9;
i.x.bx=0;
i.x.cx=0;
i.x.dx=(unsigned)shape;
segread(&s);
s.es=s.ds;
int86x(0x33,&i,&i,&s);
}

void RestrictPtr(int X1,int Y1,int X2,int Y2)
{
i.x.ax=7;
i.x.cx=X1;
i.x.dx=X2;
int86(0x33,&i,&o);
i.x.ax=8;
i.x.cx=Y1;
i.x.dx=Y2;
int86(0x33,&i,&o);
}

-------------------------------------------------------------
/*LL Using GRAPHICS
------Under Process-------
*/
#include"stdio.h"
#include"conio.h"
#include"graphics.h"

#include"SLL.C"
#include"MOUSE.C"
#include"DRAWINGS.C"

#define BGCOLOR DARKGRAY
#define CLEAR 0
#define PRINT 2
#define RESTORE 0
#define SAVE 1
#define COMPOSE 2

void CreateBG();
void ExitBar(int STAT);
void CreateNode();
void DrawCanvas(int STAT);
void DrawList(LL *);
void InstBar(int,char *);
void InsertData();
void DeleteNODE();

int Mx,My,BL=90,NodeLen=10;//BL=Button Length
int BTNxy[5][2];
int canvasXY[4];
int EXITxy[2],exitLen=18;
int Nodexy[100][2];

char options[][20]={"Create Node",
"Enter data",
"Delete Data",
"Delete Node",
"Clear Canvas"
};

void main()
{
int gd=DETECT,gm;
int Mode,flag=0;
int btn,x,y,i;
char *inst[]={"TREE is EMPTY currently.",
"Create ROOT NODE first!"
};
initgraph(&gd,&gm,"..\\bgi");

if(InitMouse()==NULL)
{
printf("\nSorry, Mouse driver can\'t be loaded. Quiting the program...");
delay(3000);
exit();
}
Mx=getmaxx();
My=getmaxy();
START=NULL;

EXITxy[0]=Mx-exitLen-8;
EXITxy[1]=8;
canvasXY[0]=5;
canvasXY[1]=85;
canvasXY[2]=Mx-5;
canvasXY[3]=My-5;

CreateBG();
InstBar(PRINT,inst[0]);
ExitBar(NORMAL);
DrawCanvas(COMPOSE);

ChangeCursor(&cursor[0]);
ShowPtr();

while(1)
{
GetMousePos(&btn,&x,&y);
//Create Node
if((x>BTNxy[0][0] &&xBTNxy[0][1] &&yBTNxy[1][0] &&xBTNxy[1][1] &&yBTNxy[2][0] &&xBTNxy[2][1] &&yBTNxy[3][0] &&xBTNxy[3][1] &&ynext!=NULL)
{
ColorButton(BTNxy[3][0],BTNxy[0][1],BL,SETACTIVE);
InstBar(CLEAR,NULL);
InstBar(PRINT,"Click the Node which you want to erase. The Rest will be linked up!");
DeleteNODE();
}
else
{
InstBar(CLEAR,NULL);
if(START->next==NULL)
InstBar(PRINT,"You cannot delete nodes now because only one node is left. Rather,use \'Clear Canvas\'...");
else
InstBar(PRINT,"Sorry, the TREE is empty currently. You cannot delete node.");
delay(200);
}
ShowPtr();
}
}
//Clear Canvas
else if((x>BTNxy[4][0] &&xBTNxy[4][1] &&yEXITxy[0] &&xEXITxy[1] &&yleft=NULL;
Node->right=NULL;
if(START==NULL)
{
START=(BT *)malloc(sizeof(BT));
START->left=NULL;
START->right=NULL;
Nodexy[count++][0]=X;
Nodexy[count][1]=Y;
START->IthVal=count;
}
else
{
for(i=count-1;i>=0||flag==0;i--)
{
if(Y>Nodexy[i][1])//y>y of nodexy?
{
if(X>Nodexy[i][0])//x>x of nodexy?
{
Nodexy[count++][0]=X;
Nodexy[count][1]=Y;
temp->IthVal=count;
temp->right=Node;
flag=1;
}
else if(X>Nodexy[i-1][0]||XIthVal=count;
temp->left=Node;
flag=1;
}
else
break;
}
else if(XIthVal=count;
temp->left=Node;
flag=1;
}
else
{
InstBar(PRINT,"SORRY, Node cannot be inserted at this location!");
}
}
}
} */

void CreateNode()
{
void CreateNodePart(int x,int y,int source,int dest,int,int,int);
LL *temp,*Node,*prev;
int i,j,k,l,count=0,flag=0;
int Click,X,Y;

delay(200);
prev=(LL *)malloc(sizeof(LL));
Node=(LL *)malloc(sizeof(LL));
temp=(LL *)malloc(sizeof(LL));

Node->next=NULL;
do
{
GetMousePos(&Click,&X,&Y);
if(Click&1==1)
count++;
}while(count!=2);

if(START==NULL)
{
Node->x=X;
Node->y=Y;
Node->item=NULL;
Node->next=NULL;
START=Node;
i=Node->x,j=Node->y;
k=X,l=Y;
flag=0;
}
else if(X>0&&X<=START->x)//Insertion at begining
{
Node->x=X;
Node->y=Y;
Node->item=NULL;
Node->next=START;
i=X;j=Y;
k=START->x;
l=START->y;
START=Node;
flag=2;
}
else
{
temp=START;
while(temp->xx;
j=temp->y;
temp=temp->next;
if(temp==NULL)
break;
}
Node->x=X;
Node->y=Y;
Node->item=NULL;
Node->next=temp;
prev->next=Node;
if(Node->next!=NULL)
{
k=temp->x;
l=temp->y;
flag=0;
}
else
{
flag=1;
}
}
CreateNodePart(X,Y,i,j,k,l,flag);
}

void CreateNodePart(int x,int y,int sx,int sy,int dx,int dy,int flag)
{
HidePtr();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(x,y,x+30,y+20);
ColorButton(x,y,20,INACTIVE);
ColorButton(x+20,y,10,INACTIVE);
InstBar(CLEAR,NULL);
InstBar(PRINT,"New Node created!");

if(sx!=dx)
{
setcolor(BLUE);
if(flag!=2)
line(sx+30,sy+10,x,y+10);
if(flag!=1)
{
line(x+30,y+10,dx,dy+10);
setcolor(WHITE);
line(sx+31,sy+10,dx-1,dy+10);
}
}
ShowPtr();
}

void DeleteNODE()
{
int btn,x,y;
int flag=0,endflag=0,txflag=0;
int tx,ty;
LL *temp,*prev;
void HighlightNode(int,int,int);
temp=(LL *)malloc(sizeof(LL));

delay(200);
do
{
temp=START;
txflag=0;
while(temp!=NULL&&endflag==0&&txflag==0)
{
if(txflag==0)
GetMousePos(&btn,&x,&y);
prev=temp->next;
tx=temp->next->x;
ty=temp->next->y;
if((x>=tx&&x<=tx+30)&&(y>=ty&&y<=ty+20)) { if(flag==0) { HidePtr(); HighlightNode(tx,ty,ACTIVE); } txflag=1; ShowPtr(); flag=1; if(btn&1==1) { HidePtr(); InstBar(CLEAR,NULL); InstBar(PRINT,"Node Deleted successfully!"); endflag=1; if(START->next==NULL)
START=NULL;
else
{
prev=prev->next;
temp->next=prev;
}
DrawCanvas(COMPOSE);
DrawList(START);
ShowPtr();
}
}
else
{
if(flag==1&&txflag==0)
{
HidePtr();
HighlightNode(tx,ty,NORMAL);
}
ShowPtr();
flag=0;
}
temp=temp->next;
}
}while(endflag!=1);
}

void HighlightNode(int x,int y,int MODE)
{
if(MODE==ACTIVE)
setcolor(DARKGRAY);
else
setcolor(WHITE);
rectangle(x,y,x+30,y+20);
if(MODE==ACTIVE)
setcolor(WHITE);
else
setcolor(DARKGRAY);
rectangle(x+1,y+1,x+29,y+19);
}

void InsertData()
{
void InsertNodeItem(LL *ptr);
int btn,x,y;
int prevX,prevY,flag=0,endflag=0;
int tx,ty,i,j,txflag=0;
LL *temp,*Next;
temp=(LL *)malloc(sizeof(LL));

delay(200);
while(endflag==0)
{
temp=START;
GetMousePos(&btn,&x,&y);
txflag=0;
while(temp!=NULL&&txflag==0)
{
tx=temp->x;
ty=temp->y;
if((x>=tx&&x<=tx+30)&&(y>=ty&&y<=ty+20)) { if(flag==0) { HidePtr(); HighlightNode(tx,ty,ACTIVE); } ShowPtr(); flag=1; txflag=1; if(btn&1==1) { HidePtr(); InstBar(CLEAR,NULL); endflag=1; InsertNodeItem(temp); InstBar(PRINT,"Item inserted successfully!"); DrawCanvas(COMPOSE); DrawList(START); ShowPtr(); txflag=0; } } else { if(flag==1) { HidePtr(); HighlightNode(tx,ty,NORMAL); } ShowPtr(); flag=0; txflag=0; } temp=temp->next;
}
}
}

void InsertNodeItem(LL *ptr)
{
static int i;
int flag=0;
HidePtr();
if(!kbhit()||flag==0)
{
i=i*10;
if(getch()!='\r')
{
ptr->item+=i*(ptr->item)+getch();
i++;
}
else
flag=1;
}
ShowPtr();
DrawList(ptr);
}

void DrawList(LL *ptr)
{
LL *temp;
int tx,ty;
char c;
temp=(LL *)malloc(sizeof(LL));

temp=ptr;
while(temp!=NULL)
{
HidePtr();
tx=temp->x;
ty=temp->y;
c=temp->item;
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(tx,ty,tx+30,ty+20);
ColorButton(tx,ty,20,INACTIVE);
setcolor(BLUE);
settextstyle(2,HORIZ_DIR,4);
outtextxy(tx+5,ty+5,&c);
ColorButton(tx+20,ty,10,INACTIVE);
InstBar(CLEAR,NULL);
InstBar(PRINT,"The Current List is:!");

temp=temp->next;
setcolor(BLUE);
if(temp->x!=NULL&&temp->y!=NULL)
line(tx+30,ty+10,temp->x,(temp->y)+10);
}
}

--------------------------------------------------------------
/*Program to implement ONE WAY LIST using Mouse n Graphics*/
#include
#define INACTIVE 0
#define NORMAL 1
#define ACTIVE 2
#define SETACTIVE 3

void SimpleButton(int,int,int,int);
void ColorButton(int,int,int,int);

void SimpleButton(int x,int y,int len,int k)
{
int i;
for(i=0;i {
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(x,y,x+len,y+20);
setcolor(BLACK);
rectangle(x,y,x+len,y+20);
x=x+(len+10);
}
}

void ColorButton(int a,int b,int len,int stat)
{
int i;

if(stat==INACTIVE)
setcolor(DARKGRAY);
else
setcolor(BLACK);
rectangle(a,b,a+len,b+20);

if(stat==SETACTIVE)
setcolor(WHITE);
else if(stat==ACTIVE)
setcolor(DARKGRAY);
else
setcolor(LIGHTGRAY);
rectangle(a+1,b+1,a+len-1,b+19);

if(stat==ACTIVE)
setcolor(WHITE);
else
setcolor(LIGHTGRAY);
line(a+2,b+2,a+len-2,b+2);
line(a+2,b+2,a+2,b+18);
line(a+3,b+3,a+len-3,b+3);
line(a+3,b+3,a+3,b+18);

if(stat==ACTIVE)
setcolor(DARKGRAY);
else
setcolor(LIGHTGRAY);
line(a+3,b+18,a+len-3,b+18);
line(a+len-2,b+18,a+len-2,b+3);
}

No comments:

Post a Comment

Contact Me

Name

Email *

Message *