mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	Animate overlay on/off.
This commit is contained in:
		
							parent
							
								
									cddc0ad502
								
							
						
					
					
						commit
						9af92b380c
					
				
					 2 changed files with 38 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -36,6 +36,7 @@ struct egl_compositor {
 | 
			
		|||
	struct egl_surface *pointer;
 | 
			
		||||
	struct egl_surface *background;
 | 
			
		||||
	struct egl_surface *overlay;
 | 
			
		||||
	int32_t overlay_target, overlay_previous;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct egl_surface {
 | 
			
		||||
| 
						 | 
				
			
			@ -468,6 +469,9 @@ draw_surface(struct egl_surface *es)
 | 
			
		|||
	glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_INT, indices);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
schedule_repaint(struct egl_compositor *ec);
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
repaint(void *data)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -475,6 +479,8 @@ repaint(void *data)
 | 
			
		|||
	struct wl_surface_iterator *iterator;
 | 
			
		||||
	struct wl_surface *surface;
 | 
			
		||||
	struct egl_surface *es;
 | 
			
		||||
	double force;
 | 
			
		||||
	int32_t y;
 | 
			
		||||
 | 
			
		||||
	draw_surface(ec->background);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -493,6 +499,26 @@ repaint(void *data)
 | 
			
		|||
	draw_surface(ec->pointer);
 | 
			
		||||
 | 
			
		||||
	eglSwapBuffers(ec->display, ec->surface);
 | 
			
		||||
 | 
			
		||||
	y = ec->overlay->map.y;
 | 
			
		||||
	force = (ec->overlay_target - ec->overlay->map.y) / 25.0 + 
 | 
			
		||||
		(ec->overlay_previous - y) / 25.0;
 | 
			
		||||
	
 | 
			
		||||
	ec->overlay->map.y = y + (y - ec->overlay_previous) + force;
 | 
			
		||||
	ec->overlay_previous = y;
 | 
			
		||||
 | 
			
		||||
	if (ec->overlay->map.y >= 800) {
 | 
			
		||||
		ec->overlay->map.y = 800;
 | 
			
		||||
		ec->overlay_previous = 800;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (ec->overlay->map.y <= 600) {
 | 
			
		||||
		ec->overlay->map.y = 600;
 | 
			
		||||
		ec->overlay_previous = 600;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (ec->overlay->map.y != y)
 | 
			
		||||
		schedule_repaint(ec);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
| 
						 | 
				
			
			@ -637,8 +663,13 @@ notify_key(struct wl_compositor *compositor,
 | 
			
		|||
{
 | 
			
		||||
	struct egl_compositor *ec = (struct egl_compositor *) compositor;
 | 
			
		||||
 | 
			
		||||
	if (key == KEY_ESC)
 | 
			
		||||
	if (key == KEY_ESC && state == 1) {
 | 
			
		||||
		if (ec->overlay_target == ec->height)
 | 
			
		||||
			ec->overlay_target -= 200;
 | 
			
		||||
		else
 | 
			
		||||
			ec->overlay_target += 200;
 | 
			
		||||
		schedule_repaint(ec);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const struct wl_compositor_interface interface = {
 | 
			
		||||
| 
						 | 
				
			
			@ -749,7 +780,9 @@ wl_compositor_create(struct wl_display *display)
 | 
			
		|||
		filename = "background.jpg";
 | 
			
		||||
	ec->background = background_create(filename, 1280, 800);
 | 
			
		||||
	ec->pointer = pointer_create(100, 100, 64, 64);
 | 
			
		||||
	ec->overlay = overlay_create(0, ec->height - 200, ec->width, 200);
 | 
			
		||||
	ec->overlay = overlay_create(0, ec->height, ec->width, 200);
 | 
			
		||||
	ec->overlay_target = ec->height;
 | 
			
		||||
	ec->overlay_previous = ec->height;
 | 
			
		||||
 | 
			
		||||
	ec->gem_fd = open(gem_device, O_RDWR);
 | 
			
		||||
	if (ec->gem_fd < 0) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -133,6 +133,7 @@ wl_event_loop_wait(struct wl_event_loop *loop)
 | 
			
		|||
{
 | 
			
		||||
	struct epoll_event ep[32];
 | 
			
		||||
	struct wl_event_source *source;
 | 
			
		||||
	wl_event_loop_idle_func_t idle_func;
 | 
			
		||||
	int i, count, timeout;
 | 
			
		||||
	uint32_t mask;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -157,8 +158,9 @@ wl_event_loop_wait(struct wl_event_loop *loop)
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	if (count == 0 && loop->idle_func != NULL) {
 | 
			
		||||
		loop->idle_func(loop->idle_data);
 | 
			
		||||
		idle_func = loop->idle_func;
 | 
			
		||||
		loop->idle_func = NULL;
 | 
			
		||||
		idle_func(loop->idle_data);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return 0;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue