Skip to content

Commit 309acac

Browse files
committed
CLuaGUIDefs: add vertical scrollbar functions
1 parent 3b68f4c commit 309acac

File tree

7 files changed

+108
-0
lines changed

7 files changed

+108
-0
lines changed

Client/gui/CGUIMemo_Impl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ void CGUIMemo_Impl::SetVerticalScrollPosition(float fPosition)
111111
}
112112
}
113113

114+
float CGUIMemo_Impl::GetMaxVerticalScrollPosition(void)
115+
{
116+
return GetScrollbarDocumentSize() - GetScrollbarPageSize();
117+
}
118+
114119
float CGUIMemo_Impl::GetScrollbarDocumentSize(void)
115120
{
116121
CEGUI::Scrollbar* pScrollbar = reinterpret_cast<CEGUI::MultiLineEditbox*>(m_pWindow)->d_vertScrollbar;

Client/gui/CGUIMemo_Impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class CGUIMemo_Impl : public CGUIMemo, public CGUIElement_Impl, public CGUITabLi
2929

3030
float GetVerticalScrollPosition(void);
3131
void SetVerticalScrollPosition(float fPosition);
32+
float GetMaxVerticalScrollPosition(void);
3233
float GetScrollbarDocumentSize(void);
3334
float GetScrollbarPageSize(void);
3435

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5569,6 +5569,24 @@ void CStaticFunctionDefinitions::GUIMemoSetCaretIndex(CClientEntity& Entity, uns
55695569
}
55705570
}
55715571

5572+
void CStaticFunctionDefinitions::GUIMemoSetVerticalScrollPosition(CClientEntity& Entity, float fPosition)
5573+
{
5574+
RUN_CHILDREN(GUIMemoSetVerticalScrollPosition(**iter, fPosition))
5575+
5576+
// Are we a GUI element?
5577+
if (IS_GUI(&Entity))
5578+
{
5579+
CClientGUIElement& GUIElement = static_cast<CClientGUIElement&>(Entity);
5580+
5581+
// Are we a gridlist?
5582+
if (IS_CGUIELEMENT_MEMO(&GUIElement))
5583+
{
5584+
CGUIMemo* guiMemo = static_cast<CGUIMemo*>(GUIElement.GetCGUIElement());
5585+
guiMemo->SetVerticalScrollPosition(fPosition / 100.0f * guiMemo->GetMaxVerticalScrollPosition());
5586+
}
5587+
}
5588+
}
5589+
55725590
void CStaticFunctionDefinitions::GUIGridListSetSortingEnabled(CClientEntity& Entity, bool bEnabled)
55735591
{
55745592
RUN_CHILDREN(GUIGridListSetSortingEnabled(**iter, bEnabled))

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ class CStaticFunctionDefinitions
460460

461461
static void GUIMemoSetReadOnly(CClientEntity& Element, bool bFlag);
462462
static void GUIMemoSetCaretIndex(CClientEntity& Element, unsigned int iCaret);
463+
static void GUIMemoSetVerticalScrollPosition(CClientEntity& Element, float fPosition);
463464

464465
static void GUIGridListSetSortingEnabled(CClientEntity& Element, bool bEnabled);
465466
static inline unsigned int GUIGridListAddColumn(CClientGUIElement& GUIElement, const char* szTitle, float fWidth)

Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ void CLuaGUIDefs::LoadFunctions(void)
134134
CLuaCFunctions::AddFunction("guiMemoGetCaretIndex", GUIMemoGetCaretIndex);
135135
CLuaCFunctions::AddFunction("guiMemoSetReadOnly", GUIMemoSetReadOnly);
136136
CLuaCFunctions::AddFunction("guiMemoIsReadOnly", GUIMemoIsReadOnly);
137+
CLuaCFunctions::AddFunction("guiMemoSetVerticalScrollPosition", GUIMemoSetVerticalScrollPosition);
138+
CLuaCFunctions::AddFunction("guiMemoGetVerticalScrollPosition", GUIMemoGetVerticalScrollPosition);
139+
CLuaCFunctions::AddFunction("guiMemoGetMaxVerticalScrollPosition", GUIMemoGetMaxVerticalScrollPosition);
137140

138141
CLuaCFunctions::AddFunction("guiLabelSetColor", GUILabelSetColor);
139142
CLuaCFunctions::AddFunction("guiLabelGetColor", GUILabelGetColor);
@@ -320,9 +323,17 @@ void CLuaGUIDefs::AddGuiMemoClass(lua_State* luaVM)
320323
lua_classfunction(luaVM, "setCaretIndex", "guiMemoSetCaretIndex");
321324
lua_classfunction(luaVM, "setReadOnly", "guiMemoSetReadOnly");
322325

326+
lua_classfunction(luaVM, "getVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");
327+
lua_classfunction(luaVM, "getMaxVerticalScrollPosition", "guiMemoGetMaxVerticalScrollPosition");
328+
329+
lua_classfunction(luaVM, "setVerticalScrollPosition", "guiMemoSetVerticalScrollPosition");
330+
323331
lua_classvariable(luaVM, "caretIndex", "guiMemoSetCaretIndex", "guiMemoGetCaretIndex");
324332
lua_classvariable(luaVM, "readOnly", "guiMemoSetReadOnly", "guiMemoIsReadOnly");
325333

334+
lua_classvariable(luaVM, "verticalScrollPosition", "guiMemoSetVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");
335+
lua_classvariable(luaVM, "maxVerticalScrollPosition", NULL, "guiMemoGetMaxVerticalScrollPosition");
336+
326337
lua_registerclass(luaVM, "GuiMemo", "GuiElement");
327338
}
328339

@@ -3132,6 +3143,29 @@ int CLuaGUIDefs::GUIMemoSetCaretIndex(lua_State* luaVM)
31323143
return 1;
31333144
}
31343145

3146+
int CLuaGUIDefs::GUIMemoSetVerticalScrollPosition(lua_State* luaVM)
3147+
{
3148+
// bool guiMemoSetVerticalScrollPosition ( gui-memo theMemo, float fPosition )
3149+
CClientGUIElement* theMemo;
3150+
float fPosition;
3151+
3152+
CScriptArgReader argStream(luaVM);
3153+
argStream.ReadUserData<CGUIMemo>(theMemo);
3154+
argStream.ReadNumber(fPosition);
3155+
3156+
if (!argStream.HasErrors())
3157+
{
3158+
CStaticFunctionDefinitions::GUIMemoSetVerticalScrollPosition(*theMemo, fPosition);
3159+
lua_pushboolean(luaVM, true);
3160+
return 1;
3161+
}
3162+
else
3163+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
3164+
3165+
lua_pushboolean(luaVM, false);
3166+
return 1;
3167+
}
3168+
31353169
int CLuaGUIDefs::GUIMemoGetCaretIndex(lua_State* luaVM)
31363170
{
31373171
// bool guiMemoGetCaretIndex ( gui-memo theMemo )
@@ -3153,6 +3187,51 @@ int CLuaGUIDefs::GUIMemoGetCaretIndex(lua_State* luaVM)
31533187
return 1;
31543188
}
31553189

3190+
int CLuaGUIDefs::GUIMemoGetMaxVerticalScrollPosition(lua_State* luaVM)
3191+
{
3192+
// float guiMemoGetMaxVerticalScrollPosition ( gui-memo theMemo )
3193+
CClientGUIElement* theMemo;
3194+
3195+
CScriptArgReader argStream(luaVM);
3196+
argStream.ReadUserData<CGUIMemo>(theMemo);
3197+
3198+
if (!argStream.HasErrors())
3199+
{
3200+
float fPos = static_cast<CGUIMemo*>(theMemo->GetCGUIElement())->GetMaxVerticalScrollPosition();
3201+
lua_pushnumber(luaVM, fPos);
3202+
return 1;
3203+
}
3204+
else
3205+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
3206+
3207+
// error: bad arguments
3208+
lua_pushboolean(luaVM, false);
3209+
return 1;
3210+
}
3211+
3212+
int CLuaGUIDefs::GUIMemoGetVerticalScrollPosition(lua_State* luaVM)
3213+
{
3214+
// float guiMemoGetVerticalScrollPosition ( gui-memo theMemo )
3215+
CClientGUIElement* theMemo;
3216+
3217+
CScriptArgReader argStream(luaVM);
3218+
argStream.ReadUserData<CGUIMemo>(theMemo);
3219+
3220+
if (!argStream.HasErrors())
3221+
{
3222+
CGUIMemo* guiMemo = static_cast<CGUIMemo*>(theMemo->GetCGUIElement());
3223+
float fPos = guiMemo->GetVerticalScrollPosition() / guiMemo->GetMaxVerticalScrollPosition() * 100.0f;
3224+
lua_pushnumber(luaVM, fPos);
3225+
return 1;
3226+
}
3227+
else
3228+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
3229+
3230+
// error: bad arguments
3231+
lua_pushboolean(luaVM, false);
3232+
return 1;
3233+
}
3234+
31563235
int CLuaGUIDefs::GUIWindowSetMovable(lua_State* luaVM)
31573236
{
31583237
// bool guiWindowSetMovable ( element theElement, bool status )

Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ class CLuaGUIDefs : public CLuaDefs
123123
LUA_DECLARE(GUIMemoIsReadOnly);
124124
LUA_DECLARE(GUIMemoSetCaretIndex);
125125
LUA_DECLARE(GUIMemoGetCaretIndex);
126+
LUA_DECLARE(GUIMemoGetVerticalScrollPosition);
127+
LUA_DECLARE(GUIMemoSetVerticalScrollPosition);
128+
LUA_DECLARE(GUIMemoGetMaxVerticalScrollPosition);
126129
LUA_DECLARE(GUIWindowSetMovable);
127130
LUA_DECLARE(GUIWindowSetSizable);
128131
LUA_DECLARE(GUIWindowGetMovable);

Client/sdk/gui/CGUIMemo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class CGUIMemo : public CGUIElement
2828

2929
virtual float GetVerticalScrollPosition(void) = 0;
3030
virtual void SetVerticalScrollPosition(float fPosition) = 0;
31+
virtual float GetMaxVerticalScrollPosition(void) = 0;
3132
virtual float GetScrollbarDocumentSize(void) = 0;
3233
virtual float GetScrollbarPageSize(void) = 0;
3334

0 commit comments

Comments
 (0)