1
0
Fork 0

Maintenance: FGPUIDialog

Inconsistent whitespace.
This commit is contained in:
Scott Giese 2021-02-26 21:09:13 -06:00
parent a3c4dcf522
commit cc2336c5fa
2 changed files with 568 additions and 585 deletions

View file

@ -4,30 +4,35 @@
#include "config.h"
#endif
#include <simgear/structure/SGBinding.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/debug/BufferedLogCallback.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/scene/tsync/terrasync.hxx>
#include <simgear/structure/SGBinding.hxx>
#include <Scripting/NasalSys.hxx>
#include <Main/fg_os.hxx>
#include <Main/globals.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include <Scripting/NasalSys.hxx>
#include "FGPUIDialog.hxx"
#include "new_gui.hxx"
#include "AirportList.hxx"
#include "property_list.hxx"
#include "layout.hxx"
#include "WaypointList.hxx"
#include "CanvasWidget.hxx"
#include "MapWidget.hxx"
#include "FGFontCache.hxx"
#include "FGColor.hxx"
#include "FGFontCache.hxx"
#include "FGPUIDialog.hxx"
#include "MapWidget.hxx"
#include "WaypointList.hxx"
#include "layout.hxx"
#include "new_gui.hxx"
#include "property_list.hxx"
using std::string;
enum format_type { f_INVALID, f_INT, f_LONG, f_FLOAT, f_DOUBLE, f_STRING };
enum format_type { f_INVALID,
f_INT,
f_LONG,
f_FLOAT,
f_DOUBLE,
f_STRING };
static const int FORMAT_BUFSIZE = 255;
static const int RESIZE_MARGIN = 7;
@ -99,10 +104,10 @@ validate_format(const char *f)
// "non-modal dragability" here. Modal dialog boxes (like the exit
// confirmation) are not draggable.
//
class fgPopup : public puPopup {
class fgPopup : public puPopup
{
public:
fgPopup(FGPUIDialog *parent_dialog, int x, int y, bool r = true, bool d = true) :
puPopup(x, y), _draggable(d), parentDialog(parent_dialog), _resizable(r), _dragging(false)
fgPopup(FGPUIDialog* parent_dialog, int x, int y, bool r = true, bool d = true) : puPopup(x, y), _draggable(d), parentDialog(parent_dialog), _resizable(r), _dragging(false)
{
propCurrentDialog = fgGetNode("/sim/gui/dialogs/current-dialog", true);
}
@ -113,8 +118,12 @@ public:
puObject* getKeyObject(puObject*, int key);
puObject* getActiveInputField(puObject*);
void applySize(puObject*);
private:
enum { LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 };
enum { LEFT = 1,
RIGHT = 2,
TOP = 4,
BOTTOM = 8 };
bool _draggable;
SGPropertyNode_ptr propCurrentDialog;
FGPUIDialog* parentDialog;
@ -128,7 +137,8 @@ private:
};
class fgValueList {
class fgValueList
{
public:
fgValueList(SGPropertyNode* p);
virtual ~fgValueList();
@ -144,20 +154,21 @@ private:
};
class fgList : public fgValueList, public puaList, 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), puaList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
fgList(int x1, int y1, int x2, int y2, SGPropertyNode* p, int sw) : fgValueList(p), puaList(x1, y1, x2, y2, _list, sw), GUI_ID(FGCLASS_LIST) {}
void update();
};
class fgComboBox : public fgValueList, public puaComboBox {
class fgComboBox : public fgValueList, public puaComboBox
{
public:
fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode *p, bool editable) :
fgValueList(p),
fgComboBox(int x1, int y1, int x2, int y2, SGPropertyNode* p, bool editable) : fgValueList(p),
puaComboBox(x1, y1, x2, y2, _list, editable),
_inHit(false)
{}
{
}
void update();
@ -166,14 +177,15 @@ public:
virtual int checkHit(int b, int up, int x, int y);
virtual void recalc_bbox();
private:
bool _inHit;
};
class LogList : public puaList, public FGPUIDialog::ActiveWidget, public GUI_ID {
class LogList : public puaList, public FGPUIDialog::ActiveWidget, public GUI_ID
{
public:
LogList(int x1, int y1, int x2, int y2, int sw) :
puaList(x1, y1, x2, y2, sw),
LogList(int x1, int y1, int x2, int y2, int sw) : puaList(x1, y1, x2, y2, sw),
GUI_ID(FGCLASS_LOGLIST)
{
m_buffer = NULL;
@ -183,16 +195,17 @@ public:
void setBuffer(simgear::BufferedLogCallback* buf);
virtual void update();
private:
std::vector<unsigned char*> m_items;
simgear::BufferedLogCallback* m_buffer;
unsigned int m_stamp;
};
class fgSelectBox : public fgValueList, public puaSelectBox {
class fgSelectBox : public fgValueList, public puaSelectBox
{
public:
fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode *p) :
fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
fgSelectBox(int x1, int y1, int x2, int y2, SGPropertyNode* p) : fgValueList(p), puaSelectBox(x1, y1, x2, y2, _list) {}
};
////////////////////////////////////////////////////////////////////////
@ -202,8 +215,7 @@ public:
/**
* User data for a GUI object.
*/
struct GUIInfo
{
struct GUIInfo {
GUIInfo(FGPUIDialog* d);
virtual ~GUIInfo();
void apply_format(SGPropertyNode*);
@ -216,8 +228,7 @@ struct GUIInfo
format_type fmt_type;
};
GUIInfo::GUIInfo (FGPUIDialog *d) :
dialog(d),
GUIInfo::GUIInfo(FGPUIDialog* d) : dialog(d),
key(-1),
fmt_type(f_INVALID)
{
@ -301,8 +312,7 @@ puObject *fgPopup::getActiveInputField(puObject *object)
if ((ret = getActiveInputField(obj)))
return ret;
if (object->getType() & (PUCLASS_INPUT|PUCLASS_LARGEINPUT)
&& ((puInput *)object)->isAcceptingInput())
if (object->getType() & (PUCLASS_INPUT | PUCLASS_LARGEINPUT) && ((puInput*)object)->isAcceptingInput())
return object;
return 0;
@ -342,14 +352,10 @@ int fgPopup::checkHit(int button, int updown, int x, int y)
int hit = getHitObjects(this, x, y);
if (hit & PUCLASS_LIST) // ctrl-click in property browser (toggle bool)
return result;
if( !global_resize
&& ( (hit & (PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
|PUCLASS_LARGEINPUT|PUCLASS_SCROLLBAR))
if (!global_resize && ((hit & (PUCLASS_BUTTON | PUCLASS_ONESHOT | PUCLASS_INPUT | PUCLASS_LARGEINPUT | PUCLASS_SCROLLBAR))
// The canvas should handle drag events on its own so exit
// here if mouse is over a CanvasWidget
|| (!global_drag && checkHitCanvas(this, x, y))
) )
{
|| (!global_drag && checkHitCanvas(this, x, y)))) {
return result;
}
@ -362,9 +368,18 @@ int fgPopup::checkHit(int button, int updown, int x, int y)
// check and prepare for resizing
static const int cursor[] = {
MOUSE_CURSOR_POINTER, MOUSE_CURSOR_LEFTSIDE, MOUSE_CURSOR_RIGHTSIDE, 0,
MOUSE_CURSOR_TOPSIDE, MOUSE_CURSOR_TOPLEFT, MOUSE_CURSOR_TOPRIGHT, 0,
MOUSE_CURSOR_BOTTOMSIDE, MOUSE_CURSOR_BOTTOMLEFT, MOUSE_CURSOR_BOTTOMRIGHT, 0,
MOUSE_CURSOR_POINTER,
MOUSE_CURSOR_LEFTSIDE,
MOUSE_CURSOR_RIGHTSIDE,
0,
MOUSE_CURSOR_TOPSIDE,
MOUSE_CURSOR_TOPLEFT,
MOUSE_CURSOR_TOPRIGHT,
0,
MOUSE_CURSOR_BOTTOMSIDE,
MOUSE_CURSOR_BOTTOMLEFT,
MOUSE_CURSOR_BOTTOMRIGHT,
0,
};
_resizing = 0;
@ -469,12 +484,10 @@ bool fgPopup::checkHitCanvas(puObject* object, int x, int y)
if (!object->isVisible())
return 0;
if( object->getType() & PUCLASS_GROUP )
{
if (object->getType() & PUCLASS_GROUP) {
for (puObject* obj = ((puGroup*)object)->getFirstChild();
obj;
obj = obj->getNextObject() )
{
obj = obj->getNextObject()) {
if (checkHitCanvas(obj, x, y))
return true;
}
@ -483,9 +496,7 @@ bool fgPopup::checkHitCanvas(puObject* object, int x, int y)
int cx, cy, cw, ch;
object->getAbsolutePosition(&cx, &cy);
object->getSize(&cw, &ch);
if( x >= cx && x < cx + cw
&& y >= cy && y < cy + ch
&& dynamic_cast<CanvasWidget*>(object) )
if (x >= cx && x < cx + cw && y >= cy && y < cy + ch && dynamic_cast<CanvasWidget*>(object))
return true;
return false;
}
@ -494,9 +505,7 @@ void fgPopup::applySize(puObject *object)
{
// compound plib widgets use setUserData() for internal purposes, so refuse
// to descend into anything that has other bits set than the following
const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE
|PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
|PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP;
const int validUserData = PUCLASS_VALUE | PUCLASS_OBJECT | PUCLASS_GROUP | PUCLASS_INTERFACE | PUCLASS_FRAME | PUCLASS_TEXT | PUCLASS_BUTTON | PUCLASS_ONESHOT | PUCLASS_INPUT | PUCLASS_ARROW | PUCLASS_DIAL | PUCLASS_POPUP;
int type = object->getType();
if (type & PUCLASS_GROUP && !(type & ~validUserData))
@ -642,8 +651,7 @@ copy_from_pui (puObject *object, SGPropertyNode *node)
case props::FLOAT:
node->setFloatValue(object->getFloatValue());
break;
case props::DOUBLE:
{
case props::DOUBLE: {
// puObject only provides float, not double, which causes precision/rounding issues
// with some numerical values (try "114.2").
// Work around: obtain string value, and manually convert with proper double precision.
@ -664,8 +672,7 @@ copy_from_pui (puObject *object, SGPropertyNode *node)
// Implementation of FGDialog.
////////////////////////////////////////////////////////////////////////
FGPUIDialog::FGPUIDialog (SGPropertyNode *props) :
FGDialog(props),
FGPUIDialog::FGPUIDialog(SGPropertyNode* props) : FGDialog(props),
_object(nullptr),
_gui(globals->get_subsystem<NewGUI>()),
_props(props),
@ -719,7 +726,8 @@ FGPUIDialog::~FGPUIDialog ()
}
}
void FGPUIDialog::bringToFront() {
void FGPUIDialog::bringToFront()
{
puMoveToLast(_object);
}
const char* FGPUIDialog::getName()
@ -727,8 +735,7 @@ const char *FGPUIDialog::getName()
return _name.c_str();
}
void
FGPUIDialog::updateValues(const std::string& objectName)
void FGPUIDialog::updateValues(const std::string& objectName)
{
for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
const string& name = _propertyObjects[i]->name;
@ -755,8 +762,7 @@ FGPUIDialog::updateValues(const std::string& objectName)
} // of property objects iteration
}
void
FGPUIDialog::applyValues(const std::string& objectName)
void FGPUIDialog::applyValues(const std::string& objectName)
{
for (unsigned int i = 0; i < _propertyObjects.size(); i++) {
const string& name = _propertyObjects[i]->name;
@ -768,8 +774,7 @@ FGPUIDialog::applyValues(const std::string& objectName)
}
}
void
FGPUIDialog::update ()
void FGPUIDialog::update()
{
for (unsigned int i = 0; i < _liveObjects.size(); i++) {
puObject* obj = _liveObjects[i]->object;
@ -792,8 +797,7 @@ FGPUIDialog::update ()
}
}
void
FGPUIDialog::display (SGPropertyNode *props)
void FGPUIDialog::display(SGPropertyNode* props)
{
if (_object != 0) {
SG_LOG(SG_GENERAL, SG_ALERT, "This widget is already active");
@ -871,9 +875,7 @@ FGPUIDialog::display (SGPropertyNode *props)
if (_object != 0) {
_object->reveal();
} else {
SG_LOG(SG_GENERAL, SG_ALERT, "Widget "
<< props->getStringValue("name", "[unnamed]")
<< " does not contain a proper GUI definition");
SG_LOG(SG_GENERAL, SG_ALERT, "Widget " << props->getStringValue("name", "[unnamed]") << " does not contain a proper GUI definition");
}
}
@ -1095,8 +1097,7 @@ FGPUIDialog::makeObject (SGPropertyNode *props, int parentWidth, int parentHeigh
}
}
void
FGPUIDialog::setupObject (puObject *object, SGPropertyNode *props)
void FGPUIDialog::setupObject(puObject* object, SGPropertyNode* props)
{
GUIInfo* info = new GUIInfo(this);
object->setUserData(info);
@ -1123,8 +1124,7 @@ FGPUIDialog::setupObject (puObject *object, SGPropertyNode *props)
if (property_node)
nft = globals->get_props()->getNode(property_node->getStringValue());
_font = FGFontCache::instance()->get(nft);
}
else {
} else {
_font = _gui->getDefaultFont();
}
puFont* lfnt = FGFontCache::instance()->get(nft);
@ -1157,8 +1157,7 @@ FGPUIDialog::setupObject (puObject *object, SGPropertyNode *props)
if (info->fmt_type != f_INVALID)
info->format = format;
else
SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '"
<< format << '\'');
SG_LOG(SG_GENERAL, SG_ALERT, "DIALOG: invalid <format> '" << format << '\'');
}
}
@ -1181,8 +1180,6 @@ FGPUIDialog::setupObject (puObject *object, SGPropertyNode *props)
if (props->getBoolValue("live"))
_liveObjects.push_back(po);
}
}
const auto bindings = props->getChildren("binding");
@ -1216,8 +1213,7 @@ FGPUIDialog::setupObject (puObject *object, SGPropertyNode *props)
}
}
void
FGPUIDialog::setupGroup(puGroup *group, SGPropertyNode *props,
void FGPUIDialog::setupGroup(puGroup* group, SGPropertyNode* props,
int width, int height, bool makeFrame)
{
setupObject(group, props);
@ -1230,11 +1226,11 @@ FGPUIDialog::setupGroup(puGroup *group, SGPropertyNode *props,
int nChildren = props->nChildren();
for (int i = 0; i < nChildren; i++)
makeObject(props->getChild(i), width, height);
group->close();
}
void
FGPUIDialog::setColor(puObject *object, SGPropertyNode *props, int which)
void FGPUIDialog::setColor(puObject* object, SGPropertyNode* props, int which)
{
string type = props->getName();
if (type.empty())
@ -1324,8 +1320,7 @@ static struct {
{0, -1},
};
int
FGPUIDialog::getKeyCode(const char *str)
int FGPUIDialog::getKeyCode(const char* str)
{
enum {
CTRL = 0x1,
@ -1436,14 +1431,11 @@ void FGPUIDialog::relayout()
if (!userh) _props->removeChild("height");
}
void
FGPUIDialog::applySize(puObject *object)
void FGPUIDialog::applySize(puObject* object)
{
// compound plib widgets use setUserData() for internal purposes, so refuse
// to descend into anything that has other bits set than the following
const int validUserData = PUCLASS_VALUE|PUCLASS_OBJECT|PUCLASS_GROUP|PUCLASS_INTERFACE
|PUCLASS_FRAME|PUCLASS_TEXT|PUCLASS_BUTTON|PUCLASS_ONESHOT|PUCLASS_INPUT
|PUCLASS_ARROW|PUCLASS_DIAL|PUCLASS_POPUP;
const int validUserData = PUCLASS_VALUE | PUCLASS_OBJECT | PUCLASS_GROUP | PUCLASS_INTERFACE | PUCLASS_FRAME | PUCLASS_TEXT | PUCLASS_BUTTON | PUCLASS_ONESHOT | PUCLASS_INPUT | PUCLASS_ARROW | PUCLASS_DIAL | PUCLASS_POPUP;
int type = object->getType();
if ((type & PUCLASS_GROUP) && !(type & ~validUserData)) {
@ -1476,28 +1468,24 @@ FGPUIDialog::applySize(puObject *object)
////////////////////////////////////////////////////////////////////////
FGPUIDialog::PropertyObject::PropertyObject(const char* n,
puObject *o, SGPropertyNode_ptr p) :
name(n),
puObject* o, SGPropertyNode_ptr p) : name(n),
object(o),
node(p)
{
}
////////////////////////////////////////////////////////////////////////
// Implementation of fgValueList and derived pui widgets
////////////////////////////////////////////////////////////////////////
fgValueList::fgValueList(SGPropertyNode *p) :
_props(p)
fgValueList::fgValueList(SGPropertyNode* p) : _props(p)
{
make_list();
}
void
fgValueList::update()
void fgValueList::update()
{
destroy_list();
make_list();
@ -1508,8 +1496,7 @@ fgValueList::~fgValueList()
destroy_list();
}
void
fgValueList::make_list()
void fgValueList::make_list()
{
SGPropertyNode_ptr values = _props;
const char* vname = "value";
@ -1533,8 +1520,7 @@ fgValueList::make_list()
_list[i] = 0;
}
void
fgValueList::destroy_list()
void fgValueList::destroy_list()
{
for (int i = 0; _list[i] != 0; i++)
if (_list[i])
@ -1543,9 +1529,7 @@ fgValueList::destroy_list()
}
void
fgList::update()
void fgList::update()
{
fgValueList::update();
int top = getTopItem();
@ -1580,7 +1564,6 @@ void LogList::setBuffer(simgear::BufferedLogCallback* buf)
// Implementation of fgComboBox
////////////////////////////////////////////////////////////////////////
void fgComboBox::update()
{
if (_inHit) {
@ -1592,7 +1575,6 @@ void fgComboBox::update()
newList(_list);
int currentItem = puaComboBox::getCurrentItem();
// look for the previous value, in the new list
for (int i = 0; _list[i] != 0; i++) {
if (_list[i] == curValue) {
@ -1649,7 +1631,6 @@ void fgComboBox::recalc_bbox()
abox.max[1] = abox.min[1] + contents.max[1];
puObject::recalc_bbox();
}
// end of FGPUIDialog.cxx

View file

@ -1,15 +1,14 @@
// FGPUIDialog.hxx - XML-configured dialog box.
#ifndef FG_PUI_DIALOG_HXX
#define FG_PUI_DIALOG_HXX 1
#pragma once
#include "dialog.hxx"
#include <plib/puAux.h>
#include <simgear/props/props.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/condition.hxx>
#include <simgear/props/props.hxx>
#include <vector>
@ -21,9 +20,13 @@
#define FGCLASS_WAYPOINTLIST 0x00000008
#define FGCLASS_LOGLIST 0x00000010
class GUI_ID { public: GUI_ID(int id) : id(id) {} virtual ~GUI_ID() {} int id; };
class GUI_ID
{
public:
GUI_ID(int id) : id(id) {}
virtual ~GUI_ID() {}
int id;
};
class NewGUI;
class FGColor;
@ -41,7 +44,6 @@ class puFont;
class FGPUIDialog : public FGDialog
{
public:
/**
* Construct a new GUI widget configured by a property tree.
*
@ -97,7 +99,8 @@ public:
void relayout();
void setNeedsLayout() {
void setNeedsLayout()
{
_needsRelayout = true;
}
virtual const char* getName();
@ -108,8 +111,8 @@ public:
public:
virtual void update() = 0;
};
private:
private:
enum {
BACKGROUND = 0x01,
FOREGROUND = 0x02,
@ -186,10 +189,11 @@ private:
class ConditionalObject : public SGConditional
{
public:
ConditionalObject(const std::string& aName, puObject* aPu) :
_name(aName),
ConditionalObject(const std::string& aName, puObject* aPu) : _name(aName),
_pu(aPu)
{ ; }
{
;
}
void update(FGPUIDialog* aDlg);
@ -203,5 +207,3 @@ private:
std::vector<ActiveWidget*> _activeWidgets;
};
#endif // __DIALOG_HXX