2245 int32_t pointerx, int32_t pointery)
2253 if(!
g->preview_ready)
return;
2263 cairo_scale(cr, zoom_scale, zoom_scale);
2268 float pzxpy[2] = { (float)pointerx, (
float)pointery };
2270 const float pzx = pzxpy[0];
2271 const float pzy = pzxpy[1];
2274 cairo_set_source_rgba(cr, .2, .2, .2, .8);
2275 cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD);
2276 cairo_rectangle(cr,
g->clip_max_x * wd - 1.f,
g->clip_max_y * ht - 1.f,
2277 g->clip_max_w * wd + 2.0,
g->clip_max_h * ht + 2.0);
2278 cairo_rectangle(cr,
g->clip_x * wd,
g->clip_y * ht,
g->clip_w * wd,
g->clip_h * ht);
2281 if(
g->clip_x > .0f ||
g->clip_y > .0f ||
g->clip_w < 1.0f ||
g->clip_h < 1.0f)
2283 cairo_set_line_width(cr, dashes / 2.0);
2284 cairo_rectangle(cr,
g->clip_x * wd,
g->clip_y * ht,
g->clip_w * wd,
g->clip_h * ht);
2292 char dimensions[16];
2293 dimensions[0] =
'\0';
2294 PangoLayout *layout;
2297 pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
2298 pango_font_description_set_absolute_size(desc,
DT_PIXEL_APPLY_DPI(16) * PANGO_SCALE / zoom_scale);
2299 layout = pango_cairo_create_layout(cr);
2300 pango_layout_set_font_description(layout, desc);
2304 snprintf(dimensions,
sizeof(dimensions),
"%.0f x %.0f", (
float)procw *
g->clip_w, (
float)proch *
g->clip_h);
2306 pango_layout_set_text(layout, dimensions, -1);
2307 pango_layout_get_pixel_extents(layout, NULL, &ext);
2308 const float text_w = ext.width;
2311 float xp = (
g->clip_x +
g->clip_w * .5f) * wd - text_w * .5f;
2312 float yp = (
g->clip_y +
g->clip_h * .5f) * ht - text_h * .5f;
2315 double x1, y1, x2, y2;
2316 cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
2317 xp =
CLAMPF(xp, x1 + 2.0 * margin, x2 - text_w - 2.0 * margin);
2318 yp =
CLAMPF(yp, y1 + 2.0 * margin, y2 - text_h - 2.0 * margin);
2320 cairo_set_source_rgba(cr, .5, .5, .5, .9);
2322 xp - margin, yp - margin);
2323 cairo_set_source_rgb(cr, .7, .7, .7);
2324 cairo_move_to(cr, xp, yp);
2325 pango_cairo_show_layout(cr, layout);
2326 pango_font_description_free(desc);
2327 g_object_unref(layout);
2331 dt_guides_draw(cr,
g->clip_x * wd,
g->clip_y * ht,
g->clip_w * wd,
g->clip_h * ht, zoom_scale);
2336 if(
g->straightening)
2339 PangoLayout *layout;
2341 pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
2342 pango_font_description_set_absolute_size(desc,
DT_PIXEL_APPLY_DPI(16) * PANGO_SCALE / zoom_scale);
2343 layout = pango_cairo_create_layout(cr);
2344 pango_layout_set_font_description(layout, desc);
2345 const float bzx =
g->button_down_zoom_x + .5f, bzy =
g->button_down_zoom_y + .5f;
2350 cairo_move_to(cr, bzx * wd, bzy * ht);
2351 cairo_line_to(cr, pzx * wd, pzy * ht);
2355 float dx = pzx * wd - bzx * wd, dy = pzy * ht - bzy * ht;
2361 float angle = atan2f(dy, dx);
2362 angle = angle * 180 /
M_PI;
2363 if(angle > 45.0) angle -= 90;
2364 if(angle < -45.0) angle += 90;
2366 char view_angle[16];
2367 view_angle[0] =
'\0';
2368 snprintf(view_angle,
sizeof(view_angle),
"%.2f\302\260", angle);
2369 pango_layout_set_text(layout, view_angle, -1);
2370 pango_layout_get_pixel_extents(layout, &ink, NULL);
2371 const float text_w = ink.width;
2374 cairo_set_source_rgba(cr, .5, .5, .5, .9);
2376 const float yp = pzy * ht - ink.height;
2378 (cr, text_w + 2 * margin, text_h + 2 * margin, xp - margin, yp - margin);
2379 cairo_set_source_rgba(cr, .7, .7, .7, .7);
2380 cairo_move_to(cr, xp, yp);
2381 pango_cairo_show_layout(cr, layout);
2382 pango_font_description_free(desc);
2383 g_object_unref(layout);
2385 else if(
g->k_show != 1)
2388 if(grab ==
GRAB_LEFT) cairo_rectangle(cr,
g->clip_x * wd,
g->clip_y * ht, border,
g->clip_h * ht);
2389 if(grab ==
GRAB_TOP) cairo_rectangle(cr,
g->clip_x * wd,
g->clip_y * ht,
g->clip_w * wd, border);
2390 if(grab ==
GRAB_TOP_LEFT) cairo_rectangle(cr,
g->clip_x * wd,
g->clip_y * ht, border, border);
2392 cairo_rectangle(cr, (
g->clip_x +
g->clip_w) * wd - border,
g->clip_y * ht, border,
g->clip_h * ht);
2394 cairo_rectangle(cr,
g->clip_x * wd, (
g->clip_y +
g->clip_h) * ht - border,
g->clip_w * wd, border);
2396 cairo_rectangle(cr, (
g->clip_x +
g->clip_w) * wd - border, (
g->clip_y +
g->clip_h) * ht - border,
2399 cairo_rectangle(cr, (
g->clip_x +
g->clip_w) * wd - border,
g->clip_y * ht, border, border);
2401 cairo_rectangle(cr,
g->clip_x * wd, (
g->clip_y +
g->clip_h) * ht - border, border, border);
2406 if(
g->k_show == 1 &&
p->k_type > 0)
2413 float pts[8] = {
p->kxa * wp,
p->kya * hp,
p->kxb * wp,
p->kyb * hp,
2414 p->kxc * wp,
p->kyc * hp,
p->kxd * wp,
p->kyd * hp };
2420 const float v1t = pts[0] - (pts[6] - pts[0]) * pts[1] / (pts[7] - pts[1]);
2421 const float v1b = (pts[6] - pts[0]) * ht / (pts[7] - pts[1]) + v1t;
2422 const float v2t = pts[2] - (pts[4] - pts[2]) * pts[3] / (pts[5] - pts[3]);
2423 const float v2b = (pts[4] - pts[2]) * ht / (pts[5] - pts[3]) + v2t;
2424 const float h1l = pts[1] - (pts[3] - pts[1]) * pts[0] / (pts[2] - pts[0]);
2425 const float h1r = (pts[3] - pts[1]) * wd / (pts[2] - pts[0]) + h1l;
2426 const float h2l = pts[7] - (pts[5] - pts[7]) * pts[6] / (pts[4] - pts[6]);
2427 const float h2r = (pts[5] - pts[7]) * wd / (pts[4] - pts[6]) + h2l;
2430 cairo_move_to(cr, v1t, 0);
2431 cairo_line_to(cr, v1b, ht);
2433 cairo_move_to(cr, v2t, 0);
2434 cairo_line_to(cr, v2b, ht);
2436 cairo_move_to(cr, 0, h1l);
2437 cairo_line_to(cr, wd, h1r);
2439 cairo_move_to(cr, 0, h2l);
2440 cairo_line_to(cr, wd, h2r);
2444 if(
g->k_selected_segment == 0)
2446 cairo_move_to(cr, pts[0], pts[1]);
2447 cairo_line_to(cr, pts[2], pts[3]);
2450 else if(
g->k_selected_segment == 1)
2452 cairo_move_to(cr, pts[4], pts[5]);
2453 cairo_line_to(cr, pts[2], pts[3]);
2456 else if(
g->k_selected_segment == 2)
2458 cairo_move_to(cr, pts[4], pts[5]);
2459 cairo_line_to(cr, pts[6], pts[7]);
2462 else if(
g->k_selected_segment == 3)
2464 cairo_move_to(cr, pts[0], pts[1]);
2465 cairo_line_to(cr, pts[6], pts[7]);
2469 else if(
p->k_type == 2)
2472 const float h1l = pts[1] - (pts[3] - pts[1]) * pts[0] / (pts[2] - pts[0]);
2473 const float h1r = (pts[3] - pts[1]) * wd / (pts[2] - pts[0]) + h1l;
2474 const float h2l = pts[7] - (pts[5] - pts[7]) * pts[6] / (pts[4] - pts[6]);
2475 const float h2r = (pts[5] - pts[7]) * wd / (pts[4] - pts[6]) + h2l;
2478 cairo_move_to(cr, 0, h1l);
2479 cairo_line_to(cr, wd, h1r);
2481 cairo_move_to(cr, 0, h2l);
2482 cairo_line_to(cr, wd, h2r);
2486 if(
g->k_selected_segment == 1)
2488 cairo_move_to(cr, pts[4], pts[5]);
2489 cairo_line_to(cr, pts[2], pts[3]);
2492 else if(
g->k_selected_segment == 3)
2494 cairo_move_to(cr, pts[0], pts[1]);
2495 cairo_line_to(cr, pts[6], pts[7]);
2499 else if(
p->k_type == 1)
2502 const float v1t = pts[0] - (pts[6] - pts[0]) * pts[1] / (pts[7] - pts[1]);
2503 const float v1b = (pts[6] - pts[0]) * ht / (pts[7] - pts[1]) + v1t;
2504 const float v2t = pts[2] - (pts[4] - pts[2]) * pts[3] / (pts[5] - pts[3]);
2505 const float v2b = (pts[4] - pts[2]) * ht / (pts[5] - pts[3]) + v2t;
2508 cairo_move_to(cr, v1t, 0);
2509 cairo_line_to(cr, v1b, ht);
2511 cairo_move_to(cr, v2t, 0);
2512 cairo_line_to(cr, v2b, ht);
2516 if(
g->k_selected_segment == 0)
2518 cairo_move_to(cr, pts[0], pts[1]);
2519 cairo_line_to(cr, pts[2], pts[3]);
2522 else if(
g->k_selected_segment == 2)
2524 cairo_move_to(cr, pts[4], pts[5]);
2525 cairo_line_to(cr, pts[6], pts[7]);
2531 if(
g->k_selected == 0)
2534 cairo_set_source_rgba(cr, 1.0, 0, 0, .8);
2539 cairo_set_source_rgba(cr, 1.0, 0, 0, .5);
2543 if(
g->k_selected == 1)
2546 cairo_set_source_rgba(cr, 1.0, 0, 0, .8);
2551 cairo_set_source_rgba(cr, 1.0, 0, 0, .5);
2555 if(
g->k_selected == 2)
2558 cairo_set_source_rgba(cr, 1.0, 0, 0, .8);
2563 cairo_set_source_rgba(cr, 1.0, 0, 0, .5);
2567 if(
g->k_selected == 3)
2570 cairo_set_source_rgba(cr, 1.0, 0, 0, .8);
2575 cairo_set_source_rgba(cr, 1.0, 0, 0, .5);
2580 PangoLayout *layout;
2583 pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
2584 pango_font_description_set_absolute_size(desc,
DT_PIXEL_APPLY_DPI(16) * PANGO_SCALE);
2585 layout = pango_cairo_create_layout(cr);
2586 pango_layout_set_font_description(layout, desc);
2588 pango_layout_set_text(layout,
"ok", -1);
2589 pango_layout_get_pixel_extents(layout, &ink, NULL);
2590 int c[2] = { (
MIN(pts[4], pts[2]) +
MAX(pts[0], pts[6])) / 2.0f,
2591 (
MIN(pts[5], pts[7]) +
MAX(pts[1], pts[3])) / 2.0f };
2592 cairo_set_source_rgba(cr, .5, .5, .5, .9);
2597 cairo_move_to(cr, c[0] - ink.width / 2.0, c[1] - 3.0 * ink.height / 4.0);
2599 pango_cairo_show_layout(cr, layout);
2600 pango_font_description_free(desc);
2601 g_object_unref(layout);
2604 gboolean sym =
FALSE;
2605 if(
p->k_type == 1 ||
p->k_type == 3)
2607 if(
p->k_sym == 1 ||
p->k_sym == 3) sym =
TRUE;
2608 gui_draw_sym(cr, (pts[0] + pts[6]) / 2.0f, (pts[1] + pts[7]) / 2.0f, 1.f, sym);
2609 gui_draw_sym(cr, (pts[2] + pts[4]) / 2.0f, (pts[3] + pts[5]) / 2.0f, 1.f, sym);
2611 if(
p->k_type == 2 ||
p->k_type == 3)
2613 sym = (
p->k_sym >= 2);
2614 gui_draw_sym(cr, (pts[0] + pts[2]) / 2.0f, (pts[1] + pts[3]) / 2.0f, 1.f, sym);
2615 gui_draw_sym(cr, (pts[6] + pts[4]) / 2.0f, (pts[7] + pts[5]) / 2.0f, 1.f, sym);