1 /* OpenCP Module Player
2  * copyright (c) '94-'10 Niklas Beisert <nbeisert@physik.tu-muenchen.de>
3  *
4  * CPIface text mode channel display
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  * revision history: (please note changes here)
21  *  -nb980510   Niklas Beisert <nbeisert@physik.tu-muenchen.de>
22  *    -first release
23  *  -fd981119   Felix Domke <tmbinc@gmx.net>
24  *    -added the really important 'NO_CPIFACE_IMPORT'
25  */
26 
27 #include "config.h"
28 #include <string.h>
29 #include "types.h"
30 #include "boot/psetting.h"
31 #include "stuff/poutput.h"
32 #include "cpiface.h"
33 
34 
35 static void (*ChanDisplay)(uint16_t *buf, int len, int i);
36 static int plChanFirstLine;
37 static int plChanHeight;
38 static int plChanWidth;
39 static char plChannelType;
40 static int plChanStartCol;
41 
42 
drawchannels()43 static void drawchannels()
44 {
45 	uint16_t buf[CONSOLE_MAX_X];
46 	int i,y,x;
47 	int h=(plChannelType==1)?((plNLChan+1)/2):plNLChan;
48 	int sh=(plChannelType==1)?(plSelCh/2):plSelCh;
49 	int first;
50 	memset(buf, 0, sizeof(buf));
51 	if (h>plChanHeight)
52 		if (sh<(plChanHeight/2))
53 			first=0;
54 		else
55 			if (sh>=(h-plChanHeight/2))
56 				first=h-plChanHeight;
57 			else
58 				first=sh-(plChanHeight-1)/2;
59 	else
60 		first=0;
61 
62 	for (y=0; y<plChanHeight; y++)
63 	{
64 		char *sign=" ";
65 		if (!y&&first)
66 			sign="\x18";
67 		if (((y+1)==plChanHeight)&&((y+first+1)!=h))
68 			sign="\x19";
69 		if (plChannelType==1)
70 		{
71 			for (x=0; x<2; x++)
72 			{
73 				i=2*first+y*2+x;
74 				if (plPanType&&(y&1))
75 					i^=1;
76 				if (i<plNLChan)
77 				{
78 					if (plChanWidth<132)
79 					{
80 						writestring(buf, x*40, plMuteCh[i]?0x08:0x07, " ##:", 4);
81 						writestring(buf, x*40, 0x0F, (i==plSelCh)?">":sign, 1);
82 						_writenum(buf, x*40+1, plMuteCh[i]?0x08:0x07, i+1, 10, 2);
83 						ChanDisplay(buf+x*40+4, 36, i);
84 					} else {
85 						writestring(buf, x*66, plMuteCh[i]?0x08:0x07, " ##:", 4);
86 						writestring(buf, x*66, 0x0F, (i==plSelCh)?">":sign, 1);
87 						_writenum(buf, x*66+1, plMuteCh[i]?0x08:0x07, i+1, 10, 2);
88 						ChanDisplay(buf+x*66+4, 62, i);
89 					}
90 				} else
91 					if (plChanWidth<132)
92 						writestring(buf, x*40, 0, "", 40);
93 					else
94 						writestring(buf, x*66, 0, "", 66);
95 			}
96 		} else {
97 			int i=y+first;
98 			if ((y+first)==plSelCh)
99 				sign=">";
100 			if (plChannelType==2)
101 			{
102 				writestring(buf, 0, plMuteCh[i]?0x08:0x07, " ##:", 4);
103 				writestring(buf, 0, 0x0F, sign, 1);
104 				_writenum(buf, 1, plMuteCh[i]?0x08:0x07, i+1, 10, 2);
105 				ChanDisplay(buf+4, (plChanWidth<128)?76:128, y+first);
106 			} else {
107 				writestring(buf, 0, plMuteCh[i]?0x08:0x07, "     ##:", 8);
108 				writestring(buf, 4, 0x0F, sign, 1);
109 				_writenum(buf, 5, plMuteCh[i]?0x08:0x07, i+1, 10, 2);
110 				ChanDisplay(buf+8, 44, y+first);
111 			}
112 		}
113 		displaystrattr(plChanFirstLine+y, plChanStartCol, buf, plChanWidth);
114 	}
115 }
116 
ChanSetWin(int xpos,int wid,int ypos,int hgt)117 static void ChanSetWin(int xpos, int wid, int ypos, int hgt)
118 {
119 	plChanFirstLine=ypos;
120 	plChanStartCol=xpos;
121 	plChanHeight=hgt;
122 	plChanWidth=wid;
123 }
124 
ChanGetWin(struct cpitextmodequerystruct * q)125 static int ChanGetWin(struct cpitextmodequerystruct *q)
126 {
127 	if ((plChannelType==3)&&(plScrWidth<132))
128 		plChannelType=0;
129 	if (!plNLChan)
130 		return 0;
131 
132 	switch (plChannelType)
133 	{
134 		case 0:
135 			return 0;
136 		case 1:
137 			q->hgtmax=(plNLChan+1)>>1;
138 			q->xmode=3;
139 			break;
140 		case 2:
141 			q->hgtmax=plNLChan;
142 			q->xmode=1;
143 			break;
144 		case 3:
145 			q->hgtmax=plNLChan;
146 			q->xmode=2;
147 			break;
148 	}
149 	q->size=1;
150 	q->top=1;
151 	q->killprio=128;
152 	q->viewprio=160;
153 	q->hgtmin=2;
154 	if (q->hgtmin>q->hgtmax)
155 		q->hgtmin=q->hgtmax;
156 	return 1;
157 }
158 
ChanDraw(int ignore)159 static void ChanDraw(int ignore)
160 {
161 	drawchannels();
162 }
163 
ChanIProcessKey(uint16_t key)164 static int ChanIProcessKey(uint16_t key)
165 {
166 	switch (key)
167 	{
168 		case KEY_ALT_K:
169 			cpiKeyHelp('c', "Enable channel viewer");
170 			cpiKeyHelp('C', "Enable channel viewer");
171 			break;
172 		case 'c': case 'C':
173 			if (!plChannelType)
174 				plChannelType=(plChannelType+1)%4;
175 			cpiTextSetMode("chan");
176 			return 1;
177 		case 'x': case 'X':
178 			plChannelType=3;
179 			break;
180 		case KEY_ALT_X:
181 			plChannelType=2;
182 			break;
183 	}
184 	return 0;
185 }
186 
ChanAProcessKey(uint16_t key)187 static int ChanAProcessKey(uint16_t key)
188 {
189 	switch (key)
190 	{
191 		case KEY_ALT_K:
192 			cpiKeyHelp('c', "Change channel view mode");
193 			cpiKeyHelp('C', "Change channel view mode");
194 			return 0;
195 		case 'c': case 'C':
196 			plChannelType=(plChannelType+1)%4;
197 			cpiTextRecalc();
198 			break;
199 		default:
200 			return 0;
201 	}
202 	return 1;
203 }
204 
ChanEvent(int ev)205 static int ChanEvent(int ev)
206 {
207 	switch (ev)
208 	{
209 		case cpievInitAll:
210 			plChannelType=cfGetProfileInt2(cfScreenSec, "screen", "channeltype", 3, 10)&3;
211 			return 0;
212 	}
213 	return 1;
214 }
215 
216 static struct cpitextmoderegstruct cpiTModeChan = {"chan", ChanGetWin, ChanSetWin, ChanDraw, ChanIProcessKey, ChanAProcessKey, ChanEvent CPITEXTMODEREGSTRUCT_TAIL};
217 
init(void)218 static void __attribute__((constructor))init(void)
219 {
220 	cpiTextRegisterDefMode(&cpiTModeChan);
221 }
222 
done(void)223 static void __attribute__((destructor))done(void)
224 {
225 	cpiTextUnregisterDefMode(&cpiTModeChan);
226 }
227 
plUseChannels(void (* Display)(uint16_t * buf,int len,int i))228 void plUseChannels(void (*Display)(uint16_t *buf, int len, int i))
229 {
230 	ChanDisplay=Display;
231 	if (!plNLChan)
232 		return;
233 	cpiTextRegisterMode(&cpiTModeChan);
234 }
235 
236