2
Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22
#include "functionwin.h"
23
#include "callbacks.h"
28
Functionwin::Functionwin (X_window *parent, X_callback *callb, int xp, int yp,
29
unsigned long bgnd, unsigned long grid, unsigned long mark) :
30
X_window (parent, xp, yp, 100, 100, bgnd),
31
_callb (callb), _bgnd (bgnd), _grid (grid), _mark (mark)
33
x_add_events (ExposureMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask);
34
x_set_bit_gravity (NorthWestGravity);
35
for (int i = 0; i < NFUNC; i++)
47
Functionwin::~Functionwin (void)
49
for (int i = 0; i < NFUNC; i++)
57
void Functionwin::handle_event (XEvent *E)
62
expose ((XExposeEvent *) E);
66
bpress ((XButtonEvent *) E);
70
motion ((XPointerMovedEvent *) E);
74
brelse ((XButtonEvent *) E);
78
printf ("Multilsider::event %d\n", E->type);
83
void Functionwin::set_xparam (int n, int x0, int dx)
88
_xs = 2 * _x0 + (_n - 1) * _dx;
92
void Functionwin::set_yparam (int k, X_scale_style *scale, unsigned long color)
96
_ys = scale->pixlen ();
97
_ymax = _ys - 1 - scale->pix [0];
98
_ymin = _ys - 1 - scale->pix [scale->nseg];
104
_yc [k] = new int [_n];
105
_st [k] = new char [_n];
110
void Functionwin::show (void)
117
void Functionwin::reset (int k)
119
for (int i = 0; i < _n; i++)
127
void Functionwin::set_point (int k, int i, float v)
132
_yc [k][i] = _ys - 1 - _sc [k]->calcpix (v);
137
void Functionwin::upd_point (int k, int i, float v)
143
_yc [k][i] = _ys - 1 - _sc [k]->calcpix (v);
149
void Functionwin::clr_point (int k, int i)
160
void Functionwin::set_mark (int i)
171
void Functionwin::expose (XExposeEvent *E)
173
if (E->count) return;
178
void Functionwin::redraw (void)
182
for (int i = 0; i < NFUNC; i++) if (_sc [i]) plot_line (i);
186
void Functionwin::bpress (XButtonEvent *E)
194
i = (x + _dx / 2) / _dx;
195
if ((i < 0) || (i >= _n)) return;
196
if (abs (x - i * _dx) > 8) return;
201
if (E->state & ControlMask)
205
for (j = n = 0; j < _n; j++) if (st [j]) n++;
206
if ((n > 1) && (abs (y - yc [i]) <= 8))
214
_vc = _sc [_fc]->calcval (_ys - 1 - y);
215
_callb->handle_callb (CB_FW_SEL, this, 0);
216
_callb->handle_callb (CB_FW_UND, this, 0);
224
if (y > _ymax) y = _ymax;
225
if (y < _ymin) y = _ymin;
232
_vc = _sc [_fc]->calcval (_ys - 1 - y);
233
_callb->handle_callb (CB_FW_SEL, this, 0);
234
_callb->handle_callb (CB_FW_DEF, this, 0);
240
for (j = 0; j < NFUNC; j++)
242
if (_sc [j] && _st [j][i] && (abs (_yc [j][i] - y) <= 8))
246
if (_callb) _callb->handle_callb (CB_FW_SEL, this, 0);
254
void Functionwin::motion (XPointerMovedEvent *E)
258
if (E->state & Button3Mask) move_curve (E->y);
259
else move_point (E->y);
264
void Functionwin::brelse (XButtonEvent *E)
270
void Functionwin::plot_grid (void)
273
X_draw D (dpy (), win (), dgc (), 0);
279
for (i = 0; i <= _sc [0]->nseg; i++)
281
D.move (0, _ys - _sc [0]->pix [i] - 1);
285
for (i = 0; i <= 10; i++)
292
D.setcolor (Colors.main_ds);
299
void Functionwin::plot_mark (void)
301
X_draw D (dpy (), win (), dgc (), 0);
306
D.setcolor (_mark ^ _grid);
307
D.move (_x0 + _im * _dx, 0);
313
void Functionwin::plot_line (int k)
318
X_draw D (dpy (), win (), dgc (), 0);
322
D.setcolor (_co [k] ^ _bgnd);
327
if (st [0]) D.drawrect (x0 - 4, yc [i0] - 4, x0 + 4, yc [i0] + 4);
328
for (i1 = 1; i1 < _n; i1++)
333
if (st [i0]) D.move (x0, yc [i0]);
334
else D.move (x0, yc [i1]);
335
D.draw (x1, yc [i1]);
336
D.drawrect (x1 - 4, yc [i1] - 4, x1 + 4, yc [i1] + 4);
343
D.move (x0, yc [i0]);
344
D.draw (x1, yc [i0]);
349
void Functionwin::move_point (int y)
352
if (y > _ymax) y = _ymax;
353
if (y < _ymin) y = _ymin;
358
_vc = _sc [_fc]->calcval (_ys - 1 - y);
359
_callb->handle_callb (CB_FW_UPD, this, 0);
364
void Functionwin::move_curve (int y)
368
char *st = _st [_fc];
371
if (y > _ymax) y = _ymax;
372
if (y < _ymin) y = _ymin;
374
for (j = 0; j < _n; j++)
379
if (y > _ymax) y = _ymax;
380
if (y < _ymin) y = _ymin;
388
for (j = 0; j < _n; j++)
393
_vc = _sc [_fc]->calcval (_ys - 1 - yc [j]);
394
_callb->handle_callb (CB_FW_UPD, this, 0);