#=============================================== # TkDraw #=============================================== package TkDraw; # TkPlotModuleの継承クラスとする use TkPlotModule; @ISA = qw(TkPlotModule); use strict; use Utils; use MyTk::GraphFrameArray; use GraphData; #============================================================ # コンストラクタ、デストラクタ(お約束) #============================================================ sub new { my ($module, $app, $canvas) = @_; my $this = {}; bless $this; $this->SetApplication($app); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } #============================================================ # 継承クラスで定義しなおす静的メンバー関数 #============================================================ #============================================================ # 継承クラスで定義しなおすウィンドウ関係メンバー関数 #============================================================ # 以下、標準の動作をしたい場合は、mw()の標準関数を呼び出す # 何もせずにundefを返すと、それぞれのウジェットを作成しない # メニューを作成する sub CreateMenu { my ($this) = @_; # return $this->mw()->InitCreateMenu(); return undef; } # ウジェット全体の作成 # mw()->InitCreateWidgets()を呼び出した後、 # ウィンドウタイトルを変更している sub CreateWidgets { my ($this) = @_; my $mw = $this->mw(); my $ret = $mw->InitCreateWidgets(); $mw->SetTitle("Draw Application demo for TkPlot.pl"); return $ret; } # ステータスバーを作成する sub CreateStatusBar { my ($this, $position) = @_; # return $this->mw()->CreateStatusBar($position); return undef; } # ツールボックスを作成する sub CreateToolBar { my ($this, $position) = @_; # return $this->mw()->CreateToolBar($position); return undef; } # ファイル選択ペインを作成する sub CreateSelectFilePane { my ($this) = @_; # return $this->mw()->CreateSelectFilePane(); return undef; } # ファイル内容リストボックス、テキストボックスを作成する sub CreateFileContentPane { my ($this) = @_; # return $this->mw()->CreateFileContentPane(); return undef; } # キャンバスを作成する sub CreateCanvasPane { my ($this) = @_; return $this->mw()->InitCreateCanvasPane(); } # 初期のウィンドウサイズを設定する sub InitWindowPosition { my ($this) = @_; return $this->mw()->InitWindowPosition(); } # 初期のグラフ枠を作成する sub InitCreateGraphFrameArray { my ($this) = @_; # return $this->mw()->CreateSampleGraphFrameArray(); return undef; } # mw()->CreateWidgets()の最後で、bindを設定する際に # 呼び出される sub ConfigureInitialBind { my ($this) = @_; my $mw = $this->mw(); my $can = $mw->Canvas(); # マウス左ボタンをCanvas上で押したとき、FirstPosで座標を取得 $mw->bind($can, "", [ \&SetFirstPosition, $mw, Tk::Ev('x'), Tk::Ev('y') ]); # マウス左ボタンを押しながら.can上を移動したとき、DrawLineを実行 $mw->bind($can, '', [ \&DrawLine, $mw, Tk::Ev('x'), Tk::Ev('y') ]); } sub InitWindow { my ($this) = @_; my $mw = $this->mw(); my $ret = $mw->InitWindow(); return $ret; } #======================================================================= # bindされた応答関数 ($canvasに線画を描く) #======================================================================= sub SetFirstPosition { my ($canvas, $this, $x1, $y1) = @_; $canvas->MoveTo($x1, $y1); } sub DrawLine { my ($canvas, $this, $x2, $y2) = @_; $canvas->LineTo($x2, $y2); } 1;