Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
hugin1/hugin/CPImageCtrl.h
Go to the documentation of this file.00001 // -*- c-basic-offset: 4 -*- 00024 #ifndef _CPIMAGECTRL_H 00025 #define _CPIMAGECTRL_H 00026 00027 #include <string> 00028 #include <vector> 00029 00030 #include <base_wx/ImageCache.h> 00031 00032 class CPEditorPanel; 00033 class CPZoomDisplayPanel; 00038 class CPEvent : public wxCommandEvent 00039 { 00040 DECLARE_DYNAMIC_CLASS(CPEvent) 00041 00042 enum CPEventMode { NONE, NEW_POINT_CHANGED, POINT_SELECTED, POINT_CHANGED, REGION_SELECTED, RIGHT_CLICK, SCROLLED }; 00043 00044 public: 00045 CPEvent( ); 00047 CPEvent(wxWindow* win, CPEventMode mode); 00049 CPEvent(wxWindow* win, hugin_utils::FDiff2D & p); 00051 CPEvent(wxWindow *win, unsigned int cpNr); 00053 CPEvent(wxWindow* win, unsigned int cpNr, const hugin_utils::FDiff2D & p); 00055 CPEvent(wxWindow* win, wxRect & reg); 00057 CPEvent(wxWindow* win, CPEventMode mode, const hugin_utils::FDiff2D & p); 00058 00059 virtual wxEvent* Clone() const; 00060 00063 CPEventMode getMode() 00064 { return mode; }; 00065 00066 const wxRect & getRect() 00067 { return region; } 00068 00069 const hugin_utils::FDiff2D & getPoint() 00070 { return point; } 00071 00072 unsigned int getPointNr() 00073 { return pointNr; } 00074 private: 00075 CPEventMode mode; 00076 wxRect region; 00077 hugin_utils::FDiff2D point; 00078 int pointNr; 00079 }; 00080 00081 typedef void (wxEvtHandler::*CPEventFunction)(CPEvent&); 00082 00083 BEGIN_DECLARE_EVENT_TYPES() 00084 DECLARE_EVENT_TYPE(EVT_CPEVENT,1) 00085 END_DECLARE_EVENT_TYPES() 00086 00087 #define EVT_CPEVENT(func) \ 00088 DECLARE_EVENT_TABLE_ENTRY( EVT_CPEVENT, \ 00089 -1, \ 00090 -1, \ 00091 (wxObjectEventFunction) \ 00092 (CPEventFunction) & func, \ 00093 (wxObject *) NULL ), 00094 00095 00100 class CPImageCtrl : public wxScrolledWindow 00101 { 00102 public: 00105 CPImageCtrl() 00106 : scaleFactor(1),fitToWindow(false) 00107 { } 00108 00109 bool Create(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = wxT("panel")); 00110 00111 void Init(CPEditorPanel * parent); 00112 00113 00116 ~CPImageCtrl(); 00117 00122 enum ImageRotation { ROT0=0, ROT90, ROT180, ROT270 }; 00123 00125 void SetZoomView(CPZoomDisplayPanel * display); 00126 00129 void setImage (const std::string & filename, ImageRotation rot); 00130 00132 void setCtrlPoints(const std::vector<hugin_utils::FDiff2D> & points); 00133 00135 void clearNewPoint(); 00136 00138 void setNewPoint(const hugin_utils::FDiff2D & p); 00139 00141 void selectPoint(unsigned int); 00142 00144 void deselect(); 00145 00146 void mousePressLMBEvent(wxMouseEvent& mouse); 00147 void mouseReleaseLMBEvent(wxMouseEvent& mouse); 00148 void mouseReleaseRMBEvent(wxMouseEvent& mouse); 00149 void mouseMoveEvent(wxMouseEvent& mouse); 00150 void mousePressMMBEvent(wxMouseEvent& mouse); 00151 void mouseReleaseMMBEvent(wxMouseEvent& mouse); 00152 00153 wxSize DoGetBestSize() const; 00154 // virtual wxSize GetBestSize() const 00155 // { return DoGetBestSize(); } 00156 00161 void setScale(double factor); 00162 00164 double getScale() 00165 { return fitToWindow ? 0 : scaleFactor; } 00166 00173 void showPosition(hugin_utils::FDiff2D point, bool warpPointer=false); 00174 00178 void showSearchArea(bool show=true); 00179 00180 void showTemplateArea(bool show=true); 00181 00183 hugin_utils::FDiff2D getNewPoint(); 00184 00186 void update(); 00187 00189 void ScrollDelta(const wxPoint & delta); 00190 00192 wxPoint MaxScrollDelta(wxPoint delta); 00193 00194 protected: 00195 wxRect drawPoint(wxDC & p, const hugin_utils::FDiff2D & point, int i, bool selected = false) const; 00196 // draw the magnified view of a selected control point 00197 wxBitmap generateMagBitmap(hugin_utils::FDiff2D point, wxPoint canvasPos) const; 00198 void OnDraw(wxDC& dc); 00199 void OnSize(wxSizeEvent & e); 00200 void OnKey(wxKeyEvent & e); 00201 void OnKeyDown(wxKeyEvent & e); 00202 void OnMouseLeave(wxMouseEvent & e); 00203 void OnMouseEnter(wxMouseEvent & e); 00204 void OnTimer(wxTimerEvent & e); 00205 00207 bool emit(CPEvent & ev); 00208 00210 double getScaleFactor() const; 00211 00213 double calcAutoScaleFactor(wxSize size); 00214 00215 // rescale image 00216 void rescaleImage(); 00217 00219 // void updateZoomed(); 00220 00221 00222 00223 private: 00224 00225 wxBitmap bitmap; 00226 std::string imageFilename; 00227 // size of displayed (probably scaled) image 00228 wxSize imageSize; 00229 // size of real image 00230 wxSize m_realSize; 00231 00232 std::vector<hugin_utils::FDiff2D> points; 00233 00234 // position of the point labels (in screen coordinates) 00235 std::vector<wxRect> m_labelPos; 00236 00237 wxCursor * m_CPSelectCursor; 00238 wxCursor * m_ScrollCursor; 00239 00240 int scale(int x) const 00241 { return (int) (x * getScaleFactor() + 0.5); } 00242 00243 double scale(double x) const 00244 { return x * getScaleFactor(); } 00245 00246 hugin_utils::FDiff2D scale(const hugin_utils::FDiff2D & p) const 00247 { 00248 hugin_utils::FDiff2D r; 00249 r.x = scale(p.x); 00250 r.y = scale(p.y); 00251 return r; 00252 } 00253 00254 wxPoint scale(const wxPoint & p) const 00255 { 00256 wxPoint r; 00257 r.x = scale(p.x); 00258 r.y = scale(p.y); 00259 return r; 00260 } 00261 00262 int invScale(int x) const 00263 { return (int) (x / getScaleFactor() + 0.5); } 00264 00265 double invScale(double x) const 00266 { return x / getScaleFactor(); } 00267 00268 hugin_utils::FDiff2D invScale(const hugin_utils::FDiff2D & p) const 00269 { 00270 hugin_utils::FDiff2D r; 00271 r.x = invScale(p.x); 00272 r.y = invScale(p.y); 00273 return r; 00274 } 00275 00276 wxPoint invScale(const wxPoint & p) const 00277 { 00278 wxPoint r; 00279 r.x = invScale(p.x); 00280 r.y = invScale(p.y); 00281 return r; 00282 } 00283 00284 wxPoint roundP(const hugin_utils::FDiff2D & p) const 00285 { 00286 return wxPoint(utils::roundi(p.x), utils::roundi(p.y)); 00287 } 00288 00289 // rotate coordinate to fit possibly rotated image display 00290 // useful for drawing something on the rotated display 00291 template <class T> 00292 T applyRot(const T & p) const 00293 { 00294 switch (m_imgRotation) { 00295 case ROT0: 00296 return p; 00297 break; 00298 case ROT90: 00299 return T(m_realSize.GetHeight()-1 - p.y, p.x); 00300 break; 00301 case ROT180: 00302 return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y); 00303 break; 00304 case ROT270: 00305 return T(p.y, m_realSize.GetWidth()-1 - p.x); 00306 break; 00307 default: 00308 return p; 00309 break; 00310 } 00311 } 00312 00313 // rotate coordinate to fit possibly rotated image display 00314 // useful for converting rotated display coordinates to image coordinates 00315 template <class T> 00316 T applyRotInv(const T & p) const 00317 { 00318 switch (m_imgRotation) { 00319 case ROT90: 00320 return T(p.y, m_realSize.GetHeight()-1 - p.x); 00321 break; 00322 case ROT180: 00323 return T(m_realSize.GetWidth()-1 - p.x, m_realSize.GetHeight()-1 - p.y); 00324 break; 00325 case ROT270: 00326 return T(m_realSize.GetWidth()-1 - p.y, p.x); 00327 break; 00328 case ROT0: 00329 default: 00330 return p; 00331 break; 00332 } 00333 } 00334 00335 // this is only valid during MOVE_POINT 00336 unsigned int selectedPointNr; 00337 // valid during MOVE_POINT and CREATE_POINT 00338 hugin_utils::FDiff2D point; 00339 hugin_utils::FDiff2D newPoint; 00340 00341 // only valid during SELECT_REGION 00342 wxRect region; 00343 // state of widget (selection modes etc) 00344 // select region can also be used to just click... 00345 00394 enum EditorState {NO_IMAGE=0, NO_SELECTION, KNOWN_POINT_SELECTED, NEW_POINT_SELECTED, SELECT_REGION}; 00395 EditorState editState; 00396 00397 // colors for the different points 00398 std::vector<wxColour> pointColors; 00399 std::vector<wxColour> textColours; 00400 double scaleFactor; 00401 bool fitToWindow; 00402 00403 bool m_showSearchArea; 00404 int m_searchRectWidth; 00405 00406 hugin_utils::FDiff2D m_mousePos; 00407 wxPoint m_mouseScrollPos; 00408 00409 bool m_showTemplateArea; 00410 int m_templateRectWidth; 00411 00412 bool m_tempZoom; 00413 double m_savedScale; 00414 00417 EditorState isOccupied(wxPoint mousePos, const hugin_utils::FDiff2D & point, unsigned int & pointNr) const; 00418 00419 CPEditorPanel * m_editPanel; 00420 00421 // CPZoomDisplayPanel * m_zoomDisplay; 00422 00423 ImageRotation m_imgRotation; 00424 00425 ImageCache::EntryPtr m_img; 00426 00427 bool m_mouseInWindow; 00428 bool m_forceMagnifier; 00429 wxTimer m_timer; 00430 00431 DECLARE_EVENT_TABLE(); 00432 DECLARE_DYNAMIC_CLASS(CPImageCtrl) 00433 }; 00434 00436 class CPImageCtrlXmlHandler : public wxXmlResourceHandler 00437 { 00438 DECLARE_DYNAMIC_CLASS(CPImageCtrlXmlHandler) 00439 00440 public: 00441 CPImageCtrlXmlHandler(); 00442 virtual wxObject *DoCreateResource(); 00443 virtual bool CanHandle(wxXmlNode *node); 00444 }; 00445 00446 00447 #endif // _CPIMAGECTRL_H
1.3.9.1