Skip to content

Commit

Permalink
Refactor view/controller interaction + replace tabs with spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
EvenAR committed Nov 15, 2020
1 parent a792a20 commit 55978e6
Show file tree
Hide file tree
Showing 18 changed files with 1,066 additions and 1,048 deletions.
69 changes: 69 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Visual Studio generated .editorconfig file with C++ settings.
root = true

[*.{c++,cc,cpp,cppm,cxx,h,h++,hh,hpp,hxx,inl,ipp,ixx,tlh,tli}]

# Visual C++ Code Style settings

cpp_generate_documentation_comments = xml

# Visual C++ Formatting settings

cpp_indent_braces = false
cpp_indent_multi_line_relative_to = innermost_parenthesis
cpp_indent_within_parentheses = indent
cpp_indent_preserve_within_parentheses = true
cpp_indent_case_contents = true
cpp_indent_case_labels = false
cpp_indent_case_contents_when_block = false
cpp_indent_lambda_braces_when_parameter = true
cpp_indent_goto_labels = one_left
cpp_indent_preprocessor = leftmost_column
cpp_indent_access_specifiers = false
cpp_indent_namespace_contents = true
cpp_indent_preserve_comments = false
cpp_new_line_before_open_brace_namespace = same_line
cpp_new_line_before_open_brace_type = same_line
cpp_new_line_before_open_brace_function = same_line
cpp_new_line_before_open_brace_block = same_line
cpp_new_line_before_open_brace_lambda = same_line
cpp_new_line_scope_braces_on_separate_lines = false
cpp_new_line_close_brace_same_line_empty_type = true
cpp_new_line_close_brace_same_line_empty_function = true
cpp_new_line_before_catch = false
cpp_new_line_before_else = false
cpp_new_line_before_while_in_do_while = false
cpp_space_before_function_open_parenthesis = remove
cpp_space_within_parameter_list_parentheses = false
cpp_space_between_empty_parameter_list_parentheses = false
cpp_space_after_keywords_in_control_flow_statements = true
cpp_space_within_control_flow_statement_parentheses = false
cpp_space_before_lambda_open_parenthesis = false
cpp_space_within_cast_parentheses = false
cpp_space_after_cast_close_parenthesis = false
cpp_space_within_expression_parentheses = false
cpp_space_before_block_open_brace = true
cpp_space_between_empty_braces = false
cpp_space_before_initializer_list_open_brace = false
cpp_space_within_initializer_list_braces = true
cpp_space_preserve_in_initializer_list = true
cpp_space_before_open_square_bracket = false
cpp_space_within_square_brackets = false
cpp_space_before_empty_square_brackets = false
cpp_space_between_empty_square_brackets = false
cpp_space_group_square_brackets = true
cpp_space_within_lambda_brackets = false
cpp_space_between_empty_lambda_brackets = false
cpp_space_before_comma = false
cpp_space_after_comma = true
cpp_space_remove_around_member_operators = true
cpp_space_before_inheritance_colon = true
cpp_space_before_constructor_colon = true
cpp_space_remove_before_semicolon = true
cpp_space_after_semicolon = true
cpp_space_remove_around_unary_operator = true
cpp_space_around_binary_operator = insert
cpp_space_around_assignment_operator = insert
cpp_space_pointer_reference_alignment = left
cpp_space_around_ternary_operator = insert
cpp_wrap_preserve_blocks = one_liners
2 changes: 2 additions & 0 deletions Aman/Aman.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="EventEmitter.cpp" />
<ClCompile Include="Aman.cpp" />
<ClCompile Include="AmanController.cpp" />
<ClCompile Include="AmanPlugIn.cpp" />
Expand All @@ -205,6 +206,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\..\..\Program Files (x86)\EuroScope\PlugInEnvironment\EuroScopePlugIn.h" />
<ClInclude Include="EventEmitter.h" />
<ClInclude Include="Aman.h" />
<ClInclude Include="AmanAircraft.h" />
<ClInclude Include="AmanController.h" />
Expand Down
6 changes: 6 additions & 0 deletions Aman/Aman.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<ClCompile Include="AmanTimeline.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="EventEmitter.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Aman.def">
Expand Down Expand Up @@ -88,6 +91,9 @@
<ClInclude Include="AmanTimeline.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="EventEmitter.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Aman.rc">
Expand Down
34 changes: 18 additions & 16 deletions Aman/AmanAircraft.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#pragma once

#include <string>

class AmanAircraft {
public:
std::string callsign;
std::string finalFix;
std::string arrivalRunway;
std::string icaoType;
std::string nextFix;
public:
std::string callsign;
std::string finalFix;
std::string arrivalRunway;
std::string icaoType;
std::string nextFix;

int viaFixIndex;
int viaFixIndex;

bool trackedByMe;
bool isSelected;
char wtc;
int eta;
double distLeft;
int secondsBehindPreceeding;
bool trackedByMe;
bool isSelected;
char wtc;
int eta;
double distLeft;
int secondsBehindPreceeding;

bool operator< (const AmanAircraft &other) const {
return eta < other.eta;
}
bool operator< (const AmanAircraft& other) const {
return eta < other.eta;
}
};
135 changes: 61 additions & 74 deletions Aman/AmanController.cpp
Original file line number Diff line number Diff line change
@@ -1,102 +1,89 @@
#include "stdafx.h"

#include "AmanController.h"
#include "AmanWindow.h"
#include "AmanPlugIn.h"
#include "AmanTimeline.h"
#include "AmanTimelineView.h"
#include "AmanWindow.h"
#include "TitleBar.h"

#define THREE_HOURS 10800
#define FIVE_MINUTES 300

AmanController::AmanController(AmanPlugIn* plugin) {
this->amanPlugin = plugin;
this->amanWindow = NULL;
this->amanPlugin = plugin;
this->amanWindow = NULL;

this->titleBar = new TitleBar();

this->titleBar->on("COLLAPSE_CLICKED", [&]() {
if (this->amanWindow->isExpanded()) {
this->amanWindow->collapse();
} else {
this->amanWindow->expand();
}
});

this->titleBar->on("MOUSE_PRESSED", [&]() { this->moveWindow = true; });

this->titleBar->on("RESIZE_PRESSED", [&]() {
if (this->amanWindow->isExpanded()) {
this->doResize = true;
}
});
}

void AmanController::openWindow() {
if (this->amanWindow == NULL) {
this->amanWindow = new AmanWindow(this);
}
}

void AmanController::dataUpdated(std::vector<AmanTimeline*>* timelines) {
if (this->amanWindow != NULL) {
this->amanWindow->update(timelines);
}
}

void AmanController::mousePressed(CRect windowRect, CPoint cursorPosition) {
this->mouseDownPosition = cursorPosition;
if (this->amanWindow == NULL) {
this->amanWindow = new AmanWindow(this, titleBar);
}
}

void AmanController::mouseReleased(CRect windowRect, CPoint cursorPosition) {
this->moveWindow = false;
this->doResize = false;
void AmanController::dataUpdated(const std::vector<AmanTimeline*>& timelines) {
if (this->amanWindow != NULL) {
this->amanWindow->update(timelines);
}
}

void AmanController::mouseMoved(CRect windowRect, CPoint cursorPosition) {
if (this->doResize) {
CPoint diff = cursorPosition - this->previousMousePosition;

CRect newRect = {
windowRect.left,
windowRect.top + diff.y,
windowRect.right + diff.x,
windowRect.bottom
};

this->amanWindow->setWindowPosition(newRect);

} else if (this->moveWindow && this->amanWindow != NULL) {
CPoint diff = cursorPosition - this->previousMousePosition;
windowRect.MoveToXY(windowRect.TopLeft() + diff);
this->amanWindow->setWindowPosition(windowRect);
}
this->previousMousePosition = cursorPosition;
}
void AmanController::mousePressed(CPoint cursorPosition) { titleBar->mousePressed(cursorPosition); }

void AmanController::mouseWheelSrolled(CPoint cursorPosition, short delta) {
auto allTimelines = this->amanPlugin->getTimelines();
auto timelinePointedAt = this->amanWindow->getTimelineAt(allTimelines, cursorPosition);
if (timelinePointedAt) {
auto currentRange = timelinePointedAt->getRange();
auto newRange = currentRange - delta;
auto limitReached = newRange < FIVE_MINUTES || newRange > THREE_HOURS;

if (!limitReached) {
timelinePointedAt->setRange(newRange);
dataUpdated(allTimelines);
}
}
void AmanController::mouseReleased(CPoint cursorPosition) {
this->moveWindow = false;
this->doResize = false;
}

void AmanController::resizebuttonPressed() {
if (this->expanded) {
this->doResize = true;
}
}
void AmanController::mouseMoved(CPoint cursorPosition) {
if (this->doResize) {
CPoint diff = cursorPosition - this->previousMousePosition;
this->amanWindow->resizeWindowBy(diff);
} else if (this->moveWindow && this->amanWindow != NULL) {
CPoint diff = cursorPosition - this->previousMousePosition;
this->amanWindow->moveWindowBy(diff);
}

void AmanController::collapseButtonPressed() {
if (this->expanded) {
this->amanWindow->collapse();
}
else {
this->amanWindow->expand();
}
this->expanded = !this->expanded;
this->previousMousePosition = cursorPosition;
}

void AmanController::titleBarPressed() {
this->moveWindow = true;
void AmanController::mouseWheelSrolled(CPoint cursorPosition, short delta) {
auto& allTimelines = this->amanPlugin->getTimelines();
auto timelinePointedAt = this->amanWindow->getTimelineAt(allTimelines, cursorPosition);
if (timelinePointedAt) {
auto currentRange = timelinePointedAt->getRange();
auto newRange = currentRange - delta;
auto limitReached = newRange < FIVE_MINUTES || newRange > THREE_HOURS;

if (!limitReached) {
timelinePointedAt->setRange(newRange);
dataUpdated(allTimelines);
}
}
}

void AmanController::windowClosed() {
this->amanWindow = NULL;
}
void AmanController::windowClosed() { this->amanWindow = NULL; }

AmanController::~AmanController() {
if (this->amanWindow != NULL) {
delete this->amanWindow;
this->amanWindow = NULL;
}
if (this->amanWindow != NULL) {
delete this->amanWindow;
this->amanWindow = NULL;
}
}
46 changes: 20 additions & 26 deletions Aman/AmanController.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,31 @@

#include <vector>

class TitleBar;
class AmanWindow;
class AmanPlugIn;
class AmanTimeline;

class AmanController
{

private:
bool expanded = true;
bool moveWindow = false;
bool doResize = false;
CPoint mouseDownPosition;
CPoint previousMousePosition;

AmanPlugIn* amanPlugin; // Model
AmanWindow* amanWindow; // View1

class AmanController {
public:
AmanController(AmanPlugIn* plugin);
void openWindow();
void windowClosed();
void mousePressed(CRect windowRect, CPoint cursorPosition);
void mouseReleased(CRect windowRect, CPoint cursorPosition);
void mouseMoved(CRect windowRect, CPoint cursorPosition);
void mouseWheelSrolled(CPoint cursorPosition, short delta);
void dataUpdated(std::vector<AmanTimeline*>* timelines);
AmanController(AmanPlugIn* plugin);
void openWindow();
void windowClosed();
void mousePressed(CPoint cursorPosition);
void mouseReleased(CPoint cursorPosition);
void mouseMoved(CPoint cursorPosition);
void mouseWheelSrolled(CPoint cursorPosition, short delta);
void dataUpdated(const std::vector<AmanTimeline*>& timelines);

void resizebuttonPressed();
void titleBarPressed();
void collapseButtonPressed();
~AmanController();

~AmanController();
private:
bool moveWindow = false;
bool doResize = false;
CPoint mouseDownPosition;
CPoint previousMousePosition;

AmanPlugIn* amanPlugin; // Model
AmanWindow* amanWindow; // View1
TitleBar* titleBar;
};

Loading

0 comments on commit 55978e6

Please sign in to comment.