The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Fun with Akamaru

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Fun with Akamaru Posted: Jan 9, 2007 3:30 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Fun with Akamaru
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

I've been promising a number of people a Cairo update for a little bit now. When I get time, I do little here and there. This may be longish. The short of it: The latest cairo works under real live win32 windows. I translated a fun little C/Gtk app called Akamaru which is a little physics constraint solver to VisualWorks. The longish post is broken down into the following things:

Newest Version of Cairo Graphics Package for VisualWorks

The latest version of the CairoGraphics package, found in the Open Repository is version 22. There are quite a few changes in it:
  • There is now a Win32Surface object. You create one by simply sending Win32Surface window: aScheduledWindow. This is a first cut. It uses the OSSystemSupport classes to fetch the HDC from the Window. I believe that under some contexts, VW assigns a new HDC to a window it manages. I need to get to the bottom of that. Technically, one should be able to put one on a Pixmap just as well. Where are the Xlib and OSX variants? Coming soon (because I hate working on windows).
  • Support for the group APIs. Grouping in cairo basically allows you to temporarily retarget the surface of the context to one that is most optimal for the original surface. You can then pop the group, and it ends up as the source for the original. It's nice for building a temporary drawing set, and then combining at once with the original surface in a uniform way. It's also a free way to do double buffering.
  • Changed the target libraries once again. Edit LibCairo to point at somewhere else. I intend to fix this right, now that I talked Michaell into doing something really very handy for me. To run on Windows, I chose to just install Glade for Windows which seems to be the popular way to get Cairo running on a Windows box.
  • More comments on classes and stuff. Some classes don't have meaningful comments. Did you know you can implement a needsComment message which returns false, so that you don't get the no comment warning triangle. Use it judiciously please.
  • Ability to create or find as appropriate, surfaces or patterns from a handle returned by a library accessor.
  • Constants...

New Approach to Constants

In a previous post, I expressed some frustration with how to express in a "Smalltalk comfortable manner" the many flags and constants that a library like Cairo might have. Boris Popov and I and Michaell Lucas-Smithspoke about this for a while. What we came up with is an approach whereby, we create an empty class which is a name similiar to the original enum type or family of defines. And then we create class side methods which express the contants. All of the Cairo enums have been converted to be this (I wrote a workspace script which traversed all of the CEnumerationTypes and did it automagically; if you're interested I can pass it on).

For example, the Cairo library has a set of enums which define line cap styles:

CAIRO_LINE_CAP_BUTT
CAIRO_LINE_CAP_ROUND
CAIRO_LINE_CAP_SQUARE

These are turned into a CapStyle class which you can send, butt, round, or square to. The fun thing about this is that we can put a fun little {C} browserIcon next to these in the browser.

Akamaru

Once I got the Win32Surface working, I got excited. So I visited the very helpful #cairo channel on irc.freenode.net where I'm often to find Carl Worth and other Cairo gurus. I told them I wanted a fun and simple demo. Something with some animation maybe. The pointed me to Akamaru thing. It's basically a physics constraint solver. It's simple and straightforward. And was fun and pretty easy to port. Allthough, I didn't get it exactly right yet, because I broke something with polygons, but I got it good enough to have fun with Cairo. You can find the initial version (1) in the Open Repository. I put a couple simple models in. And then put a UI around it. And then for grins, I thought it'd be fun to be able to toggle between a cairo rendering and rendering which is as compatible as possible just using good old GraphicsContext stuff. In the following winklet, I'm creating some of the models and dragging them around, switching back and forth between classic and cairo.
Both rendering types are fun to watch the solver do it's job. The molecule is my favorite because it's over constrained, and every time I manage to get it to do something different. To my eye, the Cairo rendering is a long cut above the the classical engine. No jagged edges on either circles or lines. Nicely blended alpha colors. And its just as easy to code it.

What's Next?

  1. Get it working on all 3 main platforms. I hope to grab Pete Hatch for help with Xlib and John Sarkela for help with OS X next week. And then use Michaell's new External-Interface-Pragmas package from the Open Repository.
  2. Robustify of course. One thing I noticed is that if you do a rotate on the context shortly after doing fp math in VW, cairo gets cornfuzzled. Also, window damage events seem to disconnect the Win32Surface sometimes.
  3. Do another fun demo
  4. Start looking at Pango

Read: Fun with Akamaru

Topic: Black tape madness for tidy desks Previous Topic   Next Topic Topic: Continous Integration With Parabuild

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use