Category : Miscellaneous Language Source Code
Archive   : CHART20.ZIP
Filename : BRUSH.CLS

 
Output of file : BRUSH.CLS contained in archive : CHART20.ZIP
/* class comment */!!

inherit(Object, #Brush, #(nColors /* # of colors for device */
colorTable), 2, nil)!!

now(BrushClass)!!

/* Create a new chart object and initialize it. */
Def new(self)
{ ^init(new(self:Behavior));
}!!

now(Brush)!!

/* This will set the number of colors for the current device */
Def setNColors(self hDC | prevColors)
{ prevColors := nColors;
nColors := Call GetDeviceCaps(hDC, NUMCOLORS);
if ((nColors >= 2) and (prevColors <> nColors))
then colorTable := getColorTable(self, hDC);
endif;
}!!

/* This method will release a created brush's memory */
Def releaseBrush(self brush hDC)
{ ^Call DeleteObject(Call SelectObject(hDC,brush));
}!!

/* This method will create a new brush (depending on device type) */
Def getBrush(self brushNum hDC| brush)
{ if (nColors <= 2)
then
brush := Call CreateHatchBrush(brushNum mod 7,0x000000);
else
brush := Call CreateSolidBrush(colorTable[brushNum mod size(colorTable)]);
endif;
^Call SelectObject(hDC,brush);
}!!

/* Set up the instance variable for the new brush object */
Def init(self | hDC)
{ hDC := Call GetDC(0);
setNColors(self, hDC);
Call ReleaseDC(0, hDC);
}!!

/* This method will get the set of colors that Windows is using and store
them in a Set to be easily indexed. This method will not put the color
of the window into the Set, as to avoid drawing "invisible" shapes. */
Def getColorTable(self, hDC| colorSet, inP, outP)
{ colorSet := new(Set,2);
inP := new(Struct, 2);
outP := new(Struct, 4);
do(nColors, /* # of colors available in system */
{using(i) putWord(inP, i, 0); /* prepare struct to put into windows call */
if (Call Escape(hDC, GETCOLORTABLE, 0, inP, outP) > 0)
then if (Call GetSysColor(COLOR_WINDOW) <> longAt(outP, 0))
then add(colorSet, longAt(outP, 0));
endif;
endif;
});
^colorSet
}!!



  3 Responses to “Category : Miscellaneous Language Source Code
Archive   : CHART20.ZIP
Filename : BRUSH.CLS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/