Exemple #1
0
bool CImageMixer_EVR::SetBitmap(HBITMAP hbm,int Opacity,COLORREF TransColor,RECT *pDestRect)
{
	IMFGetService *pGetService;
	IMFVideoDisplayControl *pDisplayControl;
	IMFVideoMixerBitmap *pMixerBitmap;
	SIZE NativeSize;
	BITMAP bm;
	MFVideoAlphaBitmap ab;
	HRESULT hr;

	if (!CreateMemDC())
		return false;
	if (FAILED(m_pRenderer->QueryInterface(IID_IMFGetService,
									reinterpret_cast<LPVOID*>(&pGetService))))
		return false;
	if (FAILED(pGetService->GetService(MR_VIDEO_MIXER_SERVICE,
									   IID_IMFVideoMixerBitmap,
									   reinterpret_cast<LPVOID*>(&pMixerBitmap)))) {
		pGetService->Release();
		return false;
	}
	if (FAILED(pGetService->GetService(MR_VIDEO_RENDER_SERVICE,
							IID_IMFVideoDisplayControl,
							reinterpret_cast<LPVOID*>(&pDisplayControl)))) {
		pMixerBitmap->Release();
		pGetService->Release();
		return false;
	}
	hr=pDisplayControl->GetNativeVideoSize(&NativeSize,NULL);
	pDisplayControl->Release();
	if (FAILED(hr)) {
		pMixerBitmap->Release();
		pGetService->Release();
		return false;
	}
	::SelectObject(m_hdc,hbm);
	ab.GetBitmapFromDC=TRUE;
	ab.bitmap.hdc=m_hdc;
	ab.params.dwFlags=MFVideoAlphaBitmap_SrcRect | MFVideoAlphaBitmap_DestRect |
					  MFVideoAlphaBitmap_Alpha;
	if (TransColor!=CLR_INVALID) {
		ab.params.dwFlags|=MFVideoAlphaBitmap_SrcColorKey;
		ab.params.clrSrcKey=TransColor;
	}
	::GetObject(hbm,sizeof(BITMAP),&bm);
	::SetRect(&ab.params.rcSrc,0,0,bm.bmWidth,bm.bmHeight);
	ab.params.nrcDest.left=(float)pDestRect->left/(float)NativeSize.cx;
	ab.params.nrcDest.top=(float)pDestRect->top/(float)NativeSize.cy;
	ab.params.nrcDest.right=(float)pDestRect->right/(float)NativeSize.cx;
	ab.params.nrcDest.bottom=(float)pDestRect->bottom/(float)NativeSize.cy;
	ab.params.fAlpha=(float)Opacity/100.0f;
	hr=pMixerBitmap->SetAlphaBitmap(&ab);
	pMixerBitmap->Release();
	pGetService->Release();
	if (FAILED(hr)) {
		::SelectObject(m_hdc,m_hbmOld);
		return false;
	}
	return true;
}
Exemple #2
0
bool CImageMixer_VMR::SetText(LPCTSTR pszText,int x,int y,HFONT hfont,COLORREF Color,int Opacity)
{
	if (pszText==NULL || pszText[0]==_T('\0') || Opacity<1)
		return false;

	HDC hdc;
	HFONT hfontOld;
	RECT rc;
	HBITMAP hbm;
	COLORREF crTransColor,crOldTextColor,crOldBkColor;
	int OldBkMode;
	RECT rcDest;

	if (!CreateMemDC())
		return false;
	hdc=::CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
	hfontOld=static_cast<HFONT>(::SelectObject(hdc,hfont));
	::SetRectEmpty(&rc);
	::DrawText(hdc,pszText,-1,&rc,DT_LEFT | DT_TOP | DT_NOPREFIX | DT_CALCRECT);
	::OffsetRect(&rc,-rc.left,-rc.top);
	hbm=::CreateCompatibleBitmap(hdc,rc.right,rc.bottom);
	::SelectObject(hdc,hfontOld);
	::DeleteDC(hdc);
	if (hbm==NULL)
		return false;
	::SelectObject(m_hdc,hbm);
#if 0
	// これだとなぜかEVRで透過されない
	//crTransColor=Color^0x00FFFFFF;
#else
	if (GetRValue(Color)<8 && GetGValue(Color)<8 && GetBValue(Color)<8)
		Color=RGB(8,8,8);
	crTransColor=RGB(0,0,0);
#endif
	hfontOld=static_cast<HFONT>(::SelectObject(m_hdc,hfont));
	crOldTextColor=::SetTextColor(m_hdc,Color);
	crOldBkColor=::SetBkColor(m_hdc,crTransColor);
	OldBkMode=::SetBkMode(m_hdc,OPAQUE);
	::DrawText(m_hdc,pszText,-1,&rc,DT_LEFT | DT_TOP | DT_NOPREFIX);
	::SetBkMode(m_hdc,OldBkMode);
	::SetBkColor(m_hdc,crOldBkColor);
	::SetTextColor(m_hdc,crOldTextColor);
	::SelectObject(m_hdc,hfontOld);
	::SelectObject(m_hdc,m_hbmOld);
	rcDest.left=x;
	rcDest.top=y;
	rcDest.right=x+rc.right;
	rcDest.bottom=y+rc.bottom;
	if (!SetBitmap(hbm,Opacity,crTransColor,&rcDest)) {
		::DeleteObject(hbm);
		return false;
	}
	if (m_hbm!=NULL)
		::DeleteObject(m_hbm);
	m_hbm=hbm;
	return true;
}
Exemple #3
0
bool CImageMixer_VMR9::SetBitmap(HBITMAP hbm,int Opacity,COLORREF TransColor,RECT *pDestRect)
{
	IVMRMixerBitmap9 *pMixerBitmap;
	IVMRWindowlessControl9 *pWindowlessControl;
	LONG NativeWidth,NativeHeight;
	BITMAP bm;
	VMR9AlphaBitmap ab;
	HRESULT hr;

	if (!CreateMemDC())
		return false;
	if (FAILED(m_pRenderer->QueryInterface(IID_IVMRMixerBitmap9,
									reinterpret_cast<LPVOID*>(&pMixerBitmap))))
		return false;
	m_pRenderer->QueryInterface(IID_IVMRWindowlessControl9,
							reinterpret_cast<LPVOID*>(&pWindowlessControl));
	if (FAILED(pWindowlessControl->GetNativeVideoSize(&NativeWidth,&NativeHeight,
																	NULL,NULL))
			|| NativeWidth==0 || NativeHeight==0) {
		NativeWidth=1440;
		NativeHeight=1080;
	}
	pWindowlessControl->Release();
	::SelectObject(m_hdc,hbm);
	ab.dwFlags=VMR9AlphaBitmap_hDC;
	if (TransColor!=CLR_INVALID)
		ab.dwFlags|=VMR9AlphaBitmap_SrcColorKey;
	ab.hdc=m_hdc;
	ab.pDDS=NULL;
	::GetObject(hbm,sizeof(BITMAP),&bm);
	::SetRect(&ab.rSrc,0,0,bm.bmWidth,bm.bmHeight);
	ab.rDest.left=(float)pDestRect->left/(float)NativeWidth;
	ab.rDest.top=(float)pDestRect->top/(float)NativeHeight;
	ab.rDest.right=(float)pDestRect->right/(float)NativeWidth;
	ab.rDest.bottom=(float)pDestRect->bottom/(float)NativeHeight;
	ab.fAlpha=(float)Opacity/100.0f;
	ab.clrSrcKey=TransColor;
	hr=pMixerBitmap->SetAlphaBitmap(&ab);
	pMixerBitmap->Release();
	if (FAILED(hr)) {
		::SelectObject(m_hdc,m_hbmOld);
		return false;
	}
	return true;
}
Exemple #4
0
/////////////////////////////////////////////////////////////////////////////
// CRollupHeader message handlers
void CRollupHeader::OnPaint() 
{
	CPaintDC dc(this);
	CRect rClientRect;
	
	if(m_bInit)
	{
		GetClientRect(&rClientRect);
		CreateMemDC(&dc, &rClientRect);
//		m_MemDC.SelectObject(&m_cpBorderPen);
//		m_MemDC.SetTextColor(m_crTextColor);
//		m_MemDC.SetBkColor(m_crBackColor);
//		m_MemDC.SetBkMode(OPAQUE);

		m_rClientRect = rClientRect;
		m_rArrowRect = rClientRect;
		m_rArrowRect.right = m_rArrowRect.left + m_iHeight;
		m_rArrowRect.DeflateRect(2,2);
		m_cpArrowPoint.x = m_rArrowRect.left + 5;
		m_cpArrowPoint.y = m_rArrowRect.top + 5;
		m_rTextRect = rClientRect;
		m_rTextRect.DeflateRect(m_iHeight + 2, 2, 4+5, 2);	// space(s) between border and text

		m_bInit = FALSE;
	}

	CPen *pOldPen = m_MemDC.SelectObject(&m_cpBorderPen);
	COLORREF crOldTxtColor = m_MemDC.SetTextColor(m_crTextColor);
	COLORREF crOldBckColor = m_MemDC.SetBkColor(m_crBackColor);
	int iOldBkMode = m_MemDC.SetBkMode(OPAQUE);

	m_MemDC.FillSolidRect(m_rClientRect, m_crBackColor);
	m_MemDC.MoveTo(m_rClientRect.left, m_rClientRect.top);
	m_MemDC.LineTo(m_rClientRect.right, m_rClientRect.top);

#ifndef NEW_LOOK
	m_MemDC.MoveTo(m_rClientRect.left, m_rClientRect.bottom-1);
	m_MemDC.LineTo(m_rClientRect.right, m_rClientRect.bottom-1);

	m_MemDC.MoveTo(m_rClientRect.left, m_rClientRect.top);
	m_MemDC.LineTo(m_rClientRect.left, m_rClientRect.bottom);

	m_MemDC.MoveTo(m_rClientRect.right-1, m_rClientRect.top);
	m_MemDC.LineTo(m_rClientRect.right-1, m_rClientRect.bottom);
#endif NEW_LOOK

	CPoint cpArrowPt(m_cpArrowPoint);
	if(m_bExpanded)
		cpArrowPt.y+=3;
	else
		cpArrowPt.x++;
	
	DrawArrow(&m_MemDC, &cpArrowPt, m_bExpanded);
	
	CFont *pOldFont = m_MemDC.SelectObject(&m_cfTextFont);
	m_MemDC.DrawText(m_strRightText, m_rTextRect,
		DT_RIGHT | DT_NOPREFIX | DT_NOCLIP | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);
	m_MemDC.DrawText(m_strLeftText, m_rTextRect,
		DT_LEFT | DT_NOPREFIX | DT_NOCLIP | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS);

	dc.BitBlt(m_rClientRect.left, m_rClientRect.top, m_rClientRect.Width(), m_rClientRect.Height(),
				&m_MemDC, 0, 0, SRCCOPY);

	m_MemDC.SelectObject(pOldFont);
	m_MemDC.SetBkMode(iOldBkMode);
	m_MemDC.SetBkColor(crOldBckColor);
	m_MemDC.SetTextColor(crOldTxtColor);
	m_MemDC.SelectObject(pOldPen);
}
static int PlatformProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {
        case MSG_CREATE:
            {
                if (!hmWnd)
                    hmWnd = hWnd;

                unsigned char* pdr = 0;
                int w,h,p;
                RECT r;
                key_down = FALSE;
                GetClientRect(hWnd, &r);
#if RGB555
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0x7C00, 0x3E0, 0x1F, 0x8000);    
#else
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0xF800, 0x7E0, 0x1F, 0x00);    
#endif
                pdr = LockDC(sdc, &r, &w, &h, &p);
                UnlockDC(sdc);
#if RGB555
                fmt = COLOR_FORMAT_RGB555;
#else
                fmt = COLOR_FORMAT_RGB565;
#endif
                ps_initialize();

                canvas = ps_canvas_create_with_data(pdr, fmt, w, h, p);
                context = ps_context_create(canvas, 0);
                on_init(context, width, height);    
            }
            break;
        case MSG_TIMER:
            on_timer();
            break;
        case MSG_PAINT:
            {
                HDC hdc = BeginPaint(hWnd);
                on_draw(context);
                BitBlt(sdc, 0, 0, width, height, hdc, 0, 0, 0);
                EndPaint(hWnd, hdc);
            }
            return 0;
        case MSG_ERASEBKGND:
            return 0;
        case MSG_LBUTTONDOWN:
            {
                key_down = TRUE;
                on_mouse_event(LEFT_BUTTON_DOWN, key_conv(wParam), LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_LBUTTONUP:
            {
                key_down = FALSE;
                on_mouse_event(LEFT_BUTTON_UP, key_conv(wParam), LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_MOUSEMOVE:
            {
                DWORD k = key_conv(wParam);
                if (key_down)
                    k |= EVT_LBUTTON;
                on_mouse_event(MOUSE_MOVE, k, LOSWORD(lParam), HISWORD(lParam));
            }
            break;
        case MSG_KEYDOWN:
            on_key_event(KEY_EVENT_DOWN, get_virtual_key(wParam));
            break;
        case MSG_KEYUP:
            on_key_event(KEY_EVENT_UP, get_virtual_key(wParam));
            break;
        case MSG_SIZECHANGED:
            {
                RECT r;
                int w,h,p;
                unsigned char* pdr = 0;
                ps_canvas* old_canvas = 0;
                RECT* rc = (RECT*)lParam;
                width = RECTWP(rc);
                height = RECTHP(rc);
                if (sdc)
                    DeleteMemDC(sdc);

                if (width < 1)
                    width = 1;
                if (height < 1)
                    height = 1;
#if RGB555
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0x7C00, 0x3E0, 0x1F, 0x8000);    
#else
            sdc = CreateMemDC(width, height, 16, MEMDC_FLAG_SWSURFACE, 0xF800, 0x7E0, 0x1F, 0x00);    
#endif
                GetClientRect(hWnd, &r);
                pdr = LockDC(sdc, &r, &w, &h, &p);
                UnlockDC(sdc);
                canvas = ps_canvas_create_with_data(pdr, fmt, w, h, p);
                old_canvas = ps_context_set_canvas(context, canvas);
                ps_canvas_unref(old_canvas);
                on_size(width, height);
            }
            break;
        case MSG_CLOSE:
            on_term(context);
            ps_context_unref(context);
            ps_canvas_unref(canvas);
            ps_shutdown();
            DeleteMemDC(sdc);
            DestroyMainWindow (hWnd);
            PostQuitMessage (hWnd);
            return 0;
    }
    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
    //------------------------------------------------------------------------
    bool platform_support::init(unsigned width, unsigned height, unsigned flags)
    {
        m_window_flags = flags;
        unsigned wflags = MEMDC_FLAG_SWSURFACE;

        if(m_window_flags & window_hw_buffer)
        {
            wflags = MEMDC_FLAG_HWSURFACE;
        }
/*
        if(m_window_flags & window_resize)
        {
            wflags |= GAL_RESIZABLE;
        }
*/
        //SDL_WM_SetCaption(m_caption, 0);

        if(m_specific->m_surf_window) 
            DeleteMemDC(m_specific->m_surf_window);
        
#if 0
        printf("init memdc: w=%d, h=%d, m_bpp=%d, wflags=%d\n", width, height, m_bpp, wflags);
        printf("init memdc: m_rmask=%x, m_gmask=%x, m_bmask=%x, m_amask=%x\n", 
                    m_specific->m_rmask,
                    m_specific->m_gmask,
                    m_specific->m_bmask,
                    m_specific->m_amask);
#endif
        m_specific->m_surf_window = CreateMemDC( 
                                 width, 
                                 height,
                                 m_bpp,
                                 wflags,
                                 m_specific->m_rmask, 
                                 m_specific->m_gmask, 
                                 m_specific->m_bmask, 
                                 m_specific->m_amask);

        if(m_specific->m_surf_window == 0) 
        {
            fprintf(stderr, 
                    "Unable to create image buffer %dx%d %d bpp: %s\n", 
                    width, 
                    height, 
                    m_bpp, 
                    //SDL_GetError());
                    "failed");
            return false;
        }
        int pitch = width * (m_bpp/8);
        //printf("init, pitch=%d\n", pitch);    
#if 0
        m_rbuf_window.attach((unsigned char*)PIXEL(SURFACE(m_specific->m_surf_window)), 
                             width, 
                             height, 
                             m_flip_y ? -pitch:pitch);
#else

        m_rbuf_window.attach((unsigned char*)LockDC(m_specific->m_surf_window, NULL, NULL, NULL, NULL), 
                             width, 
                             height, 
                             m_flip_y ? -pitch:pitch);
#endif
        if(!m_specific->m_initialized)
        {
            m_initial_width = width;
            m_initial_height = height;
            on_init();
            m_specific->m_initialized = true;
        }
        on_resize(m_rbuf_window.width(), m_rbuf_window.height());
        m_specific->m_update_flag = true;
        return true;
    }