Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
HelloWorld Class Reference

#include <HelloWorld.h>

Inheritance diagram for HelloWorld:
sk_app::Application sk_app::Window::Layer

Public Member Functions

 HelloWorld (int argc, char **argv, void *platformData)
 
 ~HelloWorld () override
 
void onIdle () override
 
void onBackendCreated () override
 
void onPaint (SkSurface *) override
 
bool onChar (SkUnichar c, skui::ModifierKey modifiers) override
 
- Public Member Functions inherited from sk_app::Application
virtual ~Application ()
 

Additional Inherited Members

- Static Public Member Functions inherited from sk_app::Application
static ApplicationCreate (int argc, char **argv, void *platformData)
 

Detailed Description

Definition at line 20 of file HelloWorld.h.

Constructor & Destructor Documentation

◆ HelloWorld()

HelloWorld::HelloWorld ( int  argc,
char **  argv,
void *  platformData 
)

Definition at line 35 of file HelloWorld.cpp.

37 : fBackendType(Window::kNativeGL_BackendType),
38#elif defined(SK_VULKAN)
39 : fBackendType(Window::kVulkan_BackendType),
40#else
41 : fBackendType(Window::kRaster_BackendType),
42#endif
43 fRotationAngle(0) {
45
46 fWindow = Window::CreateNativeWindow(platformData);
48
49 // register callbacks
50 fWindow->pushLayer(this);
51
52 fWindow->attach(fBackendType);
53
54 fTypeface = ToolUtils::CreateTypefaceFromResource("fonts/Roboto-Regular.ttf");
55 if (!fTypeface) {
57 }
58}
static void Init()
void pushLayer(Layer *layer)
Definition Window.h:132
virtual void setRequestedDisplayParams(const DisplayParams &, bool allowReattach=true)
Definition Window.cpp:137
virtual bool attach(BackendType)=0
sk_sp< SkTypeface > DefaultPortableTypeface()
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)

◆ ~HelloWorld()

HelloWorld::~HelloWorld ( )
override

Definition at line 60 of file HelloWorld.cpp.

60 {
61 fWindow->detach();
62 delete fWindow;
63}
void detach()
Definition Window.cpp:25

Member Function Documentation

◆ onBackendCreated()

void HelloWorld::onBackendCreated ( )
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 88 of file HelloWorld.cpp.

88 {
89 this->updateTitle();
90 fWindow->show();
91 fWindow->inval();
92}
virtual void show()=0

◆ onChar()

bool HelloWorld::onChar ( SkUnichar  c,
skui::ModifierKey  modifiers 
)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 148 of file HelloWorld.cpp.

148 {
149 if (' ' == c) {
150 if (Window::kRaster_BackendType == fBackendType) {
151#if defined(SK_GL)
152 fBackendType = Window::kNativeGL_BackendType;
153#elif defined(SK_VULKAN)
154 fBackendType = Window::kVulkan_BackendType;
155#else
156 SkDebugf("No GPU backend configured\n");
157 return true;
158#endif
159 } else {
160 fBackendType = Window::kRaster_BackendType;
161 }
162 fWindow->detach();
163 fWindow->attach(fBackendType);
164 }
165 return true;
166}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1

◆ onIdle()

void HelloWorld::onIdle ( )
overridevirtual

Implements sk_app::Application.

Definition at line 143 of file HelloWorld.cpp.

143 {
144 // Just re-paint continuously
145 fWindow->inval();
146}

◆ onPaint()

void HelloWorld::onPaint ( SkSurface surface)
overridevirtual

Reimplemented from sk_app::Window::Layer.

Definition at line 94 of file HelloWorld.cpp.

94 {
95 auto canvas = surface->getCanvas();
96
97 // Clear background
98 canvas->clear(SK_ColorWHITE);
99
101 paint.setColor(SK_ColorRED);
102
103 // Draw a rectangle with red paint
104 SkRect rect = SkRect::MakeXYWH(10, 10, 128, 128);
105 canvas->drawRect(rect, paint);
106
107 // Set up a linear gradient and draw a circle
108 {
109 SkPoint linearPoints[] = { { 0, 0 }, { 300, 300 } };
110 SkColor linearColors[] = { SK_ColorGREEN, SK_ColorBLACK };
111 paint.setShader(SkGradientShader::MakeLinear(linearPoints, linearColors, nullptr, 2,
113 paint.setAntiAlias(true);
114
115 canvas->drawCircle(200, 200, 64, paint);
116
117 // Detach shader
118 paint.setShader(nullptr);
119 }
120
121 // Draw a message with a nice black paint
122 SkFont font(fTypeface, 20);
123 font.setSubpixel(true);
124 paint.setColor(SK_ColorBLACK);
125
126 canvas->save();
127 static const char message[] = "Hello World ";
128
129 // Translate and rotate
130 canvas->translate(300, 300);
131 fRotationAngle += 0.2f;
132 if (fRotationAngle > 360) {
133 fRotationAngle -= 360;
134 }
135 canvas->rotate(fRotationAngle);
136
137 // Draw the text
138 canvas->drawSimpleText(message, strlen(message), SkTextEncoding::kUTF8, 0, 0, font, paint);
139
140 canvas->restore();
141}
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
@ kUTF8
uses bytes to represent UTF-8 or ASCII
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
Win32Message message
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
font
Font Metadata and Metrics.
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

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