]> git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/autocapture.h
Update configuration for OpenVMS
[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 _AUTOCAPTURE_H_
10 #define _AUTOCAPTURE_H_
11
12 #include <vector>
13 #include <ctime>
14
15 #include <wx/notebook.h>
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 // delay is only useful for Mac, for fixing a delay bug
69 static wxBitmap Capture(wxRect rect, int delay = 0);
70 static wxBitmap Capture(int x, int y, int width, int height, int delay = 0);
71
72 static void Delay(int seconds);
73
74
75 private: // internal utils
76 struct Control
77 {
78 Control() {}
79
80 Control(wxWindow * _ctrl, wxString _name, int _flag)
81 : ctrl(_ctrl), name(_name), flag(_flag) {}
82
83 wxWindow * ctrl;
84 wxString name;
85 int flag;
86 };
87
88 wxBitmap Capture(Control & ctrl);
89
90 // if AJ_RegionAdjust is specified, the following line will use the label
91 // trick to adjust the region position and size
92 wxRect GetRect(wxWindow* ctrl, int flag);
93
94 // put the control back after the label trick(Using reparent/resizer approach)
95 void PutBack(wxWindow * ctrl);
96
97 wxBitmap Union(wxBitmap pic1, wxBitmap pic2);
98
99 void Save(wxBitmap screenshot, wxString fileName);
100
101 typedef std::vector<Control> ControlList;
102 ControlList m_controlList;
103
104 // here we introduce the dependency on wxNotebook.
105 // The assumption of this whole class is that the gui has the following top-down structure
106 // wxNotebook wxPanel wxSizer wxControls
107 wxNotebook* m_notebook;
108
109 wxFlexGridSizer* m_grid;
110
111 wxString m_dir;
112 int m_border;
113 };
114
115 #endif // _AUTOCAPTURE_H_
116
117