Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
ChineseFlingSlide Class Reference
Inheritance diagram for ChineseFlingSlide:
Slide SkRefCnt SkRefCntBase

Public Member Functions

 ChineseFlingSlide ()
 
void draw (SkCanvas *canvas) override
 
void load (SkScalar w, SkScalar h) override
 
void createRandomWord (SkUnichar glyphs[kWordLength])
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 42 of file ChineseFlingSlide.cpp.

Constructor & Destructor Documentation

◆ ChineseFlingSlide()

ChineseFlingSlide::ChineseFlingSlide ( )
inline

Definition at line 53 of file ChineseFlingSlide.cpp.

53{ fName = "chinese-fling"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ createRandomWord()

void ChineseFlingSlide::createRandomWord ( SkUnichar  glyphs[kWordLength])
inline

Definition at line 101 of file ChineseFlingSlide.cpp.

101 {
102 for (int i = 0; i < kWordLength; ++i) {
103 glyphs[i] = fRand.nextRangeU(0x4F00, 0x9FA0);
104 }
105 }
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition: SkRandom.h:80

◆ draw()

void ChineseFlingSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 55 of file ChineseFlingSlide.cpp.

55 {
56 canvas->clear(0xFFDDDDDD);
57
59 paint.setColor(0xDE000000);
60
61 // draw a consistent run of the 'words' - one word per line
62 int index = fIndex;
63 for (SkScalar y = 0.0f; y < 1024.0f; ) {
64
65 y += -fMetrics.fAscent;
66 canvas->drawTextBlob(fBlobs[index], 0, y, paint);
67
68 y += fMetrics.fDescent + fMetrics.fLeading;
69 ++index;
70 index %= kNumBlobs;
71 }
72 // now "fling" a random amount
73 fIndex += fRand.nextRangeU(5, 20);
74 fIndex %= kNumBlobs;
75 }
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
double y
SkScalar fLeading
distance to add between lines, typically positive or zero
Definition: SkFontMetrics.h:57
SkScalar fAscent
distance to reserve above baseline, typically negative
Definition: SkFontMetrics.h:54
SkScalar fDescent
distance to reserve below baseline, typically positive
Definition: SkFontMetrics.h:55

◆ load()

void ChineseFlingSlide::load ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 77 of file ChineseFlingSlide.cpp.

77 {
78 fTypeface = chinese_typeface();
79
80 SkFont font(fTypeface, 56);
81 font.getMetrics(&fMetrics);
82
83 SkUnichar glyphs[kWordLength];
84 for (int32_t i = 0; i < kNumBlobs; ++i) {
85 this->createRandomWord(glyphs);
86
89 (const char*)glyphs,
90 kWordLength * 4,
92 font,
93 0,
94 0);
95
96 fBlobs[i] = builder.make();
97 }
98 }
static sk_sp< SkTypeface > chinese_typeface()
@ kUTF32
uses four byte words to represent all of Unicode
int32_t SkUnichar
Definition: SkTypes.h:175
void createRandomWord(SkUnichar glyphs[kWordLength])
Definition: SkFont.h:35
void add_to_text_blob_w_len(SkTextBlobBuilder *builder, const char *text, size_t len, SkTextEncoding encoding, const SkFont &font, SkScalar x, SkScalar y)
Definition: ToolUtils.cpp:213
font
Font Metadata and Metrics.

The documentation for this class was generated from the following file: