touch.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* PDCurses */
  2. #include <curspriv.h>
  3. /*man-start**************************************************************
  4. touch
  5. -----
  6. ### Synopsis
  7. int touchwin(WINDOW *win);
  8. int touchline(WINDOW *win, int start, int count);
  9. int untouchwin(WINDOW *win);
  10. int wtouchln(WINDOW *win, int y, int n, int changed);
  11. bool is_linetouched(WINDOW *win, int line);
  12. bool is_wintouched(WINDOW *win);
  13. int touchoverlap(const WINDOW *win1, WINDOW *win2);
  14. ### Description
  15. touchwin() and touchline() throw away all information about which
  16. parts of the window have been touched, pretending that the entire
  17. window has been drawn on. This is sometimes necessary when using
  18. overlapping windows, since a change to one window will affect the
  19. other window, but the records of which lines have been changed in the
  20. other window will not reflect the change.
  21. untouchwin() marks all lines in the window as unchanged since the
  22. last call to wrefresh().
  23. wtouchln() makes n lines in the window, starting at line y, look as
  24. if they have (changed == 1) or have not (changed == 0) been changed
  25. since the last call to wrefresh().
  26. is_linetouched() returns TRUE if the specified line in the specified
  27. window has been changed since the last call to wrefresh().
  28. is_wintouched() returns TRUE if the specified window has been changed
  29. since the last call to wrefresh().
  30. touchoverlap(win1, win2) marks the portion of win2 which overlaps
  31. with win1 as modified.
  32. ### Return Value
  33. All functions return OK on success and ERR on error except
  34. is_wintouched() and is_linetouched().
  35. ### Portability
  36. X/Open ncurses NetBSD
  37. touchwin Y Y Y
  38. touchline Y Y Y
  39. untouchwin Y Y Y
  40. wtouchln Y Y Y
  41. is_linetouched Y Y Y
  42. is_wintouched Y Y Y
  43. touchoverlap - - Y
  44. **man-end****************************************************************/
  45. int touchwin(WINDOW *win)
  46. {
  47. int i;
  48. PDC_LOG(("touchwin() - called: Win=%x\n", win));
  49. if (!win)
  50. return ERR;
  51. for (i = 0; i < win->_maxy; i++)
  52. {
  53. win->_firstch[i] = 0;
  54. win->_lastch[i] = win->_maxx - 1;
  55. }
  56. return OK;
  57. }
  58. int touchline(WINDOW *win, int start, int count)
  59. {
  60. int i;
  61. PDC_LOG(("touchline() - called: win=%p start %d count %d\n",
  62. win, start, count));
  63. if (!win || start > win->_maxy || start + count > win->_maxy)
  64. return ERR;
  65. for (i = start; i < start + count; i++)
  66. {
  67. win->_firstch[i] = 0;
  68. win->_lastch[i] = win->_maxx - 1;
  69. }
  70. return OK;
  71. }
  72. int untouchwin(WINDOW *win)
  73. {
  74. int i;
  75. PDC_LOG(("untouchwin() - called: win=%p", win));
  76. if (!win)
  77. return ERR;
  78. for (i = 0; i < win->_maxy; i++)
  79. {
  80. win->_firstch[i] = _NO_CHANGE;
  81. win->_lastch[i] = _NO_CHANGE;
  82. }
  83. return OK;
  84. }
  85. int wtouchln(WINDOW *win, int y, int n, int changed)
  86. {
  87. int i;
  88. PDC_LOG(("wtouchln() - called: win=%p y=%d n=%d changed=%d\n",
  89. win, y, n, changed));
  90. if (!win || y > win->_maxy || y + n > win->_maxy)
  91. return ERR;
  92. for (i = y; i < y + n; i++)
  93. {
  94. if (changed)
  95. {
  96. win->_firstch[i] = 0;
  97. win->_lastch[i] = win->_maxx - 1;
  98. }
  99. else
  100. {
  101. win->_firstch[i] = _NO_CHANGE;
  102. win->_lastch[i] = _NO_CHANGE;
  103. }
  104. }
  105. return OK;
  106. }
  107. bool is_linetouched(WINDOW *win, int line)
  108. {
  109. PDC_LOG(("is_linetouched() - called: win=%p line=%d\n", win, line));
  110. if (!win || line > win->_maxy || line < 0)
  111. return FALSE;
  112. return (win->_firstch[line] != _NO_CHANGE) ? TRUE : FALSE;
  113. }
  114. bool is_wintouched(WINDOW *win)
  115. {
  116. int i;
  117. PDC_LOG(("is_wintouched() - called: win=%p\n", win));
  118. if (win)
  119. for (i = 0; i < win->_maxy; i++)
  120. if (win->_firstch[i] != _NO_CHANGE)
  121. return TRUE;
  122. return FALSE;
  123. }
  124. int touchoverlap(const WINDOW *win1, WINDOW *win2)
  125. {
  126. int y, endy, endx, starty, startx;
  127. PDC_LOG(("touchoverlap() - called: win1=%p win2=%p\n", win1, win2));
  128. if (!win1 || !win2)
  129. return ERR;
  130. starty = max(win1->_begy, win2->_begy);
  131. startx = max(win1->_begx, win2->_begx);
  132. endy = min(win1->_maxy + win1->_begy, win2->_maxy + win2->_begy);
  133. endx = min(win1->_maxx + win1->_begx, win2->_maxx + win2->_begx);
  134. if (starty >= endy || startx >= endx)
  135. return OK;
  136. starty -= win2->_begy;
  137. startx -= win2->_begx;
  138. endy -= win2->_begy;
  139. endx -= win2->_begx;
  140. endx -= 1;
  141. for (y = starty; y < endy; y++)
  142. {
  143. win2->_firstch[y] = startx;
  144. win2->_lastch[y] = endx;
  145. }
  146. return OK;
  147. }