~ubuntu-branches/ubuntu/warty/xplanet/warty

« back to all changes in this revision

Viewing changes to src/libannotate/Symbol.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:14:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040824071400-2dr4qnjbjmm8z3ia
Tags: 1.0.6-1ubuntu1
Build-depend: libtiff4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cmath>
 
2
using namespace std;
 
3
 
 
4
#ifndef M_PI_2
 
5
#define M_PI_2         1.57079632679489661923  /* pi/2 */
 
6
#endif
 
7
 
 
8
#include "Symbol.h"
 
9
 
 
10
#include "libdisplay/libdisplay.h"
 
11
 
 
12
Symbol::Symbol(const unsigned char color[3], 
 
13
               const int x, const int y, const int r)
 
14
    : Annotation(color), x_(x), y_(y), r_(r)
 
15
{
 
16
    width_ = 2*r;
 
17
    height_ = 2*r;
 
18
}
 
19
 
 
20
Symbol::~Symbol()
 
21
{
 
22
}
 
23
 
 
24
void
 
25
Symbol::DrawCircle(DisplayBase *display, const int r, 
 
26
                   const unsigned char color[3])
 
27
{
 
28
    int xx, yy;
 
29
    double r2 = r * r;
 
30
    double dd = 1 / (M_PI_2 * r);
 
31
    for (double d = 0; d < M_PI_2; d += dd)
 
32
    {
 
33
        xx = static_cast<int>(cos(d) * r + 0.5);
 
34
        yy = static_cast<int>(sin(d) * r + 0.5);
 
35
        double opacity = (xx * xx + yy * yy) / r2;
 
36
        if (opacity > 1) opacity = 1/opacity;
 
37
 
 
38
        display->setPixel(x_ + xx, y_ + yy, color, opacity);
 
39
        display->setPixel(x_ - xx, y_ + yy, color, opacity);
 
40
        display->setPixel(x_ + xx, y_ - yy, color, opacity);
 
41
        display->setPixel(x_ - xx, y_ - yy, color, opacity);
 
42
    }
 
43
    display->setPixel(x_, y_ + r, color);
 
44
    display->setPixel(x_, y_ - r, color);
 
45
}
 
46
 
 
47
void
 
48
Symbol::Draw(DisplayBase *display)
 
49
{
 
50
    unsigned char black[3] = { 0, 0, 0 };
 
51
    DrawCircle(display, r_ - 1, black);
 
52
    DrawCircle(display, r_ + 1, black);
 
53
 
 
54
    DrawCircle(display, r_, color_);
 
55
}
 
56