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.

edging.c 2.4KB

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