亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? cpcanvas.java

?? this is best wamp jkbkgnkldjkb jkfbjdksgkjl bjkgsbkjfdb gjdsblkj gbfkjsd
?? JAVA
?? 第 1 頁 / 共 3 頁
字號:
/*
	ChibiPaint
    Copyright (c) 2006-2008 Marc Schefer

    This file is part of ChibiPaint.

    ChibiPaint is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ChibiPaint is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ChibiPaint. If not, see <http://www.gnu.org/licenses/>.

 */

package chibipaint.gui;

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.awt.image.*;

import javax.swing.*;

import chibipaint.*;
import chibipaint.engine.*;
import chibipaint.util.*;

public class CPCanvas extends JComponent implements MouseListener, MouseMotionListener, MouseWheelListener,
		ComponentListener, KeyListener, CPController.ICPToolListener, CPController.ICPModeListener,
		CPArtwork.ICPArtworkListener {

	CPController controller;

	// FIXME: this should not be public
	public Image img;

	BufferedImage checkerboardPattern;
	MemoryImageSource imgSource;
	CPRect updateRegion = new CPRect();

	int[] buffer;
	CPArtwork artwork;

	boolean spacePressed = false;

	// canvas transformations
	float zoom = 1, minZoom = .05f, maxZoom = 16.f;
	int offsetX, offsetY;
	float canvasRotation = 0.f;
	AffineTransform transform = new AffineTransform();
	boolean interpolation = false;

	int mouseX, mouseY;

	boolean brushPreview = false;
	Rectangle oldPreviewRect;

	Cursor defaultCursor, hideCursor, moveCursor, crossCursor;
	boolean mouseIn;

	boolean dontStealFocus = false;

	// Grid options

	// FIXME: these shouldn't be public
	public int gridSize = 32;
	public boolean showGrid = false;

	//
	// Modes system: modes control the way the GUI is reacting to the user input
	// All the tools are implemented through modes
	//

	CPMode defaultMode = new CPDefaultMode();
	CPMode colorPickerMode = new CPColorPickerMode();
	CPMode moveCanvasMode = new CPMoveCanvasMode();
	CPMode rotateCanvasMode = new CPRotateCanvasMode();
	CPMode floodFillMode = new CPFloodFillMode();
	CPMode rectSelectionMode = new CPRectSelectionMode();
	CPMode moveToolMode = new CPMoveToolMode();

	// this must correspond to the stroke modes defined in CPToolInfo
	CPMode drawingModes[] = { new CPFreehandMode(), new CPLineMode(), new CPBezierMode(), };

	CPMode curDrawMode = drawingModes[CPBrushInfo.SM_FREEHAND];
	CPMode curSelectedMode = curDrawMode;
	CPMode activeMode = defaultMode;
	
	// Container with scrollbars
	JPanel container;
	JScrollBar horizScroll, vertScroll;
	
	public CPCanvas(CPController ctrl) {
		this.controller = ctrl;
		artwork = ctrl.getArtwork();

		buffer = artwork.getDisplayBM().getData();

		int w = artwork.width;
		int h = artwork.height;

		imgSource = new MemoryImageSource(w, h, buffer, 0, w);
		imgSource.setAnimated(true);
		// imgSource.setFullBufferUpdates(false);
		img = createImage(imgSource);

		centerCanvas();

		ctrl.setCanvas(this);

		int[] pixels = new int[16 * 16];
		Image image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(16, 16, pixels, 0, 16));
		hideCursor = Toolkit.getDefaultToolkit().createCustomCursor(image, new Point(0, 0), "invisiblecursor");
		defaultCursor = new Cursor(Cursor.DEFAULT_CURSOR);
		moveCursor = new Cursor(Cursor.MOVE_CURSOR);
		crossCursor = new Cursor(Cursor.CROSSHAIR_CURSOR);

		// Creates the checkboard pattern seen in transparent areas
		checkerboardPattern = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);
		pixels = new int[64 * 64];
		for (int j = 0; j < 64; j++) {
			for (int i = 0; i < 64; i++) {
				if ((i & 0x8) != 0 ^ (j & 0x8) != 0) {
					pixels[i + j * 64] = 0xffffffff;
				} else {
					pixels[i + j * 64] = 0xffcccccc;
				}
			}
		}
		checkerboardPattern.setRGB(0, 0, 64, 64, pixels, 0, 64);

		/*
		 * KeyStroke escapeKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false); Action escapeAction = new
		 * AbstractAction() { public void actionPerformed(ActionEvent e) { controller.setAlpha((int)(.5f*255)); } };
		 * 
		 * getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW). put(escapeKeyStroke, "SPACE"); getActionMap().put("SPACE",
		 * escapeAction);
		 */

		// register as a listener for Mouse & MouseMotion events
		addMouseListener(this);
		addMouseMotionListener(this);
		addMouseWheelListener(this);
		addComponentListener(this);
		addKeyListener(this);

		controller.addToolListener(this);
		controller.addModeListener(this);

		artwork.addListener(this);

		// We'll need to refresh the whole thing at least once
		updateRegion = new CPRect(w, h);

		// So that the tab key will work
		setFocusTraversalKeysEnabled(false);
	}

	public boolean isOpaque() {
		return true;
	}

	// //////////////////////////////////////////////////////////////////////////////////////
	// Container and ScrollBars
	// //////////////////////////////////////////////////////////////////////////////////////
	
	public JPanel getContainer() {
		if (container != null) {
			return container;
		}
		
		container = new JPanel();
		container.setLayout(new GridBagLayout());

		GridBagConstraints gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.BOTH;
		gbc.weightx = 1.;
		gbc.weighty = 1.;
		container.add(this, gbc);
		
		vertScroll = new JScrollBar(JScrollBar.VERTICAL);
		gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.VERTICAL;
		container.add(vertScroll, gbc);

		horizScroll = new JScrollBar(JScrollBar.HORIZONTAL);
		gbc = new GridBagConstraints();
		gbc.gridx = 0;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		container.add(horizScroll, gbc);
		
		updateScrollBars();
		
		horizScroll.addAdjustmentListener(new AdjustmentListener() {
			public void adjustmentValueChanged(AdjustmentEvent e) {
				Point p = getOffset();
				p.x = - e.getValue();
				setOffset(p);
			}
		});
		
		vertScroll.addAdjustmentListener(new AdjustmentListener() {
			public void adjustmentValueChanged(AdjustmentEvent e) {
				Point p = getOffset();
				p.y = - e.getValue();
				setOffset(p);
			}
		});
		
		return container;
	}
	
	void updateScrollBars() {
		if (horizScroll == null || vertScroll == null
		 || horizScroll.getValueIsAdjusting() || vertScroll.getValueIsAdjusting() ) {
			return;
		}
		
		if (img == null) {
			horizScroll.setEnabled(false);
			vertScroll.setEnabled(false);
		}
		
		Rectangle visibleRect = getRefreshArea(new CPRect(img.getWidth(null), img.getHeight(null)));
		updateScrollBar(horizScroll, visibleRect.x, visibleRect.width, getWidth(), -getOffset().x);
		updateScrollBar(vertScroll, visibleRect.y, visibleRect.height, getHeight(), -getOffset().y);
	}
		
	
	void updateScrollBar(JScrollBar scroll, int visMin, int visWidth, int viewSize, int offset) {
		if (visMin >= 0 && visMin + visWidth < viewSize) {
			scroll.setEnabled(false);
		} else {
			scroll.setEnabled(true);
			
			int xMin = Math.min(0, (visMin - viewSize / 4));
			int xMax = Math.max(viewSize, visMin + visWidth + viewSize / 4);
			
			scroll.setValues(offset, viewSize, xMin + offset, xMax + offset);
			scroll.setBlockIncrement(Math.max(1, (int) (viewSize * .66)));
			scroll.setUnitIncrement(Math.max(1, (int) (viewSize * .05)));
		}
	}

	// //////////////////////////////////////////////////////////////////////////////////////
	// painting methods
	// //////////////////////////////////////////////////////////////////////////////////////

	public void update(Graphics g) {
		paint(g);
	}

	public void paint(Graphics g) {
		Graphics2D g2d = (Graphics2D) g;
		
		g2d.setColor(new Color(0x606060));
		g2d.fillRect(0, 0, getWidth(), getHeight());

		if (!updateRegion.isEmpty()) {
			artwork.fusionLayers();
			imgSource.newPixels(updateRegion.left, updateRegion.top, updateRegion.getWidth(), updateRegion.getHeight());
			updateRegion.makeEmpty();
		}

		int w = img.getWidth(null);
		int h = img.getHeight(null);

		Graphics2D g2doc = (Graphics2D) g2d.create();
		g2doc.transform(transform);

		// Draw the checkerboard pattern
		// we'll draw the pattern over an area larger than the image
		// and then remove the extra to avoid display problems
		// when the displayed bitmap doesn't match exactly with the checkerboard area

		GeneralPath path = getCheckerboardBackgroundPath(new Rectangle2D.Float(0, 0, w, h));

		// get the bounding rect and make it a bit larger to be sure to include everything
		Rectangle pathRect = path.getBounds();
		pathRect.x -= 2;
		pathRect.y -= 2;
		pathRect.width += 4;
		pathRect.height += 4;

		g2d.setPaint(new TexturePaint(checkerboardPattern, new Rectangle(0, 0, 64, 64)));
		g2d.fill(pathRect);

		// Draw the image on the canvas

		if (interpolation) {
			RenderingHints hints = g2doc.getRenderingHints();
			hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
			g2doc.addRenderingHints(hints);
		}

		g2doc.drawImage(img, 0, 0, w, h, 0, 0, img.getWidth(null), img.getHeight(null), null);

		// Redraw over the checkerboard border, removing a just a little bit of the image to avoid display problems
		path.append(pathRect, false);
		path.setWindingRule(GeneralPath.WIND_EVEN_ODD);
		g2d.setColor(new Color(0x606060));
		g2d.fill(path);

		// This XOR mode guaranties contrast over all colors
		g2d.setColor(Color.black);
		g2d.setXORMode(new Color(0x808080));

		// Draw selection
		if (!artwork.getSelection().isEmpty()) {
			Stroke stroke = g2d.getStroke();
			g2d
					.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f,
							new float[] { 2f }, 0f));
			g2d.draw(coordToDisplay(artwork.getSelection()));
			g2d.setStroke(stroke);
		}

		// Draw grid
		if (showGrid) {
			Stroke stroke = g2d.getStroke();
			g2d.setStroke(new BasicStroke(1f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, null, 0f));

			CPRect size = artwork.getSize();
			for (int i = gridSize - 1; i < size.getWidth(); i += gridSize) {
				Point2D.Float p1 = coordToDisplay(new Point2D.Float(i, 0));
				Point2D.Float p2 = coordToDisplay(new Point2D.Float(i, size.getHeight() - 1));
				g2d.draw(new Line2D.Float(p1, p2));
			}

			for (int i = gridSize - 1; i < size.getHeight(); i += gridSize) {
				Point2D.Float p1 = coordToDisplay(new Point2D.Float(0, i));
				Point2D.Float p2 = coordToDisplay(new Point2D.Float(size.getWidth() - 1, i));
				g2d.draw(new Line2D.Float(p1, p2));
			}

			g2d.setStroke(stroke);
		}

		// Additional drawing by the current mode
		activeMode.paint(g2d);

		// This bit of code is used to test repaint areas
		/*
		 * if((test++ & 16) == 0) { g.setColor(Color.magenta); Dimension dd = getSize();
		 * g.fillRect(0,0,dd.width,dd.height); g.setColor(Color.black); }
		 */
	}

	private GeneralPath getCheckerboardBackgroundPath(Rectangle2D r) {
		GeneralPath path = new GeneralPath();
		float delta = (canvasRotation == 0f ? 0f : 1f / zoom);

		Point2D.Float p = coordToDisplay(new Point2D.Float((float) r.getX() + delta, (float) r.getY() + delta));
		path.moveTo(p.x, p.y);

		p = coordToDisplay(new Point2D.Float((float) r.getMaxX() - delta, (float) r.getY() + delta));
		path.lineTo(p.x, p.y);

		p = coordToDisplay(new Point2D.Float((float) r.getMaxX() - delta, (float) r.getMaxY() - delta));
		path.lineTo(p.x, p.y);

		p = coordToDisplay(new Point2D.Float((float) r.getX() + delta, (float) r.getMaxY() - delta));
		path.lineTo(p.x, p.y);
		path.closePath();

		return path;
	}

	//
	// Mouse input methods
	//

	public void mouseEntered(MouseEvent e) {
		mouseIn = true;
	}

	public void mouseExited(MouseEvent e) {
		mouseIn = false;
		repaint();
	}

	public void mousePressed(MouseEvent e) {
		requestFocusInWindow();
		activeMode.mousePressed(e);
	}

	public void mouseDragged(MouseEvent e) {
		mouseX = e.getX();
		mouseY = e.getY();

		activeMode.mouseDragged(e);
	}

	public void mouseReleased(MouseEvent e) {
		activeMode.mouseReleased(e);
	}

	public void mouseMoved(MouseEvent e) {
		mouseX = e.getX();
		mouseY = e.getY();

		if (!dontStealFocus) {
			requestFocusInWindow();
		}
		activeMode.mouseMoved(e);
		CPTablet.getRef().mouseDetect();
	}

	public void mouseWheelMoved(MouseWheelEvent e) {
		float factor = 1;
		if (e.getWheelRotation() > 0) {
			factor = 1 / 1.15f;
		}
		if (e.getWheelRotation() < 0) {
			factor = 1.15f;
		}

		Point2D.Float pf = coordToDocument(new Point2D.Float(mouseX, mouseY));
		if (artwork.isPointWithin(pf.x, pf.y)) {
			zoomOnPoint(getZoom() * factor, mouseX, mouseY);
		} else {
			zoomOnPoint(getZoom() * factor, offsetX + (int) (artwork.width * zoom / 2), offsetY
					+ (int) (artwork.height * zoom / 2));
		}
		// FIXME: clean the above code, some coordinates get transformed multiple times for nothing
	}

	// //////////////////////////////////////////////////////////////////////////////////////
	// Transformation methods
	// //////////////////////////////////////////////////////////////////////////////////////

	// Zoom

	public void setZoom(float zoom) {
		this.zoom = zoom;
		updateTransform();
	}

	public float getZoom() {
		return zoom;
	}

	// Offset

	public void setOffset(Point p) {
		setOffset(p.x, p.y);
	}

	public void setOffset(int x, int y) {
		offsetX = x;
		offsetY = y;
		updateTransform();
	}

	public Point getOffset() {
		return new Point(offsetX, offsetY);
	}

	// Rotation

	public void setRotation(float angle) {
		canvasRotation = (float) (angle % (2 * Math.PI));
		updateTransform();
	}

	public float getRotation() {
		return canvasRotation;
	}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
美国精品在线观看| 国产福利一区二区三区视频在线| 久久影视一区二区| 日本韩国欧美一区| 高清视频一区二区| 狠狠色丁香久久婷婷综| 五月综合激情婷婷六月色窝| 国产精品久久免费看| 精品久久国产老人久久综合| 欧美三级在线看| 99re这里只有精品视频首页| 国产成人综合在线播放| 美女久久久精品| 婷婷一区二区三区| 亚洲免费资源在线播放| 中国av一区二区三区| 久久久久9999亚洲精品| 日韩一区二区三区高清免费看看 | 麻豆精品一区二区| 亚洲欧美日韩久久| 中文字幕在线一区免费| 中文字幕av一区二区三区| 欧美精品一区二区三区久久久| 欧美卡1卡2卡| 欧美日韩综合在线| 在线观看免费一区| 欧洲日韩一区二区三区| 91亚洲男人天堂| 成人福利电影精品一区二区在线观看| 国产又黄又大久久| 国产一区二区视频在线| 久久69国产一区二区蜜臀| 麻豆91小视频| 狠狠色伊人亚洲综合成人| 精品一区二区三区免费视频| 久久国产综合精品| 久久99精品久久久| 精品一区二区三区久久| 久久91精品国产91久久小草| 精品一区二区三区在线观看国产| 喷水一区二区三区| 国产在线精品一区二区三区不卡| 激情五月婷婷综合网| 国产一区二区三区四区在线观看| 国产一区二区三区日韩| 高清国产一区二区三区| 99久久免费视频.com| 一本一道波多野结衣一区二区| 一本到不卡免费一区二区| 91成人免费在线视频| 欧美精品99久久久**| 欧美日韩不卡一区二区| 日韩欧美一区电影| 久久久久青草大香线综合精品| 亚洲国产精品99久久久久久久久| 国产精品网站一区| 一区二区三区四区中文字幕| 一区二区三区国产精品| 日本成人在线不卡视频| 国产精品99久久久久久久女警| 成人av免费观看| 欧美日韩美少妇| 精品福利一二区| 中文字幕一区二区三区蜜月| 亚洲国产成人精品视频| 精品无码三级在线观看视频| 成人午夜私人影院| 欧美日韩在线三级| 26uuu另类欧美| 亚洲欧美视频在线观看视频| 日韩高清在线不卡| 成人精品视频一区| 欧美日韩二区三区| 久久久精品免费观看| 亚洲精品国产第一综合99久久 | 亚洲精品国产一区二区精华液| 亚洲18女电影在线观看| 国产一区二区精品久久99| 一本到三区不卡视频| 精品国产a毛片| 一区二区三区毛片| 激情五月婷婷综合网| 91高清视频免费看| 久久久久久免费毛片精品| 一级女性全黄久久生活片免费| 国内精品伊人久久久久av一坑| 99久久综合精品| 91精品国产全国免费观看 | 成人免费视频在线观看| 日韩成人一区二区| 91丨九色丨蝌蚪富婆spa| 日韩欧美你懂的| 一个色综合网站| 国产精品一区二区在线观看网站| 欧洲国内综合视频| 国产亚洲短视频| 男女男精品视频网| 91福利在线播放| 国产欧美一区二区精品性| 偷拍亚洲欧洲综合| 91影院在线免费观看| 久久综合九色综合97婷婷| 亚洲成人av福利| 色综合久久久久综合99| 欧美国产亚洲另类动漫| 另类小说综合欧美亚洲| 欧美男同性恋视频网站| 最新国产成人在线观看| 国产成人三级在线观看| 日韩欧美一级在线播放| 日韩高清欧美激情| 欧美日韩电影在线| 亚洲国产精品尤物yw在线观看| 波多野结衣中文一区| 国产女同互慰高潮91漫画| 老司机精品视频在线| 欧美日韩国产成人在线91| 一区av在线播放| 色噜噜狠狠色综合中国| 一区在线播放视频| 成人国产精品免费网站| 国产欧美日产一区| 国产不卡视频在线播放| 国产香蕉久久精品综合网| 经典三级在线一区| 精品久久久久久最新网址| 麻豆极品一区二区三区| 日韩欧美你懂的| 国产综合色在线| 国产亚洲欧美中文| 国产99精品国产| 国产精品久久久一本精品 | 在线免费观看视频一区| 悠悠色在线精品| 欧美系列日韩一区| 亚洲国产一区二区在线播放| 欧美日韩精品一区视频| 午夜私人影院久久久久| 91精品久久久久久久91蜜桃| 男女男精品视频| 精品国一区二区三区| 国内精品嫩模私拍在线| 国产欧美一区视频| 99国产精品国产精品毛片| 亚洲美女屁股眼交3| 欧美在线不卡视频| 肉丝袜脚交视频一区二区| 91精品国产91综合久久蜜臀| 美女www一区二区| 国产偷国产偷亚洲高清人白洁| 国产成人午夜精品影院观看视频| 中文字幕欧美日韩一区| 91热门视频在线观看| 亚洲www啪成人一区二区麻豆 | 亚洲特级片在线| 欧美色老头old∨ideo| 美女视频黄 久久| 亚洲国产精品精华液2区45| 色婷婷精品大在线视频| 日韩av中文字幕一区二区| 久久久久久久一区| 91在线国产福利| 日韩成人av影视| 亚洲国产高清不卡| 欧美亚洲国产一区二区三区| 青青草国产精品97视觉盛宴| 久久久电影一区二区三区| 色综合一个色综合| 日本成人在线不卡视频| 中文字幕乱码一区二区免费| 91成人免费在线| 国产在线视视频有精品| 伊人开心综合网| 欧美成人精品高清在线播放| 成人小视频在线观看| 婷婷国产v国产偷v亚洲高清| 国产亚洲精品7777| 欧美美女bb生活片| 国产91在线观看丝袜| 亚洲a一区二区| 国产精品久久久久久久久动漫 | 欧美一区二区在线免费观看| 国产91高潮流白浆在线麻豆 | 国产高清成人在线| 亚洲成人av电影| 国产精品丝袜一区| 91精品国产欧美一区二区| 91猫先生在线| 国产成人综合自拍| 天堂在线一区二区| 亚洲美女偷拍久久| 国产亚洲午夜高清国产拍精品| 欧美日韩精品一区二区三区| 国产成人亚洲综合a∨婷婷| 日韩**一区毛片| 亚洲激情图片小说视频| 亚洲精品在线网站| 欧美精品自拍偷拍| 在线亚洲免费视频| 高清久久久久久|