Esempio n. 1
0
BOOL CObjectIcon::LoadImage(UINT idx, char* pImageFilePath)
{
	if( (m_pImage==NULL) || (m_nImgCount==0) )
	{
		printf("%s: Image Count Not Allocated\r\n", __func__);
		return FALSE;
	}

	if(idx >= m_nImgCount)
	{
		printf("%s: Invalid Image Index(%d), Max=%d\r\n", __func__, idx, m_nImgCount);
		return FALSE;
	}

	if(pImageFilePath == NULL)
	{
		printf("%s: Invalid File Path\r\n", __func__);
		return FALSE;
	}

	m_pImage[idx] = GrLoadImageFromFile(pImageFilePath, 0);
	if(m_pImage[idx] == 0)
	{
		printf("%s: GrLoadImageFromFile, %s\r\n", __func__, pImageFilePath);
		return FALSE;
	}

//	printf("%s: '%s' loaded at %d\r\n", __func__, pImageFilePath, idx);

	return TRUE;
}
Esempio n. 2
0
static void
GrLoadImageFromFileWrapper(void *r)
{
	nxLoadImageFromFileReq *req = r;
	GR_IMAGE_ID		id;

	id = GrLoadImageFromFile(GetReqData(req), req->flags);
	GsWriteType(current_fd, GrNumLoadImageFromFile);
	GsWrite(current_fd, &id, sizeof(id));
}
Esempio n. 3
0
//------------------------------------------------------------------------------
// Function Name  : ui_load_icon_img()
// Description    :
//------------------------------------------------------------------------------
int ui_load_icon_img(obj_icon_t *_h, int _idx, char *_path)
{
	if (_idx >= MAX_ICON_IMG_CNT) {
		DBG_MSG_CO(CO_RED, "<%s> Invalid index\r\n", __func__);
		return -1;
	}
	
	_h->imgs[_idx] = GrLoadImageFromFile(_path, 0);
	
	return 1;
}
Esempio n. 4
0
BOOL CObjectPlatButton::LoadImage(UINT idx, char* pImageFilePath)
{
	if(pImageFilePath == NULL)
	{
		printf("%s: Invalid File Path\r\n", __func__);
		return FALSE;
	}

	m_Image = GrLoadImageFromFile(pImageFilePath, 0);
	if(m_Image == 0)
	{
		printf("%s: GrLoadImageFromFile, %s\r\n", __func__, pImageFilePath);
		return FALSE;
	}

//	printf("%s: '%s' loaded at %d\r\n", __func__, pImageFilePath, idx);

	return FALSE;
}
Esempio n. 5
0
static void mappaint(){
int x=0;
int i=0;
int p=0;
	GrSetGCForeground(keyman_gc, BLACK);
	kmimage_id=GrLoadImageFromFile(pathimage,0);
	yomipict_pixmap=GrNewPixmap(384,128,NULL);
	allmap_pixmap=GrNewPixmap(160,(TATEHABA*16),NULL);
	GrDrawImageToFit(yomipict_pixmap,keyman_gc,0,0,384,128,kmimage_id);
	
	for (i=0;i<=(TATEHABA-1);i++){
	
		for (p=0;p<=9;p++){
			x=pictx(wyomidata.mapd[p][i]);
			GrCopyArea(allmap_pixmap,keyman_gc,(p*16),(i*16),16,16,yomipict_pixmap,x,0,0);
			

		}
	}
}
Esempio n. 6
0
/**
 * Load image from filename and return its ID
*/
GR_WINDOW_ID theme_load_image(char * filename)
{
	GR_GC_ID gc;
	GR_IMAGE_ID iid;
	GR_WINDOW_ID pid;
	GR_IMAGE_INFO iif;

	gc = GrNewGC();
	if(!(iid = GrLoadImageFromFile(filename, 0))) {
		fprintf(stderr, "Failed to load image file \"%s\"\n", filename);
		return 0;
	}
	GrGetImageInfo(iid, &iif);
	pid = GrNewPixmap(iif.width, iif.height, NULL);

	GrDrawImageToFit(pid, gc, 0, 0, iif.width, iif.height, iid);
	GrDestroyGC(gc);
	GrFreeImage(iid);

	return pid;
}
Esempio n. 7
0
void new_keyman_window( void )
{
	
    keyman_gc = GrNewGC();
    GrSetGCUseBackground(keyman_gc, GR_FALSE);
    GrSetGCForeground(keyman_gc, WHITE);
	GrGetScreenInfo(&screen_info);
	
	yomipict_pixmap=GrNewPixmap(384,128,NULL);
	mainmenu_pixmap=GrNewPixmap(160,128,NULL);
	shu_pixmap=GrNewPixmap(16,16,NULL);
	dialogall_pixmap=GrNewPixmap(96,80,NULL);
	dialog_pixmap=GrNewPixmap(96,80,NULL);
	
	
    keyman_wid = pz_new_window(0, 0, 
	screen_info.cols, screen_info.rows, 
	keyman_do_draw, keyman_handle_event);

		
	if (!(kmimage_id=GrLoadImageFromFile(pathimage,0))){
		GAMEN=NODATA;
		
	}
	else {
		GAMEN=MENU;
		GrDrawImageToFit(yomipict_pixmap,keyman_gc,0,0,384,128,kmimage_id);
		makedialog();
	}
	
	

    GrSelectEvents( keyman_wid, GR_EVENT_MASK_TIMER|
	GR_EVENT_MASK_EXPOSURE|GR_EVENT_MASK_KEY_UP|GR_EVENT_MASK_KEY_DOWN);

    keyman_timer = GrCreateTimer( keyman_wid, 90 );
    GrMapWindow( keyman_wid );
    pz_draw_header( "KeyMan" );
}
Esempio n. 8
0
//------------------------------------------------------------------------------
// Function Name  : ui_create_img_obj()
// Description    :
//------------------------------------------------------------------------------
obj_img_t *ui_create_img_obj(int x, int y, int w, int h, char *_path)
{
	obj_img_t *obj_h = NULL;

	if (_path == NULL) {
		return NULL;
	}
	
	obj_h = malloc(sizeof(obj_img_t));
	if (obj_h != NULL) {
		memset(obj_h, 0, sizeof(obj_img_t));
		obj_h->rect.x = x;
		obj_h->rect.y = y;
		obj_h->rect.w = w;
		obj_h->rect.h = h;
		obj_h->gc = g_gc;
		obj_h->wid = g_wid;
		obj_h->img = GrLoadImageFromFile(_path, 0);
	} else {
		DBG_MSG_CO(CO_RED, "<%s> obj create failed\r\n");
	}
	
	return obj_h;
}
Esempio n. 9
0
BOOL CObjectCheck::LoadImage(UINT idx, char* pImageFilePath)
{
	if(idx >= IMG_BUTTON_COUNT)
	{
		printf("%s: Invalid Image Index(%d), Max=%d\r\n", __func__, idx, IMG_BUTTON_COUNT);
		return FALSE;
	}
	if(pImageFilePath == NULL)
	{
		printf("%s: Invalid File Path\r\n", __func__);
		return FALSE;
	}

	m_Image[idx] = GrLoadImageFromFile(pImageFilePath, 0);
	if(m_Image[idx] == 0)
	{
		printf("%s: GrLoadImageFromFile, %s\r\n", __func__, pImageFilePath);
		return FALSE;
	}

//	printf("%s: '%s' loaded at %d\r\n", __func__, pImageFilePath, idx);

	return TRUE;
}
Esempio n. 10
0
void
show_jpeg(int client, char *file, int show_time)
{
    GR_EVENT        event;          /* current event */
    GR_IMAGE_ID     id = 0;
    GR_SIZE         w = -1;
    GR_SIZE         h = -1;
    GR_IMAGE_INFO   info;
    GR_WINDOW_ID    w1;             /* id for large window */
    GR_GC_ID        gc1;            /* graphics context for text */
    GR_SCREEN_INFO  si;

    int time_left;
    bool ever_exposed = false;

#if !defined(HAVE_JPEG_SUPPORT) && !defined(HAVE_BMP_SUPPORT) && !defined(HAVE_GIF_SUPPORT)
    printf("Sorry, no image support compiled in\n");
    exit(1);        
#endif

    GrGetScreenInfo(&si);
    printf("Loading image: %s\n", file);
    if (access(file, F_OK) < 0) {
        fdprintf(client, "Can't access \"%s\": %s\n", file, strerror(errno));
        return;
    }
    id = GrLoadImageFromFile(file, 0);
    if (id) {
        GrGetImageInfo(id, &info);
    } else {
        // File exists, so why the error?
        int fd, len;
        char buf[64];
        fdprintf(client, "Can't load %s\n", file);
        if ((fd = open(file, O_RDONLY)) >= 0) {
            len = read(fd, buf, 64);
            if (len != 64) {
                diag_printf("Short read? len = %d\n", len);
            } else {
                diag_dump_buf(buf, len);
            }
            close(fd);
        } else {
            diag_printf("Can't oopen \"%s\": %s\n",  file, strerror(errno));
        }
        return;
    }

    w = info.width;
    h = info.height;
    if ((si.rows < info.height) || (si.cols < info.width)) {
        // Preserve aspect ratio
        if (si.cols < info.width) {
            w = si.cols;
            h = (si.cols * info.height) / info.width;
        }
        if (si.rows < h) {
            w = (si.rows * w) / h;
            h = si.rows;
        }
    }
    printf("Create window - orig %dx%d => %dx%d\n", info.width, info.height, w, h);
    fdprintf(client, "<INFO> Display \"%s\" - orig %dx%d => %dx%d\n", file, info.width, info.height, w, h);
    w1 = GrNewWindow(GR_ROOT_WINDOW_ID, 10, 10, w, h, 4, BLACK, WHITE);
    GrSelectEvents(w1, GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);
    GrMapWindow(w1);
    gc1 = GrNewGC();
    GrSetGCForeground(gc1, WHITE);

#define TO_MS 50
    time_left = show_time * 1000;
    while (time_left > 0) {
        GrGetNextEventTimeout(&event, TO_MS);  // milliseconds
        switch(event.type) {
        case GR_EVENT_TYPE_CLOSE_REQ:
            GrDestroyWindow(w1);
            GrFreeImage(id);
            return;
            /* no return*/
        case GR_EVENT_TYPE_EXPOSURE:
            /*GrDrawImageFromFile(w1, gc1, 0, 0, w, h, argv[1],0);*/
            GrDrawImageToFit(w1, gc1, 0, 0, w, h, id);
            ever_exposed = true;
            break;
        default:
        case GR_EVENT_TYPE_NONE:
        case GR_EVENT_TYPE_TIMEOUT:
            time_left -= TO_MS;
            if ((time_left < 0) && !ever_exposed) {
                // Things get real cranky if we delete the window too fast!
                time_left = TO_MS;
            }
            break;
        }
    }    
    GrUnmapWindow(w1);
    GrDestroyWindow(w1);
    GrDestroyGC(gc1);
    GrFreeImage(id);
}
Esempio n. 11
0
void initialise(lstate *state)
{
	GR_SCREEN_INFO si;
	GR_IMAGE_ID back_image;
	GR_IMAGE_INFO imageinfo;
	int rows = 1, columns = 1, width, height, x = 0, y = 0;
	GR_WM_PROPERTIES props;
	litem *i;

	if(GrOpen() < 0) {
		GrError("Couldn't connect to Nano-X server\n");
		exit(4);
	}

	state->window_background_mode = 0;
	state->window_background_image = NULL;
	sspid = -1;

	read_config(state);

	GrGetScreenInfo(&si);

	if(si.rows > si.cols) {
		rows = state->numlitems;
		while((((rows / columns) + rows % columns) * ITEM_HEIGHT) >
								si.rows) {
			columns++;
		}
		if((columns * ITEM_WIDTH) > si.cols) goto toomany;
		rows = (rows / columns) + (rows % columns);
		width = columns * ITEM_WIDTH + 1 + columns;
		height = rows * ITEM_HEIGHT + 1 + rows;
	} else {
		columns = state->numlitems;
		while((((columns / rows) + (columns % rows)) * ITEM_WIDTH) >
								si.cols) {
			rows++;
		}
		if((rows * ITEM_HEIGHT) > si.rows) goto toomany;
		columns = (columns / rows) + (columns % rows);
		width = columns * ITEM_WIDTH + 1 + columns;
		height = (rows * ITEM_HEIGHT) + 1 + rows;
		y = si.rows - (rows * ITEM_HEIGHT) - 1 - rows;
	}

	state->gc = GrNewGC();
	GrSetGCForeground(state->gc, ITEM_TEXT_COLOUR);
	GrSetGCBackground(state->gc, ITEM_BACKGROUND_COLOUR);

	if(state->window_background_image) {
		if(!(back_image = GrLoadImageFromFile(
					state->window_background_image, 0))) {
			GrError("Couldn't load background image\n");
		} else {
			GrGetImageInfo(back_image, &imageinfo);
			if(!(state->background_pixmap = GrNewPixmap(
							imageinfo.width,
						imageinfo.height, NULL))) {
				GrError("Couldn't allocate pixmap "	
						"for background image\n");
			} else {
				GrDrawImageToFit(state->background_pixmap,
					state->gc, 0, 0, imageinfo.width,
					imageinfo.height, back_image);
				GrFreeImage(back_image);
				GrSetBackgroundPixmap(GR_ROOT_WINDOW_ID,
					state->background_pixmap,
					state->window_background_mode);
				GrClearWindow(GR_ROOT_WINDOW_ID, GR_TRUE);
			}
		}
	}

	if(state->ssitems)
		GrSelectEvents(GR_ROOT_WINDOW_ID, GR_EVENT_MASK_SCREENSAVER);

	state->main_window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, y, width, height,
						0, ITEM_BACKGROUND_COLOUR, 0);
	GrSelectEvents(state->main_window, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_TIMER);
	props.flags = GR_WM_FLAGS_PROPS;
	props.props = GR_WM_PROPS_NOMOVE | GR_WM_PROPS_NODECORATE | GR_WM_PROPS_NOAUTOMOVE | GR_WM_PROPS_NOAUTORESIZE;
	GrSetWMProperties(state->main_window, &props);

	i = state->lastlitem;
	y = 0;
	while(i) {
		i->wid = GrNewWindow(state->main_window,
					(x * ITEM_WIDTH) + x + 1,
					(y * ITEM_HEIGHT) + y + 1, ITEM_WIDTH,
					ITEM_HEIGHT, 1, ITEM_BACKGROUND_COLOUR, ITEM_BORDER_COLOUR);
		GrSelectEvents(i->wid, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN);
		GrMapWindow(i->wid);
		i = i->prev;
		if(++x == columns) {
			x = 0;
			y++;
		}
	}

	GrMapWindow(state->main_window);

	signal(SIGCHLD, &reaper);

	do_startups(state);

	return;

toomany:
	GrError("Too many items to fit on screen\n");
	exit(6);
}
Esempio n. 12
0
void parse_config_line(lstate *state, char *buf, int lineno)
{
	char *p, *pp, *name, *icon;
	int n;
	litem *new_litem, *li;
	ssitem *new_ssitem, *tmp_ssitem;
	stitem *new_stitem, *tmp_stitem;
	GR_IMAGE_INFO imageinfo;

	p = buf;

	if((!*p) || (*p == '#') || (*p == '\n')) return;

	while(isspace(*p)) p++;
	name = p;
	while(*p && (!isspace(*p))) p++;
	if(!*p) goto premature;
	*p++ = 0;

	if(!strcmp(name, "$screensaver")) {
		new_ssitem = my_malloc(sizeof(ssitem));
		if(!(new_ssitem->prog = make_prog_item(p, lineno))) {
			free(new_ssitem);
			return;
		}
		state->numssitems++;
		new_ssitem->next = NULL;
		if(!state->ssitems) state->ssitems = new_ssitem;
		else {
			tmp_ssitem = state->ssitems;
			while(tmp_ssitem->next) tmp_ssitem = tmp_ssitem->next;
			tmp_ssitem->next = new_ssitem;
		}
		return;
	} else if(!strcmp(name, "$startup")) {
		new_stitem = my_malloc(sizeof(stitem));
		if(!(new_stitem->prog = make_prog_item(p, lineno))) {
			free(new_stitem);
			return;
		}
		new_stitem->next = NULL;
		if(!state->stitems) state->stitems = new_stitem;
		else {
			tmp_stitem = state->stitems;
			while(tmp_stitem->next) tmp_stitem = tmp_stitem->next;
			tmp_stitem->next = new_stitem;
		}
		return;
	} else if(!strcmp(name, "$screensaver_timeout")) {
		n = strtol(p, NULL, 10);
		GrSetScreenSaverTimeout(n);
		return;
	} else if(!strcmp(name, "$screensaver_rotate_time")) {
		state->rotatess = strtol(p, NULL, 10);
		return;
	} else if(!strcmp(name, "$random_screensaver")) {
		srand(time(0));
		state->randomss = 1;
		return;
	} else if(!strcmp(name, "$window_background_image")) {
		while(isspace(*p)) p++;
		if(!*p) goto premature;
		pp = p;
		while(*p && (!isspace(*p))) p++;
		*p = 0;
		state->window_background_image = strdup(pp);
		return;
	} else if(!strcmp(name, "$window_background_mode")) {
		state->window_background_mode = (int) strtol(p, NULL, 10);
		return;
	} else if(!strcmp(name, "$window_background_colour")) {
		set_window_background_colour(p, lineno);
		return;
	}

	while(isspace(*p)) p++;
	if(!*p) goto premature;
	icon = p;
	while(*p && (!isspace(*p))) p++;
	if(!*p) goto premature;
	*p++ = 0;

	new_litem = my_malloc(sizeof(litem));
	if(!(new_litem->name = strdup(name))) {
		free(new_litem);
		goto nomem;
	}
	if(!(new_litem->icon = strdup(icon))) {
		free(new_litem->name);
		free(new_litem);
		goto nomem;
	}
	if(!(new_litem->prog = make_prog_item(p, lineno))) {
		free(new_litem->name);
		free(new_litem->icon);
		free(new_litem);
		return;
	}
	new_litem->iconid = 0;
	if(strcmp("-", icon)) {
		li = state->litems;
		while(li) {
			if(!(strcmp(icon, li->name))) {
				new_litem->iconid = li->iconid;
				break;
			}
			li = li->next;
		}
		if(!new_litem->iconid) {
			if(!(new_litem->iconid = GrLoadImageFromFile(icon, 0))){
				GrError("Couldn't load icon \"%s\"\n",
									icon);
			} else {
				GrGetImageInfo(new_litem->iconid, &imageinfo);
				if((imageinfo.width != ICON_WIDTH) ||
					(imageinfo.height != ICON_HEIGHT)) {
					GrError("Icon \"%s\" is the "
					"wrong size (%dx%d instead of %dx%d)"
					"\n", icon, imageinfo.width,
					imageinfo.height, ICON_WIDTH,
					ICON_HEIGHT);
					GrFreeImage(new_litem->iconid);
					new_litem->iconid = 0;
				}
			}
		}
	}

	new_litem->prev = NULL;
	new_litem->next = NULL;
	if(!state->litems) {
		state->lastlitem = new_litem;
		state->litems = new_litem;
	} else {
		new_litem->next = state->litems;
		state->litems->prev = new_litem;
		state->litems = new_litem;
	}

	state->numlitems++;

	return;

nomem:
	GrError("Out of memory\n");
	exit(1);

premature:
	GrError("Premature end of line on line %d of config file\n",
								lineno);
}
Esempio n. 13
0
int
main(int argc,char **argv)
{
	int			t;
	GR_IMAGE_ID	image_id;
	GR_WINDOW_ID	window_id;
	GR_GC_ID	gc_id;
	GR_SIZE		w = -1;
	GR_SIZE		h = -1;
	GR_EVENT	event;
	GR_SCREEN_INFO	sinfo;
	GR_IMAGE_INFO	info;
	char		title[256];

	if (argc < 2) {
		GrError("Usage: nxview [-p] [-s] <image file>\n");
		return 1;
	}

	t = 1;
	while ( t < argc ) {
		if ( !strcmp("-p",argv[t])) {
			pflag = 1;
			++t;
			continue;
		}
		if ( !strcmp("-s",argv[t])) {
			sflag = 1;
			++t;
			continue;
		}
		break;
	}

	if (GrOpen() < 0) {
		GrError("cannot open graphics\n");
		return 1;
	}
	
	if (!(image_id = GrLoadImageFromFile(argv[t], 0))) {
		GrError("Can't load image file: %s\n", argv[t]);
		return 1;
	}

	if(sflag) {
		/* stretch to half screen size*/
		GrGetScreenInfo(&sinfo);
		w = sinfo.cols/2;
		h = sinfo.rows/2;
	} else {
		GrGetImageInfo(image_id, &info);
		w = info.width;
		h = info.height;
	}

	sprintf(title, "nxview %s", argv[t]);
	window_id = GrNewWindowEx(GR_WM_PROPS_APPWINDOW, title, GR_ROOT_WINDOW_ID, 0, 0, w, h, GRAY);

	GrSelectEvents(window_id,
		GR_EVENT_MASK_CLOSE_REQ|GR_EVENT_MASK_EXPOSURE);

	GrMapWindow(window_id);

	gc_id = GrNewGC();

	while (1) {
		GrGetNextEvent(&event);
		switch(event.type) {
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrDestroyWindow(window_id);
			GrDestroyGC(gc_id);
			GrFreeImage(image_id);
			GrClose();
			return 0;
			/* no return*/
		case GR_EVENT_TYPE_EXPOSURE:
			if (pflag) {
				int x, y;
				GR_WINDOW_INFO wi;

				GrGetWindowInfo(window_id, &wi);
				for (x=0; x<wi.width; x+=CX*2)
					for (y=0; y<wi.height; y+=CY) {
						if (y & CY)
							GrFillRect(window_id, gc_id, x, y, CX, CY);
						else GrFillRect(window_id, gc_id, x+CX, y, CX, CY); 
					}
			}
			GrDrawImageToFit(window_id, gc_id, 0,0, w,h, image_id);
			break;
		}
	}

	return 0;
}
Esempio n. 14
0
/* Create a new sprite from the specified image file. Returns the address of
 * the new sprite on success or 0 on failure. If width is -1, the real
 * dimensions of the image file will be used, otherwise the image will be
 * scaled up or down to the specified dimensions. */
sprite *load_sprite(nbstate *state, unsigned char *fname, int width, int height)
{
	sprite *s;
	GR_DRAW_ID a;
	GR_DRAW_ID p;
	GR_IMAGE_ID img;
	GR_IMAGE_INFO ii;

	/* Make sure the file name has been specified: */
	if (! fname) return 0;

	/* Try to find a sprite in the list with the specified filename and
	 * dimensions (any dimensions are OK if width is -1). If one is found,
	 * increment its usage count and return its address. */
	for(s = state->spritelist; s; s = s->next) {
		if ((width == -1 || (width == s->w && height == s->h)) &&
		    s->fname && !strcmp(fname, s->fname)) {
			s->usage++;
			return s;
		}
	}
#ifdef HAVE_FILEIO
	{
	/* Make the full path to the filename because the Nano-X server
	 * probably isn't running from the game data directory: */
	char buf[256];
	if (snprintf(buf, 256, "%s/%s", state->gamedir, fname) >= 256){
		debug_printf ("Warning: image path \"%s/%s\" is too long\n",
				state->gamedir, fname);
		return 0;
	}

	/* Try to load the image file, and return 0 on failure: */
	img = GrLoadImageFromFile (buf, 0);
	}
#else
	if      (strcmp (fname, (unsigned char*)   "nbb1.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb1_data, sizeof(   nbb1_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb2.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb2_data, sizeof(   nbb2_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb3.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb3_data, sizeof(   nbb3_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb4.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb4_data, sizeof(   nbb4_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb5.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb5_data, sizeof(   nbb5_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb6.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb6_data, sizeof(   nbb6_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb7.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb7_data, sizeof(   nbb7_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb8.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb8_data, sizeof(   nbb8_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbb9.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbb9_data, sizeof(   nbb9_data), 0);
	else if (strcmp (fname, (unsigned char*)"nbball1.gif") == 0) img = GrLoadImageFromBuffer ((char*)nbball1_data, sizeof(nbball1_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat1.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat1_data, sizeof( nbbat1_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat2.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat2_data, sizeof( nbbat2_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbat3.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbat3_data, sizeof( nbbat3_data), 0);
	else if (strcmp (fname, (unsigned char*) "nbbg10.gif") == 0) img = GrLoadImageFromBuffer ((char*) nbbg10_data, sizeof( nbbg10_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg1.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg1_data, sizeof(  nbbg1_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg2.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg2_data, sizeof(  nbbg2_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg3.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg3_data, sizeof(  nbbg3_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg4.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg4_data, sizeof(  nbbg4_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg5.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg5_data, sizeof(  nbbg5_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg6.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg6_data, sizeof(  nbbg6_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg7.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg7_data, sizeof(  nbbg7_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg8.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg8_data, sizeof(  nbbg8_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbbg9.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbbg9_data, sizeof(  nbbg9_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpf.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpf_data, sizeof(   nbpf_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpn.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpn_data, sizeof(   nbpn_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpp.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpp_data, sizeof(   nbpp_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbps.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbps_data, sizeof(   nbps_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpt.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpt_data, sizeof(   nbpt_data), 0);
	else if (strcmp (fname, (unsigned char*)   "nbpw.gif") == 0) img = GrLoadImageFromBuffer ((char*)   nbpw_data, sizeof(   nbpw_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp1.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp1_data, sizeof(  nbsp1_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp2.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp2_data, sizeof(  nbsp2_data), 0);
	else if (strcmp (fname, (unsigned char*)  "nbsp3.gif") == 0) img = GrLoadImageFromBuffer ((char*)  nbsp3_data, sizeof(  nbsp3_data), 0);
	else {
		debug_printf ("No such image: \"%s\"\n", fname);
		uos_halt (0);
		return 0;
	}
#endif
	if (! img) {
		debug_printf ("Warning: failed to load image \"%s\"- make "
				"sure it is where the server can find it and "
				"that support for loading the relevant image "
				"type has been built into the server\n", fname);
		return 0;
	}

	/* If a size wasn't specified, get the real image size from the server
	 * instead: */
	if(width == -1 || height == -1) {
		GrGetImageInfo(img, &ii);
		width = ii.width;
		height = ii.height;
	}

	/* Make the alpha channel and pixmap to store the image in: */
	if(!(a = GrNewPixmap(width, height, 0))) {
		GrFreeImage(img);
		return 0;
	}
	if(!(p = GrNewPixmap(width, height, 0))) {
		GrFreeImage(img);
		GrDestroyWindow(a);
		return 0;
	}

	/* Draw the image into the specified pixmap and alpha channel, scaling
	 * it up or down if necessary: */
	GrDrawImageToFit(p, state->gc, 0, 0, width, height, img);
	GrFreeImage(img); /* Destroy the server image object. */

	/* Make a new sprite and link it into the list, then return its
	 * address to the caller: */
	s = make_sprite(state, fname, width, height, p, a);
	if (! s) {
		GrDestroyWindow(a);
		GrDestroyWindow(p);
		return 0;
	}

	return s;
}
Esempio n. 15
0
/**
 * Get specified image from the active theme
 *
*/
int theme_get_image(int group_index, int image_index, int * xcoord, int * ycoord, GR_IMAGE_ID * pict_id)
{
	char buffer[300], *p = buffer;

	if (load_theme_config() < 0)
		return -1;
	/* load needed image */
	const char * theme_group; /*  group name */
	const char ** theme_images;	/* pointer to the theme_*_images array */
	switch(group_index) {
		case THEME_GROUP_TITLE:
			theme_group 	= theme_title;
			theme_images	= theme_title_images;
			break;
		case THEME_GROUP_MAINSCREEN:
			theme_group 	= theme_mainscreen;
			theme_images	= theme_mainscreen_images;
			break;
		default:
			return -1;
	}
	if (ini_locateHeading (theme_config_fd, theme_group) ) {
		fprintf (stderr, "theme_get: Unable to find group %s\n",theme_group);
		return -1;
	}
	if (ini_locateKey (theme_config_fd, theme_images[image_index] ) < 0 ) {
		fprintf (stderr, "theme_get: Unable to find key %s\n",theme_images[image_index]);
		return -1;
	}
	if (ini_readString (theme_config_fd, p, sizeof (buffer))  < 0 ) {
		fprintf (stderr, "theme_get: Unable to get string from key %s\n",theme_images[image_index]);
		return -1;
	}
	/* now parse key value */
	char * token;
	token = strtok(p, ", ");
	/*token = xcoord */
	*xcoord = atoi(token);

	token = strtok(NULL, ", ");
	/*token = ycoord */
	*ycoord = atoi(token);

	token = strtok(NULL, ", ");
	/*token = imagename */

	if (token) {
		/* we have found image name, now load it */
		char path[256] =  ACTIVETHEME_PATH;
		strncat(path, token, 255);
		char *filename = cfg_findfile (path);
		if(!filename) {
			fprintf (stderr, "theme_get: Unable to find image %s\n",path);
		} else {
	//		*wid = theme_load_image(filename);
			*pict_id = GrLoadImageFromFile(filename, 0);
			if (*pict_id == 0)
				fprintf(stderr, "theme_get: Failed to load image %s\n", filename);
			free(filename);
		}
	} else {
		*pict_id = 0;
	}
	return (*pict_id == 0)?-2:0;
}
Esempio n. 16
0
int load_images(void)
{
	char buf[128];

	sprintf(buf,"%s/board.gif",IMAGE_PATH);
        if (!(board_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load board image file\n");
                exit(-1);
        }
        GrGetImageInfo(board_image_id, &board_info);
        board_w = board_info.width;
        board_h = board_info.height;
 
	/* ****************/
	sprintf(buf,"%s/w_p.gif",IMAGE_PATH);
        if (!(w_p_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load white pawn image file\n");
                exit(-1);
        }
        GrGetImageInfo(w_p_image_id, &w_p_info);
        w_p_w = w_p_info.width;
        w_p_h = w_p_info.height;
 
	/* ****************/
	sprintf(buf,"%s/w_n.gif",IMAGE_PATH);
        if (!(w_n_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load white knight image file\n");
                exit(-1);
        }
        GrGetImageInfo(w_n_image_id, &w_n_info);
        w_n_w = w_n_info.width;
        w_n_h = w_n_info.height;

 
	/* ****************/
	sprintf(buf,"%s/w_b.gif",IMAGE_PATH);
        if (!(w_b_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load white bishop image file\n");
                exit(-1);
        }
        GrGetImageInfo(w_b_image_id, &w_b_info);
        w_b_w = w_b_info.width;
        w_b_h = w_b_info.height;
 
 
	/* ****************/
	sprintf(buf,"%s/w_r.gif",IMAGE_PATH);
        if (!(w_r_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load white rook image file\n");
                exit(-1);
        }
        GrGetImageInfo(w_r_image_id, &w_r_info);
        w_r_w = w_r_info.width;
        w_r_h = w_r_info.height;
 
 
	/* ****************/
	sprintf(buf,"%s/w_k.gif",IMAGE_PATH);
        if (!(w_k_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load white king image file\n");
                exit(-1);
        }
        GrGetImageInfo(w_k_image_id, &w_k_info);
        w_k_w = w_k_info.width;
        w_k_h = w_k_info.height;
 
 
	/* ****************/
	sprintf(buf,"%s/w_q.gif",IMAGE_PATH);
        if (!(w_q_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load white queen image file\n");
                exit(-1);
        }
        GrGetImageInfo(w_q_image_id, &w_q_info);
        w_q_w = w_q_info.width;
        w_q_h = w_q_info.height;
 
 
	/* ****************/
	sprintf(buf,"%s/b_p.gif",IMAGE_PATH);
        if (!(b_p_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load black pawn image file\n");
                exit(-1);
        }
        GrGetImageInfo(b_p_image_id, &b_p_info);
        b_p_w = b_p_info.width;
        b_p_h = b_p_info.height;
 
	/* ****************/
	sprintf(buf,"%s/b_n.gif",IMAGE_PATH);
        if (!(b_n_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load black knight image file\n");
                exit(-1);
        }
        GrGetImageInfo(b_n_image_id, &b_n_info);
        b_n_w = b_n_info.width;
        b_n_h = b_n_info.height;

 
	/* ****************/
	sprintf(buf,"%s/b_b.gif",IMAGE_PATH);
        if (!(b_b_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load black bishop image file\n");
                exit(-1);
        }
        GrGetImageInfo(b_b_image_id, &b_b_info);
        b_b_w = b_b_info.width;
        b_b_h = b_b_info.height;
 
 
	/* ****************/
	sprintf(buf,"%s/b_r.gif",IMAGE_PATH);
        if (!(b_r_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load black rook image file\n");
                exit(-1);
        }
        GrGetImageInfo(b_r_image_id, &b_r_info);
        b_r_w = b_r_info.width;
        b_r_h = b_r_info.height;
 
 
	/* ****************/
	sprintf(buf,"%s/b_k.gif",IMAGE_PATH);
        if (!(b_k_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load black king image file\n");
                exit(-1);
        }
        GrGetImageInfo(b_k_image_id, &b_k_info);
        b_k_w = b_k_info.width;
        b_k_h = b_k_info.height;
 
 
	/* ****************/
	sprintf(buf,"%s/b_q.gif",IMAGE_PATH);
        if (!(b_q_image_id = GrLoadImageFromFile(buf, 0))) {
                fprintf(stderr, "Can't load black queen image file\n");
                exit(-1);
        }
        GrGetImageInfo(b_q_image_id, &b_q_info);
        b_q_w = b_q_info.width;
        b_q_h = b_q_info.height;
 
	return(0);
}