home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <dos/dos.h>
- #include <proto/SysInfo.h>
- #include <libraries/SysInfo.h>
- #include <dos/dosextens.h>
- #include <intuition/intuition.h>
- #include <intuition/gadgetclass.h>
- #include <intuition/intuitionbase.h>
- #include <intuition/classusr.h>
- #include <intuition/imageclass.h>
- #include <intuition/gadgetclass.h>
- #include <intuition/cghooks.h>
- #include <intuition/icclass.h>
- #include <intuition/classes.h>
- #include <intuition/sghooks.h>
- #include <intuition/screens.h>
- #include <graphics/gfxbase.h>
- #include <graphics/text.h>
- #include <graphics/gfxmacros.h>
- #include <utility/tagitem.h>
- #include <utility/hooks.h>
- #include <string.h>
- #include "gaugeclass.h"
- #include "tinymeter.h"
-
- struct GaugeData
- {
- ULONG min;
- ULONG max;
- ULONG current;
- ULONG base;
- ULONG old_cur;
- ULONG old_bas;
- WORD labelpos;
- UBYTE fmtind;
-
- ULONG type, diswhat;
-
- char *txtlbl;
- char *txtfmt;
-
- struct GAU_Color Colors[GAU_UsedColors];
-
- BOOL Style3D;
- BOOL StyleBorder;
- BOOL StyleBackground;
- BOOL StyleShadowLabel;
- BOOL StyleNoGauge;
- BOOL StyleNoFormat;
- BOOL StyleNoBase;
-
- struct TextFont *textFont;
-
- ULONG Pens[GAU_UsedColors];
- BOOL PorC[GAU_UsedColors];
-
- BOOL InitNotDone;
-
- struct RastPort *nolock_rp;
-
- LONG histpos,
- oldlgth,
- oldx;
-
- WORD text_y;
- struct Locale *locale;
- char clocktxt[256];
- char *voltxt;
-
- struct RastPort *bg_buffer;
- struct RastPort *wk_buffer;
- struct RastPort *hs_buffer;
-
- WORD clockpos;
-
- BOOL highlight;
- WORD oldclockx;
- WORD oldclockw;
-
- ULONG voltype;
- struct Screen *scr;
- };
-
-
- extern struct SysInfo *si;
- extern ULONG executive;
- extern struct Library *RetinaBase;
- extern ULONG idle, maximum;
-
- __saveds ULONG dispatchGaugeGadget(Class *cl,Object *o, Msg msg)
- {
- switch( msg->MethodID )
- {
- case OM_SET:
- setGauge(cl,(struct Gadget *)o,(struct gpRender *)msg);
- return(DoSuperMethodA(cl,o,msg));
- case GM_RENDER:
- return(renderGauge(cl,(struct Gadget *)o,(struct gpRender *)msg));
- case OM_NEW:
- if(o = (Object *)DoSuperMethodA(cl, o, msg) )
- return(newGauge(cl,(struct Gadget *)o,(struct gpRender *)msg,INST_DATA(cl, o)));
- else return(0L);
- case OM_GET:
- return(getGauge(cl,(struct Gadget *)o,(struct gpRender *)msg));
- case MY_REFRESH:
- my_Refresh(cl,(struct Gadget *)o,msg);
- return(0L);
- case OM_DISPOSE:
- disposeGauge(cl,(struct Gadget *)o,(struct gpRender *)msg);
- default:
- return(DoSuperMethodA(cl,o,msg));
- }
- }
-
- Class *initGaugeGadgetClass(void)
- {
- struct IClass *cl;
- if( cl = (struct IClass *)MakeClass( NULL, "gadgetclass", NULL, sizeof(struct GaugeData), 0) )
- {
- cl->cl_Dispatcher.h_Entry = HookEntry;
- cl->cl_Dispatcher.h_SubEntry = (HOOKFUNC)dispatchGaugeGadget;
- return((Class *)cl);
- }
- return(0L);
- }
-
- BOOL freeGaugeGadgetClass( Class *cl )
- {
- return(FreeClass(cl));
- }
-
- void getVolsize(struct GaugeData *inst,char *volname)
- {
- struct InfoData inf;
- struct DevProc *devproc;
- if(devproc=(struct DevProc *)GetDeviceProc(volname,NULL))
- {
- if(DoPkt(devproc->dvp_Port,ACTION_DISK_INFO,MKBADDR(&inf),NULL,NULL,NULL,NULL)==DOSTRUE)
- {
- switch(inf.id_DiskType)
- {
- case 0x42555359:
- inst->max =0;
- inst->current=GAU_err_busy;
- break;
- case ID_UNREADABLE_DISK:
- inst->max =0;
- inst->current=GAU_err_unreadable;
- break;
- case ID_NOT_REALLY_DOS:
- inst->max =0;
- inst->current=GAU_err_nodos;
- break;
- case ID_NO_DISK_PRESENT:
- inst->max =0;
- inst->current=GAU_err_notpresent;
- break;
- case ID_KICKSTART_DISK:
- inst->max =0L;
- inst->current=GAU_err_kickstart;
- break;
- default:
- inst->current=(inf.id_NumBlocks-inf.id_NumBlocksUsed)*inf.id_BytesPerBlock;
- inst->max =inf.id_NumBlocks*inf.id_BytesPerBlock;
- inst->voltype=inf.id_DiskType;
- break;
- }
- }
- FreeDeviceProc(devproc);
- }
- else
- {
- inst->max=0;
- inst->current=GAU_err_notmount;
- }
- }
-
- void my_Refresh(Class *cl,struct Gadget *g,Msg msg)
- {
- struct GaugeData *inst=INST_DATA(cl,g);
-
- switch (inst->diswhat)
- {
- case typ_all:
- inst->current=AvailMem(0L);
- break;
- case typ_chip:
- inst->current=AvailMem(MEMF_CHIP);
- break;
- case typ_fast:
- inst->current=AvailMem(MEMF_FAST);
- break;
- case typ_idle:
- switch (executive)
- {
- case idle_none:
- inst->current=0L;
- break;
- case idle_executive:
- {
- struct SI_CpuUsage cpu;
- GetCpuUsage(si,&cpu);
- inst->current=(cpu.used_cputime_lastsec_hz-cpu.used_cputime_lastsec)<<8;
- }
- break;
- case idle_own:
- inst->current=idle;
- break;
- }
- if(inst->base<inst->current)inst->base=inst->current;
- break;
- case typ_largest_total:
- inst->current=AvailMem(MEMF_LARGEST);
- break;
- case typ_largest_chip:
- inst->current=AvailMem(MEMF_LARGEST|MEMF_CHIP);
- break;
- case typ_largest_fast:
- inst->current=AvailMem(MEMF_LARGEST|MEMF_FAST);
- break;
- case typ_largest_retina:
- if(RetinaBase)
- inst->current=Retina_AvailMem(MEMF_LARGEST);
- else
- inst->current=GAU_err_notavail;
- break;
- case typ_retina:
- if(RetinaBase)
- inst->current=Retina_AvailMem(0L);
- else
- inst->current=GAU_err_notavail;
- break;
- case typ_volume:
- if(inst->voltxt)getVolsize(inst,inst->voltxt);
- break;
- default:
- break;
- }
- if(msg) renderGauge(cl,g,(struct gpRender *)msg);
- }
-
- void my_Max(Class *cl,struct Gadget *g)
- {
- struct GaugeData *inst=INST_DATA(cl,g);
- switch (inst->diswhat)
- {
- case typ_largest_total:
- case typ_all:
- inst->max=AvailMem(MEMF_TOTAL);
- break;
- case typ_largest_chip:
- case typ_chip:
- inst->max=AvailMem(MEMF_CHIP|MEMF_TOTAL);
- break;
- case typ_largest_fast:
- case typ_fast:
- inst->max=AvailMem(MEMF_FAST|MEMF_TOTAL);
- break;
- case typ_idle:
- switch (executive)
- {
- case idle_none:
- inst->max=0L;
- break;
- case idle_executive:
- {
- struct SI_CpuUsage cpu;
- GetCpuUsage(si,&cpu);
- inst->max=(cpu.used_cputime_lastsec_hz)<<8;
- }
- break;
- case idle_own:
- inst->max=maximum;
- break;
- }
- break;
- case typ_largest_retina:
- case typ_retina:
- if(RetinaBase)
- inst->max=Retina_AvailMem(MEMF_TOTAL);
- else
- inst->max=GAU_err_notavail;
- break;
- default:
- break;
- }
- inst->base=inst->current;
- }
-
-
- ULONG newGauge(Class *cl,struct Gadget *g,struct gpRender *msg,struct GaugeData *inst)
- {
- struct TagItem *ti;
- if(ti = ((struct opSet *)msg)->ops_AttrList)
- {
- if(inst->textFont = (struct TextFont *)GetTagData(GAU_TextFont,(ULONG)OpenTopaz(),ti))
- {
- struct RastPort *dummy;
- if(dummy=(struct RastPort *)pAllocVec(sizeof(struct RastPort)))
- {
- int i;
- char *foo;
- UWORD def_pens[]={ 2, 2, 1, 3, 1, 2, 1, 0 };
- ULONG gau_tags[]={GAU_ColLabel,GAU_ColFormat,GAU_ColBase,GAU_ColCurrent,GAU_ColNegative,GAU_ColBrightEdg,GAU_ColDarkEdg,GAU_ColBackground};
-
- InitRastPort(dummy);
- dummy->Font=inst->textFont;
-
- inst->txtfmt = (char *)GetTagData(GAU_TextFormat,(ULONG)"%td",ti);
- inst->txtlbl = (char *)GetTagData(GAU_Label,(ULONG)"Gauge", ti);
- inst->labelpos = GetTagData(GAU_LabelPos,TextLength(dummy,inst->txtlbl,my_strlen(inst->txtlbl))+4, ti);
-
- inst->Style3D = GetTagData(GAU_3D, TRUE, ti);
- inst->StyleBorder = GetTagData(GAU_Border, TRUE, ti);
- inst->StyleBackground = GetTagData(GAU_Background, FALSE, ti);
- inst->StyleShadowLabel = GetTagData(GAU_ShadowLabel, FALSE, ti);
- inst->StyleNoGauge = GetTagData(GAU_NoGauge, FALSE, ti);
- inst->StyleNoFormat = GetTagData(GAU_NoFormat, FALSE, ti);
- inst->StyleNoBase = GetTagData(GAU_NoBase, FALSE, ti);
- inst->fmtind = GetTagData(GAU_FmtIndent, FALSE, ti);
- inst->type = GetTagData(GAU_Type, GAU_Type_gauge, ti);
- inst->diswhat = GetTagData(GAU_DisWhat, 0,ti);
- inst->voltxt=0L;
- if(foo = (char *)GetTagData(GAU_Expansion,NULL,ti))
- {
- if(inst->diswhat==typ_volume)
- {
- inst->voltxt=foo;
- }
- }
- for(i=0;i<GAU_UsedColors;i++) CopyMem((APTR)GetTagData(gau_tags[i],(ULONG)GetGaugePen(def_pens[i]),ti),(APTR)&inst->Colors[i],sizeof(struct GAU_Color));
-
- if(inst->diswhat==typ_clock_)
- {
- inst->type = typ_clock;
- inst->locale = (struct Locale *)OpenLocale(NULL);
- }
- else inst->locale = 0L;
-
- inst->InitNotDone=TRUE;
- inst->highlight=TRUE;
- inst->oldclockw=0L;
- inst->oldclockx=0L;
-
- pFreeVec((ULONG *)dummy);
-
- my_Refresh(cl,g,NULL);
- my_Max(cl,g);
-
- return((ULONG)g);
- }
- else return(0L);
- }
- else return(0L);
- }
- else return(0L);
- }
-
- void freeRPorts(struct GaugeData *inst)
- {
- if(inst->bg_buffer)
- {
- FreeBitMap(inst->bg_buffer->BitMap);
- pFreeVec((ULONG *)inst->bg_buffer);
- inst->bg_buffer=0L;
- }
-
- if(inst->wk_buffer)
- {
- FreeBitMap(inst->wk_buffer->BitMap);
- pFreeVec((ULONG *)inst->wk_buffer);
- inst->wk_buffer=0L;
- }
-
- if(inst->hs_buffer)
- {
- FreeBitMap(inst->hs_buffer->BitMap);
- pFreeVec((ULONG *)inst->hs_buffer);
- inst->hs_buffer=0L;
- }
-
- }
-
- void disposeGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
- {
- int w;
- struct GaugeData *inst=INST_DATA(cl,g);
- CloseLocale(inst->locale);
- for(w=0;w<GAU_UsedColors;w++)FreePenNew(inst->scr,&inst->Colors[w],w,inst->Pens);
- freeRPorts(inst);
- }
-
- ULONG getGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
- {
- struct GaugeData *inst=INST_DATA(cl,g);
- switch (((struct opGet *)msg)->opg_AttrID)
- {
- case GAU_RPBackground:
- *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->bg_buffer;
- break;
- case GAU_Base:
- *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->base;
- break;
- case GAU_Current:
- *(((struct opGet *)msg)->opg_Storage)=(ULONG)inst->current;
- break;
- default:
- *(((struct opGet *)msg)->opg_Storage)=0L;
- break;
- }
- return((ULONG)TRUE);
- }
-
- void setGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
- {
- struct TagItem *ti,*tstate=((struct opSet *)msg)->ops_AttrList;
- struct GaugeData *inst=INST_DATA(cl,g);
- ULONG t_data;
-
- while(ti=(struct TagItem *)NextTagItem(&tstate))
- {
- t_data=(ULONG)ti->ti_Data;
- switch(ti->ti_Tag)
- {
- case GAU_Current:
- inst->current= (ULONG)t_data;
- break;
- case GAU_Base:
- inst->base= (ULONG)t_data;
- break;
- case GAU_Max:
- inst->max= (ULONG)t_data;
- break;
- case GAU_VolType:
- inst->voltype= (ULONG)t_data;
- break;
- }
- }
- if ( FindTagItem(GA_Width, ((struct opSet *)msg)->ops_AttrList) ||
- FindTagItem(GA_Height, ((struct opSet *)msg)->ops_AttrList) ||
- FindTagItem(GA_Top, ((struct opSet *)msg)->ops_AttrList) ||
- FindTagItem(GA_Left, ((struct opSet *)msg)->ops_AttrList) )
- {
- inst->highlight=TRUE;
- inst->InitNotDone=TRUE;
- freeRPorts(inst);
- }
- }
-
- char *formattext(ULONG current, ULONG base, ULONG max, char format[], ULONG special, char *temp_str)
- {
- int i=0,
- j=0;
- char temp_str_1[64];
- BOOL negative;
-
- while(format[i]!=0)
- {
- if(format[i]=='%')
- {
- ULONG dummy=0;
- UBYTE dummy_2=0,
- dummy_1=0,
- dummy_3=0;
- i++;
- if(format[i]=='t'){dummy_2=1;i++;}
- if(format[i]=='T'){dummy_2=4;i++;}
- if(format[i]=='k'){dummy_1=1;i++;}
- if(format[i]=='m'){dummy_1=2;i++;}
- if(format[i]=='o'){dummy_3=1;i++;}
- if(format[i]=='%'){dummy_2=3;i++;}
- switch(format[i])
- {
- case 'd':
- dummy=current;
- negative=FALSE;
- break;
- case 'b':
- dummy=base;
- negative=FALSE;
- break;
- case 'f':
- dummy = base<current ? current-base : base-current;
- negative= base<current ? TRUE : FALSE;
- break;
- case 'a':
- dummy=max;
- negative=FALSE;
- break;
- case 'p':
- dummy_2=2; dummy=current;
- negative=FALSE;
- break;
- case 'v':
- dummy_2=5;
- break;
- default:
- goto noforward;
- break;
- }
- i++;
- noforward:
- if(dummy_3==1)dummy=max-dummy;
- if(dummy_1==1)dummy=dummy>>10;
- if(dummy_1==2)dummy=dummy>>20;
- switch(dummy_2)
- {
- case 4:
- dummy_2=long_2_string_with_thousand(dummy,&temp_str_1[0],'.',negative);
- for(dummy_1=0;dummy_1<dummy_2;dummy_1++) temp_str[j++]=temp_str_1[dummy_1];
- break;
- case 1:
- dummy_2=long_2_string_with_thousand(dummy,&temp_str_1[0],',',negative);
- for(dummy_1=0;dummy_1<dummy_2;dummy_1++) temp_str[j++]=temp_str_1[dummy_1];
- break;
- case 2:
- dummy_2=0;
- if(negative) sprintf(&temp_str_1[0],"-%ld",(((dummy>>8)*100)/((max>>8)+1)));
- else sprintf(&temp_str_1[0],"%ld", (((dummy>>8)*100)/((max>>8)+1)));
- while ((temp_str_1[dummy_2] != 0)&(dummy_2<64)) temp_str[j++]=temp_str_1[dummy_2++];
- break;
- case 0:
- dummy_2=0;
- if(negative) sprintf(&temp_str_1[0],"-%ld",dummy);
- else sprintf(&temp_str_1[0],"%ld", dummy);
- while ((temp_str_1[dummy_2] != 0)&(dummy_2<64)) temp_str[j++]=temp_str_1[dummy_2++];
- break;
- case 3:
- temp_str[j++]='%';
- break;
- case 5:
- if(special&0xFF000000)temp_str[j++]=(char)((special>>24)&0xFF);
- if(special&0x00FF0000)temp_str[j++]=(char)((special>>16)&0xFF);
- if(special&0x0000FF00)temp_str[j++]=(char)((special>>8) &0xFF);
- temp_str[j++]='\\';
- temp_str[j++]=(char)( special &0xFF)+0x30;
- break;
- }
- }
- else temp_str[j++]=format[i++];
- }
- temp_str[j]=0;
- return(temp_str);
- }
-
- __saveds void putChar_hook(struct Hook *hook,struct Locale *locale,ULONG thechar)
- {
- struct GaugeData *data;
- data=(struct GaugeData *)hook->h_Data;
- data->clocktxt[data->clockpos++]=(UBYTE)(thechar);
- }
-
- struct Hook putCharHook = { { 0,0 },(void *)HookEntry,(void *)putChar_hook, NULL };
-
- char *getSTR(struct GaugeData *inst)
- {
- static char *errstr[]=
- {
- "Disk is busy",
- "Not mounted",
- "No disk present",
- "Disk unreadable",
- "No DOS format",
- "n.a.",
- "Kickstart disk"
- };
- switch (inst->current-inst->max)
- {
- case GAU_err_busy:
- return( errstr[0]);
- case GAU_err_notmount:
- return( errstr[1]);
- case GAU_err_notpresent:
- return( errstr[2]);
- case GAU_err_unreadable:
- return( errstr[3]);
- case GAU_err_nodos:
- return( errstr[4]);
- case GAU_err_notavail:
- return( errstr[5]);
- case GAU_err_kickstart:
- return( errstr[6]);
- break;
- default:
- return(formattext(inst->current,inst->base,inst->max,inst->txtfmt,inst->voltype,inst->clocktxt));
- }
- }
-
- ULONG renderGauge(Class *cl,struct Gadget *g,struct gpRender *msg)
- {
- struct RastPort *rp;
- struct BitMap *work_bm;
- struct RastPort *wk_rp,*bg_rp,*hs_rp;
- struct GaugeData *inst=INST_DATA(cl,g);
- struct DateStamp d_stamp;
- WORD text_x,w,h;
- WORD x1,x2,g_x,g_size,g_height,t_length;
- char *fmt;
- LONG max;
-
- if((msg->MethodID == MY_REFRESH)&&(((struct my_redraw_msg *)msg)->win))
- {
- rp = ((struct my_redraw_msg *)msg)->win->RPort;
- inst->scr = ((struct my_redraw_msg *)msg)->win->WScreen;
- }
- else if(msg->gpr_GInfo)
- {
- rp = ( msg->MethodID == GM_RENDER ) ? msg->gpr_RPort : (struct RastPort *) ObtainGIRPort(msg->gpr_GInfo);
- inst->scr=msg->gpr_GInfo->gi_Screen;
- }
- if(rp)
- {
- if(inst->InitNotDone)
- {
- for(w=0;w<GAU_UsedColors;w++)GetPenNew(inst->scr,&inst->Colors[w],w,inst->PorC,inst->Pens);
-
- if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,rp->BitMap))
- {
- if(inst->bg_buffer=(struct RastPort *)pAllocVec(sizeof(struct RastPort)))
- {
- InitRastPort(inst->bg_buffer);
- inst->bg_buffer->BitMap=work_bm;
- my_Blit(rp,g->LeftEdge,g->TopEdge,inst->bg_buffer,0,0,g->Width,g->Height);
- if((!inst->StyleBackground)&&(inst->type==GAU_Type_histmeter))
- {
- SetAPen(rp,inst->Pens[col_bg]);
- RectFill(rp,g->LeftEdge,g->TopEdge,g->LeftEdge+g->Width,g->TopEdge+g->Height);
- SetAPen(inst->bg_buffer,inst->Pens[col_bg]);
- RectFill(inst->bg_buffer,0,0,g->Width,g->Height);
- }
- }
- else
- {
- FreeBitMap(work_bm);
- return(0L);
- }
- }
- else return(0L);
-
- if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,inst->bg_buffer->BitMap))
- {
- if(inst->wk_buffer=(struct RastPort *)pAllocVec(sizeof(struct RastPort)))
- {
- InitRastPort(inst->wk_buffer);
- inst->wk_buffer->BitMap=work_bm;
-
- inst->text_y=((g->Height-((inst->textFont->tf_Baseline+inst->textFont->tf_YSize)>>1))>>1);
- if(inst->textFont->tf_Baseline<inst->textFont->tf_YSize)
- {
- inst->text_y+=inst->textFont->tf_Baseline-1;
- if(inst->text_y<inst->textFont->tf_Baseline)inst->text_y=inst->textFont->tf_Baseline;
- }
- else
- {
- inst->text_y+=inst->textFont->tf_YSize-1;
- if(inst->text_y<inst->textFont->tf_YSize) inst->text_y=inst->textFont->tf_YSize;
- }
-
- SetDrMd(inst->wk_buffer,JAM1);
- SetFont(inst->wk_buffer,inst->textFont);
- }
- else
- {
- FreeBitMap(work_bm);
- return(0L);
- }
- }
- else return(0L);
- if(inst->type==GAU_Type_histmeter)
- {
- if(work_bm=(struct BitMap *)AllocBitMap(g->Width,g->Height+2,rp->BitMap->Depth,BMF_CLEAR,inst->wk_buffer->BitMap))
- {
- if(inst->hs_buffer=(struct RastPort *)pAllocVec(sizeof(struct RastPort)))
- {
- inst->histpos=0;
- InitRastPort(inst->hs_buffer);
- inst->hs_buffer->BitMap=work_bm;
- my_Blit(inst->bg_buffer,0,0,inst->hs_buffer,0,0,g->Width,g->Height);
- }
- else
- {
- FreeBitMap(work_bm);
- return(0L);
- }
- }
- else return(0L);
- }
- else inst->hs_buffer=0L;
- inst->old_cur=-1;
- inst->old_bas=-1;
- inst->InitNotDone=FALSE;
- }
-
- wk_rp=inst->wk_buffer;
- bg_rp=inst->bg_buffer;
- switch (inst->type)
- {
- case GAU_Type_gauge:
- w=g->Width;
- h=g->Height;
- max=inst->max>>8;
- if((inst->current!=inst->old_cur)||(inst->base!=inst->old_bas))
- {
- inst->old_cur=inst->current;
- inst->old_bas=inst->base;
- if(inst->highlight)
- {
- SetDrMd(rp,JAM1);
- SetFont(rp,inst->textFont);
- if(inst->StyleBorder)draw_border_new(rp,inst->labelpos+g->LeftEdge,g->TopEdge,w-inst->labelpos,g->Height,inst->Pens[col_dark],inst->Pens[col_bright]);
- if(inst->StyleShadowLabel)
- {
- SetAPen(rp,inst->Pens[col_dark]);
- Move(rp,1+g->LeftEdge,inst->text_y+1+g->TopEdge);
- Text(rp,inst->txtlbl,my_strlen(inst->txtlbl));
- }
- SetAPen(rp,inst->Pens[col_label]);
- Move(rp,g->LeftEdge,inst->text_y+g->TopEdge);
- Text(rp,inst->txtlbl,my_strlen(inst->txtlbl));
- inst->highlight=FALSE;
- }
-
- g_x=1+inst->labelpos;
- g_size=w-inst->labelpos-2;
- g_height=h-2;
- my_Blit(bg_rp,g_x,1,wk_rp,g_x,1,g_size,g_height);
-
- if((!inst->StyleNoGauge)&&(inst->current<inst->max))
- {
- x1=g_size-(WORD)(((inst->base>>8) *g_size)/((max)==0 ? 1 : (max)));
- x2=g_size-(WORD)(((inst->current>>8)*g_size)/((max)==0 ? 1 : (max)));
-
- if(!inst->StyleNoBase)
- {
- if(x1<x2)
- {
- SetAPen(wk_rp,inst->Pens[col_base]);
- my_RectFill(wk_rp,g_x,1,x1,g_height);
- SetAPen(wk_rp,inst->Pens[col_current]);
- my_RectFill(wk_rp,g_x+x1,1,x2-x1,g_height);
-
- if(!inst->StyleBackground)
- {
- SetAPen(wk_rp,inst->Pens[col_bg]);
- my_RectFill(wk_rp,g_x+x2,1,g_size-x2,g_height);
- }
- if(inst->Style3D)
- {
- if(x1>1) draw_border_new(wk_rp,g_x,1,x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
- if(x2-x1>1)draw_border_new(wk_rp,g_x+x1,1,x2-x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
- }
- }
- else if(x1>x2)
- {
- SetAPen(wk_rp,inst->Pens[col_base]);
- my_RectFill(wk_rp,g_x,1,x2,g_height);
- SetAPen(wk_rp,inst->Pens[col_negative]);
- my_RectFill(wk_rp,g_x+x2,1,x1-x2,g_height);
-
- if(!inst->StyleBackground)
- {
- SetAPen(wk_rp,inst->Pens[col_bg]);
- my_RectFill(wk_rp,g_x+x1,1,g_size-x1,g_height);
- }
- if(inst->Style3D)
- {
- if(x2>1) draw_border_new(wk_rp,g_x,1,x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
- if(x1-x2>1)draw_border_new(wk_rp,g_x+x2,1,x1-x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
- }
- }
- else
- {
- SetAPen(wk_rp,inst->Pens[col_base]);
- my_RectFill(wk_rp,g_x,1,x1,g_height);
-
- if(!inst->StyleBackground)
- {
- SetAPen(wk_rp,inst->Pens[col_bg]);
- my_RectFill(wk_rp,g_x+x1,1,g_size-x1,g_height);
- }
- if((inst->Style3D)&&(x1>1))draw_border_new(wk_rp,g_x,1,x1,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
- }
- }
- else
- {
- SetAPen(wk_rp,inst->Pens[col_current]);
- my_RectFill(wk_rp,g_x,1,x2,g_height);
- if(!inst->StyleBackground)
- {
- SetAPen(wk_rp,inst->Pens[col_bg]);
- my_RectFill(wk_rp,g_x+x2,1,g_size-x2,g_height);
- }
- if(inst->Style3D) draw_border_new(wk_rp,g_x,1,x2,g_height,inst->Pens[col_bright],inst->Pens[col_dark]);
- }
- }
- if(!inst->StyleNoFormat)
- {
- fmt=getSTR(inst);
- SetAPen(wk_rp,inst->Pens[col_format]);
- t_length=TextLength(wk_rp,fmt,my_strlen(fmt));
- if(t_length<(w-inst->labelpos-1))
- {
- switch(inst->fmtind)
- {
- case ind_centered:
- text_x=g_x+((g_size-t_length)>>1);
- break;
- case ind_left:
- text_x=g_x+2;
- break;
- case ind_right:
- text_x=w-t_length-3;
- break;
- }
- Move(wk_rp,text_x,inst->text_y);
- Text(wk_rp,fmt,my_strlen(fmt));
- }
- }
- my_Blit(wk_rp,g_x,1,rp,g->LeftEdge+g_x,1+g->TopEdge,g_size,g_height);
- }
- break;
- case GAU_Type_histmeter:
- max=inst->max>>8;
- w=g->Width;
- h=g->Height;
- g_size=h-1;
- hs_rp=inst->hs_buffer;
- if((!inst->StyleNoGauge)&&(inst->current<inst->max))
- {
- x1=(WORD)(((inst->base >>8)*(g_size-1))/((max)==0 ? 1 : (max)))+1;
- x2=(WORD)(((inst->current>>8)*(g_size-1))/((max)==0 ? 1 : (max)))+1;
- inst->histpos++;
- if(inst->histpos>w-3)
- {
- if(inst->StyleBackground)
- {
- my_Blit(inst->bg_buffer,0,0,inst->hs_buffer,0,0,w,h);
- my_Blit(inst->bg_buffer,0,0,rp,g->LeftEdge,g->TopEdge,w,h);
- }
- else
- {
- SetAPen(hs_rp,inst->Pens[col_bg]);
- RectFill(hs_rp,0,0,w,h);
- SetAPen(rp,inst->Pens[col_bg]);
- RectFill(rp,g->LeftEdge,g->TopEdge,g->LeftEdge+g->Width,g->TopEdge+g->Height);
- }
- inst->histpos=0L;
- }
- if(!inst->StyleNoBase)
- {
- SetAPen(hs_rp,inst->Pens[col_base]);
- if(x1>x2)
- {
- RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
- SetAPen(hs_rp,inst->Pens[col_current]);
- RectFill(hs_rp,inst->histpos,x2,inst->histpos,x1);
- }
- else if(x1<x2)
- {
- RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
- SetAPen(hs_rp,inst->Pens[col_negative]);
- RectFill(hs_rp,inst->histpos,x1,inst->histpos,x2);
- }
- else
- {
- RectFill(hs_rp,inst->histpos,x1,inst->histpos,g_size);
- }
- }
- else
- {
- SetAPen(hs_rp,inst->Pens[col_current]);
- RectFill(hs_rp,inst->histpos,x2,inst->histpos,g_size);
- }
- my_Blit(hs_rp,inst->histpos,0,rp,inst->histpos+g->LeftEdge,g->TopEdge,1,h-1);
- }
- if(inst->StyleBorder)draw_border_new(rp,g->LeftEdge,g->TopEdge,w,h,inst->Pens[col_dark],inst->Pens[col_bright]);
- if(!inst->StyleNoFormat)
- {
- fmt=getSTR(inst);
- SetAPen(wk_rp,inst->Pens[col_format]);
- t_length=TextLength(wk_rp,fmt,my_strlen(fmt));
- if(t_length<w)
- {
- UWORD x1,x2,y1,y2;
- switch(inst->fmtind)
- {
- case ind_centered:
- text_x=((w-t_length)>>1);
- break;
- case ind_left:
- text_x=2;
- break;
- case ind_right:
- text_x=w-t_length-2;
- break;
- }
- if((inst->oldlgth>t_length)||(inst->oldx<text_x))
- {
- x1=inst->oldx;
- x2=inst->oldlgth;
- }
- else
- {
- x1=text_x;
- x2=t_length;
- }
- y1=h-1-inst->textFont->tf_YSize;
- y2=inst->textFont->tf_YSize;
- if((x1>0)&&((y1)>0)&&((x1+x2)<w))
- {
- my_Blit(hs_rp,x1,y1,wk_rp,x1, y1, x2,y2);
- Move(wk_rp,text_x,h-3);
- Text(wk_rp,fmt,my_strlen(fmt));
- my_Blit(wk_rp,x1,y1,rp, x1+g->LeftEdge,y1+g->TopEdge,x2,y2);
- }
- inst->oldlgth=t_length;
- inst->oldx=text_x;
- }
- }
- break;
- case GAU_Type_clock:
- if(inst->clocktxt)
- {
- w=g->Width-1;
- h=g->Height;
- DateStamp((struct DateStamp *)&d_stamp);
- inst->clockpos=0; putCharHook.h_Data=inst; FormatDate(inst->locale,inst->txtfmt,&d_stamp,&putCharHook);
- if((t_length=TextLength(wk_rp,inst->clocktxt,my_strlen(inst->clocktxt)))<w)
- {
- switch(inst->fmtind)
- {
- case ind_centered:
- text_x=(w-t_length)>>1;
- break;
- case ind_left:
- text_x=0;
- break;
- case ind_right:
- text_x=w-t_length-1;
- break;
- }
- if(inst->oldclockw>t_length)
- {
- my_Blit(bg_rp,inst->oldclockx,0,wk_rp,inst->oldclockx,0,inst->oldclockw,h);
- }
- else
- {
- my_Blit(bg_rp,text_x,0,wk_rp,text_x,0,t_length,h);
- }
- if(inst->StyleShadowLabel)
- {
- SetAPen(wk_rp,inst->Pens[col_dark]);
- Move(wk_rp,text_x+1,inst->text_y+1);
- Text(wk_rp,inst->clocktxt,my_strlen(inst->clocktxt));
- }
- SetAPen(wk_rp,inst->Pens[col_format]);
- Move(wk_rp,text_x,inst->text_y);
- Text(wk_rp,inst->clocktxt,my_strlen(inst->clocktxt));
- if(inst->oldclockw>t_length)
- {
- my_Blit(wk_rp,inst->oldclockx,0,rp,g->LeftEdge+inst->oldclockx,g->TopEdge,inst->oldclockw,h);
- }
- else
- {
- my_Blit(wk_rp,text_x,0,rp,g->LeftEdge+text_x,g->TopEdge,t_length,h);
- }
- inst->oldclockx=text_x;
- inst->oldclockw=t_length;
- }
- }
- break;
- }
- if((msg->MethodID !=GM_RENDER)&&(msg->MethodID !=MY_REFRESH))ReleaseGIRPort(rp);
- return(TRUE);
- }
- else return(FALSE);
- }
-
-