make Capture() functions static members of AutoCaptureMechanism; adjusted slightly...
[wxWidgets.git] / utils / screenshotgen / src / autocapture.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: autocapture.h
3 // Purpose: Defines the AutoCaptureMechanism class
4 // Author: Utensil Candel (UtensilCandel@@gmail.com)
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 #ifndef AUTOCAP_H
10 #define AUTOCAP_H
11
12 #include <wx/notebook.h>
13 #include <wx/settings.h>
14 #include <vector>
15 #include <ctime>
16
17
18 // TODO: document what these flags mean
19 enum AdjustFlags
20 {
21 AJ_Normal = 0,
22 AJ_RegionAdjust = 1 << 0,
23 AJ_Dropdown = 1 << 1,
24 AJ_TurnPage = 1 << 2,
25 AJ_Union = 1 << 3,
26 AJ_UnionEnd = 1 << 4
27 };
28
29
30 // ----------------------------------------------------------------------------
31 // class AutoCaptureMechanism
32 // ----------------------------------------------------------------------------
33
34 class AutoCaptureMechanism
35 {
36 public:
37 AutoCaptureMechanism(wxNotebook *notebook,
38 wxString directory = wxT("screenshots"),
39 int border = 5)
40 : m_notebook(notebook), m_dir(directory), m_border(border) {}
41
42 ~AutoCaptureMechanism(){}
43
44 /*
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
47 */
48 void RegisterControl(wxWindow * ctrl, wxString name = wxT(""),
49 int flag = AJ_Normal)
50 {
51 m_controlList.push_back(Control(ctrl, name, flag));
52 }
53
54 void RegisterControl(wxWindow * ctrl, int flag)
55 {
56 RegisterControl(ctrl, wxT(""), flag);
57 }
58
59 void RegisterPageTurn()
60 {
61 m_controlList.push_back(Control(0, wxT(""), AJ_TurnPage));
62 }
63
64 // capture all controls of the associated notebook
65 void CaptureAll();
66
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);
70
71
72 protected: // internal utils
73 struct Control
74 {
75 Control() {}
76
77 Control(wxWindow * _ctrl, wxString _name, int _flag)
78 : ctrl(_ctrl), name(_name), flag(_flag) {}
79
80 wxWindow * ctrl;
81 wxString name;
82 int flag;
83 };
84
85 wxBitmap Capture(Control & ctrl);
86
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);
90
91 // put the control back after the label trick(Using reparent/resizer approach)
92 void PutBack(wxWindow * ctrl);
93
94 wxBitmap Union(wxBitmap pic1, wxBitmap pic2);
95
96 void Save(wxBitmap screenshot, wxString fileName);
97
98 private:
99 typedef std::vector<Control> ControlList;
100 ControlList m_controlList;
101
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;
106
107 wxFlexGridSizer* m_grid;
108
109 wxString m_dir;
110 int m_border;
111 };
112
113 #endif // AUTOCAP_H
114
115