最近要求在QNX上做一个全景的应用,所以首先需要学习在QNX上如何显示内容。
需求描述:应用程序拥有两个窗口且两个窗口是叠加放置,使上面的窗口半透明,可以显示出下面窗口的内容。
实现逻辑简述:首先是创建两个窗口,再创建两个缓冲区。且将两个缓冲区分别绑定到两个窗口上,既窗口跟缓存区是一一对应的关系。然后分别向缓冲区填充内容,再将上面的窗口配置上透明度设置的属性。最后显示即可。
具体实现:
#include
#include <screen/screen.h>
using namespace std;
int main() {
screen_context_t screen_ctx;
screen_window_t screen_win;
char window_group_name[64];
screen_window_t screen_child_window;
// Create screen context 创建上下文
screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT);
// Create your render targets. 创建父窗口
screen_create_window(&screen_win, screen_ctx);
// Retrieve the window ID 获取窗口组标示
screen_get_window_property_cv(screen_win, SCREEN_PROPERTY_ID, sizeof(window_group_name), window_group_name );
// Create child window 创建子窗口
int wintype = SCREEN_CHILD_WINDOW;
screen_create_window_type(&screen_child_window, screen_ctx, wintype );
// child window join window group 将子窗口加入窗口组
screen_join_window_group(screen_child_window, window_group_name);
// set screen window property 设置父窗口属性
int usage = SCREEN_USAGE_WRITE | SCREEN_USAGE_NATIVE;
screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage);
// set screen child window property 设置子窗口属性
int usage1 = 10; //设置子窗口透明度,此值取值范围是0~255,0表示完全透明,255表示完全不透明
screen_set_window_property_iv(screen_child_window, SCREEN_PROPERTY_GLOBAL_ALPHA, &usage1);
int size[2] = { 1080, 720 };//设置子窗口大小
screen_set_window_property_iv(screen_child_window, SCREEN_PROPERTY_SIZE, size);
// Create screen window buffers 创建父窗口缓冲区
screen_create_window_buffers(screen_win, 1);
// Create screen child window buffers 创建子窗口的缓冲区
screen_create_window_buffers(screen_child_window, 1);
//Get access to your buffers. 父窗口绑定父窗口的缓冲区
screen_buffer_t screen_buf[2];
screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)screen_buf);
screen_buffer_t screen_child_buf[2]; //子窗口绑定子窗口的缓冲区
screen_get_window_property_pv(screen_child_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)screen_child_buf);
//3.Draw to your buffer. 向父窗口的缓冲区中填充内容
int color = 0xffffff00;
int bg[] = { SCREEN_BLIT_COLOR, color, SCREEN_BLIT_END };
screen_fill(screen_ctx, screen_buf[0], bg);
//向子窗口的缓冲区填充内容
int color2 = 0x58945600;
int bg2[] = { SCREEN_BLIT_COLOR, color2,SCREEN_BLIT_END };
screen_fill(screen_ctx, screen_child_buf[0], bg2);
//4.Trigger blit (or fill) operations (copy to your destination buffer).
int rect = 200;
screen_post_window(screen_child_window, screen_child_buf[0], 1, &rect, 0); //显示
screen_post_window(screen_win, screen_buf[0], 1, &rect, 0); //显示
while(1)
{
}
return 0;
}
注意事项:
1.除事件外,所有Screen API组件都必须与上下文相关联。
2.在窗口组中,必须将子窗口加入到窗口组中否则子窗口不会被显示
3.在程序最后是加了个死循环,目的是使程序不退出。
4.在设置窗口的透明度时,其取值范围是0~255,0是完全透明,255是完全不透明