58 #include <cairo-win32.h>
60 #include <cairo-quartz.h>
62 #include <cairo-xlib.h>
74 render_zoom_display(gint zoomType, gdouble scaleFactor, gdouble mouseX, gdouble mouseY) {
75 gdouble mouseCoordinateX = 0.0;
76 gdouble mouseCoordinateY = 0.0;
77 double oldWidth, oldHeight;
82 if (zoomType == ZOOM_IN_CMOUSE || zoomType == ZOOM_OUT_CMOUSE) {
93 MIN((gdouble)GERBV_SCALE_MAX, (1 + 1 / 3.0) * screenRenderInfo.
scaleFactorX);
101 case ZOOM_OUT_CMOUSE:
103 MAX((gdouble)GERBV_SCALE_MIN, (1 - 1 / 3.0) * screenRenderInfo.
scaleFactorX);
112 screenRenderInfo.
scaleFactorX = MIN((gdouble)GERBV_SCALE_MAX, scaleFactor);
119 default: GERB_MESSAGE(_(
"Illegal zoom direction %d"), zoomType);
122 if (zoomType == ZOOM_IN_CMOUSE || zoomType == ZOOM_OUT_CMOUSE) {
128 render_refresh_rendered_image_on_screen();
140 int x1, y1, x2, y2, dx, dy;
141 double centerPointX, centerPointY;
144 x1 = MIN((gdouble)screen.start_x, event->x);
145 y1 = MIN((gdouble)screen.start_y, event->y);
146 x2 = MAX((gdouble)screen.start_x, event->x);
147 y2 = MAX((gdouble)screen.start_y, event->y);
151 if ((dx >= 4) && (dy >= 4)) {
152 if (screen.centered_outline_zoom) {
154 x1 = screen.start_x - dx;
155 y1 = screen.start_y - dy;
159 half_x = (x1 + x2) / 2;
160 half_y = (y1 + y2) / 2;
174 render_refresh_rendered_image_on_screen();
179 render_draw_selection_box_outline(
void) {
182 GdkGCValuesMask values_mask;
183 gint x1, y1, x2, y2, dx, dy;
185 memset(&values, 0,
sizeof(values));
186 values.function = GDK_XOR;
187 if (!screen.zoom_outline_color.pixel)
188 gdk_colormap_alloc_color(gdk_colormap_get_system(), &screen.zoom_outline_color, FALSE, TRUE);
189 values.foreground = screen.zoom_outline_color;
190 values_mask = GDK_GC_FUNCTION | GDK_GC_FOREGROUND;
191 gc = gdk_gc_new_with_values(screen.drawing_area->window, &values, values_mask);
193 x1 = MIN(screen.start_x, screen.last_x);
194 y1 = MIN(screen.start_y, screen.last_y);
195 x2 = MAX(screen.start_x, screen.last_x);
196 y2 = MAX(screen.start_y, screen.last_y);
200 gdk_draw_rectangle(screen.drawing_area->window, gc, FALSE, x1, y1, dx, dy);
206 render_draw_zoom_outline(gboolean centered) {
209 GdkGCValuesMask values_mask;
210 gint x1, y1, x2, y2, dx, dy;
212 memset(&values, 0,
sizeof(values));
213 values.function = GDK_XOR;
214 if (!screen.zoom_outline_color.pixel)
215 gdk_colormap_alloc_color(gdk_colormap_get_system(), &screen.zoom_outline_color, FALSE, TRUE);
216 values.foreground = screen.zoom_outline_color;
217 values_mask = GDK_GC_FUNCTION | GDK_GC_FOREGROUND;
218 gc = gdk_gc_new_with_values(screen.drawing_area->window, &values, values_mask);
220 x1 = MIN(screen.start_x, screen.last_x);
221 y1 = MIN(screen.start_y, screen.last_y);
222 x2 = MAX(screen.start_x, screen.last_x);
223 y2 = MAX(screen.start_y, screen.last_y);
229 x1 = screen.start_x - dx;
230 y1 = screen.start_y - dy;
237 gdk_draw_rectangle(screen.drawing_area->window, gc, FALSE, x1, y1, dx, dy);
241 memset(&values, 0,
sizeof(values));
242 values.function = GDK_XOR;
243 values.foreground = screen.zoom_outline_color;
244 values.line_style = GDK_LINE_ON_OFF_DASH;
245 values_mask = GDK_GC_FUNCTION | GDK_GC_FOREGROUND | GDK_GC_LINE_STYLE;
246 gc = gdk_gc_new_with_values(screen.drawing_area->window, &values, values_mask);
249 || ((
double)dx / dy > (
double)screen.drawing_area->allocation.width / screen.drawing_area->allocation.height)) {
250 dy = dx * (double)screen.drawing_area->allocation.height / screen.drawing_area->allocation.width;
252 dx = dy * (double)screen.drawing_area->allocation.width / screen.drawing_area->allocation.height;
255 gdk_draw_rectangle(screen.drawing_area->window, gc, FALSE, (x1 + x2 - dx) / 2, (y1 + y2 - dy) / 2, dx, dy);
263 render_board2screen(gdouble* X, gdouble* Y, gdouble x, gdouble y) {
270 render_trim_point(gdouble* start_x, gdouble* start_y, gdouble last_x, gdouble last_y) {
271 const gdouble max_coord = (1 << 15) - 2;
275 if (fabs(*start_x) < max_coord && fabs(*start_y) < max_coord)
278 dx = last_x - *start_x;
279 dy = last_y - *start_y;
281 if (*start_x < -max_coord) {
282 *start_x = -max_coord;
283 if (last_x > -max_coord && fabs(dx) > 0.1)
284 *start_y = last_y - (last_x + max_coord) / dx * dy;
286 if (*start_x > max_coord) {
287 *start_x = max_coord;
288 if (last_x < max_coord && fabs(dx) > 0.1)
289 *start_y = last_y - (last_x - max_coord) / dx * dy;
292 dx = last_x - *start_x;
293 dy = last_y - *start_y;
295 if (*start_y < -max_coord) {
296 *start_y = -max_coord;
297 if (last_y > -max_coord && fabs(dy) > 0.1)
298 *start_x = last_x - (last_y + max_coord) / dy * dx;
300 if (*start_y > max_coord) {
301 *start_y = max_coord;
302 if (last_y < max_coord && fabs(dy) > 0.1)
303 *start_x = last_x - (last_y - max_coord) / dy * dx;
315 GdkGCValuesMask values_mask;
316 gdouble start_x, start_y, last_x, last_y;
317 memset(&values, 0,
sizeof(values));
318 values.function = GDK_XOR;
319 values.line_width = 6;
320 if (!screen.zoom_outline_color.pixel)
321 gdk_colormap_alloc_color(gdk_colormap_get_system(), &screen.zoom_outline_color, FALSE, TRUE);
322 values.foreground = screen.zoom_outline_color;
323 values_mask = GDK_GC_FUNCTION | GDK_GC_LINE_WIDTH | GDK_GC_FOREGROUND;
324 gc = gdk_gc_new_with_values(screen.drawing_area->window, &values, values_mask);
325 render_board2screen(&start_x, &start_y, screen.measure_start_x, screen.measure_start_y);
326 render_board2screen(&last_x, &last_y, screen.measure_stop_x, screen.measure_stop_y);
327 render_trim_point(&start_x, &start_y, last_x, last_y);
328 render_trim_point(&last_x, &last_y, start_x, start_y);
329 gdk_draw_line(screen.drawing_area->window, gc, start_x, start_y, last_x, last_y);
339 dx = fabs(screen.measure_start_x - screen.measure_stop_x);
340 dy = fabs(screen.measure_start_y - screen.measure_stop_y);
342 screen.measure_last_x = dx;
343 screen.measure_last_y = dy;
344 callbacks_update_statusbar_measured_distance(dx, dy);
350 render_selection(
void) {
351 gerbv_selection_item_t sel_item;
358 if (selection_length(&screen.selectionInfo) == 0)
361 if (screen.selectionRenderData)
362 cairo_surface_destroy((cairo_surface_t*)screen.selectionRenderData);
364 screen.selectionRenderData = (gpointer)cairo_surface_create_similar(
365 (cairo_surface_t*)screen.windowSurface, CAIRO_CONTENT_COLOR_ALPHA, screenRenderInfo.
displayWidth,
377 for (j = 0; j < selection_length(&screen.selectionInfo); j++) {
378 sel_item = selection_get_item_by_index(&screen.selectionInfo, j);
379 if (file->
image != sel_item.image)
384 cr = cairo_create(screen.selectionRenderData);
385 gerbv_render_cairo_set_scale_and_translation(cr, &screenRenderInfo);
386 cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.85);
387 draw_image_to_cairo_target(
388 cr, file->
image, pixel_width, DRAW_SELECTIONS, &screen.selectionInfo, &screenRenderInfo, TRUE,
400 render_refresh_rendered_image_on_screen(
void) {
403 dprintf(
"----> Entering redraw_pixmap...\n");
404 cursor = gdk_cursor_new(GDK_WATCH);
405 gdk_window_set_cursor(GDK_WINDOW(screen.drawing_area->window), cursor);
406 gdk_cursor_destroy(cursor);
410 gdk_pixmap_unref(screen.pixmap);
411 screen.pixmap = gdk_pixmap_new(
414 gerbv_render_to_pixmap_using_gdk(
415 mainProject, screen.pixmap, &screenRenderInfo, &screen.selectionInfo, &screen.selection_color
417 dprintf(
"<---- leaving redraw_pixmap.\n");
420 dprintf(
" .... Now try rendering the drawing using cairo .... \n");
431 (cairo_surface_t*)screen.windowSurface, CAIRO_CONTENT_COLOR_ALPHA, screenRenderInfo.
displayWidth,
436 dprintf(
" .... calling render_image_to_cairo_target on layer %d...\n", i);
441 render_recreate_composite_surface();
444 callbacks_switch_to_correct_cursor();
445 callbacks_force_expose_event_for_screen();
453 for (i = 0; i < selection_length(sel_info);) {
454 gerbv_selection_item_t sItem = selection_get_item_by_index(sel_info, i);
457 selection_clear_item_by_index(sel_info, i);
465 render_create_cairo_buffer_surface() {
466 if (screen.bufferSurface) {
467 cairo_surface_destroy(screen.bufferSurface);
468 screen.bufferSurface = NULL;
470 if (!screen.windowSurface)
473 screen.bufferSurface = cairo_surface_create_similar(
474 (cairo_surface_t*)screen.windowSurface, CAIRO_CONTENT_COLOR, screenRenderInfo.
displayWidth,
482 render_find_selected_objects_and_refresh_display(gint activeFileIndex,
enum selection_action action) {
483 enum draw_mode mode = FIND_SELECTIONS;
486 if ((action == SELECTION_REPLACE) && (selection_length(&screen.selectionInfo) != 0))
487 selection_clear(&screen.selectionInfo);
489 if (action == SELECTION_TOGGLE)
490 mode = FIND_SELECTIONS_TOGGLE;
494 if (!render_create_cairo_buffer_surface())
499 cairo_t* cr = cairo_create(screen.bufferSurface);
500 gerbv_render_cairo_set_scale_and_translation(cr, &screenRenderInfo);
501 draw_image_to_cairo_target(
510 render_refresh_rendered_image_on_screen();
512 render_recreate_composite_surface();
513 callbacks_force_expose_event_for_screen();
519 render_fill_selection_buffer_from_mouse_click(
520 gint mouseX, gint mouseY, gint activeFileIndex,
enum selection_action action
522 screen.selectionInfo.lowerLeftX = mouseX;
523 screen.selectionInfo.lowerLeftY = mouseY;
526 render_find_selected_objects_and_refresh_display(activeFileIndex, action);
531 render_fill_selection_buffer_from_mouse_drag(
532 gint corner1X, gint corner1Y, gint corner2X, gint corner2Y, gint activeFileIndex,
enum selection_action action
535 screen.selectionInfo.lowerLeftX = MIN(corner1X, corner2X);
536 screen.selectionInfo.lowerLeftY = MIN(corner1Y, corner2Y);
538 screen.selectionInfo.upperRightX = MAX(corner1X, corner2X);
539 screen.selectionInfo.upperRightY = MAX(corner1Y, corner2Y);
542 render_find_selected_objects_and_refresh_display(activeFileIndex, action);
547 render_recreate_composite_surface() {
550 if (!render_create_cairo_buffer_surface())
553 cairo_t* cr = cairo_create(screen.bufferSurface);
555 cairo_set_source_rgba(
575 if (selection_length(&screen.selectionInfo) != 0) {
577 cairo_set_source_surface(cr, (cairo_surface_t*)screen.selectionRenderData, 0, 0);
578 cairo_paint_with_alpha(cr, 1.0);
585 render_project_to_cairo_target(cairo_t* cr) {
587 cairo_set_source_rgba(
593 cairo_set_source_surface(cr, (cairo_surface_t*)screen.bufferSurface, 0, 0);
599 render_free_screen_resources(
void) {
600 if (screen.selectionRenderData)
601 cairo_surface_destroy((cairo_surface_t*)screen.selectionRenderData);
602 if (screen.bufferSurface)
603 cairo_surface_destroy((cairo_surface_t*)screen.bufferSurface);
604 if (screen.windowSurface)
605 cairo_surface_destroy((cairo_surface_t*)screen.windowSurface);
607 gdk_pixmap_unref(screen.pixmap);
Header info for the GUI callback functions.
Header info for the cairo rendering functions and the related selection calculating functions.
void gerbv_drill_stats_add_layer(gerbv_drill_stats_t *accum_stats, gerbv_drill_stats_t *input_stats, int this_layer)
gerbv_drill_stats_t * gerbv_drill_stats_new(void)
Allocates a new drill_stats structure.
gerbv_stats_t * gerbv_stats_new(void)
Allocates a new gerbv_stats structure.
void gerbv_stats_add_layer(gerbv_stats_t *accum_stats, gerbv_stats_t *input_stats, int this_layer)
void gerbv_render_zoom_to_fit_display(gerbv_project_t *gerbvProject, gerbv_render_info_t *renderInfo)
Calculate the zoom and translations to fit the rendered scene inside the given scene size.
void gerbv_render_layer_to_cairo_target(cairo_t *cr, gerbv_fileinfo_t *fileInfo, gerbv_render_info_t *renderInfo)
Render a layer to a cairo context.
The main header file for the libgerbv library.
@ GERBV_RENDER_TYPE_GDK_XOR
@ GERBV_SELECTION_POINT_CLICK
@ GERBV_SELECTION_DRAG_BOX
Header info for the GUI building functions for Gerber Viewer.
gerbv_project_t * mainProject
Global state variable to keep track of what's happening on the screen.
Header info for common structs and functions used for the GUI application.
void render_calculate_zoom_from_outline(GtkWidget *widget, GdkEventButton *event)
Will determine the outline of the zoomed regions.
gerbv_stats_t * generate_gerber_analysis(void)
void render_draw_measure_distance(void)
Displays a measured distance graphically on screen and in statusbar.
void render_toggle_measure_line(void)
Draws/erases measure line.
gerbv_drill_stats_t * generate_drill_analysis(void)
Header info for the rendering support functions for gerbv.
Header info for the selection support functions for libgerbv.
gerbv_user_transformation_t transform
gpointer privateRenderData
gerbv_stats_t * gerbv_stats
gerbv_layertype_t layertype
gerbv_drill_stats_t * drill_stats
gboolean show_invisible_selection
gerbv_render_types_t renderType