Skip to content

Commit a7668df

Browse files
committed
Fixing markers
1 parent 748c41f commit a7668df

File tree

7 files changed

+57
-44
lines changed

7 files changed

+57
-44
lines changed

.zep/project.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ include = [
2424
"*.hpp",
2525
"*.txt",
2626
"*.cmake",
27-
"*.orca"
27+
"*.orca",
28+
"*.cfg"
2829
]

include/zep/display.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class ZepDisplay
4040
virtual uint32_t GetCodePointCount(const uint8_t* pCh, const uint8_t* pEnd) const;
4141
virtual NVec2f GetCharSize(const uint8_t* pChar);
4242
virtual const NVec2f& GetDefaultCharSize();
43+
virtual const NVec2f& GetDotSize();
4344
virtual void InvalidateCharCache();
4445
virtual void DrawRect(const NRectf& rc, const NVec4f& col = NVec4f(1.0f)) const;
4546

@@ -52,6 +53,7 @@ class ZepDisplay
5253
NVec2f m_charCacheASCII[256];
5354

5455
NVec2f m_defaultCharSize;
56+
NVec2f m_dotSize;
5557
};
5658

5759
// A NULL renderer, used for testing

include/zep/window.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ZepWindow : public ZepComponent
172172
NVec2i BufferToDisplay(const GlyphIterator& location);
173173

174174
void ScrollToCursor();
175-
bool IsInsideTextRegion(NVec2i pos) const;
175+
bool IsInsideVisibleText(NVec2i pos) const;
176176

177177
enum class SpecialChar
178178
{

src/display.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ void ZepDisplay::BuildCharCache()
2525
m_charCacheASCII[i] = GetTextSize(&ch, &ch + 1);
2626
}
2727
m_charCacheDirty = false;
28+
29+
m_dotSize = m_defaultCharSize / 8.0f;
30+
m_dotSize.x = std::min(m_dotSize.x, m_dotSize.y);
31+
m_dotSize.y = std::min(m_dotSize.x, m_dotSize.y);
32+
m_dotSize.x = std::max(1.0f, m_dotSize.x);
33+
m_dotSize.y = std::max(1.0f, m_dotSize.y);
2834
}
2935

3036
const NVec2f& ZepDisplay::GetDefaultCharSize()
@@ -33,9 +39,15 @@ const NVec2f& ZepDisplay::GetDefaultCharSize()
3339
{
3440
BuildCharCache();
3541
}
42+
3643
return m_defaultCharSize;
3744
}
3845

46+
const NVec2f& ZepDisplay::GetDotSize()
47+
{
48+
return m_dotSize;
49+
}
50+
3951
uint32_t ZepDisplay::GetCodePointCount(const uint8_t* pCh, const uint8_t* pEnd) const
4052
{
4153
uint32_t count = 0;

src/syntax.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,6 @@ SyntaxResult ZepSyntax::GetSyntaxAt(const GlyphIterator& offset) const
5959
}
6060
}
6161

62-
if (!(m_flags & ZepSyntaxFlags::IgnoreLineHighlight))
63-
{
64-
if (offset.Index() >= m_activeLineRange.first && offset.Index() < (m_activeLineRange.second - 1))
65-
{
66-
result.background = ThemeColor::CursorLineBackground;
67-
}
68-
}
69-
7062
if (m_flashRange.x != m_flashRange.y && m_flashRange.x <= offset.Index() && m_flashRange.y > offset.Index())
7163
{
7264
auto elapsed = timer_get_elapsed_seconds(m_flashTimer);

src/window.cpp

+36-33
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ namespace Zep
3333
{
3434

3535
const float ScrollBarSize = 17.0f;
36+
const float UnderlineMargin = 1.0f;
37+
3638
ZepWindow::ZepWindow(ZepTabWindow& window, ZepBuffer* buffer)
3739
: ZepComponent(window.GetEditor())
3840
, m_tabWindow(window)
@@ -342,7 +344,7 @@ NVec2f ZepWindow::ArrangeLineMarkers(tRangeMarkers& markers)
342344
{
343345
// Account for markers
344346
auto margins = DPI_VEC2(GetEditor().GetConfig().widgetMargins);
345-
auto underlineHeight = DPI_Y(GetEditor().GetConfig().underlineHeight) + DPI_Y(2.0f);
347+
auto underlineHeight = DPI_Y(GetEditor().GetConfig().underlineHeight) + DPI_Y(UnderlineMargin * 2.0f);
346348
NVec2f height(0.0f);
347349

348350
uint32_t lineWidgetCount = 0;
@@ -752,20 +754,37 @@ NRectf SquareRect(const NRectf& rc)
752754

753755
void ZepWindow::DisplayLineBackground(SpanInfo& lineInfo, ZepSyntax* pSyntax)
754756
{
755-
auto cursorCL = BufferToDisplay();
756757
auto& display = GetEditor().GetDisplay();
757758

758759
auto widgetMargins = DPI_VEC2(GetEditor().GetConfig().widgetMargins);
759760
auto underlineHeight = DPI_Y(GetEditor().GetConfig().underlineHeight);
760761
auto inlineMargins = DPI_VEC2(GetEditor().GetConfig().inlineWidgetMargins);
761-
762762
auto screenPosX = m_textRegion->rect.Left() + m_xPad;
763-
764763
auto widgetMarkers = m_pBuffer->GetRangeMarkers(RangeMarkerType::Widget);
765764
auto itrWidgetMarkers = widgetMarkers.begin();
766-
767765
auto tipTimeSeconds = timer_get_elapsed_seconds(m_toolTipTimer);
768766

767+
NVec2f linePx = GetSpanPixelRange(lineInfo);
768+
769+
if (lineInfo.lineByteRange.ContainsLocation(GetBufferCursor().Index()))
770+
{
771+
// Note; We fill below the line for underlines for now, to make them standout in minimal mode
772+
display.DrawRectFilled(
773+
NRectf(
774+
NVec2f(linePx.x, ToWindowY(lineInfo.yOffsetPx)),
775+
NVec2f(linePx.y, ToWindowY(lineInfo.yOffsetPx + lineInfo.FullLineHeightPx() + lineInfo.lineWidgetHeights.y))),
776+
GetBlendedColor(ThemeColor::CursorLineBackground));
777+
}
778+
else
779+
{
780+
// Fill the background of the line
781+
display.DrawRectFilled(
782+
NRectf(
783+
NVec2f(linePx.x, ToWindowY(lineInfo.yOffsetPx)),
784+
NVec2f(linePx.y, ToWindowY(lineInfo.yOffsetPx + lineInfo.FullLineHeightPx() + lineInfo.lineWidgetHeights.y))),
785+
GetBlendedColor(ThemeColor::Background));
786+
}
787+
769788
// Walk from the start of the line to the end of the line (in buffer chars)
770789
for (auto& cp : lineInfo.lineCodePoints)
771790
{
@@ -838,7 +857,8 @@ void ZepWindow::DisplayLineBackground(SpanInfo& lineInfo, ZepSyntax* pSyntax)
838857
if (marker->displayType & RangeMarkerDisplayType::Underline)
839858
{
840859
float offset = lineInfo.yOffsetPx + lineInfo.FullLineHeightPx();
841-
offset += marker->displayRow * (DPI_Y(2.0f) + underlineHeight) + 1.0f; // Margins & an extra line to seperate from background highlight
860+
offset += marker->displayRow * (DPI_Y(UnderlineMargin * 2) + underlineHeight) + 1.0f; // Margins & an extra line to seperate from background highlight
861+
842862
display.DrawRectFilled(
843863
NRectf(NVec2f(screenPosX, ToWindowY(offset)),
844864
NVec2f(screenPosX + cp.size.x, ToWindowY(offset + underlineHeight))),
@@ -894,13 +914,13 @@ void ZepWindow::DisplayLineNumbers()
894914
auto cursorCL = BufferToDisplay();
895915
auto& display = GetEditor().GetDisplay();
896916

897-
if (m_indicatorRegion->rect.Width() > 0)
917+
if (m_numberRegion->rect.Width() > 0)
898918
{
899919
for (long windowLine = m_visibleLineIndices.x; windowLine < m_visibleLineIndices.y; windowLine++)
900920
{
901921
auto& lineInfo = *m_windowLines[windowLine];
902922

903-
if (!IsInsideTextRegion(NVec2i(0, lineInfo.spanLineIndex)))
923+
if (!IsInsideVisibleText(NVec2i(0, lineInfo.spanLineIndex)))
904924
return;
905925

906926
auto cursorBufferLine = GetCursorLineInfo(cursorCL.y).bufferLineNumber;
@@ -959,6 +979,7 @@ void ZepWindow::DisplayLineNumbers()
959979
}
960980
}
961981

982+
962983
// TODO: This function draws one char at a time. It could be more optimal at the expense of some
963984
// complexity. Basically, I don't like the current implementation, but it works for now.
964985
// The text is displayed acorrding to the region bounds and the display lineData
@@ -967,50 +988,31 @@ bool ZepWindow::DisplayLine(SpanInfo& lineInfo, int displayPass)
967988
{
968989
static const auto blankSpace = ' ';
969990

970-
auto cursorCL = BufferToDisplay();
971-
auto& display = GetEditor().GetDisplay();
972-
display.SetClipRect(m_bufferRegion->rect);
973-
974991
auto& buffer = GetBuffer();
975992
auto pMode = buffer.GetMode();
976993
if (!pMode)
977994
{
978995
return false;
979996
}
980997

998+
auto cursorCL = BufferToDisplay();
999+
auto& display = GetEditor().GetDisplay();
9811000
auto pSyntax = m_pBuffer->GetSyntax();
982-
9831001
auto cursorBlink = GetEditor().GetCursorBlinkState();
9841002
auto cursorType = GetBuffer().GetMode()->GetCursorType();
985-
986-
auto defaultCharSize = GetEditor().GetDisplay().GetDefaultCharSize();
1003+
auto defaultCharSize = display.GetDefaultCharSize();
1004+
auto dotSize = display.GetDotSize();
9871005
auto whiteSpaceCol = m_pBuffer->GetTheme().GetColor(ThemeColor::Whitespace);
988-
9891006
auto widgetMargins = DPI_VEC2(GetEditor().GetConfig().widgetMargins);
9901007

991-
auto dotSize = defaultCharSize / 8.0f;
992-
dotSize.x = std::min(dotSize.x, dotSize.y);
993-
dotSize.y = std::min(dotSize.x, dotSize.y);
994-
dotSize.x = std::max(1.0f, dotSize.x);
995-
dotSize.y = std::max(1.0f, dotSize.y);
996-
9971008
// Drawing commands for the whole line
9981009
if (displayPass == WindowPass::Background)
9991010
{
10001011
display.SetClipRect(m_textRegion->rect);
10011012

1002-
NVec2f linePx = GetSpanPixelRange(lineInfo);
1003-
1004-
// Fill the background of the line
1005-
// TODO: Adjust pixelRenderRange
1006-
display.DrawRectFilled(
1007-
NRectf(
1008-
NVec2f(linePx.x, ToWindowY(lineInfo.yOffsetPx)),
1009-
NVec2f(linePx.y, ToWindowY(lineInfo.yOffsetPx + lineInfo.FullLineHeightPx()))),
1010-
GetBlendedColor(ThemeColor::Background));
1011-
10121013
DisplayLineBackground(lineInfo, pSyntax);
10131014

1015+
/*
10141016
// Here we tell the syntax coloring about the active line
10151017
if (pSyntax)
10161018
{
@@ -1032,6 +1034,7 @@ bool ZepWindow::DisplayLine(SpanInfo& lineInfo, int displayPass)
10321034
}
10331035
}
10341036
}
1037+
*/
10351038
}
10361039

10371040
display.SetClipRect(m_textRegion->rect);
@@ -1192,7 +1195,7 @@ bool ZepWindow::DisplayLine(SpanInfo& lineInfo, int displayPass)
11921195
return true;
11931196
}
11941197

1195-
bool ZepWindow::IsInsideTextRegion(NVec2i pos) const
1198+
bool ZepWindow::IsInsideVisibleText(NVec2i pos) const
11961199
{
11971200
if (pos.y < m_visibleLineIndices.x || pos.y >= m_visibleLineIndices.y)
11981201
{

zep.cfg

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Vertical Scroller: 0 = off, 1 = on if necessary, 2 = on always
44
show_scrollbar = 0
55

6-
# Style: Normal, or Minimal for a live-coding style of editor
6+
# Style: normal, or minimal for a live-coding style of editor
77
style = "normal"
88
show_line_numbers = true
99
show_indicator_region = true
@@ -15,3 +15,6 @@ line_margin_top = 1
1515
line_margin_bottom = 1
1616
widget_margin_top = 5
1717
widget_margin_bottom = 5
18+
19+
background_fade_time = 20
20+
background_fade_wait = 5

0 commit comments

Comments
 (0)