예제 #1
0
void doDisplay(node *tree)
{
    SDL_Simplewin sw;
    fntrow font[FNTCHARS][FNTHEIGHT];
    unsigned drawcounter=0;


    /*set up screen*/
    SDL_myInit(&sw);
    Neill_SDL_ReadFont(font, FONTFILE);

    do { /* draw and animate tree */
        SDL_Delay(SDL_LOOP_DELAY);
        drawcounter += SDL_LOOP_DELAY;

        Neill_SDL_Events(&sw);

        if(drawcounter>= LIGHT_CHANGE_DELAY){
            drawcounter=0;
            drawTree(&sw, tree, font);
            Neill_SDL_DrawString(&sw, font, "Xmas (Binary) Tree",
                                        0, TITLE_POS);

            /* update window once */
            SDL_RenderPresent(sw.renderer);
            SDL_UpdateWindowSurface(sw.win);
        }
    }
    while (!sw.finished);

}
예제 #2
0
파일: life.c 프로젝트: zellcht/c
int main(int argc, char *argv[]){
  int x, y, i, j;
  FILE *file;
  char iniBoard[MAX_SIZE][MAX_SIZE];
  int status[MAX_SIZE][MAX_SIZE];
  SDL_Simplewin sw;
  SDL_Rect rectangle;

  file = NULL;
  Neill_SDL_Init(&sw);
  initial(iniBoard, status);
  file = fopen(argv[1], "r");
  /* fopen returns NULL pointer on failure */
  if (file == NULL){
    printf("Could not open file. \n");
  }
  else {
    printf("File (%s) opened. \n", argv[1]);
    fscanf(file, "%d %d", &x, &y);
    printf("Row: %d Column: %d \n", x, y);
    char board[y][x];
    if(fgetc(file) != EOF){
      for(j = 0; j < y; j++){
	for(i = 0; i < x + 1; i++){
	  board[j][i] = fgetc(file);
	}
      }
    }
    /* Closing file */
    fclose(file);
    /* Input the board which read from the txt file to a 50x50 board*/
    inputBoard(x, y, board, iniBoard);
    do{
      /* Sleep for a short time */
      SDL_Delay(MILLISECONDDELAY);
      SDL_RenderClear(sw.renderer);   
      /* Draw the actual board */
      drawBoard(iniBoard, sw, rectangle, x, y);      
      /* Update window */
      SDL_RenderPresent(sw.renderer);
      SDL_UpdateWindowSurface(sw.win); 
      /* Get the neighbours' status */
      getNeighbours(x, y, iniBoard, status);
      /* Calculate next generation */
      nextGen(x, y, iniBoard, status);
      Neill_SDL_Events(&sw);
    }while(!sw.finished);
    /* Clear up graphics subsystems */
    atexit(SDL_Quit);
  }
  return 0;
}
예제 #3
0
/* Display the maze in an SDL GUI */
void display_SDL(max_maze array, maze_dimensions dims){
	
	// Fit the maze to the window height by scaling each cell's dimensions
	int rectsize = WHEIGHT / dims.height; 
	int window_offset = (WWIDTH-WHEIGHT)/2;
	int cx=0, cy =0;
	
	SDL_Simplewin win;
	SDL_Rect rectangle;
	rectangle.w = rectsize;
	rectangle.h = rectsize;
	Neill_SDL_Init(&win);

	do {
		// Draw the array graphically.
		for (int i = 0; i < dims.height; ++i) {
			for (int j = 0; j < dims.width; ++j) {

				if ( array[i][j] == '#' ) {
					Neill_SDL_SetDrawColour(&win,255,255,255); // Set colour to WHITE
					
					// Draw rectangle for each array cell, centred in the window
					rectangle.x = (j * rectsize) + window_offset ;
					rectangle.y = i * rectsize;
					SDL_RenderFillRect(win.renderer, &rectangle);
				} 
				if ( array[i][j] == '.') {	
					Neill_SDL_SetDrawColour(&win,255,128,0); // Set colour to ORANGE

					cx = (j*rectsize) + window_offset + (rectsize/2);
					cy = (i*rectsize) + (rectsize/2);
					Neill_SDL_RenderFillCircle(win.renderer, cx, cy, RADIUS);
				}
			}
		}

		// Update window.
		SDL_RenderPresent(win.renderer);
		SDL_UpdateWindowSurface(win.win);
		Neill_SDL_Events(&win); 		// Check for user kill

		SDL_Delay(MILLISECONDDELAY); 	// Wait a short time

	} while(!win.finished);

	// Cleans up.
	atexit(SDL_Quit);
}
예제 #4
0
int main(void)
{

   SDL_Simplewin sw;
   SDL_Rect rectangle;
   rectangle.w = RECTSIZE;
   rectangle.h = RECTSIZE;

   Neill_SDL_Init(&sw);

   do{

      // Sleep for a short time
      SDL_Delay(MILLISECONDDELAY);

      // Choose a random colour, a mixture of red, green and blue.
      Neill_SDL_SetDrawColour(&sw,
                             rand()%SDL_8BITCOLOUR, rand()%SDL_8BITCOLOUR,
                             rand()%SDL_8BITCOLOUR);

      // Filled Rectangle, fixed size, random position
      rectangle.x = rand()%(WWIDTH-RECTSIZE);
      rectangle.y = rand()%(WHEIGHT-RECTSIZE);
      SDL_RenderFillRect(sw.renderer, &rectangle);

      // Unfilled Rectangle, fixed size, random position
      rectangle.x = rand()%(WWIDTH-RECTSIZE);
      rectangle.y = rand()%(WHEIGHT-RECTSIZE);
      SDL_RenderDrawRect(sw.renderer, &rectangle);

      // Update window - no graphics appear on some devices until this is finished
      SDL_RenderPresent(sw.renderer);
      SDL_UpdateWindowSurface(sw.win); 
      
      // Has anyone pressed ESC or killed the SDL window ?
      // Must be called frequently - it's the only way of escaping 
      Neill_SDL_Events(&sw);

   }while(!sw.finished);


   // Clear up graphics subsystems
   atexit(SDL_Quit);

   return 0;

}
void print_board_SDL(board_struct *current_board, SDL_Simplewin *sw, on_off intermediate_indicator,
					 int row_coordinate, int col_coordinate, success_failure success_index)
{
	int i, j, temp_x, temp_y;
	SDL_Rect rectangle;
	colour_struct colour_range;

   	rectangle.w = RECT_SIZE;
   	rectangle.h = RECT_SIZE;

   	sw->skip_checker = off;

   	for(i = 0; i < BOARD_H; ++i){
   		for(j = 0; j < BOARD_W; ++j){

   			if(success_index == symmetric_successful){

   				temp_x = BOARD_W - BORDER - j;
   				rectangle.x = temp_x * SCALE_FACT + (WWIDTH - SCALE_FACT * BOARD_W) / 2;
   				colour_chooser(current_board, i, j, &colour_range, intermediate_indicator, row_coordinate, BOARD_W - BORDER - col_coordinate);

   			}
   			else{

   				rectangle.x = j * SCALE_FACT + (WWIDTH - SCALE_FACT * BOARD_W) / 2;
   				colour_chooser(current_board, i, j, &colour_range, intermediate_indicator, row_coordinate, col_coordinate);

   			}

   			temp_y = BOARD_H - BORDER - i;
   			rectangle.y = temp_y * SCALE_FACT + (WHEIGHT - SCALE_FACT * BOARD_H) / 2;						//For centering.

   			Neill_SDL_SetDrawColour(sw, colour_range.colour_r, colour_range.colour_g, colour_range.colour_b);
   			SDL_RenderFillRect(sw->renderer, &rectangle);
   		}
   	}

   	SDL_RenderPresent(sw->renderer);
    	SDL_UpdateWindowSurface(sw->win);
    
    	do{
    		Neill_SDL_Events(sw);
    	}while(sw->skip_checker != on && sw->finished != 1);

}
예제 #6
0
void endFrame()	{
	SDL_Simplewin sw = getSw(NULL);
    SDL_RenderPresent(sw->renderer);
    SDL_UpdateWindowSurface(sw->win);	
	Neill_SDL_Events();
}