1 // puList.cxx - implementation of a scrolling list box.
7 * Static function: handle slider movements.
10 handle_slider (puObject * slider)
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);
21 * Static function: handle list entry clicks.
24 handle_list_entry (puObject * listbox)
26 puListBox * box = (puListBox *)listbox->getUserData();
27 box->invokeCallback();
32 * Static function: handle arrow clicks.
35 handle_arrow (puObject * arrow)
37 puSlider * slider = (puSlider *)arrow->getUserData();
38 puListBox * list_box = (puListBox *)slider->getUserData();
41 switch (((puArrowButton *)arrow)->getArrowType()) {
53 int index = list_box->getTopItem();
57 else if (index >= list_box->getNumItems())
58 index = list_box->getNumItems() - 1;
59 list_box->setTopItem(index);
61 slider->setValue(1.0f - float(index)/list_box->getNumItems());
64 puList::puList (int x, int y, int w, int h)
71 puList::puList (int x, int y, int w, int h, char ** contents)
84 puList::newList (char ** contents)
86 _list_box->newList(contents);
91 puList::getListStringValue ()
93 int i = _list_box->getIntegerValue();
94 return i < 0 ? 0 : _contents[i];
98 puList::getListIntegerValue()
100 return _list_box->getIntegerValue();
104 puList::init (int w, int h)
107 _frame = new puFrame(0, 0, w, h);
109 _list_box = new puListBox(0, 0, w-sw, h);
110 _list_box->setStyle(-PUSTYLE_SMALL_SHADED);
111 _list_box->setUserData(this);
112 _list_box->setCallback(handle_list_entry);
113 _list_box->setValue(0);
115 _slider = new puSlider(w-sw, sw, h-2*sw, true, sw);
116 _slider->setValue(1.0f);
117 _slider->setUserData(_list_box);
118 _slider->setCallback(handle_slider);
119 _slider->setCBMode(PUSLIDER_ALWAYS);
121 _down_arrow = new puArrowButton(w-sw, 0, w, sw, PUARROW_DOWN) ;
122 _down_arrow->setUserData(_slider);
123 _down_arrow->setCallback(handle_arrow);
125 _up_arrow = new puArrowButton(w-sw, h-sw, w, h, PUARROW_UP);
126 _up_arrow->setUserData(_slider);
127 _up_arrow->setCallback(handle_arrow);
133 puList::setColourScheme (float r, float g, float b, float a)
135 puObject::setColourScheme(r, g, b, a);
136 _list_box->setColourScheme(r, g, b, a);
140 puList::setColour (int which, float r, float g, float b, float a)
142 puObject::setColour(which, r, g, b, a);
143 _list_box->setColour(which, r, g, b, a);