gui_util.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * gui_util.h - GUI helper functions
  3. *
  4. * Written 2009, 2010 by Werner Almesberger
  5. * Copyright 2009, 2010 by Werner Almesberger
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #ifndef GUI_UTIL_H
  13. #define GUI_UTIL_H
  14. #include <gtk/gtk.h>
  15. #include "coord.h"
  16. struct draw_ctx {
  17. GtkWidget *widget;
  18. int scale;
  19. struct coord center;
  20. };
  21. struct pix_buf {
  22. GdkDrawable *da;
  23. int x, y;
  24. GdkPixbuf *buf;
  25. };
  26. extern struct draw_ctx draw_ctx;
  27. #define DA GDK_DRAWABLE(draw_ctx.widget->window)
  28. GdkColor get_color(const char *spec);
  29. void set_width(GdkGC *gc, int width);
  30. void free_pix_buf(struct pix_buf *buf);
  31. struct pix_buf *save_pix_buf(GdkDrawable *da, int xa, int ya, int xb, int yb,
  32. int border);
  33. void restore_pix_buf(struct pix_buf *buf);
  34. void draw_arc(GdkDrawable *da, GdkGC *gc, int fill,
  35. int x, int y, int r, double a1, double a2);
  36. void draw_circle(GdkDrawable *da, GdkGC *gc, int fill,
  37. int x, int y, int r);
  38. /* tooltips are optional (use NULL for none) */
  39. GtkWidget *label_in_box_new(const char *s, const char *tooltip);
  40. GtkWidget *box_of_label(GtkWidget *label);
  41. void label_in_box_fg(GtkWidget *box, const char *color);
  42. void label_in_box_bg(GtkWidget *box, const char *color);
  43. void vacate_widget(GtkWidget *widget);
  44. GtkWidget *make_image(GdkDrawable *drawable, char **xpm, const char *tooltip);
  45. GtkWidget *make_transparent_image(GdkDrawable *drawable, char **xpm,
  46. const char *tooltip);
  47. void set_image(GtkWidget *widget, GtkWidget *image);
  48. GtkWidget *tool_button(GtkWidget *bar, GdkDrawable *drawable,
  49. char **xpm, const char *tooltip,
  50. gboolean (*cb)(GtkWidget *widget, GdkEventButton *event, gpointer data),
  51. gpointer data);
  52. void render_text(GdkDrawable *da, GdkGC *gc, int x, int y, double angle,
  53. const char *s, const char *font, double xalign, double yalign,
  54. int xmax, int ymax);
  55. void debug_save_pixbuf(GdkPixbuf *buf);
  56. void debug_save_widget(GtkWidget *widget);
  57. void destroy_all_children(GtkContainer *container);
  58. int get_widget_width(GtkWidget *widget);
  59. #endif /* !GUI_UTIL_H */