draw.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <draw.h>
  4. void
  5. _setdrawop(Display *d, Drawop op)
  6. {
  7. uchar *a;
  8. if(op != SoverD){
  9. a = bufimage(d, 1+1);
  10. if(a == 0)
  11. return;
  12. a[0] = 'O';
  13. a[1] = op;
  14. }
  15. }
  16. static void
  17. draw1(Image *dst, Rectangle *r, Image *src, Point *p0, Image *mask, Point *p1, Drawop op)
  18. {
  19. uchar *a;
  20. _setdrawop(dst->display, op);
  21. a = bufimage(dst->display, 1+4+4+4+4*4+2*4+2*4);
  22. if(a == 0)
  23. return;
  24. if(src == nil)
  25. src = dst->display->black;
  26. if(mask == nil)
  27. mask = dst->display->opaque;
  28. a[0] = 'd';
  29. BPLONG(a+1, dst->id);
  30. BPLONG(a+5, src->id);
  31. BPLONG(a+9, mask->id);
  32. BPLONG(a+13, r->min.x);
  33. BPLONG(a+17, r->min.y);
  34. BPLONG(a+21, r->max.x);
  35. BPLONG(a+25, r->max.y);
  36. BPLONG(a+29, p0->x);
  37. BPLONG(a+33, p0->y);
  38. BPLONG(a+37, p1->x);
  39. BPLONG(a+41, p1->y);
  40. }
  41. void
  42. draw(Image *dst, Rectangle r, Image *src, Image *mask, Point p1)
  43. {
  44. draw1(dst, &r, src, &p1, mask, &p1, SoverD);
  45. }
  46. void
  47. drawop(Image *dst, Rectangle r, Image *src, Image *mask, Point p1, Drawop op)
  48. {
  49. draw1(dst, &r, src, &p1, mask, &p1, op);
  50. }
  51. void
  52. gendraw(Image *dst, Rectangle r, Image *src, Point p0, Image *mask, Point p1)
  53. {
  54. draw1(dst, &r, src, &p0, mask, &p1, SoverD);
  55. }
  56. void
  57. gendrawop(Image *dst, Rectangle r, Image *src, Point p0, Image *mask, Point p1, Drawop op)
  58. {
  59. draw1(dst, &r, src, &p0, mask, &p1, op);
  60. }