forked from mirrors/0ad
Add getTextSize() for CButton
Summary:9c5062147aintroduced the `getTextSize()` to all GUIObjects for getting the rendered size of a text.8190293f8bmade it only available to CText. `getTextSize()` can also be useful for CButtons so this diff adds the function back to CButtons. There seem to be no other GUIObjects besiders CText and CButton where `getTextSize()` makes sense. Reviewed By: wraitii Differential Revision: https://code.wildfiregames.com/D3195 This was SVN commit r24378.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUIText.h"
|
||||
#include "gui/Scripting/JSInterface_GUIProxy.h"
|
||||
#include "gui/SettingTypes/CGUIColor.h"
|
||||
|
||||
CButton::CButton(CGUI& pGUI)
|
||||
@@ -117,3 +118,24 @@ const CGUIColor& CButton::ChooseColor()
|
||||
|
||||
return m_TextColorOver || m_TextColor;
|
||||
}
|
||||
|
||||
void CButton::CreateJSObject()
|
||||
{
|
||||
ScriptRequest rq(m_pGUI.GetScriptInterface());
|
||||
|
||||
js::ProxyOptions options;
|
||||
options.setClass(&JSI_GUIProxy<CButton>::ClassDefinition());
|
||||
|
||||
JS::RootedValue cppObj(rq.cx), data(rq.cx);
|
||||
cppObj.get().setPrivate(this);
|
||||
data.get().setPrivate(GetGUI().GetProxyData(&JSI_GUIProxy<CButton>::Singleton()));
|
||||
m_JSObject.init(rq.cx, js::NewProxyObject(rq.cx, &JSI_GUIProxy<CButton>::Singleton(), cppObj, nullptr, options));
|
||||
js::SetProxyReservedSlot(m_JSObject, 0, data);
|
||||
}
|
||||
|
||||
void CButton::getTextSize(ScriptInterface& scriptInterface, JS::MutableHandleValue ret)
|
||||
{
|
||||
ScriptRequest rq(scriptInterface);
|
||||
UpdateText();
|
||||
ScriptInterface::ToJSVal(rq, ret, m_GeneratedTexts[0].GetSize());
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ class CButton : public IGUIObject, public IGUITextOwner, public IGUIButtonBehavi
|
||||
{
|
||||
GUI_OBJECT(CButton)
|
||||
|
||||
friend JSI_GUIProxy<CButton>;
|
||||
|
||||
public:
|
||||
CButton(CGUI& pGUI);
|
||||
virtual ~CButton();
|
||||
@@ -69,6 +71,10 @@ protected:
|
||||
*/
|
||||
CPos m_TextPos;
|
||||
|
||||
virtual void CreateJSObject();
|
||||
|
||||
void getTextSize(ScriptInterface& scriptInterface, JS::MutableHandleValue ret);
|
||||
|
||||
// Settings
|
||||
float m_BufferZone;
|
||||
i32 m_CellID;
|
||||
|
||||
Reference in New Issue
Block a user