summaryrefslogtreecommitdiff
path: root/jni/ruby/ext/tk/sample/tkextlib/vu/pie.rb
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/ext/tk/sample/tkextlib/vu/pie.rb
Fresh start
Diffstat (limited to 'jni/ruby/ext/tk/sample/tkextlib/vu/pie.rb')
-rw-r--r--jni/ruby/ext/tk/sample/tkextlib/vu/pie.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/jni/ruby/ext/tk/sample/tkextlib/vu/pie.rb b/jni/ruby/ext/tk/sample/tkextlib/vu/pie.rb
new file mode 100644
index 0000000..c8f9276
--- /dev/null
+++ b/jni/ruby/ext/tk/sample/tkextlib/vu/pie.rb
@@ -0,0 +1,56 @@
+#!/usr/bin/env ruby
+
+require 'tk'
+require 'tkextlib/vu/pie'
+
+pie = Tk::Vu::Pie.new(:label=>"My Revolving Budget"){
+ itemconfigure('Welfare', :value=>3.004)
+ itemconfigure('Military', :value=>7.006)
+ itemconfigure('Transport', :value=>1.6, :explode=>15)
+ itemconfigure('Parks', :value=>0.9)
+ itemconfigure('Schools', :value=>2)
+ itemconfigure('Debt', :value=>4, :explode=>10)
+
+ configure(:angle=>10, :origin=>90, :shadow=>10)
+}
+
+spin = TkTimer.new(60, -1, proc{|obj|
+ pie.configure(:origin=>pie[:origin] + 1)
+})
+
+f = TkFrame.new
+fast_btn = TkButton.new(f, :text=>"Spin Faster", :command=>proc{spin.start})
+slow_btn = TkButton.new(f, :text=>"Spin Slower", :command=>proc{spin.stop})
+quit_btn = TkButton.new(f, :text=>"Exit", :command=>proc{exit})
+
+Tk.grid(pie, :sticky=>:news)
+Tk.grid(f, :sticky=>:ew)
+
+Tk.pack(fast_btn, slow_btn, quit_btn,
+ :in=>f, :side=>:left, :fill=>:both, :expand=>true, :padx=>6, :pady=>4)
+
+Tk.root.grid_columnconfigure(0, :weight=>1)
+Tk.root.grid_rowconfigure(0, :weight=>1)
+
+priv = {
+ :x=>0, :y=>0, :pie_in=>false, :angle=>pie[:angle], :origin=>pie[:origin]
+}
+
+pie.bind('ButtonPress-1', proc{|w, x, y|
+ priv[:x] = x
+ priv[:y] = y
+ priv[:pie_in] = (w.winfo_width/1.8 > x)
+ priv[:angle] = w[:angle]
+ priv[:origin] = w[:origin]
+ }, '%W %x %y')
+
+pie.bind('B1-Motion', proc{|w, x, y|
+ if priv[:pie_in]
+ w.configure(:angle=>priv[:angle] + (priv[:y] - y)/3,
+ :origin=>(priv[:origin] +
+ ((w.winfo_height/2.2 > y)? -1: 1) *
+ (priv[:x] - x)/3) % 360)
+ end
+ }, '%W %x %y')
+
+Tk.mainloop