Microsoft Windows Base Driver Using GDI+
This driver represents a base driver for all system-dependent drivers implemented in the Microsoft Windows system, but uses a new API called GDI+. Only the drivers Native Window, IUP, Image, Printer, EMF and Double Buffer were implemented. The drivers WMF and Clipboard, and the function cdPlay of the EMF driver were not implemented using GDI+.
The main motivation for the use of GDI+ was transparency for all the primitives. Beyond that we got other features like anti-aliasing, gradient filling, bezier lines, filled cardinal splines and world coordinate directly implemented by the driver.
This driver still does not completely replace the GDI Windows base driver, because GDI+ still does not have support for XOR. And the applications need to adapt because the rendering of text is slightly different from GDI. Also is know that GDI+ can be slower that GDI in some cases and faster in other cases, Microsoft does not make this clear.
So we let the programmer to choose what to use. We created the function cdUseContextPlus that allows activate or deactivate the use of GDI+ for the available drivers. This function affects only the cdCreateCanvas function call, once created the canvas will be always a GDI+ canvas. In fact the function affects primary the definitions CD_IUP, CD_NATIVEWINDOW, etc, because they are function calls and not static defines.
Using GDI+ it is allowed to create more that one canvas at the same time for the same Window. And they can co-exist with a standard GDI canvas.
To use the GDI+ based drivers you must call the function cdInitGdiPlus() once and link to the libraries "cdgdiplus.lib" and "gdiplus.lib". Also the file "gdiplus.dll" must be available in your system. These files already came with Visual C++ 7 and Windows XP. For other compiler you will need to copy the ".lib" file for you libraries area, and you will need to copy the DLL for the Windows\System (Win98/Me) or Windows\System32 (Win2000/NT4-SP6) folder.
In CDLUA it is not necessary any additional initialization.
The GDI+ has other features not explored by the drivers because of the CD limitations. But some of the features can be available through attributes, for example: other hatch styles, custom line styles, coordinates transformations, line start/join/end styles, text alignment in rectangles.
Exclusive Functions
int cdUseContextPlus(int use); [in C]
cdUseContextPlus(use: number) -> (old_use:
number) [in Lua]
Activates or deactivates the use of an external context for the next calls of the cdCreateCanvas function. This function is declared in the "cdgdiplus.h" header, because now it is useful only for GDI+. But it is implemented in the standard library.
void cdInitGdiPlus(void); [in C]
Initializes the GDI+ driver to be used as an external context replacing the traditional GDI drivers. This function is declared in the "cdgdiplus.h" header.
Behavior of Functions
Control
- cdPlay: does nothing, returns CD_ERROR.
Coordinate System and Clipping
- cdUpdateYAxis: the orientation of axis Y is the opposite to its orientation in the CD library.
Primitives
- cdPixel: uses GDI. Excepting when the canvas is an image so it is done using GDI+.
- cdMark: is simulated.
- cdSector: it also draws an arc in the same position to complete the size of the sector.
- cdText: opaque text is simulated using a rectangle in the back.
-
cdBegin: if the parameter
CD_CLIP is specified, the polygon created will be
used as a clipping polygon. Beyond the standard modes it accepts the
additional modes:: CD_BEZIER,
CD_FILLSPLINE, CD_IMAGEWARP,
CD_GRADIENT e CD_PATHGRADIENT. The
C definitions of these modes are available in the cdgdiplus.h header.
CD_BEZIER defines the points of a bezier curve. There must be 4 points at least: start, control, control and end. To specify a sequence of curves use 3 more points for each curve: control, control, end, control, control, end, ... The end point is used as start point for the next curve.
CD_FILLSPLINE defines the points of a filled curve constructed by a cardinal spline.
CD_IMAGEWARP defines 3 points of a parallelogram to warp the image. It affects all the cdPutImage* functions. The destination rectangle is ignored. Its use is only activated by the "IMAGEWARP" attribute. The specified points are: the upper-left corner, the upper right corner and the lower left corner.
CD_GRADIENT defines a filled interior style that uses a gradient between two colors. It uses 2 points only, one for the starting point using the foreground color, and another one for the end point using the background color.
CD_PATHGRADIENT defines a filled interior style that uses a gradient defined by a polygon and its center. The first point defines the center. The colors of the center and of the surrounding colors are defined by the "PATHGRADIENT" attribute, that must be set before the cdEnd function.
Attributes
- cdBackOpacity: only changes the transparency of the background color to 0 (transparent) or 255 (opaque).
- cdHatch: diagonal styles are drawn with anti-aliasing.
- cdWriteMode: does nothing. There is no support for XOR or NOT_XOR.
- cdPattern: each pixel can contain transparency information.
- cdLineStyle: uses a custom GDI+ style with the proportion of 3/3/9 for blank/dot/dash.
- cdFontDim: the maximum width is estimated from the character "W".
-
cdNativeFont: the font string
describer has the following format:
"fontname, size [style] [-k] [-u]", where fontname is the name of the font in Windows (notice the comma after the font name), size is given in points, style is the same as cdFont, -u means underline and -k means strikethrough, or "-d" to show the font-selection dialogue box. However, this function also accepts the font string used by the WINFONT attribute of the IUP library. - cdTextAlignment: is simulated. Although GDI+ has text alignment, the results for the CD were poor.
- cdFont: see the font mapping table for the equivalence used to map CD fonts into Windows fonts (note that in GDI+ there is no direct mapping for the system font):
CD Fonts | Windows Fonts |
---|---|
CD_SYSTEM | GenericSansSerif (usually MS Sans Serif) |
CD_COURIER | Courier New |
CD_TIMES_ROMAN | Times New Roman |
CD_HELVETICA | Arial |
Colors
- cdPalette: works only when the canvas is a server image.
- cdForeground e cdBackground: accepts the transparency information encoded in the color.
Client Images
- cdGetImageRGB: uses GDI. Excepting when the canvas is an image so it is done using GDI+.
Server Images
- cdGetImage: uses GDI. Excepting when the canvas is an image so it is done using GDI+.
- cdScrollArea: uses GDI. Excepting when the canvas is an image so it is done using GDI+.
WC
- Implemented directly in the driver.
Exclusive Attributes
- "ANTIALIAS": controls the use of anti-aliasing by the text, image zoom and line drawing primitives. Assumes values "1" (active) and "0" (inactive). Default value: "1".
- "IMAGEWARP": controls the use of the warping points for images. Assumes values "1" (active) and "0" (inactive). Default value: "1". The points must be initialized by cdBegin, cdVertex e cdEnd. See comment above.
- "PATHGRADIENT": necessary for the creation of the gradient fill defined by a polygon (see details in the function cdBegin above). The first color defines the color at the center. The number of following colors must be the same of the polygon vertices. It uses an array of longs, the first element is the total number of colors in the array. Use NULL to remove the attribute. It can not be retrieved.
- "IMAGETRANSP": defines an interval of colors to be considered transparent. It uses 2 longs for the two colors. Use NULL to remove the attribute. It can not be retrieved.
- "IMAGEFORMAT": defines the number of bits per pixel used by server images. It uses 1 long that can have the values: 32 or 24. Use NULL to remove the attribute. It can not be retrieved.