Skip to content

Commit

Permalink
Updated objects to compile with latest vt-managed-working-set branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ad3154 committed Nov 25, 2023
1 parent af16681 commit 43e76a5
Show file tree
Hide file tree
Showing 30 changed files with 584 additions and 184 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ target_sources(
"src/OutputLineComponent.cpp"
"src/OutputLinearBarGraphComponent.cpp"
"src/OutputPolygonComponent.cpp"
"src/InputStringComponent.cpp"
"src/AlarmMaskAudio.cpp"
"src/AppImages.cpp"
"src/InputListComponent.cpp")
Expand Down
1 change: 1 addition & 0 deletions include/DataMaskRenderAreaComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class DataMaskRenderAreaComponent : public Component
std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> parentWorkingSet;
std::unique_ptr<AlertWindow> inputListModal;
std::unique_ptr<AlertWindow> inputNumberModal;
std::unique_ptr<AlertWindow> inputStringModal;
std::unique_ptr<Slider> inputNumberSlider;
std::vector<std::shared_ptr<Component>> childComponents;
std::vector<std::shared_ptr<Component>> currentModalComponentCache;
Expand Down
33 changes: 33 additions & 0 deletions include/InputStringComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//================================================================================================
/// @file InputStringComponent.hpp
///
/// @brief Defines a GUI component to draw an input string.
/// @author Adrian Del Grosso
///
/// @copyright 2023 Adrian Del Grosso
//================================================================================================
#ifndef INPUT_STRING_COMPONENT_HPP
#define INPUT_STRING_COMPONENT_HPP

#include "isobus/isobus/isobus_virtual_terminal_objects.hpp"
#include "isobus/isobus/isobus_virtual_terminal_server_managed_working_set.hpp"

#include "JuceHeader.h"

class InputStringComponent : public isobus::InputString
, public Component
{
public:
InputStringComponent(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet, isobus::InputString sourceObject);

void paint(Graphics &g) override;

static Justification convert_justification(HorizontalJustification horizontalJustification, VerticalJustification verticalJustification);

private:
std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> parentWorkingSet;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(InputStringComponent)
};

#endif // INPUT_STRING_COMPONENT_HPP
4 changes: 2 additions & 2 deletions src/AlarmMaskComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void AlarmMaskComponent::on_content_changed(bool initial)
{
for (std::uint16_t i = 0; i < this->get_number_children(); i++)
{
auto child = get_object_by_id(get_child_id(i));
auto child = get_object_by_id(get_child_id(i), parentWorkingSet->get_object_tree());

if ((nullptr != child) && (isobus::VirtualTerminalObjectType::SoftKeyMask != child->get_object_type()))
{
Expand All @@ -41,7 +41,7 @@ void AlarmMaskComponent::on_content_changed(bool initial)

void AlarmMaskComponent::paint(Graphics &g)
{
auto vtColour = colourTable.get_colour(backgroundColor);
auto vtColour = parentWorkingSet->get_colour(backgroundColor);

g.fillAll(Colour::fromFloatRGBA(vtColour.r, vtColour.g, vtColour.b, 1.0f));
}
6 changes: 3 additions & 3 deletions src/ButtonComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ButtonComponent::ButtonComponent(std::shared_ptr<isobus::VirtualTerminalServerMa

for (std::uint16_t i = 0; i < this->get_number_children(); i++)
{
auto child = get_object_by_id(get_child_id(i));
auto child = get_object_by_id(get_child_id(i), parentWorkingSet->get_object_tree());

if (nullptr != child)
{
Expand All @@ -33,7 +33,7 @@ ButtonComponent::ButtonComponent(std::shared_ptr<isobus::VirtualTerminalServerMa

void ButtonComponent::paint(Graphics &g)
{
auto vtColour = colourTable.get_colour(backgroundColor);
auto vtColour = parentWorkingSet->get_colour(backgroundColor);

if (true == get_option(Options::TransparentBackground))
{
Expand All @@ -46,7 +46,7 @@ void ButtonComponent::paint(Graphics &g)

if (false == get_option(Options::NoBorder))
{
vtColour = colourTable.get_colour(get_border_colour());
vtColour = parentWorkingSet->get_colour(get_border_colour());
g.setColour(Colour::fromFloatRGBA(vtColour.r, vtColour.g, vtColour.b, 1.0f));
g.drawRect(0, 0, get_width(), get_height(), 4);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ContainerComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ContainerComponent::ContainerComponent(std::shared_ptr<isobus::VirtualTerminalSe

for (std::uint16_t i = 0; i < this->get_number_children(); i++)
{
auto child = get_object_by_id(get_child_id(i));
auto child = get_object_by_id(get_child_id(i), parentWorkingSet->get_object_tree());

if (nullptr != child)
{
Expand Down
4 changes: 2 additions & 2 deletions src/DataMaskComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void DataMaskComponent::on_content_changed(bool initial)
{
for (std::uint16_t i = 0; i < this->get_number_children(); i++)
{
auto child = get_object_by_id(get_child_id(i));
auto child = get_object_by_id(get_child_id(i), parentWorkingSet->get_object_tree());

if ((nullptr != child) && (isobus::VirtualTerminalObjectType::SoftKeyMask != child->get_object_type()))
{
Expand All @@ -41,7 +41,7 @@ void DataMaskComponent::on_content_changed(bool initial)

void DataMaskComponent::paint(Graphics &g)
{
auto vtColour = colourTable.get_colour(backgroundColor);
auto vtColour = parentWorkingSet->get_colour(backgroundColor);

g.fillAll(Colour::fromFloatRGBA(vtColour.r, vtColour.g, vtColour.b, 1.0f));
}
120 changes: 102 additions & 18 deletions src/DataMaskRenderAreaComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event)

for (std::uint32_t i = 0; i < clickedList->get_number_children(); i++)
{
auto child = clickedList->get_object_by_id(clickedList->get_child_id(static_cast<std::uint16_t>(i)));
auto child = clickedList->get_object_by_id(clickedList->get_child_id(static_cast<std::uint16_t>(i)), parentWorkingSet->get_object_tree());

if (nullptr != child)
{
Expand Down Expand Up @@ -181,7 +181,7 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event)

if (isobus::NULL_OBJECT_ID != clickedList->get_variable_reference())
{
auto child = clickedList->get_object_by_id(clickedList->get_variable_reference());
auto child = clickedList->get_object_by_id(clickedList->get_variable_reference(), parentWorkingSet->get_object_tree());

if (nullptr != child)
{
Expand Down Expand Up @@ -222,16 +222,15 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event)

float scaledValue = (clickedNumber->get_value() + clickedNumber->get_offset()) * clickedNumber->get_scale();

for (std::uint16_t i = 0; i < clickedNumber->get_number_children(); i++)
if (isobus::NULL_OBJECT_ID != clickedNumber->get_variable_reference())
{
auto child = clickedNumber->get_object_by_id(clickedNumber->get_child_id(i));
auto child = clickedNumber->get_object_by_id(clickedNumber->get_variable_reference(), parentWorkingSet->get_object_tree());

if (nullptr != child)
{
if (isobus::VirtualTerminalObjectType::NumberVariable == child->get_object_type())
{
scaledValue = (std::static_pointer_cast<isobus::NumberVariable>(child)->get_value() + clickedNumber->get_offset()) * clickedNumber->get_scale();
break;
}
}
}
Expand All @@ -257,15 +256,14 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event)
{
clickedNumber->set_value(inputNumberListener.get_last_value());

for (std::uint32_t i = 0; i < clickedNumber->get_number_children(); i++)
if (isobus::NULL_OBJECT_ID != clickedNumber->get_variable_reference())
{
auto child = clickedNumber->get_object_by_id(clickedNumber->get_child_id(static_cast<std::uint16_t>(i)));
auto child = clickedNumber->get_object_by_id(clickedNumber->get_variable_reference(), parentWorkingSet->get_object_tree());

if ((nullptr != child) && (isobus::VirtualTerminalObjectType::NumberVariable == child->get_object_type()))
{
std::static_pointer_cast<isobus::NumberVariable>(child)->set_value(inputNumberListener.get_last_value());
varNumID = child->get_id();
break;
}
}
this->needToRepaintActiveArea = true;
Expand Down Expand Up @@ -305,9 +303,9 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event)
{
bool hasNumberVariable = false;

for (std::uint16_t i = 0; i < clickedBool->get_number_children(); i++)
if (isobus::NULL_OBJECT_ID != clickedBool->get_variable_reference())
{
auto child = clickedBool->get_object_by_id(clickedBool->get_child_id(i));
auto child = clickedBool->get_object_by_id(clickedBool->get_variable_reference(), parentWorkingSet->get_object_tree());

if (nullptr != child)
{
Expand All @@ -316,7 +314,6 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event)
hasNumberVariable = true;
std::static_pointer_cast<isobus::NumberVariable>(child)->set_value(!(0 != std::static_pointer_cast<isobus::NumberVariable>(child)->get_value()));
ownerServer.send_change_numeric_value_message(child->get_id(), std::static_pointer_cast<isobus::NumberVariable>(child)->get_value(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet));
break;
}
}
}
Expand All @@ -331,6 +328,72 @@ void DataMaskRenderAreaComponent::mouseUp(const MouseEvent &event)
}
break;

case isobus::VirtualTerminalObjectType::InputString:
{
auto clickedString = std::static_pointer_cast<isobus::InputString>(clickedObject);
std::shared_ptr<isobus::StringVariable> stringVariable;

if (clickedString->get_enabled())
{
bool hasStringVariable = false;

if (isobus::NULL_OBJECT_ID != clickedString->get_variable_reference())
{
auto child = clickedString->get_object_by_id(clickedString->get_variable_reference(), parentWorkingSet->get_object_tree());

if (nullptr != child)
{
if (isobus::VirtualTerminalObjectType::StringVariable == child->get_object_type())
{
hasStringVariable = true;
stringVariable = std::static_pointer_cast<isobus::StringVariable>(child);
}
}
}

inputStringModal.reset(new AlertWindow("Input String", "Enter a value for this input string, then press OK.", MessageBoxIconType::QuestionIcon));
inputStringModal->addTextEditor("Input String", hasStringVariable ? stringVariable->get_value() : clickedString->get_value());
inputStringModal->addButton("OK", 0);
inputStringModal->addButton("Cancel", 1); // TODO catch ESC as cancel
auto resultCallback = [this, clickedString, stringVariable](int result) {
this->inputStringModal->exitModalState();
ownerServer.send_select_input_object_message(clickedString->get_id(), false, false, ownerServer.get_client_control_function_for_working_set(parentWorkingSet));

if (0 == result) //OK
{
String newContent = this->inputStringModal->getTextEditor("Input String")->getText();

if (nullptr != stringVariable)
{
// It seems common practice to pad the string value out to the length in the object pool.
while (newContent.length() < stringVariable->get_value().length())
{
newContent.append(" ", 1);
}
stringVariable->set_value(newContent.toStdString());
ownerServer.send_change_string_value_message(stringVariable->get_id(), newContent.toStdString(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet));
}
else
{
// It seems common practice to pad the string value out to the length in the object pool.
while (newContent.length() < clickedString->get_value().length())
{
newContent.append(" ", 1);
}
clickedString->set_value(newContent.toStdString());
ownerServer.send_change_string_value_message(clickedString->get_id(), newContent.toStdString(), ownerServer.get_client_control_function_for_working_set(parentWorkingSet));
}
needToRepaintActiveArea = true;
}
inputStringModal->exitModalState();
inputStringModal.reset();
};
inputStringModal->enterModalState(true, ModalCallbackFunction::create(std::move(resultCallback)), false);
ownerServer.send_select_input_object_message(clickedString->get_id(), true, true, ownerServer.get_client_control_function_for_working_set(parentWorkingSet));
}
}
break;

default:
break;
}
Expand Down Expand Up @@ -376,28 +439,48 @@ std::shared_ptr<isobus::VTObject> DataMaskRenderAreaComponent::getClickedChildRe
{
std::shared_ptr<isobus::VTObject> retVal;

if ((nullptr == object) || (0 == object->get_number_children()))
if ((nullptr == object) ||
((isobus::VirtualTerminalObjectType::ObjectPointer != object->get_object_type()) &&
(0 == object->get_number_children())))
{
return nullptr;
}

for (std::uint16_t i = 0; i < object->get_number_children(); i++)
if (isobus::VirtualTerminalObjectType::ObjectPointer == object->get_object_type())
{
auto child = object->get_object_by_id(object->get_child_id(i));
auto child = object->get_object_by_id(std::static_pointer_cast<isobus::ObjectPointer>(object)->get_value(), parentWorkingSet->get_object_tree());

if ((nullptr != child) &&
(objectCanBeClicked(child)) &&
(isClickWithinBounds(x, y, object->get_child_x(i), object->get_child_y(i), child->get_width(), child->get_height())))
(isClickWithinBounds(x, y, 0, 0, child->get_width(), child->get_height())))
{
return child;
}
else if (!objectCanBeClicked(child))
{
retVal = getClickedChildRecursive(child, x - object->get_child_x(i), y - object->get_child_y(i));
retVal = getClickedChildRecursive(child, x, y);
}
}
else
{
for (std::uint16_t i = 0; i < object->get_number_children(); i++)
{
auto child = object->get_object_by_id(object->get_child_id(i), parentWorkingSet->get_object_tree());

if (nullptr != retVal)
if ((nullptr != child) &&
(objectCanBeClicked(child)) &&
(isClickWithinBounds(x, y, object->get_child_x(i), object->get_child_y(i), child->get_width(), child->get_height())))
{
break;
return child;
}
else if (!objectCanBeClicked(child))
{
retVal = getClickedChildRecursive(child, x - object->get_child_x(i), y - object->get_child_y(i));

if (nullptr != retVal)
{
break;
}
}
}
}
Expand All @@ -417,6 +500,7 @@ bool DataMaskRenderAreaComponent::objectCanBeClicked(std::shared_ptr<isobus::VTO
case isobus::VirtualTerminalObjectType::Key:
case isobus::VirtualTerminalObjectType::InputNumber:
case isobus::VirtualTerminalObjectType::InputBoolean:
case isobus::VirtualTerminalObjectType::InputString:
{
retVal = true;
}
Expand Down
14 changes: 6 additions & 8 deletions src/InputBooleanComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,32 @@ InputBooleanComponent::InputBooleanComponent(std::shared_ptr<isobus::VirtualTerm
void InputBooleanComponent::paint(Graphics &g)
{
// Draw background
auto vtColour = colourTable.get_colour(get_background_color());
auto vtColour = parentWorkingSet->get_colour(get_background_color());
g.setColour(Colour::fromFloatRGBA(vtColour.r, vtColour.g, vtColour.b, 1.0f));
g.drawRect(0, 0, static_cast<int>(get_width()), static_cast<int>(get_height()), 0);

g.setColour(Colour::fromFloatRGBA(0.0f, 0.0f, 0.0f, 1.0f));
// Change colour to foreground colour if present
for (std::uint16_t i = 0; i < get_number_children(); i++)
if (isobus::NULL_OBJECT_ID != get_foreground_colour_object_id())
{
auto child = get_object_by_id(get_child_id(i));
auto child = get_object_by_id(get_foreground_colour_object_id(), parentWorkingSet->get_object_tree());

if ((nullptr != child) && (isobus::VirtualTerminalObjectType::FontAttributes == child->get_object_type()))
{
vtColour = colourTable.get_colour(std::static_pointer_cast<isobus::FontAttributes>(child)->get_background_color());
vtColour = parentWorkingSet->get_colour(std::static_pointer_cast<isobus::FontAttributes>(child)->get_background_color());
g.setColour(Colour::fromFloatRGBA(vtColour.r, vtColour.g, vtColour.b, 1.0f));
break;
}
}

bool isChecked = (0 != get_value());
// Change use number variable if one was provided
for (std::uint16_t i = 0; i < get_number_children(); i++)
if (isobus::NULL_OBJECT_ID != get_variable_reference())
{
auto child = get_object_by_id(get_child_id(i));
auto child = get_object_by_id(get_variable_reference(), parentWorkingSet->get_object_tree());

if ((nullptr != child) && (isobus::VirtualTerminalObjectType::NumberVariable == child->get_object_type()))
{
isChecked = std::static_pointer_cast<isobus::NumberVariable>(child)->get_value();
break;
}
}

Expand Down
Loading

0 comments on commit 43e76a5

Please sign in to comment.