]> git.vomp.tv Git - vompclient.git/commitdiff
CWFs, formatting and cast changes for WSelectList
authorChris Tallon <chris@vomp.tv>
Wed, 18 Mar 2020 16:34:25 +0000 (16:34 +0000)
committerChris Tallon <chris@vomp.tv>
Wed, 18 Mar 2020 16:34:25 +0000 (16:34 +0000)
wselectlist.cc
wselectlist.h

index e11dad2f51a999f2a3cc403791d38cb375799370..1eaff37bdffe67aa571e435df73eaf24b1bc5fac 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright 2004-2005 Chris Tallon
+    Copyright 2004-2020 Chris Tallon
 
     This file is part of VOMP.
 
     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 <https://www.gnu.org/licenses/>.
 */
 
-#include "wselectlist.h"
+#include <math.h>
+#include <string.h>
 
 #include "colour.h"
 #include "log.h"
 
-#include <math.h>
-#include <string.h>
+#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<int>(static_cast<float>(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<float>(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<int>(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<int>(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<int>(static_cast<float>(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<int>(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<UINT>(topOption - 1)) topOption--;
   // if still not visible...
-  if ((selectedOption < (UINT)topOption) || (selectedOption > (topOption + numOptionsDisplayable)))
+  if ((selectedOption < static_cast<UINT>(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<int>(options.size())) || (selected + topOption < 0)) return -1;
   return selected + topOption;
 }
index 07db58e95d7d70d99c60855e74530f5b30d8ea5c..4643ea474c2659335a19b414876a75b9649a1d79 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright 2004-2005 Chris Tallon
+    Copyright 2004-2020 Chris Tallon
 
     This file is part of VOMP.
 
     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 <https://www.gnu.org/licenses/>.
 */
 
 #ifndef WSELECTLIST_H
 #define WSELECTLIST_H
 
-#include <stdio.h>
-#include <string.h>
-
 #include <vector>
 
 #include "defines.h"
@@ -33,7 +29,7 @@ typedef struct
 {
   char* text;
   void* data;
-  TVMediaInfo *pict;
+  TVMediaInfopict;
 } 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<wsloption> 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