]> git.mxchange.org Git - flightgear.git/blob - src/GUI/puList.cxx
replace depreciated plib symbols with their new forms
[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 arrow clicks.
22  */
23 static void
24 handle_arrow (puObject * arrow)
25 {
26     puSlider * slider = (puSlider *)arrow->getUserData();
27     puListBox * list_box = (puListBox *)slider->getUserData();
28
29     int step;
30     switch (((puArrowButton *)arrow)->getArrowType()) {
31     case PUARROW_DOWN:
32         step = 1;
33         break;
34     case PUARROW_UP:
35         step = -1;
36         break;
37     default:
38         step = 0;
39         break;
40     }
41
42     int index = list_box->getTopItem();
43     index += step;
44     if (index < 0)
45         index = 0;
46     else if (index >= list_box->getNumItems())
47         index = list_box->getNumItems() - 1;
48     list_box->setTopItem(index);
49
50     slider->setValue(1.0f - float(index)/list_box->getNumItems());
51 }
52
53 puList::puList (int x, int y, int w, int h)
54     : puGroup(x, y)
55 {
56     type |= PUCLASS_LIST;
57     init(w, h);
58 }
59
60 puList::puList (int x, int y, int w, int h, char ** contents)
61     : puGroup(x, y)
62 {
63     type |= PUCLASS_LIST;
64     init(w, h);
65     newList(contents);
66 }
67
68 puList::~puList ()
69 {
70 }
71
72 void
73 puList::newList (char ** contents)
74 {
75     _list_box->newList(contents);
76     _contents = contents;
77 }
78
79 char *
80 puList::getListStringValue ()
81 {
82     return _contents[_list_box->getIntegerValue()];
83 }
84
85 int
86 puList::getListIntegerValue()
87 {
88   return _list_box->getIntegerValue();
89 }
90
91 void
92 puList::init (int w, int h)
93 {
94     _frame = new puFrame(0, 0, w, h);
95
96     _list_box = new puListBox(0, 0, w-30, h);
97     _list_box->setStyle(-PUSTYLE_SMALL_SHADED);
98     _list_box->setUserData(this);
99     _list_box->setValue(0);
100
101     _slider = new puSlider(w-30, 30, h-60, true);
102     _slider->setValue(1.0f);
103     _slider->setUserData(_list_box);
104     _slider->setCallback(handle_slider);
105     _slider->setCBMode(PUSLIDER_ALWAYS);
106
107     _down_arrow = new puArrowButton(w-30, 0, w, 30, PUARROW_DOWN) ;
108     _down_arrow->setUserData(_slider);
109     _down_arrow->setCallback(handle_arrow);
110
111     _up_arrow = new puArrowButton(w-30, h-30, w, h, PUARROW_UP);
112     _up_arrow->setUserData(_slider);
113     _up_arrow->setCallback(handle_arrow);
114
115     close();
116 }
117
118 // end of puList.cxx