[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    Color(3X) manual page Table of Contents

Name

Color - color for use by a Painter

Remarks:

The displayed intensities of a color will depend on the characteristics of the display hardware.

Synopsis

#include <ivplus/color.h>

Description

Color defines a mix of red, green and blue intensities.

Class Hierarchy

Color->Resource

Constructors

Color(int r, int g, int b)

Constructs a color with the given red, green and blue intensities. White is the color whose red, green, and blue intensities are all zero. Zero represents no intensity, 65535 represents full intensity.

Public Operations

virtual boolean distinguished(Display*, const Color*) const

Returns true if the given display can distinguish the color, false otherwise.

virtual boolean distinguished(const Color*) const

Returns true if the default display can distinguish the color, false otherwise.

void Intensities(int& r, int& g, int& b) const

Gets the integer value of the intensities used to display the color.

static const Color* lookup(Display*, const char* name)

Returns a pointer to the color object associated with the given name. The list of valid names can be found in the X11 rgb.txt file. Alternately, the name can be of the form #rrggbb where rr is the hexadecimal value for red, gg for green, and bb for blue. If the color is not found, the returned value is nil.

The display pointer to be passed into this function can be accessed by calling: World::current()->display().

int PixelValue() const

Returns the color’s index in its color map.

ColorRep* rep(Display*) const

Returns a pointer to the ColorRep for the color. The ColorRep class is a low level interface to X Windows. It is not expected that developers will need details of the ColorRep interface so the ColorRep class is not documented.

Protected Operations

None.

X Resources

None.

Examples


//                          Color Example
#include <ivplus/color.h>
#include <ivplus/interactor.h>
#include <ivplus/frame.h>
#include <ivplus/painter.h>
#include <ivplus/shape.h>
#include <ivplus/world.h>
// Create a derived class from Interactor to make use of color.
class MyInteractor : public Interactor {
public:
   MyInteractor() {};
private:
   void Reconfig();
   void Redraw(IntCoord, IntCoord, IntCoord, IntCoord);
};
// Define shape of MyInteractor here.
void MyInteractor::Reconfig()
{
   Interactor::Reconfig();
   shape->width = 300; // pixels
   shape->height = 300;
};
// Do the drawing here
void MyInteractor::Redraw(IntCoord, IntCoord, IntCoord, IntCoord)
{
   int i;
  
   // Make foreground & background colors with some RGB value.
   const Color* fg1 = new Color(35000, 65535, 0);
   const Color* bg1 = new Color(0, 35000, 65535);
   // Make foreground & background colors from the display value.
   // This can be used if the window is mapped.
   // World* w = GetWorld();
   // Display* dp = w->display();
   // const Color* fg2 = Color::lookup (dp, "black");
   // const Color* bg2 = Color::lookup (dp, "white");
  
   // Draw a few filled rectangles using the fg, bg colors on the canvas.
   for (i=0; i<5; i++)
   { 
      // Set the painter foreground & background colors
      // change the bg & fg after each iteration.
      if (i%2)   
         output->SetColors(fg1, bg1);
      else
         output->SetColors(bg1, fg1);
      output->FillRect(canvas, (i*50), (i*50), shape->width-(i*50),
                 shape->height-(i*50));
   }
};
int main(int argc, char **argv)
{
   World* world = new World("MyApp", argc, argv);
  
   // Make an instance of MyInteractor.
   MyInteractor* interactor = new MyInteractor();
  
   // Map the window.
   world->InsertApplication(new Frame(interactor, 1, BevelOut));
   // Enter the event loop.
   world->Run();
   return 0;
}

Files


color.h

See Also

Painter(3X) , Resource(3X) .


Table of Contents