Combine buffers with blit functions and properties

To create the illusion of the moving blue bar, you can use blit functions and properties to combine the buffers you've created and make them visible by posting them to the application window.

The sample doesn't bother listening for events, so if you want to break the while loop, just press Ctrl+C to exit the sample or kill the process.

while (1) {
    screen_buffer_t screen_buf[2];
    screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)screen_buf);
        

The sample fills the buffer with the yellow background color — the format of the color argument is AARRGGBB. By default a fill operation covers the entire destination buffer. For the background window, this is what you want to see, so there's no need to specify more arguments.

int bg[] = { SCREEN_BLIT_COLOR, 0xffffff00, SCREEN_BLIT_END };
screen_fill(screen_ctx, screen_buf[0], bg);
        

The vertical blue bar is also a rectangular area, so you can use the screen_fill() function again. This time you must specify the size, position, and color of the rectangle. The vertical bar covers the entire height of the window, but not its width.

int bar[] = {
SCREEN_BLIT_COLOR, 0xff0000ff,
SCREEN_BLIT_DESTINATION_X, pos,
SCREEN_BLIT_DESTINATION_WIDTH, barwidth,
SCREEN_BLIT_END };
screen_fill(screen_ctx, screen_buf[0], bar);
        

To complete the application's graphics, blend the hourglass in the pixmap with the window buffer. Specify the dimensions of a rectangle to contain the hourglass and set the transparency mode to indicate that the hourglass should blend with whatever is already in the window buffer.

int hg[] = {
    SCREEN_BLIT_SOURCE_WIDTH, 100,
    SCREEN_BLIT_SOURCE_HEIGHT, 100,
    SCREEN_BLIT_DESTINATION_X, 10,
    SCREEN_BLIT_DESTINATION_Y, 10,
    SCREEN_BLIT_DESTINATION_WIDTH, 100,
    SCREEN_BLIT_DESTINATION_HEIGHT, 100,
    SCREEN_BLIT_TRANSPARENCY, SCREEN_TRANSPARENCY_SOURCE_OVER,
    SCREEN_BLIT_END
};
        
Calling screen_post_window() will:
  1. Draw the background, the hourglass, and the blue bar onto the window buffer.
  2. Make the background, the hourglass and the blue bar visible on the display.
  3. Signal the windowing system to redraw the screen.

This function also flushes the blits, so it's not necessary to flush the blits before calling a post operation.

screen_blit(screen_ctx, screen_buf[0], screen_pbuf, hg);
screen_post_window(screen_win, screen_buf[0], 1, rect, 0);
        

Finally, to make the blue bar appear to move from left to right across the background, increment its position by one after each frame, and then wrap the position back to the origin of the buffer before the bar begins to move off the right-hand edge of the screen.

if (++pos > rect[2] - barwidth) {
    pos = 0;
    }
}