Root/src/menu.h

1/***************************************************************************
2 * Copyright (C) 2006 by Massimiliano Torromeo *
3 * massimiliano.torromeo@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#ifndef MENU_H
22#define MENU_H
23
24#include "delegate.h"
25#include "layer.h"
26#include "link.h"
27
28#include <memory>
29#include <string>
30#include <vector>
31
32class GMenu2X;
33class IconButton;
34class LinkApp;
35class Monitor;
36
37
38/**
39Handles the menu structure
40
41    @author Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
42*/
43class Menu : public Layer {
44private:
45    class Animation {
46    public:
47        Animation();
48        bool isRunning() { return curr != 0; }
49        int currentValue() { return curr; }
50        void adjust(int delta);
51        void step();
52    private:
53        int curr;
54    };
55
56    GMenu2X *gmenu2x;
57    Touchscreen &ts;
58    std::unique_ptr<IconButton> btnContextMenu;
59    int iSection, iLink;
60    uint iFirstDispRow;
61    std::vector<std::string> sections;
62    std::vector< std::vector<Link*> > links;
63
64    uint linkColumns, linkRows;
65
66    Animation sectionAnimation;
67
68    /**
69     * Determine which section headers are visible.
70     * The output values are relative to the middle section at 0.
71     */
72    void calcSectionRange(int &leftSection, int &rightSection);
73
74    std::vector<Link*> *sectionLinks(int i = -1);
75
76    void readLinks();
77    void freeLinks();
78    void orderLinks();
79
80    // Load all the sections of the given "sections" directory.
81    void readSections(std::string parentDir);
82
83#ifdef HAVE_LIBOPK
84    // Load all the .opk packages of the given directory
85    void readPackages(std::string parentDir);
86#ifdef ENABLE_INOTIFY
87    std::vector<Monitor *> monitors;
88#endif
89#endif
90
91    // Load all the links on the given section directory.
92    void readLinksOfSection(std::string path, std::vector<std::string> &linkfiles);
93
94    void decSectionIndex();
95    void incSectionIndex();
96    void linkLeft();
97    void linkRight();
98    void linkUp();
99    void linkDown();
100
101public:
102    Menu(GMenu2X *gmenu2x, Touchscreen &ts);
103    virtual ~Menu();
104
105#ifdef HAVE_LIBOPK
106    void openPackage(std::string path, bool order = true);
107    void openPackagesFromDir(std::string path);
108#ifdef ENABLE_INOTIFY
109    void removePackageLink(std::string path);
110#endif
111#endif
112
113    int selSectionIndex();
114    const std::string &selSection();
115    void setSectionIndex(int i);
116
117    bool addActionLink(uint section, const std::string &title,
118            function_t action, const std::string &description="",
119            const std::string &icon="");
120    bool addLink(std::string path, std::string file, std::string section="");
121    bool addSection(const std::string &sectionName);
122    void deleteSelectedLink();
123    void deleteSelectedSection();
124
125    void skinUpdated();
126
127    // Layer implementation:
128    virtual bool runAnimations();
129    virtual void paint(Surface &s);
130    virtual bool handleButtonPress(InputManager::Button button);
131    virtual bool handleTouchscreen(Touchscreen &ts);
132
133    bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
134
135    int selLinkIndex();
136    Link *selLink();
137    LinkApp *selLinkApp();
138    void setLinkIndex(int i);
139
140    const std::vector<std::string> &getSections() { return sections; }
141    void renameSection(int index, const std::string &name);
142};
143
144#endif // MENU_H
145

Archive Download this file



interactive