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-2022
   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 /*** file scope variables ************************************************************************/
  46 
  47 /* --------------------------------------------------------------------------------------------- */
  48 /*** file scope functions ************************************************************************/
  49 /* --------------------------------------------------------------------------------------------- */
  50 
  51 static const int *
  52 background_get_colors (const Widget * w)
     /* [previous][next][first][last][top][bottom][index][help]  */
  53 {
  54     return &(CONST_BACKGROUND (w)->color);
  55 }
  56 
  57 /* --------------------------------------------------------------------------------------------- */
  58 
  59 static void
  60 background_adjust (WBackground * b)
     /* [previous][next][first][last][top][bottom][index][help]  */
  61 {
  62     Widget *w = WIDGET (b);
  63 
  64     w->rect = WIDGET (w->owner)->rect;
  65     w->pos_flags |= WPOS_KEEP_ALL;
  66 }
  67 
  68 /* --------------------------------------------------------------------------------------------- */
  69 
  70 static void
  71 background_draw (const WBackground * b)
     /* [previous][next][first][last][top][bottom][index][help]  */
  72 {
  73     const Widget *w = CONST_WIDGET (b);
  74 
  75     tty_setcolor (b->color);
  76     tty_fill_region (w->rect.y, w->rect.x, w->rect.lines, w->rect.cols, b->pattern);
  77 }
  78 
  79 /* --------------------------------------------------------------------------------------------- */
  80 /*** public functions ****************************************************************************/
  81 /* --------------------------------------------------------------------------------------------- */
  82 
  83 cb_ret_t
  84 background_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  85 {
  86     WBackground *b = BACKGROUND (w);
  87 
  88     switch (msg)
  89     {
  90     case MSG_INIT:
  91         background_adjust (b);
  92         return MSG_HANDLED;
  93 
  94     case MSG_DRAW:
  95         background_draw (b);
  96         return MSG_HANDLED;
  97 
  98     default:
  99         return widget_default_callback (w, sender, msg, parm, data);
 100     }
 101 }
 102 
 103 /* --------------------------------------------------------------------------------------------- */
 104 
 105 WBackground *
 106 background_new (int y, int x, int lines, int cols, int color, unsigned char pattern,
     /* [previous][next][first][last][top][bottom][index][help]  */
 107                 widget_cb_fn callback)
 108 {
 109     WRect r = { y, x, lines, cols };
 110     WBackground *b;
 111     Widget *w;
 112 
 113     b = g_new (WBackground, 1);
 114     w = WIDGET (b);
 115     widget_init (w, &r, callback != NULL ? callback : background_callback, NULL);
 116     w->get_colors = background_get_colors;
 117 
 118     b->color = color;
 119     b->pattern = pattern;
 120 
 121     return b;
 122 }
 123 
 124 /* --------------------------------------------------------------------------------------------- */

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