Image Component Library (ICL)
|
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.LGPL ** 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/CompatMacros.h> 00034 #include <ICLUtils/Point32f.h> 00035 #include <ICLUtils/Rect32f.h> 00036 #include <ICLCore/Types.h> 00037 #include <ICLCore/CoreFunctions.h> 00038 00039 namespace icl{ 00040 namespace qt{ 00041 00043 class ICLDrawWidget; 00046 00047 struct ICLQt_API Dragger{ 00048 00050 struct Color{ 00051 00053 00059 static void xyb_to_rg(icl8u &r, icl8u &g, float b, float x, float y){ 00060 float k = x/(1.0-x); 00061 g = utils::clipped_cast<icl32f,icl8u>((b*(k+1.0))/(1.0/y-1.0-k)); 00062 r = utils::clipped_cast<icl32f,icl8u>(g/y-g-b); 00063 } 00065 Color(icl8u r=0, icl8u g=0, icl8u b=0, icl8u a=255): 00066 r(r),g(g),b(b),a(a){} 00067 00068 icl8u r; 00069 icl8u g; 00070 icl8u b; 00071 icl8u a; 00072 }; 00073 00075 00079 Dragger(const utils::Point32f &p=utils::Point32f::null, float d=0.02,const Color &c=Color(255,0,0)): 00080 p(p),d(d),r(utils::Rect32f(p.x-d,p.y-d,2*d,2*d)),dr(false),c(c),ov(false){} 00081 00083 bool hit(const utils::Point32f &x) const{ return r.contains(x.x,x.y); } 00084 00086 const utils::Rect32f &rect() const { return r; } 00087 00089 float dim() const { return d; } 00090 00092 const utils::Point32f &pos() const { return p; } 00093 00095 const Color &col() const { return c; } 00096 00098 00102 void setColor(float r,float g, float b){ 00103 c = Color(utils::clipped_cast<icl32f,icl8u>(r), 00104 utils::clipped_cast<icl32f,icl8u>(g), 00105 utils::clipped_cast<icl32f,icl8u>(b)); 00106 } 00107 00109 00110 void setDim(float d){ 00111 this->d=d; 00112 r.x = p.x-d; 00113 r.y = p.y-d; 00114 } 00115 00117 00118 void setPos(const utils::Point32f &x){ 00119 p = x; 00120 p.x = utils::clip(p.x,float(0.0),float(1.0)); 00121 p.y = utils::clip(p.y,float(0.0),float(1.0)); 00122 r.x = p.x-d; 00123 r.y = p.y-d; 00124 } 00126 00129 void move(const utils::Point32f &dist){ 00130 setPos(p+dist); 00131 } 00132 00134 00137 void drag(const utils::Point32f &x) { 00138 dr = true; 00139 dragOffs = p - x; 00140 } 00141 00143 00146 void dragTo(const utils::Point32f &x){ 00147 setPos(x+dragOffs); 00148 } 00149 00151 void drop() { dr = false; } 00152 00154 00168 void draw( ICLDrawWidget *w) const; 00169 00171 bool over() const { return ov; } 00172 00174 00176 void setOver(bool val=true) { ov = val; } 00177 00179 bool dragged() const { return dr; } 00180 00181 private: 00182 00183 utils::Point32f p; 00184 float d; 00185 utils::Rect32f r; 00186 bool dr; 00187 Color c; 00188 bool ov; 00189 utils::Point32f dragOffs; 00190 }; 00191 00192 } // namespace qt 00193 } 00194