/*
- 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()
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();
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--;
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);
}
drawOptionLine(options[i].text, 5, ypos, area.w - 5, DrawStyle::LIGHTTEXT, options[i].pict);
}
- ypos += ySeperation;
+ ypos += ySeparation;
}
-
}
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)
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
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;
}
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;
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;
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;
}
/*
- 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"
{
char* text;
void* data;
- TVMediaInfo *pict;
+ TVMediaInfo* pict;
} wsloption;
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();
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