00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "asterisk.h"
00045 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 369001 $")
00046 #include "asterisk/utils.h"
00047 #include "console_video.h"
00048
00049 #ifdef HAVE_SDL
00050 #include <SDL/SDL.h>
00051
00052
00053 #define FONT_H 20
00054 #define FONT_W 9
00055
00056 struct board {
00057 int kb_output;
00058
00059 SDL_Surface *screen;
00060 SDL_Rect *p_rect;
00061 SDL_Surface *blank;
00062
00063 int v_h;
00064 int v_w;
00065 int p_h;
00066
00067 int p_w;
00068
00069
00070 int cur_col;
00071 int cur_line;
00072
00073
00074
00075 SDL_Surface *font;
00076 SDL_Rect *font_rects;
00077 char *text;
00078
00079
00080
00081
00082
00083 };
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 struct board *board_setup(SDL_Surface *screen, SDL_Rect *dest,
00094 SDL_Surface *font, SDL_Rect *font_rects);
00095 struct board *board_setup(SDL_Surface *screen, SDL_Rect *dest,
00096 SDL_Surface *font, SDL_Rect *font_rects)
00097 {
00098 struct board *b = ast_calloc(1, sizeof (*b));
00099 SDL_Rect br;
00100
00101 if (b == NULL)
00102 return NULL;
00103
00104 b->font = font;
00105 b->font_rects = font_rects;
00106
00107
00108 b->p_rect = dest;
00109 b->screen = screen;
00110
00111
00112 b->p_h = b->p_rect->h/FONT_H;
00113 b->p_w = b->p_rect->w/FONT_W;
00114
00115
00116 b->v_h = b->p_h * 10;
00117 b->v_w = b->p_w;
00118
00119
00120 br.h = b->p_h * FONT_H;
00121 br.w = b->p_w * FONT_W;
00122 br.x = br.y = 0;
00123
00124
00125 b->text = ast_calloc(b->v_w*b->v_h + 1, 1);
00126 if (b->text == NULL) {
00127 ast_log(LOG_WARNING, "Unable to allocate board history memory.\n");
00128 ast_free(b);
00129 return NULL;
00130 }
00131 memset(b->text, ' ', b->v_w * b->v_h);
00132
00133
00134 b->blank = SDL_CreateRGBSurface(screen->flags, br.w, br.h,
00135 screen->format->BitsPerPixel,
00136 screen->format->Rmask, screen->format->Gmask,
00137 screen->format->Bmask, screen->format->Amask);
00138
00139 if (b->blank == NULL) {
00140 ast_log(LOG_WARNING, "Unable to allocate board virtual screen: %s\n",
00141 SDL_GetError());
00142 ast_free(b->text);
00143 ast_free(b);
00144 return NULL;
00145 }
00146 SDL_BlitSurface(screen, b->p_rect, b->blank, &br);
00147
00148
00149
00150
00151
00152 b->cur_col = 0;
00153 b->cur_line = 0;
00154
00155 if (0) ast_log(LOG_WARNING, "Message board %dx%d@%d,%d successfully initialized\n",
00156 b->p_rect->w, b->p_rect->h,
00157 b->p_rect->x, b->p_rect->y);
00158 return b;
00159 }
00160
00161
00162
00163
00164
00165
00166 static void render_board(struct board *b)
00167 {
00168 int first_row = b->v_h - b->p_h - b->cur_line;
00169 int first_char = b->v_w * first_row;
00170 int last_char = first_char + b->p_h * b->v_w;
00171 int i, col;
00172 SDL_Rect dst;
00173
00174
00175 dst.w = FONT_W;
00176 dst.h = FONT_H;
00177 dst.x = b->p_rect->x;
00178 dst.y = b->p_rect->y;
00179
00180
00181
00182 SDL_BlitSurface(b->blank, NULL, b->screen, b->p_rect);
00183
00184
00185 for (i = first_char, col = 0; i < last_char; i++) {
00186 int c = b->text[i] - 32;
00187 if (c < 0)
00188 c = 0;
00189 SDL_BlitSurface(b->font, &b->font_rects[c], b->screen, &dst);
00190
00191 dst.x += dst.w;
00192 col++;
00193 if (col >= b->v_w) {
00194 dst.x = b->p_rect->x;
00195 dst.y += dst.h;
00196 col = 0;
00197 }
00198 }
00199 SDL_UpdateRects(b->screen, 1, b->p_rect);
00200 }
00201
00202 void move_message_board(struct board *b, int dy)
00203 {
00204 int cur = b->cur_line + dy;
00205 if (cur < 0)
00206 cur = 0;
00207 else if (cur >= b->v_h - b->p_h)
00208 cur = b->v_h - b->p_h - 1;
00209 b->cur_line = cur;
00210 render_board(b);
00211 }
00212
00213
00214 const char *read_message(const struct board *b)
00215 {
00216 return b->text;
00217 }
00218
00219 int reset_board(struct board *b)
00220 {
00221 memset(b->text, ' ', b->v_w * b->v_h);
00222 b->cur_col = 0;
00223 b->cur_line = 0;
00224 render_board(b);
00225 return 0;
00226 }
00227
00228
00229
00230
00231 int print_message(struct board *b, const char *s)
00232 {
00233 int i, l, row, col;
00234 char *dst;
00235
00236 if (ast_strlen_zero(s))
00237 return 0;
00238
00239 l = strlen(s);
00240 row = 0;
00241 col = b->cur_col;
00242
00243
00244
00245
00246
00247
00248
00249 for (i = 0; i < l; i++) {
00250 switch (s[i]) {
00251 case '\r':
00252 col = 0;
00253 break;
00254 case '\n':
00255 col = 0;
00256 row++;
00257 break;
00258 case '\b':
00259 if (col > 0)
00260 col--;
00261 break;
00262 default:
00263 if (s[i] < 32)
00264 break;
00265 col++;
00266 if (col >= b->v_w) {
00267 col -= b->v_w;
00268 row++;
00269 }
00270 break;
00271 }
00272 }
00273
00274 if (row > 0) {
00275 memcpy(b->text, b->text + row * b->v_w, b->v_w * (b->v_h - row));
00276
00277 dst = b->text + b->v_w * (b->v_h - row - 1) + b->cur_col;
00278 memset(dst, ' ', b->v_w - b->cur_col + b->v_w * row);
00279 }
00280
00281
00282
00283
00284 dst = b->text + b->v_w * (b->v_h - row - 1);
00285 col = b->cur_col;
00286 for (i = 0; i < l; i++) {
00287 switch (s[i]) {
00288 case '\r':
00289 col = 0;
00290 break;
00291 case '\n':
00292 dst[col] = '\0';
00293 col = 0;
00294 dst += b->v_w;
00295 break;
00296 case '\b':
00297 if (col > 0)
00298 col--;
00299 dst[col] = ' ';
00300 break;
00301 default:
00302 if (s[i] < 32)
00303 break;
00304 dst[col] = s[i];
00305 col++;
00306 if (col >= b->v_w) {
00307 col -= b->v_w;
00308 dst += b->v_w;
00309 }
00310 break;
00311 }
00312 }
00313 dst[col] = '\0';
00314 b->cur_col = col;
00315
00316 render_board(b);
00317 return 1;
00318 }
00319
00320
00321
00322
00323
00324 void delete_board(struct board *b)
00325 {
00326 if (b) {
00327
00328 if (b->text)
00329 ast_free (b->text);
00330
00331 SDL_FreeSurface(b->blank);
00332
00333 ast_free(b);
00334 }
00335 }
00336
00337 #if 0
00338
00339
00340 static int scroll_message(...)
00341 {
00342 if moving up, scroll text up;
00343 if (gui->message_board.screen_cur > 0)
00344 gui->message_board.screen_cur--;
00345 otherwise scroll text down.
00346 if ((b->screen_cur + b->p_line) < b->board_next) {
00347 gui->message_board.screen_cur++;
00348 #endif
00349
00350 #endif