Skip to content

Commit

Permalink
Support striketrhoug text style
Browse files Browse the repository at this point in the history
  • Loading branch information
martonmiklos committed Jan 10, 2025
1 parent 559c1e2 commit 6282844
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 702 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ target_sources(
"src/OutputLinearBarGraphComponent.cpp"
"src/OutputPolygonComponent.cpp"
"src/InputStringComponent.cpp"
"src/NumberComponent.cpp"
"src/AlarmMaskAudio.cpp"
"src/AppImages.cpp"
"src/ASCIILogFile.cpp"
"src/ConfigureHardwareWindow.cpp"
"src/ConfigureHardwareComponent.cpp"
"src/StringEncodingConversions.cpp"
"src/InputListComponent.cpp"
"src/ShortcutsWindow.cpp")
"src/ShortcutsWindow.cpp"
"src/TextDrawingComponent.cpp")

target_include_directories(AgISOVirtualTerminal
PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
Expand Down
2 changes: 1 addition & 1 deletion cmake/FindCAN_Stack.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ if(NOT TARGET isobus::isobus)
FetchContent_Declare(
CAN_Stack
GIT_REPOSITORY https://github.com/Open-Agriculture/AgIsoStack-plus-plus.git
GIT_TAG 67e231298f2ca8367d437d903e396aa3bcefe080)
GIT_TAG 4ad80207b5e44d041d8e0fba8ef044367dfbfe86)
FetchContent_MakeAvailable(CAN_Stack)
endif()
9 changes: 2 additions & 7 deletions include/InputNumberComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@

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

#include "JuceHeader.h"

class InputNumberComponent : public isobus::InputNumber
, public Component
, public NumberComponent
{
public:
InputNumberComponent(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet, isobus::InputNumber 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(InputNumberComponent)
};

Expand Down
9 changes: 3 additions & 6 deletions include/InputStringComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@

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

#include "JuceHeader.h"

class InputStringComponent : public isobus::InputString
, public Component
, public TextDrawingComponent
{
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
#endif // INPUT_STRING_COMPONENT_HPP
31 changes: 31 additions & 0 deletions include/NumberComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//================================================================================================
/// @file NumberComponent.hpp
///
/// @brief Common functions for drawing numbers
/// @author Miklos Marton
///
/// @copyright 2024 Adrian Del Grosso
//================================================================================================
#ifndef NUMBER_COMPONENT_HPP
#define NUMBER_COMPONENT_HPP

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

#include "JuceHeader.h"

class NumberComponent : public TextDrawingComponent
{
public:
NumberComponent(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet);

void paint(Graphics &g) override;

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

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(NumberComponent)
};

#endif // NUMBER_COMPONENT_HPP
9 changes: 2 additions & 7 deletions include/OutputNumberComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@

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

#include "JuceHeader.h"

class OutputNumberComponent : public isobus::OutputNumber
, public Component
, public NumberComponent
{
public:
OutputNumberComponent(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet, isobus::OutputNumber 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(OutputNumberComponent)
};

Expand Down
5 changes: 2 additions & 3 deletions include/OutputStringComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

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

#include "JuceHeader.h"

class OutputStringComponent : public isobus::OutputString
, public Component
, public TextDrawingComponent
{
public:
OutputStringComponent(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet, isobus::OutputString sourceObject);
Expand All @@ -25,8 +26,6 @@ class OutputStringComponent : public isobus::OutputString
static Justification convert_justification(HorizontalJustification horizontalJustification, VerticalJustification verticalJustification);

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

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OutputStringComponent)
};

Expand Down
39 changes: 39 additions & 0 deletions include/TextDrawingComponent.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//================================================================================================
/// @file TextDawingComponent.hpp
///
/// @brief Common functions for drawing numbers
/// @author Miklos Marton
///
//================================================================================================
#ifndef TEXTDRAWING_COMPONENT_HPP
#define TEXTDRAWING_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 TextDrawingComponent : public Component
{
public:
TextDrawingComponent(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet);

void setSourceObject(isobus::VTObject *newSourceObject);

protected:
static Justification convert_justification(isobus::TextualVTObject::HorizontalJustification horizontalJustification,
isobus::TextualVTObject::VerticalJustification verticalJustification);
uint8_t prepare_text_painting(Graphics &g,
std::shared_ptr<isobus::FontAttributes> font_attributes,
char referenceCharForWidthCalc);

void paintText(Graphics &g, const std::string &text, bool enabled = true);
std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> parentWorkingSet;
isobus::VTObject *sourceObject;

void drawStrikeThrough(Graphics &g, int w, int h, const String &str, isobus::TextualVTObject::HorizontalJustification justification);

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(TextDrawingComponent)
};

#endif // TEXTDRAWING_COMPONENT_HPP
150 changes: 3 additions & 147 deletions src/InputNumberComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

InputNumberComponent::InputNumberComponent(std::shared_ptr<isobus::VirtualTerminalServerManagedWorkingSet> workingSet, isobus::InputNumber sourceObject) :
isobus::InputNumber(sourceObject),
parentWorkingSet(workingSet)
NumberComponent(workingSet)
{
setSourceObject(this);
setSize(get_width(), get_height());

if (get_option(Options::Transparent))
if (get_option(isobus::NumberVTObject::Options::Transparent))
{
setOpaque(false);
}
Expand All @@ -24,148 +25,3 @@ InputNumberComponent::InputNumberComponent(std::shared_ptr<isobus::VirtualTermin
}
}

void InputNumberComponent::paint(Graphics &g)
{
if (isOpaque())
{
auto vtColour = parentWorkingSet->get_colour(backgroundColor);
g.fillAll(Colour::fromFloatRGBA(vtColour.r, vtColour.g, vtColour.b, 1.0f));
}

float scaledValue = (get_value() + get_offset()) * get_scale();
g.setColour(getLookAndFeel().findColour(ListBox::textColourId));

// Get font data
if (isobus::NULL_OBJECT_ID != get_font_attributes())
{
auto child = get_object_by_id(get_font_attributes(), parentWorkingSet->get_object_tree());

if ((nullptr != child) &&
(isobus::VirtualTerminalObjectType::FontAttributes == child->get_object_type()))
{
auto font = std::static_pointer_cast<isobus::FontAttributes>(child);
auto colour = parentWorkingSet->get_colour(font->get_colour());
Font juceFont(Font::getDefaultMonospacedFontName(), font->get_font_height_pixels(), Font::FontStyleFlags::plain);
auto fontWidth = juceFont.getStringWidthFloat("1");
juceFont.setHorizontalScale(static_cast<float>(font->get_font_width_pixels()) / fontWidth);
g.setColour(Colour::fromFloatRGBA(colour.r, colour.g, colour.b, 1.0f));
g.setFont(juceFont);
}
}

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

if ((nullptr != child) &&
(isobus::VirtualTerminalObjectType::NumberVariable == child->get_object_type()))
{
scaledValue = (std::static_pointer_cast<isobus::NumberVariable>(child)->get_value() + get_offset()) * get_scale();
}
}

std::ostringstream valueText;
valueText << std::fixed << std::setprecision(get_number_of_decimals()) << scaledValue;
g.drawText(valueText.str(), 0, 0, get_width(), get_height(), convert_justification(get_horizontal_justification(), get_vertical_justification()), false);
}

Justification InputNumberComponent::convert_justification(HorizontalJustification horizontalJustification, VerticalJustification verticalJustification)
{
Justification retVal = Justification::topLeft;

switch (horizontalJustification)
{
case HorizontalJustification::PositionLeft:
{
switch (verticalJustification)
{
case VerticalJustification::PositionTop:
{
retVal = Justification::topLeft;
}
break;

case VerticalJustification::PositionMiddle:
{
retVal = Justification::centredLeft;
}
break;

case VerticalJustification::PositionBottom:
{
retVal = Justification::bottomLeft;
}
break;

case VerticalJustification::Reserved:
default:
break;
}
}
break;

case HorizontalJustification::PositionMiddle:
{
switch (verticalJustification)
{
case VerticalJustification::PositionTop:
{
retVal = Justification::centredTop;
}
break;

case VerticalJustification::PositionMiddle:
{
retVal = Justification::centred;
}
break;

case VerticalJustification::PositionBottom:
{
retVal = Justification::centredBottom;
}
break;

case VerticalJustification::Reserved:
default:
break;
}
}
break;

case HorizontalJustification::PositionRight:
{
switch (verticalJustification)
{
case VerticalJustification::PositionTop:
{
retVal = Justification::topRight;
}
break;

case VerticalJustification::PositionMiddle:
{
retVal = Justification::centredRight;
}
break;

case VerticalJustification::PositionBottom:
{
retVal = Justification::bottomRight;
}
break;

case VerticalJustification::Reserved:
default:
break;
}
}
break;

default:
{
}
break;
}
return retVal;
}
Loading

0 comments on commit 6282844

Please sign in to comment.