1
0
Fork 0

- require plib 1.8.5

- switch puList to puaList
- drop src/GUI/puList.[ch]xx
- remove #ifdefs, FIXMEs, and workarounds that have accumulated over time
- warnings--
This commit is contained in:
mfranz 2008-03-11 15:58:57 +00:00
parent f375f649c1
commit 2100394117
11 changed files with 21 additions and 318 deletions

View file

@ -464,11 +464,11 @@ if test "x$ac_cv_header_plib_ul_h" != "xyes"; then
exit
fi
AC_MSG_CHECKING([for plib 1.8.4 or newer])
AC_MSG_CHECKING([for plib 1.8.5 or newer])
AC_TRY_RUN([
#include <plib/ul.h>
#define MIN_PLIB_VERSION 184
#define MIN_PLIB_VERSION 185
int main() {
int major, minor, micro;
@ -483,7 +483,7 @@ int main() {
],
AC_MSG_RESULT(yes),
[AC_MSG_RESULT(wrong version);
AC_MSG_ERROR([Install plib 1.8.4 or later first...])],
AC_MSG_ERROR([Install plib 1.8.5 or later first...])],
AC_MSG_RESULT(yes)
)

View file

@ -6,7 +6,7 @@
AirportList::AirportList (int x, int y, int width, int height)
: puList(x, y, width, height),
: puaList(x, y, width, height),
GUI_ID(FGCLASS_AIRPORTLIST),
_airports(globals->get_airports()),
_content(0)
@ -57,13 +57,6 @@ AirportList::destroy_list ()
delete [] _content;
}
char *
AirportList::getListStringValue ()
{
int i = getListIntegerValue();
return i < 0 ? 0 : _content[i];
}
void
AirportList::setValue (const char *s)
{

View file

@ -6,15 +6,16 @@
#include <simgear/compiler.h>
#include STL_STRING
#include <plib/pu.h>
#include <plib/puAux.h>
#include "dialog.hxx"
SG_USING_STD(string);
class FGAirportList;
class AirportList : public puList, public GUI_ID
class AirportList : public puaList, public GUI_ID
{
public:
AirportList (int x, int y, int width, int height);
@ -22,9 +23,6 @@ class AirportList : public puList, public GUI_ID
virtual void create_list();
virtual void destroy_list();
// FIXME: add other string value functions
virtual char * getListStringValue ();
virtual void setValue (const char *);
private:

View file

@ -10,7 +10,6 @@ libGUI_a_SOURCES = \
mouse.cxx fonts.cxx \
sgVec3Slider.cxx sgVec3Slider.hxx \
trackball.c trackball.h \
puList.cxx puList.hxx \
AirportList.cxx AirportList.hxx \
property_list.cxx property_list.hxx \
layout.cxx layout-props.cxx layout.hxx

View file

@ -327,17 +327,9 @@ copy_from_pui (puObject * object, SGPropertyNode * node)
node->setFloatValue(object->getFloatValue());
break;
default:
// Special case to handle lists, as getStringValue cannot be overridden
if(object->getType() & PUCLASS_LIST)
{
const char *s = ((puList *) object)->getListStringValue();
if (s)
node->setStringValue(s);
}
else
{
node->setStringValue(object->getStringValue());
}
const char *s = object->getStringValue();
if (s)
node->setStringValue(s);
break;
}
}
@ -642,11 +634,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
fgComboBox * obj = new fgComboBox(x, y, x + width, y + height, props,
props->getBoolValue("editable", false));
setupObject(obj, props);
#ifdef PUCOL_EDITFIELD // plib > 0.8.4
setColor(obj, props, EDITFIELD);
#else
setColor(obj, props, FOREGROUND|LABEL);
#endif
return obj;
} else if (type == "slider") {
@ -690,11 +678,7 @@ FGDialog::makeObject (SGPropertyNode * props, int parentWidth, int parentHeight)
} else if (type == "select") {
fgSelectBox * obj = new fgSelectBox(x, y, x + width, y + height, props);
setupObject(obj, props);
#ifdef PUCOL_EDITFIELD // plib > 0.8.4
setColor(obj, props, EDITFIELD);
#else
setColor(obj, props, FOREGROUND|LABEL);
#endif
return obj;
} else {
return 0;
@ -831,9 +815,7 @@ FGDialog::setColor(puObject * object, SGPropertyNode * props, int which)
{ LABEL, PUCOL_LABEL, "label", "color-label" },
{ LEGEND, PUCOL_LEGEND, "legend", "color-legend" },
{ MISC, PUCOL_MISC, "misc", "color-misc" },
#ifdef PUCOL_EDITFIELD // plib > 0.8.4
{ EDITFIELD, PUCOL_EDITFIELD, "editfield", "color-editfield" },
#endif
};
const int numcol = sizeof(pucol) / sizeof(pucol[0]);
@ -1019,7 +1001,9 @@ void
fgList::update()
{
fgValueList::update();
int top = getTopItem();
newList(_list);
setTopItem(top);
}
// end of dialog.cxx

View file

@ -14,14 +14,11 @@
#include <simgear/props/props.hxx>
#include <simgear/misc/sg_path.hxx>
#undef PUCLASS_LIST
#include "puList.hxx"
#include <vector>
SG_USING_STD(vector);
// ugly temproary workaround for plib's lack of user defined class ids FIXME
// ugly temporary workaround for plib's lack of user defined class ids FIXME
#define FGCLASS_LIST 0x00000001
#define FGCLASS_AIRPORTLIST 0x00000002
#define FGCLASS_PROPERTYLIST 0x00000004
@ -207,10 +204,10 @@ private:
};
class fgList : public fgValueList, public puList, public GUI_ID {
class fgList : public fgValueList, public puaList, public GUI_ID {
public:
fgList(int x1, int y1, int x2, int y2, SGPropertyNode *p, int sw) :
fgValueList(p), puList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
fgValueList(p), puaList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
void update();
};

View file

@ -393,7 +393,7 @@ FGColor::merge(const FGColor *color)
////////////////////////////////////////////////////////////////////////
static const struct {
char *name;
const char *name;
puFont *font;
} guifonts[] = {
{ "default", &FONT_HELVETICA_14 },

View file

@ -143,7 +143,7 @@ static void sanitize(stdString& s)
PropertyList::PropertyList(int minx, int miny, int maxx, int maxy, SGPropertyNode *start) :
puList(minx, miny, maxx, maxy, short(0), 20),
puaList(minx, miny, maxx, maxy, short(0), 20),
GUI_ID(FGCLASS_PROPERTYLIST),
_curr(start),
_return(0),

View file

@ -24,13 +24,12 @@
#define _PROPERTY_LIST_HXX
#include <plib/pu.h>
#include <plib/puAux.h>
#include <simgear/props/props.hxx>
#include "dialog.hxx"
#include "puList.hxx"
class PropertyList : public puList, public SGPropertyChangeListener, public GUI_ID {
class PropertyList : public puaList, public SGPropertyChangeListener, public GUI_ID {
public:
PropertyList(int minx, int miny, int maxx, int maxy, SGPropertyNode *);
~PropertyList();
@ -42,8 +41,8 @@ public:
void toggleVerbosity() { _verbose = !_verbose; }
// overridden plib pui methods
virtual char *getListStringValue() { return (char *)(_return ? _return->getPath(true) : ""); }
//virtual char *getStringValue(void) { return (char *)(_return ? _return->getPath(true) : ""); }
virtual char *getStringValue(void) { return (char *)(_return ? _return->getPath(true) : ""); }
//virtual char *getListStringValue() { return (char *)(_return ? _return->getPath(true) : ""); }
virtual void setValue(const char *);
// listener method

View file

@ -1,212 +0,0 @@
// 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 total = box->getNumItems();
int visible = box->getNumVisible();
// negative numbers are OK -- setTopItem() clamps anyway
int index = int((total - visible) * (1.0 - slider->getFloatValue()));
box->setTopItem(index);
}
/**
* Static function: handle list entry clicks.
*/
static void
handle_list_entry (puObject * listbox)
{
puListBox * box = (puListBox *)listbox->getUserData();
box->invokeCallback();
}
/**
* Static function: handle arrow clicks.
*/
static void
handle_arrow (puObject * arrow)
{
puSlider * slider = (puSlider *)arrow->getUserData();
puListBox * list_box = (puListBox *)slider->getUserData();
puList * list = (puList *)list_box->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->getTopItem();
list->setTopItem(index + step);
slider->setValue(1.0f - float(list->getTopItem()) / (list->getNumItems() - list->getNumVisible()));
}
puList::puList (int x, int y, int w, int h, int sl_width)
: puGroup(x, y),
_sw(sl_width)
{
type |= PUCLASS_LIST;
init(w, h, 1);
}
puList::puList (int x, int y, int w, int h, char ** contents, int sl_width)
: puGroup(x, y),
_sw(sl_width)
{
type |= PUCLASS_LIST;
init(w, h, 1);
newList(contents);
}
puList::~puList ()
{
}
void
puList::newList (char ** contents)
{
_list_box->newList(contents);
_contents = contents;
// new size calculation to consider slider visibility
setSize(_width, _height);
}
void
puList::setTopItem( int top )
{
int visible = _list_box->getNumVisible();
int num = _list_box->getNumItems();
if ( top < 0 || num <= visible )
top = 0 ;
else if ( num > 0 && top > num-visible )
top = num-visible;
_list_box->setTopItem(top);
top = _list_box->getTopItem();
// read clamped value back in, and only set slider if it doesn't match the new
// index to avoid jumps
int slider_index = int((1.0f - _slider->getFloatValue()) * (getNumItems() - getNumVisible()));
if (slider_index != top)
_slider->setValue(1.0f - float(getTopItem()) / (getNumItems() - getNumVisible()));
}
char *
puList::getListStringValue ()
{
int i = _list_box->getIntegerValue();
return i < 0 ? 0 : _contents[i];
}
int
puList::getListIntegerValue()
{
return _list_box->getIntegerValue();
}
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);
}
void
puList::setSize (int w, int h)
{
_width = w;
_height = h;
puObject::setSize(w, h);
if (_frame)
_frame->setSize(w, h);
int total = _list_box->getNumItems();
int visible = _list_box->getNumVisible();
if (total > visible)
{
if (!_slider->isVisible())
{
_slider->setValue(1.0f);
_slider->reveal();
_up_arrow->reveal();
_down_arrow->reveal();
}
_list_box->setSize(w-_sw, h);
_slider->setPosition(w-_sw, _sw);
_slider->setSize(_sw, h-2*_sw);
_slider->setSliderFraction(float(visible) / total);
_down_arrow->setPosition(w-_sw, 0);
_up_arrow->setPosition(w-_sw, h-_sw);
}
else
{
if (_slider->isVisible())
{
_slider->hide();
_up_arrow->hide();
_down_arrow->hide();
}
_list_box->setSize(w, h);
}
}
void
puList::init (int w, int h, short transparent)
{
if ( transparent )
_frame = NULL ;
else
_frame = new puFrame(0, 0, w, h);
_list_box = new puListBox(0, 0, w-_sw, h);
_list_box->setStyle(-PUSTYLE_SMALL_SHADED);
_list_box->setUserData(this);
_list_box->setCallback(handle_list_entry);
_list_box->setValue(0);
_slider = new puSlider(w-_sw, _sw, h-2*_sw, true, _sw);
_slider->setValue(1.0f);
_slider->setUserData(_list_box);
_slider->setCallback(handle_slider);
_slider->setCBMode(PUSLIDER_ALWAYS);
_down_arrow = new puArrowButton(w-_sw, 0, w, _sw, PUARROW_DOWN) ;
_down_arrow->setUserData(_slider);
_down_arrow->setCallback(handle_arrow);
_up_arrow = new puArrowButton(w-_sw, h-_sw, w, h, PUARROW_UP);
_up_arrow->setUserData(_slider);
_up_arrow->setCallback(handle_arrow);
setSize(w, h);
close();
}
// end of puList.cxx

View file

@ -1,55 +0,0 @@
// puList.hxx - a scrolling PUI list box.
#ifndef __PULIST_HXX
#define __PULIST_HXX 1
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <plib/pu.h>
# define PUCLASS_LIST 0x80000000 // Hopefully this value will never be used by plib
/**
* A scrolling list for PUI.
*
* Believe it or not, PUI does not have one of these.
*/
class puList : public puGroup
{
char ** _contents;
puFrame * _frame;
puSlider * _slider;
puArrowButton * _up_arrow;
puArrowButton * _down_arrow;
int _style;
int _sw; // slider width
int _width, _height;
protected:
virtual void init (int w, int h, short transparent);
puListBox * _list_box;
public:
puList (int x, int y, int w, int h, int sl_width = 20);
puList (int x, int y, int w, int h, char ** contents, int sl_width = 20);
virtual ~puList ();
virtual void newList (char ** contents);
// TODO: other string value funcs
virtual char * getListStringValue ();
virtual int getListIntegerValue();
virtual void setColourScheme (float r, float g, float b, float a);
virtual void setColour (int which, float r, float g, float b, float a);
virtual void setSize (int w, int h);
int getNumVisible ( void ) const { return _list_box->getNumVisible(); }
int getNumItems ( void ) const { return _list_box->getNumItems(); }
int getTopItem ( void ) const { return _list_box->getTopItem(); }
void setTopItem (int index);
};
#endif // __PULIST_HXX