1 #ifndef INCLUDE_AL_WINDOW_HPP
2 #define INCLUDE_AL_WINDOW_HPP
66 #ifndef AL_MOUSE_MAX_BUTTONS
67 #define AL_MOUSE_MAX_BUTTONS 4
129 void print(std::ostream &stream)
const;
132 friend class WindowImpl;
139 void setKey(
int k,
bool v);
173 friend class WindowImpl;
177 double mScrollX, mScrollY;
179 int mBX[AL_MOUSE_MAX_BUTTONS];
180 int mBY[AL_MOUSE_MAX_BUTTONS];
181 bool mB[AL_MOUSE_MAX_BUTTONS];
183 void button(
int b,
bool v);
184 void position(
int x,
int y);
185 void scroll(
double x,
double y);
221 virtual bool resize(
int dw,
int dh) {
return true; }
229 bool attached()
const {
return NULL != mWindow; }
230 Window &window() {
return *mWindow; }
231 const Window &window()
const {
return *mWindow; }
237 WindowEventHandler &window(Window *v) {
241 void removeFromWindow();
253 typedef std::vector<WindowEventHandler *> WindowEventHandlers;
279 Dim(
int v = 0) : l(0), t(0), w(v), h(v) {}
280 Dim(
int w_,
int h_) : l(0), t(0), w(w_), h(h_) {}
281 Dim(
int l_,
int t_,
int w_,
int h_) : l(l_), t(t_), w(w_), h(h_) {}
282 void set(
int l_,
int t_,
int w_,
int h_) {
289 float aspect()
const {
return (w != 0 && h != 0) ? float(w) / h : 1; }
290 void print()
const { printf(
"Dim: %4d x %4d @ (%4d, %4d)\n", w, h, l, t); }
336 int fbHeight()
const;
339 float highres_factor() {
return mHighresFactor; }
341 bool decorated()
const;
362 void decorated(
bool b);
374 std::function<bool(Mouse
const &)> onMouseDown = [](Mouse
const &) {
377 std::function<bool(Mouse
const &)> onMouseUp = [](Mouse
const &) {
380 std::function<bool(Mouse
const &)> onMouseDrag = [](Mouse
const &) {
383 std::function<bool(Mouse
const &)> onMouseMove = [](Mouse
const &) {
386 std::function<bool(Mouse
const &)> onMouseScroll = [](Mouse
const &) {
389 std::function<void(
int,
int)> onResize = [](int, int) {};
391 WindowEventHandlers &windowEventHandlers() {
return mWindowEventHandlers; }
409 WindowEventHandlers mWindowEventHandlers;
410 Dim mDim{50, 50, 640, 480};
411 Dim mFullScreenDim{0};
413 std::string mTitle =
"allolib";
415 bool mCursorHide =
false;
416 bool mFullScreen =
false;
417 bool mVisible =
false;
419 bool mDecorated =
true;
422 float mHighresFactor = 0;
423 int mFramebufferWidth = 0;
424 int mFramebufferHeight = 0;
427 friend class WindowImpl;
430 std::unique_ptr<class WindowImpl> mImpl;
433 bool implCreate(
bool is_verbose =
false);
434 bool implCreated()
const;
435 void implMakeCurrent();
438 void implSetCursor();
439 void implSetCursorHide();
440 void implSetDimensions();
441 void implSetFullScreen(
int monitorIndex = 0);
446 void implSetDecorated(
bool decorated);
447 bool implShouldClose();
450 Window &insert(WindowEventHandler &v,
int i);
454 for (unsigned i = 0; i < mWindowEventHandlers.size(); ++i) { \
455 if (false == mWindowEventHandlers[i]->e) break; \
458 void callHandlersMouseDown() {
459 CALL(mouseDown(mMouse));
462 void callHandlersMouseDrag() {
463 CALL(mouseDrag(mMouse));
466 void callHandlersMouseMove() {
467 CALL(mouseMove(mMouse));
470 void callHandlersMouseUp() {
471 CALL(mouseUp(mMouse));
474 void callHandlersMouseScroll() {
475 CALL(mouseScroll(mMouse));
476 onMouseScroll(mMouse);
478 void callHandlersKeyDown() {
479 CALL(keyDown(mKeyboard));
480 onKeyDown(mKeyboard);
482 void callHandlersKeyUp() {
483 CALL(keyUp(mKeyboard));
486 void callHandlersResize(
int w,
int h) {
490 void callHandlersVisibility(
bool v) { CALL(visibility(v)); }
511 void initializeWindowManager();
512 void terminateWindowManager();
513 float getCurrentWindowPixelDensity();
bool down() const
Whether last event was button down.
void ctrl(bool state)
Set ctrl key state.
void caps(bool state)
Set alt key state.
void meta(bool state)
Set meta key state.
bool ctrl() const
Whether a control key is down.
void shift(bool state)
Set shift key state.
int keyAsNumber() const
Returns decimal number correlating to key code.
void alt(bool state)
Set alt key state.
bool alt() const
Whether an alt key is down.
bool caps() const
Whether capslock is down.
void print(std::ostream &stream) const
Print keyboard state.
bool shift() const
Whether a shift key is down.
bool meta() const
Whether a meta (e.g. windows, apple) key is down.
bool isNumber() const
Whether key is a number key.
bool key(int k) const
Whether the last key was 'k'.
int key() const
Returns character or code of last key event.
bool left() const
Get whether left button is down.
bool down(int button) const
Get state of a button.
int dx() const
Get change in x position, in pixels.
int button() const
Get last clicked button.
bool down() const
Get state of last clicked button.
double scrollX() const
Get x scroll amount.
double scrollY() const
Get y scroll amount.
bool right() const
Get whether right button is down.
int dy() const
Get change in y position, in pixels.
bool middle() const
Get whether middle button is down.
Controller for handling input and window events.
virtual bool keyDown(const Keyboard &k)
Called when a keyboard key is pressed.
virtual bool mouseUp(const Mouse &m)
Called when a mouse button is released.
virtual bool mouseMove(const Mouse &m)
Called when the mouse moves.
virtual bool resize(int dw, int dh)
Called whenever window dimensions change.
virtual bool mouseDown(const Mouse &m)
Called when a mouse button is pressed.
virtual bool keyUp(const Keyboard &k)
Called when a keyboard key is released.
virtual bool mouseScroll(const Mouse &m)
Called when mouse scrolled.
virtual bool mouseDrag(const Mouse &m)
Called when the mouse moves while a button is down.
virtual bool visibility(bool v)
Called when window changes from hidden to shown and vice versa.
WindowEventHandler & windowEventHandler()
Return self.
Window with OpenGL context.
int height() const
Get window height, in pixels.
void fullScreenToggle()
Toggle fullscreen.
bool cursorHide() const
Whether the cursor is hidden.
const std::string & title() const
Get title of window.
void displayMode(DisplayMode v)
DisplayMode displayMode() const
Get current display mode.
void hide()
Hide window (if showing)
Window & prepend(WindowEventHandler &v)
static void destroyAll()
Destroy all created windows.
const Keyboard & keyboard() const
Get current keyboard state.
bool enabled(DisplayMode v) const
Get whether display mode flag is set.
void cursor(Cursor v)
Set cursor type.
double aspect() const
Get aspect ratio (width divided by height)
void dimensions(int w, int h)
Set dimensions.
Window & append(WindowEventHandler &v)
int width() const
Get window width, in pixels.
Dim dimensions() const
Get current dimensions of window.
Window & remove(WindowEventHandler &v)
Remove all window event handlers matching argument.
const Mouse & mouse() const
Get current mouse state.
void dimensions(int x, int y, int w, int h)
Set dimensions.
void cursorHideToggle()
Toggle cursor hiding.
bool create(bool is_verbose=false)
void title(const std::string &v)
Set title.
void fullScreen(bool on, int monitorIndex=0)
void dimensions(const Dim &v)
Set dimensions.
bool visible() const
Get whether window is visible.
bool fullScreen() const
Get whether window is in fullscreen.
void iconify()
Iconify window.
bool vsync() const
Get whether v-sync is enabled.
DisplayMode
Window display mode bit flags.
Cursor cursor() const
Get current cursor type.
void destroy()
Destroy current window and its associated graphics context.
void cursorHide(bool v)
Set cursor hiding.