1
0
Fork 0

- added support for conditions

- added support for group layers
This commit is contained in:
curt 2001-08-03 00:17:58 +00:00
parent 17c781a870
commit b077c3a8a0
2 changed files with 174 additions and 83 deletions

View file

@ -48,6 +48,11 @@
#define WIN_W 1024 #define WIN_W 1024
#define WIN_H 768 #define WIN_H 768
#ifdef NONE
#pragma warn A sloppy coder has defined NONE as a macro!!!
#undef NONE
#endif
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -460,11 +465,13 @@ FGPanelAction::addBinding (const FGBinding &binding)
void void
FGPanelAction::doAction () FGPanelAction::doAction ()
{ {
if (test()) {
int nBindings = _bindings.size(); int nBindings = _bindings.size();
for (int i = 0; i < nBindings; i++) { for (int i = 0; i < nBindings; i++) {
_bindings[i].fire(); _bindings[i].fire();
} }
} }
}
@ -558,6 +565,7 @@ FGPanelInstrument::addAction (FGPanelAction * action)
bool bool
FGPanelInstrument::doMouseAction (int button, int x, int y) FGPanelInstrument::doMouseAction (int button, int x, int y)
{ {
if (test()) {
action_list_type::iterator it = _actions.begin(); action_list_type::iterator it = _actions.begin();
action_list_type::iterator last = _actions.end(); action_list_type::iterator last = _actions.end();
for ( ; it != last; it++) { for ( ; it != last; it++) {
@ -566,6 +574,7 @@ FGPanelInstrument::doMouseAction (int button, int x, int y)
return true; return true;
} }
} }
}
return false; return false;
} }
@ -591,6 +600,7 @@ FGLayeredInstrument::~FGLayeredInstrument ()
void void
FGLayeredInstrument::draw () FGLayeredInstrument::draw ()
{ {
if (test()) {
for (int i = 0; i < (int)_layers.size(); i++) { for (int i = 0; i < (int)_layers.size(); i++) {
glPushMatrix(); glPushMatrix();
glTranslatef(0.0, 0.0, (i / 100.0) + 0.1); glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
@ -598,6 +608,7 @@ FGLayeredInstrument::draw ()
glPopMatrix(); glPopMatrix();
} }
} }
}
int int
FGLayeredInstrument::addLayer (FGInstrumentLayer *layer) FGLayeredInstrument::addLayer (FGInstrumentLayer *layer)
@ -656,6 +667,7 @@ FGInstrumentLayer::transform () const
transformation_list::const_iterator last = _transformations.end(); transformation_list::const_iterator last = _transformations.end();
while (it != last) { while (it != last) {
FGPanelTransformation *t = *it; FGPanelTransformation *t = *it;
if (t->test()) {
float val = (t->node == 0 ? 0.0 : t->node->getFloatValue()); float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
if (val < t->min) { if (val < t->min) {
val = t->min; val = t->min;
@ -679,6 +691,7 @@ FGInstrumentLayer::transform () const
glRotatef(-val, 0.0, 0.0, 1.0); glRotatef(-val, 0.0, 0.0, 1.0);
break; break;
} }
}
it++; it++;
} }
} }
@ -690,6 +703,38 @@ FGInstrumentLayer::addTransformation (FGPanelTransformation * transformation)
} }
////////////////////////////////////////////////////////////////////////
// Implementation of FGGroupLayer.
////////////////////////////////////////////////////////////////////////
FGGroupLayer::FGGroupLayer ()
{
}
FGGroupLayer::~FGGroupLayer ()
{
for (int i = 0; i < _layers.size(); i++)
delete _layers[i];
}
void
FGGroupLayer::draw ()
{
if (test()) {
int nLayers = _layers.size();
for (int i = 0; i < nLayers; i++)
_layers[i]->draw();
}
}
void
FGGroupLayer::addLayer (FGInstrumentLayer * layer)
{
_layers.push_back(layer);
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Implementation of FGTexturedLayer. // Implementation of FGTexturedLayer.
@ -711,6 +756,7 @@ FGTexturedLayer::~FGTexturedLayer ()
void void
FGTexturedLayer::draw () FGTexturedLayer::draw ()
{ {
if (test()) {
int w2 = _w / 2; int w2 = _w / 2;
int h2 = _h / 2; int h2 = _h / 2;
@ -733,6 +779,7 @@ FGTexturedLayer::draw ()
glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2); glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
glEnd(); glEnd();
} }
}
@ -760,6 +807,7 @@ FGTextLayer::~FGTextLayer ()
void void
FGTextLayer::draw () FGTextLayer::draw ()
{ {
if (test()) {
glPushMatrix(); glPushMatrix();
glColor4fv(_color); glColor4fv(_color);
transform(); transform();
@ -779,6 +827,7 @@ FGTextLayer::draw ()
glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
glPopMatrix(); glPopMatrix();
} }
}
void void
FGTextLayer::addChunk (FGTextLayer::Chunk * chunk) FGTextLayer::addChunk (FGTextLayer::Chunk * chunk)
@ -849,6 +898,7 @@ FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
const char * const char *
FGTextLayer::Chunk::getValue () const FGTextLayer::Chunk::getValue () const
{ {
if (test()) {
switch (_type) { switch (_type) {
case TEXT: case TEXT:
sprintf(_buf, _fmt.c_str(), _text.c_str()); sprintf(_buf, _fmt.c_str(), _text.c_str());
@ -861,6 +911,9 @@ FGTextLayer::Chunk::getValue () const
break; break;
} }
return _buf; return _buf;
} else {
return "";
}
} }
@ -885,6 +938,7 @@ FGSwitchLayer::~FGSwitchLayer ()
void void
FGSwitchLayer::draw () FGSwitchLayer::draw ()
{ {
if (test()) {
transform(); transform();
if (_node->getBoolValue()) { if (_node->getBoolValue()) {
_layer1->draw(); _layer1->draw();
@ -892,6 +946,7 @@ FGSwitchLayer::draw ()
_layer2->draw(); _layer2->draw();
} }
} }
}
// end of panel.cxx // end of panel.cxx

View file

@ -184,6 +184,24 @@ readTexture (const SGPropertyNode * node)
} }
/**
* Test for a condition in the current node.
*/
////////////////////////////////////////////////////////////////////////
// Read a condition and use it if necessary.
////////////////////////////////////////////////////////////////////////
static void
readConditions (FGConditional * component, const SGPropertyNode * node)
{
const SGPropertyNode * conditionNode = node->getChild("condition");
if (conditionNode != 0)
// The top level is implicitly AND
component->setCondition(fgReadCondition(conditionNode));
}
/** /**
* Read an action from the instrument's property list. * Read an action from the instrument's property list.
* *
@ -230,6 +248,7 @@ readAction (const SGPropertyNode * node, float w_scale, float h_scale)
action->addBinding(FGBinding(bindings[i])); // TODO: allow modifiers action->addBinding(FGBinding(bindings[i])); // TODO: allow modifiers
} }
readConditions(action, node);
return action; return action;
} }
@ -340,6 +359,7 @@ readTransformation (const SGPropertyNode * node, float w_scale, float h_scale)
return 0; return 0;
} }
readConditions(t, node);
SG_LOG( SG_COCKPIT, SG_DEBUG, "Read transformation " << name ); SG_LOG( SG_COCKPIT, SG_DEBUG, "Read transformation " << name );
return t; return t;
} }
@ -405,6 +425,7 @@ readTextChunk (const SGPropertyNode * node)
return 0; return 0;
} }
readConditions(chunk, node);
return chunk; return chunk;
} }
@ -458,6 +479,19 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
layer = new FGTexturedLayer(texture, w, h); layer = new FGTexturedLayer(texture, w, h);
} }
// A group of sublayers.
else if (type == "group") {
layer = new FGGroupLayer();
for (int i = 0; i < node->nChildren(); i++) {
const SGPropertyNode * child = node->getChild(i);
cerr << "Trying child " << child->getName() << endl;
if (child->getName() == "layer") {
cerr << "succeeded!" << endl;
((FGGroupLayer *)layer)->addLayer(readLayer(child, w_scale, h_scale));
}
}
}
// A textual instrument layer. // A textual instrument layer.
else if (type == "text") { else if (type == "text") {
@ -552,6 +586,7 @@ readLayer (const SGPropertyNode * node, float w_scale, float h_scale)
} }
} }
readConditions(layer, node);
SG_LOG( SG_COCKPIT, SG_DEBUG, "Read layer " << name ); SG_LOG( SG_COCKPIT, SG_DEBUG, "Read layer " << name );
return layer; return layer;
} }
@ -639,6 +674,7 @@ readInstrument (const SGPropertyNode * node)
} }
} }
readConditions(instrument, node);
SG_LOG( SG_COCKPIT, SG_DEBUG, "Done reading instrument " << name ); SG_LOG( SG_COCKPIT, SG_DEBUG, "Done reading instrument " << name );
return instrument; return instrument;
} }