diff options
author | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-01 16:09:54 +0000 |
---|---|---|
committer | nagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-05-01 16:09:54 +0000 |
commit | 4c4631c2daaf7b2418c1f0e39292c8ee27a64813 (patch) | |
tree | dfeb96c4772df8caba4e01e749c8f3e1262f8fe0 /ext/tk/sample/demos-en/tcolor | |
parent | ce23680755e4e9ab0eed9dc6adb091ef7f1c58cb (diff) | |
download | ruby-4c4631c2daaf7b2418c1f0e39292c8ee27a64813.tar.gz |
* renewal Ruby/Tk
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/sample/demos-en/tcolor')
-rw-r--r-- | ext/tk/sample/demos-en/tcolor | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/ext/tk/sample/demos-en/tcolor b/ext/tk/sample/demos-en/tcolor index 6d023f0f8b..5b29797906 100644 --- a/ext/tk/sample/demos-en/tcolor +++ b/ext/tk/sample/demos-en/tcolor @@ -1,30 +1,28 @@ #!/usr/bin/env ruby # # tcolor -- -# このスクリプトはRGB,HSB,CYM形式をサポートする -# 簡易カラーエディタです。 +# simple color editor which supports RGB, HSB and CYM color space # # Copyright (C) 1998 Takaaki Tateishi(ttate@jaist.ac.jp) # last update: Thu Jun 18 06:32:35 JST 1998 # -# まずはtk.rbを読み込む。 - require "tk" -# Tkによって変更される変数はTkVariableのインスタンスを使う。 +# use TkVariable instance for the variable which is changed by Tk interpreter $colorSpace = TkVariable.new(:rgb) +$master = nil $red = 65535 $green = 0 $blue = 0 $color = "#ffff00000000" $updating = TkVariable.new(0) $autoUpdate = TkVariable.new(1) -$name = TkVariable.new("") -# $command = TkVariable.new("print(%%,\"\n\")") -$command = TkVariable.new("") +$name = TkVariable.new($color) +$command = TkVariable.new("print(%%,\"\n\")") +# $command = TkVariable.new("") $label1 = TkVariable.new("label1") $label2 = TkVariable.new("label2") $label3 = TkVariable.new("label3") @@ -36,7 +34,7 @@ if (TkVarAccess.new('tcl_platform')['platform'] == 'unix') end -# 各イベント用のメソッド +# methods for events def rgbToHsv(red,green,blue) @@ -134,6 +132,8 @@ def tc_scaleChanged return end + $master = :scale if $master == nil + scale1 = $root.middle.middle.scale1 scale2 = $root.middle.middle.scale2 scale3 = $root.middle.middle.scale3 @@ -158,11 +158,13 @@ def tc_scaleChanged raise(Exception,"unknown colorSpace") end $color = format("#%04x%04x%04x",$red.to_i,$green.to_i,$blue.to_i) + $name.value = $color if $master == :scale $root.middle.right.set_color($color) if( $autoUpdate.to_i == 1 ) doUpdate end - Tk.update(TRUE) + Tk.update(true) + $master = nil if $master == :scale end @@ -196,6 +198,8 @@ end def tc_loadNamedColor(name) + $name.value = name + $master = :name if $master == nil if name[0,1] != "#" list = TkWinfo.rgb($root.middle.right.swatch,name) $red = list[0] @@ -222,9 +226,9 @@ def tc_loadNamedColor(name) if strlist.length != 3 raise(eException,"syntax error in color name \"#{name}\"") end - $red = strlist[0].to_i - $green = strlist[1].to_i - $blue = strlist[2].to_i + $red = strlist[0].hex + $green = strlist[1].hex + $blue = strlist[2].hex } $red = $red << shift $green = $green << shift @@ -237,6 +241,8 @@ def tc_loadNamedColor(name) if $autoUpdate.to_i == 1 doUpdate end + Tk.update(true) + $master = nil if $master == :name end @@ -259,10 +265,7 @@ def changeColorSpace(space) end - - - -# tcolor用のメニュー +# menu class TkColorMenuFrame<TkFrame def initialize(parent) @@ -270,10 +273,10 @@ class TkColorMenuFrame<TkFrame "relief"=>"raised", "borderwidth"=>"2") - # Fileメニューボタンの生成 + # File menubutton @file = TkMenubutton.new(self){|button| - # Fileメニューの作成 + # File menu @file_menu = TkMenu.new(button){ add "radio", "label" => "RGB color space", @@ -311,7 +314,7 @@ class TkColorMenuFrame<TkFrame "command" => proc{exit} } - # FileメニューとFileボタンを関連付ける + # assign File menu to File button menu @file_menu text "File" @@ -323,7 +326,7 @@ class TkColorMenuFrame<TkFrame end -# 下部のフレームのためのクラス +# bottom frame class TkColorBotFrame<TkFrame def initialize(parent) super(parent, @@ -349,7 +352,7 @@ class TkColorBotFrame<TkFrame end -# 中段左のフレーム +# left side frame of middle level class TkColorMiddleLeftFrame<TkFrame def initialize(parent) super(parent) @@ -393,9 +396,8 @@ class TkColorMiddleLeftFrame<TkFrame end -# 中段中央のフレーム +# middle frame of middle level class TkColorMiddleMiddleFrame<TkFrame - # @scale1,@scale2,@scale3を外部から参照のみ許可する。(変更不可) attr_reader :scale1, :scale2, :scale3 def initialize(parent) @@ -470,7 +472,7 @@ end -# 中段のフレーム +# middle level frame class TkColorMiddleFrame<TkFrame attr_reader :left, :middle, :right @@ -513,7 +515,7 @@ end $root = TkColor.new - -# イベントを待つ為にループに入る。 changeColorSpace :rgb + +# start eventloop Tk.mainloop |