Browse Source

- major implementation work completed (testing in progress)

- some optimisation done
tags/v0.9.3
Dan Lynch 18 years ago
parent
commit
1632c25c78
1 changed files with 120 additions and 7 deletions
  1. 120
    7
      src/hci/mucurses/slk.c

+ 120
- 7
src/hci/mucurses/slk.c View File

4
 #include <string.h>
4
 #include <string.h>
5
 #include "core.h"
5
 #include "core.h"
6
 
6
 
7
-extern struct _softlabelkeys *slks;
7
+/** @file
8
+ *
9
+ * Soft label key functions
10
+ */
11
+
12
+#define MIN_SPACE_SIZE 2
13
+
14
+struct _softlabel {
15
+	// label string
16
+	char *label;
17
+	/* Format of soft label 
18
+	   0: left justify
19
+	   1: centre justify
20
+	   2: right justify
21
+	 */
22
+	unsigned short fmt;
23
+};
24
+
25
+struct _softlabelkeys {
26
+	struct _softlabel fkeys[12];
27
+	attr_t attrs;
28
+	/* Soft label layout format
29
+	   0: 3-2-3
30
+	   1: 4-4
31
+	   2: 4-4-4
32
+	   3: 4-4-4 with index line
33
+	*/
34
+	unsigned short fmt;
35
+	unsigned short max_label_len;
36
+	unsigned short maj_space_len;
37
+	unsigned short num_labels;
38
+	unsigned short num_spaces;
39
+	unsigned short *spaces;
40
+};
41
+
42
+struct _softlabelkeys *slks;
43
+
44
+/*
45
+  I either need to break the primitives here, or write a collection of
46
+  functions specifically for SLKs that directly access the screen
47
+  functions - since this technically isn't part of stdscr, I think
48
+  this should be ok...
49
+ */
50
+
51
+static void _movetoslk ( void ) {
52
+	stdscr->scr->movetoyx( stdscr->scr, LINES, 0 );
53
+}
8
 
54
 
9
 /**
55
 /**
10
  * Return the attribute used for the soft function keys
56
  * Return the attribute used for the soft function keys
105
 int slk_clear ( void ) {
151
 int slk_clear ( void ) {
106
 	if ( slks == NULL )
152
 	if ( slks == NULL )
107
 		return ERR;
153
 		return ERR;
108
-
109
-	wmove(stdscr,stdscr->height-1,0);
110
-	wclrtoeol(stdscr);
111
 	return 0;
154
 	return 0;
112
 }
155
 }
113
 
156
 
157
+/**
158
+ * Set soft label colour pair
159
+ */
160
+int slk_colour ( short colour_pair_number ) {
161
+	if ( slks == NULL ) 
162
+		return ERR;
163
+	if ( ( unsigned short )colour_pair_number > COLORS )
164
+		return ERR;
165
+
166
+	slks->attrs = ( (unsigned short)colour_pair_number << CPAIR_SHIFT )
167
+		| ( slks->attrs & A_ATTRIBUTES );
168
+
169
+	return OK;
170
+}
171
+
114
 /**
172
 /**
115
  * Initialise the soft function keys
173
  * Initialise the soft function keys
116
  *
174
  *
118
  * @ret rc	return status code
176
  * @ret rc	return status code
119
  */
177
  */
120
 int slk_init ( int fmt ) {
178
 int slk_init ( int fmt ) {
179
+	unsigned short nmaj, nmin, nblocks, available_width;
180
+
121
 	if ( (unsigned)fmt > 3 ) {
181
 	if ( (unsigned)fmt > 3 ) {
122
 		return ERR;
182
 		return ERR;
123
 	}
183
 	}
124
 
184
 
125
 	slks = malloc(sizeof(struct _softlabelkeys));
185
 	slks = malloc(sizeof(struct _softlabelkeys));
126
 	slks->attrs = A_DEFAULT;
186
 	slks->attrs = A_DEFAULT;
127
-	slks->fmt = (unsigned short)fmt;
128
-	slks->maxlablen = 5;
187
+	slks->fmt = fmt;
188
+	switch(fmt) {
189
+	case 0:
190
+		nblocks = 8; nmaj = 2; nmin = 5;
191
+		slks->spaces = calloc(2, sizeof(unsigned short));
192
+		slks->spaces[0] = 2; slks->spaces[1] = 4;
193
+		break;
194
+	case 1:
195
+		nblocks = 8; nmaj = 1; nmin = 6;
196
+		slks->spaces = calloc(1, sizeof(unsigned short));
197
+		slks->spaces[0] = 3;
198
+		break;
199
+	case 2:
200
+		// same allocations as format 3
201
+	case 3:
202
+		nblocks = 12; nmaj = 2; nmin = 9;
203
+		slks->spaces = calloc(2, sizeof(unsigned short));
204
+		slks->spaces[0] = 3; slks->spaces[1] = 7;
205
+		break;
206
+	}
207
+
208
+	// determine maximum label length and major space size
209
+	available_width = COLS - ( ( MIN_SPACE_SIZE * nmaj ) + nmin );
210
+	slks->max_label_len = available_width / nblocks;
211
+	slks->maj_space_len = ( available_width % nblocks ) / nmaj;
212
+	slks->num_spaces = nmaj;
213
+
214
+	// strip a line from the screen
215
+	LINES -= 1;
216
+
129
 	return OK;
217
 	return OK;
130
 }
218
 }
131
 
219
 
148
  * @ret rc	return status code
236
  * @ret rc	return status code
149
  */
237
  */
150
 int slk_restore ( void ) {
238
 int slk_restore ( void ) {
239
+	unsigned short i, j,
240
+		*next_space, *last_space;
241
+	chtype space_ch;
242
+	char c;
243
+
151
 	if ( slks == NULL ) 
244
 	if ( slks == NULL ) 
152
 		return ERR;
245
 		return ERR;
153
 
246
 
247
+	_movetoslk();
248
+
249
+	space_ch = (int)' ' | slks->attrs;
250
+	next_space = &(slks->spaces[0]);
251
+	last_space = &(slks->spaces[slks->num_spaces-1]);
252
+
253
+	for ( i = 0; i < slks->num_labels ; i++ ) {
254
+		while ( ( c = *(slks->fkeys[i].label++) ) != '\0' ) {
255
+			stdscr->scr->putc( stdscr->scr, (int)c | slks->attrs );
256
+		}
257
+		if ( i == *next_space ) {
258
+			for ( j = 0; j < slks->maj_space_len; j++ )
259
+				stdscr->scr->putc( stdscr->scr, space_ch );
260
+			if ( next_space < last_space )
261
+				next_space++;
262
+		} else {
263
+			stdscr->scr->putc( stdscr->scr, space_ch );
264
+		}
265
+	}
266
+
154
 	return OK;
267
 	return OK;
155
 }
268
 }
156
 
269
 
169
 		return ERR;
282
 		return ERR;
170
 	if ( (unsigned short)fmt >= 3 )
283
 	if ( (unsigned short)fmt >= 3 )
171
 		return ERR;
284
 		return ERR;
172
-	if ( strlen(label) > slks->maxlablen )
285
+	if ( strlen(label) > slks->max_label_len )
173
 		return ERR;
286
 		return ERR;
174
 
287
 
175
 	strcpy( slks->fkeys[labnum].label, label );
288
 	strcpy( slks->fkeys[labnum].label, label );

Loading…
Cancel
Save