bool D3D10System::GetTextureFileInfo(CTSTR lpFile, TextureInfo &info) { D3DX10_IMAGE_INFO ii; if(SUCCEEDED(D3DX10GetImageInfoFromFile(lpFile, NULL, &ii, NULL))) { info.width = ii.Width; info.height = ii.Height; switch(ii.Format) { case DXGI_FORMAT_A8_UNORM: info.type = GS_ALPHA; break; case DXGI_FORMAT_R8_UNORM: info.type = GS_GRAYSCALE; break; case DXGI_FORMAT_B8G8R8X8_UNORM: info.type = GS_BGR; break; case DXGI_FORMAT_B8G8R8A8_UNORM: info.type = GS_BGRA; break; case DXGI_FORMAT_R8G8B8A8_UNORM: info.type = GS_RGBA; break; case DXGI_FORMAT_R16G16B16A16_FLOAT: info.type = GS_RGBA16F; break; case DXGI_FORMAT_R32G32B32A32_FLOAT: info.type = GS_RGBA32F; break; case DXGI_FORMAT_BC1_UNORM: info.type = GS_DXT1; break; case DXGI_FORMAT_BC2_UNORM: info.type = GS_DXT3; break; case DXGI_FORMAT_BC3_UNORM: info.type = GS_DXT5; break; default: info.type = GS_UNKNOWNFORMAT; } return true; } return false; }
bool STDCALL ConfigureBitmapSource(XElement *element, bool bCreating) { if(!element) { AppWarning(TEXT("ConfigureBitmapSource: NULL element")); return false; } XElement *data = element->GetElement(TEXT("data")); if(!data) data = element->CreateElement(TEXT("data")); ConfigBitmapInfo configInfo; configInfo.data = data; if(DialogBoxParam(hinstMain, MAKEINTRESOURCE(IDD_CONFIGUREBITMAPSOURCE), hwndMain, ConfigureBitmapProc, (LPARAM)&configInfo) == IDOK) { CTSTR lpBitmap = data->GetString(TEXT("path")); D3DX10_IMAGE_INFO ii; if(SUCCEEDED(D3DX10GetImageInfoFromFile(lpBitmap, NULL, &ii, NULL))) { element->SetInt(TEXT("cx"), ii.Width); element->SetInt(TEXT("cy"), ii.Height); } else AppWarning(TEXT("ConfigureBitmapSource: could not get image info for bitmap '%s'"), lpBitmap); return true; } return false; }
bool STDCALL ConfigureCloudSource(XElement *element, bool bCreating) { if (!element) { AppWarning(TEXT("ConfigureIVASource: NULL element")); return false; } XElement *data = element->GetElement(TEXT("data")); if (!data) data = element->CreateElement(TEXT("data")); ConfigIVAInfo configInfo; configInfo.data = data; if (OBSDialogBox(hinstMain, MAKEINTRESOURCE(IDD_IVACLOUD), API->GetMainWindow(), IVACloudProc, (LPARAM)&configInfo) == IDOK) { int nIndex = data->GetInt(TEXT("SelIndex")); std::string strPath = g_pCloudData->m_vIPicDesc[nIndex].strFileName; std::wstring wstrPath; StringToWString(strPath, wstrPath); CTSTR lpBitmap = wstrPath.c_str(); D3DX10_IMAGE_INFO ii; if (SUCCEEDED(D3DX10GetImageInfoFromFile(lpBitmap, NULL, &ii, NULL))) { element->SetInt(TEXT("cx"), ii.Width); element->SetInt(TEXT("cy"), ii.Height); } else AppWarning(TEXT("ConfigureBitmapSource: could not get image info for bitmap '%s'"), lpBitmap); return true; } return false; }
// assumes that deck is full of cards // if bFull, create a full deck, otherwise create an empty deck // empty decks get cards from other non empty decks HRESULT CDeck::InitSprite(ID3D10Device* pD3D10Device, bool bFull) { HRESULT hr = S_OK; D3DX10_IMAGE_INFO InfoFromFile; D3DX10_IMAGE_LOAD_INFO LoadImageInfo; const_deckIterator deckitr; int i; DWORD nDirectoryLength = 255; TCHAR lpCurrentDir[255]; if (bFull) { // index 0 refers to back side of card LPTSTR lpCardName[NUM_CARD_VIEWS] = { L"b1fv", L"h1", L"h2", L"h3", L"h4", L"h5", L"h6", L"h7", L"h8", L"h9", L"h10", L"hj", L"hq", L"hk", L"d1", L"d2", L"d3", L"d4", L"d5", L"d6", L"d7", L"d8", L"d9", L"d10", L"dj", L"dq", L"dk", L"c1", L"c2", L"c3", L"c4", L"c5", L"c6", L"c7", L"c8", L"c9", L"c10", L"cj", L"cq", L"ck", L"s1", L"s2", L"s3", L"s4", L"s5", L"s6", L"s7", L"s8", L"s9", L"s10", L"sj", L"sq", L"sk", }; // set up file path GetCurrentDirectory(nDirectoryLength, lpCurrentDir); lstrcat(lpCurrentDir, (LPCTSTR)L"\\Graphics\\"); deckitr = getDeckIterator(); for (i=0;i<NUM_CARD_VIEWS;i++) { if (m_cardGraphics[i].pShaderResource == NULL) { m_cardGraphics[i].ID = i; m_cardGraphics[i].lpCardDesc[0] = '\0'; lstrcpy((LPWSTR)m_cardGraphics[i].lpFileName, lpCurrentDir); lstrcat((LPWSTR)m_cardGraphics[i].lpFileName, lpCardName[i]); lstrcat((LPWSTR)m_cardGraphics[i].lpFileName, L".png"); hr = D3DX10GetImageInfoFromFile((LPWSTR)m_cardGraphics[i].lpFileName, NULL, &InfoFromFile, NULL); if (FAILED(hr)) { return -1; } LoadImageInfo.Width = InfoFromFile.Width; LoadImageInfo.Height = InfoFromFile.Height; LoadImageInfo.Depth = InfoFromFile.Depth; LoadImageInfo.FirstMipLevel = 1; LoadImageInfo.MipLevels = InfoFromFile.MipLevels; LoadImageInfo.Usage = D3D10_USAGE_DEFAULT; LoadImageInfo.BindFlags = D3D10_BIND_SHADER_RESOURCE; LoadImageInfo.CpuAccessFlags = 0; LoadImageInfo.MiscFlags = 0; LoadImageInfo.Format = InfoFromFile.Format; LoadImageInfo.Filter = D3DX10_FILTER_NONE; LoadImageInfo.MipFilter = D3DX10_FILTER_NONE; LoadImageInfo.pSrcInfo = &InfoFromFile; hr = D3DX10CreateShaderResourceViewFromFile(pD3D10Device, (LPWSTR)m_cardGraphics[i].lpFileName, &LoadImageInfo, NULL, &(m_cardGraphics[i].pShaderResource), NULL); if (FAILED(hr)) { return hr; } // now assign textures to each card. // assume that deck has not been shuffled // and is in same order as lpCardName array. if ((deckitr != NULL ) && (i >= 1)) { POINT pt; pt.x = 100; pt.y = 100; deckitr->data->setFrontTexture(m_cardGraphics[i].pShaderResource); deckitr->data->setBackTexture(m_cardGraphics[0].pShaderResource); deckitr->data->setSpriteWidth(InfoFromFile.Width); deckitr->data->setSpriteLength(InfoFromFile.Height); deckitr->data->setFileName(m_cardGraphics[i].lpFileName); deckitr->data->setLocation(pt); deckitr = deckitr->next; } } else { if ((deckitr != NULL ) && (i >= 1)) { deckitr->data->setFrontTexture(m_cardGraphics[i].pShaderResource); deckitr->data->setBackTexture(m_cardGraphics[0].pShaderResource); deckitr = deckitr->next; } } } } return S_OK; }
INT_PTR CALLBACK ConfigureBitmapTransitionProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_INITDIALOG: { ConfigBitmapInfo *configInfo = (ConfigBitmapInfo*)lParam; SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)configInfo); LocalizeWindow(hwnd); //-------------------------- HWND hwndTemp = GetDlgItem(hwnd, IDC_BITMAPS); StringList bitmapList; configInfo->data->GetStringList(TEXT("bitmap"), bitmapList); for(UINT i=0; i<bitmapList.Num(); i++) { CTSTR lpBitmap = bitmapList[i]; if(OSFileExists(lpBitmap)) SendMessage(hwndTemp, LB_ADDSTRING, 0, (LPARAM)lpBitmap); } //-------------------------- hwndTemp = GetDlgItem(hwnd, IDC_TRANSITIONTIME); UINT transitionTime = configInfo->data->GetInt(TEXT("transitionTime")); SendMessage(hwndTemp, UDM_SETRANGE32, MIN_TRANSITION_TIME, MAX_TRANSITION_TIME); if(!transitionTime) transitionTime = 10; SendMessage(hwndTemp, UDM_SETPOS32, 0, transitionTime); EnableWindow(GetDlgItem(hwnd, IDC_REPLACE), FALSE); EnableWindow(GetDlgItem(hwnd, IDC_REMOVE), FALSE); EnableWindow(GetDlgItem(hwnd, IDC_MOVEUPWARD), FALSE); EnableWindow(GetDlgItem(hwnd, IDC_MOVEDOWNWARD), FALSE); //-------------------------- BOOL bFadeInOnly = configInfo->data->GetInt(TEXT("fadeInOnly"), 1); BOOL bDisableFading = configInfo->data->GetInt(TEXT("disableFading")); BOOL bRandomize = configInfo->data->GetInt(TEXT("randomize")); SendMessage(GetDlgItem(hwnd, IDC_FADEINONLY), BM_SETCHECK, bFadeInOnly ? BST_CHECKED : BST_UNCHECKED, 0); SendMessage(GetDlgItem(hwnd, IDC_DISABLEFADING), BM_SETCHECK, bDisableFading ? BST_CHECKED : BST_UNCHECKED, 0); SendMessage(GetDlgItem(hwnd, IDC_RANDOMIZE), BM_SETCHECK, bRandomize ? BST_CHECKED : BST_UNCHECKED, 0); EnableWindow(GetDlgItem(hwnd, IDC_FADEINONLY), !bDisableFading); return TRUE; } case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_ADD: { TSTR lpFile = (TSTR)Allocate(32*1024*sizeof(TCHAR)); zero(lpFile, 32*1024*sizeof(TCHAR)); OPENFILENAME ofn; zero(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.lpstrFile = lpFile; ofn.hwndOwner = hwnd; ofn.nMaxFile = 32*1024*sizeof(TCHAR); ofn.lpstrFilter = TEXT("All Formats (*.bmp;*.dds;*.jpg;*.png;*.gif)\0*.bmp;*.dds;*.jpg;*.png;*.gif\0"); ofn.nFilterIndex = 1; ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER; TCHAR curDirectory[MAX_PATH+1]; GetCurrentDirectory(MAX_PATH, curDirectory); BOOL bOpenFile = GetOpenFileName(&ofn); TCHAR newDirectory[MAX_PATH+1]; GetCurrentDirectory(MAX_PATH, newDirectory); SetCurrentDirectory(curDirectory); if(bOpenFile) { TSTR lpCurFile = lpFile+ofn.nFileOffset; while(lpCurFile && *lpCurFile) { String strPath; strPath << newDirectory << TEXT("\\") << lpCurFile; SendMessage(GetDlgItem(hwnd, IDC_BITMAPS), LB_ADDSTRING, 0, (LPARAM)strPath.Array()); lpCurFile += slen(lpCurFile)+1; } } Free(lpFile); break; } case IDC_BITMAPS: if(HIWORD(wParam) == LBN_SELCHANGE) { EnableWindow(GetDlgItem(hwnd, IDC_REPLACE), TRUE); EnableWindow(GetDlgItem(hwnd, IDC_REMOVE), TRUE); EnableWindow(GetDlgItem(hwnd, IDC_MOVEUPWARD), TRUE); EnableWindow(GetDlgItem(hwnd, IDC_MOVEDOWNWARD), TRUE); } break; case IDC_REMOVE: { UINT curSel = (UINT)SendMessage(GetDlgItem(hwnd, IDC_BITMAPS), LB_GETCURSEL, 0, 0); if(curSel != LB_ERR) { SendMessage(GetDlgItem(hwnd, IDC_BITMAPS), LB_DELETESTRING, curSel, 0); EnableWindow(GetDlgItem(hwnd, IDC_REPLACE), FALSE); EnableWindow(GetDlgItem(hwnd, IDC_REMOVE), FALSE); EnableWindow(GetDlgItem(hwnd, IDC_MOVEUPWARD), FALSE); EnableWindow(GetDlgItem(hwnd, IDC_MOVEDOWNWARD), FALSE); } } break; case IDC_MOVEUPWARD: { HWND hwndBitmaps = GetDlgItem(hwnd, IDC_BITMAPS); UINT curSel = (UINT)SendMessage(hwndBitmaps, LB_GETCURSEL, 0, 0); if(curSel != LB_ERR) { if(curSel > 0) { String strText = GetLBText(hwndBitmaps, curSel); SendMessage(hwndBitmaps, LB_DELETESTRING, curSel, 0); SendMessage(hwndBitmaps, LB_INSERTSTRING, --curSel, (LPARAM)strText.Array()); PostMessage(hwndBitmaps, LB_SETCURSEL, curSel, 0); } } } break; case IDC_MOVEDOWNWARD: { HWND hwndBitmaps = GetDlgItem(hwnd, IDC_BITMAPS); UINT numBitmaps = (UINT)SendMessage(hwndBitmaps, LB_GETCOUNT, 0, 0); UINT curSel = (UINT)SendMessage(hwndBitmaps, LB_GETCURSEL, 0, 0); if(curSel != LB_ERR) { if(curSel < (numBitmaps-1)) { String strText = GetLBText(hwndBitmaps, curSel); SendMessage(hwndBitmaps, LB_DELETESTRING, curSel, 0); SendMessage(hwndBitmaps, LB_INSERTSTRING, ++curSel, (LPARAM)strText.Array()); PostMessage(hwndBitmaps, LB_SETCURSEL, curSel, 0); } } } break; case IDC_DISABLEFADING: { BOOL bDisableFading = SendMessage(GetDlgItem(hwnd, IDC_DISABLEFADING), BM_GETCHECK, 0, 0) == BST_CHECKED; EnableWindow(GetDlgItem(hwnd, IDC_FADEINONLY), !bDisableFading); } break; case IDOK: { HWND hwndBitmaps = GetDlgItem(hwnd, IDC_BITMAPS); UINT numBitmaps = (UINT)SendMessage(hwndBitmaps, LB_GETCOUNT, 0, 0); if(!numBitmaps) { OBSMessageBox(hwnd, Str("Sources.TransitionSource.Empty"), NULL, 0); break; } //--------------------------- StringList bitmapList; for(UINT i=0; i<numBitmaps; i++) bitmapList << GetLBText(hwndBitmaps, i); ConfigBitmapInfo *configInfo = (ConfigBitmapInfo*)GetWindowLongPtr(hwnd, DWLP_USER); D3DX10_IMAGE_INFO ii; if(SUCCEEDED(D3DX10GetImageInfoFromFile(bitmapList[0], NULL, &ii, NULL))) { configInfo->cx = ii.Width; configInfo->cy = ii.Height; } else { configInfo->cx = configInfo->cy = 32; AppWarning(TEXT("ConfigureBitmapTransitionSource: could not get image info for bitmap '%s'"), bitmapList[0].Array()); } configInfo->data->SetStringList(TEXT("bitmap"), bitmapList); UINT transitionTime = (UINT)SendMessage(GetDlgItem(hwnd, IDC_TRANSITIONTIME), UDM_GETPOS32, 0, 0); configInfo->data->SetInt(TEXT("transitionTime"), transitionTime); BOOL bFadeInOnly = SendMessage(GetDlgItem(hwnd, IDC_FADEINONLY), BM_GETCHECK, 0, 0) == BST_CHECKED; BOOL bDisableFading = SendMessage(GetDlgItem(hwnd, IDC_DISABLEFADING), BM_GETCHECK, 0, 0) == BST_CHECKED; BOOL bRandomize = SendMessage(GetDlgItem(hwnd, IDC_RANDOMIZE), BM_GETCHECK, 0, 0) == BST_CHECKED; configInfo->data->SetInt(TEXT("fadeInOnly"), bFadeInOnly); configInfo->data->SetInt(TEXT("disableFading"), bDisableFading); configInfo->data->SetInt(TEXT("randomize"), bRandomize); } case IDCANCEL: EndDialog(hwnd, LOWORD(wParam)); break; } break; } return 0; }
Texture* D3D10Texture::CreateFromFile(CTSTR lpFile, BOOL bBuildMipMaps) { HRESULT err; D3DX10_IMAGE_INFO ii; if(FAILED(D3DX10GetImageInfoFromFile(lpFile, NULL, &ii, NULL))) { AppWarning(TEXT("D3D10Texture::CreateFromFile: Could not get information about texture file '%s'"), lpFile); return NULL; } //------------------------------------------ if(bBuildMipMaps && (!IsPow2(ii.Width) || !IsPow2(ii.Height))) bBuildMipMaps = FALSE; D3DX10_IMAGE_LOAD_INFO ili; ili.Width = D3DX10_DEFAULT; ili.Height = D3DX10_DEFAULT; ili.Depth = D3DX10_DEFAULT; ili.FirstMipLevel = D3DX10_DEFAULT; ili.MipLevels = bBuildMipMaps ? 0 : 1; ili.Usage = (D3D10_USAGE)D3DX10_DEFAULT; ili.BindFlags = D3DX10_DEFAULT; ili.CpuAccessFlags = D3DX10_DEFAULT; ili.MiscFlags = D3DX10_DEFAULT; ili.Format = (DXGI_FORMAT)D3DX10_DEFAULT; ili.Filter = D3DX10_DEFAULT; ili.MipFilter = D3DX10_DEFAULT; ili.pSrcInfo = NULL; ID3D10Resource *texResource; if(FAILED(err = D3DX10CreateTextureFromFile(GetD3D(), lpFile, &ili, NULL, &texResource, NULL))) { AppWarning(TEXT("D3D10Texture::CreateFromFile: failed to load '%s'"), lpFile); return NULL; } //------------------------------------------ D3D10_SHADER_RESOURCE_VIEW_DESC resourceDesc; zero(&resourceDesc, sizeof(resourceDesc)); resourceDesc.Format = ii.Format; resourceDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; resourceDesc.Texture2D.MipLevels = bBuildMipMaps ? -1 : 1; ID3D10ShaderResourceView *resource; if(FAILED(err = GetD3D()->CreateShaderResourceView(texResource, &resourceDesc, &resource))) { SafeRelease(texResource); AppWarning(TEXT("D3D10Texture::CreateFromFile: CreateShaderResourceView failed, result = 0x%08lX"), err); return NULL; } //------------------------------------------ ID3D10Texture2D *tex2D; err = texResource->QueryInterface(__uuidof(ID3D10Texture2D), (void**)&tex2D); if(FAILED(err)) { SafeRelease(texResource); SafeRelease(resource); AppWarning(TEXT("D3D10Texture::CreateFromFile: could not query texture interface")); return NULL; } texResource->Release(); //------------------------------------------ D3D10Texture *newTex = new D3D10Texture; newTex->resource = resource; newTex->texture = tex2D; newTex->width = ii.Width; newTex->height = ii.Height; switch(ii.Format) { case DXGI_FORMAT_R8_UNORM: newTex->format = GS_ALPHA; break; case DXGI_FORMAT_A8_UNORM: newTex->format = GS_GRAYSCALE; break; case DXGI_FORMAT_B8G8R8X8_UNORM: newTex->format = GS_BGR; break; case DXGI_FORMAT_B8G8R8A8_UNORM: newTex->format = GS_BGRA; break; case DXGI_FORMAT_R8G8B8A8_UNORM: newTex->format = GS_RGBA; break; case DXGI_FORMAT_R16G16B16A16_FLOAT: newTex->format = GS_RGBA16F; break; case DXGI_FORMAT_R32G32B32A32_FLOAT: newTex->format = GS_RGBA32F; break; case DXGI_FORMAT_BC1_UNORM: newTex->format = GS_DXT1; break; case DXGI_FORMAT_BC2_UNORM: newTex->format = GS_DXT3; break; case DXGI_FORMAT_BC3_UNORM: newTex->format = GS_DXT5; break; default: newTex->format = GS_UNKNOWNFORMAT; } return newTex; }