In order to put a skin on the simulator, you must be sure that you are using TouchGFX 4.7.0 or later, and that your project has been upgraded to use SDL2. If you created your project from one of the examples or demos that comes with TouchGFX 4.7.0, your application is already using SDL2. Otherwise you need to migrate your application, see Migrating from SDL to SDL2.
Start by creating the images that you want your simulator to run “inside”. Make sure that you have a rectangular area the size of the frame buffer in the image. If your application can switch between portrait mode and landscape mode, two skins are required in order to have skins in both orientations. Make sure that you save the images in .png format, and place the files in the simulator folder under the names portrait.png and landscape.png.
To apply the skins to your simulator, insert the following lines in your simulator/main.cpp
:
static_cast<HALSDL2&>(hal).loadSkin(touchgfx::ORIENTATION_LANDSCAPE, 20, 44);
static_cast<HALSDL2&>(hal).loadSkin(touchgfx::ORIENTATION_PORTRAIT, 24, 41);
It is important that the lines are inserted after the call to sdl_init()
and before the call to taskEntry()
.
Simply pass the orientation and the coordinates of the upper left corner where the frame buffer should be drawn. the loadSkin()
.
Note that a window with a skin does not have a title bar which will allow the window to be dragged on the screen. Instead use the right mouse button anywhere inside the window to drag the simulator on the screen.
Also note, that you can still use F2 to make the invalidated areas of the frame buffer flash briefly every time the screen is redrawn. You can also press F4 to disable the skin. Press F4 again to re-enable the skin.
Shaped windows
If you want your window to have a special non-rectangular shape, just make areas in the .png files transparent. The display_orientation_example shows an example of how this can be done.
Note that SDL2 does not support semi-transparent areas, so any pixel with any amount of transparency is completely transparent.
Also note, that shaped windows do not appear to work for Linux, but this is under investigation.