| 163 | } |
| 164 | |
| 165 | int 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; |
nothing calls this directly
no test coverage detected