]>
Commit | Line | Data |
---|---|---|
1 | \section{\class{wxPaintEvent}}\label{wxpaintevent} | |
2 | ||
3 | A paint event is sent when a window's contents needs to be repainted. | |
4 | ||
5 | \wxheading{Derived from} | |
6 | ||
7 | \helpref{wxEvent}{wxevent}\\ | |
8 | \helpref{wxObject}{wxobject} | |
9 | ||
10 | \wxheading{Include files} | |
11 | ||
12 | <wx/event.h> | |
13 | ||
14 | \wxheading{Event table macros} | |
15 | ||
16 | To process a paint event, use this event handler macro to direct input to a member | |
17 | function that takes a wxPaintEvent argument. | |
18 | ||
19 | \twocolwidtha{7cm} | |
20 | \begin{twocollist}\itemsep=0pt | |
21 | \twocolitem{{\bf EVT\_PAINT(func)}}{Process a wxEVT\_PAINT event.} | |
22 | \end{twocollist}% | |
23 | ||
24 | \wxheading{See also} | |
25 | ||
26 | %\helpref{wxWindow::OnPaint}{wxwindowonpaint}, | |
27 | \helpref{Event handling overview}{eventhandlingoverview} | |
28 | ||
29 | \wxheading{Remarks} | |
30 | ||
31 | Note that In a paint event handler, the application must {\it always} create a \helpref{wxPaintDC}{wxpaintdc} object, | |
32 | even if you do not use it. Otherwise, under MS Windows, refreshing for this and other windows will go wrong. | |
33 | ||
34 | For example: | |
35 | ||
36 | \small{% | |
37 | \begin{verbatim} | |
38 | void MyWindow::OnPaint(wxPaintEvent\& event) | |
39 | { | |
40 | wxPaintDC dc(this); | |
41 | ||
42 | DrawMyDocument(dc); | |
43 | } | |
44 | \end{verbatim} | |
45 | }% | |
46 | ||
47 | You can optimize painting by retrieving the rectangles | |
48 | that have been damaged and only repainting these. The rectangles are in | |
49 | terms of the client area, and are unscrolled, so you will need to do | |
50 | some calculations using the current view position to obtain logical, | |
51 | scrolled units. | |
52 | ||
53 | Here is an example of using the \helpref{wxRegionIterator}{wxregioniterator} class: | |
54 | ||
55 | {\small% | |
56 | \begin{verbatim} | |
57 | // Called when window needs to be repainted. | |
58 | void MyWindow::OnPaint(wxPaintEvent\& event) | |
59 | { | |
60 | wxPaintDC dc(this); | |
61 | ||
62 | // Find Out where the window is scrolled to | |
63 | int vbX,vbY; // Top left corner of client | |
64 | GetViewStart(&vbX,&vbY); | |
65 | ||
66 | int vX,vY,vW,vH; // Dimensions of client area in pixels | |
67 | wxRegionIterator upd(GetUpdateRegion()); // get the update rect list | |
68 | ||
69 | while (upd) | |
70 | { | |
71 | vX = upd.GetX(); | |
72 | vY = upd.GetY(); | |
73 | vW = upd.GetW(); | |
74 | vH = upd.GetH(); | |
75 | ||
76 | // Alternatively we can do this: | |
77 | // wxRect rect; | |
78 | // upd.GetRect(&rect); | |
79 | ||
80 | // Repaint this rectangle | |
81 | ...some code... | |
82 | ||
83 | upd ++ ; | |
84 | } | |
85 | } | |
86 | \end{verbatim} | |
87 | }% | |
88 | ||
89 | ||
90 | \latexignore{\rtfignore{\wxheading{Members}}} | |
91 | ||
92 | \membersection{wxPaintEvent::wxPaintEvent} | |
93 | ||
94 | \func{}{wxPaintEvent}{\param{int }{id = 0}} | |
95 | ||
96 | Constructor. | |
97 |