void paint_message(cairo_t *cr, const char *from, const char *content) { static char from_buffer[256]; if (strlen(from) > 0) snprintf(from_buffer, sizeof(from_buffer), "[%s]", from); else strncpy(from_buffer, "", sizeof(from_buffer)); cairo_save(cr); //清空背景 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.0); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint (cr); //设置字体 cairo_select_font_face (cr, font_name, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size (cr, font_size); //计算文字位置 cairo_text_extents_t extents_from, extents_content; cairo_text_extents(cr, from_buffer, &extents_from); cairo_text_extents(cr, content, &extents_content); int x = (window_width - extents_from.width - extents_content.width) / 2; if (x < 0) x = 0; int y = window_height - 10; //实现昵称和消息内容 paint_text(cr, from_buffer, x, y, 1, 2, font_color, border_color, shadow_color); paint_text(cr, content, x + extents_from.width + font_size / 2, y, 1, 2, font_color, border_color, shadow_color); cairo_restore (cr); check_cairo_status(); }
/* paint the combobox */ static LRESULT paint (HTHEME theme, HWND hwnd, HDC hParamDC, ULONG state) { PAINTSTRUCT ps; HDC hDC; COMBOBOXINFO cbi; DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE); hDC = (hParamDC) ? hParamDC : BeginPaint( hwnd, &ps); TRACE("hdc=%p\n", hDC); if( hDC && !(state & STATE_NOREDRAW) ) { RECT frameRect; int buttonState; cbi.cbSize = sizeof (cbi); SendMessageW (hwnd, CB_GETCOMBOBOXINFO, 0, (LPARAM)&cbi); /* paint border */ if ((dwStyle & CBS_DROPDOWNLIST) != CBS_SIMPLE) GetClientRect (hwnd, &frameRect); else { CopyRect (&frameRect, &cbi.rcItem); InflateRect(&frameRect, EDIT_CONTROL_PADDING + COMBO_XBORDERSIZE, EDIT_CONTROL_PADDING + COMBO_YBORDERSIZE); } DrawThemeBackground (theme, hDC, 0, IsWindowEnabled (hwnd) ? CBXS_NORMAL : CBXS_DISABLED, &frameRect, NULL); /* paint button */ if (cbi.stateButton != STATE_SYSTEM_INVISIBLE) { if (!IsWindowEnabled (hwnd)) buttonState = CBXS_DISABLED; else if (cbi.stateButton == STATE_SYSTEM_PRESSED) buttonState = CBXS_PRESSED; else if (state & STATE_HOT) buttonState = CBXS_HOT; else buttonState = CBXS_NORMAL; DrawThemeBackground (theme, hDC, CP_DROPDOWNBUTTON, buttonState, &cbi.rcButton, NULL); } /* paint text, if we need to */ if ((dwStyle & CBS_DROPDOWNLIST) == CBS_DROPDOWNLIST) paint_text (hwnd, hDC, dwStyle, &cbi); } if( !hParamDC ) EndPaint(hwnd, &ps); return 0; }
void paint_text(cairo_t *cr, const char *text, int x, int y, int border, int shadow, const float font_color[3], const float border_color[3], const float shadow_color[3]) { cairo_save(cr); if (shadow > 0) paint_text(cr, text, x + shadow, y + shadow, border, 0, shadow_color, shadow_color, shadow_color); if (border > 0) { cairo_set_source_rgb (cr, border_color[0], border_color[1], border_color[2]); int dx, dy; for (dx = -border; dx <= border; dx ++) { for (dy = -border; dy <= border; dy ++) { cairo_move_to (cr, x + dx, y + dy); cairo_show_text(cr, text); } } } cairo_set_source_rgb (cr, font_color[0], font_color[1], font_color[2]); cairo_move_to (cr, x, y); cairo_show_text(cr, text); cairo_restore (cr); check_cairo_status(); }
void win3d::paintGL() { QPainter painter(this); QGLPainter p(this); // clear qglClearColor(QColor(0,0,0)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // 3D painting glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glEnable(GL_CULL_FACE); paint_spheres(&p); paint_cylinders(&p); paint_lines(&p); // finishing 3d painting p.disableEffect(); // text painting crashes without this p.end(); // 3D text painting glEnable(GL_DEPTH_TEST); paint_text(); // 2D painting glDisable(GL_CULL_FACE); // glDisable(GL_BLEND); glDisable(GL_DEPTH_TEST); draw_text(painter); }
void entity_paint(SDL_Surface * dst, Entity * entity) { paint_text(dst, entity->info->name, Title, &entity->rect, ALIGN_HCENTER | ALIGN_TOP); if (entity->not_supported) paint_text(dst, "Not Supported", Error, &entity->rect, ALIGN_CENTER); else { switch (entity->data_type) { case ENTITY_DATA_TYPE_TEXT: draw_text_data(dst, &entity->rect, entity); break; case ENTITY_DATA_TYPE_FLOAT: { SDL_Rect r; r.x = entity->rect.x + 5; r.w = entity->rect.w - 10; r.y = entity->rect.y + 30; r.h = entity->rect.h - 60; draw_float_data(dst, &r, entity); } break; case ENTITY_DATA_TYPE_NONE: default: /* invalid entity type, do nothing */ break; } } #ifndef NO_DEBUG paint_text(dst, entity->info->command, Debug, &entity->rect, ALIGN_BOTTOM | ALIGN_RIGHT); #endif if (entity->paint_opts.draw_border) { rectangleRGBA(dst, entity->rect.x, entity->rect.y, entity->rect.x + entity->rect.w - 1, entity->rect.y + entity->rect.h - 1, (BORDER_COLOR >> 16) & 0xFF, (BORDER_COLOR >> 8) & 0xFF, BORDER_COLOR & 0xFF, 255); }