/src/wrappers/gtk/examples/style/style_demo.e

http://github.com/tybor/Liberty · Specman e · 114 lines · 58 code · 27 blank · 29 comment · 0 complexity · 372acc9fca4ed7e1d603f171024f9649 MD5 · raw file

  1. class STYLE_DEMO
  2. insert
  3. ANY
  4. GTK
  5. GTK_STATE_TYPE
  6. PANGO_CONSTANTS
  7. PANGO_WRAP_MODE
  8. creation
  9. make
  10. feature
  11. on_delete_event (a_gtk_object: GTK_OBJECT) is
  12. do
  13. gtk.quit
  14. end
  15. make is
  16. local
  17. style: GTK_STYLE
  18. pixbuf: GDK_PIXBUF
  19. pixmap: GDK_PIXMAP
  20. gc: GDK_GC
  21. color: GDK_COLOR
  22. layout: PANGO_LAYOUT
  23. msg, font, fgcolor: STRING
  24. size: TUPLE [INTEGER, INTEGER]
  25. live_width, live_height: INTEGER
  26. scale: REAL
  27. do
  28. gtk.initialize
  29. create window.make
  30. window.set_default_size (280, 190)
  31. window.connect_agent_to_destroy_signal (agent on_delete_event)
  32. create label.with_label ("Hello World!")
  33. window.set_border_width (20)
  34. window.add (label)
  35. window.show_all
  36. style := window.style
  37. create pixbuf.from_file("cartman.png")
  38. pixmap := pixbuf.render_pixmap_and_mask (0).first
  39. create gc.make (pixmap)
  40. pixmap.draw_line (gc, 5, 10, 10, 30)
  41. create color.make
  42. color.set_red (65535)
  43. gc.set_rgb_fg_color (color)
  44. pixmap.draw_rectangle (gc, False, 35, 9, 10, 5)
  45. color.set_green (5535)
  46. color.set_red (5535)
  47. gc.set_rgb_fg_color (color)
  48. pixmap.draw_point (gc, 0, 0)
  49. pixmap.draw_arc (gc, False, 5, 38, 38, 10, 0, 11520)
  50. live_width := 1024
  51. live_height := 768
  52. msg := "Arrepentidos ahora que estais a tiempo, hijos de Hebron"
  53. font := "Arial 12 Bold"
  54. fgcolor := "#ff0000"
  55. layout := window.create_pango_layout ("")
  56. layout.set_width (live_width)
  57. layout.set_wrap (pango_wrap_word_char)
  58. layout.set_markup ("<span foreground='" + fgcolor + "' font_desc='" + font + "'>" + msg + "</span>")
  59. size := layout.size
  60. create pixbuf.make (True, size.first // pango_scale, size.second // pango_scale)
  61. --pixbuf.fill (0)
  62. pixmap := pixbuf.render_pixmap_and_mask (0).first
  63. pixmap.draw_layout (gc, 0, 0, layout)
  64. create pixbuf.from_drawable (pixmap, 0, 0, pixmap.width, pixmap.height)
  65. scale := (pixbuf.width * 100) / live_width -- Esto no funciona si el layout es m??s apaisado que el viewer
  66. -- previewer.set_overlay (pixbuf, scale, 50, 50)
  67. style.set_background_pixmap (pixmap, gtk_state_normal)
  68. gtk.run_main_loop
  69. end
  70. window: GTK_WINDOW
  71. label: GTK_LABEL
  72. end -- class STYLE_DEMO