Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Dragger.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLQt/src/ICLQt/Dragger.h                              **
00010 ** Module : ICLQt                                                  **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLUtils/Point32f.h>
00034 #include <ICLUtils/Rect32f.h>
00035 #include <ICLCore/Types.h>
00036 #include <ICLCore/CoreFunctions.h>
00037 
00038 namespace icl{
00039   namespace qt{
00040   
00042     class ICLDrawWidget;
00045 
00046     struct Dragger{
00047       
00049       struct Color{
00050         
00052 
00058         static void xyb_to_rg(icl8u &r, icl8u &g, float b, float x, float y){
00059           float k = x/(1.0-x);
00060           g = utils::clipped_cast<icl32f,icl8u>((b*(k+1.0))/(1.0/y-1.0-k));
00061           r = utils::clipped_cast<icl32f,icl8u>(g/y-g-b);
00062         }
00064         Color(icl8u r=0, icl8u g=0, icl8u b=0, icl8u a=255):
00065           r(r),g(g),b(b),a(a){}
00066         
00067         icl8u r; 
00068         icl8u g; 
00069         icl8u b; 
00070         icl8u a; 
00071       };  
00072       
00074 
00078       Dragger(const utils::Point32f &p=utils::Point32f::null, float d=0.02,const Color &c=Color(255,0,0)):
00079         p(p),d(d),r(utils::Rect32f(p.x-d,p.y-d,2*d,2*d)),dr(false),c(c),ov(false){}
00080   
00082       bool hit(const utils::Point32f &x) const{ return r.contains(x.x,x.y); }
00083       
00085       const utils::Rect32f &rect() const { return r; }
00086       
00088       float dim() const { return d; }
00089       
00091       const utils::Point32f &pos() const { return p; }
00092       
00094       const Color &col() const { return c; }
00095       
00097 
00101       void setColor(float r,float g, float b){
00102         c = Color(utils::clipped_cast<icl32f,icl8u>(r),
00103                   utils::clipped_cast<icl32f,icl8u>(g),
00104                   utils::clipped_cast<icl32f,icl8u>(b));
00105       }
00106       
00108 
00109       void setDim(float d){
00110         this->d=d;
00111         r.x = p.x-d;
00112         r.y = p.y-d;
00113       }
00114       
00116 
00117       void setPos(const utils::Point32f &x){
00118         p = x;
00119         p.x = utils::clip(p.x,float(0.0),float(1.0));
00120         p.y = utils::clip(p.y,float(0.0),float(1.0));
00121         r.x = p.x-d;
00122         r.y = p.y-d;
00123       }
00125 
00128       void move(const utils::Point32f &dist){
00129         setPos(p+dist);
00130       }
00131       
00133 
00136       void drag(const utils::Point32f &x) { 
00137         dr = true; 
00138         dragOffs = p - x;
00139       }
00140       
00142 
00145       void dragTo(const utils::Point32f &x){
00146         setPos(x+dragOffs);
00147       }
00148   
00150       void drop() { dr = false; }
00151   
00153 
00167       void draw( ICLDrawWidget *w) const;
00168            
00170       bool over() const { return ov; }
00171       
00173 
00175       void setOver(bool val=true) { ov = val; }
00176   
00178       bool dragged() const { return dr; }
00179   
00180       private:
00181      
00182       utils::Point32f p; 
00183       float d;    
00184       utils::Rect32f r;  
00185       bool dr;    
00186       Color c;    
00187       bool ov;    
00188       utils::Point32f dragOffs; 
00189     };
00190     
00191   } // namespace qt
00192 }
00193 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines