Skip to content
Snippets Groups Projects
FXColorRing.i 5.55 KiB
Newer Older
/***********************************************************************
 * FXRuby -- the Ruby language bindings for the FOX GUI toolkit.
 * Copyright (c) 2001-2009 by Lyle Johnson. All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * For further information please contact the author by e-mail
 * at "lyle@lylejohnson.name".
 ***********************************************************************/

%rename("hue=")       FXColorRing::setHue(FXfloat);
%rename("hue")        FXColorRing::getHue() const;
%rename("sat=")       FXColorRing::setSat(FXfloat);
%rename("sat")        FXColorRing::getSat() const;
%rename("val=")       FXColorRing::setVal(FXfloat);
%rename("val")        FXColorRing::getVal() const;
%rename("ringWidth=") FXColorRing::setRingWidth(FXint);
%rename("ringWidth")  FXColorRing::getRingWidth() const;
%rename("helpText=")  FXColorRing::setHelpText(const FXString&);
%rename("helpText")   FXColorRing::getHelpText() const;
%rename("tipText=")   FXColorRing::setTipText(const FXString&);
%rename("tipText")    FXColorRing::getTipText() const;

/**
* A Color Ring widget provides an intuitive way to specify a color.
* The outer ring of the widget is rotated to control the hue of the color
* being specified, while the inner triangle varies the color saturation
* and the brightness of the color.  The color saturation axis of the
* triangle goes from a fully saturated "pure" color to "pastel" color;
* the brightness goes from black to a bright color.
*/
class FXColorRing : public FXFrame {
protected:
  FXImage  *dial;         // HSV dial image
  FXfloat   hsv[3];       // Hue, saturation, value
  FXint     ringwidth;    // Width of hue ring
  FXint     ringouter;    // Outer radius
  FXint     ringinner;    // Inner radius
  FXint     dialx;        // Dial x location
  FXint     dialy;        // Dial y location
  FXint     satvalx;      // Saturation value x
  FXint     satvaly;      // Saturation value y
  FXint     huex;         // Hue x
  FXint     huey;         // Hue y
  FXint     clrx;         // Color corner of triangle
  FXint     clry;
  FXint     blkx;         // Black corner of triangle
  FXint     blky;
  FXint     whtx;         // White corner of triangle
  FXint     whty;
  FXString  tip;          // Tooltip value
  FXString  help;         // Help value
  FXuchar   mode;         // Mode widget is in
protected:
  FXColorRing();
  void updatering();
  FXfloat hueFromXY(FXint x,FXint y) const;
  void hueToXY(FXint& x,FXint& y,FXfloat hue) const;
  void satValToXY(FXint& x,FXint& y,FXfloat s,FXfloat v) const;
  void satValFromXY(FXfloat& s,FXfloat& v,FXint x,FXint y) const;
  FXbool inCorner(FXint x,FXint y) const;
  FXbool inHueRing(FXint x,FXint y) const;
  FXbool inTriangle(FXint x,FXint y) const;
protected:
  enum {
    MOUSE_NONE,         // No mouse operation
    MOUSE_HUE,          // Moving in hue-ring
    MOUSE_SATVAL        // Moving in saturation/value triangle
    };
private:
  FXColorRing(const FXColorRing&);
  FXColorRing &operator=(const FXColorRing&);
public:
  long onPaint(FXObject*,FXSelector,void* PTR_EVENT);
  long onLeftBtnPress(FXObject*,FXSelector,void* PTR_EVENT);
  long onLeftBtnRelease(FXObject*,FXSelector,void* PTR_EVENT);
  long onMotion(FXObject*,FXSelector,void* PTR_EVENT);
  long onMouseWheel(FXObject*,FXSelector,void* PTR_EVENT);
  long onCmdSetHelp(FXObject*,FXSelector,void* PTR_STRING);
  long onCmdGetHelp(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onCmdSetTip(FXObject*,FXSelector,void* PTR_STRING);
  long onCmdGetTip(FXObject*,FXSelector,void* PTR_IGNORE); // FIXME
  long onQueryHelp(FXObject*,FXSelector,void* PTR_NULL);
  long onQueryTip(FXObject*,FXSelector,void* PTR_NULL);
public:

  %extend {
    /// Construct color ring with initial color clr
    FXColorRing(FXComposite* p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=FRAME_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=DEFAULT_PAD,FXint pr=DEFAULT_PAD,FXint pt=DEFAULT_PAD,FXint pb=DEFAULT_PAD){
      return new FXRbColorRing(p,tgt,sel,opts,x,y,w,h,pl,pr,pt,pb);
      }
  }

  /// Change hue
  void setHue(FXfloat h);

  /// Return hue
  FXfloat getHue() const;

  /// Change saturation
  void setSat(FXfloat s);

  /// Return saturation
  FXfloat getSat() const;

  /// Change value
  void setVal(FXfloat v);

  /// Return value
  FXfloat getVal() const;

  /// Set hue, saturation, value
  void setHueSatVal(FXfloat h,FXfloat s,FXfloat v);

  /// Change width of hue ring
  void setRingWidth(FXint rw);

  /// Return width of hue ring
  FXint getRingWidth() const;

  /// Set status line help text for this color well
  void setHelpText(const FXString& text);

  /// Get status line help text for this color well
  const FXString& getHelpText() const;

  /// Set tool tip message for this color well
  void setTipText(const FXString& text);

  /// Get tool tip message for this color well
  const FXString& getTipText() const;

 /// Destructor
  virtual ~FXColorRing();
  };