PRBool nsMenuFrame::SizeToPopup(nsBoxLayoutState& aState, nsSize& aSize) { if (!IsCollapsed(aState)) { PRBool widthSet, heightSet; nsSize tmpSize(-1, 0); nsIBox::AddCSSPrefSize(this, tmpSize, widthSet, heightSet); if (!widthSet && GetFlex(aState) == 0) { if (!mPopupFrame) return PR_FALSE; tmpSize = mPopupFrame->GetPrefSize(aState); aSize.width = tmpSize.width; // if there is a scroll frame, add the desired width of the scrollbar as well nsIScrollableFrame* scrollFrame = do_QueryFrame(mPopupFrame->GetFirstChild(nsnull)); if (scrollFrame) { aSize.width += scrollFrame->GetDesiredScrollbarSizes(&aState).LeftRight(); } return PR_TRUE; } } return PR_FALSE; }
void ewol::compositing::Image::setSource(const std::string& _newFile, const vec2& _size) { clear(); ememory::SharedPtr<ewol::resource::TextureFile> resource = m_resource; ememory::SharedPtr<ewol::resource::ImageDF> resourceDF = m_resourceDF; m_filename = _newFile; m_requestSize = _size; m_resource.reset(); m_resourceDF.reset(); ivec2 tmpSize(_size.x(),_size.y()); // note that no image can be loaded... if (_newFile != "") { // link to new one if (m_distanceFieldMode == false) { m_resource = ewol::resource::TextureFile::create(m_filename, tmpSize); if (m_resource == nullptr) { EWOL_ERROR("Can not get Image resource"); } } else { m_resourceDF = ewol::resource::ImageDF::create(m_filename, tmpSize); if (m_resourceDF == nullptr) { EWOL_ERROR("Can not get Image resource DF"); } } } if ( m_resource == nullptr && m_resourceDF == nullptr) { if (resource != nullptr) { EWOL_WARNING("Retrive previous resource"); m_resource = resource; } if (resourceDF != nullptr) { EWOL_WARNING("Retrive previous resource (DF)"); m_resourceDF = resourceDF; } } }
bool LabelTextFormatter::createStringSprites(Label *theLabel) { theLabel->_limitShowCount = 0; // check for string int stringLen = theLabel->getStringLength(); if (stringLen <= 0) return false; auto totalHeight = theLabel->_commonLineHeight * theLabel->_currNumLines; auto longestLine = 0.0f; auto nextFontPositionX = 0.0f; auto nextFontPositionY = totalHeight; auto contentScaleFactor = CC_CONTENT_SCALE_FACTOR(); if (theLabel->_labelHeight > 0) { auto labelHeightPixel = theLabel->_labelHeight * contentScaleFactor; if (totalHeight > labelHeightPixel) { int numLines = labelHeightPixel / theLabel->_commonLineHeight; totalHeight = numLines * theLabel->_commonLineHeight; } switch (theLabel->_vAlignment) { case TextVAlignment::TOP: nextFontPositionY = labelHeightPixel; break; case TextVAlignment::CENTER: nextFontPositionY = (labelHeightPixel + totalHeight) / 2.0f; break; case TextVAlignment::BOTTOM: nextFontPositionY = totalHeight; break; default: break; } } int charXOffset = 0; int charYOffset = 0; int charAdvance = 0; auto strWhole = theLabel->_currentUTF16String; auto fontAtlas = theLabel->_fontAtlas; FontLetterDefinition tempDefinition; Vec2 letterPosition; const auto& kernings = theLabel->_horizontalKernings; CCASSERT(kernings, "kernings must's be nullptr!!!"); float clipTop = 0; float clipBottom = 0; int lineIndex = 0; bool lineStart = true; bool clipBlank = false; if (theLabel->_currentLabelType == Label::LabelType::TTF && theLabel->_clipEnabled) { clipBlank = true; } for (int i = 0; i < stringLen; i++) { char16_t c = strWhole[i]; if (fontAtlas->getLetterDefinitionForChar(c, tempDefinition)) { charXOffset = tempDefinition.offsetX; charYOffset = tempDefinition.offsetY; charAdvance = tempDefinition.xAdvance; } else { charXOffset = -1; charYOffset = -1; charAdvance = -1; } if (c == '\n') { lineIndex++; nextFontPositionX = 0; nextFontPositionY -= theLabel->_commonLineHeight; theLabel->recordPlaceholderInfo(i); if(nextFontPositionY < theLabel->_commonLineHeight) break; lineStart = true; continue; } else if (clipBlank && tempDefinition.height > 0.0f) { if (lineStart) { if (lineIndex == 0) { clipTop = charYOffset; } lineStart = false; clipBottom = tempDefinition.clipBottom; } else if(tempDefinition.clipBottom < clipBottom) { clipBottom = tempDefinition.clipBottom; } if (lineIndex == 0 && charYOffset < clipTop) { clipTop = charYOffset; } } letterPosition.x = (nextFontPositionX + charXOffset + kernings[i]) / contentScaleFactor; letterPosition.y = (nextFontPositionY - charYOffset) / contentScaleFactor; if( theLabel->recordLetterInfo(letterPosition, tempDefinition, i) == false) { log("WARNING: can't find letter definition in font file for letter: %c", c); continue; } nextFontPositionX += charAdvance + theLabel->_additionalKerning; auto letterRight = letterPosition.x + tempDefinition.width; if (longestLine < letterRight) { longestLine = letterRight; } } Size tmpSize(longestLine * contentScaleFactor, totalHeight); if (theLabel->_labelHeight > 0) { tmpSize.height = theLabel->_labelHeight * contentScaleFactor; } if (clipBlank) { int clipTotal = (clipTop + clipBottom) / contentScaleFactor; tmpSize.height -= clipTotal * contentScaleFactor; clipBottom /= contentScaleFactor; for (int i = 0; i < theLabel->_limitShowCount; i++) { theLabel->_lettersInfo[i].position.y -= clipBottom; } } theLabel->setContentSize(CC_SIZE_PIXELS_TO_POINTS(tmpSize)); return true; }
void render() { const std::vector<Point>& listPosition = m_position.getValue(); const std::vector<float>& listSize = m_size.getValue(); const std::vector<Color>& listColor = m_color.getValue(); GLuint texId = m_texture.getValue().getTextureId(); int nbPosition = listPosition.size(); int nbSize = listSize.size(); int nbColor = listColor.size(); if(nbPosition && nbSize && nbColor && texId) { if(!m_shader.getValue().apply(m_shaderProgram)) return; if (!m_VAO) initGL(); m_verticesVBO.bind(); m_verticesVBO.write(listPosition); m_sizeVBO.bind(); if (nbSize < nbPosition) { std::vector<float> tmpSize(nbPosition, listSize[0]); m_sizeVBO.write(tmpSize); } else m_sizeVBO.write(listSize); m_colorsVBO.bind(); if (nbColor < nbPosition) { std::vector<types::Color> tmpColors(nbPosition, listColor[0]); m_colorsVBO.write(tmpColors); } else m_colorsVBO.write(listColor); m_VAO.bind(); glEnable(GL_POINT_SPRITE); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); m_shaderProgram.bind(); m_shaderProgram.setUniformValueMat4("MVP", getMVPMatrix().data()); glBindTexture(GL_TEXTURE_2D, texId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D ,GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); m_shaderProgram.setUniformValue("tex0", 0); glDrawArrays(GL_POINTS, 0, nbPosition); m_shaderProgram.release(); m_VAO.release(); glDisable(GL_POINT_SPRITE); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); } }