com.jniwrapper.win32.gdi
Class DC

java.lang.Object
  extended bycom.jniwrapper.Parameter
      extended bycom.jniwrapper.Pointer.Void
          extended bycom.jniwrapper.win32.Handle
              extended bycom.jniwrapper.win32.gdi.DC
All Implemented Interfaces:
com.jniwrapper.IntegerParameter, com.jniwrapper.PointerParameter
Direct Known Subclasses:
WindowDC

public class DC
extends Handle

This class provides methods for working with Windows device contexts (DC). It corresponds to HDC Windows data type.


Nested Class Summary
static class DC.MappingMode
          Enumeration of available mapping modes.
static class DC.RasterOperation
          The RasterOperation class represents the enumeration of raster operations.
 
Field Summary
static int BKMODE_LAST
           
static int BKMODE_OPAQUE
           
static int BKMODE_TRANSPARENT
          Background modes.
static int DC_PEN
           
static int DT_RIGHT
           
static long GRADIENT_FILL_RECT_H
           
static long GRADIENT_FILL_RECT_V
           
 
Fields inherited from class com.jniwrapper.win32.Handle
INFINITE_TIMEOUT, INVALID_HANDLE_VALUE, STATUS_ABANDONED_WAIT_0, STATUS_TIMEOUT, STATUS_WAIT_0
 
Fields inherited from class com.jniwrapper.Parameter
LICENSE_TYPE, V
 
Constructor Summary
DC()
           
DC(long value)
           
 
Method Summary
 boolean alphaBlend(int xDest, int yDest, int widthDest, int heightDest, DC hdcSrc, int xSrc, int ySrc, int widthSrc, int heightSrc, BlendFunction blendFunction)
          Copies an image with transparent pixels to the destination rectangle of the DC.
static void bitBlt(DC hdcDest, int xDest, int yDest, int width, int height, DC hdcSrc, int xSrc, int ySrc, DC.RasterOperation rop)
          Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context.
static DC createCompatibleDC(DC dc)
          Creates a compatible DC for a given DC.
static void deleteDC(DC dc)
          Deletes the specified DC.
 void drawGrayed(DC srcDC, Rect destRect)
          Draws the grayed picture from source DC on the current DC.
 boolean drawIcon(int x, int y, Icon icon)
          Draws a specified icon in this device context.
 void drawIconEx(int x, int y, Icon icon, int width, int heght, int frameIndex, Handle bgBrush, int flags)
          Draws a specified icon in this device context.
 boolean drawRectangle(Rect rect)
           
 void drawText(java.lang.String text, Rect clipRect, com.jniwrapper.UInt uFormat)
          Draws a specified text.
 void fillRect(Rect rect, Brush brush)
          Fills a given rectangle with a specified brush.
 boolean fillRectangle(int left, int top, int right, int bottom)
           
 void fillRegion(Region region, Brush brush)
          Fills a region by using the specified brush.
 void frameRegion(Region region, Brush brush, int width, int heigh)
          Draws a border around the specified region by using the specified brush.
 int getDeviceCaps(int index)
          Returns device-specific information for the specified device.
 ColorRef getPixel(int x, int y)
          Returns a color (by ColorRef) of the specified pixel on this device context.
 int getPolyFillMode()
          Retrieves the current polygon fill mode.
 Size getTextExtentPoint32(DC dc, java.lang.String str)
          Returns the size of a specified text.
 boolean gradientFill(Rect rect, java.awt.Color leftColor, java.awt.Color rightColor)
          Fills a rectangle by horisontal gradient.
 int intersectClipRect(int left, int top, int right, int bottom)
          Creates a new clipping region from the intersection of the current clipping region and the specified rectangle.
 boolean invertRegion(Region region)
          Inverts the colors in the specified region.
 boolean lineTo(int x, int y)
           
 void maskBlt(Bitmap.PredefinedBitmap predefinedMaskBitmap, int x, int y, Brush fgBrush)
          Paints a bitmap using a mask.
 boolean moveTo(int x, int y)
           
 void paintBitmap(Bitmap bitmap, int x, int y)
          Paints a bitmap on this device context.
 void paintOpaqueBitmap(Bitmap bitmap, int x, int y)
          Paints an opaque bitmap on this device context.
 boolean paintRegion(Region region)
          Paints the specified region by using the brush currently selected into the device context.
 boolean patBlt(int xLeft, int yLeft, int width, int height, DC.RasterOperation rasterOp)
          This method paints the specified rectangle using the brush that is currently selected into the specified device context.
 boolean rectangle(int left, int top, int right, int bottom)
           
 void release()
          Releases the current DC by calling its delete method.
 boolean roundRect(int left, int top, int right, int bottom, int arcWidth, int arcHeight)
           
 void selectClipRgn(Region region)
          Selects a given region as the current clipping region.
 Bitmap selectObject(Bitmap bitmap)
          Selects a specified bitmap in the device context.
 Brush selectObject(Brush brush)
          Selects a specified brush in the device context.
 Font selectObject(Font font)
          Selects a specified font in the device context.
 Pen selectObject(Pen pen)
          Selects a specified pen in the device context.
 Region selectObject(Region region)
          Selects the passed region in the device context.
 ColorRef setBkColor(ColorRef color)
          Sets the background color in this device context.
 int setBkMode(int bgMode)
          Sets the background mode in this device context.
static ColorRef setDCBrushColor(DC hDC, ColorRef clrref)
          This method sets the current device context (DC) brush color to the specified color value.
 ColorRef setDCPenColor(DC hDC, ColorRef colorRef)
          This method sets the current device context (DC) pen color to the specified color value or the nearest to the specified color value in case when the device cannot set the specified color value.
 DC.MappingMode setMapMode(DC.MappingMode mode)
          Sets the mapping mode of the specified device context.
 void setPolyFillMode(PolyFillMode polyFillMode)
          Sets the polygon fill mode for functions that fill polygons.
 ColorRef setTextColor(ColorRef color)
          Sets the text color in this device context.
static boolean stretchBlt(DC hDCDest, int xOriginDest, int yOriginDest, int widthDest, int heightDest, DC hDCSrc, int xOriginSrc, int yOriginSrc, int widthSrc, int heightSrc, DC.RasterOperation rasterOp)
          Copies a bitmap from a source rectangle into a destination rectangle, stretching or shrinking to fit the dimensions of the destination rectangle, if necessary.
 void textOut(int x, int y, java.lang.String text)
          Draws the text at given coordinates.
 void transparentBlt(Bitmap bitmap, int x, int y)
          Paints a transparent bitmap on screen DC.
 
Methods inherited from class com.jniwrapper.win32.Handle
clone, closeHandle, equals, waitFor, waitFor
 
Methods inherited from class com.jniwrapper.Pointer.Void
asFunction, asFunction, asTypedPointer, castTo, getDebugInfo, getLength, getValue, hashCode, isNull, read, setValue, toString, write
 
Methods inherited from class com.jniwrapper.Parameter
, a, a, acceptIOPerformer, asReturnValue, b, dataBufferAssigned, getAlignedLength, getAlignmentRequirement, getDataBuffer, getDataBufferOffset, indent, pop, push, read, read, setDataBuffer, toByteArray, write
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DC_PEN

public static final int DC_PEN
See Also:
Constant Field Values

BKMODE_TRANSPARENT

public static final int BKMODE_TRANSPARENT
Background modes.

See Also:
Constant Field Values

BKMODE_OPAQUE

public static final int BKMODE_OPAQUE
See Also:
Constant Field Values

BKMODE_LAST

public static final int BKMODE_LAST
See Also:
Constant Field Values

GRADIENT_FILL_RECT_H

public static final long GRADIENT_FILL_RECT_H
See Also:
Constant Field Values

GRADIENT_FILL_RECT_V

public static final long GRADIENT_FILL_RECT_V
See Also:
Constant Field Values

DT_RIGHT

public static final int DT_RIGHT
See Also:
Constant Field Values
Constructor Detail

DC

public DC()

DC

public DC(long value)
Method Detail

createCompatibleDC

public static DC createCompatibleDC(DC dc)
Creates a compatible DC for a given DC.

Parameters:
dc - DC to create a compatible one from.
Returns:
a compatible DC.

selectObject

public Brush selectObject(Brush brush)
Selects a specified brush in the device context.

Parameters:
brush - a brush to select.
Returns:
the previous brush.

selectObject

public Pen selectObject(Pen pen)
Selects a specified pen in the device context.

Parameters:
pen - a pen to select.
Returns:
the previous pen.

selectObject

public Bitmap selectObject(Bitmap bitmap)
Selects a specified bitmap in the device context.

Parameters:
bitmap - a bitmap to select.
Returns:
the previous bitmap.

selectObject

public Font selectObject(Font font)
Selects a specified font in the device context.

Parameters:
font - a font to select.
Returns:
the previous font.

selectObject

public Region selectObject(Region region)
Selects the passed region in the device context.

Parameters:
region - the region to select
Returns:
region

bitBlt

public static void bitBlt(DC hdcDest,
                          int xDest,
                          int yDest,
                          int width,
                          int height,
                          DC hdcSrc,
                          int xSrc,
                          int ySrc,
                          DC.RasterOperation rop)
Performs a bit-block transfer of the color data corresponding to a rectangle of pixels from the specified source device context into a destination device context. All coordinate parameters are in logical units.
NOTE: bitBlt does only clipping on the destination DC.

Parameters:
xDest - the x-coordinate of the upper-left corner of the destination rectangle.
yDest - the y-coordinate of the upper-left corner of the destination rectangle.
width - the width of the source and destination rectangles.
height - the height of the source and the destination rectangles.
xSrc - the x-coordinate of the upper-left corner of the source rectangle.
ySrc - the y-coordinate of the upper-left corner of the source rectangle.
rop - a raster-operation code.

stretchBlt

public static boolean stretchBlt(DC hDCDest,
                                 int xOriginDest,
                                 int yOriginDest,
                                 int widthDest,
                                 int heightDest,
                                 DC hDCSrc,
                                 int xOriginSrc,
                                 int yOriginSrc,
                                 int widthSrc,
                                 int heightSrc,
                                 DC.RasterOperation rasterOp)
Copies a bitmap from a source rectangle into a destination rectangle, stretching or shrinking to fit the dimensions of the destination rectangle, if necessary. The image transformation is determined by the stretching mode currently set in the device context. All coordinate parameters are in logical units.

Parameters:
hDCDest - a destination device context.
xOriginDest - the x-coordinate of the upper-left corner of the destination rectangle.
yOriginDest - the y-coordinate of the upper-left corner of the destination rectangle.
widthDest - the width of the destination rectangle.
heightDest - the height of the destination rectangle.
hDCSrc - source device context.
xOriginSrc - the x-coordinate of the upper-left corner of the source rectangle.
yOriginSrc - the y-coordinate of the upper-left corner of the source rectangle.
widthSrc - specifies the width of the source rectangle.
heightSrc - specifies the height of the source rectangle.
rasterOp - specifies the raster operation to be performed. Raster operation codes define how the system combines colors in output operations that involve a brush, a source bitmap, and a destination bitmap.
Returns:
nonzero if the method succeeds, zero if otherwise.

patBlt

public boolean patBlt(int xLeft,
                      int yLeft,
                      int width,
                      int height,
                      DC.RasterOperation rasterOp)
This method paints the specified rectangle using the brush that is currently selected into the specified device context. The brush color and the surface color or colors are combined by using the specified raster operation.

NOTE: The values of the rastOps parameter for this method are a limited subset of the full 256 ternary raster-operation codes; in particular, an operation code that refers to a source rectangle cannot be used.

Parameters:
xLeft - specifies the x-coordinate, in logical units, of the upper-left corner of the rectangle to be filled.
yLeft - specifies the y-coordinate, in logical units, of the upper-left corner of the rectangle to be filled.
width - specifies the width, in logical units, of the rectangle.
height - specifies the height, in logical units, of the rectangle.
rasterOp - specifies the raster operation code. This code can be one of the following values:
PATCOPY - Copies the specified pattern into the destination bitmap.
PATINVERT - Combines the colors of the specified pattern with the colors of the destination rectangle by using the Boolean XOR operator.
DSTINVERT - Inverts the destination rectangle.
BLACKNESS - Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette.)
WHITENESS - Fills the destination rectangle using the color associated with index 1 in the physical palette. (This color is white for the default physical palette.)
Returns:
If the method succeeds, the return value is non-zero. If the method fails, the return value is zero.

release

public void release()
Releases the current DC by calling its delete method.


deleteDC

public static void deleteDC(DC dc)
Deletes the specified DC.

Parameters:
dc - DC to be deleted.

textOut

public void textOut(int x,
                    int y,
                    java.lang.String text)
Draws the text at given coordinates.

Parameters:
x - the x-coordinate of the upper-left corner.
y - the y-coordinate of the upper-left corner.
text - a text to display.

drawText

public void drawText(java.lang.String text,
                     Rect clipRect,
                     com.jniwrapper.UInt uFormat)
Draws a specified text.

Parameters:
text - a text to be drawn.
clipRect - a clip rectangle for drawing.
uFormat - drawing format.

getTextExtentPoint32

public Size getTextExtentPoint32(DC dc,
                                 java.lang.String str)
Returns the size of a specified text.

Parameters:
dc - unused
str - a text to be measured.
Returns:
the size of text in DC.

drawIconEx

public void drawIconEx(int x,
                       int y,
                       Icon icon,
                       int width,
                       int heght,
                       int frameIndex,
                       Handle bgBrush,
                       int flags)
Draws a specified icon in this device context.

Parameters:
x - the x-coordinate of the image.
y - the y-coordinate of the image.
icon - the icon to be drawn.
width - the width of the drawn icon.
heght - the height of the drawn icon.
frameIndex - the frame index.
bgBrush - the background brush.
flags - drawing flags.

drawIcon

public boolean drawIcon(int x,
                        int y,
                        Icon icon)
Draws a specified icon in this device context.

Parameters:
x - the x-coordinate of the image.
y - the y-coordinate of the image.
icon - the icon to be drawn.
Returns:
the result of drawing: true if succeeds; false if fails.

setBkMode

public int setBkMode(int bgMode)
Sets the background mode in this device context.

Parameters:
bgMode - a new background mode.
Returns:
the previous background mode.

setBkColor

public ColorRef setBkColor(ColorRef color)
Sets the background color in this device context.

Parameters:
color - the background color.
Returns:
the previous background color.

setTextColor

public ColorRef setTextColor(ColorRef color)
Sets the text color in this device context.

Parameters:
color - the text color.
Returns:
the previous text color.

selectClipRgn

public void selectClipRgn(Region region)
Selects a given region as the current clipping region.

Parameters:
region - the region to be selected.

fillRegion

public void fillRegion(Region region,
                       Brush brush)
Fills a region by using the specified brush.

Parameters:
region - the region to fill.
brush - a brush to be used for painting.

frameRegion

public void frameRegion(Region region,
                        Brush brush,
                        int width,
                        int heigh)
Draws a border around the specified region by using the specified brush.

Parameters:
region -
brush -
width -
heigh -

getPolyFillMode

public int getPolyFillMode()
Retrieves the current polygon fill mode.

Returns:
polygon fill mode.

invertRegion

public boolean invertRegion(Region region)
Inverts the colors in the specified region.

Parameters:
region -
Returns:
If the function succeeds, the return value is true; otherwise false.

paintRegion

public boolean paintRegion(Region region)
Paints the specified region by using the brush currently selected into the device context.

Parameters:
region -
Returns:
If the function succeeds, the return value is true; otherwise false.

setPolyFillMode

public void setPolyFillMode(PolyFillMode polyFillMode)
Sets the polygon fill mode for functions that fill polygons.

Parameters:
polyFillMode -

getPixel

public ColorRef getPixel(int x,
                         int y)
Returns a color (by ColorRef) of the specified pixel on this device context.

Parameters:
x - the x-coordinate of pixel.
y - the y-coordinate of pixel.
Returns:
the color (by ColorRef) of the pixel.

setDCBrushColor

public static ColorRef setDCBrushColor(DC hDC,
                                       ColorRef clrref)
This method sets the current device context (DC) brush color to the specified color value. If the device cannot represent the specified color value, the color is set to the nearest physical color.

Parameters:
hDC - an instance of the DC class representing the current device context.
clrref - an instance of the ColorRef class representing the color for the brush.
Returns:
If the method succeeds, the return value specifies the previous DC brush color as a ColorRef value. If the method fails, the return value is CLR_INVALID.

setDCPenColor

public ColorRef setDCPenColor(DC hDC,
                              ColorRef colorRef)
This method sets the current device context (DC) pen color to the specified color value or the nearest to the specified color value in case when the device cannot set the specified color value.

Parameters:
hDC - an instance of the DC class.
colorRef - an instance of the ColorRef class.
Returns:
If the method succeeds, the return value specifies the previous DC pen color as instance of the ColorRef class.

transparentBlt

public void transparentBlt(Bitmap bitmap,
                           int x,
                           int y)
Paints a transparent bitmap on screen DC.

Parameters:
bitmap -
x -
y -

paintBitmap

public void paintBitmap(Bitmap bitmap,
                        int x,
                        int y)
Paints a bitmap on this device context.

Parameters:
bitmap - a bitmap to be painted.
x - the x-coordinate of the image.
y - the y-coordinate of the image.

paintOpaqueBitmap

public void paintOpaqueBitmap(Bitmap bitmap,
                              int x,
                              int y)
Paints an opaque bitmap on this device context.

Parameters:
bitmap - a bitmap to be painted.
x - the x-coordinate of the image.
y - the y-coordinate of the image.

alphaBlend

public boolean alphaBlend(int xDest,
                          int yDest,
                          int widthDest,
                          int heightDest,
                          DC hdcSrc,
                          int xSrc,
                          int ySrc,
                          int widthSrc,
                          int heightSrc,
                          BlendFunction blendFunction)
Copies an image with transparent pixels to the destination rectangle of the DC.

Parameters:
xDest - the x-coordinate of the upper-left corner for the destination rectangle.
yDest - the y-coordinate of the upper-left corner for the destination rectangle.
widthDest - the width of the destination rectangle.
heightDest - the height of the destination rectangle.
hdcSrc - DC that contains the image.
xSrc - the x-coordinate of the upper-left corner for the image.
ySrc - the y-coordinate of the upper-left corner for the image.
widthSrc - the width of the image.
heightSrc - the height of the image.
blendFunction - blend function.
Returns:
true if succeeds, false if fails.

drawGrayed

public void drawGrayed(DC srcDC,
                       Rect destRect)
Draws the grayed picture from source DC on the current DC. The function applies the effect to non-white pixels of the source DC.

Usage: paint some text, a transparent picture on a white background, and then use this function for screen DC (i.e. current DC must be screen DC).

Parameters:
srcDC - source DC.
destRect - a destination rectangle.

fillRect

public void fillRect(Rect rect,
                     Brush brush)
Fills a given rectangle with a specified brush.

Parameters:
rect - a rectangle to be filled.
brush - a brush to use for filling.

maskBlt

public void maskBlt(Bitmap.PredefinedBitmap predefinedMaskBitmap,
                    int x,
                    int y,
                    Brush fgBrush)
Paints a bitmap using a mask. The mask is a monochrome bitmap. The function paints pixels of the foreground color by black pixels of the mask. Other pixels of the current DC are not changed.

Precondition: the current DC is screen DC.

Parameters:
predefinedMaskBitmap - a predefined bitmap for the mask.
x - the x-coordinate of the upper corner for the destination rectangle.
y - the y-coordinate of the upper corner for the destination rectangle.
fgBrush - a brush for the foreground color.

gradientFill

public boolean gradientFill(Rect rect,
                            java.awt.Color leftColor,
                            java.awt.Color rightColor)
Fills a rectangle by horisontal gradient. Note: This function doesn't work on Windows 95 / NT.

Parameters:
rect - a rectangle for fill.
Returns:
true if succeeds.

lineTo

public boolean lineTo(int x,
                      int y)

moveTo

public boolean moveTo(int x,
                      int y)

drawRectangle

public boolean drawRectangle(Rect rect)

setMapMode

public DC.MappingMode setMapMode(DC.MappingMode mode)
Sets the mapping mode of the specified device context. The mapping mode defines the unit of measure used to transform page-space units into device-space units, and also defines the orientation of the device's x and y axes.

Parameters:
mode - Specifies the new mapping mode.
Returns:
previous mapping mode.

getDeviceCaps

public int getDeviceCaps(int index)
Returns device-specific information for the specified device.

Parameters:
index - index of capability.
Returns:
The return value specifies the value of the desired item.

intersectClipRect

public int intersectClipRect(int left,
                             int top,
                             int right,
                             int bottom)
Creates a new clipping region from the intersection of the current clipping region and the specified rectangle.

Parameters:
left - x-coord of upper-left corner
top - y-coord of upper-left corner
right - x-coord of lower-right corner
bottom - y-coord of lower-right corner
Returns:
value specifies the new clipping region's type and can be one of the following values.

rectangle

public boolean rectangle(int left,
                         int top,
                         int right,
                         int bottom)

roundRect

public boolean roundRect(int left,
                         int top,
                         int right,
                         int bottom,
                         int arcWidth,
                         int arcHeight)

fillRectangle

public boolean fillRectangle(int left,
                             int top,
                             int right,
                             int bottom)