//Draw all visible windows. void WindowManager::draw() { GFXHudMode( true ); //Load identity matrices. GFXColorf( GUI_OPAQUE_WHITE() ); GFXDisable( DEPTHTEST ); GFXEnable( DEPTHWRITE ); GFXDisable( LIGHTING ); GFXDisable( CULLFACE ); GFXClear( GFXTRUE ); GFXDisable( DEPTHWRITE ); GFXBlendMode( SRCALPHA, INVSRCALPHA ); GFXDisable( TEXTURE1 ); GFXEnable( TEXTURE0 ); //Just loop through all the windows, and remember if anything gets drawn. //Since the first window in the list is drawn first, z-order is //maintained. First entry is the bottom window, last is the top window. //FIXME mbyron -- I think the event manager needs to get involved with window z-order. //(Mouse events should go to windows in zorder, shouldn't they?) for (size_t i = 0; i < m_windows.size(); i++) { if ( m_windows[i]->controller() )//it's a controller m_windows[i]->controller()->draw();//that can draw if ( i < m_windows.size() ) m_windows[i]->draw(); } //Emulate EndGUIFrame. static VSSprite MouseVSSprite( "mouse.spr", BILINEAR, GFXTRUE ); static Texture dummy( "white.bmp", 0, NEAREST, TEXTURE2D, TEXTURE_2D, GFXTRUE ); GFXDisable( CULLFACE ); ConditionalCursorDraw( true ); //Figure position of cursor sprite. float sizex = 0.0, sizey = 0.0; const Point loc = globalEventManager().mouseLoc(); MouseVSSprite.GetSize( sizex, sizey ); float tempx = 0.0, tempy = 0.0; MouseVSSprite.GetPosition( tempx, tempy ); MouseVSSprite.SetPosition( tempx+loc.x+sizex/2, tempy+loc.y+sizey/2 ); dummy.MakeActive(); GFXBlendMode( SRCALPHA, INVSRCALPHA ); GFXColorf( GUI_OPAQUE_WHITE() ); //Draw the cursor sprite. GFXEnable( TEXTURE0 ); GFXDisable( DEPTHTEST ); GFXDisable( TEXTURE1 ); MouseVSSprite.Draw(); GFXHudMode( false ); GFXEnable( CULLFACE ); MouseVSSprite.SetPosition( tempx, tempy ); }
void GameCockpit::beginElement( const string &name, const AttributeList &attributes ) { static bool cockpit_smooth = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "cockpit_smooth_texture", "false" ) ); static bool panel_smooth = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "panel_smooth_texture", "true" ) ); static bool crosshair_smooth = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "crosshair_smooth_texture", "true" ) ); AttributeList::const_iterator iter; Gauge::DIRECTION tmpdir = Gauge::GAUGE_UP; VSSprite **newsprite = NULL; VDU **newvdu = NULL; VSSprite *adjsprite = NULL; std::string gaugename( "shieldstat.spr" ); std::string myfont( "9x12.font" ); Names elem = (Names) element_map.lookup( name ); Names attr; unsigned int mymodes = 0; float xsize = -1, ysize = -1, xcent = FLT_MAX, ycent = FLT_MAX; float leftx = -10; float rightx = -10; float topy = -10; float boty = -10; short rows = 13; short cols = 15; unsigned int default_mode = VDU::TARGET; VSSprite *oldpit = NULL; bool replaced[4] = {false, false, false, false}; int counter = 0; switch ((int)elem) { case COCKPIT: for (iter = attributes.begin(); iter != attributes.end(); iter++) { attr = (Names) attribute_map.lookup( (*iter).name ); switch (attr) { case MYFONT: myfont = (*iter).value; break; case RED: textcol.r = XMLSupport::parse_float( (*iter).value ); break; case GREEN: textcol.g = XMLSupport::parse_float( (*iter).value ); break; case BLUE: textcol.b = XMLSupport::parse_float( (*iter).value ); break; case ALPH: textcol.a = XMLSupport::parse_float( (*iter).value ); break; case VIEWOFFSET: viewport_offset = XMLSupport::parse_float( (*iter).value ); break; case COCKPITOFFSET: cockpit_offset = XMLSupport::parse_float( (*iter).value ); break; case XFILE: { std::string tmp = getRes( (*iter).value ); oldpit = Pit[0]; Pit[0] = new VSSprite( tmp.c_str(), cockpit_smooth ? BILINEAR : NEAREST ); if ( !Pit[0]->LoadSuccess() ) { delete Pit[0]; Pit[0] = new VSSprite( (*iter).value.c_str(), cockpit_smooth ? BILINEAR : NEAREST ); } replaced[0] = true; if (oldpit) delete oldpit; break; } case SOUNDFILE: SetSoundFile( (*iter).value ); break; case MESH: mesh = Mesh::LoadMeshes( (*iter).value.c_str(), Vector( 1, 1, 1 ), 0, NULL ); break; case FRONT: case BACK: case LEFT: case RIGHT: { std::string tmp = getRes( (*iter).value ); oldpit = Pit[attr-FRONT]; Pit[attr-FRONT] = new VSSprite( tmp.c_str(), cockpit_smooth ? BILINEAR : NEAREST ); if ( !Pit[attr-FRONT]->LoadSuccess() ) { delete Pit[attr-FRONT]; Pit[attr-FRONT] = new VSSprite( (*iter).value.c_str(), cockpit_smooth ? BILINEAR : NEAREST ); } replaced[attr-FRONT] = true; if (oldpit) delete oldpit; break; } default: break; } } text = new TextPlane(); for (counter = 0; counter < 4; ++counter) if (!replaced[counter]) { delete Pit[counter]; Pit[counter] = NULL; } break; case UnitImages< void >::SHIELD4: case UnitImages< void >::SHIELD5: case UnitImages< void >::SHIELD6: case UnitImages< void >::SHIELD7: shield8 = true; goto pastarmor8; case UnitImages< void >::ARMOR4: case UnitImages< void >::ARMOR5: case UnitImages< void >::ARMOR6: case UnitImages< void >::ARMOR7: armor8 = true; pastarmor8: case UnitImages< void >::JUMP: case UnitImages< void >::MISSILELOCK: case UnitImages< void >::ECM: case UnitImages< void >::ARMORF: case UnitImages< void >::ARMORR: case UnitImages< void >::ARMORL: case UnitImages< void >::ARMORB: case UnitImages< void >::FUEL: case UnitImages< void >::SHIELDF: case UnitImages< void >::SHIELDL: case UnitImages< void >::SHIELDR: case UnitImages< void >::SHIELDB: case UnitImages< void >::TARGETSHIELDF: case UnitImages< void >::TARGETSHIELDB: case UnitImages< void >::TARGETSHIELDR: case UnitImages< void >::TARGETSHIELDL: case UnitImages< void >::ENERGY: case UnitImages< void >::WARPENERGY: case UnitImages< void >::EJECT: case UnitImages< void >::LOCK: case UnitImages< void >::HULL: case UnitImages< void >::KPS: case UnitImages< void >::SETKPS: case UnitImages< void >::AUTOPILOT: case UnitImages< void >::COLLISION: case UnitImages< void >::COCKPIT_FPS: case UnitImages< void >::WARPFIELDSTRENGTH: case UnitImages< void >::MASSEFFECT: case UnitImages< void >::AUTOPILOT_MODAL: case UnitImages< void >::SPEC_MODAL: case UnitImages< void >::FLIGHTCOMPUTER_MODAL: case UnitImages< void >::TURRETCONTROL_MODAL: case UnitImages< void >::ECM_MODAL: case UnitImages< void >::CLOAK_MODAL: case UnitImages< void >::TRAVELMODE_MODAL: case UnitImages< void >::RECIEVINGFIRE_MODAL: case UnitImages< void >::RECEIVINGMISSILES_MODAL: case UnitImages< void >::RECEIVINGMISSILELOCK_MODAL: case UnitImages< void >::RECEIVINGTARGETLOCK_MODAL: case UnitImages< void >::COLLISIONWARNING_MODAL: case UnitImages< void >::CANJUMP_MODAL: case UnitImages< void >::CANDOCK_MODAL: for (iter = attributes.begin(); iter != attributes.end(); iter++) { switch ( attribute_map.lookup( (*iter).name ) ) { case XFILE: gaugename = (*iter).value; break; case NETWORK: if ( (Network != NULL) != XMLSupport::parse_bool( (*iter).value ) ) return; //Don't show if not in multiplayer (or single if false) break; case TOPY: topy = XMLSupport::parse_float( (*iter).value ); break; case BOTY: boty = XMLSupport::parse_float( (*iter).value ); break; case LEFT: leftx = XMLSupport::parse_float( (*iter).value ); break; case RIGHT: rightx = XMLSupport::parse_float( (*iter).value ); break; case XSIZE: xsize = XMLSupport::parse_float( (*iter).value ); break; case YSIZE: ysize = XMLSupport::parse_float( (*iter).value ); break; case XCENT: xcent = XMLSupport::parse_float( (*iter).value ); break; case YCENT: ycent = XMLSupport::parse_float( (*iter).value ); break; case G_UP: tmpdir = Gauge::GAUGE_UP; break; case G_DOWN: tmpdir = Gauge::GAUGE_DOWN; break; case G_LEFT: tmpdir = Gauge::GAUGE_LEFT; break; case G_RIGHT: tmpdir = Gauge::GAUGE_RIGHT; break; case G_TIME: tmpdir = Gauge::GAUGE_TIME; break; } } gauges[elem] = new Gauge( gaugename.c_str(), tmpdir ); if (xsize != -1) gauges[elem]->SetSize( xsize, ysize ); if (xcent != FLT_MAX) gauges[elem]->SetPosition( xcent, ycent ); if (leftx != -10 && rightx != -10 && topy != -10 && boty != -10) { gauges[elem]->SetPosition( .5*(leftx+rightx), .5*(topy+boty) ); gauges[elem]->SetSize( fabs( leftx-rightx ), fabs( topy-boty ) ); } break; case CROSSHAIRS: case PANEL: if (elem == CROSSHAIRS) { if (Panel.size() == 0) Panel.push_back( NULL ); if ( Panel.front() ) { delete Panel.front(); Panel.front() = NULL; } newsprite = &Panel.front(); } else { if (Panel.size() == 0) /* Create NULL crosshairs */ Panel.push_back( NULL ); Panel.push_back( NULL ); newsprite = &Panel.back(); } goto loadsprite; case RADAR: newsprite = &radarSprites[0]; goto loadsprite; case REARRADAR: newsprite = &radarSprites[1]; goto loadsprite; case LVDU: vdu.push_back( NULL ); newvdu = &vdu.back(); mymodes = VDU::MANIFEST|VDU::WEAPON|VDU::DAMAGE|VDU::OBJECTIVES|VDU::SHIELD; default_mode = VDU::OBJECTIVES; #ifdef NETCOMM_WEBCAM mymodes = mymodes|VDU::WEBCAM; #endif if (Network != NULL) mymodes = mymodes|VDU::NETWORK; goto loadsprite; case RVDU: vdu.push_back( NULL ); newvdu = &vdu.back(); mymodes = VDU::TARGETMANIFEST|VDU::NAV|VDU::TARGET; default_mode = VDU::TARGET; goto loadsprite; case AVDU: vdu.push_back( NULL ); newvdu = &vdu.back(); mymodes = VDU::MSG; for (iter = attributes.begin(); iter != attributes.end(); iter++) { switch ( attribute_map.lookup( (*iter).name ) ) { case VDUTYPE: { mymodes = parse_vdu_type( (*iter).value.c_str() ); std::string firstmode = (*iter).value.substr( 0, (*iter).value.find( " " ) ); default_mode = parse_vdu_type( firstmode.c_str() ); break; } default: break; } } goto loadsprite; loadsprite: for (iter = attributes.begin(); iter != attributes.end(); iter++) { switch ( attribute_map.lookup( (*iter).name ) ) { case NETWORK: if ( (Network != NULL) != XMLSupport::parse_bool( (*iter).value ) ) return; //Don't show if not in multiplayer (or single if false) break; case XFILE: if (newsprite) { std::string tmp = getRes( (*iter).value ); bool bil = elem == PANEL ? panel_smooth : crosshair_smooth; (*newsprite) = new VSSprite( tmp.c_str(), bil ? BILINEAR : NEAREST ); if ( !(*newsprite)->LoadSuccess() ) { delete (*newsprite); (*newsprite) = new VSSprite( (*iter).value.c_str(), bil ? BILINEAR : NEAREST ); } adjsprite = *newsprite; } else if (newvdu) { VDU *tmp = new VDU( (*iter).value.c_str(), text, mymodes, rows, cols, &StartArmor[0], &maxhull ); (*newvdu) = tmp; adjsprite = *newvdu; if (tmp->getMode() != default_mode) { for (int i = 0; i < 32; ++i) { tmp->SwitchMode( NULL ); if (tmp->getMode() == default_mode) break; } } } break; case TOPY: topy = XMLSupport::parse_float( (*iter).value ); break; case BOTY: boty = XMLSupport::parse_float( (*iter).value ); break; case LEFT: leftx = XMLSupport::parse_float( (*iter).value ); break; case RIGHT: rightx = XMLSupport::parse_float( (*iter).value ); break; case XSIZE: xsize = XMLSupport::parse_float( (*iter).value ); break; case YSIZE: ysize = XMLSupport::parse_float( (*iter).value ); break; case XCENT: xcent = XMLSupport::parse_float( (*iter).value ); break; case YCENT: ycent = XMLSupport::parse_float( (*iter).value ); break; case ROWS: rows = XMLSupport::parse_int( (*iter).value ); break; case COLS: cols = XMLSupport::parse_int( (*iter).value ); break; break; } } if (adjsprite) { if (xsize != -1) adjsprite->SetSize( xsize, ysize ); if (xcent != FLT_MAX) adjsprite->SetPosition( xcent, ycent ); if (leftx != -10 && rightx != -10 && topy != -10 && boty != -10) { adjsprite->SetPosition( .5*(leftx+rightx), .5*(topy+boty) ); adjsprite->SetSize( fabs( leftx-rightx ), fabs( topy-boty ) ); } } else if ( newsprite == &Panel.back() ) { Panel.erase( Panel.end()-1 ); //don't want null panels } break; case EVENT: { std::string soundfile; bool looping = false; float gain = 1.0f; EVENTID event = Cockpit::NUM_EVENTS; for (iter = attributes.begin(); iter != attributes.end(); iter++) { switch ( attribute_map.lookup( (*iter).name ) ) { case SOUNDFILE: soundfile = (*iter).value; break; case LOOPING: looping = XMLSupport::parse_bool( (*iter).value ); break; case EVENT: event = (Cockpit::EVENTID) attribute_map.lookup( (*iter).value ); break; case GAIN: gain = XMLSupport::parse_float( (*iter).value ); break; default: break; } } if (!soundfile.empty() && (event > 0) && (event < Cockpit::NUM_EVENTS)) { SetSoundForEvent(event, SoundContainer(soundfile, looping, gain)); } } break; default: break; } }