Flutter Engine
The Flutter Engine
Classes | Namespaces | Functions | Variables
strokedlines.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlurTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPathUtils.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkDashPathEffect.h"
#include "include/effects/SkGradientShader.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTemplates.h"
#include "tools/ToolUtils.h"
#include <initializer_list>

Go to the source code of this file.

Classes

class  skiagm::StrokedLinesGM
 

Namespaces

namespace  skiagm
 

Functions

static void draw_line (SkCanvas *canvas, const SkPoint &p0, const SkPoint &p1, const SkPaint &paint, bool useDrawPath)
 
static void draw_fins (SkCanvas *canvas, const SkPoint &offset, float angle, const SkPaint &paint, bool useDrawPath)
 
static void draw_snowflake (SkCanvas *canvas, const SkPaint &paint, bool useDrawPath)
 
static void draw_row (SkCanvas *canvas, const SkPaint &paint, const SkMatrix &localMatrix, bool useDrawPath)
 
static void skiagm::draw_path (SkCanvas *canvas, const SkPoint &p0, const SkPoint &p1, SkPaint::Cap cap)
 
 skiagm::DEF_SIMPLE_GM (strokedline_caps, canvas, 1400, 740)
 

Variables

constexpr int kNumColumns = 6
 
constexpr int kNumRows = 8
 
constexpr int kRadius = 40
 
constexpr int kPad = 5
 
constexpr int kNumSpokes = 6
 
constexpr SkScalar kStrokeWidth = 5.0f
 
static constexpr float skiagm::kStrokeWidth = 20.f
 

Function Documentation

◆ draw_fins()

static void draw_fins ( SkCanvas canvas,
const SkPoint offset,
float  angle,
const SkPaint paint,
bool  useDrawPath 
)
static

Definition at line 53 of file strokedlines.cpp.

54 {
55 SkScalar cos, sin;
56
57 // first fin
58 sin = SkScalarSin(angle + (SK_ScalarPI/4));
59 cos = SkScalarCos(angle + (SK_ScalarPI/4));
60 sin *= kRadius / 2.0f;
61 cos *= kRadius / 2.0f;
62
63 draw_line(canvas, offset, offset + SkPoint{cos, sin}, paint, useDrawPath);
64
65 // second fin
66 sin = SkScalarSin(angle - (SK_ScalarPI/4));
67 cos = SkScalarCos(angle - (SK_ScalarPI/4));
68 sin *= kRadius / 2.0f;
69 cos *= kRadius / 2.0f;
70
71 draw_line(canvas, offset, offset + SkPoint{cos, sin}, paint, useDrawPath);
72}
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
SeparatedVector2 offset
static void draw_line(SkCanvas *canvas, const SkPoint &p0, const SkPoint &p1, const SkPaint &paint, bool useDrawPath)
constexpr int kRadius

◆ draw_line()

static void draw_line ( SkCanvas canvas,
const SkPoint p0,
const SkPoint p1,
const SkPaint paint,
bool  useDrawPath 
)
static

Definition at line 44 of file strokedlines.cpp.

45 {
46 if (useDrawPath) {
47 canvas->drawPath(SkPath::Line(p0, p1), paint);
48 } else {
49 canvas->drawLine(p0, p1, paint);
50 }
51}
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
static SkPath Line(const SkPoint a, const SkPoint b)
Definition: SkPath.h:106

◆ draw_row()

static void draw_row ( SkCanvas canvas,
const SkPaint paint,
const SkMatrix localMatrix,
bool  useDrawPath 
)
static

Definition at line 99 of file strokedlines.cpp.

100 {
101 canvas->translate(kRadius+kPad, 0.0f);
102
104 for (auto isAA : { true, false }) {
105 SkPaint tmp(paint);
106 tmp.setStrokeWidth(kStrokeWidth);
107 tmp.setStyle(SkPaint::kStroke_Style);
108 tmp.setStrokeCap(cap);
109 tmp.setAntiAlias(isAA);
110
111 int saveCount = canvas->save();
112 canvas->concat(localMatrix);
113 draw_snowflake(canvas, tmp, useDrawPath);
114 canvas->restoreToCount(saveCount);
115
116 canvas->translate(2*(kRadius+kPad), 0.0f);
117 }
118 }
119}
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void restoreToCount(int saveCount)
Definition: SkCanvas.cpp:478
int save()
Definition: SkCanvas.cpp:447
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition: SkPaint.h:334
@ kSquare_Cap
adds square
Definition: SkPaint.h:336
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
constexpr int kPad
constexpr SkScalar kStrokeWidth
static void draw_snowflake(SkCanvas *canvas, const SkPaint &paint, bool useDrawPath)

◆ draw_snowflake()

static void draw_snowflake ( SkCanvas canvas,
const SkPaint paint,
bool  useDrawPath 
)
static

Definition at line 75 of file strokedlines.cpp.

75 {
76
78
79 SkScalar sin, cos, angle = 0.0f;
80 for (int i = 0; i < kNumSpokes/2; ++i, angle += SK_ScalarPI/(kNumSpokes/2)) {
81 sin = SkScalarSin(angle);
82 cos = SkScalarCos(angle);
83 sin *= kRadius;
84 cos *= kRadius;
85
86 // main spoke
87 draw_line(canvas, {-cos, -sin}, {cos, sin}, paint, useDrawPath);
88
89 // fins on positive side
90 const SkPoint posOffset = SkPoint::Make(0.5f * cos, 0.5f * sin);
91 draw_fins(canvas, posOffset, angle, paint, useDrawPath);
92
93 // fins on negative side
94 const SkPoint negOffset = SkPoint::Make(-0.5f * cos, -0.5f * sin);
95 draw_fins(canvas, negOffset, angle+SK_ScalarPI, paint, useDrawPath);
96 }
97}
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
static void draw_fins(SkCanvas *canvas, const SkPoint &offset, float angle, const SkPaint &paint, bool useDrawPath)
constexpr int kNumSpokes
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

Variable Documentation

◆ kNumColumns

constexpr int kNumColumns = 6
constexpr

Definition at line 37 of file strokedlines.cpp.

◆ kNumRows

constexpr int kNumRows = 8
constexpr

Definition at line 38 of file strokedlines.cpp.

◆ kNumSpokes

constexpr int kNumSpokes = 6
constexpr

Definition at line 41 of file strokedlines.cpp.

◆ kPad

constexpr int kPad = 5
constexpr

Definition at line 40 of file strokedlines.cpp.

◆ kRadius

constexpr int kRadius = 40
constexpr

Definition at line 39 of file strokedlines.cpp.

◆ kStrokeWidth

constexpr SkScalar kStrokeWidth = 5.0f
constexpr

Definition at line 42 of file strokedlines.cpp.