mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-30 17:00:05 +00:00 
			
		
		
		
	Add location icon to overlay layer
This commit is contained in:
		
							parent
							
								
									c91b1c9a65
								
							
						
					
					
						commit
						9590e2cc52
					
				
					 1 changed files with 71 additions and 1 deletions
				
			
		|  | @ -1,5 +1,8 @@ | |||
| #include <scwx/qt/map/overlay_layer.hpp> | ||||
| #include <scwx/qt/gl/draw/geo_icons.hpp> | ||||
| #include <scwx/qt/gl/draw/rectangle.hpp> | ||||
| #include <scwx/qt/manager/position_manager.hpp> | ||||
| #include <scwx/qt/types/texture_types.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| #include <scwx/util/time.hpp> | ||||
| 
 | ||||
|  | @ -10,6 +13,7 @@ | |||
| #endif | ||||
| 
 | ||||
| #include <imgui.h> | ||||
| #include <QGeoPositionInfo> | ||||
| 
 | ||||
| #if !defined(_MSC_VER) | ||||
| #   include <date/date.h> | ||||
|  | @ -34,13 +38,24 @@ class OverlayLayerImpl | |||
| public: | ||||
|    explicit OverlayLayerImpl(std::shared_ptr<MapContext> context) : | ||||
|        activeBoxOuter_ {std::make_shared<gl::draw::Rectangle>(context)}, | ||||
|        activeBoxInner_ {std::make_shared<gl::draw::Rectangle>(context)} | ||||
|        activeBoxInner_ {std::make_shared<gl::draw::Rectangle>(context)}, | ||||
|        icons_ {std::make_shared<gl::draw::GeoIcons>(context)}, | ||||
|        locationIconName_ { | ||||
|           types::GetTextureName(types::ImageTexture::Crosshairs32)} | ||||
|    { | ||||
|    } | ||||
|    ~OverlayLayerImpl() = default; | ||||
| 
 | ||||
|    std::shared_ptr<manager::PositionManager> positionManager_ { | ||||
|       manager::PositionManager::Instance()}; | ||||
|    QGeoPositionInfo currentPosition_ {}; | ||||
| 
 | ||||
|    std::shared_ptr<gl::draw::Rectangle> activeBoxOuter_; | ||||
|    std::shared_ptr<gl::draw::Rectangle> activeBoxInner_; | ||||
|    std::shared_ptr<gl::draw::GeoIcons>  icons_; | ||||
| 
 | ||||
|    const std::string&                         locationIconName_; | ||||
|    std::shared_ptr<gl::draw::GeoIconDrawItem> locationIcon_ {}; | ||||
| 
 | ||||
|    std::string sweepTimeString_ {}; | ||||
|    bool        sweepTimeNeedsUpdate_ {true}; | ||||
|  | @ -52,6 +67,7 @@ OverlayLayer::OverlayLayer(std::shared_ptr<MapContext> context) : | |||
| { | ||||
|    AddDrawItem(p->activeBoxOuter_); | ||||
|    AddDrawItem(p->activeBoxInner_); | ||||
|    AddDrawItem(p->icons_); | ||||
| 
 | ||||
|    p->activeBoxOuter_->SetPosition(0.0f, 0.0f); | ||||
| } | ||||
|  | @ -73,6 +89,42 @@ void OverlayLayer::Initialize() | |||
|               this, | ||||
|               &OverlayLayer::UpdateSweepTimeNextFrame); | ||||
|    } | ||||
| 
 | ||||
|    p->currentPosition_ = p->positionManager_->position(); | ||||
|    auto coordinate     = p->currentPosition_.coordinate(); | ||||
| 
 | ||||
|    p->icons_->StartIconSheets(); | ||||
|    p->icons_->AddIconSheet(p->locationIconName_); | ||||
|    p->icons_->FinishIconSheets(); | ||||
| 
 | ||||
|    p->icons_->StartIcons(); | ||||
|    p->locationIcon_ = p->icons_->AddIcon(); | ||||
|    gl::draw::GeoIcons::SetIconTexture( | ||||
|       p->locationIcon_, p->locationIconName_, 0); | ||||
|    gl::draw::GeoIcons::SetIconLocation( | ||||
|       p->locationIcon_, coordinate.latitude(), coordinate.longitude()); | ||||
|    p->icons_->FinishIcons(); | ||||
| 
 | ||||
|    connect(p->positionManager_.get(), | ||||
|            &manager::PositionManager::LocationTrackingChanged, | ||||
|            this, | ||||
|            [this]() { Q_EMIT NeedsRendering(); }); | ||||
|    connect(p->positionManager_.get(), | ||||
|            &manager::PositionManager::PositionUpdated, | ||||
|            this, | ||||
|            [this](const QGeoPositionInfo& position) | ||||
|            { | ||||
|               auto coordinate = position.coordinate(); | ||||
|               if (position.isValid() && | ||||
|                   p->currentPosition_.coordinate() != coordinate) | ||||
|               { | ||||
|                  gl::draw::GeoIcons::SetIconLocation(p->locationIcon_, | ||||
|                                                      coordinate.latitude(), | ||||
|                                                      coordinate.longitude()); | ||||
|                  Q_EMIT NeedsRendering(); | ||||
|               } | ||||
|               p->currentPosition_ = position; | ||||
|            }); | ||||
| } | ||||
| 
 | ||||
| void OverlayLayer::Render( | ||||
|  | @ -85,6 +137,9 @@ void OverlayLayer::Render( | |||
| 
 | ||||
|    context()->set_render_parameters(params); | ||||
| 
 | ||||
|    // Set OpenGL blend mode for transparency
 | ||||
|    gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||
| 
 | ||||
|    p->sweepTimePicked_ = false; | ||||
| 
 | ||||
|    if (p->sweepTimeNeedsUpdate_ && radarProductView != nullptr) | ||||
|  | @ -117,6 +172,10 @@ void OverlayLayer::Render( | |||
|       p->activeBoxInner_->SetBorder(1.0f * pixelRatio, {255, 255, 255, 255}); | ||||
|    } | ||||
| 
 | ||||
|    // Location Icon
 | ||||
|    p->icons_->SetVisible(p->currentPosition_.isValid() && | ||||
|                          p->positionManager_->IsLocationTracked()); | ||||
| 
 | ||||
|    DrawLayer::Render(params); | ||||
| 
 | ||||
|    if (radarProductView != nullptr) | ||||
|  | @ -198,6 +257,17 @@ void OverlayLayer::Deinitialize() | |||
|                  this, | ||||
|                  &OverlayLayer::UpdateSweepTimeNextFrame); | ||||
|    } | ||||
| 
 | ||||
|    disconnect(p->positionManager_.get(), | ||||
|               &manager::PositionManager::LocationTrackingChanged, | ||||
|               this, | ||||
|               nullptr); | ||||
|    disconnect(p->positionManager_.get(), | ||||
|               &manager::PositionManager::PositionUpdated, | ||||
|               this, | ||||
|               nullptr); | ||||
| 
 | ||||
|    p->locationIcon_ = nullptr; | ||||
| } | ||||
| 
 | ||||
| bool OverlayLayer::RunMousePicking( | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat