ltofront.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include <memdraw.h>
  13. #include <memlayer.h>
  14. /*
  15. * Pull i towards top of screen, just behind front
  16. */
  17. static
  18. void
  19. _memltofront(Memimage *i, Memimage *front, int fill)
  20. {
  21. Memlayer *l;
  22. Memscreen *s;
  23. Memimage *f, *ff, *rr;
  24. Rectangle x;
  25. int overlap;
  26. l = i->layer;
  27. s = l->screen;
  28. while(l->front != front){
  29. f = l->front;
  30. x = l->screenr;
  31. overlap = rectclip(&x, f->layer->screenr);
  32. if(overlap){
  33. memlhide(f, x);
  34. f->layer->clear = 0;
  35. }
  36. /* swap l and f in screen's list */
  37. ff = f->layer->front;
  38. rr = l->rear;
  39. if(ff == nil)
  40. s->frontmost = i;
  41. else
  42. ff->layer->rear = i;
  43. if(rr == nil)
  44. s->rearmost = f;
  45. else
  46. rr->layer->front = f;
  47. l->front = ff;
  48. l->rear = f;
  49. f->layer->front = i;
  50. f->layer->rear = rr;
  51. if(overlap && fill)
  52. memlexpose(i, x);
  53. }
  54. }
  55. void
  56. _memltofrontfill(Memimage *i, int fill)
  57. {
  58. _memltofront(i, nil, fill);
  59. _memlsetclear(i->layer->screen);
  60. }
  61. void
  62. memltofront(Memimage *i)
  63. {
  64. _memltofront(i, nil, 1);
  65. _memlsetclear(i->layer->screen);
  66. }
  67. void
  68. memltofrontn(Memimage **ip, int n)
  69. {
  70. Memimage *i, *front;
  71. Memscreen *s;
  72. if(n == 0)
  73. return;
  74. front = nil;
  75. while(--n >= 0){
  76. i = *ip++;
  77. _memltofront(i, front, 1);
  78. front = i;
  79. }
  80. s = front->layer->screen;
  81. _memlsetclear(s);
  82. }