Чтение онлайн

ЖАНРЫ

Применение Windows API

Легалов А. И.

Шрифт:

 BitmapCanvas bmpCanvas(canvas, bmp);

 RECT rect = { 0, 0, _cx, _cy };

 bmpCanvas.WhiteWash(rect);

 // Do the off-line drawing

 Blitter bltBkg(_background);

 bltBkg.BlitTo(bmpCanvas);

 int xRange = (_widthBkg - _widthSprite) / 2;

 int yRange = (_heightBkg - _heightSprite) / 2;

 int x = xRange + static_cast<int>(xRange * sin(speed * _tick));

 int y = yRange + static_cast<int>(yRange * cos(4 * speed * _tick));

 Blitter bltMask(_mask);

 bltMask.SetMode(SRCPAINT);

 bltMask.SetDest(x, y);

 bltMask.BlitTo(bmpCanvas);

 Blitter bltSprite(_sprite);

 bltSprite.SetMode(SRCAND);

 bltSprite.SetDest(x, y);

 bltSprite.BlitTo(bmpCanvas);

 // update the buffer

 _bitmapBuf = bmp;

}

For completeness, here's the definition of bitmap canvas. You draw directly on this canvas using standard canvas methods, like Line, Text, SetPixel, etc... Here we only blit bitmaps into it.

class BitmapCanvas: public MemCanvas {

public:

 BitmapCanvas(HDC hdc, HBITMAP hBitmap) : MemCanvas(hdc) {

// convert bitmap to format compatible with canvas

_hOldBitmap = reinterpret_cast(::SelectObject(_hdc, hBitmap));

 }

 ~BitmapCanvas {

::SelectObject(_hdc, _hOldBitmap);

 }

private:

 HBITMAP _hOldBitmap;

};

class MemCanvas: public Canvas {

public:

 MemCanvas(HDC hdc) : Canvas(::CreateCompatibleDC(hdc)) {}

 ~MemCanvas {

::DeleteDC(_hdc);

 }

};

Now, if you want more speed, read about DirectDraw.

Поделиться с друзьями: