Version 41 of NexTk

Updated 2008-05-30 05:39:54 by GPS

As of Thursday May 29, 2008 NexTk 0.5 has been released!

NexTk is a powerful toolkit written in Tcl. A window system is implemented for NexTk. The window system supports alpha transparency for each window, and rotation of window buffers, with input translation so that events consider the rotation. Every widget is scripted in Tcl, with no C required to write widgets. A unique prototype-based object-oriented system was developed called objstructure for NexTk. Objstructure provides a wealth of features with a simple API. With objstructure you can trace changes to widget option changes, as you would with the trace Tcl command. You can port NexTk to nearly any device (easily) which has a framebuffer, and an input device of some sort. PNG and JPEG support is available in the standard nextksh (a wish-like shell). Freetype is used for rendering antialiased text.

Currently NexTk has been ported to Windows (NT 4 and above), X11. It has run and been tested in Windows XP, Linux, and OpenBSD.

NexTk uses a 3 clause BSD license, in addition to the licensing requirements of zlib, libpng, libjpeg, and freetype.

The sources in .tar.bz2 format:

The sources in .zip format:

A prebuilt nextksh binary with a nextksh.bat that can be used to run the demos:

Some old and simple screenshots:

So, is NexTk a next generation exploration of Tk ? Just trying to understand what it actually is. I don't have a machine available to try the code right now.

It's a next generation implementation of Tk. -GPS

NexTk is available with a massive collection of code here:


Steps to get it running (albeit with a silly demo at the moment):

  1. svn checkout megapkg
  2. cd megapkg
  3. cp build.conf build.conf.whatever
  4. edit build.conf.whatever (you may need to install development packages for Freetype, libpng, libjpeg, X11, Xv, XShm)
  5. tclsh8.5 build.tcl build.conf.whatever unix
  6. tclsh8.5 build.tcl build.conf.whatever NexTk_demo.kit (for historical reasons that doesn't actually generate a starkit. It just copies the build directory contents to NexTk_demo.vfs/lib.
  7. cd NexTk_demo.vfs
  8. sh
  9. sh
  10. wish8.5 main.tcl
  11. Send me patches!

You can also try the NexTk_image_viewer.vfs that uses ntk (it's only a few days old). After running the previous steps do:

  1. cd NexTk_image_viewer.vfs
  2. sh (the script by default copies the Linux build tree, for BSD you'll need to edit it)
  3. tclsh8.5 main.tcl

(Corrected Oct 4, 2007)

George Peter Staplin 2006.07.11 : As the Tcl/Tk core team is taking their time with Tk 8.5, I've been working on my own Tk9 for a few months. (Now named NexTk) It implements a window system using Tcl, and some C extensions from megapkg (megaimage, megaimagetk, structure). It has full support for alpha transparency in any widget. You can rotate windows, and every color in Tk9 consists of [list R G B A].

Features so far include (from megaimage):

  • antialiased line drawing using Wu's algorithm (full RGBA support).
  • portable antialiased text
  • rectangle drawing (full RGBA support)
  • polygon drawing (full RGBA support)
  • window rotation
  • generate buffer rotation
  • scaling
  • arbitrary pixel put/get
  • getrow/putrow
  • and much much more! :)

NEWS George Peter Staplin 2008.05.21 : I rewrote a lot of the grid2 layout code. It should be even better than before, and more consistent, especially with minwidth/minheight windows.

I updated the top of this page with some new NexTk demos I have created. 2 demos even helped shake out some bugs that the shallow test suite hasn't.

I've started work on nextksh. I've been using that today to run the demos.

I wrote a VNC widget for NexTk. It works really well.

I switched to the objstructure C extension. It's similar to the structure extension I was using, but it faster, cleaner, and better overall.

I have worked on the ntk_text widget, and I'm now happy with the data structure. It's using binary format and binary scan to serialize the lists of characters and contexts. The usage of the binary command reduces the memory requirements over a list of lists approach, at the cost of some extra processing time.

The ntk_entry widget has had some work so it does geometry management differently.

The ntk_spinbox does proper geometry requests now.

The input system should now work properly with more than 1 ntk_toplevel.

I've done some work on a few ntkx prefixed commands that are just for X11 and provided by ntk. I used these to embed an xterm, and soon I think I will make an xterm widget for NexTk via these commands.

There have been a lot of minor bug fixes throughout the NexTk_objstructure.vfs tree.

We will soon have a 0.5 release of NexTk. This will mainly be a developer preview, but it should be usable for some things.

George Peter Staplin 2008.04.29 : I have the scale widget working pretty well now. It just needs the -orient vertical finished.

I've done more work on the notebook, but it's still a work-in-progress.

I added a neat feature to the window system rendering. You can use: ntk_render-last toplevel callback to have a callback called whenever an entire toplevel is rendered. And the callback can add another callback. So you can have your own custom drawing routine for the final composited image.

The input system has had several changes for per-toplevel support.

The freetypeext has had some code rewritten. Now there are more commands, and the C interface returns a font descriptor. This allows us to keep the font image open. It has also improved performance and simplified the code a bit. The widgets that use -font now take a font descriptor rather than a font path. This has eliminated the -fontsize. Now you specify the font size when creating the font descriptor.

I fixed up the listbox a bit, and the scrollbar to make them slightly simpler.

The text widget is still a work in progress. It's tough to make a good text widget that doesn't hog memory. I need better data structures I suspect. I was going to use a list of lists of text segments, where each segment would be a list with a context id (for font, color, size, etc.) and the string of text, but that has proven difficult to get right. I have a new idea that may work better.

I have improved the entry widget a lot today. It now has a blinking cursor, and the ability to draw a selection rectangle via dragging the mouse. This was the first time I've created something like that.

I want to get the clipboard/selection code working in, and make the text widget usable.

I started documenting a few of the widgets. NexTk_doc contains documentation for the scrollbar and listbox.

George Peter Staplin 2008.04.11 : I have done a lot of work on ntk.dll. It now uses OpenGL by default for displaying NexTk content. The OpenGL support configurable at runtime, so you can downgrade to a DIB with set ::env(NTK_DISABLE_GL) 1. Ntk.dll is looking much better. I've done a lot of work to make the code more robust.

Many more of the extensions are multiple-interp safe now. This will make thread support easier to add in the future too.

Windows keyboard support is still something I want to focus on. Right now it's disabled, because I had a fault occur with some related path. I think partly because I don't always have standard channels in NexTkKit. It may be fixed now.

Today I made freetypeext support multiple interps. Freetypeext has a slightly different API as of today. It should allow for higher performance, because the struct freetypeext_font and some other information is retained between freetype calls from Tcl. Now you create a freetype font descriptor for use with the freetype command. This also required a flurry of changes to make NexTk work properly after that. I'm so far happier with the design.

megapkg now has a webcam server that is powered by some NexTk extensions, as well as a portable client. The server runs in Linux and uses (a new video4linux2-based extension).

George Peter Staplin 2008.03.17 : We now have a working NexTkKit that can be used to create stand-alone executables. I have created 2 test executables that use NexTkKit.

For Linux:


 $ ldd NexTkKit.bin =>  (0xffffe000) => /usr/lib/ (0xb7ea4000) => /usr/lib/ (0xb7e96000) => /lib/tls/i686/cmov/ (0xb7e6e000) => /lib/tls/i686/cmov/ (0xb7d2d000) => /lib/tls/i686/cmov/ (0xb7d29000) => /usr/lib/ (0xb7d26000) => /usr/lib/ (0xb7d21000)
 /lib/ (0xb7fb3000)

For Windows NT 4 or greater:

I have added a new feature to ntk for retrieving the total number of toplevel windows. The Win32 version feels slower than X11, because of the ntk-put-image path I think. It could use some loop unrolling, and especially profiling. The X11 version operates on 4 pixels per loop iteration, whereas the Win32 version does 1. I wanted to make it work, and then make it fast. I did the same thing with the original X11 version.

The tickmakefile is going to need some thought to work with NexTkKit properly.

escargo - The current version of Nagelfar has some profiling code in it. If you preprocess your Tcl code, run it, and do an appropriate shutdown, you can move a log file back and see what code executed (code coverage). In addition, the log file shows how many times statements executed. This is good for finding program hot spots.

George Peter Staplin 2008.03.13 : The code has been cleaned up a lot in many areas.

The grid.img was partially rewritten, and is now running as grid2.img. The grid manager has had a lot of work done on it. I have written tests for the grid engine as well, beyond just the demo programs. I added geometry propagation that can be disabled in a parent widget with the _propagate_geometry variable in a window structure. I'll probably eventually add a proc to set/unset the propagation.

The segfault upon exit with Win32 ntk is now fixed.

The usability in Win32 has improved a lot. I still need to work on keyboards events for Win32. The TODO files have more.

See also:

George Peter Staplin 2007.11.23 : The ntk extension now runs in Win32 properly (for the most part). I've fixed many bugs and polished things a lot more. The selection code for Win32 and X is what I plan to focus on soon, after I get the configure callback for the ntk system/toplevel windows delivered properly, so that the toplevels resize.

New widgets or widgets in progress include: ntk_notebook, and ntk_scale.

The entry widget is a little broken at the moment. I plan to focus on text input, and the text widget soon.

I've improved the speed of the blending algorithm again, as well as the image dithering. I made several attempts to rewrite the alpha blending with SSE, but so far those have turned out slower than the code generated by gcc.

apw continues his great work on itcl-ng and ntkWidget. He's been working a lot on the OpenGL backend.

George Peter Staplin 2007.11.06 : The NexTk_image_viewer now uses the ntk_panedwindow widget. The panedwindow widget is new and supports -orient horizontal and vertical. The scrollbar has had a lot of polishing done.

Some other new widgets are ntk_checkbox and ntk_spinbox. They are pretty much complete, and work well.

The text widget is now using some ideas from Zarutian. He suggested separating the data from the metadata. I think it's cleaner this way, and much easier to program. I'm slowly improving the text widget, as its design evolves.

I took input from KBK on the listbox widget, and added a 3D appearance to the listbox. I updated the image viewer screenshot below.

I found a way to reduce the memory requirements by almost a third, by reducing the temporary buffers used in rendertree.tcl. One thing to keep in mind is that NexTk in combination with ntk keeps most of the buffers that Tk would use, on the client side. It may seem at times like NexTk is using more memory than a typical app, but that's because, Pixmap and Window buffers in X11 are stored on the server side with most toolkits.

I have some ideas for improving the speed of tclTimer.c that will probably be implemented soon and I hope make it into 8.6.

apw is working a lot on ntkWidget. I've tried some of his demos, and they work. He's been spending a lot of time on OpenGL ideas. He has taken a thing called GLFW and added multiple window support, and other features, to enable working with megaimages. Based on what we've talked about FBOs or frame buffer objects are in the future. He also wrote a cool script for his tclGL that translates the OpenGL API from header files to Tcl commands.

I'm also working occasionally on glimage, which is meant to have a higher level API and not look so much like OpenGL.

Slow, but steady progress. I'm not going to burn out.

Here's a screenshot of NexTk's panedwindow, checkbutton, button, label, and spinbox:

George Peter Staplin 2007.10.16 : Well, we now have the NexTk image viewer working quite well. It views JPEG and PNG images, and supports drag scrolling of large images.

The listbox has had a lot of changes, as well as the scrollbar since the last update. I've also been working a lot on ntk. The ntk_listbox and ntk_scrollbar now do proper scrolling in all of the cases of the image viewer. Left to add are page-relative scrolling (if desired), I'm still not sure. We also need to theme the scrollbar sliders. At the moment they are just rectangles.

apw has been doing a lot of work on his version of NexTk based on mine. We're working together to improve the future Tks.

I've been also working on megaimage3d, and structure. I made ntk display its first window in NT 4, and it works in XP as well. The Over and Out game has been reimplemented. It's now much cleaner/simpler.

Here's a screenshot of the image viewer:


I'm looking forward to this when I get one of them thar' round toits.

KJN 2007.09.20 : Are the Enlightenment E17 libraries of any use? They are BSD licensed, and do 2D graphics with transparency and animation. The Enlightenment live CD has some good demos, but the best item is not switched on by default (you have to search for it) - an animated taskbar like the one in OS X.

George Peter Staplin 2007.09.20 : Hi KJN, are the Enlightenment libraries portable? I've been working the last week or 2 on a new Tcl extension called ntk in megapkg. It provides Win32, X11, and hopefully in the future Mac OS X compatibility. More on ntk below (under NEWS).

KJN 2007.09.20 : I'm no expert, but the Evas (Enlightenment Canvas) has several "engines" (backends). Recent CVS commits [L1 ] have these log entries:

  • "Glew OpenGL engine added. Windows can have an opengl engine thgough the Glew library, now. See INSTALL note" (the note refers to the Glew library and compilation with MinGW)
  • "Direct3D engine. I'm not an expert of that api, so there should room for lots of improvements"
  • "added per-engine pc files" - as well as Glew and Direct3D, the engines include SDL and ddraw. The engines are in [L2 ] and also include win32_gdi.

I haven't tried to build and run Evas with any of these engines, so I don't know how complete they are - but it is clear that the project is actively developing backends for several different platforms.

How on earth do you get this thing running on Win2k?

That's a good question. I've never actually tried to build in Windows (I use a MinGW cross compiler)... :) -GPS