Debian Codegraph @

wxcrafter/controls/gl_canvas_wrapper.cpp

raw
1 #include "gl_canvas_wrapper.h"
2 #include "allocator_mgr.h"
3 //#include <wx/glcanvas.h>
4 #include "int_property.h"
5
6 GLCanvasWrapper::GLCanvasWrapper()
7 : wxcWidget(ID_WXGLCANVAS)
8 {
9 m_namePattern = "m_glCanvas";
10
11 SetPropertyString(_("Common Settings"), "wxGLCanvas");
12 DelProperty(PROP_CONTROL_SPECIFIC_SETTINGS);
13 AddCategory(_("wxGLCanvas Attribute List"));
14
15 AddProperty(new StringProperty("WX_GL_RGBA", _("Use true color palette (on if no attrs specified)")));
16 m_attrs.Add("WX_GL_RGBA");
17
18 AddProperty(new StringProperty("WX_GL_BUFFER_SIZE", _("bits for buffer if not WX_GL_RGBA")));
19 m_attrs.Add("WX_GL_BUFFER_SIZE");
20
21 AddProperty(new StringProperty("WX_GL_LEVEL", _("0 for main buffer, >0 for overlay, <0 for underlay")));
22 m_attrs.Add("WX_GL_LEVEL");
23
24 AddProperty(new StringProperty("WX_GL_DOUBLEBUFFER", _("use double buffering (on if no attrs specified)")));
25 m_attrs.Add("WX_GL_DOUBLEBUFFER");
26
27 AddProperty(new StringProperty("WX_GL_STEREO", _("use stereoscopic display")));
28 m_attrs.Add("WX_GL_STEREO");
29
30 AddProperty(new StringProperty("WX_GL_AUX_BUFFERS", _("number of auxiliary buffers")));
31 m_attrs.Add("WX_GL_AUX_BUFFERS");
32
33 AddProperty(new StringProperty("WX_GL_MIN_RED", _("use red buffer with most bits (> MIN_RED bits)")));
34 m_attrs.Add("WX_GL_MIN_RED");
35
36 AddProperty(new StringProperty("WX_GL_MIN_GREEN", _("use green buffer with most bits (> MIN_GREEN bits)")));
37 m_attrs.Add("WX_GL_MIN_GREEN");
38
39 AddProperty(new StringProperty("WX_GL_MIN_BLUE", _("use blue buffer with most bits (> MIN_BLUE bits)")));
40 m_attrs.Add("WX_GL_MIN_BLUE");
41
42 AddProperty(new StringProperty("WX_GL_MIN_ALPHA", _("use alpha buffer with most bits (> MIN_ALPHA bits)")));
43 m_attrs.Add("WX_GL_MIN_ALPHA");
44
45 AddProperty(new StringProperty("WX_GL_DEPTH_SIZE", _("bits for Z-buffer (0,16,32)")));
46 m_attrs.Add("WX_GL_DEPTH_SIZE");
47
48 AddProperty(new StringProperty("WX_GL_STENCIL_SIZE", _("bits for stencil buffer")));
49 m_attrs.Add("WX_GL_STENCIL_SIZE");
50
51 AddProperty(
52 new StringProperty("WX_GL_MIN_ACCUM_RED", _("use red accum buffer with most bits (> MIN_ACCUM_RED bits)")));
53 m_attrs.Add("WX_GL_MIN_ACCUM_RED");
54
55 AddProperty(
56 new StringProperty("WX_GL_MIN_ACCUM_GREEN", _("use green buffer with most bits (> MIN_ACCUM_GREEN bits)")));
57 m_attrs.Add("WX_GL_MIN_ACCUM_GREEN");
58
59 AddProperty(
60 new StringProperty("WX_GL_MIN_ACCUM_BLUE", _("use blue buffer with most bits (> MIN_ACCUM_BLUE bits)")));
61 m_attrs.Add("WX_GL_MIN_ACCUM_BLUE");
62
63 AddProperty(
64 new StringProperty("WX_GL_MIN_ACCUM_ALPHA", _("use alpha buffer with most bits (> MIN_ACCUM_ALPHA bits)")));
65 m_attrs.Add("WX_GL_MIN_ACCUM_ALPHA");
66
67 AddProperty(new StringProperty("WX_GL_SAMPLE_BUFFERS", _("1 for multisampling support (antialiasing)")));
68 m_attrs.Add("WX_GL_SAMPLE_BUFFERS");
69
70 AddProperty(new StringProperty("WX_GL_SAMPLES", _("4 for 2x2 antialiasing supersampling on most graphics cards")));
71 m_attrs.Add("WX_GL_SAMPLES");
72
73 SetName(GenerateName());
74 }
75
76 GLCanvasWrapper::~GLCanvasWrapper() {}
77
78 wxcWidget* GLCanvasWrapper::Clone() const { return new GLCanvasWrapper(); }
79
80 wxString GLCanvasWrapper::CppCtorCode() const
81 {
82 wxString cppCode;
83 wxString attrList;
84 wxArrayString validAttrsName, validAttrsValue;
85 // get the number of attributes provided
86 int bufferSize = 0;
87 for(size_t i = 0; i < m_attrs.GetCount(); ++i) {
88 wxString v = PropertyString(m_attrs.Item(i));
89 if(!v.Trim().Trim(false).IsEmpty()) {
90 bufferSize += 2; // one for the property and one for its value
91 validAttrsName.Add(m_attrs.Item(i));
92 validAttrsValue.Add(v);
93 }
94 }
95
96 wxString AttrName;
97 AttrName << GetName() << "Attr";
98 if(bufferSize) {
99 bufferSize++; // terminator
100 attrList << "int *" << AttrName << " = new int[ " << bufferSize << " ];\n";
101 } else {
102 attrList << "int *" << AttrName << " = NULL;\n";
103 }
104
105 int idx = 0;
106 for(size_t i = 0; i < validAttrsName.GetCount(); ++i) {
107 attrList << AttrName << "[" << idx++ << "] = " << validAttrsName.Item(i) << ";\n";
108 attrList << AttrName << "[" << idx++ << "] = " << validAttrsValue.Item(i) << ";\n";
109 }
110
111 if(validAttrsName.GetCount()) { attrList << AttrName << "[" << idx << "] = 0;\n"; }
112
113 if(!attrList.IsEmpty()) { cppCode << attrList; }
114
115 cppCode << GetName() << " = new " << GetRealClassName() << "(" << GetWindowParent() << ", " << GetId() << ", "
116 << AttrName << ", "
117 << "wxDefaultPosition, " << SizeAsString() << ", " << StyleFlags("0") << ");\n";
118 cppCode << CPPCommonAttributes();
119 cppCode << "wxDELETEA( " << AttrName << " );\n";
120 return cppCode;
121 }
122
123 void GLCanvasWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add("#include <wx/glcanvas.h>"); }
124
125 wxString GLCanvasWrapper::GetWxClassName() const { return "wxGLCanvas"; }
126
127 void GLCanvasWrapper::ToXRC(wxString& text, XRC_TYPE type) const
128 {
129 if(type == XRC_LIVE) {
130 text << XRCUnknown();
131
132 } else {
133 text << XRCPrefix() << XRCStyle() << XRCSize() << XRCCommonAttributes() << XRCSuffix();
134 }
135 }