Thursday, June 23, 2005

Prohibited from using the wagon

Oh, BANDwagon.

Take the MIT Weblog Survey

Tuesday, June 14, 2005

Vellum is a Gnome Canvas Application


I have successfully made the switch from PyGame to Gnome Canvas in Vellum. While it has been by no means seamless, most of my problems were due to misunderstanding how it works, and general unfamiliarity with graphic programming in general and making drawing tools in particular.

Vellum maps now have scrollbars, which I never managed to implement in PyGame because it doesn't have a scrolling concept. It's not really meant for use with a toolkit, so this shouldn't be surprising. With Gnome Canvas, the scrollbars were the source of most of my problems. I was using GTK's Viewport widget, and dropping my Canvas in that to get scrollbars. In short, when it's in a Viewport, Canvas isn't double-buffered and it doesn't get the advantage of its infinite-width scrolling areas. In fact, resizing large scroll areas inside a Viewport is VERY slow. It was only when I realized that Canvas has native support for moving scrollbars around that I threw out the Viewport widget and got the performance that Canvas promises. Now the app is very fast, drawing is double-buffered and graphic operations take place near instantly.

After adding the working scrollbars I gave Vellum two new tools.
  1. There's a Pan tool, selectable by clicking on the hand icon in the toolbar. Pan allows you to drag the map around freely without having to reach for the scrollbars. This gives you finer control over what portion of the map you're looking at. I like Pan tools.
  2. There's a Magnify tool. This works like the magnify tool in Gimp. Click the Zoom button, then click somewhere in the canvas and drag. You get a rectangle which shows you what the inscribed area will be. When you release, the Canvas zooms in and centers on the area you inscribed with your rectangle. This tool will be one of the ones I use the most, as it allows a user to focus on particular aspects of a map or combat.
I will be adding keyboard shortcuts for all these tools in due time. For now I'm going to be taking pride in the fact that I've added a new application area to my repertoire of things I know how to program: Graphic editing applications.

This also represents another minor milestone for Vellum. The GUI actually does something useful. Granted, it's basically a crippled image viewer at this point, but look at it in context. There's now a way for a GM to share a map with his clients: create a .map file and put it in the server. The clients can connect and get that map, which happens automatically after they type in the right address. And everyone can scroll around or zoom to parts of the map that are interesting, which gives them a shared frame of reference for IRC-based games. It's certainly not earth-shattering, but it's something to dogfood.

I promised in my last post to provide more details on how I got Gnome Canvas to compile on Windows. There's really no special magic. If you want to see how it's done:

svn co svn://svn.berlios.de/vellum/sandbox/corydodt/canvas

There's a shell script in there to build libgnomecanvas and another one to build gnomecanvas-bindings. Ignore the libgnomecanvas one, as the binaries are checked into that directory as well (no special magic is required to build the C library runtime, it turns out). README.txt will fill in the rest. You just run the shell script, which invokes the code generator (I know, I didn't write it), compiles the two C files and links them.

Edit: Original post said I switched from "PyGTK", not from "PyGame" which is what I meant.

Monday, June 06, 2005

Gnome Canvas on Win32

Compiled libgnomecanvas and its bindings successfully (no errors or warnings!), ran a demo with it. Have yet to test text rendering or anything moderately complex with it, so cross your fingers. So far, though, lookin' gooood. It's compiled "native" (without Cygwin) so it'll be distributable without Cygwin.

Props to muntyan @ irc.gimp.org for guidance.

Details to come.

Saturday, June 04, 2005

Why Hacks are Bad

So, Pygame in a GTK window is a dead end. It requires the SDL window hack (see vellum/gui/frontend.py for implementation details). This works, with a lot of kludgity, in Python 2.3. I just discovered that it's completely broken again in Python 2.4 if you're on Windows. This, combined with the fundamental problem that you can only have one Pygame window in your program (not "at a time"; ever) makes Pygame a total dead end for Vellum. Maybe I can try to make gnomecanvas bindings compile again. (Sigh of a thousand hurricanes.)