Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXColorRing.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                         C o l o r R i n g   W i d g e t                       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2005,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXColorRing.h,v 1.11 2006/01/22 17:57:59 fox Exp $                       *
00023 ********************************************************************************/
00024 #ifndef FXCOLORRING_H
00025 #define FXCOLORRING_H
00026 
00027 #ifndef FXFRAME_H
00028 #include "FXFrame.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 class FXImage;
00035 
00036 
00037 /**
00038 * A Color Ring widget provides an intuitive way to specify a color.
00039 * The outer ring of the widget is rotated to control the hue of the color
00040 * being specified, while the inner triangle varies the color saturation
00041 * and the brightness of the color.  The color saturation axis of the
00042 * triangle goes from a fully saturated "pure" color to "pastel" color;
00043 * the brightness goes from black to a bright color.
00044 */
00045 class FXAPI FXColorRing : public FXFrame {
00046   FXDECLARE(FXColorRing)
00047 protected:
00048   FXImage  *dial;         // HSV dial image
00049   FXfloat   hsv[3];       // Hue, saturation, value
00050   FXint     ringwidth;    // Width of hue ring
00051   FXint     ringouter;    // Outer radius
00052   FXint     ringinner;    // Inner radius
00053   FXint     dialx;        // Dial x location
00054   FXint     dialy;        // Dial y location
00055   FXint     satvalx;      // Saturation value x
00056   FXint     satvaly;      // Saturation value y
00057   FXint     huex;         // Hue x
00058   FXint     huey;         // Hue y
00059   FXint     clrx;         // Color corner of triangle
00060   FXint     clry;
00061   FXint     blkx;         // Black corner of triangle
00062   FXint     blky;
00063   FXint     whtx;         // White corner of triangle
00064   FXint     whty;
00065   FXString  tip;          // Tooltip value
00066   FXString  help;         // Help value
00067   FXuchar   mode;         // Mode widget is in
00068 protected:
00069   FXColorRing();
00070   void updatering();
00071   FXfloat hueFromXY(FXint x,FXint y) const;
00072   void hueToXY(FXint& x,FXint& y,FXfloat hue) const;
00073   void satValToXY(FXint& x,FXint& y,FXfloat s,FXfloat v) const;
00074   void satValFromXY(FXfloat& s,FXfloat& v,FXint x,FXint y) const;
00075   FXbool inCorner(FXint x,FXint y) const;
00076   FXbool inHueRing(FXint x,FXint y) const;
00077   FXbool inTriangle(FXint x,FXint y) const;
00078 protected:
00079   enum {
00080     MOUSE_NONE,         // No mouse operation
00081     MOUSE_HUE,          // Moving in hue-ring
00082     MOUSE_SATVAL        // Moving in saturation/value triangle
00083     };
00084 private:
00085   FXColorRing(const FXColorRing&);
00086   FXColorRing &operator=(const FXColorRing&);
00087 public:
00088   long onPaint(FXObject*,FXSelector,void*);
00089   long onLeftBtnPress(FXObject*,FXSelector,void*);
00090   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00091   long onMotion(FXObject*,FXSelector,void*);
00092   long onMouseWheel(FXObject*,FXSelector,void*);
00093   long onCmdSetHelp(FXObject*,FXSelector,void*);
00094   long onCmdGetHelp(FXObject*,FXSelector,void*);
00095   long onCmdSetTip(FXObject*,FXSelector,void*);
00096   long onCmdGetTip(FXObject*,FXSelector,void*);
00097   long onQueryHelp(FXObject*,FXSelector,void*);
00098   long onQueryTip(FXObject*,FXSelector,void*);
00099 public:
00100 
00101   /// Construct color ring with initial color clr
00102   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);
00103 
00104   /// Create server-side resources
00105   virtual void create();
00106 
00107   /// Detach server-side resources
00108   virtual void detach();
00109 
00110   /// Perform layout
00111   virtual void layout();
00112 
00113   /// Return default width
00114   virtual FXint getDefaultWidth();
00115 
00116   /// Return default height
00117   virtual FXint getDefaultHeight();
00118 
00119   /// Change hue
00120   void setHue(FXfloat h);
00121 
00122   /// Return hue
00123   FXfloat getHue() const { return hsv[0]; }
00124 
00125   /// Change saturation
00126   void setSat(FXfloat s);
00127 
00128   /// Return saturation
00129   FXfloat getSat() const { return hsv[1]; }
00130 
00131   /// Change value
00132   void setVal(FXfloat v);
00133 
00134   /// Return value
00135   FXfloat getVal() const { return hsv[2]; }
00136 
00137   /// Set hue, saturation, value
00138   void setHueSatVal(FXfloat h,FXfloat s,FXfloat v);
00139 
00140   /// Change width of hue ring
00141   void setRingWidth(FXint rw);
00142 
00143   /// Return width of hue ring
00144   FXint getRingWidth() const { return ringwidth; }
00145 
00146   /// Set status line help text for this color well
00147   void setHelpText(const FXString& text){ help=text; }
00148 
00149   /// Get status line help text for this color well
00150   const FXString& getHelpText() const { return help; }
00151 
00152   /// Set tool tip message for this color well
00153   void setTipText(const FXString& text){ tip=text; }
00154 
00155   /// Get tool tip message for this color well
00156   const FXString& getTipText() const { return tip; }
00157 
00158   /// Save color well to a stream
00159   virtual void save(FXStream& store) const;
00160 
00161   /// Load color well from a stream
00162   virtual void load(FXStream& store);
00163 
00164   /// Destructor
00165   virtual ~FXColorRing();
00166   };
00167 
00168 }
00169 
00170 #endif

Copyright © 1997-2005 Jeroen van der Zijp