forked from romaonishuk/LexI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TextView is a glyph that is a text editor glyph, that provides functionality to control glyphs that are drawn, manages pages, etc Add: - DrawAt function to window interface - Get key function to KeyboardEvent
- Loading branch information
Roman Onyshchuk
authored and
Roman Onyshchuk
committed
Apr 20, 2020
1 parent
7bf0636
commit 26d0963
Showing
11 changed files
with
184 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,82 @@ | ||
// | ||
// Created by ronyshchuk on 07.04.20. | ||
// | ||
|
||
#include "text_view.hpp" | ||
#include "cursor.hpp" | ||
#include "font.hpp" | ||
#include "page.hpp" | ||
#include "window.hpp" | ||
|
||
TextView::TextView(const GlyphParams& params, Gui::Window* w): | ||
Gui::Window(params, w), | ||
m_visibleArea(0, 0, params.width, params.height) | ||
{ | ||
const auto pageHeight = 200; | ||
m_currentPage = std::make_shared<Page>(this, GlyphParams{0, 0, m_params.width - 1, pageHeight}); | ||
ICompositeGlyph::Add(m_currentPage); | ||
m_visiblePages.push_back(m_currentPage); | ||
this->ShowWindow(); | ||
} | ||
|
||
void TextView::Draw(Gui::Window* window) | ||
{ | ||
for(auto& page: m_visiblePages) { | ||
page->Draw(this); | ||
} | ||
|
||
m_currentPage->DrawCursor(this); | ||
} | ||
|
||
// TODO(rmn): chunking | ||
void TextView::ProcessEvent(Gui::Window* window, const Event& event) | ||
{ | ||
if(event.GetEvent() == EventType::KeyPressed) { | ||
m_currentPage->ProcessEvent(window, event); | ||
|
||
if(Lexi::Cursor::Get().GetCursorEnd() < m_visibleArea.y) { | ||
m_visibleArea.y -= Lexi::FontManager::Get().GetCharHeight(); | ||
IGlyph::ReDraw(window); | ||
} | ||
|
||
if(Lexi::Cursor::Get().GetCursorEnd() > m_visibleArea.y + m_params.height) { | ||
m_visibleArea.y += Lexi::FontManager::Get().GetCharHeight(); | ||
IGlyph::ReDraw(window); | ||
} | ||
|
||
return; | ||
} | ||
} | ||
|
||
void TextView::DrawRectangle(const GlyphParams& params) const | ||
{ | ||
if(m_visibleArea.IsIntersects(params) || params.IsIntersects(m_visibleArea)) { | ||
m_window_impl->DrawRectangle({params.x, params.y - m_visibleArea.y}, params.width, params.height); | ||
} | ||
} | ||
|
||
void TextView::DrawText(const Point& text_position, std::string text) const | ||
{ | ||
if(m_visibleArea.IsIntersects({text_position.x, text_position.y})) { | ||
m_window_impl->DrawText({text_position.x, text_position.y - m_visibleArea.y}, text); | ||
} | ||
} | ||
|
||
void TextView::DrawLine(const Point& start_point, const Point& end_point) const | ||
{ | ||
// TODO(rmn) :intersection | ||
m_window_impl->DrawLine( | ||
{start_point.x, start_point.y - m_visibleArea.y}, {end_point.x, end_point.y - m_visibleArea.y}); | ||
} | ||
|
||
void TextView::UpdateVisibleArea(height_t h) | ||
{ | ||
m_visibleArea.y = h; | ||
Draw(this); | ||
} | ||
|
||
void TextView::MoveVisibleArea(height_t h) | ||
{ | ||
m_visibleArea.y += h; | ||
Draw(this); | ||
} |
Oops, something went wrong.