mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
LibVT: Rename VT::BufferPosition to VT::Position and move to own file
This commit is contained in:
parent
e8eadd19a5
commit
4fb02c78a9
4 changed files with 59 additions and 53 deletions
|
@ -279,14 +279,14 @@ void Terminal::set_opacity(u8 new_opacity)
|
||||||
force_repaint();
|
force_repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
VT::BufferPosition Terminal::normalized_selection_start() const
|
VT::Position Terminal::normalized_selection_start() const
|
||||||
{
|
{
|
||||||
if (m_selection_start < m_selection_end)
|
if (m_selection_start < m_selection_end)
|
||||||
return m_selection_start;
|
return m_selection_start;
|
||||||
return m_selection_end;
|
return m_selection_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
VT::BufferPosition Terminal::normalized_selection_end() const
|
VT::Position Terminal::normalized_selection_end() const
|
||||||
{
|
{
|
||||||
if (m_selection_start < m_selection_end)
|
if (m_selection_start < m_selection_end)
|
||||||
return m_selection_end;
|
return m_selection_end;
|
||||||
|
@ -298,7 +298,7 @@ bool Terminal::has_selection() const
|
||||||
return m_selection_start.is_valid() && m_selection_end.is_valid();
|
return m_selection_start.is_valid() && m_selection_end.is_valid();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Terminal::selection_contains(const VT::BufferPosition& position) const
|
bool Terminal::selection_contains(const VT::Position& position) const
|
||||||
{
|
{
|
||||||
if (!has_selection())
|
if (!has_selection())
|
||||||
return false;
|
return false;
|
||||||
|
@ -306,7 +306,7 @@ bool Terminal::selection_contains(const VT::BufferPosition& position) const
|
||||||
return position >= normalized_selection_start() && position <= normalized_selection_end();
|
return position >= normalized_selection_start() && position <= normalized_selection_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
VT::BufferPosition Terminal::buffer_position_at(const Point& position) const
|
VT::Position Terminal::buffer_position_at(const Point& position) const
|
||||||
{
|
{
|
||||||
auto adjusted_position = position.translated(-(frame_thickness() + m_inset), -(frame_thickness() + m_inset));
|
auto adjusted_position = position.translated(-(frame_thickness() + m_inset), -(frame_thickness() + m_inset));
|
||||||
int row = adjusted_position.y() / m_line_height;
|
int row = adjusted_position.y() / m_line_height;
|
||||||
|
|
|
@ -31,11 +31,11 @@ public:
|
||||||
RefPtr<CConfigFile> config() const { return m_config; }
|
RefPtr<CConfigFile> config() const { return m_config; }
|
||||||
|
|
||||||
bool has_selection() const;
|
bool has_selection() const;
|
||||||
bool selection_contains(const VT::BufferPosition&) const;
|
bool selection_contains(const VT::Position&) const;
|
||||||
String selected_text() const;
|
String selected_text() const;
|
||||||
VT::BufferPosition buffer_position_at(const Point&) const;
|
VT::Position buffer_position_at(const Point&) const;
|
||||||
VT::BufferPosition normalized_selection_start() const;
|
VT::Position normalized_selection_start() const;
|
||||||
VT::BufferPosition normalized_selection_end() const;
|
VT::Position normalized_selection_end() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// ^GWidget
|
// ^GWidget
|
||||||
|
@ -61,8 +61,8 @@ private:
|
||||||
|
|
||||||
VT::Terminal m_terminal;
|
VT::Terminal m_terminal;
|
||||||
|
|
||||||
VT::BufferPosition m_selection_start;
|
VT::Position m_selection_start;
|
||||||
VT::BufferPosition m_selection_end;
|
VT::Position m_selection_end;
|
||||||
|
|
||||||
bool m_should_beep { false };
|
bool m_should_beep { false };
|
||||||
bool m_belling { false };
|
bool m_belling { false };
|
||||||
|
|
48
Libraries/LibVT/Position.h
Normal file
48
Libraries/LibVT/Position.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace VT {
|
||||||
|
|
||||||
|
class Position {
|
||||||
|
public:
|
||||||
|
Position() {}
|
||||||
|
Position(int row, int column)
|
||||||
|
: m_row(row)
|
||||||
|
, m_column(column)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_valid() const { return m_row >= 0 && m_column >= 0; }
|
||||||
|
int row() const { return m_row; }
|
||||||
|
int column() const { return m_column; }
|
||||||
|
|
||||||
|
bool operator<(const Position& other) const
|
||||||
|
{
|
||||||
|
return m_row < other.m_row || (m_row == other.m_row && m_column < other.m_column);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<=(const Position& other) const
|
||||||
|
{
|
||||||
|
return *this < other || *this == other;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>=(const Position& other) const
|
||||||
|
{
|
||||||
|
return !(*this < other);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Position& other) const
|
||||||
|
{
|
||||||
|
return m_row == other.m_row && m_column == other.m_column;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Position& other) const
|
||||||
|
{
|
||||||
|
return !(*this == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_row { -1 };
|
||||||
|
int m_column { -1 };
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
#include <AK/NonnullOwnPtrVector.h>
|
#include <AK/NonnullOwnPtrVector.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibVT/Position.h>
|
||||||
|
|
||||||
namespace VT {
|
namespace VT {
|
||||||
|
|
||||||
|
@ -56,49 +57,6 @@ struct Attribute {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class BufferPosition {
|
|
||||||
public:
|
|
||||||
BufferPosition() {}
|
|
||||||
BufferPosition(int row, int column)
|
|
||||||
: m_row(row)
|
|
||||||
, m_column(column)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_valid() const { return m_row >= 0 && m_column >= 0; }
|
|
||||||
int row() const { return m_row; }
|
|
||||||
int column() const { return m_column; }
|
|
||||||
|
|
||||||
bool operator<(const BufferPosition& other) const
|
|
||||||
{
|
|
||||||
return m_row < other.m_row || (m_row == other.m_row && m_column < other.m_column);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<=(const BufferPosition& other) const
|
|
||||||
{
|
|
||||||
return *this < other || *this == other;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator>=(const BufferPosition& other) const
|
|
||||||
{
|
|
||||||
return !(*this < other);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator==(const BufferPosition& other) const
|
|
||||||
{
|
|
||||||
return m_row == other.m_row && m_column == other.m_column;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator!=(const BufferPosition& other) const
|
|
||||||
{
|
|
||||||
return !(*this == other);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_row { -1 };
|
|
||||||
int m_column { -1 };
|
|
||||||
};
|
|
||||||
|
|
||||||
class Terminal {
|
class Terminal {
|
||||||
public:
|
public:
|
||||||
explicit Terminal(TerminalClient&);
|
explicit Terminal(TerminalClient&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue