[asterisk-commits] rizzo: branch group/video_console r90545 - /team/group/video_console/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 3 11:36:39 CST 2007


Author: rizzo
Date: Mon Dec  3 11:36:38 2007
New Revision: 90545

URL: http://svn.digium.com/view/asterisk?view=rev&rev=90545
Log:
support full dragging of the x11 window


Modified:
    team/group/video_console/channels/console_video.c

Modified: team/group/video_console/channels/console_video.c
URL: http://svn.digium.com/view/asterisk/team/group/video_console/channels/console_video.c?view=diff&rev=90545&r1=90544&r2=90545
==============================================================================
--- team/group/video_console/channels/console_video.c (original)
+++ team/group/video_console/channels/console_video.c Mon Dec  3 11:36:38 2007
@@ -167,8 +167,8 @@
 #ifdef HAVE_X11
 	Display		*dpy;			/* x11 grabber info */
 	XImage		*image;
-	int		X_max_width;	/* max width of X screen */
-	int		X_max_height;	/* max height of X screen */
+	int		screen_width;	/* width of X screen */
+	int		screen_height;	/* height of X screen */
 #endif
 };
 
@@ -1364,8 +1364,8 @@
 
 	/* find width and height of the screen */
 	screen_num = DefaultScreen(v->dpy);
-	v->X_max_width = DisplayWidth(v->dpy, screen_num);
-	v->X_max_height = DisplayHeight(v->dpy, screen_num);
+	v->screen_width = DisplayWidth(v->dpy, screen_num);
+	v->screen_height = DisplayHeight(v->dpy, screen_num);
 
 	v->image = im = XGetImage(v->dpy,
 		RootWindow(v->dpy, DefaultScreen(v->dpy)),
@@ -1459,9 +1459,6 @@
 		goto error;
 	}
 	ast_log(LOG_WARNING, "success opening camera\n");
-
-	/* XXX don't know if this is really needed */
-	v->X_max_width = v->X_max_height = 0;
     }
 #endif /* HAVE_VIDEODEV_H */
 
@@ -1473,6 +1470,7 @@
 error:
 	ast_log(LOG_WARNING, "fd %d dpy %p img %p data %p\n",
 		v->fd, v->dpy, v->image, v->loc_src.data);
+	/* XXX maybe XDestroy (v->image) ? */
 	if (v->dpy)
 		XCloseDisplay(v->dpy);
 	v->dpy = NULL;
@@ -2469,17 +2467,16 @@
  */
 static int boundary_checks(int x, int limit)
 {
-	/* res = (x <= 0) ? 0 : ((x > limit) ? limit : x); */
-
-	if (x <= 0)
-		return 0;
-
-	if (x > limit)
-		return limit;
-
-	return x;
-}
-	
+	return (x <= 0) ? 0 : (x > limit ? limit : x);
+}
+
+/* implement superlinear acceleration on the movement */
+static int move_accel(int delta)
+{
+	int d1 = delta*delta / 100;
+	return (delta > 0) ? delta + d1 : delta - d1;
+}
+
 /*
  * Move the source of the captured video.
  *
@@ -2489,33 +2486,21 @@
 static void move_capture_source(struct video_desc *env, int x_final_drag, int y_final_drag)
 {
 	int new_x, new_y;		/* new coordinates for grabbing local video */
-	int x = env->out.loc_src.x;	/* temporary, used to print the old x value */
-	int y = env->out.loc_src.y;	/* temporary, used to print the old y value */
-
-	/* compute new coordinates */
-	#define X_MAG 3
-	#define Y_MAG 2
-#if 0
-	/* move the source in the direction of the mouse */
-	new_x = env->out.loc_src.x + (x_final_drag - env->gui.x_drag) * X_MAG;
-	new_y = env->out.loc_src.y + (y_final_drag - env->gui.y_drag) * Y_MAG;
-#else
-	/* drag */
-	new_x = env->out.loc_src.x + (env->gui.x_drag - x_final_drag) * X_MAG;
-	new_y = env->out.loc_src.y + (env->gui.y_drag - y_final_drag) * Y_MAG;
-#endif
+	int x = env->out.loc_src.x;	/* old value */
+	int y = env->out.loc_src.y;	/* old value */
+
+	/* move the origin */
+#define POLARITY -1		/* +1 or -1 depending on the desired direction */
+	new_x = x + POLARITY*move_accel(x_final_drag - env->gui.x_drag) * 3;
+	new_y = y + POLARITY*move_accel(y_final_drag - env->gui.y_drag) * 3;
+#undef POLARITY
+	env->gui.x_drag = x_final_drag;	/* update origin */
+	env->gui.y_drag = y_final_drag;
 
 	/* check boundary and let the source to grab from the new points */
-	env->out.loc_src.x = boundary_checks(new_x, env->out.X_max_width - env->out.loc_src.w);
-	env->out.loc_src.y = boundary_checks(new_y, env->out.X_max_height - env->out.loc_src.h);
-
-	ast_log(LOG_WARNING, "Computing new grab values, start grab points %d %d, \
-				end grab points (with magnifier) %d %d, \
-				boundary checked points %d %d\n",
-				x, y, new_x, new_y, env->out.loc_src.x , env->out.loc_src.y);
-
-return;
-
+	env->out.loc_src.x = boundary_checks(new_x, env->out.screen_width - env->out.loc_src.w);
+	env->out.loc_src.y = boundary_checks(new_y, env->out.screen_height - env->out.loc_src.h);
+	return;
 }
 
 /*
@@ -2543,12 +2528,18 @@
 			case SDL_KEYDOWN:
 				handle_keyboard_input(env, ev[i].key.keysym.sym);
 				break;
+			case SDL_MOUSEMOTION:
+				if (env->gui.drag_mode != 0)
+					move_capture_source(env, ev[i].motion.x, ev[i].motion.y);
+				break;
 			case SDL_MOUSEBUTTONDOWN:
 				handle_button_event(env, ev[i].button.x, ev[i].button.y);
 				break;
 			case SDL_MOUSEBUTTONUP:
-				if (env->gui.drag_mode != 0)
+				if (env->gui.drag_mode != 0) {
 					move_capture_source(env, ev[i].button.x, ev[i].button.y);
+					env->gui.drag_mode = 0;
+				}
 				break;
 			}
 
@@ -2874,9 +2865,11 @@
 		env->out.keypad_dpy.w = env->gui.keypad->w;
 		env->out.keypad_dpy.h = env->gui.keypad->h;
 	}
-
+#define BORDER	5	/* border around our windows */
 	maxw = env->in.rem_dpy.w + env->out.loc_dpy.w + env->out.keypad_dpy.w;
 	maxh = MAX( MAX(env->in.rem_dpy.h, env->out.loc_dpy.h), env->out.keypad_dpy.h);
+	maxw += 4 * BORDER;
+	maxh += 2 * BORDER;
 	env->screen = SDL_SetVideoMode(maxw, maxh, 0, 0);
 	if (!env->screen) {
 		ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n");
@@ -2884,10 +2877,11 @@
 	}
 	SDL_WM_SetCaption("Asterisk console Video Output", NULL);
 	if (set_win(env->screen, &env->win[WIN_REMOTE], dpy_fmt,
-			env->in.rem_dpy.w, env->in.rem_dpy.h, 0, 0))
+			env->in.rem_dpy.w, env->in.rem_dpy.h, BORDER, BORDER))
 		goto no_sdl;
 	if (set_win(env->screen, &env->win[WIN_LOCAL], dpy_fmt,
-			env->out.loc_dpy.w, env->out.loc_dpy.h, env->in.rem_dpy.w + env->out.keypad_dpy.w, 0))
+			env->out.loc_dpy.w, env->out.loc_dpy.h,
+			3*BORDER+env->in.rem_dpy.w + env->out.keypad_dpy.w, BORDER))
 		goto no_sdl;
 
 	/* display the skin, but do not free it as we need it later to
@@ -2895,8 +2889,8 @@
 	 */
 	if (env->gui.keypad) {
 		struct SDL_Rect *dest = &env->win[WIN_KEYPAD].rect;
-		dest->x = env->in.rem_dpy.w;
-		dest->y = 0;
+		dest->x = 2*BORDER + env->in.rem_dpy.w;
+		dest->y = BORDER;
 		dest->w = env->gui.keypad->w;
 		dest->h = env->gui.keypad->h;
 		SDL_BlitSurface(env->gui.keypad, NULL, env->screen, dest);




More information about the asterisk-commits mailing list