void HelloWorld::onTouchesBegan(const std::vector<Touch*>& touches, Event *unused_event) { genBackground(); _tapDown = true; Vec2 touchLocation = _terrain->convertTouchToNodeSpace(touches.front()); createTestBodyAtPostition(touchLocation); }
void HelloWorld::onEnter() { Layer::onEnter(); setupWorld(); _terrain = Terrain::create(_world); addChild(_terrain, 1); genBackground(); // Enable Touches/Mouse. auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = CC_CALLBACK_2(HelloWorld::onTouchesBegan, this); listener->onTouchesEnded = CC_CALLBACK_2(HelloWorld::onTouchesEnded, this); listener->onTouchesCancelled = CC_CALLBACK_2(HelloWorld::onTouchesCancelled, this); this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); scheduleUpdate(); _hero = Hero::create(_world); _hero->autorelease(); _terrain->getBatchNode()->addChild(_hero); }
/*! (reimplemented) First copies a background image of the hue donut and its background color onto the frame, then draws the color triangle, and finally the selectors. */ void QtColorTriangle::paintEvent(QPaintEvent *e) { QPainter p(this); if (e->rect().intersects(contentsRect())) p.setClipRegion(e->region().intersect(contentsRect())); if (mustGenerateBackground) { genBackground(); mustGenerateBackground = false; } // Blit the static generated background with the hue gradient onto // the double buffer. QImage buf = bg.copy(); // Draw the trigon int h,s,v; curColor.getHsv(&h, &s, &v); // Find the color with only the hue, and max value and saturation QColor hueColor; hueColor.setHsv(curHue, 255, 255); // Draw the triangle drawTrigon(&buf, pa, pb, pc, hueColor); // Slow step: convert the image to a pixmap QPixmap pix = QPixmap::fromImage(buf); QPainter painter(&pix); painter.setRenderHint(QPainter::Antialiasing); // Draw an outline of the triangle QColor halfAlpha(0, 0, 0, 128); painter.setPen(QPen(halfAlpha, 0)); painter.drawLine(pa, pb); painter.drawLine(pb, pc); painter.drawLine(pc, pa); int ri, gi, bi; hueColor.getRgb(&ri, &gi, &bi); if ((ri * 30) + (gi * 59) + (bi * 11) > 12800) painter.setPen(QPen(Qt::black, penWidth)); else painter.setPen(QPen(Qt::white, penWidth)); painter.drawEllipse((int) (pd.x() - ellipseSize / 2.0), (int) (pd.y() - ellipseSize / 2.0), ellipseSize, ellipseSize); curColor.getRgb(&ri, &gi, &bi); // Find a color for painting the selector based on the brightness // value of the color. if ((ri * 30) + (gi * 59) + (bi * 11) > 12800) painter.setPen(QPen(Qt::black, penWidth)); else painter.setPen(QPen(Qt::white, penWidth)); // Draw the selector ellipse. painter.drawEllipse(QRectF(selectorPos.x() - ellipseSize / 2.0, selectorPos.y() - ellipseSize / 2.0, ellipseSize + 0.5, ellipseSize + 0.5)); // Blit p.drawPixmap(contentsRect().topLeft(), pix); }