1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-26 03:22:48 +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:
Maarten ter Huurne 2013-08-09 19:09:57 +02:00
parent 3f299f62b6
commit 71f4391cda
5 changed files with 41 additions and 42 deletions

View File

@ -33,9 +33,6 @@ bool Background::handleButtonPress(InputManager::Button button) {
case InputManager::SETTINGS:
gmenu2x.showSettings();
return true;
case InputManager::MENU:
gmenu2x.contextMenu();
return true;
default:
return false;
}

View File

@ -231,7 +231,6 @@ GMenu2X::GMenu2X()
bg = NULL;
font = NULL;
btnContextMenu = nullptr;
setSkin(confStr["skin"], !fileExists(confStr["wallpaper"]));
layers.insert(layers.begin(), make_shared<Background>(*this));
initMenu();
@ -276,7 +275,6 @@ GMenu2X::~GMenu2X() {
delete PowerSaver::getInstance();
quit();
delete btnContextMenu;
delete font;
delete monitor;
}
@ -390,13 +388,6 @@ void GMenu2X::initMenu() {
menu->setSectionIndex(confInt["section"]);
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);
}
@ -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() {
if (!fileExists(CARD_ROOT))
CARD_ROOT = "";
bool quit = false;
while (!quit) {
paint();
// Paint layers.
for (auto layer : layers) {
layer->paint(*s);
}
s->flip();
//touchscreen
// Handle touchscreen events.
if (ts.available()) {
ts.poll();
btnContextMenu->handleTS();
for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
if ((*it)->handleTouchscreen(ts)) {
break;
@ -640,6 +612,7 @@ void GMenu2X::main() {
}
}
// Handle other input events.
InputManager::Button button = input.waitForPressedButton();
for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
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(); ) {
auto layer = *it;
if (layer->wasDismissed()) {

View File

@ -78,8 +78,6 @@ private:
@return String containing a human readable representation of the free disk space
*/
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
unsigned cpuFreqMin; //!< Minimum CPU frequency
unsigned cpuFreqMax; //!< Maximum theoretical CPU frequency
@ -121,8 +119,6 @@ private:
void initFont();
void initMenu();
void paint();
void showManual();
public:
@ -139,6 +135,8 @@ public:
*/
uint resX, resY, halfX, halfY;
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;
@ -155,7 +153,6 @@ public:
Translator tr;
Surface *s, *bg;
Font *font;
IconButton *btnContextMenu;
//Status functions
void main();

View File

@ -38,12 +38,15 @@
#include "filelister.h"
#include "utilities.h"
#include "debug.h"
#include "iconbutton.h"
using namespace std;
Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts)
: gmenu2x(gmenu2x)
, ts(ts)
, btnContextMenu(new IconButton(gmenu2x, ts, "skin:imgs/menu.png"))
{
readSections(GMENU2X_SYSTEM_DIR "/sections");
readSections(GMenu2X::getHome() + "/sections");
@ -73,6 +76,9 @@ Menu::Menu(GMenu2X *gmenu2x, Touchscreen &ts)
#endif
orderLinks();
btnContextMenu->setPosition(gmenu2x->resX - 38, gmenu2x->bottomBarIconY);
btnContextMenu->setAction(std::bind(&GMenu2X::contextMenu, gmenu2x));
}
Menu::~Menu() {
@ -205,6 +211,23 @@ void Menu::paint(Surface &s) {
width / 2, height - bottomBarHeight + 2,
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) {
@ -230,12 +253,17 @@ bool Menu::handleButtonPress(InputManager::Button button) {
case InputManager::ALTRIGHT:
incSectionIndex();
return true;
case InputManager::MENU:
gmenu2x->contextMenu();
return true;
default:
return false;
}
}
bool Menu::handleTouchscreen(Touchscreen &ts) {
btnContextMenu->handleTS();
ConfIntHash &skinConfInt = gmenu2x->skinConfInt;
const int topBarHeight = skinConfInt["topBarHeight"];
const int screenWidth = gmenu2x->resX;

View File

@ -25,11 +25,13 @@
#include "layer.h"
#include "link.h"
#include <memory>
#include <string>
#include <vector>
class LinkApp;
class GMenu2X;
class IconButton;
class LinkApp;
class Monitor;
@ -42,6 +44,7 @@ class Menu : public Layer {
private:
GMenu2X *gmenu2x;
Touchscreen &ts;
std::unique_ptr<IconButton> btnContextMenu;
int iSection, iLink;
uint iFirstDispRow;
std::vector<std::string> sections;