1 /**************************************************************************
2 **
3 ** sngrep - SIP Messages flow viewer
4 **
5 ** Copyright (C) 2013-2018 Ivan Alonso (Kaian)
6 ** Copyright (C) 2013-2018 Irontec SL. All rights reserved.
7 **
8 ** This program is free software: you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation, either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
20 **
21 ****************************************************************************/
22 /**
23 * @file scrollbar.c
24 * @author Ivan Alonso [aka Kaian] <kaian@irontec.com>
25 *
26 * @brief Source of functions defined in scrollbar.h
27 */
28
29 #include "config.h"
30 #include "scrollbar.h"
31
32 scrollbar_t
ui_set_scrollbar(WINDOW * win,int alignment,int dock)33 ui_set_scrollbar(WINDOW *win, int alignment, int dock)
34 {
35 scrollbar_t sb;
36 sb.win = win;
37 sb.alignment = alignment;
38 sb.dock = dock;
39 return sb;
40 }
41
42
43 void
ui_scrollbar_draw(scrollbar_t sb)44 ui_scrollbar_draw(scrollbar_t sb)
45 {
46 int height, width, cline, scrollen, scrollypos, scrollxpos;
47
48 // Get window available space
49 getmaxyx(sb.win, height, width);
50
51 // If no even a screen has been filled, don't draw it
52 if (sb.max < height)
53 return;
54
55 // Display the scrollbar left or right
56 scrollxpos = (sb.dock == SB_LEFT) ? 0 : width - 1;
57
58 // Initialize scrollbar line
59 mvwvline(sb.win, 0, scrollxpos, ACS_VLINE, height);
60
61 // How long the scroll will be
62 if (!(scrollen = (height * 1.0f / sb.max * height) + 0.5))
63 scrollen = 1;
64
65 // Where will the scroll start
66 scrollypos = height * (sb.pos * 1.0f / sb.max);
67
68 // Draw the N blocks of the scrollbar
69 for (cline = 0; cline < scrollen; cline++) {
70 mvwaddch(sb.win, cline + scrollypos, scrollxpos, ACS_CKBOARD);
71 }
72
73 }
74