- added support for conditions
- added support for group layers
This commit is contained in:
parent
17c781a870
commit
b077c3a8a0
2 changed files with 174 additions and 83 deletions
|
@ -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,9 +465,11 @@ FGPanelAction::addBinding (const FGBinding &binding)
|
||||||
void
|
void
|
||||||
FGPanelAction::doAction ()
|
FGPanelAction::doAction ()
|
||||||
{
|
{
|
||||||
int nBindings = _bindings.size();
|
if (test()) {
|
||||||
for (int i = 0; i < nBindings; i++) {
|
int nBindings = _bindings.size();
|
||||||
_bindings[i].fire();
|
for (int i = 0; i < nBindings; i++) {
|
||||||
|
_bindings[i].fire();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,12 +565,14 @@ FGPanelInstrument::addAction (FGPanelAction * action)
|
||||||
bool
|
bool
|
||||||
FGPanelInstrument::doMouseAction (int button, int x, int y)
|
FGPanelInstrument::doMouseAction (int button, int x, int y)
|
||||||
{
|
{
|
||||||
action_list_type::iterator it = _actions.begin();
|
if (test()) {
|
||||||
action_list_type::iterator last = _actions.end();
|
action_list_type::iterator it = _actions.begin();
|
||||||
for ( ; it != last; it++) {
|
action_list_type::iterator last = _actions.end();
|
||||||
if ((*it)->inArea(button, x, y)) {
|
for ( ; it != last; it++) {
|
||||||
(*it)->doAction();
|
if ((*it)->inArea(button, x, y)) {
|
||||||
return true;
|
(*it)->doAction();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -591,11 +600,13 @@ FGLayeredInstrument::~FGLayeredInstrument ()
|
||||||
void
|
void
|
||||||
FGLayeredInstrument::draw ()
|
FGLayeredInstrument::draw ()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)_layers.size(); i++) {
|
if (test()) {
|
||||||
glPushMatrix();
|
for (int i = 0; i < (int)_layers.size(); i++) {
|
||||||
glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
|
glPushMatrix();
|
||||||
_layers[i]->draw();
|
glTranslatef(0.0, 0.0, (i / 100.0) + 0.1);
|
||||||
glPopMatrix();
|
_layers[i]->draw();
|
||||||
|
glPopMatrix();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -656,28 +667,30 @@ 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;
|
||||||
float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
|
if (t->test()) {
|
||||||
if (val < t->min) {
|
float val = (t->node == 0 ? 0.0 : t->node->getFloatValue());
|
||||||
val = t->min;
|
if (val < t->min) {
|
||||||
} else if (val > t->max) {
|
val = t->min;
|
||||||
val = t->max;
|
} else if (val > t->max) {
|
||||||
}
|
val = t->max;
|
||||||
if(t->table==0) {
|
}
|
||||||
|
if(t->table==0) {
|
||||||
val = val * t->factor + t->offset;
|
val = val * t->factor + t->offset;
|
||||||
} else {
|
} else {
|
||||||
val = t->table->interpolate(val) * t->factor + t->offset;
|
val = t->table->interpolate(val) * t->factor + t->offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
case FGPanelTransformation::XSHIFT:
|
case FGPanelTransformation::XSHIFT:
|
||||||
glTranslatef(val, 0.0, 0.0);
|
glTranslatef(val, 0.0, 0.0);
|
||||||
break;
|
break;
|
||||||
case FGPanelTransformation::YSHIFT:
|
case FGPanelTransformation::YSHIFT:
|
||||||
glTranslatef(0.0, val, 0.0);
|
glTranslatef(0.0, val, 0.0);
|
||||||
break;
|
break;
|
||||||
case FGPanelTransformation::ROTATION:
|
case FGPanelTransformation::ROTATION:
|
||||||
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,27 +756,29 @@ FGTexturedLayer::~FGTexturedLayer ()
|
||||||
void
|
void
|
||||||
FGTexturedLayer::draw ()
|
FGTexturedLayer::draw ()
|
||||||
{
|
{
|
||||||
int w2 = _w / 2;
|
if (test()) {
|
||||||
int h2 = _h / 2;
|
int w2 = _w / 2;
|
||||||
|
int h2 = _h / 2;
|
||||||
transform();
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
|
transform();
|
||||||
glBegin(GL_POLYGON);
|
glBindTexture(GL_TEXTURE_2D, _texture.getTexture()->getHandle());
|
||||||
|
glBegin(GL_POLYGON);
|
||||||
|
|
||||||
// From Curt: turn on the panel
|
// From Curt: turn on the panel
|
||||||
// lights after sundown.
|
// lights after sundown.
|
||||||
if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
|
if ( cur_light_params.sun_angle * SGD_RADIANS_TO_DEGREES < 95.0 ) {
|
||||||
glColor4fv( cur_light_params.scene_diffuse );
|
glColor4fv( cur_light_params.scene_diffuse );
|
||||||
} else {
|
} else {
|
||||||
glColor4f(0.7, 0.2, 0.2, 1.0);
|
glColor4f(0.7, 0.2, 0.2, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
|
||||||
|
glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
|
||||||
|
glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
|
||||||
|
glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
|
||||||
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
glTexCoord2f(_texture.getMinX(), _texture.getMinY()); glVertex2f(-w2, -h2);
|
|
||||||
glTexCoord2f(_texture.getMaxX(), _texture.getMinY()); glVertex2f(w2, -h2);
|
|
||||||
glTexCoord2f(_texture.getMaxX(), _texture.getMaxY()); glVertex2f(w2, h2);
|
|
||||||
glTexCoord2f(_texture.getMinX(), _texture.getMaxY()); glVertex2f(-w2, h2);
|
|
||||||
glEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -760,24 +807,26 @@ FGTextLayer::~FGTextLayer ()
|
||||||
void
|
void
|
||||||
FGTextLayer::draw ()
|
FGTextLayer::draw ()
|
||||||
{
|
{
|
||||||
glPushMatrix();
|
if (test()) {
|
||||||
glColor4fv(_color);
|
glPushMatrix();
|
||||||
transform();
|
glColor4fv(_color);
|
||||||
text_renderer.setFont(guiFntHandle);
|
transform();
|
||||||
text_renderer.setPointSize(_pointSize);
|
text_renderer.setFont(guiFntHandle);
|
||||||
text_renderer.begin();
|
text_renderer.setPointSize(_pointSize);
|
||||||
text_renderer.start3f(0, 0, 0);
|
text_renderer.begin();
|
||||||
|
text_renderer.start3f(0, 0, 0);
|
||||||
|
|
||||||
_now.stamp();
|
_now.stamp();
|
||||||
if (_now - _then > 100000) {
|
if (_now - _then > 100000) {
|
||||||
recalc_value();
|
recalc_value();
|
||||||
_then = _now;
|
_then = _now;
|
||||||
|
}
|
||||||
|
text_renderer.puts((char *)(_value.c_str()));
|
||||||
|
|
||||||
|
text_renderer.end();
|
||||||
|
glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
|
||||||
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
text_renderer.puts((char *)(_value.c_str()));
|
|
||||||
|
|
||||||
text_renderer.end();
|
|
||||||
glColor4f(1.0, 1.0, 1.0, 1.0); // FIXME
|
|
||||||
glPopMatrix();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -849,18 +898,22 @@ FGTextLayer::Chunk::Chunk (ChunkType type, const SGPropertyNode * node,
|
||||||
const char *
|
const char *
|
||||||
FGTextLayer::Chunk::getValue () const
|
FGTextLayer::Chunk::getValue () const
|
||||||
{
|
{
|
||||||
switch (_type) {
|
if (test()) {
|
||||||
case TEXT:
|
switch (_type) {
|
||||||
sprintf(_buf, _fmt.c_str(), _text.c_str());
|
case TEXT:
|
||||||
|
sprintf(_buf, _fmt.c_str(), _text.c_str());
|
||||||
|
return _buf;
|
||||||
|
case TEXT_VALUE:
|
||||||
|
sprintf(_buf, _fmt.c_str(), _node->getStringValue().c_str());
|
||||||
|
break;
|
||||||
|
case DOUBLE_VALUE:
|
||||||
|
sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult);
|
||||||
|
break;
|
||||||
|
}
|
||||||
return _buf;
|
return _buf;
|
||||||
case TEXT_VALUE:
|
} else {
|
||||||
sprintf(_buf, _fmt.c_str(), _node->getStringValue().c_str());
|
return "";
|
||||||
break;
|
|
||||||
case DOUBLE_VALUE:
|
|
||||||
sprintf(_buf, _fmt.c_str(), _node->getFloatValue() * _mult);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return _buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -885,11 +938,13 @@ FGSwitchLayer::~FGSwitchLayer ()
|
||||||
void
|
void
|
||||||
FGSwitchLayer::draw ()
|
FGSwitchLayer::draw ()
|
||||||
{
|
{
|
||||||
transform();
|
if (test()) {
|
||||||
if (_node->getBoolValue()) {
|
transform();
|
||||||
_layer1->draw();
|
if (_node->getBoolValue()) {
|
||||||
} else {
|
_layer1->draw();
|
||||||
_layer2->draw();
|
} else {
|
||||||
|
_layer2->draw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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") {
|
||||||
|
@ -551,7 +585,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
@ -638,7 +673,8 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue