diff options
author | Kahrl <kahrl@gmx.net> | 2012-02-01 00:56:30 +0100 |
---|---|---|
committer | Kahrl <kahrl@gmx.net> | 2012-02-01 00:56:30 +0100 |
commit | 0c3d39357b7006844f5e86baf21704d3fa8a7be7 (patch) | |
tree | c26b550d9b953131c421723b138e521616be8dec /src/utility.h | |
parent | 0e8bd531c243c4e19217ef249c2316710cee44cc (diff) | |
download | minetest-0c3d39357b7006844f5e86baf21704d3fa8a7be7.tar.gz minetest-0c3d39357b7006844f5e86baf21704d3fa8a7be7.tar.bz2 minetest-0c3d39357b7006844f5e86baf21704d3fa8a7be7.zip |
F1 toggles HUD, F2 toggles chat, F5 toggles debug info, F6 toggles profiler pages
Diffstat (limited to 'src/utility.h')
-rw-r--r-- | src/utility.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h index 50f27c11b..f4c7c3017 100644 --- a/src/utility.h +++ b/src/utility.h @@ -1757,6 +1757,50 @@ protected: float m_accumulator; }; +/* + Splits a list into "pages". For example, the list [1,2,3,4,5] split + into two pages would be [1,2,3],[4,5]. This function computes the + minimum and maximum indices of a single page. + + length: Length of the list that should be split + page: Page number, 1 <= page <= pagecount + pagecount: The number of pages, >= 1 + minindex: Receives the minimum index (inclusive). + maxindex: Receives the maximum index (exclusive). + + Ensures 0 <= minindex <= maxindex <= length. +*/ +inline void paging(u32 length, u32 page, u32 pagecount, u32 &minindex, u32 &maxindex) +{ + if(length < 1 || pagecount < 1 || page < 1 || page > pagecount) + { + // Special cases or invalid parameters + minindex = maxindex = 0; + } + else if(pagecount <= length) + { + // Less pages than entries in the list: + // Each page contains at least one entry + minindex = (length * (page-1) + (pagecount-1)) / pagecount; + maxindex = (length * page + (pagecount-1)) / pagecount; + } + else + { + // More pages than entries in the list: + // Make sure the empty pages are at the end + if(page < length) + { + minindex = page-1; + maxindex = page; + } + else + { + minindex = 0; + maxindex = 0; + } + } +} + std::string translatePassword(std::string playername, std::wstring password); enum PointedThingType |