Esempio n. 1
0
void MSVGauge::drawGauge(void)
{
  if (mapped()==MSTrue)
   {
     int x=sliderAreaRect().x()+SliderAreaShadowThickness;
     int y=y_end();
     int curValue=valueToPixel(currentValue())+slider()->height();
     int startValue;
     if(_startValue.isSet()==MSTrue)
      {
        double sv=_startValue;
        if(sv<valueMin()) sv=valueMin();
	else if(sv>valueMax()) sv=valueMax();
	startValue=valueToPixel(sv)+slider()->height();
      }
     else startValue=y-SliderAreaShadowThickness;
     Direction direction=curValue<startValue?Up:Down;
     int thickness=slider()->shadowThickness();
     int h=abs(startValue-curValue); 
     int starty=(direction==Up)?startValue:curValue;
     
     if (h>=thickness&&slider()->width()>thickness*2)
      {
        int height=h-(h>thickness*2?thickness*2:thickness);
        XBFillRectangle(display(),window(),slider()->backgroundShadowGC(),
                        x+thickness,starty-h+thickness,slider()->width()-2*thickness,height);
      }
     if (h>thickness&&thickness>0)
      {
        drawGaugeShadow(x,starty,h,thickness,direction);
      }
     gaugeHeight(h);
     _direction=direction;
   }
}
Esempio n. 2
0
void MSVGauge::updateGauge(int h_)
{
  if (mapped()==MSTrue)
   {
     int x=sliderAreaRect().x()+SliderAreaShadowThickness;
     int y=y_end();
     int curValue=valueToPixel(h_)+slider()->height();
     int startValue;
     if(_startValue.isSet()==MSTrue)
      {
        double sv=_startValue;
        if(sv<valueMin()) sv=valueMin();
	else if(sv>valueMax()) sv=valueMax();
	startValue=valueToPixel(sv)+slider()->height();
      }
     else startValue=y-SliderAreaShadowThickness;
     Direction direction=curValue<startValue?Up:Down;
     int thickness=slider()->shadowThickness();
     int h=abs(startValue-curValue); 
     int starty=startValue;
     int height=abs(h-gaugeHeight());
             
     if (h==gaugeHeight() && direction==_direction) return;
     else if (direction==_direction)
      {
        if (h<gaugeHeight())
         {
           // value is smaller, clear area
           starty=direction==Up?starty-gaugeHeight():starty+h-thickness;
           XFillRectangle(display(),window(),selectShadowGC(),x,starty,slider()->width(),height+thickness);
         }
        else
         {
           // value is bigger, add area
           starty=direction==Up?starty-h+thickness:starty+gaugeHeight()-thickness;
           XFillRectangle(display(),window(),slider()->backgroundShadowGC(),x+thickness,
                          starty,slider()->width()-2*thickness,height);
         }
        if (h>thickness&&thickness>0) updateGaugeShadow(x,starty,h,thickness,direction);
      }
     else
      {
        // direction changed, redraw
        drawSliderArea();
        drawGauge();
      }
     gaugeHeight(h);
     _direction=direction;
   }
}
Esempio n. 3
0
void Chart::drawFullGraphLine() {
    boolean first = true;
    for( int i = 0 ; i < _numValues ; i++ ) {
    	int x = _x1+(i*_step);

    	_lcd->fillRect(0, x, _y1, x+_step, _y2);

        preventLCDBufferOverflow();

	    int value = constrain(  _y2-valueToPixel(_values[i]),
	    						_y1,
	    						_y2 );

    	if(x > _x2) {
            break;
	    }

        if(first) {

    	   first = false;
    	    _lcd->drawLine(_x1, value, x, value);

        } else {

            _lcd->continueLine(x+floor(_step/2), value);

        }

        preventLCDBufferOverflow();

    }
}
Esempio n. 4
0
void Chart::drawFullGraphBar(boolean relativeToOffset) {
    for( int i = 0 ; i < _numValues ; i++ ) {

        int x = _x1+(i*_step);


        int offsetPx = _y2;
		if(relativeToOffset) {
			offsetPx = _y2 - abs(_offset * _verticalRatio);
		}



        int value = constrain(  _y2-valueToPixel(_values[i]),
        						_y1,
        						_y2 );

	    drawBar(x, value, offsetPx);

        preventLCDBufferOverflow();
    }
}
Esempio n. 5
0
void AudioSignal::paintEvent(QPaintEvent* /*e*/)
{
    if (!m_aMonitoringEnabled->isChecked() || !isVisible()) {
        return;
    }
    QPainter p(this);
    int numchan = channels.size();
    bool horiz=width() > height();
    int dbsize = fontMetrics().width("-60") + 2;
    bool showdb=width()>(dbsize+2);
    const int h = IEC_Scale(-dbscale.at(0)) * height() - 2;

    //valpixel=1.0 for 127, 1.0+(1/40) for 1 short oversample, 1.0+(2/40) for longer oversample
    for (int i = 0; i < numchan; i++) {
        double valpixel=valueToPixel((double)(unsigned char)channels[i]/127.0);
        int maxx=  h  * valpixel;
        int xdelta= h / 42 ;
        int _y2= (showdb?width()-dbsize:width () ) / numchan - 1  ;
        int _y1= (showdb?width()-dbsize:width() ) *i/numchan;
        int _x2= maxx >  xdelta ? xdelta - 3 : maxx - 3 ;
        if (horiz){
            dbsize=9;
            showdb=height()>(dbsize);
            maxx=width()*valpixel; 
            xdelta = width() / 42;
            _y2=( showdb?height()-dbsize:height() ) / numchan - 1 ;
            _y1= (showdb?height()-dbsize:height() ) * i/numchan;
            _x2= maxx >  xdelta ? xdelta - 1 : maxx - 1;
        }

        for (int x = 0; x <= 42; x++) {
            int _x1= x *xdelta;
            QColor sig=Qt::green;
            //value of actual painted digit
            double ival=(double)_x1/(double)xdelta/42.0;
            if (ival > 40.0/42.0){
                sig=Qt::red;
            }else if ( ival > 37.0/42.0){
                sig=Qt::darkYellow;
            }else if ( ival >30.0/42.0){
                sig=Qt::yellow;
            }
            if (maxx > 0) {
                if (horiz){
                    p.fillRect(_x1, _y1, _x2, _y2, QBrush(sig, Qt::SolidPattern) );
                }else{
                    p.fillRect(_y1+dbsize, height()-_x1, _y2,-_x2, QBrush(sig, Qt::SolidPattern) );
                }
                maxx -= xdelta;
            }
        }
        int xp=valueToPixel((double)peeks.at(i)/127.0)*(horiz?width():h)-2;
        p.fillRect(horiz?xp:_y1+dbsize, horiz?_y1:height()-xdelta-xp, horiz?3:_y2, horiz?_y2:3, QBrush(Qt::black,Qt::SolidPattern));

    }
    if (showdb){
        //draw db value at related pixel
        for (int l=0;l<dbscale.size();l++){
            if (!horiz){
                double xf = IEC_Scale(dbscale.at(l)) * h;
                p.drawText(0, height() - xf + 2, QString().sprintf("%s%d",dbscale.at(l)>=0?"  ":"",dbscale.at(l)));
            }else{
                double xf = IEC_Scale(dbscale.at(l)) * (double) width();
                p.drawText(xf*40/42-10,height()-2, QString().sprintf("%d",dbscale.at(l)));
            }
        }
    }
    p.end();
}
Esempio n. 6
0
QImage AudioSignal::renderAudioScope(uint, const QVector<int16_t> audioFrame,
                                     const int, const int num_channels, const int samples, const int)
{
    QTime start = QTime::currentTime();

    int num_samples = samples > 200 ? 200 : samples;

    QByteArray channels;
    for (int i = 0; i < num_channels; i++) {
        long val = 0;
        for (int s = 0; s < num_samples; s ++) {
            val += abs(audioFrame[i+s*num_channels] / 128);
        }
        channels.append(val / num_samples);
    }

    if (peeks.count()!=channels.count()){
        peeks=QByteArray(channels.count(),0);
        peekage=QByteArray(channels.count(),0);
    }
    for (int chan=0;chan<peeks.count();chan++)
    {
        peekage[chan] = peekage[chan]+1;
        if (  peeks.at(chan)<channels.at(chan) ||  peekage.at(chan)>50 )
        {
            peekage[chan]=0;
            peeks[chan]=channels[chan];
        }
    }

    QImage image(m_scopeRect.size(), QImage::Format_ARGB32);
    image.fill(Qt::transparent);
    QPainter p(&image);
    p.setPen(Qt::white);
    p.setRenderHint(QPainter::TextAntialiasing, false);
    p.setRenderHint(QPainter::Antialiasing, false);
    
    int numchan = channels.size();
    bool horiz=width() > height();
    int dbsize=20;
    bool showdb=width()>(dbsize+40);
    //valpixel=1.0 for 127, 1.0+(1/40) for 1 short oversample, 1.0+(2/40) for longer oversample
    for (int i = 0; i < numchan; i++) {
        //int maxx= (unsigned char)channels[i] * (horiz ? width() : height() ) / 127;
        double valpixel=valueToPixel((double)(unsigned char)channels[i]/127.0);
        int maxx=  height()  * valpixel;
        int xdelta= height()   /42 ;
        int _y2= (showdb?width()-dbsize:width () ) / numchan - 1  ;
        int _y1= (showdb?width()-dbsize:width() ) *i/numchan;
        int _x2= maxx >  xdelta ? xdelta - 3 : maxx - 3 ;
        if (horiz){
            dbsize=9;
            showdb=height()>(dbsize);
            maxx=width()*valpixel;
            xdelta = width() / 42;
            _y2=( showdb?height()-dbsize:height() ) / numchan - 1 ;
            _y1= (showdb?height()-dbsize:height() ) * i/numchan;
            _x2= maxx >  xdelta ? xdelta - 1 : maxx - 1;
        }

        for (int x = 0; x <= 42; x++) {
            int _x1= x *xdelta;
            QColor sig=Qt::green;
            //value of actual painted digit
            double ival=(double)_x1/(double)xdelta/42.0;
            if (ival > 40.0/42.0){
                sig=Qt::red;
            }else if ( ival > 37.0/42.0){
                sig=Qt::darkYellow;
            }else if ( ival >30.0/42.0){
                sig=Qt::yellow;
            }
            if (maxx > 0) {
                if (horiz){
                    p.fillRect(_x1, _y1, _x2, _y2, QBrush(sig, Qt::SolidPattern) );
                }else{
                    p.fillRect(_y1, height()-_x1, _y2,-_x2, QBrush(sig, Qt::SolidPattern) );
                }
                maxx -= xdelta;
            }
        }
        int xp=valueToPixel((double)peeks.at(i)/127.0)*(horiz?width():height())-2;
        p.fillRect(horiz?xp:_y1,horiz?_y1:height()-xdelta-xp,horiz?3:_y2,horiz?_y2:3,QBrush(Qt::gray,Qt::SolidPattern));

    }
    if (showdb){
        //draw db value at related pixel
        for (int l=0;l<dbscale.size();l++){
            if (!horiz){
                double xf=pow(10.0,(double)dbscale.at(l) / 20.0 )*(double)height();
                p.drawText(width()-20,height()-xf*40.0/42.0+20, QString().sprintf("%d",dbscale.at(l)));
            }else{
                double xf=pow(10.0,(double)dbscale.at(l) / 20.0 )*(double)width();
                p.drawText(xf*40/42-10,height()-2, QString().sprintf("%d",dbscale.at(l)));
            }
        }
    }
    p.end();
    emit signalScopeRenderingFinished((uint) start.elapsed(), 1);
    return image;
}