?? apollo.c
字號(hào):
#include<graphics.h>
#include<ctype.h>
#include<dos.h>
#include<stdlib.h>
#include<math.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<alloc.h>
#define NORMAL 0
#define ERASER 1
#define CANV_X_MAX 605
#define CANV_X_MIN 50
#define CANV_Y_MAX 430
#define CANV_Y_MIN 35
int select_flag;
int save_flag;
char file[20];
int trans_flag;
int first_trans;
int current_color = BLACK;
int current_pointer = NORMAL;
int current_line_style = SOLID_LINE;
int sminx, sminy, smaxx, smaxy;
int brush;
int copied = 0;
FILE* c_c_p;
void paste ( void );
int tool_selected ( union REGS );
void save_file ( void );
int get_tool ( int, int );
void draw_screen ( void );
void init_mouse ( void );
int in_range ( int, int, int );
void copy_selected_portion (void );
void draw_palette ( void );
void draw_icons ( void );
void draw_canvas ( void );
void draw_tool_bar ( void );
void set_position ( int, int );
void restrict ( int, int, int, int );
void show ( void );
void show_coords ( int, int );
void hide (void );
void draw_menu ( void );
void highlight_button ( int, int );
void draw_rectangle ( void );
void draw_polygon ( void );
void draw_line ( void );
void draw_ellipse ( void );
void translate ( void );
void cube ( long double, int,int) ;
int main ( )
{
int gdriver = DETECT, gmode;
initgraph ( &gdriver, &gmode, "" );
draw_canvas ( );
draw_screen ( );
draw_palette ( );
draw_tool_bar ( );
draw_menu ( );
init_mouse ( );
closegraph ( );
return 0;
}
void draw_screen ( void )
{
setfillstyle ( SOLID_FILL, BLUE );
bar (0,5,640,20); //top most blue
setfillstyle ( SOLID_FILL,LIGHTGRAY);
bar ( 0, 20, 640, 34); // menu
bar ( 0, 433, 640, 475);//bottom
bar ( 606, 35, 640, 450); //right side
bar ( 0, 35, 49, 430);
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 625,7, 635,17 );
setcolor ( BLACK );
line ( 627, 9, 633, 15 ); // for the close button
line ( 627, 15, 633, 9 );
}
void draw_palette (void )
{ int i;
for ( i = 0; i <=15; i++ )
{
setfillstyle ( SOLID_FILL, i );
bar (614,45+i*17+5,631,45+(i+1)*17+2);
setcolor ( BLACK );
rectangle ( 614,45+i*17+5,631,45+(i+1)*17+2 );
}
setfillstyle ( SOLID_FILL, WHITE );
bar ( 619, 370, 641, 390 );
rectangle ( 619, 370, 641, 390 );
setfillstyle ( SOLID_FILL, BLACK );
bar ( 608, 360, 630, 380 );
rectangle ( 608, 360, 630, 380 );
}
void draw_canvas ( void )
{
setfillstyle ( SOLID_FILL, WHITE );
bar ( 0, 5, 640, 475 );
}
void draw_tool_bar( void )
{
int i;
setcolor ( BLACK );
rectangle ( 2, 80, 48, 320 );
line ( 25, 80 , 25, 320 );
for ( i = 0; i < 8 ; i++ )
line ( 2, 80+i*30, 48,80+i*30 );
draw_icons ( );
setcolor ( current_color );
return;
}
void draw_ipen ( void )
{
setfillstyle ( SOLID_FILL, RED );
bar ( 10, 87, 18, 101 );
line ( 10, 101, 14 , 107 );
line ( 18, 101, 14, 107 );
line ( 10, 101, 18, 101 );
setfillstyle ( SOLID_FILL, BLACK );
floodfill ( 13, 104, BLACK );
}
void draw_iline ( void )
{
line ( 31, 107, 43, 85 );
}
void draw_iell ( void )
{
ellipse ( 14, 125, 0, 360, 9, 7 );
}
void draw_irect ( void )
{
rectangle ( 28, 116, 45, 130 );
}
void draw_ipoly ( void )
{
line ( 13, 145, 6, 165 );
line ( 21, 145, 16, 158 );
line ( 6, 165, 22, 165 );
line ( 16, 158, 22, 158 );
line ( 13, 145, 21, 145 );
line ( 22, 165, 22, 158 );
}
void draw_ierase ( void )
{
rectangle( 31, 146, 43, 160 );
setfillstyle ( SOLID_FILL, WHITE );
floodfill ( 32, 150, BLACK) ;
}
void draw_ifill ( void )
{
line ( 15, 177, 24, 189 );
line ( 8, 182, 17, 194);
line ( 15, 177, 8, 182 );
line ( 24, 189, 17, 194 );
line ( 11, 183, 18, 181 );
setfillstyle ( SOLID_FILL, BLUE );
floodfill ( 14, 184, BLACK );
}
void draw_ibrush ( void )
{
int i = 34;
rectangle ( 34, 184, 42, 187 );
for ( i = 34; i<=42; i+=2 )
line ( i, 188, i, 191 );
setcolor ( BROWN );
for ( i = 35; i<=41; i+=2)
line ( i, 188, i, 191 );
setfillstyle ( SOLID_FILL, YELLOW );
floodfill ( 35, 185, BLACK );
setcolor ( BLACK );
rectangle ( 37, 175, 39, 184 );
}
void draw_ispray ( void )
{
line(14, 212, 9, 224 );
line ( 20, 212, 22, 224 );
line (9, 224, 22, 224 );
line ( 14, 212, 20, 212 );
rectangle( 16, 208, 18, 212 );
setfillstyle ( SOLID_FILL, MAGENTA );
floodfill ( 14, 220, BLACK );
putpixel ( 13, 206, MAGENTA );
putpixel ( 12, 209, MAGENTA );
putpixel ( 10, 202, MAGENTA );
putpixel ( 4, 203, MAGENTA );
putpixel ( 9, 205, MAGENTA );
putpixel ( 13, 213, MAGENTA );
putpixel ( 11, 214, MAGENTA );
putpixel ( 7, 200, MAGENTA );
putpixel ( 2, 201, MAGENTA );
putpixel ( 9, 212, MAGENTA );
putpixel ( 3, 211, MAGENTA );
putpixel ( 5, 207, MAGENTA );
putpixel ( 5, 209, MAGENTA );
putpixel ( 6, 201, MAGENTA );
putpixel ( 10, 202, MAGENTA );
putpixel ( 11, 205, MAGENTA );
setcolor ( BLACK );
}
void draw_iselect ( void )
{
setlinestyle ( DOTTED_LINE, 0, 1);
rectangle ( 28, 208, 44, 223 );
setlinestyle ( SOLID_LINE, 1, 1 );
}
void draw_itranslate ( void )
{
line ( 15, 246, 21, 246 );
line ( 11, 246, 5, 246 );
line ( 13, 244, 13, 236 );
line ( 13, 248, 13, 256 );
line ( 18, 243, 21, 246 );
line ( 18, 249, 21, 246 );
line ( 8, 243, 5, 246 );
line ( 8, 249, 5, 246 );
line ( 10, 239, 13, 236 );
line ( 16, 239, 13, 236 );
line ( 10, 253, 13, 256 );
line ( 16, 253, 13, 256 );
}
void draw_irotate ( void )
{
arc ( 30, 255, 0, 90, 15 );
line ( 30, 241, 33, 238 );
line ( 30, 241, 33, 244 );
outtextxy ( 27, 250, "90" );
}
void draw_icube ( void )
{
line ( 6, 271, 6, 283 );
line ( 16, 271, 16, 283 );
line ( 6, 271, 16, 271 );
line ( 6, 283, 16, 283 );
line ( 6, 271, 11, 265 );
line ( 16, 271, 21, 265 );
line ( 11, 265, 21, 265 );
line ( 21, 265, 21, 277 );
line ( 16, 283, 21, 277 );
}
void draw_ishear ( void )
{
rectangle ( 28, 275, 40, 285 );
line ( 28, 285, 34, 275 );
line ( 40, 285, 46, 275 );
line ( 40, 275, 46, 275 );
setcolor ( BLUE );
line ( 40, 276, 40, 284 );
setfillstyle ( SOLID_FILL, BLUE);
floodfill ( 40, 276, BLACK );
setcolor ( BLACK );
line ( 40, 275, 40, 285 );
outtextxy ( 26, 265, "sh" );
}
void draw_itext ( void )
{
outtextxy ( 26, 292, "T" );
outtextxy ( 31, 298, "e" );
outtextxy ( 36, 304, "x" );
outtextxy ( 42, 312, "t" );
}
void draw_iscale ( void )
{
rectangle ( 7, 306, 22, 318 );
rectangle ( 7, 294, 13, 298 );
}
void draw_icons ( void )
{
draw_ipen ( );
draw_iline ( );
draw_iell ( );
draw_irect ( );
draw_ipoly ( );
draw_ierase ( );
draw_ifill ( );
draw_ibrush ( );
draw_ispray ( );
draw_iselect ( );
draw_irotate ( );
draw_itranslate ( );
draw_itext ( );
draw_icube ( );
draw_ishear ( );
draw_iscale ( );
}
void display_selected_color ( int color )
{
setfillstyle ( SOLID_FILL, color );
bar (608, 360, 630, 380);
rectangle ( 608,360, 630, 380 );
}
int color_selected ( union REGS out )
{
int i;
for ( i = 0; i<=15; i++ )
{
if ( in_range ( out.x.cx,614,631 ) && in_range ( out.x.dx, 45+i*17+5,45+(i+1)*17+2 ) && out.x.bx == 1 )
return 1;
}
return 0;
}
void show_current_color ( int x, int y, int button )
{
int i;
for ( i = 0 ;i <= 15 ; i++ )
{
if ( button == 1 && in_range ( x, 614, 631 ) && in_range ( y, 45+i*17+5, 45+(i+1)*17+2 ))
{
display_selected_color ( i );
current_color = i;
break;
}
}
}
void draw_free_hand ( union REGS out )
{
union REGS in;
int cx = 0, cy = 0;
while ( 1 )
{
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
delay ( 5 );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 430, 640, 475);
show_coords ( out.x.cx, out.x.dx );
if ( out.x.bx != 1 )
cx = cy = 0;
setcolor ( current_color );
if ( out.x.bx == 1 && in_range ( out.x.cx, 50, 605) && in_range ( out.x.dx, 35, 430))
{
hide ( );
if ( cx || cy )
{
line ( cx, cy, out.x.cx, out.x.dx );
if ( brush )
{
line ( cx+1, cy, out.x.cx+1, out.x.dx );
line ( cx, cy+1, out.x.cx, out.x.dx+1 );
}
}
show();
delay ( 5 );
cx = out.x.cx;
cy = out.x.dx;
}
else if ( tool_selected ( out ) && get_tool ( out.x.cx, out.x.dx ) != 1 && brush == 0 )
return;
else if ( tool_selected ( out ) && brush && get_tool ( out.x.cx, out.x.dx ) != 8 )
return;
else if ( in_range ( out.x.cx,625, 635 ) && in_range ( out.x.dx, 7, 17 )&& out.x.bx==1)
exit ( 0 );
else if ( color_selected ( out))
show_current_color ( out.x.cx, out.x.dx, out.x.bx );
else
continue;
}
}
int tool_selected ( union REGS out )
{
if ( in_range ( out.x.cx, 2, 48 ) && in_range ( out.x.dx, 80, 320 ) && out.x.bx == 1 )
return 1;
return 0;
}
int get_tool ( int x, int y )
{
int i;
for ( i = 0 ; i < 8 ; i++ )
if ( in_range ( y, 80+i*30, 80+(i+1)*30 ))
break;
if ( in_range ( x, 2, 25))
return i*2+1;
else
return i*2+2;
}
void draw_menu ( void )
{
int i;
setcolor ( BLACK );
rectangle ( 2, 330, 48, 420 );
for ( i = 1; i <= 5; i++ )
{
line ( 2, 330+i*15, 48, 330+i*15 );
switch ( i )
{
case 1 : outtextxy ( 15, 330+4, "New" );
break;
case 2 : outtextxy ( 13, 330+(i-1)*15+4, "Open");
break;
case 3 : outtextxy ( 13, 330+(i-1)*15+4, "Save" );
break;
case 4 : outtextxy ( 15, 330+(i-1)*15+4, "Cut" );
break;
case 5 : outtextxy ( 13, 330+(i-1)*15+4, "Copy" );
break;
}
}
outtextxy ( 7, 330+(i-1)*15+4, "Paste" );
setcolor ( current_color );
}
int get_select ( int x, int y )
{
int i = 0;
for ( i = 0 ; i <6 ; i++ )
{
if ( in_range ( x, 2, 48 ) && in_range ( y, 330+i*15, 330+(i+1)*15 ) )
return ( i+1 );
}
return 0;
}
void open_new_file ( void )
{
char ch;
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 20, 640, 34 );
setcolor ( BLACK );
outtextxy ( 45, 25, "New" );
bar ( 0, 20, 640, 34 );
outtextxy ( 45, 25, "Save current file ( y/n ) ?" );
ch = getch ( );
if ( ch == 'y' )
save_file ( );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 20, 640, 34 );
setfillstyle ( SOLID_FILL, WHITE );
bar ( CANV_X_MIN, CANV_Y_MIN, CANV_X_MAX, CANV_Y_MAX );
setcolor ( current_color );
}
void open_file ( void )
{
char ch;
int count = 0, i;
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 20, 640, 34 );
for ( i = 0; i < 20; i++ )
file[i] = '\0';
setcolor ( BLACK );
outtextxy ( 45, 25, "Save file? ( y/n)" );
ch = getch ( );
if ( ch == 'y' )
save_file ( );
bar ( 0, 20, 640, 34 );
outtextxy ( 45, 25, "Enter the file name:" );
while ( 1 )
{
ch = getch ( );
if ( !isalnum ( ch ) )
break;
file[count++] = ch;
bar ( 208, 20, 640, 34 );
outtextxy ( 208, 25, file );
}
save_flag = 1;
sminx = CANV_X_MIN;
sminy = CANV_Y_MIN;
smaxx = CANV_X_MAX;
smaxy = CANV_Y_MAX;
setfillstyle ( SOLID_FILL, WHITE );
bar ( CANV_X_MIN, CANV_Y_MIN, CANV_X_MAX, CANV_Y_MAX );
paste ( );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 20, 640, 34 );
outtextxy ( 45, 25, "Open" );
setcolor ( current_color );
}
void save_file ( void )
{
char ch;
int count = 0, i;
bar ( 0, 20, 640, 34 );
for ( i = 0; i < 20; i++ )
file[i] = '\0';
setcolor ( BLACK );
outtextxy ( 45, 25, "Enter the file name:" );
while ( 1 )
{
ch = getch ( );
if ( !isalnum ( ch ) )
break;
file[count++] = ch;
bar ( 208, 20, 640, 34 );
outtextxy ( 208, 25, file );
}
save_flag = 1;
sminx = CANV_X_MIN;
sminy = CANV_Y_MIN;
smaxx = CANV_X_MAX;
smaxy = CANV_Y_MAX;
copy_selected_portion ( );
setcolor ( current_color );
}
void cut_selected_portion ( void )
{
copy_selected_portion ( );
setfillstyle ( SOLID_FILL, WHITE );
bar ( sminx, sminy, smaxx, smaxy );
setfillstyle ( SOLID_FILL, LIGHTGRAY);
bar ( 0, 20, 640, 34 );
setcolor ( BLACK );
outtextxy ( 45, 25, "Cut" );
setcolor ( current_color );
}
void copy_selected_portion ( void )
{
int i,j;
bar ( 0, 20, 640, 34 );
outtextxy ( 45, 25, "Copy" );
if ( !save_flag )
{
setlinestyle ( DOTTED_LINE, 0, 1 );
setwritemode ( XOR_PUT );
setcolor ( 15 - BLACK );
rectangle ( sminx, sminy, smaxx, smaxy );
if ( !first_trans && trans_flag )
rectangle ( sminx, sminy, smaxx, smaxy );
setlinestyle ( SOLID_LINE, 0, 1 );
c_c_p = fopen ("temp", "w" );
}
else
c_c_p = fopen ( file, "w" );
i = sminx;
j = sminy;
hide ( );
while ( j < smaxy)
{
putc ( '0'+ getpixel ( i, j ) , c_c_p );
i++;
if ( i == smaxx )
{
j++;
i = sminx;
}
}
fclose ( c_c_p );
show ( );
setcolor ( current_color );
setwritemode ( COPY_PUT );
}
void paste (void)
{
int i, j;
if ( !save_flag )
c_c_p = fopen ("temp", "r" );
else
c_c_p = fopen ( file, "r" );
i = CANV_X_MIN;
j = CANV_Y_MIN;
hide ( );
while ( j < CANV_Y_MIN+smaxy-sminy )
{
putpixel( i, j , getc (c_c_p) - '0' );
i++;
if ( i == CANV_X_MIN+smaxx-sminx )
{
j++;
i = CANV_X_MIN;
}
}
fclose ( c_c_p );
show ( );
setfillstyle ( SOLID_FILL, LIGHTGRAY );
bar ( 0, 20, 640, 34 );
setcolor ( BLACK );
outtextxy ( 45, 25, "Paste" );
setcolor ( current_color );
}
void scan_menu (void )
{
union REGS in, out;
in.x.ax = 0x0003;
int86 ( 0x33, &in, &out );
if ( out.x.bx != 1 )
return;
switch ( get_select ( out.x.cx, out.x.dx ))
{
case 1 : open_new_file ( );
break;
case 2 : save_flag = 1;
open_file ( );
save_flag = 0;
break;
case 3 : save_flag = 1;
save_file ( );
save_flag = 0;
break;
case 4 : cut_selected_portion ( );
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -