Logo Search packages:      
Sourcecode: tagua version File versions  Download package

void Board::updateBorder (  )  [private]

this internal function updates the border after the board has been resized

Definition at line 213 of file board.cpp.

References boardRect(), PixmapLoader::getValue(), m_border_text, m_border_text_far, m_border_text_near, m_canvas_border, m_controls_loader, m_flipped, m_sprites, and m_square_size.

Referenced by flip(), onResize(), and recreateBorder().

                         {
  while(!m_canvas_border->items()->isEmpty())
    delete m_canvas_border->items()->first();

  if(!m_square_size)
    return;

  int at = 0;
  for(int w = 0; w<2; w++)
  for(int i = 0;i<m_sprites.getSize().x;i++) {
    int x = (m_flipped  ?  (m_sprites.getSize().x-1-i)  :  i)*m_square_size;
    int y = w  ?  -m_border_text_far  :  m_square_size*m_sprites.getSize().y+m_border_text_near;

    m_border_text[at]->setVisible(m_border_text_near != m_border_text_far);
    m_border_text[at]->setConstrainRect(QRect(x,y,m_square_size,m_border_text_far-m_border_text_near));
    at++;
  }

  for(int w = 0; w<2; w++)
  for(int i = 0;i<m_sprites.getSize().y;i++) {
    int x = w  ?  (-m_border_text_far-m_border_text_near)/2
               :  m_square_size*m_sprites.getSize().x + (m_border_text_far+m_border_text_near)/2;
    int y = (!m_flipped  ?  (m_sprites.getSize().y-1-i)  :  i)*m_square_size
                + (m_square_size-m_border_text_far-m_border_text_near)/2;

    m_border_text[at]->setVisible(m_border_text_near != m_border_text_far);
    m_border_text[at]->setConstrainRect(QRect(x-m_square_size/2,y,m_square_size,m_border_text_far-m_border_text_near));
    at++;
  }

  ::LuaApi::LuaValueMap params;
  params["width"] = m_square_size*m_sprites.getSize().x;
  params["height"] = m_square_size*m_sprites.getSize().y;
  Loader::PixmapOrMap bord = m_controls_loader.getValue<Loader::PixmapOrMap>("border", &params);
  if(const QPixmap* p = boost::get<QPixmap>(&bord)) {
    KGameCanvasTiledPixmap *t = new KGameCanvasTiledPixmap(*p, boardRect().size(), QPoint(),
                                    true, m_canvas_border);
    t->show();
  }
  else if(const Loader::PixmapMap* p = boost::get<Loader::PixmapMap>(&bord)) {
    for(Loader::PixmapMap::const_iterator it = p->begin(); it != p->end(); ++it) {
      KGameCanvasTiledPixmap *t = new KGameCanvasTiledPixmap(it->second, it->first.size(),
                                      QPoint(), true, m_canvas_border);
      t->moveTo(it->first.topLeft());
      t->show();
    }
  }
  else
    kError() << "Board::updateBorder(): unexpected type in boost::variant!";
}


Generated by  Doxygen 1.6.0   Back to index