]>
Commit | Line | Data |
---|---|---|
0d5eda9c FM |
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 | ||
0d5eda9c | 17 | |
6cd1aa9d | 18 | // TODO: document what these flags mean |
0d5eda9c FM |
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 | ||
4bae10bd FM |
29 | |
30 | // ---------------------------------------------------------------------------- | |
31 | // class AutoCaptureMechanism | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
0d5eda9c FM |
34 | class AutoCaptureMechanism |
35 | { | |
36 | public: | |
6cd1aa9d | 37 | AutoCaptureMechanism(wxNotebook *notebook, |
0d5eda9c FM |
38 | wxString directory = wxT("screenshots"), |
39 | int border = 5) | |
40 | : m_notebook(notebook), m_dir(directory), m_border(border) {} | |
60a2264d | 41 | |
0d5eda9c FM |
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 | ||
6cd1aa9d | 64 | // capture all controls of the associated notebook |
60a2264d | 65 | void CaptureAll(); |
0d5eda9c | 66 | |
6cd1aa9d FM |
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 | ||
4bae10bd | 72 | protected: // internal utils |
0d5eda9c FM |
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 | ||
4bae10bd | 85 | wxBitmap Capture(Control & ctrl); |
0d5eda9c | 86 | |
6cd1aa9d FM |
87 | // if AJ_RegionAdjust is specified, the following line will use the label |
88 | // trick to adjust the region position and size | |
0d5eda9c | 89 | wxRect GetRect(wxWindow* ctrl, int flag); |
4bae10bd | 90 | |
6cd1aa9d | 91 | // put the control back after the label trick(Using reparent/resizer approach) |
0d5eda9c FM |
92 | void PutBack(wxWindow * ctrl); |
93 | ||
4bae10bd | 94 | wxBitmap Union(wxBitmap pic1, wxBitmap pic2); |
0d5eda9c | 95 | |
4bae10bd | 96 | void Save(wxBitmap screenshot, wxString fileName); |
0d5eda9c | 97 | |
4bae10bd FM |
98 | private: |
99 | typedef std::vector<Control> ControlList; | |
100 | ControlList m_controlList; | |
0d5eda9c | 101 | |
4bae10bd FM |
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; | |
0d5eda9c | 106 | |
4bae10bd | 107 | wxFlexGridSizer* m_grid; |
0d5eda9c | 108 | |
4bae10bd FM |
109 | wxString m_dir; |
110 | int m_border; | |
0d5eda9c FM |
111 | }; |
112 | ||
113 | #endif // AUTOCAP_H | |
114 | ||
115 |