[Gcblue-commits] gcb_wx/src/graphics tcMPGameView.cpp,NONE,1.1 tcGameView.cpp,1.18,1.19 tcMapView.cp
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2006-05-04 22:47:30
|
Update of /cvsroot/gcblue/gcb_wx/src/graphics In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15842a/src/graphics Modified Files: tcGameView.cpp tcMapView.cpp tcPlatformGui.cpp Added Files: tcMPGameView.cpp Log Message: Index: tcMapView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcMapView.cpp,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** tcMapView.cpp 23 Mar 2006 01:11:02 -0000 1.44 --- tcMapView.cpp 4 May 2006 22:47:26 -0000 1.45 *************** *** 2,6 **** ** @file tcMapView.cpp */ ! /* Copyright (C) 2003-2005 Dewitt Colclough (de...@gc...) ** All rights reserved. --- 2,6 ---- ** @file tcMapView.cpp */ ! /* Copyright (C) 2003-2006 Dewitt Colclough (de...@gc...) ** All rights reserved. *************** *** 31,34 **** --- 31,35 ---- #include "aerror.h" #include "mapsymbols.h" + #include "nsNav.h" #include "simmath.h" #include "tcSound.h" // this causes tcTacticalMapView to vanish from class browser in some positions !? *************** *** 175,178 **** --- 176,188 ---- return pscreen; } + + tcPoint tcMapView::GeoToScreen(double afLon, double afLat) + { + tcPoint pscreen; + pscreen.x = (afLon - mfLonCenter)*mfScaleX_pelprad + mnXCenter; + pscreen.y = (-afLat + mfLatCenter)*mfScaleY_pelprad + mnYCenter; + return pscreen; + } + /***********************************************************************************/ float tcMapView::GeoExtentToScreen(float afExtent_rad) *************** *** 277,291 **** void tcMapView::SetView(tcPoint center, float afLonSpan) { - float fLatSpan; - float fMaxLonSpan, fMaxLatSpan; - tcGeoRect newview; - if (center.x < -C_PI) {center.x += C_TWOPI;} else if (center.x >= C_PI) {center.x -= C_TWOPI;} ! fMaxLonSpan = mrectViewBounds.Width(); ! fMaxLatSpan = mrectViewBounds.Height(); if (afLonSpan > fMaxLonSpan) {afLonSpan = fMaxLonSpan;} ! fLatSpan = afLonSpan*mnHeight/mnWidth; if (fLatSpan > fMaxLatSpan) { --- 287,297 ---- void tcMapView::SetView(tcPoint center, float afLonSpan) { if (center.x < -C_PI) {center.x += C_TWOPI;} else if (center.x >= C_PI) {center.x -= C_TWOPI;} ! float fMaxLonSpan = mrectViewBounds.Width(); ! float fMaxLatSpan = mrectViewBounds.Height(); if (afLonSpan > fMaxLonSpan) {afLonSpan = fMaxLonSpan;} ! float fLatSpan = afLonSpan*mnHeight/mnWidth; if (fLatSpan > fMaxLatSpan) { *************** *** 293,297 **** --- 299,311 ---- afLonSpan = fLatSpan*mnWidth/mnHeight; } + + float minLatSpan = 100.0f * C_MTORAD; // limit zoom to 100 m over height of view + if (fLatSpan < minLatSpan) + { + fLatSpan = minLatSpan; + afLonSpan = fLatSpan*mnWidth/mnHeight; + } + tcGeoRect newview; newview.Set(center.x - 0.5f*afLonSpan, center.x + 0.5f*afLonSpan, center.y - 0.5f*fLatSpan, center.y + 0.5f*fLatSpan); *************** *** 364,374 **** tcMapView::~tcMapView() { ! /* ! if (mpPen != NULL) {delete mpPen;} ! if (mpPenThin != NULL) {delete mpPenThin;} ! if (mpFont != NULL) {delete mpFont;} ! if (mpFontSmall != NULL) {delete mpFontSmall;} ! if (mpBrush != NULL) {delete mpBrush;} ! */ } --- 378,382 ---- tcMapView::~tcMapView() { ! } *************** *** 377,381 **** --- 385,401 ---- /**************************************************************/ + void tcTacticalMapView::ActivateCmd(teMapCmdType aeCmd) + { + mbMapCmdActive = true; + meMapCmd = aeCmd; + + mapCommandStartLocation = mpointMouse; + } + void tcTacticalMapView::DeactivateCmd() + { + mbMapCmdActive = false; + meMapCmd = MC_NONE; + } /** *************** *** 407,411 **** if (mfGridSize_rad == 0) {return;} ! osg::Vec4 color(0.69, 0.69, 0.69, 1.0); // change this to set range based on what will cover the screen as well --- 427,431 ---- if (mfGridSize_rad == 0) {return;} ! osg::Vec4 color(0.69, 0.69, 0.69, 0.5); // change this to set range based on what will cover the screen as well *************** *** 546,549 **** --- 566,572 ---- DrawLineR(x-8, y+8, x+8, y-8, color); break; + case MC_RANGE: + DrawMapCmdRange(); + break; default: break; *************** *** 552,555 **** --- 575,632 ---- /** + * Draw circle (ellipse on screen) of constant range. If no object is hooked, center is + * the mouse position when command was activated. Otherwise the center is the location of + * the hooked object. Heading and range are relative to current mouse position. + */ + void tcTacticalMapView::DrawMapCmdRange() + { + bool isObjectHooked = hookedId.size() > 0; + tcPoint pCenter; + tcPoint screenCenter; // in screen coordinates + if (isObjectHooked) + { + pCenter.x = mfHookLon; + pCenter.y = mfHookLat; + screenCenter = GeoToScreen(pCenter); + } + else + { + pCenter = ScreenToGeo(mapCommandStartLocation); + screenCenter.x = float(mapCommandStartLocation.x); + screenCenter.y = float(mapCommandStartLocation.y); + } + + tcPoint pCurrent = ScreenToGeo(mpointMouse); + float range_rad = nsNav::GCDistanceApprox_rad(pCenter.y, pCenter.x, pCurrent.y, pCurrent.x); + float bearing_rad = nsNav::GCHeadingApprox_rad(pCenter.y, pCenter.x, pCurrent.y, pCurrent.x); + if (bearing_rad < 0) bearing_rad += C_TWOPI; // force 0 - 360 format + + float ellipseHeight = GeoExtentToScreen(2.0f * range_rad); + float ellipseWidth = GeoExtentToScreen(2.0f * range_rad / cosf(pCenter.y)); + + // draw ellipse from center passing through current with latitude based eccentricity + osg::Vec4 lineColor(1.0f, 1.0f, 1.0f, 0.8f); + osg::Geometry* rangeCircle = CreatePieGeometry(ellipseWidth, ellipseHeight, -180, 180, lineColor, FILL_OFF); + DrawGeometryR(rangeCircle, screenCenter.x, screenCenter.y); + + // draw line from center to current + DrawLineR(screenCenter.x, screenCenter.y, mpointMouse.x, mpointMouse.y, lineColor); + + // draw text with range and bearing info + osg::Vec4 fontColor(1.0f, 1.0f, 1.0f, 0.9f); + float range_km = C_RADTOKM * range_rad; + wxString s; + s.Printf("%.0f km %.0f deg", range_km, C_180OVERPI * bearing_rad); + + // draw text halfway between center and current mouse pos + float xtext = 0.5f * (screenCenter.x + float(mpointMouse.x)); + float ytext = 0.5f * (screenCenter.y + float(mpointMouse.y)); + + DrawTextR(s.c_str(), xtext, ytext, + defaultFont.get(), fontColor, 12.0, CENTER_CENTER); + + } + + /** * */ *************** *** 671,675 **** /*** Draw grid ***/ ! //DrawGrid(); // disabled until the terrain view graphics are ported to OSG /*** Draw scale bar ***/ --- 748,752 ---- /*** Draw grid ***/ ! DrawGrid(); // disabled until the terrain view graphics are ported to OSG /*** Draw scale bar ***/ *************** *** 851,854 **** --- 928,936 ---- } + bool tcTacticalMapView::IsMapCmdActive() const + { + return mbMapCmdActive != 0; + } + /** * Creates default osg::Geometry object for symbol *************** *** 1752,1756 **** pMO->mbFocus = (IsHooked(pMO->mnID)) && (type != SYMBOL_SENSOR); ! if (mbMapCmdActive && (pMO->mbFocus) && (IsFirstHook(pMO->mnID))) { mfHookLat = pMO->mfLat; // refactor --- 1834,1838 ---- pMO->mbFocus = (IsHooked(pMO->mnID)) && (type != SYMBOL_SENSOR); ! if (pMO->mbFocus && IsFirstHook(pMO->mnID)) { mfHookLat = pMO->mfLat; // refactor *************** *** 2293,2297 **** long mnID; ! if (mpCommandInterface == NULL) {return;} switch (meMapCmd) --- 2375,2379 ---- long mnID; ! if (mpCommandInterface == 0) return; switch (meMapCmd) *************** *** 2328,2331 **** --- 2410,2414 ---- break; default: + meMapCmd = MC_NONE; mbMapCmdActive = false; break; *************** *** 2573,2587 **** void tcTacticalMapView::OnMouseWheel(wxMouseEvent& event) { ! wxPoint point(mnXCenter, mnYCenter); // zoom on center regardless of pointer pos int zDelta = event.GetWheelRotation(); if (zDelta > 0) { ! SetViewCenterZoom(point,2.0f); tcSound::Get()->PlayEffect("Beep2"); } else if (zDelta < 0) { ! SetViewCenterZoom(point,0.5f); tcSound::Get()->PlayEffect("Beep2"); } --- 2656,2683 ---- void tcTacticalMapView::OnMouseWheel(wxMouseEvent& event) { ! // if object is hooked zoom on that position, otherwise zoom on center ! wxPoint zoomPoint; ! if (hookedId.size() > 0) ! { ! tcPoint hookScreen = GeoToScreen(mfHookLon, mfHookLat); ! zoomPoint.x = int(hookScreen.x); ! zoomPoint.y = int(hookScreen.y); ! } ! else ! { ! zoomPoint.x = mnXCenter; ! zoomPoint.y = mnYCenter; ! } ! int zDelta = event.GetWheelRotation(); if (zDelta > 0) { ! SetViewCenterZoom(zoomPoint, 2.0f); tcSound::Get()->PlayEffect("Beep2"); } else if (zDelta < 0) { ! SetViewCenterZoom(zoomPoint, 0.5f); tcSound::Get()->PlayEffect("Beep2"); } *************** *** 2706,2710 **** scrollActive(false), lastScrollTime(0), ! scrollDirection(0.0) { --- 2802,2808 ---- scrollActive(false), lastScrollTime(0), ! scrollDirection(0.0), ! mfHookLat(0), ! mfHookLon(0) { Index: tcGameView.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcGameView.cpp,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** tcGameView.cpp 23 Mar 2006 01:11:02 -0000 1.18 --- tcGameView.cpp 4 May 2006 22:47:26 -0000 1.19 *************** *** 1,6 **** /* ! ** tcGameView.cpp ! ** ! ** Copyright (C) 2003 Dewitt Colclough (de...@gc...) ** All rights reserved. --- 1,6 ---- /* ! ** @file tcGameView.cpp ! */ ! /* Copyright (C) 2003-2006 Dewitt Colclough (de...@gc...) ** All rights reserved. *************** *** 148,153 **** { GeoPoint pcurrent; ! pcurrent.mfLon_rad = (float)platformObj->mcKin.mfLon_rad; ! pcurrent.mfLat_rad = (float)platformObj->mcKin.mfLat_rad; pcurrent.mfAlt_m = platformObj->mcKin.mfAlt_m; navpoints.push_back(pcurrent); // add current position --- 148,153 ---- { GeoPoint pcurrent; ! pcurrent.mfLon_rad = platformObj->mcKin.mfLon_rad; ! pcurrent.mfLat_rad = platformObj->mcKin.mfLat_rad; pcurrent.mfAlt_m = platformObj->mcKin.mfAlt_m; navpoints.push_back(pcurrent); // add current position *************** *** 625,630 **** mpMapView->maMapObj[rnIndex].meSymbol = GetMapSymbolByClassification(pdata->mnType); mpMapView->maMapObj[rnIndex].meAffiliation = aeAffiliation; ! mpMapView->maMapObj[rnIndex].mfLon = (float)po->mcKin.mfLon_rad; ! mpMapView->maMapObj[rnIndex].mfLat = (float)po->mcKin.mfLat_rad; mpMapView->maMapObj[rnIndex].mnID = po->mnID; mpMapView->maMapObj[rnIndex].mnColor = 0; --- 625,630 ---- mpMapView->maMapObj[rnIndex].meSymbol = GetMapSymbolByClassification(pdata->mnType); mpMapView->maMapObj[rnIndex].meAffiliation = aeAffiliation; ! mpMapView->maMapObj[rnIndex].mfLon = po->mcKin.mfLon_rad; ! mpMapView->maMapObj[rnIndex].mfLat = po->mcKin.mfLat_rad; mpMapView->maMapObj[rnIndex].mnID = po->mnID; mpMapView->maMapObj[rnIndex].mnColor = 0; *************** *** 655,660 **** mpWorldMapView->maMapObj[rnWorldIdx].mbExists = 1; mpWorldMapView->maMapObj[rnWorldIdx].mnColor = nColor; ! mpWorldMapView->maMapObj[rnWorldIdx].mfLon = (float)po->mcKin.mfLon_rad; ! mpWorldMapView->maMapObj[rnWorldIdx].mfLat = (float)po->mcKin.mfLat_rad; mpWorldMapView->maMapObj[rnWorldIdx].mnID = po->mnID; mpWorldMapView->maMapObj[rnWorldIdx].meAffiliation = aeAffiliation; --- 655,660 ---- mpWorldMapView->maMapObj[rnWorldIdx].mbExists = 1; mpWorldMapView->maMapObj[rnWorldIdx].mnColor = nColor; ! mpWorldMapView->maMapObj[rnWorldIdx].mfLon = po->mcKin.mfLon_rad; ! mpWorldMapView->maMapObj[rnWorldIdx].mfLat = po->mcKin.mfLat_rad; mpWorldMapView->maMapObj[rnWorldIdx].mnID = po->mnID; mpWorldMapView->maMapObj[rnWorldIdx].meAffiliation = aeAffiliation; Index: tcPlatformGui.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/graphics/tcPlatformGui.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** tcPlatformGui.cpp 23 Mar 2006 01:11:02 -0000 1.8 --- tcPlatformGui.cpp 4 May 2006 22:47:26 -0000 1.9 *************** *** 69,73 **** item->SetIcon(icon); ! item->SetId(child->mnKey); std::string itemName = child->mzClass.mz; --- 69,77 ---- item->SetIcon(icon); ! /* Changed to make id unique within platform gui so that ! ** correct item is unloaded. May have bad side effects. ! */ ! long itemId = (child->mnKey << 8) + launcherIdx; ! item->SetId(itemId); std::string itemName = child->mzClass.mz; --- NEW FILE: tcMPGameView.cpp --- /** ** @file tcMPGameView.cpp */ /* Copyright (C) 2006 Dewitt Colclough (de...@gc...) ** All rights reserved. ** This file is part of the Global Conflict Blue (GCB) program. ** GCB is free software; you can redistribute it and/or modify ** it under the terms of version 2 of the GNU General Public License as ** published by the Free Software Foundation. ** GCB is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** You should have received a copy of the GNU General Public License ** along with GCB; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "stdwx.h" #ifndef WX_PRECOMP #include "wx/wx.h" #endif #include "tcMPGameView.h" #include "tcButton.h" #include "tcEditBox.h" #include "tcConsoleBox.h" #include "common/tinyxml.h" #include "network/tcMultiplayerInterface.h" #include "wxcommands.h" #include "tcSimState.h" #include "common/tcOptions.h" #include "tcUserInfo.h" BEGIN_EVENT_TABLE(tcMPGameView, tcXmlWindow) EVT_COMMAND(2, wxEVT_COMMAND_TEXT_UPDATED, tcMPGameView::SendChatText) END_EVENT_TABLE() #ifdef _DEBUG #define new DEBUG_NEW #endif using network::tcMultiplayerInterface; void tcMPGameView::Draw() { DrawChildren(); HideUnusedObjects(); } void tcMPGameView::OnLButtonDown(wxMouseEvent& event) { } /** * Send chat text to all connections */ void tcMPGameView::SendChatText(wxCommandEvent& event) { tcMultiplayerInterface* multiplayerInterface = tcMultiplayerInterface::Get(); bool isServer = multiplayerInterface->IsServer(); std::string chatText = event.GetString().c_str(); if (isServer && (multiplayerInterface->IsCommand(chatText))) { chatBox->Print(chatText.c_str()); multiplayerInterface->ProcessCommandServer(chatText); return; } /* prepend name tag if server, this is done for clients by server, server has ** to do tagging itself */ if (isServer) { chatText = std::string("<") + multiplayerInterface->GetName() + std::string("> ") + chatText; } tcMultiplayerInterface::Get()->BroadcastChatText(chatText); // if server, print chat text locally since no echo comes back if (isServer) { chatBox->Print(chatText.c_str()); } } /** * @param surfaceHost tcWindow to share surface of */ tcMPGameView::tcMPGameView(wxWindow *parent, const wxPoint& pos, const wxSize& size, const wxString& name) : tcXmlWindow(parent, pos, size, "xml/mpgame_view.xml", name) { LoadBackgroundImage("background.jpg"); if (config) { // AddXMLControls(); } else { fprintf(stderr, "tcMPGameView::tcMPGameView - NULL xml config node\n"); return; } TiXmlNode* root = config->FirstChild("Window"); if (!root) { fprintf(stderr, "tcMPGameView::tcMPGameView - Missing top level <Window> tag\n"); return; } // add chat text console TiXmlNode* current = root->FirstChild("ChatBox"); chatBox = new tcConsoleBox(this, current); chatBox->SetBackgroundColor(osg::Vec4(0, 0, 0, 1)); chatBox->SetBackgroundDraw(true); chatBox->SetActive(true); tcMultiplayerInterface::Get()->AddChatSubscriber(chatBox); // add chat text edit box current = root->FirstChild("ChatEntry"); chatEntry = new tcEditBox(this, current); chatEntry->SetActive(true); chatEntry->SetCommand(2); chatEntry->SetClearOnReturn(true); chatEntry->SetBuffer(""); } tcMPGameView::~tcMPGameView() { } |