Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0008957: add missing vertical scrollbar functions to gui memo element #248

Merged
merged 3 commits into from Jul 22, 2018
Merged
Diff settings

Always

Just for now

@@ -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;
@@ -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);

@@ -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))
@@ -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)
@@ -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);
@@ -320,9 +322,15 @@ void CLuaGUIDefs::AddGuiMemoClass(lua_State* luaVM)
lua_classfunction(luaVM, "setCaretIndex", "guiMemoSetCaretIndex");
lua_classfunction(luaVM, "setReadOnly", "guiMemoSetReadOnly");

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

This comment has been minimized.

Copy link
@qaisjp

qaisjp Jul 22, 2018

Member

this line should sit with getCaretIndex

This comment has been minimized.

Copy link
@patrikjuvonen

patrikjuvonen Jul 22, 2018

Author Member

Thanks. Done.


lua_classfunction(luaVM, "setVerticalScrollPosition", "guiMemoSetVerticalScrollPosition");

This comment has been minimized.

Copy link
@qaisjp

qaisjp Jul 22, 2018

Member

this line should sit with setCaretIndex

This comment has been minimized.

Copy link
@patrikjuvonen

patrikjuvonen Jul 22, 2018

Author Member

Thanks. Done.


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

lua_classvariable(luaVM, "verticalScrollPosition", "guiMemoSetVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");

lua_registerclass(luaVM, "GuiMemo", "GuiElement");
}

@@ -3132,6 +3140,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 )
@@ -3153,6 +3184,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 )
@@ -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);
@@ -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;

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.