home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
CLIPART
/
VPOINT.ZIP
/
CAD3.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-06
|
81KB
|
3,482 lines
/* -----------------------------------------------------------------------
CAD?.C -- An interactive graphics drawing program. Mainly a learning
exercise in Microsoft QuickC graphics functions. Includes most of the
drawing functions available in large commercial paint programs, with
the notable exceptions of file saves and opens, and editing functions.
Portions of this program are copyright by John Clark Craig in
"Microsoft QuickC Programmers Toolbox" 1990. These sections are
indicated below above the #include statements. This is an organic
proccess, and some functions are incomplete. All liability for the use
of this program is assumed by the user. Suggestions or comments are
encouraged.
Written by Arthur Dunphy Jr. Winter 1992-93
80 Samoset Ave. #6, Hull, MA 02045
E-Mail: AJ@BU.EDU
----------------------------------------------------------------------*/
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graph.h>
#include <time.h>
/* The following include files are copyright. The names are fairly
self-descriptive. See above. */
#include "sound.h"
#include "mousefun.h"
#include "getkey.h"
/* This file consists of graphics function definitions & constants.
The functions are defined in the file AJGFUN.C */
#include "ajgfun.h"
/* The following constants describe the upper left and lower right corners
of the rectangle composing the drawing area. */
#define X1 106
#define Y1 45
#define X2 632
#define Y2 440
#define mx (X1 + X2) / 2 /// Midpoints of the drawing area
#define my (Y1 + Y2) / 2
#define SIZE 22
#define CX 275
#define CY vc.numypixels
#define NULL2 '\0'
#define MAXIMAGESIZE 50000 /* Storage area allocation for graphics images.
This appears to be the maximum allowed under
the "Large" memory model I installed with the
compiler, minus the overhead for other memory
requirements. Suggestions are very welcome. */
#define BOXSIZE 43
void draw_screen( void );
void mouse_adjust( void );
void set_cad_logorg( void );
int select_style( int );
void draw_grid( void ) ;
void draw_menu( void );
void scroll_intro(void);
void remap_std_palette(void);
void cycle_palette(void);
void reset_vanish_pt(pixtype x, pixtype y);
int getcolor(pixtype);
void break_color( color_t cnum, short *red, short *blue, short *green );
boolean inXscreen( pixtype h, pixtype v );
int get_shape( pixtype h, pixtype v );
void draw_1stbox(void);
boolean quit_prompt( short );
void helpbox(void);
short getbordercolor(void);
int remap_screen( short x1, short y1, short x2, short y2, short maptype );
boolean draw_chars( pixtype x, pixtype y );
boolean get_pos( pixtype *x1, pixtype *y1, pixtype *pos);
short font_menu( void );
short fonttype( void );
void get_font_info( pixtype , pixtype );
short get_font_size(short);
void set_vector(void );
void get_vector(void );
void get_fillmask( void );
void remap_color( short col );
void draw_newbox( rect_s *, short, short, short, short );
short get_brush_shape( short oldshape );
void drawrect( boolean fill, rect_s *r );
void draw_star( pixtype, pixtype );
void draw_spray( pixtype, pixtype );
void draw_slash( pixtype x, pixtype y, short len);
void draw_backslash( pixtype x, pixtype y ,short len);
void draw_square(pixtype, pixtype,short);
void draw_ellipse(pixtype, pixtype, short);
void update_newbox(pixtype midx, pixtype midy, short shape );
void draw_paint2(pixtype x1, pixtype y1, short shape );
void draw_paint(pixtype x1, pixtype y1, short shape );
void cycle3( void );
void sqx( pixtype x, pixtype y );
color_t custom_color(short palette_num );
void update_shapebox( short type );
void draw_arc( short );
int XSCREEN = 263;
int YSCREEN = 193;
color_t c_array[16] = {
_BLACK, _BLUE, _GREEN, _CYAN, _RED, _MAGENTA, _BROWN,
_WHITE, _GRAY, _LIGHTBLUE, _LIGHTGREEN, _LIGHTCYAN,
_LIGHTRED, _LIGHTMAGENTA, _YELLOW, _BRIGHTWHITE};
color_t c_array3[16] = {
_BLACK, _BLUE, _GREEN, _CYAN, _RED, _MAGENTA, _BROWN,
_WHITE, _GRAY, _LIGHTBLUE, _LIGHTGREEN, _LIGHTCYAN,
_LIGHTRED, _LIGHTMAGENTA, _YELLOW, _BRIGHTWHITE};
/* The following variables are global to the program. The reasons for
these are mainly because of memory management on the IBM PC, and
ease of use in many functions which depend on the same memory areas.*/
char temp[80];
pixtype MX = mx, MY = my;
int normal; /// linestyle default
int menu_box[5][2];
char _far image[3000];/// array for _getimage() & _putimage()
char _far randbox[1200];
char _far msgbox[50000];
char _far charbox[3000];
short size = 5;
char ipick = 1;
boolean fill_on = FALSE;
short bshape = 1, bsize = 10;
struct videoconfig vc; /* Since I change logical origin,
video configuration & palette values
in many different functions, the
new values must be determined almost
constantly. Making this struct global
facillitates writing code. */
boolean clearscreen = FALSE;
boolean soundon = FALSE;
boolean warp_on = FALSE;
boolean mirror_on = TRUE;
boolean scroll_flag = TRUE;
unsigned char pick[5][8];
short oldcolor = 1, border = 15;
extern int r, g, b;
boolean c_used[16];
mtype = 1;
unsigned long imagesize;
short font1 = TRMN;
short color = 12;
short newcolor, c;
main()
{
pixtype x, t;
pixtype x1, x2, y1, y2, oldx1, oldx2, oldy1, oldy2;
boolean esc_flag = FALSE;
char temp[90];
mouse_t lb, rb, h, v, oldh = 0, oldv = 0;
struct _fontinfo fi;
int type = 1, oldtype = 1, pixtemp;
int xtextpos;
if ( UNABLETO _setvideomode( _MAXRESMODE ) )
{
_outtext(" This program requires at least VGA video capabilities. Sorry");
exit(1);
}
else
{
_outtext(" VGA card detected.\n ");
_getvideoconfig( &vc );
}
if ( NOT regfonts2() )
{
_settextcolor(12);
_outtext(" \n Sorry, unable to register character font files.\n\
Try \\QC25\\BIN or \\WINDOWS\\SYSTEM if they are installed\n\
on your computer. Otherwise the *.FON files should be in\n\
the directory where you are running this program from.");
getch();
exit( 1 );
}
else
{
_outtext("Font information registered.\n");
_getfontinfo( &fi );
set_font( TRMN, 8 );
}
if ( UNABLETO reset_mouse() )
{
_outtext(" This program requires a two-button MS compatible mouse. Sorry.");
_setvideomode( _DEFAULTMODE );
exit(1);
}
else
_outtext("Two-button mouse detected.");
/* Seed the random number generator with the current time and set color
values so the program won't repeat the same starting colors. */
srand( (unsigned)time( NULL ) );
r = rand() % 64 + 1;
g = rand() % 64 + 1;
b = rand() % 64 + 1;
/* imagesize = _imagesize( X1 ,Y1 ,X2 ,Y2 );
sprintf( temp, "\nImage size of screen in Bytes = %u\nHit a Key", imagesize);
_outtext( temp );
getch(); */
normal = _getlinestyle();
for ( t = 0; t <= 15; t++)
c_used[t] = FALSE;
note( 660, 3 );
_clearscreen( _GCLEARSCREEN );
mouse_adjust();
/// mouse_setgcurs( &gcursor_hand );
_setcolor(15);
draw_screen();
_setcolor( 12 );
set_font( TRMN, 8 );
scroll_intro();
set_cad_logorg();
mouse_show();
_setcolor( 9 );
font_menu();
_setlogorg( MX, MY );
while ( NOT esc_flag )
{
loop_flag:
oldtype = type;
oldh = h;
oldv = v;
mouse_status(&lb, &rb, &h, &v );
if ( (oldh NE h) OR (oldv NE v) )
{
sprintf( temp, "(%d, %d)", h - MX, -(v - MY) );
_settextcolor(9);
_settextposition(vc.numtextrows - 1, 22 );
_outtext(" ");
_settextposition(vc.numtextrows - 1, 22 );
_outtext( temp );
if ( h >= X1 AND v >= 50)
mouse_show();
}
if ( kbhit() )
type = select_style( type );
oldtype = type;
if ((lb) AND ( h >= X1 ) AND ( v >= Y1 ) AND ( inXscreen( h, v ) ) )
{
if (soundon)
{
oldcolor = _getcolor();
note( (oldcolor * 200) + rand() % 2000 , 1);
}
/* Determine if any of the coordinates are out of the drawing
area. If they are, reset them to outer limit of any edges before
drawing the shape. */
set_cad_logorg();
mouse_hide();
if (clearscreen)
{
_setlogorg(0,0);
_getvideoconfig(&vc);
oldcolor = _getcolor();
_setcolor(0);
_rectangle(_GFILLINTERIOR, X1, Y1, X2, Y2 );
if (oldcolor == 0)
oldcolor = rand() % 15 + 1;
_setcolor( oldcolor );
set_cad_logorg();
}
else
{
x1 = h - MX;
y1 = v - MY;
x2 = -h + MX;
y2 = -v + MY;
if ( x1 <= -XSCREEN )
x1 = -XSCREEN + 1;
if ( y1 <= -YSCREEN )
y1 = -YSCREEN;
if ( y2 >= YSCREEN )
y2 = YSCREEN + 1;
if ( x2 >= XSCREEN )
x2 = XSCREEN - 1;
if ( x1 >= XSCREEN )
x1 = XSCREEN - 1;
if ( y1 >= YSCREEN )
y1 = YSCREEN;
if ( y2 <= -YSCREEN )
y2 = YSCREEN + 1;
if ( x2 <= -XSCREEN )
x2 = -XSCREEN + 1;
set_cad_logorg();
c_used[ _getcolor() ] = TRUE;
switch (type)
{
case 2:
_ellipse(_GBORDER, x1, y1, x2, y2);
break;
case 100:
if (mtype)
type = remap_screen(x1,y1,x2,y2, mtype );
type = oldtype;
break;
case 1:
_rectangle( _GBORDER, x1, y1, x2, y2);
break;
case 4:
if (fill_on)
_setfillmask( pick[ ipick ] );
_ellipse( _GFILLINTERIOR, x1, y1, x2, y2);
if (fill_on)
_setfillmask(NULL);
break;
case 5:
if (fill_on)
_setfillmask( pick[ ipick ] );
_rectangle( _GFILLINTERIOR, x1, y1, x2, y2);
if (fill_on)
_setfillmask(NULL );
break;
case 99 :
_setcolor(newcolor);
if (fill_on)
_setfillmask( pick[ ipick ] );
_floodfill( x1, y1, border);
if (fill_on)
_setfillmask( NULL );
type = oldtype;
break;
case 8:
draw_chars(h, v);
break;
case 666 :
draw_arc(1);
lb = FALSE;
break;
case 667 :
draw_arc(2);
lb = FALSE;
break;
case 6:
_moveto( x1, y1);
_lineto( 0, 0 );
if (mirror_on)
{
_moveto( -x1, y1);
_lineto( 0, 0 );
_moveto( x1, -y1);
_lineto( 0, 0 );
_moveto( -x1, -y1);
_lineto( 0, 0 );
if (x1 < -197 )
x1 = -197;
if (x2 > 197 )
x2 = 197;
if (x2 < -197 )
x2 = -197;
if (x1 > 197 )
x1 = 197;
_moveto( y1, x1);
_lineto( 0, 0 );
_moveto( -y1, x1);
_lineto( 0, 0 );
_moveto( y1, -x1);
_lineto( 0, 0 );
_moveto( -y1, -x1);
_lineto( 0, 0 );
}
break;
case 25:
draw_paint2(x1, y1, bshape );
break;
case 111 :
sqx( x1, y1 );
break;
default:
break;
}
}
mouse_show();
mouse_condoff( 10, 50, X1 - 10, Y2 );
}
if ( ( type == 11 ) AND ( h >= X1 ) AND ( v >= Y1 ))
{
MX = h;
MY = v;
reset_vanish_pt( h, v );
}
if ( lb AND v > Y2 )
{
_setlogorg(0,0);
newcolor = getcolor(h);
if ( newcolor )
_setcolor( newcolor );
}
else
if ( rb AND v > Y2 )
{
_setlogorg(0,0);
border = getbordercolor();
_setlogorg(0,0);
_setlinestyle(normal);
_rectangle( _GBORDER, X1, Y1, X2, Y2 );
_setcolor(newcolor);
set_cad_logorg();
}
if ( rb AND inXscreen( h, v ) )
reset_vanish_pt( h, v );
if ( (rb OR lb) AND ( h < X1 ) AND ( v < 300 ) )
type = get_shape( h,v );
if ( (lb OR rb) AND ( v < 34 ) AND ( h > 115) )
get_font_info(h, v);
if ( lb AND (v < 34) AND (h > 15) AND (h < 115) )
get_fillmask();
if ( type EQ 3 )
{
esc_flag = quit_prompt(oldtype);
type = oldtype;
}
}
_unregisterfonts();
_setvideomode( _DEFAULTMODE );
}
void draw_screen( void )
/* This function draws the basic outline of the "work area" screen. */
{
pixtype x, y; /// x & y pixels available in current video mode.
color_t color;
struct videoconfig vc; /// Video Configuration info.(_MAXRESMODE) only
pixtype mx1, my1; /* midpoints of the outside of the
rectangle included in the drawing area. */
int linestyle = _getlinestyle();
_getvideoconfig( &vc );
x = vc.numxpixels;
y = vc.numypixels;
_rectangle( _GBORDER, 0, 0, x - 1, y - 1 );
_rectangle( _GBORDER, 8, 8, x - 8, 40 ) ; /// 1
_rectangle( _GBORDER, (pixtype) (x / 6), 45, x - 8, y - 40 ) ; /// 2
_rectangle( _GBORDER, (pixtype) (x / 6), y - 35, x - 8, y - 8 ); /// 3
_rectangle( _GBORDER, 8, 45, (pixtype) (x / 6) - 8 , y - 8 ); /// 4
draw_menu();
/* _setcolor(4);
_rectangle( _GFILLINTERIOR, 10, 50, X1 - 10, 110 );
_rectangle( _GFILLINTERIOR, 10, 115, X1 - 10, 175 );
_setcolor(12);
_rectangle( _GBORDER, 10, 50, X1 - 10, 110 );
_rectangle( _GBORDER, 10, 115, X1 - 10, 175 );
_setcolor( 15 );
_rectangle( _GBORDER, 30, 70, X1 - 30, 90 );
_ellipse( _GBORDER, 30, 130, X1 - 30, 155 ); */
mx1 = (X2 + X1) / 2;
my1 = (Y2 + Y1) / 2;
_setcolor( 12 );
_setlinestyle( 1);
_moveto( mx1, Y1 );
_lineto( mx1, Y2 );
_moveto( X1, my1 );
_lineto( X2, my1 );
_setlinestyle( linestyle );
}
void mouse_adjust( void )
{
mouse_sethorz( 10, X2 );
mouse_setvert( 10, vc.numypixels - 10 );
mouse_setpos( (X1 + X2) / 2, (Y1 + Y2) / 2 );
// mouse_condoff( 10, 50, X1 - 10, Y2 );
mouse_setsensitivity( 70, 70, 70 );
}
void set_cad_logorg( void )
{
/* pixtype mx1 = (X1 + X2) / 2;
pixtype my1 = (Y1 + Y2) / 2; */
_setlogorg( MX, MY );
_getvideoconfig( &vc );
}
int select_style( int type1 )
{
int oldstyle = type1;
unsigned key;
int type = type1, t;
unsigned short linestyle = _getlinestyle();
short c = _getcolor();
key = getkey();
switch ( key )
{
case 'l' :
_setlinestyle( normal );
break;
case 'h' :
case 'H' :
case KEY_F1 :
helpbox();
break;
case 'p' : /// Single pixels
type = 25;
break;
case 'g' :
type = 7;
break;
case KEY_HOME :
fonttype();
break;
case 'r' :
type = 1; /// rectangle
break;
case 'f' :
oldcolor = _getcolor();
type = 99;
break;
case 'e' :
type = 2; /// ellipse
break;
case 'E' :
type = 4; /// solid ellipse
break;
case 'R' :
type = 5; /// solid rectangle
break;
case 'L' :
type = 6;
break;
case 'x' : fonttype();
break;
case KEY_LEFT :
if ( linestyle > 0 )
_setlinestyle( linestyle -= 3 );
break;
case KEY_RIGHT :
_setlinestyle( linestyle += 3);
break;
case KEY_ESCAPE :
type = 3; /// Bag Out
break;
case KEY_DELETE: /// clear drawing box
for ( t = 0; t <= 15; t++)
c_used[t] = FALSE;
draw_grid();
set_cad_logorg();
mouse_setpos(mx,my);
MX = mx;
MY = my;
mouse_show();
break;
case KEY_F3 :
scroll_flag = !scroll_flag;
break;
case KEY_F2 :
_setlogorg(0,0);
scroll_intro();
set_cad_logorg();
break;
case KEY_F4 :
remap_std_palette();
break;
case KEY_F5 :
cycle_palette();
break;
case KEY_F9 :
clearscreen = NOT clearscreen;
break;
case KEY_F8 :
soundon = NOT soundon;
break;
case KEY_F6 :
mirror_on = NOT mirror_on;
break;
case KEY_ALT_F2 :
mtype = getmaptype();
type = 100;
break;
case KEY_ALT_F4 :
_setfillmask( pick[ ipick ] );
break;
case KEY_ALT_F5 :
_setfillmask( NULL );
break;
case KEY_ALT_F6 :
fill_on = NOT fill_on;
break;
case KEY_ALT_F1 :
mouse_hide();
get_fillmask();
break;
case KEY_ALT_F3 :
remap_color( newcolor );
break;
case KEY_ALT_F8 :
type = 111;
break;
case KEY_ALT_F10 :
bshape = get_brush_shape(bshape);
break;
case KEY_ALT_F9:
cycle3();
break;
case KEY_CTRL_F2 :
///draw_arc();
type = 666;
break;
case KEY_CTRL_F3 :
///draw_arc();
type = 667;
break;
default :
warble(1);
break;
}
update_shapebox( type );
_setcolor( c );
return( type );
}
void draw_grid( void )
{
pixtype mx1 = (X2 + X1) / 2;
pixtype my1 = (Y2 + Y1) / 2;
int linestyle = _getlinestyle();
pixtype nx = ( int ) ( X2 - X1 ) / 8;
pixtype ny = ( int ) ( Y2 - Y1 ) / 8;
pixtype xpos, ypos;
pixtype i, j;
short c = _getcolor();
mouse_hide();
_setlogorg(0, 0);
mouse_setpos(mx1, my1);
_setcolor( 0 );
_rectangle( _GFILLINTERIOR, X1, Y1, X2, Y2 );
_setcolor( border );
_setlinestyle(normal);
_rectangle( _GBORDER, X1, Y1, X2, Y2 );
_setcolor( 12 );
_setlinestyle( 1 );
_moveto( mx1, Y1 );
_lineto( mx1, Y2 );
_moveto( X1, my1 );
_lineto( X2, my1 );
_setlinestyle( linestyle );
set_cad_logorg();
/// mouse_setpos(mx1, my1);
_setcolor( c );
mouse_show();
mouse_condoff( 10, 50, X1 - 10, Y2 );
}
void draw_menu( void )
{
short color = 0, c = _getcolor();
int x = 15, y = 265; /// x & y virtual screen positions
pixtype yrand, xrand;
short i; /// index counter
_setlogorg( 0, 0 );
_setcolor(8);
_rectangle( _GFILLINTERIOR, 10, 50, 53, 93 );
_rectangle( _GFILLINTERIOR, 56, 50, X1 - 10, 93 );
_rectangle( _GFILLINTERIOR, 10, 98, 53, 141 );
_rectangle( _GFILLINTERIOR, 56, 98, X1 - 10, 141 );
_rectangle( _GFILLINTERIOR, 10, 146, 53, 189 );
_rectangle( _GFILLINTERIOR, 56, 146, X1 - 10, 189 );
_rectangle( _GFILLINTERIOR, 10, 194, 53, 237 );
_rectangle( _GFILLINTERIOR, 56, 194, X1 - 10, 237 );
_setcolor(7);
_rectangle( _GBORDER, 10, 50, 53, 93 );
_rectangle( _GBORDER, 56, 50, X1 - 10, 93 );
_rectangle( _GBORDER, 10, 98, 53, 141 );
_rectangle( _GBORDER, 56, 98, X1 - 10, 141 );
_rectangle( _GBORDER, 10, 146, 53, 189 );
_rectangle( _GBORDER, 56, 146, X1 - 10, 189 );
_rectangle( _GBORDER, 10, 194, 53, 237 );
_rectangle( _GBORDER, 56, 194, X1 - 10, 237 );
_setcolor( 15 );
_rectangle( _GBORDER, 20, 60, 43, 83 ); /// square box
_ellipse( _GBORDER, 66, 60, X1 - 20, 83 ); /// circle box
_moveto( 15, 103 ); /// line box
_lineto( 48, 136 );
_moveto( 64, 106 ); /// Character box
set_font( TRMN, 8 );
_outgtext("A");
_setcolor( c );
_rectangle( _GFILLINTERIOR, 20, 156, 43, 179 ); /// Solid rectangle
_ellipse(_GFILLINTERIOR, 66, 156, X1 - 20, 179 ); /// Solid ellipse
_setcolor( 15 ); /// Quit flag
set_font( TRMN, 5 );
_moveto( 10, 205 );
_outgtext("Quit");
/// Single pixels
for (i = 1; i < 50; i++ )
{
xrand = rand() % 33 + 60;
yrand = rand() % 33 + 201;
///note( xrand, 1 );
_setpixel( xrand, yrand );
}
_getimage(54, 194, X1 - 10, 237, randbox );
draw_1stbox();
/// _rectangle( _GBORDER, (pixtype) (x / 6), y - 35, x - 8, y - 8 );
x = 275 ;
y = vc.numypixels - 31;
/* Create the color bars */
for (color = 0; color <= 15; color++ )
{
_setcolor( color );
_moveto( x, y );
if ( color EQ 0 )
{
_setcolor( 15 );
_rectangle( _GBORDER, x - 1, y - 1, x + 20, y + 20 );
}
else
_rectangle( _GFILLINTERIOR, x, y, x + 19, y + 19 );
x += 22;
}
_setcolor( 1 );
_rectangle( _GFILLINTERIOR, X1 + SIZE + 12, vc.numypixels - 31,\
X1 + SIZE + SIZE + 10, vc.numypixels - 11);
_rectangle( _GFILLINTERIOR, X1 + 5, vc.numypixels - 31, X1 + SIZE + 5, \
vc.numypixels - 11);
}
void scroll_intro(void)
{
int i, x = 10, newx = 11, stop, len;
unsigned long color = 1, newcolor = 1;
int type = 1;
int randindx = 1;
_setlogorg(0,0);
_getvideoconfig( &vc );
stop = vc.numxpixels / 2 - 45;
_setcolor(0);
_rectangle( _GFILLINTERIOR, 8, 8, vc.numxpixels - 8, 40 ) ; /// 1
_setcolor(15);
_rectangle( _GBORDER, 8, 8, vc.numxpixels - 8, 40 ) ; /// 1
_setcolor( 1 );
set_font( TRMN, 6 );
len = _getgtextextent(" Vanishing Point");
_moveto( 10 , 12 );
_outgtext(" Vanishing Point");
///remap2(10, 12, len + 10, fi.pixheight + 12, 1 );
_getimage( 10, 12, \
10 + _getgtextextent(" Vanishing Point"), \
12 + fi.pixheight, image);
while ( NOT kbhit())
{
if (newcolor == vc.numcolors)
newcolor = 1;
else
++newcolor;
for ( x = 10; x <= (vc.numxpixels - len - 18); x+= 5 )
{
_putimage( x, 12, image, _GPSET );
_putimage( newx, 12, image, _GXOR );
newx += 5;
color = get_color( &type, &r, &g, &b );
_remappalette((short)newcolor, color );
///(long)c_array[newcolor] );
c_array[newcolor] = color;
if (scroll_flag)
_remappalette(1, color );
if ( kbhit() )
break;
}
_setcolor(0);
_rectangle( _GFILLINTERIOR, 8, 8, vc.numxpixels - 8, 40 ) ; /// 1
_setcolor(15);
_rectangle( _GBORDER, 8, 8, vc.numxpixels - 8, 40 ) ; /// 1
_moveto( vc.numxpixels / 2 - 65 , 12 );
_putimage( stop, 12, image, _GPSET );
}
remap_std_palette();
font_menu(); /*****/
set_cad_logorg();
}
int getcolor( pixtype h)
/* Returns the palette number of a color selected from the color menu at the
bottom of the screen. Activated when the left mouse button is pressed in
the area over the color palette. */
{
short c;
_setlogorg(0,0);
c = (short) (h - CX) / SIZE ;
_setcolor( c );
_rectangle( _GFILLINTERIOR, X1 + 5, vc.numypixels - 31, X1 + SIZE + 5, \
vc.numypixels - 11);
if ( c EQ 8 ) ///Gray Background case
{
_setcolor( 8 );
_rectangle( _GFILLINTERIOR, 20, 156, 43, 179 ); /// Solid rectangle
_ellipse(_GFILLINTERIOR, 66, 156, X1 - 20, 179 ); /// Solid ellipse
_setcolor(15);
_rectangle( _GBORDER, 20, 156, 43, 179 ); /// Solid rectangle
_ellipse(_GBORDER, 66, 156, X1 - 20, 179 ); /// Solid ellipse
}
else
{
_rectangle( _GFILLINTERIOR, 20, 156, 43, 179 ); /// Solid rectangle
_ellipse(_GFILLINTERIOR, 66, 156, X1 - 20, 179 ); /// Solid ellipse
}
///set_cad_logorg();
return( (h - CX) / SIZE );
}
short getbordercolor(void)
{
mouse_t lb, rb, h, v;
short c;
mouse_status(&lb, &rb, &h, &v );
c = (short) (h - CX) / SIZE ;
_setcolor( c );
_rectangle( _GFILLINTERIOR, X1 + SIZE + 12, vc.numypixels - 31,\
X1 + SIZE + SIZE + 10, vc.numypixels - 11);
set_cad_logorg();
return( (h - CX) / SIZE );
}
void remap_std_palette(void)
{
/*_remappalette(0, _BLACK);
_remappalette(1, _BLUE);
_remappalette(2, _GREEN);
_remappalette(3, _CYAN);
_remappalette(4, _RED);
_remappalette(5, _MAGENTA);
_remappalette(6, _BROWN);
_remappalette(7, _WHITE);
_remappalette(8, _GRAY);
_remappalette(9, _LIGHTBLUE);
_remappalette(10, _LIGHTGREEN);
_remappalette(11, _LIGHTCYAN);
_remappalette(12, _LIGHTRED);
_remappalette(13, _LIGHTMAGENTA);
_remappalette(14, _YELLOW);
_remappalette(15, _BRIGHTWHITE);
*/
_remapallpalette( c_array3 );
}
void cycle_palette(void)
{
unsigned long color;
color_t newcolor = 1;
boolean esc_flag = FALSE;
short r = 20, g = 30, b = 40, type = 1;
int i;
while (NOT esc_flag)
{
for ( i = 1; i <= 5; i++ )
{
///break_color( c_array[ i ], &r, &g, &b );
color = get_color( &type, &r, &g, &b );
_remappalette((short)newcolor, color);
if ( kbhit() )
{
esc_flag = TRUE;
break;
}
}
if (newcolor == vc.numcolors)
newcolor = 1;
else
++newcolor;
if ( kbhit() )
esc_flag = TRUE;
}
}
void reset_vanish_pt(pixtype x, pixtype y)
{
short c = _getcolor();
mouse_hide();
note(x * y, 1);
_setlogorg(0,0);
/* _getimage( X1 + 50, Y1 + 50, X2 - 50, Y2 - 50, screen);
_setcolor(0);
_rectangle(_GFILLINTERIOR, X1, Y1, X2, Y2 );
_putimage( X1 + 50, Y1 + 50, screen, _GXOR); */
_setcolor(12);
_setlinestyle(1);
_moveto( x, Y1 );
_lineto( x, Y2 );
_moveto( X1, y );
_lineto( X2, y );
_setlinestyle(normal);
_setlogorg(x, y);
_getvideoconfig( &vc );
MX = x;
MY = y;
_setcolor( c );
mouse_show();
}
boolean inXscreen( pixtype h, pixtype v )
{
_setlogorg(0,0);
if ( ( h <= X1 ) OR ( h >= X2) OR \
( v <= Y1 ) OR ( v >= Y2 ) )
{
set_cad_logorg();
return( FALSE );
}
else
{
set_cad_logorg();
return( TRUE );
}
}
int get_shape( pixtype h, pixtype v )
{
int type = -1;
pixtype ypos, xpos;
short c = _getcolor();
_getvideoconfig(&vc);
ypos = vc.numypixels - 12;
xpos = 12;
if ( h > 10 AND v > 50 AND h < 53 AND v < 93 )
type = 1; /// rectangle
if ( h > 56 AND v > 50 AND h < (X1 - 10) AND v < 93 )
type = 2; /// ellipse
if ( h > 10 AND v > 98 AND h < 53 AND v < 142 )
type = 6; /// line
if ( h > 56 AND v > 98 AND h < ( X1 - 10 ) AND v < 142 )
type = 8; /// Character
if ( h > 10 AND v > 146 AND h < 53 AND v < 189 )
type = 5; /// Solid rectangle
if ( h > 56 AND v > 146 AND h < ( X1 - 10) AND v < 189 )
type = 4; /// Solid ellipse
if ( h > 10 AND v > 194 AND h < 53 AND v < 237 )
type = 3; /// Quit flag
if ( h > 56 AND v > 194 AND h < (X1 - 10) AND v < 237 )
type = 25; /// Single pixels
update_shapebox(type);
_setcolor( c );
return( type );
}
void draw_1stbox(void)
{
pixtype xpos, ypos;
short c = _getcolor();
ypos = vc.numypixels - 12;
xpos = 12;
_setlogorg( 0, 0 );
_setcolor(8);
_rectangle(_GFILLINTERIOR, xpos, ypos - 43, xpos + 43, ypos );
_setcolor( 7 );
_rectangle(_GBORDER, xpos, ypos - 43, xpos + 43, ypos );
_setcolor(15);
_rectangle( _GBORDER, xpos + 5, ypos - 38, xpos + 38, ypos - 5 );
_setcolor( c );
}
boolean quit_prompt(short type )
{
unsigned long key;
_setlogorg(0,0);
_getvideoconfig(&vc);
_setfillmask( NULL );
mouse_hide();
_getimage( 200, 200, 600, 250, msgbox );
_setcolor(7);
_rectangle( _GFILLINTERIOR, 200, 200, 600, 250 );
_setcolor(15);
_rectangle( _GBORDER, 205, 205, 595, 245 );
set_font( TRMN, 5 );
_setcolor( 1 );
_moveto( 215, 215 );
_outgtext("You Loathsome Wretch. Press Y or N");
update_shapebox( 3 );
while ( 1 )
{
key = getch();
if ( key EQ 'y' OR key EQ 'Y' )
{
_setbkcolor(_WHITE);
siren(2);
return( TRUE );
}
if ( key EQ 'n' OR key EQ 'N' )
{
_putimage( 200, 200, msgbox, _GPSET );
update_shapebox( type );
mouse_show();
return( FALSE );
}
warble(1);
}
}
void helpbox(void)
{
short c = _getcolor();
short row = 12, col = 22;
unsigned long key;
boolean done = FALSE;
boolean shownext = FALSE;
_setlogorg(0,0);
_getvideoconfig( &vc );
_getimage(150, 70, 355, 400, msgbox );
_setcolor(0);
_rectangle( _GFILLINTERIOR, 150, 70, 355, 400 );
_setcolor(15);
_rectangle( _GBORDER, 150, 70, 355, 400 );
set_font(HELV, 6);
_setcolor(12);
_moveto( 163, 75);
_outgtext("Commands Help");
set_font( TRMN, 8 );
_setcolor( 3 );
_moveto( 205, 125 );
_outgtext( "F Keys");
_settextcolor( 1 );
_settextposition( row++, col);
_outtext("F1: This Help Menu");
_settextposition( row++, col);
_outtext("F2: Scroll Intro");
_settextposition( row++, col);
_outtext("F3: Stop Scroll Colors");
_settextposition( row++, col);
_outtext("F4: Reset Std Colors");
_settextposition( row++, col);
_outtext("F5: Cycle Colors");
_settextposition( row++, col);
_outtext("F6: Mirror On/Off");
_settextposition( row++, col);
_outtext("F7: Warp Shape On/Off");
_settextposition( row++, col);
_outtext("F8: Sound On/Off");
_settextposition( row++, col);
_outtext("F9: Clearscreen On/Off");
_settextposition( row++, col);
_outtext("F10: Clear Area");
set_font( COUR, 4 );
_setcolor(13);
_moveto( 170, 365 );
_outgtext("PGDN");
_moveto(170 + _getgtextextent("PGDN") + 2, 365);
_setcolor(5);
_outgtext(" For More");
_moveto( 170, 380 );
_setcolor( 13 );
_outgtext("END");
_moveto(170 + _getgtextextent("END") + 2, 380);
_setcolor(5);
_outgtext(" To Return");
while( NOT done )
{
key = getkey();
switch ( key )
{
case KEY_PGDN :
shownext = TRUE;
done = TRUE;
break;
case KEY_ESCAPE:
case KEY_END :
done = TRUE;
break;
default :
warble( 1 );
break;
}
}
if ( shownext )
{
_setcolor(0);
_rectangle(_GFILLINTERIOR, 156, 95, 348, 348 );
set_font( TRMN, 6 );
_setcolor(3);
_moveto( 165, 108 );
_outgtext( "Mouse Functions");
row = 10;
col = 21;
_settextcolor( 12 );
_settextposition( row++, col);
_outtext(" Clicking Left Button:");
_settextcolor( 15 );
_settextposition( row++, col);
_outtext("Draws shapes within the");
_settextposition( row++, col);
_outtext("drawing area while");
_settextposition( row++, col);
_outtext("depressed");
_settextcolor( 12 );
_settextposition( row++, col);
_outtext(" Clicking Right Button:");
_settextcolor( 15 );
_settextposition( row++, col);
_outtext("Selects from color pal-");
_settextposition( row++, col);
_outtext("ette the active color.");
_settextposition( row++, col);
_outtext("Selects shapes at left");
_settextposition( row++, col);
_outtext("as the active shape.");
_settextposition( row++, col);
_outtext("Clicking anywhere within");
_settextposition( row++, col);
_outtext("drawing area resets the");
_settextposition( row++, col);
_outtext("Vanishing point to those");
_settextposition( row++, col);
_outtext("screen coordinates.");
}
done = FALSE;
shownext = FALSE;
while( NOT done )
{
key = getkey();
switch ( key )
{
case KEY_PGDN :
case KEY_DOWN :
shownext = TRUE;
done = TRUE;
break;
case KEY_ESCAPE:
case KEY_END :
done = TRUE;
break;
default :
warble( 1 );
break;
}
}
if ( shownext )
{
_setcolor(0);
_rectangle(_GFILLINTERIOR, 156, 95, 350, 395 );
set_font( TRMN, 6 );
_setcolor(3);
_moveto( 155, 108 );
_outgtext( "Keyboard Functions");
row = 11;
col = 22;
_settextposition( row++, col);
_settextcolor(12);
_outtext("r :");
_settextcolor(15);
_outtext(" Lined Rectangle");
_settextposition( row++, col);
_settextcolor(12);
_outtext("R :");
_settextcolor(15);
_outtext(" Filled Rectangle");
_settextposition( row++, col);
_settextcolor(12);
_outtext("e :");
_settextcolor(15);
_outtext(" Lined Ellipse");
_settextposition( row++, col);
_settextcolor(12);
_outtext("E :");
_settextcolor(15);
_outtext(" Solid Ellipse ");
_settextcolor(12);
_settextposition( row++, col);
_outtext("h :");
_settextcolor(15);
_outtext(" This Help Menu");
_settextcolor(12);
_settextposition( row++, col);
_outtext("p :");
_settextcolor(15);
_outtext(" Individual Pixels");
_settextposition( row++, col);
_settextcolor(12);
_outtext("<- :");
_settextcolor(15);
_outtext(" -- Linestyle");
_settextposition( row++, col);
_settextcolor(12);
_outtext("-> :");
_settextcolor(15);
_outtext(" ++ Linestyle ");
_settextposition( row++, col);
_settextcolor(12);
_outtext("L :");
_settextcolor(15);
_outtext(" Reset Linestyle");
_settextcolor(12);
_settextposition( row++, col);
_outtext("ESC:");
_settextcolor(15);
_outtext(" Exit Program");
_settextcolor(12);
_settextposition( row++, col);
_outtext("DEL:");
_settextcolor(15);
_outtext(" Clear Box ");
set_font( TRMN, 6 );
_setcolor(1);
_moveto( 180, 355);
_outgtext("Press A Key");
getch();
}
_putimage(150, 70, msgbox, _GPSET );
hfree( msgbox );
_setcolor( c );
}
short getmaptype( void )
{
unsigned long key;
boolean done = FALSE;
pixtype x1, y1, x2, y2;
short maptype;
x1 = y1 = 180;
x2 = 600;
y2 = 300;
_setlogorg(0,0);
_setbkcolor(0);
mouse_hide();
_getimage( x1, y1, x2, y2, msgbox);
_setcolor(0);
_rectangle(_GFILLINTERIOR, x1, y1, x2, y2);
_setcolor(1);
_rectangle(_GBORDER, x1, y1, x2, y2);
_setcolor(9);
_rectangle(_GBORDER, x1 + 5, y1 + 5, x2 - 5, y2 - 5);
_settextposition(14, 26);
_settextcolor(12);
_outtext("Enter the type of remapping you want, range 1..4");
_settextposition(16,26);
_settextcolor(1);
_outtext(" Press ESC to Return:");
_settextposition(15,26);
_settextcolor(14);
_outtext(" Select area to remap with left mouse button");
while (NOT done)
{
done = TRUE;
key = getkey();
switch (key)
{
case '1':
maptype = 1;
break;
case '2':
maptype = 2;
break;
case '3':
maptype = 3;
break;
case '4':
maptype = 4;
break;
case KEY_ESCAPE :
maptype = -1;
break;
default :
done = FALSE;
warble(1);
break;
}
}
_putimage( x1, y1, msgbox, _GPSET);
hfree(msgbox);
set_cad_logorg();
if ( fill_on )
_setfillmask( pick[ipick] );
mouse_show();
return( maptype );
}
int remap_screen( short x1, short y1, short x2, short y2, short type )
{
if ( type )
remap2( x1, y1, x2, y2, type );
return(1);
}
boolean draw_chars( pixtype x, pixtype y )
{
char str[90];
short slen, sht; /// Length of string and grapics char height;
short i, pos = 0; /// index & current str pos
char c;
unsigned long key;
boolean done = FALSE, move = FALSE;
mouse_t lb, rb, h, v, oldh, oldv;
short c1, oldx = x, oldy = y;
short font;
short col = _getcolor();
_getfontinfo( &fi );
_setlogorg(0,0);
sht = fi.pixheight - 1;
_getimage( x-1, y-1, X2, y + sht, charbox);
str[1] = NULL2 ;
mouse_status( &lb, &rb, &oldh, &oldv );
while ( NOT done )
{
oldx = x;
oldy = y;
mouse_show();
mouse_status( &lb, &rb, &h, &v );
if ( oldh != h OR oldv != v )
{
if (lb OR rb )
{
if ( ( h > X1) AND (v > Y1) AND (h < X2) AND (v < Y2))
{
x = h;
y = v;
_setcolor(0);
_setpixel( oldx, oldy );
_setpixel( oldx+1, oldy );
_setpixel( oldx, oldy+1 );
_setpixel( oldx-1, oldy );
_setpixel( oldx, oldy-1 );
pos = 0;
str[1] = '\0';
mouse_hide();
_getimage( x-1, y-1, X2, y + sht, charbox);
_setcolor( col );
_setpixel( x, y );
_setpixel( x+1, y );
_setpixel( x, y+1 );
_setpixel( x-1, y );
_setpixel( x, y-1 );
mouse_show();
}
else
if ( (v < Y1) AND ( h > 20 ) )
get_font_info( h, v );
else
if ( lb AND v > Y2 )
{
col = getcolor(h);
if ( col >= 0 )
_setcolor( col );
_setlogorg(0,0);
}
else
if ( rb AND v > Y2 )
{
border = getbordercolor();
_setlogorg(0,0);
}
}
}
if ( kbhit() )
{
mouse_hide();
key = getkey();
switch (key)
{
case KEY_LEFT :
x -= 5;
move = TRUE;
break;
case KEY_RIGHT:
x += 5;
move = TRUE;
break;
case KEY_UP :
y -= 5;
move = TRUE;
break;
case KEY_DOWN :
y += 5;
move = TRUE;
break;
case KEY_ESCAPE:
done = TRUE;
break;
default :
break;
}
if ( move )
{
mouse_hide();
_putimage( oldx-1, oldy-1, charbox, _GPSET );
_moveto( oldx, oldy );
_outgtext( str );
_getimage( x-1, y-1, X2, y + sht, charbox);
str[0] = '\0';
pos = 0;
move = FALSE;
}
else
{
mouse_show();
str[pos] = key;
if ( key EQ KEY_BACKSPACE OR key EQ KEY_DELETE)
{
str[pos + 2] = '\0';
if ( pos >= 1 )
{
str[pos +1] = ' ';
pos -= 2;
}
}
str[pos + 1] = NULL2;
slen = _getgtextextent(str);
mouse_hide();
_putimage( x-1, y-1, charbox, _GPSET );
_moveto( x, y );
_outgtext( str );
pos += 1;
if ( key EQ KEY_ENTER )
{
pos = 0;
str[1] = '\0';
y+= sht + 2;
_getimage( x-1, y-1, X2 , y + sht, charbox);
}
}
}
}
_setgtextvector(1,0);
}
short font_menu( void )
{
pixtype x1, y1, x2, y2;
short oldc = _getcolor();
_setlogorg(0,0);
_getvideoconfig(&vc);
mouse_hide();
_setgtextvector(1,0);
_setcolor(0);
_rectangle(_GFILLINTERIOR, 10, 10, 600, 36);
set_font( HELV, 5);
x1 = 125;
y1 = 11;
x2 = 225;
y2 = 35;
_setcolor(7);
_rectangle(_GFILLINTERIOR, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1+ 2, y1+2, x2- 2, y2 - 2);
_moveto( x1 + 26, y1 + 3);
_setcolor(0);
_outgtext("Fonts");
x1 = 235;
x2 = 335;
_setcolor(7);
_rectangle(_GFILLINTERIOR, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1+ 2, y1+2, x2- 2, y2 - 2);
_moveto( x1 + 29, y1 + 3);
_setcolor(0);
_outgtext("Sizes");
x1 = 345;
x2 = 445;
_setcolor(7);
_rectangle(_GFILLINTERIOR, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1+ 2, y1+2, x2- 2, y2 - 2);
_moveto( x1 + 20, y1 + 3);
_setcolor(0);
_outgtext("Vectors");
x1 = 455;
x2 = 555;
_setcolor(7);
_rectangle(_GFILLINTERIOR, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1+ 2, y1+2, x2- 2, y2 - 2);
_moveto( x1 + 23, y1 + 3);
_setcolor(0);
_outgtext("Colors");
x1 = 15;
x2 = 115;
_setcolor(7);
_rectangle(_GFILLINTERIOR, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1, y1, x2, y2);
_setcolor(15);
_rectangle(_GBORDER, x1+ 2, y1+2, x2- 2, y2 - 2);
_moveto( x1 + 17, y1 + 3);
_setcolor(0);
_outgtext("Patterns");
_setcolor(oldc);
mouse_show();
return(1);
}
short fonttype( void )
{
pixtype p1, p2, q1, q2, porg, qorg;
unsigned long key;
boolean nochoice = FALSE;
short f = 1;
_setlogorg(0,0);
_getvideoconfig(&vc);
mouse_hide();
_setgtextvector(1,0);
p1 = porg = 125;
q1 = qorg = 45;
p2 = 325;
q2 = 350;
_getimage( p1, q1, p2, q2, msgbox );
_setcolor( 7 );
_rectangle(_GFILLINTERIOR, p1, q1, p2, q2);
_setcolor(15);
_rectangle(_GBORDER, p1, q1, p2, q2);
_setcolor(12);
_rectangle(_GBORDER, p1+ 2, q1 + 2, p2 - 2, q2 - 2);
set_font( TRMN, 8 );
_setcolor( 0 );
_moveto( p1 + 15, q1 + 15 );
_outgtext("Select A Font");
_setcolor( 8 );
_moveto( p1 + 14, q1 + 14);
_outgtext("Select A Font");
q1 += 40;
set_font( COUR, 10 );
_setcolor( 1 );
_moveto( p1 + 50, q1 + 15 );
_outgtext("Courier");
set_font( HELV, 7 );
_moveto( p1 + 20, q1 += (3 + fi.pixheight) );
_outgtext("Helevatica");
set_font( TRMN, 7 );
_moveto( p1 + 10, q1 += (3 + fi.pixheight) );
_outgtext("Times Roman");
set_font( MOD, 7 );
_moveto( p1 + 28, q1 += (3 + fi.pixheight) - 10);
_outgtext("Modern");
set_font( SCRP, 10 );
_moveto( p1 + 13, q1 += (3 + fi.pixheight) - 17 );
_outgtext("Script");
set_font( ROM, 8 );
_moveto( p1 + 20, q1 += (3 + fi.pixheight) );
_outgtext("Roman");
_setcolor(0);
_rectangle(_GFILLINTERIOR, p1 + 5, q1 + 45, p2 - 5, q2 - 5 );
_setcolor(11);
_rectangle(_GBORDER, p1 + 5, q1 + 45, p2 - 5, q2 - 5 );
_setcolor(4);
_rectangle(_GBORDER, p1 + 8, q1 + 48, p2 - 8, q2 - 8 );
_settextcolor(1);
_settextposition( 19, 19 );
_outtext("Enter the 1st Letter");
_settextposition( 20, 19 );
_outtext("of the font you want");
_settextposition( 21, 19 );
_outtext(" To Display");
key = getkey();
switch (key)
{
case 'c':
case 'C':
f = COUR;
break;
case 'h':
case 'H':
f = HELV;
break;
case 't':
case 'T':
f = TRMN;
break;
case 'm':
case 'M':
f = MOD;
break;
case 's':
case 'S':
f = SCRP;
break;
case 'r':
case 'R':
f = ROM;
break;
case KEY_ESCAPE:
f = -1;
break;
default :
note(765,1);
break;
}
_putimage( porg, qorg, msgbox, _GPSET);
mouse_show();
hfree(msgbox);
return( f );
}
void get_font_info( pixtype h, pixtype v)
{
short v1 = 0, v2 = 0;
if ( h > 235 AND h < 335)
{
size = get_font_size(size);
set_font( font1, size );
return;
}
else
if ( h > 345 AND h < 445 )
{
get_vector();
return;
}
else
if (h > 125 AND h < 225 )
{
font1 = fonttype();
if ( font1 > -1)
set_font( font1, size );
return;
}
return;
}
short get_font_size(short s)
{
pixtype p1 = 235;
pixtype q1 = Y1 + 5;
pixtype p2 = 485;
pixtype q2 = Y1 + 105;
short col = _getcolor();
short f = font1;
unsigned long key;
boolean done = FALSE;
char str1[20];
_setlogorg(0,0);
mouse_hide();
_getimage(p1, q1, p2, q2, msgbox );
_setcolor(1);
_rectangle(_GFILLINTERIOR, p1 + 1, q1 + 1, p2 - 1, q2 -1);
_setcolor(7);
_rectangle(_GFILLINTERIOR, p1, q1, p2, q2);
_setcolor(8);
_rectangle(_GBORDER, p1+1, q1+1, p2-1, q2-1);
_rectangle(_GBORDER, p1+2, q1+2, p2-2, q2-2);
_setcolor(7);
_rectangle(_GBORDER, p1+3, q1+3, p2-3, q2-3);
_rectangle(_GBORDER, p1+4, q1+4, p2-4, q2-4);
set_font( TRMN, 6 );
_setcolor(0);
_moveto( p1 + 25, q1 + 5 );
_outgtext(" Select Font Size");
_setcolor(15);
_moveto( p1 + 24, q1 + 4 );
_outgtext(" Select Font Size");
_moveto( p1 + 2, q1 + 30 );
_setcolor(1);
_outgtext(" Choose a Size in");
_moveto( p1 + 2, q1 + 45);
_outgtext(" the range 1..9");
_settextcolor(4);
while (NOT done)
{
sprintf( str1, " Current Size: %d", s );
_settextposition(9, 38);
_outtext( str1 );
key = getkey();
switch (key)
{
case '1' : s =1;
break;
case '2' : s =2; break;
case '3' : s =3; break;
case '4' : s =4; break;
case '5' : s =5; break;
case '6' : s =6; break;
case '7' : s =7; break;
case '8' : s =8; break;
case '9' : s =9; break;
case KEY_UP:
if ( s < 9 )
++s;
break;
case KEY_DOWN:
if ( s > 2 )
--s;
break;
case KEY_ESCAPE:
case KEY_ENTER :
done = TRUE;
break;
default : note(500, 1 );
break;
}
}
_putimage(p1, q1, msgbox, _GPSET);
_setcolor( col );
mouse_show();
return(s);
}
void get_fillmask( void )
{
unsigned char mask[8];
///unsigned char pick[5][8];
pixtype p1, q1, p2, q2, r1, s1, r2, s2;
pixtype xpos, ypos, oldx;
pixtype boxsize = 70;
boolean done = FALSE, change = TRUE, null = FALSE;
short col = _getcolor();
short i, j, oldi; /// indexes
unsigned short key;
p1 = X1 + 50;
q1 = Y1 + 100;
p2 = p1 + 400;
q2 = Y1 + 300;
_setlogorg(0,0);
mouse_hide();
_getimage( p1, q1, p2, q2, msgbox );
_setfillmask( NULL );
fill_on = TRUE;
_setcolor(1);
_rectangle(_GFILLINTERIOR, p1 ,q1, p2, q2 );
_setcolor(9);
_rectangle(_GFILLINTERIOR, p1 + 3, q1 + 3, p2 - 3, q2 - 3);
_setcolor(11);
_rectangle(_GFILLINTERIOR, p1 + 6, q1 + 6, p2 - 6, q2 - 6);
r1 = p1 + 15;
r2 = r1 + boxsize;
s1 = q1 + 55 + boxsize;
s2 = s1 + 25;
_setcolor(0);
_rectangle(_GFILLINTERIOR, r1, s1, r2, s2 );
_setcolor(8);
_rectangle(_GFILLINTERIOR, r1 + 3, s1 + 3, r2 - 3, s2 - 3 );
_setcolor(7);
_rectangle(_GFILLINTERIOR, r1 + 6, s1 + 6, r2 - 6, s2 - 6 );
_setcolor(0);
set_font( HELV, 5);
_moveto( r1 + 13, s1 + 3 );
_outgtext("More");
s1 += 35;
s2 += 35;
_setcolor(0);
_rectangle(_GFILLINTERIOR, r1, s1, r2, s2 );
_setcolor(8);
_rectangle(_GFILLINTERIOR, r1 + 3, s1 + 3, r2 - 3, s2 - 3 );
_setcolor(7);
_rectangle(_GFILLINTERIOR, r1 + 6, s1 + 6, r2 - 6, s2 - 6 );
_setcolor(0);
_moveto( r1 + 6, s1 + 3 );
_outgtext("Default");
r1 = r2 + 5;
r2 = r1 + boxsize;
_setcolor(0);
_rectangle(_GFILLINTERIOR, r1, s1, r2, s2 );
_setcolor(8);
_rectangle(_GFILLINTERIOR, r1 + 3, s1 + 3, r2 - 3, s2 - 3 );
_setcolor(7);
_rectangle(_GFILLINTERIOR, r1 + 6, s1 + 6, r2 - 6, s2 - 6 );
_setcolor(0);
_moveto( r1 + 11, s1 + 3 );
_outgtext(" OK");
s1 -= 35;
s2 -= 35;
_setcolor(0);
_rectangle(_GFILLINTERIOR, r1, s1, r2, s2 );
_setcolor(8);
_rectangle(_GFILLINTERIOR, r1 + 3, s1 + 3, r2 - 3, s2 - 3 );
_setcolor(7);
_rectangle(_GFILLINTERIOR, r1 + 6, s1 + 6, r2 - 6, s2 - 6 );
_setcolor(0);
_moveto( r1 + 13, s1 + 3 );
_outgtext("Make");
r1 = r2 + 5;
r2 = r1 + boxsize;
_setcolor(0);
_rectangle(_GFILLINTERIOR, r1, s1, r2, s2 );
_setcolor(8);
_rectangle(_GFILLINTERIOR, r1 + 3, s1 + 3, r2 - 3, s2 - 3 );
_setcolor(7);
_rectangle(_GFILLINTERIOR, r1 + 6, s1 + 6, r2 - 6, s2 - 6 );
_setcolor(0);
_moveto( r1 + 6, s1 + 3 );
_outgtext("Cancel");
s1 += 35;
s2 += 35;
_setcolor(0);
_rectangle(_GFILLINTERIOR, r1, s1, r2, s2 );
_setcolor(8);
_rectangle(_GFILLINTERIOR, r1 + 3, s1 + 3, r2 - 3, s2 - 3 );
_setcolor(7);
_rectangle(_GFILLINTERIOR, r1 + 6, s1 + 6, r2 - 6, s2 - 6 );
_setcolor(0);
_moveto( r1 + 11, s1 + 3 );
_outgtext(" Help");
set_font( TRMN, 8 );
_moveto( p1 + 75, q1 + 15 );
_setcolor(12);
_outgtext("Select A Fill Pattern");
_moveto( p1 + 74, q1 + 14 );
_setcolor(4);
_outgtext("Select A Fill Pattern");
xpos = oldx = p1 + 15;
ypos = q1 + 45;
for ( i = 0; i < 5; i++ )
{
_setcolor(0);
_rectangle(_GFILLINTERIOR, xpos, ypos, xpos + boxsize, ypos + boxsize );
_setcolor(8);
_rectangle(_GFILLINTERIOR, xpos + 3, ypos + 3, xpos + boxsize - 3, ypos + boxsize -3);
_setcolor(col);
for ( j = 0; j < 8; j++ )
mask[j] = pick[i][j] = (unsigned char)rand();
_setfillmask( mask );
_rectangle(_GFILLINTERIOR, xpos + 6, ypos + 6, xpos + boxsize - 6, ypos + boxsize -6);
_setfillmask(NULL);
xpos += boxsize + 5;
}
_setcolor(15);
_rectangle(_GBORDER, oldx, ypos, oldx + boxsize, ypos + boxsize );
_rectangle(_GBORDER ,oldx + 3, ypos + 3, oldx + boxsize - 3, ypos + boxsize - 3 );
i = 0;
mouse_show();
while ( NOT done )
{
key = getkey();
oldi = i;
switch ( key )
{
case KEY_RIGHT :
if ( i < 4 )
++i;
else
i = 0;
break;
case KEY_LEFT :
if ( i >= 1 )
--i;
else
i = 4;
break;
case KEY_ENTER :
done = TRUE;
break;
case KEY_HOME :
null = TRUE;
break;
case KEY_ESCAPE:
_setcolor( col );
fill_on = FALSE;
_putimage(p1, q1, msgbox, _GPSET );
_setfillmask( NULL );
/// mouse_setgcurs( &gcursor_hand );
mouse_show();
return;
default :
note(660, 2);
break;
}
mouse_hide();
_setcolor( 0 );
_setfillmask(NULL);
_rectangle(_GFILLINTERIOR, p2 - 85, q2 - 80, p2 - 85 + boxsize , q2 - 80 + boxsize );
if ( NOT null )
_setfillmask( pick[i] );
else
_setfillmask( NULL );
_setcolor(col);
_rectangle(_GFILLINTERIOR, p2 - 85, q2 - 80, p2 - 85 + boxsize , q2 - 80 + boxsize );
_setcolor(15);
_rectangle(_GBORDER, p2 - 85, q2 - 80, p2 - 85 + boxsize , q2 - 80 + boxsize );
_rectangle(_GBORDER, p2 - 83, q2 - 78, p2 - 87 + boxsize , q2 - 82 + boxsize );
null = FALSE;
ipick = i;
oldi = xpos ;
xpos = p1 + 15 + ( i * ( boxsize + 5) - 1) ;
if ( NOT done )
{
_setcolor(15);
_rectangle(_GBORDER, xpos, ypos, xpos + boxsize, ypos + boxsize );
_rectangle(_GBORDER, xpos+ 3, ypos + 3, xpos + boxsize - 3, ypos + boxsize -3);
xpos = p1 + 15 + ( ( i ) * ( boxsize + 5) );
_setcolor(0);
_rectangle(_GBORDER, oldi, ypos, oldi + boxsize, ypos + boxsize );
_rectangle(_GBORDER, oldi + 3, ypos + 3, oldi + boxsize - 3, ypos + boxsize -3);
oldi = xpos;
}
mouse_show();
}
_setcolor( col );
mouse_hide();
_putimage(p1, q1, msgbox, _GPSET );
_setfillmask( NULL );
/// mouse_setgcurs( &gcursor_hand );
mouse_show();
return;
}
void get_vector(void )
{
pixtype p1, q1, p2, q2;
pixtype vx, vy;
char msg[7] = "Vector";
char xnum[4], ynum[4];
char str[50];
short col = _getcolor();
pixtype xpos, ypos;
boolean done = FALSE;
short xvect = 1, yvect = 0;
short xcol = 53 , ycol = 65, row = 20;
unsigned long key;
pixtype cht; /// Character height
p1 = 300;
q1 = Y1 + 10;
p2 = 600;
q2 = Y1 + 310;
mouse_hide();
_getimage( p1, q1, p2, q2, msgbox );
_setfillmask (NULL);
_setcolor(15);
_rectangle(_GFILLINTERIOR, p1, q1, p2, q2);
_setcolor(0);
_rectangle(_GFILLINTERIOR, p1+2, q1+2, p2-2, q2-2);
_setcolor(8);
_rectangle(_GFILLINTERIOR, p1 + 4, q1+4, p2-4, q2-4);
_setcolor(7);
_rectangle(_GFILLINTERIOR, p1 + 6, q1 + 6, p2 - 6, q2 - 6);
_setgtextvector(1, 0);
_moveto( p1 + 10, q1 + 10 );
_setcolor(0);
set_font( HELV, 7);
_outgtext("Choose a Text Vector");
_moveto( p1 + 9, q1 + 9 );
_setcolor(8);
_outgtext("Choose a Text Vector");
_setcolor(1);
_rectangle(_GFILLINTERIOR, p1 + 10, q2 - 100, p2 - 10, q2 - 10);
_setcolor(9);
_rectangle(_GFILLINTERIOR, p1+13, q2 - 97, p2-13, q2-13);
_setcolor(11);
_rectangle(_GFILLINTERIOR, p1 + 16, q2 - 94, p2-16, q2 - 16);
_setcolor(0);
_rectangle(_GFILLINTERIOR, p1 + 19, q2 - 91, p2-19, q2 - 19);
_setcolor(1);
_rectangle(_GFILLINTERIOR, p1 + 10, q1 + 35, p2 - 10, q2 - 105);
_setcolor(9);
_rectangle(_GFILLINTERIOR, p1+13, q1 + 38, p2-13, q2-108);
_setcolor(11);
_rectangle(_GFILLINTERIOR, p1 + 16, q1 + 41, p2-16, q2 - 111);
_setcolor(0);
_rectangle(_GFILLINTERIOR, p1 + 19, q1 + 44, p2-19, q2 - 114);
_settextcolor(5);
_settextposition(20,46);
sprintf( str,"X Vector:%2d Y Vector:%2d", xvect, yvect);
_outtext(str);
_setcolor(col);
set_font(TRMN, 8 );
xpos = p1 + ((p2 - p1)/2) - (_getgtextextent(msg) / 2) + 1;
ypos = q1 + 100;
_setgtextvector(xvect, yvect);
_moveto(xpos, q1 + 100);
_outgtext( msg );
mouse_show();
while ( NOT done )
{
key = getkey();
switch (key)
{
case KEY_UP :
if ( xvect < 1 )
++xvect;
break;
case KEY_DOWN :
if ( xvect > -1 )
--xvect;
break;
case KEY_LEFT :
if ( yvect > -1 )
--yvect;
break;
case KEY_RIGHT :
if ( yvect < 1 )
++yvect;
break;
case KEY_HOME :
xvect = 1;
yvect = 0;
break;
case KEY_ENTER:
case KEY_ESCAPE:
done = TRUE;
break;
default :
note(660, 2);
break;
}
mouse_hide();
_settextposition(20,46);
sprintf( str,"X Vector: %2d Y Vector: %2d", xvect, yvect);
_outtext(str);
_setcolor(1);
_rectangle(_GFILLINTERIOR, p1 + 10, q1 + 35, p2 - 10, q2 - 110);
_setcolor(9);
_rectangle(_GFILLINTERIOR, p1+13, q1 + 38, p2-13, q2-113);
_setcolor(11);
_rectangle(_GFILLINTERIOR, p1 + 16, q1 + 41, p2-16, q2 - 116);
_setcolor(0);
_rectangle(_GFILLINTERIOR, p1 + 19, q1 + 44, p2-19, q2 - 119);
_setcolor( col );
mouse_show();
if ( (xvect EQ 1) AND (yvect == -1) )
{
xpos = p1 + 45;
ypos = q1 + 60;
}
else
if ( (xvect EQ 1) AND (yvect == 1) )
{
xpos = p1 + 80;
ypos = q2 - 40;
}
else
if ( (xvect EQ 0) AND (yvect == -1) )
{
xpos = 450;
ypos = q1 + 60;
}
else
if ( (xvect EQ -1) AND (yvect == -1) )
{
xpos = p2 -40;
ypos = q1 + 30;
}
else
if ( (xvect EQ 0) AND (yvect == 1) )
{
xpos = 400;
ypos = q2 - 135;
}
else
if ( (xvect EQ -1) AND (yvect == 0 ) )
{
xpos = p2 - 35;
ypos = Y1 + 150;
}
_setgtextvector(xvect, yvect);
_moveto(xpos, ypos);
_outgtext( msg );
xpos = p1 + ((p2 - p1)/2) - (_getgtextextent(msg) / 2) + 1;
ypos = q1 + 100;
}
_setcolor( col );
mouse_hide();
_putimage( p1, q1, msgbox, _GPSET );
mouse_show();
return;
}
void remap_color( short col )
{
pixtype p1,q1,p2,q2;
short oldcolor = _getcolor();
short ht = 130, wd = 40, space = 12;
short rindx, gindx, bindx, i ;
pixtype xpos, ypos;
boolean done = FALSE, go = TRUE;
color_t newcolor;
short row = 20, column = 31;
short oldc, current;
unsigned long key;
char t[5];
_setlogorg(0,0);
mouse_hide();
p1 = 200;
q1 = 100;
p2 = p1 + 200;
q2 = q1 + 300;
rindx = gindx = bindx = 32;
r = g = b = 32;
oldc = current = 1;
_getimage( p1, q1, p2, q2, msgbox );
_setcolor(15);
_rectangle(_GFILLINTERIOR, p1, q1, p2, q2 );
_setcolor(8);
_rectangle(_GFILLINTERIOR, p1 + 5, q1 + 5, p2 - 5, q2 - 5 );
_setcolor(7);
_rectangle(_GFILLINTERIOR, p1 + 10, q1 + 10, p2 - 10, q2 - 10 );
_setcolor(0);
_rectangle(_GFILLINTERIOR, p1 + 15, q1 + 15, p2 - 15, q2 - 15 );
newcolor = rgb( r, g, b );
_remappalette(col, newcolor);
_setcolor( col );
_rectangle(_GFILLINTERIOR, p1 + 25, q2 - 60, p1 + 60, q2 - 25 );
_setcolor(15);
_rectangle(_GBORDER, p1 + 25, q2 - 60, p1 + 60, q2 - 25 );
xpos = p1 + 28;
ypos = q1 + 55;
for ( i = 1; i <= 3; i++ )
{
_setcolor(15);
_rectangle(_GBORDER, xpos, ypos, xpos + wd, ypos + ht );
_rectangle(_GBORDER, xpos + 3, ypos + 3, xpos + wd - 3, ypos + ht -3);
switch( i )
{
case 1 :
_setcolor( 4 );
_settextcolor( 4 );
break;
case 2 :
_setcolor( 2 );
_settextcolor( 2 );
break;
case 3 :
_setcolor( 1 );
_settextcolor( 1 );
break;
default:
break;
}
_rectangle(_GBORDER, xpos, ypos + ht + space, xpos + wd, ypos + ht + space + 25);
_settextposition( row, column );
_outtext("32");
column += 8 - i;
_rectangle(_GFILLINTERIOR, xpos + 10, ypos + ht - 15 - (r * 2), \
xpos + wd - 10, ypos + ht - 8);
xpos += wd + space;
}
_setcolor(12);
set_font( TRMN, 6 );
_moveto( p1 + 27, q1 + 20);
_outgtext("Custom Colors");
_setcolor(4);
_moveto( p1 + 26, q1 + 19);
_outgtext("Custom Colors");
xpos = p1 + 28;
ypos = q1 + 55;
row = 20;
while ( NOT done )
{
key = getkey_or_mouse();
oldc = current;
column = 31;
switch( key )
{
case KEY_LEFT :
if ( current == 1 )
current = 3;
else
--current ;
go = FALSE;
break;
case KEY_RIGHT :
if ( current == 3 )
current = 1;
else
++current ;
go = FALSE;
break;
case KEY_UP :
if ( (current == 1) AND (r < 63) )
++r;
else
if ( (current == 2) AND (g < 63) )
++g;
else
if ( (current == 3) AND (b < 63) )
++b;
go = TRUE;
break;
case KEY_DOWN :
if ( (current == 1) AND (r > 1) )
--r;
else
if ( (current == 2) AND (g > 1) )
--g;
else
if ( (current == 3) AND (b > 1) )
--b;
go = TRUE;
break;
case KEY_ESCAPE:
case KEY_ENTER :
done = TRUE;
break;
default :
note(777, 2);
break;
}
newcolor = rgb( r, g, b );
_remappalette(col, newcolor);
_setcolor( col );
_rectangle(_GFILLINTERIOR, p1 + 25, q2 - 60, p1 + 60, q2 - 25 );
_setcolor(15);
_rectangle(_GBORDER, p1 + 25, q2 - 60, p1 + 60, q2 - 25 );
_setcolor(15);
xpos = (p1 + 28) + ((oldc - 1) * (wd + space));
oldc = current;
_rectangle(_GBORDER, xpos, ypos, xpos + wd, ypos + ht );
_rectangle(_GBORDER, xpos + 3, ypos + 3, xpos + wd - 3, ypos + ht -3);
switch (current)
{
case 1: _setcolor(4);
_settextcolor(4);
break;
case 2: _setcolor(2);
_settextcolor(2);
break;
case 3: _setcolor(1);
_settextcolor(1);
break;
default:
break;
}
if (go)
switch( current )
{
case 1 :
_setcolor(0);
_rectangle(_GFILLINTERIOR, xpos + 10, ypos + 10, \
xpos + wd - 10, ypos + ht - 8);
_settextcolor( 4 );
sprintf( t, "%2d", (int)r );
column = 31;
_setcolor( 4 );
_rectangle(_GFILLINTERIOR, xpos + 10, ypos + ht - 5 - (r * 2), \
xpos + wd - 10, ypos + ht - 8);
break;
case 2 :
_setcolor(0);
_rectangle(_GFILLINTERIOR, xpos + 10, ypos + 10, \
xpos + wd - 10, ypos + ht - 8);
_settextcolor( 2 );
sprintf( t, "%2d", (int)g );
column = 38;
_setcolor( 2 );
_rectangle(_GFILLINTERIOR, xpos + 10, ypos + ht - 5 - (g * 2), \
xpos + wd - 10, ypos + ht - 8);
break;
case 3 :
_setcolor(0);
_rectangle(_GFILLINTERIOR, xpos + 10, ypos + 10, \
xpos + wd - 10, ypos + ht - 8);
_settextcolor( 1 );
sprintf( t, "%2d", (int)b );
column = 44;
_setcolor( 1 );
_rectangle(_GFILLINTERIOR, xpos + 10, ypos + ht - 5 - (b * 2), \
xpos + wd - 10, ypos + ht - 8);
break;
default:
break;
}
xpos = (p1 + 28) + ((current - 1) * (wd + space));
_rectangle(_GBORDER, xpos, ypos, xpos + wd, ypos + ht );
_setcolor(15);
_rectangle(_GBORDER, xpos + 3, ypos + 3, xpos + wd - 3, ypos + ht -3);
_rectangle(_GBORDER, xpos, ypos + ht + space, xpos + wd, ypos + ht + space + 25);
_settextposition( row, column );
_outtext(t);
}
_setcolor( oldcolor );
_putimage( p1, q1, msgbox, _GPSET );
}
void draw_newbox( rect_s *r, short c1, short c2, short c3, short c4 )
{
pixtype p1, p2, q1, q2;
char i, s = 2;
p1 = r -> x1;
q1 = r -> y1;
p2 = r -> x2;
q2 = r -> y2;
_setcolor( c1 );
drawrect(FILL, r );
r -> x1 += s;
r -> y1 += s;
r -> x2 -= s;
r -> y2 -= s;
_setcolor( c2 );
drawrect(FILL, r );
r -> x1 += s;
r -> y1 += s;
r -> x2 -= s;
r -> y2 -= s;
_setcolor( c3 );
drawrect(FILL, r );
r -> x1 += s;
r -> y1 += s;
r -> x2 -= s;
r -> y2 -= s;
_setcolor( c4 );
drawrect(FILL, r );
}
short get_brush_shape( short oldshape )
{
rect_s r;
pixtype p1, q1, p2, q2;
short c1 = 1, c2 = 9, c3 = 5, c4 = 13;
short boxsize = 60;
boolean done = FALSE;
pixtype xpos, ypos, space = 15;
pixtype midx, midy; /// Center of boxes
short i, j, oldi, oldj;
pixtype xloc[5], yloc[2];
key_t key;
mouse_t lb, rb, h, v;
char tempstr[80];
boolean mouse_on = FALSE;
short shape = oldshape;
short old_color = _getcolor();
pixtype newx, newy;
boolean size_change = FALSE;
p1 = r.x1 = 175;
q1 = r.y1 = 175;
p2 = r.x2 = p1 + 400;
q2 = r.y2 = q1 + 200;
mouse_hide();
_setlogorg(0,0);
_getimage( p1, q1, p2, q2, msgbox );
draw_newbox( &r, 15, 8, 7, 0);
set_font( TRMN, 7 );
_setcolor(12);
_moveto( p1 + 15 + space, q1 + 16 );
_outgtext("Select a Brush Shape");
_setcolor(4);
_moveto( p1 + 14 + space, q1 + 15 );
_outgtext("Select a Brush Shape");
xpos = p1 + 15 + space;
ypos = q1 + 35 + space;
for ( i = 1; i <= 2; i++ )
{
yloc[i] = ypos;
for ( j = 1; j <= 5; j++ )
{
if ( NOT ( i EQ 1 AND j EQ 5 ))
{
if ( j EQ 5 )
{
r.x1 = newx = xpos + 10;
r.y1 = newy = ypos;
r.x2 = xpos + boxsize + 10;
r.y2 = ypos + boxsize;
draw_newbox( &r, 12, 4, 0, 0);
}
else
{
r.x1 = xpos;
xloc[j] = xpos;
r.y1 = ypos;
r.x2 = xpos + boxsize;
r.y2 = ypos + boxsize;
draw_newbox( &r, 1, 9, 0, 0);
xpos = r.x2 + space;
}
}
/* else
if ( i EQ 2 AND j EQ 5 )
{
r.x1 = newx = xpos + 10;
r.y1 = newy = ypos;
r.x2 = xpos + boxsize + 10;
r.y2 = ypos + boxsize;
draw_newbox( &r, 12, 4, 11, 0);
} */
}
ypos += boxsize + space - 5 ;
xpos = p1 + 15 + space;
}
_setcolor(15);
newx = newx + (boxsize / 2) - 1;
newy = newy + (boxsize / 2) - 1;
update_newbox( newx, newy, oldshape );
midx = xloc[1] + (boxsize / 2 ) - 1;
midy = yloc[1] + (boxsize / 2 ) - 1;
draw_star( midx, midy );
midx = xloc[2] + (boxsize / 2 ) - 1;
draw_slash( midx, midy ,bsize);
midx = xloc[3] + (boxsize / 2 ) - 1;
draw_backslash( midx, midy, bsize );
midx = xloc[4] + (boxsize / 2 ) - 1;
draw_ellipse(midx,midy,bsize);
midx = xloc[1] + (boxsize / 2 ) - 1;
midy = yloc[2] + (boxsize / 2 ) - 1;
draw_square(midx, midy, bsize);
if (oldshape < 5)
{
i = oldshape;
j = 1;
}
else
{
i = 1;
j = 2;
}
xpos = xloc[i];
ypos = yloc[j];
r.x1 = xpos;
r.y1 = ypos;
r.x2 = xpos + boxsize;
r.y2 = ypos + boxsize;
_setcolor( 15 );
drawrect(NOFILL, &r );
mouse_status(&lb, &rb, &h, &v);
mouse_show();
while ( NOT done )
{
oldi = i;
oldj = j;
mouse_show();
mouse_status(&lb, &rb, &h, &v);
if (lb OR rb)
{
if ( (h > xloc[1] ) AND (h < ( xloc[4] + boxsize)) )
if ( (v > yloc[1] ) AND (v < ( yloc[1] + boxsize)) )
{
j = 1;
xpos = xloc[1];
ypos = yloc[1];
if ( v < ypos + boxsize )
{
if ( h < xpos + boxsize )
i = 1;
else
if ( (h > xpos + boxsize + space) AND \
(h < xpos + (boxsize + space) * 2 ) )
i = 2;
else
if ( (h > xpos + (boxsize + space) * 2) AND \
(h < xpos + (boxsize + space) * 3 ) )
i = 3;
else
if ( (h > xpos + (boxsize + space) * 3) AND \
(h < xpos + (boxsize + space) * 4 ) )
i = 4;
}
}
else
if ( (v > yloc[2] ) AND (v < ( yloc[2] + boxsize)) )
{
j = 2;
xpos = xloc[1];
ypos = yloc[2];
if ( v < ypos + boxsize )
{
if ( h < xpos + boxsize )
i = 1;
else
if ( (h > xpos + boxsize + space) AND \
(h < xpos + (boxsize + space) * 2 ) )
i = 2;
else
if ( (h > xpos + (boxsize + space) * 2) AND \
(h < xpos + (boxsize + space) * 3 ) )
i = 3;
else
if ( (h > xpos + (boxsize + space) * 3) AND \
(h < xpos + (boxsize + space) * 4 ) )
i = 4;
}
}
}
if (kbhit())
{
key = getkey();
/*** i = column j = row ***/
switch( key )
{
case KEY_UP :
if ( j EQ 1 )
j = 2;
else
j = 1;
break;
case KEY_DOWN :
if ( j EQ 2 )
j = 1;
else
j = 2;
break;
case KEY_LEFT :
if ( i EQ 1 )
i = 4;
else
--i;
break;
case KEY_RIGHT:
if ( i EQ 4 )
i = 1;
else
++i;
break;
case KEY_CTRL_RIGHT :
if (bsize < 20)
{
++bsize;
size_change = TRUE;
}
else
note( 400, 3 );
break;
case KEY_CTRL_LEFT :
if (bsize > 1)
{
--bsize;
size_change = TRUE;
}
else
note( 400, 3 );
break;
case KEY_ESCAPE:
case KEY_END :
done = TRUE;
i = 0;
break;
case KEY_ENTER:
done = TRUE;
break;
default :
note( 200, 3 );
break;
}
}
if ( (oldi NE i) OR ( oldj NE j ) OR size_change)
{
xpos = xloc[oldi];
ypos = yloc[oldj];
r.x1 = xpos;
r.y1 = ypos;
r.x2 = xpos + boxsize;
r.y2 = ypos + boxsize;
_setcolor( c1 );
mouse_hide();
drawrect(NOFILL, &r );
xpos = xloc[i];
ypos = yloc[j];
r.x1 = xpos;
r.y1 = ypos;
r.x2 = xpos + boxsize;
r.y2 = ypos + boxsize;
_setcolor( 15 );
drawrect(NOFILL, &r );
mouse_show();
mouse_on = FALSE;
shape = i + (j - 1) * 4;
update_newbox(newx, newy, shape);
size_change = FALSE;
}
}
if (j EQ 1 AND i > 0 AND i <= 4)
shape = i;
else
if (j EQ 2 AND i > 0 AND i <= 1)
shape = i + 4;
else
shape = oldshape;
mouse_hide();
_putimage( p1, q1, msgbox, _GPSET );
mouse_show();
_setcolor(oldcolor);
return( shape );
}
void drawrect( boolean fill, rect_s *r )
{
if ( fill )
_rectangle(_GFILLINTERIOR, r -> x1, r -> y1, r -> x2, r -> y2 );
else
_rectangle(_GBORDER, r -> x1, r -> y1, r -> x2, r -> y2 );
}
void draw_star( pixtype x, pixtype y )
{
_setpixel( x, y );
_setpixel( x+1, y );
_setpixel( x, y+1 );
_setpixel( x-1, y );
_setpixel( x, y-1 );
}
void draw_spray( pixtype x, pixtype y )
{
char i, j;
for ( i = -10; i <= 10; i++)
{
for ( j = -10; j <= 10; j++)
{
_setpixel( x + j, y);
x += 1;
}
/// _setpixel( x, j + i );
/// y += 1;
}
}
void draw_slash( pixtype x, pixtype y , short len)
{
short i;
for ( i = 0; i <= 2; ++i )
{
_moveto( x - len + i, y - len );
_lineto( x + len + i, y + len );
}
}
void draw_backslash( pixtype x, pixtype y , short len)
{
short i;
for ( i = 0; i <= 2; ++i )
{
_moveto( x + len + i, y - len );
_lineto( x - len + i, y + len );
}
}
void draw_square(pixtype midx, pixtype midy, short size )
{
_rectangle(_GFILLINTERIOR,midx - size,midy - size, midx + size, midy + size );
}
void draw_ellipse(pixtype midx, pixtype midy, short size )
{
_ellipse(_GFILLINTERIOR,midx - size,midy - size, midx + size, midy + size );
}
void update_newbox(pixtype midx, pixtype midy, short shape )
{
if ( shape > 5 )
return;
_setcolor(0);
_rectangle(_GFILLINTERIOR, midx - 25, midy - 25, midx + 25, midy + 25);
_setcolor(15);
switch ( shape )
{
case 1 :
draw_star( midx, midy );
break;
case 2 :
draw_slash(midx, midy, bsize);
break;
case 3 :
draw_backslash(midx, midy, bsize);
break;
case 4:
draw_ellipse(midx, midy, bsize );
break;
case 5:
draw_square( midx, midy, bsize);
break;
default:
break;
}
}
void draw_paint(pixtype midx, pixtype midy, short shape )
{
if ( shape > 5 )
return;
switch ( shape )
{
case 1 :
draw_star( midx, midy );
break;
case 2 :
draw_slash(midx, midy, bsize);
break;
case 3 :
draw_backslash(midx, midy, bsize);
break;
case 4:
draw_ellipse(midx, midy, bsize );
break;
case 5:
draw_square( midx, midy, bsize);
break;
default:
break;
}
}
void draw_paint2(pixtype x1, pixtype y1, short shape )
{
pixtype pixtemp, oldx1, oldy1;
draw_paint( x1, y1, shape );
if ( mirror_on )
{
oldx1 = x1;
oldy1 = y1;
x1 = -x1; // -y +x
y1 = -y1; // y, -x
draw_paint( x1, y1, shape );
x1 = -x1;
draw_paint( x1, y1, shape );
y1 = -y1;
x1 = - x1; // y, -x
draw_paint( x1, y1, shape );
pixtemp = oldy1;
y1 = oldx1;
x1 = pixtemp;
if ((y1 < -197 ) OR (-y1 > 197 ) OR \
(-y1 < -197 )OR (y1 > 197 ))
return;
draw_paint( x1, y1, shape );
x1 = -x1;
y1 = -y1;
draw_paint( x1, y1, shape );
x1 = -x1; // -y +x
draw_paint( x1, y1, shape );
y1 = -y1;
x1 = -x1; // y, -x
draw_paint( x1, y1, shape );
}
}
void break_color( color_t cnum, short *red, short *blue, short *green )
{
*red = cnum % 64;
*green = (cnum >> 8L) % 64;
*blue = cnum >> 16L;
}
color_t custom_color(short palette_num )
{
boolean done = FALSE;
boolean change = TRUE;
short red, green, blue; /// Amount of each element of color, 0..63
rect_s c_bar[3][4]; /// Boxes for color bars & text
rect_s r1; /// Coordinates of whole message box
pixtype xpos, ypos, ht, wd, space;
pixtype p1,p2,q1,q2;
short i, j; /// row / column indexes
color_t newcol;
mouse_t lb, rb, h, v;
key_t key;
char str[80];
short row, column;
r1.x1 = p1 = 200;
r1.y1 = q1 = 70;
r1.x2 = p2 = p1 + 226;
r1.y2 = q2 = q1 + 350;
_getimage( p1, q1, p2, q2, msgbox );
draw_newbox( &r1, 15,7,8,0 );
set_font(TRMN, 7);
_getvideoconfig( &vc);
_setcolor(12);
_moveto( p1 + 15, q1 + 12 );
_outgtext("Custom Colors");
_moveto( p1 + 14, q1 + 11 );
_setcolor(4);
_outgtext("Custom Colors");
ht = 148; /// height & width of color bar boxes
wd = 50;
space = 12;
ypos = q1 + 50;
xpos = p1 + 22;
/* Draw the original boxes to contain the color bars & text info &
save the screen coordinates of each in the "c_bar" array */
for (j = 1; j <= 3; j++)
{
for ( i = 1; i <= 2; i++)
{
if (i EQ 1)
{
c_bar[i][j].x1 = xpos;
c_bar[i][j].y1 = ypos;
c_bar[i][j].x2 = xpos + wd;
c_bar[i][j].y2 = ypos + ht;
draw_newbox( &c_bar[i][j], 15, 0, 15, 0 );
}
else
{
c_bar[i][j].x1 = xpos;
c_bar[i][j].y1 = ypos + ht + space;
c_bar[i][j].x2 = xpos + wd;
c_bar[i][j].y2 = ypos + ht + space + 30;
draw_newbox( &c_bar[i][j], 15, 0, 0, 0 );
}
}
xpos += wd + space;
}
/* Determine the primary color values used in creating the given color: */
break_color( _BRIGHTWHITE, &red, &green, &blue );
/* Draw the color bars showing the breakdown of these values. */
row = 19;
column = 31;
for ( j = 1; j <= 3; j++ )
{
ypos = c_bar[1][j].y2 - 5;
xpos = c_bar[1][j].x1 + 7;
switch( j )
{
case 1 :
_setcolor( 4 );
_rectangle(_GFILLINTERIOR, xpos, ypos, xpos + wd - 20, \
ypos - ( red * 2 ) - 1 );
_settextcolor( 4 );
sprintf(str,"%2d", red );
_settextposition( row, column );
_outtext( str );
break;
case 2 :
_setcolor( 2 );
_rectangle(_GFILLINTERIOR, xpos, ypos, xpos + wd - 20, \
ypos - ( green * 2 ) - 1 );
sprintf(str,"%2d", green );
_settextposition( row, column += 8 );
_settextcolor( 2 );
_outtext( str );
break;
case 3 :
_setcolor( 1 );
_rectangle(_GFILLINTERIOR, xpos, ypos, xpos + wd - 20, \
ypos - ( blue * 2 ) - 1 );
sprintf(str,"%2d", blue );
_settextposition( row, column += 8);
_settextcolor( 1 );
_outtext( str );
break;
default:
break;
}
}
getch();
_putimage(p1, q1, msgbox, _GPSET );
}
void sqx( pixtype x, pixtype y )
{
_moveto(x, y);
_lineto(-y, x);
_lineto(-x, -y);
_lineto(y, -x);
_lineto(x, y);
}
void cycle3( void )
{
boolean done = FALSE;
short pnum;
short red, green, blue;
color_t newc;
short color_pick;
short shift;
char str[80];
while ( NOT done )
{
for ( pnum = 1; pnum <= 15; pnum++ )
{
if ( c_used[ pnum ] )
{
break_color( c_array[ pnum ], &red, &green, &blue );
done = TRUE;
done = FALSE;
color_pick = rand() % 6 + 1;
shift = rand() % 7;
newc = RGB( red, green, blue );
newc << shift;
_remappalette( pnum, newc );
c_array[ pnum ] = newc;
///if ( kbhit() )
done = (getkey() == KEY_ESCAPE);
if (done) break;
/* switch( shift )
{
case 1:
if ( red + shift <= 63 )
red += shift;
else
red -= shift;
break;
case 2:
if ( green + shift <= 63 )
green += shift;
else
green -= shift;
break;
case 3:
if ( blue + shift <= 63 )
blue += shift;
else
blue -= shift;
break;
case 4:
if ( red - shift >= 0 )
red -= shift;
else
red += shift;
break;
case 5:
if ( green - shift >= 0 )
green -= shift;
else
green += shift;
break;
case 6:
if ( blue - shift >= 0 )
blue -= shift;
else
blue += shift;
break;
case 7:
if ( red <= 63 )
++red;
/// else
/// --red;
break;
case 8:
if ( green <= 63 )
++green;
/// else
/// --green;
break;
case 9:
if ( blue <= 63 )
++blue;
/// else
/// --blue;
break;
case 10:
if ( red >= 0 )
--red;
///else
/// ++red;
break;
case 11:
if ( green >= 0 )
--green;
/// else
///++green;
break;
case 12:
if ( blue >= 0 )
--blue;
/// else
/// ++blue;
break;
default:
break;
}
newc = rgb( red, green, blue );
_remappalette( pnum, newc );
c_array[ pnum ] = newc; */
}
}
}
}
void update_shapebox( short type )
{
short xpos, ypos;
short newtype = type;
short c = _getcolor();
ypos = vc.numypixels - 12;
xpos = 12;
_setlogorg( 0, 0 );
_getvideoconfig( &vc );
_setcolor(8);
_rectangle(_GFILLINTERIOR, xpos, ypos - 43, xpos + 43, ypos );
_setcolor( 7 );
_rectangle(_GBORDER, xpos, ypos - 43, xpos + 43, ypos );
_setcolor(15);
switch ( type )
{
case 1 : /// square box
_rectangle( _GBORDER, xpos + 5, ypos - 38, xpos + 38, ypos - 5 );
break;
case 2 : /// ellipse box
_ellipse( _GBORDER, xpos + 5, ypos - 38, xpos + 38, ypos - 5 );
break;
case 5 : /// Solid rectangle
_setcolor( c );
if ( fill_on )
_setfillmask( pick[ipick] );
_rectangle(_GFILLINTERIOR, xpos + 5, ypos - 38, xpos + 38, ypos - 5 );
if ( fill_on )
_setfillmask( NULL );
break;
case 4 : /// Solid ellipse
_setcolor( c );
if ( fill_on )
_setfillmask( pick[ipick] );
_ellipse(_GFILLINTERIOR,xpos + 5, ypos - 38, xpos + 38, ypos - 5 );
if ( fill_on )
_setfillmask( NULL );
break;
case 6 : /// Line box
_moveto( xpos + 5, ypos - 38 );
_lineto( xpos + 38, ypos - 5 );
break;
case 8 :/// Character Box
set_font( TRMN, 8 );
_moveto( xpos + 10, ypos - 33 );
_outgtext("A");
break;
case 3 :/// Quit Box
set_font( HELV, 8 );
_moveto( xpos + 13, ypos - 33 );
_setcolor( 12 );
_outgtext("?");
set_font( TRMN, 5 );
_moveto( xpos + 2, ypos - 33 );
_setcolor( 15 );
_outgtext("Quit");
break;
case 99:/// Fill Box
set_font( TRMN, 7 );
_moveto( xpos + 2, ypos - 33 );
_outgtext("Fill");
break;
case 666:/// Arc Box
set_font( TRMN, 5 );
_moveto( xpos + 3, ypos - 33 );
_outgtext("Arc");
break;
case 667:/// Pie Box
set_font( TRMN, 7 );
_moveto( xpos + 2, ypos - 33 );
_outgtext("Pie");
break;
case 25 : /// Brush Box
_putimage(12, vc.numypixels - 55, randbox, _GPSET );
break;
default:
break;
}
}
void draw_arc( short fill_type )
{
pixtype xb, yb, xe, ye, p, q, pabs, qabs;
mouse_t lb, rb, h, v, status;
boolean done = FALSE;
boolean done1 = FALSE;
boolean done2 = FALSE;
short c = _getcolor();
short presses = 0;
unsigned long size;
char str[80];
set_cad_logorg();
_getvideoconfig( &vc );
_setlinestyle( 4 );
mouse_press( LBUTTON, &status, &presses, &h, &v );
while( NOT done )
{
mouse_show();
mouse_press( LBUTTON, &status, &presses, &h, &v );
if ( presses > 0 )
if ( NOT done1)
{
p = h - MX;
q = v - MY;
_setcolor( 7 );
size = _imagesize( p, q, -p, -q );
if ( size >= MAXIMAGESIZE )
done1 = FALSE;
else
{
if ( p > 0 )
p = -p;
if ( q > 0 )
q = -q;
mouse_hide();
_getimage( p, q, -p, -q, msgbox );
_rectangle( _GBORDER, p, q, -p, -q );
_ellipse( _GBORDER, p, q, -p, -q );
mouse_show();
done1 = TRUE;
}
}
else
if ( NOT done2 )
{
xb = h - MX;
yb = v - MY;
_setcolor(12);
draw_star( xb, yb );
_moveto( xb, yb );
_lineto( 0, 0 );
done2 = TRUE;
}
else
{
xe = h - MX;
ye = v - MY;
_setcolor( c );
done1 = FALSE;
mouse_hide();
_putimage( p, q, msgbox, _GPSET );
if ( fill_type EQ 1 )
_arc( p, q, -p, -q, xb, yb, xe, ye );
else
_pie( _GFILLINTERIOR, p, q, -p, -q, xb, yb, xe, ye );
///done1 = done2 = FALSE;
mouse_show();
done = TRUE;
}
if ( kbhit() )
{
if ( getch() EQ KEY_ESCAPE )
{
mouse_hide();
_putimage( p, q, msgbox, _GPSET );
mouse_show();
done = TRUE;
}
else
note( 440, 2 );
}
}
_setlinestyle( normal );
_setcolor( c );
mouse_show();
}