Drawing UI handlers – h file

Here are the prototyped rewritten classes. Will move from C++ MFC to C++ 11 modern code with STL sooner.

Element_h.docx

Here is the CElement class which contains basic and generic drawing objects:

class CElement : public CObject
{
public:
DECLARE_SERIAL(CElement);
CElement();
CElement(ElementType type);
virtual ~CElement(void);

// Operations
public:
virtual void Serialize(CArchive& ar);   // overridden for document i/o
CString ToString();
CString ToString(ElementType type);
static bool IsDrawable(ElementType type);
BOOL Intersects(const CRect& rect);
void InvalidateObj(void);
void Draw(CModeler1View * pView, CDC* pDC);

// Attributes
public:
CString m_name;
ElementType m_type;
CString m_objectId;
CString m_caption;
CString m_text;
CRect m_rect;
CPoint m_point;
CPoint m_last;
CElementManager * m_pManager;

CElementManager * GetManager() const
{
return m_pManager;
}
};

The CElementManager class contains the code for the UI handlers and some others stuff.

class CElementManager : public CObject
{
public:
DECLARE_SERIAL(CElementManager);
CElementManager();
virtual ~CElementManager(void);

// Attributes
public:
CTypedPtrList<CObList, CElement*> m_objects;
CTypedPtrList<CObList, CElement*> m_selection;
COLORREF m_paperColor;
// Page size in logical coordinates
CSize m_size;
CPoint m_lastPoint;
// Current working object
CString m_objectId;

// Operations
public:
virtual void Serialize(CArchive& ar);   // overridden for document i/o
CElement * FindElement(ElementType type);
CElement * FindElement(CString objectId);
CElement * ObjectAt(const CPoint & point);
static void ViewToManager(CModeler1View * pView, CPoint & point);
static void ViewToManager(CModeler1View * pView, CRect & rect);
static void ManagerToView(CModeler1View * pView, CPoint & point);
static void ManagerToView(CModeler1View * pView, CRect & rect);
COLORREF GetPaperColor() const { return m_paperColor; }
void Invalidate(CModeler1View * pView, CElement * pElement);
void InvalObj(CModeler1View * pView, CElement * pElement);
CSize GetSize() const { return m_size; }
void UpdatePropertyGrid(CModeler1View * pView, CElement * pElement);
void UpdateFromPropertyGrid(CString objectId, CString name, CString value);

// Managing Object Selection
public:
BOOL HasSelection();
BOOL IsSelected(CElement * pElement);
BOOL Select(CElement * pElement);
BOOL Deselect(CElement * pElement);
void SelectNone();

// Managing/Viewing Object Selection & Tracker helpers
public:
int GetHandleCount();
CPoint GetHandle(CElement * pElement, int nHandle);
void DrawTracker(CElement *pElement, CDC* pDC, TrackerState state);
HCURSOR GetHandleCursor(int nHandle);

// Overridables
public:
virtual void Draw(CModeler1View * pView, CDC * pDC);
virtual void DrawEx(CModeler1View * pView, CDC * pDC);
virtual void Update(CModeler1View * pView, LPARAM lHint, CObject* pHint);

// UI Handlers
public:
virtual void OnLButtonDown(CModeler1View* pView, UINT nFlags, const CPoint& cpoint);
virtual void OnLButtonDblClk(CModeler1View* pView, UINT nFlags, const CPoint& cpoint);
virtual void OnLButtonUp(CModeler1View* pView, UINT nFlags, const CPoint& cpoint);
virtual void OnMouseMove(CModeler1View* pView, UINT nFlags, const CPoint& cpoint);
};

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: