mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-22 21:59:43 +02:00
Moved linkColumns and linkRows fields into Menu class
This commit is contained in:
parent
8d7ac6e0ba
commit
bdf3cfdf86
@ -394,7 +394,7 @@ void GMenu2X::initMenu() {
|
|||||||
btnContextMenu->setPosition(resX - 38, bottomBarIconY);
|
btnContextMenu->setPosition(resX - 38, bottomBarIconY);
|
||||||
btnContextMenu->setAction(BIND(&GMenu2X::contextMenu));
|
btnContextMenu->setAction(BIND(&GMenu2X::contextMenu));
|
||||||
|
|
||||||
menu->loadIcons();
|
menu->skinUpdated();
|
||||||
|
|
||||||
//DEBUG
|
//DEBUG
|
||||||
//menu->addLink( CARD_ROOT, "sample.pxml", "applications" );
|
//menu->addLink( CARD_ROOT, "sample.pxml", "applications" );
|
||||||
@ -895,11 +895,7 @@ void GMenu2X::setSkin(const string &skin, bool setWallpaper) {
|
|||||||
evalIntConf( &skinConfInt["linkHeight"], 40, 32,120 );
|
evalIntConf( &skinConfInt["linkHeight"], 40, 32,120 );
|
||||||
evalIntConf( &skinConfInt["linkWidth"], 60, 32,120 );
|
evalIntConf( &skinConfInt["linkWidth"], 60, 32,120 );
|
||||||
|
|
||||||
//recalculate some coordinates based on the new element sizes
|
if (menu != NULL) menu->skinUpdated();
|
||||||
linkColumns = (resX-10)/skinConfInt["linkWidth"];
|
|
||||||
linkRows = (resY-35-skinConfInt["topBarHeight"])/skinConfInt["linkHeight"];
|
|
||||||
|
|
||||||
if (menu != NULL) menu->loadIcons();
|
|
||||||
|
|
||||||
//Selection png
|
//Selection png
|
||||||
useSelectionPng = sc.addSkinRes("imgs/selection.png", false) != NULL;
|
useSelectionPng = sc.addSkinRes("imgs/selection.png", false) != NULL;
|
||||||
|
@ -140,7 +140,7 @@ public:
|
|||||||
* Variables needed for elements disposition
|
* Variables needed for elements disposition
|
||||||
*/
|
*/
|
||||||
uint resX, resY, halfX, halfY;
|
uint resX, resY, halfX, halfY;
|
||||||
uint bottomBarIconY, bottomBarTextY, linkColumns, linkRows;
|
uint bottomBarIconY, bottomBarTextY;
|
||||||
|
|
||||||
InputManager input;
|
InputManager input;
|
||||||
|
|
||||||
|
44
src/menu.cpp
44
src/menu.cpp
@ -109,7 +109,13 @@ void Menu::readSections(std::string parentDir)
|
|||||||
closedir(dirp);
|
closedir(dirp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::loadIcons() {
|
void Menu::skinUpdated() {
|
||||||
|
ConfIntHash &skinConfInt = gmenu2x->skinConfInt;
|
||||||
|
|
||||||
|
//recalculate some coordinates based on the new element sizes
|
||||||
|
linkColumns = (gmenu2x->resX - 10) / skinConfInt["linkWidth"];
|
||||||
|
linkRows = (gmenu2x->resY - 35 - skinConfInt["topBarHeight"]) / skinConfInt["linkHeight"];
|
||||||
|
|
||||||
//reload section icons
|
//reload section icons
|
||||||
vector<string>::size_type i = 0;
|
vector<string>::size_type i = 0;
|
||||||
for (string sectionName : sections) {
|
for (string sectionName : sections) {
|
||||||
@ -127,7 +133,6 @@ void Menu::loadIcons() {
|
|||||||
|
|
||||||
void Menu::paint(Surface &s) {
|
void Menu::paint(Surface &s) {
|
||||||
const uint width = s.width(), height = s.height();
|
const uint width = s.width(), height = s.height();
|
||||||
const uint linkColumns = gmenu2x->linkColumns, linkRows = gmenu2x->linkRows;
|
|
||||||
Font &font = *gmenu2x->font;
|
Font &font = *gmenu2x->font;
|
||||||
SurfaceCollection sc = gmenu2x->sc;
|
SurfaceCollection sc = gmenu2x->sc;
|
||||||
|
|
||||||
@ -205,7 +210,6 @@ void Menu::handleTS() {
|
|||||||
const int topBarHeight = skinConfInt["topBarHeight"];
|
const int topBarHeight = skinConfInt["topBarHeight"];
|
||||||
const int linkWidth = skinConfInt["linkWidth"];
|
const int linkWidth = skinConfInt["linkWidth"];
|
||||||
const int screenWidth = gmenu2x->resX;
|
const int screenWidth = gmenu2x->resX;
|
||||||
const uint linkColumns = gmenu2x->linkColumns, linkRows = gmenu2x->linkRows;
|
|
||||||
|
|
||||||
SDL_Rect re = {
|
SDL_Rect re = {
|
||||||
0, 0,
|
0, 0,
|
||||||
@ -474,15 +478,17 @@ bool Menu::linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSecti
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Menu::linkLeft() {
|
void Menu::linkLeft() {
|
||||||
if (iLink%gmenu2x->linkColumns == 0)
|
if (iLink % linkColumns == 0)
|
||||||
setLinkIndex( sectionLinks()->size()>iLink+gmenu2x->linkColumns-1 ? iLink+gmenu2x->linkColumns-1 : sectionLinks()->size()-1 );
|
setLinkIndex(sectionLinks()->size() > iLink + linkColumns - 1
|
||||||
|
? iLink + linkColumns - 1 : sectionLinks()->size() - 1);
|
||||||
else
|
else
|
||||||
setLinkIndex(iLink - 1);
|
setLinkIndex(iLink - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::linkRight() {
|
void Menu::linkRight() {
|
||||||
if (iLink%gmenu2x->linkColumns == (gmenu2x->linkColumns-1) || iLink == (int)sectionLinks()->size()-1)
|
if (iLink % linkColumns == linkColumns - 1
|
||||||
setLinkIndex(iLink-iLink%gmenu2x->linkColumns);
|
|| iLink == (int)sectionLinks()->size() - 1)
|
||||||
|
setLinkIndex(iLink - iLink % linkColumns);
|
||||||
else
|
else
|
||||||
setLinkIndex(iLink + 1);
|
setLinkIndex(iLink + 1);
|
||||||
}
|
}
|
||||||
@ -490,27 +496,27 @@ void Menu::linkRight() {
|
|||||||
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
|
||||||
|
|
||||||
void Menu::linkUp() {
|
void Menu::linkUp() {
|
||||||
int l = iLink-gmenu2x->linkColumns;
|
int l = iLink - linkColumns;
|
||||||
if (l<0) {
|
if (l<0) {
|
||||||
unsigned int rows;
|
unsigned int rows;
|
||||||
rows = DIV_ROUND_UP(sectionLinks()->size(), gmenu2x->linkColumns);
|
rows = DIV_ROUND_UP(sectionLinks()->size(), linkColumns);
|
||||||
l = (rows*gmenu2x->linkColumns)+l;
|
l = (rows * linkColumns) + l;
|
||||||
if (l >= (int)sectionLinks()->size())
|
if (l >= (int)sectionLinks()->size())
|
||||||
l -= gmenu2x->linkColumns;
|
l -= linkColumns;
|
||||||
}
|
}
|
||||||
setLinkIndex(l);
|
setLinkIndex(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::linkDown() {
|
void Menu::linkDown() {
|
||||||
uint l = iLink+gmenu2x->linkColumns;
|
uint l = iLink + linkColumns;
|
||||||
if (l >= sectionLinks()->size()) {
|
if (l >= sectionLinks()->size()) {
|
||||||
unsigned int rows, curCol;
|
unsigned int rows, curCol;
|
||||||
rows = DIV_ROUND_UP(sectionLinks()->size(), gmenu2x->linkColumns);
|
rows = DIV_ROUND_UP(sectionLinks()->size(), linkColumns);
|
||||||
curCol = DIV_ROUND_UP(iLink + 1, gmenu2x->linkColumns);
|
curCol = DIV_ROUND_UP(iLink + 1, linkColumns);
|
||||||
if (rows > curCol)
|
if (rows > curCol)
|
||||||
l = sectionLinks()->size() - 1;
|
l = sectionLinks()->size() - 1;
|
||||||
else
|
else
|
||||||
l %= gmenu2x->linkColumns;
|
l %= linkColumns;
|
||||||
}
|
}
|
||||||
setLinkIndex(l);
|
setLinkIndex(l);
|
||||||
}
|
}
|
||||||
@ -534,10 +540,10 @@ void Menu::setLinkIndex(int i) {
|
|||||||
else if (i>=(int)sectionLinks()->size())
|
else if (i>=(int)sectionLinks()->size())
|
||||||
i=0;
|
i=0;
|
||||||
|
|
||||||
if (i>=(int)(iFirstDispRow*gmenu2x->linkColumns+gmenu2x->linkColumns*gmenu2x->linkRows))
|
if (i >= (int)(iFirstDispRow * linkColumns + linkColumns * linkRows))
|
||||||
iFirstDispRow = i/gmenu2x->linkColumns-gmenu2x->linkRows+1;
|
iFirstDispRow = i / linkColumns - linkRows + 1;
|
||||||
else if (i<(int)(iFirstDispRow*gmenu2x->linkColumns))
|
else if (i<(int)(iFirstDispRow * linkColumns))
|
||||||
iFirstDispRow = i/gmenu2x->linkColumns;
|
iFirstDispRow = i / linkColumns;
|
||||||
|
|
||||||
iLink = i;
|
iLink = i;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ private:
|
|||||||
std::vector<std::string> sections;
|
std::vector<std::string> sections;
|
||||||
std::vector< std::vector<Link*> > links;
|
std::vector< std::vector<Link*> > links;
|
||||||
|
|
||||||
|
uint linkColumns, linkRows;
|
||||||
|
|
||||||
std::vector<Link*> *sectionLinks(int i = -1);
|
std::vector<Link*> *sectionLinks(int i = -1);
|
||||||
|
|
||||||
void readLinks();
|
void readLinks();
|
||||||
@ -92,7 +94,7 @@ public:
|
|||||||
void deleteSelectedLink();
|
void deleteSelectedLink();
|
||||||
void deleteSelectedSection();
|
void deleteSelectedSection();
|
||||||
|
|
||||||
void loadIcons();
|
void skinUpdated();
|
||||||
void paint(Surface &s);
|
void paint(Surface &s);
|
||||||
void handleTS();
|
void handleTS();
|
||||||
bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
|
bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
|
||||||
|
Loading…
Reference in New Issue
Block a user