57 # include <cairo-win32.h>
59 # include <cairo-quartz.h>
61 # include <cairo-xlib.h>
66 #define dprintf if(DEBUG) printf
71 extern gerbv_screen_t
screen;
81 render_check_scale_factor_limits (
void) {
92 render_zoom_display (gint zoomType, gdouble scaleFactor, gdouble mouseX, gdouble mouseY) {
95 gdouble mouseCoordinateX = 0.0;
96 gdouble mouseCoordinateY = 0.0;
97 double oldWidth, oldHeight;
106 if (zoomType == ZOOM_IN_CMOUSE || zoomType == ZOOM_OUT_CMOUSE) {
109 mouseCoordinateY = (screenRenderInfo.
displayHeight - mouseY) /
122 case ZOOM_IN_CMOUSE :
125 (void) render_check_scale_factor_limits ();
132 case ZOOM_OUT_CMOUSE :
148 (void) render_check_scale_factor_limits ();
155 GERB_MESSAGE(_(
"Illegal zoom direction %d"), zoomType);
158 if (zoomType == ZOOM_IN_CMOUSE || zoomType == ZOOM_OUT_CMOUSE) {
164 render_refresh_rendered_image_on_screen();
178 int x1, y1, x2, y2, dx, dy;
179 double centerPointX, centerPointY;
182 x1 = MIN(
screen.start_x, event->x);
183 y1 = MIN(
screen.start_y, event->y);
184 x2 = MAX(
screen.start_x, event->x);
185 y2 = MAX(
screen.start_y, event->y);
189 if ((dx >= 4) && (dy >= 4)) {
190 if (
screen.centered_outline_zoom) {
206 (void) render_check_scale_factor_limits ();
212 render_refresh_rendered_image_on_screen();
217 render_draw_selection_box_outline(
void) {
220 GdkGCValuesMask values_mask;
221 gint x1, y1, x2, y2, dx, dy;
223 memset(&values, 0,
sizeof(values));
224 values.function = GDK_XOR;
225 if (!
screen.zoom_outline_color.pixel)
226 gdk_colormap_alloc_color(gdk_colormap_get_system(), &
screen.zoom_outline_color, FALSE, TRUE);
227 values.foreground =
screen.zoom_outline_color;
228 values_mask = GDK_GC_FUNCTION | GDK_GC_FOREGROUND;
229 gc = gdk_gc_new_with_values(
screen.drawing_area->window, &values, values_mask);
238 gdk_draw_rectangle(
screen.drawing_area->window, gc, FALSE, x1, y1, dx, dy);
244 render_draw_zoom_outline(gboolean centered)
248 GdkGCValuesMask values_mask;
249 gint x1, y1, x2, y2, dx, dy;
251 memset(&values, 0,
sizeof(values));
252 values.function = GDK_XOR;
253 if (!
screen.zoom_outline_color.pixel)
254 gdk_colormap_alloc_color(gdk_colormap_get_system(), &
screen.zoom_outline_color, FALSE, TRUE);
255 values.foreground =
screen.zoom_outline_color;
256 values_mask = GDK_GC_FUNCTION | GDK_GC_FOREGROUND;
257 gc = gdk_gc_new_with_values(
screen.drawing_area->window, &values, values_mask);
276 gdk_draw_rectangle(
screen.drawing_area->window, gc, FALSE, x1, y1, dx, dy);
280 memset(&values, 0,
sizeof(values));
281 values.function = GDK_XOR;
282 values.foreground =
screen.zoom_outline_color;
283 values.line_style = GDK_LINE_ON_OFF_DASH;
284 values_mask = GDK_GC_FUNCTION | GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE;
285 gc = gdk_gc_new_with_values(
screen.drawing_area->window, &values,
288 if ((dy == 0) || ((
double)dx/dy > (
double)
screen.drawing_area->allocation.width/
289 screen.drawing_area->allocation.height)) {
290 dy = dx * (double)
screen.drawing_area->allocation.height/
291 screen.drawing_area->allocation.width;
294 dx = dy * (double)
screen.drawing_area->allocation.width/
295 screen.drawing_area->allocation.height;
298 gdk_draw_rectangle(
screen.drawing_area->window, gc, FALSE, (x1+x2-dx)/2,
299 (y1+y2-dy)/2, dx, dy);
307 render_board2screen(gdouble *X, gdouble *Y, gdouble x, gdouble y) {
315 render_trim_point(gdouble *start_x, gdouble *start_y, gdouble last_x, gdouble last_y)
317 const gdouble max_coord = (1<<15) - 2;
321 if (fabs (*start_x) < max_coord && fabs (*start_y) < max_coord)
324 dx = last_x - *start_x;
325 dy = last_y - *start_y;
327 if (*start_x < -max_coord) {
328 *start_x = -max_coord;
329 if (last_x > -max_coord && fabs (dx) > 0.1)
330 *start_y = last_y - (last_x + max_coord) / dx * dy;
332 if (*start_x > max_coord) {
333 *start_x = max_coord;
334 if (last_x < max_coord && fabs (dx) > 0.1)
335 *start_y = last_y - (last_x - max_coord) / dx * dy;
338 dx = last_x - *start_x;
339 dy = last_y - *start_y;
341 if (*start_y < -max_coord) {
342 *start_y = -max_coord;
343 if (last_y > -max_coord && fabs (dy) > 0.1)
344 *start_x = last_x - (last_y + max_coord) / dy * dx;
346 if (*start_y > max_coord) {
347 *start_y = max_coord;
348 if (last_y < max_coord && fabs (dy) > 0.1)
349 *start_x = last_x - (last_y - max_coord) / dy * dx;
362 GdkGCValuesMask values_mask;
363 gdouble start_x, start_y, last_x, last_y;
364 memset(&values, 0,
sizeof(values));
365 values.function = GDK_XOR;
366 if (!
screen.zoom_outline_color.pixel)
367 gdk_colormap_alloc_color(gdk_colormap_get_system(), &
screen.zoom_outline_color, FALSE, TRUE);
368 values.foreground =
screen.zoom_outline_color;
369 values_mask = GDK_GC_FUNCTION | GDK_GC_FOREGROUND;
370 gc = gdk_gc_new_with_values(
screen.drawing_area->window, &values,
372 render_board2screen(&start_x, &start_y,
374 render_board2screen(&last_x, &last_y,
376 render_trim_point(&start_x, &start_y, last_x, last_y);
377 render_trim_point(&last_x, &last_y, start_x, start_y);
378 gdk_draw_line(
screen.drawing_area->window, gc, start_x,
379 start_y, last_x, last_y);
388 gdouble x1, y1, x2, y2;
391 x1 = MIN(
screen.measure_start_x,
screen.measure_last_x);
392 y1 = MIN(
screen.measure_start_y,
screen.measure_last_y);
393 x2 = MAX(
screen.measure_start_x,
screen.measure_last_x);
394 y2 = MAX(
screen.measure_start_y,
screen.measure_last_y);
398 screen.win.lastMeasuredX = dx;
399 screen.win.lastMeasuredY = dy;
400 callbacks_update_statusbar_measured_distance (dx, dy);
405 void render_selection_layer (
void){
408 if (
screen.selectionRenderData)
409 cairo_surface_destroy ((cairo_surface_t *)
screen.selectionRenderData);
410 screen.selectionRenderData =
411 (gpointer) cairo_surface_create_similar ((cairo_surface_t *)
screen.windowSurface,
412 CAIRO_CONTENT_COLOR_ALPHA, screenRenderInfo.
displayWidth,
415 cr= cairo_create(
screen.selectionRenderData);
416 gerbv_render_cairo_set_scale_and_translation(cr, &screenRenderInfo);
417 cairo_set_source_rgba (cr, 1.0, 1.0, 1.0, 0.85);
421 if (
screen.selectionInfo.selectedNodeArray->len > 0) {
422 gerbv_selection_item_t sItem = g_array_index (
screen.selectionInfo.selectedNodeArray,
423 gerbv_selection_item_t, 0);
425 dprintf(
" .... calling render_image_to_cairo_target on selection layer...\n");
431 DRAW_SELECTIONS, &
screen.selectionInfo, &screenRenderInfo,
441 void render_refresh_rendered_image_on_screen (
void) {
444 dprintf(
"----> Entering redraw_pixmap...\n");
445 cursor = gdk_cursor_new(GDK_WATCH);
446 gdk_window_set_cursor(GDK_WINDOW(
screen.drawing_area->window), cursor);
447 gdk_cursor_destroy(cursor);
451 gdk_pixmap_unref(
screen.pixmap);
456 dprintf(
"<---- leaving redraw_pixmap.\n");
460 dprintf(
" .... Now try rendering the drawing using cairo .... \n");
471 (gpointer) cairo_surface_create_similar ((cairo_surface_t *)
screen.windowSurface,
472 CAIRO_CONTENT_COLOR_ALPHA, screenRenderInfo.
displayWidth,
476 dprintf(
" .... calling render_image_to_cairo_target on layer %d...\n", i);
481 render_selection_layer();
483 render_recreate_composite_surface ();
486 callbacks_switch_to_correct_cursor ();
487 callbacks_force_expose_event_for_screen();
492 render_clear_selection_buffer (
void){
496 g_array_remove_range (
screen.selectionInfo.selectedNodeArray, 0,
497 screen.selectionInfo.selectedNodeArray->len);
499 callbacks_update_selected_object_message (FALSE);
503 render_remove_selected_objects_belonging_to_layer (gint index) {
506 for (i=
screen.selectionInfo.selectedNodeArray->len-1; i>=0; i--) {
507 gerbv_selection_item_t sItem = g_array_index (
screen.selectionInfo.selectedNodeArray,
508 gerbv_selection_item_t, i);
512 g_array_remove_index (
screen.selectionInfo.selectedNodeArray, index);
515 callbacks_update_selected_object_message (FALSE);
520 render_create_cairo_buffer_surface () {
521 if (
screen.bufferSurface) {
522 cairo_surface_destroy (
screen.bufferSurface);
523 screen.bufferSurface = NULL;
525 if (!
screen.windowSurface)
528 screen.bufferSurface= cairo_surface_create_similar ((cairo_surface_t *)
screen.windowSurface,
536 render_find_selected_objects_and_refresh_display (gint activeFileIndex, gboolean eraseOldSelection){
538 if ((eraseOldSelection)&&(
screen.selectionInfo.selectedNodeArray->len))
539 g_array_remove_range (
screen.selectionInfo.selectedNodeArray, 0,
540 screen.selectionInfo.selectedNodeArray->len);
544 if (!render_create_cairo_buffer_surface())
549 cairo_t *cr= cairo_create(
screen.bufferSurface);
550 gerbv_render_cairo_set_scale_and_translation(cr,&screenRenderInfo);
553 FIND_SELECTIONS, &
screen.selectionInfo, &screenRenderInfo, TRUE,
558 if (!
screen.selectionInfo.selectedNodeArray->len)
562 render_refresh_rendered_image_on_screen ();
565 render_selection_layer();
566 render_recreate_composite_surface ();
567 callbacks_force_expose_event_for_screen();
573 render_fill_selection_buffer_from_mouse_click (gint mouseX, gint mouseY, gint activeFileIndex,
574 gboolean eraseOldSelection) {
575 screen.selectionInfo.lowerLeftX = mouseX;
576 screen.selectionInfo.lowerLeftY = mouseY;
579 render_find_selected_objects_and_refresh_display (activeFileIndex, eraseOldSelection);
584 render_fill_selection_buffer_from_mouse_drag (gint corner1X, gint corner1Y,
585 gint corner2X, gint corner2Y, gint activeFileIndex, gboolean eraseOldSelection) {
587 screen.selectionInfo.lowerLeftX = MIN(corner1X, corner2X);
588 screen.selectionInfo.lowerLeftY = MIN(corner1Y, corner2Y);
590 screen.selectionInfo.upperRightX = MAX(corner1X, corner2X);
591 screen.selectionInfo.upperRightY = MAX(corner1Y, corner2Y);
594 render_find_selected_objects_and_refresh_display (activeFileIndex, eraseOldSelection);
598 void render_recreate_composite_surface () {
601 if (!render_create_cairo_buffer_surface())
604 cairo_t *cr= cairo_create(
screen.bufferSurface);
626 cairo_set_source_surface (cr, (cairo_surface_t *)
screen.selectionRenderData,
628 cairo_paint_with_alpha (cr,1.0);
634 void render_project_to_cairo_target (cairo_t *cr) {
641 cairo_set_source_surface (cr, (cairo_surface_t *)
screen.bufferSurface, 0 , 0);
647 render_free_screen_resources (
void) {
648 if (
screen.selectionRenderData)
649 cairo_surface_destroy ((cairo_surface_t *)
650 screen.selectionRenderData);
652 cairo_surface_destroy ((cairo_surface_t *)
655 cairo_surface_destroy ((cairo_surface_t *)
658 gdk_pixmap_unref(
screen.pixmap);