差分情報適用後の実行イメージ

差分情報

パッチファイル (Unified diffs)

--- PtFill.java	Mon Jun 01 05:12:13 2009
+++ PtFill.java	Wed Jun 17 18:51:03 2009
@@ -12,6 +12,8 @@
 import java.awt.image.BufferedImage;
 import java.util.LinkedList;
 import java.util.Queue;
+import javax.swing.ButtonGroup;
+import javax.swing.JRadioButton;
 
 // PaintToolを継承する
 public class PtFill extends PaintTool {
@@ -22,10 +24,28 @@
 	// FIFOキュー
 	Queue queue = null;
 
+	// ラジオボタン
+
+	private JRadioButton jRadioButtonNormalFill = null;
+
+	private JRadioButton jRadioButtonGradationTopFFF = null;
+
+	private JRadioButton jRadioButtonGradationBottomFFF = null;
+
 	// --------------------------------------------------
 	// コンストラクタ
 	// --------------------------------------------------
 	PtFill() {
+		// ラジオボックスのグループ登録とコンポーネント登録
+
+		ButtonGroup buttonGroup = new ButtonGroup(); // ボタングループ
+		buttonGroup.add(getJRadioButtonNormalFill()); // 登録
+		buttonGroup.add(getJRadioButtonGradationTopFFF()); // 登録
+		buttonGroup.add(getJRadioButtonGradationBottomFFF()); // 登録
+
+		super.jPanel.add(jRadioButtonNormalFill); // コンポーネント登録
+		super.jPanel.add(jRadioButtonGradationTopFFF); // コンポーネント登録
+		super.jPanel.add(jRadioButtonGradationBottomFFF); // コンポーネント登録
 	}
 
 	// --------------------------------------------------
@@ -39,10 +59,14 @@
 	// --------------------------------------------------
 	// 塗りつぶし(シード・フィル アルゴリズム)
 	// --------------------------------------------------
-	private void seedFill(int x, int y, Color fillColor, Graphics2D g2d, BufferedImage img) {
+	private void seedFill(int clickX, int clickY, Color fillColor, Graphics2D g2d, BufferedImage img) {
 		// FIFOキューの初期化
 		queue = new LinkedList();
 
+		// 塗りつぶし地点の座標を保持しておくために、新たにx、yを作成することにする
+		int x = clickX;
+		int y = clickY;
+
 		// 塗りつぶし地点の、「塗りつぶし対象色」を保持しておく
 		Color clr = new Color(img.getRGB(x, y));
 
@@ -55,6 +79,18 @@
 		queue.offer(Integer.valueOf(x));
 		queue.offer(Integer.valueOf(y));
 
+		// ピクセル走査用イメージを新たに作成し、そのイメージに今までの描写済イメージをコピーしておく
+
+		// ピクセル走査用イメージを作成
+		BufferedImage scan_img = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
+		// ピクセル走査用イメージを制御するグラフィックスインスタンスの作成
+		Graphics2D scan_g2d = scan_img.createGraphics();
+		// グラフィックスインスタンスを利用してコピーを行う
+		scan_g2d.drawImage(img, 0, 0, null);
+
+		// 実際に塗りつぶす色(グラデーションの場合はfillColorを少しずつずらして塗りつぶすため)変数を用意
+		Color nowColor = null;
+
 		do {
 			// キューから座標を取り出す
 			int leftX = Integer.parseInt(queue.poll().toString());
@@ -75,8 +111,36 @@
 					break;
 			}
 
-			// 左端から右端まで直線を引くことで塗りつぶす
-			g2d.setPaint(fillColor);
+			// 上側が明るいグラデーションラジオボタン
+			if (jRadioButtonGradationTopFFF.isSelected()) {
+				// fillColorと塗りつぶし地点をもとに、グラデーション色を作成する
+				nowColor = new Color(byteCheck(fillColor.getRed() - (y - clickY)), byteCheck(fillColor.getGreen() - (y - clickY)), byteCheck(fillColor.getBlue() - (y - clickY)));
+
+				// 走査用イメージを左端から右端まで直線を引くことで塗りつぶす
+				scan_g2d.setPaint(fillColor);
+				line.setLine(new Point2D.Double(leftX, y), new Point2D.Double(rightX, y));
+				scan_g2d.draw(line);
+			}
+
+			// 下側が明るいグラデーションラジオボタン
+			else if (jRadioButtonGradationBottomFFF.isSelected()) {
+				// fillColorと塗りつぶし地点をもとに、グラデーション色を作成する
+				nowColor = new Color(byteCheck(fillColor.getRed() + (y - clickY)), byteCheck(fillColor.getGreen() + (y - clickY)), byteCheck(fillColor.getBlue() + (y - clickY)));
+
+				// 走査用イメージを左端から右端まで直線を引くことで塗りつぶす
+				scan_g2d.setPaint(fillColor);
+				line.setLine(new Point2D.Double(leftX, y), new Point2D.Double(rightX, y));
+				scan_g2d.draw(line);
+			}
+
+			// 通常の塗りつぶしラジオボタン
+			else {
+				// fillColorをそのまま使う
+				nowColor = fillColor;
+			}
+
+			// 描写済イメージを更新(走査用イメージが塗りつぶした部分をグラデーションを津付けつつ塗りつぶす)
+			g2d.setPaint(nowColor);
 			line.setLine(new Point2D.Double(leftX, y), new Point2D.Double(rightX, y));
 			g2d.draw(line);
 
@@ -90,6 +154,15 @@
 		} while (queue.size() > 0); // キューが空になるまで以上の処理を繰り返す
 	}
 
+	// 引数iが0から255の範囲外であれば0もしくは255を返す
+	int byteCheck(int i) {
+		if (i < 0)
+			return 0;
+		if (i > 255)
+			return 255;
+		return i;

+	}
+
 	// 走査用メソッド
 	private void scanLine(int leftX, int rightX, int y, Color clr, BufferedImage img) {
 		// ループ処理
@@ -114,5 +187,29 @@
 			queue.offer(Integer.valueOf(leftX - 1));
 			queue.offer(Integer.valueOf(y));
 		}
+	}
+
+	// 通常の塗りつぶしラジオボタン
+	private JRadioButton getJRadioButtonNormalFill() {
+		if (jRadioButtonNormalFill == null) {
+			jRadioButtonNormalFill = new JRadioButton("Normal", true);
+		}
+		return jRadioButtonNormalFill;
+	}
+
+	// 上側が明るいグラデーションラジオボタン
+	private JRadioButton getJRadioButtonGradationTopFFF() {
+		if (jRadioButtonGradationTopFFF == null) {
+			jRadioButtonGradationTopFFF = new JRadioButton("TopFFF", false);
+		}
+		return jRadioButtonGradationTopFFF;
+	}
+
+	// 下側が明るいグラデーションラジオボタン
+	private JRadioButton getJRadioButtonGradationBottomFFF() {
+		if (jRadioButtonGradationBottomFFF == null) {
+			jRadioButtonGradationBottomFFF = new JRadioButton("BottomFFF", false);
+		}
+		return jRadioButtonGradationBottomFFF;
 	}
 }

変更後のファイル

変更の種類 変更後のファイル 変更前後の比較
修正 /branches/modify_fill/PtFill.java Side-by-side diffs
リンク先は リポジトリ上のURLです