]> git.mxchange.org Git - flightgear.git/blob - src/GUI/layout-props.cxx
layout-props.cxx: hrule/vrule shall be accepted as widgets even if they
[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 but "hrule" and "vrule"
46     // are widgets...
47     int n = 0;
48     for(int i=0; i<_prop->nChildren(); i++) {
49         SGPropertyNode* p = _prop->getChild(i);
50         const char* name = p->getName();
51         if(p->nChildren() != 0 || !strcmp(name, "hrule")
52                 || !strcmp(name, "vrule"))
53             n++;
54     }
55     return n;
56 }
57
58 LayoutWidget LayoutWidget::getChild(int idx)
59 {
60     // Same hack.  Note that access is linear time in the number of
61     // children...
62     int n = 0;
63     for(int i=0; i<_prop->nChildren(); i++) {
64         SGPropertyNode* p = _prop->getChild(i);
65         const char* name = p->getName();
66         if(p->nChildren() != 0 || !strcmp(name, "hrule")
67                 || !strcmp(name, "vrule")) {
68             if(idx == n) return LayoutWidget(p);
69             n++;
70         }
71     }
72     return LayoutWidget(0);
73 }
74
75 bool LayoutWidget::hasField(const char* f)
76 {
77     return _prop->hasChild(f);
78 }
79
80 int LayoutWidget::getNum(const char* f)
81 {
82     return _prop->getIntValue(f);
83 }
84
85 bool LayoutWidget::getBool(const char* f)
86 {
87     return _prop->getBoolValue(f);
88 }
89
90 const char* LayoutWidget::getStr(const char* f)
91 {
92     return _prop->getStringValue(f);
93 }
94
95 void LayoutWidget::setNum(const char* f, int num)
96 {
97     _prop->setIntValue(f, num);
98 }
99