OmegaT の背景に画像を表示します。
背景タイリング画像を保持する処理を追加
| @@ -19,8 +19,6 @@ | ||
| 19 | 19 | import java.awt.AlphaComposite; |
| 20 | 20 | import java.awt.Graphics; |
| 21 | 21 | import java.awt.Graphics2D; |
| 22 | -import java.awt.Rectangle; | |
| 23 | -import java.awt.TexturePaint; | |
| 24 | 22 | import java.awt.image.BufferedImage; |
| 25 | 23 | import java.awt.image.WritableRaster; |
| 26 | 24 | import javax.swing.JLayeredPane; |
| @@ -44,7 +42,7 @@ | ||
| 44 | 42 | public class MoeLayeredPane extends JLayeredPane { |
| 45 | 43 | |
| 46 | 44 | private BufferedImage image = null; |
| 47 | - private TexturePaint paint = null; | |
| 45 | + private BufferedImage tiledImage = null; | |
| 48 | 46 | private float alpha = 0.5f; //@@TODO replace literal to constant |
| 49 | 47 | private int paintMarginTop = 0; |
| 50 | 48 |
| @@ -67,15 +65,21 @@ | ||
| 67 | 65 | Graphics2D g2 = (Graphics2D) g.create(); |
| 68 | 66 | g2.setComposite(makeComposite(alpha)); |
| 69 | 67 | |
| 70 | - if (getWidth() > image.getWidth() || getHeight() > image.getHeight()) { | |
| 71 | - //g2.setPaint(paint); | |
| 72 | - //g2.fillRect(0, 0, getWidth(), getHeight()); | |
| 73 | - //g2.fillRect(0, paintMarginTop, getWidth(), getHeight()); | |
| 74 | - BufferedImage tiledImage = createTiledImage(image, getWidth(), getHeight()); | |
| 75 | - g2.drawImage(tiledImage, 0, paintMarginTop, this); | |
| 76 | - } else { | |
| 77 | - g2.drawImage(image, 0, paintMarginTop, this); | |
| 68 | + // 当初 TexturePaint を用意して、 | |
| 69 | + // g2.setPaint(paint); | |
| 70 | + // g2.fillRect(0, 0, getWidth(), getHeight()); | |
| 71 | + // などとしていたが、メニューバーなどが不透過に設定された場合に | |
| 72 | + // 背景の描画開始位置を下げる必要があり、テクスチャによるタイリング | |
| 73 | + // では対応できなかった(描画開始位置を下げてもテクスチャの位置が | |
| 74 | + // 変わらないので、テクスチャの途中から描画が始まる感じ)。 | |
| 75 | + // そこで、自前でタイリング画像を作って保持し、その一枚絵を貼る路線 | |
| 76 | + // に変更する。 | |
| 77 | + int width = getWidth(); | |
| 78 | + int height = getHeight(); | |
| 79 | + if (width > image.getWidth() || height > image.getHeight()) { | |
| 80 | + this.tiledImage = createTiledImage(image, width, height); | |
| 78 | 81 | } |
| 82 | + g2.drawImage(tiledImage, 0, paintMarginTop, this); | |
| 79 | 83 | |
| 80 | 84 | g2.dispose(); |
| 81 | 85 | } |
| @@ -89,12 +93,11 @@ | ||
| 89 | 93 | |
| 90 | 94 | private void setPicture(BufferedImage image) { |
| 91 | 95 | this.image = image; |
| 92 | - | |
| 96 | + | |
| 93 | 97 | if (image == null) { |
| 94 | - this.paint = null; | |
| 98 | + this.tiledImage = null; | |
| 95 | 99 | } else { |
| 96 | - Rectangle rect = new Rectangle(image.getWidth(), image.getHeight()); | |
| 97 | - this.paint = new TexturePaint(image, rect); | |
| 100 | + this.tiledImage = createTiledImage(image, getWidth(), getHeight()); | |
| 98 | 101 | } |
| 99 | 102 | } |
| 100 | 103 |