other cleanup; adjusted english in the UI
[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 // 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);
20
21 enum AdjustFlags
22 {
23 AJ_Normal = 0,
24 AJ_RegionAdjust = 1 << 0,
25 AJ_Dropdown = 1 << 1,
26 AJ_TurnPage = 1 << 2,
27 AJ_Union = 1 << 3,
28 AJ_UnionEnd = 1 << 4
29 };
30
31
32 // ----------------------------------------------------------------------------
33 // class AutoCaptureMechanism
34 // ----------------------------------------------------------------------------
35
36 class AutoCaptureMechanism
37 {
38 public:
39 AutoCaptureMechanism(wxNotebook * notebook,
40 wxString directory = wxT("screenshots"),
41 int border = 5)
42 : m_notebook(notebook), m_dir(directory), m_border(border) {}
43
44 ~AutoCaptureMechanism(){}
45
46 /*
47 If wxRTTI can't get the name correctly, specify name;
48 If wxWindow::GetScreenRect doesn't get the rect correctly, set flag to AJ_RegionAdjust
49 */
50 void RegisterControl(wxWindow * ctrl, wxString name = wxT(""),
51 int flag = AJ_Normal)
52 {
53 m_controlList.push_back(Control(ctrl, name, flag));
54 }
55
56 void RegisterControl(wxWindow * ctrl, int flag)
57 {
58 RegisterControl(ctrl, wxT(""), flag);
59 }
60
61 void RegisterPageTurn()
62 {
63 m_controlList.push_back(Control(0, wxT(""), AJ_TurnPage));
64 }
65
66 void CaptureAll();
67
68 protected: // internal utils
69 struct Control
70 {
71 Control() {}
72
73 Control(wxWindow * _ctrl, wxString _name, int _flag)
74 : ctrl(_ctrl), name(_name), flag(_flag) {}
75
76 wxWindow * ctrl;
77 wxString name;
78 int flag;
79 };
80
81 wxBitmap Capture(Control & ctrl);
82
83 //if AJ_RegionAdjust is specified, the following line will use the label trick to adjust
84 //the region position and size
85 wxRect GetRect(wxWindow* ctrl, int flag);
86
87 //put the control back after the label trick(Using reparent/resizer approach)
88 void PutBack(wxWindow * ctrl);
89
90 wxBitmap Union(wxBitmap pic1, wxBitmap pic2);
91
92 void Save(wxBitmap screenshot, wxString fileName);
93
94 private:
95 typedef std::vector<Control> ControlList;
96 ControlList m_controlList;
97
98 // here we introduce the dependency on wxNotebook.
99 // The assumption of this whole class is that the gui has the following top-down structure
100 // wxNotebook wxPanel wxSizer wxControls
101 wxNotebook* m_notebook;
102
103 wxFlexGridSizer* m_grid;
104
105 wxString m_dir;
106 int m_border;
107 };
108
109 #endif // AUTOCAP_H
110
111