void Console::Render() { if( !IsEnabled() ) return; //TODO: Clean up this nonsense static float sTestAlpha = 0.75; Vec2i winDimensions; winDimensions.X = theCamera.GetWindowWidth(); winDimensions.Y = theCamera.GetWindowHeight(); static float fScreenHeightPct = 0.5f; static int sTextBoxBorder = winDimensions.Y/192; static int sTextBoxHeight = winDimensions.Y/32 + sTextBoxBorder; int consoleBGHeight = (int)(fScreenHeightPct * (float)winDimensions.Y); int consoleBGBottomY = consoleBGHeight; glColor4f(0.0f,0.0f,0.0f,sTestAlpha); DrawTile(0, consoleBGBottomY, winDimensions.X, consoleBGHeight ); //Draw log static int sLogXPos = sTextBoxBorder; int logYPos = consoleBGBottomY - sTextBoxBorder; if (_buffer.size() > 0) { glColor4f(1.0f, 1.0f, 1.0f, 1.0f); StringList::iterator it = _buffer.end(); while (it != _buffer.begin()) { it--; /* Vector2 textSize = */ DrawGameText( *it, "ConsoleSmall", sLogXPos, logYPos ); logYPos -= (int)_lineHeight + sTextBoxBorder; } } //Draw text box border glColor4f(0.0f,1.0f,0.0f,sTestAlpha/2.0f); int textBoxBottomY = consoleBGBottomY + sTextBoxHeight; DrawTile(0, textBoxBottomY, winDimensions.X, sTextBoxHeight ); //Draw text box int textBoxHeight = sTextBoxHeight - sTextBoxBorder; int textBoxWidth = winDimensions.X - sTextBoxBorder; int textBoxXPos = (winDimensions.X - textBoxWidth)/2; int textBoxYPos = textBoxBottomY - (sTextBoxHeight-textBoxHeight)/2; glColor4f(0.0f,0.0f,0.0f,sTestAlpha); DrawTile(textBoxXPos, textBoxYPos, textBoxWidth, textBoxHeight); textBoxXPos += sTextBoxBorder; textBoxYPos -= sTextBoxBorder + (sTextBoxBorder/2); glColor4f(0.0f,1.0f,0.0f,1.0f); String printInput = _prompt; printInput += _currentInput.substr(0, _cursorPos); if(_bCursorDisp) { printInput += "|"; } else { printInput += " "; } if (_cursorPos < _currentInput.length()) { printInput += _currentInput.substr(_cursorPos, _currentInput.length()); } DrawGameText(printInput.c_str(), "ConsoleSmall", textBoxXPos, textBoxYPos); //Draw autocomplete static int sMaxAutoCompleteLines = MAX_AUTO_COMPLETE; int numAutoCompleteLines = MathUtil::Min(sMaxAutoCompleteLines, (int)_autoCompleteList.size() ); int autoCompleteBottomY = textBoxBottomY + (numAutoCompleteLines * sTextBoxHeight); int autoCompleteStartY = textBoxBottomY + 2*sTextBoxHeight/3; int autoCompleteXPos = textBoxXPos + winDimensions.Y / 24; int autoCompleteBoxXPos = autoCompleteXPos - sTextBoxBorder; glColor4f(0.0f,0.0f,0.0f,sTestAlpha); DrawTile(autoCompleteBoxXPos, autoCompleteBottomY, winDimensions.X-autoCompleteBoxXPos, numAutoCompleteLines * sTextBoxHeight); glColor4f(0.0f,1.0f,0.0f,1.0f); Vector2 outPos((float)autoCompleteXPos, (float)autoCompleteStartY); for( int i = 0; i < numAutoCompleteLines; i++ ) { if( (int)_autoCompleteList.size() > sMaxAutoCompleteLines-1 && i == sMaxAutoCompleteLines-1 ) DrawGameText( "...", "ConsoleSmall", autoCompleteXPos, (int)outPos.Y ); else DrawGameText( _autoCompleteList[i].c_str(), "ConsoleSmall", autoCompleteXPos, (int)outPos.Y ); outPos.Y += sTextBoxHeight; } }
/** * Run. */ boost::shared_ptr<Array> execute(vector< boost::shared_ptr<Array> >& inputArrays, boost::shared_ptr<Query> query) { if (query->getInstanceID() != 0) { //I am not instance 0 - I don't need to do anything. Return an empty array. return shared_ptr<Array>(new MemArray(_schema)); } //I am instance 0, let's save the array to a bmp image. string filepath = ((boost::shared_ptr<OperatorParamPhysicalExpression>&)_parameters[0])->getExpression()->evaluate().getString(); ArrayDesc const& inputSchema = inputArrays[0]->getArrayDesc(); size_t nRows = inputSchema.getDimensions()[0].getLength(); size_t rowStart = inputSchema.getDimensions()[0].getStart(); size_t nCols = inputSchema.getDimensions()[1].getLength(); size_t colStart = inputSchema.getDimensions()[1].getStart(); SimpleImage image(nRows, nCols); vector<shared_ptr<ConstArrayIterator> > aiters(3); aiters[0] = inputArrays[0]->getConstIterator(0); aiters[1] = inputArrays[0]->getConstIterator(1); aiters[2] = inputArrays[0]->getConstIterator(2); int iterationMode = ConstChunkIterator::IGNORE_OVERLAPS | ConstChunkIterator::IGNORE_EMPTY_CELLS; vector<shared_ptr<ConstChunkIterator> > citers(3); while(!aiters[0]->end()) { citers[0] = aiters[0]->getChunk().getConstIterator(iterationMode); citers[1] = aiters[1]->getChunk().getConstIterator(iterationMode); citers[2] = aiters[2]->getChunk().getConstIterator(iterationMode); while(!citers[0]->end()) { Coordinates const& pos = citers[0]->getPosition(); size_t row = pos[0] - rowStart; size_t col = pos[1] - colStart; Value const& valueRed = citers[0]->getItem(); Value const& valueGreen = citers[1]->getItem(); Value const& valueBlue = citers[2]->getItem(); if (valueRed.isNull() || valueGreen.isNull() || valueBlue.isNull()) { image.setPixel(row,col,0,0,0); } else { uint8_t red = valueRed.getUint8(); uint8_t green = valueGreen.getUint8(); uint8_t blue = valueBlue.getUint8(); image.setPixel(row,col,blue,green,red); } ++(*citers[0]); ++(*citers[1]); ++(*citers[2]); } ++(*aiters[0]); ++(*aiters[1]); ++(*aiters[2]); } FILE* f = fopen(filepath.c_str(), "wb"); if(!f) { throw SYSTEM_EXCEPTION(SCIDB_SE_INTERNAL, SCIDB_LE_ILLEGAL_OPERATION) << "savebmp can't open the target file!"; } size_t fileSize = image.saveToBmp(f); if(fileSize == 0) { throw SYSTEM_EXCEPTION(SCIDB_SE_INTERNAL, SCIDB_LE_ILLEGAL_OPERATION) << "savebmp can't write the target file!"; } fclose(f); shared_ptr<Array> dstArray(new MemArray(_schema)); Coordinates outPos(1); outPos[0]=0; Value outValue; shared_ptr<ArrayIterator> daiter = dstArray->getIterator(0); Chunk& outChunk = daiter->newChunk(outPos); shared_ptr<ChunkIterator> dciter = outChunk.getIterator(query); dciter->setPosition(outPos); outValue.setString("File Saved Successfully"); dciter->writeItem(outValue); dciter->flush(); shared_ptr<ArrayIterator>daiter2 = dstArray->getIterator(1); Chunk& outChunk2 = daiter2->newChunk(outPos); shared_ptr<ChunkIterator>dciter2 = outChunk2.getIterator(query); dciter2->setPosition(outPos); outValue.setDouble(fileSize * 1.0 / (1024*1024)); dciter2->writeItem(outValue); dciter2->flush(); return dstArray; }