static void allocate_buffer(struct gears *gears) { EGLImageKHR image; struct rectangle allocation; window_draw(gears->window); gears->surface[gears->current] = window_get_surface(gears->window); #ifdef HAVE_CAIRO_EGL image = display_get_image_for_drm_surface(gears->display, gears->surface[gears->current]); #else /* XXX: hack to make Wayland compile, even if this example doesn't run */ die("gears cannot allocate buffer: it was compiled without cairo-gl\n"); return; #endif if (!eglMakeCurrent(gears->display, NULL, NULL, gears->context)) die("faile to make context current\n"); glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->color_rbo[gears->current]); glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, image); glBindRenderbuffer(GL_RENDERBUFFER_EXT, gears->depth_rbo); window_get_child_allocation(gears->window, &allocation); glRenderbufferStorage(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, allocation.width + 20 + 32, allocation.height + 60 + 32); }
/** * \brief CALLBACK function, Wayland requests the window to redraw. * \param widget widget to be redrawn * \param data user data associated to the window * * Draws a red rectangle as demonstration of per-window data. */ static void redraw_handler(struct widget *widget, void *data) { struct eventdemo *e = data; cairo_surface_t *surface; cairo_t *cr; struct rectangle rect; if (log_redraw) printf("redraw\n"); widget_get_allocation(e->widget, &rect); surface = window_get_surface(e->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, rect.x, rect.y, rect.width, rect.height); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_fill(cr); cairo_rectangle(cr, e->x, e->y, e->w, e->h); cairo_set_source_rgba(cr, 1.0, 0, 0, 1); cairo_fill(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct editor *editor = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(editor->window); widget_get_allocation(editor->widget, &allocation); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_translate(cr, allocation.x, allocation.y); /* Draw background */ cairo_push_group(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_fill(cr); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct resizor *resizor = data; cairo_surface_t *surface; cairo_t *cr; struct rectangle allocation; widget_get_allocation(resizor->widget, &allocation); surface = window_get_surface(resizor->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_fill(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void resizor_draw(struct resizor *resizor) { cairo_surface_t *surface; cairo_t *cr; struct rectangle allocation; window_draw(resizor->window); window_get_child_allocation(resizor->window, &allocation); surface = window_get_surface(resizor->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_fill(cr); cairo_destroy(cr); cairo_surface_destroy(surface); window_flush(resizor->window); if (fabs(resizor->height.previous - resizor->height.target) > 0.1) { wl_display_frame_callback(display_get_display(resizor->display), frame_callback, resizor); } }
static void redraw_handler(struct widget *widget, void *data) { struct cliptest *cliptest = data; struct geometry *g = cliptest->view.geometry; struct rectangle allocation; cairo_t *cr; cairo_surface_t *surface; GLfloat ex[8]; GLfloat ey[8]; int n; n = calculate_edges(&cliptest->view, &g->clip, &g->surf, ex, ey); widget_get_allocation(cliptest->widget, &allocation); surface = window_get_surface(cliptest->window); cr = cairo_create(surface); widget_get_allocation(cliptest->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_paint(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_line_width(cr, 1.0); cairo_move_to(cr, allocation.width / 2.0, 0.0); cairo_line_to(cr, allocation.width / 2.0, allocation.height); cairo_move_to(cr, 0.0, allocation.height / 2.0); cairo_line_to(cr, allocation.width, allocation.height / 2.0); cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 1.0); cairo_stroke(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_push_group(cr); cairo_translate(cr, allocation.width / 2.0, allocation.height / 2.0); cairo_scale(cr, 4.0, 4.0); cairo_set_line_width(cr, 0.5); cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL); cairo_select_font_face(cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 5.0); draw_geometry(cr, &cliptest->view, ex, ey, n); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0); cairo_select_font_face(cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(cr, 12.0); draw_coordinates(cr, 10.0, 10.0, ex, ey, n); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void panel_launcher_redraw_handler(struct widget *widget, void *data) { struct panel_launcher *launcher = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(launcher->panel->window); cr = cairo_create(surface); widget_get_allocation(widget, &allocation); if (launcher->pressed) { allocation.x++; allocation.y++; } cairo_set_source_surface(cr, launcher->icon, allocation.x, allocation.y); cairo_paint(cr); if (launcher->focused) { cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.4); cairo_mask_surface(cr, launcher->icon, allocation.x, allocation.y); } cairo_destroy(cr); }
static void redraw_handler(struct widget *widget, void *data) { struct image *image = data; struct rectangle allocation; cairo_t *cr; cairo_surface_t *surface; double width, height, doc_aspect, window_aspect, scale; cairo_matrix_t matrix; cairo_matrix_t translate; surface = window_get_surface(image->window); cr = cairo_create(surface); widget_get_allocation(image->widget, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_push_group(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_paint(cr); if (!image->initialized) { image->initialized = true; width = cairo_image_surface_get_width(image->image); height = cairo_image_surface_get_height(image->image); doc_aspect = width / height; window_aspect = (double) allocation.width / allocation.height; if (doc_aspect < window_aspect) scale = allocation.height / height; else scale = allocation.width / width; image->width = width; image->height = height; cairo_matrix_init_scale(&image->matrix, scale, scale); clamp_view(image); } matrix = image->matrix; cairo_matrix_init_translate(&translate, allocation.x, allocation.y); cairo_matrix_multiply(&matrix, &matrix, &translate); cairo_set_matrix(cr, &matrix); cairo_set_source_surface(cr, image->image, 0, 0); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_paint(cr); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void text_entry_redraw_handler(struct widget *widget, void *data) { struct text_entry *entry = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(entry->window); widget_get_allocation(entry->widget, &allocation); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_push_group(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_source_rgba(cr, 1, 1, 1, 1); cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_fill(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); if (entry->active) { cairo_rectangle(cr, 0, 0, allocation.width, allocation.height); cairo_set_line_width (cr, 3); cairo_set_source_rgba(cr, 0, 0, 1, 1.0); cairo_stroke(cr); } cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_translate(cr, text_offset_left, allocation.height / 2); if (!entry->layout) entry->layout = pango_cairo_create_layout(cr); else pango_cairo_update_layout(cr, entry->layout); text_entry_update_layout(entry); pango_cairo_show_layout(cr, entry->layout); text_entry_draw_cursor(entry, cr); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct box *box = data; cairo_surface_t *surface; cairo_t *cr; surface = window_get_surface(box->window); if (surface == NULL || cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "failed to create cairo egl surface\n"); return; } cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_line_width(cr, 1.0); cairo_translate(cr, RECT_X, RECT_Y); /* red background */ cairo_set_source_rgba(cr, 255, 0, 0, 255); cairo_paint(cr); /* blue box */ cairo_set_source_rgba(cr, 0, 0, 255, 255); cairo_rectangle(cr, 0, 0, RECT_W, RECT_H); cairo_fill(cr); /* black border outside the box */ cairo_set_source_rgb(cr, 0, 0, 0); cairo_move_to(cr, 0, RECT_H + 0.5); cairo_line_to(cr, RECT_W, RECT_H + 0.5); cairo_stroke(cr); /* white border inside the box */ cairo_set_source_rgb(cr, 1, 1, 1); cairo_move_to(cr, RECT_W - 0.5, 0); cairo_line_to(cr, RECT_W - 0.5, RECT_H); cairo_stroke(cr); /* the green border on inside the box, to be split half by crop */ cairo_set_source_rgb(cr, 0, 1, 0); cairo_move_to(cr, 0.5, RECT_H); cairo_line_to(cr, 0.5, 0); cairo_move_to(cr, 0, 0.5); cairo_line_to(cr, RECT_W, 0.5); cairo_stroke(cr); cairo_destroy(cr); /* TODO: buffer_transform */ cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct view *view = data; struct rectangle allocation; cairo_surface_t *surface; cairo_t *cr; PopplerPage *page; double width, height, doc_aspect, window_aspect, scale; widget_get_allocation(view->widget, &allocation); surface = window_get_surface(view->window); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_paint(cr); if(!view->document) { cairo_destroy(cr); cairo_surface_destroy(surface); window_flush(view->window); return; } page = poppler_document_get_page(view->document, view->page); poppler_page_get_size(page, &width, &height); doc_aspect = width / height; window_aspect = (double) allocation.width / allocation.height; if (doc_aspect < window_aspect) scale = allocation.height / height; else scale = allocation.width / width; cairo_translate(cr, allocation.x, allocation.y); cairo_scale(cr, scale, scale); cairo_translate(cr, (allocation.width - width * scale) / 2 / scale, (allocation.height - height * scale) / 2 / scale); cairo_rectangle(cr, 0, 0, width, height); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgb(cr, 1, 1, 1); cairo_fill(cr); poppler_page_render(page, cr); cairo_destroy(cr); cairo_surface_destroy(surface); g_object_unref(G_OBJECT(page)); }
static void redraw_handler(struct widget *widget, void *data) { struct flower *flower = data; cairo_surface_t *surface; surface = window_get_surface(flower->window); if (surface == NULL || cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "failed to create cairo egl surface\n"); return; } draw_stuff(surface, flower->width, flower->height); cairo_surface_destroy(surface); }
static void image_draw(struct image *image) { struct rectangle allocation; GdkPixbuf *pb; cairo_t *cr; cairo_surface_t *surface; window_draw(image->window); window_get_child_allocation(image->window, &allocation); pb = gdk_pixbuf_new_from_file_at_size(image->filename, allocation.width, allocation.height, NULL); if (pb == NULL) return; surface = window_get_surface(image->window); cr = cairo_create(surface); window_get_child_allocation(image->window, &allocation); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_push_group(cr); cairo_translate(cr, allocation.x, allocation.y); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 0, 0, 0, 1); cairo_paint(cr); set_source_pixbuf(cr, pb, 0, 0, allocation.width, allocation.height); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_paint(cr); g_object_unref(pb); cairo_pop_group_to_source(cr); cairo_paint(cr); cairo_destroy(cr); window_flush(image->window); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct keyboard *keyboard = data; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; unsigned int i; unsigned int row = 0, col = 0; const struct layout *layout; layout = get_current_layout(keyboard->keyboard); surface = window_get_surface(keyboard->window); widget_get_allocation(keyboard->widget, &allocation); cr = cairo_create(surface); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_clip(cr); cairo_select_font_face(cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 16); cairo_translate(cr, allocation.x, allocation.y); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 1, 1, 1, 0.75); cairo_rectangle(cr, 0, 0, layout->columns * key_width, layout->rows * key_height); cairo_paint(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); for (i = 0; i < layout->count; ++i) { cairo_set_source_rgb(cr, 0, 0, 0); draw_key(keyboard, &layout->keys[i], cr, row, col); col += layout->keys[i].width; if (col >= layout->columns) { row += 1; col = 0; } } cairo_destroy(cr); cairo_surface_destroy(surface); }
int main(int argc, char *argv[]) { cairo_surface_t *s; struct flower flower; struct display *d; struct timeval tv; d = display_create(&argc, &argv, NULL, NULL); if (d == NULL) { fprintf(stderr, "failed to create display: %m\n"); return -1; } gettimeofday(&tv, NULL); srandom(tv.tv_usec); flower.width = 200; flower.height = 200; flower.display = d; flower.window = window_create(d, flower.width, flower.height); window_set_title(flower.window, "flower"); window_set_decoration(flower.window, 0); window_draw(flower.window); s = window_get_surface(flower.window); if (s == NULL || cairo_surface_status (s) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "failed to create cairo egl surface\n"); return -1; } draw_stuff(s, flower.width, flower.height); cairo_surface_flush(s); cairo_surface_destroy(s); window_flush(flower.window); window_set_motion_handler(flower.window, motion_handler); window_set_button_handler(flower.window, button_handler); window_set_user_data(flower.window, &flower); display_run(d); return 0; }
static void redraw_handler(struct widget *widget, void *data) { struct smoke *smoke = data; uint32_t time = smoke->time; struct wl_callback *callback; cairo_surface_t *surface; diffuse(smoke, time / 30, smoke->b[0].u, smoke->b[1].u); diffuse(smoke, time / 30, smoke->b[0].v, smoke->b[1].v); project(smoke, time / 30, smoke->b[1].u, smoke->b[1].v, smoke->b[0].u, smoke->b[0].v); advect(smoke, time / 30, smoke->b[1].u, smoke->b[1].v, smoke->b[1].u, smoke->b[0].u); advect(smoke, time / 30, smoke->b[1].u, smoke->b[1].v, smoke->b[1].v, smoke->b[0].v); project(smoke, time / 30, smoke->b[0].u, smoke->b[0].v, smoke->b[1].u, smoke->b[1].v); diffuse(smoke, time / 30, smoke->b[0].d, smoke->b[1].d); advect(smoke, time / 30, smoke->b[0].u, smoke->b[0].v, smoke->b[1].d, smoke->b[0].d); surface = window_get_surface(smoke->window); render(smoke, surface); window_damage(smoke->window, 0, 0, smoke->width, smoke->height); cairo_surface_destroy(surface); callback = wl_surface_frame(window_get_wl_surface(smoke->window)); wl_callback_add_listener(callback, &listener, smoke); wl_surface_commit(window_get_wl_surface(smoke->window)); }
static void redraw_handler(struct widget *widget, void *data) { static const double r = 10.0; struct clickdot *clickdot = data; cairo_surface_t *surface; cairo_t *cr; struct rectangle allocation; widget_get_allocation(clickdot->widget, &allocation); surface = window_get_surface(clickdot->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_rectangle(cr, allocation.x, allocation.y, allocation.width, allocation.height); cairo_set_source_rgba(cr, 0, 0, 0, 0.8); cairo_fill(cr); draw_line(clickdot, cr, &allocation); cairo_translate(cr, clickdot->dot.x + 0.5, clickdot->dot.y + 0.5); cairo_set_line_width(cr, 1.0); cairo_set_source_rgb(cr, 0.1, 0.9, 0.9); cairo_move_to(cr, 0.0, -r); cairo_line_to(cr, 0.0, r); cairo_move_to(cr, -r, 0.0); cairo_line_to(cr, r, 0.0); cairo_arc(cr, 0.0, 0.0, r, 0.0, 2.0 * M_PI); cairo_stroke(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct transformed *transformed = data; struct rectangle allocation; cairo_surface_t *surface; cairo_t *cr; surface = window_get_surface(transformed->window); if (surface == NULL || cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "failed to create cairo egl surface\n"); return; } widget_get_allocation(transformed->widget, &allocation); cr = widget_cairo_create(widget); draw_stuff(cr, allocation.width, allocation.height); cairo_surface_destroy(surface); }
static void redraw_handler(struct widget *widget, void *data) { struct smoke *smoke = data; uint32_t time = widget_get_last_time(smoke->widget); cairo_surface_t *surface; diffuse(smoke, time / 30, smoke->b[0].u, smoke->b[1].u); diffuse(smoke, time / 30, smoke->b[0].v, smoke->b[1].v); project(smoke, time / 30, smoke->b[1].u, smoke->b[1].v, smoke->b[0].u, smoke->b[0].v); advect(smoke, time / 30, smoke->b[1].u, smoke->b[1].v, smoke->b[1].u, smoke->b[0].u); advect(smoke, time / 30, smoke->b[1].u, smoke->b[1].v, smoke->b[1].v, smoke->b[0].v); project(smoke, time / 30, smoke->b[0].u, smoke->b[0].v, smoke->b[1].u, smoke->b[1].v); diffuse(smoke, time / 30, smoke->b[0].d, smoke->b[1].d); advect(smoke, time / 30, smoke->b[0].u, smoke->b[0].v, smoke->b[1].d, smoke->b[0].d); surface = window_get_surface(smoke->window); render(smoke, surface); window_damage(smoke->window, 0, 0, smoke->width, smoke->height); cairo_surface_destroy(surface); widget_schedule_redraw(smoke->widget); }
static void redraw_handler(struct widget *widget, void *data) { struct calibrator *calibrator = data; struct rectangle allocation; cairo_surface_t *surface; cairo_t *cr; int32_t drawn_x, drawn_y; widget_get_allocation(calibrator->widget, &allocation); surface = window_get_surface(calibrator->window); cr = cairo_create(surface); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); cairo_paint(cr); drawn_x = test_ratios[calibrator->current_test].x_ratio * allocation.width; drawn_y = test_ratios[calibrator->current_test].y_ratio * allocation.height; calibrator->tests[calibrator->current_test].drawn_x = drawn_x; calibrator->tests[calibrator->current_test].drawn_y = drawn_y; cairo_translate(cr, drawn_x, drawn_y); cairo_set_line_width(cr, 2.0); cairo_set_source_rgb(cr, 1.0, 0.0, 0.0); cairo_move_to(cr, 0, -10.0); cairo_line_to(cr, 0, 10.0); cairo_stroke(cr); cairo_move_to(cr, -10.0, 0); cairo_line_to(cr, 10.0, 0.0); cairo_stroke(cr); cairo_destroy(cr); cairo_surface_destroy(surface); }
static void panel_tag_redraw_handler(struct widget *widget, void *data) { static char* tag_names[] = {"a", "s", "d", "f", "g", "h", "j", "k", "l", ";"}; struct panel_tag *tag = data; cairo_text_extents_t extents; cairo_surface_t *surface; struct rectangle allocation; cairo_t *cr; surface = window_get_surface(tag->panel->window); cr = cairo_create(surface); widget_get_allocation(widget, &allocation); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_select_font_face(cr, "monospace", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, tag->font_size); //cairo_text_extents(cr, "1", &extents); int x = 0; int y = 0; cairo_move_to(cr, allocation.x, 26); if (tag->focused) cairo_set_source_rgba(cr, 0.8, 1, 1, 1); else if (tag->pressed) cairo_set_source_rgba(cr, 1, 0, 0, 1); else cairo_set_source_rgba(cr, 0, 0.7, 1, 1); cairo_show_text(cr, tag_names[tag->no]); //cairo_set_source_surface(cr, launcher->icon, allocation.x, allocation.y); //cairo_paint(cr); cairo_destroy(cr); }
static void redraw_handler(struct widget *widget, void *data) { struct fullscreen *fullscreen = data; struct rectangle allocation; cairo_surface_t *surface; cairo_t *cr; int i; double x, y, border; const char *method_name[] = { "default", "center", "zoom", "zoom_crop", "stretch"}; surface = window_get_surface(fullscreen->window); if (surface == NULL || cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "failed to create cairo egl surface\n"); return; } widget_get_allocation(fullscreen->widget, &allocation); cr = widget_cairo_create(widget); cairo_set_source_rgb(cr, 0, 0, 0); cairo_paint (cr); cairo_set_source_rgb(cr, 0, 0, 1); cairo_set_line_width (cr, 10); cairo_rectangle(cr, 5, 5, allocation.width - 10, allocation.height - 10); cairo_stroke (cr); cairo_move_to(cr, allocation.x + 15, allocation.y + 25); cairo_set_source_rgb(cr, 1, 1, 1); if (fullscreen->fshell) { draw_string(cr, "Surface size: %d, %d\n" "Scale: %d, transform: %d\n" "Pointer: %f,%f\n" "Output: %s, present method: %s\n" "Keys: (s)cale, (t)ransform, si(z)e, (m)ethod,\n" " (o)utput, modes(w)itch, (q)uit\n", fullscreen->width, fullscreen->height, window_get_buffer_scale (fullscreen->window), window_get_buffer_transform (fullscreen->window), fullscreen->pointer_x, fullscreen->pointer_y, method_name[fullscreen->present_method], fullscreen->current_output ? output_get_model(fullscreen->current_output->output): "null"); } else { draw_string(cr, "Surface size: %d, %d\n" "Scale: %d, transform: %d\n" "Pointer: %f,%f\n" "Fullscreen: %d\n" "Keys: (s)cale, (t)ransform, si(z)e, (f)ullscreen, (q)uit\n", fullscreen->width, fullscreen->height, window_get_buffer_scale (fullscreen->window), window_get_buffer_transform (fullscreen->window), fullscreen->pointer_x, fullscreen->pointer_y, fullscreen->fullscreen); } y = 100; i = 0; while (y + 60 < fullscreen->height) { border = (i++ % 2 == 0) ? 1 : 0.5; x = 50; cairo_set_line_width (cr, border); while (x + 70 < fullscreen->width) { if (window_has_focus(fullscreen->window) && fullscreen->pointer_x >= x && fullscreen->pointer_x < x + 50 && fullscreen->pointer_y >= y && fullscreen->pointer_y < y + 40) { cairo_set_source_rgb(cr, 1, 0, 0); cairo_rectangle(cr, x, y, 50, 40); cairo_fill(cr); } cairo_set_source_rgb(cr, 0, 1, 0); cairo_rectangle(cr, x + border/2.0, y + border/2.0, 50, 40); cairo_stroke(cr); x += 60; } y += 50; } if (window_has_focus(fullscreen->window) && fullscreen->draw_cursor) { cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_line_width (cr, 8); cairo_move_to(cr, fullscreen->pointer_x - 12, fullscreen->pointer_y - 12); cairo_line_to(cr, fullscreen->pointer_x + 12, fullscreen->pointer_y + 12); cairo_stroke(cr); cairo_move_to(cr, fullscreen->pointer_x + 12, fullscreen->pointer_y - 12); cairo_line_to(cr, fullscreen->pointer_x - 12, fullscreen->pointer_y + 12); cairo_stroke(cr); cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_line_width (cr, 4); cairo_move_to(cr, fullscreen->pointer_x - 10, fullscreen->pointer_y - 10); cairo_line_to(cr, fullscreen->pointer_x + 10, fullscreen->pointer_y + 10); cairo_stroke(cr); cairo_move_to(cr, fullscreen->pointer_x + 10, fullscreen->pointer_y - 10); cairo_line_to(cr, fullscreen->pointer_x - 10, fullscreen->pointer_y + 10); cairo_stroke(cr); } cairo_destroy(cr); }