draw.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * wmfs2 by Martin Duquesnoy <xorg62@gmail.com> { for(i = 2011; i < 2111; ++i) ©(i); }
  3. * For license, see COPYING.
  4. */
  5. #ifndef DRAW_H
  6. #define DRAW_H
  7. #include <string.h>
  8. #include <X11/Xlib.h>
  9. #ifdef HAVE_IMLIB2
  10. #include <Imlib2.h>
  11. #endif /* HAVE_IMLIB2 */
  12. #include "wmfs.h"
  13. #include "config.h"
  14. #include "screen.h"
  15. #define TEXTY(t, w) ((t->font.height - t->font.de) + ((w - t->font.height) >> 1))
  16. #define PAD (8)
  17. static inline void
  18. draw_text(Drawable d, struct theme *t, int x, int y, Color fg, const char *str)
  19. {
  20. XSetForeground(W->dpy, W->gc, fg);
  21. XmbDrawString(W->dpy, d, t->font.fontset, W->gc, x, y, str, strlen(str));
  22. }
  23. static inline void
  24. draw_rect(Drawable d, struct geo *g, Color bg)
  25. {
  26. XSetForeground(W->dpy, W->gc, bg);
  27. XFillRectangle(W->dpy, d, W->gc, g->x, g->y, g->w, g->h);
  28. }
  29. #ifdef HAVE_IMLIB2
  30. /*
  31. * Draw image on drawable with g geo
  32. * Require that the image was loaded with draw_image_load()
  33. */
  34. static inline void
  35. draw_image(Drawable d, struct geo *g)
  36. {
  37. imlib_context_set_drawable(d);
  38. imlib_render_image_on_drawable_at_size(g->x, g->y, g->w, g->h);
  39. imlib_free_image();
  40. }
  41. /*
  42. * Load image, set it in imlib context, and return
  43. * width & height as argument 2 & 3
  44. */
  45. static inline void
  46. draw_image_load(char *path, int *w, int *h)
  47. {
  48. Imlib_Image image = imlib_load_image(path);
  49. imlib_context_set_image(image);
  50. *w = imlib_image_get_width();
  51. *h = imlib_image_get_height();
  52. }
  53. #endif /* HAVE_IMLIB2 */
  54. /*
  55. * For client use
  56. */
  57. static inline void
  58. draw_reversed_rect(Drawable dr, struct client *c, bool t)
  59. {
  60. struct geo *g = (t ? &c->tgeo : &c->geo);
  61. struct geo *ug = &c->screen->ugeo;
  62. int i = c->theme->client_border_width;
  63. if(c->flags & CLIENT_FREE)
  64. {
  65. XDrawRectangle(W->dpy, dr, W->rgc,
  66. ug->x + g->x + i,
  67. ug->y + g->y + i,
  68. g->w - (i << 1),
  69. g->h - (i << 1));
  70. }
  71. else
  72. {
  73. XDrawRectangle(W->dpy, dr, W->rgc,
  74. ug->x + g->x + i + (W->padding >> 2),
  75. ug->y + g->y + i + (W->padding >> 2),
  76. g->w - (i << 1) - (W->padding >> 1),
  77. g->h - (i << 1) - (W->padding >> 1));
  78. }
  79. }
  80. static inline void
  81. draw_line(Drawable d, int x1, int y1, int x2, int y2)
  82. {
  83. XDrawLine(W->dpy, d, W->gc, x1, y1, x2, y2);
  84. }
  85. static inline unsigned short
  86. draw_textw(struct theme *t, const char *str)
  87. {
  88. XRectangle r;
  89. XmbTextExtents(t->font.fontset, str, strlen(str), NULL, &r);
  90. return r.width;
  91. }
  92. #endif /* DRAW_H */