Using Color in edm Widgets

The details of using color related objects and methods can best be seen by examining code for the example widget. Nevertheless, the following code fragments demonstrate some of the issues involved in using color objects in a widget. Note that the color of an object is normally not set to "RED" (or some other literal color), but is instead set to the color specified interactively by the user of the widget.

// in the widget .h file ...

// if a color will be sensitive to pv alarm and connection state
// use the pvColorClass object
pvColorClass fgColor;
int bufFgColor; // for the property dialog box

// else use an int
int bgColor;
int bufBgColor; // for the property dialog box

// declare a color button object for each color object; these will
// tie the color objects to the color palette/menu through the
// property dialog box
colorButtonClass fgCb, bgCb;



// in the widget .cc file ...

  // ------------------------------------------------------------
  // Initialization code will set the alarm sensitivity
  // and connect sensitivity of the pvColorClass object
  fgColor.setConnectSensitive();

  fgColor.setAlarmSensitive();


  // ------------------------------------------------------------
  // process variable callback code will set the alarm and
  // connect state of the pvColorClass object
  obj->fgColor.setDisconnected();

  obj->fgColor.setStatus( st, sev );


  // ------------------------------------------------------------
  // entry form callback code will be written to update color objects;
  // the code will look something like the following
  obj->fgColor.setColorIndex( obj->bufFgColor, obj->actWin->ci );

  obj->bgColor = obj->bufBgColor;


  // ------------------------------------------------------------
  // add the color buttons to the property dialog box
  ef.addColorButton( "Fg", actWin->ci, &fgCb, &bufFgColor );
  ef.addColorButton( "Bg", actWin->ci, &bgCb, &bufBgColor );


  // ------------------------------------------------------------
  // draw an object with the foreground color
  actWin->drawGc.setFG( fgColor.pixelColor(), &blink );
  XDrawRectangle( actWin->d, XtWindow(actWin->drawWidget),
   actWin->drawGc.normGC(), x, y, w, h );


  // ------------------------------------------------------------
  // draw an object with the background color
  actWin->drawGc.setFG( actWin->ci->pix(bgColor), &blink );
  XDrawRectangle( actWin->d, XtWindow(actWin->drawWidget),
   actWin->drawGc.normGC(), x, y, w, h );


  // ------------------------------------------------------------
  // draw an image string using foreground and background
  actWin->drawGc.setFG( fgColor.pixelColor(), &blink );
  actWin->drawGc.setBG( actWin->ci->pix(bgColor) ); // BG blinking not allowed
  XDrawImageString( actWin->d, XtWindow(actWin->drawWidget),
   actWin->drawGc.normGC(), stringX, stringY, string, stringLength );