draw.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. static inline void
  31. draw_image(Drawable d, struct geo *g, char *path)
  32. {
  33. Imlib_Image image = imlib_load_image(path);
  34. imlib_context_set_drawable(d);
  35. imlib_context_set_image(image);
  36. imlib_render_image_on_drawable_at_size(g->x, g->y, g->w, g->h);
  37. imlib_free_image();
  38. }
  39. static inline void
  40. draw_image_get_size(char *path, int *w, int *h)
  41. {
  42. Imlib_Image image = imlib_load_image(path);
  43. imlib_context_set_image(image);
  44. *w = imlib_image_get_width();
  45. *h = imlib_image_get_height();
  46. imlib_free_image();
  47. }
  48. #endif /* HAVE_IMLIB2 */
  49. /*
  50. * For client use
  51. */
  52. static inline void
  53. draw_reversed_rect(Drawable dr, struct client *c, bool t)
  54. {
  55. struct geo *g = (t ? &c->tgeo : &c->geo);
  56. struct geo *ug = &c->screen->ugeo;
  57. int i = c->theme->client_border_width;
  58. XDrawRectangle(W->dpy, dr, W->rgc,
  59. ug->x + g->x + i,
  60. ug->y + g->y + i,
  61. g->w - (i << 1),
  62. g->h - (i << 1));
  63. }
  64. static inline void
  65. draw_reversed_cross(Drawable dr, struct geo *g)
  66. {
  67. int x = g->x + W->screen->ugeo.x;
  68. int y = g->y + W->screen->ugeo.y;
  69. XDrawLine(W->dpy, dr, W->rgc,
  70. x, y, x + g->w, y + g->h);
  71. XDrawLine(W->dpy, dr, W->rgc,
  72. x + g->w, y, x, y + g->h);
  73. }
  74. static inline unsigned short
  75. draw_textw(struct theme *t, const char *str)
  76. {
  77. XRectangle r;
  78. XmbTextExtents(t->font.fontset, str, strlen(str), NULL, &r);
  79. return r.width;
  80. }
  81. #endif /* DRAW_H */