background.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. Widgets for the Midnight Commander
  3. Copyright (C) 2020-2024
  4. The Free Software Foundation, Inc.
  5. Authors:
  6. Andrew Borodin <aborodin@vmail.ru>, 2020-2022
  7. This file is part of the Midnight Commander.
  8. The Midnight Commander is free software: you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation, either version 3 of the License,
  11. or (at your option) any later version.
  12. The Midnight Commander is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /** \file background.c
  20. * \brief Source: WBackground widget (background area of dialog)
  21. */
  22. #include <config.h>
  23. #include <stdlib.h>
  24. #include "lib/global.h"
  25. #include "lib/tty/tty.h"
  26. #include "lib/tty/color.h"
  27. #include "lib/widget.h"
  28. /*** global variables ****************************************************************************/
  29. /*** file scope macro definitions ****************************************************************/
  30. /*** file scope type declarations ****************************************************************/
  31. /*** forward declarations (file scope functions) *************************************************/
  32. /*** file scope variables ************************************************************************/
  33. /* --------------------------------------------------------------------------------------------- */
  34. /*** file scope functions ************************************************************************/
  35. /* --------------------------------------------------------------------------------------------- */
  36. static const int *
  37. background_get_colors (const Widget *w)
  38. {
  39. return &(CONST_BACKGROUND (w)->color);
  40. }
  41. /* --------------------------------------------------------------------------------------------- */
  42. static void
  43. background_adjust (WBackground *b)
  44. {
  45. Widget *w = WIDGET (b);
  46. w->rect = WIDGET (w->owner)->rect;
  47. w->pos_flags |= WPOS_KEEP_ALL;
  48. }
  49. /* --------------------------------------------------------------------------------------------- */
  50. static void
  51. background_draw (const WBackground *b)
  52. {
  53. const Widget *w = CONST_WIDGET (b);
  54. tty_setcolor (b->color);
  55. tty_fill_region (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, b->pattern);
  56. }
  57. /* --------------------------------------------------------------------------------------------- */
  58. /*** public functions ****************************************************************************/
  59. /* --------------------------------------------------------------------------------------------- */
  60. cb_ret_t
  61. background_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
  62. {
  63. WBackground *b = BACKGROUND (w);
  64. switch (msg)
  65. {
  66. case MSG_INIT:
  67. background_adjust (b);
  68. return MSG_HANDLED;
  69. case MSG_DRAW:
  70. background_draw (b);
  71. return MSG_HANDLED;
  72. default:
  73. return widget_default_callback (w, sender, msg, parm, data);
  74. }
  75. }
  76. /* --------------------------------------------------------------------------------------------- */
  77. WBackground *
  78. background_new (int y, int x, int lines, int cols, int color, unsigned char pattern,
  79. widget_cb_fn callback)
  80. {
  81. WRect r = { y, x, lines, cols };
  82. WBackground *b;
  83. Widget *w;
  84. b = g_new (WBackground, 1);
  85. w = WIDGET (b);
  86. widget_init (w, &r, callback != NULL ? callback : background_callback, NULL);
  87. w->get_colors = background_get_colors;
  88. b->color = color;
  89. b->pattern = pattern;
  90. return b;
  91. }
  92. /* --------------------------------------------------------------------------------------------- */