📄 arrowobject.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 "ArrowObject.h"
static const FPOINT static_arrow[] = {{0,0}, {-1,-1}, {-1, -0.5}, {-2, -0.5}, {-2, 0.5}, {-1, 0.5}, {-1, 1}};
static const int NUM_POINTS = sizeof(static_arrow) / sizeof(static_arrow[0]);
static const float ARROW_SCALE = 0.03f;
static const float DRAG_FACTOR = ARROW_SCALE * 1.0f;
ArrowObject::ArrowObject(ObjectManager *om, ViewPort *vp, FPOINT *p)
{
this->om = om;
this->vp = vp;
this->pos.x = p->x;
this->pos.y = p->y;
this->oldpos = this->pos;
this->rotvec[0].x = 1;
this->rotvec[0].y = 0;
this->rotvec[1].x = 0;
this->rotvec[1].y = 1;
this->oldvec.x = 0;
this->oldvec.y = 0;
}
ArrowObject::~ArrowObject(void)
{
}
void ArrowObject::drawSelf(ViewPort *vp, FRECT *rect) {
FPOINT arrow[NUM_POINTS];
this->calcArrow(arrow);
vp->drawPolygon(arrow, NUM_POINTS);
}
void ArrowObject::getBounds(FRECT *rect){
FPOINT arrow[NUM_POINTS];
this->calcArrow(arrow);
rect->top = rect->bottom = arrow[0].y;
rect->right = rect->left = arrow[0].x;
for(int i = 1; i < NUM_POINTS; i++) {
addPoint2Bound(&arrow[i], rect);
}
vp->expandBoundsHack(rect);
}
void ArrowObject::setPoint(FPOINT *p){
FRECT temp;
this->getBounds(&temp);
pos = *p;
FPOINT vec = {pos.x - oldpos.x, pos.y - oldpos.y};
vec.x += oldvec.x * DRAG_FACTOR / vp->getZoom();
vec.y += oldvec.y * DRAG_FACTOR / vp->getZoom();
float len = (float)sqrt(pow(vec.x, 2) + pow(vec.y, 2));
vec.x = (vec.x / len);
vec.y = (vec.y / len);
rotvec[0].x = vec.x;
rotvec[0].y = -vec.y;
rotvec[1].x = vec.y;
rotvec[1].y = vec.x;
this->oldvec = vec;
oldpos = pos;
om->objectMoved(this, &temp);
}
void ArrowObject::calcArrow(FPOINT *arrow){
for(int i = 0; i < NUM_POINTS; i++){
arrow[i].x = static_arrow[i].x*rotvec[0].x+static_arrow[i].y*rotvec[0].y;
arrow[i].y = static_arrow[i].x*rotvec[1].x+static_arrow[i].y*rotvec[1].y;
arrow[i].x *= ARROW_SCALE / vp->getZoom();
arrow[i].y *= ARROW_SCALE / vp->getZoom();
arrow[i].x += pos.x;
arrow[i].y += pos.y;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -