1
0
forked from mirrors/0ad

Remove virtual inheritance from the codebase, refs 6b51d71c85, e21ebb37f5 e326ebae46.

Remove workaround in 3d07327837 / D2136, the pointer from IGUIObject to
IGUITextOwner that avoided the dynamic_cast.
Have the GUIObject implementing class take responsibility of calling the
virtual methods in the base classes.
Leaves the code in a clean state that can serve as an example for new
GUI object classes, such as D1346, refs #4683.

Differential Revision: https://code.wildfiregames.com/D2325
Comments By: Vladislav on IRC 2019-07-30, 2019-08-22, 2019-09-20-23
Tested on: clang 8.0.1, Jenkins

This was SVN commit r23020.
This commit is contained in:
elexis
2019-09-30 14:08:14 +00:00
parent 1679510bb8
commit 8190293f8b
31 changed files with 293 additions and 250 deletions
+47 -2
View File
@@ -22,11 +22,12 @@
#include "gui/CGUI.h"
#include "gui/CGUIScrollBarVertical.h"
#include "gui/CGUIText.h"
#include "scriptinterface/ScriptInterface.h"
CText::CText(CGUI& pGUI)
: IGUIObject(pGUI),
IGUIScrollBarOwner(pGUI),
IGUITextOwner(pGUI),
IGUIScrollBarOwner(*static_cast<IGUIObject*>(this)),
IGUITextOwner(*static_cast<IGUIObject*>(this)),
m_BufferZone(),
m_Caption(),
m_CellID(),
@@ -121,8 +122,21 @@ void CText::SetupText()
}
}
void CText::ResetStates()
{
IGUIObject::ResetStates();
IGUIScrollBarOwner::ResetStates();
}
void CText::UpdateCachedSize()
{
IGUIObject::UpdateCachedSize();
IGUITextOwner::UpdateCachedSize();
}
void CText::HandleMessage(SGUIMessage& Message)
{
IGUIObject::HandleMessage(Message);
IGUIScrollBarOwner::HandleMessage(Message);
//IGUITextOwner::HandleMessage(Message); <== placed it after the switch instead!
@@ -237,3 +251,34 @@ bool CText::MouseOverIcon()
return false;
}
void CText::RegisterScriptFunctions()
{
JSContext* cx = m_pGUI.GetScriptInterface()->GetContext();
JSAutoRequest rq(cx);
JS_DefineFunctions(cx, m_JSObject, CText::JSI_methods);
}
JSFunctionSpec CText::JSI_methods[] =
{
JS_FN("getTextSize", CText::GetTextSize, 0, 0),
JS_FS_END
};
bool CText::GetTextSize(JSContext* cx, uint argc, JS::Value* vp)
{
// No JSAutoRequest needed for these calls
JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
CText* thisObj = ScriptInterface::GetPrivate<CText>(cx, args, &JSI_IGUIObject::JSI_class);
if (!thisObj)
{
JSAutoRequest rq(cx);
JS_ReportError(cx, "This is not a CText object!");
return false;
}
thisObj->UpdateText();
ScriptInterface::ToJSVal(cx, args.rval(), thisObj->m_GeneratedTexts[0].GetSize());
return true;
}