==== Video processing ====
//iimavlib// provides several [[support:iimavlib:video_types|video data types]].
There are also some basic [[support:iimavlib:video_ops|video operations]].
=== SDLDevice ===
For video related operations, iimavlib provides lightweight wrapper around SDL library, in the class **SDLDevice**.
Signature of the constructor is:
SDLDevice(size_t width, size_t height, const std::string& title = "IIMAudio application", bool fullscreen = false);
The first two mandatory parameters (//width// and //height//) define dimensions of the application window. Parameter //title// defines the title of the window. When the parameter //fullscreen// is set to true, the application will try to start in fullscreen rather than in a window.
For simple drawing you need to use only a single method: **SDLDevice::blit**.
It's signature is:
bool blit(const video_buffer_t&, rectangle_t position);
The only parameter it has is a vector of data, pointing to the image to be shown. It expects it to be RGB data (24bit per pixel), stored in R, G, B order. The call will copy the data, so you are free to manipulate with the buffer once the method returns.
For easier manipulation with the data, the library provide a data type representing a single pixel: **RGB**, and there is a typedef **SDLDevice::data_type** representing a vector of there RGB values.
So for a window of size //width// x //height//, you can define the bitmap image as follows:
SDLDevice::data_type image(width*height);
=== Input (keyboard, mouse) ===
If you intend to handle keyboard events, you have to inherit from the **SDLDevice** class and implement methods handling the input events.
An example how to use them is in the example called **sdl_drums** in the library package (either in the binary form and the source one).
^ event ^ method to implement ^
| key press | do_key_pressed(key, pressed) |
| mouse click | do_mouse_button(key, pressed, x, y) |
| mouse move | do_mouse_moved(x, y, rel_x, rel_y) |
All the method return a boolean value. If the returned value is **false**, then the application will end.
== do_key_pressed ==
This method is called for every key press or release event. The parameter key defined the key that was pressed (you can find definitions of the keys in //include/iimavlib/keys//). When parameter //pressed// is true then the key was pressed, when it's false then the key wa released.
== do_mouse_button ==
This method is called for every mouse button. //key// means the button index, //pressed// has the same meaning as in do_key_pressed. Parameters //x// and //y// mean position of mouse when the button was pressed.
== do_mouse_moved ==
This method is called when mouse is moved. Parameters //x// and //y// mean the new position of the mouse, parameters //rel_x// and //rel_y// mean relative mouse movement since last event.