テトリスのソースを読む(その5)
個々のブロックを描くのに、wxPaintDCクラスを使っている。その使い方は、
http://www.harukaze.net/~haruka/wxpython/wxpy18.htmlに詳しい。とても良く分かる。
メソッドdrawSquareを見る。
def drawSquare(self, dc, x, y, shape): ...(略) pen = wx.Pen(light[shape]) # 線の色を決める pen.SetCap(wx.CAP_PROJECTING) # 端点のスタイルを指定(直線で切断) dc.SetPen(pen) dc.DrawLine(x, y+self.squareHeight()-1, x, y) # 直線を引く(始点の座標、終点の座標) dc.DrawLine(x, y, x+self.squareWidth()-1, y) darkpen = wx.Pen(dark[shape]) # 繰り返し darkpen.SetCap(wx.CAP_PROJECTING) dc.SetPen(darkpen) dc.DrawLine(x+1, y+self.squareHeight()-1, x+self.squareWidth()-1, y+self.squareHeight()-1) dc.DrawLine(x+self.squareWidth()-1, y+self.squareHeight()-1, x+self.squareWidth()-1, y+1) # ここまでで辺が4つ描ける dc.SetPen(wx.TRANSPARENT_PEN) # 透明なペン??? dc.SetBrush(wx.Brush(colors[shape]) # 今度はペンでなくブラシ dc.DrawRectangle(x+1, y+1, self.squareWidth()-2, self.squareHeight()-2) # 長方形を描く(ブラシだから塗りつぶし)