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, int sl_width)
72 puList::puList (int x, int y, int w, int h, char ** contents, int sl_width)
86 puList::newList (char ** contents)
88 _list_box->newList(contents);
93 puList::getListStringValue ()
95 int i = _list_box->getIntegerValue();
96 return i < 0 ? 0 : _contents[i];
100 puList::getListIntegerValue()
102 return _list_box->getIntegerValue();
106 puList::init (int w, int h)
108 _frame = new puFrame(0, 0, w, h);
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);
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);
122 _down_arrow = new puArrowButton(w-sw, 0, w, sw, PUARROW_DOWN) ;
123 _down_arrow->setUserData(_slider);
124 _down_arrow->setCallback(handle_arrow);
126 _up_arrow = new puArrowButton(w-sw, h-sw, w, h, PUARROW_UP);
127 _up_arrow->setUserData(_slider);
128 _up_arrow->setCallback(handle_arrow);
134 puList::setColourScheme (float r, float g, float b, float a)
136 puObject::setColourScheme(r, g, b, a);
137 _list_box->setColourScheme(r, g, b, a);
141 puList::setColour (int which, float r, float g, float b, float a)
143 puObject::setColour(which, r, g, b, a);
144 _list_box->setColour(which, r, g, b, a);
148 puList::setSize (int w, int h)
150 puObject::setSize(w, h);
151 _frame->setSize(w, h);
152 _list_box->setSize(w-sw, h);
154 _slider->setPosition(w-sw, sw);
155 _slider->setSize(sw, h-2*sw);
157 _down_arrow->setPosition(w-sw, 0);
158 _up_arrow->setPosition(w-sw, h-sw);