1 /******************************************************************************** 2 * * 3 * C o l o r R i n g W i d g e t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 2005,2006 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or * 9 * modify it under the terms of the GNU Lesser General Public * 10 * License as published by the Free Software Foundation; either * 11 * version 2.1 of the License, or (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 16 * Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public * 19 * License along with this library; if not, write to the Free Software * 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 21 ********************************************************************************* 22 * $Id: FXColorRing.h,v 1.11 2006/01/22 17:57:59 fox Exp $ * 23 ********************************************************************************/ 24 #ifndef FXCOLORRING_H 25 #define FXCOLORRING_H 26 27 #ifndef FXFRAME_H 28 #include "FXFrame.h" 29 #endif 30 31 namespace FX { 32 33 34 class FXImage; 35 36 37 /** 38 * A Color Ring widget provides an intuitive way to specify a color. 39 * The outer ring of the widget is rotated to control the hue of the color 40 * being specified, while the inner triangle varies the color saturation 41 * and the brightness of the color. The color saturation axis of the 42 * triangle goes from a fully saturated "pure" color to "pastel" color; 43 * the brightness goes from black to a bright color. 44 */ 45 class FXAPI FXColorRing : public FXFrame { 46 FXDECLARE(FXColorRing) 47 protected: 48 FXImage *dial; // HSV dial image 49 FXfloat hsv[3]; // Hue, saturation, value 50 FXint ringwidth; // Width of hue ring 51 FXint ringouter; // Outer radius 52 FXint ringinner; // Inner radius 53 FXint dialx; // Dial x location 54 FXint dialy; // Dial y location 55 FXint satvalx; // Saturation value x 56 FXint satvaly; // Saturation value y 57 FXint huex; // Hue x 58 FXint huey; // Hue y 59 FXint clrx; // Color corner of triangle 60 FXint clry; 61 FXint blkx; // Black corner of triangle 62 FXint blky; 63 FXint whtx; // White corner of triangle 64 FXint whty; 65 FXString tip; // Tooltip value 66 FXString help; // Help value 67 FXuchar mode; // Mode widget is in 68 protected: 69 FXColorRing(); 70 void updatering(); 71 FXfloat hueFromXY(FXint x,FXint y) const; 72 void hueToXY(FXint& x,FXint& y,FXfloat hue) const; 73 void satValToXY(FXint& x,FXint& y,FXfloat s,FXfloat v) const; 74 void satValFromXY(FXfloat& s,FXfloat& v,FXint x,FXint y) const; 75 FXbool inCorner(FXint x,FXint y) const; 76 FXbool inHueRing(FXint x,FXint y) const; 77 FXbool inTriangle(FXint x,FXint y) const; 78 protected: 79 enum { 80 MOUSE_NONE, // No mouse operation 81 MOUSE_HUE, // Moving in hue-ring 82 MOUSE_SATVAL // Moving in saturation/value triangle 83 }; 84 private: 85 FXColorRing(const FXColorRing&); 86 FXColorRing &operator=(const FXColorRing&); 87 public: 88 long onPaint(FXObject*,FXSelector,void*); 89 long onLeftBtnPress(FXObject*,FXSelector,void*); 90 long onLeftBtnRelease(FXObject*,FXSelector,void*); 91 long onMotion(FXObject*,FXSelector,void*); 92 long onMouseWheel(FXObject*,FXSelector,void*); 93 long onCmdSetHelp(FXObject*,FXSelector,void*); 94 long onCmdGetHelp(FXObject*,FXSelector,void*); 95 long onCmdSetTip(FXObject*,FXSelector,void*); 96 long onCmdGetTip(FXObject*,FXSelector,void*); 97 long onQueryHelp(FXObject*,FXSelector,void*); 98 long onQueryTip(FXObject*,FXSelector,void*); 99 public: 100 101 /// Construct color ring with initial color clr 102 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); 103 104 /// Create server-side resources 105 virtual void create(); 106 107 /// Detach server-side resources 108 virtual void detach(); 109 110 /// Perform layout 111 virtual void layout(); 112 113 /// Return default width 114 virtual FXint getDefaultWidth(); 115 116 /// Return default height 117 virtual FXint getDefaultHeight(); 118 119 /// Change hue 120 void setHue(FXfloat h); 121 122 /// Return hue getHue()123 FXfloat getHue() const { return hsv[0]; } 124 125 /// Change saturation 126 void setSat(FXfloat s); 127 128 /// Return saturation getSat()129 FXfloat getSat() const { return hsv[1]; } 130 131 /// Change value 132 void setVal(FXfloat v); 133 134 /// Return value getVal()135 FXfloat getVal() const { return hsv[2]; } 136 137 /// Set hue, saturation, value 138 void setHueSatVal(FXfloat h,FXfloat s,FXfloat v); 139 140 /// Change width of hue ring 141 void setRingWidth(FXint rw); 142 143 /// Return width of hue ring getRingWidth()144 FXint getRingWidth() const { return ringwidth; } 145 146 /// Set status line help text for this color well setHelpText(const FXString & text)147 void setHelpText(const FXString& text){ help=text; } 148 149 /// Get status line help text for this color well getHelpText()150 const FXString& getHelpText() const { return help; } 151 152 /// Set tool tip message for this color well setTipText(const FXString & text)153 void setTipText(const FXString& text){ tip=text; } 154 155 /// Get tool tip message for this color well getTipText()156 const FXString& getTipText() const { return tip; } 157 158 /// Save color well to a stream 159 virtual void save(FXStream& store) const; 160 161 /// Load color well from a stream 162 virtual void load(FXStream& store); 163 164 /// Destructor 165 virtual ~FXColorRing(); 166 }; 167 168 } 169 170 #endif 171