1 //Copyright Paul Reiche, Fred Ford. 1992-2002
2
3 /*
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #include "oscill.h"
20
21 #include "setup.h"
22 // for OffScreenContext
23 #include "libs/graphics/gfx_common.h"
24 #include "libs/graphics/drawable.h"
25 #include "libs/sound/sound.h"
26 #include "libs/sound/trackplayer.h"
27
28
29 static FRAME scope_frame;
30 static int scope_init = 0;
31 static FRAME scopeWork;
32 static Color scopeColor;
33 static EXTENT scopeSize;
34 BOOLEAN oscillDisabled = FALSE;
35
36 void
InitOscilloscope(FRAME scopeBg)37 InitOscilloscope (FRAME scopeBg)
38 {
39 scope_frame = scopeBg;
40 if (!scope_init)
41 {
42 EXTENT size = GetFrameBounds (scope_frame);
43 POINT midPt = {size.width / 2, size.height / 2};
44
45 // mid-image pixel defines the color of scope lines
46 scopeColor = GetFramePixel (scope_frame, midPt);
47 // insist that scope lines be purely opaque
48 scopeColor.a = 0xff;
49
50 scopeWork = CaptureDrawable (CreateDrawable (
51 WANT_PIXMAP | MAPPED_TO_DISPLAY,
52 size.width, size.height, 1));
53
54 // assume and subtract the borders
55 scopeSize.width = size.width - 2;
56 scopeSize.height = size.height - 2;
57
58 scope_init = 1;
59 }
60 }
61
62 void
UninitOscilloscope(void)63 UninitOscilloscope (void)
64 {
65 // XXX: Is never called (BUG?)
66 DestroyDrawable (ReleaseDrawable (scopeWork));
67 scopeWork = NULL;
68 scope_init = 0;
69 }
70
71 // draws the oscilloscope
72 void
DrawOscilloscope(void)73 DrawOscilloscope (void)
74 {
75 STAMP s;
76 BYTE scope_data[128];
77
78 if (oscillDisabled)
79 return;
80
81 assert ((size_t)scopeSize.width <= sizeof scope_data);
82 assert (scopeSize.height < 256);
83
84 if (GraphForegroundStream (scope_data, scopeSize.width, scopeSize.height,
85 usingSpeech))
86 {
87 int i;
88 CONTEXT oldContext;
89
90 oldContext = SetContext (OffScreenContext);
91 SetContextFGFrame (scopeWork);
92 SetContextClipRect (NULL);
93
94 // draw the background image
95 s.origin.x = 0;
96 s.origin.y = 0;
97 s.frame = scope_frame;
98 DrawStamp (&s);
99
100 // draw the scope lines
101 SetContextForeGroundColor (scopeColor);
102 for (i = 0; i < scopeSize.width - 1; ++i)
103 {
104 LINE line;
105
106 line.first.x = i + 1;
107 line.first.y = scope_data[i] + 1;
108 line.second.x = i + 2;
109 line.second.y = scope_data[i + 1] + 1;
110 DrawLine (&line);
111 }
112
113 SetContext (oldContext);
114
115 s.frame = scopeWork;
116 }
117 else
118 { // no data -- draw blank scope background
119 s.frame = scope_frame;
120 }
121
122 // draw the final scope image to screen
123 s.origin.x = 0;
124 s.origin.y = 0;
125 DrawStamp (&s);
126 }
127
128
129 static STAMP sliderStamp;
130 static STAMP buttonStamp;
131 static BOOLEAN sliderChanged = FALSE;
132 int sliderSpace; // slider width - button width
133 BOOLEAN sliderDisabled = FALSE;
134
135 /*
136 * Initialise the communication progress bar
137 * x - x location of slider
138 * y - y location of slider
139 * width - width of slider
140 * height - height of slider
141 * bwidth - width of button indicating current progress
142 * bheight - height of button indicating progress
143 * f - image for the slider
144 */
145
146 void
InitSlider(int x,int y,int width,FRAME sliderFrame,FRAME buttonFrame)147 InitSlider (int x, int y, int width, FRAME sliderFrame, FRAME buttonFrame)
148 {
149 EXTENT sliderSize = GetFrameBounds (sliderFrame);
150 EXTENT buttonSize = GetFrameBounds (buttonFrame);
151
152 sliderStamp.origin.x = x;
153 sliderStamp.origin.y = y;
154 sliderStamp.frame = sliderFrame;
155
156 buttonStamp.origin.x = x;
157 buttonStamp.origin.y = y - ((buttonSize.height - sliderSize.height) / 2);
158 buttonStamp.frame = buttonFrame;
159
160 sliderSpace = width - buttonSize.width;
161 }
162
163 void
SetSliderImage(FRAME f)164 SetSliderImage (FRAME f)
165 {
166 sliderChanged = TRUE;
167 buttonStamp.frame = f;
168 }
169
170 void
DrawSlider(void)171 DrawSlider (void)
172 {
173 int offs;
174 static int last_offs = -1;
175
176 if (sliderDisabled)
177 return;
178
179 offs = GetTrackPosition (sliderSpace);
180 if (offs != last_offs || sliderChanged)
181 {
182 sliderChanged = FALSE;
183 last_offs = offs;
184 buttonStamp.origin.x = sliderStamp.origin.x + offs;
185 BatchGraphics ();
186 DrawStamp (&sliderStamp);
187 DrawStamp (&buttonStamp);
188 UnbatchGraphics ();
189 }
190 }
191
192