diff options
Diffstat (limited to '')
-rw-r--r-- | gui/fileselector.cpp | 96 |
1 files changed, 94 insertions, 2 deletions
diff --git a/gui/fileselector.cpp b/gui/fileselector.cpp index bc10f917d..edf3279f4 100644 --- a/gui/fileselector.cpp +++ b/gui/fileselector.cpp @@ -53,6 +53,8 @@ GUIFileSelector::GUIFileSelector(xml_node<>* node) mFolderIcon = mFileIcon = mBackground = mFont = mHeaderIcon = NULL; mBackgroundX = mBackgroundY = mBackgroundW = mBackgroundH = 0; mShowFolders = mShowFiles = mShowNavFolders = 1; + mFastScrollW = mFastScrollLineW = mFastScrollRectW = mFastScrollRectH = 0; + mFastScrollRectX = mFastScrollRectY = -1; mUpdate = 0; touchDebounce = 6; mPathVar = "cwd"; @@ -62,6 +64,8 @@ GUIFileSelector::GUIFileSelector(xml_node<>* node) ConvertStrToColor("black", &mHeaderSeparatorColor); ConvertStrToColor("white", &mFontColor); ConvertStrToColor("white", &mHeaderFontColor); + ConvertStrToColor("white", &mFastScrollLineColor); + ConvertStrToColor("white", &mFastScrollRectColor); hasHighlightColor = false; hasFontHighlightColor = false; isHighlighted = false; @@ -276,6 +280,43 @@ GUIFileSelector::GUIFileSelector(xml_node<>* node) } else mSelection = "0"; + // Fast scroll colors + child = node->first_node("fastscroll"); + if (child) + { + attr = child->first_attribute("linecolor"); + if(attr) + ConvertStrToColor(attr->value(), &mFastScrollLineColor); + + attr = child->first_attribute("rectcolor"); + if(attr) + ConvertStrToColor(attr->value(), &mFastScrollRectColor); + + attr = child->first_attribute("w"); + if (attr) { + string parsevalue = gui_parse_text(attr->value()); + mFastScrollW = atoi(parsevalue.c_str()); + } + + attr = child->first_attribute("linew"); + if (attr) { + string parsevalue = gui_parse_text(attr->value()); + mFastScrollLineW = atoi(parsevalue.c_str()); + } + + attr = child->first_attribute("rectw"); + if (attr) { + string parsevalue = gui_parse_text(attr->value()); + mFastScrollRectW = atoi(parsevalue.c_str()); + } + + attr = child->first_attribute("recth"); + if (attr) { + string parsevalue = gui_parse_text(attr->value()); + mFastScrollRectH = atoi(parsevalue.c_str()); + } + } + // Retrieve the line height gr_getFontDetails(mFont ? mFont->GetResource() : NULL, &mFontHeight, NULL); mLineHeight = mFontHeight; @@ -355,10 +396,14 @@ int GUIFileSelector::Render(void) int folderSize = mShowFolders ? mFolderList.size() : 0; int fileSize = mShowFiles ? mFileList.size() : 0; + int listW = mRenderW; + if (folderSize + fileSize < lines) { lines = folderSize + fileSize; scrollingY = 0; + mFastScrollRectX = mFastScrollRectY = -1; } else { + listW -= mFastScrollW; // space for fast scroll lines++; if (lines < folderSize + fileSize) lines++; @@ -437,12 +482,12 @@ int GUIFileSelector::Render(void) 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); + 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, mRenderW, mSeparatorH); + gr_fill(mRenderX, yPos + actualLineHeight - mSeparatorH, listW, mSeparatorH); } // Move the yPos @@ -477,6 +522,27 @@ int GUIFileSelector::Render(void) gr_fill(mRenderX, yPos + mHeaderH - mHeaderSeparatorH, mRenderW, mHeaderSeparatorH); } + // render fast scroll + lines = (mRenderH - mHeaderH) / (actualLineHeight); + if(mFastScrollW > 0 && folderSize + fileSize > 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)/((folderSize + fileSize)*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; } @@ -591,6 +657,32 @@ int GUIFileSelector::NotifyTouch(TOUCH_STATE state, int x, int y) break; } + // Fast scroll + if(mFastScrollRectX != -1 && x >= mRenderX + mRenderW - mFastScrollW) + { + int pct = ((y-mRenderY-mHeaderH)*100)/(mRenderH-mHeaderH); + int totalSize = (mShowFolders ? mFolderList.size() : 0) + (mShowFiles ? mFileList.size() : 0); + int lines = (mRenderH - mHeaderH) / (actualLineHeight); + + float l = float((totalSize-lines)*pct)/100; + if(l + lines >= totalSize) + { + mStart = totalSize - lines; + scrollingY = 0; + } + else + { + mStart = l; + scrollingY = -(l - int(l))*actualLineHeight; + } + + startSelection = -1; + mUpdate = 1; + scrollingSpeed = 0; + isHighlighted = false; + break; + } + // Provide some debounce on initial touches if (startSelection != -1 && abs(y - startY) < touchDebounce) { isHighlighted = true; |