2
Copyright (C) 2003 Fons Adriaensen <fons.adriaensen@skynet.be>
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 "multislider.h"
23
#include "callbacks.h"
28
Multislider::Multislider (X_window *parent, X_callback *callb, int xp, int yp,
29
unsigned long grid, unsigned long mark) :
30
X_window (parent, xp, yp, 100, 100, Colors.func_bg),
32
_bgnd (Colors.func_bg),
33
_grid (grid), _mark (mark), _yc (0), _st (0),
34
_move (-1), _draw (-1)
36
x_add_events (ExposureMask | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask);
37
x_set_bit_gravity (NorthWestGravity);
42
Multislider::~Multislider (void)
49
void Multislider::handle_event (XEvent *E)
54
expose ((XExposeEvent *) E);
58
bpress ((XButtonEvent *) E);
62
motion ((XPointerMovedEvent *) E);
66
brelse ((XButtonEvent *) E);
70
printf ("Multilsider::event %d\n", E->type);
75
void Multislider::set_xparam (int n, int x0, int dx, int wx)
81
_xs = _n * _dx + 2 * x0;
89
void Multislider::set_yparam (X_scale_style *scale, int iref)
92
_ys = _scale->pixlen ();
93
_yr = _ys - 1 - _scale->pix [iref];
94
_ymax = _ys - 1 - _scale->pix [0];
95
_ymin = _ys - 1 - _scale->pix [_scale->nseg];
96
for (int i = 0; i < _n; i++)
104
void Multislider::show (void)
111
void Multislider::expose (XExposeEvent *E)
113
if (E->count) return;
118
void Multislider::redraw (void)
126
void Multislider::set_mark (int i)
137
void Multislider::plot_grid (void)
140
X_draw D (dpy (), win (), dgc (), 0);
145
for (i = 0; i <= _scale->nseg; i++)
147
D.move (0, _ys - _scale->pix [i] - 1);
151
for (i = 0; i < _n; i++)
158
D.setcolor (Colors.main_ds);
165
void Multislider::plot_mark (int k)
167
X_draw D (dpy (), win (), dgc (), 0);
172
x = _x0 + _im * _dx + _dx / 2;
175
D.setcolor (k ? _mark : _grid);
177
D.draw (x, (y < _yr) ? _yr + 1 : y + 1);
179
D.draw (x, (y < _yr) ? y + 1 : _yr + 1);
184
void Multislider::plot_bars (void)
187
X_draw D (dpy (), win (), dgc (), 0);
192
for (i = 0; i < _n; i++)
194
D.setcolor (_st [i] ? _col2 : _col1);
196
if (y < _yr) D.fillrect (x, y, x + _wx, _yr + 1);
197
else D.fillrect (x, _yr, x + _wx, y + 1);
203
void Multislider::plot_1bar (int i)
206
X_draw D (dpy (), win (), dgc (), 0);
209
D.setcolor (_st [i] ? _col2 : _col1);
210
x = _dx / 2 + _x0 + i * _dx;
213
if (y < _yr) D.fillrect (x, y, x + _wx, _yr + 1);
214
else D.fillrect (x, _yr, x + _wx, y + 1);
218
void Multislider::update_val (int i, int y)
221
if (y < _ymin) y = _ymin;
222
if (y > _ymax) y = _ymax;
227
_val = _scale->calcval (_ys - y - 1);
228
_callb->handle_callb (CB_MS_UPD, this, 0);
233
void Multislider::undefine_val (int i)
235
if (_callb && _st [i])
238
_callb->handle_callb (CB_MS_UND, this, 0);
243
void Multislider::update_bar (int i, int y)
245
int x, yc, ya0, ya1, ye0, ye1;
246
X_draw D (dpy (), win (), dgc (), 0);
252
x = i * _dx + _dx / 2 + _x0;
259
if (_yr < yc) ya0 = yc + 1;
260
else if (_yr > y) ye1 = y;
271
if (_yr > yc) ya1 = yc;
272
else if (_yr < y) ye0 = y + 1;
282
D.setcolor (_st [i] ? _col2 : _col1);
283
D.fillrect (x, ya0, x + _wx, ya1);
288
D.fillrect (x, ye0, x + _wx, ye1);
289
D.setcolor ((i == _im) ? _mark : _grid);
290
D.move (x + _wx / 2, ye0);
291
D.rdraw (0, ye1 - ye0);
293
for (i = 0; i <= _scale->nseg; i++)
295
y = _ys - _scale->pix [i] - 1;
296
if (y >= ye1) continue;
305
void Multislider::bpress (XButtonEvent *E)
311
if ((i < 0) || (i >= _n)) return;
312
x -= i * _dx + _dx / 2;
313
if (E->button == Button3)
316
if (E->state & ControlMask) undefine_val (i);
317
else update_val (i, E->y);
319
else if (2 * abs (x) <= _wx)
321
if (E->state & ControlMask) undefine_val (i);
322
else update_val (_move = i, E->y);
326
_callb->handle_callb (CB_MS_SEL, this, 0);
332
void Multislider::motion (XPointerMovedEvent *E)
336
if (_move >= 0) update_val (_move, E->y);
341
if ((i < 0) || (i >= _n)) return;
342
x -= i * _dx + _dx / 2;
343
if (2 * abs (x) > _wx) return;
345
if (E->state & ControlMask)
351
y = (E->state & ShiftMask) ? _yc [_draw] : E->y;
358
void Multislider::brelse (XButtonEvent *E)
365
void Multislider::set_col (int i, int c)
375
void Multislider::set_val (int i, int c, float v)
377
int y = _ys - 1 - _scale->calcpix (v);
379
if (c == _st [i]) update_bar (i, y);