Community Core Vision 1.4
Cross platform, user friendly computer vision.
C:/CCV/1.4/addons/ofxNCore/src/Controls/ofxGuiTypes.h
Go to the documentation of this file.
00001 /*
00002  *  ofxGuiTypes.h
00003  *  openFrameworks
00004  *
00005  *  Created by Stefan Kirch on 18.06.08.
00006  *  Copyright 2008 alphakanal. All rights reserved.
00007  *
00008  */
00009 
00010 //      ----------------------------------------------------------------------------------------------------
00011 
00012 #ifndef OFX_GUI_TYPES
00013 #define OFX_GUI_TYPES
00014 
00015 //      ----------------------------------------------------------------------------------------------------
00016 
00017 #define OF_ADDON_USING_OFXDIRLIST
00018 #define OF_ADDON_USING_OFXVECTORMATH
00019 #define OF_ADDON_USING_OFXXMLSETTINGS
00020 
00021 #include "ofMain.h"
00022 #include "ofAddons.h"
00023 
00024 //      ----------------------------------------------------------------------------------------------------
00025 
00026 #define OFXGUI_VERSION                  "0.10"
00027 #define OFXGUI_XML                              "ofxGui.xml"
00028 
00029 #define OFXGUI_PANEL_BORDER             10
00030 #define OFXGUI_PANEL_SPACING    10
00031 
00032 #define OFXGUI_BUTTON_HEIGHT    10
00033 #define OFXGUI_FILES_HEIGHT             15      
00034 #define OFXGUI_SLIDER_HEIGHT    10
00035 #define OFXGUI_COLOR_HEIGHT             30
00036 #define OFXGUI_MATRIX_SPACING    6
00037 
00038 //      ----------------------------------------------------------------------------------------------------
00039 
00040 static const string kofxGui_Tags[] =
00041 {
00042         "UI",
00043         "PANEL",
00044         "SLIDER",
00045         "XYPAD",
00046         "POINTS",
00047         "BUTTON",
00048         "FILES",
00049         "COLOR",
00050         "MATRIX",
00051         "SCOPE",
00052         "KNOB",
00053         "RADAR",
00054         "SWITCH",
00055 };
00056 
00057 enum
00058 {
00059         kofxGui_Object_Base,
00060         kofxGui_Object_Panel,
00061         kofxGui_Object_Slider,
00062         kofxGui_Object_XYPad,
00063         kofxGui_Object_Points,
00064         kofxGui_Object_Button,
00065         kofxGui_Object_Files,
00066         kofxGui_Object_Color,
00067         kofxGui_Object_Matrix,
00068         kofxGui_Object_Scope,
00069         kofxGui_Object_Knob,
00070         kofxGui_Object_Radar,
00071         kofxGui_Object_Switch,
00072 };
00073 
00074 enum
00075 {
00076         kofxGui_Display_Hex,
00077         kofxGui_Display_Int,
00078         kofxGui_Display_Float2,
00079         kofxGui_Display_Float4,
00080         kofxGui_Display_String,
00081 };
00082 
00083 enum
00084 {
00085         kofxGui_Button_Off,
00086         kofxGui_Button_On,
00087         kofxGui_Button_Switch,
00088         kofxGui_Button_Trigger,
00089 };
00090 
00091 enum
00092 {
00093         kofxGui_Color_RGB,
00094         kofxGui_Color_RGBA,
00095 };
00096 
00097 enum
00098 {
00099         kofxGui_Matrix_Clear,
00100         kofxGui_Matrix_Set,
00101         kofxGui_Matrix_Selected,
00102 };
00103 
00104 enum
00105 {
00106         kofxGui_Get_Bool,
00107         kofxGui_Get_Int,
00108         kofxGui_Get_Float,
00109         kofxGui_Get_Cell,
00110         kofxGui_Get_Point,
00111         kofxGui_Get_Color,
00112         kofxGui_Get_IntArray,
00113         kofxGui_Get_FloatArray,
00114         kofxGui_Get_String,
00115         
00116         kofxGui_Set_Bool,
00117         kofxGui_Set_Int,
00118         kofxGui_Set_Float,
00119         kofxGui_Set_Cell,
00120         kofxGui_Set_Point,
00121         kofxGui_Set_Color,
00122         kofxGui_Set_IntArray,
00123         kofxGui_Set_FloatArray,
00124         kofxGui_Set_String,
00125 };
00126 
00127 //      ----------------------------------------------------------------------------------------------------
00128 
00129 static inline int roundInt(float value)
00130 {
00131         return (int)(value + 0.5f);
00132 }
00133 
00134 static inline float linear(float fract, float x0, float x1)
00135 {
00136         return x0 + (x1 - x0) * fract;
00137 }
00138 
00139 // -----------------------------------------------------------------------------
00140 
00141 class ofxGuiListener
00142 { 
00143 public:
00144         
00145         virtual void handleGui(int parameterId, int task, void* data, int length){}
00146 };
00147 
00148 // -----------------------------------------------------------------------------
00149 
00150 class ofCell
00151 {
00152 public:
00153         
00154         int id;
00155         int value;
00156 
00157         ofCell()
00158         { 
00159                 id              = 0;
00160                 value   = 0;
00161         }
00162         
00163         ofCell(int _id, int _value)
00164         { 
00165                 id              = _id;
00166                 value   = _value;
00167         }
00168 };
00169 
00170 // -----------------------------------------------------------------------------
00171 
00172 class ofRGBA
00173 {
00174 public:
00175         
00176         float r;
00177         float g;
00178         float b;
00179         float a;
00180         
00181         ofRGBA()
00182         { 
00183                 r = 0.0f;
00184                 g = 0.0f;
00185                 b = 0.0f;
00186                 a = 1.0f;
00187         }
00188         
00189         ofRGBA(int rgba)
00190         {
00191                 r = ((rgba >> 24) & 0xFF) / 255.0f;
00192                 g = ((rgba >> 16) & 0xFF) / 255.0f;
00193                 b = ((rgba >>  8) & 0xFF) / 255.0f;
00194                 a = ((rgba >>  0) & 0xFF) / 255.0f;
00195         }
00196         
00197         ofRGBA(string hex)
00198         {
00199                 int rgba;
00200                 sscanf(hex.c_str(), "%x", &rgba);
00201                 
00202                 r = ((rgba >> 24) & 0xFF) / 255.0f;
00203                 g = ((rgba >> 16) & 0xFF) / 255.0f;
00204                 b = ((rgba >>  8) & 0xFF) / 255.0f;
00205                 a = ((rgba >>  0) & 0xFF) / 255.0f;
00206         }
00207         
00208         ofRGBA(int _r, int _g, int _b, int _a)
00209         {
00210                 r = (float)_r / 255.0f; r = MAX(0.0f, MIN(r, 1.0f));
00211                 g = (float)_g / 255.0f; g = MAX(0.0f, MIN(g, 1.0f));
00212                 b = (float)_b / 255.0f; b = MAX(0.0f, MIN(b, 1.0f));
00213                 a = (float)_a / 255.0f; a = MAX(0.0f, MIN(a, 1.0f));
00214         }
00215 
00216         ofRGBA(float _r, float _g, float _b, float _a)
00217         {
00218                 r = _r; r = MAX(0.0f, MIN(r, 1.0f));
00219                 g = _g; g = MAX(0.0f, MIN(g, 1.0f));
00220                 b = _b; b = MAX(0.0f, MIN(b, 1.0f));
00221                 a = _a; a = MAX(0.0f, MIN(a, 1.0f));
00222         }
00223         
00224         void setChanel(int chanel, float value)
00225         {
00226                 switch (chanel)
00227                 {
00228                         case 0:
00229                                 r = value;
00230                                 break;
00231                         case 1:
00232                                 g = value;
00233                                 break;
00234                         case 2:
00235                                 b = value;
00236                                 break;
00237                         case 3:
00238                                 a = value;
00239                                 break;
00240                 }
00241         }
00242 
00243         int toInt(int mode)
00244         {               
00245                 int red         = roundInt(r * 255.0f) & 0xFF;
00246                 int green       = roundInt(g * 255.0f) & 0xFF;
00247                 int blue        = roundInt(b * 255.0f) & 0xFF;
00248                 int alpha       = roundInt(a * 255.0f) & 0xFF;
00249                 
00250                 int value       = 0;
00251                 
00252                 if(mode == kofxGui_Color_RGB)
00253                         value = (red << 16) | (green << 8) | (blue << 0);
00254                 else if(mode == kofxGui_Color_RGBA)
00255                         value = (red << 24) | (green << 16) | (blue << 8) | (alpha << 0);
00256                 
00257                 return value;
00258         }
00259 
00260         string toString(int mode)
00261         {
00262                 char hex[9];
00263                 
00264                 int red         = roundInt(r * 255.0f);
00265                 int green       = roundInt(g * 255.0f);
00266                 int blue        = roundInt(b * 255.0f);
00267                 int alpha       = roundInt(a * 255.0f);
00268                 
00269                 if(mode == kofxGui_Color_RGB)
00270                         sprintf(hex, "%.2X%.2X%.2X", red, green, blue);
00271                 else if(mode == kofxGui_Color_RGBA)
00272                         sprintf(hex, "%.2X%.2X%.2X%.2X", red, green, blue, alpha);
00273                 
00274                 return hex;
00275         }
00276 }; 
00277 
00278 // -----------------------------------------------------------------------------
00279 
00280 class ofPointList
00281 {               
00282 public:
00283         
00284         int             activePoint;
00285         vector  <ofxPoint2f> points;
00286         
00287         ofPointList()
00288         {
00289                 activePoint     = -1;
00290         }
00291                 
00292         void addPointAtPosition(ofxPoint2f p)
00293         {
00294                 for(int i = 1; i < points.size(); i++)
00295                 {
00296                         ofxPoint2f      prev    = points.at(i - 1);
00297                         ofxPoint2f      next    = points.at(i);
00298                         
00299                         if(p.x >= prev.x && p.x <= next.x)
00300                         {
00301                                 points.insert(points.begin() + i, p);
00302                                 break;
00303                         }
00304                 }
00305         }
00306         
00307         void deleteActivePoint()
00308         {
00309                 if(activePoint > 0 && activePoint < points.size() - 1)
00310                         points.erase(points.begin() + activePoint);
00311         }
00312 
00313         ofxPoint2f positionToValue(ofxPoint2f p)
00314         {
00315                 ofxPoint2f value = p;
00316                 
00317                 for(int i = 1; i < points.size(); i++)
00318                 {
00319                         ofxPoint2f      prev    = points.at(i - 1);
00320                         ofxPoint2f      next    = points.at(i);
00321                         
00322                         if(p.x >= prev.x && p.x <= next.x)
00323                         {
00324                                 float fraction = (p.x - prev.x) / (next.x - prev.x);
00325                                 value.y = linear(fraction, prev.y, next.y);
00326                                 
00327                                 break;
00328                         }
00329                 }
00330                 
00331                 return value;
00332         }
00333 };
00334 
00335 //      ----------------------------------------------------------------------------------------------------
00336 
00337 #endif
00338 
00339 //      ----------------------------------------------------------------------------------------------------
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines