Esempio n. 1
0
        /**
         * Flushes any buffered pixel values to the appropriate texure targets, then restores the GL state to its previous
         * configuration before {@link #beginRendering(gov.nasa.worldwind.render.DrawContext, int, int, int, int)} was
         * called. Finally, all texture targets associated with this OGLRenderToTextureSupport are unbound.
         *
         * @param dc the current DrawContext.
         *
         * @throws ArgumentException if the DrawContext is null.
         */
        public void endRendering(DrawContext dc)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            this.flush(dc);

            if (this.useFramebufferObject(dc))
            {
                if (this.colorTarget != null)
                {
                    this.bindFramebufferColorAttachment(dc, null);
                }

                this.endFramebufferObjectRendering(dc);
            }

            this.stackHandler.pop(gl);
            this.drawRegion  = null;
            this.colorTarget = null;
        }
Esempio n. 2
0
 public override bool hit(java.awt.Rectangle rect, java.awt.Shape s, bool onStroke)
 {
     if (onStroke)
     {
         //TODO use stroke
         //s = stroke.createStrokedShape(s);
     }
     return(s.intersects(rect));
 }
Esempio n. 3
0
 public override java.awt.Rectangle getClipBounds(java.awt.Rectangle r)
 {
     using (Region clip = g.Clip)
     {
         if (!clip.IsInfinite(g))
         {
             RectangleF rec = clip.GetBounds(g);
             r.x      = (int)rec.X;
             r.y      = (int)rec.Y;
             r.width  = (int)rec.Width;
             r.height = (int)rec.Height;
         }
         return(r);
     }
 }
Esempio n. 4
0
        /**
         * Configures the GL attached to the specified DrawContext for rendering a 2D model to a texture. The modelview
         * matrix is set to the identity, the projection matrix is set to an orthographic projection aligned with the
         * specified draw rectangle (x, y, width, height), the viewport and scissor boxes are set to the specified draw
         * rectangle, and the depth test and depth write flags are disabled. Because the viewport and scissor boxes are set
         * to the draw rectangle, only the texels intersecting the specified drawing rectangle (x, y, width, height) are
         * affected by GL commands. Once rendering is complete, this should always be followed with a call to {@link
         * #endRendering(gov.nasa.worldwind.render.DrawContext)}.
         *
         * @param dc     the current DrawContext.
         * @param x      the x-coordinate of the draw region's lower left corner.
         * @param y      the y-coordinate of the draw region's lower left corner.
         * @param width  the draw region width.
         * @param height the draw region height.
         *
         * @throws ArgumentException if the DrawContext is null.
         */
        public void beginRendering(DrawContext dc, int x, int y, int width, int height)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            this.drawRegion = new java.awt.Rectangle(x, y, width, height);

            // Note: there is no attribute bit for framebuffer objects. The default framebuffer object state (object ID 0
            // is bound as the current fbo) is restored in endRendering().
            this.stackHandler.pushAttrib(gl,
                                         GL2.GL_COLOR_BUFFER_BIT   // For clear color.
                                         | GL2.GL_DEPTH_BUFFER_BIT // For depth test and depth mask.
                                         | GL2.GL_SCISSOR_BIT      // For scissor test and scissor box.
                                         | GL2.GL_TRANSFORM_BIT    // For matrix mode.
                                         | GL2.GL_VIEWPORT_BIT);   // For viewport state.

            this.stackHandler.pushTextureIdentity(gl);
            this.stackHandler.pushProjectionIdentity(gl);
            gl.glOrtho(x, x + width, y, y + height, -1, 1);
            this.stackHandler.pushModelviewIdentity(gl);

            // Disable the depth test and writing to the depth buffer. This provides consistent render to texture behavior
            // regardless of whether we are using copy-to-texture or framebuffer objects. For copy-to-texture, the depth
            // test and depth writing are explicitly disabled. For fbos there is no depth buffer components, so the depth
            // dest is implicitly disabled.
            gl.glDisable(GL.GL_DEPTH_TEST);
            gl.glDepthMask(false);
            // Enable the scissor test and set both the scissor box and the viewport to the specified region. This enables
            // the caller to set up rendering to a subset of the texture. Note that the scissor box defines the region
            // affected by a call to glClear().
            gl.glEnable(GL.GL_SCISSOR_TEST);
            gl.glScissor(x, y, width, height);
            gl.glViewport(x, y, width, height);

            if (this.useFramebufferObject(dc))
            {
                this.beginFramebufferObjectRendering(dc);
            }
        }
        public void beginDrawAnnotations(DrawContext dc, java.awt.Rectangle bounds)
        {
            if (dc == null)
            {
                String message = Logging.getMessage("nullValue.DrawContextIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            if (bounds == null)
            {
                String message = Logging.getMessage("nullValue.RectangleIsNull");
                Logging.logger().severe(message);
                throw new ArgumentException(message);
            }

            GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

            this.stackHandler.pushModelview(gl);
        }
Esempio n. 6
0
        public int[] getRGBPixels(java.awt.Rectangle r)
        {
            int      width  = r.width;
            int      height = r.height;
            Bitmap   bitmap = new Bitmap(width, height);
            Graphics g      = Graphics.FromImage(bitmap);

            g.CopyFromScreen(r.x, r.y, 0, 0, new Size(width, height));
            g.Dispose();
            int[] pixels = new int[width * height];
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    pixels[i + j * width] = bitmap.GetPixel(i, j).ToArgb();
                }
            }
            bitmap.Dispose();
            return(pixels);
        }
Esempio n. 7
0
        public override void setPaint(java.awt.Paint paint)
        {
            if (paint is java.awt.Color)
            {
                setColor((java.awt.Color)paint);
                return;
            }

            if (paint == null || this.javaPaint == paint)
            {
                return;
            }
            this.javaPaint = paint;

            if (paint is java.awt.GradientPaint)
            {
                java.awt.GradientPaint gradient = (java.awt.GradientPaint)paint;
                LinearGradientBrush linear;
                if (gradient.isCyclic())
                {
                    linear = new LinearGradientBrush(
                        J2C.ConvertPoint(gradient.getPoint1()),
                        J2C.ConvertPoint(gradient.getPoint2()),
                        composite.GetColor(gradient.getColor1()),
                        composite.GetColor(gradient.getColor2()));
                }
                else
                {
                    //HACK because .NET does not support continue gradient like Java else Tile Gradient
                    //that we receize the rectangle very large (factor z) and set 4 color values
                    // a exact solution will calculate the size of the Graphics with the current transform
                    Color color1 = composite.GetColor(gradient.getColor1());
                    Color color2 = composite.GetColor(gradient.getColor2());
                    float x1 = (float)gradient.getPoint1().getX();
                    float x2 = (float)gradient.getPoint2().getX();
                    float y1 = (float)gradient.getPoint1().getY();
                    float y2 = (float)gradient.getPoint2().getY();
                    float diffX = x2 - x1;
                    float diffY = y2 - y1;
                    const float z = 60; //HACK zoom factor, with a larger factor .NET will make the gradient wider.
                    linear = new LinearGradientBrush(
                        new PointF(x1 - z * diffX, y1 - z * diffY),
                        new PointF(x2 + z * diffX, y2 + z * diffY),
                        color1,
                        color1);
                    ColorBlend colorBlend = new ColorBlend(4);
                    Color[] colors = colorBlend.Colors;
                    colors[0] = colors[1] = color1;
                    colors[2] = colors[3] = color2;
                    float[] positions = colorBlend.Positions;
                    positions[1] = z / (2 * z + 1);
                    positions[2] = (z + 1) / (2 * z + 1);
                    positions[3] = 1.0f;
                    linear.InterpolationColors = colorBlend;
                }
                linear.WrapMode = WrapMode.TileFlipXY;
                brush = linear;
                pen.Brush = brush;
                return;
            }

            if (paint is java.awt.TexturePaint)
            {
                java.awt.TexturePaint texture = (java.awt.TexturePaint)paint;
                Bitmap txtr = J2C.ConvertImage(texture.getImage());
                java.awt.geom.Rectangle2D anchor = texture.getAnchorRect();
                TextureBrush txtBrush;
                brush = txtBrush = new TextureBrush(txtr, new Rectangle(0, 0, txtr.Width, txtr.Height), composite.GetImageAttributes());
                txtBrush.TranslateTransform((float)anchor.getX(), (float)anchor.getY());
                txtBrush.ScaleTransform((float)anchor.getWidth() / txtr.Width, (float)anchor.getHeight() / txtr.Height);
                txtBrush.WrapMode = WrapMode.Tile;
                pen.Brush = brush;
                return;
            }

            if (paint is java.awt.LinearGradientPaint) {
                java.awt.LinearGradientPaint gradient = (java.awt.LinearGradientPaint)paint;
                PointF start = J2C.ConvertPoint(gradient.getStartPoint());
                PointF end = J2C.ConvertPoint(gradient.getEndPoint());

                java.awt.Color[] javaColors = gradient.getColors();
                ColorBlend colorBlend;
                Color[] colors;
                bool noCycle = gradient.getCycleMethod() == java.awt.MultipleGradientPaint.CycleMethod.NO_CYCLE;
                if (noCycle) {
                    //HACK because .NET does not support continue gradient like Java else Tile Gradient
                    //that we receize the rectangle very large (factor z) and set 2 additional color values
                    //an exact solution will calculate the size of the Graphics with the current transform
                    float diffX = end.X - start.X;
                    float diffY = end.Y - start.Y;
                    SizeF size = GetSize();
                    //HACK zoom factor, with a larger factor .NET will make the gradient wider.
                    float z = Math.Min(10, Math.Max(size.Width / diffX, size.Height / diffY));
                    start.X -= z * diffX;
                    start.Y -= z * diffY;
                    end.X += z * diffX;
                    end.Y += z * diffY;

                    colorBlend = new ColorBlend(javaColors.Length + 2);
                    colors = colorBlend.Colors;
                    float[] fractions = gradient.getFractions();
                    float[] positions = colorBlend.Positions;
                    for (int i = 0; i < javaColors.Length; i++) {
                        colors[i + 1] = composite.GetColor(javaColors[i]);
                        positions[i + 1] = (z + fractions[i]) / (2 * z + 1);
                    }
                    colors[0] = colors[1];
                    colors[colors.Length - 1] = colors[colors.Length - 2];
                    positions[positions.Length - 1] = 1.0f;
                } else {
                    colorBlend = new ColorBlend(javaColors.Length);
                    colors = colorBlend.Colors;
                    colorBlend.Positions = gradient.getFractions();
                    for (int i = 0; i < javaColors.Length; i++) {
                        colors[i] = composite.GetColor(javaColors[i]);
                    }
                }
                LinearGradientBrush linear = new LinearGradientBrush(start, end, colors[0], colors[colors.Length - 1]);
                linear.InterpolationColors = colorBlend;
                switch (gradient.getCycleMethod().ordinal()) {
                    case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE:
                    case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.REFLECT:
                        linear.WrapMode = WrapMode.TileFlipXY;
                        break;
                    case (int)java.awt.MultipleGradientPaint.CycleMethod.__Enum.REPEAT:
                        linear.WrapMode = WrapMode.Tile;
                        break;
                }
                brush = linear;
                pen.Brush = brush;
                return;
            }

            if (paint is java.awt.RadialGradientPaint )
            {
                java.awt.RadialGradientPaint gradient = (java.awt.RadialGradientPaint)paint;
                GraphicsPath path = new GraphicsPath();
                SizeF size = GetSize();

                PointF center = J2C.ConvertPoint(gradient.getCenterPoint());

                float radius = gradient.getRadius();
                int factor = (int)Math.Ceiling(Math.Max(size.Width, size.Height) / radius);

                float diameter = radius * factor;
                path.AddEllipse(center.X - diameter, center.Y - diameter, diameter * 2, diameter * 2);

                java.awt.Color[] javaColors = gradient.getColors();
                float[] fractions = gradient.getFractions();
                int length = javaColors.Length;
                ColorBlend colorBlend = new ColorBlend(length * factor);
                Color[] colors = colorBlend.Colors;
                float[] positions = colorBlend.Positions;

                for (int c = 0, j = length - 1; j >= 0; )
                {
                    positions[c] = (1 - fractions[j]) / factor;
                    colors[c++] = composite.GetColor(javaColors[j--]);
                }

                java.awt.MultipleGradientPaint.CycleMethod.__Enum cycle = (java.awt.MultipleGradientPaint.CycleMethod.__Enum)gradient.getCycleMethod().ordinal();
                for (int f = 1; f < factor; f++)
                {
                    int off = f * length;
                    for (int c = 0, j = length - 1; j >= 0; j--, c++)
                    {
                        switch (cycle)
                        {
                            case java.awt.MultipleGradientPaint.CycleMethod.__Enum.REFLECT:
                                if (f % 2 == 0)
                                {
                                    positions[off + c] = (f + 1 - fractions[j]) / factor;
                                    colors[off + c] = colors[c];
                                }
                                else
                                {
                                    positions[off + c] = (f + fractions[c]) / factor;
                                    colors[off + c] = colors[j];
                                }
                                break;
                            case java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE:
                                positions[off + c] = (f + 1 - fractions[j]) / factor;
                                break;
                            default: //CycleMethod.REPEAT
                                positions[off + c] = (f + 1 - fractions[j]) / factor;
                                colors[off + c] = colors[c];
                                break;
                        }
                    }
                }
                if (cycle == java.awt.MultipleGradientPaint.CycleMethod.__Enum.NO_CYCLE && factor > 1)
                {
                    Array.Copy(colors, 0, colors, colors.Length - length, length);
                    Color color = colors[length - 1];
                    for (int i = colors.Length - length - 1; i >= 0; i--)
                    {
                        colors[i] = color;
                    }
                }

                PathGradientBrush pathBrush = new PathGradientBrush(path);
                pathBrush.CenterPoint = center;
                pathBrush.InterpolationColors = colorBlend;

                brush = pathBrush;
                pen.Brush = brush;
                return;
            }

            //generic paint to brush conversion for custom paints
            //the tranform of the graphics should not change between the creation and it usage
            using (Matrix transform = g.Transform)
            {
                SizeF size = GetSize();
                int width = (int)size.Width;
                int height = (int)size.Height;
                java.awt.Rectangle bounds = new java.awt.Rectangle(0, 0, width, height);

                java.awt.PaintContext context = paint.createContext(ColorModel.getRGBdefault(), bounds, bounds, C2J.ConvertMatrix(transform), getRenderingHints());
                WritableRaster raster = (WritableRaster)context.getRaster(0, 0, width, height);
                BufferedImage txtrImage = new BufferedImage(context.getColorModel(), raster, true, null);
                Bitmap txtr = J2C.ConvertImage(txtrImage);

                TextureBrush txtBrush;
                brush = txtBrush = new TextureBrush(txtr, new Rectangle(0, 0, width, height), composite.GetImageAttributes());
                transform.Invert();
                txtBrush.Transform = transform;
                txtBrush.WrapMode = WrapMode.Tile;
                pen.Brush = brush;
                return;
            }
        }
Esempio n. 8
0
 internal static Rectangle ConvertRect(java.awt.Rectangle rect)
 {
     return(new Rectangle(rect.x, rect.y, rect.width, rect.height));
 }
        protected void doDrawOnTo(BufferWrapperRaster canvas)
        {
            if (!this.getSector().intersects(canvas.getSector()))
            {
                return;
            }

            int    thisWidth            = this.getWidth();
            int    thisHeight           = this.getHeight();
            int    canvasWidth          = canvas.getWidth();
            int    canvasHeight         = canvas.getHeight();
            double thisTransparentValue = this.getTransparentValue();

            // Compute the transform from the canvas' coordinate system to this raster's coordinate system.
            java.awt.geom.AffineTransform canvasToThis = this.computeSourceToDestTransform(
                canvasWidth, canvasHeight, canvas.getSector(),
                thisWidth, thisHeight, this.getSector());

            /// Compute the region of the destination raster to be be clipped by the specified clipping sector. If no
            // clipping sector is specified, then perform no clipping. We compute the clip region for the destination
            // raster because this region is used to limit which pixels are rasterized to the destination.
            java.awt.Rectangle clipRect = new java.awt.Rectangle(0, 0, canvasWidth - 1, canvasHeight - 1);
//        if (clipSector != null)
//        {
//            java.awt.Rectangle rect = this.computeClipRect(clipSector, canvas);
//            clipRect = clipRect.intersection(rect);
//        }

            // Precompute the interpolation values for each transformed x- and y-coordinate.
            InterpolantLookupTable lut = this.createLookupTable(
                canvasWidth, canvasHeight,           // lookup table dimensions
                0, thisWidth - 1, 0, thisHeight - 1, // lookup table xMin, xMax, yMin, yMax
                canvasToThis);                       // lookup transform

            // If the lookup table is null, then no values in the canvas fall within this raster's bounds. This means
            // either the two rasters do not intersect or that this raster fits entirely between two x-coordinates or two
            // y-coordinates (or both) in the canvas. In either case, we do not rasterize any contribution from this raster
            // into the canvas, and simply exit.
            if (lut == null)
            {
                return;
            }

            // Allocate space to hold the lookup table parameters.
            double[] xParams = new double[3];
            double[] yParams = new double[3];

            // Compute the range of x-values in this raster that are needed during rendering.
            lut.computeRangeX(xParams);
            int xParamMin   = (int)Math.Floor(xParams[0]);
            int xParamMax   = (int)Math.Ceiling(xParams[1]);
            int xParamWidth = xParamMax - xParamMin + 1;

            // Allocate a buffer for two rows of samples from this raster, and allocate a buffer for one row of samples
            // from the canvas.
            double[] thisSamples = new double[2 * xParamWidth];
            double[] canvasSamples = new double[canvasWidth];
            int      x1, x2, y1, y2;
            double   xf, yf;

            // Iterate over each canvas row, filling canvas pixels with samples from this raster.
            for (int j = clipRect.y; j <= (clipRect.y + clipRect.height); j++)
            {
                // If the interpolant lookup table has an entry for "j", then process this row.
                if (lut.getInterpolantY(j, yParams))
                {
                    y1 = (int)yParams[0];
                    y2 = (int)yParams[1];
                    yf = yParams[2];
                    // Read the two rows of image samples that straddle yf.
                    this.get(xParamMin, y1, xParamWidth, thisSamples, 0);
                    this.get(xParamMin, y2, xParamWidth, thisSamples, xParamWidth);
                    // Read the canvas row samples.
                    canvas.get(0, j, canvasWidth, canvasSamples, 0);

                    // Iterate over each canvas column, sampling canvas pixels.
                    for (int i = clipRect.x; i <= (clipRect.x + clipRect.width); i++)
                    {
                        // If the interpolant lookup table has an entry for "i", then process this column.
                        if (lut.getInterpolantX(i, xParams))
                        {
                            x1 = (int)xParams[0] - xParamMin;
                            x2 = (int)xParams[1] - xParamMin;
                            xf = xParams[2];
                            // Sample this raster with the interpolated coordinates. This produces a bi-linear mix
                            // of the four values surrounding the canvas pixel. Place the output in the canvas sample array.
                            sample(thisSamples, x1, x2, xf, 0, 1, yf, xParamWidth, thisTransparentValue, canvasSamples, i);
                        }
                    }

                    // Write the canvas row samples.
                    canvas.put(0, j, canvasSamples, 0, canvasWidth);
                }
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Paint a representation of the value into a given area of screen
 /// real estate.  Note that the propertyEditor is responsible for doing
 /// its own clipping so that it fits into the given rectangle.
 /// <para>
 /// If the PropertyEditor doesn't honor paint requests (see isPaintable)
 /// this method should be a silent noop.
 ///
 /// </para>
 /// </summary>
 /// <param name="gfx">  Graphics object to paint into. </param>
 /// <param name="box">  Rectangle within graphics object into which we should paint. </param>
 public virtual void PaintValue(java.awt.Graphics gfx, java.awt.Rectangle box)
 {
 }