Skip to content

Commit

Permalink
Added override for wxGraphicContext.GetTextExtent to properly retur…
Browse files Browse the repository at this point in the history
…n its results (closes #50).
  • Loading branch information
pkulchenko committed Dec 14, 2019
1 parent 0dd4436 commit 7ec6cff
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
5 changes: 2 additions & 3 deletions wxLua/bindings/wxwidgets/wxcore_graphics.i
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,8 @@ class %delete wxGraphicsContext : public wxGraphicsObject
void DrawText( const wxString &str, wxDouble x, wxDouble y,
wxDouble angle, const wxGraphicsBrush& backgroundBrush );


virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height,
wxDouble *descent = NULL, wxDouble *externalLeading = NULL ) const;// = 0;
// %override [wxDouble width, wxDouble height, wxDouble descent, wxDouble externalLeading] int GetTextExtent(const wxString& string;
void GetTextExtent(const wxString& string);

// virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const;// = 0;

Expand Down
27 changes: 27 additions & 0 deletions wxLua/bindings/wxwidgets/wxcore_override.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2894,3 +2894,30 @@ static int LUACALL wxLua_wxLuaPrintout_constructor(lua_State *L)
return 1;
}
%end

// ----------------------------------------------------------------------------
// Overrides for wxcore_graphics.i
// ----------------------------------------------------------------------------

%override wxLua_wxGraphicsContext_GetTextExtent
// void GetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent = NULL, wxCoord *externalLeading = NULL, wxFont *font = NULL)
static int LUACALL wxLua_wxGraphicsContext_GetTextExtent(lua_State *L)
{
wxDouble externalLeading;
wxDouble descent;
wxDouble h;
wxDouble w;

wxString string = wxlua_getwxStringtype(L, 2);
// get this
wxGraphicsContext *self = (wxGraphicsContext *)wxluaT_getuserdatatype(L, 1, wxluatype_wxGraphicsContext);
// call GetTextExtent
self->GetTextExtent(string, &w, &h, &descent, &externalLeading);
lua_pushnumber(L, w);
lua_pushnumber(L, h);
lua_pushnumber(L, descent);
lua_pushnumber(L, externalLeading);
// return the number of parameters
return 4;
}
%end
38 changes: 19 additions & 19 deletions wxLua/modules/wxbind/src/wxcore_graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3170,32 +3170,32 @@ static int LUACALL wxLua_wxGraphicsContext_GetSize(lua_State *L)
return 0;
}

static wxLuaArgType s_wxluatypeArray_wxLua_wxGraphicsContext_GetTextExtent[] = { &wxluatype_wxGraphicsContext, &wxluatype_TSTRING, &wxluatype_TLIGHTUSERDATA, &wxluatype_TLIGHTUSERDATA, &wxluatype_TLIGHTUSERDATA, &wxluatype_TLIGHTUSERDATA, NULL };
static wxLuaArgType s_wxluatypeArray_wxLua_wxGraphicsContext_GetTextExtent[] = { &wxluatype_wxGraphicsContext, &wxluatype_TSTRING, NULL };
static int LUACALL wxLua_wxGraphicsContext_GetTextExtent(lua_State *L);
static wxLuaBindCFunc s_wxluafunc_wxLua_wxGraphicsContext_GetTextExtent[1] = {{ wxLua_wxGraphicsContext_GetTextExtent, WXLUAMETHOD_METHOD, 4, 6, s_wxluatypeArray_wxLua_wxGraphicsContext_GetTextExtent }};
// wxDouble *descent = NULL, wxDouble *externalLeading = NULL ) const;// = 0;
static wxLuaBindCFunc s_wxluafunc_wxLua_wxGraphicsContext_GetTextExtent[1] = {{ wxLua_wxGraphicsContext_GetTextExtent, WXLUAMETHOD_METHOD, 2, 2, s_wxluatypeArray_wxLua_wxGraphicsContext_GetTextExtent }};
// %override wxLua_wxGraphicsContext_GetTextExtent
// void GetTextExtent(const wxString& string, wxCoord *w, wxCoord *h, wxCoord *descent = NULL, wxCoord *externalLeading = NULL, wxFont *font = NULL)
static int LUACALL wxLua_wxGraphicsContext_GetTextExtent(lua_State *L)
{
// get number of arguments
int argCount = lua_gettop(L);
// wxDouble externalLeading = NULL
wxDouble * externalLeading = (argCount >= 6 ? (wxDouble *)wxlua_touserdata(L, 6) : NULL);
// wxDouble descent = NULL
wxDouble * descent = (argCount >= 5 ? (wxDouble *)wxlua_touserdata(L, 5) : NULL);
// wxDouble height
wxDouble * height = (wxDouble *)wxlua_touserdata(L, 4);
// wxDouble width
wxDouble * width = (wxDouble *)wxlua_touserdata(L, 3);
// const wxString text
const wxString text = wxlua_getwxStringtype(L, 2);
wxDouble externalLeading;
wxDouble descent;
wxDouble h;
wxDouble w;

wxString string = wxlua_getwxStringtype(L, 2);
// get this
wxGraphicsContext * self = (wxGraphicsContext *)wxluaT_getuserdatatype(L, 1, wxluatype_wxGraphicsContext);
wxGraphicsContext *self = (wxGraphicsContext *)wxluaT_getuserdatatype(L, 1, wxluatype_wxGraphicsContext);
// call GetTextExtent
self->GetTextExtent(text, width, height, descent, externalLeading);

return 0;
self->GetTextExtent(string, &w, &h, &descent, &externalLeading);
lua_pushnumber(L, w);
lua_pushnumber(L, h);
lua_pushnumber(L, descent);
lua_pushnumber(L, externalLeading);
// return the number of parameters
return 4;
}


static wxLuaArgType s_wxluatypeArray_wxLua_wxGraphicsContext_GetTransform[] = { &wxluatype_wxGraphicsContext, NULL };
static int LUACALL wxLua_wxGraphicsContext_GetTransform(lua_State *L);
static wxLuaBindCFunc s_wxluafunc_wxLua_wxGraphicsContext_GetTransform[1] = {{ wxLua_wxGraphicsContext_GetTransform, WXLUAMETHOD_METHOD, 1, 1, s_wxluatypeArray_wxLua_wxGraphicsContext_GetTransform }};
Expand Down

0 comments on commit 7ec6cff

Please sign in to comment.