/*
 *  Copyright (C) by Y.Ishioka 2012-2013
 */
#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>
#include <WSCvdrawingArea.h>

#include <string.h>
#include <demo_main.h>

extern const char  *yi_studio_jpg_name  ;
extern const int  yi_studio_jpg_size ;
extern const unsigned char  yi_studio_jpg[] ;

char  demo_imagename[128] ;


/*
 * Set Image file name
 */
void  demo_draw_set_file( char *name, char *date )
{
    if( strcmp( demo_imagename, name ) != 0 ) {
        strcpy( demo_imagename, (const char*)name ) ;
    }

    demo_main->setAbsoluteDraw(True);
    demo_main->draw();
    demo_main->redraw();
}


/*
 * Init Draw Image
 */
void  demo_draw_init( void )
{
    FILE  *fp ;

    /* make yi_studio_jpg */
    fp = fopen( yi_studio_jpg_name, "r" ) ;
    if( fp == NULL ) {
        fp = fopen( yi_studio_jpg_name, "wb" ) ;
        fwrite( yi_studio_jpg, 1, yi_studio_jpg_size, fp ) ;
    }
    fclose( fp ) ;

    strcpy( demo_imagename, "yi_studio.jpg" ) ;
}



//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
void demo_drawimage(WSCbase* object){
    WSCvdrawingArea*  drawing_a  = demvdra_000 ;

    if( demo_imagename[0] != 0x00 ) {
        drawing_a->drawStretchedImage( 0,0,320,240, demo_imagename );
    }
}
static WSCfunctionRegister  op("demo_drawimage",(void*)demo_drawimage);
