more steps to decouple the gui from the rest of the code.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@94823 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Luigi Rizzo 18 years ago
parent bda73977fa
commit 07afabbaf1

@ -381,26 +381,27 @@ static int kp_match_area(const struct keypad_entry *e, int x, int y);
static void handle_button_event(struct video_desc *env, SDL_MouseButtonEvent button) static void handle_button_event(struct video_desc *env, SDL_MouseButtonEvent button)
{ {
uint8_t index = KEY_OUT_OF_KEYPAD; /* the key or region of the display we clicked on */ uint8_t index = KEY_OUT_OF_KEYPAD; /* the key or region of the display we clicked on */
struct gui_info *gui = env->gui;
#if 0 #if 0
ast_log(LOG_WARNING, "event %d %d have %d/%d regions at %p\n", ast_log(LOG_WARNING, "event %d %d have %d/%d regions at %p\n",
button.x, button.y, env->gui->kp_used, env->gui->kp_size, env->gui->kp); button.x, button.y, gui->kp_used, gui->kp_size, gui->kp);
#endif #endif
/* for each click we come back in normal mode */ /* for each click we come back in normal mode */
env->gui->text_mode = 0; gui->text_mode = 0;
/* define keypad boundary */ /* define keypad boundary */
if (button.x < env->in.rem_dpy.w) if (button.x < env->in.rem_dpy.w)
index = KEY_REM_DPY; /* click on remote video */ index = KEY_REM_DPY; /* click on remote video */
else if (button.x > env->in.rem_dpy.w + env->gui->keypad->w) else if (button.x > env->in.rem_dpy.w + gui->keypad->w)
index = KEY_LOC_DPY; /* click on local video */ index = KEY_LOC_DPY; /* click on local video */
else if (button.y > env->gui->keypad->h) else if (button.y > gui->keypad->h)
index = KEY_OUT_OF_KEYPAD; /* click outside the keypad */ index = KEY_OUT_OF_KEYPAD; /* click outside the keypad */
else if (env->gui->kp) { else if (gui->kp) {
int i; int i;
for (i = 0; i < env->gui->kp_used; i++) { for (i = 0; i < gui->kp_used; i++) {
if (kp_match_area(&env->gui->kp[i], button.x - env->in.rem_dpy.w, button.y)) { if (kp_match_area(&gui->kp[i], button.x - env->in.rem_dpy.w, button.y)) {
index = env->gui->kp[i].c; index = gui->kp[i].c;
break; break;
} }
} }
@ -477,20 +478,21 @@ static void handle_button_event(struct video_desc *env, SDL_MouseButtonEvent but
*/ */
static void handle_keyboard_input(struct video_desc *env, SDLKey key) static void handle_keyboard_input(struct video_desc *env, SDLKey key)
{ {
if (env->gui->text_mode) { struct gui_info *gui = env->gui;
if (gui->text_mode) {
/* append in the text-message buffer */ /* append in the text-message buffer */
if (key == SDLK_RETURN) { if (key == SDLK_RETURN) {
/* send the text message and return in normal mode */ /* send the text message and return in normal mode */
env->gui->text_mode = 0; gui->text_mode = 0;
keypad_send_command(env, "send text"); keypad_send_command(env, "send text");
} else { } else {
/* accumulate the key in the message buffer */ /* accumulate the key in the message buffer */
append_char(env->gui->msgbuf, &env->gui->msgbuf_pos, key); append_char(gui->msgbuf, &gui->msgbuf_pos, key);
} }
} }
else { else {
/* append in the dial buffer */ /* append in the dial buffer */
append_char(env->gui->inbuf, &env->gui->inbuf_pos, key); append_char(gui->inbuf, &gui->inbuf_pos, key);
} }
return; return;
@ -573,7 +575,7 @@ static void eventhandler(struct video_desc *env, const char *caption)
handle_keyboard_input(env, ev[i].key.keysym.sym); handle_keyboard_input(env, ev[i].key.keysym.sym);
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
if (env->gui->drag_mode != 0) if (gui->drag_mode != 0)
move_capture_source(env, ev[i].motion.x, ev[i].motion.y); move_capture_source(env, ev[i].motion.x, ev[i].motion.y);
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
@ -582,7 +584,7 @@ static void eventhandler(struct video_desc *env, const char *caption)
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (gui->drag_mode != 0) { if (gui->drag_mode != 0) {
move_capture_source(env, ev[i].button.x, ev[i].button.y); move_capture_source(env, ev[i].button.x, ev[i].button.y);
env->gui->drag_mode = 0; gui->drag_mode = 0;
} }
break; break;
} }
@ -743,6 +745,7 @@ static void sdl_setup(struct video_desc *env)
const SDL_VideoInfo *info; const SDL_VideoInfo *info;
int kp_w = 0, kp_h = 0; /* keypad width and height */ int kp_w = 0, kp_h = 0; /* keypad width and height */
int sdl_ok = 0; int sdl_ok = 0;
struct gui_info *gui = env->gui;
/* /*
* initialize the SDL environment. We have one large window * initialize the SDL environment. We have one large window
@ -755,7 +758,7 @@ static void sdl_setup(struct video_desc *env)
* SDL window, because the size is only known here. * SDL window, because the size is only known here.
*/ */
if (env->gui == NULL && SDL_Init(SDL_INIT_VIDEO)) { if (gui == NULL && SDL_Init(SDL_INIT_VIDEO)) {
ast_log(LOG_WARNING, "Could not initialize SDL - %s\n", ast_log(LOG_WARNING, "Could not initialize SDL - %s\n",
SDL_GetError()); SDL_GetError());
/* again not fatal, just we won't display anything */ /* again not fatal, just we won't display anything */
@ -768,39 +771,39 @@ static void sdl_setup(struct video_desc *env)
depth = info->vfmt->BitsPerPixel; depth = info->vfmt->BitsPerPixel;
if (depth < 16) if (depth < 16)
depth = 16; depth = 16;
if (!env->gui) if (!gui)
env->gui = gui_init(); env->gui = gui = gui_init();
if (!env->gui) if (!gui)
goto no_sdl; goto no_sdl;
/* initialize grab coordinates */ /* initialize grab coordinates */
env->out.loc_src.x = 0; env->out.loc_src.x = 0;
env->out.loc_src.y = 0; env->out.loc_src.y = 0;
keypad_setup(env->gui, env->keypad_file); keypad_setup(gui, env->keypad_file);
#if 0 #if 0
ast_log(LOG_WARNING, "keypad_setup returned %p %d\n", ast_log(LOG_WARNING, "keypad_setup returned %p %d\n",
env->gui->keypad, env->gui->kp_used); gui->keypad, gui->kp_used);
#endif #endif
if (env->gui->keypad) { if (gui->keypad) {
kp_w = env->gui->keypad->w; kp_w = gui->keypad->w;
kp_h = env->gui->keypad->h; kp_h = gui->keypad->h;
} }
#define BORDER 5 /* border around our windows */ #define BORDER 5 /* border around our windows */
maxw = env->in.rem_dpy.w + env->out.loc_dpy.w + kp_w; maxw = env->in.rem_dpy.w + env->out.loc_dpy.w + kp_w;
maxh = MAX( MAX(env->in.rem_dpy.h, env->out.loc_dpy.h), kp_h); maxh = MAX( MAX(env->in.rem_dpy.h, env->out.loc_dpy.h), kp_h);
maxw += 4 * BORDER; maxw += 4 * BORDER;
maxh += 2 * BORDER; maxh += 2 * BORDER;
env->gui->screen = SDL_SetVideoMode(maxw, maxh, depth, 0); gui->screen = SDL_SetVideoMode(maxw, maxh, depth, 0);
if (!env->gui->screen) { if (!gui->screen) {
ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n"); ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n");
goto no_sdl; goto no_sdl;
} }
SDL_WM_SetCaption("Asterisk console Video Output", NULL); SDL_WM_SetCaption("Asterisk console Video Output", NULL);
if (set_win(env->gui->screen, &env->gui->win[WIN_REMOTE], dpy_fmt, if (set_win(gui->screen, &gui->win[WIN_REMOTE], dpy_fmt,
env->in.rem_dpy.w, env->in.rem_dpy.h, BORDER, BORDER)) env->in.rem_dpy.w, env->in.rem_dpy.h, BORDER, BORDER))
goto no_sdl; goto no_sdl;
if (set_win(env->gui->screen, &env->gui->win[WIN_LOCAL], dpy_fmt, if (set_win(gui->screen, &gui->win[WIN_LOCAL], dpy_fmt,
env->out.loc_dpy.w, env->out.loc_dpy.h, env->out.loc_dpy.w, env->out.loc_dpy.h,
3*BORDER+env->in.rem_dpy.w + kp_w, BORDER)) 3*BORDER+env->in.rem_dpy.w + kp_w, BORDER))
goto no_sdl; goto no_sdl;
@ -808,14 +811,14 @@ static void sdl_setup(struct video_desc *env)
/* display the skin, but do not free it as we need it later to /* display the skin, but do not free it as we need it later to
* restore text areas and maybe sliders too. * restore text areas and maybe sliders too.
*/ */
if (env->gui && env->gui->keypad) { if (gui && gui->keypad) {
struct SDL_Rect *dest = &env->gui->win[WIN_KEYPAD].rect; struct SDL_Rect *dest = &gui->win[WIN_KEYPAD].rect;
dest->x = 2*BORDER + env->in.rem_dpy.w; dest->x = 2*BORDER + env->in.rem_dpy.w;
dest->y = BORDER; dest->y = BORDER;
dest->w = env->gui->keypad->w; dest->w = gui->keypad->w;
dest->h = env->gui->keypad->h; dest->h = gui->keypad->h;
SDL_BlitSurface(env->gui->keypad, NULL, env->gui->screen, dest); SDL_BlitSurface(gui->keypad, NULL, gui->screen, dest);
SDL_UpdateRects(env->gui->screen, 1, dest); SDL_UpdateRects(gui->screen, 1, dest);
} }
env->in.dec_in_cur = &env->in.dec_in[0]; env->in.dec_in_cur = &env->in.dec_in[0];
env->in.dec_in_dpy = NULL; /* nothing to display */ env->in.dec_in_dpy = NULL; /* nothing to display */
@ -823,7 +826,7 @@ static void sdl_setup(struct video_desc *env)
no_sdl: no_sdl:
if (!sdl_ok) /* free resources in case of errors */ if (!sdl_ok) /* free resources in case of errors */
env->gui = cleanup_sdl(env->gui); env->gui = cleanup_sdl(gui);
} }
/* /*

Loading…
Cancel
Save