
Go to the source code of this file.
Data Structures | |
| struct | board |
Defines | |
| #define | FONT_H 20 |
| #define | FONT_W 9 |
Functions | |
| struct board * | board_setup (SDL_Surface *screen, SDL_Rect *dest, SDL_Surface *font, SDL_Rect *font_rects) |
| Initialize the board. return 0 on success, 1 on error TODO, if this is done at reload time, free resources before allocate new ones TODO: resource deallocation in case of error. TODO: move the font load at gui_initialization TODO: deallocation of the message history. | |
| void | delete_board (struct board *b) |
| deallocates memory space for a board | |
| void | move_message_board (struct board *b, int dy) |
| int | print_message (struct board *b, const char *s) |
| const char * | read_message (const struct board *b) |
| return the whole text from a board | |
| static void | render_board (struct board *b) |
| int | reset_board (struct board *b) |
| reset the board to blank | |
| #define FONT_H 20 |
Definition at line 49 of file console_board.c.
Referenced by board_setup(), gui_init(), and render_board().
| #define FONT_W 9 |
Definition at line 50 of file console_board.c.
Referenced by board_setup(), gui_init(), and render_board().
| struct board * board_setup | ( | SDL_Surface * | screen, |
| SDL_Rect * | dest, | ||
| SDL_Surface * | font, | ||
| SDL_Rect * | font_rects | ||
| ) | [read] |
Initialize the board. return 0 on success, 1 on error TODO, if this is done at reload time, free resources before allocate new ones TODO: resource deallocation in case of error. TODO: move the font load at gui_initialization TODO: deallocation of the message history.
Definition at line 91 of file console_board.c.
References ast_calloc, ast_free, ast_log(), board::blank, board::cur_col, board::cur_line, board::font, FONT_H, board::font_rects, FONT_W, LOG_WARNING, board::p_h, board::p_rect, board::p_w, board::screen, board::text, board::v_h, and board::v_w.
Referenced by init_board(), and sdl_setup().
{
struct board *b = ast_calloc(1, sizeof (*b));
SDL_Rect br;
if (b == NULL)
return NULL;
/* font, points to the gui structure */
b->font = font;
b->font_rects = font_rects;
/* Destination rectangle on the screen - reference is the whole screen */
b->p_rect = dest;
b->screen = screen;
/* compute physical sizes */
b->p_h = b->p_rect->h/FONT_H;
b->p_w = b->p_rect->w/FONT_W;
/* virtual sizes */
b->v_h = b->p_h * 10; /* XXX 10 times larger */
b->v_w = b->p_w; /* same width */
/* the rectangle we actually use */
br.h = b->p_h * FONT_H; /* pixel sizes of the background */
br.w = b->p_w * FONT_W;
br.x = br.y = 0;
/* allocate a buffer for the text */
b->text = ast_calloc(b->v_w*b->v_h + 1, 1);
if (b->text == NULL) {
ast_log(LOG_WARNING, "Unable to allocate board history memory.\n");
ast_free(b);
return NULL;
}
memset(b->text, ' ', b->v_w * b->v_h); /* fill with spaces */
/* make a copy of the original rectangle, for cleaning up */
b->blank = SDL_CreateRGBSurface(screen->flags, br.w, br.h,
screen->format->BitsPerPixel,
screen->format->Rmask, screen->format->Gmask,
screen->format->Bmask, screen->format->Amask);
if (b->blank == NULL) {
ast_log(LOG_WARNING, "Unable to allocate board virtual screen: %s\n",
SDL_GetError());
ast_free(b->text);
ast_free(b);
return NULL;
}
SDL_BlitSurface(screen, b->p_rect, b->blank, &br);
/* Set color key, if not alpha channel present */
//colorkey = SDL_MapRGB(b->board_surface->format, 0, 0, 0);
//SDL_SetColorKey(b->board_surface, SDL_SRCCOLORKEY, colorkey);
b->cur_col = 0; /* current print column */
b->cur_line = 0; /* last line displayed */
if (0) ast_log(LOG_WARNING, "Message board %dx%d@%d,%d successfully initialized\n",
b->p_rect->w, b->p_rect->h,
b->p_rect->x, b->p_rect->y);
return b;
}
| void delete_board | ( | struct board * | b | ) |
deallocates memory space for a board
Definition at line 320 of file console_board.c.
References ast_free, board::blank, and board::text.
Referenced by cleanup_sdl().
| void move_message_board | ( | struct board * | b, |
| int | dy | ||
| ) |
Definition at line 198 of file console_board.c.
References board::cur_line, board::p_h, render_board(), and board::v_h.
Referenced by eventhandler().
| int print_message | ( | struct board * | b, |
| const char * | s | ||
| ) |
Definition at line 227 of file console_board.c.
References ast_strlen_zero(), board::cur_col, render_board(), board::text, board::v_h, and board::v_w.
Referenced by handle_keyboard_input(), handle_mousedown(), keypad_digit(), keypad_pick_up(), and update_device_info().
{
int i, l, row, col;
char *dst;
if (ast_strlen_zero(s))
return 0;
l = strlen(s);
row = 0;
col = b->cur_col;
/* First, only check how much space we need.
* Starting from the current print position, we move
* it forward and down (if necessary) according to input
* characters (including newlines, tabs, backspaces...).
* At the end, row tells us how many rows to scroll, and
* col (ignored) is the final print position.
*/
for (i = 0; i < l; i++) {
switch (s[i]) {
case '\r':
col = 0;
break;
case '\n':
col = 0;
row++;
break;
case '\b':
if (col > 0)
col--;
break;
default:
if (s[i] < 32) /* signed, so take up to 127 */
break;
col++;
if (col >= b->v_w) {
col -= b->v_w;
row++;
}
break;
}
}
/* scroll the text window */
if (row > 0) { /* need to scroll by 'row' rows */
memcpy(b->text, b->text + row * b->v_w, b->v_w * (b->v_h - row));
/* clean the destination area */
dst = b->text + b->v_w * (b->v_h - row - 1) + b->cur_col;
memset(dst, ' ', b->v_w - b->cur_col + b->v_w * row);
}
/* now do the actual printing. The print position is 'row' lines up
* from the bottom of the buffer, start at the same 'cur_col' as before.
* dst points to the beginning of the current line.
*/
dst = b->text + b->v_w * (b->v_h - row - 1); /* start of current line */
col = b->cur_col;
for (i = 0; i < l; i++) {
switch (s[i]) {
case '\r':
col = 0;
break;
case '\n': /* move to beginning of next line */
dst[col] = '\0'; /* mark the rest of the line as empty */
col = 0;
dst += b->v_w;
break;
case '\b': /* one char back */
if (col > 0)
col--;
dst[col] = ' '; /* delete current char */
break;
default:
if (s[i] < 32) /* signed, so take up to 127 */
break; /* non printable */
dst[col] = s[i]; /* store character */
col++;
if (col >= b->v_w) {
col -= b->v_w;
dst += b->v_w;
}
break;
}
}
dst[col] = '\0'; /* the current position is empty */
b->cur_col = col;
/* everything is printed now, must do the rendering */
render_board(b);
return 1;
}
| const char* read_message | ( | const struct board * | b | ) |
return the whole text from a board
Definition at line 210 of file console_board.c.
References board::text.
Referenced by keypad_pick_up().
{
return b->text;
}
| static void render_board | ( | struct board * | b | ) | [static] |
Definition at line 162 of file console_board.c.
References board::blank, board::cur_line, board::font, FONT_H, board::font_rects, FONT_W, board::p_h, board::p_rect, board::screen, board::text, board::v_h, and board::v_w.
Referenced by move_message_board(), print_message(), and reset_board().
{
int first_row = b->v_h - b->p_h - b->cur_line;
int first_char = b->v_w * first_row;
int last_char = first_char + b->p_h * b->v_w;
int i, col;
SDL_Rect dst;
/* top left char on the physical surface */
dst.w = FONT_W;
dst.h = FONT_H;
dst.x = b->p_rect->x;
dst.y = b->p_rect->y;
/* clean the surface board */
SDL_BlitSurface(b->blank, NULL, b->screen, b->p_rect);
/* blit all characters */
for (i = first_char, col = 0; i < last_char; i++) {
int c = b->text[i] - 32; /* XXX first 32 chars are not printable */
if (c < 0) /* buffer terminator or anything else is a blank */
c = 0;
SDL_BlitSurface(b->font, &b->font_rects[c], b->screen, &dst);
/* point dst to next char position */
dst.x += dst.w;
col++;
if (col >= b->v_w) { /* next row */
dst.x = b->p_rect->x;
dst.y += dst.h;
col = 0;
}
}
SDL_UpdateRects(b->screen, 1, b->p_rect); /* Update the screen */
}
| int reset_board | ( | struct board * | b | ) |
reset the board to blank
Definition at line 215 of file console_board.c.
References board::cur_col, board::cur_line, render_board(), board::text, board::v_h, and board::v_w.
Referenced by keypad_pick_up(), and update_device_info().