mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 14:44:34 +00:00
Replace source file viewer with one that actually works.
This is much simpler, custom implementation of a text file viewer. It is able to perform these two tasks as intended: - center source view on the selected line, - highlight that line.
This commit is contained in:
parent
57e14c9e5c
commit
9672dba765
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 BalazsJako
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
File diff suppressed because it is too large
Load Diff
@ -1,394 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include "../imgui/imgui.h"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class TextEditor
|
||||
{
|
||||
public:
|
||||
enum class PaletteIndex
|
||||
{
|
||||
Default,
|
||||
Keyword,
|
||||
Number,
|
||||
String,
|
||||
CharLiteral,
|
||||
Punctuation,
|
||||
Preprocessor,
|
||||
Identifier,
|
||||
KnownIdentifier,
|
||||
PreprocIdentifier,
|
||||
Comment,
|
||||
MultiLineComment,
|
||||
Background,
|
||||
Cursor,
|
||||
Selection,
|
||||
ErrorMarker,
|
||||
Breakpoint,
|
||||
LineNumber,
|
||||
CurrentLineFill,
|
||||
CurrentLineFillInactive,
|
||||
CurrentLineEdge,
|
||||
Max
|
||||
};
|
||||
|
||||
enum class SelectionMode
|
||||
{
|
||||
Normal,
|
||||
Word,
|
||||
Line
|
||||
};
|
||||
|
||||
struct Breakpoint
|
||||
{
|
||||
int mLine;
|
||||
bool mEnabled;
|
||||
std::string mCondition;
|
||||
|
||||
Breakpoint()
|
||||
: mLine(-1)
|
||||
, mEnabled(false)
|
||||
{}
|
||||
};
|
||||
|
||||
// Represents a character coordinate from the user's point of view,
|
||||
// i. e. consider an uniform grid (assuming fixed-width font) on the
|
||||
// screen as it is rendered, and each cell has its own coordinate, starting from 0.
|
||||
// Tabs are counted as [1..mTabSize] count empty spaces, depending on
|
||||
// how many space is necessary to reach the next tab stop.
|
||||
// For example, coordinate (1, 5) represents the character 'B' in a line "\tABC", when mTabSize = 4,
|
||||
// because it is rendered as " ABC" on the screen.
|
||||
struct Coordinates
|
||||
{
|
||||
int mLine, mColumn;
|
||||
Coordinates() : mLine(0), mColumn(0) {}
|
||||
Coordinates(int aLine, int aColumn) : mLine(aLine), mColumn(aColumn)
|
||||
{
|
||||
assert(aLine >= 0);
|
||||
assert(aColumn >= 0);
|
||||
}
|
||||
static Coordinates Invalid() { static Coordinates invalid(-1, -1); return invalid; }
|
||||
|
||||
bool operator ==(const Coordinates& o) const
|
||||
{
|
||||
return
|
||||
mLine == o.mLine &&
|
||||
mColumn == o.mColumn;
|
||||
}
|
||||
|
||||
bool operator !=(const Coordinates& o) const
|
||||
{
|
||||
return
|
||||
mLine != o.mLine ||
|
||||
mColumn != o.mColumn;
|
||||
}
|
||||
|
||||
bool operator <(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine < o.mLine;
|
||||
return mColumn < o.mColumn;
|
||||
}
|
||||
|
||||
bool operator >(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine > o.mLine;
|
||||
return mColumn > o.mColumn;
|
||||
}
|
||||
|
||||
bool operator <=(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine < o.mLine;
|
||||
return mColumn <= o.mColumn;
|
||||
}
|
||||
|
||||
bool operator >=(const Coordinates& o) const
|
||||
{
|
||||
if (mLine != o.mLine)
|
||||
return mLine > o.mLine;
|
||||
return mColumn >= o.mColumn;
|
||||
}
|
||||
};
|
||||
|
||||
struct Identifier
|
||||
{
|
||||
Coordinates mLocation;
|
||||
std::string mDeclaration;
|
||||
};
|
||||
|
||||
typedef std::string String;
|
||||
typedef std::unordered_map<std::string, Identifier> Identifiers;
|
||||
typedef std::unordered_set<std::string> Keywords;
|
||||
typedef std::map<int, std::string> ErrorMarkers;
|
||||
typedef std::unordered_set<int> Breakpoints;
|
||||
typedef std::array<ImU32, (unsigned)PaletteIndex::Max> Palette;
|
||||
typedef uint8_t Char;
|
||||
|
||||
struct Glyph
|
||||
{
|
||||
Char mChar;
|
||||
PaletteIndex mColorIndex = PaletteIndex::Default;
|
||||
bool mComment : 1;
|
||||
bool mMultiLineComment : 1;
|
||||
bool mPreprocessor : 1;
|
||||
|
||||
Glyph(Char aChar, PaletteIndex aColorIndex) : mChar(aChar), mColorIndex(aColorIndex),
|
||||
mComment(false), mMultiLineComment(false), mPreprocessor(false) {}
|
||||
};
|
||||
|
||||
typedef std::vector<Glyph> Line;
|
||||
typedef std::vector<Line> Lines;
|
||||
|
||||
struct LanguageDefinition
|
||||
{
|
||||
typedef std::pair<std::string, PaletteIndex> TokenRegexString;
|
||||
typedef std::vector<TokenRegexString> TokenRegexStrings;
|
||||
typedef bool(*TokenizeCallback)(const char * in_begin, const char * in_end, const char *& out_begin, const char *& out_end, PaletteIndex & paletteIndex);
|
||||
|
||||
std::string mName;
|
||||
Keywords mKeywords;
|
||||
Identifiers mIdentifiers;
|
||||
Identifiers mPreprocIdentifiers;
|
||||
std::string mCommentStart, mCommentEnd, mSingleLineComment;
|
||||
char mPreprocChar;
|
||||
bool mAutoIndentation;
|
||||
|
||||
TokenizeCallback mTokenize;
|
||||
|
||||
TokenRegexStrings mTokenRegexStrings;
|
||||
|
||||
bool mCaseSensitive;
|
||||
|
||||
LanguageDefinition()
|
||||
: mPreprocChar('#'), mAutoIndentation(true), mTokenize(nullptr), mCaseSensitive(true)
|
||||
{
|
||||
}
|
||||
|
||||
static const LanguageDefinition& CPlusPlus();
|
||||
static const LanguageDefinition& HLSL();
|
||||
static const LanguageDefinition& GLSL();
|
||||
static const LanguageDefinition& C();
|
||||
static const LanguageDefinition& SQL();
|
||||
static const LanguageDefinition& AngelScript();
|
||||
static const LanguageDefinition& Lua();
|
||||
};
|
||||
|
||||
TextEditor();
|
||||
~TextEditor();
|
||||
|
||||
void SetLanguageDefinition(const LanguageDefinition& aLanguageDef);
|
||||
const LanguageDefinition& GetLanguageDefinition() const { return mLanguageDefinition; }
|
||||
|
||||
const Palette& GetPalette() const { return mPaletteBase; }
|
||||
void SetPalette(const Palette& aValue);
|
||||
|
||||
void SetErrorMarkers(const ErrorMarkers& aMarkers) { mErrorMarkers = aMarkers; }
|
||||
void SetBreakpoints(const Breakpoints& aMarkers) { mBreakpoints = aMarkers; }
|
||||
|
||||
void Render(const char* aTitle, const ImVec2& aSize = ImVec2(), bool aBorder = false);
|
||||
void SetText(const std::string& aText);
|
||||
std::string GetText() const;
|
||||
|
||||
void SetTextLines(const std::vector<std::string>& aLines);
|
||||
std::vector<std::string> GetTextLines() const;
|
||||
|
||||
std::string GetSelectedText() const;
|
||||
std::string GetCurrentLineText()const;
|
||||
|
||||
int GetTotalLines() const { return (int)mLines.size(); }
|
||||
bool IsOverwrite() const { return mOverwrite; }
|
||||
|
||||
void SetReadOnly(bool aValue);
|
||||
bool IsReadOnly() const { return mReadOnly; }
|
||||
bool IsTextChanged() const { return mTextChanged; }
|
||||
bool IsCursorPositionChanged() const { return mCursorPositionChanged; }
|
||||
|
||||
bool IsColorizerEnabled() const { return mColorizerEnabled; }
|
||||
void SetColorizerEnable(bool aValue);
|
||||
|
||||
Coordinates GetCursorPosition() const { return GetActualCursorCoordinates(); }
|
||||
void SetCursorPosition(const Coordinates& aPosition);
|
||||
|
||||
inline void SetHandleMouseInputs (bool aValue){ mHandleMouseInputs = aValue;}
|
||||
inline bool IsHandleMouseInputsEnabled() const { return mHandleKeyboardInputs; }
|
||||
|
||||
inline void SetHandleKeyboardInputs (bool aValue){ mHandleKeyboardInputs = aValue;}
|
||||
inline bool IsHandleKeyboardInputsEnabled() const { return mHandleKeyboardInputs; }
|
||||
|
||||
inline void SetImGuiChildIgnored (bool aValue){ mIgnoreImGuiChild = aValue;}
|
||||
inline bool IsImGuiChildIgnored() const { return mIgnoreImGuiChild; }
|
||||
|
||||
inline void SetShowWhitespaces(bool aValue) { mShowWhitespaces = aValue; }
|
||||
inline bool IsShowingWhitespaces() const { return mShowWhitespaces; }
|
||||
|
||||
void SetTabSize(int aValue);
|
||||
inline int GetTabSize() const { return mTabSize; }
|
||||
|
||||
void InsertText(const std::string& aValue);
|
||||
void InsertText(const char* aValue);
|
||||
|
||||
void MoveUp(int aAmount = 1, bool aSelect = false);
|
||||
void MoveDown(int aAmount = 1, bool aSelect = false);
|
||||
void MoveLeft(int aAmount = 1, bool aSelect = false, bool aWordMode = false);
|
||||
void MoveRight(int aAmount = 1, bool aSelect = false, bool aWordMode = false);
|
||||
void MoveTop(bool aSelect = false);
|
||||
void MoveBottom(bool aSelect = false);
|
||||
void MoveHome(bool aSelect = false);
|
||||
void MoveEnd(bool aSelect = false);
|
||||
|
||||
void SetSelectionStart(const Coordinates& aPosition);
|
||||
void SetSelectionEnd(const Coordinates& aPosition);
|
||||
void SetSelection(const Coordinates& aStart, const Coordinates& aEnd, SelectionMode aMode = SelectionMode::Normal);
|
||||
void SelectWordUnderCursor();
|
||||
void SelectAll();
|
||||
bool HasSelection() const;
|
||||
|
||||
void Copy();
|
||||
void Cut();
|
||||
void Paste();
|
||||
void Delete();
|
||||
|
||||
bool CanUndo() const;
|
||||
bool CanRedo() const;
|
||||
void Undo(int aSteps = 1);
|
||||
void Redo(int aSteps = 1);
|
||||
|
||||
static const Palette& GetDarkPalette();
|
||||
static const Palette& GetLightPalette();
|
||||
static const Palette& GetRetroBluePalette();
|
||||
|
||||
private:
|
||||
typedef std::vector<std::pair<std::regex, PaletteIndex>> RegexList;
|
||||
|
||||
struct EditorState
|
||||
{
|
||||
Coordinates mSelectionStart;
|
||||
Coordinates mSelectionEnd;
|
||||
Coordinates mCursorPosition;
|
||||
};
|
||||
|
||||
class UndoRecord
|
||||
{
|
||||
public:
|
||||
UndoRecord() {}
|
||||
~UndoRecord() {}
|
||||
|
||||
UndoRecord(
|
||||
const std::string& aAdded,
|
||||
const TextEditor::Coordinates aAddedStart,
|
||||
const TextEditor::Coordinates aAddedEnd,
|
||||
|
||||
const std::string& aRemoved,
|
||||
const TextEditor::Coordinates aRemovedStart,
|
||||
const TextEditor::Coordinates aRemovedEnd,
|
||||
|
||||
TextEditor::EditorState& aBefore,
|
||||
TextEditor::EditorState& aAfter);
|
||||
|
||||
void Undo(TextEditor* aEditor);
|
||||
void Redo(TextEditor* aEditor);
|
||||
|
||||
std::string mAdded;
|
||||
Coordinates mAddedStart;
|
||||
Coordinates mAddedEnd;
|
||||
|
||||
std::string mRemoved;
|
||||
Coordinates mRemovedStart;
|
||||
Coordinates mRemovedEnd;
|
||||
|
||||
EditorState mBefore;
|
||||
EditorState mAfter;
|
||||
};
|
||||
|
||||
typedef std::vector<UndoRecord> UndoBuffer;
|
||||
|
||||
void ProcessInputs();
|
||||
void Colorize(int aFromLine = 0, int aCount = -1);
|
||||
void ColorizeRange(int aFromLine = 0, int aToLine = 0);
|
||||
void ColorizeInternal();
|
||||
float TextDistanceToLineStart(const Coordinates& aFrom) const;
|
||||
void EnsureCursorVisible();
|
||||
int GetPageSize() const;
|
||||
std::string GetText(const Coordinates& aStart, const Coordinates& aEnd) const;
|
||||
Coordinates GetActualCursorCoordinates() const;
|
||||
Coordinates SanitizeCoordinates(const Coordinates& aValue) const;
|
||||
void Advance(Coordinates& aCoordinates) const;
|
||||
void DeleteRange(const Coordinates& aStart, const Coordinates& aEnd);
|
||||
int InsertTextAt(Coordinates& aWhere, const char* aValue);
|
||||
void AddUndo(UndoRecord& aValue);
|
||||
Coordinates ScreenPosToCoordinates(const ImVec2& aPosition) const;
|
||||
Coordinates FindWordStart(const Coordinates& aFrom) const;
|
||||
Coordinates FindWordEnd(const Coordinates& aFrom) const;
|
||||
Coordinates FindNextWord(const Coordinates& aFrom) const;
|
||||
int GetCharacterIndex(const Coordinates& aCoordinates) const;
|
||||
int GetCharacterColumn(int aLine, int aIndex) const;
|
||||
int GetLineCharacterCount(int aLine) const;
|
||||
int GetLineMaxColumn(int aLine) const;
|
||||
bool IsOnWordBoundary(const Coordinates& aAt) const;
|
||||
void RemoveLine(int aStart, int aEnd);
|
||||
void RemoveLine(int aIndex);
|
||||
Line& InsertLine(int aIndex);
|
||||
void EnterCharacter(ImWchar aChar, bool aShift);
|
||||
void Backspace();
|
||||
void DeleteSelection();
|
||||
std::string GetWordUnderCursor() const;
|
||||
std::string GetWordAt(const Coordinates& aCoords) const;
|
||||
ImU32 GetGlyphColor(const Glyph& aGlyph) const;
|
||||
|
||||
void HandleKeyboardInputs();
|
||||
void HandleMouseInputs();
|
||||
void Render();
|
||||
|
||||
float mLineSpacing;
|
||||
Lines mLines;
|
||||
EditorState mState;
|
||||
UndoBuffer mUndoBuffer;
|
||||
int mUndoIndex;
|
||||
|
||||
int mTabSize;
|
||||
bool mOverwrite;
|
||||
bool mReadOnly;
|
||||
bool mWithinRender;
|
||||
bool mScrollToCursor;
|
||||
bool mScrollToTop;
|
||||
bool mTextChanged;
|
||||
bool mColorizerEnabled;
|
||||
float mTextStart; // position (in pixels) where a code line starts relative to the left of the TextEditor.
|
||||
int mLeftMargin;
|
||||
bool mCursorPositionChanged;
|
||||
int mColorRangeMin, mColorRangeMax;
|
||||
SelectionMode mSelectionMode;
|
||||
bool mHandleKeyboardInputs;
|
||||
bool mHandleMouseInputs;
|
||||
bool mIgnoreImGuiChild;
|
||||
bool mShowWhitespaces;
|
||||
|
||||
Palette mPaletteBase;
|
||||
Palette mPalette;
|
||||
LanguageDefinition mLanguageDefinition;
|
||||
RegexList mRegexList;
|
||||
|
||||
bool mCheckComments;
|
||||
Breakpoints mBreakpoints;
|
||||
ErrorMarkers mErrorMarkers;
|
||||
ImVec2 mCharAdvance;
|
||||
Coordinates mInteractiveStart, mInteractiveEnd;
|
||||
std::string mLineBuffer;
|
||||
uint64_t mStartTime;
|
||||
|
||||
float mLastClick;
|
||||
};
|
||||
|
||||
}
|
@ -2741,7 +2741,6 @@ The following libraries are included with and used by the Tracy Profiler. Entrie
|
||||
\item MIT license
|
||||
\begin{itemize}
|
||||
\item Dear ImGui -- \url{https://github.com/ocornut/imgui}
|
||||
\item ImGuiColorTextEdit -- \url{https://github.com/BalazsJako/ImGuiColorTextEdit}
|
||||
\item JSON for Modern C++ -- \url{https://github.com/nlohmann/json}
|
||||
\item robin-hood-hashing -- \url{https://github.com/martinus/robin-hood-hashing}
|
||||
\end{itemize}
|
||||
|
@ -105,7 +105,6 @@
|
||||
<ClCompile Include="..\..\..\common\TracySystem.cpp" />
|
||||
<ClCompile Include="..\..\..\common\tracy_lz4.cpp" />
|
||||
<ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" />
|
||||
<ClCompile Include="..\..\..\imguicolortextedit\TextEditor.cpp" />
|
||||
<ClCompile Include="..\..\..\imgui\imgui.cpp" />
|
||||
<ClCompile Include="..\..\..\imgui\imgui_demo.cpp" />
|
||||
<ClCompile Include="..\..\..\imgui\imgui_draw.cpp" />
|
||||
@ -116,6 +115,7 @@
|
||||
<ClCompile Include="..\..\..\server\TracyMemory.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyMmap.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyPrint.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracySourceView.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyStorage.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTaskDispatch.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTexture.cpp" />
|
||||
@ -171,7 +171,6 @@
|
||||
<ClInclude Include="..\..\..\common\TracySystem.hpp" />
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp" />
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4hc.hpp" />
|
||||
<ClInclude Include="..\..\..\imguicolortextedit\TextEditor.h" />
|
||||
<ClInclude Include="..\..\..\imgui\imconfig.h" />
|
||||
<ClInclude Include="..\..\..\imgui\imgui.h" />
|
||||
<ClInclude Include="..\..\..\imgui\imgui_internal.h" />
|
||||
@ -199,6 +198,7 @@
|
||||
<ClInclude Include="..\..\..\server\TracyShortPtr.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracySlab.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracySort.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracySourceView.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyStorage.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyStringDiscovery.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTaskDispatch.hpp" />
|
||||
|
@ -19,9 +19,6 @@
|
||||
<Filter Include="nfd">
|
||||
<UniqueIdentifier>{46eb6aa0-de1c-447a-a6dd-aee2a06f85ef}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="imguicolortextedit">
|
||||
<UniqueIdentifier>{96740ecd-86b9-452d-991c-8743dde61551}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="zstd">
|
||||
<UniqueIdentifier>{c67291b2-9e67-4915-b80f-6891ceb683a3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@ -60,9 +57,6 @@
|
||||
<ClCompile Include="..\..\..\server\TracyBadVersion.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\imguicolortextedit\TextEditor.cpp">
|
||||
<Filter>imguicolortextedit</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\imgui_freetype.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
@ -195,6 +189,9 @@
|
||||
<ClCompile Include="..\..\..\server\TracyTextureCompression.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\server\TracySourceView.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||
@ -296,9 +293,6 @@
|
||||
<ClInclude Include="..\..\..\server\TracyFilesystem.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\imguicolortextedit\TextEditor.h">
|
||||
<Filter>imguicolortextedit</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\FontAwesomeSolid.hpp">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
@ -479,6 +473,9 @@
|
||||
<ClInclude Include="..\..\..\server\TracyTextureCompression.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\server\TracySourceView.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="DebugVis.natvis" />
|
||||
|
114
server/TracySourceView.cpp
Normal file
114
server/TracySourceView.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../imgui/imgui.h"
|
||||
#include "TracyImGui.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
|
||||
#include "TracySourceView.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
SourceView::SourceView( ImFont* font )
|
||||
: m_font( font )
|
||||
, m_file( nullptr )
|
||||
, m_data( nullptr )
|
||||
, m_dataSize( 0 )
|
||||
, m_targetLine( 0 )
|
||||
, m_selectedLine( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
SourceView::~SourceView()
|
||||
{
|
||||
delete[] m_data;
|
||||
}
|
||||
|
||||
void SourceView::Open( const char* fileName, int line )
|
||||
{
|
||||
m_targetLine = line;
|
||||
m_selectedLine = line;
|
||||
|
||||
if( m_file != fileName )
|
||||
{
|
||||
m_file = fileName;
|
||||
FILE* f = fopen( fileName, "rb" );
|
||||
fseek( f, 0, SEEK_END );
|
||||
const auto sz = ftell( f );
|
||||
fseek( f, 0, SEEK_SET );
|
||||
if( sz > m_dataSize )
|
||||
{
|
||||
delete[] m_data;
|
||||
m_data = new char[sz+1];
|
||||
m_dataSize = sz;
|
||||
}
|
||||
fread( m_data, 1, sz, f );
|
||||
m_data[sz] = '\0';
|
||||
fclose( f );
|
||||
|
||||
m_lines.clear();
|
||||
auto txt = m_data;
|
||||
for(;;)
|
||||
{
|
||||
auto end = txt;
|
||||
while( *end != '\n' && *end != '\r' && end - m_data < sz ) end++;
|
||||
m_lines.emplace_back( Line { txt, end } );
|
||||
if( *end == '\n' )
|
||||
{
|
||||
end++;
|
||||
if( *end == '\r' ) end++;
|
||||
}
|
||||
else if( *end == '\r' )
|
||||
{
|
||||
end++;
|
||||
if( *end == '\n' ) end++;
|
||||
}
|
||||
if( *end == '\0' ) break;
|
||||
txt = end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SourceView::Render()
|
||||
{
|
||||
ImGui::BeginChild( "##sourceView", ImVec2( 0, 0 ), true );
|
||||
if( m_font ) ImGui::PushFont( m_font );
|
||||
const auto nw = ImGui::CalcTextSize( "123,345" ).x;
|
||||
int lineNum = 1;
|
||||
for( auto& line : m_lines )
|
||||
{
|
||||
if( m_targetLine == lineNum )
|
||||
{
|
||||
m_targetLine = 0;
|
||||
ImGui::SetScrollHereY();
|
||||
}
|
||||
RenderLine( line, lineNum++ );
|
||||
}
|
||||
if( m_font ) ImGui::PopFont();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
void SourceView::RenderLine( const Line& line, int lineNum )
|
||||
{
|
||||
const auto ty = ImGui::GetFontSize();
|
||||
auto draw = ImGui::GetWindowDrawList();
|
||||
const auto w = ImGui::GetWindowWidth();
|
||||
const auto wpos = ImGui::GetCursorScreenPos();
|
||||
if( lineNum == m_selectedLine )
|
||||
{
|
||||
draw->AddRectFilled( wpos, wpos + ImVec2( w, ty+1 ), 0xFF333322 );
|
||||
}
|
||||
|
||||
const auto lineString = RealToString( lineNum );
|
||||
const auto linesz = strlen( lineString );
|
||||
char buf[16];
|
||||
memset( buf, ' ', 7 - linesz );
|
||||
memcpy( buf + 7 - linesz, lineString, linesz+1 );
|
||||
TextDisabledUnformatted( buf );
|
||||
ImGui::SameLine( 0, ty );
|
||||
ImGui::TextUnformatted( line.begin, line.end );
|
||||
|
||||
draw->AddLine( wpos + ImVec2( 0, ty+2 ), wpos + ImVec2( w, ty+2 ), 0x08FFFFFF );
|
||||
}
|
||||
|
||||
}
|
36
server/TracySourceView.hpp
Normal file
36
server/TracySourceView.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
#include <vector>
|
||||
|
||||
struct ImFont;
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class SourceView
|
||||
{
|
||||
struct Line
|
||||
{
|
||||
const char* begin;
|
||||
const char* end;
|
||||
};
|
||||
|
||||
public:
|
||||
SourceView( ImFont* font );
|
||||
~SourceView();
|
||||
|
||||
void Open( const char* fileName, int line );
|
||||
void Render();
|
||||
|
||||
private:
|
||||
void RenderLine( const Line& line, int lineNum );
|
||||
|
||||
ImFont* m_font;
|
||||
const char* m_file;
|
||||
char* m_data;
|
||||
size_t m_dataSize;
|
||||
int m_targetLine;
|
||||
int m_selectedLine;
|
||||
|
||||
std::vector<Line> m_lines;
|
||||
};
|
||||
|
||||
}
|
@ -35,10 +35,9 @@
|
||||
#include "TracyPopcnt.hpp"
|
||||
#include "TracyPrint.hpp"
|
||||
#include "TracySort.hpp"
|
||||
#include "TracySourceView.hpp"
|
||||
#include "TracyView.hpp"
|
||||
|
||||
#include "../imguicolortextedit/TextEditor.h"
|
||||
|
||||
#ifdef TRACY_FILESELECTOR
|
||||
# include "../nfd/nfd.h"
|
||||
#endif
|
||||
@ -134,7 +133,6 @@ View::View( const char* addr, int port, ImFont* fixedWidth, ImFont* smallFont, I
|
||||
, m_pause( false )
|
||||
, m_frames( nullptr )
|
||||
, m_messagesScrollBottom( true )
|
||||
, m_textEditorFont( fixedWidth )
|
||||
, m_smallFont( smallFont )
|
||||
, m_bigFont( bigFont )
|
||||
, m_stcb( stcb )
|
||||
@ -143,7 +141,7 @@ View::View( const char* addr, int port, ImFont* fixedWidth, ImFont* smallFont, I
|
||||
assert( s_instance == nullptr );
|
||||
s_instance = this;
|
||||
|
||||
InitTextEditor();
|
||||
InitTextEditor( fixedWidth );
|
||||
}
|
||||
|
||||
View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb )
|
||||
@ -153,7 +151,6 @@ View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont,
|
||||
, m_pause( true )
|
||||
, m_frames( m_worker.GetFramesBase() )
|
||||
, m_messagesScrollBottom( false )
|
||||
, m_textEditorFont( fixedWidth )
|
||||
, m_smallFont( smallFont )
|
||||
, m_bigFont( bigFont )
|
||||
, m_stcb( stcb )
|
||||
@ -165,7 +162,7 @@ View::View( FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont,
|
||||
m_notificationTime = 4;
|
||||
m_notificationText = std::string( "Trace loaded in " ) + TimeToString( m_worker.GetLoadTime() );
|
||||
|
||||
InitTextEditor();
|
||||
InitTextEditor( fixedWidth );
|
||||
SetViewToLastFrames();
|
||||
m_userData.StateShouldBePreserved();
|
||||
m_userData.LoadState( m_vd );
|
||||
@ -190,18 +187,19 @@ View::~View()
|
||||
s_instance = nullptr;
|
||||
}
|
||||
|
||||
void View::InitTextEditor()
|
||||
void View::InitTextEditor( ImFont* font )
|
||||
{
|
||||
m_textEditor = std::make_unique<TextEditor>();
|
||||
m_textEditor->SetReadOnly( true );
|
||||
m_textEditor->SetLanguageDefinition( TextEditor::LanguageDefinition::CPlusPlus() );
|
||||
m_textEditor->SetShowWhitespaces( m_textEditorWhitespace );
|
||||
|
||||
m_textEditorFile = nullptr;
|
||||
m_sourceView = std::make_unique<SourceView>( font );
|
||||
m_sourceViewFile = nullptr;
|
||||
}
|
||||
|
||||
void View::SetTextEditorFile( const char* fileName, int line )
|
||||
{
|
||||
m_sourceViewFile = fileName;
|
||||
m_sourceView->Open( fileName, line );
|
||||
|
||||
#if 0
|
||||
// DUPA
|
||||
if( !m_textEditorFile || strcmp( m_textEditorFile, fileName ) != 0 )
|
||||
{
|
||||
FILE* f = fopen( fileName, "rb" );
|
||||
@ -219,6 +217,7 @@ void View::SetTextEditorFile( const char* fileName, int line )
|
||||
m_textEditor->SetCursorPosition( TextEditor::Coordinates( line-1, 0 ) );
|
||||
|
||||
m_textEditorFile = fileName;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char* View::ShortenNamespace( const char* name ) const
|
||||
@ -722,7 +721,7 @@ bool View::DrawImpl()
|
||||
if( m_callstackInfoWindow != 0 ) DrawCallstackWindow();
|
||||
if( m_memoryAllocInfoWindow >= 0 ) DrawMemoryAllocWindow();
|
||||
if( m_showInfo ) DrawInfo();
|
||||
if( m_textEditorFile ) DrawTextEditor();
|
||||
if( m_sourceViewFile ) DrawTextEditor();
|
||||
if( m_goToFrame ) DrawGoToFrame();
|
||||
if( m_lockInfoWindow != InvalidId ) DrawLockInfoWindow();
|
||||
if( m_showPlayback ) DrawPlayback();
|
||||
@ -6364,7 +6363,7 @@ void View::DrawZoneInfoWindow()
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
bool hilite = m_textEditorFile == fileName;
|
||||
bool hilite = m_sourceViewFile == fileName;
|
||||
if( hilite )
|
||||
{
|
||||
SetButtonHighlightColor();
|
||||
@ -7341,7 +7340,7 @@ void View::DrawGpuInfoWindow()
|
||||
if( SourceFileValid( fileName, m_worker.GetCaptureTime() ) )
|
||||
{
|
||||
ImGui::SameLine();
|
||||
bool hilite = m_textEditorFile == fileName;
|
||||
bool hilite = m_sourceViewFile == fileName;
|
||||
if( hilite )
|
||||
{
|
||||
SetButtonHighlightColor();
|
||||
@ -13059,16 +13058,10 @@ void View::DrawTextEditor()
|
||||
#else
|
||||
TextColoredUnformatted( ImVec4( 1.f, 1.f, 0.2f, 1.f ), "/!\\" );
|
||||
#endif
|
||||
TextFocused( "File:", m_textEditorFile );
|
||||
if( SmallCheckbox( "Show whitespace", &m_textEditorWhitespace ) )
|
||||
{
|
||||
m_textEditor->SetShowWhitespaces( m_textEditorWhitespace );
|
||||
}
|
||||
if( m_textEditorFont ) ImGui::PushFont( m_textEditorFont );
|
||||
m_textEditor->Render( m_textEditorFile, ImVec2(), true );
|
||||
if( m_textEditorFont ) ImGui::PopFont();
|
||||
TextFocused( "File:", m_sourceViewFile );
|
||||
m_sourceView->Render();
|
||||
ImGui::End();
|
||||
if( !show ) m_textEditorFile = nullptr;
|
||||
if( !show ) m_sourceViewFile = nullptr;
|
||||
}
|
||||
|
||||
void View::DrawGoToFrame()
|
||||
|
@ -28,7 +28,7 @@ namespace tracy
|
||||
struct MemoryPage;
|
||||
struct QueueItem;
|
||||
class FileRead;
|
||||
class TextEditor;
|
||||
class SourceView;
|
||||
struct ZoneTimeData;
|
||||
|
||||
class View
|
||||
@ -108,7 +108,7 @@ private:
|
||||
uint64_t mem;
|
||||
};
|
||||
|
||||
void InitTextEditor();
|
||||
void InitTextEditor( ImFont* font );
|
||||
|
||||
const char* ShortenNamespace( const char* name ) const;
|
||||
|
||||
@ -380,10 +380,8 @@ private:
|
||||
Vector<const ZoneEvent*> m_zoneInfoStack;
|
||||
Vector<const GpuEvent*> m_gpuInfoStack;
|
||||
|
||||
std::unique_ptr<TextEditor> m_textEditor;
|
||||
const char* m_textEditorFile;
|
||||
ImFont* m_textEditorFont;
|
||||
bool m_textEditorWhitespace = true;
|
||||
std::unique_ptr<SourceView> m_sourceView;
|
||||
const char* m_sourceViewFile;
|
||||
|
||||
ImFont* m_smallFont;
|
||||
ImFont* m_bigFont;
|
||||
|
Loading…
Reference in New Issue
Block a user