Пример #1
0
void TEWidget::setColorTable(const ColorEntry table[])
{
  for (int i = 0; i < TABLE_COLORS; i++) color_table[i] = table[i];
  
  const QPixmap* pm = backgroundPixmap();
  //if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);
  QPalette palette;
  palette.setColor(QPalette::Background, color_table[DEFAULT_BACK_COLOR].color);
  setPalette(palette);

  qDebug("org code : if (!pm) setBackgroundColor(color_table[DEFAULT_BACK_COLOR].color);");
  update();
}
Пример #2
0
QPixmap BrushStyle::getSample(qreal scale, qreal alpha, bool selected, const QColor &color, bool emptyBackground)
{
	QPixmap backgroundPixmap( (selected) ? BRUSH_SAMPLE_SELECTED_BG : BRUSH_SAMPLE_BACKGROUND);

	if (emptyBackground)
		backgroundPixmap.fill(Qt::transparent);

	// Scale the sample
	QSizeF pointSize(BRUSH_SAMPLE_SIDE, BRUSH_SAMPLE_SIDE);

	if (scale != 1.0)
	{
		pointSize.setWidth(pointSize.width() * scale);
		pointSize.setHeight(pointSize.height() * scale);
	}

	// Apply color and alpha
	QColor alphaColor(Qt::black);

	if (color.isValid())
		alphaColor = color;

	if (alpha != 1.0)
		alphaColor.setAlphaF(alpha);
	
	// Draw sample in the middle of background
	QPainter painter(&backgroundPixmap);
	painter.setRenderHint(QPainter::Antialiasing);

	QRectF pointRect(QPointF(0, 0), pointSize);
	pointRect.moveTo(backgroundPixmap.width() / 2 - pointSize.width() / 2, backgroundPixmap.height() / 2 - pointSize.height() / 2);

	if (color.isValid() && color.value() > 210 && color.saturation() < 50)
		painter.setPen("#d0d0d0");
	else
		painter.setPen(Qt::NoPen);

	painter.setBrush(alphaColor);
	painter.drawEllipse(pointRect);

	painter.end();

	return backgroundPixmap;
}
Пример #3
0
void GameScene::resized() {
    qDebug() << "GameScene::resized(): called";
    //menuBackgroundRect->setRect(toFp(0), toFp(0), toFp(100), toFp(100));
    mainMenu->setProperty("width", width());
    mainMenu->setProperty("height", height());

    QPixmap backgroundPixmap(":/images/background.png");
    QPixmap scaledBackgroundPixmap;
    // check the ratio of the pixmap against the ratio of our scene
    if((qreal)backgroundPixmap.width() / (qreal)backgroundPixmap.height() > (qreal)width() / (qreal)height()) {
        scaledBackgroundPixmap = backgroundPixmap.scaledToHeight(height());
    } else {
        scaledBackgroundPixmap = backgroundPixmap.scaledToWidth(width());
    }
    this->removeItem(backgroundImage);
    delete backgroundImage;
    backgroundImage = addPixmap(scaledBackgroundPixmap);
    backgroundImage->setZValue(-1000);
}
PAAlternativeLauncher::PAAlternativeLauncher()
 : mNetworkAccessManager(new QNetworkAccessManager(this))
#if defined(linux)
 , mPlatform("Linux")
 , mDefaultInstallPath(QDir::homePath() + "/Games/PA")
#elif defined(_WIN32)
 , mPlatform("Windows")
 , mDefaultInstallPath("C:\\Games\\Uber Entertainment\\Planetary Annihilation Launcher\\Planetary Annihilation")
 , mWinTaskbarProgress(NULL)
#elif defined(__APPLE__)
 , mPlatform("OSX")
 , mDefaultInstallPath("/Applications/Planetary Annihilation")
#else
# error Not a supported os
#endif
 , mBufferSize(1024*1024), mBuffer(NULL), mPatcher(NULL)
{
	setWindowIcon(QIcon(":/img/icon.png"));
	setWindowTitle("PA Alternative Launcher");
	info.setParent(this);
	info.log("Starting launcher", QDateTime::currentDateTime().toString());

	convertOldSettings();

	if(mNetworkAccessManager == NULL)
		info.critical("Init", "Network Access Manager failed to initialize.");

	QPalette palette;
	QPixmap backgroundPixmap(":/img/img_bground_galaxy_01.png");
	QBrush backgroundBrush(backgroundPixmap);
 	palette.setBrush(QPalette::Background, backgroundBrush);
 	setPalette(palette);

	QWidget *main_widget = new QWidget(this);
	QVBoxLayout *main_layout = new QVBoxLayout(main_widget);
	
	QLabel *disclaimer_label = new QLabel(tr("This is an UNOFFICIAL launcher and not connected to Planetary Annihilation Inc. in any way."), main_widget);
	disclaimer_label->setStyleSheet("QLabel {color: red; font-weight: bold;}");
	disclaimer_label->setAlignment(Qt::AlignCenter);
	disclaimer_label->setAutoFillBackground(true);
	disclaimer_label->setBackgroundRole(QPalette::Dark);
	main_layout->addWidget(disclaimer_label);

	QLabel *header_label = new QLabel(main_widget);
	header_label->setPixmap(QPixmap(":/img/img_pa_logo_start_rest.png"));
	header_label->setAlignment(Qt::AlignCenter);
	main_layout->addWidget(header_label);

	QWidget *centre_widget = new QWidget(main_widget);
	QHBoxLayout *centre_layout = new QHBoxLayout(centre_widget);

	QWidget *commander_widget = new QWidget(centre_widget);
	QVBoxLayout *commander_layout = new QVBoxLayout(commander_widget);
	QLabel *commander_label = new QLabel(commander_widget);
	commander_label->setPixmap(QPixmap(":img/img_imperial_invictus.png"));
	commander_layout->addWidget(commander_label);

	centre_layout->addWidget(commander_widget);

	QWidget *middle_horizontal_widget = new QWidget(centre_widget);
	QVBoxLayout *middle_horizontal_layout = new QVBoxLayout(middle_horizontal_widget);

	QWidget *stream_widget = new QWidget(middle_horizontal_widget);
	QHBoxLayout *stream_layout = new QHBoxLayout(stream_widget);
	QLabel *streams_label = new QLabel(tr("Stream"), stream_widget);
	QPalette palettewhite = main_widget->palette();
	palettewhite.setColor(QPalette::WindowText, Qt::white);
	streams_label->setPalette(palettewhite);
	stream_layout->addWidget(streams_label);
	mStreamsComboBox = new QComboBox(stream_widget);
	stream_layout->addWidget(mStreamsComboBox);
	mUpdateAvailableLabel = new QLabel("", stream_widget);
	mUpdateAvailableLabel->setStyleSheet("QLabel {font-weight: bold; color: white}");
	mUpdateAvailableLabel->setPalette(palettewhite);
	stream_layout->addWidget(mUpdateAvailableLabel);
	stream_layout->addStretch();
	middle_horizontal_layout->addWidget(stream_widget);

	mLoginWidget = createLoginWidget(middle_horizontal_widget);
	mDownloadWidget = createDownloadWidget(middle_horizontal_widget);
	mDownloadWidget->setVisible(false);
	mWaitWidget = createWaitWidget(middle_horizontal_widget);
	mWaitWidget->setVisible(false);
	middle_horizontal_layout->addWidget(mLoginWidget);
	middle_horizontal_layout->addWidget(mDownloadWidget);
	middle_horizontal_layout->addWidget(mWaitWidget);

	QWidget *install_path_widget = new QWidget(middle_horizontal_widget);
	QHBoxLayout *install_path_layout = new QHBoxLayout(install_path_widget);

	mInstallPathLineEdit = new QLineEdit(install_path_widget);
	mInstallPathLineEdit->setPlaceholderText(tr("Enter the PA install directory here."));
	install_path_layout->addWidget(mInstallPathLineEdit);

	QPushButton *install_path_push_button = new QPushButton(style()->standardIcon(QStyle::SP_DirOpenIcon), "", install_path_widget);
	install_path_push_button->setFlat(true);
	connect(install_path_push_button, SIGNAL(clicked(bool)), SLOT(installPathButtonClicked(bool)));
	install_path_layout->addWidget(install_path_push_button);
	middle_horizontal_layout->addWidget(install_path_widget);

	centre_layout->addWidget(middle_horizontal_widget);
/*
	mModDatabaseFrame = new ModDatabaseFrame(centre_widget);
	centre_layout->addWidget(mModDatabaseFrame);
*/
	main_layout->addWidget(centre_widget);

	QDialogButtonBox *button_box = new QDialogButtonBox(main_widget);
	mLaunchButton = new QPushButton(tr("&Launch PA"), button_box);
	mLaunchButton->setEnabled(false);
	connect(mLaunchButton, SIGNAL(clicked(bool)), SLOT(launchPushButtonClicked(bool)));
	button_box->addButton(mLaunchButton, QDialogButtonBox::AcceptRole);
	QPushButton *launch_offline_button = new QPushButton(tr("Launch &offline"), button_box);
	connect(launch_offline_button, SIGNAL(clicked(bool)), SLOT(launchOfflinePushButtonClicked(bool)));
	button_box->addButton(launch_offline_button, QDialogButtonBox::AcceptRole);
	QPushButton *advanced_button = new QPushButton(tr("&Advanced"), button_box);
	connect(advanced_button, SIGNAL(clicked(bool)), SLOT(advancedPushButtonClicked(bool)));
	button_box->addButton(advanced_button, QDialogButtonBox::NoRole);
	mDownloadButton = new QPushButton(tr("&Download and install"), button_box);
	mDownloadButton->setEnabled(false);
	connect(mDownloadButton, SIGNAL(clicked(bool)), SLOT(downloadPushButtonClicked(bool)));
	button_box->addButton(mDownloadButton, QDialogButtonBox::NoRole);

	main_layout->addWidget(button_box);

	mPatchLabel = new QLabel(main_widget);
	mPatchLabel->setStyleSheet("QLabel {color: white; font-weight: bold}");
	mPatchLabel->setAlignment(Qt::AlignCenter);
	main_layout->addWidget(mPatchLabel);

	mPatchProgressbar = new QProgressBar(main_widget);
	mPatchProgressbar->setMinimum(0);
	mPatchProgressbar->setMaximum(100);
	main_layout->addWidget(mPatchProgressbar);

	QLabel *disclaimer_label2 = new QLabel(tr("This is an UNOFFICIAL launcher and not connected to Planetary Annihilation Inc. in any way."), main_widget);
	disclaimer_label2->setStyleSheet("QLabel {color: red; font-weight: bold;}");
	disclaimer_label2->setAlignment(Qt::AlignCenter);
	disclaimer_label2->setAutoFillBackground(true);
	disclaimer_label2->setBackgroundRole(QPalette::Dark);
	main_layout->addWidget(disclaimer_label2);

	QWidget *about_widget = new QWidget(main_widget);
	QHBoxLayout *about_layout = new QHBoxLayout(about_widget);

	QLabel *created_by_label = new QLabel(tr("Created by") + " DeathByDenim " + tr("using Qt5"), about_widget);
	created_by_label->setStyleSheet("QLabel {color: white}");
	about_layout->addWidget(created_by_label);
	QLabel *blackmage_label = new QLabel(about_widget);
	blackmage_label->setPixmap(QPixmap(":img/blackmage.png"));
	blackmage_label->setMaximumSize(16, 16);
	about_layout->addWidget(blackmage_label);
	about_layout->addStretch();
	QLabel *version_label = new QLabel(tr("Version") + " " VERSION, about_widget);
	version_label->setStyleSheet("QLabel {color: white}");
	about_layout->addWidget(version_label);

	main_layout->addWidget(about_widget);

	setCentralWidget(main_widget);


	QSettings settings;
	restoreGeometry(settings.value("mainwindow/geometry").toByteArray());

	settings.beginGroup("streams");
	QStringList streamgroups = settings.childGroups();
	for(QStringList::const_iterator stream = streamgroups.constBegin(); stream != streamgroups.constEnd(); ++stream)
		mStreamsComboBox->addItem(*stream);
	settings.endGroup();
	connect(mStreamsComboBox, SIGNAL(currentIndexChanged(int)), SLOT(streamsComboBoxCurrentIndexChanged(int)));
	if(streamgroups.contains(settings.value("streams/defaultstream").toString()))
		mStreamsComboBox->setCurrentText(settings.value("streams/defaultstream").toString());
	else
		mStreamsComboBox->setCurrentText("stable");

	mSessionTicket = settings.value("login/sessionticket").toString();
	if(!mSessionTicket.isEmpty())
	{
		setState(wait_state);

		QNetworkRequest request(QUrl("https://uberent.com/Launcher/ListStreams?Platform=" + mPlatform));
		request.setRawHeader("X-Authorization", mSessionTicket.toUtf8());
		request.setRawHeader("X-Clacks-Overhead", "GNU Terry Pratchett");
		request.setRawHeader("User-Agent", QString("PAAlternativeLauncher/%1").arg(VERSION).toUtf8());
		QNetworkReply *reply = mNetworkAccessManager->get(request);
		connect(reply, SIGNAL(finished()), SLOT(streamsFinished()));
	}

	if(mUserNameLineEdit->text().isEmpty())
		mUserNameLineEdit->setFocus();
	else
		mPasswordLineEdit->setFocus();
}
Пример #5
0
void KGameProgress::drawContents(QPainter *p)
{
	QRect cr = contentsRect(), er = cr;
	fr = cr;
	QBrush fb(bar_color), eb(backgroundColor());

	if (bar_pixmap)
		fb.setPixmap(*bar_pixmap);

	if (backgroundPixmap())
		eb.setPixmap(*backgroundPixmap());

	switch (bar_style) {
		case Solid:
			if (orient == Horizontal) {
				fr.setWidth(recalcValue(cr.width()));
				er.setLeft(fr.right() + 1);
			} else {
				fr.setTop(cr.bottom() - recalcValue(cr.height()));
				er.setBottom(fr.top() - 1);
			}

			p->setBrushOrigin(cr.topLeft());
			p->fillRect(fr, fb);

			p->fillRect(er, eb);

			break;

		case Blocked:
			const int margin = 2;
			int max, num, dx, dy;
			if (orient == Horizontal) {
				fr.setHeight(cr.height() - 2 * margin);
				fr.setWidth((int)(0.67 * fr.height()));
				fr.moveTopLeft(QPoint(cr.left() + margin, cr.top() + margin));
				dx = fr.width() + margin;
				dy = 0;
				max = (cr.width() - margin) / (fr.width() + margin) + 1;
				num = recalcValue(max);
			} else {
				fr.setWidth(cr.width() - 2 * margin);
				fr.setHeight((int)(0.67 * fr.width()));
				fr.moveBottomLeft(QPoint(cr.left() + margin, cr.bottom() - margin));
				dx = 0;
				dy = - (fr.height() + margin);
				max = (cr.height() - margin) / (fr.height() + margin) + 1;
				num = recalcValue(max);
			}
			p->setClipRect(cr.x() + margin, cr.y() + margin,
			               cr.width() - margin, cr.height() - margin);
			for (int i = 0; i < num; i++) {
				p->setBrushOrigin(fr.topLeft());
				p->fillRect(fr, fb);
				fr.moveBy(dx, dy);
			}
			
			if (num != max) {
				if (orient == Horizontal)
					er.setLeft(fr.right() + 1);
				else
					er.setBottom(fr.bottom() + 1);
				if (!er.isNull()) {
					p->setBrushOrigin(cr.topLeft());
					p->fillRect(er, eb);
				}
			}

			break;
	}

	if (text_enabled && bar_style != Blocked)
		drawText(p);
}
Пример #6
0
Card::Card(Suit s, unsigned int v)
  : NSWindow(true, gameWindow, 0, 0, cardWidth, cardHeight, 1, BlackPixel(dpy, 0))
{
#ifdef SHAPE
  if (Option::roundCard() && !initialized) {
    //Shape
    boundingMask = XCreateBitmapFromData(dpy, root(), (char*)boundingMask_bits,
                                         boundingMask_width,
                                         boundingMask_height);
    clipMask = XCreateBitmapFromData(dpy, root(), (char*)clipMask_bits,
                                     clipMask_width, clipMask_height);

    //Cursor
    XColor fore, back, xc;
    Pixmap p, mask;
    Colormap cm = DefaultColormap(dpy, 0);

    p =  XCreateBitmapFromData(dpy, gameWindow, (char*) cursor_bits,
                               cursor_width, cursor_height);
    mask = XCreateBitmapFromData(dpy, gameWindow, (char*) cursor_back_bits,
                                 cursor_back_width, cursor_back_height);
    XAllocNamedColor(dpy, cm, "white", &fore, &xc);
    XAllocNamedColor(dpy, cm, "black", &back, &xc);
    cursor = XCreatePixmapCursor(dpy, p,mask, &fore, &back, 0, 0);

    initialized = true;
  }
#endif

  _parent = 0;
  _stack = 0;
  _suit = s;
  _value = v;
  _removed = false;
  makeBitmap(s, v, bitmap);

  // initialization on X things
  unsigned long fore, back, hilight;

  if (suitColor(s) == RedSuit)
    fore = getColor(dpy, "red");
  else
    fore = getColor(dpy, "black");
  back = WhitePixel(dpy, 0);
  hilight = getColor(dpy, "lightskyblue4");

  _usualPixmap = XCreatePixmapFromBitmapData(dpy, gameWindow, bitmap,
                                             cardWidth - 2, cardHeight - 2,
                                             fore, back,
                                     DefaultDepth(dpy, DefaultScreen(dpy)));
  _hilightedPixmap = XCreatePixmapFromBitmapData(dpy, gameWindow, bitmap, cardWidth - 2,
                                                 cardHeight - 2, fore, hilight,
                                     DefaultDepth(dpy, DefaultScreen(dpy)));

  selectInput(ButtonPressMask | EnterWindowMask | LeaveWindowMask);
  backgroundPixmap(_usualPixmap);

#ifdef SHAPE
  if (Option::roundCard()) {
    XShapeCombineMask(dpy, window(), ShapeBounding, 0, 0, boundingMask, ShapeSet);
    XShapeCombineMask(dpy, window(), ShapeClip, 0, 0, clipMask, ShapeSet);
  }
#endif

  NSWindow::move(0, 0);

  map();
}
Пример #7
0
Card::Card(Suit s, unsigned int v)
  : NSWindow(true, gameWindow, 0, 0, cardWidth, cardHeight, 1, XC_BLACK)
{
  if (!initialized) {
#ifdef SHAPE
    if (Option::roundCard()) {
     	    //Shape
	    boundingMask = XCreateBitmapFromData(dpy, root(),
				boundingMask_bits, boundingMask_width,
				boundingMask_height);
	    clipMask = XCreateBitmapFromData(dpy, root(), clipMask_bits,
				clipMask_width, clipMask_height);
    }
#endif

    //Cursor
    //XColor fore, back, xc;
    //gi_window_id_t p, mask;
    //Colormap cm = DefaultColormap(dpy, 0);
    //p =  XCreateBitmapFromData(dpy, gameWindow, (char*) cursor_bits, cursor_width, cursor_height);
    //mask = XCreateBitmapFromData(dpy, gameWindow, (char*) cursor_back_bits, cursor_back_width, cursor_back_height);
    //XAllocNamedColor(dpy, cm, "white", &fore, &xc);
    //XAllocNamedColor(dpy, cm, "black", &back, &xc);
    //cursor = XCreatePixmapCursor(dpy, p,mask, &fore, &back, 0, 0);

#ifdef GIXOK
    uint16_t *p = gi_create_bitmap_from_data(16, 16, cursor_width, cursor_height, cursor_bits,
    	TRUE,TRUE);
    uint16_t *mask =  gi_create_bitmap_from_data(16, 16, cursor_back_width, cursor_back_height,
    	cursor_back_bits, TRUE,TRUE);
    cursor = GrNewCursor(16, 16, 8, 0, XC_BLACK, XC_WHITE, p, mask);
    free(p);
    free(mask);
#endif

    initialized = true;
  }

  _parent = 0;
  _stack = 0;
  _suit = s;
  _value = v;
  _removed = false;
  makeBitmap(s, v, bitmap);

  // initialization on X things
  unsigned long fore, back, hilight;

  if (suitColor(s) == RedSuit)
    fore = getColor( XC_RED);
  else
    fore = getColor( XC_BLACK);
  back = XC_WHITE;
  hilight = getColor( XC_LIGHTSKYBLUE4);


  _usualPixmap = 
    gi_create_pixmap_from_bitmap( gameWindow, bitmap, cardWidth - 2,
	cardHeight - 2, fore, back, gi_screen_format() );
  _hilightedPixmap = 
    gi_create_pixmap_from_bitmap( gameWindow, bitmap, cardWidth - 2,
	cardHeight - 2, fore, hilight, gi_screen_format() );


  selectInput(GI_MASK_BUTTON_DOWN | GI_MASK_MOUSE_ENTER | GI_MASK_MOUSE_EXIT);
  backgroundPixmap(_usualPixmap);

#ifdef SHAPE
  if (Option::roundCard()) {
    XShapeCombineMask(dpy, window(), ShapeBounding, 0, 0, boundingMask, ShapeSet);
    XShapeCombineMask(dpy, window(), ShapeClip, 0, 0, clipMask, ShapeSet);
  }
#endif

  NSWindow::move(0, 0);

  map();
}
Пример #8
0
void TEWidget::paintEvent( QPaintEvent* pe )
{
//{ static int cnt = 0; printf("paint %d\n",cnt++); }
  const QPixmap* pm = backgroundPixmap();
  QPainter paint;
  setUpdatesEnabled(FALSE);
  paint.begin( this );
  paint.setBackgroundMode( TransparentMode );
HCNT("paintEvent");
  qDebug("in TEWidget::paintEvent()");
  //sleep(2);

  // Note that the actual widget size can be slightly larger
  // than the image (the size is truncated towards the smaller
  // number of characters in `resizeEvent'. The paint rectangle
  // can thus be larger than the image, but less then the size
  // of one character.

  QRect rect = pe->rect().intersect(contentsRect());

  QPoint tL  = contentsRect().topLeft();
  int    tLx = tL.x();
  int    tLy = tL.y();

  int lux = min(columns-1, max(0,(rect.left()   - tLx - blX ) / font_w));
  int luy = min(lines-1,   max(0,(rect.top()    - tLy - bY  ) / font_h));
  int rlx = min(columns-1, max(0,(rect.right()  - tLx - blX ) / font_w));
  int rly = min(lines-1,   max(0,(rect.bottom() - tLy - bY  ) / font_h));

  /*
 printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly,
  rect.left(), rect.right(), rect.top(), rect.bottom());
  */

  //  if (pm != NULL && color_table[image->b].transparent)
  //  erase(rect);
  // BL: I have no idea why we need this, and it breaks the refresh.

  QChar *disstrU = new QChar[columns];
  QFontMetrics fm(font());

  for (int y = luy; y <= rly; y++)
  {
    int draw_font_w=0;
  for (int x = lux; x <= rlx; x++)
  {
    int len = 1;
    disstrU[0] = fontMap(image[loc(x,y)].c);
    int cf = image[loc(x,y)].f;
    int cb = image[loc(x,y)].b;
    int cr = image[loc(x,y)].r;
    while (x+len <= rlx &&
           image[loc(x+len,y)].f == cf &&
           image[loc(x+len,y)].b == cb &&
           image[loc(x+len,y)].r == cr )
    {
      disstrU[len] = fontMap(image[loc(x+len,y)].c);
      len += 1;
    }
    QString unistr(disstrU,len);
/*
    qDebug("blX+tLx+font_w*x: %d", blX+tLx+font_w*x);
    qDebug("bY+tLy+font_h*y: %d", bY+tLy+font_h*y);
    qDebug("font_w*len: %d", font_w*len);
    qDebug("font_h: %d", font_h);
    qDebug("font_w: %d", font_w);
    qDebug("x: %d", x);
*/
    //drawAttrStr(paint, QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), unistr, image[loc(x,y)], pm != NULL, false);
    drawAttrStr(paint, QRect(blX+tLx+draw_font_w,bY+tLy+font_h*y,font_w*len/2,font_h), unistr, image[loc(x,y)], pm != NULL, false);
    draw_font_w+=fm.width(unistr);
    //sleep(2);
    x += len - 1;
  }
  }
  delete [] disstrU;
  drawFrame( &paint );
  paint.end();
  setUpdatesEnabled(TRUE);
}
Пример #9
0
void TEWidget::setImage(const ca* const newimg, int lines, int columns)
{ int y,x,len;
  const QPixmap* pm = backgroundPixmap();
  //qDebug("in TEWidget::setImage()");
  //sleep(2);
  //QPainter paint;
  setUpdatesEnabled(FALSE);
  //paint.begin( this );
HCNT("setImage");

  QPoint tL  = contentsRect().topLeft();
  int    tLx = tL.x();
  int    tLy = tL.y();
  hasBlinker = FALSE;

  int cf  = -1; // undefined
  int cb  = -1; // undefined
  int cr  = -1; // undefined

  int lins = min(this->lines,  max(0,lines  ));
  int cols = min(this->columns,max(0,columns));
  QChar *disstrU = new QChar[cols];
  bool repaint_screen=false;

//{ static int cnt = 0; printf("setImage %d\n",cnt++); }
  for (y = 0; y < lins; y++)
  {
    const ca*       lcl = &image[y*this->columns];
    const ca* const ext = &newimg[y*columns];
    if (!resizing) // not while resizing, we're expecting a paintEvent
    for (x = 0; x < cols; x++)
    {
      hasBlinker |= (ext[x].r & RE_BLINK);
      if (ext[x] != lcl[x])
      {
        repaint_screen=true;
        cr = ext[x].r;
        cb = ext[x].b;
        if (ext[x].f != cf) cf = ext[x].f;
        int lln = cols - x;
        disstrU[0] = fontMap(ext[x+0].c);
        for (len = 1; len < lln; len++)
        {
          if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr ||
              ext[x+len] == lcl[x+len] )
            break;
          disstrU[len] = fontMap(ext[x+len].c);
        }
        //QString unistr(disstrU,len);
        //drawAttrStr(paint, QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), unistr, ext[x], pm != NULL, true);
        x += len - 1;
      }
      else
      {
        //qDebug("(ext[x] == lcl[x]");
      }
    }
    // finally, make `image' become `newimg'.
    memcpy((void*)lcl,(const void*)ext,cols*sizeof(ca));
  }
  //drawFrame( &paint );
  //paint.end();
  if (repaint_screen==true)
    setUpdatesEnabled(TRUE);
  if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms
  if (!hasBlinker &&  blinkT->isActive()) { blinkT->stop(); blinking = FALSE; }
  delete [] disstrU;
}
Пример #10
0
GameScene::GameScene(GameView *parent) :
    QGraphicsScene(parent),
    m_level(1),
    m_highestLevel(1),
    m_gameState(GameRunning),
    m_dt(0),
    firstStep(true),
    m_selectedType(ParticlePositive),
    m_isSlowMotionEnabled(false),
    currentTime(0),
    lastFrameTime(0),
    frameNumber(0),
    dtSum(0)
{
    qRegisterMetaType<GameScene::GameMode>("GameMode");
    qRegisterMetaType<GameScene::GameState>("GameState");
#ifdef OS_IS_ANDROID
    qDebug() << "Force syncing settings";
    settings.sync();
#endif
    if(isDemo()) {
        qDebug() << "This is the demo version";
    } else {
        qDebug() << "This is the full version";
    }

    setSelectedType(ParticlePositive);

    // load images
    selectionImage = QImage(":/images/selection-overlay.png");
    positiveImage = QImage(":/images/particle-positive.png");
    negativeImage = QImage(":/images/particle-negative.png");
    neutralImage = QImage(":/images/particle-neutral.png");
    playerImage = QImage(":/images/particle-player.png");
    playerOverchargedImage = QImage(":/images/particle-player-overcharged.png");
    glowingImage = QImage(":/images/particle-glowing.png");
    enemyImage = QImage(":/images/particle-enemy.png");
    slowMotionImage = QImage(":/images/particle-slow-motion.png");
    repellentImage = QImage(":/images/particle-repellent.png");
    transferImage = QImage(":/images/particle-transfer.png");

    setSceneRect(0, 0, 854, 480); // TODO: just for init, should be chosen by the platform
    setItemIndexMethod(QGraphicsScene::NoIndex);

    // Background image
    QPixmap backgroundPixmap(":/images/background.png");
    backgroundImage = this->addPixmap(backgroundPixmap);

    // Main menu
    QDeclarativeEngine *engine = new QDeclarativeEngine;
//#ifdef OS_IS_ANDROID
//    QDeclarativeComponent mainMenuComponent(engine, QUrl(adjustPath("assets:/qml/MainMenu.qml")));
//#else
    QDeclarativeComponent mainMenuComponent(engine, QUrl("qrc:/qml/MainMenu.qml"));
//#endif
    engine->rootContext()->setContextProperty("contextGameScene", this);
    mainMenu = qobject_cast<QGraphicsObject *>(mainMenuComponent.create());
    qDebug() << "Component errors:\n" << mainMenuComponent.errors();
    qDebug() << "End component errors";
    // Connect the QML back to this class
    addItem(mainMenu);
    mainMenu->setZValue(1000);
    m_specialParticles = new QList<int>;

#ifdef OS_IS_HARMATTAN
    mainMenu->setProperty("exit.visible", false);
#endif


#ifdef OS_IS_SYMBIAN
    qreal screenWidth = QApplication::desktop()->screenGeometry().width();
    qreal screenHeight = QApplication::desktop()->screenGeometry().height();
    if(screenWidth  > screenHeight) { // Symbian hack
        mainMenu->setProperty("width", screenWidth);
        mainMenu->setProperty("height", screenHeight);
    } else {
        mainMenu->setProperty("width", screenHeight);
        mainMenu->setProperty("height", screenWidth);
    }
#endif

    // set up timer
    levelTimer = new QTimer(this);
    levelTimer->setInterval(1000);
    connect(levelTimer, SIGNAL(timeout()), SLOT(updateLevelTime()));

    // Set up animations
    timeFactorAnimation = new QPropertyAnimation(this, "timeFactor");
    qDebug() << "Highest level is" << m_level;

    setGameState(GameStarted);

    // just init all in the resize() function
    resized();

    // Start level and start timers
    //    startLevel(level());

    connect(&advanceTimer, SIGNAL(timeout()), SLOT(advance()));
    advanceTimer.start(10);
    time.start();
    qDebug() << "Timers started!";

    // dashboard button
#if (defined(OS_IS_DESKTOP_LINUX) || defined(Q_OS_WIN32) || defined(Q_OS_MAC) || defined(Q_WS_MAEMO_5))
    qDebug() << "Show dashboard button";
    mainMenu->setProperty("dashboardButtonVisible", true);
#else
    qDebug() << "Don't show dashboard button";
    mainMenu->setProperty("dashboardButtonVisible", false);
#endif

    // load settings
    setGameMode((GameMode)settings.value("gameMode", ModeClassic).toInt());
}
Пример #11
0
/*!\reimp
*/
void QRadioButton::drawButton( QPainter *paint )
{
    QPainter	*p = paint;
    const QColorGroup & g = colorGroup();
    int		 x, y;

    QFontMetrics fm = fontMetrics();
    QSize lsz = fm.size(ShowPrefix, text());
    QSize sz = style().exclusiveIndicatorSize();
    x = text().isEmpty() ? 1 : 0;
    y = (height() - lsz.height() + fm.height() - sz.height())/2;

#ifndef QT_NO_TEXTSTREAM
#define SAVE_RADIOBUTTON_PIXMAPS
#endif

#if defined(SAVE_RADIOBUTTON_PIXMAPS)
    QString pmkey;				// pixmap key
    int kf = 0;
    if ( isDown() )
	kf |= 1;
    if ( isOn() )
	kf |= 2;
    if ( isEnabled() )
	kf |= 4;
    QTextOStream os(&pmkey);
    os << "$qt_radio_" << style().className() << "_"
			 << palette().serialNumber() << "_" << kf;
    QPixmap *pm = QPixmapCache::find( pmkey );
    if ( pm ) {					// pixmap exists
	drawButtonLabel( p );
	p->drawPixmap( x, y, *pm );
	return;
    }
    bool use_pm = TRUE;
    QPainter pmpaint;
    int wx, wy;
    if ( use_pm ) {
	pm = new QPixmap( sz );			// create new pixmap
	CHECK_PTR( pm );
	pmpaint.begin( pm );
	p = &pmpaint;				// draw in pixmap
	wx=x;  wy=y;				// save x,y coords
	x = y = 0;
	p->setBackgroundColor( g.background() );
    }
#endif

#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)

    style().drawExclusiveIndicator(p, x, y, sz.width(), sz.height(), g, isOn(), isDown(), isEnabled() );

#if defined(SAVE_RADIOBUTTON_PIXMAPS)
    if ( use_pm ) {
	pmpaint.end();
	if ( backgroundPixmap() || backgroundMode() == X11ParentRelative ) {
	    QBitmap bm( pm->size() );
	    bm.fill( color0 );
	    pmpaint.begin( &bm );
	    style().drawExclusiveIndicatorMask( &pmpaint, 0, 0, bm.width(), bm.height(), isOn() );
	    pmpaint.end();
	    pm->setMask( bm );
	}
	p = paint;				// draw in default device
	p->drawPixmap( wx, wy, *pm );
	if (!QPixmapCache::insert(pmkey, pm) )	// save in cache
	    delete pm;
    }
#endif
    drawButtonLabel( p );
}