lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Thanks for the heads up.

Would you consider adopting an object-like interface, instead of the C- like you currently use? This is the #1 issue keeping me away from LuaCairo and using others (oocairo).

The Cairo C++ API (cairomm) could be used as a reference API. It is as official as the C API is.

Your current sample (now and "then"):

-- taken from http://luaforge.net/projects/luacairo/
--
local cairo = require"lcairo"
local CAIRO = cairo

local w = 320
local h = 240
local outfile = "cairo_test2.png"
local cs = cairo.image_surface_create(CAIRO.FORMAT_RGB24, w, h)
local cr = cairo.create(cs)

cairo.set_source_rgb(cr, 1, 1, 1)
cairo.paint(cr)

cairo.set_source_rgb(cr, 0, 0, 0)
cairo.select_font_face(cr, "Sans", CAIRO.FONT_SLANT_NORMAL, CAIRO.FONT_WEIGHT_BOLD)
cairo.set_font_size(cr, w/6)
cairo.move_to(cr, 0, h/4)
cairo.show_text(cr, "Hello cairo!")

cairo.select_font_face(cr, "Sans", CAIRO.FONT_SLANT_NORMAL, CAIRO.FONT_WEIGHT_NORMAL)
cairo.set_font_size(cr, w/8)
cairo.move_to(cr, 0, 3*h/4)
cairo.text_path (cr, "Lua calling...")
cairo.set_source_rgb (cr, 0.5, 0.5, 1)
cairo.fill_preserve (cr)
cairo.set_source_rgb (cr, 0, 0, 0)
cairo.set_line_width (cr, w/200)
cairo.stroke (cr)

cairo.surface_write_to_png(cs, outfile)

With cairomm like API:

-- taken from http://luaforge.net/projects/luacairo/
--
local cairo = require"lcairo"
local CAIRO = cairo

local w = 320
local h = 240
local outfile = "cairo_test2.png"
local cs = cairo.image_surface_create(CAIRO.FORMAT_RGB24, w, h)
local cr = cairo.create(cs)

cr:set_source_rgb(1, 1, 1)
cr:paint()

cr:set_source_rgb(0, 0, 0)
cr:select_font_face("Sans", CAIRO.FONT_SLANT_NORMAL, CAIRO.FONT_WEIGHT_BOLD)
cr:set_font_size(w/6)
cr:move_to(0, h/4)
cr:show_text("Hello cairo!")

cr:select_font_face("Sans", CAIRO.FONT_SLANT_NORMAL, CAIRO.FONT_WEIGHT_NORMAL)
cr:set_font_size(w/8)
cr:move_to(0, 3*h/4)
cr:text_path("Lua calling...")
cr:set_source_rgb(0.5, 0.5, 1)
cr:fill_preserve()
cr:set_source_rgb(0, 0, 0)
cr:set_line_width(w/200)
cr:stroke()

cs:write_to_png(outfile)

Hakki Dogusan kirjoitti 17.11.2008 kello 10:13:

Hi,


http://www.dynaset.org/dogusanh/

LuaCairo (1.8.4.0):
A Lua binding of Cairo graphics library.
   * Adapted to Cairo-1.8.4
   * Adapted to Lua-5.1.4


CairoPad (0.83):
An application using above binding.
Written to study Cairo.
   * Adapted to Cairo-1.8.4
   * Adapted to Lua-5.1.4
   * Adapted to wxWidgets-2.8.9
* Periodic refresh implementation changed to allow to use user defined timer interval
   * An animation sample added (translated from http://www.zetcode.com/tutorials/cairographicstutorial/transformations/)


--
Regards,
Hakki Dogusan