/*
* Bitmap.h
* Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
#pragma once
#include <sol\GdiObject.h>
namespace SOL {
class DC;
class Bitmap :public GdiObject {
private:
int dx, dy;
int sx, sy;
int ratio;
int width;
int height;
DWORD operation;
Boolean destructable;
public:
Bitmap(const TCHAR* name, HBITMAP hbitmap)
:GdiObject(name, hbitmap)
{
dx = dy = 0;
sx = sy = 0;
BITMAP bm;
::GetObject(hbitmap, sizeof(BITMAP), (LPSTR)&bm);
width = bm.bmWidth;
height = bm.bmHeight;
ratio = 100; // V1.20 specify a percentage
operation = SRCCOPY;
destructable = TRUE;
}
public:
~Bitmap() {
if(destructable) {
::DeleteObject(get());
}
}
public:
void draw(HDC hdc, int x, int y)
{
HBITMAP hbitmap = (HBITMAP)get();
if(hbitmap) {
HDC hdcMem = ::CreateCompatibleDC(hdc);
::SelectObject(hdcMem, hbitmap);
::SetMapMode(hdcMem, GetMapMode(hdc));
::StretchBlt(hdc, x, y, width*ratio/100, height*ratio/100,
hdcMem, sx, sy, width, height, operation);
::DeleteDC(hdcMem);
}
}
public:
void draw(DC& dc, int x, int y)
{
Bitmap::draw(dc.get(), x, y);
}
void getDestination(int& x, int& y) { x = dx; y = dy; }
void getSize(int& w, int& h) { w = width; h = height; }
void getSource(int& x, int& y) { x = sx; y = sy; }
void setDestination(int x, int y) { dx = x; dy = y; }
void setFlag(Boolean flag) { destructable = flag; }
void setOperation(DWORD op) { operation = op; }
void setSource(int x, int y) { sx = x; sy = y; }
void setStretchingRatio(int r) { ratio = r; }
};
}
|