]> git.mxchange.org Git - flightgear.git/blob - src/GUI/puList.cxx
Don't restore initial screen geometry because there is nothing in fg_os* to resize...
[flightgear.git] / src / GUI / puList.cxx
1 // puList.cxx - implementation of a scrolling list box.
2
3 #include "puList.hxx"
4
5
6 /**
7  * Static function: handle slider movements.
8  */
9 static void
10 handle_slider (puObject * slider)
11 {
12     puListBox * box = (puListBox *)slider->getUserData();
13     int index = int(box->getNumItems() * (1.0 - slider->getFloatValue()));
14     if (index >= box->getNumItems())
15         index = box->getNumItems() - 1;
16     box->setTopItem(index);
17 }
18
19
20 /**
21  * Static function: handle list entry clicks.
22  */
23 static void
24 handle_list_entry (puObject * listbox)
25 {
26     puListBox * box = (puListBox *)listbox->getUserData();
27     box->invokeCallback();
28 }
29
30
31 /**
32  * Static function: handle arrow clicks.
33  */
34 static void
35 handle_arrow (puObject * arrow)
36 {
37     puSlider * slider = (puSlider *)arrow->getUserData();
38     puListBox * list_box = (puListBox *)slider->getUserData();
39
40     int step;
41     switch (((puArrowButton *)arrow)->getArrowType()) {
42     case PUARROW_DOWN:
43         step = 1;
44         break;
45     case PUARROW_UP:
46         step = -1;
47         break;
48     default:
49         step = 0;
50         break;
51     }
52
53     int index = list_box->getTopItem();
54     index += step;
55     if (index < 0)
56         index = 0;
57     else if (index >= list_box->getNumItems())
58         index = list_box->getNumItems() - 1;
59     list_box->setTopItem(index);
60
61     slider->setValue(1.0f - float(index)/list_box->getNumItems());
62 }
63
64 puList::puList (int x, int y, int w, int h, int sl_width)
65     : puGroup(x, y),
66       sw(sl_width)
67 {
68     type |= PUCLASS_LIST;
69     init(w, h);
70 }
71
72 puList::puList (int x, int y, int w, int h, char ** contents, int sl_width)
73     : puGroup(x, y),
74       sw(sl_width)
75 {
76     type |= PUCLASS_LIST;
77     init(w, h);
78     newList(contents);
79 }
80
81 puList::~puList ()
82 {
83 }
84
85 void
86 puList::newList (char ** contents)
87 {
88     _list_box->newList(contents);
89     _contents = contents;
90 }
91
92 char *
93 puList::getListStringValue ()
94 {
95     int i = _list_box->getIntegerValue();
96     return i < 0 ? 0 : _contents[i];
97 }
98
99 int
100 puList::getListIntegerValue()
101 {
102   return _list_box->getIntegerValue();
103 }
104
105 void
106 puList::init (int w, int h)
107 {
108     _frame = new puFrame(0, 0, w, h);
109
110     _list_box = new puListBox(0, 0, w-sw, h);
111     _list_box->setStyle(-PUSTYLE_SMALL_SHADED);
112     _list_box->setUserData(this);
113     _list_box->setCallback(handle_list_entry);
114     _list_box->setValue(0);
115
116     _slider = new puSlider(w-sw, sw, h-2*sw, true, sw);
117     _slider->setValue(1.0f);
118     _slider->setUserData(_list_box);
119     _slider->setCallback(handle_slider);
120     _slider->setCBMode(PUSLIDER_ALWAYS);
121
122     _down_arrow = new puArrowButton(w-sw, 0, w, sw, PUARROW_DOWN) ;
123     _down_arrow->setUserData(_slider);
124     _down_arrow->setCallback(handle_arrow);
125
126     _up_arrow = new puArrowButton(w-sw, h-sw, w, h, PUARROW_UP);
127     _up_arrow->setUserData(_slider);
128     _up_arrow->setCallback(handle_arrow);
129
130     close();
131 }
132
133 void
134 puList::setColourScheme (float r, float g, float b, float a)
135 {
136     puObject::setColourScheme(r, g, b, a);
137     _list_box->setColourScheme(r, g, b, a);
138 }
139
140 void
141 puList::setColour (int which, float r, float g, float b, float a)
142 {
143     puObject::setColour(which, r, g, b, a);
144     _list_box->setColour(which, r, g, b, a);
145 }
146
147 void
148 puList::setSize (int w, int h)
149 {
150     puObject::setSize(w, h);
151     _frame->setSize(w, h);
152     _list_box->setSize(w-sw, h);
153
154     _slider->setPosition(w-sw, sw);
155     _slider->setSize(sw, h-2*sw);
156
157     _down_arrow->setPosition(w-sw, 0);
158     _up_arrow->setPosition(w-sw, h-sw);
159 }
160
161 // end of puList.cxx