www.pudn.com > dos_gui.zip > 3DGBAS.CPP


#include "msgbox.h" 
#include "yyxmain.h" 
#include "editdlg.h" 
#include "filedial.h" 
#include  
#include  
#include  
#include  
#include  
 
#include "3dgbas.h" 
#include "3dmenu.h" 
 
graphbas_class::graphbas_class (int ID,char *title,byte type,byte hotkey, 
	 int left, int top, int width, int height ) 
	:win_class (ID,title,type,hotkey,left,top,width,height) 
{ 
	rho =40; theta =0; phi = PI/2 ; d =450; 
	viewport.clip =1 ; // CLIP_ON; 
	setup_window();  // may result in a duplicate 
} 
 
void graphbas_class::setup_window () 
{	win_class::setup_window(); 
 
	cx 	=( bounds.right-bounds.left-25) /2 ; 
	cy 	=( bounds.bottom-bounds.top-25) /2; 
//	ix1=25, iy1=25, ix2=bounds.right-bounds.left-25, iy2=bounds.bottom-bounds.top-90;   // bounds.top 
	calc(); 
} 
 
graphbas_class::~graphbas_class () 
{ 
} 
 
int graphbas_class::key_pressed_handler  ( int key_scan_num ) 
{ 
 
  int ret_value; 
	if ((ret_value=win_class::key_pressed_handler (key_scan_num )) !=FALSE) 
		return ret_value; 
 
	draw_all_surface (BLACK); 
 
	switch(key_scan_num )	{ 
		case F1KEY:rho *=2;  break; 
		case F2KEY:rho /=2;  break; 
		case LEFTKEY:theta +=PI/8;break; 
		case RIGHTKEY:theta -=PI/8;break; 
		case UPKEY:phi +=PI/8;break; 
		case DOWNKEY:phi -=PI/8;break; 
		case '7':d   *=2;break; 
		case '8':d   /=2;break; 
	} 
 
	calc(); 
	draw_all_surface (GREEN); 
	return FALSE; 
} 
 
 
int graphbas_class::msg_handler (MSG& message ) 
{ 
	if (win_class::msg_handler (message) !=FALSE ) return TRUE; 
	switch ( message .Action){ 
		case MenuActionMSG: 
			switch (message.ID ){ 
				case LEFT: key_pressed_handler  ( LEFTKEY);break; 
				case RIGHT:key_pressed_handler  ( RIGHTKEY);break; 
				case UP:   key_pressed_handler  (   UPKEY);break; 
				case DOWN: key_pressed_handler  ( DOWNKEY);break; 
				case NEAR: key_pressed_handler  (   F2KEY);break; 
				case FAR : key_pressed_handler  (   F1KEY);break; 
 
				case DISTANCE: break; 
  Teditdlg * modifydlg; 
  char buf[30]; 
				case X_VALUE: 
					sprintf (buf,"%4.1f",X); 
					modifydlg=new Teditdlg(0,"INPUT X VALUE",150,100,300,200,buf); 
					if (theprogram->exec_dialog(modifydlg) ==Dlg_OK )  { 
						X = atof ( buf ); 
 
						rho = sqrt (X*X+Y*Y+Z*Z); 
						theta = acos ( Z/ rho); 
						phi   = acos ( X/ sqrt(X*X+Y*Y)); 
						calc (); 
						draw_win_contents(); 
					}; 
					break; 
				case Y_VALUE: 
					sprintf (buf,"%4.1f",Y); 
					modifydlg=new Teditdlg(0,"INPUT Y VALUE",150,100,300,200,buf); 
					if (theprogram->exec_dialog(modifydlg) ==Dlg_OK )  { 
						Y = atof ( buf ); 
 
						rho = sqrt (X*X+Y*Y+Z*Z); 
						theta = acos ( Z/ rho); 
						phi   = acos ( X/ sqrt(X*X+Y*Y)); 
						calc (); 
						draw_win_contents(); 
					}; 
					break; 
				case Z_VALUE: 
					sprintf (buf,"%4.1f",Z); 
					modifydlg=new Teditdlg(0,"INPUT Z VALUE",150,100,300,200,buf); 
					if (theprogram->exec_dialog(modifydlg) ==Dlg_OK )  { 
						Z = atof ( buf ); 
 
						rho = sqrt (X*X+Y*Y+Z*Z); 
						theta = acos ( Z/ rho); 
						phi   = acos ( X/ sqrt(X*X+Y*Y)); 
						calc (); 
						draw_win_contents(); 
					}; 
					break; 
			}; 
			break; 
		default: return FALSE; 
	} 
 
	return TRUE; 
} 
 
 
int graphbas_class::draw_win_contents() 
{ 
	getviewsettings (¤t_viewport ); 
	setport (viewport); 
/*	setviewport (viewport.left, 
		viewport.top, 
		viewport.right, 
		viewport.bottom-2*bar_height, 1); 
*/ 
	setfillstyle(SOLID_FILL,BLACK); 
	bar (0,0,viewport.right-viewport.left, 
		viewport.bottom-viewport.top-bar_height); 
 
	putch (0x007); 
//	calc (); 
	draw_all_surface(GREEN); 
 
	setport (current_viewport ); 
	return 0; 
} 
 
void graphbas_class::draw_all_surface(int color) 
{ 
  int i; 
	setcolor (color); 
	for (i=0;i