Index: experimental/SkiaExamples/HelloSkiaExample.cpp |
diff --git a/experimental/SkiaExamples/HelloSkiaExample.cpp b/experimental/SkiaExamples/HelloSkiaExample.cpp |
index f25cd76bfabcad6dcbb74584fb20e3f2fa6e5877..2424b76f96acc36304b05973a5165e9b090ce3dc 100644 |
--- a/experimental/SkiaExamples/HelloSkiaExample.cpp |
+++ b/experimental/SkiaExamples/HelloSkiaExample.cpp |
@@ -7,7 +7,7 @@ |
* |
*/ |
-#include "BaseExample.h" |
+#include "SkExample.h" |
#include "SkApplication.h" |
#include "SkDraw.h" |
@@ -15,98 +15,96 @@ |
#include "SkGraphics.h" |
#include "SkUnitMappers.h" |
-class HelloSkia : public BaseExample { |
- public: |
- HelloSkia(void* hWnd, int argc, char** argv) |
- : INHERITED(hWnd, argc, argv) |
- { |
- fBGColor = SK_ColorWHITE; |
- fRotationAngle = SkIntToScalar(0); |
+class HelloSkia : public SkExample { |
+public: |
+ HelloSkia(SkExampleWindow* window) : SkExample(window) { |
+ fName = "HelloSkia"; |
+ fBGColor = SK_ColorWHITE; |
+ fRotationAngle = SkIntToScalar(0); |
- setupBackend(kGPU_DeviceType); |
- // Another option is software rendering: |
- // setupBackend(kRaster_DeviceType); |
- } |
+ fWindow->setupBackend(SkExampleWindow::kGPU_DeviceType); |
+ // Another option is software rendering: |
+ // setupBackend(SkExampleWindow::kRaster_DeviceType); |
+ } |
- protected: |
- virtual void draw(SkCanvas* canvas) SK_OVERRIDE { |
- // Clear background |
- canvas->drawColor(fBGColor); |
+protected: |
+ void draw(SkCanvas* canvas) { |
+ // Clear background |
+ canvas->drawColor(fBGColor); |
- SkPaint paint; |
- paint.setColor(SK_ColorRED); |
+ SkPaint paint; |
+ paint.setColor(SK_ColorRED); |
- // Draw a rectangle with blue paint |
- SkRect rect = { |
+ // Draw a rectangle with blue paint |
+ SkRect rect = { |
SkIntToScalar(10), SkIntToScalar(10), |
SkIntToScalar(128), SkIntToScalar(128) |
- }; |
- canvas->drawRect(rect, paint); |
+ }; |
+ canvas->drawRect(rect, paint); |
- // Set up a linear gradient and draw a circle |
- { |
- SkPoint linearPoints[] = { |
+ // Set up a linear gradient and draw a circle |
+ { |
+ SkPoint linearPoints[] = { |
{SkIntToScalar(0), SkIntToScalar(0)}, |
{SkIntToScalar(300), SkIntToScalar(300)} |
- }; |
- SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; |
- |
- SkUnitMapper* linearMapper = new SkDiscreteMapper(100); |
- SkAutoUnref lm_deleter(linearMapper); |
- |
- SkShader* shader = SkGradientShader::CreateLinear( |
- linearPoints, linearColors, NULL, 2, |
- SkShader::kMirror_TileMode, linearMapper); |
- SkAutoUnref shader_deleter(shader); |
+ }; |
+ SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK}; |
- paint.setShader(shader); |
- paint.setFlags(SkPaint::kAntiAlias_Flag); |
+ SkUnitMapper* linearMapper = new SkDiscreteMapper(100); |
+ SkAutoUnref lm_deleter(linearMapper); |
- canvas->drawCircle(SkIntToScalar(200), SkIntToScalar(200), |
- SkIntToScalar(64), paint); |
+ SkShader* shader = SkGradientShader::CreateLinear( |
+ linearPoints, linearColors, NULL, 2, |
+ SkShader::kMirror_TileMode, linearMapper); |
+ SkAutoUnref shader_deleter(shader); |
- // Detach shader |
- paint.setShader(NULL); |
- } |
+ paint.setShader(shader); |
+ paint.setFlags(SkPaint::kAntiAlias_Flag); |
+ canvas->drawCircle(SkIntToScalar(200), SkIntToScalar(200), |
+ SkIntToScalar(64), paint); |
- // 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(SkIntToScalar(20)); |
+ // Detach shader |
+ paint.setShader(NULL); |
+ } |
- canvas->save(); |
+ // 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(SkIntToScalar(20)); |
- static const char message[] = "Hello Skia!!!"; |
+ canvas->save(); |
- // Translate and rotate |
- canvas->translate(SkIntToScalar(300), SkIntToScalar(300)); |
- fRotationAngle += SkDoubleToScalar(0.2); |
- if (fRotationAngle > SkDoubleToScalar(360.0)) { |
- fRotationAngle -= SkDoubleToScalar(360.0); |
- } |
- canvas->rotate(fRotationAngle); |
+ static const char message[] = "Hello Skia!!!"; |
- // Draw the text: |
- canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntToScalar(0), paint); |
+ // Translate and rotate |
+ canvas->translate(SkIntToScalar(300), SkIntToScalar(300)); |
+ fRotationAngle += SkDoubleToScalar(0.2); |
+ if (fRotationAngle > SkDoubleToScalar(360.0)) { |
+ fRotationAngle -= SkDoubleToScalar(360.0); |
+ } |
+ canvas->rotate(fRotationAngle); |
- canvas->restore(); |
+ // Draw the text: |
+ canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntToScalar(0), paint); |
- // Invalidate the window to force a redraw. Poor man's animation mechanism. |
- this->inval(NULL); |
+ canvas->restore(); |
- INHERITED::draw(canvas); |
- } |
+ // Invalidate the window to force a redraw. Poor man's animation mechanism. |
+ this->fWindow->inval(NULL); |
+ } |
- private: |
- SkScalar fRotationAngle; |
- SkColor fBGColor; |
- typedef BaseExample INHERITED; |
+private: |
+ SkScalar fRotationAngle; |
+ SkColor fBGColor; |
}; |
-SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { |
- return new HelloSkia(hwnd, argc, argv); |
+static SkExample* MyFactory(SkExampleWindow* window) { |
+ return new HelloSkia(window); |
} |
+ |
+// Register this class as a Skia Example. |
+SkExample::Registry registry(MyFactory); |