wxRectTracker
LineTracker.h
Go to the documentation of this file.
00001 /* ****************************************************************************
00002  * LineTracker.h                                                              *
00003  *                                                                            *
00004  * (c) 2004-2012 - Rémi Peyronnet <remi+rphoto@via.ecp.fr>                    *
00005  * LineTracker was originally designed for RPhoto, but can be used separately *
00006  *                                                                            *
00007  * Licence : wxWindows (based on L-GPL)                                       *
00008  *                                                                            *
00009  * ************************************************************************** */
00010 
00011 #ifndef __LINETRACKER_H__
00012 #define __LINETRACKER_H__
00013 
00014 #include <wx/wx.h>
00015 #include "RectTracker.h"
00016 
00017 /// Handler position enum.
00018 enum RT_LINE_HANDLER
00019 {
00020    RT_LINE_HANDLER_OUTSIDE       = -1,
00021    RT_LINE_HANDLER_NONE          =  0,
00022    RT_LINE_HANDLER_BEGIN         =  1,
00023    RT_LINE_HANDLER_END           =  2,
00024    RT_LINE_HANDLER_ON_LINE       =  3,
00025 };
00026 
00027 /// Mask to use with SetHandlerMask() to specify which handlers will be displayed.
00028 enum RT_LINE_MASK
00029 {
00030    /// Use this to hide handlers.
00031    RT_LINE_MASK_NONE         = 0x00,
00032    RT_LINE_MASK_BEGIN        = 0x01,
00033    RT_LINE_MASK_END          = 0x02,
00034    /// Use this to show all handlers (default).
00035    RT_LINE_MASK_ALL          = 0xFF
00036 };
00037 
00038 /** wxLineTracker control
00039  * 
00040  * This control aims at providing same functionnalies as wxRectTracker, but for lines.
00041  * It is basically a line with dragging capabilites, to set its size and position.
00042  *
00043  *  @see wxRectTracker
00044  */ 
00045 class wxLineTracker : public wxRectTracker
00046 {
00047     DECLARE_CLASS(wxLineTracker)
00048 public:
00049     /** wxLineTracker constructor
00050      */
00051     wxLineTracker(wxWindow* parent, wxFrame * frame = NULL);
00052     virtual ~wxLineTracker();
00053 
00054 public:
00055     /// Returns true if the provided coordinates are in the tracker. (Parent coo.)
00056     int HitTest(int x, int y) const;
00057 
00058     /// Update the tracker position and size (usefull for initialisation)
00059     void Update();
00060     /// Get the list of handlers to be displayed (See RT_LINE_MASK enum)
00061     int GetHandlerMask() const { return m_iHandlerMask; }
00062     /// Set which handlers will be displayed (See RT_MASK enum)
00063     void SetHandlerMask(int iMask = RT_LINE_MASK_ALL) { m_iHandlerMask = iMask; }
00064     
00065     /// Get the current position of the tracker, without taking in account any scroll area.
00066     wxPoint GetPosBegin() const; 
00067     wxPoint GetPosEnd() const; 
00068     wxPoint GetPosHandler(enum RT_HANDLER handler) const;
00069     /// Set a new position for the tracker
00070     virtual void SetTrackerPosition(wxPoint begin, wxPoint end);
00071 
00072 protected:
00073     // Internals : Events
00074     // - Misc Events
00075     virtual void OnPaint(wxPaintEvent & event);
00076     virtual void OnKey(wxKeyEvent & event);
00077     virtual void OnMouseMotion(wxMouseEvent & event);
00078     virtual void OnMouseLeftDown(wxMouseEvent & event);
00079     virtual void OnMouseLeftUp(wxMouseEvent & event);
00080 
00081     // Helper Functions
00082     virtual void DrawLine(wxDC & dc, wxPoint begin, wxPoint end);
00083     virtual void DrawTracker(wxDC & dc, wxPoint begin, wxPoint end);
00084 
00085 protected:
00086     // Behaviour Functions
00087     virtual void AdjustLineTracker(wxPoint & begin, wxPoint & end, int handler);
00088     void AdjustLineTrackerMax(wxPoint & begin, wxPoint & end, int handler);
00089 
00090 protected:
00091     wxPoint m_pCurBegin; /// Coordinates of the previous first point
00092     wxPoint m_pCurEnd;   /// Coordinates of the previous last point
00093 
00094     enum RT_HANDLER m_iBeginHandler;    // Handler of Begin Point
00095     enum RT_HANDLER m_iEndHandler;      // Handler of End Point
00096 
00097 };
00098 
00099 
00100 #endif // __LINETRACKER_H__