From fc03f11c0e59515d4b467f8288f5dc7b962ec0bc Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Fri, 18 Apr 2014 18:39:38 +1000 Subject: Half arsed window and button implementation. --- ClientHamr/GuiLua/GuiLua.c | 89 +++++++++++++++++++++++++++++++++++++++----- ClientHamr/GuiLua/skang.lua | 45 ++++++++++++++++++++-- ClientHamr/GuiLua/test.skang | 5 ++- 3 files changed, 125 insertions(+), 14 deletions(-) (limited to 'ClientHamr') diff --git a/ClientHamr/GuiLua/GuiLua.c b/ClientHamr/GuiLua/GuiLua.c index 3854bdd..b42df1b 100644 --- a/ClientHamr/GuiLua/GuiLua.c +++ b/ClientHamr/GuiLua/GuiLua.c @@ -216,6 +216,9 @@ void loggingStartup(globals *ourGlobals) eina_log_level_set(EINA_LOG_LEVEL_DBG); eina_log_domain_level_set("GuiLua", EINA_LOG_LEVEL_DBG); eina_log_print_cb_set(_ggg_log_print_cb, stderr); + + // Shut up the excess debugging shit from EFL. + eina_log_domain_level_set("ecore_input_evas", EINA_LOG_LEVEL_WARN); } char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) @@ -527,32 +530,94 @@ static void _on_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info { // globals *ourGlobals = data; -// TODO - skang.quit() should do this to. // Tell the main loop to stop, which it will, eventually. elm_exit(); } + +struct widget +{ + Evas_Object *widget; + char *label, *look, *action, *help; + // foreground / background colour + // thing + // types {} + // skangCoord x, y, w, h +}; + +/* Sooo, how to do this - + +widget has to be a light userdata +The rest can be Lua sub things? Each with a C function to update the widget. + +win.quitter.look + +win.quitter:colour(1,2,3,4) -> win.quitter.colour(win.quitter, 1,2,3,4) -> __call(win.quitter.colour, win.quitter, 1,2,3,4) -> skang.colour(win.quitter.colour, win.quitter, 1,2,3,4) +win.quitter.colour.r = 5 -> direct access to the table, well "direct" via Thing and Mum. We eventually want to call skang.colour() though. + +*/ + +static int widget(lua_State *L) +{ + globals *ourGlobals; + Evas_Object *bt; + char *type = "label"; + char *title = ":"; + int x = 1, y = 1, w = WIDTH/3, h = HEIGHT/3; + + lua_getfield(L, LUA_REGISTRYINDEX, globName); + ourGlobals = lua_touserdata(L, -1); + lua_pop(L, 1); + + pull_lua(L, 1, "$type $title %x %y %w %h", &type, &title, &x, &y, &w, &h); + + // Poor mans introspection, until I write real introspection into EFL. + if (strcmp(type, "button") == 0) + { + bt = elm_button_add(ourGlobals->win); + elm_object_text_set(bt, title); + evas_object_smart_callback_add(bt, "clicked", _on_done, ourGlobals); + evas_object_resize(bt, w, h); + evas_object_move(bt, x, y); + evas_object_show(bt); + lua_pushlightuserdata(L, &bt); + return 1; + } + + return 0; +} + +static int colour(lua_State *L) +{ +// TODO - This is just a stub for now. + + return 0; +} + + static int window(lua_State *L) { globals *ourGlobals; - char *title = NULL; + char *name = "GuiLua"; + char *title = "GuiLua test harness"; int w = WIDTH, h = HEIGHT; lua_getfield(L, LUA_REGISTRYINDEX, globName); ourGlobals = lua_touserdata(L, -1); lua_pop(L, 1); - if (pull_lua(L, 1, "%w %h $title", &w, &h, &title) > 0) - PI("Setting window to %d %d %s", w, h, title); - else - title = "GuiLua test harness"; + pull_lua(L, 1, "%w %h $title $name", &w, &h, &title, &name); + PI("Setting window to %d %d %s", w, h, title); - if ((ourGlobals->win = elm_win_util_standard_add("GuiLua", title))) + if ((ourGlobals->win = elm_win_util_standard_add(name, title))) { evas_object_smart_callback_add(ourGlobals->win, "delete,request", _on_done, ourGlobals); evas_object_resize(ourGlobals->win, w, h); evas_object_move(ourGlobals->win, 0, 0); evas_object_show(ourGlobals->win); + + lua_pushlightuserdata(L, &ourGlobals->win); + return 1; } return 0; @@ -600,6 +665,10 @@ static int closeWindow(lua_State *L) ourGlobals = lua_touserdata(L, -1); lua_pop(L, 1); + // This causes EO to spill lots of meaningless error messages. +// if (bt) +// evas_object_del(bt); + if (ourGlobals->win) evas_object_del(ourGlobals->win); @@ -665,8 +734,10 @@ int luaopen_libGuiLua(lua_State *L) // Define our functions. //thingasm{'window', 'The size and title of the application Frame.', window, 'x,y,name', acl='GGG'} - push_lua(L, "@ ( { = $ $ & $ $acl } )", skang, THINGASM, skang, "window", "Opens our window.", window, "number,number,string", "GGG", 0); - push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "clear", "The current skin is cleared of all widgets", clear, 0); + push_lua(L, "@ ( { = $ $ & $ $acl } )", skang, THINGASM, skang, "Cwindow", "Opens our window.", window, "number,number,string", "GGG", 0); + push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "clear", "The current skin is cleared of all widgets.", clear, 0); + push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "widget", "Create a widget.", widget, 0); + push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "Colour", "Change widget colours.", colour, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "loopWindow", "Run our windows main loop.", loopWindow, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "quit", "Quit, exit, remove thyself.", quit, 0); push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "closeWindow", "Closes our window.", closeWindow, 0); diff --git a/ClientHamr/GuiLua/skang.lua b/ClientHamr/GuiLua/skang.lua index 5796361..6686e4d 100644 --- a/ClientHamr/GuiLua/skang.lua +++ b/ClientHamr/GuiLua/skang.lua @@ -625,7 +625,9 @@ local Thing = if 'nil' == t then if self.required then table.insert(self.errors, mum .. '.' .. name .. ' is required!') end else - if self.types[1] ~= t then table.insert(self.errors, mum .. '.' .. name .. ' should be a ' .. self.types[1] .. ', but it is a ' .. t .. '!') + if 'widget' == self.types[1] then + -- TODO - Should validate any attached Thing. + elseif self.types[1] ~= t then table.insert(self.errors, mum .. '.' .. name .. ' should be a ' .. self.types[1] .. ', but it is a ' .. t .. '!') else if 'number' == t then value = '' .. value end if ('number' == t) or ('string' == t) then @@ -669,7 +671,6 @@ end local Mum = { ---[[ From an email by Mike Pall - __index = function (parent, key) -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. @@ -882,6 +883,16 @@ thingasm = function (names, ...) setmetatable(thingy.default, thisMum) end + if 'widget' == thingy.types[1] then + local args, err = loadstring('return ' .. thingy.widget) + if args then + setfenv(args, parent) + parent.W[name] = {widget = widget(args())} + else + print("ERROR - " .. err) + end + end + -- Remove old names, then stash the Thing under all of it's new names. for i, v in ipairs(oldNames) do metaMum.__self.stuff[v] = nil @@ -891,7 +902,7 @@ thingasm = function (names, ...) end -- This triggers the Mum.__newindex metamethod above. If nothing else, it triggers thingy.isValid() - if new and not metaMum.__self.isKeyed then parent[name] = thingy.default end + if new and not metaMum.__self.isKeyed and ('widget' ~= thingy.types[1]) then parent[name] = thingy.default end end @@ -996,6 +1007,34 @@ thingasm('set', 'Set the current value of an existing Thing or metadata.', set, thingasm('nada', 'Do nothing.', function () --[[ This function intentionally left blank. ]] end) + +-- Widget wrappers. +-- TODO - Fix this up so we don't need .W +local widgets = {} +--thingasm{widgets, 'window', 'The window.', types='userdata'} +thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'} +widgets.W{'look,l', 'The look of the widget.', types='string'} +widgets.W{'colour,color,c', 'The colours of the widget.', types='table'} +widgets.W.c{'red,r', 'The red colour of the widget.', 255, types='number'} +widgets.W.c{'green,g', 'The green colour of the widget.', 255, types='number'} +widgets.W.c{'blue,b', 'The blue colour of the widget.', 255, types='number'} +widgets.W.c{'alpha,a', 'The alpha colour of the widget.', 255, types='number'} +-- At this point we want to change widgets.W.c() to go to a different __call, coz right now it's going to the Mum.__call, which wraps thingasm. +-- TODO - Keep an eye on this if we change to a single Mum, instead of the shallow copy we use now. +local wMum = getmetatable(widgets.W.c) +wMum.__call = function (func, ...) + return Colour(func, ...) +end + +window = function(w, h, title, name) + name = name or 'myWindow' + local win = {} + win.W = copy(widgets.W, name) + win.window = Cwindow(w, h, title, name) + return win +end + + -- TODO - Some function stubs, for now. Fill them up later. skang = function (name) end diff --git a/ClientHamr/GuiLua/test.skang b/ClientHamr/GuiLua/test.skang index ebf5b53..a8ca105 100644 --- a/ClientHamr/GuiLua/test.skang +++ b/ClientHamr/GuiLua/test.skang @@ -6,9 +6,10 @@ -- local other = require 'otherPackageName' skang.clear() -skang.window(500, 500, "G'day planet.") +local win = skang.window(500, 500, "G'day planet.", 'testWindow') ---quitter = skang.widget('button', 'Quit', 0.5, 0.5, 0.5, 0.5) + +skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50', required=true} --quitter:action('quit') -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'. --other.foo = 'stuff' -- cgit v1.1