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