/src/wrappers/cairo/examples/simple/cairosimple.e

http://github.com/tybor/Liberty · Specman e · 60 lines · 30 code · 12 blank · 18 comment · 0 complexity · 959c76729b581448aa008da4aca0d21d MD5 · raw file

  1. class CAIROSIMPLE
  2. insert
  3. CAIRO_FORMAT
  4. create {ANY}
  5. make
  6. feature {ANY}
  7. pi: REAL is 3.14159265358979323846 -- PI
  8. make
  9. local
  10. context: CAIRO_CONTEXT
  11. surface: CAIRO_IMAGE_SURFACE
  12. res: INTEGER
  13. do
  14. create surface.make (cairo_format_argb32, 300, 200)
  15. create context.make (surface)
  16. -- First draw something easy, say a redish rectangle
  17. context.set_source_rgb (0.8, 0.2, 0.4)
  18. context.rectangle (10, 10, 40, 80)
  19. context.fill_preserve
  20. context.set_source_rgb (0.4, 0.1, 0.2)
  21. context.stroke
  22. -- Now a semitransparent circle
  23. context.set_source_rgba (0.4, 0.8, 1.0, 0.5) -- alpha 1=opaque, 0=transparent
  24. context.set_line_width (1.0)
  25. context.arc (75, 75, 45, 0, 2 * pi)
  26. context.fill_preserve
  27. context.set_source_rgba (0, 0, 0, 0.5)
  28. context.stroke
  29. -- Finally, write to a PNG file
  30. res := surface.write_to_png ("cairosimple.png")
  31. surface.finish
  32. end
  33. end -- class CAIROSIMPLE
  34. -- Copyright (C) 2010-2017: Paolo Redaelli, 2013 Cyril Adrian
  35. -- This library is free software; you can redistribute it and/or
  36. -- modify it under the terms of the GNU Lesser General Public License
  37. -- as published by the Free Software Foundation; either version 2.1 of
  38. -- the License, or (at your option) any later version.
  39. --
  40. -- This library is distributed in the hope that it will be useful, but
  41. -- WITHOUT ANY WARRANTY; without even the implied warranty of
  42. -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  43. -- Lesser General Public License for more details.
  44. --
  45. -- You should have received a copy of the GNU Lesser General Public
  46. -- License along with this library; if not, write to the Free Software
  47. -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  48. -- 02110-1301 USA