Skip to content

Commit

Permalink
Apply Guichan's changes from 5de1c0cbb341e45819ee5efcd8907e398568f0c7…
Browse files Browse the repository at this point in the history
… (Sept 18th 2008)

http://code.google.com/p/guichan/issues/detail?id=72 and comments and code clean up.
  • Loading branch information
Jarod42 committed Sep 6, 2024
1 parent 34fd54b commit 7d31434
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 8 deletions.
2 changes: 1 addition & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* Continue rebasing from 5de1c0cbb341e45819ee5efcd8907e398568f0c7
* Continue rebasing from 3acee30c0bb2540b2104ee2f803d8cd2844af0b9
* Add a focus listener interface.
* Make focus apply synchronously.
* Graphics and input objects for DirectX.
Expand Down
1 change: 1 addition & 0 deletions include/guisan/basiccontainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ namespace gcn

virtual Widget *getWidgetAt(int x, int y);

virtual std::list<Widget*> getWidgetsIn(const Rectangle& area, Widget* ignore = NULL);

// Inherited from DeathListener

Expand Down
35 changes: 32 additions & 3 deletions include/guisan/text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,29 @@ namespace gcn
* A utility class to ease working with text in widgets such as
* TextBox and TextField. The class wraps common text operations
* such as inserting and deleting text.
*
* @since 1.1.0
*/
class GCN_CORE_DECLSPEC Text
{
public:
/**
* Constructor.
* @since 1.1.0
*/
Text();

/**
* Constructor.
*
* @param content The content of the text.
* @since 1.1.0
*/
Text(const std::string& content);

/**
* Destructor.
* @since 1.1.0
*/
virtual ~Text();

Expand All @@ -84,13 +89,15 @@ namespace gcn
* any previous text and reset the caret position.
*
* @param content The content of the text.
* @since 1.1.0
*/
virtual void setContent(const std::string& text);

/**
* Gets the content of the text.
*
* @return The content of the text.
* @since 1.1.0
*/
virtual std::string getContent() const;

Expand All @@ -99,6 +106,7 @@ namespace gcn
*
* @param row The row to set the text of.
* @throws Exception when the row does not exist.
* @since 1.1.0
*/
virtual void setRow(unsigned int row, const std::string& content);

Expand All @@ -107,6 +115,7 @@ namespace gcn
* not change the current caret position.
*
* @param row The row to add.
* @since 1.1.0
*/
virtual void addRow(const std::string& row);

Expand All @@ -116,13 +125,15 @@ namespace gcn
* @param row The row to get the content of.
* @return The content of a row.
* @throws Exception when no such row exists.
* @since 1.1.0
*/
virtual std::string getRow(unsigned int row) const;

/**
* Inserts a character at the current caret position.
*
* @parameter character The character to insert.
* @param character The character to insert.
* @since 1.1.0
*/
virtual void insert(int character);

Expand All @@ -137,14 +148,16 @@ namespace gcn
* removed the row with the line feed will be merged
* with the row above the line feed.
*
* @numberOfCharacters The number of characters to remove.
* @param numberOfCharacters The number of characters to remove.
* @since 1.1.0
*/
virtual void remove(int numberOfCharacters);

/**
* Gets the caret position.
*
* @return The caret position;
* @return The caret position.
* @since 1.1.0
*/
virtual int getCaretPosition() const;

Expand All @@ -153,6 +166,7 @@ namespace gcn
* clamp to the dimension of the content.
*
* @param position The position of the caret.
* @since 1.1.0
*/
virtual void setCaretPosition(int position);

Expand All @@ -163,20 +177,23 @@ namespace gcn
* @param x The x coordinate of the caret.
* @param y The y coordinate of the caret.
* @param font The font to use when calculating the position.
* @since 1.1.0
*/
virtual void setCaretPosition(int x, int y, Font* font);

/**
* Gets the column the caret is currently in.
*
* @return The column the caret is currently in.
* @since 1.1.0
*/
virtual int getCaretColumn() const;

/**
* Gets the row the caret is currently in.
*
* @return The row the caret is currently in.
* @since 1.1.0
*/
virtual int getCaretRow() const;

Expand All @@ -185,6 +202,7 @@ namespace gcn
* will be clamp to the current row.
*
* @param column The column the caret should be in.
* @since 1.1.0
*/
virtual void setCaretColumn(int column);

Expand All @@ -198,6 +216,7 @@ namespace gcn
* column.
*
* @param row The row the caret should be in.
* @since 1.1.0
*/
virtual void setCaretRow(int row);

Expand All @@ -206,6 +225,7 @@ namespace gcn
*
* @param font The font to use when calculating the x coordinate.
* @return The x coorinate of the caret in pixels.
* @since 1.1.0
*/
virtual int getCaretX(Font* font) const;

Expand All @@ -214,6 +234,7 @@ namespace gcn
*
* @param font The font to use when calculating the y coordinate.
* @return The y coorinate of the caret in pixels.
* @since 1.1.0
*/
virtual int getCaretY(Font* font) const;

Expand All @@ -223,6 +244,7 @@ namespace gcn
*
* @param font The font to use when calculating the dimension.
* @return The dimension in pixels of the text given a font.
* @since 1.1.0
*/
virtual Rectangle getDimension(Font* font) const;

Expand All @@ -233,6 +255,7 @@ namespace gcn
*
* @param font The font to use when calculating the dimension.
* @return The dimension of the caret.
* @since 1.1.0
*/
virtual Rectangle getCaretDimension(Font* font) const;

Expand All @@ -242,13 +265,15 @@ namespace gcn
*
* @param row The row to get the width of.
* @return The width in pixels of a row.
* @since 1.1.0
*/
virtual int getWidth(int row, Font* font) const;

/**
* Gets the maximum row the caret can be in.
*
* @return The maximum row the caret can be in.
* @since 1.1.0
*/
virtual unsigned int getMaximumCaretRow() const;

Expand All @@ -257,20 +282,23 @@ namespace gcn
*
* @param row The row of the caret.
* @return The maximum column of a row the caret can be in.
* @since 1.1.0
*/
virtual unsigned int getMaximumCaretRow(unsigned int row) const;

/**
* Gets the number of rows in the text.
*
* @return The number of rows in the text.
* @since 1.1.0
*/
virtual unsigned int getNumberOfRows() const;

/**
* Gets the number of characters in the text.
*
* @return The number of characters in the text.
* @since 1.1.0
*/
virtual unsigned int getNumberOfCharacters() const;

Expand All @@ -281,6 +309,7 @@ namespace gcn
* @param row The row to get the number of characters in.
* @return The number of characters in a certain row, or zero
* if the row does not exist.
* @since 1.1.0
*/
virtual unsigned int getNumberOfCharacters(unsigned int row) const;

Expand Down
15 changes: 14 additions & 1 deletion include/guisan/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ namespace gcn
virtual bool isModalMouseInputFocused() const;

/**
* Gets a widget from a certain position in the widget.
* Gets a widget at a certain position in the widget.
* This function is used to decide which gets mouse input,
* thus it can be overloaded to change that behaviour.
*
Expand All @@ -836,6 +836,19 @@ namespace gcn
*/
virtual Widget *getWidgetAt(int x, int y);

/**
* Gets all widgets inside a certain area of the widget.
*
* NOTE: This always returns an empty list if the widget is not
* a container.
*
* @param area The area to check.
* @param ignore If supplied, this widget will be ignored.
* @return A list of widgets. An empty list if no widgets was found.
* @since 1.1.0
*/
virtual std::list<Widget*> getWidgetsIn(const Rectangle& area, Widget* ignore = NULL);

/**
* Gets the mouse listeners of the widget.
*
Expand Down
14 changes: 14 additions & 0 deletions src/basiccontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,4 +453,18 @@ namespace gcn

setSize(w, h);
}

std::list<Widget*> BasicContainer::getWidgetsIn(const Rectangle& area, Widget* ignore)
{
std::list<Widget*> result;

for (std::list<Widget*>::const_iterator iter = mWidgets.begin(); iter != mWidgets.end(); iter++)
{
Widget* widget = (*iter);
if (ignore != widget && widget->getDimension().isIntersecting(area))
result.push_back(widget);
}

return result;
}
}
6 changes: 3 additions & 3 deletions src/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace gcn
unsigned int total = 0;
for (unsigned int i = 0; i < mRows.size(); i++)
{
if (position <= total + (int) mRows[i].size())
if (position <= (int) (total + mRows[i].size()))
{
mCaretRow = i;
mCaretColumn = position - total;
Expand Down Expand Up @@ -281,7 +281,7 @@ namespace gcn
{
if (mRows.empty() || column < 0)
mCaretColumn = 0;
else if (column > mRows[mCaretRow].size())
else if (column > (int) mRows[mCaretRow].size())
mCaretColumn = mRows[mCaretRow].size();
else
mCaretColumn = column;
Expand All @@ -293,7 +293,7 @@ namespace gcn
{
if (mRows.empty() || row < 0)
mCaretRow = 0;
else if (row >= mRows.size())
else if (row >= (int) mRows.size())
mCaretRow = mRows.size() - 1;
else
mCaretRow = row;
Expand Down
5 changes: 5 additions & 0 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,9 @@ namespace gcn

return widget;
}

std::list<Widget*> Widget::getWidgetsIn(const Rectangle& area, Widget* ignore)
{
return std::list<Widget*>();
}
}

0 comments on commit 7d31434

Please sign in to comment.