1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/*
Copyright (C) 2009 Fons Adriaensen <fons@kokkinizita.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <math.h>
#include "mkimage.h"
#include "meter.h"
X_scale_style *Meter::_scale = 0;
XImage *Meter::_imag0 = 0;
XImage *Meter::_imag1 = 0;
Meter::Meter (X_window *parent, int xpos, int ypos) :
X_window (parent, xpos, ypos, XS, YS, 0),
_pixm (0),
_k (-1)
{
if (!_imag0 || !_imag1 || !_scale) return;
_pixm = XCreatePixmap (dpy (), win (), XS, YS, disp ()->depth ());
XPutImage (dpy (), _pixm, dgc (), _imag0, 0, 0, 0, 0, XS, YS);
XSetWindowBackgroundPixmap (dpy (), win (), _pixm);
}
Meter::~Meter (void)
{
if (_pixm) XFreePixmap (dpy (), _pixm);
}
void Meter::update (float v)
{
int y, k;
XSetFunction (dpy (), dgc (), GXcopy);
k = _scale->calcpix (v);
if (k > _k)
{
y = YS - 1 - k;
XPutImage (dpy (), _pixm, dgc (), _imag1, 0, y, 0, y, XS, k - _k);
}
else if (k < _k)
{
y = YS - 1 - _k;
XPutImage (dpy (), _pixm, dgc (), _imag0, 0, y, 0, y, XS, _k - k);
}
_k = k;
x_clear ();
}
void Meter::load_images (X_display *disp, X_scale_style *scale)
{
char s [1024];
_scale = scale;
snprintf (s, 1024, "%s/ambdec/meter0.png", SHARED);
_imag0 = mkimage (s, disp, 0);
snprintf (s, 1024, "%s/ambdec/meter1.png", SHARED);
_imag1 = mkimage (s, disp, 0);
}
|