第一个Wayland程序

来源:互联网 发布:淘宝激活店铺激活不了 编辑:程序博客网 时间:2024/05/02 04:46

这是楼主的第一个Wayland程序:

效果图:



程序源代码:

void PaintProc(HSURFACE hSurface){PAINTSTRUCTURE ps;memset(&ps, 0, sizeof(ps));wlBeginPaint(hSurface, &ps);memset(ps.lpBuffer->lpPixelBuffer, 0xff, ps.lpBuffer->length);SIZE sz = wlGetSurfaceSize(hSurface);//paint_pixels(ps.lpBuffer->lpPixelBuffer, 20, sz.width, sz.height, ps.uTime);HCAIROSURFACE hCairoSurface = ps.lpBuffer->hCairoSurface; // 类似与 HWNDHCAIRO hdc = cairo_create(hCairoSurface); // 类似于 HDC cairo_set_source_rgb(hdc,0, 0.4, 0.8); cairo_set_line_width(hdc, 50); cairo_move_to(hdc, 0, 0); cairo_line_to(hdc, sz.width, 0);  cairo_stroke(hdc);  cairo_set_source_rgb(hdc, 0 , 0, 0); cairo_move_to(hdc, 10, 20); cairo_set_font_size(hdc, 18); cairo_show_text(hdc, "这是标题栏"); cairo_stroke(hdc);int btnCloseHeight = 20;int btnCloseWidth = 20;int btnCloseLineWidth = 2;cairo_set_source_rgb(hdc, 1, 0, 0);cairo_set_line_width(hdc, 2);cairo_move_to(hdc, sz.width-btnCloseWidth, btnCloseLineWidth/2); cairo_line_to(hdc, sz.width, btnCloseLineWidth/2);cairo_move_to(hdc, sz.width-btnCloseWidth, 0); cairo_line_to(hdc, sz.width-btnCloseWidth, btnCloseHeight);cairo_move_to(hdc, sz.width, 0); cairo_line_to(hdc, sz.width, btnCloseHeight);cairo_move_to(hdc, sz.width-btnCloseWidth, btnCloseHeight); cairo_line_to(hdc, sz.width, btnCloseHeight);cairo_move_to(hdc, sz.width-btnCloseWidth, btnCloseLineWidth/2); cairo_line_to(hdc, sz.width, btnCloseHeight);cairo_move_to(hdc, sz.width, btnCloseLineWidth/2); cairo_line_to(hdc, sz.width-btnCloseWidth, btnCloseHeight);cairo_stroke(hdc);cairo_set_source_rgb(hdc, 0 , 0, 0);cairo_move_to(hdc, 10, sz.height/2);cairo_set_font_size(hdc, 30);cairo_show_text(hdc, "你好, 中国!");cairo_stroke(hdc);cairo_set_source_rgb(hdc, 0 , 0, 0);cairo_move_to(hdc, 10, sz.height/2+30);cairo_set_font_size(hdc, 18);cairo_show_text(hdc, "--第三界主");cairo_stroke(hdc);cairo_destroy(hdc);wlRequestPaintDone(hSurface);wlEndPaint(hSurface, &ps);}void PaintDone(HSURFACE hSurface){printf("PaintDone\n");//wlRequestPaintDone(hSurface);}void PointerProc(HSURFACE hSurface, uint32_t button, uint32_t state, uint32_t serial){LPSURFACEPRIVATE lpSurfacePrivate = wlGetSurfacePrivate(hSurface);/* 鼠标左键按下了,移动窗口 */if (BTN_LEFT == button && state == WL_POINTER_BUTTON_STATE_PRESSED){HSHELLSURFACE hShellSurface = lpSurfacePrivate->hShellSurface;wl_shell_surface_move(hShellSurface, wlGetRegistry()->s_seat, serial);return;}}int main(int argc, char **argv){wlInit();int width = 400, height = 300;HSURFACE surface = wlCreateSurface("wayland-hello", width, height);wlSetPaintProc(surface, PaintProc);wlSetPaintDone(surface, PaintDone);wlSetPointerProc(surface, PointerProc);wlShowSurface(surface);int ret = 0;while (ret != -1){ret = wlDispatch();}return 0;}


0 0
原创粉丝点击