aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ClientHamr
diff options
context:
space:
mode:
authorDavid Walter Seikel2014-04-18 18:39:38 +1000
committerDavid Walter Seikel2014-04-18 18:39:38 +1000
commitfc03f11c0e59515d4b467f8288f5dc7b962ec0bc (patch)
tree2df1e3381e9a3cd92afb9ab4a59afa12529d475c /ClientHamr
parentNot sure why I had parent in there, it's not used anywhere. (diff)
downloadSledjHamr-fc03f11c0e59515d4b467f8288f5dc7b962ec0bc.zip
SledjHamr-fc03f11c0e59515d4b467f8288f5dc7b962ec0bc.tar.gz
SledjHamr-fc03f11c0e59515d4b467f8288f5dc7b962ec0bc.tar.bz2
SledjHamr-fc03f11c0e59515d4b467f8288f5dc7b962ec0bc.tar.xz
Half arsed window and button implementation.
Diffstat (limited to 'ClientHamr')
-rw-r--r--ClientHamr/GuiLua/GuiLua.c89
-rw-r--r--ClientHamr/GuiLua/skang.lua45
-rw-r--r--ClientHamr/GuiLua/test.skang5
3 files changed, 125 insertions, 14 deletions
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)
216 eina_log_level_set(EINA_LOG_LEVEL_DBG); 216 eina_log_level_set(EINA_LOG_LEVEL_DBG);
217 eina_log_domain_level_set("GuiLua", EINA_LOG_LEVEL_DBG); 217 eina_log_domain_level_set("GuiLua", EINA_LOG_LEVEL_DBG);
218 eina_log_print_cb_set(_ggg_log_print_cb, stderr); 218 eina_log_print_cb_set(_ggg_log_print_cb, stderr);
219
220 // Shut up the excess debugging shit from EFL.
221 eina_log_domain_level_set("ecore_input_evas", EINA_LOG_LEVEL_WARN);
219} 222}
220 223
221char *getDateTime(struct tm **nowOut, char *dateOut, time_t *timeOut) 224char *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
527{ 530{
528// globals *ourGlobals = data; 531// globals *ourGlobals = data;
529 532
530// TODO - skang.quit() should do this to.
531 // Tell the main loop to stop, which it will, eventually. 533 // Tell the main loop to stop, which it will, eventually.
532 elm_exit(); 534 elm_exit();
533} 535}
534 536
537
538struct widget
539{
540 Evas_Object *widget;
541 char *label, *look, *action, *help;
542 // foreground / background colour
543 // thing
544 // types {}
545 // skangCoord x, y, w, h
546};
547
548/* Sooo, how to do this -
549
550widget has to be a light userdata
551The rest can be Lua sub things? Each with a C function to update the widget.
552
553win.quitter.look
554
555win.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)
556win.quitter.colour.r = 5 -> direct access to the table, well "direct" via Thing and Mum. We eventually want to call skang.colour() though.
557
558*/
559
560static int widget(lua_State *L)
561{
562 globals *ourGlobals;
563 Evas_Object *bt;
564 char *type = "label";
565 char *title = ":";
566 int x = 1, y = 1, w = WIDTH/3, h = HEIGHT/3;
567
568 lua_getfield(L, LUA_REGISTRYINDEX, globName);
569 ourGlobals = lua_touserdata(L, -1);
570 lua_pop(L, 1);
571
572 pull_lua(L, 1, "$type $title %x %y %w %h", &type, &title, &x, &y, &w, &h);
573
574 // Poor mans introspection, until I write real introspection into EFL.
575 if (strcmp(type, "button") == 0)
576 {
577 bt = elm_button_add(ourGlobals->win);
578 elm_object_text_set(bt, title);
579 evas_object_smart_callback_add(bt, "clicked", _on_done, ourGlobals);
580 evas_object_resize(bt, w, h);
581 evas_object_move(bt, x, y);
582 evas_object_show(bt);
583 lua_pushlightuserdata(L, &bt);
584 return 1;
585 }
586
587 return 0;
588}
589
590static int colour(lua_State *L)
591{
592// TODO - This is just a stub for now.
593
594 return 0;
595}
596
597
535static int window(lua_State *L) 598static int window(lua_State *L)
536{ 599{
537 globals *ourGlobals; 600 globals *ourGlobals;
538 char *title = NULL; 601 char *name = "GuiLua";
602 char *title = "GuiLua test harness";
539 int w = WIDTH, h = HEIGHT; 603 int w = WIDTH, h = HEIGHT;
540 604
541 lua_getfield(L, LUA_REGISTRYINDEX, globName); 605 lua_getfield(L, LUA_REGISTRYINDEX, globName);
542 ourGlobals = lua_touserdata(L, -1); 606 ourGlobals = lua_touserdata(L, -1);
543 lua_pop(L, 1); 607 lua_pop(L, 1);
544 608
545 if (pull_lua(L, 1, "%w %h $title", &w, &h, &title) > 0) 609 pull_lua(L, 1, "%w %h $title $name", &w, &h, &title, &name);
546 PI("Setting window to %d %d %s", w, h, title); 610 PI("Setting window to %d %d %s", w, h, title);
547 else
548 title = "GuiLua test harness";
549 611
550 if ((ourGlobals->win = elm_win_util_standard_add("GuiLua", title))) 612 if ((ourGlobals->win = elm_win_util_standard_add(name, title)))
551 { 613 {
552 evas_object_smart_callback_add(ourGlobals->win, "delete,request", _on_done, ourGlobals); 614 evas_object_smart_callback_add(ourGlobals->win, "delete,request", _on_done, ourGlobals);
553 evas_object_resize(ourGlobals->win, w, h); 615 evas_object_resize(ourGlobals->win, w, h);
554 evas_object_move(ourGlobals->win, 0, 0); 616 evas_object_move(ourGlobals->win, 0, 0);
555 evas_object_show(ourGlobals->win); 617 evas_object_show(ourGlobals->win);
618
619 lua_pushlightuserdata(L, &ourGlobals->win);
620 return 1;
556 } 621 }
557 622
558 return 0; 623 return 0;
@@ -600,6 +665,10 @@ static int closeWindow(lua_State *L)
600 ourGlobals = lua_touserdata(L, -1); 665 ourGlobals = lua_touserdata(L, -1);
601 lua_pop(L, 1); 666 lua_pop(L, 1);
602 667
668 // This causes EO to spill lots of meaningless error messages.
669// if (bt)
670// evas_object_del(bt);
671
603 if (ourGlobals->win) 672 if (ourGlobals->win)
604 evas_object_del(ourGlobals->win); 673 evas_object_del(ourGlobals->win);
605 674
@@ -665,8 +734,10 @@ int luaopen_libGuiLua(lua_State *L)
665 734
666 // Define our functions. 735 // Define our functions.
667//thingasm{'window', 'The size and title of the application Frame.', window, 'x,y,name', acl='GGG'} 736//thingasm{'window', 'The size and title of the application Frame.', window, 'x,y,name', acl='GGG'}
668 push_lua(L, "@ ( { = $ $ & $ $acl } )", skang, THINGASM, skang, "window", "Opens our window.", window, "number,number,string", "GGG", 0); 737 push_lua(L, "@ ( { = $ $ & $ $acl } )", skang, THINGASM, skang, "Cwindow", "Opens our window.", window, "number,number,string", "GGG", 0);
669 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "clear", "The current skin is cleared of all widgets", clear, 0); 738 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "clear", "The current skin is cleared of all widgets.", clear, 0);
739 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "widget", "Create a widget.", widget, 0);
740 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "Colour", "Change widget colours.", colour, 0);
670 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "loopWindow", "Run our windows main loop.", loopWindow, 0); 741 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "loopWindow", "Run our windows main loop.", loopWindow, 0);
671 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "quit", "Quit, exit, remove thyself.", quit, 0); 742 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "quit", "Quit, exit, remove thyself.", quit, 0);
672 push_lua(L, "@ ( = $ $ & )", skang, THINGASM, skang, "closeWindow", "Closes our window.", closeWindow, 0); 743 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 =
625 if 'nil' == t then 625 if 'nil' == t then
626 if self.required then table.insert(self.errors, mum .. '.' .. name .. ' is required!') end 626 if self.required then table.insert(self.errors, mum .. '.' .. name .. ' is required!') end
627 else 627 else
628 if self.types[1] ~= t then table.insert(self.errors, mum .. '.' .. name .. ' should be a ' .. self.types[1] .. ', but it is a ' .. t .. '!') 628 if 'widget' == self.types[1] then
629 -- TODO - Should validate any attached Thing.
630 elseif self.types[1] ~= t then table.insert(self.errors, mum .. '.' .. name .. ' should be a ' .. self.types[1] .. ', but it is a ' .. t .. '!')
629 else 631 else
630 if 'number' == t then value = '' .. value end 632 if 'number' == t then value = '' .. value end
631 if ('number' == t) or ('string' == t) then 633 if ('number' == t) or ('string' == t) then
@@ -669,7 +671,6 @@ end
669 671
670local Mum = 672local Mum =
671{ 673{
672--[[ From an email by Mike Pall -
673 674
674__index = function (parent, key) 675__index = function (parent, key)
675 -- This only works for keys that don't exist. By definition a value of nil means it doesn't exist. 676 -- 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, ...)
882 setmetatable(thingy.default, thisMum) 883 setmetatable(thingy.default, thisMum)
883 end 884 end
884 885
886 if 'widget' == thingy.types[1] then
887 local args, err = loadstring('return ' .. thingy.widget)
888 if args then
889 setfenv(args, parent)
890 parent.W[name] = {widget = widget(args())}
891 else
892 print("ERROR - " .. err)
893 end
894 end
895
885 -- Remove old names, then stash the Thing under all of it's new names. 896 -- Remove old names, then stash the Thing under all of it's new names.
886 for i, v in ipairs(oldNames) do 897 for i, v in ipairs(oldNames) do
887 metaMum.__self.stuff[v] = nil 898 metaMum.__self.stuff[v] = nil
@@ -891,7 +902,7 @@ thingasm = function (names, ...)
891 end 902 end
892 903
893 -- This triggers the Mum.__newindex metamethod above. If nothing else, it triggers thingy.isValid() 904 -- This triggers the Mum.__newindex metamethod above. If nothing else, it triggers thingy.isValid()
894 if new and not metaMum.__self.isKeyed then parent[name] = thingy.default end 905 if new and not metaMum.__self.isKeyed and ('widget' ~= thingy.types[1]) then parent[name] = thingy.default end
895end 906end
896 907
897 908
@@ -996,6 +1007,34 @@ thingasm('set', 'Set the current value of an existing Thing or metadata.', set,
996thingasm('nada', 'Do nothing.', function () --[[ This function intentionally left blank. ]] end) 1007thingasm('nada', 'Do nothing.', function () --[[ This function intentionally left blank. ]] end)
997 1008
998 1009
1010
1011-- Widget wrappers.
1012-- TODO - Fix this up so we don't need .W
1013local widgets = {}
1014--thingasm{widgets, 'window', 'The window.', types='userdata'}
1015thingasm{widgets, 'W', 'Holds all the widgets', types='Keyed'}
1016widgets.W{'look,l', 'The look of the widget.', types='string'}
1017widgets.W{'colour,color,c', 'The colours of the widget.', types='table'}
1018widgets.W.c{'red,r', 'The red colour of the widget.', 255, types='number'}
1019widgets.W.c{'green,g', 'The green colour of the widget.', 255, types='number'}
1020widgets.W.c{'blue,b', 'The blue colour of the widget.', 255, types='number'}
1021widgets.W.c{'alpha,a', 'The alpha colour of the widget.', 255, types='number'}
1022-- 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.
1023-- TODO - Keep an eye on this if we change to a single Mum, instead of the shallow copy we use now.
1024local wMum = getmetatable(widgets.W.c)
1025wMum.__call = function (func, ...)
1026 return Colour(func, ...)
1027end
1028
1029window = function(w, h, title, name)
1030 name = name or 'myWindow'
1031 local win = {}
1032 win.W = copy(widgets.W, name)
1033 win.window = Cwindow(w, h, title, name)
1034 return win
1035end
1036
1037
999-- TODO - Some function stubs, for now. Fill them up later. 1038-- TODO - Some function stubs, for now. Fill them up later.
1000skang = function (name) 1039skang = function (name)
1001end 1040end
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 @@
6-- local other = require 'otherPackageName' 6-- local other = require 'otherPackageName'
7 7
8skang.clear() 8skang.clear()
9skang.window(500, 500, "G'day planet.") 9local win = skang.window(500, 500, "G'day planet.", 'testWindow')
10 10
11--quitter = skang.widget('button', 'Quit', 0.5, 0.5, 0.5, 0.5) 11
12skang.thingasm{win, 'quitter', 'Quits the skang window', types = 'widget', widget='"button", "Quit", 10, 10, 100, 50', required=true}
12--quitter:action('quit') -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'. 13--quitter:action('quit') -- 'quit' is looked up in ThingSpace.commands, and translated into the Lua 'skang.quit()'.
13 14
14--other.foo = 'stuff' 15--other.foo = 'stuff'