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

Function app_main

examples/hello_laf.cpp:33–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31}
32
33int app_main(int argc, char* argv[])
34{
35 SystemRef system = System::make();
36 system->setAppMode(AppMode::GUI);
37
38 WindowRef window = system->makeWindow(400, 300);
39
40 // Set the title bar caption of the native window.
41 window->setTitle("Hello World");
42
43 // We can change the cursor to use when the mouse is above this
44 // window, this line is not required because by default the native
45 // cursor to be shown in a window is the arrow.
46 window->setCursor(NativeCursor::Arrow);
47
48 system->handleWindowResize = draw_window;
49
50 // On macOS: With finishLaunching() we start processing
51 // NSApplicationDelegate events. After calling this we'll start
52 // receiving Event::DropFiles events. It's a way to say "ok
53 // we're ready to process messages"
54 system->finishLaunching();
55
56 // On macOS, when we compile the program outside an app bundle, we
57 // must active the app explicitly if we want to put the app on the
58 // front. Remove this if you're planning to distribute your app on a
59 // bundle or enclose it in something like #ifdef _DEBUG/#endif
60 system->activateApp();
61
62 // Wait until a key is pressed or the window is closed
63 EventQueue* queue = system->eventQueue();
64 bool running = true;
65 bool redraw = true;
66 while (running) {
67 if (redraw) {
68 const bool isVisible = window->isVisible();
69
70 redraw = false;
71 draw_window(window.get());
72
73 if (!isVisible)
74 window->setVisible(true);
75 }
76 // Wait for an event in the queue, the "true" parameter indicates
77 // that we'll wait for a new event, and the next line will not be
78 // processed until we receive a new event. If we use "false" and
79 // there is no events in the queue, we receive an "ev.type() == Event::None
80 Event ev;
81 queue->getEvent(ev);
82
83 switch (ev.type()) {
84 case Event::CloseApp:
85 case Event::CloseWindow: running = false; break;
86
87 case Event::KeyDown:
88 switch (ev.scancode()) {
89 case kKeyEsc: running = false; break;
90

Callers

nothing calls this directly

Calls 15

eventQueueMethod · 0.80
scancodeMethod · 0.80
gpuAccelerationMethod · 0.80
draw_windowFunction · 0.70
setAppModeMethod · 0.45
makeWindowMethod · 0.45
setTitleMethod · 0.45
setCursorMethod · 0.45
finishLaunchingMethod · 0.45
activateAppMethod · 0.45
isVisibleMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected