Esempio n. 1
0
VOID ShowStatusLine( const HPS hps, const char Moves,
							const char Ships, const LONG Width,
							const LONG Height )
{
    RECTL Rect = { 0, Height, Width, Height + 30 };
    POINTL Point = { Width, Height };
    CHAR text[256];
 
    WinFillRect( hps, &Rect, CLR_WHITE ); //SYSCLR_WINDOW );	// clear background
    GpiSetColor( hps, CLR_BLACK );
    GpiSetLineType( hps, LINETYPE_SHORTDASH );
    GpiSetLineWidth( hps, LINEWIDTH_NORMAL );
    GpiSetMix( hps, FM_OVERPAINT );
    GpiMove( hps, &Point );
    Point.x = 0;
    GpiLine( hps, &Point );
    Point.x += 10;
    Point.y += 10;
    GpiMove( hps, &Point );
    if( Ships )
	sprintf( text, "%d %s made     %d %s still lost", Moves,
		 Moves == 1 ? "move" : "moves", Ships, Ships == 1 ? "ship" : "ships" );
    else
	sprintf( text, "%d %s made     All ships found", Moves,
		 Moves == 1 ? "move" : "moves" );

    GpiCharString( hps, strlen(text), text );
    DosSleep( 1 );	// free time slice 
} 
/*--------------------------------------------------
 * Draws the 3D border
 *-------------------------------------------------*/
void PMWindow::draw_3dborder( HPS ps, const SHAPE& rect, long thickness )
{
  LONG palette_format;

  if( !GpiQueryColorData( ps, 1, &palette_format ))
    PM_THROW_GUIERROR();

  LONG white    = palette_format == LCOLF_RGB ? RGB_WHITE    : CLR_WHITE;
  LONG darkgray = palette_format == LCOLF_RGB ? RGB_DARKGRAY : CLR_DARKGRAY;
  LONG palegray = palette_format == LCOLF_RGB ? RGB_PALEGRAY : CLR_PALEGRAY;
  LONG black    = palette_format == LCOLF_RGB ? RGB_BLACK    : CLR_BLACK;

  POINTL pos;
  GpiSetLineWidth( ps, LINEWIDTH_NORMAL );

  pos.y = rect.y;
  pos.x = rect.x;
  GpiMove( ps, &pos );

  GpiSetColor( ps, white );
  pos.x = rect.x+rect.cx-1;
  GpiLine( ps, &pos );
  pos.y = rect.y+rect.cy-1;
  GpiLine( ps, &pos );

  GpiSetColor( ps, darkgray );
  pos.x = rect.x;
  GpiLine( ps, &pos );
  pos.y = rect.y;
  GpiLine( ps, &pos );

  if( thickness > 1 )
  {
    pos.y = rect.y+1;
    pos.x = rect.x+1;
    GpiMove( ps, &pos );

    GpiSetColor( ps, palegray );
    pos.x = rect.x+rect.cx-2;
    GpiLine( ps, &pos );
    pos.y = rect.y+rect.cy-2;
    GpiLine( ps, &pos );

    GpiSetColor( ps, black );
    pos.x = rect.x+1;
    GpiLine( ps, &pos );
    pos.y = rect.y+1;
    GpiLine( ps, &pos );
  }
}
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     {
     static INT  cxClient, cyClient ;
     static LONG alJoin [] = { LINEJOIN_BEVEL, LINEJOIN_ROUND, LINEJOIN_MITRE },
                 alEnd  [] = { LINEEND_FLAT, LINEEND_SQUARE, LINEEND_ROUND } ;
     HPS         hps ;
     INT         i ;

     switch (msg)
	  {
          case WM_SIZE:
               cxClient = SHORT1FROMMP (mp2) ;
               cyClient = SHORT2FROMMP (mp2) ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ;

               GpiErase (hps) ;

               for (i = 0 ; i < 3 ; i++)
                    {
                              // Draw the geometric line

                    GpiSetLineJoin (hps, alJoin [i]) ;
                    GpiSetLineEnd  (hps, alEnd  [i]) ;
                    GpiSetLineWidthGeom (hps, cxClient / 20) ;
                    GpiSetColor (hps, CLR_DARKGRAY) ;

                    GpiBeginPath (hps, 1) ;
                    DrawFigure (hps, i, cxClient, cyClient) ;
                    GpiEndPath (hps) ;

                    GpiStrokePath (hps, 1, 0) ;

                              // Draw the cosmetic line

                    GpiSetLineWidth (hps, LINEWIDTH_THICK) ;
                    GpiSetColor (hps, CLR_BLACK) ;

                    DrawFigure (hps, i, cxClient, cyClient) ;
                    }

               WinEndPaint (hps) ;
               return 0 ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }
Esempio n. 4
0
/*
	draw_thread
	This is the drawing-thread.
	You have a valid presentation space handle (hps), a valid window
	handle (hwndSaver) and the configuration_data structure is loaded.
	The screen size is stored in "screenSizeX" and "screenSizeY".
	IMPORTANT NOTE 1:
	You must check the "stop_draw_thread" flag regularly. If it is set,
	free all resources you have allocated and call _endthread (or just
	return) to end the drawing-thread.
	IMPORTANT NOTE 2:
	If the "low_priority" flag is NOT set (that means you run with
	regular priority, sharing CPU usage with other programs), you should
	call DosSleep(x) with "x" set at least to 1 as often as possible, to
	allow other programs to do their work. A screen saver should not eat
	up other program's CPU time!
	IMPORTANT NOTE 3:
	For some of the PM calls to work properly, your thread needs an
	own HAB and maybe even a message queue. You have to get and release
	both of them here if you use such PM calls.

	The following sample code is from the "Pyramids" module that comes
	with the ScreenSaver distribution.
	It selects a random color and a random point on the screen, then
	draws lines in the selected color from each corner of the screen
	to the selected point (looks somewhat like a pyramid).
	It remembers a number of points (this number can be set in the
	configuration dialog). Having filled the point memory, it redraws
	the "oldest" visible pyramid in black. This has the effect that more
	and more pixels on the screen get black, only a few constantly
	changing colored lines remain.
*/
void draw_thread(void *args)
    {
	int i, j;
	const RECTL ScreenRect = { 0, 0, screenSizeX, screenSizeY };
	int color_count = 0;
	ULONG color;
	int pushleftx = 11, pushlefty = 11, pushrightx = 11, pushrighty = 11;
	BOOL	point_buffer_filled;
	BOOL first_paint = TRUE;
	POINTL	*ptleft, *ptright;
	EXCEPTIONREGISTRATIONRECORD xcpthand = { 
	    (PEXCEPTIONREGISTRATIONRECORD)0, GPFHandler };

	DosSetExceptionHandler(&xcpthand) ;

	i = 0;
	point_buffer_filled = FALSE;
	/* allocate memory for circular point buffer	*/
	ptleft = malloc(configuration_data.count * sizeof(POINTL));
	ptright = malloc(configuration_data.count * sizeof(POINTL));
	if( (ptleft == NULL) || (ptright == NULL) ) goto end;
	GpiSetLineWidth( hps, LINEWIDTH_THICK );

	srand(WinGetCurrentTime(hab));
	
	do{
	    color = ((unsigned)rand()) % 17 - 2;
	}while ( color == -1 || color == 0 || color == 7 || color == 8 );
	/* blank screen if requested	*/
	if( configuration_data.blank_screen )
	    WinFillRect( hps, &ScreenRect, CLR_BLACK );

	while(!stop_draw_thread){

	    if(point_buffer_filled){
		/* redraw old line in black	*/
		GpiSetColor(hps, CLR_BLACK);
		GpiMove(hps, &ptleft[i]);
		GpiLine(hps, &ptright[i]);
	    }
	    if( color_count == configuration_data.colors ){
		/* select random color	*/
		do{
		    color = ((unsigned)rand()) % 17 - 2;
		}while ( color == -1 || color == 0 || color == 7 || color == 8 );
		color_count = 0;
	    }
	    GpiSetColor(hps, color);
	    color_count++;	
	    if (first_paint ){		
		/* set the start coordinates	*/
		ptleft[0].x = rand() % screenSizeX;
		ptleft[0].y = rand() % screenSizeY;
		ptright[0].x = rand() % screenSizeX;
		ptright[0].y = rand() % screenSizeY;
		first_paint = FALSE;
	    } else {
		/* calculate new line points	*/
		j = i==0 ? configuration_data.count - 1 : i - 1;
		ptleft[i].x = ptleft[j].x + pushleftx; 
		ptleft[i].y = ptleft[j].y + pushlefty; 
		ptright[i].x = ptright[j].x + pushrightx;
		ptright[i].y = ptright[j].y + pushrighty; 
	    }

	    /* adjust lines if they hit a screen border */
	    if( ptleft[i].x >= screenSizeX ) {
		ptleft[i].x = 2 * screenSizeX - ptleft[i].x;
		pushleftx = - pushleftx + (rand() % 2);
	    }	
	    if( ptleft[i].y >= screenSizeY ) {
		ptleft[i].y = 2 * screenSizeY - ptleft[i].y;
		pushlefty = - pushlefty + (rand() % 2);
	    }	
	    if( ptright[i].x >= screenSizeX ) {
		ptright[i].x = 2 * screenSizeX - ptright[i].x;
		pushrightx = - pushrightx + ( rand() % 2);
	    }	
	    if( ptright[i].y >= screenSizeY ) {
		ptright[i].y = 2 * screenSizeY - ptright[i].y;
		pushrighty = - pushrighty + ( rand() % 2);
	    }
	    if( ptleft[i].x < 0 ) {	
		ptleft[i].x *= -1;
		pushleftx = - pushleftx + (rand() % 2);
	    }	
	    if( ptleft[i].y < 0 ) {
		ptleft[i].y *= -1;
		pushlefty = - pushlefty + (rand() % 2);
	    }	
	    if( ptright[i].x < 0 ) {
		ptright[i].x *= -1;
		pushrightx = - pushrightx + (rand() % 2);
	    }	
	    if( ptright[i].y < 0 ) {
		ptright[i].y *= -1;
		pushrighty = - pushrighty + (rand() % 2);
	    }	
		
	    /* draw line	*/
	    GpiMove(hps, &ptleft[i]);
	    GpiLine(hps, &ptright[i]);

	    /* sleep if necessary	*/
	    if(low_priority == FALSE)
		DosSleep(1);

	    // sleep if user requests slower animation
				 switch(configuration_data.animation_speed){
				 case 4: break;
				 case 3: DosSleep(10); break;
				 case 2: DosSleep(30); break;
				 case 1: DosSleep(50); break;
				 case 0: DosSleep(70); break;
				 }
	    i++;
	    /* move circular buffer index	*/
	    if(i == configuration_data.count){
		point_buffer_filled = TRUE;
		i = 0;
	    }	
	}
	/* free resources	*/
      end:  // goto from memory allocation
	free( ptleft );
	free( ptright );
	DosUnsetExceptionHandler(&xcpthand);
	_endthread();
    }
MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     {
     static INT  cxClient, cyClient ;
     HPS         hps ;
     INT         x, y ;
     POINTL      ptl ;

     switch (msg)
	  {
          case WM_SIZE:
               cxClient = SHORT1FROMMP (mp2) ;
               cyClient = SHORT2FROMMP (mp2) ;
               return 0 ;

          case WM_PAINT:
               hps = WinBeginPaint (hwnd, NULLHANDLE, NULL) ;

               GpiErase (hps) ;

               for (x = 0 ; x < 3 ; x++)
               for (y = 0 ; y < 2 ; y++)
                    {
                         // Create an open sub-path

                    GpiBeginPath (hps, 1) ;

                    ptl.x = (1 + 10 * x) * cxClient / 30 ;
                    ptl.y = (4 +  5 * y) * cyClient / 10 ;
                    GpiMove (hps, &ptl) ;

                    ptl.x = (5 + 10 * x) * cxClient / 30 ;
                    ptl.y = (2 +  5 * y) * cyClient / 10 ;
                    GpiLine (hps, &ptl) ;

                    ptl.x = (9 + 10 * x) * cxClient / 30 ;
                    ptl.y = (4 +  5 * y) * cyClient / 10 ;
                    GpiLine (hps, &ptl) ;

                         // Create a closed sub-path

                    ptl.x = (1 + 10 * x) * cxClient / 30 ;
                    ptl.y = (3 +  5 * y) * cyClient / 10 ;
                    GpiMove (hps, &ptl) ;

                    ptl.x = (5 + 10 * x) * cxClient / 30 ;
                    ptl.y = (1 +  5 * y) * cyClient / 10 ;
                    GpiLine (hps, &ptl) ;

                    ptl.x = (9 + 10 * x) * cxClient / 30 ;
                    ptl.y = (3 +  5 * y) * cyClient / 10 ;
                    GpiLine (hps, &ptl) ;

                    GpiCloseFigure (hps) ;
                    GpiEndPath (hps) ;

                         // Possibly modify the path

                    if (y == 0)
                         {
                         GpiSetLineWidthGeom (hps, cxClient / 30) ;
                         GpiModifyPath (hps, 1, MPATH_STROKE) ;
                         }

                         // Perform the operation

                    GpiSetLineWidth (hps, LINEWIDTH_THICK) ;
                    GpiSetLineWidthGeom (hps, cxClient / 50) ;
                    GpiSetPattern (hps, PATSYM_HALFTONE) ;

                    switch (x)
                         {
                         case 0:  GpiOutlinePath (hps, 1, 0) ;
                                  break ;

                         case 1:  GpiStrokePath (hps, 1, 0) ;
                                  break ;

                         case 2:  GpiFillPath (hps, 1, FPATH_ALTERNATE) ;
                                  break ;
                         }
                    }

               WinEndPaint (hps) ;
               return 0 ;
          }
     return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
     }
Esempio n. 6
0
VOID GRAPHBOARD::DrawPMBoard( const HPS hps )
{
    POINTL StartHor = LowerLeftPlace;
    POINTL EndHor;
    POINTL StartVert = LowerLeftPlace;
    POINTL EndVert;
    int Value;
	
    EndHor.x = StartHor.x + (Columns - 3) * dist;	// shown cols = Columns - 2
    EndHor.y = StartHor.y;
    EndVert.x = StartVert.x;
    EndVert.y = StartVert.y + (Rows - 3) * dist;

    GpiSetColor( hps, CLR_BLACK );
    GpiSetLineType( hps, LINETYPE_SOLID );
    GpiSetLineWidth( hps, LINEWIDTH_NORMAL );


    if( !InfoData.IsLineStyle(IDC_DIAGONALS) ){
	// first we paint the horizontal lines:
	for( ; StartHor.y <= EndVert.y; StartHor.y += dist, EndHor.y += dist ){
	    GpiMove( hps, &StartHor );
	    GpiLine( hps, &EndHor );
	}
	// then the vertical lines:
	for(; StartVert.x <= EndHor.x; StartVert.x += dist, EndVert.x += dist ){
	    GpiMove( hps, &StartVert );
	    GpiLine( hps, &EndVert );
	}
    }	// end if !InfoData.IsLineStyle( IDC_DIAGONALS )
    DosSleep( 1 );	// free time slice 

    if( !InfoData.IsLineStyle(IDC_VERTICALS) ){
	// there are still some diagonals left:
	// Start... draw from left top to right bottom
	GpiSetLineType( hps, LINETYPE_DOT );
	StartVert.x = LowerLeftPlace.x;
	StartVert.y = LowerLeftPlace.y + dist;
	StartHor.x = LowerLeftPlace.x + dist;
	StartHor.y = LowerLeftPlace.y;

	// End... draw from right top to left bottom
	EndVert.x = LowerLeftPlace.x + ( Columns - 3) * dist;
	EndVert.y = LowerLeftPlace.y + dist;
	EndHor.x = LowerLeftPlace.x + ( Columns - 4) * dist;
	EndHor.y = LowerLeftPlace.y;
		
	int VertBreak = 0;
	int HorBreak = 0;
	while( StartVert.x != StartHor.x || StartVert.y != StartHor.y )
	    {
		GpiMove( hps, &StartHor );
		GpiLine( hps, &StartVert );
		GpiMove( hps, &EndHor );
		GpiLine( hps, &EndVert );
		if( VertBreak ){
		    StartVert.x += dist;
		    EndVert.x -= dist;
		} else {
		    StartVert.y += dist;
		    EndVert.y += dist;
		    if( StartVert.y == LowerLeftPlace.y + (Rows - 3)*dist)
			VertBreak = 1;
		}
		if( HorBreak ){
		    StartHor.y += dist;
		    EndHor.y += dist;
		} else {
		    StartHor.x += dist;
		    EndHor.x -= dist;
		    if( StartHor.x == LowerLeftPlace.x + (Columns - 3 ) * dist )
			HorBreak = 1;
		}
	    }	
    }	// end if !InfoData.IsLineStyle( IDC_VERTICALS )
    DosSleep( 1 );	// free time slice 
	
    // now we insert the values that have already been discovered
    for( char i = 1; i < Rows - 1; i++ ){
	for( char j = 1; j < Columns - 1; j++ ){
	    if( (Value = GetDiscovered( i, j) ) != -1 ){
		DrawPMPlace( hps, i, j, Value, FALSE );
	    } else {	
		ToggleMarked( i, j );
		DrawPMMark( hps, i, j );
	    }
	}			// for j
	DosSleep( 1 );		// free timeslice
    }				// for i
}