| 127 | } |
| 128 | |
| 129 | int app_main(int argc, char* argv[]) |
| 130 | { |
| 131 | SystemRef system = System::make(); |
| 132 | system->setAppMode(AppMode::GUI); |
| 133 | |
| 134 | FontMgrRef fontMgr = FontMgr::Make(); |
| 135 | FontRef font = fontMgr->defaultFont(32); |
| 136 | if (!font) { |
| 137 | std::printf("Font not found\n"); |
| 138 | return 1; |
| 139 | } |
| 140 | |
| 141 | WindowRef window = system->makeWindow(800, 800, 2); |
| 142 | window->setTitle(kTitle); |
| 143 | |
| 144 | system->finishLaunching(); |
| 145 | system->activateApp(); |
| 146 | |
| 147 | // Wait until a key is pressed or the window is closed |
| 148 | EventQueue* queue = system->eventQueue(); |
| 149 | gfx::Point mousePos; |
| 150 | bool running = true; |
| 151 | bool redraw = true; |
| 152 | |
| 153 | system->handleWindowResize = [&](Window* w) { draw_window(w, fontMgr, font, mousePos); }; |
| 154 | |
| 155 | while (running) { |
| 156 | // Pick next event in the queue (without waiting) |
| 157 | Event ev; |
| 158 | queue->getEvent(ev, 0.0); |
| 159 | |
| 160 | // If there are no more events in the queue (Event::None type), |
| 161 | // redraw the window and wait for some event. We do this so we |
| 162 | // don't need to redraw the text on each mouse movement (we can |
| 163 | // process several mouse movements at the same time and redraw |
| 164 | // when the messages stop). |
| 165 | if (ev.type() == Event::None) { |
| 166 | if (redraw) { |
| 167 | redraw = false; |
| 168 | draw_window(window.get(), fontMgr, font, mousePos); |
| 169 | } |
| 170 | queue->getEvent(ev); |
| 171 | } |
| 172 | |
| 173 | switch (ev.type()) { |
| 174 | case Event::CloseWindow: running = false; break; |
| 175 | |
| 176 | case Event::KeyDown: |
| 177 | switch (ev.scancode()) { |
| 178 | case kKeyEsc: running = false; break; |
| 179 | case kKey1: |
| 180 | case kKey2: |
| 181 | case kKey3: |
| 182 | case kKey4: |
| 183 | case kKey5: |
| 184 | case kKey6: |
| 185 | case kKey7: |
| 186 | case kKey8: |
nothing calls this directly
no test coverage detected