on dragEnter
set the acceptDrop to true
end dragEnter
ここは前回と同じ
-- その下に書くスクリプト
on dragDrop
put dragData["files"] into tPath
-- 「.pngの条件」と「.jpgの条件」をカッコでくくって、「or」でつないでまとめる
if (word 1 of the target is "image" and char -4 to -1 of tPath is ".png") or \
( word 1 of the target is "image" and char -4 to -1 of tPath is ".jpg") then
-- ドロップしたイメージをイメージ・オブジェクトにセットするコマンドは同じ
setImage tPath
else
-- 上の条件以外は全てビープを鳴らしてスクリプトから抜ける
beep
exit to top
end if
end dragDrop
private command setImage pPath
set the filename of the target to ("file://"& pPath)
/* 以下16:9の比率の写真を使用するので必要ありません
set the width of image "dropImage" to the width of this cd / 2
set the height of image "dropImage" to \
(the formattedheight of image "dropImage" * the width of this cd / 2) \
/ the formattedwidth of image "dropImage"
*/
end setImage
private command setImage pPath
set the filename of the target to ("file://"& pPath)
-- カスタム・プロパティ「the tOriginalData」にイメージ・データを収納
set the tOriginalData of image "dropImage" to the imageData of image "dropImage"
-- イメージ・データのバイナリをファールドに入れる
put the tOriginalData of image "dropImage" into fld "tImageData"
end setImage
on mouseUp
-- 過程をロックしておくと経過表示をしないので早くなります(ほとんど目には見えない程度ですが)
lock screen
-- 元のイメージ「dropImage」のレクト(rectangle)を記録しておく
put the rect of image "dropImage" into tRectImage
-- 「dropImage」の横・縦を「tWidth」「tHeight」に収納
put the width of image "dropImage" into tWidth
put the height of image "dropImage" into tHeight
--「dropImageS」を「dropImage」と同じ大きさに(あとで違う表記にします)
set the width of image "dropImageS" to tWidth
set the height of image "dropImageS" to tHeight
-- オリジナルのイメージ・データを「dropImageS」にセット
set the imagedata of image "dropImageS" to the tOriginalData of image "dropImage"
-- イメージ「dropImageS」をパーセントで縮小
put (the thumbpos of sb "sbBar" / 100) into tPercent
set the width of image "dropImageS" to tWidth * tPercent
set the height of image "dropImageS" to tHeight * tPercent
-- イメージ「dropImage」をイメージ「dropImagS」のサイズに
set the width of image "dropImage" to the width of image "dropImageS"
set the height of image "dropImage" to the height of image "dropImageS"
-- イメージ「dropImageS」のイメージ・データをイメージ「dropImage」に
set the imagedata of image "dropImage" to the imagedata of image "dropImageS"
-- イメージ「dropImage」を元のサイズ、ロケーションに
set the rect of image "dropImage" to tRectImage
end mouseUp
-- イメージ「dropImageS」をイメージ「dropImage」のロケーション(中心位置)に
set the loc of image "dropImageS" to the loc of image "dropImage"
スクロール・バーのスクリプトをまとめて書き直します。
on mouseUp
lock screen
put the rect of image "dropImage" into tRectImage
put the width of image "dropImage" into tWidth
put the height of image "dropImage" into tHeight
set the rect of image "dropImageS" to tRectImage
set the imagedata of image "dropImageS" to the tOriginalData of image "dropImage"
put (the thumbpos of sb "sbBar" / 100) into tPercent
set the width of image "dropImageS" to tWidth * tPercent
set the height of image "dropImageS" to tHeight * tPercent
set the width of image "dropImage" to the width of image "dropImageS"
set the height of image "dropImage" to the height of image "dropImageS"
set the imagedata of image "dropImage" to the imagedata of image "dropImageS"
set the rect of image "dropImage" to tRectImage
set the loc of image "dropImageS" to the loc of image "dropImage"
end mouseUp