void drawButton (xcb_connection_t *connection, xcb_screen_t *screen, xcb_window_t window, int16_t x1, int16_t y1, const char *label ) { uint8_t length = strlen (label); int16_t inset = 2; int16_t width = 7 * length + 2 * (inset + 1); int16_t height = 13 + 2 * (inset + 1); xcb_point_t points[5]; points[0].x = x1; points[0].y = y1; points[1].x = x1 + width; points[1].y = y1; points[2].x = x1 + width; points[2].y = y1 - height; points[3].x = x1; points[3].y = y1 - height; points[4].x = x1; points[4].y = y1; xcb_colormap_t colors[2]; colors[0]=screen->black_pixel; colors[1]=screen->white_pixel; xcb_gcontext_t gc = getFontGC2 (connection, screen, window,colors, "7x13"); uint32_t gcv[1]= {screen->black_pixel}; xcb_change_gc(connection,gc, XCB_GC_FOREGROUND, gcv); xcb_void_cookie_t lineCookie = xcb_poly_line_checked (connection, XCB_COORD_MODE_ORIGIN, window, gc, 5, points ); testCookie (lineCookie, connection, "can't draw lines"); xcb_void_cookie_t textCookie = xcb_image_text_8_checked (connection, length, window, gc, x1 + inset + 1, y1 - inset - 1, label ); testCookie (textCookie, connection, "can't paste text"); xcb_void_cookie_t gcCookie = xcb_free_gc (connection, gc); testCookie (gcCookie, connection, "can't free gc"); };
static void drawButton(xcb_connection_t *connection, xcb_screen_t *screen, xcb_window_t window, int16_t x1, int16_t y1, const char *label) { uint8_t length = strlen(label); int16_t inset = 2; int16_t width = 7 * length + 2 * (inset + 1); int16_t height =13 + 2 * (inset + 1); xcb_point_t points[5]; points[0].x = x1; points[0].y = y1; points[1].x = x1 + width; points[1].y = y1; points[2].x = x1 + width; points[2].y = y1 - height; points[3].x = x1; points[3].y = y1 - height; points[4].x = x1; points[4].y = y1; xcb_gcontext_t gc = getFontGC(connection, screen, window, "fixed"); xcb_void_cookie_t lineCookie = xcb_poly_line_checked(connection, XCB_COORD_MODE_ORIGIN, window, gc, 5, points); testCookie(lineCookie, connection, "can't draw lines"); xcb_void_cookie_t textCookie = xcb_image_text_8_checked(connection, length, window, gc, x1 + inset +1, y1 - inset -1, label); testCookie(textCookie, connection, "can't paste text"); xcb_void_cookie_t gcCookie = xcb_free_gc(connection, gc); testCookie(gcCookie, connection, "can't free gc"); }
static void button_draw (xcb_connection_t *c, xcb_screen_t *screen, xcb_window_t window, int16_t x1, int16_t y1, const char *label) { xcb_point_t points[5]; xcb_void_cookie_t cookie_gc; xcb_void_cookie_t cookie_line; xcb_void_cookie_t cookie_text; xcb_generic_error_t *error; xcb_gcontext_t gc; int16_t width; int16_t height; uint8_t length; int16_t inset; length = strlen (label); inset = 2; gc = gc_font_get(c, screen, window, "7x13"); width = 7 * length + 2 * (inset + 1); height = 13 + 2 * (inset + 1); points[0].x = x1; points[0].y = y1; points[1].x = x1 + width; points[1].y = y1; points[2].x = x1 + width; points[2].y = y1 - height; points[3].x = x1; points[3].y = y1 - height; points[4].x = x1; points[4].y = y1; cookie_line = xcb_poly_line_checked (c, XCB_COORD_MODE_ORIGIN, window, gc, 5, points); error = xcb_request_check (c, cookie_line); if (error) { fprintf (stderr, "ERROR: can't draw lines : %d\n", error->error_code); xcb_disconnect (c); exit (-1); } cookie_text = xcb_image_text_8_checked (c, length, window, gc, x1 + inset + 1, y1 - inset - 1, label); error = xcb_request_check (c, cookie_text); if (error) { fprintf (stderr, "ERROR: can't paste text : %d\n", error->error_code); xcb_disconnect (c); exit (-1); } cookie_gc = xcb_free_gc (c, gc); error = xcb_request_check (c, cookie_gc); if (error) { fprintf (stderr, "ERROR: can't free gc : %d\n", error->error_code); xcb_disconnect (c); exit (-1); } }