StDiagnosticsGUI::StDiagnosticsGUI(StDiagnostics* thePlugin) : StGLRootWidget(thePlugin->myResMgr), myPlugin(thePlugin), myLangMap(new StTranslations(thePlugin->myResMgr, StDiagnostics::ST_DRAWER_PLUGIN_NAME)), myGeomWidget(NULL), myFpsWidget(NULL), myCntWidgetLT(NULL), myCntWidgetBR(NULL), myFrameCounter(0) { myGeomWidget = new StGeometryTest(this); // FPS widget myFpsWidget = new StGLFpsLabel(this); myFpsWidget->signals.onBtnClick.connect(myPlugin, &StDiagnostics::doFpsClick); // counters myCntWidgetLT = new StGLTextArea(this, 32, 32, StGLCorner(ST_VCORNER_TOP, ST_HCORNER_LEFT), 128, 32); myCntWidgetBR = new StGLTextArea(this, -32, -32, StGLCorner(ST_VCORNER_BOTTOM, ST_HCORNER_RIGHT), 128, 32); myCntWidgetLT->setupAlignment(StGLTextFormatter::ST_ALIGN_X_CENTER, StGLTextFormatter::ST_ALIGN_Y_CENTER); myCntWidgetBR->setupAlignment(StGLTextFormatter::ST_ALIGN_X_CENTER, StGLTextFormatter::ST_ALIGN_Y_CENTER); myCntWidgetLT->setBorder(true); myCntWidgetBR->setBorder(true); myCntWidgetLT->setBackColor(StGLVec3(0.77f, 0.77f, 0.77f)); myCntWidgetBR->setBackColor(StGLVec3(0.77f, 0.77f, 0.77f)); myCntWidgetLT->setText("0000"); myCntWidgetBR->setText("0000"); }
bool StGLUVCylinder::computeMesh() { clearRAM(); if(myNbRings == 0) { return false; } const int aNbVerts = (myNbRings + 1) * 2; myVertices.initArray(aNbVerts); myNormals .initArray(aNbVerts); myTCoords .initArray(aNbVerts); for(int aRingIter = 0; aRingIter <= myNbRings; ++aRingIter) { const GLfloat aPhi = float(aRingIter) * float(M_PI * 2.0) / float(myNbRings); const GLfloat aTexCrd = float(aRingIter) / float(myNbRings); myTCoords.changeValue(aRingIter * 2 + 0) = StGLVec2(aTexCrd, 0.0f); myTCoords.changeValue(aRingIter * 2 + 1) = StGLVec2(aTexCrd, 1.0f); const StGLVec3 aNorm(cosf(aPhi), 0.0f, sinf(aPhi)); myNormals.changeValue(aRingIter * 2 + 0) = aNorm; myNormals.changeValue(aRingIter * 2 + 1) = aNorm; myVertices.changeValue(aRingIter * 2 + 0) = myCenter + aNorm * myRadius - StGLVec3(0.0f, myHeight * 0.5f, 0.0f); myVertices.changeValue(aRingIter * 2 + 1) = myCenter + aNorm * myRadius + StGLVec3(0.0f, myHeight * 0.5f, 0.0f); } return true; }
void StGLRootWidget::stglResize(const StGLBoxPx& theRectPx) { const bool isChanged = getRectPx().right() != theRectPx.width() || getRectPx().bottom() != theRectPx.height(); myProjCamera.resize(*myGlCtx, theRectPx.width(), theRectPx.height()); changeRectPx().right() = theRectPx.width(); // (left, top) forced to zero point (0, 0) changeRectPx().bottom() = theRectPx.height(); myProjCamera.getZParams(myRectGl); myScaleGlX = (myRectGl.right() - myRectGl.left()) / GLdouble(getRectPx().width()); myScaleGlY = (myRectGl.top() - myRectGl.bottom()) / GLdouble(getRectPx().height()); myScrProjMat = myProjCamera.getProjMatrix(); myScrProjMat.translate(StGLVec3(0.0f, 0.0f, -myProjCamera.getZScreen())); if(myMenuProgram->isValid()) { myMenuProgram->use(*myGlCtx); myMenuProgram->setProjMat(*myGlCtx, getScreenProjection()); myMenuProgram->unuse(*myGlCtx); } // update all child widgets if(isChanged) { StGLWidget::stglResize(); } }
bool StGLRangeFieldFloat32::stglInit() { if(myValueText != NULL) { return true; } myValueText = new StGLTextArea(this, 0, 0, StGLCorner(ST_VCORNER_CENTER, ST_HCORNER_LEFT), -myRoot->scale(1), myRoot->scale(10)); onValueChange(0.0f); myValueText->setTextColor(StGLVec3(1.0f, 1.0f, 1.0f)); myValueText->setVisibility(true, true); if(!myValueText->stglInitAutoHeightWidth()) { delete myValueText; myValueText = NULL; return false; } myValueText->changeRectPx().right() += myRoot->scale(10); myValueText->setTextWidth(myValueText->getRectPx().width()); myValueText->setupAlignment(StGLTextFormatter::ST_ALIGN_X_RIGHT, StGLTextFormatter::ST_ALIGN_Y_TOP); onValueChange(myTrackValue->getValue()); const GLint aHeight = myValueText->getRectPx().height(); StGLButton* aButDec = new StGLButton(this, 0, 0, "-"); aButDec->setCorner(StGLCorner(ST_VCORNER_CENTER, ST_HCORNER_LEFT)); aButDec->setHeight(aHeight); aButDec->setWidth(myRoot->scale(15)); aButDec->setVisibility(true, true); aButDec->signals.onBtnClick += stSlot(this, &StGLRangeFieldFloat32::doDecrement); myValueText->changeRectPx().moveLeftTo(aButDec->getRectPx().right() - myRoot->scale(5)); StGLButton* aButInc = new StGLButton(this, myValueText->getRectPx().right() + myRoot->scale(5), 0, "+"); aButInc->setCorner(StGLCorner(ST_VCORNER_CENTER, ST_HCORNER_LEFT)); aButInc->setHeight(aHeight); aButInc->setWidth(myRoot->scale(15)); aButInc->setVisibility(true, true); aButInc->signals.onBtnClick += stSlot(this, &StGLRangeFieldFloat32::doIncrement); changeRectPx().right() = getRectPx().left() + aButInc->getRectPx().right(); changeRectPx().bottom() = getRectPx().top() + aHeight; return StGLWidget::stglInit(); }
void StBndBox::reset() { StBndContainer::reset(); myMin = StGLVec3(); myMax = StGLVec3(); }
void StGeometryTest::resizeGrid(const StRectI_t& winRectPx) { StGLContext& aCtx = getContext(); // grid size_t linesCountV = 16 + 1; size_t cellSizePx = 10; size_t linesCountH = 16 + 1; if(winRectPx.width() > winRectPx.height()) { cellSizePx = winRectPx.width() / (linesCountV - 1); linesCountH = (winRectPx.height() / cellSizePx) + 1; } else { cellSizePx = winRectPx.height() / (linesCountH - 1); linesCountV = (winRectPx.width() / cellSizePx) + 1; } myCellSize.x() = 2.0f * GLfloat(cellSizePx) / GLfloat(winRectPx.width()); myCellSize.y() = 2.0f * GLfloat(cellSizePx) / GLfloat(winRectPx.height()); size_t vertixesCount = (linesCountH + linesCountV) * 2; StArray<StGLVec4> vertArray(vertixesCount); // insert black gap to make quads StGLVec2 blackGap(GLfloat(winRectPx.width() - cellSizePx * (linesCountV - 1)) / GLfloat(winRectPx.width()), GLfloat(winRectPx.height() - cellSizePx * (linesCountH - 1)) / GLfloat(winRectPx.height())); StGLVec2 bottomLeft = StGLVec2(-1.0f) + blackGap; StGLVec2 fat = StGLVec2( 2.0f) - blackGap * 2.0f; // horizontal lines for(size_t lineId = 0; lineId < linesCountH; ++lineId) { GLfloat anY = bottomLeft.y() + fat.y() * (GLfloat(lineId) / GLfloat(linesCountH - 1)); vertArray[2 * lineId] = StGLVec4(-1.0f, anY, 0.0f, 1.0f); vertArray[2 * lineId + 1] = StGLVec4( 1.0f, anY, 0.0f, 1.0f); } // vertical lines for(size_t lineId = 0; lineId < linesCountV; ++lineId) { GLfloat anX = bottomLeft.x() + fat.x() * (GLfloat(lineId) / GLfloat(linesCountV - 1)); vertArray[2 * linesCountH + 2 * lineId] = StGLVec4(anX, -1.0f, 0.0f, 1.0f); vertArray[2 * linesCountH + 2 * lineId + 1] = StGLVec4(anX, 1.0f, 0.0f, 1.0f); } myGrid.changeVBO(ST_VBO_VERTEX)->init(aCtx, vertArray); // white color StArray<StGLVec4> lColorsArray(vertixesCount, StGLVec4(1.0f)); myGrid.changeVBO(ST_VBO_COLORS)->init(aCtx, lColorsArray); // bottom left circle myCircles[0].create(StGLVec3(bottomLeft + myCellSize), myCellSize.x(), myCellSize.y(), 64); // bottom right circle myCircles[1].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(GLfloat(linesCountV - 2), 1.0f)), myCellSize.x(), myCellSize.y(), 64); // top left circle myCircles[2].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(1.0f, GLfloat(linesCountH - 2))), myCellSize.x(), myCellSize.y(), 64); // top right circle myCircles[3].create(StGLVec3(bottomLeft + myCellSize * StGLVec2(GLfloat(linesCountV - 2), GLfloat(linesCountH - 2))), myCellSize.x(), myCellSize.y(), 64); // center circle GLfloat minSize = 0.5f * (((linesCountV < linesCountH) ? linesCountV : linesCountH) - 1); myCircles[4].create(StGLVec3(0.0f), myCellSize.x() * minSize, myCellSize.y() * minSize, 64); // white color for(size_t aCircleId = 0; aCircleId < 5; ++aCircleId) { myCircles[aCircleId].computeMesh(); myCircles[aCircleId].initColorsArray(StGLVec4(1.0f)); myCircles[aCircleId].initVBOs(aCtx); } }