1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Defines the AutoCaptureMechanism class
4 // Author: Utensil Candel (UtensilCandel@@gmail.com)
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
9 #ifndef _AUTOCAPTURE_H_
10 #define _AUTOCAPTURE_H_
15 #include <wx/notebook.h>
18 // TODO: document what these flags mean
22 AJ_RegionAdjust
= 1 << 0,
30 // ----------------------------------------------------------------------------
31 // class AutoCaptureMechanism
32 // ----------------------------------------------------------------------------
34 class AutoCaptureMechanism
37 AutoCaptureMechanism(wxNotebook
*notebook
,
38 wxString directory
= wxT("screenshots"),
40 : m_notebook(notebook
), m_dir(directory
), m_border(border
) {}
42 ~AutoCaptureMechanism(){}
45 If wxRTTI can't get the name correctly, specify name;
46 If wxWindow::GetScreenRect doesn't get the rect correctly, set flag to AJ_RegionAdjust
48 void RegisterControl(wxWindow
* ctrl
, wxString name
= wxT(""),
51 m_controlList
.push_back(Control(ctrl
, name
, flag
));
54 void RegisterControl(wxWindow
* ctrl
, int flag
)
56 RegisterControl(ctrl
, wxT(""), flag
);
59 void RegisterPageTurn()
61 m_controlList
.push_back(Control(0, wxT(""), AJ_TurnPage
));
64 // capture all controls of the associated notebook
67 // take a screenshot only of the given rect
68 // delay is only useful for Mac, for fixing a delay bug
69 static wxBitmap
Capture(wxRect rect
, int delay
= 0);
70 static wxBitmap
Capture(int x
, int y
, int width
, int height
, int delay
= 0);
72 static void Delay(int seconds
);
75 private: // internal utils
80 Control(wxWindow
* _ctrl
, wxString _name
, int _flag
)
81 : ctrl(_ctrl
), name(_name
), flag(_flag
) {}
88 wxBitmap
Capture(Control
& ctrl
);
90 // if AJ_RegionAdjust is specified, the following line will use the label
91 // trick to adjust the region position and size
92 wxRect
GetRect(wxWindow
* ctrl
, int flag
);
94 // put the control back after the label trick(Using reparent/resizer approach)
95 void PutBack(wxWindow
* ctrl
);
97 wxBitmap
Union(wxBitmap pic1
, wxBitmap pic2
);
99 void Save(wxBitmap screenshot
, wxString fileName
);
101 typedef std::vector
<Control
> ControlList
;
102 ControlList m_controlList
;
104 // here we introduce the dependency on wxNotebook.
105 // The assumption of this whole class is that the gui has the following top-down structure
106 // wxNotebook wxPanel wxSizer wxControls
107 wxNotebook
* m_notebook
;
109 wxFlexGridSizer
* m_grid
;
115 #endif // _AUTOCAPTURE_H_