void VGContext::releasePaint(VGbitfield paintModes) { if(paintModes & VG_FILL_PATH) { //release previous paint Paint* prev = (Paint*)m_fillPaint; if(prev) { if(!prev->removeReference()) RI_DELETE(prev); } m_fillPaint = VG_INVALID_HANDLE; } if(paintModes & VG_STROKE_PATH) { //release previous paint Paint* prev = (Paint*)m_strokePaint; if(prev) { if(!prev->removeReference()) RI_DELETE(prev); } m_strokePaint = VG_INVALID_HANDLE; } }
virtual void OnDraw(const Context &context) override { using wiztk::graphic::Canvas; using wiztk::graphic::Paint; const RectF &rect = GetBounds(); int scale = context.surface()->GetScale(); Canvas *canvas = context.canvas(); canvas->Save(); canvas->Scale(scale, scale); Paint paint; paint.SetColor(ColorF(0.855f, 0.855f, 0.165f, .9f)); canvas->DrawRect(rect, paint); canvas->Restore(); SkCanvas *sk_canvas = canvas->GetSkCanvas(); SkImageInfo info = SkImageInfo::MakeN32(400, 400, kPremul_SkAlphaType); sk_sp<SkSurface> surface = sk_canvas->makeSurface(info); SkCanvas *top_canvas = surface->getCanvas(); SkRect top_rect = SkRect::MakeXYWH(50, 50, 100, 100); SkPaint top_paint; top_paint.setColor(0xFFFF0000); top_canvas->drawRect(top_rect, top_paint); top_canvas->flush(); surface->draw(sk_canvas, 100, 100, nullptr); canvas->Flush(); }
static void drawBitmap(JNIEnv* env, jobject jcanvas, jlong canvasHandle, jlong bitmapHandle, jfloat left, jfloat top, jlong paintHandle, jint canvasDensity, jint screenDensity, jint bitmapDensity) { Canvas* canvas = get_canvas(canvasHandle); const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle); if (canvasDensity == bitmapDensity || canvasDensity == 0 || bitmapDensity == 0) { if (screenDensity != 0 && screenDensity != bitmapDensity) { Paint filteredPaint; if (paint) { filteredPaint = *paint; } filteredPaint.setFilterLevel(Paint::kLow_FilterLevel); canvas->drawBitmap(*bitmap, left, top, &filteredPaint); } else { canvas->drawBitmap(*bitmap, left, top, paint); } } else { canvas->save(SkCanvas::kMatrixClip_SaveFlag); SkScalar scale = canvasDensity / (float)bitmapDensity; canvas->translate(left, top); canvas->scale(scale, scale); Paint filteredPaint; if (paint) { filteredPaint = *paint; } filteredPaint.setFilterLevel(Paint::kLow_FilterLevel); canvas->drawBitmap(*bitmap, 0, 0, &filteredPaint); canvas->restore(); } }
static void android_view_DisplayListCanvas_drawRegionAsRects(JNIEnv* env, jobject clazz, jlong rendererPtr, jlong regionPtr, jlong paintPtr) { DisplayListCanvas* renderer = reinterpret_cast<DisplayListCanvas*>(rendererPtr); SkRegion* region = reinterpret_cast<SkRegion*>(regionPtr); Paint* paint = reinterpret_cast<Paint*>(paintPtr); if (paint->getStyle() != Paint::kFill_Style || (paint->isAntiAlias() && !renderer->isCurrentTransformSimple())) { SkRegion::Iterator it(*region); while (!it.done()) { const SkIRect& r = it.rect(); renderer->drawRect(r.fLeft, r.fTop, r.fRight, r.fBottom, *paint); it.next(); } } else { int count = 0; Vector<float> rects; SkRegion::Iterator it(*region); while (!it.done()) { const SkIRect& r = it.rect(); rects.push(r.fLeft); rects.push(r.fTop); rects.push(r.fRight); rects.push(r.fBottom); count += 4; it.next(); } renderer->drawRects(rects.array(), count, paint); } }
// Regular JNI static void nAddStyleRun(JNIEnv* /* unused */, jclass /* unused */, jlong builderPtr, jlong paintPtr, jint start, jint end, jboolean isRtl) { Paint* paint = toPaint(paintPtr); const Typeface* typeface = Typeface::resolveDefault(paint->getAndroidTypeface()); minikin::MinikinPaint minikinPaint = MinikinUtils::prepareMinikinPaint(paint, typeface); toBuilder(builderPtr)->addStyleRun(start, end, std::move(minikinPaint), isRtl); }
int main(int argc, char* argv[]) { string input; Scan scan; Paint print; if (argc == 2)//无-a -f { input = argv[1]; scan.ToStringQueue(input); print.Printqueue(); } else if (argc == 3 )//第二个参数-a { input = argv[2]; cout << input << " "; scan.ToStringQueue(input); print.Printqueue(); } else// -f的情况 { fout.open(argv[3]); flag = 4; ifstream fin; fin.open(argv[2]); if (fin.is_open()) { while (fin.good() && !fin.eof())//读取到文件尾停止读入 { string message;//先将运算式存入message 再转存如input进行操作 fin >> message; input = message; ssss = argv[3]; scan.ToStringQueue(input); print.Printqueue(); } } } system("pause"); return 0; }
void Canvas::drawAtlas(CanvasImage* atlas, const Vector<RSTransform>& transforms, const Vector<Rect>& rects, const Vector<SkColor>& colors, TransferMode mode, const Rect& cullRect, const Paint& paint) { if (!m_canvas) return; RefPtr<SkImage> skImage = atlas->image(); Vector<SkRSXform> skXForms; skXForms.reserveInitialCapacity(transforms.size()); for (const RSTransform& transform : transforms) skXForms.append(transform.sk_xform); Vector<SkRect> skRects; skRects.reserveInitialCapacity(rects.size()); for (const Rect& rect : rects) skRects.append(rect.sk_rect); m_canvas->drawAtlas( skImage.get(), skXForms.data(), skRects.data(), colors.isEmpty() ? nullptr : colors.data(), skXForms.size(), mode, cullRect.is_null ? nullptr : &cullRect.sk_rect, paint.paint() ); }
void Canvas::saveLayer(const Rect& bounds, const Paint& paint) { if (!m_canvas) return; m_canvas->saveLayer(!bounds.is_null ? &bounds.sk_rect : nullptr, paint.paint()); }
void Canvas::drawImageNine(const CanvasImage* image, Rect& center, Rect& dst, const Paint& paint) { if (!m_canvas) return; ASSERT(image); SkIRect icenter; center.sk_rect.round(&icenter); m_canvas->drawImageNine(image->image(), icenter, dst.sk_rect, paint.paint()); }
void Spinner::Private::Draw(const Context &context) { angle += 5.f; if (angle > 360.f) angle = 0.f; Canvas *canvas = context.canvas(); int scale = context.surface()->GetScale(); canvas->Scale(scale, scale); const RectF &rect = proprietor()->GetBounds(); float radius = base::Clamp(std::min(rect.width(), rect.height()) / 2.f - 50.f, 50.f, 200.f); Paint paint; paint.SetAntiAlias(true); paint.SetColor(background); paint.SetStyle(Paint::Style::kStyleFill); canvas->DrawRect(rect, paint); paint.SetColor(ColorF(foreground)); paint.SetStyle(Paint::Style::kStyleStroke); paint.SetStrokeWidth(6.f); canvas->DrawArc(RectF(rect.center_x() - radius, rect.center_y() - radius, rect.center_x() + radius, rect.center_y() + radius), angle, 300.f, false, paint); frame_callback.Setup(context.surface()); }
void doFrame(int frameNr) override { const char* text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; std::unique_ptr<Canvas> canvas( Canvas::create_recording_canvas(container->stagingProperties().getWidth(), container->stagingProperties().getHeight(), container.get())); Paint paint; paint.setAntiAlias(true); paint.setColor(Color::Black); for (int i = 0; i < 5; i++) { paint.setTextSize(10 + (frameNr % 20) + i * 20); TestUtils::drawUtf8ToCanvas(canvas.get(), text, paint, 0, 100 * (i + 2)); } container->setStagingDisplayList(canvas->finishRecording()); }
void Canvas::saveLayer(double left, double top, double right, double bottom, const Paint& paint) { if (!m_canvas) return; SkRect bounds = SkRect::MakeLTRB(left, top, right, bottom); m_canvas->saveLayer(&bounds, paint.paint()); }
void Canvas::drawVertices(SkCanvas::VertexMode vertexMode, const Vector<Point>& vertices, const Vector<Point>& textureCoordinates, const Vector<SkColor>& colors, SkXfermode::Mode transferMode, const Vector<int>& indices, const Paint& paint, ExceptionState& es) { if (!m_canvas) return; size_t vertexCount = vertices.size(); if (textureCoordinates.size() && textureCoordinates.size() != vertexCount) return es.ThrowRangeError("vertices and textureCoordinates lengths must match"); if (colors.size() && colors.size() != vertexCount) return es.ThrowRangeError("vertices and colors lengths must match"); Vector<SkPoint> skVertices; for (size_t x = 0; x < vertices.size(); x++) { const Point& point = vertices[x]; if (point.is_null) return es.ThrowRangeError("vertices contained a null"); skVertices.append(point.sk_point); } Vector<SkPoint> skTextureCoordinates; for (size_t x = 0; x < textureCoordinates.size(); x++) { const Point& point = textureCoordinates[x]; if (point.is_null) return es.ThrowRangeError("textureCoordinates contained a null"); skTextureCoordinates.append(point.sk_point); } Vector<uint16_t> skIndices; for (size_t x = 0; x < indices.size(); x++) { uint16_t i = indices[x]; skIndices.append(i); } RefPtr<SkXfermode> transferModePtr = adoptRef(SkXfermode::Create(transferMode)); m_canvas->drawVertices( vertexMode, skVertices.size(), skVertices.data(), skTextureCoordinates.isEmpty() ? nullptr : skTextureCoordinates.data(), colors.isEmpty() ? nullptr : colors.data(), transferModePtr.get(), skIndices.isEmpty() ? nullptr : skIndices.data(), skIndices.size(), *paint.paint() ); }
void doFrame(int frameNr) override { std::unique_ptr<uint16_t[]> text = TestUtils::asciiToUtf16( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); ssize_t textLength = 26 * 2; TestCanvas canvas( container->stagingProperties().getWidth(), container->stagingProperties().getHeight()); Paint paint; paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); paint.setAntiAlias(true); paint.setColor(Color::Black); for (int i = 0; i < 5; i++) { paint.setTextSize(10 + (frameNr % 20) + i * 20); canvas.drawText(text.get(), 0, textLength, textLength, 0, 100 * (i + 2), kBidi_Force_LTR, paint, nullptr); } container->setStagingDisplayList(canvas.finishRecording(), nullptr); }
static void drawBitmapRect(JNIEnv* env, jobject, jlong canvasHandle, jlong bitmapHandle, float srcLeft, float srcTop, float srcRight, float srcBottom, float dstLeft, float dstTop, float dstRight, float dstBottom, jlong paintHandle, jint screenDensity, jint bitmapDensity) { Canvas* canvas = get_canvas(canvasHandle); const SkBitmap* bitmap = reinterpret_cast<SkBitmap*>(bitmapHandle); const Paint* paint = reinterpret_cast<Paint*>(paintHandle); if (screenDensity != 0 && screenDensity != bitmapDensity) { Paint filteredPaint; if (paint) { filteredPaint = *paint; } filteredPaint.setFilterLevel(Paint::kLow_FilterLevel); canvas->drawBitmap(*bitmap, srcLeft, srcTop, srcRight, srcBottom, dstLeft, dstTop, dstRight, dstBottom, &filteredPaint); } else { canvas->drawBitmap(*bitmap, srcLeft, srcTop, srcRight, srcBottom, dstLeft, dstTop, dstRight, dstBottom, paint); } }
void TitleBar::CloseButton::OnDraw(const Context &context) { Canvas *canvas = context.canvas(); int scale = context.surface()->GetScale(); const RectF &rect = GetBounds(); canvas->Scale(scale, scale); Paint paint; paint.SetAntiAlias(true); base::ColorF background = 0xFFDD6666; if (IsHovered()) { if (IsPressed()) { background -= 45; } else { background += 35; } } paint.SetStyle(Paint::Style::kStyleFill); paint.SetColor(background); canvas->DrawCircle(rect.center_x(), rect.center_y(), 7.f, paint); // paint.SetColor(Theme::GetData().title_bar.active.foreground.color); paint.SetColor(0xFFDDDDDD); paint.SetStrokeWidth(1.5f); canvas->DrawLine(rect.center_x() - 3.f, rect.center_y() - 3.f, rect.center_x() + 3.f, rect.center_y() + 3.f, paint); canvas->DrawLine(rect.center_x() + 3.f, rect.center_y() - 3.f, rect.center_x() - 3.f, rect.center_y() + 3.f, paint); }
void SliderView::draw(ICanvas& c){ Paint paint; paint.setStyle( Paint::eSTYLE_FILL_AND_STROKE ); paint.setFillColor( mBaseColor ); paint.setStrokeColor( mBorderColor ); // Base rect c.drawRect(0, 0, getSize().x, getSize().y, &paint); // Slider paint.setStyle( Paint::eSTYLE_FILL ); paint.setFillColor( mSliderColor ); if(mMode == eMODE_HORIZONTAL){ // Progress rect float pos = glm::mix(0.0f, getSize().x - mBarWidth, mValue/100.0f); c.drawRect(pos, 0, mBarWidth, getSize().y, &paint); } else{ float pos = glm::mix(0.0f, getSize().y - mBarWidth, mValue/100.0f); c.drawRect(0, pos, mBarWidth, getSize().x, &paint); } }
void Canvas::drawVertices(SkCanvas::VertexMode vertexMode, const std::vector<Point>& vertices, const std::vector<Point>& textureCoordinates, const std::vector<CanvasColor>& colors, TransferMode transferMode, const std::vector<int>& indices, const Paint& paint) { if (!m_canvas) return; std::vector<SkPoint> skVertices; skVertices.reserve(vertices.size()); for (const Point& point : vertices) skVertices.push_back(point.sk_point); std::vector<SkPoint> skTextureCoordinates; skVertices.reserve(textureCoordinates.size()); for (const Point& point : textureCoordinates) skTextureCoordinates.push_back(point.sk_point); std::vector<SkColor> skColors; skColors.reserve(colors.size()); for (const CanvasColor& color : colors) skColors.push_back(color); std::vector<uint16_t> skIndices; skIndices.reserve(indices.size()); for (uint16_t i : indices) skIndices.push_back(i); RefPtr<SkXfermode> transferModePtr = adoptRef(SkXfermode::Create(transferMode)); m_canvas->drawVertices( vertexMode, skVertices.size(), skVertices.data(), skTextureCoordinates.empty() ? nullptr : skTextureCoordinates.data(), skColors.empty() ? nullptr : skColors.data(), transferModePtr.get(), skIndices.empty() ? nullptr : skIndices.data(), skIndices.size(), *paint.paint() ); }
void Canvas::drawImageRect(const CanvasImage* image, double srcLeft, double srcTop, double srcRight, double srcBottom, double dstLeft, double dstTop, double dstRight, double dstBottom, const Paint& paint) { if (!m_canvas) return; ASSERT(image); m_canvas->drawImageRect(image->image(), SkRect::MakeLTRB(srcLeft, srcTop, srcRight, srcBottom), SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom), paint.paint(), SkCanvas::kFast_SrcRectConstraint); }
void Canvas::drawImageNine(const CanvasImage* image, double centerLeft, double centerTop, double centerRight, double centerBottom, double dstLeft, double dstTop, double dstRight, double dstBottom, const Paint& paint) { if (!m_canvas) return; ASSERT(image); SkRect center = SkRect::MakeLTRB(centerLeft, centerTop, centerRight, centerBottom); SkIRect icenter; center.round(&icenter); m_canvas->drawImageNine(image->image(), icenter, SkRect::MakeLTRB(dstLeft, dstTop, dstRight, dstBottom), paint.paint()); }
void Canvas::drawAtlas(CanvasImage* atlas, const Vector<RSTransform>& transforms, const Vector<Rect>& rects, const Vector<SkColor>& colors, SkXfermode::Mode mode, const Rect& cullRect, const Paint& paint, ExceptionState& es) { if (!m_canvas) return; RefPtr<SkImage> skImage = atlas->image(); if (transforms.size() != rects.size()) return es.ThrowRangeError("transforms and rects lengths must match"); if (colors.size() && colors.size() != rects.size()) return es.ThrowRangeError("if supplied, colors length must match that of transforms and rects"); Vector<SkRSXform> skXForms; for (size_t x = 0; x < transforms.size(); x++) { const RSTransform& transform = transforms[x]; if (transform.is_null) return es.ThrowRangeError("transforms contained a null"); skXForms.append(transform.sk_xform); } Vector<SkRect> skRects; for (size_t x = 0; x < rects.size(); x++) { const Rect& rect = rects[x]; if (rect.is_null) return es.ThrowRangeError("rects contained a null"); skRects.append(rect.sk_rect); } m_canvas->drawAtlas( skImage.get(), skXForms.data(), skRects.data(), colors.isEmpty() ? nullptr : colors.data(), skXForms.size(), mode, cullRect.is_null ? nullptr : &cullRect.sk_rect, paint.paint() ); }
void Canvas::drawVertices(SkCanvas::VertexMode vertexMode, const Vector<Point>& vertices, const Vector<Point>& textureCoordinates, const Vector<SkColor>& colors, TransferMode transferMode, const Vector<int>& indices, const Paint& paint) { if (!m_canvas) return; Vector<SkPoint> skVertices; skVertices.reserveInitialCapacity(vertices.size()); for (const Point& point : vertices) skVertices.append(point.sk_point); Vector<SkPoint> skTextureCoordinates; skVertices.reserveInitialCapacity(textureCoordinates.size()); for (const Point& point : textureCoordinates) skTextureCoordinates.append(point.sk_point); Vector<uint16_t> skIndices; skIndices.reserveInitialCapacity(indices.size()); for (uint16_t i : indices) skIndices.append(i); RefPtr<SkXfermode> transferModePtr = adoptRef(SkXfermode::Create(transferMode)); m_canvas->drawVertices( vertexMode, skVertices.size(), skVertices.data(), skTextureCoordinates.isEmpty() ? nullptr : skTextureCoordinates.data(), colors.isEmpty() ? nullptr : colors.data(), transferModePtr.get(), skIndices.isEmpty() ? nullptr : skIndices.data(), skIndices.size(), *paint.paint() ); }
void Canvas::drawAtlas(CanvasImage* atlas, const std::vector<RSTransform>& transforms, const std::vector<Rect>& rects, const std::vector<CanvasColor>& colors, TransferMode mode, const Rect& cullRect, const Paint& paint) { if (!m_canvas) return; RefPtr<SkImage> skImage = atlas->image(); std::vector<SkRSXform> skXForms; skXForms.reserve(transforms.size()); for (const RSTransform& transform : transforms) skXForms.push_back(transform.sk_xform); std::vector<SkRect> skRects; skRects.reserve(rects.size()); for (const Rect& rect : rects) skRects.push_back(rect.sk_rect); std::vector<SkColor> skColors; skColors.reserve(colors.size()); for (const CanvasColor& color : colors) skColors.push_back(color); m_canvas->drawAtlas( skImage.get(), skXForms.data(), skRects.data(), skColors.empty() ? nullptr : skColors.data(), skXForms.size(), mode, cullRect.is_null ? nullptr : &cullRect.sk_rect, paint.paint() ); }
void TitleBar::MinimizeButton::OnDraw(const Context &context) { Canvas *canvas = context.canvas(); int scale = context.surface()->GetScale(); const RectF &rect = GetBounds(); canvas->Scale(scale, scale); Paint paint; paint.SetAntiAlias(true); if (IsHovered()) { if (IsPressed()) { paint.SetColor(Theme::GetData().title_bar.highlight.foreground.colors[0]); paint.SetStyle(Paint::Style::kStyleFill); canvas->DrawCircle(rect.center_x(), rect.center_y(), 7.f, paint); paint.Reset(); paint.SetAntiAlias(true); } paint.SetStyle(Paint::Style::kStyleStroke); paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStrokeWidth(1.f); canvas->DrawCircle(rect.center_x(), rect.center_y(), 6.5f, paint); } paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStrokeWidth(1.5f); canvas->DrawLine(rect.center_x() - 4.f, rect.center_y(), rect.center_x() + 4.f, rect.center_y(), paint); }
void Canvas::saveLayerWithoutBounds(const Paint& paint) { if (!m_canvas) return; m_canvas->saveLayer(nullptr, paint.paint()); }
void StructuralReports:: saveMaterialBoundariesBeta_2(const GridDescription & grid, const VoxelizedPartition & vp) { ObjFile objFile; int ii,jj,kk; ostringstream foutname; foutname << grid.name() << "_faces.obj"; ofstream fout(foutname.str().c_str()); const Map<Paint*, SetupUpdateEquationPtr> materials(vp.setupMaterials()); map<Paint*, SetupUpdateEquationPtr>::const_iterator itr; const VoxelGrid & vg(vp.voxels()); //const StructureGrid& grid = *mStructureGrid; // We'll write the materials one at a time. for (itr = materials.begin(); itr != materials.end(); itr++) if ( (*itr).first == (*itr).first->withoutModifications()) { Paint* paint = (*itr).first; SetupUpdateEquationPtr mat = (*itr).second; string name = paint->fullName(); Rect3i roi = grid.nonPMLHalfCells(); Paint* lastMat; Paint* curMat; LOGF << "Considering material " << name << endl; //fout << name << endl; vector<OrientedRect3i> xFaces; vector<OrientedRect3i> yFaces; vector<OrientedRect3i> zFaces; // Do all the face determination stuff { // X-normal faces // a. Bottom layer ii = roi.p1[0]; for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++) for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++) { curMat = vg(ii, jj, kk); if (curMat == paint) { xFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii,jj+1,kk+1), Vector3i(-1, 0, 0)) ); } } // b. Top layer ii = roi.p2[0]; for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++) for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++) { curMat = vg(ii, jj, kk); if (curMat == paint) { xFaces.push_back( OrientedRect3i( Rect3i(ii+1,jj,kk,ii+1,jj+1,kk+1), Vector3i(1,0,0) )); } } // c. Middle (careful about X direction for-loop limits) for (ii = roi.p1[0]+1; ii <= roi.p2[0]; ii++) for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++) for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++) { lastMat = vg(ii-1, jj, kk); curMat = vg(ii, jj, kk); if (lastMat == paint && curMat != paint) { xFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii,jj+1,kk+1), Vector3i(1, 0, 0)) ); } else if (lastMat != paint && curMat == paint) { xFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii,jj+1,kk+1), Vector3i(-1,0,0) )); } } // Y-normal faces // a. Top layer jj = roi.p1[1]; for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++) for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++) { curMat = vg(ii, jj, kk); if (curMat == paint) { yFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii+1,jj,kk+1), Vector3i(0, -1, 0) )); } } // b. Bottom layer jj = roi.p2[1]; for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++) for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++) { curMat = vg(ii, jj, kk); if (curMat == paint) { yFaces.push_back( OrientedRect3i( Rect3i(ii,jj+1,kk,ii+1,jj+1,kk+1), Vector3i(0, 1, 0) )); } } // c. Middle (careful about X direction for-loop limits) for (jj = roi.p1[1]+1; jj <= roi.p2[1]; jj++) for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++) for (kk = roi.p1[2]; kk <= roi.p2[2]; kk++) { lastMat = vg(ii, jj-1, kk); curMat = vg(ii, jj, kk); if (lastMat == paint && curMat != paint) { yFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii+1,jj,kk+1), Vector3i(0, 1, 0) )); } else if (lastMat != paint && curMat == paint) { yFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii+1,jj,kk+1), Vector3i(0, -1, 0) )); } } // Z-normal faces // a. Top layer kk = roi.p1[2]; for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++) for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++) { curMat = vg(ii, jj, kk); if (curMat == paint) { zFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii+1,jj+1,kk), Vector3i(0, 0, -1) )); } } // b. Bottom layer kk = roi.p2[2]; for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++) for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++) { curMat = vg(ii, jj, kk); if (curMat == paint) { zFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk+1,ii+1,jj+1,kk+1), Vector3i(0, 0, 1) )); } } // c. Middle (careful about X direction for-loop limits) for (kk = roi.p1[2]+1; kk <= roi.p2[2]; kk++) for (jj = roi.p1[1]; jj <= roi.p2[1]; jj++) for (ii = roi.p1[0]; ii <= roi.p2[0]; ii++) { lastMat = vg(ii, jj, kk-1); curMat = vg(ii, jj, kk); if (lastMat == paint && curMat != paint) { zFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii+1,jj+1,kk), Vector3i(0, 0, 1) )); } else if (lastMat != paint && curMat == paint) { zFaces.push_back( OrientedRect3i( Rect3i(ii,jj,kk,ii+1,jj+1,kk), Vector3i(0, 0, -1) )); } } } // Now try to consolidate a little bit. list<OrientedRect3i> xCompressed; list<OrientedRect3i> yCompressed; list<OrientedRect3i> zCompressed; consolidateRects(xFaces, xCompressed, 0); consolidateRects(yFaces, yCompressed, 1); consolidateRects(zFaces, zCompressed, 2); /* ostream_iterator<OrientedRect3i> fout_itr(fout, "\n"); copy(xCompressed.begin(), xCompressed.end(), fout_itr); copy(yCompressed.begin(), yCompressed.end(), fout_itr); copy(zCompressed.begin(), zCompressed.end(), fout_itr); */ objFile.appendGroup(name, xCompressed); objFile.appendGroup(name, yCompressed); objFile.appendGroup(name, zCompressed); } objFile.write(fout, -grid.origin(), 0.5*grid.dxyz()); //objFile.write(fout, 0.5); // The scale factor 0.5 undoes half-cells. fout.close(); }
void Canvas::drawImageRect(const CanvasImage* image, Rect& src, Rect& dst, const Paint& paint) { if (!m_canvas) return; ASSERT(image); m_canvas->drawImageRect(image->image(), src.sk_rect, dst.sk_rect, paint.paint(), SkCanvas::kFast_SrcRectConstraint); }
void Canvas::drawImage(const CanvasImage* image, const Point& p, const Paint& paint) { if (!m_canvas) return; ASSERT(image); m_canvas->drawImage(image->image(), p.sk_point.x(), p.sk_point.y(), paint.paint()); }
void TitleBar::FullscreenButton::OnDraw(const Context &context) { Canvas *canvas = context.canvas(); int scale = context.surface()->GetScale(); const RectF &rect = GetBounds(); canvas->Scale(scale, scale); Paint paint; paint.SetAntiAlias(true); if (IsHovered()) { if (IsPressed()) { paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStyle(Paint::Style::kStyleFill); canvas->DrawCircle(rect.center_x(), rect.center_y(), 7.f, paint); paint.Reset(); paint.SetAntiAlias(true); } paint.SetStyle(Paint::Style::kStyleStroke); paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStrokeWidth(1.f); canvas->DrawCircle(rect.center_x(), rect.center_y(), 6.5f, paint); } paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); paint.SetStyle(Paint::Style::kStyleFill); Path path; path.MoveTo(-5.f, 0.f); path.RelativeLineTo(3.5f, -3.5f); path.RelativeLineTo(0.f, 7.f); path.Close(); canvas->Translate(rect.center_x(), rect.center_y()); canvas->Rotate(-45.f); canvas->DrawPath(path, paint); canvas->Rotate(180.f); canvas->DrawPath(path, paint); }
void TitleBar::OnDraw(const Context &context) { using namespace base; using namespace graphic; int scale = context.surface()->GetScale(); const RectF bounds = GetBounds() * scale; float factor = 0.5f * scale; Paint paint; paint.SetAntiAlias(true); paint.SetStyle(Paint::kStyleFill); Point2F points[2] = {{factor, bounds.top + factor}, {factor, bounds.bottom}}; uint32_t colors[2] = {0xFFE7E7E7, 0xFFD7D7D7}; float pos[2] = {0.f, 1.f}; Shader shader = GradientShader::MakeLinear(points, colors, pos, 2, Shader::kTileModeClamp); paint.SetShader(shader); context.canvas()->DrawRect(RectF::FromLTRB(bounds.left + factor, bounds.top + factor, bounds.right - factor, bounds.bottom), paint); paint.Reset(); paint.SetAntiAlias(true); paint.SetStyle(Paint::kStyleFill); paint.SetFont(font_); paint.SetTextSize(font_.GetSize() * scale); paint.SetColor(Theme::GetData().title_bar.active.foreground.colors[0]); float text_width = paint.MeasureText(title_.c_str(), title_.length()); SkTextBox text_box; // Put the foreground at the center text_box.setBox(bounds.l + (bounds.width() - text_width) / 2.f, bounds.t + 1.f, // move down a little for better look bounds.r - (bounds.width() - text_width) / 2.f, bounds.b); text_box.setSpacingAlign(SkTextBox::kCenter_SpacingAlign); text_box.setText(title_.c_str(), title_.length(), paint.GetSkPaint()); text_box.draw(context.canvas()->GetSkCanvas()); }