aboutsummaryrefslogtreecommitdiffstats
path: root/ext/tk/sample/tkextlib/vu/canvItems.rb
blob: c3e563058c3907dbf72ec087d6531492efaba7f1 (plain)
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
#!/usr/bin/env ruby

require 'tk'
require 'tkextlib/vu/charts'

#######################################

xbm = File.join(File.dirname(File.expand_path(__FILE__)), 'm128_000.xbm')

sval = [ 11, 22, 33, 44, 55, 66, 77, 88, 99 ]

l0 = TkLabel.new(:width=>128, :height=>128, 
		 :bitmap=>"@#{xbm}", :relief=>:groove).pack(:side=>:left)

c0 = TkCanvas.new(:width=>80, :height=>80, 
		  :insertwidth=>0, :highlightthickness=>0, 
		  :selectborderwidth=>0, :borderwidth=>2, 
		  :relief=>:ridge).place(:in=>l0, :relx=>0.5, :rely=>0.5, 
					 :anchor=>:c)

st = Tk::Vu::TkcStripchart.new(c0, 3, 3, 80, 80, 
			       :background=>"#b7c0d7", :fill=>'slategray3', 
			       :jumpscroll=>1, :outline=>'black', 
			       :scaleline=>'blue', :stripline=>'red', 
			       :selected=>1, :values=>sval)

TkcText.create(c0, 40, 40, 
	       :text=>Tk::TCL_PATCHLEVEL, :fill=>'cyan', :tags=>'text')


l1 = TkLabel.new(:width=>128, :height=>128, 
		 :bitmap=>"@#{xbm}", :relief=>:groove).pack(:side=>:left)

c1 = TkCanvas.new(:width=>80, :height=>80, 
		  :insertwidth=>0, :highlightthickness=>0, 
		  :selectborderwidth=>0, :borderwidth=>2, 
		  :relief=>:ridge).place(:in=>l1, :relx=>0.5, :rely=>0.5, 
					 :anchor=>:c)

bar1 = Tk::Vu::TkcBarchart.new(c1, 3, 3, 80, 80, 
			       :background=>"#b7c0d7", :scalevalue=>10.0, 
			       :autocolor=>true, :selected=>1, 
			       :outline=>'black', :barline=>'yellow', 
			       :scalelinestyle=>0)

bar2 = Tk::Vu::TkcBarchart.new(c1, 53, 3, 80, 80, 
			       :background=>"#b7c0d7", :scalevalue=>10.0, 
			       :autocolor=>true, :selected=>1, 
			       :outline=>'black', :fill=>"#b7c0d7", 
			       :barline=>'red', :scalelinestyle=>22)


l2 = TkLabel.new(:width=>128, :height=>128, 
		 :bitmap=>"@#{xbm}", :relief=>:groove).pack(:side=>:left)

c2 = TkCanvas.new(:width=>80, :height=>80, 
		  :insertwidth=>0, :highlightthickness=>0, 
		  :selectborderwidth=>0, :borderwidth=>2, 
		  :relief=>:ridge).place(:in=>l2, :relx=>0.5, :rely=>0.5, 
					 :anchor=>:c)

begin
  stick = Tk::Vu::TkcSticker.new(c2, 3, 3, 80, 80, 
				 :text=>"Tcl/Tk", :space=>0, :color=>'red', 
				 :outline=>'red', :font=>'Helvetica 14 bold', 
				 :fill=>'', :stipple=>'', :bar=>'blue', 
				 :orient=>:vertical, :anchor=>:s, 
				 :relheight=>1.0, :relwidth=>0.15, 
				 :relx=>0.1, :rely=>0.0)
rescue
  stick = nil
  TkcText.new(c2, 40, 10, :text=>"No Sticker Item")
end

c_do = proc{
  st[:values]   = rand() * 100

  bar1[:values] = rand() * 10
  bar2[:values] = rand() * 10

  stick[:rely]  = rand() * 100 * 0.01 if stick
}

c0.bind('1', c_do)

TkTimer.new(100, -1, c_do).start

Tk.root.bind('q', proc{exit})

Tk.mainloop