-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathrender.h
More file actions
164 lines (137 loc) · 4.99 KB
/
Copy pathrender.h
File metadata and controls
164 lines (137 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#pragma once
#include <QtGui/QPainter>
#include "binaryninjaapi.h"
#include "uicontext.h"
#include "action.h"
/*!
\defgroup render Render
\ingroup uiapi
*/
/*!
\ingroup render
*/
enum HexEditorHighlightMode
{
NoHighlight,
ColumnHighlight,
ByteValueHighlight
};
/*!
\ingroup render
*/
enum HexEditorColorMode
{
NoColorization,
AsciiColorization,
ModificationColorization
};
/*!
\ingroup render
*/
enum HexEditorHighlightContrast
{
NormalContrastHighlight,
MediumContrastHighlight,
HighContrastHighlight
};
/*!
\ingroup render
*/
struct BINARYNINJAUIAPI HexEditorHighlightState
{
HexEditorHighlightMode mode;
HexEditorColorMode color;
HexEditorHighlightContrast contrast;
void restoreSettings();
void saveSettings();
};
/*!
A piece of text together with the character cell it starts at.
\ingroup render
*/
struct BINARYNINJAUIAPI CellAlignedText
{
QString text;
size_t cell;
};
/*!
\ingroup render
*/
class BINARYNINJAUIAPI FontParameters
{
QWidget* m_owner;
QFont m_font, m_emojiFont;
int m_baseline, m_charWidth, m_charHeight, m_charOffset;
float m_fontScale;
bool m_customFont;
public:
FontParameters(QWidget* parent, float fontScale = 1.0f);
void update();
const QFont& getFont() const { return m_font; }
QFont& getFont() { return m_font; }
const QFont& getEmojiFont() const { return m_emojiFont; }
QFont& getEmojiFont() { return m_emojiFont; }
void setFont(const QFont& font);
void setEmojiFont(const QFont& emojiFont);
int getBaseline() const { return m_baseline; }
int getWidth() const { return m_charWidth; }
int getHeight() const { return m_charHeight; }
int getOffset() const { return m_charOffset; }
};
/*!
\ingroup render
*/
class BINARYNINJAUIAPI RenderContext
{
QWidget* m_owner;
FontParameters m_fontParams;
bool m_drawIndents;
std::vector<QColor> m_braceColors;
QIcon m_collapsedIcon;
QIcon m_expandedIcon;
public:
RenderContext(QWidget* parent, float fontScale = 1.0f);
void update();
FontParameters& getFontParamters() { return m_fontParams; }
const FontParameters& getFontParameters() const { return m_fontParams; }
int getFontWidth() const { return m_fontParams.getWidth(); }
int getFontHeight() const { return m_fontParams.getHeight(); }
void init(QPainter& p);
QColor getColorForHexDumpByte(
const HexEditorHighlightState& state, BNModificationStatus modification, uint8_t byte);
QColor getHighlightColor(BNHighlightColor color);
HighlightTokenState getTokenForDisassemblyLinePosition(
int64_t col, const std::vector<BinaryNinja::InstructionTextToken>& tokens);
HighlightTokenState getTokenForDisassemblyTokenIndex(
size_t tokenIndex, const std::vector<BinaryNinja::InstructionTextToken>& tokens);
HighlightTokenState getHighlightTokenForTextToken(const BinaryNinja::InstructionTextToken& token);
void drawText(QPainter& p, int x, int y, QColor color, const QString& text) const;
/*! Draws text positioned on the character cell grid, so that wide code points occupy the cells
their token width accounted for. ASCII text is drawn in a single call as a fast path. */
void drawCellAlignedText(QPainter& p, int x, int y, QColor color, const std::string& text) const;
void drawUnderlinedText(QPainter& p, int x, int y, QColor color, const QString& text);
void drawSeparatorLine(QPainter& p, QColor top, QColor bottom, QColor line, const QRect& rect);
void drawInstructionHighlight(QPainter& p, const QRect& rect, bool focused = true);
void drawLinearDisassemblyLineBackground(
QPainter& p, BNLinearDisassemblyLineType type, const QRect& rect, const QRect& dirtyRect, int gutterWidth);
int drawDisassemblyLine(QPainter& p, int left, int top,
const std::vector<BinaryNinja::InstructionTextToken>& tokens, HighlightTokenState& highlight,
bool highlightOnly = false, bool renderCollapseIndicator = false) const;
void drawHexEditorLine(QPainter& p, int left, int top, const HexEditorHighlightState& highlight, BinaryViewRef view,
uint64_t lineStartAddr, size_t cols, size_t firstCol, size_t count, bool cursorVisible, bool cursorAscii,
size_t cursorPos, bool byteCursor);
QFont getFont() const { return m_fontParams.getFont(); }
QFont getEmojiFont() const { return m_fontParams.getEmojiFont(); }
void setFont(const QFont& font);
/*! Splits text into the pieces needed to draw it on the character cell grid.
Text is broken at grapheme cluster boundaries, since a cluster is what the user sees as a single
character and what the width accounting measured; a cluster can span many code points, as combining
marks, emoji modifiers, and ZWJ sequences all join into one. Runs of plain ASCII are kept together
so the font can still shape and apply ligatures across them.
The returned cell offsets always total the string's width as reported by
BinaryNinja::Unicode::GetDisplayWidth, so drawing stays aligned with the layout that width produced.
\param text Text to lay out
\return The pieces to draw, in order, each with the cell offset to draw it at
*/
static std::vector<CellAlignedText> layOutTextInCells(const std::string& text);
};