GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lua & Clutter/ClutterGtk Toolkit Example (Lua)

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
caracal
GTK+ Guru


Joined: 21 Jun 2007
Posts: 207
Location: Wilkes Barre Pa

PostPosted: Wed Sep 16, 2009 6:18 pm    Post subject: Lua & Clutter/ClutterGtk Toolkit Example (Lua) Reply with quote

Just a quick example on how to use the lgob Clutter/ClutterGtk Bindings
http://oproj.tuxfamily.org/wiki/doku.php?id=lgob

This example is a prototype for a desktop it has been tested and works with
"Metacity, Oroborus" Doesn't work with "xfwm4" <-- Not sure what they did
but the problem is definitely on there end.

Demos "Desktop Background,
Desktop Icons,
Mouse Button 1 2 3,
Up, Down,
Move,
In, Out Events
Icons Popup Menu, and Desktop Popup Menu"
Also demonstrates basic icon effects.

Its missing things like "Click Count, Rubber Band Selection, Drag & Drop, and Event sounds"

The C prototype of this application completely destroys Nautilus Desktop Icons & xfce4-desktop in performance test when using a an nvidia or intel card with hardware accelerated drivers.

I am shooting for kde4 desktop like features.



Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130

#! /usr/bin/env lua

require("lgob.clutter")
require("lgob.cluttergtk")
require("lgob.gtk")
require("lgob.gdk")

cluttergtk.init_once()

s1, s2, s3, s4, s5 = gdk.Window.get_geometry()
print(string.format("(%d, %d)", s3, s4))

function desktop_motion(data, event)
    local x, y = clutter.Event.get_coords(event)
    print(string.format("Stage motion event at (%d, %d)", x, y))
    return true
end

function desktop_event(data, event)
    local x = clutter.ButtonEvent.button(event)
    if x == 1 then
        print("Mouse Button 1 Desktop Click Event")
    elseif x == 2 then
        print("Mouse Button 2 Desktop Click Event")
    elseif x == 3 then
        print("Mouse Button 3 Desktop Click Event")
        local menu = gtk.Menu.new()
        local i1 = gtk.ImageMenuItem.new_from_stock("Desktop Menu")
        menu:add(i1)
        menu:show_all()
        menu:popup(data)
    else
       
print(x)
    end
    return true
end

function icon_event_clicked(data, event)
    local x = clutter.ButtonEvent.button(event)
    local cl = clutter.Event.get_source(event)
    if x == 1 then
        clutter.Actor.set_scale (cl, 0.90, 0.90);
        print("Mouse Button 1 Icon Click Event")
    elseif x == 2 then
        print("Mouse Button 2 Icon Click Event")
    elseif x == 3 then
        print("Mouse Button 3 Icon Click Event")
        local menu = gtk.Menu.new()
        local i1 = gtk.ImageMenuItem.new_from_stock("Icon Menu")
        menu:add(i1)
        menu:show_all()
        menu:popup(data)
    else
       
print(x)
    end
    return true
end

function icon_event_released(data, event)
    local cl = clutter.Event.get_source(event)
    clutter.Actor.set_scale (cl, 1.00, 1.00);
    print("Icon was released")
    return true
end

local win = gtk.Window.new(gtk.WINDOW_TOPLEVEL)
win.set_type_hint(win, 7)
gtk.Window.fullscreen(win)

local vbox = gtk.VBox.new(false, 5)
win:set("title", "Zester Desktop v0.0.1a", "window-position", gtk.WIN_POS_CENTER)
win:connect("delete-event", gtk.main_quit)

local embed = cluttergtk.Embed.new()
embed:set("width-request", s3, "height-request", s4)
vbox:add(embed)
win:add(vbox)

local stage = embed:get_stage()
stage:set_size(s3, s4)
stage:set_color(clutter.color_parse("black"))

-- Add a label actor to the stage
local image = clutter.Texture.new_from_file("wallpaper/background1.jpg")
image:set_size(s3, s4)
image:set_position(0, 0)
stage:add_actor(image)
clutter.Actor.set_reactive(stage, true);
stage:connect("button-press-event", desktop_event)
stage:connect("motion-event", desktop_motion)

group1 = clutter.Group.new()
group1:set_size(48, 48)
group1:set_position(20, 40)
stage:add_actor(group1)
clutter.Actor.set_reactive(group1, true);
group1:connect("button-press-event", icon_event_clicked)
group1:connect("button-release-event", icon_event_released)

-- Add a label actor to the stage
local icon1 = clutter.Texture.new_from_file("icons/user-home.svg")
group1:add_actor(icon1)

-- Add a label actor to the stage
local label1 = clutter.Label.new_full("Sans 8", "Home", clutter.color_parse("white"))
label1:set_position(9.6, 50)
group1:add_actor(label1)

group2 = clutter.Group.new()
group2:set_size(48, 48)
group2:set_position(20, 120)
stage:add_actor(group2)
clutter.Actor.set_reactive(group2, true);
group2:connect("button-press-event", icon_event_clicked)
group2:connect("button-release-event", icon_event_released)

-- Add a label actor to the stage
local icon2 = clutter.Texture.new_from_file("icons/user-trash.svg")
group2:add_actor(icon2)

-- Add a label actor to the stage
local label2 = clutter.Label.new_full("Sans 8", "Trash", clutter.color_parse("white"))
label2:set_position(9.6, 50)
group2:add_actor(label2)

win:show_all()

gtk.main()


You can find the lgob library here.
http://oproj.tuxfamily.org/wiki/doku.php?id=lgob
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP