FifeGUI 0.3.0
A C++ GUI library designed for games.
text.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#ifndef INCLUDE_FIFECHAN_TEXT_HPP_
6#define INCLUDE_FIFECHAN_TEXT_HPP_
7
8// Standard library includes
9#include <string>
10#include <vector>
11
12// Platform config include
13#include "fifechan/platform.hpp"
14
15// Project headers (subdirs before local)
16#include "fifechan/rectangle.hpp"
17
18namespace fcn
19{
20 class Font;
21
31 class FIFEGUI_API Text
32 {
33 public:
34 Text();
35
41 explicit Text(std::string const & content);
42
46 virtual ~Text();
47
51 Text(Text const &) = default;
52
56 Text& operator=(Text const &) = default;
57
61 Text(Text&&) = default;
62
66 Text& operator=(Text&&) = default;
67
74 virtual void setContent(std::string const & content);
75
81 virtual std::string getContent() const;
82
90 virtual void setRow(unsigned int row, std::string const & content);
91
98 virtual void addRow(std::string const & row);
99
107 virtual void insertRow(std::string const & row, unsigned int position);
108
115 virtual void eraseRow(unsigned int row);
116
124 virtual std::string& getRow(unsigned int row);
125
131 virtual void insert(int character);
132
146 virtual void remove(int numberOfCharacters);
147
153 virtual int getCaretPosition() const;
154
161 virtual void setCaretPosition(int position);
162
171 virtual void setCaretPosition(int x, int y, Font* font);
172
178 virtual int getCaretColumn() const;
179
185 virtual int getCaretRow() const;
186
193 virtual void setCaretColumn(int column);
194
206 virtual void setCaretRow(int row);
207
214 virtual int getCaretX(Font* font) const;
215
222 virtual int getCaretY(Font* font) const;
223
231 virtual Rectangle getDimension(Font* font) const;
232
241 virtual Rectangle getCaretDimension(Font* font) const;
242
251 virtual int getWidth(int row, Font* font) const;
252
258 virtual unsigned int getMaximumCaretRow() const;
259
266 virtual unsigned int getMaximumCaretRow(unsigned int row) const;
267
273 virtual unsigned int getNumberOfRows() const;
274
280 virtual unsigned int getNumberOfCharacters() const;
281
290 virtual unsigned int getNumberOfCharacters(unsigned int row) const;
291
292 protected:
297
301 std::vector<std::string> mRows;
302
307 unsigned int mCaretPosition{0};
308
313 unsigned int mCaretRow{0};
314
319 unsigned int mCaretColumn{0};
320 };
321} // namespace fcn
322
323#endif // INCLUDE_FIFECHAN_TEXT_HPP_
Abstract interface for font rendering.
Definition font.hpp:26
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:22
unsigned int mCaretColumn
Holds the column the caret is in.
Definition text.hpp:319
virtual void setCaretColumn(int column)
Sets the column the caret should be in.
Definition text.cpp:334
virtual unsigned int getNumberOfCharacters() const
Gets the number of characters in the text.
Definition text.cpp:428
virtual unsigned int getMaximumCaretRow() const
Gets the maximum row the caret can be in.
Definition text.cpp:418
virtual void setContent(std::string const &content)
Sets the content of the text.
Definition text.cpp:57
virtual unsigned int getNumberOfRows() const
Gets the number of rows in the text.
Definition text.cpp:435
virtual int getWidth(int row, Font *font) const
Gets the width in pixels of a row.
Definition text.cpp:413
virtual std::string & getRow(unsigned int row)
Gets a reference to a row.
Definition text.cpp:155
virtual void setCaretRow(int row)
Sets the row the caret should be in.
Definition text.cpp:347
virtual int getCaretPosition() const
Gets the caret position.
Definition text.cpp:250
virtual ~Text()
Virtual destructor.
virtual void addRow(std::string const &row)
Adds a row to the content.
Definition text.cpp:112
virtual void setRow(unsigned int row, std::string const &content)
Sets the content of a row.
Definition text.cpp:102
virtual void remove(int numberOfCharacters)
Removes a given number of characters at starting at the current caret position.
Definition text.cpp:191
unsigned int mCaretRow
Holds the row the caret is in.
Definition text.hpp:313
Text(Text const &)=default
Copy constructor.
virtual int getCaretColumn() const
Gets the column the caret is currently in.
Definition text.cpp:324
virtual void insertRow(std::string const &row, unsigned int position)
Inserts a row before the specified row position.
Definition text.cpp:124
virtual void setCaretPosition(int position)
Sets the caret position.
Definition text.cpp:255
virtual int getCaretX(Font *font) const
Gets the x coordinate of the caret in pixels given a font.
Definition text.cpp:360
unsigned int mCaretPosition
Holds the position of the caret.
Definition text.hpp:307
virtual int getCaretRow() const
Gets the row the caret is currently in.
Definition text.cpp:329
virtual void eraseRow(unsigned int row)
Erases the given row.
Definition text.cpp:146
virtual int getCaretY(Font *font) const
Gets the y coordinate of the caret in pixels given a font.
Definition text.cpp:371
std::vector< std::string > mRows
Holds the text row by row.
Definition text.hpp:301
Text & operator=(Text &&)=default
Move assignment operator.
virtual std::string getContent() const
Gets the content of the text.
Definition text.cpp:86
virtual void insert(int character)
Inserts a character at the current caret position.
Definition text.cpp:164
Text(Text &&)=default
Move constructor.
void calculateCaretPositionFromRowAndColumn()
Calculates the caret position from the caret row and caret column.
Definition text.cpp:449
Text & operator=(Text const &)=default
Copy assignment operator.
virtual Rectangle getDimension(Font *font) const
Gets the dimension in pixels of the text given a font.
Definition text.cpp:379
virtual Rectangle getCaretDimension(Font *font) const
Gets the caret dimension relative to this text.
Definition text.cpp:400
Used replacement tokens by configure_file():