13 #ifdef HAVE_LIBDMALLOC
17 /* This is the "gui" that is installed at startup, and is used when
18 there is no other real GUI to use. For the most part, it just
19 stops the application from (1) crashing randomly, and (2) doing
20 gui-specific things when it shouldn't. */
22 #define CRASH fprintf(stderr, "HID error: pcb called GUI function %s without having a GUI available.\n", __FUNCTION__); abort()
24 typedef struct hid_gc_struct
26 int nothing_interesting_here
;
29 static HID_Attribute
*
30 nogui_get_export_options (int *n_ret
)
37 nogui_do_export (HID_Attr_Val
* options
)
43 nogui_parse_arguments (int *argc
, char ***argv
)
49 nogui_invalidate_lr (int l
, int r
, int t
, int b
)
55 nogui_invalidate_all (void)
61 nogui_set_layer (const char *name
, int idx
, int empty
)
68 nogui_end_layer (void)
79 nogui_destroy_gc (hidGC gc
)
84 nogui_use_mask (enum mask_mode mode
)
90 nogui_set_color (hidGC gc
, const char *name
)
96 nogui_set_line_cap (hidGC gc
, EndCapStyle style
)
102 nogui_set_line_width (hidGC gc
, Coord width
)
108 nogui_set_draw_xor (hidGC gc
, int xor_
)
114 nogui_set_draw_faded (hidGC gc
, int faded
)
119 nogui_draw_line (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
125 nogui_draw_arc (hidGC gc
, Coord cx
, Coord cy
, Coord width
, Coord height
,
126 Angle start_angle
, Angle end_angle
)
132 nogui_draw_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
138 nogui_fill_circle (hidGC gc
, Coord cx
, Coord cy
, Coord radius
)
144 nogui_fill_polygon (hidGC gc
, int n_coords
, Coord
*x
, Coord
*y
)
150 nogui_fill_pcb_polygon (hidGC gc
, PolygonType
*poly
, const BoxType
*clip_box
)
156 nogui_fill_pcb_pad (hidGC gc
, PadType
*pad
, bool clear
, bool mask
)
162 nogui_thindraw_pcb_pad (hidGC gc
, PadType
*pad
, bool clear
, bool mask
)
168 nogui_fill_pcb_pv (hidGC fg_gc
, hidGC bg_gc
, PinType
*pad
, bool drawHole
, bool mask
)
174 nogui_thindraw_pcb_pv (hidGC fg_gc
, hidGC bg_gc
, PinType
*pad
, bool drawHole
, bool mask
)
180 nogui_fill_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
186 nogui_calibrate (double xval
, double yval
)
192 nogui_shift_is_pressed (void)
194 /* This is called from FitCrosshairIntoGrid() when the board is loaded. */
199 nogui_control_is_pressed (void)
206 nogui_mod1_is_pressed (void)
213 nogui_get_coords (const char *msg
, Coord
*x
, Coord
*y
)
219 nogui_set_crosshair (int x
, int y
, int action
)
224 nogui_add_timer (void (*func
) (hidval user_data
),
225 unsigned long milliseconds
, hidval user_data
)
234 nogui_stop_timer (hidval timer
)
240 nogui_watch_file (int fd
, unsigned int condition
, void (*func
) (hidval watch
, int fd
, unsigned int condition
, hidval user_data
),
250 nogui_unwatch_file (hidval watch
)
256 nogui_add_block_hook (void (*func
) (hidval data
), hidval data
)
265 nogui_stop_block_hook (hidval block_hook
)
271 nogui_log (const char *fmt
, ...)
280 nogui_logv (const char *fmt
, va_list ap
)
285 /* Return a line of user input text, stripped of any newline characters.
286 * Returns NULL if the user simply presses enter, or otherwise gives no input.
288 #define MAX_LINE_LENGTH 1024
290 read_stdin_line (void)
292 static char buf
[MAX_LINE_LENGTH
];
296 s
= fgets (buf
, MAX_LINE_LENGTH
, stdin
);
303 /* Strip any trailing newline characters */
304 for (i
= strlen (s
) - 1; i
>= 0; i
--)
305 if (s
[i
] == '\r' || s
[i
] == '\n')
313 #undef MAX_LINE_LENGTH
316 nogui_confirm_dialog (char *msg
, ...)
320 bool valid_answer
= false;
325 va_start (args
, msg
);
329 printf (" ? 0=cancel 1 = ok : ");
331 answer
= read_stdin_line ();
336 if (answer
[0] == '0' && answer
[1] == '\0')
342 if (answer
[0] == '1' && answer
[1] == '\0')
350 while (!valid_answer
);
355 nogui_close_confirm_dialog ()
357 return nogui_confirm_dialog (_("OK to lose data ?"), NULL
);
361 nogui_report_dialog (char *title
, char *msg
)
363 printf ("--- %s ---\n%s\n", title
, msg
);
367 nogui_prompt_for (const char *msg
, const char *default_string
)
372 printf ("%s [%s] : ", msg
, default_string
);
374 printf ("%s : ", msg
);
376 answer
= read_stdin_line ();
378 return strdup ((default_string
!= NULL
) ? default_string
: "");
383 /* FIXME - this could use some enhancement to actually use the other
386 nogui_fileselect (const char *title
, const char *descr
,
387 char *default_file
, char *default_ext
,
388 const char *history_tag
, int flags
)
393 printf ("%s [%s] : ", title
, default_file
);
395 printf ("%s : ", title
);
397 answer
= read_stdin_line ();
399 return (default_file
!= NULL
) ? strdup (default_file
) : NULL
;
405 nogui_attribute_dialog (HID_Attribute
* attrs
,
406 int n_attrs
, HID_Attr_Val
* results
,
407 const char * title
, const char * descr
)
413 nogui_show_item (void *item
)
426 nogui_progress (int so_far
, int total
, const char *message
)
432 nogui_request_debug_draw (void)
438 nogui_flush_debug_draw (void)
443 nogui_finish_debug_draw (void)
448 common_nogui_init (HID
*hid
)
450 hid
->get_export_options
= nogui_get_export_options
;
451 hid
->do_export
= nogui_do_export
;
452 hid
->parse_arguments
= nogui_parse_arguments
;
453 hid
->invalidate_lr
= nogui_invalidate_lr
;
454 hid
->invalidate_all
= nogui_invalidate_all
;
455 hid
->set_layer
= nogui_set_layer
;
456 hid
->end_layer
= nogui_end_layer
;
457 hid
->make_gc
= nogui_make_gc
;
458 hid
->destroy_gc
= nogui_destroy_gc
;
459 hid
->use_mask
= nogui_use_mask
;
460 hid
->set_color
= nogui_set_color
;
461 hid
->set_line_cap
= nogui_set_line_cap
;
462 hid
->set_line_width
= nogui_set_line_width
;
463 hid
->set_draw_xor
= nogui_set_draw_xor
;
464 hid
->set_draw_faded
= nogui_set_draw_faded
;
465 hid
->draw_line
= nogui_draw_line
;
466 hid
->draw_arc
= nogui_draw_arc
;
467 hid
->draw_rect
= nogui_draw_rect
;
468 hid
->fill_circle
= nogui_fill_circle
;
469 hid
->fill_polygon
= nogui_fill_polygon
;
470 hid
->fill_pcb_polygon
= nogui_fill_pcb_polygon
;
471 hid
->fill_pcb_pad
= nogui_fill_pcb_pad
;
472 hid
->thindraw_pcb_pad
= nogui_thindraw_pcb_pad
;
473 hid
->fill_pcb_pv
= nogui_fill_pcb_pv
;
474 hid
->thindraw_pcb_pv
= nogui_thindraw_pcb_pv
;
475 hid
->fill_rect
= nogui_fill_rect
;
476 hid
->calibrate
= nogui_calibrate
;
477 hid
->shift_is_pressed
= nogui_shift_is_pressed
;
478 hid
->control_is_pressed
= nogui_control_is_pressed
;
479 hid
->mod1_is_pressed
= nogui_mod1_is_pressed
;
480 hid
->get_coords
= nogui_get_coords
;
481 hid
->set_crosshair
= nogui_set_crosshair
;
482 hid
->add_timer
= nogui_add_timer
;
483 hid
->stop_timer
= nogui_stop_timer
;
484 hid
->watch_file
= nogui_watch_file
;
485 hid
->unwatch_file
= nogui_unwatch_file
;
486 hid
->add_block_hook
= nogui_add_block_hook
;
487 hid
->stop_block_hook
= nogui_stop_block_hook
;
488 hid
->log
= nogui_log
;
489 hid
->logv
= nogui_logv
;
490 hid
->confirm_dialog
= nogui_confirm_dialog
;
491 hid
->close_confirm_dialog
= nogui_close_confirm_dialog
;
492 hid
->report_dialog
= nogui_report_dialog
;
493 hid
->prompt_for
= nogui_prompt_for
;
494 hid
->fileselect
= nogui_fileselect
;
495 hid
->attribute_dialog
= nogui_attribute_dialog
;
496 hid
->show_item
= nogui_show_item
;
497 hid
->beep
= nogui_beep
;
498 hid
->progress
= nogui_progress
;
499 hid
->request_debug_draw
= nogui_request_debug_draw
;
500 hid
->flush_debug_draw
= nogui_flush_debug_draw
;
501 hid
->finish_debug_draw
= nogui_finish_debug_draw
;
504 static HID nogui_hid
;
507 hid_nogui_get_hid (void)
509 memset (&nogui_hid
, 0, sizeof (HID
));
511 nogui_hid
.struct_size
= sizeof (HID
);
512 nogui_hid
.name
= "nogui";
513 nogui_hid
.description
= "Default GUI when no other GUI is present. "
516 common_nogui_init (&nogui_hid
);