root/lib/widget/background.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. background_get_colors
  2. background_adjust
  3. background_draw
  4. background_callback
  5. background_new

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

/* [previous][next][first][last][top][bottom][index][help]  */