Debian Codegraph @

source/editwin.cc

raw
1 // ----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2003-2013 Fons Adriaensen <[email protected]>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // ----------------------------------------------------------------------------
19
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <math.h>
24 #include "styles.h"
25 #include "editwin.h"
26 #include "global.h"
27
28
29
30 Editwin::Editwin (X_window *parent, X_callback *callb, int xp, int yp, int xs, int ys) :
31 X_window (parent, xp, yp, xs, ys, Colors.plot_bg),
32 _callb (callb),
33 _xs (xs),
34 _ys (ys),
35 _x0 (9999),
36 _x1 (-9999),
37 _show (false),
38 _wait (false),
39 _xdrag (INT_MIN),
40 _mdrag (INT_MIN),
41 _cmark (INT_MIN)
42 {
43 int k, x, y;
44
45 x_add_events (ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask | StructureNotifyMask);
46
47 _xd = _xs - LSW - RPM - RWW;
48 _yd = _ys - TPM - BSH - BWH;
49
50 _plotw = new X_subwin (this, LSW, TPM, _xd, _yd, Colors.plot_bg);
51 _plotw->x_add_events (ExposureMask);
52 _plotw->x_map ();
53
54 _lswin = new X_subwin (this, 0, 0, LSW, _yd + TPM + 8, Colors.plot_bg);
55 _lswin->x_add_events (ExposureMask);
56 _lswin->x_map ();
57
58 _bswin = new X_subwin (this, LSW - 8, TPM + _yd, _xd + 16, BSH, Colors.plot_bg);
59 _bswin->x_set_win_gravity (SouthWestGravity);
60 _bswin->x_add_events (ExposureMask);
61 _bswin->x_map ();
62
63 _rbwin = new X_window (this, _xs - RWW, 0, RWW, _ys - BWH, XftColors.main_bg->pixel);
64 _rbwin->x_set_win_gravity (NorthEastGravity);
65 _rbwin->x_map ();
66
67 _bbwin = new X_window (this, 0, _ys - BWH, _xs, BWH, XftColors.main_bg->pixel);
68 _bbwin->x_set_win_gravity (SouthWestGravity);
69 _bbwin->x_map ();
70
71 x = _xs - RWW - 240;
72 Bst0.size.x = 17;
73 Bst0.size.y = 17;
74 for (k = 0; k < 2; k++)
75 {
76 X_ibutton *B;
77 B = new X_ibutton (_bbwin, this, &Bst0, x, 3, disp ()->image1515 (X_display::IMG_UP), B_MK0 + k);
78 B->x_set_win_gravity (EastGravity);
79 B->set_col (Colors.plot_mk [k], XftColors.mark_fg->pixel);
80 B->x_map ();
81 _marks [k]._flags = 0;
82 _marks [k]._color = Colors.plot_mk [k] ^ Colors.plot_bg;
83 _marks [k]._butt = B;
84 x += 17;
85 }
86 _tmark = new X_textip (_bbwin, 0, &Tst1, x + 4, 3, 160, 16, 31, 0);
87 _tmark->x_set_win_gravity (EastGravity);
88 _tmark->x_map ();
89
90 Bst0.size.x = 17;
91 Bst0.size.y = 17;
92 x = _xs - RWW - 34;
93 _bxmi = new X_ibutton (_bbwin, this, &Bst0, x, 3, disp ()->image1515 (X_display::IMG_MI), B_XMI);
94 _bxmi->x_set_win_gravity (EastGravity);
95 _bxmi->x_map ();
96 x += 17;
97 _bxpl = new X_ibutton (_bbwin, this, &Bst0, x, 3, disp ()->image1515 (X_display::IMG_PL), B_XPL);
98 _bxpl->x_set_win_gravity (EastGravity);
99 _bxpl->x_map ();
100
101 Bst0.size.x = 35;
102 Bst0.size.y = 18;
103 y = 0;
104 _blin = new X_tbutton (_rbwin, this, &Bst0, 1, y, "Lin", 0, B_LIN);
105 _blin->x_set_win_gravity (NorthGravity);
106 _blin->x_map ();
107 y += 18;
108 _blog = new X_tbutton (_rbwin, this, &Bst0, 1, y, "Log", 0, B_LOG);
109 _blog->x_set_win_gravity (NorthGravity);
110 _blog->x_map ();
111
112 Bst0.size.x = 17;
113 Bst0.size.y = 17;
114 y = _ys - BWH - 34;
115 _bypl = new X_ibutton (_rbwin, this, &Bst0, 4, y, disp ()->image1515 (X_display::IMG_PL), B_YPL);
116 _bypl->x_set_win_gravity (SouthEastGravity);
117 _bypl->x_map ();
118 y += 17;
119 _bymi = new X_ibutton (_rbwin, this, &Bst0, 4, y, disp ()->image1515 (X_display::IMG_MI), B_YMI);
120 _bymi->x_set_win_gravity (SouthEastGravity);
121 _bymi->x_map ();
122
123 k = disp ()->xsize () - LSW - RPM - RWW + 2;
124 _segm = new XSegment [k];
125 set_data (0, 0, 0, 0, 0);
126 }
127
128
129 Editwin::~Editwin (void)
130 {
131 delete[] _segm;
132 }
133
134
135 void Editwin::handle_event (XEvent *E)
136 {
137 switch (E->type)
138 {
139 case MapNotify:
140 _show = true;
141 break;
142 case UnmapNotify:
143 _show = false;
144 break;
145 case GraphicsExpose:
146 case Expose:
147 expose ((XExposeEvent *) E);
148 break;
149 case ButtonPress:
150 bpress ((XButtonEvent *) E);
151 break;
152 case ButtonRelease:
153 brelse ((XButtonEvent *) E);
154 break;
155 case MotionNotify:
156 motion ((XPointerMovedEvent *) E);
157 break;
158 }
159 }
160
161
162 void Editwin::handle_callb (int k, X_window *W, XEvent *E )
163 {
164 int b, c, e;
165
166 c = X_callback::cb_class (k);
167 e = X_callback::cb_event (k);
168 switch (c)
169 {
170 case X_callback::BUTTON:
171 {
172 X_button *B = (X_button *) W;
173 b = ((XButtonEvent *) E)->button;
174 k = B->cbid ();
175 if (e == X_button::PRESS)
176 {
177 switch (k)
178 {
179 case B_MK0:
180 case B_MK1:
181 if (b == Button3) show_mark (k - B_MK0, 2 * _xd / 5);
182 else goto_mark (k - B_MK0);
183 break;
184 case B_XMI:
185 set_xzoom ((b == Button3) ? -4 : -1);
186 break;
187 case B_XPL:
188 set_xzoom ((b == Button3) ? 4 : 1);
189 break;
190 case B_LIN:
191 logmode (false);
192 break;
193 case B_LOG:
194 logmode (true);
195 break;
196 case B_YPL:
197 set_yzoom (1);
198 break;
199 case B_YMI:
200 set_yzoom (-1);
201 break;
202 }
203 }
204 break;
205 }
206
207 default:
208 ;
209 }
210 }
211
212
213 void Editwin::expose (XExposeEvent *E)
214 {
215 int x0, x1;
216
217 if (E->window == win ())
218 {
219 X_draw D (dpy (), win (), dgc (), xft ());
220 D.setcolor (Colors.plot_gr);
221 D.setfunc (GXcopy);
222 D.setline (0);
223 D.move (LSW - 1, TPM - 1);
224 D.rdraw (_xd + 2, 0);
225 D.rdraw (0, _yd + 2);
226 }
227 else if (E->window == _plotw->win ())
228 {
229 x0 = E->x;
230 x1 = E->x + E->width;
231 if (x0 < _x0) _x0 = x0;
232 if (x1 > _x1) _x1 = x1;
233 if (E->count == 0) redraw ();
234 }
235 else if (E->window == _bswin->win ())
236 {
237 if (E->count == 0) plot_xscale ();
238 }
239 else if (E->window == _lswin->win ())
240 {
241 if (E->count == 0) plot_yscale ();
242 }
243 }
244
245
246 void Editwin::resize (int xs, int ys)
247 {
248 if ((_xs != xs) || (_ys != ys))
249 {
250 _xs = xs;
251 _ys = ys;
252 _xd = _xs - LSW - RPM - RWW;
253 _yd = _ys - TPM - BSH - BWH;
254 set_yscale ();
255 x_resize (_xs, _ys);
256 _plotw->x_resize (_xd, _yd);
257 _lswin->x_resize (LSW, _yd + TPM + 8);
258 _rbwin->x_resize (RWW, _ys - BWH);
259 _bswin->x_resize (_xd + 16, BSH);
260 _bbwin->x_resize (_xs, BWH);
261 check_marks ();
262 }
263 }
264
265
266 void Editwin::bpress (XButtonEvent *E)
267 {
268 if (E->subwindow == _plotw->win ())
269 {
270 _mdrag = find_mark (E->x - LSW, E->y - TPM);
271 if (_data && (_mdrag < 0) && (E->button == Button3))
272 {
273 if (_marks [0]._flags == Mark::OFF) curr_mark (_mdrag = 0);
274 else if (_marks [1]._flags == Mark::OFF) curr_mark (_mdrag = 1);
275 if (_mdrag >= 0) show_mark (_mdrag, E->x - LSW);
276 }
277 }
278 else if (E->subwindow == _bswin->win ())
279 {
280 _xdrag = E->x;
281 }
282 }
283
284
285 void Editwin::motion (XPointerMovedEvent *E)
286 {
287 if (_xdrag != INT_MIN)
288 {
289 if (! _wait)
290 {
291 xscroll (_xdrag - E->x);
292 _xdrag = E->x;
293 }
294 }
295 else if (_mdrag >= 0)
296 {
297 move_mark (E->x - LSW);
298 curr_mark (_cmark);
299 }
300 }
301
302
303 void Editwin::brelse (XButtonEvent *E)
304 {
305 _xdrag = INT_MIN;
306 _mdrag = INT_MIN;
307 check_marks ();
308 }
309
310
311 void Editwin::set_data (Impdata *data, int mask, int opts, float t0, float t1)
312 {
313 _data = data;
314 if (_data)
315 {
316 if (mask)
317 {
318 _mask = mask;
319 _opts = opts;
320 _blin->set_stat ((opts & LOGMODE) ? 0 : 2);
321 _blog->set_stat ((opts & LOGMODE) ? 2 : 0);
322 _rate = (U32) data->drate ();
323 _offs = 0;
324 _ind0 = 0;
325 _gain = 1.0;
326 _slin = 0;
327 _slog = -80;
328 set_xrange (t0, t1);
329 set_yscale ();
330 plot_yscale ();
331 clear_marks ();
332 }
333 }
334 else
335 {
336 _mask = 1;
337 _opts = 0;
338 _blin->set_stat (0);
339 _blog->set_stat (0);
340 _rate = 48000;
341 _offs = 0;
342 _ind0 = 0;
343 _gain = 1.0;
344 _slin = 0;
345 _slog = -80;
346 set_yscale ();
347 plot_yscale ();
348 set_xrange (0.0f, 1.0f);
349 clear_marks ();
350 }
351 update ();
352 }
353
354
355 void Editwin::set_mask (int mask)
356 {
357 if (mask && (_mask != mask))
358 {
359 _mask = mask;
360 set_yscale ();
361 plot_yscale ();
362 update ();
363 }
364 }
365
366
367 void Editwin::logmode (bool on)
368 {
369 int b = on ? (_opts | LOGMODE) : (_opts & ~LOGMODE);
370 if (b != _opts)
371 {
372 _opts = b;
373 _blin->set_stat (on ? 0 : 2);
374 _blog->set_stat (on ? 2 : 0);
375 set_yscale ();
376 plot_yscale ();
377 update ();
378 }
379 }
380
381
382 void Editwin::overlay (bool on)
383 {
384 int b = on ? (_opts | OVERLAY) : (_opts & ~OVERLAY);
385 if (b != _opts)
386 {
387 _opts = b;
388 set_yscale ();
389 plot_yscale ();
390 update ();
391 }
392 }
393
394
395 void Editwin::set_offs (int d)
396 {
397 _offs = d;
398 plot_xscale ();
399 update ();
400 }
401
402
403 void Editwin::set_ind0 (int d)
404 {
405 _ind0= d;
406 update ();
407 curr_mark (_cmark);
408 }
409
410
411 void Editwin::set_gain (float g)
412 {
413 _gain = g;
414 update ();
415 }
416
417
418 void Editwin::unset_all (void)
419 {
420 _offs = 0;
421 _ind0 = 0;
422 _gain = 1.0;
423 clear_marks ();
424 plot_xscale ();
425 update ();
426 }
427
428
429 void Editwin::set_xrange (float t0, float t1)
430 {
431 int k;
432 double t;
433
434 t = (t1 - t0) * _rate / (_xd - 1);
435 for (k = 0; (k < NZOOM - 1) && (t > _ztab [k]); k++);
436 _zoom = _ztab [_zind = k];
437 k = (int)(floor (t0 * _rate / _zoom));
438 _fst0 = k * _zoom;
439 set_xscale ();
440 plot_xscale ();
441 update ();
442 check_marks ();
443 }
444
445
446 void Editwin::set_xzoom (int z)
447 {
448 int j, n;
449
450 z = _zind - z;
451 if (z >= NZOOM) z = NZOOM - 1;
452 else if (z < 0) z = 0;
453 if (z != _zind)
454 {
455 if ((_cmark >= 0) && (_marks [_cmark]._flags != Mark::OFF))
456 {
457 j = (_marks [_cmark]._posit - _fst0 - _data->tref_i ()) / _zoom;
458 if ((j < 0) || (j >= _xd)) j = _xd / 2;
459 }
460 else j = _xd / 2;
461 n = _fst0 + j * _zoom;
462 _zoom = _ztab [_zind = z];
463 n = (int)(floor ((double) n / _zoom + 0.5)) * _zoom;
464 _fst0 = n - j * _zoom;
465 set_xscale ();
466 plot_xscale ();
467 update ();
468 check_marks ();
469 }
470 }
471
472
473 void Editwin::set_yzoom (int d)
474 {
475 if (_opts & LOGMODE)
476 {
477 d = (d > 0) ? -20 : 20;
478 _slog += d;
479 if (_slog > -20) _slog = -20;
480 if (_slog < -160) _slog = -160;
481 }
482 else
483 {
484 d = (d > 0) ? -6 : 6;
485 _slin += d;
486 if (_slin > 12) _slin = 12;
487 if (_slin < -120) _slin = -120;
488 }
489 set_yscale ();
490 plot_yscale ();
491 update ();
492 }
493
494
495 void Editwin::set_xscale (void)
496 {
497 int d;
498 double t;
499
500
501 _xsc = (double) _rate / _zoom;
502 _xmm = 5;
503 d = 1000000;
504 t = 6 * _xsc;
505 while (d > 5 * t) d /= 10;
506 if (d > 2 * t) { d /= 5; _xmm = 4; }
507 else if (d > t) d /= 2;
508 _xun = 100.0 / d;
509 }
510
511
512 void Editwin::set_yscale (void)
513 {
514 int b, d, i, k, n, y;
515
516 if (_opts & OVERLAY) n = 1;
517 else for (i = n = 0, b = _mask; i < NTRACE; b >>= 1, i++) n += b & 1;
518 if (n > 4) n = 1;
519 k = (_yd - 8) / n;
520 d = 8 + (k & 7);
521 k -= d;
522 y = 4 + d / 2;
523 // if (~_opts & LOGMODE) y += k / 2;
524 for (i = 0, b = _mask; i < NTRACE; b >>= 1, i++)
525 {
526 _ypos [i] = y;
527 if ((b & 1) && (n > 1)) y += k + d;
528 }
529 if (_opts & LOGMODE)
530 {
531 for (i = 0; i < NYTAB; i++)
532 {
533 d = _ytab [i];
534 if (k * d / -_slog >= 30) break;
535 }
536 if (i == NYTAB) d = -_slog;
537 }
538 else
539 {
540 d = k / 2;
541 if (d > 60) d /= 2;
542 if (d > 60) d /= 2;
543 }
544 _yref = k;
545 _ydel = d;
546 }
547
548
549 void Editwin::plot_xscale (void)
550 {
551 int i, d, x, x0;
552 double t, t0;;
553 char s [16];
554 const char *f;
555 X_draw D (dpy (), _bswin->win (), dgc (), xft ());
556
557 if (!_show) return;
558
559 D.setfont (XftFonts.scales);
560 D.clearwin ();
561 D.setfunc (GXcopy);
562 D.setline (0);
563 x0 = 8;
564 t0 = (double)(_fst0 - _offs) / _rate;
565 d = XftFonts.scales->ascent + 2;
566 f = (_xun > 0.019f) ? "%3.1lf" : "%5.3lf";
567 i = _xi0 = (int)(ceil (t0 / _xun));
568
569 D.setcolor (Colors.plot_gr);
570 D.move (x0 - 1, 0);
571 D.rdraw (_xd + 2, 0);
572 D.setcolor (XftColors.plot_sc);
573
574 while (1)
575 {
576 t = i * _xun;
577 x = (int)((t - t0) * _xsc + 0.5);
578 if (x >= _xd) break;
579 D.move (x + x0, 0);
580 if (i % _xmm) D.rdraw (0, 3);
581 else
582 {
583 sprintf (s, f, t);
584 D.rdraw (0, 5);
585 D.rmove (0, d);
586 D.drawstring (s, 0);
587 }
588 i++;
589 }
590 }
591
592
593 void Editwin::plot_yscale (void)
594 {
595 int b, d, i, j, x0, y, y0, dy;
596 float u;
597 char s [16];
598 X_draw D (dpy (), _lswin->win (), dgc (), xft ());
599
600 if (!_show) return;
601
602 D.setfont (XftFonts.scales);
603 D.clearwin ();
604 D.setfunc (GXcopy);
605 D.setline (0);
606 x0 = LSW - 1;
607 y0 = TPM;
608 d = XftFonts.scales->ascent / 2 - 1;
609
610 D.setcolor (Colors.plot_gr);
611 D.move (x0, y0 - 1);
612 D.rdraw (0, _yd + 2);
613 D.setcolor (XftColors.plot_sc);
614
615 if (_opts & LOGMODE)
616 {
617 u = (float) _yref / -_slog;
618 }
619 else
620 {
621 u = 0;
622 sprintf (s, "%d", _slin);
623 }
624 for (i = 0, b = _mask; i < NTRACE; b >>= 1, i++)
625 {
626 if (b & 1)
627 {
628 j = 0;
629 y = y0 + _ypos [i];
630 if (_opts & LOGMODE)
631 {
632 while (1)
633 {
634 dy = (int)(j * _ydel * u + 0.5f);
635 if (dy > _yref) break;
636 D.move (x0, y + dy);
637 D.rdraw (-5, 0);
638 sprintf (s, "%d", -j * _ydel);
639 D.rmove (-4, d);
640 D.drawstring (s, 1);
641 j++;
642 }
643 }
644 else
645 {
646 while (1)
647 {
648 dy = j * _ydel;
649 if (dy > _yref) break;
650 D.move (x0, y + dy);
651 D.rdraw (-5, 0);
652 if (j == 0)
653 {
654 D.rmove (-4, d);
655 D.drawstring (s, 1);
656 }
657 j++;
658 }
659 }
660 }
661 }
662 }
663
664
665 void Editwin::update (void)
666 {
667 if (_show)
668 {
669 _x0 = 0;
670 _x1 = _xd;
671 redraw ();
672 }
673 }
674
675
676 void Editwin::xscroll (int dx)
677 {
678 X_draw D (dpy (), _plotw->win (), dgc (), xft ());
679 if (dx)
680 {
681 _wait = true;
682 _fst0 += dx * _zoom;
683 plot_xscale ();
684 D.movepix (dx, 0, _xd, _yd);
685 }
686 }
687
688
689 void Editwin::redraw ()
690 {
691 X_draw D (dpy (), _plotw->win (), dgc (), xft ());
692
693 D.setcolor (Colors.plot_bg);
694 D.setfunc (GXcopy);
695 D.fillrect (_x0, 0, _x1, _yd);
696 D.setclip (_x0, 0, _x1, _yd);
697 plot_grid (&D);
698 if (_data)
699 {
700 plot_data (&D);
701 D.setfunc (GXxor);
702 plot_mark (&D, 0);
703 plot_mark (&D, 1);
704 }
705 D.noclip ();
706 _wait = false;
707 _x0 = 9999;
708 _x1 = -9999;
709 }
710
711
712 void Editwin::plot_grid (X_draw *D)
713 {
714 int b, i, j, x, y, dy;
715 float u;
716 double t, t0;
717
718 D->setline (0);
719 D->setcolor (Colors.plot_gr);
720
721 t0 = (double)(_fst0 - _offs) / _rate;
722 i = _xi0;
723 while (1)
724 {
725 if (i % _xmm == 0)
726 {
727 t = i * _xun;
728 x = (int)((t - t0) * _xsc + 0.5);
729 if (x >= _xd) break;
730 D->move (x, 0);
731 D->rdraw (0, _yd);
732 }
733 i++;
734 }
735
736 u = (_opts & LOGMODE) ? ((float) _yref / -_slog) : 1.0f;
737 for (i = 0, b = ~_mask; i < NTRACE; b >>= 1, i++)
738 {
739 if (b & 1) continue;
740 y = _ypos [i];
741 j = 0;
742 while (1)
743 {
744 dy = (int)(j++ * _ydel * u + 0.5f);
745 if (dy > _yref) break;
746 D->move (0, y + dy);
747 D->rdraw (_xd, 0);
748 }
749 }
750 }
751
752
753 void Editwin::plot_data (X_draw *D)
754 {
755 int b, c, i, j, k, n, x0, x1, y0, r0, r1;
756 float s, v, d, *p, min, max;
757 XSegment *S;
758 XPoint *P;
759
760 if (_opts & LOGMODE)
761 {
762 s = ((_opts & POWMODE) ? 10.0f : 20.0f) * _yref / _slog;
763 d = log10f (_gain);;
764 }
765 else
766 {
767 s = 0.5f * _yref * _gain * powf (10.0f, -0.05f * _slin);
768 d = 0;
769 }
770
771 c = _data->n_chan ();
772 for (i = 0, b = ~_mask; i < (int)(_data->n_chan ()); b >>= 1, i++)
773 {
774 if (b & 1) continue;
775 D->setcolor (Colors.plot_da [i & 1]);
776
777 y0 = _ypos [i];
778 if (~_opts & LOGMODE) y0 += _yref / 2;
779 x0 = _x0;
780 x1 = _x1;
781 n = x1 - x0;
782 k = _fst0 + _data->tref_i () - _zoom / 2;
783 p = _data->data (i);
784 r0 = 0;
785 r1 = _data->n_fram ();
786
787 if (_opts & LOGMODE)
788 {
789 P = (XPoint *) _segm;
790 x0--;
791 x1++;
792 n += 2;
793 k += x0 * _zoom;
794 while (x0 < x1)
795 {
796 if ((k >= r0) && (k + _zoom <= r1))
797 {
798 max = fabsf (p [c * k++]) + 1e-30;
799 for (j = 1; j < _zoom; j++, k++)
800 {
801 v = fabs (p [c * k]);
802 if (v > max) max = v;
803 }
804 j = (int)(s * (d + log10f (max)) + 0.5f);
805 if (j > _yref + 1) j = _yref + 1;
806 }
807 else if ((k + _zoom <= r0) || (k >= r1))
808 {
809 j = _yref + 1;
810 k += _zoom;
811 }
812 else
813 {
814 max = 1e-30f;
815 for (j = 0; j < _zoom; j++, k++)
816 {
817 if ((k >= r0) && (k < r1))
818 {
819 v = fabsf (p [c * k]);
820 if (v > max) max = v;
821 }
822 }
823 j = (int)(s * (d + log10f (max)) + 0.5f);
824 if (j > _yref + 1) j = _yref + 1;
825 }
826 P->x = x0++;
827 P->y = y0 + j;
828 P++;
829 }
830 D->drawlines (n, (XPoint *) _segm);
831 }
832 else if (_zoom > 1)
833 {
834 S = _segm;
835 k += x0 * _zoom;
836 while (x0 < x1)
837 {
838 if ((k >= r0) && (k + _zoom < r1))
839 {
840 max = min = p [c * k];
841 for (j = 1; j <= _zoom; j++)
842 {
843 v = p [c * ++k];
844 if (v > max) max = v;
845 if (v < min) min = v;
846 }
847 }
848 else if ((k + _zoom < r0) || (k >= r1))
849 {
850 max = min = 0;
851 k += _zoom;
852 }
853 else
854 {
855 max = min = 0;
856 for (j = 0; j <= _zoom; j++, k++)
857 {
858 if ((k >= r0) && (k < r1))
859 {
860 v = p [c * k];
861 if (v > max) max = v;
862 if (v < min) min = v;
863 }
864 }
865 --k;
866 }
867 S->x1 = S->x2 = x0++;
868 S->y1 = y0 - (int) floorf (s * max + 0.5);
869 S->y2 = y0 - (int) floorf (s * min + 0.5);
870 S++;
871 }
872 D->drawsegments (n, _segm);
873 }
874 else
875 {
876 P = (XPoint *) _segm;
877 x0--;
878 x1++;
879 n += 2;
880 k += x0;
881 while (x0 < x1)
882 {
883 if ((k >= r0) && (k < r1)) j = (int) floorf (s * p [c * k++] + 0.5f);
884 else { j = 0; k++; }
885 P->x = x0++;
886 P->y = y0 - j;
887 P++;
888 }
889 D->drawlines (n, (XPoint *) _segm);
890 }
891 }
892 }
893
894
895 void Editwin::clear_marks (void)
896 {
897 int i;
898 Mark *M;
899 X_draw D (dpy (), _plotw->win (), dgc (), xft ());
900
901 D.setcolor (Colors.plot_bg);
902 D.setfunc (GXxor);
903 for (i = 0, M = _marks; i < NMARK; i++, M++)
904 {
905 plot_mark (&D, i);
906 M->_flags = 0;
907 M->_butt->set_image (disp ()->image1515 (X_display::IMG_PT));
908 M->_butt->set_stat (0);
909 }
910 curr_mark (_mdrag = INT_MIN);
911 }
912
913
914 void Editwin::check_marks (void)
915 {
916 int i, f, x;
917 Mark *M;
918
919 for (i = 0, M = _marks; i < NMARK; i++, M++)
920 {
921 f = Mark::OFF;
922 if (M->_flags != Mark::OFF)
923 {
924 x = (M->_posit - _fst0 - _data->tref_i ()) / _zoom;
925 if (x < 0) f = Mark::LL;
926 else if (x >= _xd) f = Mark::RR;
927 else f = Mark::ON;
928 }
929 if (f != M->_flags)
930 {
931 switch (M->_flags = f)
932 {
933 case Mark::OFF:
934 M->_butt->set_image (disp ()->image1515 (X_display::IMG_PT));
935 M->_butt->set_stat (0);
936 break;
937 case Mark::ON:
938 M->_butt->set_image (disp ()->image1515 (X_display::IMG_UP));
939 M->_butt->set_stat (4);
940 break;
941 case Mark::LL:
942 M->_butt->set_image (disp ()->image1515 (X_display::IMG_LT));
943 M->_butt->set_stat (4);
944 break;
945 case Mark::RR:
946 M->_butt->set_image (disp ()->image1515 (X_display::IMG_RT));
947 M->_butt->set_stat (4);
948 break;
949 }
950 M->_butt->redraw ();
951 }
952 }
953 }
954
955
956 void Editwin::show_mark (int i, int x)
957 {
958 Mark *M = _marks + i;
959
960 if (_data)
961 {
962 if (M->_flags == Mark::ON)
963 {
964 togg_mark (i);
965 M->_flags = Mark::OFF;
966 M->_butt->set_image (disp ()->image1515 (X_display::IMG_PT));
967 M->_butt->set_stat (0);
968 if (_cmark == i)
969 {
970 M = _marks + (i ^ 1);
971 curr_mark ((M->_flags == Mark::OFF) ? INT_MIN : i ^ 1);
972 }
973 }
974 else
975 {
976 M->_flags = Mark::ON;
977 M->_posit = _fst0 + _data->tref_i () + x * _zoom;
978 M->_butt->set_image (disp ()->image1515 (X_display::IMG_UP));
979 M->_butt->set_stat (4);
980 togg_mark (i);
981 curr_mark (i);
982 }
983 }
984 }
985
986
987 void Editwin::move_mark (int x)
988 {
989 togg_mark (_cmark);
990 _marks [_cmark]._posit = _fst0 + _data->tref_i () + x * _zoom;
991 togg_mark (_cmark);
992 }
993
994
995 void Editwin::goto_mark (int i)
996 {
997 Mark *M = _marks + i;
998
999 if (_data)
1000 {
1001 if (M->_flags != Mark::OFF)
1002 {
1003 xscroll ((M->_posit - _fst0 - _data->tref_i ()) / _zoom - _xd / 2);
1004 curr_mark (i);
1005 check_marks ();
1006 }
1007 }
1008 }
1009
1010
1011 int Editwin::find_mark (int x, int y)
1012 {
1013 int i, mx, my;
1014 Mark *M;
1015
1016 if (_data)
1017 {
1018 for (i = 0, M = _marks; i < NMARK; i++, M++)
1019 {
1020 if (M->_flags != Mark::OFF)
1021 {
1022 mx = (M->_posit - _fst0 - _data->tref_i ()) / _zoom;
1023 my = 20 * (i + 1);
1024 if ((abs (mx - x) < 6) && (abs (my - y) < 6))
1025 {
1026 curr_mark (i);
1027 return i;
1028 }
1029 }
1030 }
1031 }
1032 return -1;
1033 }
1034
1035
1036 void Editwin::togg_mark (int i)
1037 {
1038 X_draw D (dpy (), _plotw->win (), dgc (), xft ());
1039 D.setfunc (GXxor);
1040 plot_mark (&D, i);
1041 }
1042
1043
1044 void Editwin::curr_mark (int i)
1045 {
1046 char s [32];
1047 Mark *A, *B;
1048
1049 if (i < 0)
1050 {
1051 if (_cmark != i)
1052 {
1053 _tmark->set_text ("");
1054 _tmark->set_color (Tst1.color.normal.bgnd, XftColors.mark_fg);
1055 }
1056 }
1057 else
1058 {
1059 A = _marks + i;
1060 B = _marks + (i ^ 1);
1061 if (B->_flags == Mark::OFF) sprintf (s, "%9d", A->_posit);
1062 else sprintf (s, "%9d (%+d)", A->_posit - _ind0, A->_posit - B->_posit);
1063 _tmark->set_text (s);
1064 if (_cmark != i) _tmark->set_color (Colors.plot_mk [i], XftColors.mark_fg);
1065 }
1066 _cmark = i;
1067 }
1068
1069
1070 void Editwin::plot_mark (X_draw *D, int i)
1071 {
1072 int x, y;
1073 Mark *M = _marks + i;
1074
1075 if (M->_flags != Mark::OFF)
1076 {
1077 x = (M->_posit - _fst0 - _data->tref_i ()) / _zoom;
1078 if ((x >= -4) && (x < _xd + 4))
1079 {
1080 D->setcolor (M->_color);
1081 y = 20 * (i + 1);
1082 D->move (x, 0);
1083 D->draw (x, _yd);
1084 D->drawrect (x - 4, y - 4, x + 4, y + 4);
1085 D->drawrect (x - 5, y - 5, x + 5, y + 5);
1086 }
1087 }
1088 }
1089
1090
1091 void Editwin::addtext (X_window *W, int xp, int yp, int xs, int ys, const char *text, int align)
1092 {
1093 (new X_textln (W, &Tst0, xp, yp, xs, ys, text, align))->x_map ();
1094 }
1095
1096
1097 int Editwin::_ztab [NZOOM] = { 1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, 1024, 1536, 2048 };
1098 int Editwin::_ytab [NYTAB] = { 1, 2, 5, 10, 15, 20, 30, 40, 60, 80, 120, 160 };
1099
1100