diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-09-02 22:55:08 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-09-02 22:55:08 (GMT) |
| commit | 4e09a077a4d7494d1c1e1f494cbc36fa9abcb19c (patch) | |
| tree | f76cf74aa260678cd230dba8955d378c5fa392f0 /src/cat/LuaButton.cpp | |
| parent | b7616a91d860871a3e4ac46cba957633a93acb59 (diff) | |
| download | powder-4e09a077a4d7494d1c1e1f494cbc36fa9abcb19c.zip powder-4e09a077a4d7494d1c1e1f494cbc36fa9abcb19c.tar.gz | |
Textbox component for Lua interface API
Diffstat (limited to 'src/cat/LuaButton.cpp')
| -rw-r--r-- | src/cat/LuaButton.cpp | 64 |
1 files changed, 19 insertions, 45 deletions
diff --git a/src/cat/LuaButton.cpp b/src/cat/LuaButton.cpp index 18001fd..59890f2 100644 --- a/src/cat/LuaButton.cpp +++ b/src/cat/LuaButton.cpp @@ -18,13 +18,15 @@ Luna<LuaButton>::RegType LuaButton::methods[] = { method(LuaButton, text), method(LuaButton, position), method(LuaButton, size), + method(LuaButton, visible), + method(LuaButton, enabled), {0, 0} }; LuaButton::LuaButton(lua_State * l) : + LuaComponent(l), actionFunction(0) { - this->l = l; int posX = luaL_optinteger(l, 1, 0); int posY = luaL_optinteger(l, 2, 0); int sizeX = luaL_optinteger(l, 3, 10); @@ -32,12 +34,8 @@ LuaButton::LuaButton(lua_State * l) : std::string text = luaL_optstring(l, 5, ""); std::string toolTip = luaL_optstring(l, 6, ""); - lua_pushstring(l, "Luacon_ci"); - lua_gettable(l, LUA_REGISTRYINDEX); - ci = (LuaScriptInterface*)lua_touserdata(l, -1); - lua_pop(l, 1); - button = new ui::Button(ui::Point(posX, posY), ui::Point(sizeX, sizeY), text, toolTip); + component = button; class ClickAction : public ui::ButtonAction { LuaButton * luaButton; @@ -51,70 +49,49 @@ LuaButton::LuaButton(lua_State * l) : button->SetActionCallback(new ClickAction(this)); } -int LuaButton::action(lua_State * l) -{ - if(lua_type(l, 1) != LUA_TNIL) - { - luaL_checktype(l, 1, LUA_TFUNCTION); - lua_pushvalue(l, 1); - actionFunction = luaL_ref(l, LUA_REGISTRYINDEX); - } - else - { - actionFunction = 0; - } -} - -int LuaButton::text(lua_State * l) +int LuaButton::enabled(lua_State * l) { int args = lua_gettop(l); if(args) { - luaL_checktype(l, 1, LUA_TSTRING); - button->SetText(lua_tostring(l, 1)); + luaL_checktype(l, 1, LUA_TBOOLEAN); + button->Enabled = lua_toboolean(l, 1); return 0; } else { - lua_pushstring(l, button->GetText().c_str()); + lua_pushboolean(l, button->Enabled); return 1; } } -int LuaButton::position(lua_State * l) +int LuaButton::action(lua_State * l) { - int args = lua_gettop(l); - if(args) + if(lua_type(l, 1) != LUA_TNIL) { - luaL_checktype(l, 1, LUA_TNUMBER); - luaL_checktype(l, 2, LUA_TNUMBER); - button->Position = ui::Point(lua_tointeger(l, 1), lua_tointeger(l, 2)); - return 0; + luaL_checktype(l, 1, LUA_TFUNCTION); + lua_pushvalue(l, 1); + actionFunction = luaL_ref(l, LUA_REGISTRYINDEX); } else { - lua_pushinteger(l, button->Position.X); - lua_pushinteger(l, button->Position.Y); - return 2; + actionFunction = 0; } } -int LuaButton::size(lua_State * l) +int LuaButton::text(lua_State * l) { int args = lua_gettop(l); if(args) { - luaL_checktype(l, 1, LUA_TNUMBER); - luaL_checktype(l, 2, LUA_TNUMBER); - button->Size = ui::Point(lua_tointeger(l, 1), lua_tointeger(l, 2)); - button->Invalidate(); + luaL_checktype(l, 1, LUA_TSTRING); + button->SetText(lua_tostring(l, 1)); return 0; } else { - lua_pushinteger(l, button->Size.X); - lua_pushinteger(l, button->Size.Y); - return 2; + lua_pushstring(l, button->GetText().c_str()); + return 1; } } @@ -133,7 +110,4 @@ void LuaButton::triggerAction() LuaButton::~LuaButton() { - if(button->GetParentWindow()) - button->GetParentWindow()->RemoveComponent(button); - delete button; }
\ No newline at end of file |
