unsigned int CheckBox::drawImages(Form* form, const Rectangle& clip) { if (!_image) return 0; // Left, v-center. // TODO: Set an alignment for icons. const Rectangle& region = _image->getRegion(); const Theme::UVs& uvs = _image->getUVs(); Vector4 color = _image->getColor(); color.w *= _opacity; Vector2 size; if (_imageSize.isZero()) { size.set(region.width, region.height); } else { size.set(_imageSize); } Vector2 pos(_viewportBounds.x, _viewportBounds.y + _viewportBounds.height * 0.5f - size.y * 0.5f); SpriteBatch* batch = _style->getTheme()->getSpriteBatch(); startBatch(form, batch); batch->draw(pos.x, pos.y, size.x, size.y, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds); finishBatch(form, batch); return 1; }
unsigned int TextBox::drawImages(Form* form, const Rectangle& clip) { Control::State state = getState(); if (_caretImage && (state == ACTIVE || hasFocus())) { // Draw the cursor at its current location. const Rectangle& region = _caretImage->getRegion(); if (!region.isEmpty()) { const Theme::UVs& uvs = _caretImage->getUVs(); Vector4 color = _caretImage->getColor(); color.w *= _opacity; float caretWidth = region.width * _fontSize / region.height; Font* font = getFont(state); unsigned int fontSize = getFontSize(state); Vector2 point; font->getLocationAtIndex(getDisplayedText().c_str(), _textBounds, fontSize, &point, _caretLocation, getTextAlignment(state), true, getTextRightToLeft(state)); SpriteBatch* batch = _style->getTheme()->getSpriteBatch(); startBatch(form, batch); batch->draw(point.x - caretWidth * 0.5f, point.y, caretWidth, fontSize, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds); finishBatch(form, batch); return 1; } } return 0; }
unsigned int ImageControl::drawImages(Form* form, const Rectangle& clip) { if (!_batch) return 0; startBatch(form, _batch); Vector4 color = Vector4::one(); color.w *= _opacity; if (_dstRegion.isEmpty()) { _batch->draw(_viewportBounds.x, _viewportBounds.y, _viewportBounds.width, _viewportBounds.height, _uvs.u1, _uvs.v1, _uvs.u2, _uvs.v2, color, _viewportClipBounds); } else { _batch->draw(_viewportBounds.x + _dstRegion.x, _viewportBounds.y + _dstRegion.y, _dstRegion.width, _dstRegion.height, _uvs.u1, _uvs.v1, _uvs.u2, _uvs.v2, color, _viewportClipBounds); } finishBatch(form, _batch); return 1; }
void BatchRenderEngine::init() { for (int i = 0; i < MAX_TEXTURES; i++) _texIDs[i] = i; _shader->Bind(); _shader->setUniform1iv("textures", MAX_TEXTURES, _texIDs); glGenVertexArrays(1, &_VAO); glGenBuffers(1, &_VBO); glBindVertexArray(_VAO); glBindBuffer(GL_ARRAY_BUFFER, _VBO); glBufferData(GL_ARRAY_BUFFER, MAX_VERTS*sizeof(Vertex), NULL, GL_DYNAMIC_DRAW); glEnableVertexAttribArray(POSITION_VB); glEnableVertexAttribArray(TEXCOORD_VB); glEnableVertexAttribArray(NORMAL_VB); glEnableVertexAttribArray(COLOR_VB); glEnableVertexAttribArray(TID_VB); glVertexAttribPointer(POSITION_VB, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)0); glVertexAttribPointer(TEXCOORD_VB, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, texCoord))); glVertexAttribPointer(NORMAL_VB, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, normal))); glVertexAttribPointer(COLOR_VB, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, color))); glVertexAttribPointer(TID_VB, 1, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid*)(offsetof(Vertex, tid))); glGenBuffers(1, &_indBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, MAX_INDICES * sizeof(GLuint), NULL, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); startBatch(); }
unsigned int Slider::drawText(Form* form, const Rectangle& clip) { unsigned int drawCalls = Label::drawText(form, clip); if (_valueTextVisible && _font) { Control::State state = getState(); unsigned int fontSize = getFontSize(state); SpriteBatch* batch = _font->getSpriteBatch(fontSize); startBatch(form, batch); _font->drawText(_valueText.c_str(), _textBounds, _textColor, fontSize, _valueTextAlignment, true, getTextRightToLeft(state), _viewportClipBounds); finishBatch(form, batch); ++drawCalls; } return drawCalls; }
void BatchRenderEngine::render() { endBatch(); flush(); glUseProgram(0); glBindTexture(GL_TEXTURE_2D, 0); glActiveTexture(GL_TEXTURE0); CEGUI::System::getSingleton().renderAllGUIContexts(); glDisable(GL_SCISSOR_TEST); // Prevents flickering caused by CEGUI call swapWindowBuffer(); clear(0.0f, 0.15f, 0.3f, 1.0f); startBatch(); }
bool QKeccakHash::file(const QString &fileName, HashBits hashBits, int blockSize) { if (isBatchRunning() || blockSize < 1) return false; if (!setHashBitLength(hashBits)) return false; QFile file(fileName); if (file.open(QFile::ReadOnly)) { qint64 fileSize = file.size(); qint64 readBytes = 0; if (!startBatch()) return false; bool success = true; char *buffer = new char[blockSize]; // repeatedly read blockSize bytes of the file to buffer and pass it to putBatch: while (file.error() == QFile::NoError) { readBytes = file.read(buffer, qMin(fileSize-file.pos(), (qint64)blockSize)); // read till end of file to buffer, but not more than blockSize bytes if (readBytes > 0) { if (!putBatch(buffer, readBytes)) { success = false; break; } if (readBytes < blockSize) // that was the last block break; } else // error occured { success = false; break; } } delete buffer; if (!stopBatch()) success = false; return success; } else return false; }
unsigned int RadioButton::drawImages(Form* form, const Rectangle& clip) { if (!_image) return 0; // Left, v-center. // TODO: Set an alignment for radio button images. const Rectangle& region = _image->getRegion(); const Theme::UVs& uvs = _image->getUVs(); Vector4 color = _image->getColor(); color.w *= _opacity; Vector2 pos(_viewportBounds.x, _viewportBounds.y); SpriteBatch* batch = _style->getTheme()->getSpriteBatch(); startBatch(form, batch); batch->draw(pos.x, pos.y, _viewportBounds.height, _viewportBounds.height, uvs.u1, uvs.v1, uvs.u2, uvs.v2, color, _viewportClipBounds); finishBatch(form, batch); return 1; }
unsigned int TextBox::drawText(Form* form, const Rectangle& clip) { if (_text.size() <= 0) return 0; // Draw the text. if (_font) { Control::State state = getState(); const std::string displayedText = getDisplayedText(); unsigned int fontSize = getFontSize(state); SpriteBatch* batch = _font->getSpriteBatch(fontSize); startBatch(form, batch); _font->drawText(displayedText.c_str(), _textBounds, _textColor, fontSize, getTextAlignment(state), true, getTextRightToLeft(state), _viewportClipBounds); finishBatch(form, batch); return 1; } return 0; }
unsigned int Label::drawText(Form* form) const { if (_viewportClipBounds.width <= 0 || _viewportClipBounds.height <= 0) return 0; // Draw the text. if (_text.size() > 0 && _font) { Control::State state = getState(); float fontSize = getFontSize(state); SpriteBatch* batch = _font->getSpriteBatch(fontSize); startBatch(form, batch); _font->drawText(_text.c_str(), _textBounds, _textColor, fontSize, getTextAlignment(state), true, getTextDrawingFlags(state), _viewportClipBounds, getCharacterSpacing(state), getLineSpacing(state)); finishBatch(form, batch); return 1; } return 0; }
void BatchRenderEngine::enqueue(Renderable r, GLuint * indices) { // Check in regard to drawString function - error? unsigned int vertNum; unsigned int indNum; unsigned int i; const GLuint tid = (GLuint)r.getTid(); float ts = 0.0f; vertNum = r.getVertices().size(); indNum = (vertNum / 4) * 6; // Assumes all input renderables are sprites - fix if (vertNum + _currVerts > MAX_VERTS || indNum + _currInds > MAX_INDICES || _currTextures >= MAX_TEXTURES) // we've reached our limit, draw everything and restart { endBatch(); flush(); startBatch(); } // Error possibly here - incorrect textures if (tid > 0) { bool found = false; for (unsigned int i = 0; i < _currTextures; i++) { if (_textures[i] == tid) { ts = (float)i; found = true; break; } } if (!found) { if (_currTextures >= MAX_TEXTURES) { endBatch(); flush(); startBatch(); } ts = _currTextures * 1.0f; _textures[_currTextures] = tid * 1.0f; _currTextures++; } } else ts = -1.0f; std::vector<Vertex *> verts = r.getVertices(); if (indices == NULL) { indices = new GLuint[6]; indices[0] = 0; indices[1] = 1; indices[2] = 2; indices[3] = 2; indices[4] = 3; indices[5] = 0; indNum = 6; } // Store all verts and attributes in arrays for (i = 0; i<vertNum; i++) { _vertices[_currVerts + i].pos = *(verts[i]->GetPos()); _vertices[_currVerts + i].texCoord = *(verts[i]->GetTexCoord()); _vertices[_currVerts + i].normal = *(verts[i]->GetNormal()); _vertices[_currVerts + i].color = *(verts[i]->GetColor()); _vertices[_currVerts + i].tid = ts; } // Store all indices in an array for (i = 0; i < indNum; i++) { _indices[_currInds + i] = indices[i] + _currVerts; } _currVerts += vertNum; _currInds += indNum; }
unsigned int Slider::drawImages(Form* form, const Rectangle& clip) { if (!(_minImage && _maxImage && _markerImage && _trackImage)) return 0; // TODO: Vertical slider. // The slider is drawn in the center of the control (perpendicular to orientation). // The track is stretched according to orientation. // Caps and marker are not stretched. const Rectangle& minCapRegion = _minImage->getRegion(); const Rectangle& maxCapRegion = _maxImage->getRegion(); const Rectangle& markerRegion = _markerImage->getRegion(); const Rectangle& trackRegion = _trackImage->getRegion(); const Theme::UVs& minCap = _minImage->getUVs(); const Theme::UVs& maxCap = _maxImage->getUVs(); const Theme::UVs& marker = _markerImage->getUVs(); const Theme::UVs& track = _trackImage->getUVs(); Vector4 minCapColor = _minImage->getColor(); Vector4 maxCapColor = _maxImage->getColor(); Vector4 markerColor = _markerImage->getColor(); Vector4 trackColor = _trackImage->getColor(); Control::State state = getState(); minCapColor.w *= _opacity; maxCapColor.w *= _opacity; markerColor.w *= _opacity; trackColor.w *= _opacity; SpriteBatch* batch = _style->getTheme()->getSpriteBatch(); startBatch(form, batch); // Compute area to draw the slider track unsigned int fontSize = getFontSize(state); float startY, endY; if (_text.length() > 0) { if (_valueTextVisible) { // Both label and value text are visible. // Draw slider in the middle. startY = fontSize; endY = _viewportBounds.height - fontSize; } else { // Only label is visible if (getTextAlignment(state) & ALIGN_BOTTOM) { // Draw slider above label startY = 0; endY = _viewportBounds.height - fontSize; } else { // Draw slider below label startY = fontSize; endY = _viewportBounds.height; } } } else if (_valueTextVisible) { // Only value text is visible. if (_valueTextAlignment & ALIGN_BOTTOM) { // Draw slider above value text startY = 0; endY = _viewportBounds.height - fontSize; } else { // Draw slider below value text startY = fontSize; endY = _viewportBounds.height; } } else { // Only the slider track is visible startY = 0; endY = _viewportBounds.height; } // Compute midpoint of track location float midY = _viewportBounds.y + startY + (endY - startY) * 0.5f; // Draw track below the slider text Vector2 pos(_viewportBounds.x + minCapRegion.width, midY - trackRegion.height * 0.5f); batch->draw(pos.x, pos.y, _viewportBounds.width - minCapRegion.width - maxCapRegion.width, trackRegion.height, track.u1, track.v1, track.u2, track.v2, trackColor, _viewportClipBounds); // Draw min cap to the left of the track pos.y = midY - minCapRegion.height * 0.5f; pos.x = _viewportBounds.x; batch->draw(pos.x, pos.y, minCapRegion.width, minCapRegion.height, minCap.u1, minCap.v1, minCap.u2, minCap.v2, minCapColor, _viewportClipBounds); // Draw max cap to the right of the track pos.x = _viewportBounds.right() - maxCapRegion.width; batch->draw(pos.x, pos.y, maxCapRegion.width, maxCapRegion.height, maxCap.u1, maxCap.v1, maxCap.u2, maxCap.v2, maxCapColor, _viewportClipBounds); // Draw the marker at the correct position float markerPosition = (_value - _min) / (_max - _min); markerPosition *= _viewportBounds.width - markerRegion.width; pos.x = _viewportBounds.x + markerPosition; pos.y = midY - markerRegion.height * 0.5f; batch->draw(pos.x, pos.y, markerRegion.width, markerRegion.height, marker.u1, marker.v1, marker.u2, marker.v2, markerColor, _viewportClipBounds); finishBatch(form, batch); return 4; }