reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofMainLoop.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofEvents.h"
4#include <unordered_map>
5
6class ofBaseApp;
9
11public:
12 ofMainLoop();
13 virtual ~ofMainLoop();
14
15 std::shared_ptr<ofAppBaseWindow> createWindow(const ofWindowSettings & settings);
16
17 template<typename Window>
18 void addWindow(const std::shared_ptr<Window> & window){
19 allowMultiWindow = Window::allowsMultiWindow();
20 if(Window::doesLoop()){
21 windowLoop = Window::loop;
22 }
23 if(Window::needsPolling()){
24 windowPollEvents = Window::pollEvents;
25 }
26 if(!allowMultiWindow){
27 windowsApps.clear();
28 }
29 windowsApps[window] = std::shared_ptr<ofBaseApp>();
30 currentWindow = window;
31 ofAddListener(window->events().keyPressed,this,&ofMainLoop::keyPressed);
32 }
33
34 void run(const std::shared_ptr<ofAppBaseWindow> & window, std::shared_ptr<ofBaseApp> && app);
35 void run(std::shared_ptr<ofBaseApp> && app);
36 int loop();
37 void loopOnce();
38 void pollEvents();
39 void exit();
40 void shouldClose(int status);
41 std::shared_ptr<ofAppBaseWindow> getCurrentWindow();
42 void setCurrentWindow(const std::shared_ptr<ofAppBaseWindow> & window);
43 void setCurrentWindow(ofAppBaseWindow * window);
44 std::shared_ptr<ofBaseApp> getCurrentApp();
45 void setEscapeQuitsLoop(bool quits);
46
49
50 std::thread::id get_thread_id() { return thread_id; };
51
52private:
53 std::thread::id thread_id { std::this_thread::get_id() };
54
55 void keyPressed(ofKeyEventArgs & key);
56 std::unordered_map<std::shared_ptr<ofAppBaseWindow>, std::shared_ptr<ofBaseApp> > windowsApps;
57 bool bShouldClose;
58 std::weak_ptr<ofAppBaseWindow> currentWindow;
59 int status;
60 bool allowMultiWindow;
61 std::function<void()> windowLoop;
62 std::function<void()> windowPollEvents;
63 bool escapeQuits;
64};
Definition ofAppBaseWindow.h:21
Definition ofBaseApp.h:14
Definition ofEvent.h:444
Definition ofEvents.h:121
Definition ofMainLoop.h:10
ofEvent< void > exitEvent
Definition ofMainLoop.h:47
int loop()
Definition ofMainLoop.cpp:122
void addWindow(const std::shared_ptr< Window > &window)
Definition ofMainLoop.h:18
std::shared_ptr< ofAppBaseWindow > createWindow(const ofWindowSettings &settings)
Definition ofMainLoop.cpp:44
virtual ~ofMainLoop()
Definition ofMainLoop.cpp:40
ofMainLoop()
Definition ofMainLoop.cpp:32
void setEscapeQuitsLoop(bool quits)
Definition ofMainLoop.cpp:255
void loopOnce()
Definition ofMainLoop.cpp:134
std::thread::id get_thread_id()
Definition ofMainLoop.h:50
void exit()
Definition ofMainLoop.cpp:158
std::shared_ptr< ofAppBaseWindow > getCurrentWindow()
Definition ofMainLoop.cpp:223
std::shared_ptr< ofBaseApp > getCurrentApp()
Definition ofMainLoop.cpp:243
ofEvent< void > loopEvent
Definition ofMainLoop.h:48
void shouldClose(int status)
Definition ofMainLoop.cpp:247
void pollEvents()
Definition ofMainLoop.cpp:152
void setCurrentWindow(const std::shared_ptr< ofAppBaseWindow > &window)
Definition ofMainLoop.cpp:227
void run(const std::shared_ptr< ofAppBaseWindow > &window, std::shared_ptr< ofBaseApp > &&app)
Definition ofMainLoop.cpp:69
Definition ofWindowSettings.h:38
void ofAddListener(EventType &event, ListenerClass *listener, void(ListenerClass::*listenerMethod)(const void *, ArgumentsType &), int prio=OF_EVENT_ORDER_AFTER_APP)
Definition ofEventUtils.h:19