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 typedef struct hid_gc_struct
27 int nothing_interesting_here
;
30 static HID_Attribute
*
31 nogui_get_export_options (int *n_ret
)
38 nogui_do_export (HID_Attr_Val
* options
)
44 nogui_parse_arguments (int *argc
, char ***argv
)
50 nogui_invalidate_lr (int l
, int r
, int t
, int b
)
56 nogui_invalidate_all (void)
62 nogui_set_layer (const char *name
, int idx
, int empty
)
69 nogui_end_layer (void)
80 nogui_destroy_gc (hidGC gc
)
85 nogui_use_mask (enum mask_mode mode
)
91 nogui_set_color (hidGC gc
, const char *name
)
97 nogui_set_line_cap (hidGC gc
, EndCapStyle style
)
103 nogui_set_line_width (hidGC gc
, Coord width
)
109 nogui_set_draw_xor (hidGC gc
, int xor_
)
115 nogui_set_draw_faded (hidGC gc
, int faded
)
120 nogui_draw_line (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
126 nogui_draw_arc (hidGC gc
, Coord cx
, Coord cy
, Coord width
, Coord height
,
127 Angle start_angle
, Angle end_angle
)
133 nogui_draw_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
139 nogui_fill_circle (hidGC gc
, Coord cx
, Coord cy
, Coord radius
)
145 nogui_fill_polygon (hidGC gc
, int n_coords
, Coord
*x
, Coord
*y
)
151 nogui_fill_pcb_polygon (hidGC gc
, PolygonType
*poly
, const BoxType
*clip_box
)
157 nogui_fill_pcb_pad (hidGC gc
, PadType
*pad
, bool clear
, bool mask
)
163 nogui_thindraw_pcb_pad (hidGC gc
, PadType
*pad
, bool clear
, bool mask
)
169 nogui_fill_pcb_pv (hidGC fg_gc
, hidGC bg_gc
, PinType
*pad
, bool drawHole
, bool mask
)
175 nogui_thindraw_pcb_pv (hidGC fg_gc
, hidGC bg_gc
, PinType
*pad
, bool drawHole
, bool mask
)
181 nogui_fill_rect (hidGC gc
, Coord x1
, Coord y1
, Coord x2
, Coord y2
)
187 nogui_calibrate (double xval
, double yval
)
193 nogui_shift_is_pressed (void)
195 /* This is called from FitCrosshairIntoGrid() when the board is loaded. */
200 nogui_control_is_pressed (void)
207 nogui_mod1_is_pressed (void)
214 nogui_get_coords (const char *msg
, Coord
*x
, Coord
*y
)
220 nogui_set_crosshair (int x
, int y
, int action
)
225 nogui_add_timer (void (*func
) (hidval user_data
),
226 unsigned long milliseconds
, hidval user_data
)
235 nogui_stop_timer (hidval timer
)
241 nogui_watch_file (int fd
, unsigned int condition
, void (*func
) (hidval watch
, int fd
, unsigned int condition
, hidval user_data
),
251 nogui_unwatch_file (hidval watch
)
257 nogui_add_block_hook (void (*func
) (hidval data
), hidval data
)
266 nogui_stop_block_hook (hidval block_hook
)
272 nogui_log (const char *fmt
, ...)
281 nogui_logv (const char *fmt
, va_list ap
)
286 /* Return a line of user input text, stripped of any newline characters.
287 * Returns NULL if the user simply presses enter, or otherwise gives no input.
289 #define MAX_LINE_LENGTH 1024
291 read_stdin_line (void)
293 static char buf
[MAX_LINE_LENGTH
];
297 s
= fgets (buf
, MAX_LINE_LENGTH
, stdin
);
304 /* Strip any trailing newline characters */
305 for (i
= strlen (s
) - 1; i
>= 0; i
--)
306 if (s
[i
] == '\r' || s
[i
] == '\n')
314 #undef MAX_LINE_LENGTH
317 nogui_confirm_dialog (char *msg
, ...)
321 bool valid_answer
= false;
326 va_start (args
, msg
);
330 printf (" ? 0=cancel 1 = ok : ");
332 answer
= read_stdin_line ();
337 if (answer
[0] == '0' && answer
[1] == '\0')
343 if (answer
[0] == '1' && answer
[1] == '\0')
351 while (!valid_answer
);
356 nogui_close_confirm_dialog ()
358 return nogui_confirm_dialog (_("OK to lose data ?"), NULL
);
362 nogui_report_dialog (char *title
, char *msg
)
364 printf ("--- %s ---\n%s\n", title
, msg
);
368 nogui_prompt_for (const char *msg
, const char *default_string
)
373 printf ("%s [%s] : ", msg
, default_string
);
375 printf ("%s : ", msg
);
377 answer
= read_stdin_line ();
379 return strdup ((default_string
!= NULL
) ? default_string
: "");
384 /* FIXME - this could use some enhancement to actually use the other
387 nogui_fileselect (const char *title
, const char *descr
,
388 char *default_file
, char *default_ext
,
389 const char *history_tag
, int flags
)
394 printf ("%s [%s] : ", title
, default_file
);
396 printf ("%s : ", title
);
398 answer
= read_stdin_line ();
400 return (default_file
!= NULL
) ? strdup (default_file
) : NULL
;
406 nogui_attribute_dialog (HID_Attribute
* attrs
,
407 int n_attrs
, HID_Attr_Val
* results
,
408 const char * title
, const char * descr
)
414 nogui_show_item (void *item
)
427 nogui_progress (int so_far
, int total
, const char *message
)
433 nogui_request_debug_draw (void)
439 nogui_flush_debug_draw (void)
444 nogui_finish_debug_draw (void)
449 common_nogui_init (HID
*hid
)
451 hid
->get_export_options
= nogui_get_export_options
;
452 hid
->do_export
= nogui_do_export
;
453 hid
->parse_arguments
= nogui_parse_arguments
;
454 hid
->invalidate_lr
= nogui_invalidate_lr
;
455 hid
->invalidate_all
= nogui_invalidate_all
;
456 hid
->set_layer
= nogui_set_layer
;
457 hid
->end_layer
= nogui_end_layer
;
458 hid
->calibrate
= nogui_calibrate
;
459 hid
->shift_is_pressed
= nogui_shift_is_pressed
;
460 hid
->control_is_pressed
= nogui_control_is_pressed
;
461 hid
->mod1_is_pressed
= nogui_mod1_is_pressed
;
462 hid
->get_coords
= nogui_get_coords
;
463 hid
->set_crosshair
= nogui_set_crosshair
;
464 hid
->add_timer
= nogui_add_timer
;
465 hid
->stop_timer
= nogui_stop_timer
;
466 hid
->watch_file
= nogui_watch_file
;
467 hid
->unwatch_file
= nogui_unwatch_file
;
468 hid
->add_block_hook
= nogui_add_block_hook
;
469 hid
->stop_block_hook
= nogui_stop_block_hook
;
470 hid
->log
= nogui_log
;
471 hid
->logv
= nogui_logv
;
472 hid
->confirm_dialog
= nogui_confirm_dialog
;
473 hid
->close_confirm_dialog
= nogui_close_confirm_dialog
;
474 hid
->report_dialog
= nogui_report_dialog
;
475 hid
->prompt_for
= nogui_prompt_for
;
476 hid
->fileselect
= nogui_fileselect
;
477 hid
->attribute_dialog
= nogui_attribute_dialog
;
478 hid
->show_item
= nogui_show_item
;
479 hid
->beep
= nogui_beep
;
480 hid
->progress
= nogui_progress
;
481 hid
->request_debug_draw
= nogui_request_debug_draw
;
482 hid
->flush_debug_draw
= nogui_flush_debug_draw
;
483 hid
->finish_debug_draw
= nogui_finish_debug_draw
;
487 common_nogui_graphics_init (HID_DRAW
*graphics
)
489 graphics
->make_gc
= nogui_make_gc
;
490 graphics
->destroy_gc
= nogui_destroy_gc
;
491 graphics
->use_mask
= nogui_use_mask
;
492 graphics
->set_color
= nogui_set_color
;
493 graphics
->set_line_cap
= nogui_set_line_cap
;
494 graphics
->set_line_width
= nogui_set_line_width
;
495 graphics
->set_draw_xor
= nogui_set_draw_xor
;
496 graphics
->set_draw_faded
= nogui_set_draw_faded
;
497 graphics
->draw_line
= nogui_draw_line
;
498 graphics
->draw_arc
= nogui_draw_arc
;
499 graphics
->draw_rect
= nogui_draw_rect
;
500 graphics
->fill_circle
= nogui_fill_circle
;
501 graphics
->fill_polygon
= nogui_fill_polygon
;
502 graphics
->fill_rect
= nogui_fill_rect
;
504 graphics
->fill_pcb_polygon
= nogui_fill_pcb_polygon
;
505 graphics
->fill_pcb_pad
= nogui_fill_pcb_pad
;
506 graphics
->thindraw_pcb_pad
= nogui_thindraw_pcb_pad
;
507 graphics
->fill_pcb_pv
= nogui_fill_pcb_pv
;
508 graphics
->thindraw_pcb_pv
= nogui_thindraw_pcb_pv
;
511 static HID nogui_hid
;
512 static HID_DRAW nogui_graphics
;
515 hid_nogui_get_hid (void)
517 memset (&nogui_hid
, 0, sizeof (HID
));
518 memset (&nogui_graphics
, 0, sizeof (HID_DRAW
));
520 nogui_hid
.struct_size
= sizeof (HID
);
521 nogui_hid
.name
= "nogui";
522 nogui_hid
.description
= "Default GUI when no other GUI is present. "
524 nogui_hid
.graphics
= &nogui_graphics
;
526 common_nogui_init (&nogui_hid
);
527 common_nogui_graphics_init (&nogui_graphics
);