// GraphicsWindowTest.cc // test the graphics package // (C) 2002 Bill Lenhart #include "GraphicsWindow.h" int main() { // Pink-Purple (255,0,255) in unsigned long format unsigned long aColorIndex = ((255*256)+0)*256+255; int x, y; // coordinates for a point char ch; // holds an input character // Create some windows GraphicsWindow window1(300,200); GraphicsWindow window2(256,256); // Make them visible window1.Show(); window2.Show(); // Draw some pixels in default color of window window1.DrawPixel(int(0.33*x), int(0.33*y)); window1.DrawPixel(int(0.66*x), int(0.66*y)); // and a segment window1.DebugSegment(10,90,90,10); // Do the same in window2 // Note: 2 different ways to draw in a given color window2.DrawPixel(30, 30, aColorIndex); window2.DrawPixel(170, 170, 255, 0, 255); // Now set window2 drawing color window2.SetForeground(aColorIndex); window2.DebugSegment(10,90,90,10); // Force graphics to appear on screen. Why: // X is a complex network-savvy, client-server system window1.Flush(); cout << "Enter any non-white char to continue: "; cin >> ch; window1.Erase(); // Set window1 drawing color to yellow window1.SetForeground(255, 255, 0); // Draw a big X window1.BigX(); window2.Flush(); cout << "Enter any non-white char to continue: "; cin >> ch; window1.Erase(); window2.Erase(); cout << "Enter PenMode for window2: (c)opy, (i)gnore, x(or), (a)nd, (o)r: "; cin >> ch; // Set pen mode switch (ch) { case('i') : window2.SetPenMode(GraphicsWindow::IgnoreMode); break; case('x') : window2.SetPenMode(GraphicsWindow::XOrMode); break; case('a') : window2.SetPenMode(GraphicsWindow::AndMode); break; case('o') : window2.SetPenMode(GraphicsWindow::OrMode); break; case('c') : default: window2.SetPenMode(GraphicsWindow::CopyMode); break; } // Repeatedly fill window using (R,G,B) intensity values // Outer loop slowly increases level of green // Inner loops control red (x direction) and blue (y direction) for(int green=0;green<256;green++) { cout << "Green level = " << green << endl; for(int blue=0;blue<256;blue++) for(int red=0;red<256;red++) { // Can use either integer (r,g,b) values window1.DrawPixel(red, blue, red, green, blue); // or floats window2.DrawPixel(red,blue,float(red/256.0), float(green/256.0), float(blue/256.0)); } // after each fill, force window update window2.Flush(); } // Erase depends on mode: only does "true" erase in CopyMode window2.SetPenMode(GraphicsWindow::CopyMode); window2.Erase(); // Draw a big X window2.BigX(); window2.Flush(); return(0); }