home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Enlightenment
/
enl14.tgz
/
enl14.tar
/
enl14
/
imageclass.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-11-06
|
5KB
|
195 lines
#include "enl.h"
Image *LoadImage(char *file)
{
if (!file) return NULL;
if (!exists(file))
{
Alert("The Image file:\n"
"%s\n"
"does not exist.The image cannot be loaded.\n",file);
return NULL;
}
return ImlibLoadImage(imd,file,NULL);
}
void FreeImageClass(ImageClass *item)
{
if (!item) return;
if (item->name) Efree(item->name);
FreeImageEntry(item->normal);
if (item->hilited!=item->normal) FreeImageEntry(item->hilited);
if ((item->clicked!=item->hilited)&&
(item->clicked!=item->normal)) FreeImageEntry(item->clicked);
if (item->disabled!=item->normal) FreeImageEntry(item->disabled);
}
void GetPixmaps(ImageClass *ic, char state, int width, int height, Pixmap *pmap, Pixmap *mask)
{
ImageEntry *ie;
if ((!ic)||(!pmap)||(!mask)) return;
if (state==STATE_NORMAL) ie=ic->normal;
else if (state==STATE_HILITED) ie=ic->hilited;
else if (state==STATE_CLICKED) ie=ic->clicked;
else if (state==STATE_DISABLED) ie=ic->disabled;
else ie=ic->normal;
if (!ie) return;
if (ic->unloadable)
{
if (!ie->im)
{
if ((ie->width==width)&&(ie->height==height))
{
*pmap=ie->pmap;*mask=ie->mask;
}
else ie->im=LoadImage(ie->name);
}
if (ie->im)
{
ImlibRender(imd,ie->im,width,height);
ie->pmap=ImlibMoveImageToPixmap(imd,ie->im);
ie->mask=ImlibMoveMaskToPixmap(imd,ie->im);
ie->width=width;ie->height=height;
*pmap=ie->pmap;*mask=ie->mask;
ImlibDestroyImage(imd,ie->im);
ie->im=NULL;
}
}
else
{
if (ie->im)
{
ImlibRender(imd,ie->im,width,height);
*pmap=ImlibMoveImageToPixmap(imd,ie->im);
*mask=ImlibMoveMaskToPixmap(imd,ie->im);
}
}
}
void FreeImageEntry(ImageEntry *item)
{
if (!item) return;
if (item->name) Efree(item->name);
if (item->im) ImlibDestroyImage(imd,item->im);
if (item->icl) Efree(item->icl);
if (item->bd) Efree(item->bd);
if (!item->im)
{
if (item->pmap) ImlibFreePixmap(imd,item->pmap);
if (item->mask) ImlibFreePixmap(imd,item->mask);
}
Efree(item);
}
ImageEntry *CfgReadImageEntry(char *type)
{
ImageEntry *ie;
char s[256];
int wd;
ie=(ImageEntry *)Emalloc(sizeof(ImageEntry));
if (!ie) return NULL;
ie->name=NULL;ie->im=NULL;ie->icl=NULL;ie->bd=NULL;
ie->width=0;ie->height=0;ie->pmap=0;ie->mask=0;
if (!CfgGetLine(NULL))
{
Efree(ie);
strcpy(type,"eof");
return NULL;
}
wd=1;
word(line,wd++,s);
if (!strcmp(s,"end"))
{
Efree(ie);
strcpy(type,"end");
return NULL;
}
word(line,wd++,s);strcpy(type,s);
word(line,wd++,s);ie->name=duplicate(s);
word(line,wd++,s);
if (!strcmp(s,"shape"))
{
ie->icl=(ImColor *)Emalloc(sizeof(ImColor));
word(line,wd++,s);ie->icl->r=atoi(s);
word(line,wd++,s);ie->icl->g=atoi(s);
word(line,wd++,s);ie->icl->b=atoi(s);
}
word(line,wd++,s);
if (!strcmp(s,"border"))
{
ie->bd=(Border *)Emalloc(sizeof(Border));
word(line,wd++,s);ie->bd->left=atoi(s);
word(line,wd++,s);ie->bd->right=atoi(s);
word(line,wd++,s);ie->bd->top=atoi(s);
word(line,wd++,s);ie->bd->bottom=atoi(s);
}
ie->im=LoadImage(ie->name);
if (!ie->im)
{
if (ie->name) Efree(ie->name);
if (ie->icl) Efree(ie->icl);
if (ie->bd) Efree(ie->bd);
Efree(ie);
return NULL;
}
if (ie->icl) ImlibSetImageTransparentColor(imd,ie->im,ie->icl);
if (ie->bd) ImlibSetImageBorder(imd,ie->im,ie->bd->left,ie->bd->right,
ie->bd->top,ie->bd->bottom);
return ie;
}
void CfgLoadImageClass()
{
ImageClass *ic;
ImageEntry *ie;
char s[1024];
if (!CfgGetLine(NULL)) return;
ic=Emalloc(sizeof(ImageClass));
if (!ic) return;
ic->name=NULL;ic->normal=NULL;ic->hilited=NULL;ic->clicked=NULL;
ic->disabled=NULL;ic->unloadable=0;
word(line,1,s);
if (!strcmp("name",s))
{
word(line,2,s);ic->name=duplicate(s);
}
if (!CfgGetLine(NULL)) return;
word(line,1,s);
if (!strcmp("unloadable",s))
{
word(line,2,s);
if (!strcmp(s,"yes")) ic->unloadable=1;
}
for (;;)
{
ie=CfgReadImageEntry(s);
if ((!strcmp(s,"end"))||(!strcmp(s,"eof")))
{
if (!ic->hilited) ic->hilited=ic->normal;
if (!ic->clicked) ic->clicked=ic->hilited;
if (!ic->disabled) ic->disabled=ic->normal;
AddItem((void *)ic,ic->name,LIST_TYPE_IMAGECLASS);
return;
}
else if (!strcmp(s,"normal"))
{
if (!ie)
{
Alert("Unable to load the normal base image of the %s image class\n"
"This will result in this class being unavailable.\n");
Efree(ic->name);
Efree(ic);
return;
}
ic->normal=ie;
}
else if (!strcmp(s,"hilited")) ic->hilited=ie;
else if (!strcmp(s,"clicked")) ic->clicked=ie;
else if (!strcmp(s,"disabled")) ic->disabled=ie;
}
}