⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 canvas.cpp

📁 swain-0.5.2.zip的源代码,比较好用,希望大家喜欢.
💻 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 "Canvas.h"

Canvas::Canvas(ObjectManager *om, ViewPort *vp) {
	objman = om;
	viewport = vp;
	tool = NULL;
	fextents.left = fextents.top = 0.0f;
	fextents.right = fextents.bottom = 1.0f;
	extents.left = extents.top = 0;
	extents.right = extents.bottom = 1280;
	
}

Canvas::~Canvas(void) {
}

void Canvas::redraw(void) {
	FRECT frect = {0.0, 0.0, 1.0, 1.0};
	redraw(&frect);
}

void Canvas::redraw(FRECT *rect) {
	int l;

	viewport->alignRect(rect);

	for (l = 0; l < NUM_LAYERS; l++) {
		Iterator *iter = objman->getIterator(l);
		while (iter->hasNext()) {
			Object *obj = iter->getNext();
			FRECT bound;
			obj->getBounds(&bound);
			if (intersectsFRECT(&bound, rect))
				obj->drawSelf(viewport, rect);
		}
		delete iter;
	}
	viewport->flip(rect);
}

void Canvas::objectAdded(Object *obj) {
	FRECT frect;
	obj->getBounds(&frect);
	viewport->invalidate(&frect);
}

void Canvas::objectMoved(Object *obj, FRECT *oldrect) {
	FRECT frect, bound;
	obj->getBounds(&bound);
	if (intersectsFRECT(&bound, oldrect)) {
		// Redraw the union of the old and new location if they overlap.
		// TODO: Be smarter and calculate 3 non-overlapping rects that cover exactly the old and new bounds.
		unionFRECT(&frect, &bound, oldrect);
		viewport->invalidate(&frect);
	} else {
		// If the old and new locations are non-overlapping just redraw them one after the other.
		viewport->invalidate(oldrect);
		viewport->invalidate(&bound);
	}
}

void Canvas::objectChanged(Object *obj, FRECT *changed) {
	viewport->invalidate(changed);
}

void Canvas::objectDeleted(FRECT *rect) {
	viewport->invalidate(rect);
}

void Canvas::mouseDown(FPOINT *point) {
	if (!tool)
		throw "No tool in mouseDown!";
	tool->mouseDown(point);
}

void Canvas::mouseUp(FPOINT *point) {
	if(!tool)
		throw "No tool in mouseUp!";
	tool->mouseUp(point);
}

void Canvas::mouseDragged(FPOINT *point) {
	if (!tool)
		throw "No tool in mouseDragged!";
	tool->mouseDragged(point);
}

void Canvas::setTool(Tool *t) {
	tool = t;
}

void Canvas::setExtents(FRECT *frect, RECT *rect) {
	if (frect != NULL)	fextents = *frect;
	if (rect != NULL)	extents = *rect;
}

void Canvas::getExtents(FRECT *frect, RECT *rect) {
	if (frect != NULL)	*frect = fextents;
	if (rect != NULL)	*rect = extents;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -