| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2013 Google Inc. | |
| 3 * | |
| 4 * | |
| 5 * Use of this source code is governed by a BSD-style license that can be | |
| 6 * found in the LICENSE file. | |
| 7 * | |
| 8 */ | |
| 9 | |
| 10 #include "BaseExample.h" | |
| 11 | |
| 12 #include "SkApplication.h" | |
| 13 #include "SkDraw.h" | |
| 14 #include "SkGradientShader.h" | |
| 15 #include "SkGraphics.h" | |
| 16 #include "SkUnitMappers.h" | |
| 17 | |
| 18 class HelloSkia : public BaseExample { | |
| 19 public: | |
| 20 HelloSkia(void* hWnd, int argc, char** argv) | |
| 21 : INHERITED(hWnd, argc, argv) | |
| 22 { | |
| 23 fBGColor = SK_ColorWHITE; | |
| 24 fRotationAngle = SkIntToScalar(0); | |
| 25 | |
| 26 setupBackend(kGPU_DeviceType); | |
| 27 // Another option is software rendering: | |
| 28 // setupBackend(kRaster_DeviceType); | |
| 29 } | |
| 30 | |
| 31 protected: | |
| 32 virtual void draw(SkCanvas* canvas) SK_OVERRIDE { | |
| 33 // Clear background | |
| 34 canvas->drawColor(fBGColor); | |
| 35 | |
| 36 SkPaint paint; | |
| 37 paint.setColor(SK_ColorRED); | |
| 38 | |
| 39 // Draw a rectangle with blue paint | |
| 40 SkRect rect = { | |
| 41 SkIntToScalar(10), SkIntToScalar(10), | |
| 42 SkIntToScalar(128), SkIntToScalar(128) | |
| 43 }; | |
| 44 canvas->drawRect(rect, paint); | |
| 45 | |
| 46 // Set up a linear gradient and draw a circle | |
| 47 { | |
| 48 SkPoint linearPoints[] = { | |
| 49 {SkIntToScalar(0), SkIntToScalar(0)}, | |
| 50 {SkIntToScalar(300), SkIntToScalar(300)} | |
| 51 }; | |
| 52 SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; | |
| 53 | |
| 54 SkUnitMapper* linearMapper = new SkDiscreteMapper(100); | |
| 55 SkAutoUnref lm_deleter(linearMapper); | |
| 56 | |
| 57 SkShader* shader = SkGradientShader::CreateLinear( | |
| 58 linearPoints, linearColors, NULL, 2, | |
| 59 SkShader::kMirror_TileMode, linearMapper); | |
| 60 SkAutoUnref shader_deleter(shader); | |
| 61 | |
| 62 paint.setShader(shader); | |
| 63 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 64 | |
| 65 canvas->drawCircle(SkIntToScalar(200), SkIntToScalar(200), | |
| 66 SkIntToScalar(64), paint); | |
| 67 | |
| 68 // Detach shader | |
| 69 paint.setShader(NULL); | |
| 70 } | |
| 71 | |
| 72 | |
| 73 // Draw a message with a nice black paint. | |
| 74 paint.setFlags( | |
| 75 SkPaint::kAntiAlias_Flag | | |
| 76 SkPaint::kSubpixelText_Flag | // ... avoid waggly text when
rotating. | |
| 77 SkPaint::kUnderlineText_Flag); | |
| 78 paint.setColor(SK_ColorBLACK); | |
| 79 paint.setTextSize(SkIntToScalar(20)); | |
| 80 | |
| 81 canvas->save(); | |
| 82 | |
| 83 static const char message[] = "Hello Skia!!!"; | |
| 84 | |
| 85 // Translate and rotate | |
| 86 canvas->translate(SkIntToScalar(300), SkIntToScalar(300)); | |
| 87 fRotationAngle += SkDoubleToScalar(0.2); | |
| 88 if (fRotationAngle > SkDoubleToScalar(360.0)) { | |
| 89 fRotationAngle -= SkDoubleToScalar(360.0); | |
| 90 } | |
| 91 canvas->rotate(fRotationAngle); | |
| 92 | |
| 93 // Draw the text: | |
| 94 canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntTo
Scalar(0), paint); | |
| 95 | |
| 96 canvas->restore(); | |
| 97 | |
| 98 // Invalidate the window to force a redraw. Poor man's animation mec
hanism. | |
| 99 this->inval(NULL); | |
| 100 | |
| 101 INHERITED::draw(canvas); | |
| 102 } | |
| 103 | |
| 104 private: | |
| 105 SkScalar fRotationAngle; | |
| 106 SkColor fBGColor; | |
| 107 typedef BaseExample INHERITED; | |
| 108 }; | |
| 109 | |
| 110 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { | |
| 111 return new HelloSkia(hwnd, argc, argv); | |
| 112 } | |
| OLD | NEW |