Image Component Library (ICL)
Dragger.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLQt/src/ICLQt/Dragger.h **
10 ** Module : ICLQt **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/Point32f.h>
35 #include <ICLUtils/Rect32f.h>
36 #include <ICLCore/Types.h>
37 #include <ICLCore/CoreFunctions.h>
38 
39 namespace icl{
40  namespace qt{
41 
43  class ICLDrawWidget;
46  struct ICLQt_API Dragger{
48 
50  struct Color{
51 
53 
59  static void xyb_to_rg(icl8u &r, icl8u &g, float b, float x, float y){
60  float k = x/(1.0-x);
61  g = utils::clipped_cast<icl32f,icl8u>((b*(k+1.0))/(1.0/y-1.0-k));
62  r = utils::clipped_cast<icl32f,icl8u>(g/y-g-b);
63  }
65  Color(icl8u r=0, icl8u g=0, icl8u b=0, icl8u a=255):
66  r(r),g(g),b(b),a(a){}
67 
68  icl8u r;
69  icl8u g;
70  icl8u b;
71  icl8u a;
72  };
73 
75 
79  Dragger(const utils::Point32f &p=utils::Point32f::null, float d=0.02,const Color &c=Color(255,0,0)):
80  p(p),d(d),r(utils::Rect32f(p.x-d,p.y-d,2*d,2*d)),dr(false),c(c),ov(false){}
81 
83  bool hit(const utils::Point32f &x) const{ return r.contains(x.x,x.y); }
84 
86  const utils::Rect32f &rect() const { return r; }
87 
89  float dim() const { return d; }
90 
92  const utils::Point32f &pos() const { return p; }
93 
95  const Color &col() const { return c; }
96 
98 
102  void setColor(float r,float g, float b){
103  c = Color(utils::clipped_cast<icl32f,icl8u>(r),
104  utils::clipped_cast<icl32f,icl8u>(g),
105  utils::clipped_cast<icl32f,icl8u>(b));
106  }
107 
109 
110  void setDim(float d){
111  this->d=d;
112  r.x = p.x-d;
113  r.y = p.y-d;
114  }
115 
117 
118  void setPos(const utils::Point32f &x){
119  p = x;
120  p.x = utils::clip(p.x,float(0.0),float(1.0));
121  p.y = utils::clip(p.y,float(0.0),float(1.0));
122  r.x = p.x-d;
123  r.y = p.y-d;
124  }
126 
129  void move(const utils::Point32f &dist){
130  setPos(p+dist);
131  }
132 
134 
137  void drag(const utils::Point32f &x) {
138  dr = true;
139  dragOffs = p - x;
140  }
141 
143 
146  void dragTo(const utils::Point32f &x){
147  setPos(x+dragOffs);
148  }
149 
151  void drop() { dr = false; }
152 
154 
168  void draw( ICLDrawWidget *w) const;
169 
171  bool over() const { return ov; }
172 
174 
176  void setOver(bool val=true) { ov = val; }
177 
179  bool dragged() const { return dr; }
180 
181  private:
182 
184  float d;
186  bool dr;
188  bool ov;
190  };
191 
192  } // namespace qt
193 }
194 
Dragger(const utils::Point32f &p=utils::Point32f::null, float d=0.02, const Color &c=Color(255, 0, 0))
creates a new Dragger
Definition: Dragger.h:79
undocument this line if you encounter any issues!
Definition: Any.h:37
math::FixedColVector< icl8u, 3 > Color
Default color type of the ICL.
Definition: Color.h:42
bool dragged() const
returns whether this dragger is currently dragged
Definition: Dragger.h:179
bool dr
Definition: Dragger.h:186
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
float y
y position of this point
Definition: Point32f.h:48
const utils::Point32f & pos() const
returns the current center position
Definition: Dragger.h:92
void drop()
drops this dragger, to it is no longer moved by the mouse
Definition: Dragger.h:151
Color(icl8u r=0, icl8u g=0, icl8u b=0, icl8u a=255)
Create a new color with given red, green, blue and alpha value.
Definition: Dragger.h:65
Color c
Definition: Dragger.h:187
icl8u a
Definition: Dragger.h:71
icl8u r
Definition: Dragger.h:68
float dim() const
returns the current dim variable
Definition: Dragger.h:89
Floating point precision implementation of the Rect class.
Definition: Rect32f.h:45
static void xyb_to_rg(icl8u &r, icl8u &g, float b, float x, float y)
conversion function calculates r and g given b R and G
Definition: Dragger.h:59
T clip(T tX, T tMin, T tMax)
clips a value into the range [tMin,tMax]
Definition: ClippedCast.h:40
void setDim(float d)
sets the current dim
Definition: Dragger.h:110
void move(const utils::Point32f &dist)
moves the dragger by a given distance
Definition: Dragger.h:129
bool ov
Definition: Dragger.h:188
bool over() const
returns whether the mouse is currently over this dragger
Definition: Dragger.h:171
static const Point32f null
null Point is x=0, y=0
Definition: Point32f.h:51
const Color & col() const
returns the current color
Definition: Dragger.h:95
Extended Image visualization widget, with a drawing state machine interface.
Definition: DrawWidget.h:142
void drag(const utils::Point32f &x)
makes this dragger "dragged" by the mouse
Definition: Dragger.h:137
utils::Point32f p
Definition: Dragger.h:183
Utility class which helps to convert rgb to RG-Chroma and back.
Definition: Dragger.h:50
const utils::Rect32f & rect() const
returns the draggers relative rect
Definition: Dragger.h:86
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
#define ICLQt_API
Definition: CompatMacros.h:178
void setOver(bool val=true)
sets the internal "over"-variable to indicate, that the mouse is over the dragger
Definition: Dragger.h:176
float x
x position of this point
Definition: Point32f.h:45
void setPos(const utils::Point32f &x)
sets the current position (which is clipped to [0,1])
Definition: Dragger.h:118
utils::Point32f dragOffs
Definition: Dragger.h:189
bool hit(const utils::Point32f &x) const
returns whether a given relative position is inside the dragger
Definition: Dragger.h:83
utils::Rect32f r
Definition: Dragger.h:185
void setColor(float r, float g, float b)
sets the current color
Definition: Dragger.h:102
icl8u b
Definition: Dragger.h:70
void dragTo(const utils::Point32f &x)
once dragged, this function will move the dragger
Definition: Dragger.h:146
icl8u g
Definition: Dragger.h:69
float d
Definition: Dragger.h:184