- drop hardcoded color/brightness values
- let listener class watch and maintain HUD color properties, which is more effective and more flexible.
This commit is contained in:
parent
14ab303877
commit
1ccacef184
2 changed files with 79 additions and 142 deletions
|
@ -66,6 +66,9 @@ extern "C" {
|
|||
|
||||
#include "hud.hxx"
|
||||
|
||||
|
||||
static HUD_Properties *HUD;
|
||||
|
||||
static char units[5];
|
||||
|
||||
// The following routines obtain information concerning the aircraft's
|
||||
|
@ -776,6 +779,7 @@ int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ )
|
|||
HUDtext->setPointSize(HUD_TextSize);
|
||||
HUD_TextList.setFont( HUDtext );
|
||||
|
||||
HUD = new HUD_Properties;
|
||||
return 0; // For now. Later we may use this for an error code.
|
||||
|
||||
}
|
||||
|
@ -805,80 +809,6 @@ int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ )
|
|||
}
|
||||
//$$$ End - added, Neetha, 28 Nov 2k
|
||||
|
||||
static int global_day_night_switch = HUD_DAY;
|
||||
|
||||
void HUD_masterswitch( bool incr )
|
||||
{
|
||||
if ( fgGetBool("/sim/hud/visibility") ) {
|
||||
if ( global_day_night_switch == HUD_DAY ) {
|
||||
global_day_night_switch = HUD_NIGHT;
|
||||
} else {
|
||||
fgSetBool("/sim/hud/visibility", false);
|
||||
}
|
||||
} else {
|
||||
fgSetBool("/sim/hud/visibility", true);
|
||||
global_day_night_switch = HUD_DAY;
|
||||
}
|
||||
}
|
||||
|
||||
void HUD_brightkey( bool incr_bright )
|
||||
{
|
||||
instr_item *pHUDInstr = HUD_deque[0];
|
||||
int brightness = pHUDInstr->get_brightness();
|
||||
|
||||
if( fgGetBool("/sim/hud/visibility") ) {
|
||||
if( incr_bright ) {
|
||||
switch (brightness)
|
||||
{
|
||||
case HUD_BRT_LIGHT:
|
||||
brightness = HUD_BRT_BLACK;
|
||||
break;
|
||||
|
||||
case HUD_BRT_MEDIUM:
|
||||
brightness = HUD_BRT_LIGHT;
|
||||
break;
|
||||
|
||||
case HUD_BRT_DARK:
|
||||
brightness = HUD_BRT_MEDIUM;
|
||||
break;
|
||||
|
||||
case HUD_BRT_BLACK:
|
||||
brightness = HUD_BRT_DARK;
|
||||
break;
|
||||
|
||||
default:
|
||||
brightness = HUD_BRT_BLACK;
|
||||
}
|
||||
} else {
|
||||
switch (brightness)
|
||||
{
|
||||
case HUD_BRT_LIGHT:
|
||||
brightness = HUD_BRT_MEDIUM;
|
||||
break;
|
||||
|
||||
case HUD_BRT_MEDIUM:
|
||||
brightness = HUD_BRT_DARK;
|
||||
break;
|
||||
|
||||
case HUD_BRT_DARK:
|
||||
brightness = HUD_BRT_BLACK;
|
||||
break;
|
||||
|
||||
case HUD_BRT_BLACK:
|
||||
brightness = HUD_BRT_LIGHT;
|
||||
break;
|
||||
|
||||
default:
|
||||
fgSetBool("/sim/hud/visibility", false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fgSetBool("/sim/hud/visibility", true);
|
||||
}
|
||||
|
||||
pHUDInstr->SetBrightness( brightness );
|
||||
}
|
||||
|
||||
|
||||
void fgHUDReshape(void) {
|
||||
#if 0
|
||||
|
@ -902,17 +832,6 @@ void fgHUDReshape(void) {
|
|||
}
|
||||
|
||||
|
||||
static void set_hud_color(float r, float g, float b) {
|
||||
static SGPropertyNode_ptr alias = fgGetNode("/sim/hud/antialiased", true);
|
||||
static SGPropertyNode_ptr alpha = fgGetNode("/sim/hud/alpha", true);
|
||||
|
||||
if (alias->getBoolValue())
|
||||
glColor4f(r, g, b, alpha->getFloatValue());
|
||||
else
|
||||
glColor3f(r, g, b);
|
||||
}
|
||||
|
||||
|
||||
// fgUpdateHUD
|
||||
//
|
||||
// Performs a once around the list of calls to instruments installed in
|
||||
|
@ -1025,8 +944,6 @@ void drawHUD()
|
|||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
static const SGPropertyNode *antialiased_node
|
||||
= fgGetNode("/sim/hud/antialiased", true);
|
||||
static const SGPropertyNode *heading_enabled
|
||||
= fgGetNode("/autopilot/locks/heading", true);
|
||||
static const SGPropertyNode *altitude_enabled
|
||||
|
@ -1038,7 +955,7 @@ void drawHUD()
|
|||
static char hud_wp2_text[256];
|
||||
static char hud_alt_text[256];
|
||||
|
||||
if( antialiased_node->getBoolValue() ) {
|
||||
if (HUD->isAntialiased()) {
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
// glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
@ -1048,56 +965,7 @@ void drawHUD()
|
|||
glLineWidth(1.0);
|
||||
}
|
||||
|
||||
if( global_day_night_switch == HUD_DAY) {
|
||||
switch (HUD_deque[0]->get_brightness())
|
||||
{
|
||||
case HUD_BRT_LIGHT:
|
||||
set_hud_color (0.1f, 0.9f, 0.1f);
|
||||
break;
|
||||
|
||||
case HUD_BRT_MEDIUM:
|
||||
set_hud_color (0.1f, 0.7f, 0.0f);
|
||||
break;
|
||||
|
||||
case HUD_BRT_DARK:
|
||||
set_hud_color (0.0f, 0.6f, 0.0f);
|
||||
break;
|
||||
|
||||
case HUD_BRT_BLACK:
|
||||
set_hud_color( 0.0f, 0.0f, 0.0f);
|
||||
break;
|
||||
|
||||
default:
|
||||
set_hud_color (0.1f, 0.9f, 0.1f);
|
||||
}
|
||||
} else {
|
||||
if( global_day_night_switch == HUD_NIGHT) {
|
||||
switch (HUD_deque[0]->get_brightness())
|
||||
{
|
||||
case HUD_BRT_LIGHT:
|
||||
set_hud_color (0.9f, 0.1f, 0.1f);
|
||||
break;
|
||||
|
||||
case HUD_BRT_MEDIUM:
|
||||
set_hud_color (0.7f, 0.0f, 0.1f);
|
||||
break;
|
||||
|
||||
case HUD_BRT_DARK:
|
||||
set_hud_color (0.6f, 0.0f, 0.0f);
|
||||
break;
|
||||
|
||||
case HUD_BRT_BLACK:
|
||||
set_hud_color( 0.0f, 0.0f, 0.0f);
|
||||
break;
|
||||
|
||||
default:
|
||||
set_hud_color (0.6f, 0.0f, 0.0f);
|
||||
}
|
||||
} else { // Just in case default
|
||||
set_hud_color (0.1f, 0.9f, 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
HUD->setColor();
|
||||
for_each(HUD_deque.begin(), HUD_deque.end(), HUDdraw());
|
||||
|
||||
HUD_TextList.add( fgText(40, 10, get_formated_gmt_time(), 0) );
|
||||
|
@ -1164,7 +1032,7 @@ void drawHUD()
|
|||
// HUD_StippleLineList.draw();
|
||||
// glDisable(GL_LINE_STIPPLE);
|
||||
|
||||
if( antialiased_node->getBoolValue() ) {
|
||||
if (HUD->isAntialiased()) {
|
||||
// glDisable(GL_BLEND);
|
||||
glDisable(GL_LINE_SMOOTH);
|
||||
glLineWidth(1.0);
|
||||
|
@ -1174,3 +1042,51 @@ void drawHUD()
|
|||
glEnable(GL_LIGHTING);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// HUD property listener class
|
||||
//
|
||||
HUD_Properties::HUD_Properties()
|
||||
{
|
||||
_colors = fgGetNode("/sim/hud/colors", true)->getChildren("color");
|
||||
_which = fgGetNode("/sim/hud/current-color", true);
|
||||
_brightness = fgGetNode("/sim/hud/brightness", true);
|
||||
_alpha = fgGetNode("/sim/hud/alpha", true);
|
||||
_visibility = fgGetNode("/sim/hud/visibility", true);
|
||||
_antialiasing = fgGetNode("/sim/hud/antialiased", true);
|
||||
|
||||
_which->addChangeListener(this);
|
||||
_brightness->addChangeListener(this);
|
||||
_alpha->addChangeListener(this);
|
||||
_visibility->addChangeListener(this);
|
||||
_antialiasing->addChangeListener(this, true);
|
||||
}
|
||||
|
||||
|
||||
void HUD_Properties::valueChanged(SGPropertyNode *n)
|
||||
{
|
||||
_visible = _visibility->getBoolValue();
|
||||
_antialiased = _antialiasing->getBoolValue();
|
||||
float brt = _brightness->getFloatValue();
|
||||
int w = _which->getIntValue();
|
||||
if (w < 0 || w >= int(_colors.size()))
|
||||
_visible = false;
|
||||
else {
|
||||
_r = clamp(brt * _colors[w]->getFloatValue("red", 1.0));
|
||||
_g = clamp(brt * _colors[w]->getFloatValue("green", 1.0));
|
||||
_b = clamp(brt * _colors[w]->getFloatValue("blue", 1.0));
|
||||
}
|
||||
_a = _alpha->getFloatValue();
|
||||
}
|
||||
|
||||
|
||||
void HUD_Properties::setColor() const
|
||||
{
|
||||
if (_antialiased)
|
||||
glColor4f(_r, _g, _b, _a);
|
||||
else
|
||||
glColor3f(_r, _g, _b);
|
||||
}
|
||||
|
||||
|
|
|
@ -1034,8 +1034,6 @@ public:
|
|||
//using namespace std;
|
||||
//deque <instr_item> * Hdeque_ptr;
|
||||
|
||||
extern void HUD_masterswitch( bool incr );
|
||||
extern void HUD_brightkey( bool incr_bright );
|
||||
extern int fgHUDInit( fgAIRCRAFT * /* current_aircraft */ );
|
||||
extern int fgHUDInit2( fgAIRCRAFT * /* current_aircraft */ );
|
||||
extern void fgUpdateHUD( void );
|
||||
|
@ -1054,4 +1052,27 @@ void fgUpdateHUD2( Hptr hud ); // Future use?
|
|||
void fgHUDSetTimeMode( Hptr hud, int time_of_day );
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
class HUD_Properties : public SGPropertyChangeListener {
|
||||
public:
|
||||
HUD_Properties();
|
||||
void valueChanged(SGPropertyNode *n);
|
||||
void setColor() const;
|
||||
bool isVisible() const { return _visible; }
|
||||
bool isAntialiased() const { return _antialiased; }
|
||||
|
||||
private:
|
||||
float clamp(float f) { return f < 0.0f ? 0.0f : f > 1.0f ? 1.0f : f; }
|
||||
vector<SGPropertyNode_ptr> _colors;
|
||||
SGPropertyNode_ptr _which;
|
||||
SGPropertyNode_ptr _brightness;
|
||||
SGPropertyNode_ptr _alpha;
|
||||
SGPropertyNode_ptr _visibility;
|
||||
SGPropertyNode_ptr _antialiasing;
|
||||
bool _visible, _antialiased;
|
||||
float _r, _g, _b, _a;
|
||||
};
|
||||
|
||||
#endif // _HUD_H
|
||||
|
|
Loading…
Reference in a new issue