1 /*
2  * Schism Tracker - a cross-platform Impulse Tracker clone
3  * copyright (c) 2003-2005 Storlek <storlek@rigelseven.com>
4  * copyright (c) 2005-2008 Mrs. Brisby <mrs.brisby@nimh.org>
5  * copyright (c) 2009 Storlek & Mrs. Brisby
6  * copyright (c) 2010-2012 Storlek
7  * URL: http://schismtracker.org/
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23 
24 #include "headers.h"
25 
26 #include "it.h"
27 #include "page.h"
28 
29 /* --------------------------------------------------------------------- */
30 /* Thumb bars */
31 
_draw_thumb_bar_internal(int width,int x,int y,int val,uint32_t fg)32 static inline void _draw_thumb_bar_internal(int width, int x, int y,
33 					    int val, uint32_t fg)
34 {
35 	const uint8_t thumb_chars[2][8] = {
36 		{155, 156, 157, 158, 159, 160, 161, 162},
37 		{0, 0, 0, 163, 164, 165, 166, 167}
38 	};
39 	int n = ++val >> 3;
40 
41 	val %= 8;
42 	draw_fill_chars(x, y, x + n - 1, y, 0);
43 	draw_char(thumb_chars[0][val], x + n, y, fg, 0);
44 	if (++n < width)
45 		draw_char(thumb_chars[1][val], x + n, y, fg, 0);
46 	if (++n < width)
47 		draw_fill_chars(x + n, y, x + width - 1, y, 0);
48 }
49 
draw_thumb_bar(int x,int y,int width,int min,int max,int val,int selected)50 void draw_thumb_bar(int x, int y, int width, int min, int max, int val,
51 		    int selected)
52 {
53 	/* this wouldn't happen in a perfect world :P */
54 	if (val < min || val > max) {
55 		draw_fill_chars(x, y, x + width - 1, y,
56 				((status.flags & CLASSIC_MODE) ? 2 : 0));
57 		return;
58 	}
59 
60 	/* fix the range so that it's 0->n */
61 	val -= min;
62 	max -= min;
63 
64 	/* draw the bar */
65 	if (!max)
66 		_draw_thumb_bar_internal(width, x, y, 0,
67 				 selected ? 3 : 2);
68 	else
69 		_draw_thumb_bar_internal(width, x, y,
70 				val * (width - 1) * 8 / max,
71 				selected ? 3 : 2);
72 }
73 
74 /* --------------------------------------------------------------------- */
75 /* VU meters */
76 
draw_vu_meter(int x,int y,int width,int val,int color,int peak)77 void draw_vu_meter(int x, int y, int width, int val, int color, int peak)
78 {
79 	const uint8_t endtext[8][3] = {
80 		{174, 0, 0}, {175, 0, 0}, {176, 0, 0}, {176, 177, 0},
81 		{176, 178, 0}, {176, 179, 180}, {176, 179, 181},
82 		{176, 179, 182},
83 	};
84 	int leftover;
85 	int chunks = (width / 3);
86 	int maxval = width * 8 / 3;
87 
88 	/* reduced from (val * maxval / 64) */
89 	val = CLAMP((val*width/24), 0, (maxval-1));
90 	if (!val)
91 		return;
92 
93 	leftover = val & 7;
94 	val >>= 3;
95 	if ((val < chunks - 1) || (status.flags & CLASSIC_MODE))
96 		peak = color;
97 
98 	draw_char(endtext[leftover][0], 3 * val + x + 0, y, peak, 0);
99 	draw_char(endtext[leftover][1], 3 * val + x + 1, y, peak, 0);
100 	draw_char(endtext[leftover][2], 3 * val + x + 2, y, peak, 0);
101 	while (val--) {
102 		draw_char(176, 3 * val + x + 0, y, color, 0);
103 		draw_char(179, 3 * val + x + 1, y, color, 0);
104 		draw_char(182, 3 * val + x + 2, y, color, 0);
105 	}
106 }
107