-
Notifications
You must be signed in to change notification settings - Fork 0
03. Drag'n'Drop
The main point about drag and drop is that it is a general function that need not be modified by the module developer. That means drag and drop can lie in the C++ part of the engine. The only aspect that may be modified is the appearence of the dragged object. In this example the alpha (transparency) will be given in the Luau part of the engine.
module.luau
setAlpha("0,5")
The exposed C function for setAlpha("0,5") looks like this.
float alpha = 1.0;
static int setAlpha(lua_State *L)
{
if (lua_isstring(L, -1))
{
const char *val = lua_tostring(L, -1);
lua_pop(L, 1);
alpha = atof(val);
}
return 0;
}
Note that
setAlpha("0.5") gave alpha = 0,000000
setAlpha(0,5) with lua_tonumber gave alpha = 5,000000
setAlpha(0.5) did not compile
The decimal separator in Lua (and atof) is locale dependent, see stackoverflow. This is important to be aware of.
The drag and drop test is made with GTK3. I do not know GTK well but it seems to me that GTK have problems with setting z-order, the ordering of GUI elements (widgets) that lie on top of each other.
GtkOverlay has the ability to z-reorder it's children, but can not move it's children.
GtkLayout and GtkFixed have the ability to move their children, but can not z-reorder their children.
GtkOverlay, GtkLayout and GtkFixed are containers but a widget can only belong to one container at a time.
I will have to do a bit more research into the possibility of reordering children in a container. The order of drawing depends on the position of the children.
CPLUS_INCLUDE_PATH=/usr/include/gtk-3.0:/usr/include/glib-2.0:/usr/lib/x86_64-linux-gnu/glib-2.0/include:/usr/include/pango-1.0:/usr/include/harfbuzz:/usr/include/cairo:/usr/include/gdk-pixbuf-2.0:/usr/include/atk-1.0:/usr/include/graphene-1.0:/usr/lib/x86_64-linux-gnu/graphene-1.0/include;export CPLUS_INCLUDE_PATH
LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu;export LD_LIBRARY_PATH
g++ -Wall -o drag-and-drop drag-and-drop.cpp -I/home/me/luau/VM/include -I/home/me/luau/Compiler/include -L/home/me/luau/build/release -lluauvm -lluaucompiler -lluauast -lisocline -lgtk-3 -lgdk-3 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lcairo