在登錄的畫面里,可以看到程序的版本顯示,那么它是怎么樣顯示出來的呢?現在就來分析顯示這個版本號的代碼,其實它是由靜態文本顯示框
LLTextBox來顯示的。比如在登錄時創建版本顯示的代碼如下:
?
這里就是創建靜態文本框。
#001?LLTextBox* version_text = LLUICtrlFactory::getTextBoxByName(this, "version_text");
?
下面是先格式化再顯示版本字符串。
#002?
?? if (version_text)
#003?
?? {
#004?
?????? LLString version = llformat("%d.%d.%d (%d)",
#005?
?????????? LL_VERSION_MAJOR,
#006?
?????????? LL_VERSION_MINOR,
#007?
?????????? LL_VERSION_PATCH,
#008?
?????????? LL_VIEWER_BUILD );
#009?
?????? version_text->setText(version);
#010?
?????? version_text->setClickedCallback(onClickVersion);
#011?
?????? version_text->setCallbackUserData(this);
#012?
?? }
?
LLTextBox類的繼承關系代碼如下:
class LLTextBox
:
??? public LLUICtrl
?
接著來分析一下它的顯示代碼,如下:
#001?void LLTextBox::draw()
#002?{
?
查看是否可以顯示。
#003?
?? if( getVisible() )
#004?
?? {
?
是否顯示邊框。
#005?
?????? if (mBorderVisible)
#006?
?????? {
#007?
?????????? gl_rect_2d_offset_local(getLocalRect(), 2, FALSE);
#008?
?????? }
#009?
?
是否顯示邊框為陰影方式。
#010?
?????? if( mBorderDropShadowVisible )
#011?
?????? {
#012?
?????????? static LLColor4 color_drop_shadow = LLUI::sColorsGroup->getColor("ColorDropShadow");
#013?
?????????? static S32 drop_shadow_tooltip = LLUI::sConfigGroup->getS32("DropShadowTooltip");
#014?
?????????? gl_drop_shadow(0, getRect().getHeight(), getRect().getWidth(), 0,
#015?
?????????????? color_drop_shadow, drop_shadow_tooltip);
#016?
?????? }
#017?
??
?
背景是否可見。
#018?
?????? if (mBackgroundVisible)
#019?
?????? {
#020?
?????????? LLRect r( 0, getRect().getHeight(), getRect().getWidth(), 0 );
#021?
?????????? gl_rect_2d( r, mBackgroundColor );
#022?
?????? }
#023 ?
?
顯示字符串的對齊方式。
#024?
?????? S32 text_x = 0;
#025?
?????? switch( mHAlign )
#026?
?????? {
#027?
?????? case LLFontGL::LEFT:???
#028?
?????????? text_x = mHPad;????????????????????
#029?
?????????? break;
#030?
?????? case LLFontGL::HCENTER:
#031?
?????????? text_x = getRect().getWidth() / 2;
#032?
?????????? break;
#033?
?????? case LLFontGL::RIGHT:
#034?
?????????? text_x = getRect().getWidth() - mHPad;
#035?
?????????? break;
#036?
?????? }
#037?
?
計算字符串顯示的高度。
#038?
?????? S32 text_y = getRect().getHeight() - mVPad;
#039?
#040?
?????? if ( getEnabled() )
#041?
?????? {
?
是否有鼠標在上面,而顯示不同的顏色。
#042?
?????????? if(mHasHover)
#043?
?????????? {
#044?
?????????????? drawText( text_x, text_y, mHoverColor );
#045?
?????????? }
#046?
?????????? else
#047?
?????????? {
#048?
?????????????? drawText( text_x, text_y, mTextColor );
#049?
?????????? }??????????????
#050?
?????? }
#051?
?????? else
#052?
?????? {
#053?
?????????? drawText( text_x, text_y, mDisabledColor );
#054?
?????? }
#055?
?
是否調試輸出窗口。
#056?
?????? if (sDebugRects)
#057?
?????? {
#058?
?????????? drawDebugRect();
#059?
?????? }
#060?
?? }
#061?
#062?
?? mHasHover = FALSE; // This is reset every frame.
#063?}
?
上面這個函數先顯示邊框,然后顯示背景,最后顯示字符串出來,這樣就實現了靜態的文本顯示。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
