Ejemplo n.º 1
0
void PointImp::draw(LocationType pixelSize)
{
   if (isVisible() == false)
   {
      return;
   }

   PlotViewImp* pPlot = dynamic_cast<PlotViewImp*>(getPlot());
   VERIFYNRV(pPlot != NULL);

   if (pixelSize.mX == 0.0)
   {
      pixelSize.mX = 1.0;
   }

   if (pixelSize.mY == 0.0)
   {
      pixelSize.mY = 1.0;
   }

   double dSymbolSizeX = mSymbolSize / pixelSize.mX;
   double dSymbolSizeY = mSymbolSize / pixelSize.mY;
   double dWorldX = 0.0;
   double dWorldY = 0.0;

   pPlot->translateDataToWorld(mLocation.mX, mLocation.mY, dWorldX, dWorldY);

   // Increase point size when selected
   if (isSelected() == true)
   {
      switch (pPlot->getSelectionDisplayMode())
      {
      case SYMBOL_SELECTION: default:
         dSymbolSizeX = (mSymbolSize + 3) / pixelSize.mX;
         dSymbolSizeY = (mSymbolSize + 3) / pixelSize.mY;
         break;

      case INVERT_SELECTION:
         // Invert symbol color and draw slightly enlarged symbol behind it when selected
         glPushMatrix();
         glLineWidth(2);

         // Invert the color
         glColor3ub(255 - mColor.red(), 255 - mColor.green(), 255 - mColor.blue());

         // Draw the inverted symbol
         glTranslatef(dWorldX, dWorldY, 0);
         glScalef( (mSymbolSize + 1) / pixelSize.mX, (mSymbolSize + 1) / pixelSize.mY, 0);
         glCallList(pPlot->getDisplayListIndex() + mSymbol);
         glLineWidth(1);
         glPopMatrix();
         break;
      case BOX_SELECTION:
         // Draw a gray box around the symbol if it is selected
         glPushMatrix();
         glLineWidth(2);
         glColor3ub(212, 208, 200);

         glTranslatef(dWorldX, dWorldY, 0);
         glScalef((mSymbolSize+2) / pixelSize.mX, (mSymbolSize+2) / pixelSize.mY, 0);
         glCallList(pPlot->getDisplayListIndex() + BOX);
         glLineWidth(1);
         glPopMatrix();
         break;
      }
   }

   // Set the color
   glColor3ub(mColor.red(), mColor.green(), mColor.blue());

   glPushMatrix();
   glTranslatef(dWorldX, dWorldY, 0);
   glScalef(dSymbolSizeX, dSymbolSizeY, 0);
   glCallList(pPlot->getDisplayListIndex() + mSymbol);
   glPopMatrix();
}
Ejemplo n.º 2
0
void PointImp::draw(LocationType pixelSize)
{
   if (isVisible() == false)
   {
      return;
   }

   PlotViewImp* pPlot = dynamic_cast<PlotViewImp*>(getPlot());
   VERIFYNRV(pPlot != NULL);

   if (pixelSize.mX == 0.0)
   {
      pixelSize.mX = 1.0;
   }

   if (pixelSize.mY == 0.0)
   {
      pixelSize.mY = 1.0;
   }

   double dSymbolSizeX = mSymbolSize / pixelSize.mX;
   double dSymbolSizeY = mSymbolSize / pixelSize.mY;
   double dWorldX = 0.0;
   double dWorldY = 0.0;

   pPlot->translateDataToWorld(mLocation.mX, mLocation.mY, dWorldX, dWorldY);

   // Increase point size when selected
   if (isSelected() == true)
   {
      switch (pPlot->getSelectionDisplayMode())
      {
      case SYMBOL_SELECTION: default:
         dSymbolSizeX = (mSymbolSize + 3) / pixelSize.mX;
         dSymbolSizeY = (mSymbolSize + 3) / pixelSize.mY;
         break;

      case INVERT_SELECTION:
      {
         // Invert the background color and draw slightly enlarged symbol behind it when selected
         glPushMatrix();
         glLineWidth(2);

         // Invert the color
         QColor backgroundColor = pPlot->getBackgroundColor();

         int selectionHue = -1;
         int selectionSaturation = 255;
         int selectionValue = 255;

         int pointHue = mColor.hue();
         int backgroundHue = backgroundColor.hue();
         if ((pointHue > -1) && (backgroundHue > -1))
         {
            selectionHue = (pointHue + backgroundHue) / 2;
            if (abs(pointHue - backgroundHue) < 180)
            {
               selectionHue += 180;
            }
         }
         else if (pointHue > -1)
         {
            selectionHue = pointHue + 180;
         }
         else if (backgroundHue > -1)
         {
            selectionHue = backgroundHue + 180;
         }
         else
         {
            int pointValue = mColor.value();
            int backgroundValue = backgroundColor.value();

            selectionValue = (pointValue + backgroundValue) / 2;
            if (abs(pointValue - backgroundValue) < 128)
            {
               selectionValue += 128;
            }
         }

         while (selectionHue >= 360)
         {
            selectionHue -= 360;
         }

         while (selectionValue >= 256)
         {
            selectionValue -= 256;
         }

         QColor selectionColor = QColor::fromHsv(selectionHue, selectionSaturation, selectionValue);
         glColor3ub(selectionColor.red(), selectionColor.green(), selectionColor.blue());

         // Draw the inverted symbol
         glTranslatef(dWorldX, dWorldY, 0);
         glScalef((mSymbolSize + 2) / pixelSize.mX, (mSymbolSize + 2) / pixelSize.mY, 0);
         glCallList(pPlot->getDisplayListIndex() + mSymbol);
         glLineWidth(1);
         glPopMatrix();
         break;
      }

      case BOX_SELECTION:
         // Draw a gray box around the symbol if it is selected
         glPushMatrix();
         glLineWidth(2);
         glColor3ub(212, 208, 200);

         glTranslatef(dWorldX, dWorldY, 0);
         glScalef((mSymbolSize+2) / pixelSize.mX, (mSymbolSize+2) / pixelSize.mY, 0);
         glCallList(pPlot->getDisplayListIndex() + BOX);
         glLineWidth(1);
         glPopMatrix();
         break;
      }
   }

   // Set the color
   glColor3ub(mColor.red(), mColor.green(), mColor.blue());

   glPushMatrix();
   glTranslatef(dWorldX, dWorldY, 0);
   glScalef(dSymbolSizeX, dSymbolSizeY, 0);
   glCallList(pPlot->getDisplayListIndex() + mSymbol);
   glPopMatrix();
}