2018-01-04 23:50:30 +01:00
|
|
|
#pragma once
|
|
|
|
|
2018-08-11 17:35:46 +02:00
|
|
|
#include <tuple>
|
2018-04-03 02:55:32 +02:00
|
|
|
#include <utility>
|
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
namespace chatterino {
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-01-04 23:50:30 +01:00
|
|
|
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
|
|
|
|
{
|
2018-08-11 17:35:46 +02:00
|
|
|
return std::tie(this->messageIndex, this->charIndex) <
|
|
|
|
std::tie(b.messageIndex, b.charIndex);
|
2018-01-16 00:26:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator>(const SelectionItem &b) const
|
2018-01-04 23:50:30 +01:00
|
|
|
{
|
2018-08-11 17:35:46 +02: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-08-06 21:17:03 +02:00
|
|
|
return this->messageIndex == b.messageIndex &&
|
|
|
|
this->charIndex == b.charIndex;
|
2018-01-04 23:50:30 +01:00
|
|
|
}
|
2018-05-17 12:16:13 +02:00
|
|
|
|
|
|
|
bool operator!=(const SelectionItem &b) const
|
|
|
|
{
|
|
|
|
return this->operator==(b);
|
|
|
|
}
|
2018-01-04 23:50:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Selection {
|
|
|
|
SelectionItem start;
|
|
|
|
SelectionItem end;
|
2018-04-15 15:09:31 +02:00
|
|
|
SelectionItem selectionMin;
|
|
|
|
SelectionItem selectionMax;
|
2018-01-04 23:50:30 +01:00
|
|
|
|
2018-04-03 02:55:32 +02:00
|
|
|
Selection() = default;
|
2018-01-04 23:50:30 +01:00
|
|
|
|
|
|
|
Selection(const SelectionItem &start, const SelectionItem &end)
|
|
|
|
: start(start)
|
|
|
|
, end(end)
|
2018-04-15 15:09:31 +02:00
|
|
|
, selectionMin(start)
|
|
|
|
, selectionMax(end)
|
2018-01-04 23:50:30 +01:00
|
|
|
{
|
2018-04-15 15:09:31 +02:00
|
|
|
if (selectionMin > selectionMax) {
|
|
|
|
std::swap(this->selectionMin, this->selectionMax);
|
2018-01-04 23:50:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2018-08-06 21:17:03 +02:00
|
|
|
return this->selectionMin.messageIndex ==
|
|
|
|
this->selectionMax.messageIndex;
|
2018-01-04 23:50:30 +01:00
|
|
|
}
|
|
|
|
};
|
2018-04-03 02:55:32 +02:00
|
|
|
|
2018-10-06 13:43:21 +02:00
|
|
|
struct DoubleClickSelection {
|
|
|
|
int originalStart = 0;
|
|
|
|
int originalEnd = 0;
|
|
|
|
int origMessageIndex;
|
|
|
|
bool selectingLeft = false;
|
|
|
|
bool selectingRight = false;
|
|
|
|
SelectionItem origStartItem;
|
|
|
|
SelectionItem origEndItem;
|
|
|
|
};
|
|
|
|
|
2018-01-16 00:26:04 +01:00
|
|
|
} // namespace chatterino
|