[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-dancr-rbcatut-intro

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2013年 3月 31日 (日) 00:58:21 JST


-------------------------
REMOTE_ADDR = 70.49.48.128
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-dancr-rbcatut-intro
-------------------------
@@ -279,20 +279,101 @@
 == Hiki Gtk With Cairo Module Download File
 (12.3.0.3){{br}}
 
-#### (12.3.XXXX) "'Hiki Gtk With Cairo' module file" ------ (section:  12.3.1.1 [((<Time To Start Using Object-Oriented Programming Paradigm|tut-gtk2-dnd-intro#Time To Start Using Object-Oriented Programming Paradigm>))], however, as you will see after this example program, we are going to expand and upgrade our((*HikiGtk*))module to include background manipulation functionality. ----- , however, as you will see after this example program, we are going to expand and upgrade our((*HikiGtk*))module to include background manipulation functionality. 
 
+To run Gtk/Cairo examples in this tutorial in the Gtk programming environment, as opposed to the console or text based terminal environment, you need to require a new module file called ((*'hiki2-gtk-w-cairo.rb'*)). But to do that you first have to download this file into either your working directory where your example programs reside, or into some common place where you keep module files, just as we did with other module files we used in the examples throughout this tutorial. If you forgot about this, you can refresh your memory in the section:  12.3.1.1 called [((<Time To Start Using Object-Oriented Programming Paradigm|tut-gtk2-dnd-intro#Time To Start Using Object-Oriented Programming Paradigm>))].
 
+#### However, as you will see after this example program, we are going to expand and upgrade our((*HikiGtk*))module to include background manipulation functionality. 
 
+Following is the module file you need to download and save as just explained:
+
+ # Minimal Gtk/Cairo module; introducing Cairo in Tutorial I'm writing on Hiki, where
+ # Hiki="http://ruby-gnome2.sourceforge.jp/hiki.cgi?c=view;p=tut-gtk2-dancr-rbcatut"
+ #
+ # FILE: hiki2-gtk-w-cairo.rb
+ # RELEASE: 1.2
+ 
+ module HikiGtk
+   require 'gtk2'
+   require 'cairo'
+ 
+   class BasicWindow < Gtk::Window
+     def initialize(title = nil)
+       super(Gtk::Window::TOPLEVEL)
+       
+       set_title(title) if title
+       set_size_request(250, 200)
+       border_width = 10
+ 
+       signal_connect("key_press_event") do |widget, event|
+         if event.state.control_mask? and event.keyval == Gdk::Keyval::GDK_q
+           destroy
+           true
+         else
+           false
+         end
+       end
+ 
+       signal_connect("delete_event") { |widget, event| quit }
+       signal_connect("destroy") { Gtk.main_quit }
+ 
+       puts "DEBUG:initialize completed in class BasicWindow"
+     end
+ 
+     def quit
+       puts "DEBUG: quiting Hiki example"
+       destroy
+       false
+     end
+   end
+ 
+ 
+   class CairoWindow < BasicWindow
+ 
+     PI = Math::PI
+     RAD2DEG = 180/PI
+     DEG2RAD = PI/180
+ 
+     BLACK=[0,0,0];     RED=[1,0,0];  GREEN=[0,1,0];  BLUE=[0,0,1]; 
+     TURQUOISE=[0,1,1]; PINK=[1,0,1]; YELLOW=[1,1,0]; WHITE=[1,1,1]
+     GRAY=[0.8,0.8,0.8]
+ 
+     def initialize(title=nil)
+       super
+       unless Gdk.cairo_available?
+         raise "This program requires GTK+ 2.8.0 or later and cairo support"
+       end
+ 
+       drawing_area = Gtk::DrawingArea.new
+       add(drawing_area)
+ 
+       drawing_area.signal_connect("expose_event") do |w, e|
+         cr = w.window.create_cairo_context
+         cr.rectangle(e.area.x, e.area.y, e.area.width, e.area.height)
+         cr.clip()
+         draw(cr, w)
+       end
+       puts "DEBUG:initialize completed in class CairoWindow"
+     end
+ 
+     def draw(cr, drawing_area)
+     
+       width, height = drawing_area.window.size
+ 
+       # Fill the background with gray
+       cr.set_source_rgb(GRAY)
+       cr.rectangle(0, 0, width, height)
+       cr.fill()
+     end
+   end
+ 
+ end
+
+
+
 # ------- REQUIRED FILES: -----------
 {{br}}
 {{br}}
-(12.3.XXXX+1){{br}}
+(12.3.0.4){{br}}
 :To run the examples in this article download the following files into your program directory:
-
-#    See: (12.1.3)
-   
-# {{image_left("")}} ....... Name it: ((*"".*))
-{{br}}
 
-# {{image_right("")}}
-# ((<|URL:http://...>))
+    * hiki2-gtk-w-cairo.rb' .......... module file; see section 12.3.0.3 ((<Hiki Gtk With Cairo Module Download File|tut-gtk2-dancr-rbcatut-intro#Hiki Gtk With Cairo Module Download File>)).




ruby-gnome2-cvs メーリングリストの案内
Back to archive index