// 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)); }
TEST(TransparencyWin, OpaqueCompositeLayerPixel) { Color red(0xFFFF0000), darkRed(0xFFBF0000); Color green(0xFF00FF00); // Make a red bottom layer, followed by a half green next layer @ 50%. OwnPtr<ImageBuffer> src(ImageBuffer::create(IntSize(16, 16), 1)); FloatRect fullRect(0, 0, 16, 16); src->context()->fillRect(fullRect, red); src->context()->beginTransparencyLayer(0.5); FloatRect rightHalf(8, 0, 8, 16); src->context()->fillRect(rightHalf, green); // Make a transparency layer inset by one pixel, and fill it inset by // another pixel with 50% black. { TransparencyWin helper; helper.init(src->context(), TransparencyWin::OpaqueCompositeLayer, TransparencyWin::KeepTransform, IntRect(1, 1, 14, 14)); FloatRect inner(2, 2, 12, 12); helper.context()->fillRect(inner, Color(0x7f000000)); // These coordinates are relative to the layer, whish is inset by 1x1 // pixels from the top left. So we're actually clearing (2, 2) and // (13,13), which are the extreme corners of the black area (and which // we check below). clearTopLayerAlphaPixel(helper.context(), 1, 1); clearTopLayerAlphaPixel(helper.context(), 12, 12); helper.composite(); } // Finish the compositing. src->context()->endLayer(); // Check that we got the right values, it should be like the rectangle was // drawn with half opacity even though the alpha channel got messed up. EXPECT_EQ(red, getPixelAt(src->context(), 0, 0)); EXPECT_EQ(red, getPixelAt(src->context(), 1, 1)); EXPECT_EQ(darkRed, getPixelAt(src->context(), 2, 2)); // The dark result is: // (black @ 50% atop green) @ 50% atop red = 0xFF804000 // which is 0xFFA02000 (Skia computes 0xFFA11F00 due to rounding). Color darkGreenRed(0xFF803f00); EXPECT_EQ(darkGreenRed, getPixelAt(src->context(), 13, 13)); // 50% green on top of red = FF808000 (rounded to what Skia will produce). Color greenRed(0xFF807F00); EXPECT_EQ(greenRed, getPixelAt(src->context(), 14, 14)); EXPECT_EQ(greenRed, getPixelAt(src->context(), 15, 15)); }
//---------------------------------------------------------------------------- Node* RoughPlaneSolidBox::CreateBox () { mBox = new0 Node(); float xExtent = (float)mModule.XLocExt; float yExtent = (float)mModule.YLocExt; float zExtent = (float)mModule.ZLocExt; VertexFormat* vformat = VertexFormat::Create(2, VertexFormat::AU_POSITION, VertexFormat::AT_FLOAT3, 0, VertexFormat::AU_COLOR, VertexFormat::AT_FLOAT3, 0); StandardMesh sm(vformat); VertexColor3Effect* effect = new0 VertexColor3Effect(); VertexBufferAccessor vba; Transform transform; TriMesh* face; int i; // +z face Float3 red(1.0f, 0.0f, 0.0f); transform.SetTranslate(APoint(0.0f, 0.0f, zExtent)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, xExtent, yExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = red; vba.Color<Float3>(0, 1) = red; vba.Color<Float3>(0, 2) = red; vba.Color<Float3>(0, 3) = red; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // -z face Float3 darkRed(0.5f, 0.0f, 0.0f); transform.SetTranslate(APoint(0.0f, 0.0f, -zExtent)); transform.SetRotate(HMatrix(AVector::UNIT_Y, AVector::UNIT_X, -AVector::UNIT_Z, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, yExtent, xExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = darkRed; vba.Color<Float3>(0, 1) = darkRed; vba.Color<Float3>(0, 2) = darkRed; vba.Color<Float3>(0, 3) = darkRed; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // +y face Float3 green(0.0f, 1.0f, 0.0f); transform.SetTranslate(APoint(0.0f, yExtent, 0.0f)); transform.SetRotate(HMatrix(AVector::UNIT_Z, AVector::UNIT_X, AVector::UNIT_Y, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, zExtent, xExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = green; vba.Color<Float3>(0, 1) = green; vba.Color<Float3>(0, 2) = green; vba.Color<Float3>(0, 3) = green; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // -y face Float3 darkGreen(0.0f, 1.0f, 0.0f); transform.SetTranslate(APoint(0.0f, -yExtent, 0.0f)); transform.SetRotate(HMatrix(AVector::UNIT_X, AVector::UNIT_Z, -AVector::UNIT_Y, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, xExtent, zExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = darkGreen; vba.Color<Float3>(0, 1) = darkGreen; vba.Color<Float3>(0, 2) = darkGreen; vba.Color<Float3>(0, 3) = darkGreen; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // +x face Float3 blue(0.0f, 0.0f, 1.0f); transform.SetTranslate(APoint(xExtent, 0.0f, 0.0f)); transform.SetRotate(HMatrix(AVector::UNIT_Y, AVector::UNIT_Z, AVector::UNIT_X, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, yExtent, zExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = blue; vba.Color<Float3>(0, 1) = blue; vba.Color<Float3>(0, 2) = blue; vba.Color<Float3>(0, 3) = blue; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); // -x face Float3 darkBlue(0.0f, 0.0f, 1.0f); transform.SetTranslate(APoint(-xExtent, 0.0f, 0.0f)); transform.SetRotate(HMatrix(AVector::UNIT_Z, AVector::UNIT_Y, -AVector::UNIT_X, APoint::ORIGIN, true)); sm.SetTransform(transform); face = sm.Rectangle(2, 2, zExtent, yExtent); vba.ApplyTo(face); for (i = 0; i < 4; ++i) { vba.Color<Float3>(0, 0) = darkBlue; vba.Color<Float3>(0, 1) = darkBlue; vba.Color<Float3>(0, 2) = darkBlue; vba.Color<Float3>(0, 3) = darkBlue; } face->SetEffectInstance(effect->CreateInstance()); mBox->AttachChild(face); MoveBox(); return mBox; }
void CodeView::paintEvent ( QPaintEvent * event ) { int rowHeight = getRowHeight(); QColor darkRed(100,0,0); QPainter painter(this); // Draw background painter.fillRect(event->rect(), Qt::black); // Border QRect rect = event->rect(); rect.setRight(BORDER_WIDTH); QColor borderColor; borderColor = QColor(60,60,60); painter.fillRect(rect, borderColor); // Show breakpoints for(int j = 0;j < m_breakpointList.size();j++) { int lineNo = m_breakpointList[j]; int rowIdx = lineNo-1; int y = rowHeight*rowIdx; QRect rect2(5,y,BORDER_WIDTH-10,rowHeight); painter.fillRect(rect2, Qt::blue); } // Draw content painter.setFont(m_font); for(size_t rowIdx = 0;rowIdx < m_highlighter.getRowCount();rowIdx++) { //int x = BORDER_WIDTH+10; int y = rowHeight*rowIdx; QString nrText; if((int)rowIdx == m_cursorY-1) { QRect rect2(BORDER_WIDTH,y,event->rect().width()-1,rowHeight); painter.fillRect(rect2, darkRed); } int fontY = y+(rowHeight-(m_fontInfo->ascent()+m_fontInfo->descent()))/2+m_fontInfo->ascent(); painter.setPen(Qt::white); nrText = QString("%1").arg(rowIdx+1); painter.drawText(4, fontY, nrText); QVector<TextField*> cols = m_highlighter.getRow(rowIdx); int x = BORDER_WIDTH+10; for(int j = 0;j < cols.size();j++) { TextField *field = cols[j]; painter.setPen(field->m_color); painter.drawText(x, fontY, field->m_text); x += m_fontInfo->width(field->m_text); } } }