Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
widgets/EACompass.cpp
- Committer:
- richardparker
- Date:
- 2010-04-26
- Revision:
- 4:f8f7f4f9c58d
- Child:
- 7:6cf21b018420
File content as of revision 4:f8f7f4f9c58d:
// Copyright 2010 Richard Parker
#include "mbed.h"
#include "EACompass.h"
#include "../graphics/EAPen.h"
#include "../graphics/EAColor.h"
#include "../screen/EALCD.h"
EACompass::EACompass( short x,
short y,
unsigned short diameter,
unsigned short angle)
{
setX(x);
setY(y);
setWidth(diameter);
setHeight(diameter);
setAngle(angle);
}
EACompass::~EACompass()
{
}
void EACompass::paint(EALCD& lcd)
{
// Draw the outer ring.
lcd.drawFilledEllipse(x(), y(), diameter(), diameter());
// Now draw the pointer.
_drawPointer(lcd);
}
void EACompass::update(EALCD& lcd, float angle)
{
// Clear the old pointer.
EAColor oldColour = lcd.pen().color();
EAColor bg = lcd.brush().color();
EAPen p;
p.setColor(bg);
lcd.setPen(p);
_drawPointer(lcd);
p.setColor(oldColour);
lcd.setPen(p);
// Now set the new angle and draw the pointer.
setAngle(angle);
_drawPointer(lcd);
}
void EACompass::_drawPointer(EALCD& lcd)
{
unsigned short r = diameter()/2;
unsigned short h = r - 10;
short oy = h * sin(angle());
short ox = h * cos(angle());
short x0 = r + x() - ox;
short y0 = r + y() + oy;
short x1 = r + x() + ox;
short y1 = r + y() - oy;
// Draw main line.
lcd.drawLine(x0, y0, x1, y1);
// Draw ball at north end.
lcd.drawFilledEllipse(x1-5, y1-5, 10, 10);
}