Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Side by Side Diff: experimental/SkiaExamples/HelloSkiaExample.cpp

Issue 16337012: Smallest possible desktop application that uses Skia to render stuff. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Initial support for OSX (not working yet). Code review fixes. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "HelloSkiaExample.h"
11
12 #include "SkApplication.h"
13 #include "SkDraw.h"
14 #include "SkGradientShader.h"
15 #include "SkGraphics.h"
16 #include "SkUnitMappers.h"
17
18 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
19 return new HelloSkia(hwnd, argc, argv);
20 }
21
22 HelloSkia::HelloSkia(void* hWnd, int argc, char** argv)
23 : INHERITED(hWnd, argc, argv)
24 {
25 fBGColor = SK_ColorWHITE;
26 fRotationAngle = SkIntToScalar(0);
27
28 setupBackend(kGPU_DeviceType);
29 }
30
31 void HelloSkia::draw(SkCanvas* canvas) {
32 // Clear background
33 canvas->drawColor(fBGColor);
34
35 SkPaint paint;
36 paint.setColor(SK_ColorRED); // SkColor is ARGB
37
38 // Draw a rectangle with blue paint
39 SkRect rect = {SkIntToScalar(10), SkIntToScalar(10), SkIntToScalar(128), SkI ntToScalar(128)};
40 canvas->drawRect(rect, paint);
41
42 // Set up a linear gradient and draw a circle
43 {
44 SkPoint linearPoints[] = {
45 {SkIntToScalar(0), SkIntToScalar(0)}, {SkIntToScalar(300), SkIntToSc alar(300)}};
46 SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK};
47
48 SkUnitMapper* linearMapper = new SkDiscreteMapper(100);
49 SkAutoUnref lm_deleter(linearMapper);
50
51 SkShader* shader = SkGradientShader::CreateLinear(
52 linearPoints, linearColors, NULL, 2, SkShader::kMirror_TileMode, linearMapper);
53 SkAutoUnref shader_deleter(shader);
54
55 paint.setShader(shader);
56 paint.setFlags(SkPaint::kAntiAlias_Flag);
57
58 canvas->drawCircle(SkIntToScalar(200), SkIntToScalar(200), SkIntToScalar (64), paint);
59
60 // Detach shader
61 paint.setShader(NULL);
62 }
63
64
65 // Draw a message with a nice black paint.
66 paint.setFlags(
67 SkPaint::kAntiAlias_Flag |
68 SkPaint::kSubpixelText_Flag | // ... avoid waggly text when rotatin g.
69 SkPaint::kUnderlineText_Flag);
70 paint.setColor(SK_ColorBLACK);
71 paint.setTextSize(SkIntToScalar(20));
72
73 canvas->save();
74
75 static const char message[] = "Hello Skia!!!";
76
77 // Translate and rotate
78 canvas->translate(SkIntToScalar(300), SkIntToScalar(300));
79 fRotationAngle += SkDoubleToScalar(0.2);
80 if (fRotationAngle > SkDoubleToScalar(360.0)) {
81 fRotationAngle -= SkDoubleToScalar(360.0);
82 }
83 canvas->rotate(fRotationAngle);
84
85 // Draw the text:
86 canvas->drawText(message, strlen(message), SkIntToScalar(0), SkIntToScalar(0 ), paint);
87
88 canvas->restore();
89
90 // Invalidate the window to force a redraw. Poor man's animation mechanism.
91 this->inval(NULL);
92 canvas->flush();
93
94 INHERITED::draw(canvas);
95 }
96
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698