4.1 WINDOW, Graphics Context and Graphics Device
4.1.1 Window
In the Symbian OS, all drawings are performed in the window, and the window is an essential unit that interacts with the system. Before we draw a drawing, we must first declare a window:
CREATEWINDOWL ();
Then set the size of the window via setRect ().
SetRect (all);
After we can draw a drawing.
4.1.2 Graphics Context
In the Symbian system, all drawings are done through Graphics Context. These include drawing points, drawing rectangles, and drawing text. All Graphics Context is derived from the CGRAPHICSCONTENT class.
The CGRAPHICSCONTENT classes include:
Paint Brush: Represents all the drawings of the current graphics context to be drawn, including color, width, style, etc., can be set by setpencolor (), setPensize (), setPenStyle ().
Brush: Represents the current graphics context to fill the drawing mode, including fill color, style, background color, etc., can be made by setbrushcolor (), setbrushorigin (), setbrushlectle (), usebrushpattern (), discardbrushpattern (), etc. Set.
Font: Indicates that Graphics Contex is currently using the font to draw text, using the usefont (), discardFont () method to set or cancel the font.
Position: Represents the current location of Graphics Contex. You can change the current position by Moveby (), MoveTo ().
Origin: Defines the offset relative to the origin of the device, the default value is (0, 0), can be changed by seorigin ().
Clipping: Define the area that needs to be cropped, setting or cancel the cropping area by setClippingRect ().
4.1.3 Graphics Device
In the Symbian system, we implemented Graphics Device through CGRAPHICSDEvice, and he specified the interface of the specific device class we have to operate.
4.2 Basic drawing function
After setting up CGRAPHICSCONTENT, we can draw graphics in the window by calling the relevant method.
4.2.1 Text:
Void DrawText (Const Tdesc & Atext, Const Tposition)
Void DrawText (Const TDesc & Atext, Const Treat & Abox, Tint Abaselineoffset, TtextAlignment = ELEFT, TINT ALEFTMARGIN = 0)
The first one of them draws text directly in the window, where Atext gives the text content to be drawn, and aposition has set the starting position to draw text.
The second is to draw a rectangular outer frame at a given ABOX while drawing the text. The aalignment parameter specifies the direction of the text, default is left aligned; ALEFTMARGIN specifies the interval distance, the default value is 0. Since the memory of the Symbian system is limited, the font system that is not used is not transferred, so we should first use the usefont () to set the system before drawing text:
Void UseFont (Const CFont * AFONT)
This system will transfer the font into memory.
After we don't use this font, in order to save memory, use discardFont () to release fonts in memory.
Void DiscardFont ()
4.2.2 points:
We draw a separate point via plot (). Point drawing mode is the same as the current brush (PEN) setting. Void Plot (Const TPoint & Apoint)
When the width of the brush is greater than one pixel, the system will be a circle in Apoint, the width of the brush is drawn in diameter, and the circle is filled with the color of the brush.
4.2.3 Lines:
Drawing a straight line There is Drawline (), DrawLineby (), DrawlineTo (), and DrawPolyline (), Drawarc (), and draw mode the same as the current brush (PEN) settings.
Void Drawline (Const Tpoint & Apoint1, Const Tpoint & Apoint2)
Drawline () draws a straight line between Apoint1 and APONIT2.
Void Drawlineto (Const Tpoint & Apoint)
Drawlineto () draws a straight line from the current point to Apoint.
Void Drawlineby (Const Tpoint & Avector)
Drawlineby () draws a straight line from the current point to the relative to the current point position.
Void DrawPolyline (const carrayfix
DrawPolyLine () draws a straight line from the first point from the first point based on a given position array, and then draws a straight line to the third point with the second point. . . . . . Until the last point.
One thing to note here is that when drawing a straight line, the system does not draw the last point of the straight line, if we want to draw a straight line including the last point, we can use the last PLOT () method to draw the last point.
4.2.4 Graphics:
We can use the system to draw five simple graphics directly, rectangle, Rounded Rectangle, polygon, elliptical (Ellipse), and PIE Slice. Draw mode and fill mode are the same as the current brush (PEN), brush (brush) settings
rectangle:
Void DrawRect (Const Treat & Arect)
DrawRect () draws a rectangle according to a given Arect on the screen.
Rounded Rectangle:
Void DrawroundRect (Const Treat & Arect, Const Tsize & Acornersize)
DrawroundRect () draws a rectangle on the screen and determines the diameter of the fillet based on a given Acornersize. Polygon:
Tint DrawPolygon (Const Carrayfix
Tint DrawPolygon (Const Tpoint * Apointlist, Tint Anumpoints, TFillrule Afillrule = Ealternate)
DrawPolygon () is sequentially connected in sequence according to a given point set apointlist and fills the polygon in accordance with the AfillRule rules.
Oval:
Void Drawellipse (Const Treat & Arect)
Drawellipse () Draw an ellipse in a given Arect area. If a given area is a square, a circle will be drawn.
Pie shape:
Void Drawpie (Const Treat & Arect, Const TPoint & Astart, Const Tpoint & And)
Drawpie () intercepts the corresponding pie region within the ellipse formed by Arect by a given start point ASTART and end point.
4.3 Reading and display of BMP files
4.3.1 Read:
First we define the bitmap you want to read:
_LIT (KmultiBitmapFileName, "// system // apps // graphics // images.mbm");
Among them, Images.mdm is the result of our bitmap file through the compressed package, is a multi-bit diagram file. We must be in the .mmp file as follows:
Start Bitmap images.mbm
HEADER
TargetPath / System / Apps / Graphics
SourcePath ../bitmaps
Source C12 Image1.bmp
Source C12 Image2.BMP
End
The system generates a bitmap header file. MBG, this header file provides an ID of the access bitmap. For example, the images.mbg file in EPOC32 / Include contains the following:
ENUM TMBMIMAGES {
Embmimagesimage1,
Embmimagesimage2,
}
Next we define:
Cfbsbitmap * iimage1;
Cfbsbitmap * iimage2;
Then we can read the bitmap files in the MDM:
IIMAGE1 = New (Eleave) cfbsbitmap ();
Cleanupstack :: Pushl (iimage1);
Tint loadException = iimage1 -> loading (kmultibitmapfilename, embmimagesimage1);
User :: Leaveiferror (LoadException);
Cleanupstack :: POP (iimage1);
4.3.2 Display:
By using the DrawbitMap () method, you can display or draw a bitmap in the window.
Void DrawbitMap (Const Tpoint & AtopleFT, Const Cfbsbitmap * Asource)
Here, atopleft specifies the upper left corner coordinate of the bitmap to be drawn, and Asource gives the contents of the bitmap to be drawn.
Void DrawbitMap (Const Treat & ADest, Const Cfbsbitmap * Asource) Draws the given bitmap Asource in the specified rectangular area ADestRect.
Void DrawbitMap (Const Treat & ADest, Const Cfbsbitmap * Asource, Const Treat & Asource)
Intercept the AsourceRect area in the given bitmap asource, draw its content in the specified rectangular area ADestRect.
4.4 pixel processing
Bitchart can be processed by using some methods of the Tbitmaputil class. include:
Void BEGIN (Const TPOINT & APOTION): Set the pixel location of the currently processed and lock the heap.
Void end (): Unlocking the pile.
Void SetPOS (Const Tposition): Change the current pixel location to aposition.
Void incxos (): From the current X coordinate from 1.
Void decxpos (): Causes the current X coordinate from 1.
Void Incypos (): From the current Y coordinate from 1.
Void decypos (): Causes the current Y coordinate from 1.
Tuint32 getpixel () Const: Get the RGB value of the current pixel.
Void SetPixel: Set the RGB value of the current pixel.
By using the operation of the TbitmapUtil class by writing a bitmap to the operation in another bitmap.
Use the bitmap that has been generated and read in front: cfbsbitmap * iimage1 and cfbsbitmap * iimage2. Here, IIMAGE2 is greater than IIMAGE1, we will reverse IIMAGE1 in IIMAGE2
Firstly, the bitmap to be operated:
Tbitmaputil Bitmap1UTIL (IBITMAP1);
Tbitmaputil Bitmap2UTIL (iBITMAP2);
Next, start the bitmap operation and set the initial point (0,0):
Bitmap1UTIL.BEGIN (TPOINT (0,0));
Bitmap2UTIL.BEGIN (TPOINT (0, 0));
Next, read from ibitmap1 by pixel and write ibitmap2:
Tsize Insize = ibitmap1-> sizeinpixels ();
Tint XPOS;
FOR (Tint Ypos = 0; YPOS { Bitmap1UTIL.SETPOS (TPOINT (0, YPOS)); Bitmap2UTIL.SETPOS (TPOINT (YPOS, 0)); For (XPOS = 0; xpos { Bitmap2UTIL.SETPIXEL (Bitmap1UTIL); Bitmap1util.incxpos (); Bitmap2util.incypos (); } } Finally, the operation, clean the stack Bitmap1UTIL.END (); Bitmap2UTIL.END (); In this way, we have completed the work that reversible IIMAGE1 and writes in iimage2.