void _ttk_draw_menu(cairo_t * cr, int x, int y, int width) { cairo_save(cr); int height = TTK_MENU_HEIGHT; cairo_set_source_rgba(cr, 59.0/255.0, 59.0/255.0, 59.0/255.0, 1); cairo_rectangle(cr, x, y, width, height); cairo_fill(cr); { cairo_surface_t * surface = cairo_get_target(cr); gfx_context_t fake_context = { .width = cairo_image_surface_get_width(surface), .height = cairo_image_surface_get_height(surface), .depth = 32, .buffer = NULL, .backbuffer = cairo_image_surface_get_data(surface) }; set_font_face(FONT_SANS_SERIF); set_font_size(13); draw_string(&fake_context, x + 8, y + height - 6, rgb(248,248,248), "File"); } cairo_restore(cr); }
void _ttk_draw_button_select(cairo_t * cr, int x, int y, int width, int height, char * title) { cairo_save(cr); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND); cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0); cairo_set_source_rgba(cr, 134.0/255.0, 173.0/255.0, 201.0/255.0, 1.0); cairo_set_line_width(cr, 2); cairo_stroke(cr); cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0); cairo_set_source_rgba(cr, 202.0/255.0, 211.0/255.0, 232.0/255.0, 1.0); cairo_fill(cr); { cairo_surface_t * surface = cairo_get_target(cr); gfx_context_t fake_context = { .width = cairo_image_surface_get_width(surface), .height = cairo_image_surface_get_height(surface), .depth = 32, .buffer = NULL, .backbuffer = cairo_image_surface_get_data(surface) }; set_font_face(FONT_SANS_SERIF); set_font_size(13); int str_width = draw_string_width(title); draw_string(&fake_context, (width - str_width) / 2 + x, y + (height) / 2 + 4, rgb(49,49,49), title); } cairo_restore(cr); }
static void draw_centered_label(int y, int size, char * label) { set_font_face(FONT_SANS_SERIF); set_font_size(size); int x = center_win_x(draw_string_width(label)); draw_string(ctx, x, y, rgb(0,0,0), label); }
void _ttk_draw_button_hover(cairo_t * cr, int x, int y, int width, int height) { cairo_save(cr); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND); cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0); cairo_set_source_rgba(cr, 44.0/255.0, 71.0/255.0, 91.0/255.0, 29.0/255.0); cairo_set_line_width(cr, 4); cairo_stroke(cr); cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0); cairo_set_source_rgba(cr, 158.0/255.0, 169.0/255.0, 177.0/255.0, 1.0); cairo_set_line_width(cr, 2); cairo_stroke(cr); { cairo_pattern_t * pat = cairo_pattern_create_linear(2 + x, 2 + y, 2 + x, 2 + y + height - 4); cairo_pattern_add_color_stop_rgba(pat, 0, 1, 1, 1, 1); cairo_pattern_add_color_stop_rgba(pat, 1, 229.0/255.0, 229.0/255.0, 246.0/255.0, 1); cairo_rounded_rectangle(cr, 2 + x, 2 + y, width - 4, height - 4, 2.0); cairo_set_source(cr, pat); cairo_fill(cr); cairo_pattern_destroy(pat); } { cairo_pattern_t * pat = cairo_pattern_create_linear(3 + x, 3 + y, 3 + x, 3 + y + height - 4); cairo_pattern_add_color_stop_rgba(pat, 0, 252.0/255.0, 252.0/255.0, 254.0/255.0, 1); cairo_pattern_add_color_stop_rgba(pat, 1, 212.0/255.0, 223.0/255.0, 251.0/255.0, 1); cairo_rounded_rectangle(cr, 3 + x, 3 + y, width - 5, height - 5, 2.0); cairo_set_source(cr, pat); cairo_fill(cr); cairo_pattern_destroy(pat); } { cairo_surface_t * surface = cairo_get_target(cr); gfx_context_t fake_context = { .width = cairo_image_surface_get_width(surface), .height = cairo_image_surface_get_height(surface), .depth = 32, .buffer = NULL, .backbuffer = cairo_image_surface_get_data(surface) }; set_font_face(FONT_SANS_SERIF); set_font_size(13); char * title = "Button with Hover Highlight"; int str_width = draw_string_width(title); draw_string(&fake_context, (width - str_width) / 2 + x, y + (height) / 2 + 4, rgb(49,49,49), title); } cairo_restore(cr); }
static void render_decorations_fancy(yutani_window_t * window, gfx_context_t * ctx, char * title, int decors_active) { int width = window->width; int height = window->height; for (int j = 0; j < decor_top_height; ++j) { for (int i = 0; i < width; ++i) { GFX(ctx,i,j) = 0; } } for (int j = decor_top_height; j < height - decor_bottom_height; ++j) { for (int i = 0; i < decor_left_width; ++i) { GFX(ctx,i,j) = 0; } for (int i = width - decor_right_width; i < width; ++i) { GFX(ctx,i,j) = 0; } } for (int j = height - decor_bottom_height; j < height; ++j) { for (int i = 0; i < width; ++i) { GFX(ctx,i,j) = 0; } } if (decors_active == DECOR_INACTIVE) decors_active = INACTIVE; draw_sprite(ctx, sprites[decors_active + 0], 0, 0); for (int i = 0; i < width - (ul_width + ur_width); ++i) { draw_sprite(ctx, sprites[decors_active + 1], i + ul_width, 0); } draw_sprite(ctx, sprites[decors_active + 2], width - ur_width, 0); for (int i = 0; i < height - (u_height + l_height); ++i) { draw_sprite(ctx, sprites[decors_active + 3], 0, i + u_height); draw_sprite(ctx, sprites[decors_active + 4], width - mr_width, i + u_height); } draw_sprite(ctx, sprites[decors_active + 5], 0, height - l_height); for (int i = 0; i < width - (ll_width + lr_width); ++i) { draw_sprite(ctx, sprites[decors_active + 6], i + ll_width, height - l_height); } draw_sprite(ctx, sprites[decors_active + 7], width - lr_width, height - l_height); set_font_face(FONT_SANS_SERIF_BOLD); set_font_size(12); int title_offset = (width / 2) - (draw_string_width(title) / 2); if (decors_active == 0) { draw_string(ctx, title_offset, TEXT_OFFSET, rgb(226,226,226), title); } else { draw_string(ctx, title_offset, TEXT_OFFSET, rgb(147,147,147), title); } /* Buttons */ draw_sprite(ctx, sprites[decors_active + 8], width - 28, 16); }
void cairo_context::add_text(text_path const& path, cairo_face_manager & manager, face_manager<freetype_engine> & font_manager, double scale_factor) { double sx = path.center.x; double sy = path.center.y; path.rewind(); for (int iii = 0; iii < path.num_nodes(); iii++) { char_info_ptr c; double x, y, angle; path.vertex(&c, &x, &y, &angle); face_set_ptr faces = font_manager.get_face_set(c->format->face_name, c->format->fontset); double text_size = c->format->text_size * scale_factor; faces->set_character_sizes(text_size); glyph_ptr glyph = faces->get_glyph(c->c); if (glyph) { cairo_matrix_t matrix; matrix.xx = text_size * cos(angle); matrix.xy = text_size * sin(angle); matrix.yx = text_size * -sin(angle); matrix.yy = text_size * cos(angle); matrix.x0 = 0; matrix.y0 = 0; set_font_matrix(matrix); set_font_face(manager, glyph->get_face()); glyph_path(glyph->get_index(), sx + x, sy - y); set_line_width(2.0 * c->format->halo_radius * scale_factor); set_line_join(ROUND_JOIN); set_color(c->format->halo_fill); stroke(); set_color(c->format->fill); show_glyph(glyph->get_index(), sx + x, sy - y); } } }
void cairo_context::add_text(glyph_positions const& pos, cairo_face_manager & manager, composite_mode_e comp_op, composite_mode_e halo_comp_op, double scale_factor) { pixel_position const& base_point = pos.get_base_point(); const double sx = base_point.x; const double sy = base_point.y; for (auto const& glyph_pos : pos) { glyph_info const& glyph = glyph_pos.glyph; glyph.face->set_character_sizes(glyph.format->text_size * scale_factor); } //render halo double halo_radius = 0; set_operator(halo_comp_op); for (auto const& glyph_pos : pos) { glyph_info const& glyph = glyph_pos.glyph; halo_radius = glyph.format->halo_radius * scale_factor; // make sure we've got reasonable values. if (halo_radius <= 0.0 || halo_radius > 1024.0) continue; double text_size = glyph.format->text_size * scale_factor; cairo_matrix_t matrix; matrix.xx = text_size * glyph_pos.rot.cos; matrix.xy = text_size * glyph_pos.rot.sin; matrix.yx = text_size * -glyph_pos.rot.sin; matrix.yy = text_size * glyph_pos.rot.cos; matrix.x0 = 0; matrix.y0 = 0; set_font_matrix(matrix); set_font_face(manager, glyph.face); pixel_position new_pos = glyph_pos.pos + glyph.offset.rotate(glyph_pos.rot); glyph_path(glyph.glyph_index, pixel_position(sx + new_pos.x, sy - new_pos.y)); set_line_width(2.0 * halo_radius); set_line_join(ROUND_JOIN); set_color(glyph.format->halo_fill, glyph.format->halo_opacity); stroke(); } set_operator(comp_op); for (auto const& glyph_pos : pos) { glyph_info const& glyph = glyph_pos.glyph; double text_size = glyph.format->text_size * scale_factor; cairo_matrix_t matrix; matrix.xx = text_size * glyph_pos.rot.cos; matrix.xy = text_size * glyph_pos.rot.sin; matrix.yx = text_size * -glyph_pos.rot.sin; matrix.yy = text_size * glyph_pos.rot.cos; matrix.x0 = 0; matrix.y0 = 0; set_font_matrix(matrix); set_font_face(manager, glyph.face); pixel_position new_pos = glyph_pos.pos + glyph.offset.rotate(glyph_pos.rot); set_color(glyph.format->fill, glyph.format->text_opacity); show_glyph(glyph.glyph_index, pixel_position(sx + new_pos.x, sy - new_pos.y)); } }