Переглянути джерело

Adjusted to use the normal internal mucurses API rather than accessing

stdscr directly.
tags/v0.9.3
Michael Brown 18 роки тому
джерело
коміт
09f9142cbf
1 змінених файлів з 25 додано та 19 видалено
  1. 25
    19
      src/hci/mucurses/slk.c

+ 25
- 19
src/hci/mucurses/slk.c Переглянути файл

@@ -4,6 +4,7 @@
4 4
 #include <string.h>
5 5
 #include <assert.h>
6 6
 #include "mucurses.h"
7
+#include "cursor.h"
7 8
 
8 9
 /** @file
9 10
  *
@@ -44,6 +45,9 @@ struct _softlabelkeys {
44 45
 	unsigned int num_labels;
45 46
 	unsigned int num_spaces;
46 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 53
 struct _softlabelkeys *slks;
@@ -55,12 +59,21 @@ struct _softlabelkeys *slks;
55 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 76
 static void _print_label ( struct _softlabel sl ) {
63
-	unsigned short i = 0;
64 77
 	int space_ch;
65 78
 	char str[SLK_MAX_LABEL_LEN + 1];
66 79
 
@@ -88,13 +101,10 @@ static void _print_label ( struct _softlabel sl ) {
88 101
 		// post-padding
89 102
 		memset(str+strlen(str), space_ch,
90 103
 		       (size_t)(slks->max_label_len - strlen(str)) );
91
-		str[slks->max_label_len] = '\0';
92 104
 	}
93 105
 
94 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,18 +204,12 @@ int slk_attr_set ( const attr_t attrs, short colour_pair_number,
194 204
  * @ret rc	return status code
195 205
  */
196 206
 int slk_clear ( void ) {
197
-	chtype space_ch;
198
-	unsigned int pos_x;
199
-
200 207
 	if ( slks == NULL )
201 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 214
 	return OK;
211 215
 }
@@ -308,7 +312,7 @@ int slk_restore ( void ) {
308 312
 
309 313
 	pos_x = 0;
310 314
 
311
-	_movetoslk();
315
+	_enter_slk();
312 316
 
313 317
 	space_ch = (chtype)' ' | slks->attrs;
314 318
 	next_space = &(slks->spaces[0]);
@@ -320,16 +324,18 @@ int slk_restore ( void ) {
320 324
 
321 325
 		if ( i == *next_space ) {
322 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 328
 			if ( next_space < last_space )
325 329
 				next_space++;
326 330
 		} else {
327 331
 			if ( pos_x < COLS )
328
-				stdscr->scr->putc( stdscr->scr, space_ch );
332
+				_wputch ( stdscr, space_ch, NOWRAP );
329 333
 			pos_x++;
330 334
 		}
331 335
 	}
332 336
 
337
+	_leave_slk();
338
+
333 339
 	return OK;
334 340
 }
335 341
 

Завантаження…
Відмінити
Зберегти