デバイスコンテキストの概要
Device context overview
Classes: wxDC, wxPostScriptDC,
wxMetafileDC, wxMemoryDC, wxPrinterDC,
wxScreenDC, wxClientDC, wxPaintDC,
wxWindowDC.
wxDC は、グラフィックやテキストを描画することが出来る
デバイスコンテキストdevice contextである。
デバイスコンテキストは、同じ API を使用することによって、
様々な出力デバイスを包括的に表現することを意図している。
幾つかのデバイスコンテキストはウィンドウを描画するために一時的に作成される。
これは、wxScreenDC、
wxClientDC、
wxPaintDC、
wxWindowDCにおいて正しい。以下の記述は、これ等の
デバイスコンテキストの違いと、どのように使用すべきかを述べたものである。
A wxDC is a
device context onto which graphics and text can be drawn.
The device context is intended to represent a number of output devices in a generic way,
with the same API being used throughout.
Some device contexts are created temporarily in order to draw on a window.
This is true of wxScreenDC, wxClientDC, wxPaintDC,
and wxWindowDC. The following describes the differences between
these device contexts and when you should use them.
- wxScreenDC. 独立したウィンドウではなく、スクリーン
(自体)にペイントする時に用いよ。
- wxClientDC. ウィンドウのクライアントエリア(ボーダーと他の飾り以外の部分)
にペイントする時に用いなさい。wxPaintEventの中から
使用してはならない。
- wxPaintDC. ウィンドウのクライアントエリアにペイントする時に用いよ。
wxPaintEventの中からのみ用いよ。
- wxWindowDC. 飾りを含む全てウィンドウの領域をペイントする時に用いよ。
Windows プラットフォームでない環境では無効かもしれない。
- wxScreenDC. Use this to paint on the screen, as opposed to an individual window.
- wxClientDC. Use this to paint on the client area of window (the part without
borders and other decorations), but do not use it from within an wxPaintEvent.
- wxPaintDC. Use this to paint on the client area of a window, but only from
within a wxPaintEvent.
- wxWindowDC. Use this to paint on the whole area of a window, including decorations.
This may not be available on non-Windows platforms.
client、paint あるいは window のデバイスコンテキストを使用するために、
ウィンドウを引数として、スタック上にオブジェクトを作成せよ。例えば:
To use a client, paint or window device context, create an object on the stack with
the window as argument, for example:
void MyWindow::OnMyCmd(wxCommandEvent& event)
{
wxClientDC dc(window);
DrawMyPicture(dc);
}
wxDCでパラメータライズされたコードを書くように心掛けよ。− このようにする
ことで、異なる多くのデバイスに対して、異なるデバイスコンテキストを通して、同様なコードを
書くことができるであろう。
このことは、いつでも有効であるとは限らない(例えば全てのデバイスコンテキストがビット
マップの描画をサポートしている訳ではない)が、大概の場合有効である。
Try to write code so it is parameterised by wxDC - if you do this, the same piece of code may
write to a number of different devices, by passing a different device context. This doesn't
work for everything (for example not all device contexts support bitmap drawing) but
will work most of the time.