Changeset View
Standalone View
source/gui/ObjectTypes/CInput.h
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
* GNU General Public License for more details. | * GNU General Public License for more details. | ||||
* | * | ||||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. | ||||
*/ | */ | ||||
#ifndef INCLUDED_CINPUT | #ifndef INCLUDED_CINPUT | ||||
#define INCLUDED_CINPUT | #define INCLUDED_CINPUT | ||||
#include "gui/CGUISprite.h" | #include "gui/CGUISprite.h" | ||||
#include "gui/ObjectBases/IGUIScrollBarOwner.h" | #include "gui/ObjectBases/IGUIScrollBarOwner.h" | ||||
#include "gui/SettingTypes/CGUIString.h" | |||||
#include "lib/external_libraries/libsdl.h" | #include "lib/external_libraries/libsdl.h" | ||||
#include <vector> | #include <vector> | ||||
/** | /** | ||||
* Text field where you can input and edit the text. | * Text field where you can input and edit the text. | ||||
* | * | ||||
* It doesn't use IGUITextOwner, because we don't need | * It doesn't use IGUITextOwner, because we don't need | ||||
* any other features than word-wrapping, and we need to be | * any other features than word-wrapping, and we need to be | ||||
* able to rapidly change the string. | * able to rapidly change the string. | ||||
*/ | */ | ||||
class CInput : public IGUIObject, public IGUIScrollBarOwner | class CInput : public IGUIObject, public IGUIScrollBarOwner | ||||
elexis: Before someone suggests removing the comment, one could also check whether it would be more… | |||||
Done Inline ActionsIGUITextOwner is used to prebuild string, but caption of input will change too frequently to benefit from that. Silier: IGUITextOwner is used to prebuild string, but caption of input will change too frequently to… | |||||
Done Inline ActionsI will remove inheritance since I am overriding most of the functions anyway Silier: I will remove inheritance since I am overriding most of the functions anyway | |||||
{ | { | ||||
GUI_OBJECT(CInput) | GUI_OBJECT(CInput) | ||||
protected: // forwards | protected: // forwards | ||||
struct SRow; | struct SRow; | ||||
public: | public: | ||||
CInput(CGUI& pGUI); | CInput(CGUI& pGUI); | ||||
virtual ~CInput(); | virtual ~CInput(); | ||||
/** | /** | ||||
* @see IGUIObject#ResetStates() | * @see IGUIObject#ResetStates() | ||||
*/ | */ | ||||
virtual void ResetStates(); | virtual void ResetStates(); | ||||
// Check where the mouse is hovering, and get the appropriate text position. | // Check where the mouse is hovering, and get the appropriate text position. | ||||
// return is the text-position index. | // return is the text-position index. | ||||
int GetMouseHoveringTextPosition() const; | int GetMouseHoveringTextPosition() const; | ||||
// Same as above, but only on one row in X, and a given value, not the mouse's. | // Same as above, but only on one row in X, and a given value, not the mouse's. | ||||
// wanted is filled with x if the row didn't extend as far as the mouse pos. | // wanted is filled with x if the row didn't extend as far as the mouse pos. | ||||
int GetXTextPosition(const std::list<SRow>::const_iterator& c, const float& x, float& wanted) const; | int GetXTextPosition(const std::list<SRow>::const_iterator& c, const float& x, float& wanted) const; | ||||
protected: | protected: | ||||
void SetupGeneratedPlaceholderText(); | |||||
/** | /** | ||||
* @see IGUIObject#HandleMessage() | * @see IGUIObject#HandleMessage() | ||||
*/ | */ | ||||
virtual void HandleMessage(SGUIMessage& Message); | virtual void HandleMessage(SGUIMessage& Message); | ||||
Not Done Inline ActionsWhy do you need these AddText methods? Especially in case there is the only one usage in the constructor. vladislavbelov: Why do you need these `AddText` methods? Especially in case there is the only one usage in the… | |||||
/** | /** | ||||
* Handle events manually to catch keyboard inputting. | * Handle events manually to catch keyboard inputting. | ||||
*/ | */ | ||||
virtual InReaction ManuallyHandleKeys(const SDL_Event_* ev); | virtual InReaction ManuallyHandleKeys(const SDL_Event_* ev); | ||||
/** | /** | ||||
* Handle events manually to catch keys which change the text. | * Handle events manually to catch keys which change the text. | ||||
Show All 28 Lines | protected: | ||||
* process everything all over again! Also notice you can | * process everything all over again! Also notice you can | ||||
* specify a 'to' also, it will only be used though if a '\n' | * specify a 'to' also, it will only be used though if a '\n' | ||||
* appears, because then the word-wrapping won't change after | * appears, because then the word-wrapping won't change after | ||||
* that. | * that. | ||||
*/ | */ | ||||
void UpdateText(int from = 0, int to_before = -1, int to_after = -1); | void UpdateText(int from = 0, int to_before = -1, int to_after = -1); | ||||
/** | /** | ||||
* Draws the text generated for placeholder. | |||||
* | |||||
* @param z Z value | |||||
* @param clipping Clipping rectangle, don't even add a parameter | |||||
* to get no clipping. | |||||
*/ | |||||
virtual void DrawPlaceholderText(float z, const CRect& clipping = CRect()); | |||||
/** | |||||
* Delete the current selection. Also places the pointer at the | * Delete the current selection. Also places the pointer at the | ||||
* crack between the two segments kept. | * crack between the two segments kept. | ||||
*/ | */ | ||||
void DeleteCurSelection(); | void DeleteCurSelection(); | ||||
/** | /** | ||||
* Is text selected? It can be denote two ways, m_iBufferPos_Tail | * Is text selected? It can be denote two ways, m_iBufferPos_Tail | ||||
* being -1 or the same as m_iBufferPos. This makes for clearer | * being -1 or the same as m_iBufferPos. This makes for clearer | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | protected: | ||||
float m_WantedX; | float m_WantedX; | ||||
/** | /** | ||||
* If we are in the process of selecting a larger selection of text | * If we are in the process of selecting a larger selection of text | ||||
* using the mouse click (hold) and drag, this is true. | * using the mouse click (hold) and drag, this is true. | ||||
*/ | */ | ||||
bool m_SelectingText; | bool m_SelectingText; | ||||
/** | |||||
* Whether the cached text is currently valid (if not then SetupText will be called by Draw) | |||||
*/ | |||||
bool m_GeneratedPlaceholderTextValid; | |||||
CGUIText m_GeneratedPlaceholderText; | |||||
// *** Things for one-line input control *** // | // *** Things for one-line input control *** // | ||||
float m_HorizontalScroll; | float m_HorizontalScroll; | ||||
/// Used to store the previous time for flashing the cursor. | /// Used to store the previous time for flashing the cursor. | ||||
double m_PrevTime; | double m_PrevTime; | ||||
/// Cursor blink rate in seconds, if greater than 0.0. | /// Cursor blink rate in seconds, if greater than 0.0. | ||||
double m_CursorBlinkRate; | double m_CursorBlinkRate; | ||||
/// If the cursor should be drawn or not. | /// If the cursor should be drawn or not. | ||||
bool m_CursorVisState; | bool m_CursorVisState; | ||||
static const CStr EventNameTextEdit; | static const CStr EventNameTextEdit; | ||||
static const CStr EventNamePress; | static const CStr EventNamePress; | ||||
static const CStr EventNameTab; | static const CStr EventNameTab; | ||||
// Settings | // Settings | ||||
i32 m_BufferPosition; | i32 m_BufferPosition; | ||||
float m_BufferZone; | float m_BufferZone; | ||||
CStrW m_Caption; | CStrW m_Caption; | ||||
CGUIString m_PlaceholderText; | |||||
Not Done Inline ActionsPerhaps CGUIText could be used to support tags (such as font) and avoid m_PlaceholderColor (or perhaps CGUIString is more consistent with COList columns or something, dunno, but there are those two possibilities. Actually COList seems to use CStrW, so there are three. CStrW would be consistent with m_Caption.) elexis: Perhaps `CGUIText` could be used to support tags (such as font) and avoid `m_PlaceholderColor`… | |||||
Done Inline ActionsCGUIString is required for CGUIText constructor so thats why not CStrW. Not sure if CGUIText can be created from js like CGUIString is but I will check. Silier: CGUIString is required for CGUIText constructor so thats why not CStrW. Not sure if CGUIText… | |||||
Done Inline ActionsFor the record: Silier: For the record:
Engine.GetGUIObjectByName("modGenericFilter").placeholder_text = setStringTags… | |||||
i32 m_CellID; | i32 m_CellID; | ||||
CStrW m_Font; | CStrW m_Font; | ||||
CStrW m_MaskChar; | CStrW m_MaskChar; | ||||
bool m_Mask; | bool m_Mask; | ||||
i32 m_MaxLength; | i32 m_MaxLength; | ||||
bool m_MultiLine; | bool m_MultiLine; | ||||
bool m_Readonly; | bool m_Readonly; | ||||
bool m_ScrollBar; | bool m_ScrollBar; | ||||
CStr m_ScrollBarStyle; | CStr m_ScrollBarStyle; | ||||
CGUISpriteInstance m_Sprite; | CGUISpriteInstance m_Sprite; | ||||
CGUISpriteInstance m_SpriteSelectArea; | CGUISpriteInstance m_SpriteSelectArea; | ||||
CGUIColor m_TextColor; | CGUIColor m_TextColor; | ||||
CGUIColor m_TextColorSelected; | CGUIColor m_TextColorSelected; | ||||
CGUIColor m_PlaceholderColor; | |||||
}; | }; | ||||
#endif // INCLUDED_CINPUT | #endif // INCLUDED_CINPUT |
Before someone suggests removing the comment, one could also check whether it would be more logically consistent to not introduce the inheritance, or to inherit but use it for both text renderings, since there would be 3 lines using the new IGUITextOwner inheritance vs. 2000 lines managing and rendering text without IGUITextOwner.
The class should use the IGUITextOwner if CInput shall be able to print selectable colorized, perhaps link-clickable text, for example for ToS, chat, mapdescription, but would require rewriting the entire class (and D1781).