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