Move some fields from the HID* structure to HID_DRAW* and HID_DRAW_CLASS*
[geda-pcb/pcjc2.git] / src / hid / common / hidnogui.c
blob85e678d8e162d72740f697921e01ab5a581cdb89
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
5 #include <stdio.h>
6 #include <stdarg.h>
7 #include <stdlib.h>
8 #include <string.h>
10 #include "global.h"
11 #include "hid.h"
12 #include "hid_draw.h"
14 #ifdef HAVE_LIBDMALLOC
15 #include <dmalloc.h>
16 #endif
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)
28 CRASH;
29 return 0;
32 static void
33 nogui_do_export (HID_Attr_Val * options)
35 CRASH;
38 static void
39 nogui_parse_arguments (int *argc, char ***argv)
41 CRASH;
44 static void
45 nogui_invalidate_lr (int l, int r, int t, int b)
47 CRASH;
50 static void
51 nogui_invalidate_all (void)
53 CRASH;
56 static int
57 nogui_set_layer (const char *name, int idx, int empty)
59 CRASH;
60 return 0;
63 static void
64 nogui_end_layer (void)
68 static hidGC
69 nogui_make_gc (void)
71 return 0;
74 static void
75 nogui_destroy_gc (hidGC gc)
79 static void
80 nogui_use_mask (enum mask_mode mode)
82 CRASH;
85 static void
86 nogui_set_color (hidGC gc, const char *name)
88 CRASH;
91 static void
92 nogui_set_line_cap (hidGC gc, EndCapStyle style)
94 CRASH;
97 static void
98 nogui_set_line_width (hidGC gc, Coord width)
100 CRASH;
103 static void
104 nogui_set_draw_xor (hidGC gc, int xor_)
106 CRASH;
109 static void
110 nogui_set_draw_faded (hidGC gc, int faded)
114 static void
115 nogui_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
117 CRASH;
120 static void
121 nogui_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height,
122 Angle start_angle, Angle end_angle)
124 CRASH;
127 static void
128 nogui_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
130 CRASH;
133 static void
134 nogui_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
136 CRASH;
139 static void
140 nogui_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
142 CRASH;
145 static void
146 nogui_draw_pcb_polygon (hidGC gc, PolygonType *poly, const BoxType *clip_box)
148 CRASH;
151 static void
152 nogui_fill_pcb_pad (hidGC gc, PadType *pad, bool clear, bool mask)
154 CRASH;
157 static void
158 nogui_thindraw_pcb_pad (hidGC gc, PadType *pad, bool clear, bool mask)
160 CRASH;
163 static void
164 nogui_fill_pcb_pv (hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask)
166 CRASH;
169 static void
170 nogui_thindraw_pcb_pv (hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask)
172 CRASH;
175 static void
176 nogui_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
178 CRASH;
181 static void
182 nogui_calibrate (double xval, double yval)
184 CRASH;
187 static int
188 nogui_shift_is_pressed (void)
190 /* This is called from FitCrosshairIntoGrid() when the board is loaded. */
191 return 0;
194 static int
195 nogui_control_is_pressed (void)
197 CRASH;
198 return 0;
201 static int
202 nogui_mod1_is_pressed (void)
204 CRASH;
205 return 0;
208 static void
209 nogui_get_coords (const char *msg, Coord *x, Coord *y)
211 CRASH;
214 static void
215 nogui_set_crosshair (int x, int y, int action)
219 static hidval
220 nogui_add_timer (void (*func) (hidval user_data),
221 unsigned long milliseconds, hidval user_data)
223 hidval rv;
224 CRASH;
225 rv.lval = 0;
226 return rv;
229 static void
230 nogui_stop_timer (hidval timer)
232 CRASH;
235 static hidval
236 nogui_watch_file (int fd, unsigned int condition, void (*func) (hidval watch, int fd, unsigned int condition, hidval user_data),
237 hidval user_data)
239 hidval rv;
240 CRASH;
241 rv.lval = 0;
242 return rv;
245 static void
246 nogui_unwatch_file (hidval watch)
248 CRASH;
251 static hidval
252 nogui_add_block_hook (void (*func) (hidval data), hidval data)
254 hidval rv;
255 CRASH;
256 rv.ptr = NULL;
257 return rv;
260 static void
261 nogui_stop_block_hook (hidval block_hook)
263 CRASH;
266 static void
267 nogui_log (const char *fmt, ...)
269 va_list ap;
270 va_start (ap, fmt);
271 vprintf (fmt, ap);
272 va_end (ap);
275 static void
276 nogui_logv (const char *fmt, va_list ap)
278 vprintf (fmt, 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
285 static char *
286 read_stdin_line (void)
288 static char buf[MAX_LINE_LENGTH];
289 char *s;
290 int i;
292 s = fgets (buf, MAX_LINE_LENGTH, stdin);
293 if (s == NULL)
295 printf ("\n");
296 return NULL;
299 /* Strip any trailing newline characters */
300 for (i = strlen (s) - 1; i >= 0; i--)
301 if (s[i] == '\r' || s[i] == '\n')
302 s[i] = '\0';
304 if (s[0] == '\0')
305 return NULL;
307 return strdup (s);
309 #undef MAX_LINE_LENGTH
311 static int
312 nogui_confirm_dialog (char *msg, ...)
314 char *answer;
315 int ret = 0;
316 bool valid_answer = false;
317 va_list args;
321 va_start (args, msg);
322 vprintf (msg, args);
323 va_end (args);
325 printf (" ? 0=cancel 1 = ok : ");
327 answer = read_stdin_line ();
329 if (answer == NULL)
330 continue;
332 if (answer[0] == '0' && answer[1] == '\0')
334 ret = 0;
335 valid_answer = true;
338 if (answer[0] == '1' && answer[1] == '\0')
340 ret = 1;
341 valid_answer = true;
344 free (answer);
346 while (!valid_answer);
347 return ret;
350 static int
351 nogui_close_confirm_dialog ()
353 return nogui_confirm_dialog (_("OK to lose data ?"), NULL);
356 static void
357 nogui_report_dialog (char *title, char *msg)
359 printf ("--- %s ---\n%s\n", title, msg);
362 static char *
363 nogui_prompt_for (const char *msg, const char *default_string)
365 char *answer;
367 if (default_string)
368 printf ("%s [%s] : ", msg, default_string);
369 else
370 printf ("%s : ", msg);
372 answer = read_stdin_line ();
373 if (answer == NULL)
374 return strdup ((default_string != NULL) ? default_string : "");
375 else
376 return answer;
379 /* FIXME - this could use some enhancement to actually use the other
380 args */
381 static char *
382 nogui_fileselect (const char *title, const char *descr,
383 char *default_file, char *default_ext,
384 const char *history_tag, int flags)
386 char *answer;
388 if (default_file)
389 printf ("%s [%s] : ", title, default_file);
390 else
391 printf ("%s : ", title);
393 answer = read_stdin_line ();
394 if (answer == NULL)
395 return (default_file != NULL) ? strdup (default_file) : NULL;
396 else
397 return answer;
400 static int
401 nogui_attribute_dialog (HID_Attribute * attrs,
402 int n_attrs, HID_Attr_Val * results,
403 const char * title, const char * descr)
405 CRASH;
408 static void
409 nogui_show_item (void *item)
411 CRASH;
414 static void
415 nogui_beep (void)
417 putchar (7);
418 fflush (stdout);
421 static int
422 nogui_progress (int so_far, int total, const char *message)
424 return 0;
427 static HID_DRAW *
428 nogui_request_debug_draw (void)
430 return NULL;
433 static void
434 nogui_flush_debug_draw (void)
438 static void
439 nogui_finish_debug_draw (void)
443 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;
479 static void
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;
506 static void
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;
515 HID *
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. "
525 "Does nothing.";
526 nogui_hid.graphics = &nogui_graphics;
528 common_nogui_init (&nogui_hid);
530 common_nogui_graphics_class_init (&nogui_graphics_class);
532 nogui_graphics.klass = &nogui_graphics_class;
533 common_nogui_graphics_init (&nogui_graphics);
535 return &nogui_hid;