Esempio n. 1
0
int
main(int argc, char *argv[])
{
	SDL_Window *window;
	SDL_Surface *surface;
	SDL_Renderer *renderer;

    /* Enable standard application logging */
    SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);

	/* Initialize SDL */
	if(SDL_Init(SDL_INIT_VIDEO) != 0)
	{
		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError());
		return 1;
	}


	/* Create window and renderer for given surface */
	window = SDL_CreateWindow("Bonjour", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN);
	if(!window)
	{
		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());
		return 1;
	}	
	surface = SDL_GetWindowSurface(window);
	renderer = SDL_CreateSoftwareRenderer(surface);
	if(!renderer)
	{
		SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Render creation for surface fail : %s\n",SDL_GetError());
		return 1;
	}

	/* Clear the rendering surface with the specified color */
	SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
	SDL_RenderClear(renderer);


	/* Draw the Image on rendering surface */
	while(1)
	{
		SDL_Event e;
		if (SDL_PollEvent(&e)) {
			if (e.type == SDL_QUIT) 
				break;

			if(e.key.keysym.sym == SDLK_ESCAPE)
				break;
		}
		
		DrawChessBoard(renderer);
		
		/* Got everything on rendering surface,
 		   now Update the drawing image on window screen */
		SDL_UpdateWindowSurface(window);

	}

	return 0;
}
Esempio n. 2
0
void InitialiseStage()
{
    REG_DISPCNT = DCNT_MODE0 | DCNT_OBJ | DCNT_OBJ_1D | DCNT_BG0 | DCNT_BG1 | DCNT_BG2 | DCNT_BG3;


    REG_BG0CNT = BG_CBB(0) | BG_SBB(30) | BG_8BPP | BG_REG_32x32;
    REG_BG1CNT = BG_CBB(1) | BG_SBB(29) | BG_8BPP | BG_REG_32x32;
    REG_BG2CNT = BG_CBB(1) | BG_SBB(28) | BG_8BPP | BG_REG_32x32;
    REG_BG3CNT = BG_CBB(1) | BG_SBB(27) | BG_8BPP | BG_REG_32x32;

    DrawChessBoard();
    PlacePieces();
}
void ribi::Chess::QtChessBoardWidget::paintEvent(QPaintEvent *)
{
  QPainter painter(this);
  DrawChessBoard( painter,this->m_widget.get());
}
void ribi::Chess::QtChessBoardWidget::DrawChessBoard(
  QPainter& painter,
  const Chess::BoardWidget * const widget)
{
  const int w = widget->GetWidth();
  const int h = widget->GetHeight();

  //Draw the plain chessboard
  DrawChessBoard(
    painter,
    widget->GetLeft(),
    widget->GetTop(),
    w,
    h,
    widget->GetBoard().get());
  //Draw the selected square
  static const Chess::QtResources r;
  const int square_w = w / 8;
  const int square_h = h / 8;


  const boost::shared_ptr<const Chess::Square> selected = widget->GetSelector()->GetSelected();
  if (selected)
  {
    TRACE_FUNC();
    const int x_co = selected->GetFile().ToInt() * square_w;
    const int y_co = selected->GetRank().ToInt() * square_h;
    if (widget->GetBoard()->GetPiece(selected))
    {
      const std::string filename = Chess::Resources::Find(
        widget->GetBoard()->GetPiece(selected),
        Chess::SquareSelector::m_selected_color,
        true);
      TRACE(filename);
      assert(fileio::FileIo().IsRegularFile(filename));
      const QPixmap p(filename.c_str());
      painter.drawPixmap(x_co,y_co,square_w,square_h,p);
    }
    else
    {
      assert(!"Should not get here");
    }

    //Draw the possible moves

    const std::vector<boost::shared_ptr<Move> > moves = widget->GetBoard()->GetMoves(selected);
    for(const boost::shared_ptr<Move> move: moves)
    {
      if (move->To())
      {
        const int x_co = move->To()->GetFile().ToInt() * square_w;
        const int y_co = move->To()->GetRank().ToInt() * square_h;
        if (widget->GetBoard()->GetPiece(move->To()))
        {
          const std::string filename = Chess::Resources::Find(
            widget->GetBoard()->GetPiece(move->To()),
            Chess::SquareSelector::m_moves_color);
          assert(fileio::FileIo().IsRegularFile(filename));
          const QPixmap p(filename.c_str());
          painter.drawPixmap(x_co,y_co,square_w,square_h,p);
        }
        else
        {
          const boost::shared_ptr<Square> square {
            SquareFactory().Create(move->To()->GetFile(),move->To()->GetRank())
          };
          const std::string filename
            = Chess::Resources::Find(
              square,
              Chess::SquareSelector::m_moves_color);
          assert(fileio::FileIo().IsRegularFile(filename));
          const QPixmap p(filename.c_str());
          painter.drawPixmap(x_co,y_co,square_w,square_h,p);
        }
      }
    }
  }
  //Draw cursor
  const boost::shared_ptr<const Chess::Square> cursor = widget->GetSelector()->GetCursor();
  assert(cursor);
  {
    const int x_co = cursor->GetFile().ToInt() * square_w;
    const int y_co = cursor->GetRank().ToInt() * square_h;
    if (widget->GetBoard()->GetPiece(cursor))
    {
      const std::string filename = Chess::Resources::Find(widget->GetBoard()->GetPiece(cursor),
        Chess::SquareSelector::m_cursor_color,
        selected && *selected == *cursor );
      assert(fileio::FileIo().IsRegularFile(filename));
      const QPixmap p(filename.c_str());
      painter.drawPixmap(x_co,y_co,square_w,square_h,p);
    }
    else
    {
      const std::string filename
        = Chess::Resources::Find(
          cursor,
          Chess::SquareSelector::m_cursor_color);
      assert(fileio::FileIo().IsRegularFile(filename));
      const QPixmap p(filename.c_str());
      painter.drawPixmap(x_co,y_co,square_w,square_h,p);
    }
  }
}