void HelloWorldWindow::drawContents(SkCanvas* canvas) { // Clear background canvas->drawColor(SK_ColorWHITE); SkPaint paint; paint.setColor(SK_ColorRED); // Draw a rectangle with red paint SkRect rect = { 10, 10, 128, 128 }; canvas->drawRect(rect, paint); // Set up a linear gradient and draw a circle { SkPoint linearPoints[] = { {0, 0}, {300, 300} }; SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; SkShader* shader = SkGradientShader::CreateLinear( linearPoints, linearColors, NULL, 2, SkShader::kMirror_TileMode); SkAutoUnref shader_deleter(shader); paint.setShader(shader); paint.setFlags(SkPaint::kAntiAlias_Flag); canvas->drawCircle(200, 200, 64, paint); // Detach shader paint.setShader(NULL); } // Draw a message with a nice black paint. paint.setFlags( SkPaint::kAntiAlias_Flag | SkPaint::kSubpixelText_Flag | // ... avoid waggly text when rotating. SkPaint::kUnderlineText_Flag); paint.setColor(SK_ColorBLACK); paint.setTextSize(20); canvas->save(); static const char message[] = "Hello World"; // Translate and rotate canvas->translate(300, 300); fRotationAngle += 0.2f; if (fRotationAngle > 360) { fRotationAngle -= 360; } canvas->rotate(fRotationAngle); // Draw the text: canvas->drawText(message, strlen(message), 0, 0, paint); canvas->restore(); }
static void drawInBitmap(SkBitmap &bitmap) { SkCanvas canvas(bitmap); canvas.clear(SK_ColorWHITE); SkPaint myPaint; myPaint.setAntiAlias(true); myPaint.setColor(SK_ColorBLACK); myPaint.setStrokeWidth(SkIntToScalar(1)); canvas.translate(SkIntToScalar(36), SkIntToScalar(36)); canvas.scale(SkIntToScalar(1), SkIntToScalar(-1)); canvas.scale(SkDoubleToScalar(0.17), SkDoubleToScalar(0.17)); { SkPoint linearPoints[] = { {SkIntToScalar(-58), SkIntToScalar(13)}, {SkIntToScalar(-58+(116/2)), SkIntToScalar(13)} }; SkColor linearColors[] = {SK_ColorBLACK, SK_ColorLTGRAY}; SkShader* shader = SkGradientShader::CreateLinear( linearPoints, linearColors, NULL, 2, SkShader::kMirror_TileMode); SkAutoUnref shader_deleter(shader); myPaint.setShader(shader); myPaint.setFlags(SkPaint::kAntiAlias_Flag); SkRect rect0; rect0.setXYWH(SkIntToScalar(-58), SkIntToScalar(13), SkIntToScalar(116), SkIntToScalar(76)); canvas.drawRect(rect0,myPaint); // Detach shader myPaint.setShader(NULL); } myPaint.setColor(SK_ColorBLACK); myPaint.setStyle(SkPaint::kStrokeAndFill_Style); SkRect rect; rect.setXYWH(SkIntToScalar(-60), SkIntToScalar(75), SkIntToScalar(120), SkIntToScalar(6)); canvas.drawRect(rect, myPaint); SkRect rect1; rect1.setXYWH(SkIntToScalar(-60), SkIntToScalar(61), SkIntToScalar(120), SkIntToScalar(6)); canvas.drawRect(rect1, myPaint); SkRect rect2; rect2.setXYWH(SkIntToScalar(-60), SkIntToScalar(49), SkIntToScalar(120), SkIntToScalar(6)); canvas.drawRect(rect2, myPaint); SkPoint pts0[] = { {-60,11}, {-42,23}, {38,23}, {56,11}, {-60,11} }; myPaint.setColor(SK_ColorBLUE); myPaint.setStyle(SkPaint::kStroke_Style); SkPath path0; path0.addPoly(pts0, 5, true); canvas.drawPath(path0, myPaint); path0.addPoly(pts0, 5, true); myPaint.setColor(SK_ColorWHITE); myPaint.setStyle(SkPaint::kFill_Style); canvas.drawPath(path0, myPaint); myPaint.setColor(SK_ColorBLACK); myPaint.setStyle(SkPaint::kStroke_Style); canvas.drawLine(SkIntToScalar(-100), SkIntToScalar(-90), SkIntToScalar(100), SkIntToScalar(-91), myPaint); canvas.drawLine(SkIntToScalar(0), SkIntToScalar(-90), SkIntToScalar(26), SkIntToScalar(-58), myPaint); canvas.drawLine(SkIntToScalar(26), SkIntToScalar(-58), SkIntToScalar(-2), SkIntToScalar(37), myPaint); myPaint.setStyle(SkPaint::kStrokeAndFill_Style); canvas.drawCircle(SkIntToScalar(0), SkIntToScalar(33), SkIntToScalar(4), myPaint); myPaint.setStyle(SkPaint::kStroke_Style); canvas.drawCircle(SkDoubleToScalar(0), SkDoubleToScalar(-(129+49)/2), SkIntToScalar(40), myPaint); myPaint.setColor(SK_ColorLTGRAY); myPaint.setStyle(SkPaint::kStrokeAndFill_Style); SkPoint pts[9]; pts[0].set(-60, -50); pts[1].set(-60, 100); pts[2].set( 60, 100); pts[3].set(60, -52); pts[4].set(100, -52); pts[5].set(100, 150); pts[6].set(-100, 150); pts[7].set(-100, -50); pts[8].set(-60, -50); SkPath path; path.addPoly(pts, 9, false); canvas.drawPath(path, myPaint); myPaint.setColor(SK_ColorBLACK); myPaint.setStyle(SkPaint::kStroke_Style); canvas.drawPath(path, myPaint); SkRect inrect; inrect.setXYWH(SkIntToScalar(-105), SkIntToScalar(100), SkIntToScalar(15), SkIntToScalar(45)); myPaint.setColor(SK_ColorLTGRAY); myPaint.setStyle(SkPaint::kFill_Style); canvas.drawRect(inrect, myPaint); myPaint.setColor(SK_ColorGRAY); myPaint.setStyle(SkPaint::kStroke_Style); canvas.drawRect(inrect, myPaint); SkRect inrect1; inrect1.setXYWH(SkIntToScalar(90), SkIntToScalar(100), SkIntToScalar(15), SkIntToScalar(45)); myPaint.setColor(SK_ColorLTGRAY); myPaint.setStyle(SkPaint::kFill_Style); canvas.drawRect(inrect1, myPaint); myPaint.setColor(SK_ColorGRAY); myPaint.setStyle(SkPaint::kStroke_Style); canvas.drawRect(inrect1, myPaint); SkRect inrect2; inrect2.setXYWH(SkIntToScalar(-105), SkIntToScalar(-115), SkIntToScalar(15), SkIntToScalar(45)); myPaint.setColor(SK_ColorLTGRAY); myPaint.setStyle(SkPaint::kFill_Style); canvas.drawRect(inrect2, myPaint); myPaint.setColor(SK_ColorGRAY); myPaint.setStyle(SkPaint::kStroke_Style); canvas.drawRect(inrect2, myPaint); SkRect inrect3; inrect3.setXYWH(SkIntToScalar(90), SkIntToScalar(-115), SkIntToScalar(15), SkIntToScalar(45)); myPaint.setColor(SK_ColorLTGRAY); myPaint.setStyle(SkPaint::kFill_Style); canvas.drawRect(inrect3, myPaint); myPaint.setColor(SK_ColorGRAY); myPaint.setStyle(SkPaint::kStroke_Style); canvas.drawRect(inrect3, myPaint); }