You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include <curses.h>
  2. #include "mucurses.h"
  3. #include "cursor.h"
  4. /** @file
  5. *
  6. * MuCurses edging functions
  7. *
  8. */
  9. /**
  10. * Draw borders from single-byte characters and renditions around a
  11. * window
  12. *
  13. * @v *win window to be bordered
  14. * @v verch vertical chtype
  15. * @v horch horizontal chtype
  16. * @ret rc return status code
  17. */
  18. int box ( WINDOW *win, chtype verch, chtype horch ) {
  19. chtype corner = '+' | win->attrs; /* default corner character */
  20. return wborder( win, verch, verch, horch, horch,
  21. corner, corner, corner, corner );
  22. }
  23. /**
  24. * Draw borders from single-byte characters and renditions around a
  25. * window
  26. *
  27. * @v *win window to be bordered
  28. * @v ls left side
  29. * @v rs right side
  30. * @v ts top
  31. * @v bs bottom
  32. * @v tl top left corner
  33. * @v tr top right corner
  34. * @v bl bottom left corner
  35. * @v br bottom right corner
  36. * @ret rc return status code
  37. */
  38. int wborder ( WINDOW *win, chtype ls, chtype rs,
  39. chtype ts, chtype bs, chtype tl,
  40. chtype tr, chtype bl, chtype br ) {
  41. struct cursor_pos pos;
  42. _store_curs_pos( win, &pos );
  43. wmove(win,0,0);
  44. _wputch(win,tl,WRAP);
  45. while ( ( win->width - 1 ) - win->curs_x ) {
  46. _wputch(win,ts,WRAP);
  47. }
  48. _wputch(win,tr,WRAP);
  49. while ( ( win->height - 1 ) - win->curs_y ) {
  50. _wputch(win,ls,WRAP);
  51. wmove(win,win->curs_y,(win->width)-1);
  52. _wputch(win,rs,WRAP);
  53. }
  54. _wputch(win,bl,WRAP);
  55. while ( ( win->width -1 ) - win->curs_x ) {
  56. _wputch(win,bs,WRAP);
  57. }
  58. _wputch(win,br,NOWRAP); /* do not wrap last char to leave
  59. cursor in last position */
  60. _restore_curs_pos( win, &pos );
  61. return OK;
  62. }
  63. /**
  64. * Create a horizontal line in a window
  65. *
  66. * @v *win subject window
  67. * @v ch rendition and character
  68. * @v n max number of chars (wide) to render
  69. * @ret rc return status code
  70. */
  71. int whline ( WINDOW *win, chtype ch, int n ) {
  72. struct cursor_pos pos;
  73. _store_curs_pos ( win, &pos );
  74. while ( ( win->curs_x - win->width ) && n-- ) {
  75. _wputch ( win, ch, NOWRAP );
  76. }
  77. _restore_curs_pos ( win, &pos );
  78. return OK;
  79. }
  80. /**
  81. * Create a vertical line in a window
  82. *
  83. * @v *win subject window
  84. * @v ch rendition and character
  85. * @v n max number of chars (high) to render
  86. * @ret rc return status code
  87. */
  88. int wvline ( WINDOW *win, chtype ch, int n ) {
  89. struct cursor_pos pos;
  90. _store_curs_pos ( win, &pos );
  91. while ( ( win->curs_y - win->height ) && n-- ) {
  92. _wputch ( win, ch, NOWRAP );
  93. wmove( win, ++(win->curs_y), pos.x);
  94. }
  95. _restore_curs_pos ( win, &pos );
  96. return OK;
  97. }