Move HID drawing API prototypes into a separate header file
[geda-pcb/pcjc2.git] / src / hid / common / hidnogui.c
blobbab0bff3bc9af9cc928b830ee19e4d74bbfea5bf
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 typedef struct hid_gc_struct
27 int nothing_interesting_here;
28 } hid_gc_struct;
30 static HID_Attribute *
31 nogui_get_export_options (int *n_ret)
33 CRASH;
34 return 0;
37 static void
38 nogui_do_export (HID_Attr_Val * options)
40 CRASH;
43 static void
44 nogui_parse_arguments (int *argc, char ***argv)
46 CRASH;
49 static void
50 nogui_invalidate_lr (int l, int r, int t, int b)
52 CRASH;
55 static void
56 nogui_invalidate_all (void)
58 CRASH;
61 static int
62 nogui_set_layer (const char *name, int idx, int empty)
64 CRASH;
65 return 0;
68 static void
69 nogui_end_layer (void)
73 static hidGC
74 nogui_make_gc (void)
76 return 0;
79 static void
80 nogui_destroy_gc (hidGC gc)
84 static void
85 nogui_use_mask (enum mask_mode mode)
87 CRASH;
90 static void
91 nogui_set_color (hidGC gc, const char *name)
93 CRASH;
96 static void
97 nogui_set_line_cap (hidGC gc, EndCapStyle style)
99 CRASH;
102 static void
103 nogui_set_line_width (hidGC gc, Coord width)
105 CRASH;
108 static void
109 nogui_set_draw_xor (hidGC gc, int xor_)
111 CRASH;
114 static void
115 nogui_set_draw_faded (hidGC gc, int faded)
119 static void
120 nogui_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
122 CRASH;
125 static void
126 nogui_draw_arc (hidGC gc, Coord cx, Coord cy, Coord width, Coord height,
127 Angle start_angle, Angle end_angle)
129 CRASH;
132 static void
133 nogui_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
135 CRASH;
138 static void
139 nogui_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
141 CRASH;
144 static void
145 nogui_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
147 CRASH;
150 static void
151 nogui_fill_pcb_polygon (hidGC gc, PolygonType *poly, const BoxType *clip_box)
153 CRASH;
156 static void
157 nogui_fill_pcb_pad (hidGC gc, PadType *pad, bool clear, bool mask)
159 CRASH;
162 static void
163 nogui_thindraw_pcb_pad (hidGC gc, PadType *pad, bool clear, bool mask)
165 CRASH;
168 static void
169 nogui_fill_pcb_pv (hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask)
171 CRASH;
174 static void
175 nogui_thindraw_pcb_pv (hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask)
177 CRASH;
180 static void
181 nogui_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
183 CRASH;
186 static void
187 nogui_calibrate (double xval, double yval)
189 CRASH;
192 static int
193 nogui_shift_is_pressed (void)
195 /* This is called from FitCrosshairIntoGrid() when the board is loaded. */
196 return 0;
199 static int
200 nogui_control_is_pressed (void)
202 CRASH;
203 return 0;
206 static int
207 nogui_mod1_is_pressed (void)
209 CRASH;
210 return 0;
213 static void
214 nogui_get_coords (const char *msg, Coord *x, Coord *y)
216 CRASH;
219 static void
220 nogui_set_crosshair (int x, int y, int action)
224 static hidval
225 nogui_add_timer (void (*func) (hidval user_data),
226 unsigned long milliseconds, hidval user_data)
228 hidval rv;
229 CRASH;
230 rv.lval = 0;
231 return rv;
234 static void
235 nogui_stop_timer (hidval timer)
237 CRASH;
240 static hidval
241 nogui_watch_file (int fd, unsigned int condition, void (*func) (hidval watch, int fd, unsigned int condition, hidval user_data),
242 hidval user_data)
244 hidval rv;
245 CRASH;
246 rv.lval = 0;
247 return rv;
250 static void
251 nogui_unwatch_file (hidval watch)
253 CRASH;
256 static hidval
257 nogui_add_block_hook (void (*func) (hidval data), hidval data)
259 hidval rv;
260 CRASH;
261 rv.ptr = NULL;
262 return rv;
265 static void
266 nogui_stop_block_hook (hidval block_hook)
268 CRASH;
271 static void
272 nogui_log (const char *fmt, ...)
274 va_list ap;
275 va_start (ap, fmt);
276 vprintf (fmt, ap);
277 va_end (ap);
280 static void
281 nogui_logv (const char *fmt, va_list ap)
283 vprintf (fmt, 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
290 static char *
291 read_stdin_line (void)
293 static char buf[MAX_LINE_LENGTH];
294 char *s;
295 int i;
297 s = fgets (buf, MAX_LINE_LENGTH, stdin);
298 if (s == NULL)
300 printf ("\n");
301 return NULL;
304 /* Strip any trailing newline characters */
305 for (i = strlen (s) - 1; i >= 0; i--)
306 if (s[i] == '\r' || s[i] == '\n')
307 s[i] = '\0';
309 if (s[0] == '\0')
310 return NULL;
312 return strdup (s);
314 #undef MAX_LINE_LENGTH
316 static int
317 nogui_confirm_dialog (char *msg, ...)
319 char *answer;
320 int ret = 0;
321 bool valid_answer = false;
322 va_list args;
326 va_start (args, msg);
327 vprintf (msg, args);
328 va_end (args);
330 printf (" ? 0=cancel 1 = ok : ");
332 answer = read_stdin_line ();
334 if (answer == NULL)
335 continue;
337 if (answer[0] == '0' && answer[1] == '\0')
339 ret = 0;
340 valid_answer = true;
343 if (answer[0] == '1' && answer[1] == '\0')
345 ret = 1;
346 valid_answer = true;
349 free (answer);
351 while (!valid_answer);
352 return ret;
355 static int
356 nogui_close_confirm_dialog ()
358 return nogui_confirm_dialog (_("OK to lose data ?"), NULL);
361 static void
362 nogui_report_dialog (char *title, char *msg)
364 printf ("--- %s ---\n%s\n", title, msg);
367 static char *
368 nogui_prompt_for (const char *msg, const char *default_string)
370 char *answer;
372 if (default_string)
373 printf ("%s [%s] : ", msg, default_string);
374 else
375 printf ("%s : ", msg);
377 answer = read_stdin_line ();
378 if (answer == NULL)
379 return strdup ((default_string != NULL) ? default_string : "");
380 else
381 return answer;
384 /* FIXME - this could use some enhancement to actually use the other
385 args */
386 static char *
387 nogui_fileselect (const char *title, const char *descr,
388 char *default_file, char *default_ext,
389 const char *history_tag, int flags)
391 char *answer;
393 if (default_file)
394 printf ("%s [%s] : ", title, default_file);
395 else
396 printf ("%s : ", title);
398 answer = read_stdin_line ();
399 if (answer == NULL)
400 return (default_file != NULL) ? strdup (default_file) : NULL;
401 else
402 return answer;
405 static int
406 nogui_attribute_dialog (HID_Attribute * attrs,
407 int n_attrs, HID_Attr_Val * results,
408 const char * title, const char * descr)
410 CRASH;
413 static void
414 nogui_show_item (void *item)
416 CRASH;
419 static void
420 nogui_beep (void)
422 putchar (7);
423 fflush (stdout);
426 static int
427 nogui_progress (int so_far, int total, const char *message)
429 return 0;
432 static HID *
433 nogui_request_debug_draw (void)
435 return NULL;
438 static void
439 nogui_flush_debug_draw (void)
443 static void
444 nogui_finish_debug_draw (void)
448 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;
486 void
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;
514 HID *
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. "
523 "Does nothing.";
524 nogui_hid.graphics = &nogui_graphics;
526 common_nogui_init (&nogui_hid);
527 common_nogui_graphics_init (&nogui_graphics);
529 return &nogui_hid;