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

Public Member Functions

 ChineseZoomSlide ()
 
bool onChar (SkUnichar uni) override
 
void draw (SkCanvas *canvas) override
 
void load (SkScalar w, SkScalar h) override
 
void createRandomLine (SkUnichar glyphs[45], int lineLength)
 
- 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 108 of file ChineseFlingSlide.cpp.

Constructor & Destructor Documentation

◆ ChineseZoomSlide()

ChineseZoomSlide::ChineseZoomSlide ( )
inline

Definition at line 121 of file ChineseFlingSlide.cpp.

121{ fName = "chinese-zoom"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ createRandomLine()

void ChineseZoomSlide::createRandomLine ( SkUnichar  glyphs[45],
int  lineLength 
)
inline

Definition at line 217 of file ChineseFlingSlide.cpp.

217 {
218 for (auto i = 0; i < lineLength; ++i) {
219 glyphs[i] = fRand.nextRangeU(0x4F00, 0x9FA0);
220 }
221 }
uint16_t glyphs[5]
Definition: FontMgrTest.cpp:46
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition: SkRandom.h:80

◆ draw()

void ChineseZoomSlide::draw ( SkCanvas canvas)
inlineoverridevirtual

Implements Slide.

Definition at line 135 of file ChineseFlingSlide.cpp.

135 {
136 canvas->clear(0xFFDDDDDD);
137
139 paint.setAntiAlias(true);
140 paint.setColor(0xDE000000);
141
142 if (fAfterFirstFrame) {
143#if defined(SK_GANESH)
144 auto direct = GrAsDirectContext(canvas->recordingContext());
145 if (direct) {
146 sk_sp<SkImage> image = direct->priv().testingOnly_getFontAtlasImage(MaskFormat::kA8,
147 0);
148 canvas->drawImageRect(image,
149 SkRect::MakeXYWH(10.0f, 10.0f, 512.0f, 512.0),
151 image = direct->priv().testingOnly_getFontAtlasImage(MaskFormat::kA8, 1);
152 canvas->drawImageRect(image,
153 SkRect::MakeXYWH(522.0f, 10.0f, 512.f, 512.0f),
155 image = direct->priv().testingOnly_getFontAtlasImage(MaskFormat::kA8, 2);
156 canvas->drawImageRect(image,
157 SkRect::MakeXYWH(10.0f, 522.0f, 512.0f, 512.0f),
159 image = direct->priv().testingOnly_getFontAtlasImage(MaskFormat::kA8, 3);
160 canvas->drawImageRect(image,
161 SkRect::MakeXYWH(522.0f, 522.0f, 512.0f, 512.0f),
163 }
164#endif
165 }
166
167 canvas->scale(fScale, fScale);
168 canvas->translate(0, fTranslate);
169 fTranslate -= 0.5f;
170
171 // draw a consistent run of the 'words' - one word per line
172 SkScalar y = 0;
173 for (int index = 0; index < kNumBlobs; ++index) {
174 y += -fMetrics.fAscent;
175 canvas->drawTextBlob(fBlobs[index], 0, y, paint);
176
177 y += 3*(fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading);
178 }
179 if (!fAfterFirstFrame) {
180 fAfterFirstFrame = true;
181 }
182 }
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
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
sk_sp< const SkImage > image
Definition: SkRecords.h:269
SkSamplingOptions(SkFilterMode::kLinear))
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
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ load()

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

Reimplemented from Slide.

Definition at line 184 of file ChineseFlingSlide.cpp.

184 {
185 fTypeface = chinese_typeface();
186
187 SkFont font(fTypeface, 11);
188 font.getMetrics(&fMetrics);
189
191 paint.setColor(0xDE000000);
192
193 SkUnichar glyphs[45];
194 for (int32_t i = 0; i < kNumBlobs; ++i) {
196 auto paragraphLength = kParagraphLength;
197 SkScalar y = 0;
198 while (paragraphLength - 45 > 0) {
199 auto currentLineLength = std::min(45, paragraphLength - 45);
200 this->createRandomLine(glyphs, currentLineLength);
201
203 (const char*)glyphs,
204 currentLineLength * 4,
206 font,
207 0,
208 y);
209 y += fMetrics.fDescent - fMetrics.fAscent + fMetrics.fLeading;
210 paragraphLength -= 45;
211 }
212 fBlobs[i] = builder.make();
213 }
214 }
static sk_sp< SkTypeface > chinese_typeface()
@ kUTF32
uses four byte words to represent all of Unicode
int32_t SkUnichar
Definition: SkTypes.h:175
void createRandomLine(SkUnichar glyphs[45], int lineLength)
Definition: SkFont.h:35
static float min(float r, float g, float b)
Definition: hsl.cpp:48
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.

◆ onChar()

bool ChineseZoomSlide::onChar ( SkUnichar  uni)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 123 of file ChineseFlingSlide.cpp.

123 {
124 if ('>' == uni) {
125 fScale += 0.125f;
126 return true;
127 }
128 if ('<' == uni) {
129 fScale -= 0.125f;
130 return true;
131 }
132 return false;
133 }

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