]> git.mxchange.org Git - flightgear.git/blob - src/GUI/puList.cxx
Boris Koenig:
[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     init(w, h);
57 }
58
59 puList::puList (int x, int y, int w, int h, char ** contents)
60     : puGroup(x, y)
61 {
62     init(w, h);
63     newList(contents);
64 }
65
66 puList::~puList ()
67 {
68 }
69
70 void
71 puList::newList (char ** contents)
72 {
73     _list_box->newList(contents);
74     _contents = contents;
75 }
76
77 char *
78 puList::getStringValue ()
79 {
80     return _contents[_list_box->getIntegerValue()];
81 }
82
83 void
84 puList::init (int w, int h)
85 {
86     _frame = new puFrame(0, 0, w, h);
87
88     _list_box = new puListBox(0, 0, w-30, h);
89     _list_box->setStyle(-PUSTYLE_SMALL_SHADED);
90     _list_box->setUserData(this);
91     _list_box->setValue(0);
92
93     _slider = new puSlider(w-30, 30, h-60, true);
94     _slider->setValue(1.0f);
95     _slider->setUserData(_list_box);
96     _slider->setCallback(handle_slider);
97     _slider->setCBMode(PUSLIDER_ALWAYS);
98
99     _down_arrow = new puArrowButton(w-30, 0, w, 30, PUARROW_DOWN) ;
100     _down_arrow->setUserData(_slider);
101     _down_arrow->setCallback(handle_arrow);
102
103     _up_arrow = new puArrowButton(w-30, h-30, w, h, PUARROW_UP);
104     _up_arrow->setUserData(_slider);
105     _up_arrow->setCallback(handle_arrow);
106
107     close();
108 }
109
110 // end of puList.cxx