index: point2.h point2.cpp results
This class captures the graphics/display aspects of a 2D geometrical point. As such it is highly system dependent.
point2.h/*\file point2.h
*/
/*! point2 is a two dimensional point with graphics characteristics
*/
#pragma once
#include "vec2.h"
//! defines two-dimensional graphics point
class point2: public Vec2 {
public:
point2(): Vec2(0.0,0.0) { } //!< default no-argument constructor
~point2() {} //!< destructor
//! constructs point2 from (x,y) coordinates
point2(double x, double y): Vec2(x,y) { }
void convert(CPoint &dst) { convert(*this,dst); }
static void convert(Vec2 &src, CPoint &dst);
static int resolution;
void draw(CDC &dc);
};
inline void point2::convert(Vec2 &src, CPoint &dst)
{
dst.x = (int) (src[0]*resolution);
dst.y = (int) (src[1]*resolution);
}
point2.cpp#include "stdafx.h"
#include "point2.h"
int point2::resolution = 96;
void point2::draw(CDC &dc)
{
CPoint p;
const int S=7;
convert(p);
CPen pen (PS_SOLID,2,RGB(0,0,0));
CPen *oldpen = (CPen *) dc.SelectObject(&pen);
CBrush brush;
brush.CreateSolidBrush(RGB(255,255,0));
CBrush *oldbrush = (CBrush *) dc.SelectObject(&brush);
dc.Ellipse(p.x-S,p.y-S,p.x+S,p.y+S);
dc.SelectObject(oldbrush);
dc.SelectObject(oldpen);
}
Maintained by John Loomis, updated Wed Jan 24 14:48:52 2007