The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Seaside-CairoGraphics

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
Seaside-CairoGraphics Posted: Dec 16, 2007 10:08 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Seaside-CairoGraphics
Feed Title: Michael Lucas-Smith
Feed URL: http://www.michaellucassmith.com/site.atom
Feed Description: Smalltalk and my misinterpretations of life
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Michael Lucas-Smith

Advertisement

Whenever I sit down to do a website, I want to make it look good. I have a strong grasp on white space, design concepts, CSS, HTML and graphics design in general. But one thing I am not, is an artist.

With today's modern websites, lots of shadows and gradients are needed at different sizes and colours. I get fed up constantly tweaking my graphical layers and exporting - after listening to Ken Treis's success using CairoGraphics as a backend PNG generator for his Seaside websites, I decided to hook CairoGraphics in as a WAFileLibrary subclass.

You can load up Seaside-CairoGraphics which prereqs in Seaside and CairoGraphics. You'll need the CairoGraphics libraries setup on your machine for this to work. You then subclass CairoGraphicsLibrary which is a subclass of WAFileLibrary.

Your subclass can now generate (and cache) PNGs from Smalltalk code using a CairoGraphics render context. You set up resources like so:

headerShadow: cr
	<resource: 'afterHeader.png' width: 800 height: 16>
	<scale>
	cr source:
		((RadialGradient from: 0.5@0 radius: 0 to: 0.5@0 radius: 0.5)
			addStopAt: 0 colorValue: (ColorValue hex: 16r777777);
			addStopAt: 1 colorValue: ColorValue white;
			yourself).
	cr paint

This generate a nice shadow radial gradient as an 'under a visual lip' effect. Notice the pragmas. The first pragma <resource> tells us that we can be read from the internet and what the images extent will be - in this case 800x16.

The second pragma is special, <scale> will automatically scale the cairo context by the specified width@height so that your rendering area is between 0@0 .. 1@1 - this is quite common for many kinds of gradients and it means you don't have to hard code the width/height in to your rendering code. This <scale> pragma is optional.

You can also load up Pango from public store and use it with this library too to render high quality blended fonts.

The caching mechanism will keep the PNGs it generates in memory as bytes and release when you modify any method on your class.

Read: Seaside-CairoGraphics

Topic: Read the fine Print Previous Topic   Next Topic Topic: For the (Board) Gamer you know

Sponsored Links



Google
  Web Artima.com   

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