⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtgraphics.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* QtGraphics.java --   Copyright (C)  2005  Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.java.awt.peer.qt;import java.awt.AlphaComposite;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Composite;import java.awt.GradientPaint;import java.awt.GraphicsConfiguration;import java.awt.Font;import java.awt.FontMetrics;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.RenderingHints;import java.awt.Rectangle;import java.awt.Paint;import java.awt.Polygon;import java.awt.Shape;import java.awt.Stroke;import java.awt.font.FontRenderContext;import java.awt.font.GlyphVector;import java.awt.geom.AffineTransform;import java.awt.geom.PathIterator;import java.awt.geom.Arc2D;import java.awt.geom.Ellipse2D;import java.awt.geom.Line2D;import java.awt.geom.Rectangle2D;import java.awt.geom.RoundRectangle2D;import java.awt.image.BufferedImage;import java.awt.image.BufferedImageOp;import java.awt.image.ImageObserver;import java.awt.image.RenderedImage;import java.awt.image.renderable.RenderableImage;import java.text.AttributedCharacterIterator;import java.text.CharacterIterator;import java.util.Map;/** * QtGraphics is an abstract implementation of Graphics2D over a QPainter * object. This is to be subclassed for different drawing contexts,  * which may have different requirements. */public abstract class QtGraphics extends Graphics2D{  /**   * Native QPainter pointer.   */  protected long nativeObject;  private static final AffineTransform identity = new AffineTransform();  // Graphics state  protected Font font;              // Current font.  protected Color color, bgcolor;   // Current color and background color.  protected Shape clip;             // Current clipping area.  protected Shape initialClip;      // Initial clip bounds  protected AffineTransform xform;  // Current transform  protected Stroke currentStroke;   // the current stroke  protected boolean nativeStroking; // whether we're using Qt's stroking or not  protected Composite composite; // current composite operator  protected double currentAlpha; // current alpha  protected Paint currentPaint;  // current paint  protected RenderingHints renderingHints; // the rendering hints.  /**    * Owner Graphics, used by subcontext created by create()   * to avoid GC of the original context.    */  Graphics parent;  /**   * Do-nothing constructor.   */  QtGraphics()  {  }  /**   * Copying constructor - used by copy() and subclasses.   */  QtGraphics(QtGraphics parent)  {    cloneNativeContext( parent );    setFont( parent.getFont() );    setAlpha( parent.currentAlpha );    setBackground( parent.getBackground() );    setColor( parent.getColor() );    setClip( (initialClip = parent.getClip()) );    setTransform( parent.getTransform() );    setStroke( parent.getStroke() );    setComposite( parent.getComposite() );    setPaint( parent.getPaint() );    setRenderingHints( parent.getRenderingHints() );  }  /**   * Set up some generic defaults.   */  protected void setup()  {    font = new Font ("Dialog", Font.PLAIN, 12);    setTransform( identity );    setStroke( new BasicStroke() );    renderingHints = new RenderingHints( null );  }  public synchronized native void delete();  public void dispose()  {  }  // ********************** etc *******************************  private void resetClip()  {    AffineTransform current = getTransform();    setTransform( identity );    setClip( initialClip );        setTransform( current );  }  protected native void initImage(QtImage image);    protected native void initVolatileImage(QtVolatileImage image);    // Creates a new native QPainter object on the same context.  private native void cloneNativeContext( QtGraphics parent );  private native void setColor(int r, int g, int b, int a);  private native void drawNative( QPainterPath p );  private native void fillNative( QPainterPath p );  private native void setClipNative( QPainterPath p );  private native void setClipRectNative( int x, int y, int w, int h );  private native void intersectClipNative( QPainterPath p );  private native void intersectClipRectNative( int x, int y, int w, int h );  private native void setQtTransform(QMatrix m);  private native void setNativeStroke(QPen p);  private native void setNativeComposite(int alphaMode);  private native void drawStringNative(String string, double x, double y);  private native void setLinearGradient(int r1, int g1, int b1, 					int r2, int g2, int b2, 					double x1, double y1, 					double x2, double y2, boolean cyclic);  private native void setAlphaNative(double alpha);  private native void setFontNative(QtFontPeer font);  private native QPainterPath getClipNative();  void setAlpha(double alpha)  {    currentAlpha = alpha;    setAlphaNative(currentAlpha);  }  // ************ Public methods *********************  /**   * Context-sensitive methods are declared abstract.   */  public abstract Graphics create();  public abstract void copyArea(int x, int y, int width, int height, 				int dx, int dy);  public abstract GraphicsConfiguration getDeviceConfiguration();  public Color getColor()  {    return new Color(color.getRed(), color.getGreen(), color.getBlue());  }  public void setColor(Color c)  {    if( c == null )      c = Color.white;    this.color = c;     int alpha = (int)(c.getAlpha() * currentAlpha);    setColor(c.getRed(), c.getGreen(), c.getBlue(), alpha);  }  public void setBackground(Color color)  {    bgcolor = new Color(color.getRed(), color.getGreen(), color.getBlue());  }  public Color getBackground()  {    return new Color(bgcolor.getRed(), bgcolor.getGreen(), bgcolor.getBlue());  }  public void setPaintMode()  {  }  public void setXORMode(Color color)  {    // FIXME  }  public boolean hit(Rectangle rect, Shape s, boolean onStroke)  {    if( onStroke )      {	Shape stroked = currentStroke.createStrokedShape( s );	return stroked.intersects( (double)rect.x, (double)rect.y, 				   (double)rect.width, (double)rect.height );      }    return s.intersects( (double)rect.x, (double)rect.y, 			 (double)rect.width, (double)rect.height );  }  // ******************* Font ***********************    public Font getFont()  {    return font;  }  public void setFont(Font font)  {    if( font == null )      return;    this.font = font;    if(font.getPeer() != null && font.getPeer() instanceof QtFontPeer)      setFontNative( (QtFontPeer)font.getPeer() );  }  public FontMetrics getFontMetrics(Font font)  {    return new QtFontMetrics(font, this);  }  // ***************** Clipping *********************  /**   * Intersects the current clip with the shape   */  public void clip(Shape s)  {    intersectClipNative( new QPainterPath( s ) );  }  public void clipRect(int x, int y, int width, int height)  {    intersectClipRectNative( x, y, width, height );  }  public void setClip(int x, int y, int width, int height)  {    setClipRectNative( x, y, width, height );  }  public Shape getClip()  {     return getClipNative().getPath();  }  public native Rectangle getClipBounds();  /**   * Sets the clip   */  public void setClip(Shape clip)  {    if (clip == null)      resetClip();    else      setClipNative(new QPainterPath( clip ));  }  // ***************** Drawing primitives *********************  public void draw(Shape s)  {     if( nativeStroking )      drawNative( new QPainterPath(s) );    else      fillNative( new QPainterPath( currentStroke.createStrokedShape( s ) ) );  }  public void fill(Shape s)  {    fillNative( new QPainterPath(s) );  }  public void drawLine(int x1, int y1, int x2, int y2)  {    if( nativeStroking )      drawNative( new QPainterPath((double)x1, (double)y1, (double)x2, (double)y2, true) );    else      draw( new Line2D.Double((double)x1, (double)y1, (double)x2, (double)y2) );  }  public void drawRect(int x, int y, int width, int height)  {    if( nativeStroking )      drawNative( new QPainterPath((double)x, (double)y, 				   (double)width, (double)height) );    else      fillNative( new QPainterPath		  ( currentStroke.createStrokedShape		    (new Rectangle2D.Double		     ((double)x, (double)y, 		      (double)width, (double)height) ) ) );  }  public void fillRect(int x, int y, int width, int height)  {    fillNative( new QPainterPath( x, y, width, height ) );  }  public void clearRect(int x, int y, int width, int height)  {    Color c = color;    setColor( bgcolor ); // FIXME    fillRect( x, y, width, height );    setColor( c );  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -