// Tests scale mode with an additional copy for transparency. This will happen // if we have a scaled textbox, for example. WebKit will create a new // transparency layer, draw the text field, then draw the text into it, then // composite this down with an opacity. TEST(TransparencyWin, ScaleTransparency) { // Create an opaque white buffer. OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); FloatRect fullBuffer(0, 0, 16, 16); src->context()->fillRect(fullBuffer, Color::white); // Make another layer (which duplicates how WebKit will make this). We fill // the top half with red, and have the layer be 50% opaque. src->context()->beginTransparencyLayer(0.5); FloatRect topHalf(0, 0, 16, 8); src->context()->fillRect(topHalf, Color(0xFFFF0000)); // Scale by 2x. src->context()->save(); AffineTransform scale; scale.scale(2.0); src->context()->concatCTM(scale); // Make a layer inset two pixels (because of scaling, this is 2->14). And // will it with 50% black. { TransparencyWin helper; helper.init(src->context(), TransparencyWin::OpaqueCompositeLayer, TransparencyWin::ScaleTransform, IntRect(1, 1, 6, 6)); helper.context()->fillRect(helper.drawRect(), Color(0x7f000000)); clearTopLayerAlphaChannel(helper.context()); helper.composite(); } // Finish the layer. src->context()->restore(); src->context()->endLayer(); Color redBackground(0xFFFF8080); // 50% red composited on white. EXPECT_EQ(redBackground, getPixelAt(src->context(), 0, 0)); EXPECT_EQ(redBackground, getPixelAt(src->context(), 1, 1)); // Top half (minus two pixel border) should be 50% gray atop opaque // red = 0xFF804141. Then that's composited with 50% transparency on solid // white = 0xFFC0A1A1. Color darkRed(0xFFBF8080); EXPECT_EQ(darkRed, getPixelAt(src->context(), 2, 2)); EXPECT_EQ(darkRed, getPixelAt(src->context(), 7, 7)); // Bottom half (minus a two pixel border) should be a layer with 5% gray // with another 50% opacity composited atop white. Color darkWhite(0xFFBFBFBF); EXPECT_EQ(darkWhite, getPixelAt(src->context(), 8, 8)); EXPECT_EQ(darkWhite, getPixelAt(src->context(), 13, 13)); Color white(0xFFFFFFFF); // Background in the lower-right. EXPECT_EQ(white, getPixelAt(src->context(), 14, 14)); EXPECT_EQ(white, getPixelAt(src->context(), 15, 15)); }
void GameScreen::paintEvent(QPaintEvent * event) { if (r >= 255) { r_dir = RANGE_DOWN; g_dir = RANGE_UP; b_dir = RANGE_IDLE; } if (g >= 255) { r_dir = RANGE_IDLE; g_dir = RANGE_DOWN; b_dir = RANGE_UP; } if (b >= 255) { r_dir = RANGE_UP; g_dir = RANGE_IDLE; b_dir = RANGE_DOWN; } if (r_dir == RANGE_UP) { r += 5; } else if (r_dir == RANGE_DOWN){ r -= 5; } if (g_dir == RANGE_UP) { g += 5; } else if (g_dir == RANGE_DOWN){ g -= 5; } if (b_dir == RANGE_UP) { b += 5; } else if (b_dir == RANGE_DOWN) { b -= 5; } QColor white(255, 255, 255); QColor darkWhite(250, 250, 250); QColor pink(255, 192, 203); QColor brown(97, 25, 11); QColor rainbow(r, g, b); QColor neg_rainbow(255 - r, 255 - g, 255 - b); QPainter painter(this); painter.fillRect(0, 0, width(), height(), darkWhite); painter.setPen(QPen(Qt::black, 1)); if (mode == MODE_MENU) { painter.drawText(400, 300, "Press the Space Key to Start"); } else if (mode == MODE_RUNNING) { //draw coffee painter.setPen(QPen(darkWhite, 1)); for (int i = 0; i < coffee_loc.size(); i++) { painter.drawRect(coffee_loc[i].first * sq_s, coffee_loc[i].second * sq_s, sq_s, sq_s); painter.fillRect(coffee_loc[i].first * sq_s + 1, coffee_loc[i].second * sq_s + 1, sq_s - 1, sq_s - 1, rainbow); } //draw fruit painter.setPen(QPen(pink, 1)); painter.setBrush(pink); for (int i = 0; i < fruit_loc.size(); i++) { painter.drawEllipse((fruit_loc[i].first * sq_s), (fruit_loc[i].second * sq_s), sq_s, sq_s); } //draw snake painter.setPen(QPen(darkWhite, 1)); for (int i = 0; i < body.size(); i++) { painter.drawRect(body[i].first * sq_s, body[i].second * sq_s, sq_s, sq_s); painter.fillRect(body[i].first * sq_s + 1, body[i].second * sq_s + 1, sq_s - 1, sq_s - 1,neg_rainbow); } } else if (mode == MODE_GAMEOVER) { painter.setPen(QPen(Qt::lightGray, 1)); for (int i = 0; i < body.size(); i++) { painter.drawRect(body[i].first * sq_s, body[i].second * sq_s, sq_s, sq_s); painter.fillRect(body[i].first * sq_s + 1, body[i].second * sq_s + 1, sq_s - 1, sq_s - 1, Qt::gray); } painter.setPen(QPen(Qt::red, 1)); painter.drawText(400, 300, "GAMEOVER"); } }