Skip to content

Commit

Permalink
Headeronly
Browse files Browse the repository at this point in the history
  • Loading branch information
mwestphal committed Dec 3, 2024
1 parent 4ea1976 commit c25a76a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 77 deletions.
69 changes: 65 additions & 4 deletions library/public/interactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,85 @@ struct F3D_EXPORT interaction_bind_t
* Operator to be able to store binds in maps and other structs
* Compare modifier and interaction
*/
bool operator<(const interaction_bind_t& bind) const;
bool operator<(const interaction_bind_t& bind) const
{
return this->mod < bind.mod || (this->mod == bind.mod && this->inter < bind.inter);
}

/**
* Operator to be able to store binds in maps and other structs
* Compare modifier and interaction
*/
bool operator==(const interaction_bind_t& bind) const;
bool operator==(const interaction_bind_t& bind) const
{
return this->mod == bind.mod && this->inter == bind.inter;
}

/**
* Format this binding into a string
* eg: "A", "Any+Question", "Shift+L".
*/
std::string format() const;
std::string format() const
{
switch (this->mod)
{
case ModifierKeys::CTRL_SHIFT:
return "Ctrl+Shift+" + this->inter;
case ModifierKeys::CTRL:
return "Ctrl+" + this->inter;
case ModifierKeys::SHIFT:
return "Shift+" + this->inter;
case ModifierKeys::ANY:
return "Any+" + this->inter;
default:
// No need to check for NONE
return this->inter;
}
}

/**
* Create and return an interaction bind from provided string
*/
static interaction_bind_t parse(const std::string& str);
static interaction_bind_t parse(const std::string& str)
{
interaction_bind_t bind;
auto plusIt = str.find_last_of('+');
if (plusIt == std::string::npos)
{
bind.inter = str;
}
else
{
bind.inter = str.substr(plusIt + 1);

std::string modStr = str.substr(0, plusIt);
if (modStr == "Ctrl+Shift")
{
bind.mod = ModifierKeys::CTRL_SHIFT;
}
else if (modStr == "Shift")
{
bind.mod = ModifierKeys::SHIFT;
}
else if (modStr == "Ctrl")
{
bind.mod = ModifierKeys::CTRL;
}
else if (modStr == "Any")
{
bind.mod = ModifierKeys::ANY;
}
else if (modStr == "None")
{
bind.mod = ModifierKeys::NONE;
}
else
{
f3d::log::warn("Invalid modifier: ", modStr, ", ignoring modifier");
}
}
return bind;
}

Check warning on line 117 in library/public/interactor.h

View check run for this annotation

Codecov / codecov/patch

library/public/interactor.h#L117

Added line #L117 was not covered by tests
};

/**
Expand Down
73 changes: 0 additions & 73 deletions library/src/interactor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,6 @@

namespace f3d
{
//----------------------------------------------------------------------------
bool interaction_bind_t::operator<(const interaction_bind_t& bind) const
{
return this->mod < bind.mod || (this->mod == bind.mod && this->inter < bind.inter);
}

//----------------------------------------------------------------------------
bool interaction_bind_t::operator==(const interaction_bind_t& bind) const
{
return this->mod == bind.mod && this->inter == bind.inter;
}

//----------------------------------------------------------------------------
std::string interaction_bind_t::format() const
{
switch (this->mod)
{
case ModifierKeys::CTRL_SHIFT:
return "Ctrl+Shift+" + this->inter;
case ModifierKeys::CTRL:
return "Ctrl+" + this->inter;
case ModifierKeys::SHIFT:
return "Shift+" + this->inter;
case ModifierKeys::ANY:
return "Any+" + this->inter;
default:
// No need to check for NONE
return this->inter;
}
}

//----------------------------------------------------------------------------
interaction_bind_t interaction_bind_t::parse(const std::string& str)
{
interaction_bind_t bind;
auto plusIt = str.find_last_of('+');
if (plusIt == std::string::npos)
{
bind.inter = str;
}
else
{
bind.inter = str.substr(plusIt + 1);

std::string modStr = str.substr(0, plusIt);
if (modStr == "Ctrl+Shift")
{
bind.mod = ModifierKeys::CTRL_SHIFT;
}
else if (modStr == "Shift")
{
bind.mod = ModifierKeys::SHIFT;
}
else if (modStr == "Ctrl")
{
bind.mod = ModifierKeys::CTRL;
}
else if (modStr == "Any")
{
bind.mod = ModifierKeys::ANY;
}
else if (modStr == "None")
{
bind.mod = ModifierKeys::NONE;
}
else
{
f3d::log::warn("Invalid modifier: ", modStr, ", ignoring modifier");
}
}
return bind;
}

//----------------------------------------------------------------------------
interactor::already_exists_exception::already_exists_exception(const std::string& what)
: exception(what)
Expand Down

0 comments on commit c25a76a

Please sign in to comment.