1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Defines the AutoCaptureMechanism class
4 // Author: Utensil Candel (UtensilCandel@@gmail.com)
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 #include <wx/notebook.h>
13 #include <wx/settings.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 static wxBitmap
Capture(wxRect rect
);
69 static wxBitmap
Capture(int x
, int y
, int width
, int height
);
72 protected: // internal utils
77 Control(wxWindow
* _ctrl
, wxString _name
, int _flag
)
78 : ctrl(_ctrl
), name(_name
), flag(_flag
) {}
85 wxBitmap
Capture(Control
& ctrl
);
87 // if AJ_RegionAdjust is specified, the following line will use the label
88 // trick to adjust the region position and size
89 wxRect
GetRect(wxWindow
* ctrl
, int flag
);
91 // put the control back after the label trick(Using reparent/resizer approach)
92 void PutBack(wxWindow
* ctrl
);
94 wxBitmap
Union(wxBitmap pic1
, wxBitmap pic2
);
96 void Save(wxBitmap screenshot
, wxString fileName
);
99 typedef std::vector
<Control
> ControlList
;
100 ControlList m_controlList
;
102 // here we introduce the dependency on wxNotebook.
103 // The assumption of this whole class is that the gui has the following top-down structure
104 // wxNotebook wxPanel wxSizer wxControls
105 wxNotebook
* m_notebook
;
107 wxFlexGridSizer
* m_grid
;