From 81a1dce92cf820068b058a501ac8191e07539980 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Wed, 18 Mar 2020 16:34:25 +0000 Subject: [PATCH] CWFs, formatting and cast changes for WSelectList --- wselectlist.cc | 125 ++++++++++++++++++++++--------------------------- wselectlist.h | 40 +++++++--------- 2 files changed, 74 insertions(+), 91 deletions(-) diff --git a/wselectlist.cc b/wselectlist.cc index e11dad2..1eaff37 100644 --- a/wselectlist.cc +++ b/wselectlist.cc @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,31 +14,20 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ -#include "wselectlist.h" +#include +#include #include "colour.h" #include "log.h" -#include -#include +#include "wselectlist.h" WSelectList::WSelectList(): backgroundColour(DrawStyle::VIEWBACKGROUND) { - selectedOption = 0; - topOption = 0; - numOptionsDisplayable = 0; - numColumns = 0; - noLoop = 0; - gap = 1; - showseloption = true; - darkseloption = false; - linesPerOption = 1; - } WSelectList::~WSelectList() @@ -83,7 +72,7 @@ void WSelectList::hintSetTop(int idx) topOption = idx; } -int WSelectList::addOption(const char* text, void* data, int selected, TVMediaInfo * pict) +int WSelectList::addOption(const char* text, void* data, int selected, TVMediaInfo* pict) { int thisNewOption = options.size(); @@ -100,9 +89,9 @@ int WSelectList::addOption(const char* text, void* data, int selected, TVMediaIn void WSelectList::draw() { int fontHeight = getFontHeight(); - int ySeperation = (int) (fontHeight * linesPerOption + gap); + int ySeparation = static_cast(static_cast(fontHeight) * linesPerOption) + gap; - numOptionsDisplayable = (area.h - 5) / ySeperation; + numOptionsDisplayable = (area.h - 5) / ySeparation; if (selectedOption == (topOption + numOptionsDisplayable)) topOption++; if (selectedOption == ((UINT)topOption - 1)) topOption--; @@ -121,12 +110,12 @@ void WSelectList::draw() for (UINT i = topOption; i < (topOption + numOptionsDisplayable); i++) { if (i == options.size()) return; - if ((ypos + ySeperation) > area.h) break; + if ((ypos + ySeparation) > area.h) break; if (i == selectedOption && showseloption) { - rectangle(0, ypos, area.w, (UINT)(fontHeight * linesPerOption-1), darkseloption ? DrawStyle::SELECTDARKHIGHLIGHT: DrawStyle::SELECTHIGHLIGHT); + rectangle(0, ypos, area.w, (UINT)(fontHeight * linesPerOption-1), darkseloption ? DrawStyle::SELECTDARKHIGHLIGHT : DrawStyle::SELECTHIGHLIGHT); drawOptionLine(options[i].text, 5, ypos, area.w - 5, DrawStyle::DARKTEXT, options[i].pict); } @@ -136,9 +125,8 @@ void WSelectList::draw() drawOptionLine(options[i].text, 5, ypos, area.w - 5, DrawStyle::LIGHTTEXT, options[i].pict); } - ypos += ySeperation; + ypos += ySeparation; } - } void WSelectList::addColumn(int x) @@ -149,8 +137,8 @@ void WSelectList::addColumn(int x) int WSelectList::getColumn(int x) { - if (x>= numColumns) return 0; - return columns[x]; + if (x >= numColumns) return 0; + return columns[x]; } void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict) @@ -158,21 +146,20 @@ void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, cons UINT curline = 0; UINT taboffset = 0; int fontHeight = getFontHeight(); - float ypos_mod= ypos + (linesPerOption-floor(linesPerOption))*((float)fontHeight)*0.5f; + float ypos_mod = ypos + (linesPerOption - floor(linesPerOption)) * ((float)fontHeight) * 0.5f; - int imagewidth=0; - int xposmod=xpos; - if (numColumns>1) imagewidth=columns[1]-columns[0]; + int imagewidth = 0; + int xposmod = xpos; + if (numColumns > 1) imagewidth = columns[1] - columns[0]; if (pict) { - drawTVMedia(*pict, xpos,ypos,imagewidth,fontHeight*linesPerOption,TopLeftLimited); - taboffset++; - xposmod+=xpos; + drawTVMedia(*pict, xpos, ypos, imagewidth, fontHeight * linesPerOption, TopLeftLimited); + taboffset++; + xposmod += xpos; } if (!numColumns && linesPerOption == 1) { - drawText(text, xpos, ypos, width, colour); } else @@ -189,15 +176,17 @@ void WSelectList::drawOptionLine(char* text, int xpos, int ypos, int width, cons drawText(pointer, xposmod + columns[currentColumn], (int)(ypos_mod + curline * fontHeight), width - columns[currentColumn], colour); pointer = STRTOKR(NULL, "\t\n", &savepointer); - if (pointer) { - char delimiter = text[pointer - buffer-1]; - if (delimiter == '\t') currentColumn++; - else if (delimiter == '\n' ){ - currentColumn = taboffset; - curline++; - } + if (pointer) + { + char delimiter = text[pointer - buffer - 1]; + if (delimiter == '\t') currentColumn++; + else if (delimiter == '\n') + { + currentColumn = taboffset; + curline++; + } } - if (curline >= linesPerOption) return; + if (static_cast(curline) >= linesPerOption) return; if (currentColumn == 10) return; } @@ -279,26 +268,27 @@ void* WSelectList::getCurrentOptionData() int WSelectList::getNumOptionsDisplayable() { - return numOptionsDisplayable; + return numOptionsDisplayable; } -bool WSelectList::mouseAndroidScroll(int x, int y,int sx, int sy) +bool WSelectList::mouseAndroidScroll(int /* x */, int /* y */, int /* sx */, int /* sy */) { -/* int fontHeight = getFontHeight(); - int movelines= sy/fontHeight; - - int seloption=selectedOption+movelines; - if (seloption<0) seloption=0; - else if (seloption>options.size()-1) seloption=options.size()-1; - selectedOption=seloption;*/ - return false; - +/* + * int fontHeight = getFontHeight(); + * int movelines= sy/fontHeight; + * + * int seloption=selectedOption+movelines; + * if (seloption<0) seloption=0; + * else if (seloption>options.size()-1) seloption=options.size()-1; + * selectedOption=seloption; +*/ + return false; } bool WSelectList::mouseMove(int x, int y) { - int ml = getMouseLine(x-getRootBoxOffsetX(), y-getRootBoxOffsetY()); - if (ml>=0 && ml!=(int)selectedOption) + int ml = getMouseLine(x - getRootBoxOffsetX(), y - getRootBoxOffsetY()); + if (ml >= 0 && ml != static_cast(selectedOption)) { selectedOption = ml; return true; @@ -308,8 +298,8 @@ bool WSelectList::mouseMove(int x, int y) bool WSelectList::mouseLBDOWN(int x, int y) { - int ml = getMouseLine(x-getRootBoxOffsetX(), y-getRootBoxOffsetY()); - if (ml == (int)selectedOption) + int ml = getMouseLine(x - getRootBoxOffsetX(), y - getRootBoxOffsetY()); + if (ml == static_cast(selectedOption)) { /* caller should generate a OK message*/ return true; @@ -320,30 +310,27 @@ bool WSelectList::mouseLBDOWN(int x, int y) int WSelectList::getMouseLine(int x,int y) { int fontHeight = getFontHeight(); - int ySeperation = (int)(fontHeight * linesPerOption + gap); + int ySeparation = static_cast(static_cast(fontHeight) * linesPerOption) + gap; - if (y<0) return -1; - if (x<0 || x>(int)area.w) return -1; - if (y>(int)(10+numOptionsDisplayable*ySeperation)) return -1; + if (y < 0) return -1; + if (x < 0 || x > (int)area.w) return -1; + if (y > (int)(10 + numOptionsDisplayable * ySeparation)) return -1; int cy = y - 5; - int selected=cy/ySeperation; - if (y<5) selected=-1; - if (selected> ((int)numOptionsDisplayable)) return -1; + int selected = cy / ySeparation; + if (y < 5) selected = -1; + if (selected > static_cast(numOptionsDisplayable)) return -1; /* Important: should be the same algorithm used in draw! */ if (selectedOption == (topOption + numOptionsDisplayable)) topOption++; - if (selectedOption == ((UINT)topOption - 1)) topOption--; + if (selectedOption == static_cast(topOption - 1)) topOption--; // if still not visible... - if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable))) + if ((selectedOption < static_cast(topOption)) || (selectedOption > (topOption + numOptionsDisplayable))) { topOption = selectedOption - (numOptionsDisplayable / 2); } if (topOption < 0) topOption = 0; - - if ((selected+topOption >= (int) options.size()) || - (selected + topOption < 0)) return -1; - + if ((selected + topOption >= static_cast(options.size())) || (selected + topOption < 0)) return -1; return selected + topOption; } diff --git a/wselectlist.h b/wselectlist.h index 07db58e..4643ea4 100644 --- a/wselectlist.h +++ b/wselectlist.h @@ -1,5 +1,5 @@ /* - Copyright 2004-2005 Chris Tallon + Copyright 2004-2020 Chris Tallon This file is part of VOMP. @@ -14,16 +14,12 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with VOMP; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + along with VOMP. If not, see . */ #ifndef WSELECTLIST_H #define WSELECTLIST_H -#include -#include - #include #include "defines.h" @@ -33,7 +29,7 @@ typedef struct { char* text; void* data; - TVMediaInfo *pict; + TVMediaInfo* pict; } wsloption; class WSelectList : public Boxx @@ -46,12 +42,12 @@ class WSelectList : public Boxx int getColumn(int x); void setNoLoop(); - void setShowSelOption(bool set) { showseloption = set; }; - void setDarkSelOption(bool set) { darkseloption = set; }; - int addOption(const char* text, void* data, int selected, TVMediaInfo * pict=NULL); + void setShowSelOption(bool set) { showseloption = set; } + void setDarkSelOption(bool set) { darkseloption = set; } + int addOption(const char* text, void* data, int selected, TVMediaInfo* pict = NULL); void draw(); void setBackgroundColour(const DrawStyle& colour); - void setLinesPerOption(float lines) {linesPerOption=lines;}; + void setLinesPerOption(float lines) { linesPerOption = lines; } void down(); void up(); @@ -70,24 +66,24 @@ class WSelectList : public Boxx virtual bool mouseMove(int x, int y); virtual bool mouseLBDOWN(int x, int y); - virtual bool mouseAndroidScroll(int x, int y,int sx, int sy); + virtual bool mouseAndroidScroll(int x, int y, int sx, int sy); private: void drawOptionLine(char* text, int xpos, int ypos, int width, const DrawStyle& colour, TVMediaInfo* pict); int getMouseLine(int x, int y); + DrawStyle backgroundColour; std::vector options; - UINT selectedOption; - int topOption; - UINT numOptionsDisplayable; + UINT selectedOption{}; + int topOption{}; + UINT numOptionsDisplayable{}; int columns[10]; - int numColumns; - int noLoop; - bool showseloption, darkseloption; - float linesPerOption; - - UINT gap; - DrawStyle backgroundColour; + int numColumns{}; + int noLoop{}; + bool showseloption{true}; + bool darkseloption{}; + float linesPerOption{1}; + UINT gap{1}; }; #endif -- 2.39.5