Esempio n. 1
0
/*
 * SetBoxColors - set the values of the color boxes
 *              - all coordinates are using the Windows convention of the
 *                top left as the origin
 */
void SetBoxColors( palette_box *screen, palette_box *inverse,
                   int num_colors, palette_box *avail_colors )
{
    short               i;
    wie_clrtype         type;
    WPI_PRES            pres;
    COLORREF            rgbcolor;

    leftColorIndex = getColorIndex( GetSelectedColor( LMOUSEBUTTON, NULL, &type ) );
    rightColorIndex = getColorIndex( GetSelectedColor( RMOUSEBUTTON, NULL, &type ) );
    chooseThePalette( num_colors );

    /*
     * First initialize the screen color boxes.
     */
    screen->box.left = SCRN_COL_X;
    screen->box.right = SCRN_COL_X + SQR_SIZE + 1;
    screen->box.top = SCRN_COL_Y;
    screen->box.bottom = SCRN_COL_Y + SQR_SIZE + 1;

    inverse->box.left = SCRN_COL_X;
    inverse->box.right = SCRN_COL_X + SQR_SIZE + 1;
    inverse->box.top = SCRN_COL_Y + SQR_SIZE;
    inverse->box.bottom = SCRN_COL_Y + 2 * SQR_SIZE + 1;

    pres = _wpi_getpres( HWND_DESKTOP );
    _wpi_torgbmode( pres );

    for( i = 0; i < PALETTE_SIZE; i += 2 ) {
        rgbcolor = RGB( palette[currentPalIndex][i].rgbRed,
                        palette[currentPalIndex][i].rgbGreen,
                        palette[currentPalIndex][i].rgbBlue );
        avail_colors[i].color = _wpi_getcolorindex( pres, rgbcolor );
        if( num_colors == 2 ) {
            avail_colors[i].solid_color = WHITE;
        } else {
            avail_colors[i].solid_color = _wpi_getnearestcolor( pres, rgbcolor );
        }
        avail_colors[i].box.left = (i / 2) * SQR_SIZE;
        avail_colors[i].box.top = 0;
        avail_colors[i].box.right = SQR_SIZE + (i / 2) * SQR_SIZE + 1;
        avail_colors[i].box.bottom = SQR_SIZE + 1;

        rgbcolor = RGB( palette[currentPalIndex][i + 1].rgbRed,
                        palette[currentPalIndex][i + 1].rgbGreen,
                        palette[currentPalIndex][i + 1].rgbBlue );
        avail_colors[i + 1].color = _wpi_getcolorindex( pres, rgbcolor );
        if( num_colors == 2 ) {
            avail_colors[i + 1].solid_color = BLACK;
        } else {
            avail_colors[i + 1].solid_color = _wpi_getnearestcolor( pres, rgbcolor );
        }
        avail_colors[i + 1].box.left = avail_colors[i].box.left;
        avail_colors[i + 1].box.top = SQR_SIZE;
        avail_colors[i + 1].box.right = avail_colors[i].box.right;
        avail_colors[i + 1].box.bottom = SQR_SIZE * 2 + 1;
    }
    _wpi_releasepres( HWND_DESKTOP, pres );

} /* SetBoxColors */
Esempio n. 2
0
/*
 * ResetColorPalette - reset the color palette to its original form (the way it
 *                     is when the program is first executed or the way it was
 *                     most recently loaded) in response to hitting the Restore button
 */
void ResetColorPalette( void )
{
    int         i;
    COLORREF    leftcolor;
    COLORREF    rightcolor;
    COLORREF    color;
    WPI_PRES    pres;
    int         leftindex;
    int         rightindex;
    wie_clrtype lefttype;
    wie_clrtype righttype;

    if( currentPalIndex != COLOR_16 && currentPalIndex != COLOR_256 ) {
        return;
    }
    leftcolor = GetSelectedColor( LMOUSEBUTTON, NULL, &lefttype );
    rightcolor = GetSelectedColor( RMOUSEBUTTON, NULL, &righttype );

    leftindex = getColorIndex( leftcolor );
    rightindex = getColorIndex( rightcolor );

    for( i = 0; i < PALETTE_SIZE - 1; i++ ) {
        palette[currentPalIndex][i] = restorePalette[i];
        ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed,
                              palette[currentPalIndex][i].rgbGreen,
                              palette[currentPalIndex][i].rgbBlue ), FALSE );
    }
    /*
     * We do the last one separately to invalidate the window.
     */
    palette[currentPalIndex][i] = restorePalette[i];
    ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed,
                          palette[currentPalIndex][i].rgbGreen,
                          palette[currentPalIndex][i].rgbBlue ), TRUE );

    if( lefttype == NORMAL_CLR ) {
        color = RGB( palette[currentPalIndex][leftindex].rgbRed,
                     palette[currentPalIndex][leftindex].rgbGreen,
                     palette[currentPalIndex][leftindex].rgbBlue );
        pres = _wpi_getpres( HWND_DESKTOP );
        _wpi_torgbmode( pres );
        SetColor( LMOUSEBUTTON, color, _wpi_getnearestcolor( pres, color ), NORMAL_CLR );
        _wpi_releasepres( HWND_DESKTOP, pres );
    }
    if( righttype == NORMAL_CLR ) {
        color = RGB( palette[currentPalIndex][rightindex].rgbRed,
                     palette[currentPalIndex][rightindex].rgbGreen,
                     palette[currentPalIndex][rightindex].rgbBlue );
        pres = _wpi_getpres( HWND_DESKTOP );
        _wpi_torgbmode( pres );
        SetColor( RMOUSEBUTTON, color, _wpi_getnearestcolor( pres, color ), NORMAL_CLR );
        _wpi_releasepres( HWND_DESKTOP, pres );
    }

} /* ResetColorPalette */
Esempio n. 3
0
/*
 * ReplacePaletteEntry - replace the current entry with the given RGB value
 */
void ReplacePaletteEntry( COLORREF newcolor )
{
    COLORREF            cur_color;
    COLORREF            nearestcolor;
    COLORREF            screencolor;
    COLORREF            rightcolor;
    wie_clrtype         lefttype;
    wie_clrtype         righttype;
    int                 index;
    int                 rightindex;
    WPI_PRES            pres;

    if( currentPalIndex != COLOR_16 && currentPalIndex != COLOR_256 ) {
        return;
    }
    cur_color = GetSelectedColor( LMOUSEBUTTON, NULL, &lefttype );

    if( lefttype == NORMAL_CLR ) {
        index = getColorIndex( cur_color );

        rightcolor = GetSelectedColor( RMOUSEBUTTON, NULL, &righttype );
        rightindex = getColorIndex( rightcolor );

        palette[currentPalIndex][index].rgbRed = GetRValue( newcolor );
        palette[currentPalIndex][index].rgbGreen = GetGValue( newcolor );
        palette[currentPalIndex][index].rgbBlue = GetBValue( newcolor );
        palette[currentPalIndex][index].rgbReserved = 0;

        ShowNewColor( index, newcolor, TRUE );
        pres = _wpi_getpres( HWND_DESKTOP );
        _wpi_torgbmode( pres );
        SetColor( LMOUSEBUTTON, newcolor, _wpi_getnearestcolor( pres, newcolor ), NORMAL_CLR );
        if( index == rightindex ) {
            SetColor( RMOUSEBUTTON, newcolor, _wpi_getnearestcolor( pres, newcolor ),
                      NORMAL_CLR );
        }
        _wpi_releasepres( HWND_DESKTOP, pres );
    } else if( lefttype == SCREEN_CLR ) {
        pres = _wpi_getpres( HWND_DESKTOP );
        _wpi_torgbmode( pres );
        nearestcolor = _wpi_getnearestcolor( pres, newcolor );
        _wpi_releasepres( HWND_DESKTOP, pres );
        SetScreenClr( nearestcolor );
    } else {
        pres = _wpi_getpres( HWND_DESKTOP );
        _wpi_torgbmode( pres );
        nearestcolor = _wpi_getnearestcolor( pres, newcolor );
        _wpi_releasepres( HWND_DESKTOP, pres );

        screencolor = GetInverseColor( nearestcolor );
        SetScreenClr( screencolor );
    }

} /* ReplacePaletteEntry */
Esempio n. 4
0
void TGLFunWidget::drawFacet1D(TVertex3D* vertex,int size)
{
//    GLUquadricObj* cObj = gluNewQuadric();
    int iColor1 = getColorIndex(vertex[0].u),
        iColor2 = getColorIndex(vertex[1].u),
        iColor,
        numSteps = abs(iColor1 - iColor2);
    Float x,
//          R = (maxX - minX)/mesh->getFE().size1()/20,
          h = (numSteps > 0) ? (vertex[1].x - vertex[0].x)/Float(numSteps) : 0;


    if (params.isFace)
    {
        glNormal3d(0,0,1);
        glBegin(GL_LINE_STRIP);
        setColor(colorTable[iColor1].red(),colorTable[iColor1].green(),colorTable[iColor1].blue(),params.alpha);
        glVertex2d(vertex[0].x, 0);
        x = vertex[0].x;
        iColor = iColor1;
        for (int i = 0; i < numSteps; i++)
        {
            x += h;
            if (iColor1 < iColor2)
                iColor++;
            else
                iColor--;
            setColor(colorTable[iColor].red(),colorTable[iColor].green(),colorTable[iColor].blue(),params.alpha);
            glVertex2d(x, 0);
        }
        setColor(colorTable[iColor2].red(),colorTable[iColor2].green(),colorTable[iColor2].blue(),params.alpha);
        glVertex2d(vertex[1].x, 0);
        glEnd();
    }
    if (params.isVertex)
    {
        glPointSize(3);
        glBegin(GL_POINTS);
            for (int i = 0; i < size; i++)
            {
                iColor = getColorIndex(vertex[i].u);
                setColor(colorTable[iColor].red(),colorTable[iColor].green(),colorTable[iColor].blue(),params.alpha);
                glPushMatrix();
                glTranslatef(vertex[i].x,0,0);
//                gluSphere(cObj,R*0.5,10,10);
                glVertex3f(vertex[i].x, 0, 0);

                glPopMatrix();
            }
        glEnd();
    }
//    gluDeleteQuadric(cObj);
}
Esempio n. 5
0
void TGLFunWidget::drawTriangle3D(TVertex3D* vertex)
{
    TVertex3D tmp;

    if (predicate.length())
    {
        if (fabs(vertex[0].u) < predicate.toFloat())
          vertex[0].u = 0;
        if (fabs(vertex[1].u) < predicate.toFloat())
          vertex[1].u = 0;
        if (fabs(vertex[2].u) < predicate.toFloat())
          vertex[2].u = 0;
    }
    vertex[0].c = getColorIndex(vertex[0].u);
    vertex[1].c = getColorIndex(vertex[1].u);
    vertex[2].c = getColorIndex(vertex[2].u);
    if ((vertex[0].c == vertex[1].c) && (vertex[1].c == vertex[2].c))
    {
        glBegin(GL_TRIANGLES);
            setColor(colorTable[vertex[0].c].red(),colorTable[vertex[0].c].green(),colorTable[vertex[0].c].blue(),params.alpha);
            vertex[0].setVertex();
            vertex[1].setVertex();
            vertex[2].setVertex();
        glEnd();
        return;
    }
    sort(vertex);
    if (vertex[2].u < vertex[1].u)
    {
        swap(vertex[2],vertex[1]);
        vertex[0].invertNormal();
        vertex[1].invertNormal();
        vertex[2].invertNormal();
    }
    if (vertex[0].c != vertex[1].c)
    {
        if (vertex[1].c != vertex[2].c)
        {
            createVertex(tmp,vertex[2],vertex[0],vertex[1].u);
            triangle1(vertex[0],tmp, vertex[1]);
            triangle2(tmp,vertex[1],vertex[2]);
        }
        else
            triangle1(vertex[0], vertex[2], vertex[1]);
    }
    else if (vertex[1].c != vertex[2].c)
        triangle2(vertex[0], vertex[1], vertex[2]);
}
Esempio n. 6
0
void double_colorIndex_ufunc(char **args, npy_intp *dimensions, npy_intp* steps,
    void* data) {
  npy_intp i;
  npy_intp n = dimensions[0];

  assert(dimensions[1] ==3);
  int nrow = 3;

  char *in = args[0], *out = args[1];
  npy_intp in_step = steps[0];
  npy_intp out_step = steps[1];

  double l,a,b;

  for(i = 0; i < n/nrow; i++) {
    l = *(double *) in;
    in+=in_step;
    a = *(double *) in;
    in+=in_step;
    b = *(double *) in;
    in+=in_step;

    *((double *) out) = getColorIndex(l, a, b);
    out +=out_step;
    *((double *) out) = -1.0;
    out +=out_step;
    *((double *) out) = -1.0;
    out +=out_step;
  }
}
Esempio n. 7
0
void SE_Image::setSurface(SE_Surface* surface)
{
    int pattern[] = {0, REPLACE_A, REPLACE_B, REPLACE_BA, REPLACE_G, REPLACE_GA,
                     REPLACE_GB, REPLACE_GBA, REPLACE_R, REPLACE_RA, REPLACE_RB, REPLACE_RBA,
                     REPLACE_RG, REPLACE_RGA, REPLACE_RGB, REPLACE_RGBA, NO_REPLACE
                    };
    int index = 0;
    SE_ColorExtractShaderProperty* sp = new SE_ColorExtractShaderProperty;
    for(int i = 1 ; i < 5 ; i++)
    {
        index |= (mImageUnits[i].valid << (4 - i));
        if(mImageUnits[i].valid)
        {
            std::string ext = mImageUnits[i].imageUnit->ext.getStr();
            int c = getColorIndex(ext);
            sp->setColorChannelIndex(i - 1, c);
        }
    }
    int op = pattern[index];
    if(mBaseColor.isValid() && op == 0)
    {
        op = NO_REPLACE;
    }
    sp->setColorOperationMode(op);
    surface->setShaderProperty(sp);
    surface->setProgramDataID(COLOREXTRACT_SHADER);
    surface->setRendererID(COLOREXTRACT_RENDERER);
}
Esempio n. 8
0
const char* getColorName(const char* str)
{
	const char* result = 0;

	int i = getColorIndex(str);
	if (i >= 0)
		result = colorNames[i];

	return result;
}
Esempio n. 9
0
void QvisColorGridWidget::mouseMoveEvent(QMouseEvent* e)
{
  int index = getColorIndex(e->x(), e->y());

  // If we've moved the mouse to a new active color, unhighlight the old one
  // and highlight the new one.
  if (index != activeColorIndex())
  {
    setActiveColorIndex(index);
  }
}
Esempio n. 10
0
void MPPrefs::setHighlightColor( unsigned long color )
{
	MC2Player* player = MPlayer->getPlayerInfo( MPlayer->commanderID );
	player->stripeColor = getColorIndex( color );
	MPlayer->sendPlayerUpdate( 0, 6, -1 );

	camera.setMech( "Bushwacker", MPlayer->colors[player->baseColor[BASECOLOR_PREFERENCE]], color, color );
	camera.zoomIn( 1.5 );


}
Esempio n. 11
0
void QvisColorGridWidget::mouseReleaseEvent(QMouseEvent* e)
{
  int index = getColorIndex(e->x(), e->y());

  // If a valid color index was returned, select the color.
  if (index != -1)
  {
    // Set the selected color.
    setSelectedColorIndex(index);
  }
}
Esempio n. 12
0
/*
 * SetNewPalette - set a new palette from a loaded file
 */
void SetNewPalette( a_pal_file *pal_file )
{
    int         i;
    wie_clrtype type;
    HMENU       hmenu;

    if( currentPalIndex != COLOR_16 && currentPalIndex != COLOR_256 ) {
        return;
    }

    leftColorIndex = getColorIndex( GetSelectedColor( LMOUSEBUTTON, NULL, &type ) );
    rightColorIndex = getColorIndex( GetSelectedColor( RMOUSEBUTTON, NULL, &type ) );

    for( i = 0; i < PALETTE_SIZE - 1; i++ ) {
        palette[currentPalIndex][i].rgbRed = pal_file->rgbqs[i].rgbBlue;
        palette[currentPalIndex][i].rgbGreen = pal_file->rgbqs[i].rgbGreen;
        palette[currentPalIndex][i].rgbBlue = pal_file->rgbqs[i].rgbRed;
        ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed,
                              palette[currentPalIndex][i].rgbGreen,
                              palette[currentPalIndex][i].rgbBlue ), FALSE );
        restorePalette[i] = palette[currentPalIndex][i];
    }
    palette[currentPalIndex][i].rgbRed = pal_file->rgbqs[i].rgbBlue;
    palette[currentPalIndex][i].rgbGreen = pal_file->rgbqs[i].rgbGreen;
    palette[currentPalIndex][i].rgbBlue = pal_file->rgbqs[i].rgbRed;
    restorePalette[i] = palette[currentPalIndex][i];

    ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed,
                          palette[currentPalIndex][i].rgbGreen,
                          palette[currentPalIndex][i].rgbBlue ), TRUE );
    SetCurrentColors( TRUE );

    if( HMainWindow != NULL ) {
        hmenu = GetMenu( _wpi_getframe( HMainWindow ) );
        _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, TRUE, FALSE );
    }

} /* SetNewPalette */
void LevelEditor::setCurrentColor(const sf::Color &color)
{
	//Search for the inputcolor in the colorvector (getColorIndex)
	m_currentColor = getColorIndex(color);

	int counter = 0;

	for(std::size_t i = m_colors.size(); i > 0; i--)
	{
		if(i > 24)
			i = 24;

		m_displayLastColors[counter].setFillColor(m_colors[i-1]);
		counter++;
	}

}
Esempio n. 14
0
string board::sColorsToNums()
{
	int count = 0;
	std::stringstream ss (stringstream::in | stringstream::out);
	for(int k =0; k < userGuess.size(); k++)
	{                            
		for(vector<string>::iterator i = colors.begin(); i != colors.end(); ++i)
		{                                
			if( userGuess[k] == *i )
				ss << getColorIndex(*i);
			else
				ss << "";                        
        }
		++count;
	}
	return ss.str();
}
Esempio n. 15
0
void QvisColorGridWidget::mousePressEvent(QMouseEvent* e)
{
  if (e->button() == Qt::RightButton)
  {
    int index = getColorIndex(e->x(), e->y());

    // If a valid color index was returned, select the color.
    if (index != -1)
    {
      // Set the selected color.
      setSelectedColorIndex(index);

      // Emit a signal that allows us to activate a menu.
      int row, column;
      QPoint center(e->x(), e->y());
      getRowColumnFromIndex(currentSelectedColor, row, column);
      emit activateMenu(selectedColor(), row, column, mapToGlobal(center));
    }
  }
}
Esempio n. 16
0
void MPPrefs::setColor( unsigned long color )
{
	long playerCount;
	const MC2Player* players = MPlayer->getPlayers(playerCount);
	for( int i = 0; i < playerCount; i++ )
	{
		if (MPlayer->colors[players[i].baseColor[BASECOLOR_SELF]] == (long)color && i != MPlayer->commanderID)
		{
			soundSystem->playDigitalSample(LOG_WRONGBUTTON);
			return;
			
		}
	}
					
	//GD:MPlayer->setPlayerBaseColor( MPlayer->commanderID, getColorIndex( color ) );
	MC2Player* player = MPlayer->getPlayerInfo( MPlayer->commanderID );
	player->baseColor[BASECOLOR_PREFERENCE] = getColorIndex(color);
	MPlayer->sendPlayerUpdate( 0, 6, -1 );

	//GD:camera.setMech( "Bushwacker", color, MPlayer->colors[player->stripeColor], MPlayer->colors[player->stripeColor] );
	//GD:camera.zoomIn( 1.5 );

}
Esempio n. 17
0
/*!
  Finds the color index for \a entity, and returns the dxfLayerData for it.
*/
dxfLayerData *
dxfConverter::getLayerData(const dimeEntity *entity)
{
  // special case for VERTEX
  if (this->currentPolyline && entity->typeId() == dimeBase::dimeVertexType) {
    if (!(entity->getEntityFlags() & FLAG_COLOR_NUMBER))
      return getLayerData(this->currentPolyline);
  }

  int colidx = getColorIndex(entity);
  if (colidx == 0) { // BYBLOCK
    colidx = this->currentInsertColorIndex;
  }
  // we don't care if layer is turned off (negative color)
  if (colidx < 0) colidx = -colidx;
    
  if (colidx < 1 || colidx > 255) { // just in case
    fprintf(stderr,"Illegal color number %d. Changed to 7 (white)\n",
	    colidx);
    colidx = 7;
  }
  return getLayerData(colidx);
}
Esempio n. 18
0
void do_for_color(const char* color, ColorFunc func, void* arg)
{
	int iBegin = -1;
	int iEnd = -1;
	int i = getColorIndex(color);
	if (0 <= i && i < kNCOLORS)
	{
		iBegin = i;
		iEnd = iBegin + 1;
	}
	else if (i == kNCOLORS)
	{
		iBegin = 0;
		iEnd = kNCOLORS;
	}

	if (iBegin >= iEnd)
		s_println("%s: unknown color", color);
	else
	{
		for (i = iBegin; i < iEnd; ++i)
			func(i, arg);
	}
}
Esempio n. 19
0
void clearBitmapColor(int xCoord, int yCoord)
{
	colors[3 * getColorIndex(xCoord, yCoord)] = cAtmosphere->backgroundRed;
	colors[3 * getColorIndex(xCoord, yCoord) + 1] = cAtmosphere->backgroundGreen;
	colors[3 * getColorIndex(xCoord, yCoord) + 2] = cAtmosphere->backgroundBlue;
}
Esempio n. 20
0
void setBitmapColor(int xCoord, int yCoord, struct Element* element)
{
	colors[3 * getColorIndex(xCoord, yCoord)] = element->red;
	colors[3 * getColorIndex(xCoord, yCoord) + 1] = element->green;
	colors[3 * getColorIndex(xCoord, yCoord) + 2] = element->blue;
}
Esempio n. 21
0
//
// handles the callback from the dime-library
//
bool 
dxfConverter::private_callback(const dimeState * const state, 
			       dimeEntity *entity)
{ 
  if (entity->typeId() == dimeBase::dimePolylineType) {
    this->currentPolyline = entity;
  }

  if (state->getCurrentInsert()) {
    this->currentInsertColorIndex = 
      getColorIndex((dimeEntity*)state->getCurrentInsert());
  }
  else {
    this->currentInsertColorIndex = 7;
  }

  dxfLayerData *ld = getLayerData(entity);

  // fillmode on by default. entities which will not fill its polygons
  // should turn it off (layerData::addQuad() will create polygons,
  // not lines)
  //
  ld->setFillmode(true);
  
  switch (entity->typeId()) { 
  case dimeBase::dime3DFaceType:
    convert_3dface(entity, state, ld, this);
    break;
  case dimeBase::dimeSolidType:
    convert_solid(entity, state, ld, this);
    break;
  case dimeBase::dimeTraceType:
    convert_solid(entity, state, ld, this);
    break;
  case dimeBase::dimeArcType:
    convert_arc(entity, state, ld, this);
    break;
  case dimeBase::dimeCircleType:
    convert_circle(entity, state, ld, this);
    break;
  case dimeBase::dimeEllipseType:
    convert_ellipse(entity, state, ld, this);
    break;
  case dimeBase::dimeInsertType:
    // handled in traverseEntities
    break;
  case dimeBase::dimeBlockType:
    // handled in traverseEntities
    break;
  case dimeBase::dimeLineType:
    convert_line(entity, state, ld, this);
    break;
  case dimeBase::dimeLWPolylineType:
    convert_lwpolyline(entity, state, ld, this);
    break;
  case dimeBase::dimePointType:
    convert_point(entity, state, ld, this);
    break;
  case dimeBase::dimePolylineType:
    convert_polyline(entity, state, ld, this);
    break;
  case dimeBase::dimeSplineType:
    // go for it Raphael! :-)
    break;
  default:
    break;
  }
  return true;
}
Esempio n. 22
0
/*
 * RestoreColorPalette - restore the color palette to the hard-coded colors
 *                       in the initialization routine
 */
void RestoreColorPalette( void )
{
    int         i;
    COLORREF    leftcolor;
    COLORREF    rightcolor;
    COLORREF    color;
    WPI_PRES    pres;
    int         leftindex;
    int         rightindex;
    wie_clrtype lefttype;
    wie_clrtype righttype;
    HMENU       hmenu;
    HWND        frame;

    if( currentPalIndex != COLOR_16 && currentPalIndex != COLOR_256 ) {
        return;
    }
    leftcolor = GetSelectedColor( LMOUSEBUTTON, NULL, &lefttype );
    rightcolor = GetSelectedColor( RMOUSEBUTTON, NULL, &righttype );

    leftindex = getColorIndex( leftcolor );
    rightindex = getColorIndex( rightcolor );

    InitPalette();
    for( i = 0; i < PALETTE_SIZE - 1; i++ ) {
        ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed,
                              palette[currentPalIndex][i].rgbGreen,
                              palette[currentPalIndex][i].rgbBlue ), FALSE );
    }
    /*
     * We do the last one separately to invalidate the window.
     */
    ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed,
                          palette[currentPalIndex][i].rgbGreen,
                          palette[currentPalIndex][i].rgbBlue ), TRUE );

    if( lefttype == NORMAL_CLR ) {
        color = RGB( palette[currentPalIndex][leftindex].rgbRed,
                     palette[currentPalIndex][leftindex].rgbGreen,
                     palette[currentPalIndex][leftindex].rgbBlue );
        pres = _wpi_getpres( HWND_DESKTOP );
        _wpi_torgbmode( pres );
        SetColor( LMOUSEBUTTON, color, _wpi_getnearestcolor( pres, color ), NORMAL_CLR );
        _wpi_releasepres( HWND_DESKTOP, pres );
    }
    if( righttype == NORMAL_CLR ) {
        color = RGB( palette[currentPalIndex][rightindex].rgbRed,
                     palette[currentPalIndex][rightindex].rgbGreen,
                     palette[currentPalIndex][rightindex].rgbBlue );
        pres = _wpi_getpres( HWND_DESKTOP );
        _wpi_torgbmode( pres );
        SetColor( RMOUSEBUTTON, color, _wpi_getnearestcolor( pres, color ), NORMAL_CLR );
        _wpi_releasepres( HWND_DESKTOP, pres );
    }

    PrintHintTextByID( WIE_PALETTERESTORED, NULL );

    if( HMainWindow != NULL ) {
        frame = _wpi_getframe( _wpi_getframe( HMainWindow ) );
        hmenu = GetMenu( frame );
        _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, FALSE, FALSE );
    }

} /* RestoreColorPalette */
Esempio n. 23
0
void TGLFunWidget::paintScale(void)
{
    QRect rc = rect();
    QFont glFont("Courier", 12, QFont::Normal);
    QFontMetrics fm(glFont);
    QString val;
    int num = 8,
        fontW1 = fm.width("12"),
        fontW2 = fm.width("1234567890"),
        fontH = fm.height(),
        i;
    Float minU = 0,
          maxU = 0,
          v_start,
          v_stop,
          v_step,
          v,
          cy;

    if (!(mesh && mesh->getFEType() != NOTYPE) || rc.height() < 9*fontH)
        return;

    minU = *min_element((*results)[funIndex].getResults().begin(),(*results)[funIndex].getResults().end());;
    maxU = *max_element((*results)[funIndex].getResults().begin(),(*results)[funIndex].getResults().end());;
    v_start = maxU;
    v_stop  = minU;
    v_step  = (maxU - minU)/(num - 1);
    cy      = rc.top() + 20;

    v = v_start;
    if (minU == maxU)
    {
        i = getColorIndex(v);
        glColor3f(colorTable[i].red(),colorTable[i].green(),colorTable[i].blue());
        glFont.setStyleStrategy(QFont::OpenGLCompatible);
        renderText(rc.width() - fontW1 - fontW2 - 10,cy,"█",glFont);
        glColor3f(1.0 - float(params.bkgColor.red())/255.0,1.0 - float(params.bkgColor.green())/255.0,1.0 - float(params.bkgColor.blue())/255.0);
        //        renderText(rc.width() - fontW2 - 10,cy,QString("%1").arg(v,5,'e',3),glFont);
        renderText(rc.width() - fontW2 - 10,cy,val.sprintf("%+5.3E",colorTable[i].value()),glFont);
        return;
    }



    for (int k = 0; k < 8; k++)
    {
        if (k == 7)
            v = v_stop;

        i = getColorIndex(v);
        glColor3f(colorTable[i].red(),colorTable[i].green(),colorTable[i].blue());
        glFont.setStyleStrategy(QFont::OpenGLCompatible);
        renderText(rc.width() - fontW1 - fontW2 - 10,cy,"█",glFont);
        glColor3f(1.0 - float(params.bkgColor.red())/255.0,1.0 - float(params.bkgColor.green())/255.0,1.0 - float(params.bkgColor.blue())/255.0);
//        glColor3f(0,0,0);
        renderText(rc.width() - fontW2 - 10,cy,val.sprintf("%+5.3E",v),glFont);

        cy += fontH;
        v -= v_step;
    }
}
Esempio n. 24
0
void TGLFunWidget::triangle2(TVertex3D& p0,TVertex3D& p1,TVertex3D& p2)
{
    int color = getColorIndex(p0.u),
        lastColor = getColorIndex(p2.u);
    Float a,
          b,
          c20,
          c21,
          tmp,
          cx20,
          cy20,
          cz20,
          cx21,
          cy21,
          cz21,
          step = (uMax - uMin)/params.numColor,
          work = (uMin + (step)*(color + 1));
    TVertex3D t0,
              t1;

    c20 = p2.u - p0.u;
    a   = (work - p0.u)/c20;
    b   = (p2.u - work)/c20;

    t0.x = a*p2.x + b*p0.x;
    t0.y = a*p2.y + b*p0.y;
    t0.z = a*p2.z + b*p0.z;
    t0.nx = p0.nx + p2.nx;
    t0.ny = p0.ny + p2.ny;
    t0.nz = p0.nz + p2.nz;


    c21 = p2.u - p1.u;
    a   = (work - p1.u)/c21;
    b   = (p2.u - work)/c21;

    t1.x = a*p2.x + b*p1.x;
    t1.y = a*p2.y + b*p1.y;
    t1.z = a*p2.z + b*p1.z;
    t1.nx = p2.nx + p1.nx;
    t1.ny = p2.ny + p1.ny;
    t1.nz = p2.nz + p1.nz;


    glBegin(GL_QUADS);
        setColor(colorTable[color].red(),colorTable[color].green(),colorTable[color].blue(),params.alpha);
        p0.setVertex();
        p1.setVertex();
        t1.setVertex();
        t0.setVertex();
        color++;
        if (color < lastColor)
        {
            tmp  = step/c20;
            cx20 = (p2.x - p0.x)*tmp;
            cy20 = (p2.y - p0.y)*tmp;
            cz20 = (p2.z - p0.z)*tmp;

            tmp  = step/c21;
            cx21 = (p2.x - p1.x)*tmp;
            cy21 = (p2.y - p1.y)*tmp;
            cz21 = (p2.z - p1.z)*tmp;
            do
            {
                setColor(colorTable[color].red(),colorTable[color].green(),colorTable[color].blue(),params.alpha);
                t0.setVertex();
                t1.setVertex();

                t0.x += cx20;
                t0.y += cy20;
                t0.z += cz20;
                t1.x += cx21;
                t1.y += cy21;
                t1.z += cz21;

                t1.setVertex();
                t0.setVertex();
                color++;
             }
             while (color < lastColor);
         }
     glEnd();
     glBegin(GL_TRIANGLES);
         setColor(colorTable[color].red(),colorTable[color].green(),colorTable[color].blue(),params.alpha);
         t0.setVertex();
         t1.setVertex();
         p2.setVertex();
     glEnd();
}