nux-1.16.0
|
00001 /* 00002 * Copyright 2010 Inalogic® Inc. 00003 * 00004 * This program is free software: you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License, as 00006 * published by the Free Software Foundation; either version 2.1 or 3.0 00007 * of the License. 00008 * 00009 * This program is distributed in the hope that it will be useful, but 00010 * WITHOUT ANY WARRANTY; without even the implied warranties of 00011 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR 00012 * PURPOSE. See the applicable version of the GNU Lesser General Public 00013 * License for more details. 00014 * 00015 * You should have received a copy of both the GNU Lesser General Public 00016 * License along with this program. If not, see <http://www.gnu.org/licenses/> 00017 * 00018 * Authored by: Jay Taoko <jaytaoko@inalogic.com> 00019 * 00020 */ 00021 00022 00023 #ifndef BEZIERCURVECONTROL2_H 00024 #define BEZIERCURVECONTROL2_H 00025 00026 #include "PaintLayer.h" 00027 00028 namespace nux 00029 { 00030 00031 class Knot2 00032 { 00033 public : 00034 00035 float m_X; 00036 float m_Y; 00037 00038 bool m_IsSelected; 00039 00040 public : 00041 00042 Knot2() : m_X (0), m_Y (0), m_IsSelected (false) {} //Constructors 00043 Knot2 (float ptX, float ptY) : 00044 m_X (ptX), m_Y (ptY), m_IsSelected (false) {} 00045 00046 void setPoint (float x, float y) 00047 { 00048 m_X = x; //Setting 00049 m_Y = y; 00050 } 00051 00052 00053 //Operator overloading 00054 void operator = (Knot2 knot) 00055 { 00056 m_X = knot.m_X; 00057 m_Y = knot.m_Y; 00058 } 00059 bool operator != (Knot2 knot) 00060 { 00061 bool b; 00062 b = ( (m_X != knot.m_X) || (m_Y != knot.m_Y) ) ? true : false; 00063 return b; 00064 } 00065 }; 00066 00067 00068 typedef float (*FunctionCallback) (float); 00069 00070 class BezierCurveControl2 : public View 00071 { 00072 public: 00073 BezierCurveControl2 (NUX_FILE_LINE_PROTO); 00074 ~BezierCurveControl2(); 00075 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00076 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00077 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw); 00078 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw); 00079 00080 void EnablePanning (bool b) 00081 { 00082 m_bPanningEnabled = b; 00083 } 00084 bool IsPanningEnabled() const 00085 { 00086 return m_bPanningEnabled; 00087 } 00088 void EnableZooming (bool b) 00089 { 00090 m_bZoomingEnabled = b; 00091 } 00092 bool IsZoomingEnable() const 00093 { 00094 return m_bZoomingEnabled; 00095 } 00096 00097 void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); 00098 void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); 00099 void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00100 00101 void RecvKeyEvent 00102 ( 00103 unsigned long eventType , /*event type*/ 00104 unsigned long keysym , /*event keysym*/ 00105 unsigned long state , /*event state*/ 00106 const TCHAR* character , /*character*/ 00107 unsigned short keyCount /*key repeat count*/ 00108 ); 00109 00110 private: 00111 void DrawRuler (GraphicsEngine &GfxContext); 00112 void DrawGrid (GraphicsEngine &GfxContext); 00113 void DrawCoordinateSystem (GraphicsEngine &GfxContext); 00114 00115 void SetXAxisBounds (float minX, float maxX); 00116 void SetYAxisBounds (float minY, float maxY); 00117 void SetFunctionCallback (FunctionCallback f); 00118 float EvalFunction (float x); 00119 void UpdateGraph(); 00120 00121 void ManipulateBezier (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00122 void ProcessPanning (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00123 void ProcessZooming (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00124 00125 std::vector<Knot2> m_control_knot; 00126 00127 float m_minX, m_minY, m_maxX, m_maxY; 00128 FunctionCallback m_FunctionCallback; 00129 00130 AbstractPaintLayer *m_Background; 00131 00132 bool m_bControlPointSelected; 00133 bool m_bPanningEnabled; 00134 bool m_bZoomingEnabled; 00135 00136 float hit_point_dx; 00137 float hit_point_dy; 00138 00139 00140 }; 00141 00142 00143 } 00144 00145 #endif // BEZIERCURVECONTROL2_H