void GuiGradientCtrl::onRender(Point2I offset, const RectI& updateRect) { if (mStateBlock.isNull()) { GFXStateBlockDesc desc; desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha); desc.setZReadWrite(false); desc.zWriteEnable = false; desc.setCullMode(GFXCullNone); mStateBlock = GFX->createStateBlock( desc ); } RectI boundsRect(offset, getExtent()); renderColorBox(boundsRect); if (mPositionChanged) { mPositionChanged = false; // Now do onAction() if we are allowed if (mActionOnMove) onAction(); } //render the children renderChildControls( offset, updateRect); }
void GuiConsoleTextCtrl::onRender( Point2I offset, const RectI &updateRect ) { RectI ctrlRect( offset, getExtent() ); // if opaque, fill the update rect with the fill color if ( mProfile->mOpaque ) GFX->getDrawUtil()->drawRectFill( ctrlRect, mProfile->mFillColor ); // if there's a border, draw the border if ( mProfile->mBorder ) renderBorder( ctrlRect, mProfile ); // If we have text to render. if ( mResult.isNotEmpty() ) { GFont *font = mProfile->mFont; GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor ); for ( U32 i = 0; i < mLineLen.size(); i++ ) { Point2I tempOffset = offset; tempOffset += mProfile->mTextOffset; tempOffset.y += i * font->getHeight(); const UTF8 *line = mResult.c_str() + mStartLineOffset[i]; U32 lineLen = mLineLen[i]; GFX->getDrawUtil()->drawTextN( font, tempOffset, line, lineLen, mProfile->mFontColors ); } } // render the child controlsmResult renderChildControls(offset, updateRect); }
void FGControl::onRender(GFXSurface *sfc, Point2I offset, const Box2I &updateRect) { bool ghosted = FALSE; SimGui::Control *topDialog = root->getDialogNumber(1); if (topDialog && (topDialog != getTopMostParent()) && (topDialog->findControlWithTag(IDCTG_DIALOG))) { ghosted = TRUE; } //if opaque, fill the update rect with the fill color if (mbOpaque) { sfc->drawRect2d_f(&RectI(offset, Point2I(offset.x + extent.x - 1, offset.y + extent.y - 1)), (! ghosted ? fillColor : ghostFillColor)); } //if there's a boarder, draw the boarder if (mbBoarder) { sfc->drawRect2d(&RectI(offset, Point2I(offset.x + extent.x - 1, offset.y + extent.y - 1)), (! ghosted ? boarderColor : ghostBoarderColor)); } renderChildControls(sfc, offset, updateRect); }
void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) { if (mStateBlock.isNull()) { GFXStateBlockDesc desc; desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha); desc.setZReadWrite(false); desc.zWriteEnable = false; desc.setCullMode(GFXCullNone); mStateBlock = GFX->createStateBlock( desc ); } RectI boundsRect(offset, getExtent()); renderColorBox(boundsRect); if (mPositionChanged) { mPositionChanged = false; Point2I extent = getRoot()->getExtent(); // If we are anything but a pallete, change the pick color if (mDisplayMode != pPallet) { Point2I resolution = getRoot()->getExtent(); U32 buf_x = offset.x + mSelectorPos.x + 1; U32 buf_y = ( extent.y - ( offset.y + mSelectorPos.y + 1 ) ); if(GFX->getAdapterType() != OpenGL) buf_y = resolution.y - buf_y; GFXTexHandle bb( resolution.x, resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) ); Point2I tmpPt( buf_x, buf_y ); GFXTarget *targ = GFX->getActiveRenderTarget(); targ->resolveTo( bb ); GBitmap bmp( bb.getWidth(), bb.getHeight() ); bb.copyToBmp( &bmp ); //bmp.writePNGDebug( "foo.png" ); ColorI tmp; bmp.getColor( buf_x, buf_y, tmp ); mPickColor = (ColorF)tmp; // Now do onAction() if we are allowed if (mActionOnMove) onAction(); } } //render the children renderChildControls( offset, updateRect); }
void GuiRolloutCtrl::onRender( Point2I offset, const RectI &updateRect ) { if( !mProfile || mProfile->mFont == NULL ) return; // Calculate actual world bounds for rendering RectI worldBounds( offset, getExtent() ); // if opaque, fill the update rect with the fill color if ( mProfile->mOpaque ) GFX->getDrawUtil()->drawRectFill( worldBounds, mProfile->mFillColor ); if ( mProfile->mBitmapArrayRects.size() >= NumBitmaps ) { GFX->getDrawUtil()->clearBitmapModulation(); // Draw Rollout From Skin if ( !mIsExpanded && !mIsAnimating ) renderFixedBitmapBordersFilled( worldBounds, 1, mProfile ); else if ( mHideHeader ) renderSizableBitmapBordersFilledIndex( worldBounds, MidPageLeft, mProfile ); else renderSizableBitmapBordersFilledIndex( worldBounds, TopLeftHeader, mProfile ); } if ( !(mIsExpanded && mHideHeader ) ) { // Draw Caption ( Vertically Centered ) ColorI currColor; GFX->getDrawUtil()->getBitmapModulation( &currColor ); Point2I textPosition = mHeader.point + offset + mProfile->mTextOffset; GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor ); renderJustifiedText( textPosition, mHeader.extent, mCaption ); GFX->getDrawUtil()->setBitmapModulation( currColor ); } // If we're collapsed we contain the first child as our content // thus we don't render it when collapsed. but to support modified // rollouts with custom header buttons etc we still render our other // children. -JDD GuiControl *pChild = dynamic_cast<GuiControl*>( at(0) ); if ( pChild ) { if ( !mIsExpanded && !mIsAnimating && pChild->isVisible() ) { pChild->setVisible( false ); } else if ( (mIsExpanded || mIsAnimating) && !pChild->isVisible() ) { pChild->setVisible( true ); } } renderChildControls( offset, updateRect ); // Render our border should we have it specified in our profile. renderBorder(worldBounds, mProfile); }
void TestButton::onRender(GFXSurface *sfc, Point2I offset, const Box2I &updateRect) { GFXFont *useFont = (stateOver) ? hFontHL : hFont; Int32 backColor = 249; Int32 insideBorderColor = (root->getFirstResponder() == this) ? 245 : 255; Int32 outsideBorderColor = 249; if (useFont) { Int32 txt_w = useFont->getStrWidth(text); Point2I localStart; // align the horizontal switch (alignment) { case RightJustify: localStart.x = extent.x - txt_w; break; case CenterJustify: localStart.x = (extent.x - txt_w) / 2; break; default: // LeftJustify localStart.x = 0; } // center the vertical localStart.y = (extent.y - useFont->getHeight()) / 2; // first draw the background RectI r(offset.x, offset.y, offset.x + extent.x - 1, offset.y + extent.y - 1); r.upperL+=2; r.lowerR-=2; sfc->drawRect2d_f(&r, backColor); // draw the inside border r.upperL-=1; r.lowerR+=1; drawBorder(sfc, r, insideBorderColor); // draw the oustside border r.upperL-=1; r.lowerR+=1; drawBorder(sfc, r, outsideBorderColor); // finally draw the text localStart.y += textVPosDelta; if (stateDepressed) localStart+=1; Point2I globalStart = localToGlobalCoord(localStart); sfc->drawText_p(useFont, &globalStart, text); } renderChildControls(sfc, offset, updateRect); }
//-------------------------------------------------------------------------- void GuiSeparatorCtrl::onRender(Point2I offset, const RectI &updateRect) { Parent::onRender( offset, updateRect ); if( mInvisible ) return; if( mText.isNotEmpty() && mSeparatorType != separatorTypeVertical ) { // If text is present and we have a left margin, then draw some separator, then the // text, and then the rest of the separator. S32 posx = offset.x + mMargin; S32 fontheight = mProfile->mFont->getHeight(); S32 seppos = (fontheight - 2) / 2 + offset.y; if( mTextLeftMargin > 0 ) { RectI rect( Point2I( posx, seppos ), Point2I( mTextLeftMargin, 2 ) ); renderSlightlyLoweredBox(rect, mProfile); posx += mTextLeftMargin; } GFX->getDrawUtil()->setBitmapModulation( mProfile->mFontColor ); posx = GFX->getDrawUtil()->drawText(mProfile->mFont, Point2I(posx,offset.y), mText, mProfile->mFontColors); RectI rect( Point2I( posx, seppos ), Point2I( getWidth() - posx + offset.x, 2 ) ); // Space text and separator a bit apart at right end. rect.point.x += 2; rect.extent.x -= 2; if( rect.extent.x > 0 ) renderSlightlyLoweredBox( rect, mProfile ); } else { if( mSeparatorType == separatorTypeHorizontal ) { S32 seppos = getHeight() / 2 + offset.y; RectI rect(Point2I(offset.x + mMargin ,seppos),Point2I(getWidth() - (mMargin * 2),2)); renderSlightlyLoweredBox(rect, mProfile); } else { S32 seppos = getWidth() / 2 + offset.x; RectI rect(Point2I(seppos, offset.y + mMargin),Point2I(2, getHeight() - (mMargin * 2))); renderSlightlyLoweredBox(rect, mProfile); } } renderChildControls(offset, updateRect); }
//------------------------------------------------------------------------------ void SmackerCtrl::onRender(GFXSurface *sfc, Point2I offset, const Box2I &updateRect) { update(sfc); if (smk && bmp) { Box2I box; if (stretch) box(offset.x, offset.y, offset.x + extent.x, offset.y + extent.y); else box(offset.x, offset.y, offset.x + bmp->getWidth(), offset.y + bmp->getHeight()); cBmp.drawBitmap(sfc, box); } renderChildControls(sfc, offset, updateRect); }
void GuiBitmapCtrl::onRender(Point2I offset, const RectI &updateRect) { GFXDEBUGEVENT_SCOPE_EX( GuiBitmapCtrl_onRender, ColorI::GREEN, avar("GuiBitmapCtrl: %s", mBitmapName.c_str()) ); if (mTextureObject) { GFX->getDrawUtil()->clearBitmapModulation(); if(mWrap) { // We manually draw each repeat because non power of two textures will // not tile correctly when rendered with GFX->drawBitmapTile(). The non POT // bitmap will be padded by the hardware, and we'll see lots of slack // in the texture. So... lets do what we must: draw each repeat by itself: GFXTextureObject* texture = mTextureObject; RectI srcRegion; RectI dstRegion; float xdone = ((float)getExtent().x/(float)texture->mBitmapSize.x)+1; float ydone = ((float)getExtent().y/(float)texture->mBitmapSize.y)+1; int xshift = mStartPoint.x%texture->mBitmapSize.x; int yshift = mStartPoint.y%texture->mBitmapSize.y; for(int y = 0; y < ydone; ++y) for(int x = 0; x < xdone; ++x) { srcRegion.set(0,0,texture->mBitmapSize.x,texture->mBitmapSize.y); dstRegion.set( ((texture->mBitmapSize.x*x)+offset.x)-xshift, ((texture->mBitmapSize.y*y)+offset.y)-yshift, texture->mBitmapSize.x, texture->mBitmapSize.y); GFX->getDrawUtil()->drawBitmapStretchSR(texture,dstRegion, srcRegion, GFXBitmapFlip_None, GFXTextureFilterLinear); } } else { RectI rect(offset, getExtent()); GFX->getDrawUtil()->drawBitmapStretch(mTextureObject, rect, GFXBitmapFlip_None, GFXTextureFilterLinear, false); } } if (mProfile->mBorder || !mTextureObject) { RectI rect(offset.x, offset.y, getExtent().x, getExtent().y); GFX->getDrawUtil()->drawRect(rect, mProfile->mBorderColor); } renderChildControls(offset, updateRect); }
//-------------------------------------------------------------------------- void GuiRectHandles::onRender(Point2I offset, const RectI &updateRect) { Parent::onRender( offset, updateRect ); ColorI handleColor = mProfile->mBorderColor; if(mUseCustomColor) handleColor = mHandleColor; // The handles range from 0-1, so scale to fit within the // control's bounds. const Point2I& extent = getExtent(); Point2I pos(extent.x*mHandleRect.point.x, extent.y*mHandleRect.point.y); Point2I size(extent.x*mHandleRect.extent.x, extent.y*mHandleRect.extent.y); RectI box(offset+pos, size); // Draw border GFX->getDrawUtil()->drawRect(box, handleColor); // Draw each handle Point2I handleSize(mHandleSize, mHandleSize); RectI handleRect(box.point, handleSize); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Upper left handleRect.point = Point2I(box.point.x+size.x-handleSize.x, box.point.y); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Upper right handleRect.point = Point2I(box.point.x, box.point.y+size.y-handleSize.y); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Lower left handleRect.point = Point2I(box.point.x+size.x-handleSize.x, box.point.y+size.y-handleSize.y); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Lower right Point2I halfSize = size / 2; Point2I halfHandleSize = handleSize / 2; handleRect.point = Point2I(box.point.x+halfSize.x-halfHandleSize.x, box.point.y); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Upper middle handleRect.point = Point2I(box.point.x+halfSize.x-halfHandleSize.x, box.point.y+size.y-handleSize.y); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Lower middle handleRect.point = Point2I(box.point.x, box.point.y+halfSize.y-halfHandleSize.y); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Left middle handleRect.point = Point2I(box.point.x+size.x-handleSize.x, box.point.y+halfSize.y-halfHandleSize.y); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Right middle handleRect.point = Point2I(box.point.x+halfSize.x-halfHandleSize.x, box.point.y+halfSize.y-halfHandleSize.y); GFX->getDrawUtil()->drawRectFill(handleRect, handleColor); // Middle renderChildControls(offset, updateRect); }
void GuiTheoraCtrl::onRender(Point2I offset, const RectI &updateRect) { if( mDone && mIsLooping ) mTheoraTexture.play(); const RectI rect(offset, getBounds().extent); if( mTheoraTexture.isReady() ) { mTheoraTexture.refresh(); if( mTheoraTexture.isPlaying() || mTheoraTexture.isPaused() ) { // Draw the frame. GFXDrawUtil* drawUtil = GFX->getDrawUtil(); drawUtil->clearBitmapModulation(); drawUtil->drawBitmapStretch( mTheoraTexture.getTexture(), rect ); // Draw frame info, if requested. if( mRenderDebugInfo ) { String info = String::ToString( "Frame Number: %i | Frame Time: %.2fs | Playback Time: %.2fs | Dropped: %i", mTheoraTexture.getFrameNumber(), mTheoraTexture.getFrameTime(), F32( mTheoraTexture.getPosition() ) / 1000.f, mTheoraTexture.getNumDroppedFrames() ); drawUtil->setBitmapModulation( mProfile->mFontColors[ 0 ] ); drawUtil->drawText( mProfile->mFont, localToGlobalCoord( Point2I( 0, 0 ) ), info, mProfile->mFontColors ); } } else mDone = true; } else GFX->getDrawUtil()->drawRectFill(rect, mBackgroundColor); // black rect renderChildControls(offset, updateRect); }
void GuiProgressCtrl::onRender(Point2I offset, const RectI &updateRect) { RectI ctrlRect(offset, getExtent()); //draw the progress S32 width = (S32)((F32)(getWidth()) * mProgress); if (width > 0) { RectI progressRect = ctrlRect; progressRect.extent.x = width; GFX->getDrawUtil()->drawRectFill(progressRect, mProfile->mFillColor); } //now draw the border if (mProfile->mBorder) GFX->getDrawUtil()->drawRect(ctrlRect, mProfile->mBorderColor); Parent::onRender( offset, updateRect ); //render the children renderChildControls(offset, updateRect); }
void GuiBorderButtonCtrl::onRender(Point2I offset, const RectI &updateRect) { if ( mProfile->mBorder > 0 ) { RectI bounds( offset, getExtent() ); for ( S32 i=0; i < mProfile->mBorderThickness; i++ ) { GFX->getDrawUtil()->drawRect( bounds, mProfile->mBorderColor ); bounds.inset( 1, 1 ); } } if ( mActive ) { if ( mStateOn || mDepressed ) { RectI bounds( offset, getExtent() ); for ( S32 i=0; i < mProfile->mBorderThickness; i++ ) { GFX->getDrawUtil()->drawRect( bounds, mProfile->mFontColorSEL ); bounds.inset( 1, 1 ); } } if ( mMouseOver ) { RectI bounds( offset, getExtent() ); for ( S32 i=0; i < mProfile->mBorderThickness; i++ ) { GFX->getDrawUtil()->drawRect( bounds, mProfile->mFontColorHL ); bounds.inset( 1, 1 ); } } } renderChildControls( offset, updateRect ); }
void GuiTSCtrl::onRender(Point2I offset, const RectI &updateRect) { // Save the current transforms so we can restore // it for child control rendering below. GFXTransformSaver saver; bool renderingToTarget = false; if(!processCameraQuery(&mLastCameraQuery)) { // We have no camera, but render the GUI children // anyway. This makes editing GuiTSCtrl derived // controls easier in the GuiEditor. renderChildControls( offset, updateRect ); return; } GFXTargetRef origTarget = GFX->getActiveRenderTarget(); // Set up the appropriate render style U32 prevRenderStyle = GFX->getCurrentRenderStyle(); Point2F prevProjectionOffset = GFX->getCurrentProjectionOffset(); Point2I renderSize = getExtent(); if(mRenderStyle == RenderStyleStereoSideBySide) { GFX->setCurrentRenderStyle(GFXDevice::RS_StereoSideBySide); GFX->setCurrentProjectionOffset(mLastCameraQuery.projectionOffset); GFX->setStereoEyeOffsets(mLastCameraQuery.eyeOffset); if (!mLastCameraQuery.hasStereoTargets) { // Need to calculate our current viewport here mLastCameraQuery.stereoViewports[0] = updateRect; mLastCameraQuery.stereoViewports[0].extent.x /= 2; mLastCameraQuery.stereoViewports[1] = mLastCameraQuery.stereoViewports[0]; mLastCameraQuery.stereoViewports[1].point.x += mLastCameraQuery.stereoViewports[1].extent.x; } if (!mLastCameraQuery.hasFovPort) { // Need to make our own fovPort mLastCameraQuery.fovPort[0] = CalculateFovPortForCanvas(mLastCameraQuery.stereoViewports[0], mLastCameraQuery); mLastCameraQuery.fovPort[1] = CalculateFovPortForCanvas(mLastCameraQuery.stereoViewports[1], mLastCameraQuery); } GFX->setStereoFovPort(mLastCameraQuery.fovPort); // NOTE: this specifies fov for BOTH eyes GFX->setSteroViewports(mLastCameraQuery.stereoViewports); GFX->setStereoTargets(mLastCameraQuery.stereoTargets); MatrixF myTransforms[2]; if (smUseLatestDisplayTransform) { // Use the view matrix determined from the display device myTransforms[0] = mLastCameraQuery.eyeTransforms[0]; myTransforms[1] = mLastCameraQuery.eyeTransforms[1]; } else { // Use the view matrix determined from the control object myTransforms[0] = mLastCameraQuery.cameraMatrix; myTransforms[1] = mLastCameraQuery.cameraMatrix; QuatF qrot = mLastCameraQuery.cameraMatrix; Point3F pos = mLastCameraQuery.cameraMatrix.getPosition(); Point3F rotEyePos; myTransforms[0].setPosition(pos + qrot.mulP(mLastCameraQuery.eyeOffset[0], &rotEyePos)); myTransforms[1].setPosition(pos + qrot.mulP(mLastCameraQuery.eyeOffset[1], &rotEyePos)); } GFX->setStereoEyeTransforms(myTransforms); // Allow render size to originate from the render target if (mLastCameraQuery.stereoTargets[0]) { renderSize = mLastCameraQuery.stereoViewports[0].extent; renderingToTarget = true; } } else { GFX->setCurrentRenderStyle(GFXDevice::RS_Standard); } if ( mReflectPriority > 0 ) { // Get the total reflection priority. F32 totalPriority = 0; for ( U32 i=0; i < smAwakeTSCtrls.size(); i++ ) if ( smAwakeTSCtrls[i]->isVisible() ) totalPriority += smAwakeTSCtrls[i]->mReflectPriority; REFLECTMGR->update( mReflectPriority / totalPriority, getExtent(), mLastCameraQuery ); } if(mForceFOV != 0) mLastCameraQuery.fov = mDegToRad(mForceFOV); if(mCameraZRot) { MatrixF rotMat(EulerF(0, 0, mDegToRad(mCameraZRot))); mLastCameraQuery.cameraMatrix.mul(rotMat); } Frustum frustum; if(mRenderStyle == RenderStyleStereoSideBySide) { // NOTE: these calculations are essentially overridden later by the fov port settings when rendering each eye. MathUtils::makeFovPortFrustum(&frustum, mLastCameraQuery.ortho, mLastCameraQuery.nearPlane, mLastCameraQuery.farPlane, mLastCameraQuery.fovPort[0]); } else { // set up the camera and viewport stuff: F32 wwidth; F32 wheight; F32 renderWidth = F32(renderSize.x); F32 renderHeight = F32(renderSize.y); F32 aspectRatio = renderWidth / renderHeight; // Use the FOV to calculate the viewport height scale // then generate the width scale from the aspect ratio. if(!mLastCameraQuery.ortho) { wheight = mLastCameraQuery.nearPlane * mTan(mLastCameraQuery.fov / 2.0f); wwidth = aspectRatio * wheight; } else { wheight = mLastCameraQuery.fov; wwidth = aspectRatio * wheight; } F32 hscale = wwidth * 2.0f / renderWidth; F32 vscale = wheight * 2.0f / renderHeight; F32 left = (updateRect.point.x - offset.x) * hscale - wwidth; F32 right = (updateRect.point.x + updateRect.extent.x - offset.x) * hscale - wwidth; F32 top = wheight - vscale * (updateRect.point.y - offset.y); F32 bottom = wheight - vscale * (updateRect.point.y + updateRect.extent.y - offset.y); frustum.set( mLastCameraQuery.ortho, left, right, top, bottom, mLastCameraQuery.nearPlane, mLastCameraQuery.farPlane ); } // Manipulate the frustum for tiled screenshots const bool screenShotMode = gScreenShot && gScreenShot->isPending(); if ( screenShotMode ) { gScreenShot->tileFrustum( frustum ); GFX->setViewMatrix(MatrixF::Identity); } RectI tempRect = updateRect; if (!renderingToTarget) { #ifdef TORQUE_OS_MAC Point2I screensize = getRoot()->getWindowSize(); tempRect.point.y = screensize.y - (tempRect.point.y + tempRect.extent.y); #endif GFX->setViewport( tempRect ); } else { // Activate stereo RT GFX->activateStereoTarget(-1); } // Clear the zBuffer so GUI doesn't hose object rendering accidentally GFX->clear( GFXClearZBuffer , ColorI(20,20,20), 1.0f, 0 ); //GFX->clear( GFXClearTarget, ColorI(255,0,0), 1.0f, 0); GFX->setFrustum( frustum ); if(mLastCameraQuery.ortho) { mOrthoWidth = frustum.getWidth(); mOrthoHeight = frustum.getHeight(); } // We're going to be displaying this render at size of this control in // pixels - let the scene know so that it can calculate e.g. reflections // correctly for that final display result. gClientSceneGraph->setDisplayTargetResolution(renderSize); // Set the GFX world matrix to the world-to-camera transform, but don't // change the cameraMatrix in mLastCameraQuery. This is because // mLastCameraQuery.cameraMatrix is supposed to contain the camera-to-world // transform. In-place invert would save a copy but mess up any GUIs that // depend on that value. MatrixF worldToCamera = mLastCameraQuery.cameraMatrix; worldToCamera.inverse(); GFX->setWorldMatrix( worldToCamera ); mSaveProjection = GFX->getProjectionMatrix(); mSaveModelview = GFX->getWorldMatrix(); mSaveViewport = updateRect; mSaveWorldToScreenScale = GFX->getWorldToScreenScale(); mSaveFrustum = GFX->getFrustum(); mSaveFrustum.setTransform( mLastCameraQuery.cameraMatrix ); // Set the default non-clip projection as some // objects depend on this even in non-reflect cases. gClientSceneGraph->setNonClipProjection( mSaveProjection ); // Give the post effect manager the worldToCamera, and cameraToScreen matrices PFXMGR->setFrameMatrices( mSaveModelview, mSaveProjection ); renderWorld(updateRect); DebugDrawer::get()->render(); // Render the canvas overlay if its available if (mRenderStyle == RenderStyleStereoSideBySide && mStereoGuiTarget.getPointer()) { GFXDEBUGEVENT_SCOPE( StereoGui_Render, ColorI( 255, 0, 0 ) ); MatrixF proj(1); Frustum originalFrustum = GFX->getFrustum(); GFXTextureObject *texObject = mStereoGuiTarget->getTexture(0); const FovPort *currentFovPort = GFX->getStereoFovPort(); const MatrixF *eyeTransforms = GFX->getStereoEyeTransforms(); const Point3F *eyeOffset = GFX->getStereoEyeOffsets(); Frustum gfxFrustum = originalFrustum; for (U32 i=0; i<2; i++) { GFX->activateStereoTarget(i); MathUtils::makeFovPortFrustum(&gfxFrustum, true, gfxFrustum.getNearDist(), gfxFrustum.getFarDist(), currentFovPort[i], eyeTransforms[i]); GFX->setFrustum(gfxFrustum); MatrixF eyeWorldTrans(1); eyeWorldTrans.setPosition(Point3F(eyeOffset[i].x,eyeOffset[i].y,eyeOffset[i].z)); MatrixF eyeWorld(1); eyeWorld.mul(eyeWorldTrans); eyeWorld.inverse(); GFX->setWorldMatrix(eyeWorld); GFX->setViewMatrix(MatrixF::Identity); if (!mStereoOverlayVB.getPointer()) { mStereoOverlayVB.set(GFX, 4, GFXBufferTypeStatic); GFXVertexPCT *verts = mStereoOverlayVB.lock(0, 4); F32 texLeft = 0.0f; F32 texRight = 1.0f; F32 texTop = 1.0f; F32 texBottom = 0.0f; F32 rectRatio = gfxFrustum.getWidth() / gfxFrustum.getHeight(); F32 rectWidth = gfxFrustum.getWidth() * TS_OVERLAY_SCREEN_WIDTH; F32 rectHeight = rectWidth * rectRatio; F32 screenLeft = -rectWidth * 0.5; F32 screenRight = rectWidth * 0.5; F32 screenTop = -rectHeight * 0.5; F32 screenBottom = rectHeight * 0.5; const F32 fillConv = 0.0f; const F32 frustumDepthAdjusted = gfxFrustum.getNearDist() + 0.012; verts[0].point.set( screenLeft - fillConv, frustumDepthAdjusted, screenTop - fillConv ); verts[1].point.set( screenRight - fillConv, frustumDepthAdjusted, screenTop - fillConv ); verts[2].point.set( screenLeft - fillConv, frustumDepthAdjusted, screenBottom - fillConv ); verts[3].point.set( screenRight - fillConv, frustumDepthAdjusted, screenBottom - fillConv ); verts[0].color = verts[1].color = verts[2].color = verts[3].color = ColorI(255,255,255,255); verts[0].texCoord.set( texLeft, texTop ); verts[1].texCoord.set( texRight, texTop ); verts[2].texCoord.set( texLeft, texBottom ); verts[3].texCoord.set( texRight, texBottom ); mStereoOverlayVB.unlock(); } if (!mStereoGuiSB.getPointer()) { // DrawBitmapStretchSR GFXStateBlockDesc bitmapStretchSR; bitmapStretchSR.setCullMode(GFXCullNone); bitmapStretchSR.setZReadWrite(false, false); bitmapStretchSR.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha); bitmapStretchSR.samplersDefined = true; bitmapStretchSR.samplers[0] = GFXSamplerStateDesc::getClampLinear(); bitmapStretchSR.samplers[0].minFilter = GFXTextureFilterPoint; bitmapStretchSR.samplers[0].mipFilter = GFXTextureFilterPoint; bitmapStretchSR.samplers[0].magFilter = GFXTextureFilterPoint; mStereoGuiSB = GFX->createStateBlock(bitmapStretchSR); } GFX->setVertexBuffer(mStereoOverlayVB); GFX->setStateBlock(mStereoGuiSB); GFX->setTexture( 0, texObject ); GFX->setupGenericShaders( GFXDevice::GSModColorTexture ); GFX->drawPrimitive( GFXTriangleStrip, 0, 2 ); } } // Restore the previous matrix state before // we begin rendering the child controls. saver.restore(); // Restore the render style and any stereo parameters GFX->setActiveRenderTarget(origTarget); GFX->setCurrentRenderStyle(prevRenderStyle); GFX->setCurrentProjectionOffset(prevProjectionOffset); if(mRenderStyle == RenderStyleStereoSideBySide && gLastStereoTexture) { GFX->setClipRect(updateRect); GFX->getDrawUtil()->drawBitmapStretch(gLastStereoTexture, updateRect); } // Allow subclasses to render 2D elements. GFX->setClipRect(updateRect); renderGui( offset, updateRect ); if (shouldRenderChildControls()) { renderChildControls(offset, updateRect); } smFrameCount++; }
void TestControl::onRender(GFXSurface *sfc, Point2I offset, const Box2I &updateRect) { RectI r(offset.x, offset.y, offset.x + extent.x - 1, offset.y + extent.y - 1); sfc->drawRect2d_f(&r, hilight + 1); renderChildControls(sfc, offset, updateRect); }
void ShapeView::onRender(GFXSurface *sfc, Point2I offset, const Box2I &) { Box2I box; RectI rect; TMat3F mat, mat2; Point3F lightpos, lightaim, screen[4]; if (instance) { // Create the camera / light transform mat.identity(); mat.p.set(0.0f, -rDist, 0.0f); // Orient rotation around a FIXED point -- looks much nicer m_mul(mat, RMat3F(EulerF(rotation.x, rotation.y, -rotation.z)), &mat2); mat2.flags |= TMat3F::Matrix_HasTranslation | TMat3F::Matrix_HasRotation; lightpos = mat2.p; mat2.inverse(); camera->setTWC(mat2); // Drop the light light->setPosition(lightpos); lightaim = center - lightpos; lightaim.normalize(); light->setAim(lightaim); // Set up the render context context.setCamera(camera); points.reset(); context.setPointArray(&points); context.setSurface(sfc); context.setLights(scene); // Lock the context and begin drawing context.lock(); sfc->draw3DBegin(); // Have to clear the background screen[0].set(offset.x, offset.y, 0.0f); screen[1].set(offset.x + extent.x, offset.y, 0.0f); screen[2].set(offset.x + extent.x, offset.y + extent.y, 0.0f); screen[3].set(offset.x, offset.y + extent.y, 0.0f); // Tell our nifty-keen hardware how to draw sfc->setHazeSource (GFX_HAZE_NONE); sfc->setShadeSource(GFX_SHADE_NONE); sfc->setAlphaSource(GFX_ALPHA_NONE); sfc->setFillMode (GFX_FILL_CONSTANT); sfc->setFillColor (Int32(0)); sfc->setZTest (GFX_ZWRITE); sfc->addVertex(&screen[0]); sfc->addVertex(&screen[1]); sfc->addVertex(&screen[2]); sfc->addVertex(&screen[3]); sfc->emitPoly(); sfc->setZTest(GFX_ZTEST_AND_WRITE); // Now render the shape TMat3F transform (EulerF (0, 0, 0), -instance->getShape().fCenter); camera->pushTransform (transform); instance->render(context); camera->popTransform (); // Done, unlock sfc->draw3DEnd(); context.unlock(); } // We kind of brute-force our draw, so we need to tell anything // overlapping us to re-draw rect.upperL = offset - 1; rect.lowerR = offset + extent + 1; sfc->setClipRect(&rect); box.fMin = rect.upperL; box.fMax = rect.lowerR; renderChildControls(sfc, offset, box); }
void GuiProgressBitmapCtrl::onRender(Point2I offset, const RectI &updateRect) { RectI ctrlRect(offset, getExtent()); //grab lowest dimension if(getHeight() <= getWidth()) mDim = getHeight(); else mDim = getWidth(); GFXDrawUtil* drawUtil = GFX->getDrawUtil(); drawUtil->clearBitmapModulation(); if(mNumberOfBitmaps == 1) { //draw the progress with image S32 width = (S32)((F32)(getWidth()) * mProgress); if (width > 0) { //drawing stretch bitmap RectI progressRect = ctrlRect; progressRect.extent.x = width; drawUtil->drawBitmapStretchSR(mProfile->mTextureObject, progressRect, mProfile->mBitmapArrayRects[0]); } } else if(mNumberOfBitmaps >= 3) { //drawing left-end bitmap RectI progressRectLeft(ctrlRect.point.x, ctrlRect.point.y, mDim, mDim); drawUtil->drawBitmapStretchSR(mProfile->mTextureObject, progressRectLeft, mProfile->mBitmapArrayRects[0]); //draw the progress with image S32 width = (S32)((F32)(getWidth()) * mProgress); if (width > mDim) { //drawing stretch bitmap RectI progressRect = ctrlRect; progressRect.point.x += mDim; progressRect.extent.x = (width - mDim - mDim); if (progressRect.extent.x < 0) progressRect.extent.x = 0; drawUtil->drawBitmapStretchSR(mProfile->mTextureObject, progressRect, mProfile->mBitmapArrayRects[1]); //drawing right-end bitmap RectI progressRectRight(progressRect.point.x + progressRect.extent.x, ctrlRect.point.y, mDim, mDim ); drawUtil->drawBitmapStretchSR(mProfile->mTextureObject, progressRectRight, mProfile->mBitmapArrayRects[2]); } } else Con::warnf("guiProgressBitmapCtrl only processes an array of bitmaps == 1 or >= 3"); //if there's a border, draw it if (mProfile->mBorder) drawUtil->drawRect(ctrlRect, mProfile->mBorderColor); Parent::onRender( offset, updateRect ); //render the children renderChildControls(offset, updateRect); }
void onRender(Point2I offset, const RectI &updateRect) { U32 elapsed = Platform::getRealMilliseconds() - wakeTime; U32 alpha; if (doFadeOut && elapsed < fadeoutTime) { // fade out alpha = 255 - (255 * (F32(elapsed) / F32(fadeoutTime))); } else if (doFadeIn && elapsed < fadeinTime) { // fade in alpha = 255 * F32(elapsed) / F32(fadeinTime); } else { // done state alpha = doFadeIn ? 255 : 0; done = true; } ColorI color(255,255,255,alpha); if (mTextureObject) { GFX->getDrawUtil()->setBitmapModulation(color); if(mWrap) { GFXTextureObject* texture = mTextureObject; RectI srcRegion; RectI dstRegion; F32 xdone = ((F32)getExtent().x/(F32)texture->mBitmapSize.x)+1; F32 ydone = ((F32)getExtent().y/(F32)texture->mBitmapSize.y)+1; S32 xshift = mStartPoint.x%texture->mBitmapSize.x; S32 yshift = mStartPoint.y%texture->mBitmapSize.y; for(S32 y = 0; y < ydone; ++y) for(S32 x = 0; x < xdone; ++x) { srcRegion.set(0,0,texture->mBitmapSize.x,texture->mBitmapSize.y); dstRegion.set( ((texture->mBitmapSize.x*x)+offset.x)-xshift, ((texture->mBitmapSize.y*y)+offset.y)-yshift, texture->mBitmapSize.x, texture->mBitmapSize.y); GFX->getDrawUtil()->drawBitmapStretchSR(texture,dstRegion, srcRegion); } } else { RectI rect(offset, getExtent()); GFX->getDrawUtil()->drawBitmapStretch(mTextureObject, rect); } } if (mProfile->mBorder || !mTextureObject) { RectI rect(offset.x, offset.y, getExtent().x, getExtent().y); ColorI borderCol(mProfile->mBorderColor); borderCol.alpha = alpha; GFX->getDrawUtil()->drawRect(rect, borderCol); } renderChildControls(offset, updateRect); }
void GuiColorPickerCtrl::onRender(Point2I offset, const RectI& updateRect) { if (mStateBlock.isNull()) { GFXStateBlockDesc desc; desc.setBlend(true, GFXBlendSrcAlpha, GFXBlendInvSrcAlpha); desc.setZReadWrite(false); desc.zWriteEnable = false; desc.setCullMode(GFXCullNone); mStateBlock = GFX->createStateBlock(desc); } RectI boundsRect(offset, getExtent()); renderColorBox(boundsRect); if (mPositionChanged || mBitmap == NULL) { bool nullBitmap = false; if (mPositionChanged == false && mBitmap == NULL) nullBitmap = true; mPositionChanged = false; Point2I extent = getRoot()->getExtent(); // If we are anything but a pallete, change the pick color if (mDisplayMode != pPallet) { Point2I resolution = getRoot()->getExtent(); U32 buf_x = offset.x + mSelectorPos.x + 1; U32 buf_y = resolution.y - (extent.y - (offset.y + mSelectorPos.y + 1)); GFXTexHandle bb( resolution.x, resolution.y, GFXFormatR8G8B8A8, &GFXDefaultRenderTargetProfile, avar("%s() - bb (line %d)", __FUNCTION__, __LINE__) ); Point2I tmpPt(buf_x, buf_y); GFXTarget *targ = GFX->getActiveRenderTarget(); targ->resolveTo(bb); if (mBitmap) { delete mBitmap; mBitmap = NULL; } mBitmap = new GBitmap(bb.getWidth(), bb.getHeight()); bb.copyToBmp(mBitmap); if (!nullBitmap) { if (mSelectColor) { Point2I pos = findColor(mSetColor, offset, resolution, *mBitmap); mSetColor = mSetColor.BLACK; mSelectColor = false; setSelectorPos(pos); } else { ColorI tmp; mBitmap->getColor(buf_x, buf_y, tmp); mPickColor = (ColorF)tmp; // Now do onAction() if we are allowed if (mActionOnMove) onAction(); } } } } //render the children renderChildControls(offset, updateRect); }
void GuiPaneControl::onRender(Point2I offset, const RectI &updateRect) { // Render our awesome little doogong if(mProfile->mBitmapArrayRects.size() >= 2 && mCollapsable) { S32 idx = mCollapsed ? 0 : 1; GFX->getDrawUtil()->clearBitmapModulation(); GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(offset, mProfile->mBitmapArrayRects[idx].extent), mProfile->mBitmapArrayRects[idx] ); } S32 textWidth = 0; if(!mBarBehindText) { GFX->getDrawUtil()->setBitmapModulation((mMouseOver ? mProfile->mFontColorHL : mProfile->mFontColor)); textWidth = GFX->getDrawUtil()->drawText( mProfile->mFont, Point2I(mThumbSize.x, 0) + offset, mCaption, mProfile->mFontColors ); } // Draw our little bar, too if(mProfile->mBitmapArrayRects.size() >= 5) { GFX->getDrawUtil()->clearBitmapModulation(); S32 barStart = mThumbSize.x + offset.x + textWidth; S32 barTop = mThumbSize.y/2 + offset.y - mProfile->mBitmapArrayRects[3].extent.y /2; Point2I barOffset(barStart, barTop); // Draw the start of the bar... GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(barOffset, mProfile->mBitmapArrayRects[2].extent), mProfile->mBitmapArrayRects[2] ); // Now draw the middle... barOffset.x += mProfile->mBitmapArrayRects[2].extent.x; S32 barMiddleSize = (getExtent().x - (barOffset.x - offset.x)) - mProfile->mBitmapArrayRects[4].extent.x; if(barMiddleSize>0) { // We have to do this inset to prevent nasty stretching artifacts RectI foo = mProfile->mBitmapArrayRects[3]; foo.inset(1,0); GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(barOffset, Point2I(barMiddleSize, mProfile->mBitmapArrayRects[3].extent.y)), foo ); } // And the end barOffset.x += barMiddleSize; GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(barOffset, mProfile->mBitmapArrayRects[4].extent), mProfile->mBitmapArrayRects[4] ); } if(mBarBehindText) { GFX->getDrawUtil()->setBitmapModulation((mMouseOver ? mProfile->mFontColorHL : mProfile->mFontColor)); GFX->getDrawUtil()->drawText( mProfile->mFont, Point2I(mThumbSize.x, 0) + offset, mCaption, mProfile->mFontColors ); } // Draw child controls if appropriate if(!mCollapsed) renderChildControls(offset, updateRect); }
void GuiTSCtrl::onRender(Point2I offset, const RectI &updateRect) { // Save the current transforms so we can restore // it for child control rendering below. GFXTransformSaver saver; if(!processCameraQuery(&mLastCameraQuery)) { // We have no camera, but render the GUI children // anyway. This makes editing GuiTSCtrl derived // controls easier in the GuiEditor. renderChildControls( offset, updateRect ); return; } // Set up the appropriate render style U32 prevRenderStyle = GFX->getCurrentRenderStyle(); Point2F prevProjectionOffset = GFX->getCurrentProjectionOffset(); Point3F prevEyeOffset = GFX->getStereoEyeOffset(); if(mRenderStyle == RenderStyleStereoSideBySide) { GFX->setCurrentRenderStyle(GFXDevice::RS_StereoSideBySide); GFX->setCurrentProjectionOffset(mLastCameraQuery.projectionOffset); GFX->setStereoEyeOffset(mLastCameraQuery.eyeOffset); } else { GFX->setCurrentRenderStyle(GFXDevice::RS_Standard); } if ( mReflectPriority > 0 ) { // Get the total reflection priority. F32 totalPriority = 0; for ( U32 i=0; i < smAwakeTSCtrls.size(); i++ ) if ( smAwakeTSCtrls[i]->isVisible() ) totalPriority += smAwakeTSCtrls[i]->mReflectPriority; REFLECTMGR->update( mReflectPriority / totalPriority, getExtent(), mLastCameraQuery ); } if(mForceFOV != 0) mLastCameraQuery.fov = mDegToRad(mForceFOV); if(mCameraZRot) { MatrixF rotMat(EulerF(0, 0, mDegToRad(mCameraZRot))); mLastCameraQuery.cameraMatrix.mul(rotMat); } // set up the camera and viewport stuff: F32 wwidth; F32 wheight; F32 renderWidth = (mRenderStyle == RenderStyleStereoSideBySide) ? F32(getWidth())*0.5f : F32(getWidth()); F32 renderHeight = F32(getHeight()); F32 aspectRatio = renderWidth / renderHeight; // Use the FOV to calculate the viewport height scale // then generate the width scale from the aspect ratio. if(!mLastCameraQuery.ortho) { wheight = mLastCameraQuery.nearPlane * mTan(mLastCameraQuery.fov / 2.0f); wwidth = aspectRatio * wheight; } else { wheight = mLastCameraQuery.fov; wwidth = aspectRatio * wheight; } F32 hscale = wwidth * 2.0f / renderWidth; F32 vscale = wheight * 2.0f / renderHeight; Frustum frustum; if(mRenderStyle == RenderStyleStereoSideBySide) { F32 left = 0.0f * hscale - wwidth; F32 right = renderWidth * hscale - wwidth; F32 top = wheight - vscale * 0.0f; F32 bottom = wheight - vscale * renderHeight; frustum.set( mLastCameraQuery.ortho, left, right, top, bottom, mLastCameraQuery.nearPlane, mLastCameraQuery.farPlane ); } else { F32 left = (updateRect.point.x - offset.x) * hscale - wwidth; F32 right = (updateRect.point.x + updateRect.extent.x - offset.x) * hscale - wwidth; F32 top = wheight - vscale * (updateRect.point.y - offset.y); F32 bottom = wheight - vscale * (updateRect.point.y + updateRect.extent.y - offset.y); frustum.set( mLastCameraQuery.ortho, left, right, top, bottom, mLastCameraQuery.nearPlane, mLastCameraQuery.farPlane ); } // Manipulate the frustum for tiled screenshots const bool screenShotMode = gScreenShot && gScreenShot->isPending(); if ( screenShotMode ) { gScreenShot->tileFrustum( frustum ); GFX->setViewMatrix(MatrixF::Identity); } RectI tempRect = updateRect; #ifdef TORQUE_OS_MAC Point2I screensize = getRoot()->getWindowSize(); tempRect.point.y = screensize.y - (tempRect.point.y + tempRect.extent.y); #endif GFX->setViewport( tempRect ); // Clear the zBuffer so GUI doesn't hose object rendering accidentally GFX->clear( GFXClearZBuffer , ColorI(20,20,20), 1.0f, 0 ); GFX->setFrustum( frustum ); if(mLastCameraQuery.ortho) { mOrthoWidth = frustum.getWidth(); mOrthoHeight = frustum.getHeight(); } // We're going to be displaying this render at size of this control in // pixels - let the scene know so that it can calculate e.g. reflections // correctly for that final display result. gClientSceneGraph->setDisplayTargetResolution(getExtent()); // Set the GFX world matrix to the world-to-camera transform, but don't // change the cameraMatrix in mLastCameraQuery. This is because // mLastCameraQuery.cameraMatrix is supposed to contain the camera-to-world // transform. In-place invert would save a copy but mess up any GUIs that // depend on that value. MatrixF worldToCamera = mLastCameraQuery.cameraMatrix; worldToCamera.inverse(); GFX->setWorldMatrix( worldToCamera ); mSaveProjection = GFX->getProjectionMatrix(); mSaveModelview = GFX->getWorldMatrix(); mSaveViewport = updateRect; mSaveWorldToScreenScale = GFX->getWorldToScreenScale(); mSaveFrustum = GFX->getFrustum(); mSaveFrustum.setTransform( mLastCameraQuery.cameraMatrix ); // Set the default non-clip projection as some // objects depend on this even in non-reflect cases. gClientSceneGraph->setNonClipProjection( mSaveProjection ); // Give the post effect manager the worldToCamera, and cameraToScreen matrices PFXMGR->setFrameMatrices( mSaveModelview, mSaveProjection ); renderWorld(updateRect); DebugDrawer::get()->render(); // Restore the previous matrix state before // we begin rendering the child controls. saver.restore(); // Restore the render style and any stereo parameters GFX->setCurrentRenderStyle(prevRenderStyle); GFX->setCurrentProjectionOffset(prevProjectionOffset); GFX->setStereoEyeOffset(prevEyeOffset); // Allow subclasses to render 2D elements. GFX->setClipRect(updateRect); renderGui( offset, updateRect ); renderChildControls(offset, updateRect); smFrameCount++; }
void GuiGameListMenuCtrl::onRender(Point2I offset, const RectI &updateRect) { GuiGameListMenuProfile * profile = (GuiGameListMenuProfile *) mProfile; F32 xScale = (float) getWidth() / profile->getRowWidth(); bool profileHasIcons = profile->hasArrows(); S32 rowHeight = profile->getRowHeight(); Point2I currentOffset = offset; Point2I extent = getExtent(); Point2I rowExtent(extent.x, rowHeight); Point2I textOffset(profile->mTextOffset.x * xScale, profile->mTextOffset.y); Point2I textExtent(extent.x - textOffset.x, rowHeight); Point2I iconExtent, iconOffset(0.0f, 0.0f); if (profileHasIcons) { iconExtent = profile->getIconExtent(); // icon is centered vertically plus any specified offset S32 iconOffsetY = (rowHeight - iconExtent.y) >> 1; iconOffsetY += profile->mIconOffset.y; iconOffset = Point2I(profile->mIconOffset.x * xScale, iconOffsetY); } for (Vector<Row *>::iterator row = mRows.begin(); row < mRows.end(); ++row) { if (row != mRows.begin()) { // rows other than the first can have padding above them currentOffset.y += (*row)->mHeightPad; currentOffset.y += rowHeight; } // select appropriate colors and textures ColorI fontColor; U32 buttonTextureIndex; S32 iconIndex = (*row)->mIconIndex; bool useHighlightIcon = (*row)->mUseHighlightIcon; if (! (*row)->mEnabled) { buttonTextureIndex = Profile::TEX_DISABLED; fontColor = profile->mFontColorNA; } else if (row == &mRows[mSelected]) { if (iconIndex != NO_ICON) { iconIndex++; } buttonTextureIndex = Profile::TEX_SELECTED; fontColor = profile->mFontColorSEL; } else if ((mHighlighted != NO_ROW) && (row == &mRows[mHighlighted])) { if (iconIndex != NO_ICON && useHighlightIcon) { iconIndex++; } buttonTextureIndex = Profile::TEX_HIGHLIGHT; fontColor = profile->mFontColorHL; } else { buttonTextureIndex = Profile::TEX_NORMAL; fontColor = profile->mFontColor; } // render the row bitmap GFX->getDrawUtil()->clearBitmapModulation(); GFX->getDrawUtil()->drawBitmapStretchSR(profile->mTextureObject, RectI(currentOffset, rowExtent), profile->getBitmapArrayRect(buttonTextureIndex)); // render the row icon if it has one if ((iconIndex != NO_ICON) && profileHasIcons && (! profile->getBitmapArrayRect((U32)iconIndex).extent.isZero())) { iconIndex += Profile::TEX_FIRST_ICON; GFX->getDrawUtil()->clearBitmapModulation(); GFX->getDrawUtil()->drawBitmapStretchSR(profile->mTextureObject, RectI(currentOffset + iconOffset, iconExtent), profile->getBitmapArrayRect(iconIndex)); } // render the row text GFX->getDrawUtil()->setBitmapModulation(fontColor); renderJustifiedText(currentOffset + textOffset, textExtent, (*row)->mLabel); } if (mDebugRender) { onDebugRender(offset); } renderChildControls(offset, updateRect); }
void GuiInspectorField::onRender( Point2I offset, const RectI &updateRect ) { RectI ctrlRect(offset, getExtent()); // Render fillcolor... if ( mProfile->mOpaque ) GFX->getDrawUtil()->drawRectFill(ctrlRect, mProfile->mFillColor); // Render caption... if ( mCaption && mCaption[0] ) { // Backup current ClipRect RectI clipBackup = GFX->getClipRect(); RectI clipRect = updateRect; // The rect within this control in which our caption must fit. RectI rect( offset + mCaptionRect.point + mProfile->mTextOffset, mCaptionRect.extent + Point2I(1,1) - Point2I(5,0) ); // Now clipRect is the amount of our caption rect that is actually visible. bool hit = clipRect.intersect( rect ); if ( hit ) { GFX->setClipRect( clipRect ); GFXDrawUtil *drawer = GFX->getDrawUtil(); // Backup modulation color ColorI currColor; drawer->getBitmapModulation( &currColor ); // Draw caption background... if( !isActive() ) GFX->getDrawUtil()->drawRectFill( clipRect, mProfile->mFillColorNA ); else if ( mHighlighted ) GFX->getDrawUtil()->drawRectFill( clipRect, mProfile->mFillColorHL ); // Draw caption text... drawer->setBitmapModulation( !isActive() ? mProfile->mFontColorNA : mHighlighted ? mProfile->mFontColorHL : mProfile->mFontColor ); // Clip text with '...' if too long to fit String clippedText( mCaption ); clipText( clippedText, clipRect.extent.x ); renderJustifiedText( offset + mProfile->mTextOffset, getExtent(), clippedText ); // Restore modulation color drawer->setBitmapModulation( currColor ); // Restore previous ClipRect GFX->setClipRect( clipBackup ); } } // Render Children... renderChildControls(offset, updateRect); // Render border... if ( mProfile->mBorder ) renderBorder(ctrlRect, mProfile); // Render divider... Point2I worldPnt = mEditCtrlRect.point + offset; GFX->getDrawUtil()->drawLine( worldPnt.x - 5, worldPnt.y, worldPnt.x - 5, worldPnt.y + getHeight(), !isActive() ? mProfile->mBorderColorNA : mHighlighted ? mProfile->mBorderColorHL : mProfile->mBorderColor ); }
void GuiFormCtrl::onRender(Point2I offset, const RectI &updateRect) { // Fill in the control's child area RectI boundsRect(offset, getExtent()); boundsRect.point.y += mThumbSize.y; boundsRect.extent.y -= mThumbSize.y; // draw the border of the form if specified if (mProfile->mOpaque) GFX->getDrawUtil()->drawRectFill(boundsRect, mProfile->mFillColor); if (mProfile->mBorder) renderBorder(boundsRect, mProfile); // If we don't have a child, put some text in the child area if( empty() ) { GFX->getDrawUtil()->setBitmapModulation(ColorI(0,0,0)); renderJustifiedText(boundsRect.point, boundsRect.extent, "[none]"); } S32 textWidth = 0; // Draw our little bar, too if (mProfile->mBitmapArrayRects.size() >= 5) { //GFX->getDrawUtil()->clearBitmapModulation(); // Copyright (C) 2013 WinterLeaf Entertainment LLC. S32 barStart = offset.x + textWidth; S32 barTop = mThumbSize.y / 2 + offset.y - mProfile->mBitmapArrayRects[3].extent.y / 2; Point2I barOffset(barStart, barTop); // Draw the start of the bar... GFX->getDrawUtil()->drawBitmapStretchSR(mProfile->mTextureObject ,RectI(barOffset, mProfile->mBitmapArrayRects[2].extent), mProfile->mBitmapArrayRects[2] ); // Now draw the middle... barOffset.x += mProfile->mBitmapArrayRects[2].extent.x; S32 barMiddleSize = (getExtent().x - (barOffset.x - offset.x)) - mProfile->mBitmapArrayRects[4].extent.x + 1; if (barMiddleSize > 0) { // We have to do this inset to prevent nasty stretching artifacts RectI foo = mProfile->mBitmapArrayRects[3]; foo.inset(1,0); GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(barOffset, Point2I(barMiddleSize, mProfile->mBitmapArrayRects[3].extent.y)), foo ); } // And the end barOffset.x += barMiddleSize; GFX->getDrawUtil()->drawBitmapStretchSR( mProfile->mTextureObject, RectI(barOffset, mProfile->mBitmapArrayRects[4].extent), mProfile->mBitmapArrayRects[4]); GFX->getDrawUtil()->setBitmapModulation((mMouseOver ? mProfile->mFontColorHL : mProfile->mFontColor)); renderJustifiedText(Point2I(mThumbSize.x, 0) + offset, Point2I(getWidth() - mThumbSize.x - mProfile->mBitmapArrayRects[4].extent.x, mThumbSize.y), (mUseSmallCaption ? mSmallCaption : mCaption) ); } // Render the children renderChildControls(offset, updateRect); }
void GuiSliderCtrl::onRender(Point2I offset, const RectI &updateRect) { Point2I pos(offset.x+mShiftPoint, offset.y); Point2I ext(getWidth() - mShiftExtent, getHeight()); RectI thumb = mThumb; if( mHasTexture ) { if(mTicks > 0) { // TODO: tick marks should be positioned based on the bitmap dimensions. Point2I mid(ext.x, ext.y/2); Point2I oldpos = pos; pos += Point2I(1, 0); PrimBuild::color4f( 0.f, 0.f, 0.f, 1.f ); PrimBuild::begin( GFXLineList, ( mTicks + 2 ) * 2 ); // tick marks for (U32 t = 0; t <= (mTicks+1); t++) { S32 x = (S32)(F32(mid.x+1)/F32(mTicks+1)*F32(t)) + pos.x; S32 y = pos.y + mid.y; PrimBuild::vertex2i(x, y + mShiftPoint); PrimBuild::vertex2i(x, y + mShiftPoint*2 + 2); } PrimBuild::end(); // TODO: it would be nice, if the primitive builder were a little smarter, // so that we could change colors midstream. PrimBuild::color4f(0.9f, 0.9f, 0.9f, 1.0f); PrimBuild::begin( GFXLineList, ( mTicks + 2 ) * 2 ); // tick marks for (U32 t = 0; t <= (mTicks+1); t++) { S32 x = (S32)(F32(mid.x+1)/F32(mTicks+1)*F32(t)) + pos.x + 1; S32 y = pos.y + mid.y + 1; PrimBuild::vertex2i(x, y + mShiftPoint ); PrimBuild::vertex2i(x, y + mShiftPoint * 2 + 3); } PrimBuild::end(); pos = oldpos; } S32 index = SliderButtonNormal; if(mMouseOver) index = SliderButtonHighlight; GFX->getDrawUtil()->clearBitmapModulation(); //left border GFX->getDrawUtil()->drawBitmapSR(mProfile->mTextureObject, Point2I(offset.x,offset.y), mBitmapBounds[SliderLineLeft]); //right border GFX->getDrawUtil()->drawBitmapSR(mProfile->mTextureObject, Point2I(offset.x + getWidth() - mBitmapBounds[SliderLineRight].extent.x, offset.y), mBitmapBounds[SliderLineRight]); //draw our center piece to our slider control's border and stretch it RectI destRect; destRect.point.x = offset.x + mBitmapBounds[SliderLineLeft].extent.x; destRect.extent.x = getWidth() - mBitmapBounds[SliderLineLeft].extent.x - mBitmapBounds[SliderLineRight].extent.x; destRect.point.y = offset.y; destRect.extent.y = mBitmapBounds[SliderLineCenter].extent.y; RectI stretchRect; stretchRect = mBitmapBounds[SliderLineCenter]; stretchRect.inset(1,0); GFX->getDrawUtil()->drawBitmapStretchSR(mProfile->mTextureObject, destRect, stretchRect); //draw our control slider button thumb.point += pos; GFX->getDrawUtil()->drawBitmapSR(mProfile->mTextureObject,Point2I(thumb.point.x,offset.y ),mBitmapBounds[index]); } else if (getWidth() >= getHeight()) { Point2I mid(ext.x, ext.y/2); if(mDisplayValue) mid.set(ext.x, mThumbSize.y/2); PrimBuild::color4f( 0.f, 0.f, 0.f, 1.f ); PrimBuild::begin( GFXLineList, ( mTicks + 2 ) * 2 + 2); // horz rule PrimBuild::vertex2i( pos.x, pos.y + mid.y ); PrimBuild::vertex2i( pos.x + mid.x, pos.y + mid.y ); // tick marks for( U32 t = 0; t <= ( mTicks + 1 ); t++ ) { S32 x = (S32)( F32( mid.x - 1 ) / F32( mTicks + 1 ) * F32( t ) ); PrimBuild::vertex2i( pos.x + x, pos.y + mid.y - mShiftPoint ); PrimBuild::vertex2i( pos.x + x, pos.y + mid.y + mShiftPoint ); } PrimBuild::end(); } else { Point2I mid(ext.x/2, ext.y); PrimBuild::color4f( 0.f, 0.f, 0.f, 1.f ); PrimBuild::begin( GFXLineList, ( mTicks + 2 ) * 2 + 2); // horz rule PrimBuild::vertex2i( pos.x + mid.x, pos.y ); PrimBuild::vertex2i( pos.x + mid.x, pos.y + mid.y ); // tick marks for( U32 t = 0; t <= ( mTicks + 1 ); t++ ) { S32 y = (S32)( F32( mid.y - 1 ) / F32( mTicks + 1 ) * F32( t ) ); PrimBuild::vertex2i( pos.x + mid.x - mShiftPoint, pos.y + y ); PrimBuild::vertex2i( pos.x + mid.x + mShiftPoint, pos.y + y ); } PrimBuild::end(); mDisplayValue = false; } // draw the thumb thumb.point += pos; renderRaisedBox(thumb, mProfile); if(mDisplayValue) { char buf[20]; dSprintf(buf,sizeof(buf),"%0.3f",mValue); Point2I textStart = thumb.point; S32 txt_w = mProfile->mFont->getStrWidth((const UTF8 *)buf); textStart.x += (S32)((thumb.extent.x/2.0f)); textStart.y += thumb.extent.y - 2; //19 textStart.x -= (txt_w/2); if(textStart.x < offset.x) textStart.x = offset.x; else if(textStart.x + txt_w > offset.x+getWidth()) textStart.x -=((textStart.x + txt_w) - (offset.x+getWidth())); GFX->getDrawUtil()->setBitmapModulation(mProfile->mFontColor); GFX->getDrawUtil()->drawText(mProfile->mFont, textStart, buf, mProfile->mFontColors); } renderChildControls(offset, updateRect); }
void GuiGraphCtrl::onRender(Point2I offset, const RectI &updateRect) { if (mBlendSB.isNull()) { GFXStateBlockDesc desc; desc.setBlend(true, GFXBlendSrcColor, GFXBlendInvSrcColor); mBlendSB = GFX->createStateBlock(desc); desc.setBlend(false, GFXBlendOne, GFXBlendZero); mSolidSB = GFX->createStateBlock(desc); } GFX->setStateBlock( mBlendSB ); GFX->getDrawUtil()->drawRectFill( updateRect, mProfile->mFillColor ); GFX->setStateBlock( mSolidSB ); const Point2I globalPos = getGlobalBounds().point; const F32 midPointY = F32( globalPos.y ) + F32( getExtent().y ) * mCenterY; for( S32 k = 0; k < MaxPlots; ++ k ) { // Check if there is an autoplot and the proper amount of time has passed, if so add datum. if( mAutoPlot[ k ] && mAutoPlotDelay[ k ] < (Sim::getCurrentTime() - mAutoPlotLastDisplay[ k ] ) ) { mAutoPlotLastDisplay[ k ] = Sim::getCurrentTime(); addDatum( k, Con::getFloatVariable( mAutoPlot[ k ] ) ); } // Nothing to graph if( mGraphData[ k ].size() == 0 ) continue; // Adjust scale to max value + 5% so we can see high values F32 Scale = F32( getExtent().y ) / F32( mGraphMax[ k ] * 1.05 ); const S32 numSamples = mGraphData[ k ].size(); switch( mGraphType[ k ] ) { case Bar: { F32 prevOffset = 0; for( S32 sample = 0; sample < numSamples; ++ sample ) { PrimBuild::begin( GFXTriangleFan, 4 ); PrimBuild::color( mGraphColor[ k ] ); F32 offset = F32( getExtent().x ) / F32( MaxDataPoints ) * F32( sample + 1 ); PrimBuild::vertex2f( globalPos.x + prevOffset, midPointY - ( getDatum( k, sample ) * Scale ) ); PrimBuild::vertex2f( globalPos.x + offset, midPointY - ( getDatum( k, sample ) * Scale ) ); PrimBuild::vertex2f( globalPos.x + offset, midPointY ); PrimBuild::vertex2f( globalPos.x + prevOffset, midPointY ); prevOffset = offset; PrimBuild::end(); } break; } case Filled: { PrimBuild::begin( GFXTriangleStrip, numSamples * 2 ); // Max size correct? -pw PrimBuild::color( mGraphColor[ k ] ); for( S32 sample = 0; sample < numSamples; ++ sample ) { F32 offset = F32( getExtent().x ) / F32( MaxDataPoints - 1 ) * F32( sample ); PrimBuild::vertex2f( globalPos.x + offset, midPointY ); PrimBuild::vertex2f( globalPos.x + offset, midPointY - ( getDatum( k, sample ) * Scale ) ); } PrimBuild::end(); break; } case Point: case Polyline: { if( mGraphType[ k ] == Point ) PrimBuild::begin( GFXPointList, numSamples ); // Max size correct? -pw else PrimBuild::begin( GFXLineStrip, numSamples ); PrimBuild::color( mGraphColor[ k ] ); for( S32 sample = 0; sample < numSamples; ++ sample ) { F32 offset = F32( getExtent().x ) / F32( MaxDataPoints - 1 ) * F32( sample ); PrimBuild::vertex2f( globalPos.x + offset, midPointY - ( getDatum( k, sample ) * Scale ) ); } PrimBuild::end(); break; } } } if( mProfile->mBorder ) { RectI rect( offset.x, offset.y, getWidth(), getHeight() ); GFX->getDrawUtil()->drawRect( rect, mProfile->mBorderColor ); } renderChildControls( offset, updateRect ); }