// DefaultColours.cc
// Gloobs example program
//
// create swatches of the default g2 colours
//
// by Smylers
// 2000 Jan 10: original version
// 2000 Jan 17: improved comments
#include <gloobs.h>
#include <stdio.h> // for sprintf() to print the numbers
// g2 has 27 colours defined by default:
const int NumColrs = 27;
// size of swatches to create:
const int SwatchHeight = 20;
const int SwatchLft = 5;
const int SwatchRgt = 35;
int main()
{
// create an appropriately-sized canvas:
Gloobs::Canvas Swatches(Gloobs::X11, 60, NumColrs * SwatchHeight + 5,
"g2_Colours");
// loop through each colour:
for (int ColrNum = 0; ColrNum < NumColrs; ColrNum++)
{
// calculate where the bottom and top of the current colour's swatch should
// go:
int Btm = ColrNum * SwatchHeight + 5;
int Top = (ColrNum + 1) * SwatchHeight;
// draw the swatch in that colour:
Swatches.pen(ColrNum);
Swatches.filled_rectangle(SwatchLft, Btm, SwatchRgt, Top);
// drawn around the swatch in colour 1, which is black:
Swatches.pen(1);
Swatches.rectangle(SwatchLft, Btm, SwatchRgt, Top);
// convert the swatch number to a string:
char NumTxt[3];
sprintf(NumTxt, "%d", ColrNum);
// draw this string on the canvas:
Swatches.string(SwatchRgt + 5, Btm + 2, NumTxt);
} // end of loop through each colour
Swatches.pause();
return 0;
}