mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-26 05:24:03 +02:00
Moved all code for opening the context menu into the Menu class
All of the entries in the context menu affect sections and links, so the context menu should be considered part of the main menu, not of the global / background context.
This commit is contained in:
parent
3f299f62b6
commit
71f4391cda
@ -33,9 +33,6 @@ bool Background::handleButtonPress(InputManager::Button button) {
|
|||||||
case InputManager::SETTINGS:
|
case InputManager::SETTINGS:
|
||||||
gmenu2x.showSettings();
|
gmenu2x.showSettings();
|
||||||
return true;
|
return true;
|
||||||
case InputManager::MENU:
|
|
||||||
gmenu2x.contextMenu();
|
|
||||||
return true;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,6 @@ GMenu2X::GMenu2X()
|
|||||||
|
|
||||||
bg = NULL;
|
bg = NULL;
|
||||||
font = NULL;
|
font = NULL;
|
||||||
btnContextMenu = nullptr;
|
|
||||||
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
|
||||||
layers.insert(layers.begin(), make_shared<Background>(*this));
|
layers.insert(layers.begin(), make_shared<Background>(*this));
|
||||||
initMenu();
|
initMenu();
|
||||||
@ -276,7 +275,6 @@ GMenu2X::~GMenu2X() {
|
|||||||
delete PowerSaver::getInstance();
|
delete PowerSaver::getInstance();
|
||||||
quit();
|
quit();
|
||||||
|
|
||||||
delete btnContextMenu;
|
|
||||||
delete font;
|
delete font;
|
||||||
delete monitor;
|
delete monitor;
|
||||||
}
|
}
|
||||||
@ -390,13 +388,6 @@ void GMenu2X::initMenu() {
|
|||||||
menu->setSectionIndex(confInt["section"]);
|
menu->setSectionIndex(confInt["section"]);
|
||||||
menu->setLinkIndex(confInt["link"]);
|
menu->setLinkIndex(confInt["link"]);
|
||||||
|
|
||||||
btnContextMenu = new IconButton(this, ts, "skin:imgs/menu.png");
|
|
||||||
btnContextMenu->setPosition(resX - 38, bottomBarIconY);
|
|
||||||
btnContextMenu->setAction(BIND(&GMenu2X::contextMenu));
|
|
||||||
|
|
||||||
//DEBUG
|
|
||||||
//menu->addLink( CARD_ROOT, "sample.pxml", "applications" );
|
|
||||||
|
|
||||||
layers.push_back(menu);
|
layers.push_back(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,40 +590,21 @@ void GMenu2X::writeTmp(int selelem, const string &selectordir) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GMenu2X::paint() {
|
|
||||||
for (auto layer : layers) {
|
|
||||||
layer->paint(*s);
|
|
||||||
}
|
|
||||||
|
|
||||||
LinkApp *linkApp = menu->selLinkApp();
|
|
||||||
if (linkApp) {
|
|
||||||
#ifdef ENABLE_CPUFREQ
|
|
||||||
s->write(font, linkApp->clockStr(confInt["maxClock"]), cpuX, bottomBarTextY, Font::HAlignLeft, Font::VAlignMiddle);
|
|
||||||
#endif
|
|
||||||
//Manual indicator
|
|
||||||
if (!linkApp->getManual().empty())
|
|
||||||
sc.skinRes("imgs/manual.png")->blit(s, manualX, bottomBarIconY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ts.available()) {
|
|
||||||
btnContextMenu->paint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GMenu2X::main() {
|
void GMenu2X::main() {
|
||||||
if (!fileExists(CARD_ROOT))
|
if (!fileExists(CARD_ROOT))
|
||||||
CARD_ROOT = "";
|
CARD_ROOT = "";
|
||||||
|
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
|
// Paint layers.
|
||||||
paint();
|
for (auto layer : layers) {
|
||||||
|
layer->paint(*s);
|
||||||
|
}
|
||||||
s->flip();
|
s->flip();
|
||||||
|
|
||||||
//touchscreen
|
// Handle touchscreen events.
|
||||||
if (ts.available()) {
|
if (ts.available()) {
|
||||||
ts.poll();
|
ts.poll();
|
||||||
btnContextMenu->handleTS();
|
|
||||||
for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
|
for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
|
||||||
if ((*it)->handleTouchscreen(ts)) {
|
if ((*it)->handleTouchscreen(ts)) {
|
||||||
break;
|
break;
|
||||||
@ -640,6 +612,7 @@ void GMenu2X::main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle other input events.
|
||||||
InputManager::Button button = input.waitForPressedButton();
|
InputManager::Button button = input.waitForPressedButton();
|
||||||
for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
|
for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
|
||||||
if ((*it)->handleButtonPress(button)) {
|
if ((*it)->handleButtonPress(button)) {
|
||||||
@ -647,6 +620,7 @@ void GMenu2X::main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove dismissed layers from the stack.
|
||||||
for (auto it = layers.begin(); it != layers.end(); ) {
|
for (auto it = layers.begin(); it != layers.end(); ) {
|
||||||
auto layer = *it;
|
auto layer = *it;
|
||||||
if (layer->wasDismissed()) {
|
if (layer->wasDismissed()) {
|
||||||
|
@ -78,8 +78,6 @@ private:
|
|||||||
@return String containing a human readable representation of the free disk space
|
@return String containing a human readable representation of the free disk space
|
||||||
*/
|
*/
|
||||||
std::string getDiskFree(const char *path);
|
std::string getDiskFree(const char *path);
|
||||||
unsigned short cpuX; //!< Offset for displaying cpu clock information
|
|
||||||
unsigned short manualX; //!< Offset for displaying the manual indicator in the taskbar
|
|
||||||
#ifdef ENABLE_CPUFREQ
|
#ifdef ENABLE_CPUFREQ
|
||||||
unsigned cpuFreqMin; //!< Minimum CPU frequency
|
unsigned cpuFreqMin; //!< Minimum CPU frequency
|
||||||
unsigned cpuFreqMax; //!< Maximum theoretical CPU frequency
|
unsigned cpuFreqMax; //!< Maximum theoretical CPU frequency
|
||||||
@ -121,8 +119,6 @@ private:
|
|||||||
void initFont();
|
void initFont();
|
||||||
void initMenu();
|
void initMenu();
|
||||||
|
|
||||||
void paint();
|
|
||||||
|
|
||||||
void showManual();
|
void showManual();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -139,6 +135,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
uint resX, resY, halfX, halfY;
|
uint resX, resY, halfX, halfY;
|
||||||
uint bottomBarIconY, bottomBarTextY;
|
uint bottomBarIconY, bottomBarTextY;
|
||||||
|
unsigned short cpuX; //!< Offset for displaying cpu clock information
|
||||||
|
unsigned short manualX; //!< Offset for displaying the manual indicator in the taskbar
|
||||||
|
|
||||||
InputManager input;
|
InputManager input;
|
||||||
|
|
||||||
@ -155,7 +153,6 @@ public:
|
|||||||
Translator tr;
|
Translator tr;
|
||||||
Surface *s, *bg;
|
Surface *s, *bg;
|
||||||
Font *font;
|
Font *font;
|
||||||
IconButton *btnContextMenu;
|
|
||||||
|
|
||||||
//Status functions
|
//Status functions
|
||||||
void main();
|
void main();
|
||||||
|
28
src/menu.cpp
28
src/menu.cpp
@ -38,12 +38,15 @@
|
|||||||
#include "filelister.h"
|
#include "filelister.h"
|
||||||
#include "utilities.h"
|
#include "utilities.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "iconbutton.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts)
|
Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts)
|
||||||
: gmenu2x(gmenu2x)
|
: gmenu2x(gmenu2x)
|
||||||
, ts(ts)
|
, ts(ts)
|
||||||
|
, btnContextMenu(new IconButton(gmenu2x, ts, "skin:imgs/menu.png"))
|
||||||
{
|
{
|
||||||
readSections(GMENU2X_SYSTEM_DIR "/sections");
|
readSections(GMENU2X_SYSTEM_DIR "/sections");
|
||||||
readSections(GMenu2X::getHome() + "/sections");
|
readSections(GMenu2X::getHome() + "/sections");
|
||||||
@ -73,6 +76,9 @@ Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
orderLinks();
|
orderLinks();
|
||||||
|
|
||||||
|
btnContextMenu->setPosition(gmenu2x->resX - 38, gmenu2x->bottomBarIconY);
|
||||||
|
btnContextMenu->setAction(std::bind(&GMenu2X::contextMenu, gmenu2x));
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu::~Menu() {
|
Menu::~Menu() {
|
||||||
@ -205,6 +211,23 @@ void Menu::paint(Surface &s) {
|
|||||||
width / 2, height - bottomBarHeight + 2,
|
width / 2, height - bottomBarHeight + 2,
|
||||||
Font::HAlignCenter, Font::VAlignBottom);
|
Font::HAlignCenter, Font::VAlignBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinkApp *linkApp = selLinkApp();
|
||||||
|
if (linkApp) {
|
||||||
|
#ifdef ENABLE_CPUFREQ
|
||||||
|
s.write(&font, linkApp->clockStr(gmenu2x->confInt["maxClock"]),
|
||||||
|
gmenu2x->cpuX, gmenu2x->bottomBarTextY,
|
||||||
|
Font::HAlignLeft, Font::VAlignMiddle);
|
||||||
|
#endif
|
||||||
|
//Manual indicator
|
||||||
|
if (!linkApp->getManual().empty())
|
||||||
|
sc.skinRes("imgs/manual.png")->blit(
|
||||||
|
&s, gmenu2x->manualX, gmenu2x->bottomBarIconY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ts.available()) {
|
||||||
|
btnContextMenu->paint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Menu::handleButtonPress(InputManager::Button button) {
|
bool Menu::handleButtonPress(InputManager::Button button) {
|
||||||
@ -230,12 +253,17 @@ bool Menu::handleButtonPress(InputManager::Button button) {
|
|||||||
case InputManager::ALTRIGHT:
|
case InputManager::ALTRIGHT:
|
||||||
incSectionIndex();
|
incSectionIndex();
|
||||||
return true;
|
return true;
|
||||||
|
case InputManager::MENU:
|
||||||
|
gmenu2x->contextMenu();
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Menu::handleTouchscreen(Touchscreen &ts) {
|
bool Menu::handleTouchscreen(Touchscreen &ts) {
|
||||||
|
btnContextMenu->handleTS();
|
||||||
|
|
||||||
ConfIntHash &skinConfInt = gmenu2x->skinConfInt;
|
ConfIntHash &skinConfInt = gmenu2x->skinConfInt;
|
||||||
const int topBarHeight = skinConfInt["topBarHeight"];
|
const int topBarHeight = skinConfInt["topBarHeight"];
|
||||||
const int screenWidth = gmenu2x->resX;
|
const int screenWidth = gmenu2x->resX;
|
||||||
|
@ -25,11 +25,13 @@
|
|||||||
#include "layer.h"
|
#include "layer.h"
|
||||||
#include "link.h"
|
#include "link.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class LinkApp;
|
|
||||||
class GMenu2X;
|
class GMenu2X;
|
||||||
|
class IconButton;
|
||||||
|
class LinkApp;
|
||||||
class Monitor;
|
class Monitor;
|
||||||
|
|
||||||
|
|
||||||
@ -42,6 +44,7 @@ class Menu : public Layer {
|
|||||||
private:
|
private:
|
||||||
GMenu2X *gmenu2x;
|
GMenu2X *gmenu2x;
|
||||||
Touchscreen &ts;
|
Touchscreen &ts;
|
||||||
|
std::unique_ptr<IconButton> btnContextMenu;
|
||||||
int iSection, iLink;
|
int iSection, iLink;
|
||||||
uint iFirstDispRow;
|
uint iFirstDispRow;
|
||||||
std::vector<std::string> sections;
|
std::vector<std::string> sections;
|
||||||
|
Loading…
Reference in New Issue
Block a user