~ubuntu-branches/ubuntu/natty/lua-gtk/natty

« back to all changes in this revision

Viewing changes to examples/pixmap.lua

  • Committer: Bazaar Package Importer
  • Author(s): Enrico Tassi
  • Date: 2009-05-17 18:16:21 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090517181621-9kmdd82nxg54jsio
* new upstream snapshot comprising many more GNOME libraries:
    Gtk, GDK, GLib, Pango, Atk, Libxml2, Cairo, Clutter, Gtkhtml, 
    GtkSourceView, Gio, Gtkspell and GConf. 
* new upstream release includes a new configure script written in Lua,
  no more bashisms there (Closes: #507205)
* renamed binary packages to liblua5.1-gnome-*
* updated standards-version to 3.8.1, no changes needed
* patch to load .so.* version of libraries and not .so (that was requiring
  -dev packages) (Closes: #522087)
* removed redundant Architecture line from the source stanza of control
  (Closes: #498120)
* updated copyright file, Wolfgang Oertl holds it for 2009 too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
-- vim:sw=4:sts=4
3
3
 
4
4
require "gtk"
 
5
require "pango"
 
6
 
 
7
gnome.set_debug_flags "memory"
5
8
 
6
9
win_count = 0
7
10
 
8
11
function mywin_new(msg)
9
12
    local self = { pixmap=nil, msg=msg }
10
 
    self.win = gtk.window_new(gtk.GTK_WINDOW_TOPLEVEL)
 
13
    self.win = gtk.window_new(gtk.WINDOW_TOPLEVEL)
11
14
    self.win:connect('destroy', on_destroy, self)
12
15
    self.win:set_title('Pixmap Test')
13
16
    local da = gtk.drawing_area_new()
32
35
--
33
36
function on_configure(da, ev, ifo)
34
37
    local window = ifo.win.window
 
38
    -- print("WINDOW", window)
 
39
    -- gnome.breakfunc()
35
40
    local width, height = window:get_size(0, 0)
 
41
    -- print("WIDTH, HEIGHT", width, height)
 
42
    assert(width)
 
43
    assert(height)
 
44
 
 
45
    if ifo.pixmap then
 
46
        -- mostly seems to work.  maybe check some more
 
47
        gnome.destroy(ifo.pixmap)
 
48
    end
36
49
 
37
50
    -- allocates memory in X server... default drawable, width, height, depth
38
51
    -- loses the reference to the previous pixmap, if any.
39
 
    ifo.pixmap = gtk.gdk_pixmap_new(window, width, height, -1)
 
52
    ifo.pixmap = gdk.pixmap_new(window, width, height, -1)
40
53
 
41
54
    local style = ifo.win:get_style()
42
55
    local white_gc = style.white_gc
58
71
 
59
72
    -- get size of message
60
73
    local region = layout:get_clip_region(0, 0, {0, string.len(message)}, 1)
61
 
    local rect = gtk.new("GdkRectangle")
 
74
    local rect = gdk.new "Rectangle"
62
75
    region:get_clipbox(rect)
63
76
    if rect.width > 0 then
64
77
        ifo.pixmap:draw_layout(black_gc, width - 15 - rect.width,
67
80
 
68
81
    -- Make sure that the unreferenced pixmap is freed NOW and not eventually,
69
82
    -- because this can eat up loads of memory of the X server.
70
 
    collectgarbage()
71
 
    collectgarbage()
 
83
    -- collectgarbage()
 
84
    -- collectgarbage()
72
85
 
73
86
    return true
74
87
end
86
99
    local window = da.window
87
100
    local style = ifo.win:get_style()
88
101
    local white_gc = style.white_gc
89
 
    gtk.gdk_draw_drawable(window, white_gc, ifo.pixmap, x, y, x, y, w, h)
 
102
    gdk.draw_drawable(window, white_gc, ifo.pixmap, x, y, x, y, w, h)
90
103
    return false
91
104
end
92
105
 
 
106
-- gnome.set_debug_flags("memory")
93
107
mywin1 = mywin_new("One")
94
108
mywin2 = mywin_new("Two")
95
109
gtk.main()
102
115
    collectgarbage("collect")
103
116
    collectgarbage("collect")
104
117
    collectgarbage("collect")
105
 
    gtk.dump_memory()
 
118
    gnome.dump_memory()
106
119
end
107
120
 
108
 
gtk.g_mem_profile()
 
121
glib.mem_profile()
109
122