Exemple #1
0
void CRTitleCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	// TODO: Replace the following code with your own drawing code.
	pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
    CRect rc = rcBounds;
    CFont* pOldFont;
    TEXTMETRIC tm;
    const CString& strCaption = InternalGetText();

    // Set the ForeColor property color and transparent background mode into the device context
    pdc->SetTextColor(TranslateColor(GetForeColor()));
    pdc->SetBkMode(TRANSPARENT);

    // Draw the caption using the stock Font and ForeColor properties
    pOldFont = SelectStockFont(pdc);
    pdc->GetTextMetrics(&tm);
    pdc->SetTextAlign(TA_CENTER | TA_TOP);
    pdc->ExtTextOut((rc.left + rc.right) / 2, 0,
		ETO_CLIPPED, rc, strCaption, strCaption.GetLength(), NULL);
    pdc->SelectObject(pOldFont);
}
Exemple #2
0
//*****************************************************************************
void CHTMLWidget::UpdateHTMLSurface()
//Updates the HTML surface.
{
	if (this->pHTMLSurface)
		SDL_FreeSurface(this->pHTMLSurface);

	//Create surface to fit the parsed HTML page.
	this->pHTMLSurface = CBitmapManager::ConvertSurface(SDL_CreateRGBSurface(
			SDL_SWSURFACE, this->w, this->wY, g_pTheBM->BITS_PER_PIXEL, 0, 0, 0, 0));
	if (this->pHTMLSurface)
	{
		//Set surface BG color to designated page color.
		const Uint32 wBGColor = TranslateColor(this->pHTMLSurface, this->wstrBGColor);
		SDL_FillRect(this->pHTMLSurface, NULL, wBGColor);

		//Draw children on the correct spot on the HTML surface.
		SDL_Surface *pDestSurface = GetDestSurface();
		SetDestSurface(this->pHTMLSurface);
		Scroll(-this->x, -this->y);
		PaintChildren();
		Scroll(this->x, this->y);
		SetDestSurface(pDestSurface);

		//Prepare for paint
		this->wHeightDrawn = (UINT)this->pHTMLSurface->h;
		this->bNeedRepaint = false;
	}
	else
	{
		//Couldn't create surface; report error and use slow rendering mode
		char errorStr[256];
		_snprintf(errorStr, 256,
				"Error creating HTML surface: %s",
				SDL_GetError());
		CFiles Files;
		Files.AppendErrorLog((char *)errorStr);
	}
}
Exemple #3
0
void CRTabsCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	if (m_bInit)
	{
		m_TabUpDC.CreateCompatibleDC(pdc);
		m_TabDownDC.CreateCompatibleDC(pdc);
		m_TabUp.LoadBitmap(IDB_TABUP);
		m_TabDown.LoadBitmap(IDB_TABDOWN);	
		m_TabUpDC.SelectObject(m_TabUp);
		m_TabDownDC.SelectObject(m_TabDown);
		BITMAP bitmap;
		m_TabUp.GetBitmap(&bitmap);
		m_TabUpWidth=bitmap.bmWidth;
		m_TabUpHeight=bitmap.bmHeight;
		m_TabDown.GetBitmap(&bitmap);
		m_TabDownWidth=bitmap.bmWidth;
		m_TabDownHeight=bitmap.bmHeight;
		m_bInit=FALSE;		   
	}
	int count=m_textList.GetCount();
	if (count==0) return;
//	*(char*)0=0;
	// TODO: Replace the following code with your own drawing code.
	CDC offscreenDC;
	VERIFY(offscreenDC.CreateCompatibleDC(pdc));
	CBitmap bitmap;
	CBitmap* pOldBitmap;
	VERIFY(bitmap.CreateCompatibleBitmap(pdc,rcBounds.Width(),rcBounds.Height()));
	pOldBitmap=offscreenDC.SelectObject(&bitmap);
//	offscreenDC.FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(BLACK_BRUSH)));
	// pre calculate the tab positions
	POSITION position = m_textList.GetHeadPosition();
	CRect rect;
	this->GetParent()->GetClientRect(rect);
	m_rectList.RemoveAll();
	m_tabList.RemoveAll();
	char* text;
    offscreenDC.SetTextAlign(TA_LEFT | TA_TOP);
    offscreenDC.SetBkMode(TRANSPARENT);
    offscreenDC.SetTextColor(TranslateColor(GetForeColor()));
    CFont* pOldFont;
	if (m_hWnd) pOldFont = offscreenDC.SelectObject((CFont*)this->GetParent()->SendMessage(WM_GETGLOBALFONT,m_FontNum,NULL));
	else pOldFont = offscreenDC.GetCurrentFont();
	int width;
	int start=0;
	if (m_bHorzAlign)
	{
		int finish;
		float seperation;
		int total=0;
		int laststart;
		int lastfinish;
		float lastseperation;
		BOOL lastrow=FALSE;
		BOOL notreallylastrow=FALSE;
		int row=0;
		for (int x=0;x<count;x++)
		{
			if (x==m_iCurrentSelection) lastrow=TRUE;
			text=m_textList.GetNext(position);
			width=offscreenDC.GetTextExtent(text).cx+15; // 15 is minimum seperation between text
			total+=width;
			if (total>rect.Width() || x==count-1)
			{
				// decide whether to put this tab on the next row...
				// doesnt happen if it is the only tab on the row
				if (x>start && total>rect.Width()) //|| (x-start)<3))
				{
//					finish=x-1;
//					total-=width;
					if (x==m_iCurrentSelection) notreallylastrow=TRUE;
					x--;
					if (position==NULL) position=m_textList.GetTailPosition();
					else m_textList.GetPrev(position);
					total-=width;
				}
//				else finish=x;
				finish=x;
				seperation=(float)(rect.Width()-total+(15*(finish-start+1)))/(float)(finish-start+1);
				if (lastrow==FALSE || notreallylastrow==TRUE)
					{
					DrawRow(seperation,start,finish,&offscreenDC,row,rect.Width(),FALSE);
					notreallylastrow=FALSE;
					}
				else
				{
					laststart=start;
					lastfinish=finish;
					lastseperation=seperation;
					lastrow=FALSE;
					row--;
				}
				total=0;
				start=x+1;
				row++;
			}
		}
		DrawRow(lastseperation,laststart,lastfinish,&offscreenDC,row,rect.Width(),TRUE);
	}
	else
	{
		// Draw vertical tabs.
		long widest;
		widest=CalcWidestWord();
		CRect rect2;
		this->GetClientRect(rect2);
//		widest=rect2.Width();
//		TRACE1("Measured Width: %d\n",widest);
		int y=0;
		char word[30];
		int startpos;
		BOOL NewTab;
		int oldy;
		int starty;
		for (int z=0;z<count;z++)
		{
			NewTab=TRUE;
			text=m_textList.GetNext(position);
			// split into component words
			start=0;
			startpos=2;
			starty=y;
			for (int x=0;x<(int)strlen(text)+1;x++) // includes terminating null character
			{
				if (text[x]==' ' || text[x]==NULL)
				{
					strncpy(word,text+start,min(x-start+1,30));
					word[min(x-start+1,30)]=NULL;
					start=x+1;
					width=offscreenDC.GetTextExtent(word).cx;
					if (NewTab)
					{
						if (z==m_iCurrentSelection)
						{
							DrawIconEx(offscreenDC.m_hDC,widest-400,y+2,m_hHighTabIcon,400,30,NULL,NULL,DI_NORMAL);
							offscreenDC.MoveTo(0,y);
							offscreenDC.LineTo(widest-15,y);
							offscreenDC.MoveTo(0,y+1);
							offscreenDC.LineTo(widest-10,y+1);
						}
						else DrawIconEx(offscreenDC.m_hDC,widest-402,y+2,m_hLowTabIcon,400,30,NULL,NULL,DI_NORMAL);
					}
					else
					{
						if (width+startpos>widest-15)
						{
							// Draw it at start of next line
							y+=30;
							startpos=2;
						}
						if (y!=oldy)
						{
							if (z==m_iCurrentSelection) DrawIconEx(offscreenDC.m_hDC,widest-400,y+2,m_hHighContinueIcon,400,30,NULL,NULL,DI_NORMAL);
							else DrawIconEx(offscreenDC.m_hDC,widest-402,y+2,m_hLowContinueIcon,400,30,NULL,NULL,DI_NORMAL);
						}
					}
					oldy=y; // oldy indicates that the background tab icon has been drawn for this line
					if (z==m_iCurrentSelection)
					{
						offscreenDC.ExtTextOut(startpos+2,y,ETO_CLIPPED,CRect(0,y,widest-15,y+30),word,NULL);
						if (width+startpos+2>widest-15) offscreenDC.TextOut(widest-12,y,"...");
					}
					else
					{
						offscreenDC.ExtTextOut(startpos,y+2,ETO_CLIPPED,CRect(0,y+2,widest-15,y+22),word,NULL);
						if (width+startpos>widest-15) offscreenDC.TextOut(widest-14,y+2,"...");
						offscreenDC.MoveTo(0,y+2);
						offscreenDC.LineTo(0,y+22);
						offscreenDC.MoveTo(1,y+2);
						offscreenDC.LineTo(1,y+22);
					}
					NewTab=FALSE;
					startpos+=width;
				}
			}
			y+=30;
			if (z<count-1) m_rectList.AddTail(CRect(0,starty,widest,y));
			else m_rectList.AddTail(CRect(0,starty,widest,INT_MAX));
			m_tabList.AddTail(z);
			if (z==count-1) // if at end fill remaining area with blank tab
			{
				while (y<rect2.Height())
				{
					if (z==m_iCurrentSelection) DrawIconEx(offscreenDC.m_hDC,widest-400,y+2,m_hHighContinueIcon,400,30,NULL,NULL,DI_NORMAL);
					else DrawIconEx(offscreenDC.m_hDC,widest-402,y+2,m_hLowContinueIcon,400,30,NULL,NULL,DI_NORMAL);
					y+=30;
				}
			}
		}
	}
	VERIFY(pdc->BitBlt(0,0,rcBounds.right-rcBounds.left,rcBounds.bottom-rcBounds.top,&offscreenDC,
					0,0,SRCCOPY)); // flips offscreen dc to real dc
	// select out any objects that were selected in
	offscreenDC.SelectObject(pOldFont);
    offscreenDC.SelectObject(pOldBitmap);
	// then delete the dc
	offscreenDC.DeleteDC();
}
void CLREnvelopeEditorCtrl::OnDraw(
			CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
	//build memory device context to draw to
	CDC			DrawDC;
	CDC*		pDrawDC=&DrawDC;
	CBitmap		MemoryBitmap;
	CBitmap*	pMemoryBitmap=&MemoryBitmap;
	CBitmap*	pOldBitmap;

	pDrawDC->CreateCompatibleDC(pdc);
	pMemoryBitmap->CreateCompatibleBitmap(pdc,rcBounds.right,rcBounds.bottom);
	pOldBitmap=pDrawDC->SelectObject(pMemoryBitmap);
	//refresh m_RCCtrlArea with valid one
	m_RCCtrlArea=rcBounds;
	m_RCCtrlArea.bottom-=CONTROL_BAR_HEIGHT;
	//clear background
	CBrush	brBackground(TranslateColor(AmbientBackColor()));
	pDrawDC->FillRect(m_RCCtrlArea, &brBackground);
	//draw selected area if present
	if(m_bHasSelection) {
		CBrush		brSelection;
		COLORREF	selection_color=TranslateColor(AmbientBackColor());
		BYTE		r_color,g_color,b_color;
		r_color=GetRValue(selection_color);
		g_color=GetGValue(selection_color);
		b_color=GetBValue(selection_color);
		int sum3=((int)r_color+(int)g_color+(int)b_color)/3;
		if(sum3>30) {
			if(r_color>30) r_color-=30;
			else r_color=0;
			if(g_color>30) g_color-=30;
			else g_color=0;
			if(b_color>30) b_color-=30;
			else b_color=0;
		}
		else {
			if(r_color<225) r_color+=30;
			else r_color=255;
			if(g_color<225) g_color+=30;
			else g_color=255;
			if(b_color<225) b_color+=30;
			else b_color=255;
		}
		selection_color=RGB(r_color,g_color,b_color);
		brSelection.CreateSolidBrush(selection_color);
		CRect selection_rect;
		selection_rect.top=0;
		selection_rect.bottom=m_RCCtrlArea.bottom;
		selection_rect.left=translateEnvelopeXToScreenX(m_lFirstSelectedPosition);
		selection_rect.right=translateEnvelopeXToScreenX(m_lLastSelectedPosition);
		pDrawDC->FillRect(&selection_rect,&brSelection);
	}
	//draw X and Y axes
	CPen	axis_pen;
	axis_pen.CreatePen(PS_SOLID,2,RGB(0,0,0));
	CPen*	old_pen;
	old_pen=pDrawDC->SelectObject(&axis_pen);
	//X
	pDrawDC->MoveTo(0,translateEnvelopeYToScreenY(0.0f));
	pDrawDC->LineTo(m_RCCtrlArea.right,translateEnvelopeYToScreenY(0.0f));
	//Y
	pDrawDC->MoveTo(translateEnvelopeXToScreenX(0),0);
	pDrawDC->LineTo(translateEnvelopeXToScreenX(0),m_RCCtrlArea.bottom);
	//draw grid
	CPen	grid_pen;
	grid_pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
	pDrawDC->SelectObject(&grid_pen);
	//draw control border
	pDrawDC->MoveTo(0,0);
	pDrawDC->LineTo(m_RCCtrlArea.right-1,0);
	pDrawDC->LineTo(m_RCCtrlArea.right-1,m_RCCtrlArea.bottom-1);
	pDrawDC->LineTo(0,m_RCCtrlArea.bottom-1);
	pDrawDC->LineTo(0,0);

	//here grid drawing starts
	long	x_step=calcEnvelopeXStep();
	float	y_step=calcEnvelopeYStep();
	long	x_pos;
	float	y_pos;
	//y
	x_pos=(m_lFirstKeyPosition/x_step+1)*x_step;
	while(x_pos<m_lLastKeyPosition) {
		pDrawDC->MoveTo(translateEnvelopeXToScreenX(x_pos),0);
		pDrawDC->LineTo(translateEnvelopeXToScreenX(x_pos),m_RCCtrlArea.bottom);
		x_pos+=x_step;
	}
	//x
	y_pos=((float)floor(m_fLowValue/y_step)+1.0f)*y_step;
	while(y_pos<m_fHighValue) {
		pDrawDC->MoveTo(0,translateEnvelopeYToScreenY(y_pos));
		pDrawDC->LineTo(m_RCCtrlArea.right,translateEnvelopeYToScreenY(y_pos));
		y_pos+=y_step;
	}

	//draw curve
	CPen	cpEnvelope;
	cpEnvelope.CreatePen(PS_SOLID,2,m_CurveColor);
	pDrawDC->SelectObject(&cpEnvelope);
	x_pos=0;	//beware that now it is screen, not envelope coordinate
	float fEvalRes=m_pEnvelope->evalEnvelope(translateScreenXToSeconds(x_pos));
	pDrawDC->MoveTo(x_pos,translateEnvelopeYToScreenY(fEvalRes));
	while(x_pos<m_RCCtrlArea.right) {
		fEvalRes=m_pEnvelope->evalEnvelope(translateScreenXToSeconds(x_pos));
		pDrawDC->LineTo(x_pos,translateEnvelopeYToScreenY(fEvalRes));
		x_pos++;
	}
	//draw keys
	if(!(m_bDirtyPositions ||
		m_bDirtyValues)) {
		long i;
		long lNumKeys=m_pEnvelope->getNumKeys();
		for(i=0;i<lNumKeys;i++) {
			drawKey(i,pDrawDC);
		}
	}

	//draw bottom bar
	CBrush		white_brush;
	white_brush.CreateSolidBrush(RGB(255,255,255));
	CRect	rcBottom=rcBounds;
	rcBottom.top=rcBounds.bottom-CONTROL_BAR_HEIGHT;
	pDrawDC->FillRect(rcBottom,&white_brush);
	pDrawDC->SelectObject(&grid_pen);

	//draw bottom bar border
	pDrawDC->MoveTo(0,rcBottom.top);
	pDrawDC->LineTo(rcBottom.right-1,rcBottom.top);
	pDrawDC->LineTo(rcBottom.right-1,rcBottom.bottom-1);
	pDrawDC->LineTo(0,rcBottom.bottom-1);
	pDrawDC->LineTo(0,rcBottom.top);

	//draw vertical lines and frame numbers every 10 x_steps in bottom bar
	CFont	cfFrameFont;
	CString	csFrameString;
	cfFrameFont.CreateFont(8,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,OUT_DEVICE_PRECIS,
		CLIP_DEFAULT_PRECIS,PROOF_QUALITY,FIXED_PITCH,NULL);
	pDrawDC->SelectObject(&cfFrameFont);
	pDrawDC->SetBkMode(TRANSPARENT);
	x_pos=m_lFirstKeyPosition-m_lFirstKeyPosition%(10*x_step)-10*x_step;
	while(x_pos<m_lLastKeyPosition) {
		if((x_pos%(10*x_step))==0) {
			pDrawDC->MoveTo(translateEnvelopeXToScreenX(x_pos),rcBottom.top);
			pDrawDC->LineTo(translateEnvelopeXToScreenX(x_pos),rcBottom.bottom);
			csFrameString.Format("%d",x_pos);
			pDrawDC->TextOut(translateEnvelopeXToScreenX(x_pos),
				rcBottom.top,csFrameString);
		}
		x_pos+=x_step;
	}
	pDrawDC->SelectObject(old_pen);

	pdc->BitBlt(0,0,rcBounds.right,rcBounds.bottom,pDrawDC,0,0,SRCCOPY);
	
	pDrawDC->SelectObject(pOldBitmap);
	pDrawDC->DeleteDC();
}
Exemple #5
0
bool CAnimationSpooler::PrepareJob_Flat(CAnimJobUI* pJob)
{
   // Determine actual colorkey
   pJob->data.plot.clrKey = TranslateColor(m_p3DBackSurface, pJob->data.plot.clrKey);
   // Prepare surfaces
   HRESULT Hr;
   RECT rc = pJob->data.plot.rcFrom;
   int cx = rc.right - rc.left;
   int cy = rc.bottom - rc.left;
   FLOAT z = 0.1f;
   FLOAT rhw = 1.0f / (z * 990.0f + 10.0f);
   D3DCOLOR col = 0xffffffff;
   // Determine texture size
   int iTexSize = 128;
   if( cx < 64 ) iTexSize = 64;
   if( cx < 32 ) iTexSize = 32;
   FLOAT fTexSize = (FLOAT) iTexSize;
   // Start building tiles
   pJob->iBufferStart = m_nBuffers;
   for( int x = rc.left; x < rc.right; x += iTexSize ) {
      for( int y = rc.top; y < rc.bottom; y += iTexSize ) {
         RECT rcTile = { x, y, MIN(rc.right, x + iTexSize), MIN(rc.bottom, y + iTexSize) };
         // Adjust texture coordinates, because last tile may only use parts
         // of the texture...
         FLOAT tcoordx = (iTexSize - (x + fTexSize - rc.right)) / fTexSize;
         FLOAT tcoordy = (iTexSize - (y + fTexSize - rc.bottom)) / fTexSize;
         if( tcoordx > 1.0f ) tcoordx = 1.0f;
         if( tcoordy > 1.0f ) tcoordy = 1.0f;
         // Create the vertex buffer
         CUSTOMFAN verts = 
         {
            { rcTile.left - 0.5f,  rcTile.top - 0.5f,    z, rhw, col, 0.0f, 0.0f },
            { rcTile.right - 0.5f, rcTile.top - 0.5f,    z, rhw, col, tcoordx, 0.0f },
            { rcTile.right - 0.5f, rcTile.bottom - 0.5f, z, rhw, col, tcoordx, tcoordy },
            { rcTile.left - 0.5f,  rcTile.bottom - 0.5f, z, rhw, col, 0.0f, tcoordy }
         };
         LPDIRECT3DVERTEXBUFFER9 pVertex = NULL;
         Hr = m_p3DDevice->CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &pVertex, NULL);
         if( FAILED(Hr) ) return false;
         CSafeRelease<IDirect3DVertexBuffer9> RefVertex = pVertex;
         memcpy(m_fans[m_nBuffers], verts, sizeof(verts));

         LPDIRECT3DTEXTURE9 pTex1 = NULL;
         Hr = m_p3DDevice->CreateTexture(iTexSize, iTexSize, 1, 0, m_ColorFormat, D3DPOOL_DEFAULT, &pTex1, NULL);
         if( FAILED(Hr) ) return false;
         CSafeRelease<IDirect3DTexture9> RefTex1 = pTex1;
         LPDIRECT3DSURFACE9 pTexSurf1 = NULL;
         Hr = pTex1->GetSurfaceLevel(0, &pTexSurf1);
         if( FAILED(Hr) ) return false;
         CSafeRelease<IDirect3DSurface9> RefTexSurf1 = pTexSurf1;
         POINT pt = { 0, 0 };         
         Hr = m_p3DDevice->UpdateSurface(m_p3DBackSurface, &rcTile, pTexSurf1, &pt);
         if( FAILED(Hr) ) return false;
         LPDIRECT3DTEXTURE9 pTex2 = NULL;
         RECT rcDest = { 0, 0, rcTile.right - rcTile.left, rcTile.bottom - rcTile.top };
         Hr = m_p3DDevice->CreateTexture(iTexSize, iTexSize, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pTex2, NULL);
         if( FAILED(Hr) ) return false;
         CSafeRelease<IDirect3DTexture9> RefTex2 = pTex2;
         LPDIRECT3DSURFACE9 pTexSurf2 = NULL;
         Hr = pTex2->GetSurfaceLevel(0, &pTexSurf2);
         if( FAILED(Hr) ) return false;
         CSafeRelease<IDirect3DSurface9> RefTexSurf2 = pTexSurf2;
         Hr = m_p3DDevice->StretchRect(pTexSurf1, &rcDest, pTexSurf2, &rcDest, D3DTEXF_NONE);
         if( FAILED(Hr) ) return false;
         // Replace colorkey pixels with alpha
         SetColorKey(pTex2, pTexSurf2, iTexSize, pJob->data.plot.clrKey);
         // Finally, assign the texture
         m_p3DTextures[m_nBuffers] = RefTex2.Detach();
         m_p3DVertices[m_nBuffers] = RefVertex.Detach();
         m_nBuffers++;
      }
   }
   pJob->iBufferEnd = m_nBuffers;
   ASSERT(m_nBuffers<MAX_BUFFERS);
   // Clear the background so the sprite can take its place
   COLORREF clrBack = pJob->data.plot.clrBack;
   if( clrBack != CLR_INVALID) {
      HDC hDC = NULL;
      Hr = m_p3DBackSurface->GetDC(&hDC);
      if( FAILED(Hr) ) return false;
      HBRUSH hBrush = ::CreateSolidBrush(clrBack);
      ::FillRect(hDC, &rc, hBrush);
      ::DeleteObject(hBrush);
      m_p3DBackSurface->ReleaseDC(hDC);
   }
   return true;
}