GDI

The GDI (Graphics Device Interface) is an interface for working with graphics. It is used to interact with graphic devices such as monitor, printer or a file. The GDI allows programmers to display data on a screen or printer without having to be concerned about the details of a particular device. The GDI insulates the programmer from the hardware.

GDI(Graphics Device Interface) は、グラフィクスを扱うインターフェースです。 モニタやプリンタ、ファイルといったグラフィックデバイスとのやり取りを行うために使用されます。 GDIのおかげでプログラマは特定のデバイスを意識することなく、スクリーンやプリンタにデータを出力することができます。 GDIはプログラマとハードウェアを切り離してくれるのです。

./img/gdi2.png

From the programmer's point of view, the GDI is a group of classes and methods for working with graphics. The GDI consists of 2D Vector Graphics, Fonts and Images.

プログラマという視点から見ると、GDIはグラフィクスを取り扱うためのクラスとメソッドの集合だと言えます。 GDIは2次元ベクタ画像、イメージ、フォントから構成されます。

To begin drawing graphics, we must create a device context (DC) object. In wxPython the device context is called wx.DC. The documentation defines wx.DC as a device context onto which which graphics and text can be drawn. It represents number of devices in a generic way. Same piece of code can write to different kinds of devices. Be it a screen or a printer. The wx.DC is not intended to be used directly. Instead a programmer should choose one of the derived classes. Each derived class is intended to be used under specific conditions.

wx.DCからの派生クラス

The wx.ScreenDC is used to draw anywhere on the screen. The wx.WindowDC is used if we want to paint on the whole window (Windows only). This includes window decorations. The wx.ClientDC is used to draw on the client area of a window. The client area is the area of a window without it's decorations (title and border). The wx.PaintDC is used to draw on the client area as well. But there is one difference between the wx.PaintDC and the wx.ClientDC. The wx.PaintDC should be used only from a wx.PaintEvent. The wx.ClientDC shoud not be used from a wx.PaintEvent. The wx.MemoryDC is used to draw graphics on the bitmap. The wx.PostScriptDC is used to write to PostScript files on any platform. The wx.PrinterDC is used to access a printer (Windows only).

wx.ScreenDC はスクリーン上の任意の場所に描画する際に使用されます。 wx.WindowDC はウィンドウ全体に描画したい時に使用されます(Windowsのみ)。 これは、ウィンドウの装飾も含みます。 wx.ClientDC

TODO シンプルな直線を描画する

最初の例は、ウィンドウのクライアント領域にシンプルな直線を描画するものです。

DrawLine(int x1, int y1, int x2, int y2)

このメソッドは1つ目の点から2つ目の点に向かって直線を描画します。 このとき2つ目の点は直線に含まれません。

#! /usr/bin/env python

# line1.py

import wx

class Line(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250, 150))

        wx.FutureCall(2000, self.DrawLine)

        self.Centre()
        self.Show(True)

    def DrawLine(self):
        dc = wx.ClientDC(self)
        dc.DrawLine(50, 60, 190, 60)

app = wx.App()
Line(None, -1, 'Line')
app.MainLoop()

TODO 2次元ベクタ画像

Date: 2010-10-21 06:23:18 JST

HTML generated by org-mode 6.21b in emacs 23