Skip to content

Commit

Permalink
Merge pull request #248 from patrikjuvonen/issue-8957
Browse files Browse the repository at this point in the history
0008957: add missing vertical scrollbar functions to gui memo element
  • Loading branch information
qaisjp committed Jul 22, 2018
2 parents 3b68f4c + e453508 commit 14cf976
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Client/gui/CGUIMemo_Impl.cpp
Expand Up @@ -111,6 +111,11 @@ void CGUIMemo_Impl::SetVerticalScrollPosition(float fPosition)
}
}

float CGUIMemo_Impl::GetMaxVerticalScrollPosition(void)
{
return GetScrollbarDocumentSize() - GetScrollbarPageSize();
}

float CGUIMemo_Impl::GetScrollbarDocumentSize(void)
{
CEGUI::Scrollbar* pScrollbar = reinterpret_cast<CEGUI::MultiLineEditbox*>(m_pWindow)->d_vertScrollbar;
Expand Down
1 change: 1 addition & 0 deletions Client/gui/CGUIMemo_Impl.h
Expand Up @@ -29,6 +29,7 @@ class CGUIMemo_Impl : public CGUIMemo, public CGUIElement_Impl, public CGUITabLi

float GetVerticalScrollPosition(void);
void SetVerticalScrollPosition(float fPosition);
float GetMaxVerticalScrollPosition(void);
float GetScrollbarDocumentSize(void);
float GetScrollbarPageSize(void);

Expand Down
18 changes: 18 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -5569,6 +5569,24 @@ void CStaticFunctionDefinitions::GUIMemoSetCaretIndex(CClientEntity& Entity, uns
}
}

void CStaticFunctionDefinitions::GUIMemoSetVerticalScrollPosition(CClientEntity& Entity, float fPosition)
{
RUN_CHILDREN(GUIMemoSetVerticalScrollPosition(**iter, fPosition))

// Are we a GUI element?
if (IS_GUI(&Entity))
{
CClientGUIElement& GUIElement = static_cast<CClientGUIElement&>(Entity);

// Are we a gridlist?
if (IS_CGUIELEMENT_MEMO(&GUIElement))
{
CGUIMemo* guiMemo = static_cast<CGUIMemo*>(GUIElement.GetCGUIElement());
guiMemo->SetVerticalScrollPosition(fPosition / 100.0f * guiMemo->GetMaxVerticalScrollPosition());
}
}
}

void CStaticFunctionDefinitions::GUIGridListSetSortingEnabled(CClientEntity& Entity, bool bEnabled)
{
RUN_CHILDREN(GUIGridListSetSortingEnabled(**iter, bEnabled))
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -460,6 +460,7 @@ class CStaticFunctionDefinitions

static void GUIMemoSetReadOnly(CClientEntity& Element, bool bFlag);
static void GUIMemoSetCaretIndex(CClientEntity& Element, unsigned int iCaret);
static void GUIMemoSetVerticalScrollPosition(CClientEntity& Element, float fPosition);

static void GUIGridListSetSortingEnabled(CClientEntity& Element, bool bEnabled);
static inline unsigned int GUIGridListAddColumn(CClientGUIElement& GUIElement, const char* szTitle, float fWidth)
Expand Down
51 changes: 51 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp
Expand Up @@ -134,6 +134,8 @@ void CLuaGUIDefs::LoadFunctions(void)
CLuaCFunctions::AddFunction("guiMemoGetCaretIndex", GUIMemoGetCaretIndex);
CLuaCFunctions::AddFunction("guiMemoSetReadOnly", GUIMemoSetReadOnly);
CLuaCFunctions::AddFunction("guiMemoIsReadOnly", GUIMemoIsReadOnly);
CLuaCFunctions::AddFunction("guiMemoSetVerticalScrollPosition", GUIMemoSetVerticalScrollPosition);
CLuaCFunctions::AddFunction("guiMemoGetVerticalScrollPosition", GUIMemoGetVerticalScrollPosition);

CLuaCFunctions::AddFunction("guiLabelSetColor", GUILabelSetColor);
CLuaCFunctions::AddFunction("guiLabelGetColor", GUILabelGetColor);
Expand Down Expand Up @@ -316,11 +318,14 @@ void CLuaGUIDefs::AddGuiMemoClass(lua_State* luaVM)
lua_classfunction(luaVM, "create", "guiCreateMemo");

lua_classfunction(luaVM, "getCaretIndex", "guiMemoGetCaretIndex");
lua_classfunction(luaVM, "getVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");

lua_classfunction(luaVM, "setCaretIndex", "guiMemoSetCaretIndex");
lua_classfunction(luaVM, "setVerticalScrollPosition", "guiMemoSetVerticalScrollPosition");
lua_classfunction(luaVM, "setReadOnly", "guiMemoSetReadOnly");

lua_classvariable(luaVM, "caretIndex", "guiMemoSetCaretIndex", "guiMemoGetCaretIndex");
lua_classvariable(luaVM, "verticalScrollPosition", "guiMemoSetVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");
lua_classvariable(luaVM, "readOnly", "guiMemoSetReadOnly", "guiMemoIsReadOnly");

lua_registerclass(luaVM, "GuiMemo", "GuiElement");
Expand Down Expand Up @@ -3132,6 +3137,29 @@ int CLuaGUIDefs::GUIMemoSetCaretIndex(lua_State* luaVM)
return 1;
}

int CLuaGUIDefs::GUIMemoSetVerticalScrollPosition(lua_State* luaVM)
{
// bool guiMemoSetVerticalScrollPosition ( gui-memo theMemo, float fPosition )
CClientGUIElement* theMemo;
float fPosition;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData<CGUIMemo>(theMemo);
argStream.ReadNumber(fPosition);

if (!argStream.HasErrors())
{
CStaticFunctionDefinitions::GUIMemoSetVerticalScrollPosition(*theMemo, fPosition);
lua_pushboolean(luaVM, true);
return 1;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaGUIDefs::GUIMemoGetCaretIndex(lua_State* luaVM)
{
// bool guiMemoGetCaretIndex ( gui-memo theMemo )
Expand All @@ -3153,6 +3181,29 @@ int CLuaGUIDefs::GUIMemoGetCaretIndex(lua_State* luaVM)
return 1;
}

int CLuaGUIDefs::GUIMemoGetVerticalScrollPosition(lua_State* luaVM)
{
// float guiMemoGetVerticalScrollPosition ( gui-memo theMemo )
CClientGUIElement* theMemo;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData<CGUIMemo>(theMemo);

if (!argStream.HasErrors())
{
CGUIMemo* guiMemo = static_cast<CGUIMemo*>(theMemo->GetCGUIElement());
float fPos = guiMemo->GetVerticalScrollPosition() / guiMemo->GetMaxVerticalScrollPosition() * 100.0f;
lua_pushnumber(luaVM, fPos);
return 1;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

// error: bad arguments
lua_pushboolean(luaVM, false);
return 1;
}

int CLuaGUIDefs::GUIWindowSetMovable(lua_State* luaVM)
{
// bool guiWindowSetMovable ( element theElement, bool status )
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h
Expand Up @@ -123,6 +123,8 @@ class CLuaGUIDefs : public CLuaDefs
LUA_DECLARE(GUIMemoIsReadOnly);
LUA_DECLARE(GUIMemoSetCaretIndex);
LUA_DECLARE(GUIMemoGetCaretIndex);
LUA_DECLARE(GUIMemoGetVerticalScrollPosition);
LUA_DECLARE(GUIMemoSetVerticalScrollPosition);
LUA_DECLARE(GUIWindowSetMovable);
LUA_DECLARE(GUIWindowSetSizable);
LUA_DECLARE(GUIWindowGetMovable);
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/gui/CGUIMemo.h
Expand Up @@ -28,6 +28,7 @@ class CGUIMemo : public CGUIElement

virtual float GetVerticalScrollPosition(void) = 0;
virtual void SetVerticalScrollPosition(float fPosition) = 0;
virtual float GetMaxVerticalScrollPosition(void) = 0;
virtual float GetScrollbarDocumentSize(void) = 0;
virtual float GetScrollbarPageSize(void) = 0;

Expand Down

0 comments on commit 14cf976

Please sign in to comment.