Esempio n. 1
0
void EngineMeter::paintEvent(QPaintEvent *)
{
	if(!m_visible)
		hide();
	else if(isHidden())
		show();

	//info.info_log("r:%d\n",m_radius);
	QPainter painter(this);
	painter.setRenderHint(QPainter::Antialiasing);
	setAxis(&painter);

	if(m_compoment & BackGround)
		drawBackground(&painter);
	if(m_compoment & Crown)
		drawCrown(&painter,m_radius);

	drawScale(&painter,m_radius);
	drawScaleNum(&painter,m_radius);
	
	drawNumericValue(&painter);

	if(m_compoment & DoubleMeter)
	{
		drawInnerScale(&painter,m_center,m_radius-m_strech);
		drawInnerScaleNum(&painter,m_center,m_radius-m_strech);
	}
	if(m_compoment & NumericValue)
		drawNumericValue(&painter);

	//draw units
	if((m_compoment & Units) || (m_compoment & NumericRate))
	{
		if(!(m_compoment & NumericRate))		//rate is invisible
		{
			int haltw = int(1.7*m_radius); 
			QRect r(-haltw,-m_radius/2-8,haltw<<1,16);
			drawContexts(&painter,QRect(r),m_units,16*m_scale,Qt::AlignCenter,QPen(Qt::darkMagenta));
	 	}
		else	 
		{
			int haltw1 = int(1.7*m_radius); 
			QRect r(-haltw1,-m_radius/2,haltw1<<1,16);
		   	//QRect r(-40,15,80,20);	 
			QString rate = QStringLiteral("¡Á") + QString("%1").arg(m_rate);
			if(m_compoment & Units)		   //units is visible
				rate += " "+m_units;
			drawContexts(&painter,QRect(r),rate,16*m_scale,Qt::AlignCenter,QPen(Qt::darkMagenta));
		}
	}
	//draw title
	if(m_compoment & Title)
	{
		QRect rect(-width()/2,m_radius+2,width(),18);
		drawContexts(&painter,rect,m_title,18*m_scale,Qt::AlignCenter,QPen(Qt::yellow));
	}

	drawRuntime(&painter);
	drawIndicator(&painter);
}
Esempio n. 2
0
void GaugeCompass::paintEvent(QPaintEvent *)
{
    int width = this->width();
    int height = this->height();
    int side = qMin(width, height);

    //绘制准备工作,启用反锯齿,平移坐标轴中心,等比例缩放
    QPainter painter(this);
    painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing);
    painter.translate(width / 2, height / 2);    
    painter.scale(side / 200.0, side / 200.0);

    //绘制外边框圆
    drawCrownCircle(&painter);
    //绘制背景圆
    drawBgCircle(&painter);
    //绘制刻度
    drawScale(&painter);
    //绘制东南西北标识
    drawScaleNum(&painter);
    //绘制覆盖圆外圆
    drawCoverOuterCircle(&painter);
    //绘制覆盖圆内圆
    drawCoverInnerCircle(&painter);
    //绘制覆盖圆中心圆
    drawCoverCenterCircle(&painter);
    //绘制南北指针
    drawPointer(&painter);
    //绘制中心圆
    drawCenterCircle(&painter);
    //绘制当前值
    drawText(&painter);
}
Esempio n. 3
0
void caCircularGauge::paintEvent(QPaintEvent *)
{
    QPainter	painter(this);
    int size = qMin(height(), width());

    /* see http://doc.trolltech.com/4.4/coordsys.html#window-viewport-conversion for a analogous example */
    painter.setRenderHint(QPainter::Antialiasing);
    painter.setViewport((int)((width()-size)*.5),(int)((height()-size)*.5),size,size);
    painter.setWindow(-50,-50,100,100);

    drawColorBar(&painter);

    if (isEnabled())
        drawNeedle(&painter);

    if (m_valueDisplayed)
        drawValue(&painter);

    if (!isEnabled())
    {
        QColor c = palette().color(QPalette::Background);
        c.setAlpha(200);
        painter.fillRect(painter.window(), c);
    }
    if (m_scaleEnabled)
    {
        drawScale(&painter);
        drawLabels(&painter);
    }
}
Esempio n. 4
0
void Thermometer::paintEvent(QPaintEvent *)
{
    painter.begin(this);

    drawTitle();
    drawUnit();
    drawLabel();
    drawDisplay();
    drawScale();
    drawMeter();
    drawRange();
    drawPointer();

    painter.end();
}
void LocMicView::showNewPixmap()
{
//	std::cerr << "showing new pixmap ...";
	QPoint sizePx = nmToPx(dimensionsNm_.bottomRight());
	QImage img((uchar*) pixmapData_, sizePx.x(), sizePx.y(), QImage::Format_ARGB32);
	
	QPixmap pixmap = QPixmap::fromImage(img);
	drawScale(&pixmap);
	imageWidget_->setPixmap(pixmap);
	
	scaleFactor_ = 1.0;

	imageWidget_->repaint();
//	std::cerr << "done" << std::endl;
}
Esempio n. 6
0
void ScalePlot::draw ()
{
  buffer.fill(backgroundColor);

  if (activeFlag)
  {
    if (buffer.isNull())
    {
      buffer.resize(this->width(), this->height());
      buffer.fill(backgroundColor);
    }

    drawScale();
  }

  update();
}
Esempio n. 7
0
void MyShape::draw() {
    glPushMatrix();

    //Translate
    glTranslatef(pos[0], pos[1], pos[2]);

    //Rotate
    // TODO TURN THIS BACK ON. YOU ARE NOT ROTATING ANYTHING RIGHT NOW
    glMultMatrixf( (const GLfloat*)orientationMat);

    //Scale
    drawScale();

    glColor3fv(color);

    drawUnit();
    glPopMatrix();
}
Esempio n. 8
0
void mySpeedWatch::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing); 	/* 使用反锯齿(如果可用) */
    painter.translate(width() / 2, height() / 2);	/* 坐标变换为窗体中心 */
    int side = qMin(width(), height());
    painter.scale(side / 200.0, side / 200.0);		/* 比例缩放 */
    painter.setPen(Qt::NoPen);
    
    drawCrown(&painter);							/* 画边框 */
    drawBackground(&painter);						/* 画背景 */
    drawScaleNum(&painter);							/* 画刻度值 */
    drawScale(&painter);							/* 画刻度线 */
    drawTitle(&painter);							/* 画单位 */

    if(m_numericIndicatorEnabled)
        drawNumericValue(&painter);					/* 画数字显示 */
    drawIndicator(&painter);						/* 画指针 */
}
Esempio n. 9
0
void caLinearGauge::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    int size, w, h;
    QFontMetrics fm(painter.font());

    h = fm.height()+2;
    w = fm.width(labels[longestLabelIndex])+2;

    if (m_orientation == Qt::Horizontal) {
        size = qMin((int)(width()*totalSize/100.0), height());
    } else {
        size = qMin((int)(height()*totalSize/100.0), width());
    }

    painter.setRenderHint(QPainter::Antialiasing);

    if (m_orientation == Qt::Horizontal) {
        painter.setViewport((int)((width()-size*100.0/totalSize)*.5),(int)((height()-size)*.5), (int)(size*100.0/totalSize), size);
        painter.setWindow((int)(-w*.5), 0, 100+w, totalSize+2); /* border */
    } else {
        painter.setViewport((int)((width()-size)*.5),(int)((height()-size*100.0/totalSize)*.5), size, (int)(size*100.0/totalSize));
        painter.setWindow(-2, (int)(-h*.5), totalSize+2, 100+h); /* border */
    }
    painter.setViewport(0,0, width(), height()); // A.Mezger I do not like above behaviour when resizing

    drawColorBar(&painter);
    if (m_scaleEnabled)
    {
        drawScale(&painter);
        drawLabels(&painter);
    }
    if (isEnabled() && (m_fillMode == ALL))
        drawMarker(&painter, true);

    if (!isEnabled())
    {
        QColor c = palette().color(QPalette::Background);
        c.setAlpha(200);
        painter.fillRect(painter.window(), c);
    }
}
Esempio n. 10
0
void CanvasDrawer::drawCanvas(PoseState& curPose, bool _isTruth){

	//画连线 gPose->curPose
	cv::line(matPathCanvas, 
		gPointBase + CFG_dDrawFrameStep*cv::Point2f(gPose.pos.x, -gPose.pos.z),
		gPointBase + CFG_dDrawFrameStep*cv::Point2f(curPose.pos.x, -curPose.pos.z),
		cv::Scalar(-1));

	
	//画新点
	cv::circle(matPathCanvas, gPointBase + CFG_dDrawFrameStep* cv::Point2f(curPose.pos.x, -curPose.pos.z), 1, cv::Scalar(-1));
	
	// 绘制GroundTruth路径
	if ( _isTruth &&  ptrPoseHelper && ptrPoseHelper->inited()) {
		cv::Point3d posGroundTruth = ptrPoseHelper->getPosition(curPose.idxImg, idxImgBegin);
		cv::circle(matPathCanvas, gPointBase + CFG_dDrawFrameStep*cv::Point2f(posGroundTruth.x, -posGroundTruth.z), 1, cv::Scalar(255, 0, 255));
	}

	//克隆一下 matCanvas 画一下方向
	cv::Mat matTmpCanvas = matPathCanvas.clone();
	cv::line(matTmpCanvas,
		gPointBase + CFG_dDrawFrameStep*cv::Point2f(curPose.pos.x, -curPose.pos.z),
		gPointBase + CFG_dDrawFrameStep*cv::Point2f(curPose.pos.x, -curPose.pos.z) + 10.0f*CFG_dDrawFrameStep * cv::Point2f(curPose.dir.x, -curPose.dir.z),
		cv::Scalar(255, 0, 0));


	cv::imshow(cv::format("%s-%s", "Canvas", CFG_sDataName.c_str()), matTmpCanvas);
	//刷新绘图
	cv::waitKey(1);

	logPose(curPose, gPose);
	drawScale(curPose, gPose);

	//每隔100输出一次图像,方便查看
	if (curPose.idxImg/100 != gPose.idxImg/100) {
		cv::imwrite(sPathRecordFile + ".png", matTmpCanvas);
	}

	//更新 gPose到新的坐标
	gPose = curPose;
}
Esempio n. 11
0
/*!
  \brief Draw the contents inside the frame

  QPalette::Window is the background color outside of the frame.
  QPalette::Base is the background color inside the frame.
  QPalette::WindowText is the background color inside the scale.

  \param painter Painter
  \sa boundingRect(), innerRect(),
    scaleInnerRect(), QWidget::setPalette()
*/
void QwtDial::drawContents( QPainter *painter ) const
{
    if ( testAttribute( Qt::WA_NoSystemBackground ) ||
        palette().brush( QPalette::Base ) !=
            palette().brush( QPalette::Window ) )
    {
        const QRectF br = boundingRect();

        painter->save();
        painter->setPen( Qt::NoPen );
        painter->setBrush( palette().brush( QPalette::Base ) );
        painter->drawEllipse( br );
        painter->restore();
    }


    const QRectF insideScaleRect = scaleInnerRect();
    if ( palette().brush( QPalette::WindowText ) !=
            palette().brush( QPalette::Base ) )
    {
        painter->save();
        painter->setPen( Qt::NoPen );
        painter->setBrush( palette().brush( QPalette::WindowText ) );
        painter->drawEllipse( insideScaleRect );
        painter->restore();
    }

    const QPointF center = insideScaleRect.center();
    const double radius = 0.5 * insideScaleRect.width();

    double direction = d_data->origin;

    if ( isValid() )
    {
        direction = d_data->minScaleArc;
        if ( maxValue() > minValue() &&
            d_data->maxScaleArc > d_data->minScaleArc )
        {
            const double ratio =
                ( value() - minValue() ) / ( maxValue() - minValue() );
            direction += ratio * ( d_data->maxScaleArc - d_data->minScaleArc );
        }

        if ( d_data->direction == QwtDial::CounterClockwise )
            direction = d_data->maxScaleArc - ( direction - d_data->minScaleArc );

        direction += d_data->origin;
        if ( direction >= 360.0 )
            direction -= 360.0;
        else if ( direction < 0.0 )
            direction += 360.0;
    }

    double origin = d_data->origin;
    if ( mode() == RotateScale )
    {
        origin -= direction - d_data->origin;
        direction = d_data->origin;
    }

    painter->save();
    drawScale( painter, center, radius, origin,
        d_data->minScaleArc, d_data->maxScaleArc );
    painter->restore();

    painter->save();
    drawScaleContents( painter, center, radius );
    painter->restore();

    if ( isValid() )
    {
        QPalette::ColorGroup cg;
        if ( isEnabled() )
            cg = hasFocus() ? QPalette::Active : QPalette::Inactive;
        else
            cg = QPalette::Disabled;

        painter->save();
        drawNeedle( painter, center, radius, direction, cg );
        painter->restore();
    }
}
Esempio n. 12
0
void drawContext::drawView()
{
  OrthofFromGModel();

  glMatrixMode(GL_MODELVIEW);
  // fill the background
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  if(CTX::instance()->bgGradient){
    glPushMatrix();
    glLoadIdentity();
    const GLfloat squareVertices[] = {
      (GLfloat)_top,	(GLfloat)_left, 2*_far,
      (GLfloat)_top,	(GLfloat)_right, 2*_far,
      (GLfloat)_bottom,	(GLfloat)_left, 2*_far,
      (GLfloat)_bottom,	(GLfloat)_right, 2*_far,
    };
    const GLubyte squareColors[] = {
      255, 255, 255, 255,
      255, 255, 255, 255,
      190, 200, 255, 255,
      190, 200, 255, 255,
    };
    glVertexPointer(3, GL_FLOAT, 0, squareVertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
    glEnableClientState(GL_COLOR_ARRAY);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
    glPopMatrix();
  }
  checkGlError("Draw background");

  glLoadIdentity();
  glScalef(_scale[0], _scale[1], _scale[2]);
  glTranslatef(_translate[0], _translate[1], _translate[2]);

  if(CTX::instance()->rotationCenterCg)
    glTranslatef(CTX::instance()->cg[0],
                 CTX::instance()->cg[1],
                 CTX::instance()->cg[2]);
  else
    glTranslatef(CTX::instance()->rotationCenter[0],
                 CTX::instance()->rotationCenter[1],
                 CTX::instance()->rotationCenter[2]);

  buildRotationMatrix();
  glMultMatrixf(_rotatef);

  if(CTX::instance()->rotationCenterCg)
    glTranslatef(-CTX::instance()->cg[0],
                 -CTX::instance()->cg[1],
                 -CTX::instance()->cg[2]);
  else
    glTranslatef(-CTX::instance()->rotationCenter[0],
                 -CTX::instance()->rotationCenter[1],
                 -CTX::instance()->rotationCenter[2]);

  checkGlError("Initialize position");

  glEnable(GL_DEPTH_TEST);

  drawMesh();
  checkGlError("Draw mesh");
  drawGeom();
  checkGlError("Draw geometry");
  drawPost();
  checkGlError("Draw post-pro");
  glDisable(GL_DEPTH_TEST);
  drawScale();
  checkGlError("Draw scales");
  drawAxes();
  checkGlError("Draw axes");
}
Esempio n. 13
0
/*!
  \brief Draw the contents inside the frame
 
  QColorGroup::Background is the background color outside of the frame.
  QColorGroup::Base is the background color inside the frame.
  QColorGroup::Foreground is the background color inside the scale.

  \param painter Painter
  \sa QwtDial::boundingRect, QwtDial::contentsRect,
    QwtDial::scaleContentsRect, QWidget::setPalette
*/
void QwtDial::drawContents(QPainter *painter) const
{
    if ( backgroundMode() == NoBackground || 
        colorGroup().brush(QColorGroup::Base) != 
            colorGroup().brush(QColorGroup::Background) )
    {
        // Don´t use QPainter::drawEllipse. There are some pixels
        // different compared to the region in the mask, leaving
        // them in background color.

        painter->save();
        painter->setPen(Qt::NoPen);
        painter->setBrush(colorGroup().brush(QColorGroup::Base));

        // Even if we want to fill the contentsRect only, we fill the
        // complete boundingRect. The frame will be painted later
        // above, but we want to have the base color below it
        // because round objects doesn´t cover all pixels.

        QRect br = boundingRect();
#if QT_VERSION < 300
#ifdef _WS_WIN32_
        // Qt-230-NC draws ellipses not as nicely as Qt-2.3.x on X Windows
        br.setTop(br.top()-1);
        br.setLeft(br.left()-1);
        br.setBottom(br.bottom()+1);
        br.setRight(br.right()+1);
#endif
#endif
        painter->setClipRegion(QRegion(painter->xForm(br), QRegion::Ellipse));
        painter->drawRect(br);
        painter->restore();
    }


    const QRect insideScaleRect = scaleContentsRect();
    if ( colorGroup().brush(QColorGroup::Foreground) !=
        colorGroup().brush(QColorGroup::Base) )
    {
        painter->save();
        painter->setPen(Qt::NoPen);
        painter->setBrush(colorGroup().brush(QColorGroup::Foreground));

        painter->setClipRegion(
            QRegion(painter->xForm(insideScaleRect), QRegion::Ellipse));
        painter->drawRect(insideScaleRect);
        painter->restore();
    }

    const QPoint center = insideScaleRect.center();
    const int radius = insideScaleRect.width() / 2;

    painter->save();
    drawScaleContents(painter, center, radius);
    painter->restore();

    double direction = d_origin;

    if (isValid())
    {
        direction = d_origin + d_minScaleArc;
        if ( maxValue() > minValue() && d_maxScaleArc > d_minScaleArc )
        {
            const double ratio = 
                (value() - minValue()) / (maxValue() - minValue());
            direction += ratio * (d_maxScaleArc - d_minScaleArc);
        }

        if ( direction >= 360.0 )
            direction -= 360.0;
    }

    double origin = d_origin;
    if ( mode() == RotateScale )
    {
        origin -= direction - d_origin;
        direction = d_origin;
    }

    painter->save();
    drawScale(painter, center, radius, origin, d_minScaleArc, d_maxScaleArc);
    painter->restore();

    if ( isValid() )
    {
        QPalette::ColorGroup cg;
        if ( isEnabled() )
            cg = hasFocus() ? QPalette::Active : QPalette::Inactive;
        else
            cg = QPalette::Disabled;

        painter->save();
        drawNeedle(painter, center, radius, direction, cg);
        painter->restore();
    }
}
Esempio n. 14
0
void CLogGraph::drawHeader(CDC& dc)
{
	XTPPaintManager()->GradientFill(&dc, m_rectHeader,m_crHeaderBack, RGB(0,0,0), FALSE);

	CPen* pOldPen, pen;
	CFont* pOldFont;
	CString fmt, s;
	int i;

	if (m_nScaleIndex != -1)
		drawScale(dc, m_nScaleIndex, m_rectScale, DT_RIGHT);

	if (m_nScaleIndex2 != -1)
		drawScale(dc, m_nScaleIndex2, m_rectScale2, DT_LEFT);

	// draw Header (로그 시작점, 로그 끝점 표시)

	CString tmp;

	pOldFont = dc.SelectObject(&m_fontHeader);
	dc.SetTextColor(m_crHeader);

	if (!m_bLoad)return;
	//short* a = new short [lib->mque_reclen(m_hQue)]; //////////////
	tdata* tp = getTptr(m_nCurrentPos);
	// read date
//	lib->mque_getn(m_hQue, m_nCurrentPos+1, a);
	m_tStart = tp->time;
	s = tformat("%Y-%m-%d\r\n%H:%M:%S", m_tStart);
	tmp.Format("%s\r\n%d", s, m_nCurrentPos);
	dc.DrawText(tmp, &m_rectHeader, DT_LEFT);

//	lib->mque_getn(m_hQue, getWndQueLastPos()-1, a);
	tp = getTptr(getWndQueLastPos()-1);
//	m_tEnd = lib->mque_time(m_hQue);
//	s = tformat("%Y-%m-%d\r\n%H:%M:%S", (int)m_tEnd);
	tmp.Format("%s\r\n%d", s, getWndQueLastPos());
	dc.DrawText(tmp, &m_rectHeader, DT_RIGHT);
//	delete a;

	// draw Header (nav button, zoom)
	
	int nav[4][20] = {		// 20x20 짜리 nav button
		{ 1,1,  4,1,  4,8,  18,1,  18,19,  4,12,  4,19,  1,19,  1,1,  0,0 },		// home
		{ 1,10,  10,1,  10,8,  19,1,  19,19,  10,12,  10,19,  1,10,  0,0 },			// pgup
		{ 1,1,   10,8,  10,1,  19,10,  10,19,  10,12,   1,19,  1,1,  0,0 },			// pgdn
		{ 1,1,  16,8,  16,1,  19,1,  19,19,  16,19,  16,12,  1,19,  1,1,  0,0 }		// end
	};

	CRect r = m_rectHeader;
	int w = 20;				// button width & height
	int iw = w - 4;		// icon size

	CBrush brush;
	CRgn rgn;
	CPoint pt[20];

	brush.CreateSolidBrush(RGB(255, 100, 100));
	pen.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
	pOldPen = dc.SelectObject(&pen);
	r.left = r.Width() / 2 - (w * 4) / 2;
	r.right = r.left + w * 4;
	r.bottom = r.top + w;
	int x = r.left;
	for (i = 0; i < 4; i++) {
		CRect rect = r;
		rect.left = x + 1;
		rect.right = x + w - 1;
		rect.top++;
		rect.bottom--;
		switch (i) {
			case 0 : m_rectHome = rect; break;
			case 1 : m_rectPgUp = rect; break;
			case 2 : m_rectPgDn = rect; break;
			case 3 : m_rectEnd = rect; break;
		}

		XTPPaintManager()->GradientFill(&dc, &rect, RGB(100,100,100), RGB(0,0,0), FALSE);
		int j;
		for (j = 0; nav[i][j] !=0; j+=2) {
			pt[j/2].x = int(double(nav[i][j]) * iw / 20.0) + x + 2;
			pt[j/2].y = int(double(nav[i][j+1]) * iw / 20.0) + r.top + 2;
		}
		VERIFY(rgn.CreatePolygonRgn(pt, j/2, WINDING));
		dc.FillRgn(&rgn, &brush);
		rgn.DeleteObject();
		x += w;
	}
	dc.SelectObject(pOldPen);

	r.top = r.top + w;
	r.DeflateRect(2, 2);
	r.bottom = m_rectHeader.bottom;
	m_rectZoom = r;

	XTPPaintManager()->GradientFill(&dc, &r, RGB(100,50,50), RGB(0,0,0), FALSE);
	s.Format("Zoom %.0f:1", m_fZoomFactor);
	dc.DrawText(s, &r, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

	dc.SelectObject(pOldFont);
}
Esempio n. 15
0
void drawContext::drawScales()
{
  std::vector<PView*> scales;
  for(unsigned int i = 0; i < PView::list.size(); i++){
    PViewData *data = PView::list[i]->getData();
    PViewOptions *opt = PView::list[i]->getOptions();
    if(!data->getDirty() && opt->visible && opt->showScale &&
       opt->type == PViewOptions::Plot3D && data->getNumElements() &&
       isVisible(PView::list[i]))
      scales.push_back(PView::list[i]);
  }
  if(scales.empty()) return;

  drawContext::global()->setFont(CTX::instance()->glFontEnum,
                                 CTX::instance()->glFontSize);
  char label[1024];
  double maxw = 0.;
  for(unsigned int i = 0; i < scales.size(); i++) {
    PViewOptions *opt = scales[i]->getOptions();
    sprintf(label, opt->format.c_str(), -M_PI * 1.e-4);
    maxw = std::max(maxw, drawContext::global()->getStringWidth(label));
  }

  const double tic = 10., bar_size = 16.;
  double width = 0., width_prev = 0., width_total = 0.;

  for(unsigned int i = 0; i < scales.size(); i++) {
    PView *p = scales[i];
    PViewData *data = p->getData();
    PViewOptions *opt = p->getOptions();

    if(!opt->autoPosition) {
      double w = opt->size[0], h = opt->size[1];
      double x = opt->position[0], y = opt->position[1] - h;
      int c = fix2dCoordinates(&x, &y);
      if(c & 1) x -= w / 2.;
      if(c & 2) y += h / 2.;
      drawScale(this, p, x, y, w, h, tic, CTX::instance()->post.horizontalScales);
    }
    else if(CTX::instance()->post.horizontalScales){
      double ysep = 20.;
      double xc = (viewport[2] - viewport[0]) / 2.;
      if(scales.size() == 1){
        double w = (viewport[2] - viewport[0]) / 2., h = bar_size;
        double x = xc - w / 2., y = viewport[1] + ysep;
        drawScale(this, p, x, y, w, h, tic, 1);
      }
      else{
        double xsep = maxw / 4. + (viewport[2] - viewport[0]) / 10.;
        double w = (viewport[2] - viewport[0] - 4 * xsep) / 2.;
        if(w < 20.) w = 20.;
        double h = bar_size;
        double x = xc - (i % 2 ? -xsep / 1.5 : w + xsep / 1.5);
        double y = viewport[1] + ysep +
          (i / 2) * (bar_size + tic +
                     2 * drawContext::global()->getStringHeight() + ysep);
        drawScale(this, p, x, y, w, h, tic, 1);
      }
    }
    else{
      double xsep = 20.;
      double dy = 2. * drawContext::global()->getStringHeight();
      if(scales.size() == 1){
        double ysep = (viewport[3] - viewport[1]) / 6.;
        double w = bar_size, h = viewport[3] - viewport[1] - 2 * ysep - dy;
        double x = viewport[0] + xsep, y = viewport[1] + ysep + dy;
        drawScale(this, p, x, y, w, h, tic, 0);
      }
      else{
        double ysep = (viewport[3] - viewport[1]) / 15.;
        double w = bar_size;
        double h = (viewport[3] - viewport[1] - 3 * ysep - 2.5 * dy) / 2.;
        double x = viewport[0] + xsep + width_total + (i / 2) * xsep;
        double y = viewport[1] + ysep + dy + (1 - i % 2) * (h + 1.5 * dy + ysep);
        drawScale(this, p, x, y, w, h, tic, 0);
      }
      // compute width
      width_prev = width;
      sprintf(label, opt->format.c_str(), -M_PI * 1.e-4);
      width = bar_size + tic + drawContext::global()->getStringWidth(label);
      if(opt->showTime){
        char tmp[256];
        sprintf(tmp, opt->format.c_str(), data->getTime(opt->timeStep));
        sprintf(label, "%s (%s)", data->getName().c_str(), tmp);
      }
      else
        sprintf(label, "%s", data->getName().c_str());
      width = std::max(width, drawContext::global()->getStringWidth(label));
      if(i % 2) width_total += std::max(bar_size + width, bar_size + width_prev);
    }
  }
}