Date:2014-10-05 08:46:48 (5 years 7 months ago)
Author:Nebuleon Fumika
Commit:2a2634b3640286bf05fa5158e5f71ba1d2490aea
Message:Remove all touch-screen-related code

It didn't work anymore, at all. Touchscreen polling occurred only
*after* waiting for a button had completed. So the touchscreen events,
if any, would be ignored until the user had pressed a button, possibly
firing off another action with that button press and forwarding the
touchscreen event to the next interface that got brought up as a
result.

Reusing this code and fixing it would require far more work than
rewriting everything anew with touchscreen devices in mind from the
beginning.

MtH: Resolved conflicts, mainly from the GMenu2X pointer to reference
change I did on 2015-04-21.
Files: src/Makefile.am (2 diffs)
src/background.cpp (1 diff)
src/background.h (1 diff)
src/browsedialog.cpp (5 diffs)
src/browsedialog.h (3 diffs)
src/buttonbox.cpp (1 diff)
src/buttonbox.h (1 diff)
src/contextmenu.cpp (1 diff)
src/contextmenu.h (1 diff)
src/dirdialog.cpp (1 diff)
src/dirdialog.h (1 diff)
src/filedialog.cpp (1 diff)
src/filedialog.h (1 diff)
src/gmenu2x.cpp (10 diffs)
src/gmenu2x.h (3 diffs)
src/helppopup.cpp (1 diff)
src/helppopup.h (1 diff)
src/iconbutton.cpp (2 diffs)
src/iconbutton.h (1 diff)
src/imagedialog.cpp (1 diff)
src/imagedialog.h (1 diff)
src/inputdialog.cpp (6 diffs)
src/inputdialog.h (2 diffs)
src/layer.h (2 diffs)
src/link.cpp (2 diffs)
src/link.h (3 diffs)
src/linkapp.cpp (1 diff)
src/menu.cpp (3 diffs)
src/menu.h (3 diffs)
src/menusetting.cpp (1 diff)
src/menusetting.h (1 diff)
src/menusettingbool.cpp (3 diffs)
src/menusettingbool.h (2 diffs)
src/menusettingdir.cpp (1 diff)
src/menusettingdir.h (1 diff)
src/menusettingfile.cpp (1 diff)
src/menusettingfile.h (1 diff)
src/menusettingimage.cpp (1 diff)
src/menusettingimage.h (1 diff)
src/menusettingint.cpp (2 diffs)
src/menusettingint.h (2 diffs)
src/menusettingmultistring.cpp (2 diffs)
src/menusettingmultistring.h (2 diffs)
src/menusettingrgba.cpp (3 diffs)
src/menusettingrgba.h (2 diffs)
src/menusettingstring.cpp (2 diffs)
src/menusettingstring.h (2 diffs)
src/settingsdialog.cpp (5 diffs)
src/settingsdialog.h (1 diff)
src/touchscreen.cpp (1 diff)
src/touchscreen.h (1 diff)
src/wallpaperdialog.cpp (2 diffs)
src/wallpaperdialog.h (1 diff)

Change Details

src/Makefile.am
99    menusettingstringbase.cpp \
1010    messagebox.cpp selector.cpp \
1111    settingsdialog.cpp surfacecollection.cpp surface.cpp \
12    textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \
12    textdialog.cpp textmanualdialog.cpp translator.cpp \
1313    utilities.cpp wallpaperdialog.cpp \
1414    browsedialog.cpp buttonbox.cpp dialog.cpp \
1515    imageio.cpp powersaver.cpp monitor.cpp mediamonitor.cpp clock.cpp \
...... 
2424    menusettingstringbase.h \
2525    messagebox.h selector.h settingsdialog.h \
2626    surfacecollection.h surface.h textdialog.h textmanualdialog.h \
27    touchscreen.h translator.h utilities.h wallpaperdialog.h \
27    translator.h utilities.h wallpaperdialog.h \
2828    browsedialog.h buttonbox.h dialog.h \
2929    imageio.h powersaver.h monitor.h mediamonitor.h clock.h \
3030    layer.h helppopup.h contextmenu.h background.h battery.h
src/background.cpp
4040            return false;
4141    }
4242}
43
44bool Background::handleTouchscreen(Touchscreen&) {
45    return false;
46}
src/background.h
2121    // Layer implementation:
2222    virtual void paint(Surface& s);
2323    virtual bool handleButtonPress(InputManager::Button button);
24    virtual bool handleTouchscreen(Touchscreen& ts);
2524
2625private:
2726    GMenu2X& gmenu2x;
src/browsedialog.cpp
1111using std::unique_ptr;
1212
1313BrowseDialog::BrowseDialog(
14        GMenu2X& gmenu2x, Touchscreen &ts_,
14        GMenu2X& gmenu2x,
1515        const string &title, const string &subtitle)
1616    : Dialog(gmenu2x)
17    , ts(ts_)
1817    , title(title)
1918    , subtitle(subtitle)
20    , ts_pressed(false)
2119{
2220    buttonBox.add(unique_ptr<IconButton>(new IconButton(
23            gmenu2x, ts, "skin:imgs/buttons/left.png")));
21            gmenu2x, "skin:imgs/buttons/left.png")));
2422    buttonBox.add(unique_ptr<IconButton>(new IconButton(
25            gmenu2x, ts, "skin:imgs/buttons/cancel.png",
23            gmenu2x, "skin:imgs/buttons/cancel.png",
2624            gmenu2x.tr["Up one folder"],
2725            bind(&BrowseDialog::directoryUp, this))));
2826
2927    buttonBox.add(unique_ptr<IconButton>(new IconButton(
30            gmenu2x, ts, "skin:imgs/buttons/accept.png",
28            gmenu2x, "skin:imgs/buttons/accept.png",
3129            gmenu2x.tr["Select"],
3230            bind(&BrowseDialog::directoryEnter, this))));
3331
3432    buttonBox.add(unique_ptr<IconButton>(new IconButton(
35            gmenu2x, ts, "skin:imgs/buttons/start.png",
33            gmenu2x, "skin:imgs/buttons/start.png",
3634            gmenu2x.tr["Confirm"],
3735            bind(&BrowseDialog::confirm, this))));
3836
3937    buttonBox.add(unique_ptr<IconButton>(new IconButton(
40            gmenu2x, ts, "skin:imgs/buttons/select.png",
38            gmenu2x, "skin:imgs/buttons/select.png",
4139            gmenu2x.tr["Exit"],
4240            bind(&BrowseDialog::quit, this))));
4341
...... 
6765        static_cast<Uint16>(gmenu2x.resX - 9),
6866        static_cast<Uint16>(gmenu2x.resY - topBarHeight - 25)
6967    };
70    touchRect = (SDL_Rect) {
71        2,
72        static_cast<Sint16>(topBarHeight + 4),
73        static_cast<Uint16>(gmenu2x.resX - 12),
74        clipRect.h
75    };
7668
7769    selected = 0;
7870    close = false;
7971    while (!close) {
80        if (ts.available()) ts.poll();
81
8272        paint();
8373
8474        handleInput();
...... 
115105void BrowseDialog::handleInput()
116106{
117107    InputManager::Button button = gmenu2x.input.waitForPressedButton();
118
119    BrowseDialog::Action action;
120    if (ts_pressed && !ts.pressed()) {
121        action = BrowseDialog::ACT_SELECT;
122        ts_pressed = false;
123    } else {
124        action = getAction(button);
125    }
126
127    if (ts.available() && ts.pressed() && !ts.inRect(touchRect)) {
128        ts_pressed = false;
129    }
108    BrowseDialog::Action action = getAction(button);
130109
131110    if (action == BrowseDialog::ACT_SELECT && fl[selected] == "..") {
132111        action = BrowseDialog::ACT_GOUP;
...... 
174153    default:
175154        break;
176155    }
177
178    buttonBox.handleTS();
179156}
180157
181158void BrowseDialog::directoryUp()
...... 
274251        gmenu2x.font->write(s, fl[i], 24, offsetY + rowHeight / 2,
275252                Font::HAlignLeft, Font::VAlignMiddle);
276253
277        if (ts.available() && ts.pressed()
278                && ts.inRect(touchRect.x, offsetY + 3, touchRect.w, rowHeight)) {
279            ts_pressed = true;
280            selected = i;
281        }
282
283254        offsetY += rowHeight;
284255    }
285256    s.clearClipRect();
src/browsedialog.h
3030#include <string>
3131
3232class OffscreenSurface;
33class Touchscreen;
3433
3534class BrowseDialog : protected Dialog {
3635protected:
37    BrowseDialog(
38            GMenu2X& gmenu2x, Touchscreen &ts,
36    BrowseDialog(GMenu2X& gmenu2x,
3937            const std::string &title, const std::string &subtitle);
4038    virtual ~BrowseDialog();
4139
...... 
6058        ACT_CONFIRM,
6159    };
6260
63    Touchscreen &ts;
6461    bool close, result;
6562
6663    std::string title;
...... 
6865    std::string path;
6966
7067    SDL_Rect clipRect;
71    SDL_Rect touchRect;
7268
7369    unsigned int numRows;
7470    unsigned int rowHeight;
7571
76    bool ts_pressed;
77
7872    OffscreenSurface *iconGoUp;
7973    OffscreenSurface *iconFolder;
8074    OffscreenSurface *iconFile;
src/buttonbox.cpp
2525        x += button->getRect().w + 6;
2626    }
2727}
28
29void ButtonBox::handleTS()
30{
31    for (auto& button : buttons) {
32        button->handleTS();
33    }
34}
src/buttonbox.h
1616    void clear();
1717
1818    void paint(Surface& s, int x, int y);
19    void handleTS();
2019
2120private:
2221    std::vector<std::unique_ptr<IconButton>> buttons;
src/contextmenu.cpp
157157    }
158158    return true;
159159}
160
161bool ContextMenu::handleTouchscreen(Touchscreen &ts) {
162    if (ts.inRect(box)) {
163        int i = std::max(0, std::min(static_cast<int>(options.size()) - 1,
164                (ts.getY() - (box.y + 4)) / (gmenu2x.font->getLineSpacing() + 2)));
165        if (ts.released()) {
166            options[i]->action();
167            dismiss();
168        } else if (ts.pressed()) {
169            selected = i;
170        }
171    } else {
172        if (ts.released()) {
173            dismiss();
174        }
175    }
176    return true;
177}
src/contextmenu.h
2424    virtual bool runAnimations();
2525    virtual void paint(Surface &s);
2626    virtual bool handleButtonPress(InputManager::Button button);
27    virtual bool handleTouchscreen(Touchscreen &ts);
2827
2928private:
3029    struct MenuOption;
src/dirdialog.cpp
2424
2525using namespace std;
2626
27DirDialog::DirDialog(
28        GMenu2X& gmenu2x, Touchscreen &ts,
29        const string &text, const string &dir)
30    : BrowseDialog(gmenu2x, ts, "Directory Browser", text)
27DirDialog::DirDialog(GMenu2X& gmenu2x, const string &text, const string &dir)
28    : BrowseDialog(gmenu2x, "Directory Browser", text)
3129{
3230    fl.setShowFiles(false);
3331    setPath(dir);
src/dirdialog.h
2525
2626class DirDialog : public BrowseDialog {
2727public:
28    DirDialog(
29            GMenu2X& gmenu2x, Touchscreen &ts,
28    DirDialog(GMenu2X& gmenu2x,
3029            const std::string &text, const std::string &dir = "");
3130};
3231
src/filedialog.cpp
2525using namespace std;
2626
2727FileDialog::FileDialog(
28        GMenu2X& gmenu2x, Touchscreen &ts, const string &text,
28        GMenu2X& gmenu2x, const string &text,
2929        const string &filter, const string &file, const string &title)
30    : BrowseDialog(gmenu2x, ts, title, text)
30    : BrowseDialog(gmenu2x, title, text)
3131{
3232    string path(CARD_ROOT);
3333    if (!file.empty()) {
src/filedialog.h
2626class FileDialog : public BrowseDialog {
2727public:
2828    FileDialog(
29            GMenu2X& gmenu2x, Touchscreen &ts, const std::string &text,
29            GMenu2X& gmenu2x, const std::string &text,
3030            const std::string &filter="*", const std::string &file="",
3131            const std::string &title = "File Dialog");
3232    bool exec();
src/gmenu2x.cpp
376376
377377void GMenu2X::initMenu() {
378378    //Menu structure handler
379    menu.reset(new Menu(*this, ts));
379    menu.reset(new Menu(*this));
380380
381381    // Add action links in the applications section.
382382    auto appIdx = menu->sectionNamed("applications");
...... 
628628            break;
629629        }
630630
631        // Handle touchscreen events.
632        if (ts.available()) {
633            ts.poll();
634            for (auto it = layers.rbegin(); it != layers.rend(); ++it) {
635                if ((*it)->handleTouchscreen(ts)) {
636                    break;
637                }
638            }
639        }
640
641631        // Handle other input events.
642632        InputManager::Button button;
643633        bool gotEvent;
...... 
656646}
657647
658648void GMenu2X::explorer() {
659    FileDialog fd(*this, ts, tr["Select an application"], "sh,bin,py,elf,");
649    FileDialog fd(*this, tr["Select an application"], "sh,bin,py,elf,");
660650    if (fd.exec()) {
661651        if (confInt["saveSelection"] && (confInt["section"]!=menu->selSectionIndex() || confInt["link"]!=menu->selLinkIndex()))
662652            writeConfig();
...... 
701691    encodings.push_back("NTSC");
702692    encodings.push_back("PAL");
703693
704    SettingsDialog sd(*this, input, ts, tr["Settings"]);
694    SettingsDialog sd(*this, input, tr["Settings"]);
705695    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
706            *this, ts, tr["Language"],
696            *this, tr["Language"],
707697            tr["Set the language used by GMenu2X"],
708698            &lang, &translations)));
709699    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
710            *this, ts, tr["Save last selection"],
700            *this, tr["Save last selection"],
711701            tr["Save the last selected link and section on exit"],
712702            &confInt["saveSelection"])));
713703#ifdef ENABLE_CPUFREQ
714704    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
715            *this, ts, tr["Clock for GMenu2X"],
705            *this, tr["Clock for GMenu2X"],
716706            tr["Set the cpu working frequency when running GMenu2X"],
717707            &confInt["menuClock"], cpuFreqMin, cpuFreqSafeMax, cpuFreqMultiple)));
718708    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
719            *this, ts, tr["Maximum overclock"],
709            *this, tr["Maximum overclock"],
720710            tr["Set the maximum overclock for launching links"],
721711            &confInt["maxClock"], cpuFreqMin, cpuFreqMax, cpuFreqMultiple)));
722712#endif
723713    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
724            *this, ts, tr["Output logs"],
714            *this, tr["Output logs"],
725715            tr["Logs the output of the links. Use the Log Viewer to read them."],
726716            &confInt["outputLogs"])));
727717    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
728            *this, ts, tr["Screen Timeout"],
718            *this, tr["Screen Timeout"],
729719            tr["Set screen's backlight timeout in seconds"],
730720            &confInt["backlightTimeout"], 0, 120)));
731721    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
732            *this, ts, tr["Button repeat rate"],
722            *this, tr["Button repeat rate"],
733723            tr["Set button repetitions per second"],
734724            &confInt["buttonRepeatRate"], 0, 20)));
735725
...... 
761751
762752    string curSkin = confStr["skin"];
763753
764    SettingsDialog sd(*this, input, ts, tr["Skin"]);
754    SettingsDialog sd(*this, input, tr["Skin"]);
765755    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
766            *this, ts, tr["Skin"],
756            *this, tr["Skin"],
767757            tr["Set the skin used by GMenu2X"],
768758            &confStr["skin"], &fl_sk.getDirectories())));
769759    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
770            *this, ts, tr["Top Bar"],
760            *this, tr["Top Bar"],
771761            tr["Color of the top bar"],
772762            &skinConfColors[COLOR_TOP_BAR_BG])));
773763    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
774            *this, ts, tr["Bottom Bar"],
764            *this, tr["Bottom Bar"],
775765            tr["Color of the bottom bar"],
776766            &skinConfColors[COLOR_BOTTOM_BAR_BG])));
777767    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
778            *this, ts, tr["Selection"],
768            *this, tr["Selection"],
779769            tr["Color of the selection and other interface details"],
780770            &skinConfColors[COLOR_SELECTION_BG])));
781771    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
782            *this, ts, tr["Message Box"],
772            *this, tr["Message Box"],
783773            tr["Background color of the message box"],
784774            &skinConfColors[COLOR_MESSAGE_BOX_BG])));
785775    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
786            *this, ts, tr["Message Box Border"],
776            *this, tr["Message Box Border"],
787777            tr["Border color of the message box"],
788778            &skinConfColors[COLOR_MESSAGE_BOX_BORDER])));
789779    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA(
790            *this, ts, tr["Message Box Selection"],
780            *this, tr["Message Box Selection"],
791781            tr["Color of the selection of the message box"],
792782            &skinConfColors[COLOR_MESSAGE_BOX_SELECTION])));
793783
...... 
888878}
889879
890880void GMenu2X::changeWallpaper() {
891    WallpaperDialog wp(*this, ts);
881    WallpaperDialog wp(*this);
892882    if (wp.exec() && confStr["wallpaper"] != wp.wallpaper) {
893883        confStr["wallpaper"] = wp.wallpaper;
894884        initBG();
...... 
897887}
898888
899889void GMenu2X::addLink() {
900    FileDialog fd(*this, ts, tr["Select an application"], "sh,bin,py,elf,");
890    FileDialog fd(*this, tr["Select an application"], "sh,bin,py,elf,");
901891    if (fd.exec())
902892        menu->addLink(fd.getPath(), fd.getFile());
903893}
...... 
925915    string diagTitle = tr.translate("Edit $1",linkTitle.c_str(),NULL);
926916    string diagIcon = linkApp->getIconPath();
927917
928    SettingsDialog sd(*this, input, ts, diagTitle, diagIcon);
918    SettingsDialog sd(*this, input, diagTitle, diagIcon);
929919    if (!linkApp->isOpk()) {
930920        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
931                *this, ts, tr["Title"],
921                *this, tr["Title"],
932922                tr["Link title"],
933923                &linkTitle, diagTitle, diagIcon)));
934924        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
935                *this, ts, tr["Description"],
925                *this, tr["Description"],
936926                tr["Link description"],
937927                &linkDescription, diagTitle, diagIcon)));
938928        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
939                *this, ts, tr["Section"],
929                *this, tr["Section"],
940930                tr["The section this link belongs to"],
941931                &newSection, &menu->getSections())));
942932        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingImage(
943                *this, ts, tr["Icon"],
933                *this, tr["Icon"],
944934                tr.translate("Select an icon for this link", linkTitle.c_str(), NULL),
945935                &linkIcon, "png")));
946936        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingFile(
947                *this, ts, tr["Manual"],
937                *this, tr["Manual"],
948938                tr["Select a manual or README file"],
949939                &linkManual, "man.png,txt")));
950940    }
951941    if (!linkApp->isOpk() || !linkApp->getSelectorDir().empty()) {
952942        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingDir(
953                *this, ts, tr["Selector Directory"],
943                *this, tr["Selector Directory"],
954944                tr["Directory to scan for the selector"],
955945                &linkSelDir)));
956946        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
957                *this, ts, tr["Selector Browser"],
947                *this, tr["Selector Browser"],
958948                tr["Allow the selector to change directory"],
959949                &linkSelBrowser)));
960950    }
961951#ifdef ENABLE_CPUFREQ
962952    sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt(
963            *this, ts, tr["Clock frequency"],
953            *this, tr["Clock frequency"],
964954            tr["CPU clock frequency for this link"],
965955            &linkClock, cpuFreqMin, confInt["maxClock"], cpuFreqMultiple)));
966956#endif
967957    if (!linkApp->isOpk()) {
968958        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
969                *this, ts, tr["Selector Filter"],
959                *this, tr["Selector Filter"],
970960                tr["Selector filter (Separate values with a comma)"],
971961                &linkSelFilter, diagTitle, diagIcon)));
972962        sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool(
973                *this, ts, tr["Display Console"],
963                *this, tr["Display Console"],
974964                tr["Must be enabled for console-based applications"],
975965                &linkApp->consoleApp)));
976966    }
...... 
10211011}
10221012
10231013void GMenu2X::addSection() {
1024    InputDialog id(*this, input, ts, tr["Insert a name for the new section"]);
1014    InputDialog id(*this, input, tr["Insert a name for the new section"]);
10251015    if (id.exec()) {
10261016        // Look up section; create if it doesn't exist yet.
10271017        auto idx = menu->sectionNamed(id.getInput());
...... 
10311021}
10321022
10331023void GMenu2X::renameSection() {
1034    InputDialog id(*this, input, ts, tr["Insert a new name for this section"],menu->selSection());
1024    InputDialog id(*this, input, tr["Insert a new name for this section"],menu->selSection());
10351025    if (id.exec()) {
10361026        //only if a section with the same name does not exist & !samename
10371027        if (menu->selSection() != id.getInput()
src/gmenu2x.h
2424#include "contextmenu.h"
2525#include "surfacecollection.h"
2626#include "translator.h"
27#include "touchscreen.h"
2827#include "inputmanager.h"
2928#include "powersaver.h"
3029#include "surface.h"
...... 
7069
7170class GMenu2X {
7271private:
73    Touchscreen ts;
7472    std::shared_ptr<Menu> menu;
7573#ifdef ENABLE_INOTIFY
7674    MediaMonitor *monitor;
...... 
210208
211209    void drawTopBar(Surface& s);
212210    void drawBottomBar(Surface& s);
213
214    Touchscreen &getTouchscreen() { return ts; }
215211};
216212
217213#endif // GMENU2X_H
src/helppopup.cpp
3636    }
3737    return true;
3838}
39
40bool HelpPopup::handleTouchscreen(Touchscreen& ts) {
41    if (ts.pressed()) {
42        dismiss();
43        ts.setHandled();
44    }
45    return true;
46}
src/helppopup.h
1919    // Layer implementation:
2020    virtual void paint(Surface& s);
2121    virtual bool handleButtonPress(InputManager::Button button);
22    virtual bool handleTouchscreen(Touchscreen& ts);
2322
2423private:
2524    GMenu2X& gmenu2x;
src/iconbutton.cpp
88
99
1010IconButton::IconButton(
11        GMenu2X& gmenu2x, Touchscreen &ts,
12        const string &icon, const string &label, Action action)
11        GMenu2X& gmenu2x, const string &icon, const string &label,
12        Action action)
1313    : gmenu2x(gmenu2x)
14    , ts(ts)
1514    , icon(icon)
1615    , label(label)
1716    , action(action)
...... 
5251    rect.h = h;
5352}
5453
55bool IconButton::handleTS() {
56    if (action && ts.released() && ts.inRect(rect)) {
57        ts.setHandled();
58        action();
59        return true;
60    }
61    return false;
62}
63
6454void IconButton::paint(Surface& s) {
6555    if (iconSurface) {
6656        iconSurface->blit(s, iconRect);
src/iconbutton.h
1010
1111class OffscreenSurface;
1212class Surface;
13class Touchscreen;
1413
1514
1615class IconButton {
1716public:
1817    typedef std::function<void(void)> Action;
1918
20    IconButton(GMenu2X& gmenu2x, Touchscreen &ts,
19    IconButton(GMenu2X& gmenu2x,
2120            const std::string &icon, const std::string &label = "",
2221            Action action = nullptr);
2322
2423    SDL_Rect getRect() { return rect; }
2524    void setPosition(int x, int y);
2625
27    bool handleTS();
28
2926    void paint(Surface& s);
3027
3128private:
3229    void recalcRects();
3330
3431    GMenu2X& gmenu2x;
35    Touchscreen &ts;
3632    std::string icon, label;
3733    Action action;
3834
src/imagedialog.cpp
3434using namespace std;
3535
3636ImageDialog::ImageDialog(
37        GMenu2X& gmenu2x, Touchscreen &ts, const string &text,
37        GMenu2X& gmenu2x, const string &text,
3838        const string &filter, const string &file)
39    : FileDialog(gmenu2x, ts, text, filter, file, "Image Browser")
39    : FileDialog(gmenu2x, text, filter, file, "Image Browser")
4040{
4141
4242    string path;
src/imagedialog.h
3131    SurfaceCollection previews;
3232public:
3333    ImageDialog(
34            GMenu2X& gmenu2x, Touchscreen &ts, const std::string &text,
34            GMenu2X& gmenu2x, const std::string &text,
3535            const std::string &filter = "", const std::string &file = "");
3636    virtual ~ImageDialog();
3737
src/inputdialog.cpp
3838}
3939
4040InputDialog::InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr_,
41        Touchscreen &ts_, const string &text,
41        const string &text,
4242        const string &startvalue, const string &title, const string &icon)
4343    : Dialog(gmenu2x)
4444    , inputMgr(inputMgr_)
45    , ts(ts_)
4645{
4746    if (title.empty()) {
4847        this->title = text;
...... 
9796    setKeyboard(0);
9897
9998    buttonbox.add(unique_ptr<IconButton>(new IconButton(
100            gmenu2x, ts, "skin:imgs/buttons/l.png",
99            gmenu2x, "skin:imgs/buttons/l.png",
101100            gmenu2x.tr["Backspace"],
102101            bind(&InputDialog::backspace, this))));
103102
104103    buttonbox.add(unique_ptr<IconButton>(new IconButton(
105            gmenu2x, ts, "skin:imgs/buttons/r.png",
104            gmenu2x, "skin:imgs/buttons/r.png",
106105            gmenu2x.tr["Space"],
107106            bind(&InputDialog::space, this))));
108107
109108    buttonbox.add(unique_ptr<IconButton>(new IconButton(
110            gmenu2x, ts, "skin:imgs/buttons/accept.png",
109            gmenu2x, "skin:imgs/buttons/accept.png",
111110            gmenu2x.tr["Confirm"],
112111            bind(&InputDialog::confirm, this))));
113112
114113    buttonbox.add(unique_ptr<IconButton>(new IconButton(
115            gmenu2x, ts, "skin:imgs/buttons/cancel.png",
114            gmenu2x, "skin:imgs/buttons/cancel.png",
116115            gmenu2x.tr["Change keys"],
117116            bind(&InputDialog::changeKeys, this))));
118117}
...... 
182181                    gmenu2x.skinConfColors[COLOR_SELECTION_BG]);
183182        }
184183
185        if (ts.available()) ts.poll();
186184        drawVirtualKeyboard();
187185        s.flip();
188186
...... 
306304                KEY_HEIGHT - 2
307305            };
308306
309            //if ts on rect, change selection
310            if (ts.available() && ts.pressed() && ts.inRect(re)) {
311                selCol = xc;
312                selRow = l;
313            }
314
315307            s.rectangle(re,
316308                    gmenu2x.skinConfColors[COLOR_SELECTION_BG]);
317309            gmenu2x.font->write(s, charX,
...... 
330322        KEY_HEIGHT - 1
331323    };
332324    s.rectangle(re, gmenu2x.skinConfColors[COLOR_SELECTION_BG]);
333    if (ts.available() && ts.pressed() && ts.inRect(re)) {
334        selCol = 0;
335        selRow = kb->size();
336    }
337325    gmenu2x.font->write(s, gmenu2x.tr["Cancel"],
338326            (int)(160 - kbLength * KEY_WIDTH / 4),
339327            KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2,
...... 
341329
342330    re.x = kbLeft + kbLength * KEY_WIDTH / 2 - 1;
343331    s.rectangle(re, gmenu2x.skinConfColors[COLOR_SELECTION_BG]);
344    if (ts.available() && ts.pressed() && ts.inRect(re)) {
345        selCol = 1;
346        selRow = kb->size();
347    }
348332    gmenu2x.font->write(s, gmenu2x.tr["OK"],
349333            (int)(160 + kbLength * KEY_WIDTH / 4),
350334            KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2,
src/inputdialog.h
2929#include <vector>
3030
3131class InputManager;
32class Touchscreen;
3332
3433class InputDialog : protected Dialog {
3534public:
36    InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr, Touchscreen &ts,
35    InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr,
3736            const std::string &text, const std::string &startvalue="",
3837            const std::string &title="", const std::string &icon="");
3938
...... 
5049    void setKeyboard(int);
5150
5251    InputManager &inputMgr;
53    Touchscreen &ts;
5452    int selRow, selCol;
5553    bool close, ok;
5654    std::string title, text, icon;
src/layer.h
77#include "inputmanager.h"
88
99class Surface;
10class Touchscreen;
1110
1211
1312/**
...... 
3736     */
3837    virtual bool handleButtonPress(InputManager::Button button) = 0;
3938
40    /**
41     * Handles the touch screen.
42     * Only called if there is a touch screen available.
43     * Returns true iff the touch screen was fully handled by this layer.
44     */
45    virtual bool handleTouchscreen(Touchscreen &ts) = 0;
46
4739    Status getStatus() { return status; }
4840
4941protected:
src/link.cpp
3434
3535Link::Link(GMenu2X& gmenu2x, Action action)
3636    : gmenu2x(gmenu2x)
37    , ts(gmenu2x.getTouchscreen())
3837    , action(action)
3938    , lastTick(0)
4039{
41// ts = gmenu2x.getTouchscreen();
4240    rect.w = gmenu2x.skinConfInt["linkWidth"];
4341    rect.h = gmenu2x.skinConfInt["linkHeight"];
4442    edited = false;
...... 
4947    updateSurfaces();
5048}
5149
52bool Link::isPressed() {
53    return ts.pressed() && ts.inRect(rect);
54}
55
56bool Link::handleTS() {
57    if (ts.released() && ts.inRect(rect)) {
58        int tickNow = SDL_GetTicks();
59        if (tickNow - lastTick < 400) {
60            ts.setHandled();
61            action();
62        }
63        lastTick = tickNow;
64        return true;
65    }
66    return false;
67}
68
6950void Link::paint() {
7051    Surface& s = *gmenu2x.s;
7152
src/link.h
2828
2929class GMenu2X;
3030class OffscreenSurface;
31class Touchscreen;
3231
3332
3433/**
...... 
4342    Link(GMenu2X& gmenu2x, Action action);
4443    virtual ~Link() {};
4544
46    bool isPressed();
47    bool handleTS();
48
4945    virtual void paint();
5046    void paintHover();
5147
...... 
7975private:
8076    void recalcCoordinates();
8177
82    Touchscreen &ts;
8378    Action action;
8479
8580    SDL_Rect rect;
src/linkapp.cpp
7272        return true;
7373    }
7474
75    bool handleTouchscreen(Touchscreen&) override {
76        return true;
77    }
78
7975private:
8076    LinkApp& app;
8177};
src/menu.cpp
6868    }
6969}
7070
71Menu::Menu(GMenu2X& gmenu2x, Touchscreen &ts)
71Menu::Menu(GMenu2X& gmenu2x)
7272    : gmenu2x(gmenu2x)
73    , ts(ts)
74    , btnContextMenu(gmenu2x, ts, "skin:imgs/menu.png", "",
73    , btnContextMenu(gmenu2x, "skin:imgs/menu.png", "",
7574            std::bind(&GMenu2X::showContextMenu, &gmenu2x))
7675{
7776    readSections(GMENU2X_SYSTEM_DIR "/sections");
...... 
275274            sc.skinRes("imgs/manual.png")->blit(
276275                    s, gmenu2x.manualX, gmenu2x.bottomBarIconY);
277276    }
278
279    if (ts.available()) {
280        btnContextMenu.paint(s);
281    }
282277}
283278
284279bool Menu::handleButtonPress(InputManager::Button button) {
...... 
312307    }
313308}
314309
315bool Menu::handleTouchscreen(Touchscreen &ts) {
316    btnContextMenu.handleTS();
317
318    ConfIntHash &skinConfInt = gmenu2x.skinConfInt;
319    const int topBarHeight = skinConfInt["topBarHeight"];
320    const int screenWidth = gmenu2x.resX;
321
322    if (ts.pressed() && ts.getY() < topBarHeight) {
323        int leftSection, rightSection;
324        calcSectionRange(leftSection, rightSection);
325
326        const int linkWidth = skinConfInt["linkWidth"];
327        const int leftSectionX = screenWidth / 2 + leftSection * linkWidth;
328        const int i = min(
329                leftSection + max((ts.getX() - leftSectionX) / linkWidth, 0),
330                rightSection);
331        const uint numSections = sections.size();
332        setSectionIndex((iSection + numSections + i) % numSections);
333
334        ts.setHandled();
335        return true;
336    }
337
338    const uint linksPerPage = linkColumns * linkRows;
339    uint i = iFirstDispRow * linkColumns;
340    while (i < (iFirstDispRow * linkColumns) + linksPerPage && i < sectionLinks()->size()) {
341        if (sectionLinks()->at(i)->isPressed()) {
342            setLinkIndex(i);
343        }
344        if (sectionLinks()->at(i)->handleTS()) {
345            i = sectionLinks()->size();
346        }
347        i++;
348    }
349    return ts.handled();
350}
351
352310/*====================================
353311   SECTION MANAGEMENT
354312  ====================================*/
src/menu.h
5555    };
5656
5757    GMenu2X& gmenu2x;
58    Touchscreen &ts;
5958    IconButton btnContextMenu;
6059    int iSection, iLink;
6160    uint iFirstDispRow;
...... 
109108public:
110109    typedef std::function<void(void)> Action;
111110
112    Menu(GMenu2X& gmenu2x, Touchscreen &ts);
111    Menu(GMenu2X& gmenu2x);
113112    virtual ~Menu();
114113
115114#ifdef HAVE_LIBOPK
...... 
152151    virtual bool runAnimations();
153152    virtual void paint(Surface &s);
154153    virtual bool handleButtonPress(InputManager::Button button);
155    virtual bool handleTouchscreen(Touchscreen &ts);
156154
157155    bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex);
158156
src/menusetting.cpp
4444    gmenu2x.font->write(s, name, 5, y, Font::HAlignLeft, Font::VAlignTop);
4545}
4646
47void MenuSetting::handleTS(int /*valueX*/, int /*y*/, int /*h*/)
48{
49    buttonBox.handleTS();
50}
51
5247void MenuSetting::drawSelected(int valueX, int y, int h)
5348{
5449    Surface& s = *gmenu2x.s;
src/menusetting.h
4545    virtual ~MenuSetting();
4646
4747    virtual void draw(int valueX, int y, int h);
48    virtual void handleTS(int valueX, int y, int h);
4948
5049    virtual bool handleButtonPress(InputManager::Button button) = 0;
5150    virtual void drawSelected(int valueX, int y, int h);
src/menusettingbool.cpp
3232using std::unique_ptr;
3333
3434MenuSettingBool::MenuSettingBool(
35        GMenu2X& gmenu2x, Touchscreen &ts,
35        GMenu2X& gmenu2x,
3636        const string &name, const string &description, int *value)
3737    : MenuSetting(gmenu2x, name, description)
38    , ts(ts)
3938{
4039    _ivalue = value;
4140    _value = NULL;
...... 
4544}
4645
4746MenuSettingBool::MenuSettingBool(
48        GMenu2X& gmenu2x, Touchscreen &ts,
47        GMenu2X& gmenu2x,
4948        const string &name, const string &description, bool *value)
5049    : MenuSetting(gmenu2x, name, description)
51    , ts(ts)
5250{
5351    _value = value;
5452    _ivalue = NULL;
...... 
6058void MenuSettingBool::initButton()
6159{
6260    buttonBox.add(unique_ptr<IconButton>(new IconButton(
63            gmenu2x, ts, "skin:imgs/buttons/accept.png",
61            gmenu2x, "skin:imgs/buttons/accept.png",
6462            gmenu2x.tr["Switch"],
6563            bind(&MenuSettingBool::toggle, this))));
6664}
src/menusettingbool.h
2424#include "inputmanager.h"
2525
2626class GMenu2X;
27class Touchscreen;
2827
2928class MenuSettingBool : public MenuSetting {
3029private:
3130    void initButton();
3231    void toggle();
3332
34    Touchscreen &ts;
3533    bool originalValue;
3634    bool *_value;
3735    int *_ivalue;
...... 
3937
4038public:
4139    MenuSettingBool(
42            GMenu2X& gmenu2x, Touchscreen &ts,
40            GMenu2X& gmenu2x,
4341            const std::string &name, const std::string &description,
4442            bool *value);
4543    MenuSettingBool(
46            GMenu2X& gmenu2x, Touchscreen &ts,
44            GMenu2X& gmenu2x,
4745            const std::string &name, const std::string &description,
4846            int *value);
4947    virtual ~MenuSettingBool() {}
src/menusettingdir.cpp
2929using std::unique_ptr;
3030
3131MenuSettingDir::MenuSettingDir(
32        GMenu2X& gmenu2x, Touchscreen &ts_,
32        GMenu2X& gmenu2x,
3333        const string &name, const string &description, string *value)
3434    : MenuSettingStringBase(gmenu2x, name, description, value)
35    , ts(ts_)
3635{
3736    buttonBox.add(unique_ptr<IconButton>(new IconButton(
38            gmenu2x, ts, "skin:imgs/buttons/cancel.png",
37            gmenu2x, "skin:imgs/buttons/cancel.png",
3938            gmenu2x.tr["Clear"],
4039            bind(&MenuSettingDir::clear, this))));
4140
4241    buttonBox.add(unique_ptr<IconButton>(new IconButton(
43            gmenu2x, ts, "skin:imgs/buttons/accept.png",
42            gmenu2x, "skin:imgs/buttons/accept.png",
4443            gmenu2x.tr["Select"],
4544            bind(&MenuSettingDir::edit, this))));
4645}
4746
4847void MenuSettingDir::edit()
4948{
50    DirDialog dd(gmenu2x, ts, description, value());
49    DirDialog dd(gmenu2x, description, value());
5150    if (dd.exec()) setValue(dd.getPath());
5251}
src/menusettingdir.h
2222
2323#include "menusettingstringbase.h"
2424
25class Touchscreen;
26
2725class MenuSettingDir : public MenuSettingStringBase {
28private:
29    Touchscreen &ts;
30
3126protected:
3227    virtual void edit();
3328
3429public:
3530    MenuSettingDir(
36            GMenu2X& gmenu2x, Touchscreen &ts,
31            GMenu2X& gmenu2x,
3732            const std::string &name, const std::string &description,
3833            std::string *value);
3934    virtual ~MenuSettingDir() {}
src/menusettingfile.cpp
2929using std::unique_ptr;
3030
3131MenuSettingFile::MenuSettingFile(
32        GMenu2X& gmenu2x, Touchscreen &ts_,
32        GMenu2X& gmenu2x,
3333        const string &name, const string &description,
3434        string *value, const string &filter_)
3535    : MenuSettingStringBase(gmenu2x, name, description, value)
36    , ts(ts_)
3736    , filter(filter_)
3837{
3938    buttonBox.add(unique_ptr<IconButton>(new IconButton(
40            gmenu2x, ts, "skin:imgs/buttons/cancel.png",
39            gmenu2x, "skin:imgs/buttons/cancel.png",
4140            gmenu2x.tr["Clear"],
4241            bind(&MenuSettingFile::clear, this))));
4342
4443    buttonBox.add(unique_ptr<IconButton>(new IconButton(
45            gmenu2x, ts, "skin:imgs/buttons/accept.png",
44            gmenu2x, "skin:imgs/buttons/accept.png",
4645            gmenu2x.tr["Select"],
4746            bind(&MenuSettingFile::edit, this))));
4847}
4948
5049void MenuSettingFile::edit()
5150{
52    FileDialog fd(gmenu2x, ts, description, filter, value());
51    FileDialog fd(gmenu2x, description, filter, value());
5352    if (fd.exec()) {
5453        setValue(fd.getPath() + "/" + fd.getFile());
5554    }
src/menusettingfile.h
2222
2323#include "menusettingstringbase.h"
2424
25class Touchscreen;
26
2725class MenuSettingFile : public MenuSettingStringBase {
2826protected:
2927    virtual void edit();
3028
31    Touchscreen &ts;
3229    std::string filter;
3330
3431public:
3532    MenuSettingFile(
36            GMenu2X& gmenu2x, Touchscreen &ts,
33            GMenu2X& gmenu2x,
3734            const std::string &name, const std::string &description,
3835            std::string *value, const std::string &filter = "");
3936    virtual ~MenuSettingFile() {}
src/menusettingimage.cpp
2727using std::string;
2828
2929MenuSettingImage::MenuSettingImage(
30        GMenu2X& gmenu2x, Touchscreen &ts,
30        GMenu2X& gmenu2x,
3131        const string &name, const string &description,
3232        string *value, const string &filter)
33    : MenuSettingFile(gmenu2x, ts, name, description, value, filter)
33    : MenuSettingFile(gmenu2x, name, description, value, filter)
3434{
3535}
3636
3737void MenuSettingImage::edit() {
38    ImageDialog id(gmenu2x, ts, description, filter, value());
38    ImageDialog id(gmenu2x, description, filter, value());
3939    if (id.exec()) setValue(id.getPath() + "/" + id.getFile());
4040}
4141
src/menusettingimage.h
2727    virtual void edit();
2828
2929public:
30    MenuSettingImage(GMenu2X& gmenu2x, Touchscreen &ts,
30    MenuSettingImage(GMenu2X& gmenu2x,
3131            const std::string &name, const std::string &description,
3232            std::string *value, const std::string &filter = "");
3333    virtual ~MenuSettingImage() {}
src/menusettingint.cpp
3333using std::unique_ptr;
3434
3535MenuSettingInt::MenuSettingInt(
36        GMenu2X& gmenu2x, Touchscreen &ts,
36        GMenu2X& gmenu2x,
3737        const string &name, const string &description,
3838        int *value, int min, int max, int increment)
3939    : MenuSetting(gmenu2x, name, description)
...... 
5050    IconButton::Action actionDec = bind(&MenuSettingInt::dec, this);
5151
5252    buttonBox.add(unique_ptr<IconButton>(new IconButton(
53            gmenu2x, ts, "skin:imgs/buttons/l.png",
53            gmenu2x, "skin:imgs/buttons/l.png",
5454            "", actionDec)));
5555    buttonBox.add(unique_ptr<IconButton>(new IconButton(
56            gmenu2x, ts, "skin:imgs/buttons/left.png",
56            gmenu2x, "skin:imgs/buttons/left.png",
5757            gmenu2x.tr["Decrease"], actionDec)));
5858
5959    buttonBox.add(unique_ptr<IconButton>(new IconButton(
60            gmenu2x, ts, "skin:imgs/buttons/r.png",
60            gmenu2x, "skin:imgs/buttons/r.png",
6161            "", actionInc)));
6262    buttonBox.add(unique_ptr<IconButton>(new IconButton(
63            gmenu2x, ts, "skin:imgs/buttons/right.png",
63            gmenu2x, "skin:imgs/buttons/right.png",
6464            gmenu2x.tr["Increase"], actionInc)));
6565}
6666
src/menusettingint.h
2323#include "menusetting.h"
2424#include "inputmanager.h"
2525
26class Touchscreen;
27
2826class MenuSettingInt : public MenuSetting {
2927private:
3028    int originalValue;
...... 
3836
3937public:
4038    MenuSettingInt(
41            GMenu2X& gmenu2x, Touchscreen &ts,
39            GMenu2X& gmenu2x,
4240            const std::string &name, const std::string &description,
4341            int *value, int min, int max, int increment = 1);
4442    virtual ~MenuSettingInt() {}
src/menusettingmultistring.cpp
3131using std::unique_ptr;
3232
3333MenuSettingMultiString::MenuSettingMultiString(
34        GMenu2X& gmenu2x, Touchscreen &ts,
34        GMenu2X& gmenu2x,
3535        const string &name, const string &description,
3636        string *value, const vector<string> *choices_)
3737    : MenuSettingStringBase(gmenu2x, name, description, value)
...... 
4040    setSel(find(choices->begin(), choices->end(), *value) - choices->begin());
4141
4242    buttonBox.add(unique_ptr<IconButton>(new IconButton(
43            gmenu2x, ts, "skin:imgs/buttons/left.png", "",
43            gmenu2x, "skin:imgs/buttons/left.png", "",
4444            bind(&MenuSettingMultiString::decSel, this))));
4545    buttonBox.add(unique_ptr<IconButton>(new IconButton(
46            gmenu2x, ts, "skin:imgs/buttons/right.png",
46            gmenu2x, "skin:imgs/buttons/right.png",
4747            gmenu2x.tr["Change value"],
4848            bind(&MenuSettingMultiString::incSel, this))));
4949}
src/menusettingmultistring.h
2525
2626#include <vector>
2727
28class Touchscreen;
29
3028class MenuSettingMultiString : public MenuSettingStringBase {
3129private:
3230    virtual void edit() {
...... 
4240
4341public:
4442    MenuSettingMultiString(
45            GMenu2X& gmenu2x, Touchscreen &ts,
43            GMenu2X& gmenu2x,
4644            const std::string &name, const std::string &description,
4745            std::string *value, const std::vector<std::string> *choices);
4846    virtual ~MenuSettingMultiString() {};
src/menusettingrgba.cpp
3434constexpr unsigned int COMPONENT_WIDTH = 28;
3535
3636MenuSettingRGBA::MenuSettingRGBA(
37        GMenu2X& gmenu2x, Touchscreen &ts_,
37        GMenu2X& gmenu2x,
3838        const string &name, const string &description, RGBAColor *value)
3939    : MenuSetting(gmenu2x, name, description)
40    , ts(ts_)
4140{
4241    edit = false;
4342
...... 
6665    font->write(s, strA, valueX + h + COMPONENT_WIDTH * 4 - 2, y, Font::HAlignRight, Font::VAlignTop);
6766}
6867
69void MenuSettingRGBA::handleTS(int valueX, int y, int h) {
70    if (ts.pressed()) {
71        for (int i=0; i<4; i++) {
72            if (i!=selPart && ts.inRect(valueX + h + i * COMPONENT_WIDTH,y,COMPONENT_WIDTH,h)) {
73                selPart = i;
74                break;
75            }
76        }
77    }
78
79    MenuSetting::handleTS(valueX, y, h);
80}
81
8268bool MenuSettingRGBA::handleButtonPress(InputManager::Button button)
8369 {
8470    if (edit) {
...... 
230216{
231217    buttonBox.clear();
232218    if (edit) {
233        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/l.png")));
234        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x.tr["Decrease"])));
235        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png")));
236        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x.tr["Increase"])));
237        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Confirm"])));
219        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/l.png")));
220        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/left.png", gmenu2x.tr["Decrease"])));
221        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/r.png")));
222        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/right.png", gmenu2x.tr["Increase"])));
223        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Confirm"])));
238224    } else {
239        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png")));
240        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x.tr["Change color component"])));
241        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Edit"])));
225        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/left.png")));
226        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/right.png", gmenu2x.tr["Change color component"])));
227        buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Edit"])));
242228    }
243229}
src/menusettingrgba.h
2626#include "inputmanager.h"
2727
2828class GMenu2X;
29class Touchscreen;
3029
3130class MenuSettingRGBA : public MenuSetting {
3231private:
33    Touchscreen &ts;
3432    unsigned short selPart;
3533    std::string strR, strG, strB, strA;
3634    RGBAColor originalValue;
...... 
4745
4846public:
4947    MenuSettingRGBA(
50            GMenu2X& gmenu2x, Touchscreen &ts,
48            GMenu2X& gmenu2x,
5149            const std::string &name, const std::string &description,
5250            RGBAColor *value);
5351    virtual ~MenuSettingRGBA() {};
5452
5553    virtual void draw(int valueX, int y, int h);
56    virtual void handleTS(int valueX, int y, int h);
5754    virtual bool handleButtonPress(InputManager::Button button);
5855    virtual void drawSelected(int valueX, int y, int h);
5956    virtual bool edited();
src/menusettingstring.cpp
2929using std::unique_ptr;
3030
3131MenuSettingString::MenuSettingString(
32        GMenu2X& gmenu2x, Touchscreen &ts_,
32        GMenu2X& gmenu2x,
3333        const string &name, const string &description, string *value,
3434        const string &diagTitle_, const string &diagIcon_)
3535    : MenuSettingStringBase(gmenu2x, name, description, value)
36    , ts(ts_)
3736    , diagTitle(diagTitle_)
3837    , diagIcon(diagIcon_)
3938{
4039    buttonBox.add(unique_ptr<IconButton>(new IconButton(
41            gmenu2x, ts, "skin:imgs/buttons/cancel.png",
40            gmenu2x, "skin:imgs/buttons/cancel.png",
4241            gmenu2x.tr["Clear"],
4342            bind(&MenuSettingString::clear, this))));
4443
4544    buttonBox.add(unique_ptr<IconButton>(new IconButton(
46            gmenu2x, ts, "skin:imgs/buttons/accept.png",
45            gmenu2x, "skin:imgs/buttons/accept.png",
4746            gmenu2x.tr["Edit"],
4847            bind(&MenuSettingString::edit, this))));
4948}
...... 
5150void MenuSettingString::edit()
5251{
5352    InputDialog id(
54            gmenu2x, gmenu2x.input, ts,
55            description, value(), diagTitle, diagIcon);
53            gmenu2x, gmenu2x.input, description, value(), diagTitle, diagIcon);
5654    if (id.exec()) setValue(id.getInput());
5755}
src/menusettingstring.h
2222
2323#include "menusettingstringbase.h"
2424
25class Touchscreen;
26
2725class MenuSettingString : public MenuSettingStringBase {
28private:
29    Touchscreen &ts;
30
3126protected:
3227    virtual void edit();
3328
...... 
3530
3631public:
3732    MenuSettingString(
38            GMenu2X& gmenu2x, Touchscreen &ts, const std::string &name,
33            GMenu2X& gmenu2x, const std::string &name,
3934            const std::string &description, std::string *value,
4035            const std::string &diagTitle = "",
4136            const std::string &diagIcon = "");
src/settingsdialog.cpp
2828using namespace std;
2929
3030SettingsDialog::SettingsDialog(
31        GMenu2X& gmenu2x, InputManager &inputMgr_, Touchscreen &ts_,
31        GMenu2X& gmenu2x, InputManager &inputMgr_,
3232        const string &text_, const string &icon)
3333    : Dialog(gmenu2x)
3434    , inputMgr(inputMgr_)
35    , ts(ts_)
3635    , text(text_)
3736{
3837    if (!icon.empty() && gmenu2x.sc[icon] != NULL) {
...... 
4645    OffscreenSurface bg(*gmenu2x.bg);
4746    bg.convertToDisplayFormat();
4847
49    bool close = false, ts_pressed = false;
48    bool close = false;
5049    uint i, sel = 0, firstElement = 0;
5150
5251    const int topBarHeight = gmenu2x.skinConfInt["topBarHeight"];
53    SDL_Rect clipRect = {
54        0,
55        static_cast<Sint16>(topBarHeight + 1),
56        static_cast<Uint16>(gmenu2x.resX - 9),
57        static_cast<Uint16>(gmenu2x.resY - topBarHeight - 25)
58    };
59    SDL_Rect touchRect = {
60        2,
61        static_cast<Sint16>(topBarHeight + 4),
62        static_cast<Uint16>(gmenu2x.resX - 12),
63        static_cast<Uint16>(clipRect.h)
64    };
6552    uint rowHeight = gmenu2x.font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1
6653    uint numRows = (gmenu2x.resY - topBarHeight - 20) / rowHeight;
6754
...... 
7360    while (!close) {
7461        OutputSurface& s = *gmenu2x.s;
7562
76        if (ts.available()) ts.poll();
77
7863        bg.blit(s, 0, 0);
7964
8065        gmenu2x.drawTopBar(s);
...... 
9378        //selected option
9479        settings[sel]->drawSelected(maxNameWidth + 15, iY, rowHeight);
9580
96        if (ts_pressed && !ts.pressed()) {
97            ts_pressed = false;
98        }
99        if (ts.available() && ts.pressed() && !ts.inRect(touchRect)) {
100            ts_pressed = false;
101        }
10281        for (i=firstElement; i<settings.size() && i<firstElement+numRows; i++) {
10382            iY = i-firstElement;
10483            settings[i]->draw(maxNameWidth + 15, iY * rowHeight + topBarHeight + 2, rowHeight);
105            if (ts.available() && ts.pressed() && ts.inRect(
106                    touchRect.x, touchRect.y + (iY * rowHeight),
107                    touchRect.w, rowHeight
108                    )) {
109                ts_pressed = true;
110                sel = i;
111            }
11284        }
11385
11486        gmenu2x.drawScrollBar(numRows, settings.size(), firstElement);
...... 
11789        writeSubTitle(s, settings[sel]->getDescription());
11890
11991        s.flip();
120        settings[sel]->handleTS(maxNameWidth + 15, iY, rowHeight);
12192
12293        InputManager::Button button = inputMgr.waitForPressedButton();
12394        if (!settings[sel]->handleButtonPress(button)) {
src/settingsdialog.h
3030
3131class InputManager;
3232class MenuSetting;
33class Touchscreen;
3433
3534class SettingsDialog : protected Dialog {
3635private:
3736    InputManager &inputMgr;
38    Touchscreen &ts;
3937    std::vector<std::unique_ptr<MenuSetting>> settings;
4038    std::string text, icon;
4139
4240public:
43    SettingsDialog(GMenu2X& gmenu2x, InputManager &inputMgr, Touchscreen &ts,
41    SettingsDialog(GMenu2X& gmenu2x, InputManager &inputMgr,
4442            const std::string &text,
4543            const std::string &icon = "skin:sections/settings.png");
4644
src/touchscreen.cpp
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#include "touchscreen.h"
22
23#include <fcntl.h>
24#include <unistd.h>
25
26
27Touchscreen::Touchscreen() {
28    calibrated = false;
29    wasPressed = false;
30    _handled = false;
31    x = 0;
32    y = 0;
33    startX = 0;
34    startY = 0;
35    event.x = 0;
36    event.y = 0;
37    event.pressure = 0;
38    ts_fd = 0;
39}
40
41Touchscreen::~Touchscreen() {
42    if (ts_fd > 0) {
43        close(ts_fd);
44    }
45}
46
47void Touchscreen::calibrate() {
48    if (event.pressure == 0) {
49        calibX = ((event.x - 200) * 320 / 3750) / 4;
50        calibY = (((event.y - 200) * 240 / 3750)) / 4;
51        calibrated = true;
52    }
53}
54
55bool Touchscreen::poll() {
56    wasPressed = pressed();
57    SDL_PumpEvents();
58    int mx, my;
59    if (SDL_GetMouseState(&mx,&my) && SDL_BUTTON(1)) {
60        x = mx;
61        y = my;
62        event.pressure = 1;
63    } else {
64        event.pressure = 0;
65    }
66    _handled = false;
67
68    if (!wasPressed && pressed()) {
69        startX = x;
70        startY = y;
71    }
72
73    return pressed();
74}
75
76bool Touchscreen::handled() {
77    return _handled;
78}
79
80void Touchscreen::setHandled() {
81    wasPressed = false;
82    _handled = true;
83}
84
85bool Touchscreen::pressed() {
86    return !_handled && event.pressure > 0;
87}
88
89bool Touchscreen::released() {
90    return !pressed() && wasPressed;
91}
92
93bool Touchscreen::inRect(int ix, int iy, int iw, int ih) {
94    return !_handled &&
95        (y >= iy) && (y <= iy + ih) && (x >= ix) && (x <= ix + iw);
96}
97
98bool Touchscreen::inRect(SDL_Rect r) {
99    return inRect(r.x, r.y, r.w, r.h);
100}
101
102bool Touchscreen::startedInRect(int ix, int iy, int iw, int ih) {
103    return !_handled &&
104        (startY >= iy) && (startY <= iy + ih) &&
105        (startX >= ix) && (startX <= ix + iw);
106}
107
108bool Touchscreen::startedInRect(SDL_Rect r) {
109    return startedInRect(r.x, r.y, r.w, r.h);
110}
src/touchscreen.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 TOUCHSCREEN_H
22#define TOUCHSCREEN_H
23
24#include <SDL.h>
25
26#include <stdint.h>
27
28typedef struct {
29    uint16_t pressure;
30    uint16_t x;
31    uint16_t y;
32    uint16_t pad;
33    struct timeval stamp;
34} TS_EVENT;
35
36class Touchscreen {
37public:
38    Touchscreen();
39    ~Touchscreen();
40
41    bool available() {
42        return false;
43    }
44
45    bool poll();
46    bool pressed();
47    bool released();
48
49    bool handled();
50    void setHandled();
51
52    bool inRect(int x, int y, int w, int h);
53    bool inRect(SDL_Rect r);
54    bool startedInRect(int x, int y, int w, int h);
55    bool startedInRect(SDL_Rect r);
56
57    int getX() { return x; }
58    int getY() { return y; }
59
60private:
61    int ts_fd;
62    bool calibrated, _handled;
63    TS_EVENT event;
64    int calibX, calibY;
65    int x, y, startX, startY;
66    bool wasPressed;
67
68    void calibrate(/*TS_EVENT event*/);
69};
70
71#endif
src/wallpaperdialog.cpp
3232
3333using namespace std;
3434
35WallpaperDialog::WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts_)
35WallpaperDialog::WallpaperDialog(GMenu2X& gmenu2x)
3636    : Dialog(gmenu2x)
37    , ts(ts_)
3837{
3938}
4039
...... 
6362    uint i, selected = 0, firstElement = 0, iY;
6463
6564    ButtonBox buttonbox;
66    buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"])));
67    buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Exit"])));
65    buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"])));
66    buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Exit"])));
6867
6968    unsigned int top, height;
7069    tie(top, height) = gmenu2x.getContentArea();
src/wallpaperdialog.h
2525
2626#include <string>
2727
28class Touchscreen;
29
3028class WallpaperDialog : protected Dialog {
31private:
32    Touchscreen &ts;
33
3429public:
35    WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts);
30    WallpaperDialog(GMenu2X& gmenu2x);
3631    std::string wallpaper;
3732
3833    bool exec();

Archive Download the corresponding diff file



interactive