hx3d  1
2D/3D Simple Game Framework
widget.cpp
1 /*
2  Base widget.
3  Copyright (C) 2015 Denis BOURGE
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
18  USA
19 */
20 
21 #include "hx3d/gui/widget.hpp"
22 
23 #include "hx3d/graphics/geometries/geometry.hpp"
24 
25 namespace hx3d {
26 namespace gui {
27 
28 Widget::Widget(Widget* parent): Mesh(),
29  _parent(parent)
30  {
31  _geometry = Make<graphics::geom::Geometry>();
32 
33  _geometry->setAttribute("Position", std::vector<float> {
34  -0.5f, 0.5f, 0.f,
35  0.5, 0.5f, 0.f,
36  -0.5f, -0.5f, 0.f,
37  0.5f, -0.5f, 0.f
38  });
39 
40  _geometry->setIndices(std::vector<GLushort> {
41  0, 1, 2,
42  0, 2, 3
43  });
44 
45  _geometry->setAttribute("Color", std::vector<float> {
46  1, 1, 1, 1,
47  1, 1, 1, 1,
48  1, 1, 1, 1,
49  1, 1, 1, 1
50  });
51 
52  _geometry->setAttribute("Texture", std::vector<float> {
53  0, 0,
54  0, 1,
55  1, 0,
56  1, 1
57  });
58 
59  _geometry->uploadAll();
60 }
61 
62 void Widget::add(Ptr<Widget> widget) {
63  widget->_parent = this;
64  _children.push_back(widget);
65 }
66 
67 void Widget::draw(Ptr<Shader> shader) {
68  Mesh::draw(shader);
69 }
70 
71 } /* gui */
72 } /* hx3d */
void add(Ptr< Widget > widget)
Add a widget to the list.
Definition: widget.cpp:62
Base GUI element.
Definition: widget.hpp:39
hx3d framework namespace
Definition: audio.hpp:26
Widget(Widget *parent)
Construct a widget from a parent widget.
Definition: widget.cpp:28
Ptr< geom::BaseGeometry > _geometry
Current geometry.
Definition: mesh.hpp:96
std::shared_ptr< T > Ptr
Quick-typing shared ptr.
Definition: ptr.hpp:34