ASPiK SDK
uigrid.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __uigrid__
6 #define __uigrid__
7 
8 #include "../../lib/cpoint.h"
9 
10 #if VSTGUI_LIVE_EDITING
11 
12 #include <cmath>
13 
14 namespace VSTGUI {
15 
16 //----------------------------------------------------------------------------------------------------
17 class UIGrid : public NonAtomicReferenceCounted
18 {
19 public:
20  UIGrid (const CPoint& size = CPoint (10, 10)) : size (size) {}
21 
22  virtual void process (CPoint& p)
23  {
24  p.x -= size.x / 2.;
25  p.y -= size.y / 2.;
26  int32_t x = (int32_t) std::floor (p.x / size.x + 0.5);
27  p.x = x * size.x;
28  int32_t y = (int32_t) std::floor (p.y / size.y + 0.5);
29  p.y = y * size.y;
30  }
31 
32  virtual void setSize (const CPoint& p) { size = p; }
33  const CPoint& getSize () const { return size; }
34 protected:
35  CPoint size;
36 };
37 
38 } // namespace
39 
40 #endif // VSTGUI_LIVE_EDITING
41 
42 #endif // __uigrid__
Definition: customcontrols.cpp:8