Thursday, July 24, 2008

Watermark for TGE

Sometimes you dont want your engine used by other, so why dont use watermark ?

add this snippet to your engine/gui/core/guicanvas.cc on void GuiCanvas::renderFrame(bool preRenderOnly, bool bufferSwap /* = true */) exactly after




if (cursorON && mouseCursor && mShowCursor)
{
Point2I pos((S32)cursorPt.x, (S32)cursorPt.y);
Point2I spot = mouseCursor->getHotSpot();

pos -= spot;
mouseCursor->render(pos);
}




This is the code, and after adding this you should rebuild the engine.




// enable/disable watermark ?
bool WT = true;

if(WT)
{
// get the default profile for text
GuiControlProfile *mtProfile;
mtProfile = NULL;

// Ok lets check to see if that worked
if( !mtProfile ) {
SimObject *obj = Sim::findObject( "GuiDefaultProfile" );

if( obj )
mtProfile = dynamic_cast(obj);
else
return;
}

if(mtProfile)
{
// changed the text into your watermark text
const char* wtText = "TGE Licenced HD";

ColorF mForegroundColor;
mForegroundColor.set( 1, 1, 1, 1 );
ColorI mFillColor;

//Vars used:
//Screensize (for position check)
//Offset to get position of cursor
//textBounds for text extent.
Point2I offset;
Point2I textBounds;
S32 textWidth = mtProfile->mFont->getStrWidth(renderTip);

//Create text bounds.
textBounds.x = textWidth+8;
textBounds.y = mtProfile->mFont->getHeight() + 4;

//Offset below cursor image
offset.y = size.y - textBounds.y - 10;
offset.x = size.x - textBounds.x - 10;

// Set rectangle for the box, and set the clip rectangle.
RectI rect(offset, textBounds);
dglSetClipRect(rect);

mFillColor.set(0,0,0,255);
dglDrawRectFill(rect, mFillColor);

mFillColor.set(255,255,255,255);
dglDrawRect( rect, mFillColor );

// Draw the text centered in the tool tip box
dglSetBitmapModulation( mForegroundColor );
Point2I start;
start.set( ( textBounds.x - textWidth) / 2, ( textBounds.y - mtProfile->mFont->getHeight() ) / 2 );
dglDrawText( mtProfile->mFont, start + offset, wtText, mtProfile->mFontColors );
dglClearBitmapModulation();

// end hd watermark
}

// free the pointer ?
mtProfile = NULL;
}

No comments: