14 #ifdef HAVE_LIBDMALLOC
18 /* This is the "gui" that is installed at startup, and is used when
19 there is no other real GUI to use. For the most part, it just
20 stops the application from (1) crashing randomly, and (2) doing
21 gui-specific things when it shouldn't. */
23 #define CRASH fprintf(stderr, "HID error: pcb called GUI function %s without having a GUI available.\n", __FUNCTION__); abort()
25 static HID_Attribute
*
26 nogui_get_export_options (int *n_ret
)
33 nogui_do_export (HID_Attr_Val
* options
)
39 nogui_parse_arguments (int *argc
, char ***argv
)
45 nogui_invalidate_lr (int l
, int r
, int t
, int b
)
51 nogui_invalidate_all (void)
57 nogui_set_layer (const char *name
, int idx
, int empty
)
64 nogui_end_layer (void)
75 nogui_destroy_gc (hidGC gc
)
80 nogui_use_mask (enum mask_mode mode
)
86 nogui_set_color (hidGC gc
, const char *name
)
92 nogui_set_line_cap (hidGC gc
, EndCapStyle style
)
98 nogui_set_line_width (hidGC gc
, Coord width
)
104 nogui_set_draw_xor (hidGC gc
, int xor_
)
110 nogui_set_draw_faded (hidGC gc
, int faded
)
115 nogui_draw_line (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
121 nogui_draw_arc (hidGC gc
, Coord cx
, Coord cy
, Coord width
, Coord height
,
122 Angle start_angle
, Angle end_angle
)
128 nogui_draw_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
134 nogui_fill_circle (hidGC gc
, Coord cx
, Coord cy
, Coord radius
)
140 nogui_fill_polygon (hidGC gc
, int n_coords
, Coord
*x
, Coord
*y
)
146 nogui_draw_pcb_polygon (hidGC gc
, PolygonType
*poly
, const BoxType
*clip_box
)
152 nogui_fill_pcb_pad (hidGC gc
, PadType
*pad
, bool clear
, bool mask
)
158 nogui_thindraw_pcb_pad (hidGC gc
, PadType
*pad
, bool clear
, bool mask
)
164 nogui_fill_pcb_pv (hidGC fg_gc
, hidGC bg_gc
, PinType
*pad
, bool drawHole
, bool mask
)
170 nogui_thindraw_pcb_pv (hidGC fg_gc
, hidGC bg_gc
, PinType
*pad
, bool drawHole
, bool mask
)
176 nogui_fill_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
182 nogui_calibrate (double xval
, double yval
)
188 nogui_shift_is_pressed (void)
190 /* This is called from FitCrosshairIntoGrid() when the board is loaded. */
195 nogui_control_is_pressed (void)
202 nogui_mod1_is_pressed (void)
209 nogui_get_coords (const char *msg
, Coord
*x
, Coord
*y
)
215 nogui_set_crosshair (int x
, int y
, int action
)
220 nogui_add_timer (void (*func
) (hidval user_data
),
221 unsigned long milliseconds
, hidval user_data
)
230 nogui_stop_timer (hidval timer
)
236 nogui_watch_file (int fd
, unsigned int condition
, void (*func
) (hidval watch
, int fd
, unsigned int condition
, hidval user_data
),
246 nogui_unwatch_file (hidval watch
)
252 nogui_add_block_hook (void (*func
) (hidval data
), hidval data
)
261 nogui_stop_block_hook (hidval block_hook
)
267 nogui_log (const char *fmt
, ...)
276 nogui_logv (const char *fmt
, va_list ap
)
281 /* Return a line of user input text, stripped of any newline characters.
282 * Returns NULL if the user simply presses enter, or otherwise gives no input.
284 #define MAX_LINE_LENGTH 1024
286 read_stdin_line (void)
288 static char buf
[MAX_LINE_LENGTH
];
292 s
= fgets (buf
, MAX_LINE_LENGTH
, stdin
);
299 /* Strip any trailing newline characters */
300 for (i
= strlen (s
) - 1; i
>= 0; i
--)
301 if (s
[i
] == '\r' || s
[i
] == '\n')
309 #undef MAX_LINE_LENGTH
312 nogui_confirm_dialog (char *msg
, ...)
316 bool valid_answer
= false;
321 va_start (args
, msg
);
325 printf (" ? 0=cancel 1 = ok : ");
327 answer
= read_stdin_line ();
332 if (answer
[0] == '0' && answer
[1] == '\0')
338 if (answer
[0] == '1' && answer
[1] == '\0')
346 while (!valid_answer
);
351 nogui_close_confirm_dialog ()
353 return nogui_confirm_dialog (_("OK to lose data ?"), NULL
);
357 nogui_report_dialog (char *title
, char *msg
)
359 printf ("--- %s ---\n%s\n", title
, msg
);
363 nogui_prompt_for (const char *msg
, const char *default_string
)
368 printf ("%s [%s] : ", msg
, default_string
);
370 printf ("%s : ", msg
);
372 answer
= read_stdin_line ();
374 return strdup ((default_string
!= NULL
) ? default_string
: "");
379 /* FIXME - this could use some enhancement to actually use the other
382 nogui_fileselect (const char *title
, const char *descr
,
383 char *default_file
, char *default_ext
,
384 const char *history_tag
, int flags
)
389 printf ("%s [%s] : ", title
, default_file
);
391 printf ("%s : ", title
);
393 answer
= read_stdin_line ();
395 return (default_file
!= NULL
) ? strdup (default_file
) : NULL
;
401 nogui_attribute_dialog (HID_Attribute
* attrs
,
402 int n_attrs
, HID_Attr_Val
* results
,
403 const char * title
, const char * descr
)
409 nogui_show_item (void *item
)
422 nogui_progress (int so_far
, int total
, const char *message
)
428 nogui_request_debug_draw (void)
434 nogui_flush_debug_draw (void)
439 nogui_finish_debug_draw (void)
444 common_nogui_init (HID
*hid
)
446 hid
->get_export_options
= nogui_get_export_options
;
447 hid
->do_export
= nogui_do_export
;
448 hid
->parse_arguments
= nogui_parse_arguments
;
449 hid
->invalidate_lr
= nogui_invalidate_lr
;
450 hid
->invalidate_all
= nogui_invalidate_all
;
451 hid
->calibrate
= nogui_calibrate
;
452 hid
->shift_is_pressed
= nogui_shift_is_pressed
;
453 hid
->control_is_pressed
= nogui_control_is_pressed
;
454 hid
->mod1_is_pressed
= nogui_mod1_is_pressed
;
455 hid
->get_coords
= nogui_get_coords
;
456 hid
->set_crosshair
= nogui_set_crosshair
;
457 hid
->add_timer
= nogui_add_timer
;
458 hid
->stop_timer
= nogui_stop_timer
;
459 hid
->watch_file
= nogui_watch_file
;
460 hid
->unwatch_file
= nogui_unwatch_file
;
461 hid
->add_block_hook
= nogui_add_block_hook
;
462 hid
->stop_block_hook
= nogui_stop_block_hook
;
463 hid
->log
= nogui_log
;
464 hid
->logv
= nogui_logv
;
465 hid
->confirm_dialog
= nogui_confirm_dialog
;
466 hid
->close_confirm_dialog
= nogui_close_confirm_dialog
;
467 hid
->report_dialog
= nogui_report_dialog
;
468 hid
->prompt_for
= nogui_prompt_for
;
469 hid
->fileselect
= nogui_fileselect
;
470 hid
->attribute_dialog
= nogui_attribute_dialog
;
471 hid
->show_item
= nogui_show_item
;
472 hid
->beep
= nogui_beep
;
473 hid
->progress
= nogui_progress
;
474 hid
->request_debug_draw
= nogui_request_debug_draw
;
475 hid
->flush_debug_draw
= nogui_flush_debug_draw
;
476 hid
->finish_debug_draw
= nogui_finish_debug_draw
;
480 common_nogui_graphics_class_init (HID_DRAW_CLASS
*klass
)
482 klass
->set_layer
= nogui_set_layer
;
483 klass
->end_layer
= nogui_end_layer
;
484 klass
->make_gc
= nogui_make_gc
;
485 klass
->destroy_gc
= nogui_destroy_gc
;
486 klass
->use_mask
= nogui_use_mask
;
487 klass
->set_color
= nogui_set_color
;
488 klass
->set_line_cap
= nogui_set_line_cap
;
489 klass
->set_line_width
= nogui_set_line_width
;
490 klass
->set_draw_xor
= nogui_set_draw_xor
;
491 klass
->set_draw_faded
= nogui_set_draw_faded
;
492 klass
->draw_line
= nogui_draw_line
;
493 klass
->draw_arc
= nogui_draw_arc
;
494 klass
->draw_rect
= nogui_draw_rect
;
495 klass
->fill_circle
= nogui_fill_circle
;
496 klass
->fill_polygon
= nogui_fill_polygon
;
497 klass
->fill_rect
= nogui_fill_rect
;
499 klass
->draw_pcb_polygon
= nogui_draw_pcb_polygon
;
500 klass
->fill_pcb_pad
= nogui_fill_pcb_pad
;
501 klass
->thindraw_pcb_pad
= nogui_thindraw_pcb_pad
;
502 klass
->fill_pcb_pv
= nogui_fill_pcb_pv
;
503 klass
->thindraw_pcb_pv
= nogui_thindraw_pcb_pv
;
507 common_nogui_graphics_init (HID_DRAW
*graphics
)
511 static HID nogui_hid
;
512 static HID_DRAW nogui_graphics
;
513 static HID_DRAW_CLASS nogui_graphics_class
;
516 hid_nogui_get_hid (void)
518 memset (&nogui_hid
, 0, sizeof (HID
));
519 memset (&nogui_graphics
, 0, sizeof (HID_DRAW
));
520 memset (&nogui_graphics_class
, 0, sizeof (HID_DRAW_CLASS
));
522 nogui_hid
.struct_size
= sizeof (HID
);
523 nogui_hid
.name
= "nogui";
524 nogui_hid
.description
= "Default GUI when no other GUI is present. "
527 common_nogui_init (&nogui_hid
);
529 common_nogui_graphics_class_init (&nogui_graphics_class
);
531 nogui_graphics
.klass
= &nogui_graphics_class
;
532 common_nogui_graphics_init (&nogui_graphics
);