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
   5    The Free Software Foundation, Inc.
   6 
   7    Authors:
   8    Andrew Borodin <aborodin@vmail.ru>, 2020
   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     Widget *wo = WIDGET (w->owner);
  64 
  65     w->y = wo->y;
  66     w->x = wo->x;
  67     w->lines = wo->lines;
  68     w->cols = wo->cols;
  69 
  70     w->pos_flags |= WPOS_KEEP_ALL;
  71 }
  72 
  73 /* --------------------------------------------------------------------------------------------- */
  74 
  75 static void
  76 background_draw (const WBackground * b)
     /* [previous][next][first][last][top][bottom][index][help]  */
  77 {
  78     const Widget *w = CONST_WIDGET (b);
  79 
  80     tty_setcolor (b->color);
  81     tty_fill_region (w->y, w->x, w->lines, w->cols, b->pattern);
  82 }
  83 
  84 /* --------------------------------------------------------------------------------------------- */
  85 /*** public functions ****************************************************************************/
  86 /* --------------------------------------------------------------------------------------------- */
  87 
  88 cb_ret_t
  89 background_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  90 {
  91     WBackground *b = BACKGROUND (w);
  92 
  93     switch (msg)
  94     {
  95     case MSG_INIT:
  96         background_adjust (b);
  97         return MSG_HANDLED;
  98 
  99     case MSG_DRAW:
 100         background_draw (b);
 101         return MSG_HANDLED;
 102 
 103     default:
 104         return widget_default_callback (w, sender, msg, parm, data);
 105     }
 106 }
 107 
 108 /* --------------------------------------------------------------------------------------------- */
 109 
 110 WBackground *
 111 background_new (int y, int x, int lines, int cols, int color, unsigned char pattern,
     /* [previous][next][first][last][top][bottom][index][help]  */
 112                 widget_cb_fn callback)
 113 {
 114     WBackground *b;
 115     Widget *w;
 116 
 117     b = g_new (WBackground, 1);
 118     w = WIDGET (b);
 119     widget_init (w, y, x, lines, cols, callback != NULL ? callback : background_callback, NULL);
 120     w->get_colors = background_get_colors;
 121 
 122     b->color = color;
 123     b->pattern = pattern;
 124 
 125     return b;
 126 }
 127 
 128 /* --------------------------------------------------------------------------------------------- */

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