mirror-chatterino2/src/messages/selection.hpp

77 lines
1.6 KiB
C++
Raw Normal View History

2018-01-04 23:50:30 +01:00
#pragma once
namespace chatterino {
namespace messages {
struct SelectionItem {
int messageIndex;
int charIndex;
SelectionItem()
{
2018-01-16 00:26:04 +01:00
this->messageIndex = 0;
this->charIndex = 0;
2018-01-04 23:50:30 +01:00
}
SelectionItem(int _messageIndex, int _charIndex)
{
this->messageIndex = _messageIndex;
2018-01-16 00:26:04 +01:00
2018-01-04 23:50:30 +01:00
this->charIndex = _charIndex;
}
2018-01-16 00:26:04 +01:00
bool operator<(const SelectionItem &b) const
{
if (this->messageIndex < b.messageIndex) {
return true;
}
if (this->messageIndex == b.messageIndex && this->charIndex < b.charIndex) {
return true;
}
return false;
}
bool operator>(const SelectionItem &b) const
2018-01-04 23:50:30 +01:00
{
2018-01-16 00:26:04 +01:00
return b.operator<(*this);
2018-01-04 23:50:30 +01:00
}
2018-01-16 00:26:04 +01:00
bool operator==(const SelectionItem &b) const
2018-01-04 23:50:30 +01:00
{
2018-01-16 00:26:04 +01:00
return this->messageIndex == b.messageIndex && this->charIndex == b.charIndex;
2018-01-04 23:50:30 +01:00
}
};
struct Selection {
SelectionItem start;
SelectionItem end;
SelectionItem min;
SelectionItem max;
Selection()
{
}
Selection(const SelectionItem &start, const SelectionItem &end)
: start(start)
, end(end)
, min(start)
, max(end)
{
2018-01-16 00:26:04 +01:00
if (min > max) {
2018-01-04 23:50:30 +01:00
std::swap(this->min, this->max);
}
}
bool isEmpty() const
{
2018-01-16 00:26:04 +01:00
return this->start == this->end;
2018-01-04 23:50:30 +01:00
}
bool isSingleMessage() const
{
return this->min.messageIndex == this->max.messageIndex;
}
};
2018-01-16 00:26:04 +01:00
} // namespace messages
} // namespace chatterino