void CCreditsThread::InitColors()
{
	// define each color we'll be using

	m_arColors.Add(PALETTERGB(0, 0, 0));	// 0 = BLACK
	m_arColors.Add(PALETTERGB(90, 90, 90));	// 1 = very dark gray
	m_arColors.Add(PALETTERGB(128, 128, 128));		// 2 = DARK GRAY
	m_arColors.Add(PALETTERGB(192, 192, 192));	// 3 = LIGHT GRAY
	m_arColors.Add(PALETTERGB(200, 50, 50));	// 4 = very light gray
	m_arColors.Add(PALETTERGB(255, 255, 128));	// 5 white
	m_arColors.Add(PALETTERGB(0, 0, 128));	// 6 dark blue
	m_arColors.Add(PALETTERGB(128, 128, 255));	// 7 light blue
	m_arColors.Add(PALETTERGB(0, 106, 0));	// 8 dark green
}
Beispiel #2
0
COLORREF RGBFromAttrib2(PCONSOLE Console, WORD Attribute)
{
    HPALETTE hPalette = Console->ActiveBuffer->PaletteHandle;
    PALETTEENTRY pe;

    if (hPalette == NULL) return RGBFromAttrib(Console, Attribute);

    GetPaletteEntries(hPalette, Attribute, 1, &pe);
    return PALETTERGB(pe.peRed, pe.peGreen, pe.peBlue);
}
Beispiel #3
0
void wxColour::InitRGBA(unsigned char r, unsigned char g, unsigned char b,
                        unsigned char a)
{
    m_red = r;
    m_green = g;
    m_blue = b;
    m_alpha = a;
    m_isInit = true;
    m_pixel = PALETTERGB(m_red, m_green, m_blue);
}
Beispiel #4
0
/*
* GetPlayerWhoNameColor:  Return color that player's name should be drawn on
*   the who list, depending on player's object flags
*/
COLORREF GetPlayerWhoNameColor(object_node* obj, char *name)
{
     int r, g, b;

     r = (obj->namecolor & 0xFF0000) >> 16;
     g = (obj->namecolor & 0x00FF00) >> 8;
     b = (obj->namecolor & 0x0000FF);

      return PALETTERGB(r, g, b);
}
Beispiel #5
0
void CColorButton::DrawFrame(CDC *DC, CRect R, int Inset)
{
    COLORREF dark, light, tlColor, brColor;
    int i, m, width;
    width = (Inset < 0)? -Inset : Inset;

    for (i = 0; i < width; i += 1) {
        m = 255 / (i + 2);
        dark = PALETTERGB(m, m, m);
        m = 192 + (63 / (i + 1));
        light = PALETTERGB(m, m, m);

        if ( width == 1 ) {
            light = RGB(255, 255, 255);
            dark = RGB(128, 128, 128);
        }

        if ( Inset < 0 ) {
            tlColor = dark;
            brColor = light;
        }
        else {
            tlColor = light;
            brColor = dark;
        }

        DrawLine(DC, R.left, R.top, R.right, R.top, tlColor);
        // Across top
        DrawLine(DC, R.left, R.top, R.left, R.bottom, tlColor);
        // Down left

        if ( (Inset < 0) && (i == width - 1) && (width > 1) ) {
            DrawLine(DC, R.left + 1, R.bottom - 1, R.right, R.bottom - 1, RGB(1, 1, 1));// Across bottom
            DrawLine(DC, R.right - 1, R.top + 1, R.right - 1, R.bottom, RGB(1, 1, 1));	// Down right
        }
        else {
            DrawLine(DC, R.left + 1, R.bottom - 1, R.right, R.bottom - 1, brColor); 	// Across bottom
            DrawLine(DC, R.right - 1, R.top + 1, R.right - 1, R.bottom, brColor);		// Down right
        }
        InflateRect(R, -1, -1);
    }
}
Beispiel #6
0
int wxPalette::GetPixel(unsigned char red, unsigned char green, unsigned char blue) const
{
#ifdef __WXMICROWIN__
    return wxNOT_FOUND;
#else
    if ( !m_refData )
        return wxNOT_FOUND;

    return ::GetNearestPaletteIndex((HPALETTE) M_PALETTEDATA->m_hPalette, PALETTERGB(red, green, blue));
#endif
}
Beispiel #7
0
void I_ConTextAttr(unsigned char a)
{
  int r,g,b,col;
  HDC conDC;

  if (!console_inited)
    return;
  conDC=GetDC(con_hWnd);
  r=0; g=0; b=0;
  if (a & FOREGROUND_INTENSITY) col=255;
  else col=128;
  if (a & FOREGROUND_RED) r=col;
  if (a & FOREGROUND_GREEN) g=col;
  if (a & FOREGROUND_BLUE) b=col;
  SetTextColor(conDC, PALETTERGB(r,g,b));
  r=0; g=0; b=0;
  if (a & BACKGROUND_INTENSITY) col=255;
  else col=128;
  if (a & BACKGROUND_RED) r=col;
  if (a & BACKGROUND_GREEN) g=col;
  if (a & BACKGROUND_BLUE) b=col;
  SetBkColor(conDC, PALETTERGB(r,g,b));
  ReleaseDC(con_hWnd,conDC);
}
CardWindow::CardWindow() : m_hWnd(0)
{
    HDC hdc = GetDC(0);

    nNumButtons       = 0;
    nNumCardRegions   = 0;
    nNumDropZones     = 0;
    nBackCardIdx      = 53;

    ResizeWndCallback = 0;
    hbmBackImage      = 0;
    hdcBackImage      = 0;

    srand((unsigned)GetTickCount());

    //All colours (buttons, highlights, decks)
    //are calculated off this single base colour
    crBackgnd = PALETTERGB(0,80,0);//PALETTERGB(0,64,100);

    // If uCardBitmapRef was previously zero, then
    // load the card bitmaps
    if(1 == InterlockedIncrement(&uCardBitmapRef))
    {
        LoadCardBitmaps();

        __hPalette  = CreateCardPalette();

        __hdcPlaceHolder  = CreateCompatibleDC(hdc);

        __holdplacepal  = UseNicePalette(__hdcPlaceHolder, __hPalette);

        __hbmPlaceHolder  = CreateSinkBmp(hdc, __hdcPlaceHolder, crBackgnd, __cardwidth, __cardheight);

    }

    ReleaseDC(0, hdc);

    //register the window class if necessary
    if(!fRegistered)
    {
        fRegistered = true;
        RegisterCardWindow();
    }

}
Beispiel #9
0
void CChildView::DoGradientFill(CDC *pDC, LPRECT pRect)
{
    CBrush* pBrush[64];
    for (int i=0; i<64; i++)
        pBrush[i] = new CBrush (PALETTERGB (0, 0, 255 - (i * 4)));

    int nWidth = pRect->right - pRect->left;
    int nHeight = pRect->bottom - pRect->top;
    CRect rect;

    for (i=0; i<nHeight; i++) {
        rect.SetRect (0, i, nWidth, i + 1);
        pDC->FillRect (&rect, pBrush[(i * 63) / nHeight]);
    }

    for (i=0; i<64; i++)
        delete pBrush[i];
}
Beispiel #10
0
VOID vTestPal2(HDC hdc)
{
    HPALETTE hpalDefault;
    HBRUSH hbrDefault, hbr;
    DWORD ulIndex, ulPal;
    PALETTEENTRY palentry;

    hpalDefault = GetStockObject(DEFAULT_PALETTE);

    SelectPalette(hdc, hpalDefault, 0);
    SelectPalette(hdc, hpalDefault, 0);
    SelectPalette(hdc, hpalDefault, 0);
    SelectPalette(hdc, hpalDefault, 0);

    for (ulIndex = 0; ulIndex < 20; ulIndex++)
    {
	ulPal = PALETTEINDEX(ulIndex);

	if (!(ulPal & 0x01000000))
	    DbgPrint("PALETTEINDEX failed to do it\n");

	hbr = CreateSolidBrush(PALETTEINDEX(ulIndex));
	hbrDefault = SelectObject(hdc, hbr);
	PatBlt(hdc, ulIndex * 20, 0, 20, 20, PATCOPY);
	SelectObject(hdc, hbrDefault);
	DeleteObject(hbr);

	GetPaletteEntries(hpalDefault, ulIndex, 1, (LPPALETTEENTRY) &ulPal);

	hbr = CreateSolidBrush(ulPal);
	hbrDefault = SelectObject(hdc, hbr);
	PatBlt(hdc, ulIndex * 20, 20, 20, 20, PATCOPY);
	SelectObject(hdc, hbrDefault);
	DeleteObject(hbr);

	GetPaletteEntries(hpalDefault, ulIndex, 1, (LPPALETTEENTRY) &palentry);

	hbr = CreateSolidBrush(PALETTERGB(palentry.peRed, palentry.peGreen, palentry.peBlue));
	hbrDefault = SelectObject(hdc, hbr);
	PatBlt(hdc, ulIndex * 20, 40, 20, 20, PATCOPY);
	SelectObject(hdc, hbrDefault);
	DeleteObject(hbr);
    }
}
Beispiel #11
0
void CSplashWnd::OnPaint()
{
	CPaintDC dc(this);

	CDC dcImage;
	if (!dcImage.CreateCompatibleDC(&dc))
		return;

	BITMAP bm;
	m_bitmap.GetBitmap(&bm);
	// Paint the image.
	CBitmap* pOldBitmap = dcImage.SelectObject(&m_bitmap);
	dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, SRCCOPY);
	dcImage.SelectObject(pOldBitmap);

	for(int i=0;i<bm.bmHeight;i++){
		COLORREF col=PALETTERGB(0,0,(255*i)/bm.bmHeight);
		CRect rect(0,i,bm.bmWidth,i+2);
		dcImage.FillSolidRect(&rect, col);
	}
	dc.BitBlt(0, 0, bm.bmWidth, bm.bmHeight, &dcImage, 0, 0, MERGEPAINT);

}
Beispiel #12
0
int
main(void)
{
  Stream *graph_id;
  int fnrc;
  word i;
  LOGPALETTE *pal;
  word colors[PERMS];
  
  /* initialise the graphics system, without any event handlers */
  
  if (!InitGraphics(NULL, NULL)) {
      fprintf(stderr,"Unable to find graphics server\n\n");
      exit(EXIT_FAILURE);
    }
  
  /* open the window in its maximum form with resizable border and */
  /* do not give the window the input focus.                       */
  
  graph_id = OpenGraph("Test", 200, 200, 64, 64, 
		       WS_OVERLAPPEDWINDOW, SW_SHOWNA);
  
  if (graph_id == (Stream *) NULL) {
      TidyGraphics();
      fprintf(stderr, "Unable to open window\n\n");
      exit(EXIT_FAILURE);
    }
  
  /* set up the values which will be used to generate the palette */
  /* create a palette with enough space */
  pal = CreatePalette(PERMS);
  
  
  for (i=0; i<PERMS; i++) {
      /* either set up the same RGB values in colors : */
      colors[i] = PALETTERGB(i, i, i);
      
      /* set up the user defined palette */
      pal->pal[i].red   = (int)i;
      pal->pal[i].green = (int)i;
      pal->pal[i].blue  = (int)i;
      pal->pal[i].flags = 0;    /* setting this to zero will generally be */
      /* sufficient                             */
      
    }
  
  
  /* enable the use of the palette */
  fnrc = SelectPalette(graph_id, pal);
  
    {
      BITMAP *bmp;
      char map[256*4];
      int k,l;
      
      bmp = CreateDIBitMap(graph_id,16,16);
      
      for (l = 0; l < 4; l++)
	for (k = 0; k < 256; k++)
	  map[l*256 + k] = 0xff ;
      
      for (l = 0; l < 256; l++)
	{
	  for (k = 0; k < 256; k++)
	    {
	      map[k*4]   = 0x00;
	      map[k*4+1] = l;
	      map[k*4+2] = l;
	      map[k*4+3] = l;
	    }
	  SetBitMapBits(bmp,map);
	  DrawBitMap(graph_id,bmp,0,0,SRCCOPY);
	  (void) getchar();
	}
    }
  
  TidyGraphics();
  
  return(0);
}
Beispiel #13
0
void vDrawStuff6(HDC hdc, RECT *prclBound)
{
    DWORD dwTemp;
    HBRUSH hBrush, hOldBrush;

// Paint the PALETTEINDEX stripes.

    vPaintStripes(hdc, prclBound);

// Paint PALETTEINDEX stripes.

    for (dwTemp = 0; dwTemp < 256; dwTemp++)
    {
        hBrush = CreateSolidBrush(PALETTEINDEX(dwTemp));
	hOldBrush = SelectObject(hdc,hBrush);

	PatBlt(hdc,
	       (((prclBound->right - prclBound->left) * dwTemp) / 256),
               75,
	       (((prclBound->right - prclBound->left) / 256) + 3),
               75,
	       PATCOPY);

	SelectObject(hdc, hOldBrush);
	DeleteObject(hBrush);
    }

// Paint the RGB stripes.

    for (dwTemp = 0; dwTemp < 256; dwTemp++)
    {
	hBrush = CreateSolidBrush(RGB(dwTemp,0,0));
	hOldBrush = SelectObject(hdc,hBrush);

	PatBlt(hdc,
	       (((prclBound->right - prclBound->left) * dwTemp) / 256),
               150,
	       (((prclBound->right - prclBound->left) / 256) + 3),
               75,
	       PATCOPY);

	SelectObject(hdc, hOldBrush);
	DeleteObject(hBrush);
    }

// Paint the PALETTERGB stripes.

    for (dwTemp = 0; dwTemp < 256; dwTemp++)
    {
	hBrush = CreateSolidBrush(PALETTERGB(dwTemp,0,0));
	hOldBrush = SelectObject(hdc,hBrush);

	PatBlt(hdc,
	       (((prclBound->right - prclBound->left) * dwTemp) / 256),
               225,
	       (((prclBound->right - prclBound->left) / 256) + 3),
               75,
	       PATCOPY);

	SelectObject(hdc, hOldBrush);
	DeleteObject(hBrush);
    }
}
Beispiel #14
0
int main(void)
{
   Stream *graph;
   int 	fnrc, i, j;
   double width, height;
   int 	r, g, b;
   char perms[MAX];
   LOGPALETTE *pal;
   word colors[PERMS];

   /* initialise the graphics system, without any event handlers */
   
   if (!InitGraphics(NULL, NULL))
   {  fprintf(stderr,"Unable to find graphics server\n\n");
      exit(EXIT_FAILURE);
   }
   
   /* open the window in its maximum form with resizable border and */
   /* do not give the window the input focus.                       */
   
   graph = OpenGraph("Palette Test", 0, 0, GetMaxX(), GetMaxY(), WS_OVERLAPPEDWINDOW, SW_SHOWNA);
                        
   if (graph == Null(Stream)) 
   {  TidyGraphics();
      fprintf(stderr, "Unable to open window\n\n");
      exit(1);
   }
   
   /* set up the values which will be used to generate the palette */
   perms[0] = 0;
   perms[1] = 51;
   perms[2] = 102;
   perms[3] = 153;
   perms[4] = 204;
   perms[5] = 255;
   
   /* create a palette with enough space */
   pal = CreatePalette(PERMS);
   
   r = 0;   g = 0;   b = 0;
   
   /* the following loop generates the color palette as well as setting */
   /* up the color used by the program.  Either the PALETTERGB color or */
   /* the PALETTEINDEX color value may be used - it produces the same   */
   /* result.                                                           */
   
   for (i=0; i<PERMS; i++)
   {  /* either set up the same RGB values in colors : */
      colors[i] = PALETTERGB(perms[r], perms[g], perms[b]);
      
      /* or use the index value into the user defined palette : */
      /* colors[i] = PALETTEINDEX(i); */
      
      /* set up the user defined palette */
      pal->pal[i].red 	= perms[r];
      pal->pal[i].green = perms[g];
      pal->pal[i].blue 	= perms[b];
      pal->pal[i].flags = 0;    /* setting this to zero will generally be */
                                /* sufficient                             */
      
      if ((++r) == MAX)
      {  r = 0;
         if ((++g) == MAX) 
         {  g = 0;
            b++;
         }
      }
   }
   
   /* work out the width and height of a color block */
   width = (double)(GetMaxX() - 2*GetResizeFrameX()) / 18.0;
   height = (double)(GetMaxY() - GetCaptionSize() - 2*GetResizeFrameY()) / 12.0;
   
   /* enable the use of the palette */
   fnrc = SelectPalette(graph, pal);
   
   /* within this loop we display the colors */
   for (i=0; i<12; i++)
      for (j=0; j<18; j++)
         FillRect(graph, (int)((double)j*width), (int)((double)i*height), 
           (int)((double)(j+1)*width), (int)((double)(i+1)*height), colors[i*18+j]);
   
   FLUSH();
   
   sleep(3);

   CloseGraph(graph);
   TidyGraphics();
   
   exit(0);
}
Beispiel #15
0
LRESULT CALLBACK TranslateDlgHandler( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	
	char sztemp[20];
	TRANSLATEOBJ * st;
	
	st = (TRANSLATEOBJ *) actobject;
    if ((st==NULL)||(st->type!=OB_TRANSLATE)) return(FALSE);

	switch( message )
	{
		case WM_INITDIALOG:
			sprintf(sztemp,"%.2f",st->in_ports[0].in_min);
			SetDlgItemText(hDlg, IDC_IN_MIN, sztemp);
			sprintf(sztemp,"%.2f",st->in_ports[0].in_max);
			SetDlgItemText(hDlg, IDC_IN_MAX, sztemp);
			sprintf(sztemp,"%.2f",st->out_ports[0].out_min);
			SetDlgItemText(hDlg, IDC_OUT_MIN, sztemp);
			sprintf(sztemp,"%.2f",st->out_ports[0].out_max);
			SetDlgItemText(hDlg, IDC_OUT_MAX, sztemp);
			
			return TRUE;
		case WM_CLOSE:		
			    EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
				break;
		case WM_COMMAND:
			switch (LOWORD(wParam)) 
			{
			case IDC_APPLY:
				st->in_ports[0].get_range=-1;
				st->out_ports[0].get_range=-1;
				GetDlgItemText(hDlg,IDC_IN_MIN,sztemp,sizeof(sztemp));
				sscanf(sztemp,"%f",&st->in_ports[0].in_min);
				GetDlgItemText(hDlg,IDC_IN_MAX,sztemp,sizeof(sztemp));
				sscanf(sztemp,"%f",&st->in_ports[0].in_max);
				GetDlgItemText(hDlg,IDC_OUT_MIN,sztemp,sizeof(sztemp));
				sscanf(sztemp,"%f",&st->out_ports[0].out_min);
				GetDlgItemText(hDlg,IDC_OUT_MAX,sztemp,sizeof(sztemp));
				sscanf(sztemp,"%f",&st->out_ports[0].out_max);
				break;

			}
			return TRUE;
		
    
	 	case WM_LBUTTONUP: st->setpoint=-1;
				break;
 	 	case WM_LBUTTONDOWN:
			{  int minpoint,i,z;
			   float actdist,mindist,actx,acty;

				  st->actmousex=(int)LOWORD(lParam);
				  st->actmousey=(int)HIWORD(lParam);
				  if ((st->actmousex<left)||(st->actmousex>right)||
					  (st->actmousey>bottom)||(st->actmousey<top)) break;
				  
				  mindist=10000;minpoint=-1;
				  actx=(float)(st->actmousex-left)/(right-left)*1023.0f;
				  acty=(float)(bottom-st->actmousey)/(bottom-top);

				  for (i=0;i<st->points;i++)
				  {
					  
				       actdist = (st->pointx[i]-actx)*(st->pointx[i]-actx)
						   + (st->pointy[i]-acty)*(st->pointy[i]-acty);
				
					   if (actdist<mindist) { mindist=actdist; minpoint=i; }

				  }

				  if (mindist<300) st->setpoint=minpoint; 
				  else 
				  { 
					 if (st->points>=MAX_TRANSLATIONPOINTS-1) break;
					
					 i=0;while ((st->pointx[i]<actx)&&(i<st->points)) i++;
					 for (z=st->points;z>i;z--)
					 {
					    st->pointx[z]=st->pointx[z-1];
					    st->pointy[z]=st->pointy[z-1];
					 }
					 st->pointx[z]=(int)actx;
					 st->pointy[z]=acty;
					 st->points++;
					 InvalidateRect(hDlg,NULL,TRUE);
					 st->setpoint=z;
				  }
			}

		case WM_MOUSEMOVE:
			{ 
				int i;
				st->actmousex=(int)LOWORD(lParam);
				st->actmousey=(int)HIWORD(lParam);
				  
				if (st->setpoint!=-1)
				{
					if ((st->actmousex<left)||(st->actmousex>right)||
					   (st->actmousey>bottom)||(st->actmousey<top))
					{
						if (st->points<=2) break;
						for (i=st->setpoint;i<st->points;i++)
						{
							st->pointx[i]=st->pointx[i+1];
							st->pointy[i]=st->pointy[i+1];
						}
						st->points--;
						st->pointx[0]=0;st->pointx[st->points-1]=1023;
						st->setpoint=-1;
					}
					else
					{
						st->pointx[st->setpoint]=(int)((st->actmousex-left)/(float)(right-left)*1023.0f);
						st->pointy[st->setpoint]=(float)(bottom-st->actmousey)/(bottom-top);
						if (st->setpoint==0) st->pointx[0]=0;
						if (st->setpoint==st->points-1) st->pointx[st->points-1]=1023;
					}
					st->calculate_map();
 					InvalidateRect(hDlg,NULL,TRUE);
				}
			}
			break;


		case WM_PAINT:
			{
				PAINTSTRUCT ps;
				HDC hdc;
				HPEN tpen;
				HBRUSH tbrush;
				int i;
				float dx,dy;

				hdc = BeginPaint (hDlg, &ps);
				tpen    = CreatePen (PS_SOLID,3,50);
				SelectObject (hdc, tpen);
				SelectObject (hdc, DRAW.brush_ltorange);
				
				tbrush = CreateSolidBrush(PALETTERGB(240,240,240));
				SelectObject (hdc, tbrush);
				
				Rectangle(hdc,left,top,right,bottom);
				
				dx=(float)(right-left)/1023.0f;
				dy=(float)(bottom-top);

				DeleteObject(tpen);
				tpen = CreatePen (PS_SOLID,2,PALETTERGB(180,0,0));
				SelectObject (hdc, tpen);

				for (i=0;i<st->points-1;i++)
				{
					MoveToEx(hdc,left+ (int)((float)st->pointx[i]*dx),bottom - (int)(st->pointy[i]*dy),NULL);
					LineTo(hdc,left + (int)((float)st->pointx[i+1]*dx),bottom - (int)(st->pointy[i+1]*dy));
				}
				DeleteObject(tbrush);
				DeleteObject(tpen);
				EndPaint(hDlg, &ps );
			} 
			break;

		case WM_SIZE:
		case WM_MOVE:  update_toolbox_position(hDlg);
			break;
		
	
	}
    return FALSE;
}
void CColourPopup::DrawCell(CDC* pDC, int nIndex)
{
    // For the Custom Text area
    if (m_strCustomText.GetLength() && nIndex == CUSTOM_BOX_VALUE)
    {
        // The extent of the actual text button
        CRect TextButtonRect = m_CustomTextRect;
        TextButtonRect.top += 2*m_nMargin;

        // Fill background
        pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE));

        // Draw horizontal line
        pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top,
                           m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DSHADOW));
        pDC->FillSolidRect(m_CustomTextRect.left+2*m_nMargin, m_CustomTextRect.top+1,
                           m_CustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DHILIGHT));

        TextButtonRect.DeflateRect(1,1);

        // fill background
        if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex)
            pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT));
        else
            pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE));

        // Draw button
        if (m_nCurrentSel == nIndex) 
            pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT);
        else if (m_nChosenColourSel == nIndex)
            pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT);

        // Draw custom text
        CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font);
        pDC->SetBkMode(TRANSPARENT);
        pDC->DrawText(m_strCustomText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
        pDC->SelectObject(pOldFont);

        return;
    }        

    // For the Default Text area
    if (m_strDefaultText.GetLength() && nIndex == DEFAULT_BOX_VALUE)
    {
        // Fill background
        pDC->FillSolidRect(m_DefaultTextRect, ::GetSysColor(COLOR_3DFACE));

        // The extent of the actual text button
        CRect TextButtonRect = m_DefaultTextRect;
        TextButtonRect.DeflateRect(1,1);

        // fill background
        if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex)
            pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DLIGHT));
        else
            pDC->FillSolidRect(TextButtonRect, ::GetSysColor(COLOR_3DFACE));

        // Draw thin line around text
        CRect LineRect = TextButtonRect;
        LineRect.DeflateRect(2*m_nMargin,2*m_nMargin);
        CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
        CPen* pOldPen = pDC->SelectObject(&pen);
        pDC->SelectStockObject(NULL_BRUSH);
        pDC->Rectangle(LineRect);
        pDC->SelectObject(pOldPen);

        // Draw button
        if (m_nCurrentSel == nIndex) 
            pDC->DrawEdge(TextButtonRect, BDR_RAISEDINNER, BF_RECT);
        else if (m_nChosenColourSel == nIndex)
            pDC->DrawEdge(TextButtonRect, BDR_SUNKENOUTER, BF_RECT);

        // Draw custom text
        CFont *pOldFont = (CFont*) pDC->SelectObject(&m_Font);
        pDC->SetBkMode(TRANSPARENT);
        pDC->DrawText(m_strDefaultText, TextButtonRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
        pDC->SelectObject(pOldFont);

        return;
    }        

    CRect rect;
    if (!GetCellRect(nIndex, rect)) return;

    // Select and realize the palette
    CPalette* pOldPalette = NULL;
    if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
    {
        pOldPalette = pDC->SelectPalette(&m_Palette, FALSE);
        pDC->RealizePalette();
    }

    // fill background
    if (m_nChosenColourSel == nIndex && m_nCurrentSel != nIndex)
        pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DHILIGHT));
    else
        pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));

    // Draw button
    if (m_nCurrentSel == nIndex) 
        pDC->DrawEdge(rect, BDR_RAISEDINNER, BF_RECT);
    else if (m_nChosenColourSel == nIndex)
        pDC->DrawEdge(rect, BDR_SUNKENOUTER, BF_RECT);

    CBrush brush(PALETTERGB(GetRValue(GetColour(nIndex)), 
                            GetGValue(GetColour(nIndex)), 
                            GetBValue(GetColour(nIndex)) ));
    CPen   pen;
    pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));

    CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
    CPen*   pOldPen   = (CPen*)   pDC->SelectObject(&pen);

    // Draw the cell colour
    rect.DeflateRect(m_nMargin+1, m_nMargin+1);
    pDC->Rectangle(rect);

    // restore DC and cleanup
    pDC->SelectObject(pOldBrush);
    pDC->SelectObject(pOldPen);
    brush.DeleteObject();
    pen.DeleteObject();

    if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
        pDC->SelectPalette(pOldPalette, FALSE);
}
void COptionTreeColorPopUp::DrawCell(CDC* pDC, int nIndex)
{
    // For the Custom Text area
    if (m_strCustomText.GetLength() && nIndex == OT_COLOR_CUSTOMBOXVALUE)
    {
        // -- The extent of the actual text button
        CRect rcTextButton = m_rcCustomTextRect;
        rcTextButton.top += 2 * m_nMargin;

        // -- Fill background
        pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE));

        // -- Draw horizontal line
        pDC->FillSolidRect(m_rcCustomTextRect.left + 2 * m_nMargin, m_rcCustomTextRect.top, m_rcCustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DSHADOW));
        pDC->FillSolidRect(m_rcCustomTextRect.left + 2 * m_nMargin, m_rcCustomTextRect.top + 1, m_rcCustomTextRect.Width()-4*m_nMargin, 1, ::GetSysColor(COLOR_3DHILIGHT));
        rcTextButton.DeflateRect(1,1);

        // -- Fill background
        if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex)
		{
            pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DLIGHT));
		}
        else
		{
            pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE));
		}

        // -- Draw button
        if (m_nCurrentSel == nIndex) 
		{
            pDC->DrawEdge(rcTextButton, BDR_RAISEDINNER, BF_RECT);
		}

        // -- Draw custom text
        CFont *pOldFont = (CFont*) pDC->SelectObject(&m_fFont);
        int nOldBack = pDC->SetBkMode(TRANSPARENT);
        pDC->DrawText(m_strCustomText, rcTextButton, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		// -- Restore
        pDC->SelectObject(pOldFont);
		pDC->SetBkMode(nOldBack);

        return;
    }        

    // For the Default Text area
    if (m_strDefaultText.GetLength() && nIndex == OT_COLOR_DEFAULTBOXVALUE)
    {
        // -- Fill background
        pDC->FillSolidRect(m_rcDefaultTextRect, ::GetSysColor(COLOR_3DFACE));

        // -- The extent of the actual text button
        CRect rcTextButton = m_rcDefaultTextRect;
        rcTextButton.DeflateRect(1,1);

        // -- Fill background
        if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex)
		{
			for (long i = rcTextButton.top; i < rcTextButton.bottom; i++)
			{
				_DrawSelectRect(pDC->GetSafeHdc(), rcTextButton.left, i, rcTextButton.Width());
			}
		}
        else
		{
            pDC->FillSolidRect(rcTextButton, ::GetSysColor(COLOR_3DFACE));
		}

        // -- Draw thin line around text
        CRect rcLineRect = rcTextButton;
        CPen pen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
        CPen* pOldPen = pDC->SelectObject(&pen);
		
		// -- Calculate the rectangle
		rcLineRect.left += 3;
		rcLineRect.right -= 3;
		rcLineRect.top += 2;
		rcLineRect.bottom -= 3;

		// -- Restore
        pDC->SelectStockObject(NULL_BRUSH);
        pDC->Rectangle(rcLineRect);
        pDC->SelectObject(pOldPen);
		if (pen.GetSafeHandle() != NULL)
		{
			pen.DeleteObject();
		}

        // -- Draw button
        if (m_nCurrentSel == nIndex) 
		{
            pDC->DrawEdge(rcTextButton, BDR_RAISEDINNER, BF_RECT);
		}
        else if (m_nChosenColorSel == nIndex)
		{
            pDC->DrawEdge(rcTextButton, BDR_SUNKENOUTER, BF_RECT);
		}

        // -- Draw custom text
        CFont *pOldFont = (CFont*) pDC->SelectObject(&m_fFont);
        int nOldBack = pDC->SetBkMode(TRANSPARENT);
        pDC->DrawText(m_strDefaultText, rcTextButton, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

		// -- Restore
        pDC->SelectObject(pOldFont);
		pDC->SetBkMode(nOldBack);

		// -- Select and realize the palette
		CPalette* pOldPalette = NULL;
		if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
		{
			pOldPalette = pDC->SelectPalette(&m_plPalette, FALSE);
			pDC->RealizePalette();
		}

		// -- Draw sample cell of default color
		CRect rcSample;
		rcSample.left = rcLineRect.left;
		rcSample.right = rcSample.left + m_nBoxSize;
		rcSample.top = rcLineRect.top;
		rcSample.bottom = rcLineRect.top + m_nBoxSize;
		rcSample.DeflateRect(m_nMargin + 1, m_nMargin + 1);

		// -- Create objects
		CBrush brush(PALETTERGB(GetRValue(m_crDefault), GetGValue(m_crDefault), GetBValue(m_crDefault)));
		CPen penSample;
		penSample.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
		CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
		CPen* pOldSamplePen = (CPen*) pDC->SelectObject(&penSample);

		// Draw the cell color
		pDC->Rectangle(rcSample);

		// Restore
		pDC->SelectObject(pOldBrush);
		pDC->SelectObject(pOldSamplePen);
		if (brush.GetSafeHandle() != NULL)
		{
			brush.DeleteObject();
		}
		if (penSample.GetSafeHandle() != NULL)
		{
			penSample.DeleteObject();
		}
		if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
		{
			pDC->SelectPalette(pOldPalette, FALSE);
		}
        return;
    }        

	// Declare variables
    CRect rcCell;
    if (!GetCellRect(nIndex, rcCell)) 
	{
		return;
	}

    // -- Select and realize the palette
    CPalette* pOldPalette = NULL;
    if (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
    {
        pOldPalette = pDC->SelectPalette(&m_plPalette, FALSE);
        pDC->RealizePalette();
    }

    // -- Fill background
    if (m_nChosenColorSel == nIndex && m_nCurrentSel != nIndex)
	{
		for (long i = rcCell.top; i < rcCell.bottom; i++)
		{
			_DrawSelectRect(pDC->GetSafeHdc(), rcCell.left, i, rcCell.Width());
		}
	}
    else
	{
        pDC->FillSolidRect(rcCell, ::GetSysColor(COLOR_3DFACE));
	}

    // Draw button
    if (m_nCurrentSel == nIndex) 
	{
        pDC->DrawEdge(rcCell, BDR_RAISEDINNER, BF_RECT);
	}
    else if (m_nChosenColorSel == nIndex)
	{
        pDC->DrawEdge(rcCell, BDR_SUNKENOUTER, BF_RECT);
	}

	// Create objects
    CBrush brush(PALETTERGB(GetRValue(GetColor(nIndex)), GetGValue(GetColor(nIndex)), GetBValue(GetColor(nIndex))));
	CPen pen;
    pen.CreatePen(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));
    CBrush* pOldBrush = (CBrush*) pDC->SelectObject(&brush);
    CPen* pOldPen = (CPen*) pDC->SelectObject(&pen);

    // Draw the cell color
    rcCell.DeflateRect(m_nMargin + 1, m_nMargin + 1);
    pDC->Rectangle(rcCell);

    // Restore
    pDC->SelectObject(pOldBrush);
    pDC->SelectObject(pOldPen);
	if (brush.GetSafeHandle() != NULL)
	{
		brush.DeleteObject();
	}
	if (pen.GetSafeHandle() != NULL)
	{
		pen.DeleteObject();
	}
    if (pOldPalette && pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
	{
        pDC->SelectPalette(pOldPalette, FALSE);
	}
}
Beispiel #18
0
}
/************************************************************************/
static char *format_chars = "`~"; // Characters that start a format code

// FormatCode types
#define CODE_COLOR 0x01
#define CODE_STYLE 0x02

typedef struct {
   char  code;  // Character that formatting type
   BYTE  type;  // Formatting that this code affects (text color, text style)
   int   data;  // Value to set formatting type
} FormatCode;

static FormatCode code_table[] = {
{ 'r', CODE_COLOR, PALETTERGB(128,   0,   0) }, // Dark red
{ 'f', CODE_COLOR, PALETTERGB(200,   0,   0) }, // Bright red
{ 'g', CODE_COLOR, PALETTERGB(  0, 100,   0) }, // Dark green
{ 'l', CODE_COLOR, PALETTERGB(  0, 255,   0) }, // Light green
{ 'b', CODE_COLOR, PALETTERGB(  0,   0, 255) }, // Dark blue
{ 'k', CODE_COLOR, PALETTERGB(  0,   0,   0) }, // Black
{ 'w', CODE_COLOR, PALETTERGB(255, 255, 255) }, // White
{ 'y', CODE_COLOR, PALETTERGB(230, 230,  25) }, // Yellow
{ 'p', CODE_COLOR, PALETTERGB(255, 105, 210) }, // Pink
{ 'o', CODE_COLOR, PALETTERGB(255, 150,   0) }, // Orange
{ 'a', CODE_COLOR, PALETTERGB(127, 255, 212) }, // Aquamarine
{ 'c', CODE_COLOR, PALETTERGB( 46, 234, 250) }, // Cyan
{ 'q', CODE_COLOR, PALETTERGB(143,  38, 170) }, // Purple
{ 't', CODE_COLOR, PALETTERGB( 11,  59, 112) }, // Teal
{ 's', CODE_COLOR, PALETTERGB( 60,  60,  60) }, // Dark grey
{ 'v', CODE_COLOR, PALETTERGB(128,   0, 128) }, // Violet
Beispiel #19
0
/*----------------------------------------------------------------------------------------------
	Draw the combo control.
----------------------------------------------------------------------------------------------*/
bool IconComboCombo::OnDrawThisItem(DRAWITEMSTRUCT * pdis)
{
    AssertPtr(pdis);
    AssertPtr(m_pival);

#ifdef JT_4_3_01_IMPLEMENTED
    HDC hdc = pdis->hDC;
    Rect rc(pdis->rcItem);
    UINT state = pdis->itemState;
    int ival = *m_pival;

    SIZE sizeMargins = { ::GetSystemMetrics(SM_CXEDGE), ::GetSystemMetrics(SM_CYEDGE) };

    // Draw the down arrow.
    ::DrawFrameControl(hdc, &m_rcArrowButton, DFC_SCROLL, DFCS_SCROLLDOWN |
                       (m_fPushed || (state & ODS_SELECTED) ? DFCS_PUSHED : 0) |
                       ((state & ODS_DISABLED) ? DFCS_INACTIVE : 0));

    ::DrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT);

    // Must reduce the size of the "client" area of the button due to edge thickness.
    rc.Inflate(-sizeMargins.cx, -sizeMargins.cy);

// This is old code from UiColor.cpp. It may be some help if we get around to implementing
// this control fully.

    // Select and realize the palette.
    HPALETTE hpalOld = g_ct.RealizePalette(hdc);

    // Fill background.
    rc.right -= m_rcArrowButton.right - m_rcArrowButton.left;
    HPEN hpenOld = (HPEN)::SelectObject(hdc, ::GetStockObject(NULL_PEN));

//	HBRUSH hbrBackground = AfGdi::CreateSolidBrush(((state & ODS_DISABLED) ||
//		clr == CLR_DEFAULT) ? ::GetSysColor(COLOR_3DFACE) : RGB(255, 255, 255));
    HBRUSH hbrBackground = AfGdi::CreateSolidBrush(((state & ODS_DISABLED) ||
                           clr == CLR_DEFAULT) ? ::GetSysColor(COLOR_3DFACE) : ::GetSysColor(COLOR_WINDOW));

    HBRUSH hbrOld = AfGdi::SelectObjectBrush(hdc, hbrBackground);
    ::Rectangle(hdc, rc.left, rc.top, rc.right + 1, rc.bottom + 1);

    // If knNinch or conflicting then leave control blank.
    if ((clr != (COLORREF)knNinch) && (clr != (COLORREF)knNinch + 1))
    {
        // Fill a small box with color.
        int nBoxHeight = rc.bottom - rc.top - 4;
        RECT rcBox = { rc.left + 2, rc.top + 2, rc.left + 2 + nBoxHeight, rc.bottom - 2 };
        if (!m_fShowText)
            ::SetRect(&rcBox, rc.left + 2, rc.top + 2, rc.right - 2, rc.bottom - 2);
        COLORREF clr2 = clr;
        if (clr2 == kclrTransparent)
            clr2 = ::GetSysColor(COLOR_WINDOW);
        //			clr2 = kclrWhite;
        HBRUSH hbr = AfGdi::CreateSolidBrush(((state & ODS_DISABLED) ||
                                              clr2 == CLR_DEFAULT) ? ::GetSysColor(COLOR_3DFACE) :
                                             PALETTERGB(GetRValue(clr2), GetGValue(clr2), GetBValue(clr2)));
        HBRUSH hbrT = AfGdi::SelectObjectBrush(hdc, hbr);
        ::Rectangle(hdc, rcBox.left, rcBox.top, rcBox.right, rcBox.bottom);
        AfGdi::SelectObjectBrush(hdc, hbrT);
        ::FrameRect(hdc, &rcBox, (HBRUSH)::GetStockObject(BLACK_BRUSH));

        AfGdi::DeleteObjectBrush(hbr);

        if (hpalOld)
            ::SelectPalette(hdc, hpalOld, false);

        if (m_fShowText)
        {
            // Write out the text to the right of the box
            //COLORREF clrOldBk = ::SetBkColor(hdc, RGB(255,255,255));
            COLORREF clrOldBk = ::SetBkColor(hdc, ::GetSysColor(COLOR_WINDOW));
            Rect rcT(rcBox.right + 2, rcBox.top - 1, rc.right - 1, rcBox.bottom + 1);
            HFONT hfontOld = AfGdi::SelectObjectFont(hdc, ::GetStockObject(DEFAULT_GUI_FONT));
            StrAnsi sta(g_ct.GetColorRid(g_ct.GetIndexFromColor(clr)));
            ::DrawText(hdc, sta.Chars(), -1, &rcT, DT_LEFT);
            AfGdi::SelectObjectFont(hdc, hfontOld, AfGdi::OLD);
            ::SetBkColor(hdc, clrOldBk);
        }

    }
    if (hpenOld)
        ::SelectObject(hdc, hpenOld);
    AfGdi::SelectObjectBrush(hdc, hbrOld, AfGdi::OLD);
    AfGdi::DeleteObjectBrush(hbrBackground);

    // Draw focus rect
    if (state & ODS_FOCUS)
    {
        Rect rcT;
        rcT.Set(rc.left + 1, rc.top + 1, rc.right - 1, rc.bottom - 1);
        ::DrawFocusRect(hdc, &rcT);
    }

#endif JT_4_3_01_IMPLEMENTED
    return true;
}
Beispiel #20
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static HPALETTE hPalette ;
     static int      cxClient, cyClient ;
     HBRUSH          hBrush ;
     HDC             hdc ;
     int             i ;
     LOGPALETTE    * plp ;
     PAINTSTRUCT     ps ;
     RECT            rect ;
     
     switch (message)
     {
     case WM_CREATE:
               // Set up a LOGPALETTE structure and create a palette

          plp = malloc (sizeof (LOGPALETTE) + 64 * sizeof (PALETTEENTRY)) ;

          plp->palVersion    = 0x0300 ;
          plp->palNumEntries = 65 ;

          for (i = 0 ; i < 65 ; i++)
          {
               plp->palPalEntry[i].peRed   = (BYTE) min (255, 4 * i) ;
               plp->palPalEntry[i].peGreen = (BYTE) min (255, 4 * i) ;
               plp->palPalEntry[i].peBlue  = (BYTE) min (255, 4 * i) ;
               plp->palPalEntry[i].peFlags = 0 ;
          }
          hPalette = CreatePalette (plp) ;
          free (plp) ;
          return 0 ;

     case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;
          return 0 ;
          
     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;

               // Select and realize the palette in the device context

          SelectPalette (hdc, hPalette, FALSE) ;
          RealizePalette (hdc) ;

               // Draw the fountain of grays

          for (i = 0 ; i < 65 ; i++)
          {
               rect.left   = i * cxClient / 64 ;
               rect.top    = 0 ;
               rect.right  = (i + 1) * cxClient / 64 ;
               rect.bottom = cyClient ;

               hBrush = CreateSolidBrush (PALETTERGB (min (255, 4 * i), 
                                                      min (255, 4 * i), 
                                                      min (255, 4 * i))) ;
               FillRect (hdc, &rect, hBrush) ;
               DeleteObject (hBrush) ;
          }
          EndPaint (hwnd, &ps) ;
          return 0 ;

     case WM_QUERYNEWPALETTE:
          if (!hPalette)
               return FALSE ;

          hdc = GetDC (hwnd) ;
          SelectPalette (hdc, hPalette, FALSE) ;
          RealizePalette (hdc) ;
          InvalidateRect (hwnd, NULL, TRUE) ;

          ReleaseDC (hwnd, hdc) ;
          return TRUE ;

     case WM_PALETTECHANGED:
          if (!hPalette || (HWND) wParam == hwnd)
               break ;

          hdc = GetDC (hwnd) ;
          SelectPalette (hdc, hPalette, FALSE) ;
          RealizePalette (hdc) ;
          UpdateColors (hdc) ;

          ReleaseDC (hwnd, hdc) ;
          break ;

     case WM_DESTROY:
          DeleteObject (hPalette) ;
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Beispiel #21
0
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
   LPARAM LParam)
{
  const char* text = "Persistent Text";

   switch (Msg)
   {
      case WM_PAINT:
      {
         // determine the invalidated area of the window
         RECT RUpdate;
         HDC Hdc;
         GetUpdateRect(HWnd, &RUpdate, FALSE);

         // grab a handle to our window's
         // common display device context
         Hdc = GetDC(HWnd);
#if 0
         try
#endif
         {
            RECT RClient;
            GetClientRect(HWnd, &RClient);

            // set the clipping region
            IntersectClipRect(Hdc, RUpdate.left, RUpdate.top,
                              RUpdate.right, RUpdate.bottom);

            // fill the client area with the background brush
            /*HBRUSH HBrush =
               reinterpret_cast<HBRUSH>
                  (HBRUSH)(GetClassLong(HWnd, GCL_HBRBACKGROUND)
                  );*/
            FillRect(Hdc, &RClient, NULL);

            // render the persistent text
            SetTextColor(Hdc, PALETTERGB(0, 0, 255));
            DrawText(Hdc, text, strlen(text), &RClient,
                     DT_CENTER | DT_VCENTER | DT_SINGLELINE);
         }
#if 0
         catch (...)
#endif
         {
            // release the device context
            ReleaseDC(HWnd, Hdc);

            // validate the update area
            ValidateRect(HWnd, &RUpdate);
         }
         // release the device context
         ReleaseDC(HWnd, Hdc);

         // validate the update area
         ValidateRect(HWnd, &RUpdate);

         break;
      }
      case WM_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }
   return DefWindowProc(HWnd, Msg, WParam, LParam);
}
Beispiel #22
0
/******************************************************************************
 *		OleTranslateColor	[OLEAUT32.421]
 *
 * Convert an OLE_COLOR to a COLORREF.
 *
 * PARAMS
 *  clr       [I] Color to convert
 *  hpal      [I] Handle to a palette for the conversion
 *  pColorRef [O] Destination for converted color, or NULL to test if the conversion is ok
 *
 * RETURNS
 *  Success: S_OK. The conversion is ok, and pColorRef contains the converted color if non-NULL.
 *  Failure: E_INVALIDARG, if any argument is invalid.
 *
 * FIXME
 *  Document the conversion rules.
 */
HRESULT WINAPI OleTranslateColor(
  OLE_COLOR clr,
  HPALETTE  hpal,
  COLORREF* pColorRef)
{
  COLORREF colorref;
  BYTE b = HIBYTE(HIWORD(clr));

  TRACE("(%08x, %p, %p)\n", clr, hpal, pColorRef);

  /*
   * In case pColorRef is NULL, provide our own to simplify the code.
   */
  if (pColorRef == NULL)
    pColorRef = &colorref;

  switch (b)
  {
    case 0x00:
    {
      if (hpal != 0)
        *pColorRef =  PALETTERGB(GetRValue(clr),
                                 GetGValue(clr),
                                 GetBValue(clr));
      else
        *pColorRef = clr;

      break;
    }

    case 0x01:
    {
      if (hpal != 0)
      {
        PALETTEENTRY pe;
        /*
         * Validate the palette index.
         */
        if (GetPaletteEntries(hpal, LOWORD(clr), 1, &pe) == 0)
          return E_INVALIDARG;
      }

      *pColorRef = clr;

      break;
    }

    case 0x02:
      *pColorRef = clr;
      break;

    case 0x80:
    {
      int index = LOBYTE(LOWORD(clr));

      /*
       * Validate GetSysColor index.
       */
      if ((index < COLOR_SCROLLBAR) || (index > COLOR_MENUBAR))
        return E_INVALIDARG;

      *pColorRef =  GetSysColor(index);

      break;
    }

    default:
      return E_INVALIDARG;
  }

  return S_OK;
}
//*****************************************************************************************
void CBCGPColorMenuButton::OnDraw (CDC* pDC, const CRect& rect, CBCGPToolBarImages* pImages,
			BOOL bHorz, BOOL bCustomizeMode, BOOL bHighlight,
			BOOL bDrawBorder, BOOL bGrayDisabledButtons)
{
	ASSERT_VALID (this);
	ASSERT_VALID (pDC);

	CBCGPToolbarMenuButton::OnDraw (pDC, rect, pImages, bHorz, bCustomizeMode,
		bHighlight, bDrawBorder, bGrayDisabledButtons);

	if (!IsDrawImage () || pImages == NULL)
	{
		return;
	}

    CPalette* pOldPalette = NULL;
	if (globalData.m_nBitsPerPixel == 8) // 256 colors
	{
		if (m_Palette.GetSafeHandle () == NULL)
		{
			//----------------------------------------
			// Palette not created yet; create it now
			//----------------------------------------
			CBCGPColorBar::CreatePalette (m_Colors, m_Palette);
		}

		ASSERT (m_Palette.GetSafeHandle () != NULL);

		pOldPalette = pDC->SelectPalette (&m_Palette, FALSE);
		pDC->RealizePalette ();
	}
	else if (m_Palette.GetSafeHandle () != NULL)
	{
		::DeleteObject (m_Palette.Detach ());
		ASSERT (m_Palette.GetSafeHandle () == NULL);
	}

	ASSERT (pImages != NULL);
	CRect rectColor = pImages->GetLastImageRect ();
	const int nColorBoxSize = CBCGPToolBar::IsLargeIcons () && !m_bMenuMode ? 10 : 5;

	rectColor.top = rectColor.bottom - nColorBoxSize;
	rectColor.OffsetRect (0, 1);

	//----------------
	// Draw color bar:
	//----------------
	BOOL bDrawImageShadow = 
		bHighlight && !bCustomizeMode &&
		CBCGPVisualManager::GetInstance ()->IsShadowHighlightedImage () &&
		!globalData.IsHighContastMode () &&
		((m_nStyle & TBBS_PRESSED) == 0) &&
		((m_nStyle & TBBS_CHECKED) == 0) &&
		((m_nStyle & TBBS_DISABLED) == 0);

	if (bDrawImageShadow)
	{
		CBrush brShadow (globalData.clrBarShadow);
		pDC->FillRect (rectColor, &brShadow);
		rectColor.OffsetRect (-1, -1);
	}

	COLORREF color = (m_nStyle & TBBS_DISABLED) ?
		globalData.clrBarShadow :
			(m_Color == (COLORREF)-1 ? m_colorAutomatic : m_Color);

	CBrush br (PALETTERGB(	GetRValue (color),
							GetGValue (color), 
							GetBValue (color)));

	CBrush* pOldBrush = pDC->SelectObject (&br);
	CPen* pOldPen = (CPen*) pDC->SelectStockObject (NULL_PEN);
	
	pDC->Rectangle (&rectColor);

	pDC->SelectObject (pOldPen);
	pDC->SelectObject (pOldBrush);

	if (CBCGPVisualManager::GetInstance ()->IsMenuFlatLook ())
	{
		if (color == globalData.clrBarFace)
		{
			pDC->Draw3dRect (rectColor, globalData.clrBarDkShadow, globalData.clrBarDkShadow);
		}
	}
	else
	{
		pDC->Draw3dRect (rectColor, globalData.clrBarShadow, globalData.clrBarLight);
	}
	
    if (pOldPalette != NULL)
	{
        pDC->SelectPalette (pOldPalette, FALSE);
	}
}
Beispiel #24
0
// Meridian is a registered trademark.
/*
 * guildmem.c:  Property page for guild membership.
 */

#include "client.h"
#include "merintr.h"

extern HWND hGuildConfigDialog;
extern GuildConfigDialogStruct *guild_info;

// # of members at rank 2 (there can only be MAX_RANK4 of these at a time)
static int num_rank4 = 0;
#define MAX_RANK4 2

static COLORREF logged_on_color  = PALETTERGB(255, 0, 0);

static void GuildMemberCommand(HWND hDlg, int ctrl_id, HWND hwndCtl, UINT codeNotify);
static BOOL GuildListDrawItem(HWND hwnd, const DRAWITEMSTRUCT *lpdis);

/*****************************************************************************/
/*
 * GuildMemberDialogProc:  Dialog procedure for guild membership dialog.
 */
BOOL CALLBACK GuildMemberDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
    HWND hList;
    int i, index, flags;

    switch (message)
    {
Beispiel #25
0
int ColorModel::alloc_color(color& c)
{
#ifdef MAC_OSX_TK
     abort();
#else
	int r = c.r;
	int g = c.g;
	int b = c.b;

	if (gamma_ != 1.) {
		r = int(256. * pow(r / 256., gamma_));
		g = int(256. * pow(g / 256., gamma_));
		b = int(256. * pow(b / 256., gamma_));
	}
#ifndef WIN32
	if (r == g && r == b && (r & 7) == 0 && r > 0) {
		/*
		 * This color is one level away from the gray ramp
		 * used in nv, ghostscript, and the LBL-modified
		 * tk library.  Change it so we'll end up sharing
		 * the colormap entry.  The error won't be perceptible.
		 */
		 r -= 1;
		 g -= 1;
		 b -= 1;
	 }
#endif
	XColor xc;
	xc.red = r << 8;
	xc.green = g << 8;
	xc.blue = b << 8;
	if (XAllocColor(dpy_, colormap_, &xc) == 0) {
		free_colors();
		return (-1);
	}
#ifdef WIN32
	/*
	 * The current WinTk returns RGB values in the pixel. X returns
	 * a colormap index. So get the palette index and use that.
	 */
	TkWinColormap *cmap = (TkWinColormap *) colormap_;
	UINT index = GetNearestPaletteIndex(cmap->palette, PALETTERGB(r, g, b));
	int pixel = index;
	pixel_[index] = xc.pixel;
	color& p = colors_[ncolor_];
	if (++ncolor_ >= 256) {
		fprintf(stderr, "vic: colormap overflow (internal error)\n");
		exit(1);
	}

#if defined(WIN32) && (TCL_MAJOR_VERSION == 8) && (TCL_MINOR_VERSION == 0)
	if (!win32Colors)
		win32Colors = pixel_;
	win32NColors = ncolor_;
#endif

#else
	int pixel = xc.pixel;
	pixel_[ncolor_] = pixel;
	if (++ncolor_ >= 256) {
		fprintf(stderr, "vic: colormap overflow (internal error)\n");
		exit(1);
	}
	color& p = colors_[pixel];
#endif
	p.r = xc.red >> 8;
	p.g = xc.green >> 8;
	p.b = xc.blue >> 8;

	/* XXX ed ditherer needs this */
	rgb_to_yuv(p);

	return (pixel);
#endif // MAC_OSX_TK
}