www.pudn.com > cxgdkh.rar > systemboot.c



/*
 *	systemboot.c
 */
#define MWINCLUDECOLORS
#include 
#include 
#include 
#include 
#include 

GR_WINDOW_ID 	wid;
GR_GC_ID    	gc;
GR_EVENT	event;
GR_IMAGE_ID 	image;
GR_WINDOW_INFO	info;
GR_IMAGE_INFO 	imageinfo;
GR_GC_ID     	gc2;
GR_WINDOW_ID	wid2;

#define PROGRESS_LOGO_X 	170
#define PROGRESS_LOGO_Y		320
#define PROGRESS_LOGO_LEN 	300
#define PROGRESS_LOGO_HEIGHT	12

#define GetMS(t)	       (((t.tv_sec &0xFF) * 1000) + (t.tv_usec / 1000))

#define LOCK(M)			pthread_mutex_lock(M)
#define UNLOCK(M)		pthread_mutex_unlock(M)

static	int SystemStat = 0;
static	int LoadStep  = 0;
static	int LastStep  = 0;
static	int RecodTime = 0;

void showphoto();
void* progress();
void systemboot();
void thread();

int main()
{
    while(1) {
    showphoto();
    SystemBoot();
    // thread();
    }
}

void showphoto()
{
    if (GrOpen() < 0) {
	fprintf(stderr, "GrOpen failed!!");
	exit(1);
    }

    wid = GrNewWindowEx(GR_WM_PROPS_APPFRAME,
			NULL, GR_ROOT_WINDOW_ID,
			0, 0, 640, 480, BLACK);
    gc = GrNewGC();
    GrSetGCUseBackground(gc, GR_FALSE);
    GrSetGCForeground(gc, WHITE);

    image = GrLoadImageFromFile("tux.gif", 0);
    
    GrSelectEvents(wid, GR_EVENT_MASK_EXPOSURE | 
		   GR_EVENT_MASK_TIMER |
		   GR_EVENT_MASK_BUTTON_UP |
		   GR_EVENT_MASK_BUTTON_DOWN |
		   GR_EVENT_MASK_KEY_UP |
		   GR_EVENT_MASK_KEY_DOWN |
		   GR_EVENT_MASK_NONE |
		   GR_EVENT_MASK_CLOSE_REQ);
    GrMapWindow(wid);
    
    while(1){
	GrGetNextEvent(&event);
	GrCheckNextEvent(&event);

	switch(event.type) {
	case GR_EVENT_TYPE_EXPOSURE:	   	
	    /*  GrGetImageInfo(image, &imageinfo);
		GrDrawImageToFit(wid, gc, 
			     (640-imageinfo.width) / 2,
			     (450-imageinfo.height) / 2,
			     imageinfo.width,
			     imageinfo.height,
			     image);  */
	    break;
	case GR_EVENT_TYPE_TIMER:
	    break;
	case GR_EVENT_TYPE_BUTTON_UP:
	    break;
	case GR_EVENT_TYPE_BUTTON_DOWN:
	    break;
	case GR_EVENT_TYPE_KEY_UP:
	    break;
	case GR_EVENT_TYPE_KEY_DOWN:	   
	    break;
	case GR_EVENT_TYPE_CLOSE_REQ:
	    GrClose();
	    exit(0);  
	    break;
	case GR_EVENT_TYPE_NONE:
	    // SystemBoot();
	    GrGetImageInfo(image, &imageinfo);
	    GrDrawImageToFit(wid, gc, 
			     (640-imageinfo.width) / 2,
			     (450-imageinfo.height) / 2,
			     imageinfo.width,
			     imageinfo.height,
			     image);
	    break;
	default:
	    break;
	}
    }
}



int SystemBoot()
{
    struct timeval t;
    int time;

    if (LoadStep > PROGRESS_LOGO_LEN) {
	return;
    }
   
    gc = GrNewGC();
    GrSetGCUseBackground(gc, GR_FALSE);
    GrSetGCForeground(gc, WHITE);

    image = GrLoadImageFromFile("tux.gif", 0);

    gettimeofday(&t, NULL);
    time = GetMS(t);
    if (time - RecodTime > 1000) {
	RecodTime = time;
	GrLine(wid, gc, PROGRESS_LOGO_X + LoadStep, 
	       PROGRESS_LOGO_Y + 1, PROGRESS_LOGO_X + LoadStep, 
	       PROGRESS_LOGO_Y + PROGRESS_LOGO_HEIGHT - 3);	
       
	GrFillRect(wid, gc, PROGRESS_LOGO_X,
		   PROGRESS_LOGO_Y + 1,
		   LoadStep,
		   PROGRESS_LOGO_HEIGHT -3);
	LoadStep += 30;
    }
}



//void thread()
//{