nux-1.14.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 BEZIERCURVECONTROL_H 00024 #define BEZIERCURVECONTROL_H 00025 00026 namespace nux 00027 { 00028 00029 class Knot 00030 { 00031 public : 00032 00033 float m_X; 00034 float m_Y; 00035 00036 bool m_IsSelected; 00037 00038 public : 00039 00040 Knot() 00041 : m_X (0) 00042 , m_Y (0) 00043 , m_IsSelected (false) 00044 {} //Constructors 00045 Knot (float ptX, float ptY) 00046 : m_X (ptX) 00047 , m_Y (ptY) 00048 , m_IsSelected (false) 00049 {} 00050 00051 void setPoint (float x, float y) 00052 { 00053 m_X = x; //Setting 00054 m_Y = y; 00055 } 00056 00057 00058 //Operator overloading 00059 void operator = (Knot knot) 00060 { 00061 m_X = knot.m_X; 00062 m_Y = knot.m_Y; 00063 } 00064 bool operator != (Knot knot) 00065 { 00066 bool b; 00067 b = ( (m_X != knot.m_X) || (m_Y != knot.m_Y) ) ? true : false; 00068 return b; 00069 } 00070 }; 00071 00072 00073 typedef float (*FunctionCallback) (float); 00074 00075 class BezierCurveControl : public View 00076 { 00077 public: 00078 BezierCurveControl (NUX_FILE_LINE_PROTO); 00079 ~BezierCurveControl(); 00080 virtual long ProcessEvent (IEvent &ievent, long TraverseInfo, long ProcessEventInfo); 00081 virtual void Draw (GraphicsEngine &GfxContext, bool force_draw); 00082 virtual void DrawContent (GraphicsEngine &GfxContext, bool force_draw); 00083 virtual void PostDraw (GraphicsEngine &GfxContext, bool force_draw); 00084 00085 00086 void RecvMouseUp (int x, int y, unsigned long button_flags, unsigned long key_flags); 00087 void RecvMouseDown (int x, int y, unsigned long button_flags, unsigned long key_flags); 00088 void RecvMouseDrag (int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); 00089 private: 00090 void SetXAxisBounds (float minX, float maxX); 00091 void SetYAxisBounds (float minY, float maxY); 00092 void SetFunctionCallback (FunctionCallback f); 00093 float EvalFunction (float x); 00094 void UpdateGraph(); 00095 00096 std::vector<Knot> m_control_knot; 00097 00098 float m_minX, m_minY, m_maxX, m_maxY; 00099 FunctionCallback m_FunctionCallback; 00100 }; 00101 00102 00103 } 00104 00105 #endif // BEZIERCURVECONTROL_H