MCPcopy Create free account
hub / github.com/aseprite/laf / app_main

Function app_main

examples/text_shape.cpp:165–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165int app_main(int argc, char* argv[])
166{
167 SystemRef system = System::make();
168 system->setAppMode(AppMode::GUI);
169
170 FontMgrRef fontMgr = FontMgr::Make();
171 FontRef font = fontMgr->defaultFont(48);
172 FontRef fontBig = fontMgr->defaultFont(128);
173 if (!font || !fontBig) {
174 std::printf("Font not found\n");
175 return 1;
176 }
177
178 WindowRef window = system->makeWindow(800, 600);
179 window->setTitle("Text Shape");
180
181 // Interpret dead keys + chars to compose unicode chars. This is
182 // useful for text editors (or when we focus a text editor in our
183 // app, in this example we're always in the text editor).
184 system->setTextInput(true);
185
186 TextEdit edit;
187 edit.text = "Hiragana ひらがな.";
188 edit.makeBlob(fontMgr, font);
189 edit.caretIndex = edit.boxes.size();
190 edit.makeCaretVisible();
191
192 FontMetrics metrics;
193 font->metrics(&metrics);
194 edit.caretHeight = metrics.descent - metrics.ascent + metrics.leading;
195 edit.caretBaseLine = -metrics.ascent - metrics.leading;
196
197 system->finishLaunching();
198 system->activateApp();
199
200 // Wait until a key is pressed or the window is closed
201 EventQueue* queue = system->eventQueue();
202 gfx::Point mousePos;
203 bool running = true;
204 bool redraw = true;
205 while (running) {
206 if (redraw) {
207 redraw = false;
208 draw_window(system.get(), window.get(), fontMgr, font, fontBig, mousePos, edit);
209 }
210
211 Event ev;
212 queue->getEvent(ev, 0.5);
213
214 // Timer timeout (blink caret)
215 while ((base::current_tick() - edit.caretTick) > 500) {
216 edit.caretTick += 500;
217 edit.caretVisible = !edit.caretVisible;
218 redraw = true;
219 }
220
221 switch (ev.type()) {
222 case Event::CloseWindow: running = false; break;

Callers

nothing calls this directly

Calls 15

current_tickFunction · 0.85
makeCaretVisibleMethod · 0.80
eventQueueMethod · 0.80
scancodeMethod · 0.80
unicodeCharAsUtf8Method · 0.80
draw_windowFunction · 0.70
setAppModeMethod · 0.45
defaultFontMethod · 0.45
makeWindowMethod · 0.45
setTitleMethod · 0.45
setTextInputMethod · 0.45
makeBlobMethod · 0.45

Tested by

no test coverage detected