Selaa lähdekoodia

Adjusted to use the normal internal mucurses API rather than accessing

stdscr directly.
tags/v0.9.3
Michael Brown 18 vuotta sitten
vanhempi
commit
09f9142cbf
1 muutettua tiedostoa jossa 25 lisäystä ja 19 poistoa
  1. 25
    19
      src/hci/mucurses/slk.c

+ 25
- 19
src/hci/mucurses/slk.c Näytä tiedosto

4
 #include <string.h>
4
 #include <string.h>
5
 #include <assert.h>
5
 #include <assert.h>
6
 #include "mucurses.h"
6
 #include "mucurses.h"
7
+#include "cursor.h"
7
 
8
 
8
 /** @file
9
 /** @file
9
  *
10
  *
44
 	unsigned int num_labels;
45
 	unsigned int num_labels;
45
 	unsigned int num_spaces;
46
 	unsigned int num_spaces;
46
 	unsigned int spaces[SLK_MAX_NUM_SPACES];
47
 	unsigned int spaces[SLK_MAX_NUM_SPACES];
48
+	struct cursor_pos saved_cursor;
49
+	attr_t saved_attrs;
50
+	short saved_pair;
47
 };
51
 };
48
 
52
 
49
 struct _softlabelkeys *slks;
53
 struct _softlabelkeys *slks;
55
   this should be ok...
59
   this should be ok...
56
  */
60
  */
57
 
61
 
58
-static void _movetoslk ( void ) {
59
-	stdscr->scr->movetoyx( stdscr->scr, LINES, 0 );
62
+static void _enter_slk ( void ) {
63
+	_store_curs_pos ( stdscr, &slks->saved_cursor );
64
+	wattr_get ( stdscr, &slks->saved_attrs, &slks->saved_pair, NULL );
65
+	LINES++;
66
+	wmove ( stdscr, LINES, 0 );
67
+	wattrset ( stdscr, slks->attrs );
68
+}
69
+
70
+static void _leave_slk ( void ) {
71
+	LINES--;
72
+	wattr_set ( stdscr, slks->saved_attrs, slks->saved_pair, NULL );
73
+	_restore_curs_pos ( stdscr, &slks->saved_cursor );
60
 }
74
 }
61
 
75
 
62
 static void _print_label ( struct _softlabel sl ) {
76
 static void _print_label ( struct _softlabel sl ) {
63
-	unsigned short i = 0;
64
 	int space_ch;
77
 	int space_ch;
65
 	char str[SLK_MAX_LABEL_LEN + 1];
78
 	char str[SLK_MAX_LABEL_LEN + 1];
66
 
79
 
88
 		// post-padding
101
 		// post-padding
89
 		memset(str+strlen(str), space_ch,
102
 		memset(str+strlen(str), space_ch,
90
 		       (size_t)(slks->max_label_len - strlen(str)) );
103
 		       (size_t)(slks->max_label_len - strlen(str)) );
91
-		str[slks->max_label_len] = '\0';
92
 	}
104
 	}
93
 
105
 
94
 	// print the formatted label
106
 	// print the formatted label
95
-	for ( ; i < slks->max_label_len; i++ ) {
96
-		stdscr->scr->putc( stdscr->scr, (chtype)str[i] | slks->attrs );
97
-	}
107
+	_wputstr ( stdscr, str, NOWRAP, slks->max_label_len );
98
 }
108
 }
99
 
109
 
100
 /**
110
 /**
194
  * @ret rc	return status code
204
  * @ret rc	return status code
195
  */
205
  */
196
 int slk_clear ( void ) {
206
 int slk_clear ( void ) {
197
-	chtype space_ch;
198
-	unsigned int pos_x;
199
-
200
 	if ( slks == NULL )
207
 	if ( slks == NULL )
201
 		return ERR;
208
 		return ERR;
202
 
209
 
203
-	_movetoslk();
204
-	pos_x = 0;
205
-	space_ch = (chtype)' ' | slks->attrs;
206
-
207
-	for ( ; pos_x < COLS; pos_x++ )
208
-		stdscr->scr->putc( stdscr->scr, space_ch );
210
+	_enter_slk();
211
+	wclrtoeol ( stdscr );
212
+	_leave_slk();
209
 
213
 
210
 	return OK;
214
 	return OK;
211
 }
215
 }
308
 
312
 
309
 	pos_x = 0;
313
 	pos_x = 0;
310
 
314
 
311
-	_movetoslk();
315
+	_enter_slk();
312
 
316
 
313
 	space_ch = (chtype)' ' | slks->attrs;
317
 	space_ch = (chtype)' ' | slks->attrs;
314
 	next_space = &(slks->spaces[0]);
318
 	next_space = &(slks->spaces[0]);
320
 
324
 
321
 		if ( i == *next_space ) {
325
 		if ( i == *next_space ) {
322
 			for ( j = 0; j < slks->maj_space_len; j++, pos_x++ )
326
 			for ( j = 0; j < slks->maj_space_len; j++, pos_x++ )
323
-				stdscr->scr->putc( stdscr->scr, space_ch );
327
+				_wputch ( stdscr, space_ch, NOWRAP );
324
 			if ( next_space < last_space )
328
 			if ( next_space < last_space )
325
 				next_space++;
329
 				next_space++;
326
 		} else {
330
 		} else {
327
 			if ( pos_x < COLS )
331
 			if ( pos_x < COLS )
328
-				stdscr->scr->putc( stdscr->scr, space_ch );
332
+				_wputch ( stdscr, space_ch, NOWRAP );
329
 			pos_x++;
333
 			pos_x++;
330
 		}
334
 		}
331
 	}
335
 	}
332
 
336
 
337
+	_leave_slk();
338
+
333
 	return OK;
339
 	return OK;
334
 }
340
 }
335
 
341
 

Loading…
Peruuta
Tallenna