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>
17 // Global helper functions. to take screenshot for a rect region
18 wxBitmap
Capture(wxRect rect
);
19 wxBitmap
Capture(int x
, int y
, int width
, int height
);
24 AJ_RegionAdjust
= 1 << 0,
32 // ----------------------------------------------------------------------------
33 // class AutoCaptureMechanism
34 // ----------------------------------------------------------------------------
36 class AutoCaptureMechanism
39 AutoCaptureMechanism(wxNotebook
* notebook
,
40 wxString directory
= wxT("screenshots"),
42 : m_notebook(notebook
), m_dir(directory
), m_border(border
) {}
43 ~AutoCaptureMechanism(){}
46 If wxRTTI can't get the name correctly, specify name;
47 If wxWindow::GetScreenRect doesn't get the rect correctly, set flag to AJ_RegionAdjust
49 void RegisterControl(wxWindow
* ctrl
, wxString name
= wxT(""),
52 m_controlList
.push_back(Control(ctrl
, name
, flag
));
55 void RegisterControl(wxWindow
* ctrl
, int flag
)
57 RegisterControl(ctrl
, wxT(""), flag
);
60 void RegisterPageTurn()
62 m_controlList
.push_back(Control(0, wxT(""), AJ_TurnPage
));
67 m_notebook
->SetSelection(0);
70 for(ControlList
::iterator it
= m_controlList
.begin();
71 it
!= m_controlList
.end();
76 if(ctrl
.flag
== AJ_TurnPage
) // Turn to next page
78 m_notebook
->SetSelection(m_notebook
->GetSelection() + 1);
83 wxBitmap screenshot
= Capture(ctrl
);
85 if(ctrl
.flag
& AJ_Union
)
87 screenshot
= Union(screenshot
, Capture(*(++it
)));
90 Save(screenshot
, ctrl
.name
);
94 protected: // internal utils
99 Control(wxWindow
* _ctrl
, wxString _name
, int _flag
)
100 : ctrl(_ctrl
), name(_name
), flag(_flag
) {}
107 wxBitmap
Capture(Control
& ctrl
);
109 //if AJ_RegionAdjust is specified, the following line will use the label trick to adjust
110 //the region position and size
111 wxRect
GetRect(wxWindow
* ctrl
, int flag
);
113 //put the control back after the label trick(Using reparent/resizer approach)
114 void PutBack(wxWindow
* ctrl
);
116 wxBitmap
Union(wxBitmap pic1
, wxBitmap pic2
);
118 void Save(wxBitmap screenshot
, wxString fileName
);
121 typedef std
::vector
<Control
> ControlList
;
122 ControlList m_controlList
;
124 // here we introduce the dependency on wxNotebook.
125 // The assumption of this whole class is that the gui has the following top-down structure
126 // wxNotebook wxPanel wxSizer wxControls
127 wxNotebook
* m_notebook
;
129 wxFlexGridSizer
* m_grid
;