Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extended mapping #467

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
50 changes: 46 additions & 4 deletions src/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ set(src__components
"components/StandardButtons.h"
"components/TitleBar.cpp"
"components/TitleBar.h"
components/CollapsibleWindowTitleBar.cpp components/CollapsibleWindowTitleBar.h)
components/CollapsibleWindowTitleBar.cpp components/CollapsibleWindowTitleBar.h components/Title.cpp components/Title.h components/Checkbox.cpp components/Checkbox.h components/Scrollbar.cpp components/Scrollbar.h components/ScrollbarFactory.cpp components/ScrollbarFactory.h components/ScrollbarClickspot.cpp components/ScrollbarClickspot.h components/ScrollbarOptions.cpp components/ScrollbarOptions.h components/ScrollableCheckboxes.cpp components/ScrollableCheckboxes.h components/CheckboxProviderInterface.cpp components/CheckboxProviderInterface.h)
source_group("src\\components" FILES ${src__components})

set(src__controller
Expand Down Expand Up @@ -256,15 +256,15 @@ set(src__flightrule
source_group("src\\flightrule" FILES ${src__flightrule})

set(src__geometry
geometry/Line.cpp geometry/Line.h geometry/DistanceRadiusToScreenRadius.cpp geometry/DistanceRadiusToScreenRadius.h)
geometry/Line.cpp geometry/Line.h geometry/DistanceRadiusToScreenRadius.cpp geometry/DistanceRadiusToScreenRadius.h geometry/RectangleFunctions.cpp geometry/RectangleFunctions.h)
source_group("src\\geometry" FILES ${src__geometry})

set(src__graphics
"graphics/GdiGraphicsInterface.h"
"graphics/GdiGraphicsWrapper.cpp"
"graphics/GdiGraphicsWrapper.h"
"graphics/GdiplusBrushes.h"
graphics/FontManager.cpp graphics/FontManager.h graphics/StringFormatManager.cpp graphics/StringFormatManager.h)
graphics/FontManager.cpp graphics/FontManager.h graphics/StringFormatManager.cpp graphics/StringFormatManager.h graphics/DrawTriangle.cpp graphics/DrawTriangle.h)
source_group("src\\graphics" FILES ${src__graphics})

set(src__handoff
Expand Down Expand Up @@ -487,6 +487,42 @@ set(src__login
)
source_group("src\\login" FILES ${src__login})

set(src__mapping
mapping/MappingElement.cpp mapping/MappingElement.h
mapping/MappingElementInterface.h
mapping/MappingElementDrawer.h
mapping/DisplayRule.h
mapping/VisualReferencePoint.cpp mapping/VisualReferencePoint.h
mapping/MappingElementManager.cpp mapping/MappingElementManager.h
mapping/MappingElementManagerFactory.cpp mapping/MappingElementManagerFactory.h
mapping/MappingModuleFactory.cpp mapping/MappingModuleFactory.h
mapping/MappingBootstrapProvider.cpp mapping/MappingBootstrapProvider.h
mapping/MappingRenderer.cpp mapping/MappingRenderer.h
mapping/MappingOptionsRenderer.cpp mapping/MappingOptionsRenderer.h
mapping/MappingRenderOptions.cpp mapping/MappingRenderOptions.h
mapping/ToggleMappingOptionsRender.cpp mapping/ToggleMappingOptionsRender.h
mapping/VisualReferencePointShouldRender.cpp mapping/VisualReferencePointShouldRender.h
mapping/RelatedAirfieldProvider.h
mapping/RelatedAirfield.cpp mapping/RelatedAirfield.h
mapping/VisualReferencePointRelatedAirfieldProvider.cpp mapping/VisualReferencePointRelatedAirfieldProvider.h
mapping/MappingElementDrawerFactoryDelegator.cpp mapping/MappingElementDrawerFactoryDelegator.h
mapping/MappingElementFactory.h
mapping/MappingElementDrawerFactory.h
mapping/VisualReferencePointDrawerFactory.cpp mapping/VisualReferencePointDrawerFactory.h
mapping/ShowsVisualReferencePoints.cpp mapping/ShowsVisualReferencePoints.h
mapping/RelatedAirfieldProviderFactory.cpp mapping/RelatedAirfieldProviderFactory.h
mapping/MappingElementFactory.cpp
mapping/DisplayRuleFactoryInterface.h
mapping/DisplayRuleTypeDelegatorFactory.cpp mapping/DisplayRuleTypeDelegatorFactory.h
mapping/DisplayRuleElementTypeDelegatorFactory.cpp mapping/DisplayRuleElementTypeDelegatorFactory.h
mapping/DisplayRuleFactoryFactory.cpp mapping/DisplayRuleFactoryFactory.h
mapping/VisualReferencePointRelatedAirfieldFactory.cpp mapping/VisualReferencePointRelatedAirfieldFactory.h
mapping/DisplayRulesetFactory.cpp mapping/DisplayRulesetFactory.h
mapping/DisplayRulesetFactoryInterface.h
mapping/DisplayRulesetAggregatorFactory.cpp mapping/DisplayRulesetAggregatorFactory.h
mapping/VisualReferencePointDefaultDisplayRulesetFactory.cpp mapping/VisualReferencePointDefaultDisplayRulesetFactory.h mapping/DefaultDisplayRulesetDelegatorFactory.cpp mapping/DefaultDisplayRulesetDelegatorFactory.h mapping/DisplayRulesetFactoryFactory.cpp mapping/DisplayRulesetFactoryFactory.h mapping/MappingElementDrawerFactoryFactory.cpp mapping/MappingElementDrawerFactoryFactory.h mapping/MappingElementTypes.cpp mapping/MappingElementTypes.h mapping/MappingRenderOptionsAsrLoader.cpp mapping/MappingRenderOptionsAsrLoader.h mapping/VisualReferencePointCheckboxProvider.cpp mapping/VisualReferencePointCheckboxProvider.h)
source_group("src\\mapping" FILES ${src__mapping})

set(src__message
"message/MessageSerializableInterface.h"
"message/UserMessager.cpp"
Expand Down Expand Up @@ -740,7 +776,7 @@ set(src__radarscreen
"radarscreen/ScreenControlsBootstrap.h"
"radarscreen/UKRadarScreen.cpp"
"radarscreen/UKRadarScreen.h"
radarscreen/RadarRenderableInterface.cpp radarscreen/ConfigurableDisplayInterface.cpp radarscreen/MenuToggleableDisplayInterface.h radarscreen/ToggleDisplayFromMenu.cpp radarscreen/ToggleDisplayFromMenu.h radarscreen/MenuToggleableDisplayFactory.cpp radarscreen/MenuToggleableDisplayFactory.h)
radarscreen/RadarRenderableInterface.cpp radarscreen/ConfigurableDisplayInterface.cpp radarscreen/MenuToggleableDisplayInterface.h radarscreen/ToggleDisplayFromMenu.cpp radarscreen/ToggleDisplayFromMenu.h radarscreen/MenuToggleableDisplayFactory.cpp radarscreen/MenuToggleableDisplayFactory.h radarscreen/ScreenObjectInterface.cpp radarscreen/ScreenObjectInterface.h)
source_group("src\\radarscreen" FILES ${src__radarscreen})

set(src__regional
Expand Down Expand Up @@ -965,6 +1001,7 @@ set(ALL_FILES
${src__intention}
${src__list}
${src__login}
${src__mapping}
${src__message}
${src__metar}
${src__minstack}
Expand Down Expand Up @@ -994,6 +1031,11 @@ set(ALL_FILES
${src__timer}
${src__wake})

################################################################################
# Source Files
################################################################################
set_source_files_properties(ALL_FILES PROPERTIES COMPILE_FLAGS "-include pch/pch.h")

################################################################################
# Target
################################################################################
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/bootstrap/BootstrapProviderCollectionFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "BootstrapProviderCollection.h"
#include "BootstrapProviderCollectionFactory.h"
#include "approach/ApproachBootstrapProvider.h"
#include "mapping/MappingBootstrapProvider.h"

namespace UKControllerPlugin::Bootstrap {
auto Make() -> std::unique_ptr<BootstrapProviderCollection>
{
auto collection = std::make_unique<BootstrapProviderCollection>();
collection->AddProvider(std::make_unique<Approach::ApproachBootstrapProvider>());
collection->AddProvider(std::make_unique<Mapping::MappingBootstrapProvider>());

return collection;
}
Expand Down
11 changes: 11 additions & 0 deletions src/plugin/bootstrap/ModuleFactories.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "ModuleFactories.h"
#include "approach/ApproachModuleFactory.h"
#include "mapping/MappingModuleFactory.h"

namespace UKControllerPlugin::Bootstrap {

ModuleFactories::ModuleFactories() = default;
ModuleFactories::~ModuleFactories() = default;

auto ModuleFactories::Approach() -> Approach::ApproachModuleFactory&
Expand All @@ -13,4 +15,13 @@ namespace UKControllerPlugin::Bootstrap {

return *approach;
}

auto ModuleFactories::Mapping() -> Mapping::MappingModuleFactory&
{
if (!mapping) {
mapping = std::make_unique<Mapping::MappingModuleFactory>();
}

return *mapping;
}
} // namespace UKControllerPlugin::Bootstrap
8 changes: 8 additions & 0 deletions src/plugin/bootstrap/ModuleFactories.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ namespace UKControllerPlugin {
namespace Approach {
class ApproachModuleFactory;
} // namespace Approach
namespace Mapping {
class MappingModuleFactory;
} // namespace Mapping
} // namespace UKControllerPlugin

namespace UKControllerPlugin::Bootstrap {
Expand All @@ -17,11 +20,16 @@ namespace UKControllerPlugin::Bootstrap {
class ModuleFactories
{
public:
ModuleFactories();
~ModuleFactories();
[[nodiscard]] auto Approach() -> Approach::ApproachModuleFactory&;
[[nodiscard]] auto Mapping() -> Mapping::MappingModuleFactory&;

private:
// The approach module
std::unique_ptr<Approach::ApproachModuleFactory> approach;

// The mapping module
std::unique_ptr<Mapping::MappingModuleFactory> mapping;
};
} // namespace UKControllerPlugin::Bootstrap
79 changes: 79 additions & 0 deletions src/plugin/components/Checkbox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "Checkbox.h"
#include "CheckboxProviderInterface.h"
#include "ClickableArea.h"
#include "graphics/FontManager.h"
#include "graphics/GdiGraphicsInterface.h"
#include "graphics/StringFormatManager.h"
#include "helper/HelperFunctions.h"

namespace UKControllerPlugin::Components {

Checkbox::Checkbox(std::shared_ptr<CheckboxProviderInterface> provider, int screenObjectId)
: provider(provider), screenObjectId(screenObjectId),
pen(std::make_shared<Gdiplus::Pen>(Gdiplus::Color(255, 255, 255))),
brush(std::make_shared<Gdiplus::SolidBrush>(Gdiplus::Color(255, 255, 255))),
clickableArea(ClickableArea::Create(
Gdiplus::Rect(area.GetLeft(), area.GetTop(), labelArea.GetRight() - area.GetLeft(), labelArea.Height),
screenObjectId,
"checkbox" + provider->Label(),
false)),
font(Graphics::FontManager::Instance().GetDefault()),
stringFormat(Graphics::StringFormatManager::Instance().GetLeftAlign())
{
}

auto Checkbox::Create(std::shared_ptr<CheckboxProviderInterface> provider, int screenObjectId)
-> std::shared_ptr<Checkbox>
{
return std::shared_ptr<Checkbox>(new Checkbox(provider, screenObjectId));
}

auto Checkbox::Checked(bool checked) -> std::shared_ptr<Checkbox>
{
this->checked = checked;
return shared_from_this();
}

void Checkbox::Draw(
Windows::GdiGraphicsInterface& graphics, Euroscope::EuroscopeRadarLoopbackInterface& radarScreen) const
{
// Draw the border
graphics.DrawRect(area, *pen);

// Draw the checkmark if checked
if (checked) {
graphics.DrawLine(
*pen, Gdiplus::Point{area.GetLeft(), area.GetTop()}, Gdiplus::Point{area.GetRight(), area.GetBottom()});
graphics.DrawLine(
*pen, Gdiplus::Point{area.GetLeft(), area.GetBottom()}, Gdiplus::Point{area.GetRight(), area.GetTop()});
}

// Clickspot
clickableArea->Apply(graphics, radarScreen);

// Label
graphics.DrawString(
HelperFunctions::ConvertToWideString(provider->Label()), labelArea, *brush, stringFormat, font);
}

void Checkbox::LeftClick(
Euroscope::EuroscopeRadarLoopbackInterface& radarScreen, const std::string& description, POINT mousePosition)
{
checked = !checked;
provider->StateChanged(checked);
}

auto Checkbox::WithPosition(POINT position) -> std::shared_ptr<Checkbox>
{
area = {position.x, position.y, DIMENSIONS, DIMENSIONS};
labelArea = {area.GetRight() + 10, position.y, 250, DIMENSIONS};
this->clickableArea->WithPosition(
{area.GetLeft(), area.GetTop(), labelArea.GetRight() - area.GetLeft(), labelArea.Height});
return shared_from_this();
}

auto Checkbox::ScreenObjectId() const -> int
{
return screenObjectId;
}
} // namespace UKControllerPlugin::Components
71 changes: 71 additions & 0 deletions src/plugin/components/Checkbox.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#pragma once
#include <string>
#include <windef.h>
#include "radarscreen/ScreenObjectInterface.h"

namespace UKControllerPlugin {
namespace Euroscope {
class EuroscopeRadarLoopbackInterface;
} // namespace Euroscope
namespace Windows {
class GdiGraphicsInterface;
} // namespace Windows
} // namespace UKControllerPlugin

namespace UKControllerPlugin::Components {
class CheckboxProviderInterface;
class ClickableArea;

/**
* A checkbox
*/
class Checkbox : public std::enable_shared_from_this<Checkbox>, public RadarScreen::ScreenObjectInterface
{
public:
static auto Create(std::shared_ptr<CheckboxProviderInterface> provider, int screenObjectId)
-> std::shared_ptr<Checkbox>;
auto Checked(bool checked) -> std::shared_ptr<Checkbox>;
void
Draw(Windows::GdiGraphicsInterface& graphics, Euroscope::EuroscopeRadarLoopbackInterface& radarScreen) const;
void LeftClick(
Euroscope::EuroscopeRadarLoopbackInterface& radarScreen,
const std::string& description,
POINT mousePosition) override;
auto ScreenObjectId() const -> int override;
auto WithPosition(POINT position) -> std::shared_ptr<Checkbox>;

protected:
Checkbox(std::shared_ptr<CheckboxProviderInterface> provider, int screenObjectId);

private:
// The provider
std::shared_ptr<CheckboxProviderInterface> provider;

// The id of the screen object
int screenObjectId;

// Clickspot area
Gdiplus::Rect area;
Gdiplus::Rect labelArea;

// Pen
std::shared_ptr<Gdiplus::Pen> pen;
std::shared_ptr<Gdiplus::Brush> brush;

// Clickspot
std::shared_ptr<ClickableArea> clickableArea;

// Font
const Gdiplus::Font& font;

// String format
const Gdiplus::StringFormat& stringFormat;

// Checked
bool checked = false;

// How big is it
inline static const int DIMENSIONS = 15;
};

} // namespace UKControllerPlugin::Components
6 changes: 6 additions & 0 deletions src/plugin/components/CheckboxProviderInterface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "CheckboxProviderInterface.h"

namespace UKControllerPlugin::Components {

CheckboxProviderInterface::~CheckboxProviderInterface() = default;
} // namespace UKControllerPlugin::Components
15 changes: 15 additions & 0 deletions src/plugin/components/CheckboxProviderInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

namespace UKControllerPlugin::Components {

/**
* Provides the information required to have a checkbox.
*/
class CheckboxProviderInterface
{
public:
virtual ~CheckboxProviderInterface();
[[nodiscard]] virtual auto Label() -> std::string = 0;
virtual void StateChanged(bool checked) = 0;
};
} // namespace UKControllerPlugin::Components
Loading