seed r139 - trunk/examples
- From: hortont svn gnome org
- To: svn-commits-list gnome org
- Subject: seed r139 - trunk/examples
- Date: Thu, 6 Nov 2008 07:17:03 +0000 (UTC)
Author: hortont
Date: Thu Nov 6 07:17:03 2008
New Revision: 139
URL: http://svn.gnome.org/viewvc/seed?rev=139&view=rev
Log:
Update pango example.
Modified:
trunk/examples/pango.js
Modified: trunk/examples/pango.js
==============================================================================
--- trunk/examples/pango.js (original)
+++ trunk/examples/pango.js Thu Nov 6 07:17:03 2008
@@ -3,15 +3,21 @@
Seed.import_namespace("Clutter");
Seed.import_namespace("Gtk");
Seed.import_namespace("GtkClutter");
+Seed.import_namespace("Pango");
+
+var current_actor;
Gtk.init(null, null);
GtkClutter.init(null, null);
-var current_text;
-
function update_text(entry)
{
- current_text.text = entry.text;
+ current_actor.text = entry.text;
+}
+
+function add_actor()
+{
+ new pango_actor("Oh hi!", "Bitstream Vera Serif 28");
}
function prop_editor()
@@ -19,38 +25,131 @@
this.text = new Gtk.Entry();
this.text.signal_changed.connect(update_text);
+ this.new_button = new Gtk.ToolButton({stock_id:"gtk-add"});
+ this.new_button.signal_clicked.connect(add_actor);
+
+ this.font_combo = new Gtk.ComboBox();
+
+
this.hbox = new Gtk.HBox();
this.hbox.pack_start(this.text, true, true);
+ this.hbox.pack_start(this.font_combo, true, true);
+ this.hbox.pack_start(this.new_button);
}
-var window = new Gtk.Window();
-var gtkstage = new GtkClutter.Embed();
+function clear_selected(stg, evt)
+{
+ if(stg.equals(stage.get_actor_at_pos(evt.get_x(), evt.get_y())))
+ select_actor(null);
+}
-var properties = new prop_editor();
-var vbox = new Gtk.VBox();
-vbox.pack_start(gtkstage, true, true);
-vbox.pack_start(properties.hbox);
+function select_actor(actor)
+{
+ timeline.rewind();
+
+ if(current_actor)
+ current_actor.opacity = 255;
+
+ current_actor = actor;
+
+ if(!current_actor)
+ {
+ // defaults
+ properties.text.text = "";
+ return;
+ }
+
+ properties.text.text = actor.text;
+ var pfd = Pango.font_description_from_string(actor.get_font_name());
+
+ Seed.print(pfd.get_family());
+}
-window.resize(600,600);
-window.add(vbox);
-window.show_all();
+function mouse_click(actor, evt)
+{
+ dx = evt.get_x() - actor.x;
+ dy = evt.get_y() - actor.y;
+
+ select_actor(actor);
+
+ dragging = true;
+
+ return true;
+}
+function mouse_release()
+{
+ dragging = false;
+}
+
+function mouse_moved(win, evt)
+{
+ if(!dragging)
+ return;
+
+ current_actor.x = evt.get_x() - dx;
+ current_actor.y = evt.get_y() - dy;
+}
+
+function pango_actor(label, font)
+{
+ this.label = new Clutter.Label({text:label, font_name:font});
+ this.label.reactive = true;
+ this.label.signal_button_press_event.connect(mouse_click);
+
+ stage.add_actor(this.label);
+}
+function pulser()
+{
+ timeline = new Clutter.Timeline({fps:30, num_frames:628, loop:true});
+
+ timeline.signal_new_frame.connect(function(timeline, frame_num)
+ { current_actor.opacity = ((Math.sin(frame_num/7)+1) * 67) + 120; });
+ timeline.start();
+}
-function mouse_click(win, evt)
+function ui_setup()
{
- Seed.print(evt.get_x()+" "+evt.get_y());
+ var window = new Gtk.Window();
+ var gtkstage = new GtkClutter.Embed();
+
+ properties = new prop_editor();
+ var vbox = new Gtk.VBox();
+ vbox.pack_start(gtkstage, true, true);
+ vbox.pack_start(properties.hbox);
+
+ window.resize(600,600);
+ window.add(vbox);
+ window.show_all();
+
+ return gtkstage;
}
-var stage = gtkstage.get_stage();
-stage.show_all();
+function pangotest_init()
+{
+ stage = ui_setup().get_stage();
+
+ Clutter.set_motion_events_frequency(60);
+
+ stage.signal_motion_event.connect(mouse_moved);
+ stage.signal_button_release_event.connect(mouse_release);
+ stage.signal_button_press_event.connect(clear_selected);
+
+ pulser();
+
+ create_default_actors();
-stage.signal_button_press_event.connect(mouse_click);
+ stage.show_all();
-current_text = new Clutter.Label({text:"Hello, world!",
- font_name:"Bitstream Vera Sans 24"});
+ Gtk.main();
+}
-stage.add_actor(current_text);
+function create_default_actors()
+{
+ select_actor((new pango_actor("Hello, world!", "Bitstream Vera Sans 24")).label);
+ new pango_actor("Oh hi!", "Bitstream Vera Serif 28");
+}
-Gtk.main();
+pangotest_init();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]