~ubuntu-branches/debian/sid/twpsk/sid

« back to all changes in this revision

Viewing changes to user-twpsk/savedir/twpskScope.C

  • Committer: Bazaar Package Importer
  • Author(s): Joop Stakenborg
  • Date: 2001-12-12 08:24:32 UTC
  • Revision ID: james.westby@ubuntu.com-20011212082432-tamea6jb427pt8lv
Tags: upstream-2.0
ImportĀ upstreamĀ versionĀ 2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* twpsk  - A gui application for PSK
 
2
 * Copyright (C) 1999 Ted Williams WA0EIR (ted_williams@HP.com)
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; either version 2 of
 
7
 * the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be
 
10
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 
11
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 
12
 * PURPOSE.  See the GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public
 
15
 * License along with this program; if not, write to the Free
 
16
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
 
17
 * USA.
 
18
 *
 
19
 * Version: 2.0 - Aug 2001
 
20
 */
 
21
 
 
22
#include "twpskScope.h"
 
23
 
 
24
 
 
25
#define LINE_WIDTH 3
 
26
/*
 
27
 * Initialize drawing stuff for scope 
 
28
 */
 
29
 
 
30
void Scope::setup (Widget shell, Widget scopeWid)
 
31
{
 
32
   Colormap dcmap;
 
33
   XColor nill;
 
34
 
 
35
   x = SCOPE_WIDTH/2;    /* initialize these to 64 so first time wont't draw */
 
36
   y = SCOPE_WIDTH/2;    /* a line from 0,0 to center. */
 
37
   scopeDA = scopeWid;
 
38
 
 
39
   gc = XCreateGC(XtDisplay(shell),
 
40
                  RootWindowOfScreen (XtScreen(shell)),
 
41
                  GCForeground, &gcv);
 
42
 
 
43
   display = XtDisplay (scopeDA);
 
44
   window  = XtWindow (scopeDA);
 
45
   screen  = DefaultScreen (display);
 
46
   dcmap   = DefaultColormap (display, screen);
 
47
 
 
48
   XAllocNamedColor (display, dcmap, "red", &color[0], &nill);
 
49
   XAllocNamedColor (display, dcmap, "yellow", &color[1], &nill);
 
50
   XAllocNamedColor (display, dcmap, "green2", &color[2], &nill);
 
51
   XAllocNamedColor (display, dcmap, "light gray", &color[3], &nill); /*Outer*/
 
52
   XAllocNamedColor (display, dcmap, "slate gray", &color[4], &nill); /*Inner*/
 
53
}
 
54
 
 
55
 
 
56
/*
 
57
 * drawline - draws the phase lines in the scope
 
58
 */
 
59
void Scope::drawline (int phdelta, int strength, int icolor)
 
60
{
 
61
   Position cx = SCOPE_WIDTH/2, cy = SCOPE_WIDTH/2;
 
62
   float theta;
 
63
   float dx,dy;
 
64
 
 
65
   /* fudge factor - converts 0->256 thingies to radians */
 
66
   float fudge =  2.0 * M_PI / 256.0; 
 
67
   theta = phdelta * fudge;
 
68
 
 
69
   XSetForeground (display, gc, color[4].pixel);  /* fg color to color[4] to */
 
70
   XDrawLine (display, window, gc,                /* undraw the last line */
 
71
      cx, cy,                                     /* Start of last line */
 
72
      x, y);                                      /* End of the last line */
 
73
 
 
74
   XSetForeground (display, gc, color[icolor].pixel);    
 
75
 
 
76
   dx = (float)strength * cos(theta+M_PI_2) * SCOPE_WIDTH/128;
 
77
   dy = (float)strength * sin(theta+M_PI_2) * SCOPE_WIDTH/128;
 
78
 
 
79
   x = (int) ((float)cx + dx);
 
80
   y = (int) ((float)cy - dy);
 
81
   XDrawLine (display, window, gc,
 
82
      cx, cy,                                     /* Start of new line */
 
83
      x, y);                                      /* End of new line */
 
84
   XSetForeground (display, gc, color[3].pixel);
 
85
}
 
86
 
 
87
 
 
88
/*
 
89
 * drawcirc - redraws the circle 
 
90
 */
 
91
void Scope::drawcirc()
 
92
{
 
93
   /* Draw outer circle */
 
94
   XSetForeground (display, gc, color[3].pixel); /* fg = white */
 
95
   XSetLineAttributes (display, gc, OUTER_CIRCLE_WIDTH,
 
96
                       LineSolid, CapRound, JoinRound);      
 
97
   XDrawArc (display, window, gc,
 
98
      BORDER_WIDTH, BORDER_WIDTH,       /* upper left corner */
 
99
      SCOPE_WIDTH - 2 * BORDER_WIDTH,
 
100
      SCOPE_WIDTH - 2 * BORDER_WIDTH,   /* axis lengths */
 
101
      0, 23040);                        /* start/stop points */
 
102
 
 
103
   /* Change the gc for inner circle */
 
104
   gcv.foreground = color[4].pixel;
 
105
   XChangeGC (display, gc, GCForeground, &gcv);
 
106
   XSetLineAttributes (display, gc, LINE_WIDTH,
 
107
                       LineSolid, CapRound, JoinRound);      
 
108
 
 
109
   /* Draw filled inner circle */ 
 
110
   XFillArc (display, window, gc,
 
111
      BORDER_WIDTH, BORDER_WIDTH,      /* upper left corner */
 
112
      SCOPE_WIDTH - 2 * BORDER_WIDTH,
 
113
      SCOPE_WIDTH - 2 * BORDER_WIDTH,  /* axis lengths */
 
114
      0, 23040);                       /* start/stop points */
 
115
}