Add support for filling / thindrawing raw polygons to the HID interface
[geda-pcb/gde.git] / src / hid / common / hidnogui.c
blob57509dcd0558bdd03aa26bac62e26f51e4737621
1 /* $Id$ */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdarg.h>
9 #include <stdlib.h>
10 #include <string.h>
12 #include "global.h"
13 #include "hid.h"
15 #ifdef HAVE_LIBDMALLOC
16 #include <dmalloc.h>
17 #endif
19 RCSID ("$Id$");
21 /* This is the "gui" that is installed at startup, and is used when
22 there is no other real GUI to use. For the most part, it just
23 stops the application from (1) crashing randomly, and (2) doing
24 gui-specific things when it shouldn't. */
26 #define CRASH fprintf(stderr, "HID error: pcb called GUI function %s without having a GUI available.\n", __FUNCTION__); abort()
28 typedef struct hid_gc_struct
30 int nothing_interesting_here;
31 } hid_gc_struct;
33 static HID_Attribute *
34 nogui_get_export_options (int *n_ret)
36 CRASH;
37 return 0;
40 static void
41 nogui_do_export (HID_Attr_Val * options)
43 CRASH;
46 static void
47 nogui_parse_arguments (int *argc, char ***argv)
49 CRASH;
52 static void
53 nogui_invalidate_wh (int x, int y, int width, int height, int last)
55 CRASH;
58 static void
59 nogui_invalidate_lr (int l, int r, int t, int b, int last)
61 CRASH;
64 static void
65 nogui_invalidate_all (void)
67 CRASH;
70 static int
71 nogui_set_layer (const char *name, int idx, int empty)
73 CRASH;
74 return 0;
77 static hidGC
78 nogui_make_gc (void)
80 return 0;
83 static void
84 nogui_destroy_gc (hidGC gc)
88 static void
89 nogui_use_mask (int use_it)
91 CRASH;
94 static void
95 nogui_set_color (hidGC gc, const char *name)
97 CRASH;
100 static void
101 nogui_set_line_cap (hidGC gc, EndCapStyle style)
103 CRASH;
106 static void
107 nogui_set_line_width (hidGC gc, int width)
109 CRASH;
112 static void
113 nogui_set_draw_xor (hidGC gc, int xor)
115 CRASH;
118 static void
119 nogui_set_draw_faded (hidGC gc, int faded)
121 CRASH;
124 static void
125 nogui_set_line_cap_angle (hidGC gc, int x1, int y1, int x2, int y2)
127 CRASH;
130 static void
131 nogui_draw_line (hidGC gc, int x1, int y1, int x2, int y2)
133 CRASH;
136 static void
137 nogui_draw_arc (hidGC gc, int cx, int cy, int width, int height,
138 int start_angle, int end_angle)
140 CRASH;
143 static void
144 nogui_draw_rect (hidGC gc, int x1, int y1, int x2, int y2)
146 CRASH;
149 static void
150 nogui_fill_circle (hidGC gc, int cx, int cy, int radius)
152 CRASH;
155 static void
156 nogui_fill_polygon (hidGC gc, int n_coords, int *x, int *y)
158 CRASH;
161 static void
162 nogui_fill_pcb_polygon (hidGC gc, PolygonType *poly, const BoxType *clip_box)
164 CRASH;
167 static void
168 nogui_fill_rect (hidGC gc, int x1, int y1, int x2, int y2)
170 CRASH;
173 static void
174 nogui_calibrate (double xval, double yval)
176 CRASH;
179 static int
180 nogui_shift_is_pressed (void)
182 /* This is called from FitCrosshairIntoGrid() when the board is loaded. */
183 return 0;
186 static int
187 nogui_control_is_pressed (void)
189 CRASH;
190 return 0;
193 static void
194 nogui_get_coords (const char *msg, int *x, int *y)
196 CRASH;
199 static void
200 nogui_set_crosshair (int x, int y, int action)
204 static hidval
205 nogui_add_timer (void (*func) (hidval user_data),
206 unsigned long milliseconds, hidval user_data)
208 hidval rv;
209 CRASH;
210 rv.lval = 0;
211 return rv;
214 static void
215 nogui_stop_timer (hidval timer)
217 CRASH;
220 static hidval
221 nogui_watch_file (int fd, unsigned int condition, void (*func) (hidval watch, int fd, unsigned int condition, hidval user_data),
222 hidval user_data)
224 hidval rv;
225 CRASH;
226 rv.lval = 0;
227 return rv;
230 static void
231 nogui_unwatch_file (hidval watch)
233 CRASH;
236 static hidval
237 nogui_add_block_hook (void (*func) (hidval data), hidval data)
239 hidval rv;
240 CRASH;
241 rv.ptr = NULL;
242 return rv;
245 static void
246 nogui_stop_block_hook (hidval block_hook)
248 CRASH;
251 static void
252 nogui_log (const char *fmt, ...)
254 va_list ap;
255 va_start (ap, fmt);
256 vprintf (fmt, ap);
257 va_end (ap);
260 static void
261 nogui_logv (const char *fmt, va_list ap)
263 vprintf (fmt, ap);
266 static int
267 nogui_confirm_dialog (char *msg, ...)
269 int rv;
270 printf ("%s ? 0=cancel 1=ok : ", msg);
271 fflush (stdout);
272 scanf ("%d", &rv);
273 return rv;
276 static int
277 nogui_close_confirm_dialog ()
279 return nogui_confirm_dialog (_("OK to lose data ?"), NULL);
282 static void
283 nogui_report_dialog (char *title, char *msg)
285 printf ("--- %s ---\n%s\n", title, msg);
288 static char *
289 nogui_prompt_for (char *msg, char *default_string)
291 static char buf[1024];
292 if (default_string)
293 printf ("%s [%s] : ", msg, default_string);
294 else
295 printf ("%s : ", msg);
296 fgets (buf, 1024, stdin);
297 if (buf[0] == 0 && default_string)
298 strcpy (buf, default_string);
299 return buf;
302 /* FIXME - this could use some enhancement to actually use the other
303 args */
304 static char *
305 nogui_fileselect (const char *title, const char *descr,
306 char *default_file, char *default_ext,
307 const char *history_tag, int flags)
309 static char buf[1024];
310 if (default_file)
311 printf ("%s [%s] : ", title, default_file);
312 else
313 printf ("%s : ", title);
314 fgets (buf, 1024, stdin);
315 if (buf[0] == 0 && default_file)
316 strcpy (buf, default_file);
317 return buf;
320 static int
321 nogui_attribute_dialog (HID_Attribute * attrs,
322 int n_attrs, HID_Attr_Val * results,
323 const char * title, const char * descr)
325 CRASH;
328 static void
329 nogui_show_item (void *item)
331 CRASH;
334 static void
335 nogui_beep (void)
337 putchar (7);
338 fflush (stdout);
341 static int
342 nogui_progress (int so_far, int total, const char *message)
344 return 0;
347 HID hid_nogui = {
348 sizeof (HID),
349 "nogui",
350 "Default GUI when no other GUI is present. Does nothing.",
351 0, 0, 0, 0, 0, 0,
352 nogui_get_export_options,
353 nogui_do_export,
354 nogui_parse_arguments,
355 nogui_invalidate_wh,
356 nogui_invalidate_lr,
357 nogui_invalidate_all,
358 nogui_set_layer,
359 nogui_make_gc,
360 nogui_destroy_gc,
361 nogui_use_mask,
362 nogui_set_color,
363 nogui_set_line_cap,
364 nogui_set_line_width,
365 nogui_set_draw_xor,
366 nogui_set_draw_faded,
367 nogui_set_line_cap_angle,
368 nogui_draw_line,
369 nogui_draw_arc,
370 nogui_draw_rect,
371 nogui_fill_circle,
372 nogui_fill_polygon,
373 nogui_fill_pcb_polygon,
374 0 /* nogui_thindraw_pcb_polygon */ ,
375 nogui_fill_rect,
376 nogui_calibrate,
377 nogui_shift_is_pressed,
378 nogui_control_is_pressed,
379 nogui_get_coords,
380 nogui_set_crosshair,
381 nogui_add_timer,
382 nogui_stop_timer,
383 nogui_watch_file,
384 nogui_unwatch_file,
385 nogui_add_block_hook,
386 nogui_stop_block_hook,
387 nogui_log,
388 nogui_logv,
389 nogui_confirm_dialog,
390 nogui_close_confirm_dialog,
391 nogui_report_dialog,
392 nogui_prompt_for,
393 nogui_fileselect,
394 nogui_attribute_dialog,
395 nogui_show_item,
396 nogui_beep,
397 nogui_progress
400 #define AD(x) if (!d->x) d->x = s->x
402 void
403 apply_default_hid (HID * d, HID * s)
405 if (s == 0)
406 s = &hid_nogui;
407 AD (get_export_options);
408 AD (do_export);
409 AD (parse_arguments);
410 AD (invalidate_wh);
411 AD (invalidate_lr);
412 AD (invalidate_all);
413 AD (set_layer);
414 AD (make_gc);
415 AD (destroy_gc);
416 AD (use_mask);
417 AD (set_color);
418 AD (set_line_cap);
419 AD (set_line_width);
420 AD (set_draw_xor);
421 AD (set_line_cap_angle);
422 AD (draw_line);
423 AD (draw_arc);
424 AD (fill_circle);
425 AD (fill_polygon);
426 AD (fill_pcb_polygon);
427 AD (thindraw_pcb_polygon);
428 AD (calibrate);
429 AD (shift_is_pressed);
430 AD (control_is_pressed);
431 AD (get_coords);
432 AD (set_crosshair);
433 AD (add_timer);
434 AD (stop_timer);
435 AD (watch_file);
436 AD (unwatch_file);
437 AD (add_block_hook);
438 AD (stop_block_hook);
439 AD (log);
440 AD (logv);
441 AD (confirm_dialog);
442 AD (close_confirm_dialog);
443 AD (report_dialog);
444 AD (prompt_for);
445 AD (fileselect);
446 AD (attribute_dialog);
447 AD (show_item);
448 AD (beep);
449 AD (progress);