Category : C Source Code
Archive   : C_ROTATE.ZIP
Filename : PIC_CLAS.I

 
Output of file : PIC_CLAS.I contained in archive : C_ROTATE.ZIP
/* CLASS Definitions for:
XY = Just a single point location, used and centers for circles,
corners for boxes, etc...

CIRCLE = XY Pos = Center of Circle


BUTTON = XY Pos = Top Left Corner with x2, y2 going down to bottom right
*/

class XY
{
protected:
int x1, y1;
public:
void create( int sx1, int sy1 );
void set( char c, int num );
int get( char c );
};

void XY::create( int sx1, int sy1 )
{
set( 'X', sx1 );
set( 'Y', sy1 );
}

void XY::set(char c, int num )
{
if( c == 'X' )
x1 = num;
else
y1 = num;
}

int XY::get( char c )
{
if( c == 'X' )
return( x1 );
else
return( y1 );
}



class XY2 : public XY
{
protected:
int x2, y2, color;
public:
void create2( int sx1, int sy1, int sx2, int sy2, int sc );
void set2( char c, int num );
void set_color( int sc );
int get2( char c );
int get_color();
};

void XY2::create2( int sx1, int sy1, int sx2, int sy2, int sc )
{
XY::create( sx1, sy1 );
set2( 'X', sx2 );
set2( 'Y', sy2 );
set_color( sc );
}

void XY2::set2(char c, int num )
{
if( c == 'X' )
x2 = num;
else
y2 = num;
}

void XY2::set_color( int sc )
{
color = sc;
}

int XY2::get2( char c )
{
if( c == 'X' )
return( x2 );
else
return( y2 );
}

int XY2::get_color()
{
return( color );
}



class CIRCLE : public XY
{
protected:
int size, color;
char text[40];
public:
void Ccreate( int sx1, int sy1, int ss, int sc, char* txt );
void set_size( int ss );
void set_color( int sc );
void set_text( char* txt );
int get_size();
int get_color();
void draw();
int IS_HIT( int mx, int my);
};

void CIRCLE::Ccreate( int sx1, int sy1, int ss, int sc, char* txt )
{
XY::create( sx1, sy1 );
set_size( ss );
set_color( sc );
strcpy( text, txt );
draw(); /* Draw with normal fill, not like mouse button hit */
}

void CIRCLE::set_size( int ss )
{
size = ss;
}

void CIRCLE::set_color( int sc )
{
color = sc;
}

void CIRCLE::set_text( char* txt )
{
strcpy( text, txt );
}

int CIRCLE::get_size()
{
return( size );
}

int CIRCLE::get_color()
{
return( color );
}

void CIRCLE::draw()

{
int OldColor = color;

gmouse.Mshow( FALSE );
setcolor( color );

circle( x1, y1, size );
setfillstyle( SOLID_FILL, color );
floodfill( x1, y1, color );

if( strlen( text ) > 0 )
{
/* don't print if no text to be printed */
setcolor( WHITE );
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
settextjustify( CENTER_TEXT, CENTER_TEXT );
outtextxy( x1, y1 + size + 10, text );
}

setcolor( OldColor );
gmouse.Mshow( TRUE );
}

int CIRCLE::IS_HIT( int mx, int my )
{ /* MX & MY are the Mouse X & Y positions when the button was pressed */
return ( hypot( abs( mx-x1 ), abs( my-y1 ) ) < size );
}

enum ButtonType { SQUARE, THREE_D, ROUNDED };

class BUTTON : public XY2
{
protected:
ButtonType buttontype;
char text[40];

public:
void Bcreate( int sx1, int sy1, int sx2, int sy2,
int sc, ButtonType sbtn, char* txt );
void set_text( char* txt );
void draw( int hit );
int IS_HIT( int mx, int my );
};

void BUTTON::Bcreate( int sx1, int sy1, int sx2, int sy2,
int sc, ButtonType sbtn, char* txt )
{
XY2::create2( sx1, sy1, sx2, sy2, sc );
strcpy( text, txt );
buttontype = sbtn;
draw( 0 );
}

void BUTTON::set_text( char* txt )
{
strcpy( text, txt );
}

void BUTTON::draw( int hit )
{
struct viewporttype vp;
int OldColor = color, radius = 6;

gmouse.Mshow( FALSE );

/* Don't redraw the entire box if the button was hit,
just do the filling / unfill portion below this */
if ( !hit )
{
setcolor( WHITE );
switch( buttontype )
{
case SQUARE: rectangle( x1, y1, x2, y2 );
break;

case THREE_D: rectangle( x1, y1, x2, y2 );
rectangle( x1+5, y1+5, x2-5, y2-5 );
line( x1, y1, x1+5, y1+5 );
line( x1, y2, x1+5, y2-5 );
line( x2, y1, x2-5, y1+5 );
line( x2, y2, x2-5, y2-5 );
break;

case ROUNDED: arc( x2-radius, y1+radius, 0, 90, radius );
arc( x1+radius, y1+radius, 90, 180, radius );
arc( x1+radius, y2-radius, 180, 270, radius );
arc( x2-radius, y2-radius, 270, 360, radius );
/* use the +1 and -1 to account for top and bottoms
of the arcs not completing to the exact line ends
if not done, the fill will fill entire screen */
line( x1+radius, y1+1, x2-radius, y1+1 );
line( x1, y1+radius, x1, y2-radius );
line( x1+radius, y2-1, x2-radius, y2-1 );
line( x2, y2-radius, x2, y1+radius );
break;
}

setcolor( WHITE );
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
settextjustify( CENTER_TEXT, CENTER_TEXT );

getviewsettings( &vp );
setviewport( x1+2, y1+2, x2-2, y2-2, TRUE );
outtextxy( abs( (x1-x2) / 2), abs( (y1-y2) / 2), text );
setviewport( vp.left, vp.top, vp.right, vp.bottom, TRUE );
}

if( hit )
setfillstyle( SOLID_FILL, color );
else
setfillstyle( WIDE_DOT_FILL, color );

/* Flood fill based on the white border, not the color being filled with.
Also, don't fill directly center.. Text may exist and not show the
actual filling / unfill appropriately
*/
if ( buttontype == THREE_D )
floodfill( x1+6, y1+6, WHITE );
else
floodfill( x1+3, y1+3, WHITE );

setcolor( OldColor );
gmouse.Mshow( TRUE );
}

int BUTTON::IS_HIT( int mx, int my )
{
if( ( x1 <= mx && mx <= x2 ) && ( y1 <= my && my <= y2 ) )
{
draw( 1 );
draw( 0 );
return( TRUE );
}

return( FALSE );
}


  3 Responses to “Category : C Source Code
Archive   : C_ROTATE.ZIP
Filename : PIC_CLAS.I

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/