Symbian control development-ccoecontrol

Source: Internet
Author: User
Tags drawtext types of functions

Ccoecontrol is the base class of all controls. It encapsulates the basic attributes and functions of a control. The following three types of functions are involved in writing simple controls:Initialization,PlottingAndUser input processing. The following is a simple control declaration.
Class csimplecontrol: Public ccoecontrol
{
Public:
Void constuctl (const trect & arect );
~ Csimplecontrol ();
PRIVATE:
Void draw (const trect & arect) const;
Tkeyresponse offerkeyeventl (const tkeyevent & akeyevent, teventcode Atype );
};
Initialization: Controls initialization includes three main content: Create a control window, set the control size and activate the control. The default size of the control is 0x0, so you must set the size, otherwise it will be invisible. Therefore, these three steps are essential. Initialization is generally completed in the second phase of constructl.
Void csimplecontrol: contructl (const trect & arect)
{
Createmediawl ();
Setrect (arect );
Activatel ();
}
Plotting: The draw () function directly determines the control appearance.
Void csimplecontrol: Draw (const trect & arect) const
{
Cwindowgc & GC = systemgc ();
GC. setpenstyle (cgraphicscontext: enullpen );
GC. setpencolor (krgbred );
GC. setbrushcolor (krgbdarkblue );
GC. setbrushstyle (cgraphicscontext: esolidbrush );
GC. drawrect (arect );
}
In this Code, first call systemgc () to obtain the image context,Systemgc ()Is a member function of ccoecontrol, and then sets the corresponding graphic context item. Finally, call the drawing function drawrect () to draw a rectangle.
All plotting is done by graphics context (GC. In Symbian OS, an abstract class cgraphicscontext is defined to unify the graphic context interface, providing a wide range of APIS for device-independent plotting. Derived classCwindowgcAndCfbsbitgcThen these APIs are implemented. We can directly use cfbsbitgc for plotting, but this method is not recommended. In actual programming, the application should use cwindowgc to plot through the window server. The drawing request of cwindowgc is cached on the Client Buffer of the window server, so that multiple drawing requests can be submitted to the window server at one time to improve the drawing efficiency. Cone provides a cwindowgc instance for each GUI application as the control's default graphical context. It is created by cconenv and can be accessed using ccoecontrol: systemgc.

Graph context storage has the following context items that have an important impact on Graph functions. 1. Paint Brush: PEN defines the drawing mode (color, style, and size), which is used to draw lines, outlines, and text. 2. Brush: the brush defines the fill mode, background color, or style. 3. Font: font defines the font used to draw text. The image context does not have a default font. Therefore, you must call usefont () to set the font before using the relevant text function. In addition, after using the font, you must call discardfont () to delete the font to avoid Memory leakage. 4. Current position: the current position is set by moveTo () and various drawxxxto () member functions (absolute position), and moved by moveBy () and drawxxxby () (relative position ). 5. Origin: Origin defines the offset relative to the device's origin. This offset is used for plotting. You can use setorigin () to set the origin. The default origin is (0, 0 ). 6. Editing area: Clipping Region to define the area to be edited in graphic operations. You can specify a simple rectangle or any complicated area. After the editing area is set, only the plotting operations that fall within the editing area are displayed. You can use the setclippingrect () function to set the rectangular editing area and use cancelclippingrect () to cancel it. Use the setclippingregion () function to set any complicated editing area and use cancelclippingregion () you can use reset () to set all context items to the default value. The system automatically calls the reset () function before calling the draw () function. Therefore, you do not need to explicitly call this function in the control. After setting the graphic context, you can call various drawing functions to draw on the control. Almost all plotting functions are designed to be successfully executed, so generally no value is returned. This allows multiple plotting functions to be packaged as one message and sent to the server for execution. This is impossible if the plot function returns a value. (1) Point and line. These functions use the current paint brush. Virtual void plot (const tpoint & apoint); Virtual void drawline (const tpoint & apnt1, const tpoint & apnt2); Virtual void drawlineto (const tpoint & apoint ); virtual void drawlineby (const tpoint & avector); Virtual void drawarc (const trect & arect, const tpoint & astart, const tpoint & aend ); virtual void drawpolyline (const carrayfix <tpoint> * apointlist); Virtual void drawpolyline (const tpoint * apointlist, tint Numpoints); (2) solid profile graphics. These functions use paint brushes and paint brushes to draw outlines, and brushes to fill the interior of the outlines. Virtual void drawpie (const trect & arect, const tpoint & astart, const tpoint & aend); Virtual void drawellipse (const trect & arect); Virtual void drawrect (const trect & arect ); virtual void drawroundrect (const trect & arect, const tsize & aellipse); Virtual tint drawpolygon (const carrayfix <tpoint> * apointlist, tfillrule afillrule = ealternate ); virtual tint drawpolygon (const tpoint * apointlist, tint anumpoint S, tfillrule afillrule = ealternate); (3) the bitmap can be drawn in a ratio of or stretched to the size of the area of the specified rectangle. Virtual void drawbitmap (const tpoint & atopleft, const Region * asource); Virtual void drawbitmap (const trect & adestrect, const Region * asource); Virtual void drawbitmap (const trect & region, const cfbsbitmap * asource, const trect & asourcerect); (4) text. use the current font. Virtual void drawtext (const tdesc & astring, const tpoint & aposition); Virtual void drawtext (const tdesc & astring, const trect & abox, tint abaselineoffset, ttextalign ahoriz = eleft, tint aleftmrg = 0); plotting and repainting: In a GUI program, all the plotting is done on the control, and the drawing is done by the draw () function of the control, its declaration is as follows: Virtual void draw (const trect & arect) const;
The draw () of the base class ccoecontrol is empty. Therefore, this function must be implemented when writing the control; otherwise, the control will be invisible. Draw () is called by the application framework. Generally, draw () should not be called directly in the application (). Controls do not just redraw their appearances during initialization, but also when it changes or the system requires redraw. Based on the trigger source of the re-painting, there are two types of controls for re-painting: System-initiated re-painting and application-initiated re-painting. The System-initiated re-painting process starts from the window server. It detects and determines when to re-paint the window. In fact, it maintains an invalid area in the window and sends a redrawing event to the application that owns the window, requiring it to repaint the invalid area. The re-painting process initiated by the application is triggered by the application. It can be implemented using the following methods as needed (these functions are ultimately implemented by calling draw (): void ccoecontrol :: drawnow (); Re-paint the entire control immediately; void ccoecontrol: drawdeferred () const; Re-paint the entire control once there is a chance; void rwindow: invalidate (const trect &); the area of the rectangle specified by the parameter will be re-painted once the opportunity arises. However, by limiting the re-painting activity to a rectangle, there is almost no cost saved. Therefore, when writing most controls, the passing of the limit rectangle parameter is generally ignored.
User input processing:
Two basic functions for processing user input in Symbian OS are offerkeyeventl () and handlepointereventl (). Because the series60 platform does not support write input, offerkeyeventl () is used (). The following is a simple control code for handling key events:
Tkeyresponse csimplecontrol: offerkeyeventl (const tkenevent & akeyevent, teventcode Atype)
{
Switch (Atype)
{
Case: eeventkey:
If (akeyevent. iscancode = estdkeynkp5 | akeyevent. iscancode = estdkeyenter)
Imygameengine-> fire ();
Break;
Case: eeventkeydown:
//....
Case: eeventkeyup:
//....
}
Return ekeywasnotconsumed;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.