Skip to content

Commit 0c02995

Browse files
authored
ofMainloop cleanup (#7357)
#changelog #core
1 parent a0d405a commit 0c02995

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

libs/openFrameworks/app/ofMainLoop.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
* Author: arturo
66
*/
77

8-
#include <ofMainLoop.h>
8+
#include "ofMainLoop.h"
99
#include "ofWindowSettings.h"
1010
#include "ofAppBaseWindow.h"
1111
#include "ofBaseApp.h"
12+
#include "ofConstants.h"
1213

1314
//========================================================================
1415
// default windowing
@@ -67,6 +68,23 @@ std::shared_ptr<ofAppBaseWindow> ofMainLoop::createWindow(const ofWindowSettings
6768
return window;
6869
}
6970

71+
template<typename Window>
72+
void ofMainLoop::addWindow(const std::shared_ptr<Window> & window){
73+
allowMultiWindow = Window::allowsMultiWindow();
74+
if(Window::doesLoop()){
75+
windowLoop = Window::loop;
76+
}
77+
if(Window::needsPolling()){
78+
windowPollEvents = Window::pollEvents;
79+
}
80+
if(!allowMultiWindow){
81+
windowsApps.clear();
82+
}
83+
windowsApps[window] = std::shared_ptr<ofBaseApp>();
84+
currentWindow = window;
85+
ofAddListener(window->events().keyPressed,this,&ofMainLoop::keyPressed);
86+
}
87+
7088
void ofMainLoop::run(const std::shared_ptr<ofAppBaseWindow> & window, std::shared_ptr<ofBaseApp> && app){
7189
windowsApps[window] = app;
7290
if(app){
@@ -162,7 +180,7 @@ void ofMainLoop::exit(){
162180
for(auto i: windowsApps){
163181
std::shared_ptr<ofAppBaseWindow> window = i.first;
164182
std::shared_ptr<ofBaseApp> app = i.second;
165-
183+
166184
if(window == nullptr) {
167185
continue;
168186
}
@@ -260,5 +278,5 @@ void ofMainLoop::setEscapeQuitsLoop(bool quits){
260278
void ofMainLoop::keyPressed(ofKeyEventArgs & key){
261279
if (key.key == OF_KEY_ESC && escapeQuits == true){ // "escape"
262280
shouldClose(0);
263-
}
281+
}
264282
}

libs/openFrameworks/app/ofMainLoop.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include "ofConstants.h"
43
#include "ofEvents.h"
54
#include <map>
65

@@ -15,21 +14,7 @@ class ofMainLoop {
1514

1615
std::shared_ptr<ofAppBaseWindow> createWindow(const ofWindowSettings & settings);
1716
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-
}
17+
void addWindow(const std::shared_ptr<Window> & window);
3318

3419
void run(const std::shared_ptr<ofAppBaseWindow> & window, std::shared_ptr<ofBaseApp> && app);
3520
void run(std::shared_ptr<ofBaseApp> && app);
@@ -48,7 +33,7 @@ class ofMainLoop {
4833
ofEvent<void> loopEvent;
4934
private:
5035
void keyPressed(ofKeyEventArgs & key);
51-
std::map<std::shared_ptr<ofAppBaseWindow>,std::shared_ptr<ofBaseApp> > windowsApps;
36+
std::map<std::shared_ptr<ofAppBaseWindow>, std::shared_ptr<ofBaseApp> > windowsApps;
5237
bool bShouldClose;
5338
std::weak_ptr<ofAppBaseWindow> currentWindow;
5439
int status;

libs/openFrameworks/app/ofWindowSettings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include "ofConstants.h"
32
#include "glm/vec2.hpp"
43

54

0 commit comments

Comments
 (0)