Chromium Code Reviews| 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); | |
|
caryclark
2013/06/17 15:08:39
add comment that caller can also use kRaster_Devic
| |
| 27 } | |
|
caryclark
2013/06/17 15:08:39
add a blank line
| |
| 28 protected: | |
| 29 virtual void draw(SkCanvas* canvas) SK_OVERRIDE { | |
| 30 // Clear background | |
| 31 canvas->drawColor(fBGColor); | |
| 32 | |
| 33 SkPaint paint; | |
| 34 paint.setColor(SK_ColorRED); // SkColor is ARGB | |
|
caryclark
2013/06/17 15:08:39
not sure the comment clarifies
| |
| 35 | |
| 36 // Draw a rectangle with blue paint | |
| 37 SkRect rect = {SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(1 28), SkIntToScalar(128)}; | |
|
caryclark
2013/06/17 15:08:39
too wide (rewrap to fit in 100 cols)
| |
| 38 canvas->drawRect(rect, paint); | |
| 39 | |
| 40 // Set up a linear gradient and draw a circle | |
| 41 { | |
| 42 SkPoint linearPoints[] = { | |
| 43 {SkIntToScalar(0), SkIntToScalar(0)}, {SkIntToScalar(300), S kIntToScalar(300)}}; | |
| 44 SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; | |
| 45 | |
| 46 SkUnitMapper* linearMapper = new SkDiscreteMapper(100); | |
| 47 SkAutoUnref lm_deleter(linearMapper); | |
| 48 | |
| 49 SkShader* shader = SkGradientShader::CreateLinear( | |
| 50 linearPoints, linearColors, NULL, 2, SkShader::kMirror_T ileMode, linearMapper); | |
|
caryclark
2013/06/17 15:08:39
too wide (rewrap to fit in 100 cols)
| |
| 51 SkAutoUnref shader_deleter(shader); | |
| 52 | |
| 53 paint.setShader(shader); | |
| 54 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
| 55 | |
| 56 canvas->drawCircle(SkIntToScalar(200), SkIntToScalar(200), SkInt ToScalar(64), paint); | |
|
caryclark
2013/06/17 15:08:39
too wide (rewrap to fit in 100 cols)
| |
| 57 | |
| 58 // Detach shader | |
| 59 paint.setShader(NULL); | |
| 60 } | |
| 61 | |
| 62 | |
| 63 // Draw a message with a nice black paint. | |
| 64 paint.setFlags( | |
| 65 SkPaint::kAntiAlias_Flag | | |
| 66 SkPaint::kSubpixelText_Flag | // ... avoid waggly text when rotating. | |
| 67 SkPaint::kUnderlineText_Flag); | |
| 68 paint.setColor(SK_ColorBLACK); | |
| 69 paint.setTextSize(SkIntToScalar(20)); | |
| 70 | |
| 71 canvas->save(); | |
| 72 | |
| 73 static const char message[] = "Hello Skia!!!"; | |
| 74 | |
| 75 // Translate and rotate | |
| 76 canvas->translate(SkIntToScalar(300), SkIntToScalar(300)); | |
| 77 fRotationAngle += SkDoubleToScalar(0.2); | |
| 78 if (fRotationAngle > SkDoubleToScalar(360.0)) { | |
| 79 fRotationAngle -= SkDoubleToScalar(360.0); | |
| 80 } | |
| 81 canvas->rotate(fRotationAngle); | |
| 82 | |
| 83 // Draw the text: | |
| 84 canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntTo Scalar(0), paint); | |
|
caryclark
2013/06/17 15:08:39
sizeof(message) - 1 would also work
sglez
2013/06/17 18:04:35
Is that a suggestion or just a note? strlen seems
| |
| 85 | |
| 86 canvas->restore(); | |
| 87 | |
| 88 // Invalidate the window to force a redraw. Poor man's animation mec hanism. | |
| 89 this->inval(NULL); | |
| 90 canvas->flush(); | |
|
caryclark
2013/06/17 15:08:39
Do you need this? It shouldn't normally be require
| |
| 91 | |
| 92 INHERITED::draw(canvas); | |
| 93 } | |
| 94 | |
| 95 private: | |
| 96 SkScalar fRotationAngle; | |
| 97 SkColor fBGColor; | |
| 98 typedef BaseExample INHERITED; | |
| 99 }; | |
| 100 | |
| 101 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { | |
|
caryclark
2013/06/17 15:08:39
It would be great if I could switch between multip
sglez
2013/06/17 18:04:35
Perhaps do this on a new CL after this one is subm
| |
| 102 return new HelloSkia(hwnd, argc, argv); | |
| 103 } | |
| 104 | |
| OLD | NEW |