Introduction
The operation of the screen is a routine operation of control implementation. However, due to the inherent reasons of the screen itself, there are some problems, such as high cost, easy damage, and difficult maintenance. Therefore, computer virtual screen has become a suitable alternative. In the field of simulation, computer virtualization of the screen has become a better method. In the software compilation of the computer virtual screen, due to the particularity of the screen, there are some difficulties in the software compilation, such as the scaling, roaming, and rotation of the screen image.
C ++ Builder is one of the best technical platforms for Visual C Language Development Based on Windows. Using the basic components provided by C ++ Builder and functions of the Software Development Kit (Windows SDK ), A set of virtual screen software is developed based on the standard application window T form and its attributes and methods. The software provides effective solutions to some features of the console screen.
Pointer rotation and transparency displayed on the screen
The implementation of the needle table on the soft screen is the most common problem on the screen. The common software is to simplify the pointer appearance, that is, draw a line segment to represent the pointer. When the index table of the actual screen cannot be simplified, the software requires rotation of the pointer image.
Windows Graphics Device Interface (GDI) is independent of graphics devices when drawing images. It provides an abstraction layer between software and hardware. To convert the drawing coordinates to the drawing device coordinates, GDI designs a Data Structure XFORM. The structure is as follows:
Typedef struct _ XFORM {
FLOAT eM11; horizontal scaling factor, cosine of Rotation Angle
FLOAT eM12; horizontal proportional factor, sine of Rotation Angle
FLOAT eM21; vertical proportional factor, negative sine of Rotation Angle
FLOAT eM22; Vertical Scaling Factor, cosine of Rotation Angle
FLOAT eDx; horizontal conversion Deviation
FLOAT eDy; vertical conversion Deviation
} XFORM;
The coordinate of the graphic device (x', y') is converted according to the following formula:
X’ = x * eM11 + y * eM21 + eDx
Y’ = x * eM12 + y * eM22 + eDy
The following provides a complete program source code that contains the center point, pointer value, Range, angle range, zero point angle, and pointer bitmap, and comments as appropriate, to illustrate how to rotate a pointer bitmap.
Void _ fast call TForm1: rotatedraw (int x, int y,/* center point refers to the point around rotation */float ff, /* the pointer value is the value pointed to by the pointer */float hr, float lr,/* the range of the range is the display value range of the needle table */float scale0, float scale1, /* The angle range is the display angle range of the needle table */float rscale,/* the zero point angle is the minimum display numerical angle of the needle table */Graphics :: TBitmap * p/* the pointer bitmap is the standard horizontal bitmap pointer of the pointer from left to right */){
XFORM xform;
Float tf, f;
/* Prevent floating point overflow due to division by zero */
If (x = 0) x = 0.0001;
/* Rotation Angle conversion */
To = (ff-lr) * (scale0-scale1)/(hr-lr)-rscale;
F = 3.14159265 * tf/180;
/* Convert coordinate system definition */
Xform. eM11 = cos (f );
Xform. eM12 = sin (f );
Xform. eM21 =-sin (f );
Xform. eM22 = cos (f );
Xform. eDx = x-(sqrt (x * x + y * y) * (cos (f + atan (y/x); //-sin (f) * p-> Height/2;
Xform. eDy = y-(sqrt (x * x + y * y) * (sin (f + atan (y/x); //-cos (f) * p-> Height/2;
/* Convert coordinate system settings */
SetGraphicsMode (Form1-> Canvas-> Handle, GM_ADVANCED );
SetWorldTransform (Form1-> Canvas-> Handle, & xform );
/* Transparent mode */
P-> Transparent = true;
/* Transparent color definition */
P-> Transparent Color = p-> Canvas-> Pixels [0] [0];
/* Pointer painting */
Form1-> Canvas-> Draw (x, y, p );
/* Cancel in transparent mode */
P-> Transparent = false;
/* Convert Coordinate System Recovery Settings */
Xform. eM11 = 1;
Xform. eM12 = 0;
Xform. eM21 = 0;
Xform. eM22 = 1;
Xform. eDx = 0;
Xform. eDy = 0;
SetWorldTransform (Form1-> Canvas-> Handle, & xform );
}
This Code also involves the transparency of the image. Because the bitmap is rectangular, in order not to overwrite the background image, you can set other parts to a single color and define them as transparent colors, in this way, the image pointer can be rotated. However, when the screen is implemented, the image is not continuous. To solve this problem, you can set a dedicated Timer Point Timer. The interval can be set to 30 ms, in this way, the refresh frequency is higher than 24Hz, and the human eyes cannot feel discontinuous. In this way, you only need to select an appropriate increment or decrement range to realize the continuous movement of the pointer.
Roaming displayed on the screen
When a soft screen is displayed, while ensuring the definition of the screen, the screen size is sometimes greater than the full screen of the display, and the operator requires that the screen can be roaming, that is, dragging and moving the screen. To achieve this function, you can set the horizontal and vertical scroll bars-HorzScrollBar and VertScrollBar in the application window, and add the horizontal and vertical offset to the corresponding dynamic display coordinates. Modify the position attribute of the horizontal and vertical scroll bars in event processing for roaming. Example:
Use these two statements instead of the x and y coordinates for dynamic operations.
X-HorzScrollBar-> Position
Y-VertScrollBar-> Position
When performing a roaming operation
HorzScrollBar-> Position = HorzScrollBar-> Position + movx/* offset x */
VertScrollBar-> Position = VertScrollBar-> Position + movy;/* offset y */
Zooming and Font Processing of Screen Display
You can use the full picture to make the screen software. However, you still need to scale the screen. There are several ways to implement screen scaling. For example, you can modify the conversion coordinate system XFORM using the same image rotation method. The settings are as follows:
Xform. eM11 = X coordinate proportional factor;
Xform. eM12 = 0;
Xform. eM21 = 0;
Xform. eM22 = Y coordinate proportional factor ;;
Xform. eDx = offset x;
Xform. eDy = offset y;
In addition, you can add an image Timage to the standard application window Tform and set its Stretch attribute Stretch to TRUE. In this way, after an image of any size is loaded, the image will be adjusted to the image Timage size. This method is mainly used to change the window size.
For the scaling of a local image, you can use the third method to create a Tbitmap and draw it, then, the StretchBlt function is used to scale the image in the specified rectangle and copy it to the standard application window. This function applies to the size change of the local image, and the effect is better.
In the production of the screen software, many optical characters appear. To avoid drawing a large number of elements, you can copy the background image and modify the color. In the dynamic implementation, the transparent technology is used to call the CopyRect function of the standard application window to realize the optical character change within the specified rectangle. This technology can also be used to achieve dynamic changes to some special images.
Conclusion
C ++ Builder has been widely used. The Windows SDK (Software Development Kit) provides powerful functions to solve some problems of the virtual screen through the Windows Graphical device interface (GDI. These methods have been applied in many software programming and have achieved good results. The unique features of the GDI technology enable it to run normally in various systems, and meet the current image change needs in the software compilation of the virtual screen.