draw.h 919 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #include "wmfs.h"
  10. #define TEXTY(t, w) ((t->font.height - t->font.de) + ((w - t->font.height) >> 1))
  11. #define PAD (8)
  12. static inline void
  13. draw_text(Drawable d, struct theme *t, int x, int y, Color fg, const char *str)
  14. {
  15. XSetForeground(W->dpy, W->gc, fg);
  16. XmbDrawString(W->dpy, d, t->font.fontset, W->gc, x, y, str, strlen(str));
  17. }
  18. static inline void
  19. draw_rect(Drawable d, struct geo g, Color bg)
  20. {
  21. XSetForeground(W->dpy, W->gc, bg);
  22. XFillRectangle(W->dpy, d, W->gc, g.x, g.y, g.w, g.h);
  23. }
  24. static inline unsigned short
  25. draw_textw(struct theme *t, const char *str)
  26. {
  27. XRectangle r;
  28. XmbTextExtents(t->font.fontset, str, strlen(str), NULL, &r);
  29. return r.width;
  30. }
  31. #endif /* DRAW_H */