]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
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 | ||
954b8ae6 JS |
10 | \wxheading{Include files} |
11 | ||
12 | <wx/event.h> | |
13 | ||
a660d684 KB |
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 | ||
f4fcc291 JS |
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} | |
5c180caf | 38 | void MyWindow::OnPaint(wxPaintEvent& event) |
f4fcc291 JS |
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. | |
5c180caf | 58 | void MyWindow::OnPaint(wxPaintEvent& event) |
f4fcc291 JS |
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: | |
62b4ae08 | 77 | // wxRect rect(upd.GetRect()); |
f4fcc291 JS |
78 | |
79 | // Repaint this rectangle | |
80 | ...some code... | |
81 | ||
82 | upd ++ ; | |
83 | } | |
84 | } | |
85 | \end{verbatim} | |
86 | }% | |
87 | ||
a660d684 KB |
88 | |
89 | \latexignore{\rtfignore{\wxheading{Members}}} | |
90 | ||
dcbd177f | 91 | \membersection{wxPaintEvent::wxPaintEvent}\label{wxpainteventctor} |
a660d684 KB |
92 | |
93 | \func{}{wxPaintEvent}{\param{int }{id = 0}} | |
94 | ||
95 | Constructor. | |
96 |