1
0
Fork 0

Csaba HALASZ & Syd ADAMS: make radar font configurable

mf: move font color parts to the font listener
This commit is contained in:
mfranz 2008-06-01 18:08:01 +00:00
parent 68124ca36d
commit e0aeda5a51
4 changed files with 85 additions and 71 deletions

View file

@ -41,9 +41,12 @@
#include "groundradar.hxx" #include "groundradar.hxx"
static const char* airport_node_name = "/sim/tower/airport-id"; static const char* airport_source_node_name = "airport-id-source";
static const char* texture_name = "Aircraft/Instruments/Textures/od_groundradar.rgb"; static const char* default_airport_node_name = "/sim/tower/airport-id";
static const char* radar_node_name = "/instrumentation/radar/range"; static const char* texture_node_name = "texture-name";
static const char* default_texture_name = "Aircraft/Instruments/Textures/od_groundradar.rgb";
static const char* range_source_node_name = "range-source";
static const char* default_range_node_name = "/instrumentation/radar/range";
struct SingleFrameCallback : public osg::Camera::DrawCallback struct SingleFrameCallback : public osg::Camera::DrawCallback
{ {
@ -55,18 +58,18 @@ struct SingleFrameCallback : public osg::Camera::DrawCallback
GroundRadar::GroundRadar(SGPropertyNode *node) GroundRadar::GroundRadar(SGPropertyNode *node)
{ {
_airport_node = fgGetNode(airport_node_name, true); _airport_node = fgGetNode(node->getStringValue(airport_source_node_name, default_airport_node_name), true);
_radar_node = fgGetNode(radar_node_name, true); _range_node = fgGetNode(node->getStringValue(range_source_node_name, default_range_node_name), true);
createTexture(); createTexture(node->getStringValue(texture_node_name, default_texture_name));
updateTexture(); updateTexture();
_airport_node->addChangeListener(this); _airport_node->addChangeListener(this);
_radar_node->addChangeListener(this); _range_node->addChangeListener(this);
} }
GroundRadar::~GroundRadar() GroundRadar::~GroundRadar()
{ {
_airport_node->removeChangeListener(this); _airport_node->removeChangeListener(this);
_radar_node->removeChangeListener(this); _range_node->removeChangeListener(this);
} }
void GroundRadar::valueChanged(SGPropertyNode*) void GroundRadar::valueChanged(SGPropertyNode*)
@ -79,14 +82,14 @@ inline static osg::Vec3 fromPolar(double fi, double r)
return osg::Vec3(sin(fi * SGD_DEGREES_TO_RADIANS) * r, cos(fi * SGD_DEGREES_TO_RADIANS) * r, 0); return osg::Vec3(sin(fi * SGD_DEGREES_TO_RADIANS) * r, cos(fi * SGD_DEGREES_TO_RADIANS) * r, 0);
} }
void GroundRadar::createTexture() void GroundRadar::createTexture(const char* texture_name)
{ {
setSize(512); setSize(512);
allocRT(); allocRT();
osg::Vec4Array* colors = new osg::Vec4Array; osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(0.0f,0.5f,0.0f,1.0f)); colors->push_back(osg::Vec4(0.0f, 0.5f, 0.0f, 1.0f));
colors->push_back(osg::Vec4(0.0f,0.5f,0.5f,1.0f)); colors->push_back(osg::Vec4(0.0f, 0.5f, 0.5f, 1.0f));
_geom = new osg::Geometry(); _geom = new osg::Geometry();
_geom->setColorArray(colors); _geom->setColorArray(colors);
@ -118,12 +121,15 @@ void GroundRadar::updateTexture()
FGRunwayList* runways = globals->get_runways(); FGRunwayList* runways = globals->get_runways();
const FGAirport* airport = fgFindAirportID(airport_name); const FGAirport* airport = fgFindAirportID(airport_name);
if (airport == 0)
return;
const SGGeod& tower_location = airport->getTowerLocation(); const SGGeod& tower_location = airport->getTowerLocation();
const double tower_lat = tower_location.getLatitudeDeg(); const double tower_lat = tower_location.getLatitudeDeg();
const double tower_lon = tower_location.getLongitudeDeg(); const double tower_lon = tower_location.getLongitudeDeg();
double scale = SG_METER_TO_NM * 200 / _radar_node->getDoubleValue(); double scale = SG_METER_TO_NM * 200 / _range_node->getDoubleValue();
for(FGRunway runway = runways->search(airport_name); runway._id == airport_name; runway = runways->next()) for (FGRunway runway = runways->search(airport_name); runway._id == airport_name; runway = runways->next())
{ {
double az1, az2, dist_m; double az1, az2, dist_m;
geo_inverse_wgs_84(tower_lat, tower_lon, runway._lat, runway._lon, &az1, &az2, &dist_m); geo_inverse_wgs_84(tower_lat, tower_lon, runway._lat, runway._lon, &az1, &az2, &dist_m);

View file

@ -38,11 +38,11 @@ public:
virtual void valueChanged(SGPropertyNode*); virtual void valueChanged(SGPropertyNode*);
protected: protected:
void createTexture(const char* texture_name);
osg::ref_ptr<osg::Geometry> _geom; osg::ref_ptr<osg::Geometry> _geom;
SGPropertyNode_ptr _airport_node; SGPropertyNode_ptr _airport_node;
SGPropertyNode_ptr _radar_node; SGPropertyNode_ptr _range_node;
void createTexture();
}; };
#endif // __INST_GROUNDRADAR_HXX #endif // __INST_GROUNDRADAR_HXX

View file

@ -75,45 +75,44 @@ typedef radar_list_type::const_iterator radar_list_const_iterator;
static const float UNIT = 1.0f / 8.0f; // 8 symbols in a row/column in the texture static const float UNIT = 1.0f / 8.0f; // 8 symbols in a row/column in the texture
static const char *DEFAULT_FONT = "typewriter.txf"; static const char *DEFAULT_FONT = "typewriter.txf";
wxRadarBg::wxRadarBg ( SGPropertyNode *node) : wxRadarBg::wxRadarBg(SGPropertyNode *node) :
_name(node->getStringValue("name", "radar")), _name(node->getStringValue("name", "radar")),
_num(node->getIntValue("number", 0)), _num(node->getIntValue("number", 0)),
_interval(node->getDoubleValue("update-interval-sec", 1.0)), _interval(node->getDoubleValue("update-interval-sec", 1.0)),
_time( 0.0 ), _time(0.0),
_last_switchKnob( "off" ), _last_switchKnob("off"),
_sim_init_done ( false ), _sim_init_done(false),
_resultTexture( 0 ), _resultTexture(0),
_wxEcho( 0 ), _wxEcho(0),
_odg( 0 ) _odg(0)
{ {
const char *tacan_source = node->getStringValue("tacan-source", string branch;
"/instrumentation/tacan"); branch = "/instrumentation/" + _name;
_Instrument = fgGetNode(branch.c_str(), _num, true );
const char *tacan_source = node->getStringValue("tacan-source", "/instrumentation/tacan");
_Tacan = fgGetNode(tacan_source, true); _Tacan = fgGetNode(tacan_source, true);
_font_node = _Instrument->getNode("font", true);
_font_node->addChangeListener(this, true);
} }
wxRadarBg::~wxRadarBg () wxRadarBg::~wxRadarBg ()
{ {
if (_radar_font_node != 0) { _font_node->removeChangeListener(this);
_radar_font_node->removeChangeListener(this);
}
} }
void void
wxRadarBg::init () wxRadarBg::init ()
{ {
string branch;
branch = "/instrumentation/" + _name;
_Instrument = fgGetNode(branch.c_str(), _num, true );
_serviceable_node = _Instrument->getNode("serviceable", true); _serviceable_node = _Instrument->getNode("serviceable", true);
// texture name to use in 2D and 3D instruments // texture name to use in 2D and 3D instruments
_texture_path = _Instrument->getStringValue("radar-texture-path", _texture_path = _Instrument->getStringValue("radar-texture-path",
"Aircraft/Instruments/Textures/od_wxradar.rgb"); "Aircraft/Instruments/Textures/od_wxradar.rgb");
_resultTexture = FGTextureManager::createTexture(_texture_path.c_str(), _resultTexture = FGTextureManager::createTexture(_texture_path.c_str(), false);
false);
SGPath tpath(globals->get_fg_root()); SGPath tpath(globals->get_fg_root());
string path = _Instrument->getStringValue("echo-texture-path", string path = _Instrument->getStringValue("echo-texture-path",
@ -138,8 +137,8 @@ wxRadarBg::init ()
// input range = n nm (20/40/80) // input range = n nm (20/40/80)
// input display-mode = arc | rose | map | plan // input display-mode = arc | rose | map | plan
FGInstrumentMgr *imgr = (FGInstrumentMgr *) globals->get_subsystem("instrumentation"); FGInstrumentMgr *imgr = (FGInstrumentMgr *)globals->get_subsystem("instrumentation");
_odg = (FGODGauge *) imgr->get_subsystem("od_gauge"); _odg = (FGODGauge *)imgr->get_subsystem("od_gauge");
_odg->setSize(512); _odg->setSize(512);
_ai = (FGAIManager*)globals->get_subsystem("ai_model"); _ai = (FGAIManager*)globals->get_subsystem("ai_model");
@ -170,10 +169,6 @@ wxRadarBg::init ()
_radar_symbol_node = n->getNode("symbol", true); _radar_symbol_node = n->getNode("symbol", true);
_radar_centre_node = n->getNode("centre", true); _radar_centre_node = n->getNode("centre", true);
_radar_rotate_node = n->getNode("rotate", true); _radar_rotate_node = n->getNode("rotate", true);
_radar_font_node = _Instrument->getNode("font", true);
_radar_font_node->addChangeListener(this);
updateFont();
_radar_centre_node->setBoolValue(false); _radar_centre_node->setBoolValue(false);
if (_radar_coverage_node->getType() == SGPropertyNode::NONE) if (_radar_coverage_node->getType() == SGPropertyNode::NONE)
@ -549,14 +544,15 @@ wxRadarBg::update_weather()
} }
} }
void void
wxRadarBg::update_data(FGAIBase* ac, double radius, double bearing, bool selected) wxRadarBg::update_data(FGAIBase* ac, double radius, double bearing, bool selected)
{ {
osgText::Text* callsign = new osgText::Text; osgText::Text* callsign = new osgText::Text;
callsign->setFont(_font.get()); callsign->setFont(_font.get());
callsign->setFontResolution(12, 12); callsign->setFontResolution(12, 12);
callsign->setCharacterSize(12); callsign->setCharacterSize(_font_size);
callsign->setColor(selected ? osg::Vec4(1, 1, 1, 1) : osg::Vec4(0, 1, 0, 1)); callsign->setColor(selected ? osg::Vec4(1, 1, 1, 1) : _font_color);
osg::Matrixf m(wxRotate(-bearing) osg::Matrixf m(wxRotate(-bearing)
* osg::Matrixf::translate(0.0f, radius, 0.0f) * osg::Matrixf::translate(0.0f, radius, 0.0f)
* wxRotate(bearing) * _centerTrans); * wxRotate(bearing) * _centerTrans);
@ -565,7 +561,7 @@ wxRadarBg::update_data(FGAIBase* ac, double radius, double bearing, bool selecte
// cast to int's, otherwise text comes out ugly // cast to int's, otherwise text comes out ugly
callsign->setPosition(osg::Vec3((int)pos.x(), (int)pos.y(), 0)); callsign->setPosition(osg::Vec3((int)pos.x(), (int)pos.y(), 0));
callsign->setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE); callsign->setAlignment(osgText::Text::LEFT_BOTTOM_BASE_LINE);
callsign->setLineSpacing(0.25); callsign->setLineSpacing(_font_spacing);
stringstream text; stringstream text;
text << ac->_getCallsign() << endl text << ac->_getCallsign() << endl
@ -578,6 +574,7 @@ wxRadarBg::update_data(FGAIBase* ac, double radius, double bearing, bool selecte
_textGeode->addDrawable(callsign); _textGeode->addDrawable(callsign);
} }
void void
wxRadarBg::update_aircraft() wxRadarBg::update_aircraft()
{ {
@ -857,14 +854,21 @@ wxRadarBg::calcRelBearing(float bearing, float heading)
return angle; return angle;
} }
void void
wxRadarBg::updateFont() wxRadarBg::updateFont()
{ {
float red = _font_node->getFloatValue("color/red", 0);
float green = _font_node->getFloatValue("color/green", 0.8);
float blue = _font_node->getFloatValue("color/blue", 0);
float alpha = _font_node->getFloatValue("color/alpha", 1);
_font_color.set(red, green, blue, alpha);
_font_size = _font_node->getFloatValue("size", 12);
_font_spacing = _font_size * _font_node->getFloatValue("line-spacing", 0.25);
string path = _font_node->getStringValue("name", DEFAULT_FONT);
SGPath tpath; SGPath tpath;
string path = _radar_font_node->getStringValue();
if (path.length() == 0) {
path = DEFAULT_FONT;
}
if (path[0] != '/') { if (path[0] != '/') {
tpath = globals->get_fg_root(); tpath = globals->get_fg_root();
tpath.append("Fonts"); tpath.append("Fonts");
@ -872,12 +876,14 @@ wxRadarBg::updateFont()
} else { } else {
tpath = path; tpath = path;
} }
#if (FG_OSG_VERSION >= 21000) #if (FG_OSG_VERSION >= 21000)
osg::ref_ptr<osgDB::ReaderWriter::Options> fontOptions = new osgDB::ReaderWriter::Options("monochrome"); osg::ref_ptr<osgDB::ReaderWriter::Options> fontOptions = new osgDB::ReaderWriter::Options("monochrome");
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str(), fontOptions.get()); osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str(), fontOptions.get());
#else #else
osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str()); osg::ref_ptr<osgText::Font> font = osgText::readFontFile(tpath.c_str());
#endif #endif
if (font != 0) { if (font != 0) {
_font = font; _font = font;
_font->setMinFilterHint(osg::Texture::NEAREST); _font->setMinFilterHint(osg::Texture::NEAREST);
@ -892,3 +898,4 @@ wxRadarBg::valueChanged(SGPropertyNode*)
{ {
updateFont(); updateFont();
} }

View file

@ -58,11 +58,8 @@ public:
double _interval; double _interval;
double _time; double _time;
bool _sim_init_done; bool _sim_init_done;
string _name; string _name;
int _num; int _num;
SGPropertyNode_ptr _serviceable_node; SGPropertyNode_ptr _serviceable_node;
@ -82,7 +79,6 @@ public:
SGPropertyNode* getInstrumentNode(const char* name, DefaultType value); SGPropertyNode* getInstrumentNode(const char* name, DefaultType value);
private: private:
string _texture_path; string _texture_path;
typedef enum { ARC, MAP, PLAN, ROSE } DisplayMode; typedef enum { ARC, MAP, PLAN, ROSE } DisplayMode;
@ -121,8 +117,8 @@ private:
SGPropertyNode_ptr _radar_ref_rng_node; SGPropertyNode_ptr _radar_ref_rng_node;
SGPropertyNode_ptr _radar_hdg_marker_node; SGPropertyNode_ptr _radar_hdg_marker_node;
SGPropertyNode_ptr _radar_rotate_node; SGPropertyNode_ptr _radar_rotate_node;
SGPropertyNode_ptr _radar_font_node;
SGPropertyNode_ptr _font_node;
SGPropertyNode_ptr _ai_enabled_node; SGPropertyNode_ptr _ai_enabled_node;
osg::ref_ptr<osg::Texture2D> _resultTexture; osg::ref_ptr<osg::Texture2D> _resultTexture;
@ -134,6 +130,9 @@ private:
osg::Vec2Array *_texCoords; osg::Vec2Array *_texCoords;
osg::Matrixf _centerTrans; osg::Matrixf _centerTrans;
osg::ref_ptr<osgText::Font> _font; osg::ref_ptr<osgText::Font> _font;
osg::Vec4 _font_color;
float _font_size;
float _font_spacing;
list_of_SGWxRadarEcho _radarEchoBuffer; list_of_SGWxRadarEcho _radarEchoBuffer;
@ -154,9 +153,9 @@ private:
bool inRadarRange(int type, double range); bool inRadarRange(int type, double range);
float calcRelBearing(float bearing, float heading); float calcRelBearing(float bearing, float heading);
}; };
template<> inline template<> inline
SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, bool value) SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, bool value)
{ {
@ -166,6 +165,7 @@ SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, bool value)
return result; return result;
} }
template<> inline template<> inline
SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, double value) SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, double value)
{ {
@ -175,6 +175,7 @@ SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, double value)
return result; return result;
} }
template<> inline template<> inline
SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name, SGPropertyNode* wxRadarBg::getInstrumentNode(const char* name,
const char* value) const char* value)