1 // Glue for GUI layout items implemented in Nasal space
3 // Copyright (C) 2014 Thomas Geymayer <tomgey@gmail.com>
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Library General Public
7 // License as published by the Free Software Foundation; either
8 // version 2 of the License, or (at your option) any later version.
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 // Library General Public License for more details.
15 // You should have received a copy of the GNU Library General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "NasalWidget.hxx"
21 #include <simgear/canvas/Canvas.hxx>
22 #include <simgear/nasal/cppbind/Ghost.hxx>
29 //----------------------------------------------------------------------------
30 NasalWidget::NasalWidget(naRef impl):
33 assert( naIsHash(_nasal_impl.get_naRef()) );
36 //----------------------------------------------------------------------------
37 void NasalWidget::setGeometry(const SGRect<int>& geom)
39 if( _geometry == geom )
45 _set_geometry(_nasal_impl.get_naRef(), geom);
48 //----------------------------------------------------------------------------
49 void NasalWidget::setSetGeometryFunc(const SetGeometryFunc& func)
54 //----------------------------------------------------------------------------
55 void NasalWidget::setImpl(naRef obj)
57 _nasal_impl.reset(obj);
60 //----------------------------------------------------------------------------
61 naRef NasalWidget::getImpl() const
63 return _nasal_impl.get_naRef();
66 //----------------------------------------------------------------------------
67 void NasalWidget::setSizeHint(const SGVec2i& s)
74 // TODO just invalidate size_hint? Probably not a performance issue...
78 //----------------------------------------------------------------------------
79 void NasalWidget::setMinimumSize(const SGVec2i& s)
88 //----------------------------------------------------------------------------
89 void NasalWidget::setMaximumSize(const SGVec2i& s)
98 //----------------------------------------------------------------------------
99 bool NasalWidget::_set(naContext c, const std::string& key, naRef val)
101 if( !_nasal_impl.valid() )
104 nasal::Hash(_nasal_impl.get_naRef(), c).set(key, val);
108 //----------------------------------------------------------------------------
109 static naRef f_makeNasalWidget(const nasal::CallContext& ctx)
111 return ctx.to_nasal(NasalWidgetRef(
112 new NasalWidget( ctx.requireArg<naRef>(0) )
116 //----------------------------------------------------------------------------
117 void NasalWidget::setupGhost(nasal::Hash& ns)
119 nasal::Ghost<NasalWidgetRef>::init("canvas.Widget")
120 .bases<LayoutItemRef>()
121 ._set(&NasalWidget::_set)
122 .member("parents", &NasalWidget::getParents)
123 .method("setSetGeometryFunc", &NasalWidget::setSetGeometryFunc)
124 .method("setSizeHint", &NasalWidget::setSizeHint)
125 .method("setMinimumSize", &NasalWidget::setMinimumSize)
126 .method("setMaximumSize", &NasalWidget::setMaximumSize);
128 nasal::Hash widget_hash = ns.createHash("Widget");
129 widget_hash.set("new", &f_makeNasalWidget);
132 //----------------------------------------------------------------------------
133 naRef NasalWidget::getParents(NasalWidget& w, naContext c)
135 naRef parents[] = { w._nasal_impl.get_naRef() };
136 return nasal::to_nasal(c, parents);
139 //----------------------------------------------------------------------------
140 SGVec2i NasalWidget::sizeHintImpl() const
145 //----------------------------------------------------------------------------
146 SGVec2i NasalWidget::minimumSizeImpl() const
151 //----------------------------------------------------------------------------
152 SGVec2i NasalWidget::maximumSizeImpl() const
157 } // namespace canvas
158 } // namespace simgear