/* depends on math.h */
typedef struct rectangleT rectangle ;
typedef rectangle* rectangleptr;
struct rectangleT
{
int left ;
int top ;
int right ;
int bottom ;
long color;
};
/* left corner x,y and width & height */
VOID drawRectangleSides ( HWND hwnd , int x , int y , int w , int h , long color )
{ int i = 0;
HDC hdc;
if( w < 0 && h < 0 )
{ /* errors message box */
}
else /* draw top, bottom,left,right sides*/
{
hdc = GetDC(hwnd);
for( i=x; i < x+w ; i++)
{ SetPixel( hdc , i , y , color ); }
for( i=x; i < x+w ; i++)
{ SetPixel( hdc , i , y+h , color ); }
for( i=y; i < y+h ; i++)
{ SetPixel( hdc , x , i , color ); }
for( i=y; i <= y+h ; i++)
{ SetPixel( hdc , x+w , i , color ); }
ReleaseDC(hwnd, hdc);
} /* end if else */
}/* end drawRectangleSides function */
/* draw rect bound by two x,y */
VOID drawRectangle ( HWND hwnd , int Ax , int Ay , int Bx , int By , long color )
{
int rectangleHeight ;
int rectangleWidth ;
int startx;
int starty;
/* assuming all points are positive */
rectangleHeight =abs( Ay - By );
rectangleWidth = abs( Ax - Bx );
/* find top left corner x = smallest x */
if( Bx > Ax ) /* left to right */
{ startx = Ax;
}
else /* right to left */
{ startx = Bx; }
/* find top left corner y = smallest y */
if( By > Ay ) /* top to bottom */
{ starty = Ay;
}
else /* bottom point is smaller to top */
{ starty = By; }
drawRectangleSides ( hwnd , startx , starty , rectangleWidth , rectangleHeight , color);
}/* end drawRectangle function */
/* draw filled rect with x,y and height width*/
int drawRectangleSolidSides ( HWND hwnd , int x , int y , int w , int h , long color )
{ int i = 0;
int k = 0;
HDC hdc;
if( w < 0 && h < 0 )
{ /* errors message box */
}
else /* draw top, bottom,left,right sides*/
{
hdc = GetDC(hwnd);
for( k = y ; k <= y+h ; k++)
{
for( i=x; i <= x+w ; i++)
{
SetPixel( hdc , i , k , color );
}
}
ReleaseDC(hwnd, hdc);
} /* end if else */
}/* end drawRectangleSolidSides function */
/* draw filled rect bound by two x,y */
VOID drawRectangleSolid ( HWND hwnd , int Ax , int Ay , int Bx , int By , long color )
{
int rectangleHeight ;
int rectangleWidth ;
int startx;
int starty;
/* assuming all points are positive */
rectangleHeight =abs( Ay - By );
rectangleWidth = abs( Ax - Bx );
/* find top left corner x = smallest x */
if( Bx > Ax ) /* left to right */
{ startx = Ax;
}
else /* right to left */
{ startx = Bx; }
/* find top left corner y = smallest y */
if( By > Ay ) /* top to bottom */
{ starty = Ay;
}
else /* bottom point is smaller to top */
{ starty = By; }
drawRectangleSolidSides ( hwnd , startx , starty , rectangleWidth , rectangleHeight , color);
}/* end drawRectangleSolid function */
VOID clearRectangle ( HWND hwnd , rectangle target )
{ HDC hdc;
RECT rc;
rc.left = target.left ;
rc.top = target.top;
/* don't know why I have to +1 */
rc.right = target.right +1;
rc.bottom = target.bottom +1;
hdc = GetDC( hwnd );
FillRect( hdc , &rc , (HBRUSH) GetStockObject(WHITE_BRUSH) );
ReleaseDC(hwnd, hdc);
}/* end clearRectangle function */