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

 
Output of file : GCONTROL.I contained in archive : C_ROTATE.ZIP
/* Graphics Control object file == GCONTROL.I
Book page 404
*/

#include
// #include
// #include "mouse.i"

typedef enum { ROUNDED, SQUARE, THREE_D } ButtonType;
typedef enum { NO_HIT, RIGHT, UP, HBAR, VBAR, LEFT, DOWN } HitType;
typedef int Outline[10];

class Point
{
protected:
int x, y, Color;
viewporttype VRef;
public:
Point();
void Move( int PtX, int PtY );
virtual void Draw();
void Create( int PtX, int PtY, int C );
void RestoreViewport();
void SetColor( int C );
virtual void SetLoc( int PtX, int PtY );
virtual void Erase();
int GetColor();
int GetX();
int GetY();
};

class Button : public Point
{
protected:
int State, Rotate, FontSize, TypeFace, SizeX, SizeY;
ButtonType ThisButton;
char BtnTxt[40];
public:
Button();
~Button();
virtual void Draw();
void Create( int PtX, int PtY, int Width, int Height, int C, char* Text );
virtual void Erase();
void Invert();
virtual void Move( int PtX, int PtY );
void SetColor( int C );
void SetState( int BState );
void SetLabel( char* Text );
void SetButtonType( ButtonType WhatType );
void SetTypeSize( int TxtSize );
void SetTypeFace( int TxtFont );
int GetWidth();
int GetHeight();
int GetState();
int GetTextSize();
int ButtonHit();
ButtonType GetType();
};

class RadioButton : public Button
{
protected:
int Outline, Radius;
public:
RadioButton();
RadioButton( int PtX, int PtY, int C, int R, char* Text );
~RadioButton();
void Create( int PtX, int PtY, int C, int R, char* Text );
void Draw();
void Erase();
void SetRadius( int R );
int GetRadius();
int ButtonHit();
};

class VueMeter : public RadioButton
{
protected:
int Closure;
public:
VueMeter();
VueMeter( int PtX, int PtY, int C, int R, char* Text );
~VueMeter();
void Create( int PtX, int PtY, int C, int R, char* Text );
void Draw();
void Erase();
void Select( int Degree );
void Close( int Degree );
void Open( int Degree );
};

class ScrollBar : public Button
{
private:
int LineColor, SPos, Step, ScrollMove;
public:
ScrollBar();
ScrollBar( int PtX, int PtY, int Size, int C1, int C2, int Orientation );
~ScrollBar();
void Create( int PtX, int PtY, int Size, int C1, int C2, int Orientation );
virtual void SetLoc( int PtX, int PtY );
HitType ScrollHit();
int GetPosition();
int GetDirection();
int GetPercent();
private:
virtual void Draw();
virtual void Erase();
void SetOutline();
void SetArrows();
void SetThumbPad();
void EraseThumbPad();
};

Point::Point()
{
getviewsettings( &VRef );
}

void Point::SetLoc( int PtX, int PtY )
{
x = PtX + VRef.left;
y = PtY + VRef.top;
}

void Point::Draw()
{
putpixel( x, y, Color );
}

void Point::RestoreViewport()
{
setviewport( VRef.left, VRef.top, VRef.right, VRef.bottom, VRef.clip );
}

void Point::Create( int PtX, int PtY, int C )
{
SetLoc( PtX, PtY );
Color = C;
Draw();
}

void Point::Erase()
{
int Temp;
Temp = Color;
Color = getbkcolor();
Draw();
Color = Temp;
}

void Point::Move( int PtX, int PtY )
{
Erase();
SetLoc( PtX, PtY );
Draw();
}

void Point::SetColor( int C )
{
Color = C;
Draw();
}

int Point::GetColor() { return( Color ); }

int Point::GetX() { return( x + VRef.left ); }

int Point::GetY() { return( y + VRef.top ); }


Button::Button()
{
Rotate = FALSE;
SetTypeSize( 2 );
SetTypeFace( TRIPLEX_FONT );
}

Button::~Button()
{
Erase();
}

void Button::Draw()
{
int i, radius = 6, offset = 3, AlignX, AlignY;
Outline RectArr;

gmouse.Mshow( FALSE );
setviewport( x, y, x+SizeX, y+SizeY, TRUE );
setcolor( Color );
switch( ThisButton )
{
case SQUARE : rectangle( 0, 0, SizeX, SizeY );
break;
case THREE_D: rectangle( 0, 0, SizeX, SizeY );
RectArr[0] = RectArr[2] = RectArr[8] =
RectArr[1] = RectArr[7] = RectArr[9] = 1;
RectArr[4] = RectArr[6] = SizeX - 1;
RectArr[3] = RectArr[5] = SizeY - 1;
setfillstyle( CLOSE_DOT_FILL, Color );
setlinestyle( USERBIT_LINE, 0, NORM_WIDTH );
fillpoly( 5, RectArr );
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
rectangle( 2*radius, 2*radius,
SizeX - 2*radius, SizeY- 2*radius );
line( 0, 0, 2*radius, 2*radius );
line( 0, SizeY, 2*radius, SizeY - 2*radius );
line( SizeX, 0, SizeX - 2*radius, 2*radius );
line( SizeX, SizeY, SizeX - 2*radius, SizeY - 2*radius );
break;
case ROUNDED: arc( SizeX-radius, radius, 0, 90, radius );
arc( radius, radius, 90, 180, radius );
arc( radius, SizeY-radius, 180, 270, radius );
arc( SizeX-radius, SizeY-radius, 270, 360, radius );
line( radius, 0, SizeX - radius, 0 );
line(radius, SizeY, SizeX - radius, SizeY );
line( 0, radius, 0, SizeY - radius );
line( SizeX, radius, SizeX, SizeY - radius );
break;
}

switch( ThisButton )
{
case SQUARE:
case ROUNDED: RectArr[0] = RectArr[2] = RectArr[8] =
RectArr[1] = RectArr[7] = RectArr[9] = offset;
RectArr[4] = RectArr[6] = SizeX - offset;
RectArr[3] = RectArr[5] = SizeY - offset;
break;
case THREE_D: RectArr[0] = RectArr[2] = RectArr[8] =
RectArr[1] = RectArr[7] = RectArr[9] = 2*radius+1;
RectArr[4] = RectArr[6] = SizeX - 2*radius-1;
RectArr[3] = RectArr[5] = SizeY - 2*radius-1;
break;
}

if( State )
setfillstyle( SOLID_FILL, Color );
else
setfillstyle( CLOSE_DOT_FILL, Color );
setlinestyle( USERBIT_LINE, 0, NORM_WIDTH );
fillpoly( 5, RectArr );
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
settextstyle( TypeFace, Rotate, FontSize );
AlignX = (SizeX/2) - 3;
AlignY = (SizeY/2) - 3;
if( State )
setcolor( getbkcolor() );
outtextxy( AlignX, AlignY, BtnTxt );
if( State )
setcolor( Color );
RestoreViewport();
gmouse.Mshow( TRUE );
}

void Button::Create( int PtX, int PtY, int Width, int Height, int C, char* Text )
{
getviewsettings( &VRef );
setviewport( 0, 0, getmaxx(), getmaxy(), TRUE );
settextjustify( CENTER_TEXT, CENTER_TEXT );
SetLoc( PtX, PtY );
if( Width < 20 )
SizeX = 20;
else
SizeX = Width;

if( Height < 20 )
SizeY = 20;
else
SizeY = Height;

if( SizeY > SizeX )
Rotate = TRUE;
else
Rotate = FALSE;

Color = C;
State = FALSE;
strcpy( BtnTxt, Text );
Draw();
}

void Button::Erase()
{
gmouse.Mshow( FALSE );
setviewport( x, y, x+SizeX, y+SizeY, TRUE );
clearviewport();
RestoreViewport();
gmouse.Mshow( TRUE );
}

void Button::Move( int PtX, int PtY )
{
Erase();
SetLoc( PtX, PtY );
Draw();
}

void Button::SetLabel( char* Text )
{
strcpy( BtnTxt, Text );
Draw();
}

void Button::SetColor( int C )
{
Color = C;
Draw();
}

void Button::SetState( int BState )
{ if( State != BState ) Invert(); }

void Button::SetTypeSize( int TxtSize )
{ FontSize = TxtSize; }

void Button::SetTypeFace( int TxtFont )
{ TypeFace = TxtFont; }

void Button::SetButtonType( ButtonType WhatType )
{ ThisButton = WhatType; }

void Button::Invert()
{
State = !State;
/* if( State )
State = FALSE;
else
State = TRUE;
*/
Draw();
}

int Button::GetWidth() { return( SizeX ); }
int Button::GetHeight() { return( SizeY ); }
int Button::GetState() { return( State ); }
int Button::GetTextSize() { return( FontSize ); }
ButtonType Button::GetType() { return( ThisButton ); }

int Button::ButtonHit()
{
Mstatus P = gmouse.Mpressed( ButtonL );
if( ( P.xaxis >= x ) && ( P.xaxis <= x+SizeX ) &&
( P.yaxis >= y ) && ( P.yaxis <= y+SizeY ) )
{
Invert();
return( TRUE );
}
return( FALSE );
}

RadioButton::RadioButton() { }
RadioButton::RadioButton( int PtX, int PtY, int C, int R, char* Text )
{ Create( PtX, PtY, C, R, Text ); }

RadioButton::~RadioButton() { Erase(); }

void RadioButton::Create( int PtX, int PtY, int C, int R, char* Text )
{
getviewsettings( &VRef );
settextjustify( CENTER_TEXT, CENTER_TEXT );
SetLoc( PtX, PtY );
Radius = R;
Outline = C | 0x08;
Color = C;
State = FALSE;
strcpy( BtnTxt, Text );
Draw();
}

void RadioButton::Draw()
{
int XAsp, YAsp, i, OldColor = getcolor();

RestoreViewport();
getaspectratio( &XAsp, &YAsp );
setcolor( Outline );
gmouse.Mshow( FALSE );
if( State )
setfillstyle( SOLID_FILL, Color );
else
setfillstyle( INTERLEAVE_FILL, Color );
fillellipse( x, y, Radius, Radius * (double) (XAsp / YAsp ) );
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
outtextxy( x, y + Radius + 10, BtnTxt );
gmouse.Mshow( TRUE );
setcolor( OldColor );
}

void RadioButton::Erase()
{
int OldColor = Color;
Color = getbkcolor();
Outline = Color;
Draw();
Color = OldColor;
Outline = OldColor | 0x08;
}

void RadioButton::SetRadius( int R ) { Radius = R; }
int RadioButton::GetRadius() { return( Radius ); }

int RadioButton::ButtonHit()
{
int OffX, OffY;
Mstatus P = gmouse.Mpressed( ButtonL );
OffX = abs( P.xaxis - x );
OffY = abs( P.yaxis - y );

if( ( OffX < 2 * Radius ) && ( OffY < 2 * Radius ) )
if( hypot( OffX, OffY) < Radius )
{
Invert();
return( TRUE );
}
return( FALSE );
}

VueMeter::VueMeter() { }

VueMeter::VueMeter( int PtX, int PtY, int C, int R, char* Text )
{ Create( PtX, PtY, C, R, Text ); }

VueMeter::~VueMeter() { Erase(); }

void VueMeter::Create( int PtX, int PtY, int C, int R, char* Text )
{
getviewsettings( &VRef );
settextjustify( CENTER_TEXT, CENTER_TEXT );
SetLoc( PtX, PtY );
Radius = R;
Color = C;
Closure = 1;
strcpy( BtnTxt, Text );
Draw();
}

void VueMeter::Draw()
{
int XAsp, YAsp;

RestoreViewport();
getaspectratio( &XAsp, &YAsp );
if( Closure < 0 ) Closure = 0;
if( Closure > 360) Closure = 360;
gmouse.Mshow( FALSE );
setcolor( Color );

setfillstyle( SOLID_FILL, Color );
sector( x, y, 0, Closure, Radius, Radius * (double) ( XAsp / YAsp ) );
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
settextjustify( CENTER_TEXT, CENTER_TEXT );
outtextxy( x, y + Radius + 10, BtnTxt );
setcolor( WHITE );
setfillstyle( CLOSE_DOT_FILL, Color );
if( Closure < 360 )
sector( x, y, Closure, 360, Radius, Radius * (double) ( XAsp / YAsp ) );
gmouse.Mshow( TRUE );
}

void VueMeter::Erase()
{
int XAsp, YAsp;
getaspectratio( &XAsp, &YAsp );
gmouse.Mshow( FALSE );
setcolor( getbkcolor() );
setfillstyle( SOLID_FILL, getbkcolor() );
sector( x, y, 0, 360, Radius, Radius * (double) ( XAsp / YAsp ) );
settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );
settextjustify( CENTER_TEXT, CENTER_TEXT );
outtextxy( x, y + Radius + 10, BtnTxt );
setcolor( WHITE );
gmouse.Mshow( TRUE );
}

void VueMeter::Select( int Degrees )
{
Closure = Degrees;
Draw();
}

void VueMeter::Close( int Degrees )
{
Closure += Degrees;
Draw();
}

void VueMeter::Open( int Degrees )
{
Closure -= Degrees;
Draw();
}

ScrollBar::ScrollBar()
{
x = y = SizeX = SizeY = Color = LineColor = SPos = Step = ScrollMove = 0;
}

ScrollBar::ScrollBar( int PtX, int PtY, int Size,
int C1, int C2, int Orientation )
{
Create( PtX, PtY, Size, C1, C2, Orientation );
}

ScrollBar::~ScrollBar() { Erase(); }

void ScrollBar::Create( int PtX, int PtY, int Size,
int C1, int C2, int Orientation )
{
getviewsettings( &VRef );
if( Size < 100 ) Size = 100;
ScrollMove = Orientation;
SPos = 21;
Step = Size / 100;
switch( ScrollMove)
{
case VERT_DIR: SizeX = 20;
SizeY = Size;
while( PtX + SizeX > VRef.right ) PtX--;
break;
case HORIZ_DIR: SizeX = Size;
SizeY = 20;
while( PtY + SizeY > VRef.bottom ) PtY--;
break;
}
SetLoc( PtX, PtY );
LineColor = C1;
Color = C2;
Draw();
}

void ScrollBar::SetLoc( int PtX, int PtY )
{
Point::SetLoc( PtX, PtY );
while( ( x + SizeX ) > VRef.right ) SizeX--;
while( ( y + SizeY ) > VRef.bottom) SizeY--;
}

void ScrollBar::EraseThumbPad()
{
switch( ScrollMove )
{
case VERT_DIR: setviewport( x+2, y+SPos, x+18, y+SPos+19, TRUE );
break;
case HORIZ_DIR: setviewport( x+SPos, y+2, x+SPos+10, y+18, TRUE );
break;
}
clearviewport();
RestoreViewport();
}

void ScrollBar::SetThumbPad()
{
Outline RectArr;
int OldColor = getcolor();
setviewport( x, y, x+SizeX, y+SizeY, TRUE );
setcolor( LineColor );
setfillstyle( CLOSE_DOT_FILL, Color );
switch( ScrollMove )
{
case VERT_DIR: RectArr[0] = RectArr[2] = RectArr[8] =
RectArr[1] = RectArr[7] = RectArr[9] = SPos;
RectArr[4] = RectArr[6] = 18;
RectArr[3] = RectArr[5] = SPos+19;
break;
case HORIZ_DIR: RectArr[0] = RectArr[2] = RectArr[8] = SPos;
RectArr[1] = RectArr[7] = RectArr[9] = 2;
RectArr[4] = RectArr[6] = SPos+19;
RectArr[3] = RectArr[5] = 19;
break;
}
fillpoly( 5, RectArr );
setcolor( OldColor );
RestoreViewport();
}

void ScrollBar::SetOutline()
{
Outline RectArr;

setcolor( LineColor );
setviewport( x, y, x+SizeX, y+SizeY, TRUE );
RectArr[0] = RectArr[2] = RectArr[8] = 1;
RectArr[1] = RectArr[7] = RectArr[9] = 1;
RectArr[4] = RectArr[6] = SizeX-1;
RectArr[3] = RectArr[5] = SizeY-1;
setfillstyle( SOLID_FILL, Color );
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
fillpoly( 5, RectArr );
setfillstyle( SOLID_FILL, getbkcolor() );
switch( ScrollMove )
{
case VERT_DIR: RectArr[1] = RectArr[7] = RectArr[9] = 21;
RectArr[3] = RectArr[5] = SizeY-21;
break;
case HORIZ_DIR: RectArr[0] = RectArr[2] = RectArr[8] = 21;
RectArr[4] = RectArr[6] = SizeX-21;
break;
}
fillpoly( 5, RectArr );
}

void ScrollBar::SetArrows()
{
setcolor( getbkcolor() );
setlinestyle( SOLID_LINE, 0, THICK_WIDTH );
switch( ScrollMove )
{
case VERT_DIR: line( 10, 4, 4, 12 );
line( 10, 4, 16, 12 );
line( 10, 4, 10, 16 );
line( 10, SizeY-4, 4, SizeY-12 );
line( 10, SizeY-4, 16, SizeY-12 );
line( 10, SizeY-4, 10, SizeY-16 );
break;
case HORIZ_DIR: line( 4, 10, 12, 4 );
line( 4, 10, 12, 16 );
line( 4, 10, 16, 10 );
line( SizeX-4, 10, SizeX-12, 4 );
line( SizeX-4, 10, SizeX-12, 16 );
line( SizeX-4, 10, SizeX-16, 10 );
break;
}
setlinestyle( SOLID_LINE, 0, NORM_WIDTH );
}

void ScrollBar::Draw()
{
int OldColor = getcolor();
SetOutline();
SetArrows();
SetThumbPad();
setcolor( OldColor );
}

void ScrollBar::Erase()
{
gmouse.Mshow( FALSE );
setviewport( x, y, x+SizeX, y+SizeY, TRUE );
clearviewport();
RestoreViewport();
gmouse.Mshow( TRUE );
}

HitType ScrollBar::ScrollHit()
{
HitType Result= NO_HIT;
int NPos = 0;
Mstatus P = gmouse.Mpressed( ButtonL );
switch( ScrollMove )
{
case VERT_DIR: if( ( P.xaxis >= x ) &&
( P.xaxis <= x+20 ) &&
( P.yaxis >= y ) )
if( P.yaxis <= y+20 )
Result = UP;
else
if( P.yaxis <= y+SizeY-31 )
Result = VBAR;
else
if( P.yaxis <= y+SizeY )
Result = DOWN;
break;
case HORIZ_DIR: if( ( P.yaxis >= y ) &&
( P.yaxis <= y+20 ) &&
( P.xaxis >= x ) )
if( P.xaxis <= x+20 )
Result = LEFT;
else
if( P.xaxis <= x+SizeX-31 )
Result = HBAR;
else
if( P.xaxis <= x+SizeX )
Result = RIGHT;
break;
}

if( Result == NO_HIT ) return ( Result );

switch( Result )
{
case LEFT:
case UP: NPos = SPos - Step;
break;
case RIGHT:
case DOWN: NPos = SPos + Step;
break;
case HBAR: NPos = P.xaxis - ( x + 10 );
break;
case VBAR: NPos = P.yaxis - ( y + 10 );
break;
}

if( NPos < 21 ) NPos = 21;
switch( Result )
{
case LEFT:
case RIGHT: if( NPos > SizeX-41 ) NPos = SizeX-41;
break;
case UP:
case DOWN: if( NPos > SizeY-41 ) NPos = SizeY-41;
break;
}

gmouse.Mshow( FALSE );
EraseThumbPad();
SPos = NPos;
SetThumbPad();
gmouse.Mshow( TRUE );
return( Result );
}

int ScrollBar::GetPosition() { return( SPos ); }

int ScrollBar::GetDirection() { return( ScrollMove ); }

int ScrollBar::GetPercent()
{
switch( ScrollMove )
{
case VERT_DIR: return( 100*(double) (SPos-21)/ (double) (SizeY-41) );
case HORIZ_DIR: return( 100*(double) (SPos-21)/ (double) (SizeX-41) );
}
}



  3 Responses to “Category : C Source Code
Archive   : C_ROTATE.ZIP
Filename : GCONTROL.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/