
/***************************************************************************
    1/89

        DIRK v2.0 -- Tune workbench colors to system performance

        Copyright (C) 1989 by Daniel Elbaum

        This software is freely redistributable provided that:
        the four files which comprise it (dirk, dirk.doc, dirk.h,
        adjust.c, main.c, sys, window.c) remain intact; all
        copyright notices contained in any of the aforementioned
        files remain intact; and no fee beyond reasonable remuneration
        for collation and distribution be charged for use and/or
        distribution.

***************************************************************************/


#include "dirk.h"

#define T_LEFT   (6)    /* centers text nicely              */
#define T_HEIGHT (10)
#define T_TOP    (WINHT1+4)

void
setcolor(sp, tm, g_f)
register struct Screen *sp;
ULONG tm;
t_gf *g_f;
{
    register f, db, t;
    int tr, tw;
    int dr, dg, db;     /* detail red, blue, green  */
    int br, bg, bb;     /* bkgnd red, blue, green   */
    ULONG mu, fm;
    ULONG amtfree();

    if (g_f->dstog){
        tqlen(&tr, &tw);

        f=CMAX-(tr+tw)/g_f->gran;
        if (f<g_f->dsmin) f=g_f->dsmin;
        if (f>g_f->dsmax) f=g_f->dsmax;
        if ((t=tr/g_f->gran+f)>CMAX) t=CMAX;
        /* Detail and Block pens seem to be reversed    */

        if ((dr=t+g_f->bd_r)>CMAX) dr=CMAX;
        if ((dg=t+g_f->bd_g)>CMAX) dg=CMAX;
        if ((db=t+g_f->bd_b)>CMAX) db=CMAX;
    }

    /* val = minval + ((mused / mtotal) * (maxval - minval)) */
    if (g_f->bstog){
        fm=amtfree();
        mu=tm-fm;
        br=g_f->lb_r+(mu*g_f->db_r)/tm;
        bg=g_f->lb_g+(mu*g_f->db_g)/tm;
        bb=g_f->lb_b+(mu*g_f->db_b)/tm;
    }

    Forbid();
    if (g_f->dstog) SetRGB4(sp->ViewPort, sp->BlockPen, dr, dg, db);
    if (g_f->bstog) SetRGB4(sp->ViewPort, sp->DetailPen, br, bg, bb);
    Permit();
}

#define N_TEXT  (8)
typedef struct IntuiText t_it;

void
fillwin(wp)
struct Window *wp;
{
    register i;
    int tr, tw;
    ULONG cavail, favail;
    char trbu[24], twbu[24], cabu[24], fabu[24];
    t_it *ita[N_TEXT];

    memset(ita, 0, sizeof(ita));
    for (i=0; i<N_TEXT; ++i)
        if (!(ita[i]=(t_it *)AllocMem(sizeof(t_it), MEMF_PUBLIC|MEMF_CLEAR)))
            break;
    if (i<N_TEXT){
        for (i=0; i<N_TEXT; ++i)
            if (ita[i]) FreeMem(ita[i], sizeof(t_it));
        return;
    }
    Forbid();
    cavail=AvailMem(MEMF_CHIP);
    favail=AvailMem(MEMF_FAST);
    Permit();

    tqlen(&tr, &tw);
    sprintf(trbu, "Ready:    %3.3d", tr);
    sprintf(twbu, "Waiting:  %3.3d", tw);
    sprintf(cabu, "Chip: %7.7d", cavail);
    sprintf(fabu, "Fast: %7.7d", favail);

    ita[0]->FrontPen=wp->BlockPen;
    ita[0]->BackPen=wp->DetailPen;
    ita[0]->DrawMode=JAM2;

    for (i=1; i<N_TEXT; ++i)
        memcpy(ita[i], ita[0], sizeof(t_it));

    ita[0]->TopEdge=0;
    ita[0]->IText="2.0  (C) 1989";
    ita[0]->NextText=ita[1];
    ita[1]->TopEdge=T_HEIGHT;
    ita[1]->IText="Daniel Elbaum";
    ita[1]->NextText=ita[2];
    ita[2]->TopEdge=T_HEIGHT*3;
    ita[2]->IText="    Tasks";
    ita[2]->NextText=ita[3];
    ita[3]->IText=trbu;
    ita[3]->TopEdge=T_HEIGHT*4;
    ita[3]->NextText=ita[4];
    ita[4]->IText=twbu;
    ita[4]->TopEdge=T_HEIGHT*5;
    ita[4]->NextText=ita[5];
    ita[5]->IText="  Memories";
    ita[5]->LeftEdge=6;
    ita[5]->TopEdge=T_HEIGHT*7;
    ita[5]->NextText=ita[6];
    ita[6]->IText=cabu;
    ita[6]->TopEdge=T_HEIGHT*8;
    ita[6]->NextText=ita[7];
    ita[7]->IText=fabu;
    ita[7]->TopEdge=T_HEIGHT*9;
    ita[7]->NextText=NULL;

    PrintIText(wp->RPort, ita[0], T_LEFT, T_TOP);
    for (i=0; i<N_TEXT; ++i)
        FreeMem(ita[i], sizeof(t_it));
    return;
}

