// Parse the command line for the parameters // Only parameters that are specified on the command line are updated, if there // are no parameters for a value, the previous WindowParams settings passed in // are preserved //----------------------------------------------------------------------------- CPUTResult CPUT_OGL::CPUTParseCommandLine(cString commandLine, CPUTWindowCreationParams *pWindowParams, cString *pFilename) { ASSERT( (NULL!=pWindowParams), _L("Required command line parsing parameter is NULL")); ASSERT( (NULL!=pFilename), _L("Required command line parsing parameter is NULL")); // there are no command line parameters, just return if(0==commandLine.size()) { return CPUT_SUCCESS; } return CPUT_SUCCESS; }
void CPUTGUIElement::SetText(cString string) { DEBUG_PRINT(_L("GUIElement SetText: %s"), string.c_str()); mText = string; if(mpFont && mpTextMaterial) { DEBUG_PRINT(_L("\t have font and material")); if(!mpTextMesh) { #ifdef CPUT_FOR_DX11 mpTextMesh = new CPUTMeshDX11(); #else mpTextMesh = new CPUTMeshOGL(); #endif } unsigned int numCharacters = (unsigned int) string.size(); unsigned int numVertices = numCharacters * 6; CPUTGUIVertex* pVB = new CPUTGUIVertex[numVertices]; CPUTBufferElementInfo pGUIVertex[3] = { { "POSITION", 0, 0, CPUT_F32, 3, 3*sizeof(float), 0 }, { "TEXCOORD", 0, 1, CPUT_F32, 2, 2*sizeof(float), 3*sizeof(float)}, { "COLOR", 0, 2, CPUT_F32, 4, 4*sizeof(float), 5*sizeof(float)}, }; mpFont->LayoutText(NULL, &mTextWidth, &mTextHeight, mText, 0, 0); mTextX = (mWidth-mTextWidth)/2; mTextY = (mHeight-mTextHeight)/2; mpFont->LayoutText(pVB, &mTextWidth, &mTextHeight, mText, 0, 0); mpTextMesh->CreateNativeResources(NULL, 1, 3, pGUIVertex, numVertices, pVB, NULL, 0, NULL); #ifdef CPUT_FOR_DX11 mpTextMesh->SetMeshTopology(CPUT_TOPOLOGY_INDEXED_TRIANGLE_LIST); D3D11_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; UINT numElements = ARRAYSIZE( layout ); ID3DBlob* pBlob = ((CPUTMaterialEffectDX11*)mpTextMaterial->GetMaterialEffects()[0])->GetVertexShader()->GetBlob(); CPUT_DX11::GetDevice()->CreateInputLayout( layout, numElements, pBlob->GetBufferPointer(), pBlob->GetBufferSize(), &mpVertexLayout ); CPUTSetDebugName( mpVertexLayout, "CPUT GUI InputLayout object"); #else #endif SAFE_DELETE_ARRAY(pVB); } }
// Add an item to the selection list //----------------------------------------------------------------------------- CPUTResult CPUTDropdown::AddSelectionItem(const cString Item, bool bIsSelected) { // Don't allow adding 'empty' elements // causes a spacing issue if(0==Item.size()) { return CPUT_ERROR_INVALID_PARAMETER; } // create a static item to hold the text CPUTText *pNewItem = new CPUTText(mpFont); pNewItem->SetText(Item, 0.35f); // set the text slightly higher than the 0.5 normal mode mpListOfSelectableItems.push_back(pNewItem); // Should this be the currently selected item? if(bIsSelected) { mSelectedItemIndex = (int) mpListOfSelectableItems.size()-1; } // was this the first item added to an empty list? if( 1==mpListOfSelectableItems.size() ) { mSelectedItemIndex=0; } // mark that a resize of dropdown selection box is needed mbSizeDirty = true; Recalculate(); // position or size may move - force a recalculation of this control's location // if it is managed by the auto-arrange function if(this->IsAutoArranged()) { CPUTGuiControllerDX11::GetController()->Resize(); } return CPUT_SUCCESS; }
// Parse the command line for the parameters // Only parameters that are specified on the command line are updated, if there // are no parameters for a value, the previous WindowParams settings passed in // are preserved //----------------------------------------------------------------------------- CPUTResult CPUT_DX11::CPUTParseCommandLine(cString commandLine, CPUTWindowCreationParams *pWindowParams, cString *pFilename) { ASSERT( (NULL!=pWindowParams), _L("Required command line parsing parameter is NULL")); ASSERT( (NULL!=pFilename), _L("Required command line parsing parameter is NULL")); // there are no command line parameters, just return if(0==commandLine.size()) { return CPUT_SUCCESS; } // we do have parameters, so parse them. #if defined (UNICODE) || defined(_UNICODE) // convert command line to lowercase version cString CommandLineParams(commandLine); std::transform(CommandLineParams.begin(), CommandLineParams.end(), CommandLineParams.begin(), ::tolower); // special case - double-clicked on a file // In the case someone has associated .set files with CPUT, then the target set file comes in surrounded // by quote marks (i.e. "c:\SoftwareOcclusionCulling\Asset\City.set"). If the first char is a quote mark, we're in this // special case if('"' == CommandLineParams[0]) { pFilename->assign(&CommandLineParams[1]); // remove the leading " char (*pFilename)[pFilename->size()-1] = '\0'; // remove the trailing " char return CPUT_SUCCESS; } wchar_t separators[] = L" \t\n"; wchar_t* nextToken = NULL; wchar_t* token = wcstok_s((wchar_t*)CommandLineParams.c_str(), separators, &nextToken); while(token) { if('-' == token[0]) { // parameter - get next token for which one cString ParameterName(&token[1]); if(0!=ParameterName.size()) { if(0==ParameterName.compare(_L("width"))) { // get the next value token = wcstok_s(NULL, separators, &nextToken); ASSERT(token, _L("-width command line parameter missing required numerical value")); pWindowParams->windowWidth = _wtoi(token); } else if(0==ParameterName.compare(_L("height"))) { // get the next value token = wcstok_s(NULL, separators, &nextToken); ASSERT(token, _L("-height command line parameter missing required numerical value")); pWindowParams->windowHeight = _wtoi(token); } else if(0==ParameterName.compare(_L("fullscreen"))) { // get the bool token = wcstok_s(NULL, separators, &nextToken); cString boolString(token); if(0==boolString.compare(_L("true"))) { pWindowParams->startFullscreen = true; } } else if(0==ParameterName.compare(_L("vsync"))) { // get the bool token = wcstok_s(NULL, separators, &nextToken); cString boolString(token); if( (0==boolString.compare(_L("on"))) || (0==boolString.compare(_L("true"))) ) { // vsync set to 30 FPS pWindowParams->deviceParams.refreshRate = 30; } if( (0==boolString.compare(_L("off"))) || (0==boolString.compare(_L("false"))) ) { pWindowParams->deviceParams.refreshRate = 0; } } else if(0==ParameterName.compare(_L("xpos"))) { // get the next value token = wcstok_s(NULL, separators, &nextToken); ASSERT(token, _L("-xpos command line parameter missing required numerical value")); pWindowParams->windowPositionX = _wtoi(token); } else if(0==ParameterName.compare(_L("ypos"))) { // get the next value token = wcstok_s(NULL, separators, &nextToken); ASSERT(token, _L("-ypos command line parameter missing required numerical value")); pWindowParams->windowPositionY = _wtoi(token); } else if(0==ParameterName.compare(_L("file"))) { // get the filename token = wcstok_s(NULL, separators, &nextToken); pFilename->assign(token); } else { // we don't know what the string was, but all specified ones should be of the form // '-<keyword> <value>' // so skip over the <value> part token = wcstok_s(NULL, separators, &nextToken); } // we don't know what this parameter is, let user parse it } } // advance to next token token = wcstok_s(NULL, separators, &nextToken); } #else ASSERT(false, _L("CPUT_DX11::CPUTParseCommandLine non-UNICODE version not written yet - need to write if we want to support multi-byte")); #endif return CPUT_SUCCESS; }