seed r65 - in trunk/examples: . shader



Author: racarr
Date: Sun Nov  2 23:13:10 2008
New Revision: 65
URL: http://svn.gnome.org/viewvc/seed?rev=65&view=rev

Log:
Give the spinning bob dylan a GtkSourceView to attach shaders to him. 
This is a rather contrived example.


Added:
   trunk/examples/shader/
   trunk/examples/shader/ShaderView.js
   trunk/examples/shader/bob.jpg   (props changed)
      - copied unchanged from r58, /trunk/examples/bob.jpg
   trunk/examples/shader/main.js   (contents, props changed)
Removed:
   trunk/examples/bob.jpg

Added: trunk/examples/shader/ShaderView.js
==============================================================================
--- (empty file)
+++ trunk/examples/shader/ShaderView.js	Sun Nov  2 23:13:10 2008
@@ -0,0 +1,45 @@
+#!/usr/local/bin/seed
+function ShaderView(source_type, actor, reflection)
+{
+    this.hbox = new Gtk.HBox();
+    
+    var source_lang_mgr = new GtkSource.SourceLanguageManager();
+    var js_lang = source_lang_mgr.get_language("c");
+
+    var source_buf = new GtkSource.SourceBuffer({language: js_lang});
+    source_buf.text = Gio.simple_read("default.glsl");
+    var source_view = GtkSource.SourceView.new_with_buffer(source_buf);
+    source_view.set_show_line_numbers(true);
+    source_view.set_show_right_margin(true);
+    source_view.set_highlight_current_line(true);
+    source_view.set_right_margin_position(80);
+    
+    this.source_type = source_type;
+    
+    var compile = new Gtk.Button({label: "Compile"});
+
+    var scrolled_window = new Gtk.ScrolledWindow(
+			   {vscrollbar_policy: Gtk.PolicyType.automatic, 
+			    hscrollbar_policy: Gtk.PolicyType.automatic});
+    scrolled_window.add(source_view);
+    
+    this.hbox.pack_start(scrolled_window, true, true);
+    this.hbox.pack_start(compile);
+    this.actor = actor;
+    this.reflection = reflection;
+    
+    this.make_shader = function()
+    {
+	shader.enabled = false;
+	if (this.source_type == "fragment_source")
+	    shader.fragment_source = source_buf.text;
+	else
+	    shader.vertex_source = source_buf.text;
+	shader.compile();
+	shader.enabled = true;
+	this.actor.set_shader(shader);
+	this.reflection.set_shader(shader);
+    }
+
+    compile.signal_clicked.connect(this.make_shader, this);
+}
\ No newline at end of file

Added: trunk/examples/shader/main.js
==============================================================================
--- (empty file)
+++ trunk/examples/shader/main.js	Sun Nov  2 23:13:10 2008
@@ -0,0 +1,51 @@
+#!/usr/local/bin/seed
+Seed.import_namespace("Clutter");
+Seed.import_namespace("Gtk");
+Seed.import_namespace("GtkSource");
+Seed.import_namespace("GtkClutter");
+Seed.import_namespace("Gio");
+Seed.include("ShaderView.js");
+
+Gtk.init(null, null);
+GtkClutter.init(null, null);
+
+var window = new Gtk.Window();
+var gtkstage = new GtkClutter.Embed();
+var stage = gtkstage.get_stage();
+var texture = new Clutter.Texture({filename:"bob.jpg"});
+var reflection = new Clutter.CloneTexture({parent_texture: texture});
+shader = new Clutter.Shader();
+var shaderfield = new ShaderView("fragment_source", texture,reflection);
+var vbox = new Gtk.VBox();
+var notebook = new Gtk.Notebook();
+var c = Clutter.Color._new();
+Clutter.color_parse("Black",c);
+
+notebook.append_page(shaderfield.hbox, new Gtk.Label({label:"Fragment"}));
+reflection.width = reflection.height = texture.width = texture.height = 300;
+
+
+gtkstage.set_size_request(500,500);
+vbox.pack_start(gtkstage, false, true);
+vbox.pack_start(notebook, true, true);
+
+window.add(vbox);
+stage.add_actor(texture);
+stage.add_actor(reflection);
+
+reflection.anchor_x = texture.anchor_x = texture.width/2;
+reflection.anchor_y = texture.anchor_y = texture.height/2;
+texture.x = stage.width/2-texture.width/4;
+texture.y = stage.height/2;
+
+reflection.x = stage.width/2-texture.width/4;
+reflection.y = stage.height/2+texture.height;
+reflection.rotation_angle_z = 180;
+reflection.opacity = 80;
+
+stage.color = c;
+
+window.show_all();
+stage.show_all();
+
+Gtk.main();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]