Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CInput Class Reference

Text field where you can input and edit the text. More...

#include <CInput.h>

Inheritance diagram for CInput:
Collaboration diagram for CInput:

Classes

struct  SRow
 

Public Member Functions

 CInput (CGUI &pGUI)
 
virtual ~CInput ()
 
virtual void ResetStates ()
 
int GetMouseHoveringTextPosition () const
 
int GetXTextPosition (const std::list< SRow >::const_iterator &c, const float &x, float &wanted) const
 
- Public Member Functions inherited from IGUIObject
 NONCOPYABLE (IGUIObject)
 
 IGUIObject (CGUI &pGUI)
 
virtual ~IGUIObject ()
 
virtual bool IsMouseOver () const
 This function checks if the mouse is hovering the rectangle that the base setting "size" makes. More...
 
virtual bool IsMouseHovering () const
 This function returns true if the mouse is hovering over this GUI object and if this GUI object is the topmost object in that screen location. More...
 
const CStr & GetName () const
 Get object name, name is unique. More...
 
void SetName (const CStr &Name)
 Get object name. More...
 
CStr GetPresentableName () const
 
const std::vector< IGUIObject * > & GetChildren () const
 Return all child objects of the current object. More...
 
void RegisterSetting (const CStr &Name, IGUISetting *setting)
 Registers the given setting with the GUI object. More...
 
void ReregisterSetting (const CStr &Name, IGUISetting *setting)
 
bool SettingExists (const CStr &Setting) const
 Returns whether there is a setting with the given name registered. More...
 
bool SetSettingFromString (const CStr &Setting, const CStrW &Value, const bool SendMessage)
 Set a setting by string, regardless of what type it is. More...
 
bool IsEnabled () const
 Returns whether this object is set to be hidden or ghost. More...
 
bool IsHidden () const
 Returns whether this is object is set to be hidden. More...
 
void SetHidden (bool hidden)
 
bool IsHiddenOrGhost () const
 Returns whether this object is set to be hidden or ghost. More...
 
void PlaySound (const CStrW &soundPath) const
 Retrieves the configured sound filename from the given setting name and plays that once. More...
 
InReaction SendEvent (EGUIMessageType type, const CStr &eventName)
 Send event to this GUI object (HandleMessage and ScriptEvent) More...
 
InReaction SendMouseEvent (EGUIMessageType type, const CStr &eventName)
 Same as SendEvent, but passes mouse coordinates and button state as an argument. More...
 
CRect GetComputedSize ()
 Updates and returns the size of the object. More...
 
virtual const CStrW & GetTooltipText () const
 
virtual const CStr & GetTooltipStyle () const
 
void RegisterScriptHandler (const CStr &eventName, const CStr &Code, CGUI &pGUI)
 Set the script handler for a particular object-specific action. More...
 
JSObject * GetJSObject ()
 Retrieves the JSObject representing this GUI object. More...
 
virtual void Tick ()
 Called on every GUI tick unless the object or one of its parent is hidden/ghost. More...
 
template<typename... Args>
void RecurseObject (bool(IGUIObject::*isRestricted)() const, void(IGUIObject::*callbackFunction)(Args... args), Args &&... args)
 Calls an IGUIObject member function recursively on this object and its children. More...
 
CGUIGetGUI ()
 
const CGUIGetGUI () const
 
void SetFocus ()
 Take focus! More...
 
void ReleaseFocus ()
 Release focus. More...
 
- Public Member Functions inherited from IGUIScrollBarOwner
 IGUIScrollBarOwner (IGUIObject &m_pObject)
 
virtual ~IGUIScrollBarOwner ()
 
virtual void Draw (CCanvas2D &canvas)
 
virtual void HandleMessage (SGUIMessage &Message)
 
virtual void ResetStates ()
 
virtual const SGUIScrollBarStyleGetScrollBarStyle (const CStr8 &style) const
 Interface for the m_ScrollBar to use. More...
 
virtual void AddScrollBar (std::unique_ptr< IGUIScrollBar > scrollbar)
 Add a scroll-bar. More...
 
virtual IGUIScrollBarGetScrollBar (const int &index)
 Get Scroll Bar reference (it should be transparent it's actually pointers). More...
 
virtual float GetScrollBarPos (const int index) const
 Get the position of the scroll bar at. More...
 

Protected Member Functions

void SetupGeneratedPlaceholderText ()
 
virtual void HandleMessage (SGUIMessage &Message)
 
virtual InReaction ManuallyHandleKeys (const SDL_Event_ *ev)
 Handle events manually to catch keyboard inputting. More...
 
virtual void ManuallyMutableHandleKeyDownEvent (const SDL_Keycode keyCode)
 Handle events manually to catch keys which change the text. More...
 
virtual void ManuallyImmutableHandleKeyDownEvent (const SDL_Keycode keyCode)
 Handle events manually to catch keys which don't change the text. More...
 
virtual InReaction ManuallyHandleHotkeyEvent (const SDL_Event_ *ev)
 Handle hotkey events (called by ManuallyHandleKeys) More...
 
virtual void UpdateCachedSize ()
 
virtual void Draw (CCanvas2D &canvas)
 Draws the Text. More...
 
void DrawContent (CCanvas2D &canvas)
 
void UpdateText (int from=0, int to_before=-1, int to_after=-1)
 Calculate m_CharacterPosition the main task for this function is to perfom word-wrapping You input from which character it has been changed, because if we add a character to the very last end, we don't want process everything all over again! Also notice you can specify a 'to' also, it will only be used though if a '
' appears, because then the word-wrapping won't change after that. More...
 
virtual void DrawPlaceholderText (CCanvas2D &canvas, const CRect &clipping=CRect())
 Draws the text generated for placeholder. More...
 
void DeleteCurSelection ()
 Delete the current selection. More...
 
bool SelectingText () const
 Is text selected? It can be denote two ways, m_iBufferPos_Tail being -1 or the same as m_iBufferPos. More...
 
float GetTextAreaWidth ()
 Get area of where text can be drawn. More...
 
void UpdateAutoScroll ()
 Called every time the auto-scrolling should be checked. More...
 
void ClearComposedText ()
 Clear composed IME input when supported (SDL2 only). More...
 
void UpdateBufferPositionSetting ()
 Updates the buffer (cursor) position exposed to JS. More...
 
- Protected Member Functions inherited from IGUIObject
virtual InReaction PreemptEvent (const SDL_Event_ *ev)
 Some objects need to be able to pre-emptively process SDL_Event_. More...
 
bool ApplyStyle (const CStr &StyleName)
 Applies the given style to the object. More...
 
virtual float GetBufferedZ () const
 Returns not the Z value, but the actual buffered Z value, i.e. More...
 
void RegisterChild (IGUIObject *child)
 Add an object to the hierarchy. More...
 
void UnregisterChild (IGUIObject *child)
 Remove an object from the hierarchy. More...
 
void SetParent (IGUIObject *pParent)
 Set parent of this object. More...
 
bool IsFocused () const
 Check if object is focused. More...
 
IGUIObjectGetParent () const
 NOTE! This will not just return m_pParent, when that is need use it! There is one exception to it, when the parent is the top-node (the object that isn't a real object), this will return nullptr, so that the top-node's children are seemingly parentless. More...
 
virtual bool HandleAdditionalChildren (const XMBData &file, const XMBElement &child)
 Handle additional children to the <object>-tag. More...
 
virtual void AdditionalChildrenHandled ()
 Allow the GUI object to process after all child items were handled. More...
 
void ScriptEvent (const CStr &eventName)
 Execute the script for a particular action. More...
 
bool ScriptEventWithReturn (const CStr &eventName)
 Execute the script for a particular action. More...
 
void ScriptEvent (const CStr &eventName, const JS::HandleValueArray &paramData)
 Execute the script for a particular action. More...
 
bool ScriptEventWithReturn (const CStr &eventName, const JS::HandleValueArray &paramData)
 Execute the script for a particular action. More...
 
void SetScriptHandler (const CStr &eventName, JS::HandleObject Function)
 Assigns a JS function to the event name. More...
 
void UnsetScriptHandler (const CStr &eventName)
 Deletes an event handler assigned to the given name, if such a handler exists. More...
 
void UpdateMouseOver (IGUIObject *const &pMouseOver)
 Inputes the object that is currently hovered, this function updates this object accordingly (i.e. More...
 

Protected Attributes

int m_iBufferPos
 Cursor position. More...
 
int m_iBufferPos_Tail
 Cursor position we started to select from. More...
 
bool m_ComposingText
 If we're composing text with an IME. More...
 
int m_iComposedLength
 The length and position of the current IME composition. More...
 
int m_iComposedPos
 
int m_iInsertPos
 The position to insert committed text. More...
 
std::list< SRowm_CharacterPositions
 List of rows to ease changing its size, so iterators stay valid. More...
 
float m_WantedX
 When you change row with up/down, and the row you jump to does not have anything at that X position, then it will keep the m_WantedX position in mind when switching to the next row. More...
 
bool m_SelectingText
 If we are in the process of selecting a larger selection of text using the mouse click (hold) and drag, this is true. More...
 
bool m_GeneratedPlaceholderTextValid
 Whether the cached text is currently valid (if not then SetupText will be called by Draw) More...
 
CGUIText m_GeneratedPlaceholderText
 
float m_HorizontalScroll
 
double m_PrevTime
 Used to store the previous time for flashing the cursor. More...
 
double m_CursorBlinkRate
 Cursor blink rate in seconds, if greater than 0.0. More...
 
bool m_CursorVisState
 If the cursor should be drawn or not. More...
 
CGUISimpleSetting< i32m_BufferPosition
 
CGUISimpleSetting< float > m_BufferZone
 
CGUISimpleSetting< CStrW > m_Caption
 
CGUISimpleSetting< CGUIStringm_PlaceholderText
 
CGUISimpleSetting< CStrW > m_Font
 
CGUISimpleSetting< CStrW > m_MaskChar
 
CGUISimpleSetting< bool > m_Mask
 
CGUISimpleSetting< i32m_MaxLength
 
CGUISimpleSetting< bool > m_MultiLine
 
CGUISimpleSetting< bool > m_Readonly
 
CGUISimpleSetting< bool > m_ScrollBar
 
CGUISimpleSetting< CStr > m_ScrollBarStyle
 
CGUISimpleSetting< CGUISpriteInstancem_Sprite
 
CGUISimpleSetting< CGUISpriteInstancem_SpriteOverlay
 
CGUISimpleSetting< CGUISpriteInstancem_SpriteSelectArea
 
CGUISimpleSetting< CGUIColorm_TextColor
 
CGUISimpleSetting< CGUIColorm_TextColorSelected
 
CGUISimpleSetting< CGUIColorm_PlaceholderColor
 
- Protected Attributes inherited from IGUIObject
CRect m_CachedActualSize
 Cached size, real size m_Size is actually dependent on resolution and can have different real outcomes, this is the real outcome cached to avoid slow calculations in real time. More...
 
CStr m_Name
 
std::vector< IGUIObject * > m_Children
 
IGUIObjectm_pParent
 
double m_LastClickTime [6]
 
bool m_MouseHovering
 This variable is true if the mouse is hovering this object and this object is the topmost object shown in this location. More...
 
std::map< CStr, IGUISetting * > m_Settings
 Settings pool, all an object's settings are located here. More...
 
CGUIm_pGUI
 
std::map< CStr, JS::Heap< JSObject * > > m_ScriptHandlers
 
std::unique_ptr< IGUIProxyObjectm_JSObject
 
CGUISimpleSetting< bool > m_Enabled
 
CGUISimpleSetting< bool > m_Hidden
 
CGUISimpleSetting< CGUISizem_Size
 
CGUISimpleSetting< CStr > m_Style
 
CGUIHotkey m_Hotkey
 
CGUISimpleSetting< float > m_Z
 
CGUISimpleSetting< bool > m_Absolute
 
CGUISimpleSetting< bool > m_Ghost
 
CGUISimpleSetting< float > m_AspectRatio
 
CGUISimpleSetting< CStrW > m_Tooltip
 
CGUISimpleSetting< CStr > m_TooltipStyle
 
- Protected Attributes inherited from IGUIScrollBarOwner
std::vector< std::unique_ptr< IGUIScrollBar > > m_ScrollBars
 Predominately you will only have one, but you can have as many as you like. More...
 

Static Protected Attributes

static const CStr EventNameTextEdit = "TextEdit"
 
static const CStr EventNamePress = "Press"
 
static const CStr EventNameTab = "Tab"
 
- Static Protected Attributes inherited from IGUIObject
static const CStr EventNameMouseEnter = "MouseEnter"
 
static const CStr EventNameMouseMove = "MouseMove"
 
static const CStr EventNameMouseLeave = "MouseLeave"
 

Detailed Description

Text field where you can input and edit the text.

It doesn't use IGUITextOwner, because we don't need any other features than word-wrapping, and we need to be able to rapidly change the string.

Constructor & Destructor Documentation

◆ CInput()

CInput::CInput ( CGUI pGUI)

◆ ~CInput()

CInput::~CInput ( )
virtual

Member Function Documentation

◆ ClearComposedText()

void CInput::ClearComposedText ( )
protected

Clear composed IME input when supported (SDL2 only).

◆ DeleteCurSelection()

void CInput::DeleteCurSelection ( )
protected

Delete the current selection.

Also places the pointer at the crack between the two segments kept.

◆ Draw()

void CInput::Draw ( CCanvas2D canvas)
protectedvirtual

Draws the Text.

Implements IGUIObject.

◆ DrawContent()

void CInput::DrawContent ( CCanvas2D canvas)
protected

◆ DrawPlaceholderText()

void CInput::DrawPlaceholderText ( CCanvas2D canvas,
const CRect clipping = CRect() 
)
protectedvirtual

Draws the text generated for placeholder.

Parameters
canvasCanvas to draw on.
clippingClipping rectangle, don't even add a parameter to get no clipping.

◆ GetMouseHoveringTextPosition()

int CInput::GetMouseHoveringTextPosition ( ) const

◆ GetTextAreaWidth()

float CInput::GetTextAreaWidth ( )
protected

Get area of where text can be drawn.

◆ GetXTextPosition()

int CInput::GetXTextPosition ( const std::list< SRow >::const_iterator &  c,
const float &  x,
float &  wanted 
) const

◆ HandleMessage()

void CInput::HandleMessage ( SGUIMessage Message)
protectedvirtual
See also
IGUIObject::HandleMessage()

Reimplemented from IGUIObject.

◆ ManuallyHandleHotkeyEvent()

InReaction CInput::ManuallyHandleHotkeyEvent ( const SDL_Event_ ev)
protectedvirtual

Handle hotkey events (called by ManuallyHandleKeys)

◆ ManuallyHandleKeys()

InReaction CInput::ManuallyHandleKeys ( const SDL_Event_ ev)
protectedvirtual

Handle events manually to catch keyboard inputting.

Reimplemented from IGUIObject.

◆ ManuallyImmutableHandleKeyDownEvent()

void CInput::ManuallyImmutableHandleKeyDownEvent ( const SDL_Keycode  keyCode)
protectedvirtual

Handle events manually to catch keys which don't change the text.

Conventions for Left/Right when text is selected:

References:

Visual Studio Visual Studio has the 'newer' approach, used by newer versions of things, and in newer applications. A left press will always place the pointer on the left edge of the selection, and then of course remove the selection. Right will do the exact same thing. If you have the pointer on the right edge and press right, it will in other words just remove the selection.

Windows (eg. Notepad) A left press always takes the pointer a step to the left and removes the selection as if it were never there in the first place. Right of course does the same thing but to the right.

I chose the Visual Studio convention. Used also in Word, gtk 2.0, MSN Messenger.

Conventions for Up/Down when text is selected:

References:

Visual Studio Visual Studio has a very strange approach, down takes you below the selection to the next row, and up to the one prior to the whole selection. The weird part is that it is always aligned as the 'pointer'. I decided this is to much work for something that is a bit arbitrary

Windows (eg. Notepad) Just like with left/right, the selection is destroyed and it moves just as if there never were a selection.

I chose the Notepad convention even though I use the VS convention with left/right.

◆ ManuallyMutableHandleKeyDownEvent()

void CInput::ManuallyMutableHandleKeyDownEvent ( const SDL_Keycode  keyCode)
protectedvirtual

Handle events manually to catch keys which change the text.

◆ ResetStates()

void CInput::ResetStates ( )
virtual
See also
IGUIObject::ResetStates()

Reimplemented from IGUIObject.

◆ SelectingText()

bool CInput::SelectingText ( ) const
protected

Is text selected? It can be denote two ways, m_iBufferPos_Tail being -1 or the same as m_iBufferPos.

This makes for clearer code.

◆ SetupGeneratedPlaceholderText()

void CInput::SetupGeneratedPlaceholderText ( )
protected

◆ UpdateAutoScroll()

void CInput::UpdateAutoScroll ( )
protected

Called every time the auto-scrolling should be checked.

◆ UpdateBufferPositionSetting()

void CInput::UpdateBufferPositionSetting ( )
protected

Updates the buffer (cursor) position exposed to JS.

◆ UpdateCachedSize()

void CInput::UpdateCachedSize ( )
protectedvirtual
See also
IGUIObject::UpdateCachedSize()

Reimplemented from IGUIObject.

◆ UpdateText()

void CInput::UpdateText ( int  from = 0,
int  to_before = -1,
int  to_after = -1 
)
protected

Calculate m_CharacterPosition the main task for this function is to perfom word-wrapping You input from which character it has been changed, because if we add a character to the very last end, we don't want process everything all over again! Also notice you can specify a 'to' also, it will only be used though if a '
' appears, because then the word-wrapping won't change after that.

Member Data Documentation

◆ EventNamePress

const CStr CInput::EventNamePress = "Press"
staticprotected

◆ EventNameTab

const CStr CInput::EventNameTab = "Tab"
staticprotected

◆ EventNameTextEdit

const CStr CInput::EventNameTextEdit = "TextEdit"
staticprotected

◆ m_BufferPosition

CGUISimpleSetting<i32> CInput::m_BufferPosition
protected

◆ m_BufferZone

CGUISimpleSetting<float> CInput::m_BufferZone
protected

◆ m_Caption

CGUISimpleSetting<CStrW> CInput::m_Caption
protected

◆ m_CharacterPositions

std::list<SRow> CInput::m_CharacterPositions
protected

List of rows to ease changing its size, so iterators stay valid.

For one-liners only one row is used.

◆ m_ComposingText

bool CInput::m_ComposingText
protected

If we're composing text with an IME.

◆ m_CursorBlinkRate

double CInput::m_CursorBlinkRate
protected

Cursor blink rate in seconds, if greater than 0.0.

◆ m_CursorVisState

bool CInput::m_CursorVisState
protected

If the cursor should be drawn or not.

◆ m_Font

CGUISimpleSetting<CStrW> CInput::m_Font
protected

◆ m_GeneratedPlaceholderText

CGUIText CInput::m_GeneratedPlaceholderText
protected

◆ m_GeneratedPlaceholderTextValid

bool CInput::m_GeneratedPlaceholderTextValid
protected

Whether the cached text is currently valid (if not then SetupText will be called by Draw)

◆ m_HorizontalScroll

float CInput::m_HorizontalScroll
protected

◆ m_iBufferPos

int CInput::m_iBufferPos
protected

Cursor position.

◆ m_iBufferPos_Tail

int CInput::m_iBufferPos_Tail
protected

Cursor position we started to select from.

(-1 if not selecting) (NB: Can be larger than m_iBufferPos if selecting from back to front.)

◆ m_iComposedLength

int CInput::m_iComposedLength
protected

The length and position of the current IME composition.

◆ m_iComposedPos

int CInput::m_iComposedPos
protected

◆ m_iInsertPos

int CInput::m_iInsertPos
protected

The position to insert committed text.

◆ m_Mask

CGUISimpleSetting<bool> CInput::m_Mask
protected

◆ m_MaskChar

CGUISimpleSetting<CStrW> CInput::m_MaskChar
protected

◆ m_MaxLength

CGUISimpleSetting<i32> CInput::m_MaxLength
protected

◆ m_MultiLine

CGUISimpleSetting<bool> CInput::m_MultiLine
protected

◆ m_PlaceholderColor

CGUISimpleSetting<CGUIColor> CInput::m_PlaceholderColor
protected

◆ m_PlaceholderText

CGUISimpleSetting<CGUIString> CInput::m_PlaceholderText
protected

◆ m_PrevTime

double CInput::m_PrevTime
protected

Used to store the previous time for flashing the cursor.

◆ m_Readonly

CGUISimpleSetting<bool> CInput::m_Readonly
protected

◆ m_ScrollBar

CGUISimpleSetting<bool> CInput::m_ScrollBar
protected

◆ m_ScrollBarStyle

CGUISimpleSetting<CStr> CInput::m_ScrollBarStyle
protected

◆ m_SelectingText

bool CInput::m_SelectingText
protected

If we are in the process of selecting a larger selection of text using the mouse click (hold) and drag, this is true.

◆ m_Sprite

CGUISimpleSetting<CGUISpriteInstance> CInput::m_Sprite
protected

◆ m_SpriteOverlay

CGUISimpleSetting<CGUISpriteInstance> CInput::m_SpriteOverlay
protected

◆ m_SpriteSelectArea

CGUISimpleSetting<CGUISpriteInstance> CInput::m_SpriteSelectArea
protected

◆ m_TextColor

CGUISimpleSetting<CGUIColor> CInput::m_TextColor
protected

◆ m_TextColorSelected

CGUISimpleSetting<CGUIColor> CInput::m_TextColorSelected
protected

◆ m_WantedX

float CInput::m_WantedX
protected

When you change row with up/down, and the row you jump to does not have anything at that X position, then it will keep the m_WantedX position in mind when switching to the next row.

It will keep on being used until it reach a row which meets the requirements. 0.0f means not in use.


The documentation for this class was generated from the following files: