Exemple #1
0
rColor rGradient::GetColor(float where) {
#ifndef DEDICATED
    if(empty()) return rColor();
    if(begin()->first >= where) return begin()->second;
    iterator upper, lower;
    iterator i=begin();
    iterator j=begin();
    ++j;
    bool finished = false;
    for(; j!=end(); ++i, ++j) {
        if(j->first >= where) {
            lower = i;
            upper = j;
            finished = true;
            break;
        }
    }
    if (!finished) return rbegin()->second;
    float diff = upper->first - lower->first;
    float pos = where - lower->first;
    rColor &c1 = lower->second;
    rColor &c2 = upper->second;
    float r = c1.r_*(diff-pos)/diff + c2.r_*pos/diff;
    float g = c1.g_*(diff-pos)/diff + c2.g_*pos/diff;
    float b = c1.b_*(diff-pos)/diff + c2.b_*pos/diff;
    float a = c1.a_*(diff-pos)/diff + c2.a_*pos/diff;
    return rColor(r,g,b,a);
#else
    return rColor(0.,0.,0.,0.);
#endif
}
Exemple #2
0
/** Recursive helper function.
 *  Colors the current graph cg, modifying it as necessary, along the way.
 *  Note: cg uses same vertex numbers and edge numbers as original graph.
 *  Also uses global data structures euler and handle, within eulerPartition
 *  method.
 *  @param Delta is the max vertex degree in the current graph cg.
 */
void ecolor_g::rColor(int Delta) {
	// if cg is a matching, just color its edges
	if (Delta == 1) {
		for (edge e = cg->first(); e != 0; e = cg->next(e))
			color[e] = nextColor;
		nextColor++;
		return;
	}

	if ((Delta&1) == 1) {
		// find matching in cg that includes every max degree vertex
		for (vertex u = 1; u <= cg->n(); u++) mEdge[u] = 0;
		mdmatch_f(*cg, mEdge);

		// now, color edges in matching and remove from cg
		for (vertex u = 1; u <= cg->n(); u++) {
			edge e = mEdge[u];
			if (e != 0 && u > cg->mate(u,e)) {
				color[e] = nextColor; cg->remove(e);
			}
		}
		nextColor++;

		Delta--; // decrement max degree
	}
	// cg now has even maximum degree
	int m = cg->m();

	// find Euler partition and return in euler and handle;
	// on completion, cg has no edges
	eulerPartition();

	// rebuild cg using half of the edges, place others in list
	List_g<edge> L(m/2); 
	while (!handle->empty()) {
		edge e = handle->value(handle->first()); handle->removeFirst();
		edge ee = e; bool odd = true;
		do {
			if (odd) cg->joinWith(gp->left(ee), gp->right(ee), ee);
			else L.addLast(ee);
			odd = not odd;
			edge tmp = ee;
			ee = euler->next(ee);
			if (tmp != e) euler->remove(tmp,e);
		} while (ee != 0);
	}
	// note: euler and handle now ready for re-use

	// recursive calls on the two subgraphs
	rColor(Delta/2);
	cg->clear();
	for (index x = L.first(); x != 0; x = L.next(x)) {
		edge e = L.value(x);
		cg->joinWith(gp->left(e), gp->right(e), e);
	}
	rColor(Delta/2);
}
void ruiStylesheetLoader::ParseColorProperty(const rString& name, const rString& value){
	int r,g,b,a;

	if (sscanf(value.c_str(), "%i %i %i %i", &r, &g, &b, &a) == 4){
		m_currentStyle->SetColor(name, rColor(r,g,b,a));
	}
}
Exemple #4
0
LRESULT CRRECToolBar::OnItemPostPaint(LPNMTBCUSTOMDRAW lpNMCustomDraw)
{
    UINT nBtnID = lpNMCustomDraw->nmcd.dwItemSpec;

    switch (nBtnID)
    {
    case BUTTON_BACKCOLOR:
    case BUTTON_TEXTCOLOR:
    {
        // paint the lowest 3 lines with the appropriate colour
        // but only as far as the beginning of the drop button
        CRect rColor(lpNMCustomDraw->nmcd.rc);

        if (CThemed().AreControlsThemed())
            rColor.bottom++;
        else
            rColor.DeflateRect(2, 2);

        rColor.top = rColor.bottom - 3;
        rColor.right = rColor.left + m_sizeImage.cx;

        CDC* pDC = CDC::FromHandle(lpNMCustomDraw->nmcd.hdc);
        COLORREF color = GetFontColor(nBtnID == BUTTON_TEXTCOLOR, TRUE);

        pDC->FillSolidRect(rColor, color);
    }
    break;
    }

    return CDRF_DODEFAULT;
}
Exemple #5
0
rPrimitive::rPrimitive(const rString& id, rEngine* engine)
	:rActor3(id, engine)
{
	m_edgeColor = rColor(200, 200, 200, 255);
	m_faceColor = rColor::White;

	m_geometry = NULL;
	m_geometryInvalid = true;

	m_drawable.reset(new rDrawable());
	m_drawable.get()->SetLineVisibility(true);
}
Exemple #6
0
/** Find a minimum edge coloring in a bipartite graph using Gabow's algorithm.
 *  @param g is a reference to the graph
 *  @param color is an array indexed by an edge number; on return
 *  color[e] is the color assigned to edge e
 *  @return the number of colors used or 0 if the graph is not bipartite
 */
ecolor_g::ecolor_g(Graph& g, int color[]) {
	// initialize data structures
	gp = &g;
	cg = new Graph(g.n(),g.M());
	cg->copyFrom(g);
	this->color = color;
	mEdge = new edge[g.n()+1];
	euler = new Dlists(g.M());
	handle = new List_g<edge>(g.M());
	start = new List_d(g.n());

	nextColor = 1;
	rColor(g.maxDegree());
}
void BasicSceneModule::AfterRenderScene(rViewInfo& view, rEngine& engine){
	if (m_drawRay){
		rImmediateBuffer buffer(rGeometryType::Lines, 3, false);
		buffer.PushVertex(m_ray.origin);
		buffer.PushVertex(m_ray.direction * 50.0f);

		buffer.PushIndex(0,1);

		rMatrix4 ident;
		engine.renderer->Render3dBuffer(buffer, ident, rColor(255,176,250,255));
	}

			rActor3* box = m_engine->scene->GetActor("box01");
		riBoundingVolume* boundingVolume = box->BoundingVolume();
		engine.renderer->RenderWireBox(boundingVolume->FitBox(), rColor::Green);
}
Exemple #8
0
void reTransformGizmoBase::HighlightAxis(reGizmoAxis axis) {
	rProp* handle = nullptr;

	switch (axis) {
	case reGizmoAxis::X:
		handle = m_xHandle;
		break;

	case reGizmoAxis::Y:
		handle = m_yHandle;
		break;

	case reGizmoAxis::Z:
		handle = m_zHandle;
		break;
	};

	if (handle) {
		SetModelInstanceColor(handle, rColor(255, 255, 0, 255));
	}
}
Exemple #9
0
#include "rColor.hpp"

const rColor rColor::White = rColor(255,255,255,255);
const rColor rColor::Red = rColor(255,0,0,255);
const rColor rColor::Green = rColor(0,255,0,255);
const rColor rColor::Blue = rColor(0,0,255,255);
const rColor rColor::Black = rColor(0,0,0,255);
const rColor rColor::Transparent = rColor(0, 0, 0, 0);

void rColor::Set(unsigned char r, unsigned char g, unsigned char b, unsigned char a){
	red = r;
	green = g;
	blue = b;
	alpha = a;
}

void rColor::Set(const unsigned char* color){
	red = color[0];
	green = color[1];
	blue = color[2];
	alpha = color[3];
}

void rColor::ToArray(unsigned char* color) const{
	color[0] = red;
	color[1] = green;
	color[2] = blue;
	color[3] = alpha;
}

bool rColor::operator==(const rColor& color){
void CXTPSyntaxEditColorComboBox::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	CDC*  pDC       = CDC::FromHandle(lpDIS->hDC);
	UINT  itemState = lpDIS->itemState;
	UINT  itemID    = lpDIS->itemID;
	CRect rcItem    = lpDIS->rcItem;

	if (itemID == (UINT)-1)
	{
		return;
	}

	BOOL bDisabled = ((itemState & ODS_DISABLED) == ODS_DISABLED);
	BOOL bSelected = ((itemState & ODS_SELECTED) == ODS_SELECTED);
	BOOL bFocus    = ((itemState & ODS_FOCUS)    == ODS_FOCUS);

	// draw background.
	if (bDisabled)
	{
		pDC->SetTextColor(GetXtremeColor(COLOR_GRAYTEXT));
		pDC->SetBkColor(GetXtremeColor(COLOR_3DFACE));
		pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_3DFACE));
	}
	else
	{
		if (bSelected)
		{
			pDC->SetTextColor(GetXtremeColor(COLOR_HIGHLIGHTTEXT));
			pDC->SetBkColor(GetXtremeColor(COLOR_WINDOW));
			pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_HIGHLIGHT));
		}
		else
		{
			pDC->SetTextColor(GetXtremeColor(COLOR_WINDOWTEXT));
			pDC->SetBkColor(GetXtremeColor(COLOR_WINDOW));
			pDC->FillSolidRect(&rcItem, GetXtremeColor(COLOR_WINDOW));
		}

		// draw focus rectangle.
		if (bFocus)
		{
			pDC->DrawFocusRect(&rcItem);
		}
	}

	// determine the size of the color rectangle.
	CRect rColor(rcItem);
	rColor.DeflateRect(2,2);
	rColor.right = rColor.left + COLOR_ITEM_WIDTH;
	rColor.bottom = rColor.top + COLOR_ITEM_WIDTH;

	// draw color rectangle.
	pDC->FillSolidRect(rColor,
		bDisabled? GetXtremeColor(COLOR_3DFACE): (COLORREF)lpDIS->itemData);

	pDC->Draw3dRect(rColor,
		GetXtremeColor(bDisabled? COLOR_GRAYTEXT: COLOR_WINDOWTEXT),
		GetXtremeColor(bDisabled? COLOR_GRAYTEXT: COLOR_WINDOWTEXT));

	// determine the size of the text display.
	CRect rText(rColor);
	rText.top -= 2;
	rText.bottom = rText.top + (::GetSystemMetrics(SM_CYVTHUMB)-::GetSystemMetrics(SM_CYEDGE));
	rText.left = rText.right + 4;
	rText.right = rcItem.right;

	// draw text.
	CString csItemText;
	GetLBText(itemID, csItemText);
	if (!csItemText.IsEmpty())
	{
		pDC->SetBkMode(TRANSPARENT);
		pDC->DrawText(csItemText, rText, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
	}
}
Exemple #11
0
void tile(int neXindex, int neYindex, int N, int holeX, int holeY)
{
  if(N==2)
   {
      Color c=rColor();
      if(flag==0)
        c=COLOR("White");
      if(holeX!=neXindex || holeY!=neYindex)
      {
        Rectangle r3(neXindex*W + W/2,neYindex*W + W/2,W,W);
        r3.setFill();
        r3.setColor(c);
        r3.imprint();
      }
      if(holeX!=neXindex || holeY!=neYindex+1)
      {
        Rectangle r1(neXindex*W + W/2,neYindex*W + 3*W/2,W,W);
        r1.setFill();
        r1.setColor(c);
        r1.imprint();
      }
      if(holeX!=neXindex+1 || holeY!=neYindex+1)
      {
        Rectangle r2(neXindex*W + 3*W/2,neYindex*W + 3*W/2,W,W);
        r2.setFill();
        r2.setColor(c);
        r2.imprint();
      }
      if(holeX!=neXindex+1 || holeY!=neYindex)
      {
        Rectangle r3(neXindex*W + 3*W/2,neYindex*W + W/2,W,W);
        r3.setFill();
        r3.setColor(c);
        r3.imprint();
      }
   } 
  else
  {
    if(neXindex<=holeX && holeX<neXindex+N/2 && neYindex<=holeY && holeY<neYindex+N/2)    //Bottom Left
    {
      tile(neXindex,neYindex,N/2,holeX,holeY);
      tile(neXindex,neYindex+N/2,N/2,neXindex-1+N/2,neYindex+N/2);
      tile(neXindex+N/2,neYindex+N/2,N/2,neXindex+N/2,neYindex+N/2);
      tile(neXindex+N/2,neYindex,N/2,neXindex+N/2,neYindex-1+N/2);
      flag=0;
      tile(neXindex-1+N/2,neYindex-1+N/2,2,neXindex-1+N/2,neYindex-1+N/2);
      flag=1;
    }
    else if(neXindex<=holeX && holeX<neXindex+N/2 && holeY>=neYindex+N/2 && holeY<neYindex+N) //Top Left
    {
      tile(neXindex,neYindex+N/2,N/2,holeX,holeY);
      tile(neXindex,neYindex,N/2,neXindex-1+N/2,neYindex-1+N/2);
      tile(neXindex+N/2,neYindex+N/2,N/2,neXindex+N/2,neYindex+N/2);
      tile(neXindex+N/2,neYindex,N/2,neXindex+N/2,neYindex-1+N/2);
      flag=0;
      tile(neXindex-1+N/2,neYindex-1+N/2,2,neXindex-1+N/2,neYindex+N/2);
      flag=1;
    }
    else if(holeX>=neXindex+N/2 && holeX<neXindex+N && holeY>=neYindex+N/2 && holeY<neYindex+N) //Top Right
    {
      tile(neXindex+N/2,neYindex+N/2,N/2,holeX,holeY);
      tile(neXindex,neYindex,N/2,neXindex-1+N/2,neYindex-1+N/2);
      tile(neXindex,neYindex+N/2,N/2,neXindex-1+N/2,neYindex+N/2);
      tile(neXindex+N/2,neYindex,N/2,neXindex+N/2,neYindex-1+N/2);
      flag=0;
      tile(neXindex-1+N/2,neYindex-1+N/2,2,neXindex+N/2,neYindex+N/2);
      flag=1;
    }
    else //if(holeX>=neXindex+N/2 && holeX<neXindex+N && neYindex<=holeY && holeY<neYindex+N/2) //Bottom Right
    {
      tile(neXindex+N/2,neYindex,N/2,holeX,holeY);
      tile(neXindex,neYindex,N/2,neXindex-1+N/2,neYindex-1+N/2);
      tile(neXindex,neYindex+N/2,N/2,neXindex-1+N/2,neYindex+N/2);
      tile(neXindex+N/2,neYindex+N/2,N/2,neXindex+N/2,neYindex+N/2);
      flag=0;
      tile(neXindex-1+N/2,neYindex-1+N/2,2,neXindex+N/2,neYindex-1+N/2);
      flag=1;
    }
  }
}
Exemple #12
0
RBitmapImage&	RWinColorPalette::GetPaletteBitmapImage( )
{
	static BOOLEAN			m_fPaletteInitialized = FALSE;
	static RBitmapImage	m_biPalette;

	if ( !m_fPaletteInitialized )
	{
		// find the resource in the resource file
		HRSRC hRsrc = FindResource( AfxGetResourceHandle(), 
			MAKEINTRESOURCE( m_uPaletteBitmapID ), RT_BITMAP );

		if ( hRsrc != NULL )
		{
			// get a handle to the resource data
			HGLOBAL hTemp = LoadResource( AfxGetResourceHandle(), hRsrc );

			if ( hTemp != NULL )
			{
				// Initlize the palette bitmap with the resource data
				m_biPalette.Initialize( LockResource( hTemp ) );

				// unlock and free the resource
				UnlockResource( hTemp );
				FreeResource( hTemp );
			}
			else
				AfxThrowResourceException( );
		}
		else
			AfxThrowResourceException( );

		m_fPaletteInitialized = TRUE;

		COLORMAP crColorMap[] =
		{
			{ RGB( 255, 255, 255 ), GetSysColor( COLOR_BTNHIGHLIGHT ) },
			{ RGB( 192, 192, 192 ), GetSysColor( COLOR_BTNFACE )      },
			{ RGB( 128, 128, 128 ), GetSysColor( COLOR_BTNSHADOW )    }
		};

		RIntPoint ptCells[] = 
		{
			FindColor( crColorMap[0].from ),
			FindColor( crColorMap[1].from ),
			FindColor( crColorMap[2].from )
		};

		void*     pRawData   = m_biPalette.GetRawData();
		RGBQUAD*  pColorData = (RGBQUAD *) RBitmapImage::GetColorData( pRawData );
		LPBYTE    pImageData = (LPBYTE) RBitmapImage::GetImageData( pRawData );

		for (int j = 0; (LPVOID) pColorData < (LPVOID) pImageData; j++, pColorData++)
		{
			for (int i = 0; i < NumElements( crColorMap ); i++)
			{
				if (crColorMap[i].from == RGB( pColorData->rgbRed, pColorData->rgbGreen, pColorData->rgbBlue ))
				{
					pColorData->rgbBlue  = GetBValue( crColorMap[i].to );
					pColorData->rgbRed   = GetRValue( crColorMap[i].to );
					pColorData->rgbGreen = GetGValue( crColorMap[i].to );
					pColorData->rgbReserved = 0;
				}
			}

			if (j == 9)
			{
				// We only need to look at the system colors, so
				// jump to the last 10 entries in the palette.
				pColorData += 235;
			}
		}

		m_biPalette.UpdatePalette();

		//
		// Relace the cells that got remapped
		//
		ROffscreenDrawingSurface dsMem;
		dsMem.SetImage( &m_biPalette );

		RSolidColor rSolid;

		for (int i = 0; i < NumElements( ptCells ); i++)
		{
			if (ptCells[i].m_x >= 0 && ptCells[i].m_y >= 0)
			{
				RIntRect rcCell( RIntSize( kCellSize.m_dx - 2, kCellSize.m_dy - 2 ) );
				rcCell.Offset( RIntSize( ptCells[i].m_x + 1, ptCells[i].m_y + 1 ) );

				rSolid = crColorMap[i].from;

				RColor rColor( rSolid );
				dsMem.SetFillColor( rColor );
				dsMem.FillRectangle( rcCell );
			}
		}

		dsMem.ReleaseImage();
	}

	return m_biPalette;
}