Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

jAPIshapes.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 #ifndef jAPIshapesH
00003 #define jAPIshapesH
00004 //---------------------------------------------------------------------------
00005 
00006 #include <vector.h>
00007 #include <stdio.h>
00008 
00009 #include "jAPIvectoriels.h"
00010 #include "jAPIgeometry.h"
00011 
00012 jSHPdrawGrid(TCanvas * _canvas, int _nbCellsX, int _nbCellsY, int _totalSizeX, int _totalSizeY, TColor _color);
00013 
00014 class jShape
00015 {
00016         public :
00017         vector<TPoint> points;
00018 
00019         jShape & operator=(jShape & s)                                          { jVCTcopy(&(s.points), &points); return (*this); }
00020 
00021         TRect __fastcall Zone()                                                 { return jVCTzone(&points); }
00022 
00023         TPoint __fastcall Origine()                                             { TRect rect = Zone(); return TPoint(rect.Left, rect.Top); }
00024 
00025         bool __fastcall Direction(jShape * src, TPoint debX, TPoint debY)       { if (!src)      return false; return jVCTdirection(&(src->points), &points, debX, debY); }
00026         bool __fastcall Direction(TPoint debX, TPoint debY)                     { return jVCTdirection(&points, debX, debY); }
00027 
00028         virtual bool __fastcall IsInside(const TPoint & p)                              { return jVCTinside(p, &points); }
00029 
00030         void __fastcall AddPoint(int X, int Y)                                  { points.push_back(TPoint(X, Y)); }
00031         void __fastcall AddPoint(TPoint p)                                      { points.push_back(p); }
00032 
00033         void __fastcall Clear()                                                 { points.clear(); }
00034 
00035         bool __fastcall Rotate(jShape * src, TPoint origine, double angle)      { if (!src)      return false; return jVCTrotate(&(src->points), &points, origine, angle); }
00036         bool __fastcall Rotate(TPoint origine, double angle)                    { return jVCTrotate(&points, origine, angle); }
00037 
00038         bool __fastcall Stretch(jShape * src, double coeffx, double coeffy)     { if (!src)      return false; return jVCTstretch(&(src->points), &points, Origine(), coeffx, coeffy); }
00039         bool __fastcall Stretch(double coeffx, double coeffy)                   { return jVCTstretch(&points, Origine(), coeffx, coeffy); }
00040 
00041         bool __fastcall Move(jShape * src, int offsetx, int offsety)            { if (!src)      return false; return jVCTmove(&(src->points), &points, offsetx, offsety); }
00042         bool __fastcall Move(int offsetx, int offsety)                          { return jVCTmove(&points, offsetx, offsety); }
00043 
00044         bool __fastcall Move(jShape * src, TPoint p)                            { if (!src)      return false; return jVCTmove(&(src->points), &points, p); }
00045         bool __fastcall Move(TPoint p)                                          { return jVCTmove(&points, p); }
00046 
00047         bool __fastcall Draw(TCanvas * cv)                                      { return jDRWshape(cv, &points); }
00048 
00049         bool __fastcall Fetch(jShape * src, TRect zone)                         { if (!src)      return false; return jVCTfetch(&(src->points), &points, zone); }
00050         bool __fastcall Fetch(TRect zone)                                       { return jVCTfetch(&points, zone); }
00051 
00052         bool __fastcall Fetch(jShape * src, TRect z_src, TRect z_dst)           { if (!src)      return false; return jVCTfetch(&(src->points), &points, z_src, z_dst); }
00053         bool __fastcall Fetch(TRect z_src, TRect z_dst)                         { return jVCTfetch(&points, z_src, z_dst); }
00054 
00055         bool __fastcall LoadFromStream(TStream * _str)                          { return jVCTloadFromStream(&points, _str); }
00056         bool __fastcall saveToStream(TStream * _str)                            { return jVCTsaveToStream(&points, _str); }
00057         bool __fastcall LoadFromFile(FILE * f)                                  { return jVCTloadFromFile(&points, f); }
00058         bool __fastcall SaveToFile(FILE * f)                                    { return jVCTsaveToFile(&points, f);   }
00059 
00060         bool __fastcall DrawFetched(TCanvas * cv, const TRect & dst, const TRect & src)
00061         {
00062                 jShape l_shape = *this;
00063                 l_shape.Fetch(src, dst);
00064                 l_shape.Draw(cv);
00065                 return true;
00066         }
00067 };
00068 
00069 enum jShpType {shpSimpleLineArrow, shpFineArrow, shpMediumArrow, shpLargeArrow,
00070                shpDoubleLineArrow, shpSegment, shpSquare};
00071 
00072 class jStdShape : public jShape
00073 {
00074         public :
00075         vector<TPoint> m_OriginalPoints;
00076 
00077         jPoint m_start;
00078         jPoint m_end;
00079 
00080         int m_type;
00081 
00082         jStdShape() {Clear();}
00083 
00084         jStdShape & operator=(const jStdShape & s)
00085         {
00086                 jVCTcopy(&(((jStdShape)s).points), &points);
00087                 jVCTcopy(&(((jStdShape)s).m_OriginalPoints), &m_OriginalPoints);
00088                 m_start = s.m_start;
00089                 m_end   = s.m_end;
00090                 m_type  = s.m_type;
00091                 return (*this);
00092         }
00093 
00094         void __fastcall Set(jShpType apparence);
00095 
00096         bool __fastcall DrawExtremities(TCanvas * cv)                          { return jDRWpoint(cv, m_start, 3) & jDRWpoint(cv, m_end, 3); }
00097 
00098         bool __fastcall Direction(TPoint deb, TPoint fin)                      { if (jVCTdirection(&m_OriginalPoints, &points, deb, fin) == false)     return false;     m_start = deb;  m_end   = fin; return true; }
00099         bool __fastcall DrawOriginal(TCanvas * cv)                             { return jDRWshape(cv, &m_OriginalPoints); }
00100 
00101         bool __fastcall LoadFromFile(FILE * f);
00102         bool __fastcall SaveToFile(FILE * f);
00103 
00104         bool __fastcall IsStartPoint(const TPoint & p)                         { return jPNTinside(p, TRect(m_start.x-3, m_start.y-3, m_start.x+3, m_start.y+3)); }
00105         bool __fastcall IsEndPoint(const TPoint & p)                           { return jPNTinside(p, TRect(m_end.x-3,   m_end.y-3,   m_end.x+3,   m_end.y+3)); }
00106 
00107         bool __fastcall Fetch(const TRect & z_old, const TRect & z_new)        { return m_start.Stretch(z_new, z_old) & m_end.Stretch(z_new, z_old) & Direction(m_start, m_end); }
00108         bool __fastcall UnFetch(const TRect & z_new, const TRect & z_old)      { return m_start.UnStretch(z_new, z_old) & m_end.UnStretch(z_new, z_old) & Direction(m_start, m_end); }
00109 
00110         bool __fastcall DrawFetched(TCanvas * cv, const TRect & dst, const TRect & src)
00111         {
00112                 jStdShape l_shape = *this;
00113                 l_shape.Fetch(src, dst);
00114                 l_shape.Draw(cv);
00115                 return true;
00116         }
00117 
00118         bool __fastcall IsInside(const TPoint & p);
00119 };
00120 
00121 class jStdShapes
00122 {
00123         vector<jStdShape> m_shapes;
00124         vector<jStdShape>::iterator it;
00125 
00126         public:
00127 
00128         jStdShapes & operator=(const jStdShapes & s)
00129         {
00130                 m_shapes.clear();
00131                 for (int i=0; i<s.Count(); i++)
00132                         m_shapes.push_back(s.At(i));
00133                 return (*this);
00134         }
00135 
00136         bool __fastcall Add(jStdShape shape)    { m_shapes.push_back(shape); return true;}
00137         int  __fastcall Count()                 { return m_shapes.size(); }
00138         jStdShape & __fastcall At(int pos)      { return m_shapes.at(pos); }
00139 
00140         bool __fastcall Draw(TCanvas * cv, bool points=false);
00141         bool __fastcall DrawFetched(TCanvas * cv, const TRect & z_dst, const TRect & z_src);
00142         bool __fastcall Remove(int pos);
00143 
00144         jStdShape * __fastcall UnderFocus(const TPoint & mouse, bool & startPoint);
00145         jStdShape * __fastcall Focused(const TPoint & mouse, TRect & view, TRect & Cadre, int & pos);
00146 
00147         bool __fastcall Fetch(const TRect & src, const TRect & dst);
00148 
00149         bool __fastcall LoadFromFile(FILE * f, int max);
00150         bool __fastcall SaveToFile(FILE * f);
00151 };
00152 
00153 #endif
00154 

Generated on Sat Nov 15 10:52:34 2003 for JAPI by doxygen 1.3.4