Allolib  1.0
C++ Components For Interactive Multimedia
al_App.hpp
1 #ifndef AL_APP_H
2 #define AL_APP_H
3 
4 #include <cassert>
5 #include <cstring>
6 #include <functional>
7 #include <iostream>
8 #include <memory>
9 #include <stack>
10 #include <vector>
11 
12 #include "al/app/al_AudioDomain.hpp"
13 #include "al/app/al_ComputationDomain.hpp"
14 #include "al/app/al_OSCDomain.hpp"
15 #include "al/app/al_OpenGLGraphicsDomain.hpp"
16 #include "al/app/al_SimulationDomain.hpp"
17 #include "al/graphics/al_Graphics.hpp"
18 
23 namespace al {
24 
29 class App {
30 public:
31  App();
32 
33  virtual ~App() {}
34 
35  template <class DomainType> std::shared_ptr<DomainType> newDomain() {
36  auto newDomain = std::make_shared<DomainType>();
37  mDomainList.push_back(newDomain);
38  // if (!newDomain->init()) {
39  // std::cerr << "ERROR initializing domain " << std::endl;
40  // }
41  return newDomain;
42  }
43 
44  virtual void onInit() {}
45  virtual void onCreate() {}
46  virtual void onAnimate(double dt) { (void)dt; }
47  virtual void onDraw(Graphics &g) { (void)g; }
48  virtual void onSound(AudioIOData &io) { (void)io; }
49  virtual void onMessage(osc::Message &m) { (void)m; }
50  virtual void onExit() {}
51 
52  virtual bool onKeyDown(Keyboard const & /*k*/) { return true; }
53  virtual bool onKeyUp(Keyboard const & /*k*/) { return true; }
54  virtual bool onMouseDown(Mouse const & /*m*/) { return true; }
55  virtual bool onMouseUp(Mouse const & /*m*/) { return true; }
56  virtual bool onMouseDrag(Mouse const & /*m*/) { return true; }
57  virtual bool onMouseMove(Mouse const & /*m*/) { return true; }
58  virtual bool onMouseScroll(Mouse const & /*m*/) { return true; }
59  virtual void onResize(int /*w*/, int /*h*/) {}
60  // virtual void onVisibility(bool v) {}
61 
62  void quit();
63  bool shouldQuit();
64 
65  // Access to graphics domain properties
66  virtual Window &defaultWindow();
67  virtual Graphics &graphics();
68 
69  virtual Viewpoint &view();
70  virtual Pose &pose();
71  virtual Lens &lens();
72  virtual Nav &nav();
73  virtual NavInputControl &navControl();
74  void fps(double f);
75 
76  // Access to default window domain
77  // These functions are only valid after start() has been called.
79  Mouse &mouse();
80 
81  double aspect();
82  bool created();
85  bool cursorHide();
89  bool fullScreen();
90  const std::string &title();
91  bool visible();
92  bool vsync();
93 
95  void hide();
96  void iconify();
97  // void show(); ///< Show window (if hidden)
98 
99  int height();
100  int width();
101 
102  // get frambuffer size
103  // it will be different from window widht and height
104  // if the display is a high resolution one (ex: RETINA display)
105  int fbHeight();
106  int fbWidth();
107 
108  float highresFactor();
109 
110  bool decorated();
112  void cursorHide(bool v);
114  void dimensions(const Window::Dim &v);
115  void dimensions(int w, int h);
116  void dimensions(int x, int y, int w, int h);
119 
122  void fullScreen(bool on);
123  void title(const std::string &v);
124  void vsync(bool v);
126  void decorated(bool b);
127 
128  // Event handlers
129  [[deprecated("Call through defaultWindow()")]] void
130  append(WindowEventHandler &handler);
131  [[deprecated("Call through defaultWindow()")]] void
132  prepend(WindowEventHandler &handler);
133  [[deprecated("Call through defaultWindow()")]] void
134  remove(WindowEventHandler &handler);
135 
136  // Access to audio domain
137  AudioIO &audioIO();
138 
139  void configureAudio(double audioRate = 44100, int audioBlockSize = 512,
140  int audioOutputs = -1, int audioInputs = -1);
141 
142  void configureAudio(AudioDevice &dev, double audioRate = -1,
143  int audioBlockSize = 512, int audioOutputs = -1,
144  int audioInputs = -1);
145 
146  // Access to OSC domain
147  ParameterServer &parameterServer();
148 
149  virtual void start();
150 
151  // Domain access
152  std::shared_ptr<OSCDomain> oscDomain() { return mOSCDomain; }
153  std::shared_ptr<AudioDomain> audioDomain() { return mAudioDomain; }
154  std::shared_ptr<OpenGLGraphicsDomain> graphicsDomain() {
155  return mOpenGLGraphicsDomain;
156  }
157  std::shared_ptr<SimulationDomain> simulationDomain() {
158  return mSimulationDomain;
159  }
160 
161  std::shared_ptr<GLFWOpenGLWindowDomain> defaultWindowDomain() {
162  return mDefaultWindowDomain;
163  }
165  bool keyDown(const Keyboard &k);
166  App *app;
167  };
168  StandardWindowAppKeyControls stdControls;
169 
170  // Modify these with care
171  std::shared_ptr<GLFWOpenGLWindowDomain> mDefaultWindowDomain;
172 
173  std::shared_ptr<OSCDomain> mOSCDomain;
174  std::shared_ptr<AudioDomain> mAudioDomain;
175  std::shared_ptr<OpenGLGraphicsDomain> mOpenGLGraphicsDomain;
176  std::shared_ptr<SimulationDomain> mSimulationDomain;
177 
178 protected:
179  void initializeDomains();
180 
181  std::vector<std::shared_ptr<AsynchronousDomain>> mDomainList;
182  std::stack<std::shared_ptr<AsynchronousDomain>> mRunningDomains;
183 };
184 
185 } // namespace al
186 
187 #endif // AL_APP_H
Simple App class.
Definition: al_App.hpp:29
void fullScreen(bool on)
void fullScreenToggle()
Toggle fullscreen.
void cursorHide(bool v)
Set cursor hiding.
void iconify()
Iconify window.
void cursor(Window::Cursor v)
Set cursor type.
Window::Cursor cursor()
Get current cursor type.
Window::DisplayMode displayMode()
Get current display mode.
void dimensions(int x, int y, int w, int h)
Set dimensions.
bool created()
void quit()
Requests domain to quit.
int width()
Get window width, in pixels.
double aspect()
Get aspect ratio (width divided by height)
Window::Dim dimensions()
Get current dimensions of window.
bool enabled(Window::DisplayMode v)
Get whether display mode flag is set.
bool fullScreen()
Get whether window is in fullscreen.
void title(const std::string &v)
Set title.
bool cursorHide()
Whether the cursor is hidden.
bool vsync()
Get whether v-sync is enabled.
Keyboard & keyboard()
Get current keyboard state.
void hide()
Hide window (if showing)
void displayMode(Window::DisplayMode v)
Mouse & mouse()
Get current mouse state.
bool visible()
Get whether window is visible.
void dimensions(const Window::Dim &v)
Set dimensions.
const std::string & title()
Get title of window.
void cursorHideToggle()
Toggle cursor hiding.
void vsync(bool v)
void dimensions(int w, int h)
Set dimensions.
int height()
Get window height, in pixels.
Interface for loading fonts and rendering text.
Definition: al_Graphics.hpp:63
The ParameterServer class creates an OSC server to receive parameter values.
A local coordinate frame.
Definition: al_Pose.hpp:63
Viewpoint within a scene.
Controller for handling input and window events.
Definition: al_Window.hpp:194
Window with OpenGL context.
Definition: al_Window.hpp:251
Cursor
Cursor icon types.
Definition: al_Window.hpp:270
DisplayMode
Window display mode bit flags.
Definition: al_Window.hpp:256
Definition: al_App.hpp:23
bool keyDown(const Keyboard &k)
Called when a keyboard key is pressed.
Window pixel dimensions.
Definition: al_Window.hpp:277