File: gl_canvas_wrapper.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (135 lines) | stat: -rw-r--r-- 5,209 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include "gl_canvas_wrapper.h"
#include "allocator_mgr.h"
//#include <wx/glcanvas.h>
#include "int_property.h"

GLCanvasWrapper::GLCanvasWrapper()
    : wxcWidget(ID_WXGLCANVAS)
{
    m_namePattern = "m_glCanvas";

    SetPropertyString(_("Common Settings"), "wxGLCanvas");
    DelProperty(PROP_CONTROL_SPECIFIC_SETTINGS);
    AddCategory("wxGLCanvas Attribute List");

    AddProperty(new StringProperty("WX_GL_RGBA", _("Use true color palette (on if no attrs specified)")));
    m_attrs.Add("WX_GL_RGBA");

    AddProperty(new StringProperty("WX_GL_BUFFER_SIZE", _("bits for buffer if not WX_GL_RGBA")));
    m_attrs.Add("WX_GL_BUFFER_SIZE");

    AddProperty(new StringProperty("WX_GL_LEVEL", _("0 for main buffer, >0 for overlay, <0 for underlay")));
    m_attrs.Add("WX_GL_LEVEL");

    AddProperty(new StringProperty("WX_GL_DOUBLEBUFFER", _("use double buffering (on if no attrs specified)")));
    m_attrs.Add("WX_GL_DOUBLEBUFFER");

    AddProperty(new StringProperty("WX_GL_STEREO", _("use stereoscopic display")));
    m_attrs.Add("WX_GL_STEREO");

    AddProperty(new StringProperty("WX_GL_AUX_BUFFERS", _("number of auxiliary buffers")));
    m_attrs.Add("WX_GL_AUX_BUFFERS");

    AddProperty(new StringProperty("WX_GL_MIN_RED", _("use red buffer with most bits (> MIN_RED bits)")));
    m_attrs.Add("WX_GL_MIN_RED");

    AddProperty(new StringProperty("WX_GL_MIN_GREEN", _("use green buffer with most bits (> MIN_GREEN bits)")));
    m_attrs.Add("WX_GL_MIN_GREEN");

    AddProperty(new StringProperty("WX_GL_MIN_BLUE", _("use blue buffer with most bits (> MIN_BLUE bits)")));
    m_attrs.Add("WX_GL_MIN_BLUE");

    AddProperty(new StringProperty("WX_GL_MIN_ALPHA", _("use alpha buffer with most bits (> MIN_ALPHA bits)")));
    m_attrs.Add("WX_GL_MIN_ALPHA");

    AddProperty(new StringProperty("WX_GL_DEPTH_SIZE", _("bits for Z-buffer (0,16,32)")));
    m_attrs.Add("WX_GL_DEPTH_SIZE");

    AddProperty(new StringProperty("WX_GL_STENCIL_SIZE", _("bits for stencil buffer")));
    m_attrs.Add("WX_GL_STENCIL_SIZE");

    AddProperty(
        new StringProperty("WX_GL_MIN_ACCUM_RED", _("use red accum buffer with most bits (> MIN_ACCUM_RED bits)")));
    m_attrs.Add("WX_GL_MIN_ACCUM_RED");

    AddProperty(
        new StringProperty("WX_GL_MIN_ACCUM_GREEN", _("use green buffer with most bits (> MIN_ACCUM_GREEN bits)")));
    m_attrs.Add("WX_GL_MIN_ACCUM_GREEN");

    AddProperty(
        new StringProperty("WX_GL_MIN_ACCUM_BLUE", _("use blue buffer with most bits (> MIN_ACCUM_BLUE bits)")));
    m_attrs.Add("WX_GL_MIN_ACCUM_BLUE");

    AddProperty(
        new StringProperty("WX_GL_MIN_ACCUM_ALPHA", _("use alpha buffer with most bits (> MIN_ACCUM_ALPHA bits)")));
    m_attrs.Add("WX_GL_MIN_ACCUM_ALPHA");

    AddProperty(new StringProperty("WX_GL_SAMPLE_BUFFERS", _("1 for multisampling support (antialiasing)")));
    m_attrs.Add("WX_GL_SAMPLE_BUFFERS");

    AddProperty(new StringProperty("WX_GL_SAMPLES", _("4 for 2x2 antialiasing supersampling on most graphics cards")));
    m_attrs.Add("WX_GL_SAMPLES");

    SetName(GenerateName());
}

GLCanvasWrapper::~GLCanvasWrapper() {}

wxcWidget* GLCanvasWrapper::Clone() const { return new GLCanvasWrapper(); }

wxString GLCanvasWrapper::CppCtorCode() const
{
    wxString cppCode;
    wxString attrList;
    wxArrayString validAttrsName, validAttrsValue;
    // get the number of attributes provided
    int bufferSize = 0;
    for(size_t i = 0; i < m_attrs.GetCount(); ++i) {
        wxString v = PropertyString(m_attrs.Item(i));
        if(!v.Trim().Trim(false).IsEmpty()) {
            bufferSize += 2; // one for the property and one for its value
            validAttrsName.Add(m_attrs.Item(i));
            validAttrsValue.Add(v);
        }
    }

    wxString AttrName;
    AttrName << GetName() << "Attr";
    if(bufferSize) {
        bufferSize++; // terminator
        attrList << "int *" << AttrName << " = new int[ " << bufferSize << " ];\n";
    } else {
        attrList << "int *" << AttrName << " = NULL;\n";
    }

    int idx = 0;
    for(size_t i = 0; i < validAttrsName.GetCount(); ++i) {
        attrList << AttrName << "[" << idx++ << "] = " << validAttrsName.Item(i) << ";\n";
        attrList << AttrName << "[" << idx++ << "] = " << validAttrsValue.Item(i) << ";\n";
    }

    if(validAttrsName.GetCount()) { attrList << AttrName << "[" << idx << "] = 0;\n"; }

    if(!attrList.IsEmpty()) { cppCode << attrList; }

    cppCode << GetName() << " = new " << GetRealClassName() << "(" << GetWindowParent() << ", " << GetId() << ", "
            << AttrName << ", "
            << "wxDefaultPosition, " << SizeAsString() << ", " << StyleFlags("0") << ");\n";
    cppCode << CPPCommonAttributes();
    cppCode << "wxDELETEA( " << AttrName << " );\n";
    return cppCode;
}

void GLCanvasWrapper::GetIncludeFile(wxArrayString& headers) const { headers.Add("#include <wx/glcanvas.h>"); }

wxString GLCanvasWrapper::GetWxClassName() const { return "wxGLCanvas"; }

void GLCanvasWrapper::ToXRC(wxString& text, XRC_TYPE type) const
{
    if(type == XRC_LIVE) {
        text << XRCUnknown();

    } else {
        text << XRCPrefix() << XRCStyle() << XRCSize() << XRCCommonAttributes() << XRCSuffix();
    }
}