/* WinBattClock.c ** ** SCRAMmer V37.3 - 27th Aug 1992 ** ------------------------------ ** ** Copyright (c) Giuliano C. Peritore ** Via Amaseno, 6 ** 04100 Latina ** ITALY ** ** Phone: (+39) 773 491692 Voice Only ** EMAIL mc6040@mclink.it */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "SCRAMmer.h" VOID ShadowText(UWORD ,UWORD, struct RastPort *,char *msg); VOID NormalText(UWORD ,UWORD, struct RastPort *,char *msg); LONG request_user(struct Window *,char *, char *, char *); VOID CloseWindowSafely(struct Window *); IMPORT struct Library *GadToolsBase; IMPORT struct IntuitionBase *IntuitionBase; IMPORT struct GfxBase *GfxBase; IMPORT struct Window *main_window; IMPORT struct Screen *def_pub_scr; IMPORT struct MsgPort *userport; IMPORT struct TextFont *tf; IMPORT struct TextAttr ta; IMPORT UWORD xfnt,yfnt,bfnt; IMPORT APTR vi; struct Library *BattClockBase, *UtilityBase=0; struct Window *battclock_win=0; static struct Gadget *battckglist; static struct RastPort *rport; static struct ClockData MyClock; static ULONG AmigaTime; static UBYTE *ampm; static UBYTE *Days[7]; static UBYTE *Months[12]; VOID refresh_battclock(VOID) { char buf[]="123456789012345678901234567890"; ShadowText(X_SEP, Y_SEP+bfnt, rport,GetString(MSG_BATTCL1)); AmigaTime=ReadBattClock(); Amiga2Date(AmigaTime,&MyClock); sprintf(buf,"%s %s %2.2d %4.4d\0",Days[MyClock.wday],Months[MyClock.month-1],MyClock.mday,MyClock.year); NormalText(X_SEP,Y_SEP+bfnt+yfnt,rport,buf); if(MyClock.hour<12) ampm="AM"; else { ampm="PM"; MyClock.hour-=12; } if(MyClock.hour==0) MyClock.hour=12; sprintf(buf,"%02d:%02d:%02d %s\0",MyClock.hour,MyClock.min,MyClock.sec,ampm); NormalText(X_SEP,Y_SEP+bfnt+yfnt*2,rport,buf); sprintf(buf,"#%10.10d\0",AmigaTime); NormalText(X_SEP+xfnt*16,Y_SEP+bfnt+yfnt*2,rport,buf); } VOID process_battclock(struct Gadget*g) { switch(g->GadgetID) { case 1: if(request_user(battclock_win,GetString(MSG_BATTCLWIN),GetString(MSG_BATTCL2),GetString(MSG_BATTCLRC))) { ResetBattClock(); refresh_battclock(); } break; } } VOID open_battclock(VOID) { static struct Gadget *gad; static struct NewGadget ng; UWORD w,h; Days[0]=GetString(MSG_SUNDAY); Days[1]=GetString(MSG_MONDAY); Days[2]=GetString(MSG_TUESDAY); Days[3]=GetString(MSG_WEDNESDAY); Days[4]=GetString(MSG_THURSDAY); Days[5]=GetString(MSG_FRIDAY); Days[6]=GetString(MSG_SATURDAY); Months[ 0]=GetString(MSG_JANUARY); Months[ 1]=GetString(MSG_FEBRUARY); Months[ 2]=GetString(MSG_MARCH); Months[ 3]=GetString(MSG_APRIL); Months[ 4]=GetString(MSG_MAY); Months[ 5]=GetString(MSG_JUNE); Months[ 6]=GetString(MSG_JULY); Months[ 7]=GetString(MSG_AUGUST); Months[ 8]=GetString(MSG_SEPTEMBER); Months[ 9]=GetString(MSG_OCTOBER); Months[10]=GetString(MSG_NOVEMBER); Months[11]=GetString(MSG_DECEMBER); if(BattClockBase=OpenResource(BATTCLOCKNAME)) { if(UtilityBase=OpenLibrary("utility.library",37)) { gad=CreateContext(&battckglist); ng.ng_TextAttr=&ta; ng.ng_VisualInfo=vi; ng.ng_Width= xfnt*10; ng.ng_Height= yfnt; ng.ng_Flags= PLACETEXT_IN; ng.ng_LeftEdge= X_SEP+xfnt*8; ng.ng_TopEdge=Y_SEP+yfnt*3; ng.ng_GadgetText=GetString(MSG_BATTCLRES); ng.ng_GadgetID=1; gad=CreateGadget(BUTTON_KIND,gad,&ng,TAG_DONE); if(gad) { w=(X_SEP*2) + 27*xfnt + (def_pub_scr->WBorLeft) + (def_pub_scr->WBorRight); h=(Y_SEP*2) + 4*yfnt + (def_pub_scr->WBorBottom) + (def_pub_scr->WBorTop) + (def_pub_scr->Font->ta_YSize) + 1; if(battclock_win=OpenWindowTags(NULL, WA_Left, 3*((def_pub_scr->Width-w)>>2), WA_Top, 3*((def_pub_scr->Height-h)>>2), WA_Width, w, WA_Height, h, WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_GIMMEZEROZERO|WFLG_SIMPLE_REFRESH, WA_AutoAdjust, FALSE, WA_IDCMP, NULL, WA_Title, GetString(MSG_BATTCLWIN), WA_PubScreen, def_pub_scr,TAG_END)) { rport=battclock_win->RPort; SetFont(rport,tf); battclock_win->UserPort=userport; AddGList(battclock_win,battckglist,-1,-1,NULL); RefreshGList(battckglist,battclock_win,NULL,-1); GT_RefreshWindow(battclock_win,NULL); ModifyIDCMP(battclock_win,BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW); refresh_battclock(); } else request_user(main_window,GetString(MSG_SCRAMMER),GetString(MSG_NOWINDOW),GetString(MSG_CANCEL)); } else request_user(main_window,GetString(MSG_SCRAMMER),GetString(MSG_NOGADGETS),GetString(MSG_CANCEL)); } else request_user(main_window,GetString(MSG_SCRAMMER),GetString(MSG_NOUTILITY),GetString(MSG_CANCEL)); } else request_user(main_window,GetString(MSG_SCRAMMER),GetString(MSG_NOBATTCLOCK),GetString(MSG_CANCEL)); } VOID close_battclock(VOID) { if(UtilityBase) { CloseLibrary(UtilityBase); UtilityBase=0; } if(battclock_win) { CloseWindowSafely(battclock_win); battclock_win=0; } FreeGadgets(battckglist); battckglist=0; }