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 arrow clicks.
24 handle_arrow (puObject * arrow)
26 puSlider * slider = (puSlider *)arrow->getUserData();
27 puListBox * list_box = (puListBox *)slider->getUserData();
30 switch (((puArrowButton *)arrow)->getArrowType()) {
42 int index = list_box->getTopItem();
46 else if (index >= list_box->getNumItems())
47 index = list_box->getNumItems() - 1;
48 list_box->setTopItem(index);
50 slider->setValue(1.0f - float(index)/list_box->getNumItems());
53 puList::puList (int x, int y, int w, int h)
60 puList::puList (int x, int y, int w, int h, char ** contents)
73 puList::newList (char ** contents)
75 _list_box->newList(contents);
80 puList::getListStringValue ()
82 return _contents[_list_box->getIntegerValue()];
86 puList::getListIntegerValue()
88 return _list_box->getIntegerValue();
92 puList::init (int w, int h)
94 _frame = new puFrame(0, 0, w, h);
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);
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);
107 _down_arrow = new puArrowButton(w-30, 0, w, 30, PUARROW_DOWN) ;
108 _down_arrow->setUserData(_slider);
109 _down_arrow->setCallback(handle_arrow);
111 _up_arrow = new puArrowButton(w-30, h-30, w, h, PUARROW_UP);
112 _up_arrow->setUserData(_slider);
113 _up_arrow->setCallback(handle_arrow);