第二人生的源码分析(九十一)LLScrollListCtrl列表的详细绘制

从前面可以看到怎么样绘制滚动列表框的代码,但在那个函数里面还调用一个函数drawItems来详细地绘制列表项的,现在就来分析这个函数的代码,如下:
#001 void LLScrollListCtrl::drawItems()
#002 {
 
计算左上角显示的位置。
#003    S32 x = mItemListRect.mLeft;
#004    S32 y = mItemListRect.mTop - mLineHeight;
#005 
 
允许显示最大的行数。
#006    // allow for partial line at bottom
#007    S32 num_page_lines = mPageLines + 1;
#008 
#009    LLRect item_rect;
#010 
#011    LLGLSUIDefault gls_ui;
#012   
#013    {
#014        LLLocalClipRect clip(mItemListRect);
#015 
#016        S32 cur_y = y;
#017       
#018        mDrewSelected = FALSE;
#019 
#020        S32 line = 0;
#021        S32 max_columns = 0;
#022 
 
获取高亮度显示的颜色。
#023        LLColor4 highlight_color = LLColor4::white;
#024         F32 type_ahead_timeout = LLUI::sConfigGroup->getF32("TypeAheadTimeout");
#025        highlight_color.mV[VALPHA] = clamp_rescale(mSearchTimer.getElapsedTimeF32(), type_ahead_timeout * 0.7f, type_ahead_timeout, 0.4f, 0.f);
#026 
#027        item_list::iterator iter;
 
下面开始遍历所有列表项。
#028        for (iter = mItemList.begin(); iter != mItemList.end(); iter++)
#029        {
 
获取一个显示的列表项。
#030            LLScrollListItem* item = *iter;
#031           
 
设置列表的位置。
#032            item_rect.setOriginAndSize(
#033                x,
#034                cur_y,
#035                mItemListRect.getWidth(),
#036                mLineHeight );
#037 
#038            //llinfos << item_rect.getWidth() << llendl;
#039 
 
判断是否选中这一项。
#040            if (item->getSelected())
#041            {
#042                mDrewSelected = TRUE;
#043            }
#044 
#045            max_columns = llmax(max_columns, item->getNumColumns());
#046 
#047            LLColor4 fg_color;
#048            LLColor4 bg_color(LLColor4::transparent);
#049 
 
滚动到那一项显示。
#050            if( mScrollLines <= line && line < mScrollLines + num_page_lines )
#051            {
#052                fg_color = (item->getEnabled() ? mFgUnselectedColor : mFgDisabledColor);
#053                if( item->getSelected() && mCanSelect)
#054                {
#055                    // Draw background of selected item
#056                    bg_color = mBgSelectedColor;
#057                    fg_color = (item->getEnabled() ? mFgSelectedColor : mFgDisabledColor);
#058                }
#059                else if (mHighlightedItem == line && mCanSelect)
#060                {
#061                    bg_color = mHighlightedColor;
#062                }
#063                else
#064                {
#065                    if (mDrawStripes && (line % 2 == 0) && (max_columns > 1))
#066                    {
#067                        bg_color = mBgStripeColor;
#068                    }
#069                }
#070 
#071                if (!item->getEnabled())
#072                {
#073                    bg_color = mBgReadOnlyColor;
#074                }
#075 
 
显示一项,通过类LLScrollListItem里的函数draw来显示,第一个参数指明显示位置,第二个参数设置字体颜色,第三个设置背景颜色,第四个设置列表对齐宽度。
#076                item->draw(item_rect, fg_color, bg_color, highlight_color, mColumnPadding);
#077 
#078                cur_y -= mLineHeight;
#079            }
#080            line++;
#081        }
#082    }
#083 }
 
上面这个函数通过遍历mItemList列表里的所有选项,然后计算每一项所在的位置、颜色、对齐的宽度,最后调用类LLScrollListItem里的函数draw来显示列表项。
 
posted @ 2008-06-15 21:04  ajuanabc  阅读(120)  评论(0)    收藏  举报