2003-11-27 23:41:00 +00:00
|
|
|
// puList.cxx - implementation of a scrolling list box.
|
|
|
|
|
|
|
|
#include "puList.hxx"
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Static function: handle slider movements.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
handle_slider (puObject * slider)
|
|
|
|
{
|
|
|
|
puListBox * box = (puListBox *)slider->getUserData();
|
|
|
|
int index = int(box->getNumItems() * (1.0 - slider->getFloatValue()));
|
|
|
|
if (index >= box->getNumItems())
|
|
|
|
index = box->getNumItems() - 1;
|
|
|
|
box->setTopItem(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-23 19:03:31 +00:00
|
|
|
/**
|
|
|
|
* Static function: handle list entry clicks.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
handle_list_entry (puObject * listbox)
|
|
|
|
{
|
|
|
|
puListBox * box = (puListBox *)listbox->getUserData();
|
|
|
|
box->invokeCallback();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
/**
|
|
|
|
* Static function: handle arrow clicks.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
handle_arrow (puObject * arrow)
|
|
|
|
{
|
|
|
|
puSlider * slider = (puSlider *)arrow->getUserData();
|
|
|
|
puListBox * list_box = (puListBox *)slider->getUserData();
|
|
|
|
|
|
|
|
int step;
|
|
|
|
switch (((puArrowButton *)arrow)->getArrowType()) {
|
|
|
|
case PUARROW_DOWN:
|
|
|
|
step = 1;
|
|
|
|
break;
|
|
|
|
case PUARROW_UP:
|
|
|
|
step = -1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
step = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = list_box->getTopItem();
|
|
|
|
index += step;
|
|
|
|
if (index < 0)
|
|
|
|
index = 0;
|
|
|
|
else if (index >= list_box->getNumItems())
|
|
|
|
index = list_box->getNumItems() - 1;
|
|
|
|
list_box->setTopItem(index);
|
|
|
|
|
|
|
|
slider->setValue(1.0f - float(index)/list_box->getNumItems());
|
|
|
|
}
|
|
|
|
|
|
|
|
puList::puList (int x, int y, int w, int h)
|
|
|
|
: puGroup(x, y)
|
|
|
|
{
|
2005-01-31 10:36:59 +00:00
|
|
|
type |= PUCLASS_LIST;
|
2003-11-27 23:41:00 +00:00
|
|
|
init(w, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
puList::puList (int x, int y, int w, int h, char ** contents)
|
|
|
|
: puGroup(x, y)
|
|
|
|
{
|
2005-01-31 10:36:59 +00:00
|
|
|
type |= PUCLASS_LIST;
|
2003-11-27 23:41:00 +00:00
|
|
|
init(w, h);
|
|
|
|
newList(contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
puList::~puList ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puList::newList (char ** contents)
|
|
|
|
{
|
|
|
|
_list_box->newList(contents);
|
|
|
|
_contents = contents;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2005-01-31 10:36:59 +00:00
|
|
|
puList::getListStringValue ()
|
2003-11-27 23:41:00 +00:00
|
|
|
{
|
2006-03-22 10:56:49 +00:00
|
|
|
int i = _list_box->getIntegerValue();
|
|
|
|
return i < 0 ? 0 : _contents[i];
|
2003-11-27 23:41:00 +00:00
|
|
|
}
|
|
|
|
|
2005-01-31 10:36:59 +00:00
|
|
|
int
|
|
|
|
puList::getListIntegerValue()
|
|
|
|
{
|
|
|
|
return _list_box->getIntegerValue();
|
|
|
|
}
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
void
|
|
|
|
puList::init (int w, int h)
|
|
|
|
{
|
2006-03-23 19:51:38 +00:00
|
|
|
const int sw = 20;
|
2003-11-27 23:41:00 +00:00
|
|
|
_frame = new puFrame(0, 0, w, h);
|
|
|
|
|
2006-03-23 19:51:38 +00:00
|
|
|
_list_box = new puListBox(0, 0, w-sw, h);
|
2003-11-27 23:41:00 +00:00
|
|
|
_list_box->setStyle(-PUSTYLE_SMALL_SHADED);
|
|
|
|
_list_box->setUserData(this);
|
2006-03-23 19:03:31 +00:00
|
|
|
_list_box->setCallback(handle_list_entry);
|
2003-11-27 23:41:00 +00:00
|
|
|
_list_box->setValue(0);
|
|
|
|
|
2006-03-23 19:51:38 +00:00
|
|
|
_slider = new puSlider(w-sw, sw, h-2*sw, true, sw);
|
2003-11-27 23:41:00 +00:00
|
|
|
_slider->setValue(1.0f);
|
|
|
|
_slider->setUserData(_list_box);
|
|
|
|
_slider->setCallback(handle_slider);
|
|
|
|
_slider->setCBMode(PUSLIDER_ALWAYS);
|
|
|
|
|
2006-03-23 19:51:38 +00:00
|
|
|
_down_arrow = new puArrowButton(w-sw, 0, w, sw, PUARROW_DOWN) ;
|
2003-11-27 23:41:00 +00:00
|
|
|
_down_arrow->setUserData(_slider);
|
|
|
|
_down_arrow->setCallback(handle_arrow);
|
|
|
|
|
2006-03-23 19:51:38 +00:00
|
|
|
_up_arrow = new puArrowButton(w-sw, h-sw, w, h, PUARROW_UP);
|
2003-11-27 23:41:00 +00:00
|
|
|
_up_arrow->setUserData(_slider);
|
|
|
|
_up_arrow->setCallback(handle_arrow);
|
|
|
|
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2006-03-23 17:44:10 +00:00
|
|
|
void
|
|
|
|
puList::setColourScheme (float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
puObject::setColourScheme(r, g, b, a);
|
|
|
|
_list_box->setColourScheme(r, g, b, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
puList::setColour (int which, float r, float g, float b, float a)
|
|
|
|
{
|
|
|
|
puObject::setColour(which, r, g, b, a);
|
|
|
|
_list_box->setColour(which, r, g, b, a);
|
|
|
|
}
|
|
|
|
|
2003-11-27 23:41:00 +00:00
|
|
|
// end of puList.cxx
|