draw.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <draw.h>
  12. void
  13. _setdrawop(Display *d, Drawop op)
  14. {
  15. uint8_t *a;
  16. if(op != SoverD){
  17. a = bufimage(d, 1+1);
  18. if(a == 0)
  19. return;
  20. a[0] = 'O';
  21. a[1] = op;
  22. }
  23. }
  24. static void
  25. draw1(Image *dst, Rectangle *r, Image *src, Point *p0, Image *mask, Point *p1, Drawop op)
  26. {
  27. uint8_t *a;
  28. _setdrawop(dst->display, op);
  29. a = bufimage(dst->display, 1+4+4+4+4*4+2*4+2*4);
  30. if(a == 0)
  31. return;
  32. if(src == nil)
  33. src = dst->display->black;
  34. if(mask == nil)
  35. mask = dst->display->opaque;
  36. a[0] = 'd';
  37. BPLONG(a+1, dst->id);
  38. BPLONG(a+5, src->id);
  39. BPLONG(a+9, mask->id);
  40. BPLONG(a+13, r->min.x);
  41. BPLONG(a+17, r->min.y);
  42. BPLONG(a+21, r->max.x);
  43. BPLONG(a+25, r->max.y);
  44. BPLONG(a+29, p0->x);
  45. BPLONG(a+33, p0->y);
  46. BPLONG(a+37, p1->x);
  47. BPLONG(a+41, p1->y);
  48. }
  49. void
  50. draw(Image *dst, Rectangle r, Image *src, Image *mask, Point p1)
  51. {
  52. draw1(dst, &r, src, &p1, mask, &p1, SoverD);
  53. }
  54. void
  55. drawop(Image *dst, Rectangle r, Image *src, Image *mask, Point p1, Drawop op)
  56. {
  57. draw1(dst, &r, src, &p1, mask, &p1, op);
  58. }
  59. void
  60. gendraw(Image *dst, Rectangle r, Image *src, Point p0, Image *mask, Point p1)
  61. {
  62. draw1(dst, &r, src, &p0, mask, &p1, SoverD);
  63. }
  64. void
  65. gendrawop(Image *dst, Rectangle r, Image *src, Point p0, Image *mask, Point p1, Drawop op)
  66. {
  67. draw1(dst, &r, src, &p0, mask, &p1, op);
  68. }