customizing murgaLua


Forum: DSL Tips and Tricks
Topic: customizing murgaLua
started by: mikshaw

Posted by mikshaw on April 08 2008,17:08
A long time ago I was asking about the possibility of customizing the look and behavior of murgaLua without having to modify individual scripts.  I can't seem to find that particular thread, so I'm making  new one (sue me).

There is of course the .Xdefaults file, in which you can set default FLTK scheme, background colors, and forground color, but thats as far as it goes:

! this is really ugly =o)
fltk*scheme:plastic
fltk*background:gray50
Text.background:gray70
fltk*foreground:yellow
fltk*selectBackground:green

This also doesn't help much because you still have to modify the scripts in order to use these resources.

Now that I've started reading < Programming in Lua > I found an answer almost immediately.  By using the LUA_INIT environment variable (exported from .bash_profile, for example), you can specify a file that Lua will run before doing anything else.

So, if you have the file /home/dsl/.murgarc, you can do this:
export LUA_INIT="@$HOME/.murgarc"
before running murgaLua (note the '@').
Whatever Lua commands are in that file will be run.

A simple example:
Code Sample
_PROMPT=os.getenv("USER").."> "
Fl:set_boxtype(fltk.FL_UP_BOX,fltk.FL_THIN_UP_BOX)
Fl:set_boxtype(fltk.FL_DOWN_BOX,fltk.FL_THIN_DOWN_BOX)

Posted by jaapz on April 08 2008,17:47
Very cool! And thanks for the link :)
Posted by roberts on April 25 2008,02:19
Maybe I am thinking of Lua/FLtk, but I recall the fonts available were limited to those in Fltk (C - FLTK Enumerations section of the FLTK manual). Is that true with murgaLua? Can I use LUA_INIT to set and use any X font globally for murgaLua scripts?
Posted by mikshaw on April 25 2008,02:58
I assume so, but lemme check....[long pause]

....well...that's odd.
Apparently you can sort of change the fonts this way, but for some reason no matter what font I try ends up displaying as 'fixed'.
The same line, Fl:set_font(0,"-*-terminus-*"), copied directly into the script shows the correct font.

So...I guess I'll have to look further into that.  But it's bed time now =o(

Posted by mikshaw on April 25 2008,11:21
I just got DSL 4.3, and successfully used LUA_INIT to set the font in murgaLua-0.6.8.  Previous versions display the fixed font only, apparently.

I don't know yet if it's possible to set a font for a particular class, but you can change the built-in constants to whatever X font you desire.

Posted by mikshaw on April 25 2008,13:06
Found a very odd thing while running some tests. I'll need to ask JohnMurga if he knows anything about it...

I tried this script to see what fonts are available:
Code Sample
numfonts=Fl:set_fonts()
for i=0,numfonts do
print(Fl:get_font_name(i)) end

Every font that had been set in LUA_INIT printed what appears to be garbage.
After fooling around a little more I found that using the command Fl:get_font_name(0) in LUA_INIT would cause FL_HELVETICA to print the appropriate name of the font I had set.

However, if I moved that command from LUA_INIT to the script, it didn't work anymore.

So apparently, in order for scripts to retrieve the appropriate font name, you must retrieve in within LUA_INIT, after the font has been set:
Code Sample
Fl:set_font(4,"terminus")
Fl:set_font(0,"smooth")
for i=0,15 do Fl:get_font_name(i) end

I did it for all 16 fonts in one go just so I don't have to bother with it again in the future.

A couple more notes:
Regardless of the above issue, murgaLua 0.6.8 now handles X font names much better than it did before. In the fonts-system demo in the murgaLua demos package the X font names would be rather messy (-*-fixed-medium-r-normal--*, for example). Now it simply uses the name "fixed".  If you attempt to use "-*-terminus-*" now, instead of just "terminus", the result can be a bit unpredictable.

Also, murgaLua *tries* to apply bold/italic using the same custom font, apparently, but if you don't have bold/normal versions of that font installed you also get unpredictible results.  It seems that FLTK just picks something that it thinks resembles what you want.

Posted by roberts on May 05 2008,03:43
Still have not been able to set font system wide for murgaLua scripts.
mikshaw, can you give an example to use, say, 7x14 ?

Posted by roberts on May 05 2008,03:45
When I use the dynamic build of murgaLua, I don't seem to have "plastic" scheme?
Posted by mikshaw on May 05 2008,11:53
According to the fonts.dir file (misc), 7x14 is -misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1

Fl:set_font(0,"-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1")
Fl:set_font(1,"-misc-fixed-bold-r-normal--14-130-75-75-c-70-iso10646-1")

Keep in mind that the font will not scale if you specify an exact font rather than a font face, Fl:set_font(0,"fixed") for example.

I have no idea about the scheme...haven't used the dynamic build.

Posted by roberts on May 05 2008,14:59
Thanks. Yes, it does work in 4.x. I should have tried that first. I was trying dsl v5.x with dynamic murgaLua. Still having issues there.
Posted by mikshaw on May 05 2008,18:19
Another thing about the fonts, which I can't remember for sure if I'd posted here before....
If the dynamic murgaLua uses freetype fonts (I think it does), it won't work with X font names.  You can get the freetype names to use by using Fl:set_fonts() and Fl:get_font_name() as shown above, or use the system fonts script in the murgaLua_demos package to get the font names and a visual preview.

Posted by roberts on May 05 2008,20:48
Great! Got it working in both 4x and 5x.
Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.