mirror-chatterino2/src/messages/layouts/messagelayoutcontainer.hpp

102 lines
2 KiB
C++
Raw Normal View History

#pragma once
#include <memory>
#include <vector>
#include <QPoint>
2018-01-15 04:08:48 +01:00
#include <QRect>
2018-01-16 00:26:04 +01:00
#include "messages/selection.hpp"
class QPainter;
namespace chatterino {
namespace messages {
namespace layouts {
class MessageLayoutElement;
struct Margin {
int top;
int right;
int bottom;
int left;
Margin()
: Margin(0)
{
}
Margin(int value)
: Margin(value, value, value, value)
{
}
Margin(int _top, int _right, int _bottom, int _left)
: top(_top)
, right(_right)
, bottom(_bottom)
, left(_left)
{
}
};
class MessageLayoutContainer
{
public:
MessageLayoutContainer();
float scale;
Margin margin;
bool centered;
bool enableCompactEmotes;
int width;
int getHeight() const;
// methods
void clear();
void addElement(MessageLayoutElement *element);
void addElementNoLineBreak(MessageLayoutElement *element);
void breakLine();
bool atStartOfLine();
bool fitsInLine(int width);
void finish();
MessageLayoutElement *getElementAt(QPoint point);
// painting
void paintElements(QPainter &painter);
2018-01-13 02:13:59 +01:00
void paintAnimatedElements(QPainter &painter, int yOffset);
void paintSelection(QPainter &painter, int messageIndex, Selection &selection);
2018-01-15 04:08:48 +01:00
// selection
int getSelectionIndex(QPoint point);
private:
2018-01-16 00:26:04 +01:00
struct Line {
int startIndex;
int endIndex;
int startCharIndex;
int endCharIndex;
QRect rect;
};
// helpers
void _addElement(MessageLayoutElement *element);
// variables
int line;
int height;
int currentX, currentY;
2018-01-16 00:26:04 +01:00
int charIndex = 0;
size_t lineStart = 0;
int lineHeight = 0;
int spaceWidth = 4;
std::vector<std::unique_ptr<MessageLayoutElement>> elements;
2018-01-15 04:08:48 +01:00
std::vector<Line> lines;
};
} // namespace layouts
2018-01-13 02:13:59 +01:00
} // namespace messages
} // namespace chatterino