int GUIPartitionList::Render(void) { if(!isConditionTrue()) return 0; // First step, fill background gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); gr_fill(mRenderX, mRenderY + mHeaderH, mRenderW, mRenderH - mHeaderH); // Next, render the background resource (if it exists) if (mBackground && mBackground->GetResource()) { mBackgroundX = mRenderX + ((mRenderW - mBackgroundW) / 2); mBackgroundY = mRenderY + ((mRenderH - mBackgroundH) / 2); gr_blit(mBackground->GetResource(), 0, 0, mBackgroundW, mBackgroundH, mBackgroundX, mBackgroundY); } // This tells us how many lines we can actually render int lines = (mRenderH - mHeaderH) / (actualLineHeight); int line; if (updateList) { mList.clear(); PartitionManager.Get_Partition_List(ListType, &mList); updateList = false; if (ListType == "backup") MatchList(); } int listSize = mList.size(); int listW = mRenderW; if (listSize < lines) { lines = listSize; scrollingY = 0; mFastScrollRectX = mFastScrollRectY = -1; } else { lines++; if (lines < listSize) lines++; if (listSize >= lines) listW -= mFastScrollW; // space for fast scrollbar else mFastScrollRectX = mFastScrollRectY = -1; // no fast scrollbar } void* fontResource = NULL; if (mFont) fontResource = mFont->GetResource(); int yPos = mRenderY + mHeaderH + scrollingY; int fontOffsetY = (int)((actualLineHeight - mFontHeight) / 2); int currentIconHeight = 0, currentIconWidth = 0; int currentIconOffsetY = 0, currentIconOffsetX = 0; int UnselectedIconOffsetY = (int)((actualLineHeight - mUnselectedIconHeight) / 2), SelectedIconOffsetY = (int)((actualLineHeight - mSelectedIconHeight) / 2); int UnselectedIconOffsetX = (mIconWidth - mUnselectedIconWidth) / 2, SelectedIconOffsetX = (mIconWidth - mSelectedIconWidth) / 2; int actualSelection = mStart; if (isHighlighted) { int selectY = scrollingY; // Locate the correct line for highlighting while (selectY + actualLineHeight < startSelection) { selectY += actualLineHeight; actualSelection++; } if (hasHighlightColor) { // Highlight the area gr_color(mHighlightColor.red, mHighlightColor.green, mHighlightColor.blue, 255); int HighlightHeight = actualLineHeight; if (mRenderY + mHeaderH + selectY + actualLineHeight > mRenderH + mRenderY) { HighlightHeight = actualLineHeight - (mRenderY + mHeaderH + selectY + actualLineHeight - mRenderH - mRenderY); } gr_fill(mRenderX, mRenderY + mHeaderH + selectY, mRenderW, HighlightHeight); } } for (line = 0; line < lines; line++) { Resource* icon; std::string label; if (line + mStart >= listSize) continue; label = mList.at(line + mStart).Display_Name; if (isHighlighted && hasFontHighlightColor && line + mStart == actualSelection) { // Use the highlight color for the font gr_color(mFontHighlightColor.red, mFontHighlightColor.green, mFontHighlightColor.blue, 255); } else { // Set the color for the font gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, 255); } if (mList.at(line + mStart).selected != 0) { icon = mIconSelected; currentIconHeight = mSelectedIconHeight; currentIconWidth = mSelectedIconWidth; currentIconOffsetY = SelectedIconOffsetY; currentIconOffsetX = SelectedIconOffsetX; } else { icon = mIconUnselected; currentIconHeight = mSelectedIconHeight; currentIconWidth = mSelectedIconWidth; currentIconOffsetY = SelectedIconOffsetY; currentIconOffsetX = SelectedIconOffsetX; } if (icon && icon->GetResource()) { int rect_y = 0, image_y = (yPos + currentIconOffsetY); if (image_y + currentIconHeight > mRenderY + mRenderH) rect_y = mRenderY + mRenderH - image_y; else rect_y = currentIconHeight; gr_blit(icon->GetResource(), 0, 0, currentIconWidth, rect_y, mRenderX + currentIconOffsetX, image_y); } gr_textExWH(mRenderX + mIconWidth + 5, yPos + fontOffsetY, label.c_str(), fontResource, mRenderX + listW, mRenderY + mRenderH); // Add the separator if (yPos + actualLineHeight < mRenderH + mRenderY) { gr_color(mSeparatorColor.red, mSeparatorColor.green, mSeparatorColor.blue, 255); gr_fill(mRenderX, yPos + actualLineHeight - mSeparatorH, listW, mSeparatorH); } // Move the yPos yPos += actualLineHeight; } // Render the Header (last so that it overwrites the top most row for per pixel scrolling) // First step, fill background gr_color(mHeaderBackgroundColor.red, mHeaderBackgroundColor.green, mHeaderBackgroundColor.blue, 255); gr_fill(mRenderX, mRenderY, mRenderW, mHeaderH); // Now, we need the header (icon + text) yPos = mRenderY; { Resource* headerIcon; int mIconOffsetX = 0; // render the icon if it exists headerIcon = mHeaderIcon; if (headerIcon && headerIcon->GetResource()) { gr_blit(headerIcon->GetResource(), 0, 0, mHeaderIconWidth, mHeaderIconHeight, mRenderX + ((mHeaderIconWidth - mIconWidth) / 2), (yPos + (int)((mHeaderH - mHeaderIconHeight) / 2))); mIconOffsetX = mIconWidth; } // render the text gr_color(mHeaderFontColor.red, mHeaderFontColor.green, mHeaderFontColor.blue, 255); gr_textExWH(mRenderX + mIconOffsetX + 5, yPos + (int)((mHeaderH - mFontHeight) / 2), mLastValue.c_str(), fontResource, mRenderX + mRenderW, mRenderY + mRenderH); // Add the separator gr_color(mHeaderSeparatorColor.red, mHeaderSeparatorColor.green, mHeaderSeparatorColor.blue, 255); gr_fill(mRenderX, yPos + mHeaderH - mHeaderSeparatorH, mRenderW, mHeaderSeparatorH); } // render fast scroll lines = (mRenderH - mHeaderH) / (actualLineHeight); if(mFastScrollW > 0 && listSize > lines) { int startX = listW + mRenderX; int fWidth = mRenderW - listW; int fHeight = mRenderH - mHeaderH; // line gr_color(mFastScrollLineColor.red, mFastScrollLineColor.green, mFastScrollLineColor.blue, 255); gr_fill(startX + fWidth/2, mRenderY + mHeaderH, mFastScrollLineW, mRenderH - mHeaderH); // rect int pct = ((mStart*actualLineHeight - scrollingY)*100)/((listSize)*actualLineHeight-lines*actualLineHeight); mFastScrollRectX = startX + (fWidth - mFastScrollRectW)/2; mFastScrollRectY = mRenderY+mHeaderH + ((fHeight - mFastScrollRectH)*pct)/100; gr_color(mFastScrollRectColor.red, mFastScrollRectColor.green, mFastScrollRectColor.blue, 255); gr_fill(mFastScrollRectX, mFastScrollRectY, mFastScrollRectW, mFastScrollRectH); } mUpdate = 0; return 0; }
int GUIFileSelector::Render(void) { // First step, fill background gr_color(mBackgroundColor.red, mBackgroundColor.green, mBackgroundColor.blue, 255); gr_fill(mRenderX, mRenderY + mHeaderH, mRenderW, mRenderH - mHeaderH); // Next, render the background resource (if it exists) if (mBackground && mBackground->GetResource()) { mBackgroundX = mRenderX + ((mRenderW - mBackgroundW) / 2); mBackgroundY = mRenderY + ((mRenderH - mBackgroundH) / 2); gr_blit(mBackground->GetResource(), 0, 0, mBackgroundW, mBackgroundH, mBackgroundX, mBackgroundY); } // This tells us how many lines we can actually render int lines = (mRenderH - mHeaderH) / (actualLineHeight); int line; int folderSize = mShowFolders ? mFolderList.size() : 0; int fileSize = mShowFiles ? mFileList.size() : 0; if (folderSize + fileSize < lines) { lines = folderSize + fileSize; scrollingY = 0; } else { lines++; if (lines < folderSize + fileSize) lines++; } void* fontResource = NULL; if (mFont) fontResource = mFont->GetResource(); int yPos = mRenderY + mHeaderH + scrollingY; int fontOffsetY = (int)((actualLineHeight - mFontHeight) / 2); int currentIconHeight = 0, currentIconWidth = 0; int currentIconOffsetY = 0, currentIconOffsetX = 0; int folderIconOffsetY = (int)((actualLineHeight - mFolderIconHeight) / 2), fileIconOffsetY = (int)((actualLineHeight - mFileIconHeight) / 2); int folderIconOffsetX = (mIconWidth - mFolderIconWidth) / 2, fileIconOffsetX = (mIconWidth - mFileIconWidth) / 2; for (line = 0; line < lines; line++) { Resource* icon; std::string label; // Set the color for the font gr_color(mFontColor.red, mFontColor.green, mFontColor.blue, 255); if (line + mStart < folderSize) { icon = mFolderIcon; label = mFolderList.at(line + mStart).fileName; currentIconHeight = mFolderIconHeight; currentIconWidth = mFolderIconWidth; currentIconOffsetY = folderIconOffsetY; currentIconOffsetX = folderIconOffsetX; } else if (line + mStart < folderSize + fileSize) { icon = mFileIcon; label = mFileList.at((line + mStart) - folderSize).fileName; currentIconHeight = mFileIconHeight; currentIconWidth = mFileIconWidth; currentIconOffsetY = fileIconOffsetY; currentIconOffsetX = fileIconOffsetX; } else { continue; } if (icon && icon->GetResource()) { int rect_y = 0, image_y = (yPos + currentIconOffsetY); if (image_y + currentIconHeight > mRenderY + mRenderH) rect_y = mRenderY + mRenderH - image_y; else rect_y = currentIconHeight; gr_blit(icon->GetResource(), 0, 0, currentIconWidth, rect_y, mRenderX + currentIconOffsetX, image_y); } gr_textExWH(mRenderX + mIconWidth + 5, yPos + fontOffsetY, label.c_str(), fontResource, mRenderX + mRenderW, mRenderY + mRenderH); // Add the separator if (yPos + actualLineHeight < mRenderH + mRenderY) { gr_color(mSeparatorColor.red, mSeparatorColor.green, mSeparatorColor.blue, 255); gr_fill(mRenderX, yPos + actualLineHeight - mSeparatorH, mRenderW, mSeparatorH); } // Move the yPos yPos += actualLineHeight; } // Render the Header (last so that it overwrites the top most row for per pixel scrolling) // First step, fill background gr_color(mHeaderBackgroundColor.red, mHeaderBackgroundColor.green, mHeaderBackgroundColor.blue, 255); gr_fill(mRenderX, mRenderY, mRenderW, mHeaderH); // Now, we need the header (icon + text) yPos = mRenderY; { Resource* headerIcon; int mIconOffsetX = 0; // render the icon if it exists headerIcon = mHeaderIcon; if (headerIcon && headerIcon->GetResource()) { gr_blit(headerIcon->GetResource(), 0, 0, mHeaderIconWidth, mHeaderIconHeight, mRenderX + ((mHeaderIconWidth - mIconWidth) / 2), (yPos + (int)((mHeaderH - mHeaderIconHeight) / 2))); mIconOffsetX = mIconWidth; } // render the text gr_color(mHeaderFontColor.red, mHeaderFontColor.green, mHeaderFontColor.blue, 255); gr_textExWH(mRenderX + mIconOffsetX + 5, yPos + (int)((mHeaderH - mFontHeight) / 2), mLastValue.c_str(), fontResource, mRenderX + mRenderW, mRenderY + mRenderH); // Add the separator gr_color(mHeaderSeparatorColor.red, mHeaderSeparatorColor.green, mHeaderSeparatorColor.blue, 255); gr_fill(mRenderX, yPos + mHeaderH - mHeaderSeparatorH, mRenderW, mHeaderSeparatorH); } mUpdate = 0; return 0; }