예제 #1
0
파일: cell.cpp 프로젝트: radekp/qneoroid
void Cell::initPixmaps()
{
  typedef QMap<int, QString> NamesMap;
  NamesMap names;
  names[L]     = "0001";
  names[D]     = "0010";
  names[D|L]   = "0011";
  names[R]     = "0100";
  names[R|L]   = "0101";
  names[R|D]   = "0110";
  names[R|D|L] = "0111";
  names[U]     = "1000";
  names[U|L]   = "1001";
  names[U|D]   = "1010";
  names[U|D|L] = "1011";
  names[U|R]   = "1100";
  names[U|R|L] = "1101";
  names[U|R|D] = "1110";

  NamesMap::ConstIterator it;
  for(it = names.constBegin(); it != names.constEnd(); ++it)
  {
    connectedpixmap[it.key()] = new QPixmap(":/cable" + it.value() + ".png");

    QImage image = connectedpixmap[it.key()]->toImage();
    for(int y = 0; y < image.height(); y++)
    {
      QRgb* line = (QRgb*)image.scanLine(y);
      for(int x = 0; x < image.width(); x++)
      {
        QRgb pix = line[x];
        if(qAlpha(pix) == 255)
        {
          int g = (255 + 4 * qGreen(pix)) / 5;
          int b = (255 + 4 * qBlue(pix)) / 5;
          int r = (255 + 4 * qRed(pix)) / 5;
          line[x] = qRgb(r, g, b);
        }
      }
    }

    disconnectedpixmap[it.key()] = new QPixmap(QPixmap::fromImage(image));
  }
}
예제 #2
0
void Cell::initPixmaps()
{
    typedef QMap<int, QString> NamesMap;
    NamesMap names;
    names[L]     = "0001";
    names[D]     = "0010";
    names[D|L]   = "0011";
    names[R]     = "0100";
    names[R|L]   = "0101";
    names[R|D]   = "0110";
    names[R|D|L] = "0111";
    names[U]     = "1000";
    names[U|L]   = "1001";
    names[U|D]   = "1010";
    names[U|D|L] = "1011";
    names[U|R]   = "1100";
    names[U|R|L] = "1101";
    names[U|R|D] = "1110";

    NamesMap::ConstIterator it;
    for(it = names.constBegin(); it != names.constEnd(); ++it)
    {
	connectedpixmap[it.key()] =
	    new QPixmap(QPixmap(":/pics/cable" + it.value() + ".png"));
	disconnectedpixmap[it.key()] =
	    new QPixmap(fadedPixmap(* connectedpixmap[it.key()]));
    }

    const int w = QPixmap(":/pics/background.png").width();
    QPixmap pixmap(":/pics/shadow.png");
    const int x1 = (pixmap.width() - w) / 2;
    const int x2 = pixmap.width() - w;
    shadowpixmap[NoShadow] = new QPixmap();
    shadowpixmap[TopLeftShadow]  = new QPixmap(pixmap.copy(0,  0,  w, w));
    shadowpixmap[TopShadow]      = new QPixmap(pixmap.copy(x1, 0,  w, w));
    shadowpixmap[TopRightShadow] = new QPixmap(pixmap.copy(x2, 0,  w, w));
    shadowpixmap[LeftShadow]     = new QPixmap(pixmap.copy(0,  x1, w, w));
    shadowpixmap[RightShadow]    = new QPixmap(pixmap.copy(x2, x1, w, w));
    shadowpixmap[BottomLeftShadow]  = new QPixmap(pixmap.copy(0,  x2, w, w));
    shadowpixmap[BottomShadow]      = new QPixmap(pixmap.copy(x1, x2, w, w));
    shadowpixmap[BottomRightShadow] = new QPixmap(pixmap.copy(x2, x2, w, w));

}