// twype.c // // by John D. de Boer #include "twist.h" typedef struct { string name, // name of event type aka; // short form of name for .ttt brevity picture icon; // icon for event type bitmap *bm; // same, but in different format bool show; // whether events of this type are selected by the user colour rgb; // colour for time-line event bars of this type } TwEventType; int TYPES; // number of different event types TwEventType **Types; // the event type details static stringlist UETyp; // event types that were not recognised // Initialisation void InitTypes(void) { TYPES=0; Types=(TwEventType **)handle(0); initstringlist(&UETyp); } static void PurgeType(TwEventType *P) { if (!P) return; old(P->name); old(P->aka); ReleaseIcon(P->icon,P->bm); } void PurgeTypes(void) { int i; purgestringlist(&UETyp); lock(Types); for (i=0;iname=copyof(S); MP->aka=NULL; MP->show=1; MP->icon=DefaultEventIcon(); MP->bm=DefaultEventBitmap(); setcolour(&(MP->rgb),emerald); unlock(Types); return NEW; } void SetTypeIcon(int TYPE, picture P) { if (!range(TYPE,TYPES) || !P) return; (*Types)[TYPE].icon=P; (*Types)[TYPE].bm=extractbitmap(P); } void SetTypeSynonym(int TYPE, char *S) { if (!range(TYPE,TYPES)) return; (*Types)[TYPE].aka=copyof(S); } void SetTypeColour(int TYPE, colour *C) { if (!range(TYPE,TYPES) || !C) return; (*Types)[TYPE].rgb=*C; } // Parsing event types static void UnknownEventType(const char *S) { if (stringisinlist(&UETyp,S)) return; WarnOld(cat3(0,"Event type \"",(char *)S,"\" not understood")); addstringtolist(&UETyp,copyof(S)); } int ParseType(const char *S) { TwEventType E; int i; if (!S || !*S) return -1; for (i=0;intype<1) return DefaultEventIcon(); TYPE=E->type[0]; if (!range(TYPE,TYPES)) return DefaultEventIcon(); return (*Types)[TYPE].icon; }*/ picture EventIcon(Event *E) { int TYPE; if (!E || E->ntype<1) return DefaultEventIcon(); TYPE=E->type[0]; if (!range(TYPE,TYPES)) return DefaultEventIcon(); return (*Types)[TYPE].icon; } bitmap *EventBitmap(Event *E) { int TYPE; if (!E || E->ntype<1) return DefaultEventBitmap(); TYPE=E->type[0]; if (!range(TYPE,TYPES)) return DefaultEventBitmap(); return (*Types)[TYPE].bm; } char *TypeName(int TYPE) { if (!range(TYPE,TYPES)) return "historical event"; return (*Types)[TYPE].name; } void TypeColour(Event *E, colour *C) { if (!C) return; if (!E || E->ntype<1 || !range(E->type[0],TYPES)) setcolour(C,turquoise); *C=(*Types)[E->type[0]].rgb; } bool TypeMatch(Event *E, const char *S) { int i; if (!E || !S) return 0; for (i=0;intype;i++) if (wordin(S,TypeName(E->type[i]),0)) return 1; return 0; }