Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CInput.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | CInput::CInput() | ||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea"); | AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea"); | ||||
AddSetting(GUIST_CColor, "textcolor"); | AddSetting(GUIST_CColor, "textcolor"); | ||||
AddSetting(GUIST_CColor, "textcolor_selected"); | AddSetting(GUIST_CColor, "textcolor_selected"); | ||||
AddSetting(GUIST_CStrW, "tooltip"); | AddSetting(GUIST_CStrW, "tooltip"); | ||||
AddSetting(GUIST_CStr, "tooltip_style"); | AddSetting(GUIST_CStr, "tooltip_style"); | ||||
CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate); | CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate); | ||||
// Add scroll-bar | // Add scrollbar | ||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(); | CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(); | ||||
bar->SetRightAligned(true); | bar->SetRightAligned(true); | ||||
AddScrollBar(bar); | AddScrollBar(bar); | ||||
} | } | ||||
CInput::~CInput() | CInput::~CInput() | ||||
{ | { | ||||
} | } | ||||
▲ Show 20 Lines • Show All 712 Lines • ▼ Show 20 Lines | void CInput::HandleMessage(SGUIMessage& Message) | ||||
switch (Message.type) | switch (Message.type) | ||||
{ | { | ||||
case GUIM_SETTINGS_UPDATED: | case GUIM_SETTINGS_UPDATED: | ||||
{ | { | ||||
bool scrollbar; | bool scrollbar; | ||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | ||||
// Update scroll-bar | // Update scrollbar | ||||
// TODO Gee: (2004-09-01) Is this really updated each time it should? | // TODO Gee: (2004-09-01) Is this really updated each time it should? | ||||
if (scrollbar && | if (scrollbar && | ||||
(Message.value == CStr("size") || | (Message.value == CStr("size") || | ||||
Message.value == CStr("z") || | Message.value == CStr("z") || | ||||
Message.value == CStr("absolute"))) | Message.value == CStr("absolute"))) | ||||
{ | { | ||||
GetScrollBar(0).SetX(m_CachedActualSize.right); | GetScrollBar(0).Setup(); | ||||
GetScrollBar(0).SetY(m_CachedActualSize.top); | |||||
GetScrollBar(0).SetZ(GetBufferedZ()); | |||||
GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); | |||||
} | } | ||||
// Update scrollbar | // Update scrollbar | ||||
if (Message.value == CStr("scrollbar_style")) | if (Message.value == CStr("scrollbar_style")) | ||||
{ | { | ||||
CStr scrollbar_style; | CStr scrollbar_style; | ||||
GUI<CStr>::GetSetting(this, Message.value, scrollbar_style); | GUI<CStr>::GetSetting(this, Message.value, scrollbar_style); | ||||
Show All 37 Lines | void CInput::HandleMessage(SGUIMessage& Message) | ||||
{ | { | ||||
bool scrollbar, multiline; | bool scrollbar, multiline; | ||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | ||||
GUI<bool>::GetSetting(this, "multiline", multiline); | GUI<bool>::GetSetting(this, "multiline", multiline); | ||||
// Check if we're selecting the scrollbar | // Check if we're selecting the scrollbar | ||||
if (GetScrollBar(0).GetStyle() && multiline) | if (GetScrollBar(0).GetStyle() && multiline) | ||||
{ | { | ||||
if (GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width) | if (GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Breadth) | ||||
break; | break; | ||||
} | } | ||||
if (m_ComposingText) | if (m_ComposingText) | ||||
break; | break; | ||||
// Okay, this section is about pressing the mouse and | // Okay, this section is about pressing the mouse and | ||||
// choosing where the point should be placed. For | // choosing where the point should be placed. For | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | if (m_SelectingText) | ||||
else | else | ||||
m_iBufferPos = GetMouseHoveringTextPosition(); | m_iBufferPos = GetMouseHoveringTextPosition(); | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
} | } | ||||
break; | break; | ||||
case GUIM_LOAD: | case GUIM_LOAD: | ||||
{ | { | ||||
GetScrollBar(0).SetX(m_CachedActualSize.right); | GetScrollBar(0).Setup(); | ||||
GetScrollBar(0).SetY(m_CachedActualSize.top); | |||||
GetScrollBar(0).SetZ(GetBufferedZ()); | |||||
GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); | |||||
CStr scrollbar_style; | CStr scrollbar_style; | ||||
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style); | GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style); | ||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style); | GetScrollBar(0).SetScrollBarStyle(scrollbar_style); | ||||
UpdateText(); | UpdateText(); | ||||
UpdateAutoScroll(); | UpdateAutoScroll(); | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | void CInput::UpdateCachedSize() | ||||
// If an ancestor's size changed, this will let us intercept the change and | // If an ancestor's size changed, this will let us intercept the change and | ||||
// update our scrollbar positions | // update our scrollbar positions | ||||
IGUIObject::UpdateCachedSize(); | IGUIObject::UpdateCachedSize(); | ||||
bool scrollbar; | bool scrollbar; | ||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | ||||
if (scrollbar) | if (scrollbar) | ||||
{ | GetScrollBar(0).Setup(); | ||||
GetScrollBar(0).SetX(m_CachedActualSize.right); | |||||
GetScrollBar(0).SetY(m_CachedActualSize.top); | |||||
GetScrollBar(0).SetZ(GetBufferedZ()); | |||||
GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); | |||||
} | |||||
} | } | ||||
void CInput::Draw() | void CInput::Draw() | ||||
{ | { | ||||
float bz = GetBufferedZ(); | float bz = GetBufferedZ(); | ||||
if (m_CursorBlinkRate > 0.0) | if (m_CursorBlinkRate > 0.0) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 740 Lines • ▼ Show 20 Lines | void CInput::UpdateText(int from, int to_before, int to_after) | ||||
{ | { | ||||
if (row.m_ListStart + (int)row.m_ListOfX.size() == current_line->m_ListStart) | if (row.m_ListStart + (int)row.m_ListOfX.size() == current_line->m_ListStart) | ||||
row.m_ListOfX.resize(row.m_ListOfX.size()-1); | row.m_ListOfX.resize(row.m_ListOfX.size()-1); | ||||
} | } | ||||
// add the final row (even if empty) | // add the final row (even if empty) | ||||
m_CharacterPositions.insert(current_line, row); | m_CharacterPositions.insert(current_line, row); | ||||
// Update scrollbar if needed | |||||
bool scrollbar; | bool scrollbar; | ||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | ||||
// Update scollbar | |||||
if (scrollbar) | if (scrollbar) | ||||
{ | { | ||||
GetScrollBar(0).SetScrollRange(m_CharacterPositions.size() * font.GetLineSpacing() + buffer_zone*2.f); | float height = m_CharacterPositions.size() * font.GetLineSpacing() + buffer_zone * 2.f; | ||||
GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight()); | m_CachedContentSize = CRect(0.0f, 0.0f, GetTextAreaWidth(), height); | ||||
GetScrollBar(0).Setup(); | |||||
} | } | ||||
} | } | ||||
int CInput::GetMouseHoveringTextPosition() const | int CInput::GetMouseHoveringTextPosition() const | ||||
{ | { | ||||
if (m_CharacterPositions.empty()) | if (m_CharacterPositions.empty()) | ||||
return 0; | return 0; | ||||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | |||||
float CInput::GetTextAreaWidth() | float CInput::GetTextAreaWidth() | ||||
{ | { | ||||
bool scrollbar; | bool scrollbar; | ||||
float buffer_zone; | float buffer_zone; | ||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | GUI<bool>::GetSetting(this, "scrollbar", scrollbar); | ||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); | GUI<float>::GetSetting(this, "buffer_zone", buffer_zone); | ||||
if (scrollbar && GetScrollBar(0).GetStyle()) | if (scrollbar && GetScrollBar(0).GetStyle()) | ||||
return m_CachedActualSize.GetWidth() - buffer_zone*2.f - GetScrollBar(0).GetStyle()->m_Width; | return m_CachedActualSize.GetWidth() - buffer_zone*2.f - GetScrollBar(0).GetStyle()->m_Breadth; | ||||
else | else | ||||
return m_CachedActualSize.GetWidth() - buffer_zone*2.f; | return m_CachedActualSize.GetWidth() - buffer_zone*2.f; | ||||
} | } | ||||
void CInput::UpdateAutoScroll() | void CInput::UpdateAutoScroll() | ||||
{ | { | ||||
float buffer_zone; | float buffer_zone; | ||||
bool multiline; | bool multiline; | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator