Window << [Table of Contents] >> Vector
uni.app.Events
So what happens when something happens? Just let it be known that you are interested in a particular event, and how to react.
import uni.group.app; import uni.group.render; void main() { auto app = new Application; auto win = new OpenGLWindow("UniD OpenGL Window", 640, 480); with(win) { subscribe("close", { delete win; }); subscribe("size", (SignalMeta meta) { glViewport(0, 0, meta.width, meta.height); paint; }); subscribe("paint", { begin; // draw something end; }); } while(app.interact) { app.rest; } }
When a window event happens, the application sends it to the window to be processed, and the window looks to see if there is anything to be done about the event. This is where signals/slots come in. Each time the window gets an event, it seeks to publish that event to all subscribers. To subscribe to an event, you just pass a name of an event and a delegate function to be used as a reaction. In this example we declare that when the window is closed that it should also be deleted. Also, when resized, that OpenGL needs to be notified and the window needs to be repainted. When a signal is sent, sometimes there is additional information available about the event called meta-information. In the case of a size event, the meta-information contains the width and height of the new window size. Finally when the window needs repainting we can use our own drawing code. This program will only repaint the window when it's resized.
Signals
Application Signals
| Signal | Meta | Provocation |
| focus | - | The application gained focus |
| blur | - | The application lost focus |
Window Signals
| Signal | Meta | Provocation |
| close | - | The window was closed |
| paint | - | The window needs to be repainted |
| size | width, height | The window was resized |
| move | x, y | The window was moved |
| focus | - | The window gained focus |
| blur | - | The window lost focus |
| enable | - | The window was enabled |
| disable | - | The window was disabled |
| hide | - | The window was hidden |
| show | - | The window was shown |
| minimize | - | The window was minimized |
| maximize | - | The window was maximized |
| restore | The window was restored | |
| mouse.button | x, y, button, state | A button on the mouse was pressed or released |
| mouse.click | x, y, button | A button on the mouse was pressed and released without moving in between |
| mouse.execute | x, y, button | A button on the mouse was double-clicked (behavior is dependent on operating system settings) |
| mouse.wheel | x, y, wheel | The wheel on the mouse was moved |
| mouse.move | x, y | The mouse was moved |
| key | x, y, key, state | A key on the keyboard was pressed or released |
