test/testdrawchessboard.c
changeset 9922 b066d5fd5fa7
parent 9836 3d43bb56c5d6
child 9998 f67cf37e9cd4
     1.1 --- a/test/testdrawchessboard.c	Wed Nov 25 21:31:02 2015 +0100
     1.2 +++ b/test/testdrawchessboard.c	Wed Nov 25 21:39:28 2015 +0100
     1.3 @@ -30,28 +30,28 @@
     1.4  void
     1.5  DrawChessBoard(SDL_Renderer * renderer)
     1.6  {
     1.7 -	int row = 0,column = 0,x = 0;
     1.8 -	SDL_Rect rect, darea;
     1.9 +    int row = 0,column = 0,x = 0;
    1.10 +    SDL_Rect rect, darea;
    1.11  
    1.12 -	/* Get the Size of drawing surface */
    1.13 -	SDL_RenderGetViewport(renderer, &darea);
    1.14 +    /* Get the Size of drawing surface */
    1.15 +    SDL_RenderGetViewport(renderer, &darea);
    1.16  
    1.17 -	for( ; row < 8; row++)
    1.18 -	{
    1.19 -		column = row%2;
    1.20 -		x = column;
    1.21 -		for( ; column < 4+(row%2); column++)
    1.22 -		{
    1.23 -			SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
    1.24 +    for( ; row < 8; row++)
    1.25 +    {
    1.26 +        column = row%2;
    1.27 +        x = column;
    1.28 +        for( ; column < 4+(row%2); column++)
    1.29 +        {
    1.30 +            SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);
    1.31  
    1.32 -			rect.w = darea.w/8;
    1.33 -			rect.h = darea.h/8;
    1.34 -			rect.x = x * rect.w;
    1.35 -			rect.y = row * rect.h;
    1.36 -			x = x + 2;
    1.37 -			SDL_RenderFillRect(renderer, &rect);
    1.38 -		}
    1.39 -	}
    1.40 +            rect.w = darea.w/8;
    1.41 +            rect.h = darea.h/8;
    1.42 +            rect.x = x * rect.w;
    1.43 +            rect.y = row * rect.h;
    1.44 +            x = x + 2;
    1.45 +            SDL_RenderFillRect(renderer, &rect);
    1.46 +        }
    1.47 +    }
    1.48  }
    1.49  
    1.50  void
    1.51 @@ -59,77 +59,77 @@
    1.52  {
    1.53      SDL_Event e;
    1.54      while (SDL_PollEvent(&e)) {
    1.55 -		if (e.type == SDL_QUIT) {
    1.56 -			done = 1;
    1.57 +        if (e.type == SDL_QUIT) {
    1.58 +            done = 1;
    1.59  #ifdef __EMSCRIPTEN__
    1.60 -			emscripten_cancel_main_loop();
    1.61 +            emscripten_cancel_main_loop();
    1.62  #endif
    1.63 -			return;
    1.64 -		}
    1.65 +            return;
    1.66 +        }
    1.67  
    1.68 -		if ((e.type == SDL_KEYDOWN) && (e.key.keysym.sym == SDLK_ESCAPE)) {
    1.69 -			done = 1;
    1.70 +        if ((e.type == SDL_KEYDOWN) && (e.key.keysym.sym == SDLK_ESCAPE)) {
    1.71 +            done = 1;
    1.72  #ifdef __EMSCRIPTEN__
    1.73 -			emscripten_cancel_main_loop();
    1.74 +            emscripten_cancel_main_loop();
    1.75  #endif
    1.76 -			return;
    1.77 -		}
    1.78 -	}
    1.79 -	
    1.80 -	DrawChessBoard(renderer);
    1.81 -	
    1.82 -	/* Got everything on rendering surface,
    1.83 -	   now Update the drawing image on window screen */
    1.84 -	SDL_UpdateWindowSurface(window);
    1.85 +            return;
    1.86 +        }
    1.87 +    }
    1.88 +
    1.89 +    DrawChessBoard(renderer);
    1.90 +
    1.91 +    /* Got everything on rendering surface,
    1.92 +       now Update the drawing image on window screen */
    1.93 +    SDL_UpdateWindowSurface(window);
    1.94  }
    1.95  
    1.96  int
    1.97  main(int argc, char *argv[])
    1.98  {
    1.99 -	SDL_Surface *surface;
   1.100 +    SDL_Surface *surface;
   1.101  
   1.102      /* Enable standard application logging */
   1.103      SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
   1.104  
   1.105 -	/* Initialize SDL */
   1.106 -	if(SDL_Init(SDL_INIT_VIDEO) != 0)
   1.107 -	{
   1.108 -		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
   1.109 -		return 1;
   1.110 -	}
   1.111 +    /* Initialize SDL */
   1.112 +    if(SDL_Init(SDL_INIT_VIDEO) != 0)
   1.113 +    {
   1.114 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
   1.115 +        return 1;
   1.116 +    }
   1.117  
   1.118  
   1.119 -	/* Create window and renderer for given surface */
   1.120 -	window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
   1.121 -	if(!window)
   1.122 -	{
   1.123 -		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
   1.124 -		return 1;
   1.125 -	}	
   1.126 -	surface = SDL_GetWindowSurface(window);
   1.127 -	renderer = SDL_CreateSoftwareRenderer(surface);
   1.128 -	if(!renderer)
   1.129 -	{
   1.130 -		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
   1.131 -		return 1;
   1.132 -	}
   1.133 +    /* Create window and renderer for given surface */
   1.134 +    window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
   1.135 +    if(!window)
   1.136 +    {
   1.137 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
   1.138 +        return 1;
   1.139 +    }
   1.140 +    surface = SDL_GetWindowSurface(window);
   1.141 +    renderer = SDL_CreateSoftwareRenderer(surface);
   1.142 +    if(!renderer)
   1.143 +    {
   1.144 +        SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
   1.145 +        return 1;
   1.146 +    }
   1.147  
   1.148 -	/* Clear the rendering surface with the specified color */
   1.149 -	SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
   1.150 -	SDL_RenderClear(renderer);
   1.151 +    /* Clear the rendering surface with the specified color */
   1.152 +    SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
   1.153 +    SDL_RenderClear(renderer);
   1.154  
   1.155  
   1.156 -	/* Draw the Image on rendering surface */
   1.157 -	done = 0;
   1.158 +    /* Draw the Image on rendering surface */
   1.159 +    done = 0;
   1.160  #ifdef __EMSCRIPTEN__
   1.161      emscripten_set_main_loop(loop, 0, 1);
   1.162  #else
   1.163      while (!done) {
   1.164          loop();
   1.165 -	}
   1.166 +    }
   1.167  #endif
   1.168  
   1.169      SDL_Quit();
   1.170 -	return 0;
   1.171 +    return 0;
   1.172  }
   1.173