/uspace/trunk/console/screenbuffer.h |
---|
30,8 → 30,8 |
#define __SCREENBUFFER_H__ |
#define DEFAULT_FOREGROUND_COLOR 0xffffff |
#define DEFAULT_BACKGROUND_COLOR 0x00003f |
#define DEFAULT_FOREGROUND_COLOR 0xffffff /**< default console foreground color */ |
#define DEFAULT_BACKGROUND_COLOR 0x00003f /**< default console background color */ |
typedef struct { |
unsigned int bg_color; /**< background color */ |
38,7 → 38,7 |
unsigned int fg_color; /**< foreground color */ |
} style_t; |
/** One field at screen. It contain one character and its attributes. */ |
/** One field on screen. It contain one character and its attributes. */ |
typedef struct { |
char character; /**< Character itself */ |
style_t style; /**< Character`s attributes */ |
54,11 → 54,22 |
unsigned int top_line; /**< Points to buffer[][] line that will be printed at screen as the first line */ |
} screenbuffer_t; |
/** Returns keyfield for position on screen. Screenbuffer->buffer is cyclic buffer so we must couted in index of the topmost line. |
* @param scr screenbuffer |
* @oaram x position on screen |
* @param y position on screen |
* @return keyfield structure with character and its attributes on x,y |
*/ |
static inline keyfield_t *get_field_at(screenbuffer_t *scr, unsigned int x, unsigned int y) |
{ |
return scr->buffer + x + ((y + scr->top_line) % scr->size_y) * scr->size_x; |
} |
/** Compares two styles. |
* @param s1 first style |
* @param s2 second style |
* @return nonzero on equality |
*/ |
static inline int style_same(style_t s1, style_t s2) |
{ |
return s1.fg_color == s2.fg_color && s1.bg_color == s2.bg_color; |
65,7 → 76,7 |
} |
int screenbuffer_putchar(screenbuffer_t *scr, char c); |
void screenbuffer_putchar(screenbuffer_t *scr, char c); |
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y); |
void screenbuffer_clear(screenbuffer_t *scr); |
72,6 → 83,7 |
void screenbuffer_clear_line(screenbuffer_t *scr, unsigned int line); |
void screenbuffer_copy_buffer(screenbuffer_t *scr, keyfield_t *dest); |
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y); |
void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color); |
#endif |
/uspace/trunk/console/console.c |
---|
298,6 → 298,15 |
case CONSOLE_FLUSH: |
sync_send_2(fb_info.phone, FB_FLUSH, 0, 0, NULL, NULL); |
break; |
case CONSOLE_SET_STYLE: |
arg1 = IPC_GET_ARG1(call); |
arg2 = IPC_GET_ARG2(call); |
screenbuffer_set_style(&(connections[consnum]),arg1, arg2); |
if (consnum == active_console) |
nsend_call_2(fb_info.phone, FB_SET_STYLE, arg1, arg2); |
break; |
case CONSOLE_GETCHAR: |
if (keybuffer_empty(&(connections[consnum].keybuffer))) { |
/* buffer is empty -> store request */ |
/uspace/trunk/console/console.h |
---|
31,12 → 31,13 |
#define CONSOLE_COUNT 12 |
#define CONSOLE_GETCHAR 1026 |
#define CONSOLE_PUTCHAR 1027 |
#define CONSOLE_CLEAR 1028 |
#define CONSOLE_GOTO 1029 |
#define CONSOLE_GETSIZE 1030 |
#define CONSOLE_FLUSH 1031 |
#define CONSOLE_GETCHAR 1026 |
#define CONSOLE_PUTCHAR 1027 |
#define CONSOLE_CLEAR 1028 |
#define CONSOLE_GOTO 1029 |
#define CONSOLE_GETSIZE 1030 |
#define CONSOLE_FLUSH 1031 |
#define CONSOLE_SET_STYLE 1032 |
#endif |
/uspace/trunk/console/screenbuffer.c |
---|
30,11 → 30,11 |
#include <malloc.h> |
#include <unistd.h> |
/** Get field from buffer that corresponds to character at position x,y at screen |
* |
/** Store one character to screenbuffer. Its position is determined by scr->position_x and scr->position_y. |
* @param scr screenbuffer |
* @param c stored character |
*/ |
int screenbuffer_putchar(screenbuffer_t *scr, char c) |
void screenbuffer_putchar(screenbuffer_t *scr, char c) |
{ |
keyfield_t *field; |
42,10 → 42,13 |
field->character = c; |
field->style = scr->style; |
return 1; |
} |
/** Initilize screenbuffer. Allocate space for screen content in accordance to given size. |
* @param scr initialized screenbuffer |
* @param size_x |
* @param size_y |
*/ |
screenbuffer_t *screenbuffer_init(screenbuffer_t *scr, int size_x, int size_y) |
{ |
if ((scr->buffer = (keyfield_t *)malloc(sizeof(keyfield_t) * size_x * size_y)) == NULL) { |
102,6 → 105,12 |
void screenbuffer_goto(screenbuffer_t *scr, unsigned int x, unsigned int y) |
{ |
scr->position_x = x % scr->size_x; |
scr->position_y = y % scr->size_y; |
scr->position_y = y % scr->size_y; |
} |
void screenbuffer_set_style(screenbuffer_t *scr, unsigned int fg_color, unsigned int bg_color) |
{ |
scr->style.fg_color = fg_color; |
scr->style.bg_color = bg_color; |
} |