Skip to content

Commit 14cf976

Browse files
authored
Merge pull request #248 from patrikjuvonen/issue-8957
0008957: add missing vertical scrollbar functions to gui memo element
2 parents 3b68f4c + e453508 commit 14cf976

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-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: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ 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);
137139

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

318320
lua_classfunction(luaVM, "getCaretIndex", "guiMemoGetCaretIndex");
321+
lua_classfunction(luaVM, "getVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");
319322

320323
lua_classfunction(luaVM, "setCaretIndex", "guiMemoSetCaretIndex");
324+
lua_classfunction(luaVM, "setVerticalScrollPosition", "guiMemoSetVerticalScrollPosition");
321325
lua_classfunction(luaVM, "setReadOnly", "guiMemoSetReadOnly");
322326

323327
lua_classvariable(luaVM, "caretIndex", "guiMemoSetCaretIndex", "guiMemoGetCaretIndex");
328+
lua_classvariable(luaVM, "verticalScrollPosition", "guiMemoSetVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");
324329
lua_classvariable(luaVM, "readOnly", "guiMemoSetReadOnly", "guiMemoIsReadOnly");
325330

326331
lua_registerclass(luaVM, "GuiMemo", "GuiElement");
@@ -3132,6 +3137,29 @@ int CLuaGUIDefs::GUIMemoSetCaretIndex(lua_State* luaVM)
31323137
return 1;
31333138
}
31343139

3140+
int CLuaGUIDefs::GUIMemoSetVerticalScrollPosition(lua_State* luaVM)
3141+
{
3142+
// bool guiMemoSetVerticalScrollPosition ( gui-memo theMemo, float fPosition )
3143+
CClientGUIElement* theMemo;
3144+
float fPosition;
3145+
3146+
CScriptArgReader argStream(luaVM);
3147+
argStream.ReadUserData<CGUIMemo>(theMemo);
3148+
argStream.ReadNumber(fPosition);
3149+
3150+
if (!argStream.HasErrors())
3151+
{
3152+
CStaticFunctionDefinitions::GUIMemoSetVerticalScrollPosition(*theMemo, fPosition);
3153+
lua_pushboolean(luaVM, true);
3154+
return 1;
3155+
}
3156+
else
3157+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
3158+
3159+
lua_pushboolean(luaVM, false);
3160+
return 1;
3161+
}
3162+
31353163
int CLuaGUIDefs::GUIMemoGetCaretIndex(lua_State* luaVM)
31363164
{
31373165
// bool guiMemoGetCaretIndex ( gui-memo theMemo )
@@ -3153,6 +3181,29 @@ int CLuaGUIDefs::GUIMemoGetCaretIndex(lua_State* luaVM)
31533181
return 1;
31543182
}
31553183

3184+
int CLuaGUIDefs::GUIMemoGetVerticalScrollPosition(lua_State* luaVM)
3185+
{
3186+
// float guiMemoGetVerticalScrollPosition ( gui-memo theMemo )
3187+
CClientGUIElement* theMemo;
3188+
3189+
CScriptArgReader argStream(luaVM);
3190+
argStream.ReadUserData<CGUIMemo>(theMemo);
3191+
3192+
if (!argStream.HasErrors())
3193+
{
3194+
CGUIMemo* guiMemo = static_cast<CGUIMemo*>(theMemo->GetCGUIElement());
3195+
float fPos = guiMemo->GetVerticalScrollPosition() / guiMemo->GetMaxVerticalScrollPosition() * 100.0f;
3196+
lua_pushnumber(luaVM, fPos);
3197+
return 1;
3198+
}
3199+
else
3200+
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());
3201+
3202+
// error: bad arguments
3203+
lua_pushboolean(luaVM, false);
3204+
return 1;
3205+
}
3206+
31563207
int CLuaGUIDefs::GUIWindowSetMovable(lua_State* luaVM)
31573208
{
31583209
// bool guiWindowSetMovable ( element theElement, bool status )

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class CLuaGUIDefs : public CLuaDefs
123123
LUA_DECLARE(GUIMemoIsReadOnly);
124124
LUA_DECLARE(GUIMemoSetCaretIndex);
125125
LUA_DECLARE(GUIMemoGetCaretIndex);
126+
LUA_DECLARE(GUIMemoGetVerticalScrollPosition);
127+
LUA_DECLARE(GUIMemoSetVerticalScrollPosition);
126128
LUA_DECLARE(GUIWindowSetMovable);
127129
LUA_DECLARE(GUIWindowSetSizable);
128130
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)