]> git.mxchange.org Git - flightgear.git/blob - src/GUI/layout-props.cxx
don't destroy iterated map entries; delete _menubar; restore closed
[flightgear.git] / src / GUI / layout-props.cxx
1 #ifdef HAVE_CONFIG_H
2 #  include <config.h>
3 #endif
4
5 #include <plib/pu.h>
6 #include <simgear/props/props.hxx>
7
8 #include "layout.hxx"
9
10 // This file contains the code implementing the LayoutWidget class in
11 // terms of a PropertyNode (plus a tiny bit of PUI glue).  See
12 // layout.cxx for the actual layout engine.
13
14 puFont LayoutWidget::FONT;
15
16 void LayoutWidget::setDefaultFont(puFont* font, int pixels)
17 {
18     UNIT = (int)(pixels * (1/3.) + 0.999);
19     FONT = *font;
20 }
21
22 int LayoutWidget::stringLength(const char* s)
23 {
24     return (int)(FONT.getFloatStringWidth(s) + 0.999);
25 }
26
27 const char* LayoutWidget::type()
28 {
29     const char* t = _prop->getName();
30     return (*t == 0) ? "dialog" : t;
31 }
32
33 bool LayoutWidget::hasParent()
34 {
35     return _prop->getParent() ? true : false;
36 }
37
38 LayoutWidget LayoutWidget::parent()
39 {
40     return LayoutWidget(_prop->getParent());
41 }
42
43 int LayoutWidget::nChildren()
44 {
45     // Hack: assume that any non-leaf nodes are widgets...
46     int n = 0;
47     for(int i=0; i<_prop->nChildren(); i++)
48         if(_prop->getChild(i)->nChildren() != 0)
49             n++;
50     return n;
51 }
52
53 LayoutWidget LayoutWidget::getChild(int idx)
54 {
55     // Same hack.  Note that access is linear time in the number of
56     // children...
57     int n = 0;
58     for(int i=0; i<_prop->nChildren(); i++) {
59         SGPropertyNode* p = _prop->getChild(i);
60         if(p->nChildren() != 0) {
61             if(idx == n) return LayoutWidget(p);
62             n++;
63         }
64     }
65     return LayoutWidget(0);
66 }
67
68 bool LayoutWidget::hasField(const char* f)
69 {
70     return _prop->hasChild(f);
71 }
72
73 int LayoutWidget::getNum(const char* f)
74 {
75     return _prop->getIntValue(f);
76 }
77
78 bool LayoutWidget::getBool(const char* f)
79 {
80     return _prop->getBoolValue(f);
81 }
82
83 const char* LayoutWidget::getStr(const char* f)
84 {
85     return _prop->getStringValue(f);
86 }
87
88 void LayoutWidget::setNum(const char* f, int num)
89 {
90     _prop->setIntValue(f, num);
91 }
92