#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Emotion.h>
#include <Esmart/Esmart_Trans_X11.h>

Evas_Object *video;

/* if the window manager requests a delete - quit cleanly */
static void
canvas_delete_request(Ecore_Evas *ee)
{
   ecore_main_loop_quit();
}

/* if the canvas is resized - resize the video too */
static void
canvas_resize(Ecore_Evas *ee)
{
   Evas_Coord w, h;
   
   evas_output_viewport_get(ecore_evas_get(ee), NULL, NULL, &w, &h);
   evas_object_move(video, 0, 0);
   evas_object_resize(video, w, h);
}

/* the main function of the program */
int main(int argc, char **argv)
{
   Ecore_Evas *ee;
   Evas_Object *bg;
   int x,y,w,h;

   /* create a canvas, display it, set a title, callbacks to call on resize */
   /* or if the window manager asks it to be deleted */
   ecore_evas_init();
   ee = ecore_evas_software_x11_new(NULL, 0, 0, 0, 800, 600);
   ecore_evas_callback_delete_request_set(ee, canvas_delete_request);
   ecore_evas_callback_resize_set(ee, canvas_resize);   
   ecore_evas_title_set(ee, "My DVD Player");
   ecore_evas_name_class_set(ee, "my_dvd_player", "My_DVD_Player");
   ecore_evas_borderless_set(ee, 1);
   bg = esmart_trans_x11_new(ecore_evas_get(ee));
   esmart_trans_x11_type_set(bg, Esmart_Trans_X11_Type_Screengrab);
   esmart_trans_x11_window_set(bg, ecore_evas_software_x11_window_get(ee));
   evas_object_move(bg, 0, 0);
   evas_object_resize(bg, 800, 600);
   evas_object_layer_set(bg, -99);
   evas_object_name_set(bg, "background");
   evas_object_show(bg);
   ecore_evas_show(ee);
   ecore_evas_move_resize(ee, 0, 0, 800, 340);
   ecore_evas_geometry_get(ee, &x, &y, &w, &h);
   esmart_trans_x11_freshen(bg, x, y, w, h);

   /* create a video object */
   video = emotion_object_add(ecore_evas_get(ee));
   evas_object_color_set(video, 255, 255, 255, 144);
   emotion_object_file_set(video, "/barn/media/The Italian Job (1969).avi");
   emotion_object_play_set(video, 1);
   evas_object_show(video);

   /* force an initial resize */
   canvas_resize(ee);
   
   /* run the main loop of the program - playing, drawing, handling events */
   ecore_main_loop_begin();
   
   /* if we exit the main loop we will shut down */
   ecore_evas_shutdown();
}

