📄 bitmapobject.cpp
字号:
/*
This file is part of SWAIN (http://sourceforge.net/projects/swain).
Copyright (C) 2006 Daniel Lindstr鰉 and Daniel Nilsson
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "StdAfx.h"
#include "BitmapObject.h"
BitmapObject::BitmapObject(Bitmap *bmp) {
bitmap = bmp;
}
BitmapObject::~BitmapObject(void) {
}
void BitmapObject::drawSelf(ViewPort *vp, FRECT *rect) {
FRECT dstfrect, bounds;
RECT srcrect;
getBounds(&bounds);
if (!intersectsFRECT(rect, &bounds)) {
return; // Nothing to draw, the code below assumes that rect and bounds overlap!
}
intersectFRECT(&dstfrect, rect, &bounds);
srcrect.left = (int)((dstfrect.left - bounds.left) / (bounds.right - bounds.left) * bitmap->getWidth());
srcrect.top = (int)((dstfrect.top - bounds.top) / (bounds.bottom - bounds.top) * bitmap->getHeight());
srcrect.right = (int)((dstfrect.right - bounds.left) / (bounds.right - bounds.left) * bitmap->getWidth());
srcrect.bottom = (int)((dstfrect.bottom - bounds.top) / (bounds.bottom - bounds.top) * bitmap->getHeight());
vp->drawBitmap(bitmap, &dstfrect, &srcrect);
}
void BitmapObject::getBounds(FRECT *rect) {
// The bitmap covers all of the canvas
float aspect = (float)bitmap->getHeight() / (float)bitmap->getWidth();
if (aspect < 1.0f) {
rect->left = 0.0f;
rect->top = 0.5f - aspect / 2.0f;
rect->right = 1.0f;
rect->bottom = 0.5f + aspect / 2.0f;
} else {
aspect = 1.0f / aspect;
rect->left = 0.5f - aspect / 2.0f;
rect->top = 0.0f;
rect->right = 0.5f + aspect / 2.0f;
rect->bottom = 1.0f;
}
}
void BitmapObject::getPixelBounds(RECT *rect) {
if (rect != NULL) {
rect->left = rect->top = 0;
rect->right = bitmap->getWidth();
rect->bottom = bitmap->getHeight();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -