~ubuntu-branches/ubuntu/precise/ghc/precise

« back to all changes in this revision

Viewing changes to libraries/Win32/cbits/ellipse.c

  • Committer: Bazaar Package Importer
  • Author(s): Joachim Breitner
  • Date: 2011-01-17 12:49:24 UTC
  • Revision ID: james.westby@ubuntu.com-20110117124924-do1pym1jlf5o636m
Tags: upstream-7.0.1
ImportĀ upstreamĀ versionĀ 7.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define UNICODE
 
2
#include <windows.h>
 
3
#include <math.h>
 
4
 
 
5
/*
 
6
 * Rotatable Ellipse hack
 
7
 *
 
8
 * Win95 (Win32?) doesn't support rotating ellipses - so we
 
9
 * implement them with polygons.
 
10
 *
 
11
 * We use a fixed number of edges rather than varying the number
 
12
 * according to the radius of the ellipse.
 
13
 * If anyone feels like improving the code (to vary the number),
 
14
 * they should place a fixed upper bound on the number of edges
 
15
 * since it takes a relatively long time to draw 1000 edges.
 
16
 */
 
17
 
 
18
int transformedEllipse(
 
19
        HDC hdc, LONG x0, LONG y0, LONG x1, LONG y1, LONG x2, LONG y2) {
 
20
  static BOOL firstTime = 1;
 
21
  static double sins[20];
 
22
  static double coss[20];
 
23
 
 
24
  int   i;
 
25
  POINT pts[20];
 
26
 
 
27
  double x = (x1 + x2) / 2;  /* centre of parallelogram */
 
28
  double y = (y1 + y2) / 2;
 
29
 
 
30
  double dx1 = (x1 - x0) / 2; /* distance to corners from centre */
 
31
  double dy1 = (y1 - y0) / 2;
 
32
  double dx2 = (x2 - x0) / 2;
 
33
  double dy2 = (y2 - y0) / 2;
 
34
 
 
35
  if (firstTime) {
 
36
    double a  = 0.0;
 
37
    double da = 2.0*3.14159 / 20;
 
38
    for (i=0; i < 20; ++i, a+=da) {
 
39
        sins[i] = sin(a);
 
40
        coss[i] = cos(a);
 
41
    }
 
42
    firstTime = 0;
 
43
  }
 
44
  for(i=0; i < 20; ++i) {
 
45
    double c = coss[i];
 
46
    double s = sins[i];
 
47
    pts[i].x = x + c*dx1 + s*dx2;
 
48
    pts[i].y = y + c*dy1 + s*dy2;
 
49
  }
 
50
  return Polygon(hdc,pts,20);
 
51
}