From 2a2634b3640286bf05fa5158e5f71ba1d2490aea Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Sun, 5 Oct 2014 06:46:48 +0000 Subject: [PATCH] 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. --- src/Makefile.am | 4 +- src/background.cpp | 4 -- src/background.h | 1 - src/browsedialog.cpp | 43 +++---------- src/browsedialog.h | 8 +-- src/buttonbox.cpp | 7 --- src/buttonbox.h | 1 - src/contextmenu.cpp | 18 ------ src/contextmenu.h | 1 - src/dirdialog.cpp | 6 +- src/dirdialog.h | 3 +- src/filedialog.cpp | 4 +- src/filedialog.h | 2 +- src/gmenu2x.cpp | 76 ++++++++++------------- src/gmenu2x.h | 4 -- src/helppopup.cpp | 8 --- src/helppopup.h | 1 - src/iconbutton.cpp | 14 +---- src/iconbutton.h | 6 +- src/imagedialog.cpp | 4 +- src/imagedialog.h | 2 +- src/inputdialog.cpp | 26 ++------ src/inputdialog.h | 4 +- src/layer.h | 8 --- src/link.cpp | 19 ------ src/link.h | 5 -- src/linkapp.cpp | 4 -- src/menu.cpp | 46 +------------- src/menu.h | 4 +- src/menusetting.cpp | 5 -- src/menusetting.h | 1 - src/menusettingbool.cpp | 8 +-- src/menusettingbool.h | 6 +- src/menusettingdir.cpp | 9 ++- src/menusettingdir.h | 7 +-- src/menusettingfile.cpp | 9 ++- src/menusettingfile.h | 5 +- src/menusettingimage.cpp | 6 +- src/menusettingimage.h | 2 +- src/menusettingint.cpp | 10 +-- src/menusettingint.h | 4 +- src/menusettingmultistring.cpp | 6 +- src/menusettingmultistring.h | 4 +- src/menusettingrgba.cpp | 32 +++------- src/menusettingrgba.h | 5 +- src/menusettingstring.cpp | 10 ++- src/menusettingstring.h | 7 +-- src/settingsdialog.cpp | 33 +--------- src/settingsdialog.h | 4 +- src/touchscreen.cpp | 110 --------------------------------- src/touchscreen.h | 71 --------------------- src/wallpaperdialog.cpp | 7 +-- src/wallpaperdialog.h | 7 +-- 53 files changed, 115 insertions(+), 586 deletions(-) delete mode 100644 src/touchscreen.cpp delete mode 100644 src/touchscreen.h diff --git a/src/Makefile.am b/src/Makefile.am index 38673a0..8765200 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -9,7 +9,7 @@ gmenu2x_SOURCES = font.cpp cpu.cpp dirdialog.cpp filedialog.cpp \ menusettingstringbase.cpp \ messagebox.cpp selector.cpp \ settingsdialog.cpp surfacecollection.cpp surface.cpp \ - textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \ + textdialog.cpp textmanualdialog.cpp translator.cpp \ utilities.cpp wallpaperdialog.cpp \ browsedialog.cpp buttonbox.cpp dialog.cpp \ imageio.cpp powersaver.cpp monitor.cpp mediamonitor.cpp clock.cpp \ @@ -24,7 +24,7 @@ noinst_HEADERS = font.h cpu.h dirdialog.h \ menusettingstringbase.h \ messagebox.h selector.h settingsdialog.h \ surfacecollection.h surface.h textdialog.h textmanualdialog.h \ - touchscreen.h translator.h utilities.h wallpaperdialog.h \ + translator.h utilities.h wallpaperdialog.h \ browsedialog.h buttonbox.h dialog.h \ imageio.h powersaver.h monitor.h mediamonitor.h clock.h \ layer.h helppopup.h contextmenu.h background.h battery.h diff --git a/src/background.cpp b/src/background.cpp index 7162a41..1dcafb0 100644 --- a/src/background.cpp +++ b/src/background.cpp @@ -40,7 +40,3 @@ bool Background::handleButtonPress(InputManager::Button button) { return false; } } - -bool Background::handleTouchscreen(Touchscreen&) { - return false; -} diff --git a/src/background.h b/src/background.h index 98e3431..c1c955c 100644 --- a/src/background.h +++ b/src/background.h @@ -21,7 +21,6 @@ public: // Layer implementation: virtual void paint(Surface& s); virtual bool handleButtonPress(InputManager::Button button); - virtual bool handleTouchscreen(Touchscreen& ts); private: GMenu2X& gmenu2x; diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index 1fe3ae4..22665a9 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -11,33 +11,31 @@ using std::string; using std::unique_ptr; BrowseDialog::BrowseDialog( - GMenu2X& gmenu2x, Touchscreen &ts_, + GMenu2X& gmenu2x, const string &title, const string &subtitle) : Dialog(gmenu2x) - , ts(ts_) , title(title) , subtitle(subtitle) - , ts_pressed(false) { buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/left.png"))); + gmenu2x, "skin:imgs/buttons/left.png"))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/cancel.png", + gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Up one folder"], bind(&BrowseDialog::directoryUp, this)))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/accept.png", + gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"], bind(&BrowseDialog::directoryEnter, this)))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/start.png", + gmenu2x, "skin:imgs/buttons/start.png", gmenu2x.tr["Confirm"], bind(&BrowseDialog::confirm, this)))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/select.png", + gmenu2x, "skin:imgs/buttons/select.png", gmenu2x.tr["Exit"], bind(&BrowseDialog::quit, this)))); @@ -67,18 +65,10 @@ bool BrowseDialog::exec() static_cast(gmenu2x.resX - 9), static_cast(gmenu2x.resY - topBarHeight - 25) }; - touchRect = (SDL_Rect) { - 2, - static_cast(topBarHeight + 4), - static_cast(gmenu2x.resX - 12), - clipRect.h - }; selected = 0; close = false; while (!close) { - if (ts.available()) ts.poll(); - paint(); handleInput(); @@ -115,18 +105,7 @@ BrowseDialog::Action BrowseDialog::getAction(InputManager::Button button) void BrowseDialog::handleInput() { InputManager::Button button = gmenu2x.input.waitForPressedButton(); - - BrowseDialog::Action action; - if (ts_pressed && !ts.pressed()) { - action = BrowseDialog::ACT_SELECT; - ts_pressed = false; - } else { - action = getAction(button); - } - - if (ts.available() && ts.pressed() && !ts.inRect(touchRect)) { - ts_pressed = false; - } + BrowseDialog::Action action = getAction(button); if (action == BrowseDialog::ACT_SELECT && fl[selected] == "..") { action = BrowseDialog::ACT_GOUP; @@ -174,8 +153,6 @@ void BrowseDialog::handleInput() default: break; } - - buttonBox.handleTS(); } void BrowseDialog::directoryUp() @@ -274,12 +251,6 @@ void BrowseDialog::paint() gmenu2x.font->write(s, fl[i], 24, offsetY + rowHeight / 2, Font::HAlignLeft, Font::VAlignMiddle); - if (ts.available() && ts.pressed() - && ts.inRect(touchRect.x, offsetY + 3, touchRect.w, rowHeight)) { - ts_pressed = true; - selected = i; - } - offsetY += rowHeight; } s.clearClipRect(); diff --git a/src/browsedialog.h b/src/browsedialog.h index 56e811b..d77f2c0 100644 --- a/src/browsedialog.h +++ b/src/browsedialog.h @@ -30,12 +30,10 @@ #include class OffscreenSurface; -class Touchscreen; class BrowseDialog : protected Dialog { protected: - BrowseDialog( - GMenu2X& gmenu2x, Touchscreen &ts, + BrowseDialog(GMenu2X& gmenu2x, const std::string &title, const std::string &subtitle); virtual ~BrowseDialog(); @@ -60,7 +58,6 @@ private: ACT_CONFIRM, }; - Touchscreen &ts; bool close, result; std::string title; @@ -68,13 +65,10 @@ private: std::string path; SDL_Rect clipRect; - SDL_Rect touchRect; unsigned int numRows; unsigned int rowHeight; - bool ts_pressed; - OffscreenSurface *iconGoUp; OffscreenSurface *iconFolder; OffscreenSurface *iconFile; diff --git a/src/buttonbox.cpp b/src/buttonbox.cpp index 3655914..bea9777 100644 --- a/src/buttonbox.cpp +++ b/src/buttonbox.cpp @@ -25,10 +25,3 @@ void ButtonBox::paint(Surface& s, int x, int y) x += button->getRect().w + 6; } } - -void ButtonBox::handleTS() -{ - for (auto& button : buttons) { - button->handleTS(); - } -} diff --git a/src/buttonbox.h b/src/buttonbox.h index b3c42ca..2bce58e 100644 --- a/src/buttonbox.h +++ b/src/buttonbox.h @@ -16,7 +16,6 @@ public: void clear(); void paint(Surface& s, int x, int y); - void handleTS(); private: std::vector> buttons; diff --git a/src/contextmenu.cpp b/src/contextmenu.cpp index 2b52dda..f8c9392 100644 --- a/src/contextmenu.cpp +++ b/src/contextmenu.cpp @@ -157,21 +157,3 @@ bool ContextMenu::handleButtonPress(InputManager::Button button) { } return true; } - -bool ContextMenu::handleTouchscreen(Touchscreen &ts) { - if (ts.inRect(box)) { - int i = std::max(0, std::min(static_cast(options.size()) - 1, - (ts.getY() - (box.y + 4)) / (gmenu2x.font->getLineSpacing() + 2))); - if (ts.released()) { - options[i]->action(); - dismiss(); - } else if (ts.pressed()) { - selected = i; - } - } else { - if (ts.released()) { - dismiss(); - } - } - return true; -} diff --git a/src/contextmenu.h b/src/contextmenu.h index 7b6a78d..cff8cf8 100644 --- a/src/contextmenu.h +++ b/src/contextmenu.h @@ -24,7 +24,6 @@ public: virtual bool runAnimations(); virtual void paint(Surface &s); virtual bool handleButtonPress(InputManager::Button button); - virtual bool handleTouchscreen(Touchscreen &ts); private: struct MenuOption; diff --git a/src/dirdialog.cpp b/src/dirdialog.cpp index cef3879..3b18b6c 100644 --- a/src/dirdialog.cpp +++ b/src/dirdialog.cpp @@ -24,10 +24,8 @@ using namespace std; -DirDialog::DirDialog( - GMenu2X& gmenu2x, Touchscreen &ts, - const string &text, const string &dir) - : BrowseDialog(gmenu2x, ts, "Directory Browser", text) +DirDialog::DirDialog(GMenu2X& gmenu2x, const string &text, const string &dir) + : BrowseDialog(gmenu2x, "Directory Browser", text) { fl.setShowFiles(false); setPath(dir); diff --git a/src/dirdialog.h b/src/dirdialog.h index 6764db0..c301dd8 100644 --- a/src/dirdialog.h +++ b/src/dirdialog.h @@ -25,8 +25,7 @@ class DirDialog : public BrowseDialog { public: - DirDialog( - GMenu2X& gmenu2x, Touchscreen &ts, + DirDialog(GMenu2X& gmenu2x, const std::string &text, const std::string &dir = ""); }; diff --git a/src/filedialog.cpp b/src/filedialog.cpp index f48d683..04ecb04 100644 --- a/src/filedialog.cpp +++ b/src/filedialog.cpp @@ -25,9 +25,9 @@ using namespace std; FileDialog::FileDialog( - GMenu2X& gmenu2x, Touchscreen &ts, const string &text, + GMenu2X& gmenu2x, const string &text, const string &filter, const string &file, const string &title) - : BrowseDialog(gmenu2x, ts, title, text) + : BrowseDialog(gmenu2x, title, text) { string path(CARD_ROOT); if (!file.empty()) { diff --git a/src/filedialog.h b/src/filedialog.h index 3c09aae..5db3cee 100644 --- a/src/filedialog.h +++ b/src/filedialog.h @@ -26,7 +26,7 @@ class FileDialog : public BrowseDialog { public: FileDialog( - GMenu2X& gmenu2x, Touchscreen &ts, const std::string &text, + GMenu2X& gmenu2x, const std::string &text, const std::string &filter="*", const std::string &file="", const std::string &title = "File Dialog"); bool exec(); diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 7b5d8db..5604791 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -376,7 +376,7 @@ void GMenu2X::initFont() { void GMenu2X::initMenu() { //Menu structure handler - menu.reset(new Menu(*this, ts)); + menu.reset(new Menu(*this)); // Add action links in the applications section. auto appIdx = menu->sectionNamed("applications"); @@ -628,16 +628,6 @@ void GMenu2X::mainLoop() { break; } - // Handle touchscreen events. - if (ts.available()) { - ts.poll(); - for (auto it = layers.rbegin(); it != layers.rend(); ++it) { - if ((*it)->handleTouchscreen(ts)) { - break; - } - } - } - // Handle other input events. InputManager::Button button; bool gotEvent; @@ -656,7 +646,7 @@ void GMenu2X::mainLoop() { } void GMenu2X::explorer() { - FileDialog fd(*this, ts, tr["Select an application"], "sh,bin,py,elf,"); + FileDialog fd(*this, tr["Select an application"], "sh,bin,py,elf,"); if (fd.exec()) { if (confInt["saveSelection"] && (confInt["section"]!=menu->selSectionIndex() || confInt["link"]!=menu->selLinkIndex())) writeConfig(); @@ -701,35 +691,35 @@ void GMenu2X::showSettings() { encodings.push_back("NTSC"); encodings.push_back("PAL"); - SettingsDialog sd(*this, input, ts, tr["Settings"]); + SettingsDialog sd(*this, input, tr["Settings"]); sd.addSetting(unique_ptr(new MenuSettingMultiString( - *this, ts, tr["Language"], + *this, tr["Language"], tr["Set the language used by GMenu2X"], &lang, &translations))); sd.addSetting(unique_ptr(new MenuSettingBool( - *this, ts, tr["Save last selection"], + *this, tr["Save last selection"], tr["Save the last selected link and section on exit"], &confInt["saveSelection"]))); #ifdef ENABLE_CPUFREQ sd.addSetting(unique_ptr(new MenuSettingInt( - *this, ts, tr["Clock for GMenu2X"], + *this, tr["Clock for GMenu2X"], tr["Set the cpu working frequency when running GMenu2X"], &confInt["menuClock"], cpuFreqMin, cpuFreqSafeMax, cpuFreqMultiple))); sd.addSetting(unique_ptr(new MenuSettingInt( - *this, ts, tr["Maximum overclock"], + *this, tr["Maximum overclock"], tr["Set the maximum overclock for launching links"], &confInt["maxClock"], cpuFreqMin, cpuFreqMax, cpuFreqMultiple))); #endif sd.addSetting(unique_ptr(new MenuSettingBool( - *this, ts, tr["Output logs"], + *this, tr["Output logs"], tr["Logs the output of the links. Use the Log Viewer to read them."], &confInt["outputLogs"]))); sd.addSetting(unique_ptr(new MenuSettingInt( - *this, ts, tr["Screen Timeout"], + *this, tr["Screen Timeout"], tr["Set screen's backlight timeout in seconds"], &confInt["backlightTimeout"], 0, 120))); sd.addSetting(unique_ptr(new MenuSettingInt( - *this, ts, tr["Button repeat rate"], + *this, tr["Button repeat rate"], tr["Set button repetitions per second"], &confInt["buttonRepeatRate"], 0, 20))); @@ -761,33 +751,33 @@ void GMenu2X::skinMenu() { string curSkin = confStr["skin"]; - SettingsDialog sd(*this, input, ts, tr["Skin"]); + SettingsDialog sd(*this, input, tr["Skin"]); sd.addSetting(unique_ptr(new MenuSettingMultiString( - *this, ts, tr["Skin"], + *this, tr["Skin"], tr["Set the skin used by GMenu2X"], &confStr["skin"], &fl_sk.getDirectories()))); sd.addSetting(unique_ptr(new MenuSettingRGBA( - *this, ts, tr["Top Bar"], + *this, tr["Top Bar"], tr["Color of the top bar"], &skinConfColors[COLOR_TOP_BAR_BG]))); sd.addSetting(unique_ptr(new MenuSettingRGBA( - *this, ts, tr["Bottom Bar"], + *this, tr["Bottom Bar"], tr["Color of the bottom bar"], &skinConfColors[COLOR_BOTTOM_BAR_BG]))); sd.addSetting(unique_ptr(new MenuSettingRGBA( - *this, ts, tr["Selection"], + *this, tr["Selection"], tr["Color of the selection and other interface details"], &skinConfColors[COLOR_SELECTION_BG]))); sd.addSetting(unique_ptr(new MenuSettingRGBA( - *this, ts, tr["Message Box"], + *this, tr["Message Box"], tr["Background color of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_BG]))); sd.addSetting(unique_ptr(new MenuSettingRGBA( - *this, ts, tr["Message Box Border"], + *this, tr["Message Box Border"], tr["Border color of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_BORDER]))); sd.addSetting(unique_ptr(new MenuSettingRGBA( - *this, ts, tr["Message Box Selection"], + *this, tr["Message Box Selection"], tr["Color of the selection of the message box"], &skinConfColors[COLOR_MESSAGE_BOX_SELECTION]))); @@ -888,7 +878,7 @@ void GMenu2X::showContextMenu() { } void GMenu2X::changeWallpaper() { - WallpaperDialog wp(*this, ts); + WallpaperDialog wp(*this); if (wp.exec() && confStr["wallpaper"] != wp.wallpaper) { confStr["wallpaper"] = wp.wallpaper; initBG(); @@ -897,7 +887,7 @@ void GMenu2X::changeWallpaper() { } void GMenu2X::addLink() { - FileDialog fd(*this, ts, tr["Select an application"], "sh,bin,py,elf,"); + FileDialog fd(*this, tr["Select an application"], "sh,bin,py,elf,"); if (fd.exec()) menu->addLink(fd.getPath(), fd.getFile()); } @@ -925,52 +915,52 @@ void GMenu2X::editLink() { string diagTitle = tr.translate("Edit $1",linkTitle.c_str(),NULL); string diagIcon = linkApp->getIconPath(); - SettingsDialog sd(*this, input, ts, diagTitle, diagIcon); + SettingsDialog sd(*this, input, diagTitle, diagIcon); if (!linkApp->isOpk()) { sd.addSetting(unique_ptr(new MenuSettingString( - *this, ts, tr["Title"], + *this, tr["Title"], tr["Link title"], &linkTitle, diagTitle, diagIcon))); sd.addSetting(unique_ptr(new MenuSettingString( - *this, ts, tr["Description"], + *this, tr["Description"], tr["Link description"], &linkDescription, diagTitle, diagIcon))); sd.addSetting(unique_ptr(new MenuSettingMultiString( - *this, ts, tr["Section"], + *this, tr["Section"], tr["The section this link belongs to"], &newSection, &menu->getSections()))); sd.addSetting(unique_ptr(new MenuSettingImage( - *this, ts, tr["Icon"], + *this, tr["Icon"], tr.translate("Select an icon for this link", linkTitle.c_str(), NULL), &linkIcon, "png"))); sd.addSetting(unique_ptr(new MenuSettingFile( - *this, ts, tr["Manual"], + *this, tr["Manual"], tr["Select a manual or README file"], &linkManual, "man.png,txt"))); } if (!linkApp->isOpk() || !linkApp->getSelectorDir().empty()) { sd.addSetting(unique_ptr(new MenuSettingDir( - *this, ts, tr["Selector Directory"], + *this, tr["Selector Directory"], tr["Directory to scan for the selector"], &linkSelDir))); sd.addSetting(unique_ptr(new MenuSettingBool( - *this, ts, tr["Selector Browser"], + *this, tr["Selector Browser"], tr["Allow the selector to change directory"], &linkSelBrowser))); } #ifdef ENABLE_CPUFREQ sd.addSetting(unique_ptr(new MenuSettingInt( - *this, ts, tr["Clock frequency"], + *this, tr["Clock frequency"], tr["CPU clock frequency for this link"], &linkClock, cpuFreqMin, confInt["maxClock"], cpuFreqMultiple))); #endif if (!linkApp->isOpk()) { sd.addSetting(unique_ptr(new MenuSettingString( - *this, ts, tr["Selector Filter"], + *this, tr["Selector Filter"], tr["Selector filter (Separate values with a comma)"], &linkSelFilter, diagTitle, diagIcon))); sd.addSetting(unique_ptr(new MenuSettingBool( - *this, ts, tr["Display Console"], + *this, tr["Display Console"], tr["Must be enabled for console-based applications"], &linkApp->consoleApp))); } @@ -1021,7 +1011,7 @@ void GMenu2X::deleteLink() { } void GMenu2X::addSection() { - InputDialog id(*this, input, ts, tr["Insert a name for the new section"]); + InputDialog id(*this, input, tr["Insert a name for the new section"]); if (id.exec()) { // Look up section; create if it doesn't exist yet. auto idx = menu->sectionNamed(id.getInput()); @@ -1031,7 +1021,7 @@ void GMenu2X::addSection() { } void GMenu2X::renameSection() { - InputDialog id(*this, input, ts, tr["Insert a new name for this section"],menu->selSection()); + InputDialog id(*this, input, tr["Insert a new name for this section"],menu->selSection()); if (id.exec()) { //only if a section with the same name does not exist & !samename if (menu->selSection() != id.getInput() diff --git a/src/gmenu2x.h b/src/gmenu2x.h index f791c02..403a4cf 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -24,7 +24,6 @@ #include "contextmenu.h" #include "surfacecollection.h" #include "translator.h" -#include "touchscreen.h" #include "inputmanager.h" #include "powersaver.h" #include "surface.h" @@ -70,7 +69,6 @@ enum color { class GMenu2X { private: - Touchscreen ts; std::shared_ptr menu; #ifdef ENABLE_INOTIFY MediaMonitor *monitor; @@ -210,8 +208,6 @@ public: void drawTopBar(Surface& s); void drawBottomBar(Surface& s); - - Touchscreen &getTouchscreen() { return ts; } }; #endif // GMENU2X_H diff --git a/src/helppopup.cpp b/src/helppopup.cpp index 792f5cb..908e500 100644 --- a/src/helppopup.cpp +++ b/src/helppopup.cpp @@ -36,11 +36,3 @@ bool HelpPopup::handleButtonPress(InputManager::Button button) { } return true; } - -bool HelpPopup::handleTouchscreen(Touchscreen& ts) { - if (ts.pressed()) { - dismiss(); - ts.setHandled(); - } - return true; -} diff --git a/src/helppopup.h b/src/helppopup.h index 6a49b38..3d6bc15 100644 --- a/src/helppopup.h +++ b/src/helppopup.h @@ -19,7 +19,6 @@ public: // Layer implementation: virtual void paint(Surface& s); virtual bool handleButtonPress(InputManager::Button button); - virtual bool handleTouchscreen(Touchscreen& ts); private: GMenu2X& gmenu2x; diff --git a/src/iconbutton.cpp b/src/iconbutton.cpp index b011191..78874e7 100644 --- a/src/iconbutton.cpp +++ b/src/iconbutton.cpp @@ -8,10 +8,9 @@ using namespace std; IconButton::IconButton( - GMenu2X& gmenu2x, Touchscreen &ts, - const string &icon, const string &label, Action action) + GMenu2X& gmenu2x, const string &icon, const string &label, + Action action) : gmenu2x(gmenu2x) - , ts(ts) , icon(icon) , label(label) , action(action) @@ -52,15 +51,6 @@ void IconButton::recalcRects() { rect.h = h; } -bool IconButton::handleTS() { - if (action && ts.released() && ts.inRect(rect)) { - ts.setHandled(); - action(); - return true; - } - return false; -} - void IconButton::paint(Surface& s) { if (iconSurface) { iconSurface->blit(s, iconRect); diff --git a/src/iconbutton.h b/src/iconbutton.h index 77ca4dc..469fd40 100644 --- a/src/iconbutton.h +++ b/src/iconbutton.h @@ -10,29 +10,25 @@ class OffscreenSurface; class Surface; -class Touchscreen; class IconButton { public: typedef std::function Action; - IconButton(GMenu2X& gmenu2x, Touchscreen &ts, + IconButton(GMenu2X& gmenu2x, const std::string &icon, const std::string &label = "", Action action = nullptr); SDL_Rect getRect() { return rect; } void setPosition(int x, int y); - bool handleTS(); - void paint(Surface& s); private: void recalcRects(); GMenu2X& gmenu2x; - Touchscreen &ts; std::string icon, label; Action action; diff --git a/src/imagedialog.cpp b/src/imagedialog.cpp index ccdb98c..a8103c2 100644 --- a/src/imagedialog.cpp +++ b/src/imagedialog.cpp @@ -34,9 +34,9 @@ using namespace std; ImageDialog::ImageDialog( - GMenu2X& gmenu2x, Touchscreen &ts, const string &text, + GMenu2X& gmenu2x, const string &text, const string &filter, const string &file) - : FileDialog(gmenu2x, ts, text, filter, file, "Image Browser") + : FileDialog(gmenu2x, text, filter, file, "Image Browser") { string path; diff --git a/src/imagedialog.h b/src/imagedialog.h index 6b7dd7d..e403304 100644 --- a/src/imagedialog.h +++ b/src/imagedialog.h @@ -31,7 +31,7 @@ protected: SurfaceCollection previews; public: ImageDialog( - GMenu2X& gmenu2x, Touchscreen &ts, const std::string &text, + GMenu2X& gmenu2x, const std::string &text, const std::string &filter = "", const std::string &file = ""); virtual ~ImageDialog(); diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index f7d0410..5f0f347 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -38,11 +38,10 @@ static bool utf8Code(unsigned char c) } InputDialog::InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr_, - Touchscreen &ts_, const string &text, + const string &text, const string &startvalue, const string &title, const string &icon) : Dialog(gmenu2x) , inputMgr(inputMgr_) - , ts(ts_) { if (title.empty()) { this->title = text; @@ -97,22 +96,22 @@ InputDialog::InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr_, setKeyboard(0); buttonbox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/l.png", + gmenu2x, "skin:imgs/buttons/l.png", gmenu2x.tr["Backspace"], bind(&InputDialog::backspace, this)))); buttonbox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/r.png", + gmenu2x, "skin:imgs/buttons/r.png", gmenu2x.tr["Space"], bind(&InputDialog::space, this)))); buttonbox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/accept.png", + gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Confirm"], bind(&InputDialog::confirm, this)))); buttonbox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/cancel.png", + gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Change keys"], bind(&InputDialog::changeKeys, this)))); } @@ -182,7 +181,6 @@ bool InputDialog::exec() { gmenu2x.skinConfColors[COLOR_SELECTION_BG]); } - if (ts.available()) ts.poll(); drawVirtualKeyboard(); s.flip(); @@ -306,12 +304,6 @@ void InputDialog::drawVirtualKeyboard() { KEY_HEIGHT - 2 }; - //if ts on rect, change selection - if (ts.available() && ts.pressed() && ts.inRect(re)) { - selCol = xc; - selRow = l; - } - s.rectangle(re, gmenu2x.skinConfColors[COLOR_SELECTION_BG]); gmenu2x.font->write(s, charX, @@ -330,10 +322,6 @@ void InputDialog::drawVirtualKeyboard() { KEY_HEIGHT - 1 }; s.rectangle(re, gmenu2x.skinConfColors[COLOR_SELECTION_BG]); - if (ts.available() && ts.pressed() && ts.inRect(re)) { - selCol = 0; - selRow = kb->size(); - } gmenu2x.font->write(s, gmenu2x.tr["Cancel"], (int)(160 - kbLength * KEY_WIDTH / 4), KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, @@ -341,10 +329,6 @@ void InputDialog::drawVirtualKeyboard() { re.x = kbLeft + kbLength * KEY_WIDTH / 2 - 1; s.rectangle(re, gmenu2x.skinConfColors[COLOR_SELECTION_BG]); - if (ts.available() && ts.pressed() && ts.inRect(re)) { - selCol = 1; - selRow = kb->size(); - } gmenu2x.font->write(s, gmenu2x.tr["OK"], (int)(160 + kbLength * KEY_WIDTH / 4), KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, diff --git a/src/inputdialog.h b/src/inputdialog.h index 07ced8a..e4af264 100644 --- a/src/inputdialog.h +++ b/src/inputdialog.h @@ -29,11 +29,10 @@ #include class InputManager; -class Touchscreen; class InputDialog : protected Dialog { public: - InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr, Touchscreen &ts, + InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr, const std::string &text, const std::string &startvalue="", const std::string &title="", const std::string &icon=""); @@ -50,7 +49,6 @@ private: void setKeyboard(int); InputManager &inputMgr; - Touchscreen &ts; int selRow, selCol; bool close, ok; std::string title, text, icon; diff --git a/src/layer.h b/src/layer.h index baf8d9a..7954502 100644 --- a/src/layer.h +++ b/src/layer.h @@ -7,7 +7,6 @@ #include "inputmanager.h" class Surface; -class Touchscreen; /** @@ -37,13 +36,6 @@ public: */ virtual bool handleButtonPress(InputManager::Button button) = 0; - /** - * Handles the touch screen. - * Only called if there is a touch screen available. - * Returns true iff the touch screen was fully handled by this layer. - */ - virtual bool handleTouchscreen(Touchscreen &ts) = 0; - Status getStatus() { return status; } protected: diff --git a/src/link.cpp b/src/link.cpp index b1ef2a3..7f419e5 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -34,11 +34,9 @@ using namespace std; Link::Link(GMenu2X& gmenu2x, Action action) : gmenu2x(gmenu2x) - , ts(gmenu2x.getTouchscreen()) , action(action) , lastTick(0) { -// ts = gmenu2x.getTouchscreen(); rect.w = gmenu2x.skinConfInt["linkWidth"]; rect.h = gmenu2x.skinConfInt["linkHeight"]; edited = false; @@ -49,23 +47,6 @@ Link::Link(GMenu2X& gmenu2x, Action action) updateSurfaces(); } -bool Link::isPressed() { - return ts.pressed() && ts.inRect(rect); -} - -bool Link::handleTS() { - if (ts.released() && ts.inRect(rect)) { - int tickNow = SDL_GetTicks(); - if (tickNow - lastTick < 400) { - ts.setHandled(); - action(); - } - lastTick = tickNow; - return true; - } - return false; -} - void Link::paint() { Surface& s = *gmenu2x.s; diff --git a/src/link.h b/src/link.h index 733fa3a..d4877a4 100644 --- a/src/link.h +++ b/src/link.h @@ -28,7 +28,6 @@ class GMenu2X; class OffscreenSurface; -class Touchscreen; /** @@ -43,9 +42,6 @@ public: Link(GMenu2X& gmenu2x, Action action); virtual ~Link() {}; - bool isPressed(); - bool handleTS(); - virtual void paint(); void paintHover(); @@ -79,7 +75,6 @@ protected: private: void recalcCoordinates(); - Touchscreen &ts; Action action; SDL_Rect rect; diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 50d4beb..62145b3 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -72,10 +72,6 @@ public: return true; } - bool handleTouchscreen(Touchscreen&) override { - return true; - } - private: LinkApp& app; }; diff --git a/src/menu.cpp b/src/menu.cpp index 1a66b15..89dc84a 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -68,10 +68,9 @@ void Menu::Animation::step() } } -Menu::Menu(GMenu2X& gmenu2x, Touchscreen &ts) +Menu::Menu(GMenu2X& gmenu2x) : gmenu2x(gmenu2x) - , ts(ts) - , btnContextMenu(gmenu2x, ts, "skin:imgs/menu.png", "", + , btnContextMenu(gmenu2x, "skin:imgs/menu.png", "", std::bind(&GMenu2X::showContextMenu, &gmenu2x)) { readSections(GMENU2X_SYSTEM_DIR "/sections"); @@ -275,10 +274,6 @@ void Menu::paint(Surface &s) { sc.skinRes("imgs/manual.png")->blit( s, gmenu2x.manualX, gmenu2x.bottomBarIconY); } - - if (ts.available()) { - btnContextMenu.paint(s); - } } bool Menu::handleButtonPress(InputManager::Button button) { @@ -312,43 +307,6 @@ bool Menu::handleButtonPress(InputManager::Button button) { } } -bool Menu::handleTouchscreen(Touchscreen &ts) { - btnContextMenu.handleTS(); - - ConfIntHash &skinConfInt = gmenu2x.skinConfInt; - const int topBarHeight = skinConfInt["topBarHeight"]; - const int screenWidth = gmenu2x.resX; - - if (ts.pressed() && ts.getY() < topBarHeight) { - int leftSection, rightSection; - calcSectionRange(leftSection, rightSection); - - const int linkWidth = skinConfInt["linkWidth"]; - const int leftSectionX = screenWidth / 2 + leftSection * linkWidth; - const int i = min( - leftSection + max((ts.getX() - leftSectionX) / linkWidth, 0), - rightSection); - const uint numSections = sections.size(); - setSectionIndex((iSection + numSections + i) % numSections); - - ts.setHandled(); - return true; - } - - const uint linksPerPage = linkColumns * linkRows; - uint i = iFirstDispRow * linkColumns; - while (i < (iFirstDispRow * linkColumns) + linksPerPage && i < sectionLinks()->size()) { - if (sectionLinks()->at(i)->isPressed()) { - setLinkIndex(i); - } - if (sectionLinks()->at(i)->handleTS()) { - i = sectionLinks()->size(); - } - i++; - } - return ts.handled(); -} - /*==================================== SECTION MANAGEMENT ====================================*/ diff --git a/src/menu.h b/src/menu.h index 4bc9206..c3215f2 100644 --- a/src/menu.h +++ b/src/menu.h @@ -55,7 +55,6 @@ private: }; GMenu2X& gmenu2x; - Touchscreen &ts; IconButton btnContextMenu; int iSection, iLink; uint iFirstDispRow; @@ -109,7 +108,7 @@ private: public: typedef std::function Action; - Menu(GMenu2X& gmenu2x, Touchscreen &ts); + Menu(GMenu2X& gmenu2x); virtual ~Menu(); #ifdef HAVE_LIBOPK @@ -152,7 +151,6 @@ public: virtual bool runAnimations(); virtual void paint(Surface &s); virtual bool handleButtonPress(InputManager::Button button); - virtual bool handleTouchscreen(Touchscreen &ts); bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex); diff --git a/src/menusetting.cpp b/src/menusetting.cpp index a08287f..e21aa17 100644 --- a/src/menusetting.cpp +++ b/src/menusetting.cpp @@ -44,11 +44,6 @@ void MenuSetting::draw(int /*valueX*/, int y, int /*h*/) gmenu2x.font->write(s, name, 5, y, Font::HAlignLeft, Font::VAlignTop); } -void MenuSetting::handleTS(int /*valueX*/, int /*y*/, int /*h*/) -{ - buttonBox.handleTS(); -} - void MenuSetting::drawSelected(int valueX, int y, int h) { Surface& s = *gmenu2x.s; diff --git a/src/menusetting.h b/src/menusetting.h index cdcb27d..8cf5d54 100644 --- a/src/menusetting.h +++ b/src/menusetting.h @@ -45,7 +45,6 @@ public: virtual ~MenuSetting(); virtual void draw(int valueX, int y, int h); - virtual void handleTS(int valueX, int y, int h); virtual bool handleButtonPress(InputManager::Button button) = 0; virtual void drawSelected(int valueX, int y, int h); diff --git a/src/menusettingbool.cpp b/src/menusettingbool.cpp index 33ebda0..85a0c42 100644 --- a/src/menusettingbool.cpp +++ b/src/menusettingbool.cpp @@ -32,10 +32,9 @@ using std::string; using std::unique_ptr; MenuSettingBool::MenuSettingBool( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const string &name, const string &description, int *value) : MenuSetting(gmenu2x, name, description) - , ts(ts) { _ivalue = value; _value = NULL; @@ -45,10 +44,9 @@ MenuSettingBool::MenuSettingBool( } MenuSettingBool::MenuSettingBool( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const string &name, const string &description, bool *value) : MenuSetting(gmenu2x, name, description) - , ts(ts) { _value = value; _ivalue = NULL; @@ -60,7 +58,7 @@ MenuSettingBool::MenuSettingBool( void MenuSettingBool::initButton() { buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/accept.png", + gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Switch"], bind(&MenuSettingBool::toggle, this)))); } diff --git a/src/menusettingbool.h b/src/menusettingbool.h index 465ec95..40c721d 100644 --- a/src/menusettingbool.h +++ b/src/menusettingbool.h @@ -24,14 +24,12 @@ #include "inputmanager.h" class GMenu2X; -class Touchscreen; class MenuSettingBool : public MenuSetting { private: void initButton(); void toggle(); - Touchscreen &ts; bool originalValue; bool *_value; int *_ivalue; @@ -39,11 +37,11 @@ private: public: MenuSettingBool( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const std::string &name, const std::string &description, bool *value); MenuSettingBool( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const std::string &name, const std::string &description, int *value); virtual ~MenuSettingBool() {} diff --git a/src/menusettingdir.cpp b/src/menusettingdir.cpp index dc7efa3..51b076f 100644 --- a/src/menusettingdir.cpp +++ b/src/menusettingdir.cpp @@ -29,24 +29,23 @@ using std::string; using std::unique_ptr; MenuSettingDir::MenuSettingDir( - GMenu2X& gmenu2x, Touchscreen &ts_, + GMenu2X& gmenu2x, const string &name, const string &description, string *value) : MenuSettingStringBase(gmenu2x, name, description, value) - , ts(ts_) { buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/cancel.png", + gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Clear"], bind(&MenuSettingDir::clear, this)))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/accept.png", + gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"], bind(&MenuSettingDir::edit, this)))); } void MenuSettingDir::edit() { - DirDialog dd(gmenu2x, ts, description, value()); + DirDialog dd(gmenu2x, description, value()); if (dd.exec()) setValue(dd.getPath()); } diff --git a/src/menusettingdir.h b/src/menusettingdir.h index 5399ef1..7f46b6a 100644 --- a/src/menusettingdir.h +++ b/src/menusettingdir.h @@ -22,18 +22,13 @@ #include "menusettingstringbase.h" -class Touchscreen; - class MenuSettingDir : public MenuSettingStringBase { -private: - Touchscreen &ts; - protected: virtual void edit(); public: MenuSettingDir( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const std::string &name, const std::string &description, std::string *value); virtual ~MenuSettingDir() {} diff --git a/src/menusettingfile.cpp b/src/menusettingfile.cpp index a56077a..7f7af12 100644 --- a/src/menusettingfile.cpp +++ b/src/menusettingfile.cpp @@ -29,27 +29,26 @@ using std::string; using std::unique_ptr; MenuSettingFile::MenuSettingFile( - GMenu2X& gmenu2x, Touchscreen &ts_, + GMenu2X& gmenu2x, const string &name, const string &description, string *value, const string &filter_) : MenuSettingStringBase(gmenu2x, name, description, value) - , ts(ts_) , filter(filter_) { buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/cancel.png", + gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Clear"], bind(&MenuSettingFile::clear, this)))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/accept.png", + gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"], bind(&MenuSettingFile::edit, this)))); } void MenuSettingFile::edit() { - FileDialog fd(gmenu2x, ts, description, filter, value()); + FileDialog fd(gmenu2x, description, filter, value()); if (fd.exec()) { setValue(fd.getPath() + "/" + fd.getFile()); } diff --git a/src/menusettingfile.h b/src/menusettingfile.h index 6e9da37..d97d25e 100644 --- a/src/menusettingfile.h +++ b/src/menusettingfile.h @@ -22,18 +22,15 @@ #include "menusettingstringbase.h" -class Touchscreen; - class MenuSettingFile : public MenuSettingStringBase { protected: virtual void edit(); - Touchscreen &ts; std::string filter; public: MenuSettingFile( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const std::string &name, const std::string &description, std::string *value, const std::string &filter = ""); virtual ~MenuSettingFile() {} diff --git a/src/menusettingimage.cpp b/src/menusettingimage.cpp index 7f59230..d7275b5 100644 --- a/src/menusettingimage.cpp +++ b/src/menusettingimage.cpp @@ -27,15 +27,15 @@ using std::string; MenuSettingImage::MenuSettingImage( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const string &name, const string &description, string *value, const string &filter) - : MenuSettingFile(gmenu2x, ts, name, description, value, filter) + : MenuSettingFile(gmenu2x, name, description, value, filter) { } void MenuSettingImage::edit() { - ImageDialog id(gmenu2x, ts, description, filter, value()); + ImageDialog id(gmenu2x, description, filter, value()); if (id.exec()) setValue(id.getPath() + "/" + id.getFile()); } diff --git a/src/menusettingimage.h b/src/menusettingimage.h index 54c5804..d44b099 100644 --- a/src/menusettingimage.h +++ b/src/menusettingimage.h @@ -27,7 +27,7 @@ protected: virtual void edit(); public: - MenuSettingImage(GMenu2X& gmenu2x, Touchscreen &ts, + MenuSettingImage(GMenu2X& gmenu2x, const std::string &name, const std::string &description, std::string *value, const std::string &filter = ""); virtual ~MenuSettingImage() {} diff --git a/src/menusettingint.cpp b/src/menusettingint.cpp index e49f6ef..4b19b1c 100644 --- a/src/menusettingint.cpp +++ b/src/menusettingint.cpp @@ -33,7 +33,7 @@ using std::stringstream; using std::unique_ptr; MenuSettingInt::MenuSettingInt( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const string &name, const string &description, int *value, int min, int max, int increment) : MenuSetting(gmenu2x, name, description) @@ -50,17 +50,17 @@ MenuSettingInt::MenuSettingInt( IconButton::Action actionDec = bind(&MenuSettingInt::dec, this); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/l.png", + gmenu2x, "skin:imgs/buttons/l.png", "", actionDec))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/left.png", + gmenu2x, "skin:imgs/buttons/left.png", gmenu2x.tr["Decrease"], actionDec))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/r.png", + gmenu2x, "skin:imgs/buttons/r.png", "", actionInc))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/right.png", + gmenu2x, "skin:imgs/buttons/right.png", gmenu2x.tr["Increase"], actionInc))); } diff --git a/src/menusettingint.h b/src/menusettingint.h index a4cbdc1..10c60ac 100644 --- a/src/menusettingint.h +++ b/src/menusettingint.h @@ -23,8 +23,6 @@ #include "menusetting.h" #include "inputmanager.h" -class Touchscreen; - class MenuSettingInt : public MenuSetting { private: int originalValue; @@ -38,7 +36,7 @@ private: public: MenuSettingInt( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const std::string &name, const std::string &description, int *value, int min, int max, int increment = 1); virtual ~MenuSettingInt() {} diff --git a/src/menusettingmultistring.cpp b/src/menusettingmultistring.cpp index 917dfcd..c10091b 100644 --- a/src/menusettingmultistring.cpp +++ b/src/menusettingmultistring.cpp @@ -31,7 +31,7 @@ using std::vector; using std::unique_ptr; MenuSettingMultiString::MenuSettingMultiString( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const string &name, const string &description, string *value, const vector *choices_) : MenuSettingStringBase(gmenu2x, name, description, value) @@ -40,10 +40,10 @@ MenuSettingMultiString::MenuSettingMultiString( setSel(find(choices->begin(), choices->end(), *value) - choices->begin()); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/left.png", "", + gmenu2x, "skin:imgs/buttons/left.png", "", bind(&MenuSettingMultiString::decSel, this)))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/right.png", + gmenu2x, "skin:imgs/buttons/right.png", gmenu2x.tr["Change value"], bind(&MenuSettingMultiString::incSel, this)))); } diff --git a/src/menusettingmultistring.h b/src/menusettingmultistring.h index d10dfae..615e3fc 100644 --- a/src/menusettingmultistring.h +++ b/src/menusettingmultistring.h @@ -25,8 +25,6 @@ #include -class Touchscreen; - class MenuSettingMultiString : public MenuSettingStringBase { private: virtual void edit() { @@ -42,7 +40,7 @@ private: public: MenuSettingMultiString( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const std::string &name, const std::string &description, std::string *value, const std::vector *choices); virtual ~MenuSettingMultiString() {}; diff --git a/src/menusettingrgba.cpp b/src/menusettingrgba.cpp index e9128d1..756a075 100644 --- a/src/menusettingrgba.cpp +++ b/src/menusettingrgba.cpp @@ -34,10 +34,9 @@ using std::unique_ptr; constexpr unsigned int COMPONENT_WIDTH = 28; MenuSettingRGBA::MenuSettingRGBA( - GMenu2X& gmenu2x, Touchscreen &ts_, + GMenu2X& gmenu2x, const string &name, const string &description, RGBAColor *value) : MenuSetting(gmenu2x, name, description) - , ts(ts_) { edit = false; @@ -66,19 +65,6 @@ void MenuSettingRGBA::draw(int valueX, int y, int h) { font->write(s, strA, valueX + h + COMPONENT_WIDTH * 4 - 2, y, Font::HAlignRight, Font::VAlignTop); } -void MenuSettingRGBA::handleTS(int valueX, int y, int h) { - if (ts.pressed()) { - for (int i=0; i<4; i++) { - if (i!=selPart && ts.inRect(valueX + h + i * COMPONENT_WIDTH,y,COMPONENT_WIDTH,h)) { - selPart = i; - break; - } - } - } - - MenuSetting::handleTS(valueX, y, h); -} - bool MenuSettingRGBA::handleButtonPress(InputManager::Button button) { if (edit) { @@ -230,14 +216,14 @@ void MenuSettingRGBA::updateButtonBox() { buttonBox.clear(); if (edit) { - buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/l.png"))); - buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x.tr["Decrease"]))); - buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png"))); - buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x.tr["Increase"]))); - buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Confirm"]))); + buttonBox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/l.png"))); + buttonBox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/left.png", gmenu2x.tr["Decrease"]))); + buttonBox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/r.png"))); + buttonBox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/right.png", gmenu2x.tr["Increase"]))); + buttonBox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Confirm"]))); } else { - buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png"))); - buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x.tr["Change color component"]))); - buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Edit"]))); + buttonBox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/left.png"))); + buttonBox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/right.png", gmenu2x.tr["Change color component"]))); + buttonBox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Edit"]))); } } diff --git a/src/menusettingrgba.h b/src/menusettingrgba.h index a2f51f3..dbe5a95 100644 --- a/src/menusettingrgba.h +++ b/src/menusettingrgba.h @@ -26,11 +26,9 @@ #include "inputmanager.h" class GMenu2X; -class Touchscreen; class MenuSettingRGBA : public MenuSetting { private: - Touchscreen &ts; unsigned short selPart; std::string strR, strG, strB, strA; RGBAColor originalValue; @@ -47,13 +45,12 @@ private: public: MenuSettingRGBA( - GMenu2X& gmenu2x, Touchscreen &ts, + GMenu2X& gmenu2x, const std::string &name, const std::string &description, RGBAColor *value); virtual ~MenuSettingRGBA() {}; virtual void draw(int valueX, int y, int h); - virtual void handleTS(int valueX, int y, int h); virtual bool handleButtonPress(InputManager::Button button); virtual void drawSelected(int valueX, int y, int h); virtual bool edited(); diff --git a/src/menusettingstring.cpp b/src/menusettingstring.cpp index 380ded5..a6212cf 100644 --- a/src/menusettingstring.cpp +++ b/src/menusettingstring.cpp @@ -29,21 +29,20 @@ using std::string; using std::unique_ptr; MenuSettingString::MenuSettingString( - GMenu2X& gmenu2x, Touchscreen &ts_, + GMenu2X& gmenu2x, const string &name, const string &description, string *value, const string &diagTitle_, const string &diagIcon_) : MenuSettingStringBase(gmenu2x, name, description, value) - , ts(ts_) , diagTitle(diagTitle_) , diagIcon(diagIcon_) { buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/cancel.png", + gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Clear"], bind(&MenuSettingString::clear, this)))); buttonBox.add(unique_ptr(new IconButton( - gmenu2x, ts, "skin:imgs/buttons/accept.png", + gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Edit"], bind(&MenuSettingString::edit, this)))); } @@ -51,7 +50,6 @@ MenuSettingString::MenuSettingString( void MenuSettingString::edit() { InputDialog id( - gmenu2x, gmenu2x.input, ts, - description, value(), diagTitle, diagIcon); + gmenu2x, gmenu2x.input, description, value(), diagTitle, diagIcon); if (id.exec()) setValue(id.getInput()); } diff --git a/src/menusettingstring.h b/src/menusettingstring.h index 5040da5..6da767f 100644 --- a/src/menusettingstring.h +++ b/src/menusettingstring.h @@ -22,12 +22,7 @@ #include "menusettingstringbase.h" -class Touchscreen; - class MenuSettingString : public MenuSettingStringBase { -private: - Touchscreen &ts; - protected: virtual void edit(); @@ -35,7 +30,7 @@ protected: public: MenuSettingString( - GMenu2X& gmenu2x, Touchscreen &ts, const std::string &name, + GMenu2X& gmenu2x, const std::string &name, const std::string &description, std::string *value, const std::string &diagTitle = "", const std::string &diagIcon = ""); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 2f32836..a21597f 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -28,11 +28,10 @@ using namespace std; SettingsDialog::SettingsDialog( - GMenu2X& gmenu2x, InputManager &inputMgr_, Touchscreen &ts_, + GMenu2X& gmenu2x, InputManager &inputMgr_, const string &text_, const string &icon) : Dialog(gmenu2x) , inputMgr(inputMgr_) - , ts(ts_) , text(text_) { if (!icon.empty() && gmenu2x.sc[icon] != NULL) { @@ -46,22 +45,10 @@ bool SettingsDialog::exec() { OffscreenSurface bg(*gmenu2x.bg); bg.convertToDisplayFormat(); - bool close = false, ts_pressed = false; + bool close = false; uint i, sel = 0, firstElement = 0; const int topBarHeight = gmenu2x.skinConfInt["topBarHeight"]; - SDL_Rect clipRect = { - 0, - static_cast(topBarHeight + 1), - static_cast(gmenu2x.resX - 9), - static_cast(gmenu2x.resY - topBarHeight - 25) - }; - SDL_Rect touchRect = { - 2, - static_cast(topBarHeight + 4), - static_cast(gmenu2x.resX - 12), - static_cast(clipRect.h) - }; uint rowHeight = gmenu2x.font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1 uint numRows = (gmenu2x.resY - topBarHeight - 20) / rowHeight; @@ -73,8 +60,6 @@ bool SettingsDialog::exec() { while (!close) { OutputSurface& s = *gmenu2x.s; - if (ts.available()) ts.poll(); - bg.blit(s, 0, 0); gmenu2x.drawTopBar(s); @@ -93,22 +78,9 @@ bool SettingsDialog::exec() { //selected option settings[sel]->drawSelected(maxNameWidth + 15, iY, rowHeight); - if (ts_pressed && !ts.pressed()) { - ts_pressed = false; - } - if (ts.available() && ts.pressed() && !ts.inRect(touchRect)) { - ts_pressed = false; - } for (i=firstElement; idraw(maxNameWidth + 15, iY * rowHeight + topBarHeight + 2, rowHeight); - if (ts.available() && ts.pressed() && ts.inRect( - touchRect.x, touchRect.y + (iY * rowHeight), - touchRect.w, rowHeight - )) { - ts_pressed = true; - sel = i; - } } gmenu2x.drawScrollBar(numRows, settings.size(), firstElement); @@ -117,7 +89,6 @@ bool SettingsDialog::exec() { writeSubTitle(s, settings[sel]->getDescription()); s.flip(); - settings[sel]->handleTS(maxNameWidth + 15, iY, rowHeight); InputManager::Button button = inputMgr.waitForPressedButton(); if (!settings[sel]->handleButtonPress(button)) { diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 7a5b8d2..d2a51fe 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -30,17 +30,15 @@ class InputManager; class MenuSetting; -class Touchscreen; class SettingsDialog : protected Dialog { private: InputManager &inputMgr; - Touchscreen &ts; std::vector> settings; std::string text, icon; public: - SettingsDialog(GMenu2X& gmenu2x, InputManager &inputMgr, Touchscreen &ts, + SettingsDialog(GMenu2X& gmenu2x, InputManager &inputMgr, const std::string &text, const std::string &icon = "skin:sections/settings.png"); diff --git a/src/touchscreen.cpp b/src/touchscreen.cpp deleted file mode 100644 index 1b40ad5..0000000 --- a/src/touchscreen.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Massimiliano Torromeo * - * massimiliano.torromeo@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "touchscreen.h" - -#include -#include - - -Touchscreen::Touchscreen() { - calibrated = false; - wasPressed = false; - _handled = false; - x = 0; - y = 0; - startX = 0; - startY = 0; - event.x = 0; - event.y = 0; - event.pressure = 0; - ts_fd = 0; -} - -Touchscreen::~Touchscreen() { - if (ts_fd > 0) { - close(ts_fd); - } -} - -void Touchscreen::calibrate() { - if (event.pressure == 0) { - calibX = ((event.x - 200) * 320 / 3750) / 4; - calibY = (((event.y - 200) * 240 / 3750)) / 4; - calibrated = true; - } -} - -bool Touchscreen::poll() { - wasPressed = pressed(); - SDL_PumpEvents(); - int mx, my; - if (SDL_GetMouseState(&mx,&my) && SDL_BUTTON(1)) { - x = mx; - y = my; - event.pressure = 1; - } else { - event.pressure = 0; - } - _handled = false; - - if (!wasPressed && pressed()) { - startX = x; - startY = y; - } - - return pressed(); -} - -bool Touchscreen::handled() { - return _handled; -} - -void Touchscreen::setHandled() { - wasPressed = false; - _handled = true; -} - -bool Touchscreen::pressed() { - return !_handled && event.pressure > 0; -} - -bool Touchscreen::released() { - return !pressed() && wasPressed; -} - -bool Touchscreen::inRect(int ix, int iy, int iw, int ih) { - return !_handled && - (y >= iy) && (y <= iy + ih) && (x >= ix) && (x <= ix + iw); -} - -bool Touchscreen::inRect(SDL_Rect r) { - return inRect(r.x, r.y, r.w, r.h); -} - -bool Touchscreen::startedInRect(int ix, int iy, int iw, int ih) { - return !_handled && - (startY >= iy) && (startY <= iy + ih) && - (startX >= ix) && (startX <= ix + iw); -} - -bool Touchscreen::startedInRect(SDL_Rect r) { - return startedInRect(r.x, r.y, r.w, r.h); -} diff --git a/src/touchscreen.h b/src/touchscreen.h deleted file mode 100644 index 45bd4a3..0000000 --- a/src/touchscreen.h +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Massimiliano Torromeo * - * massimiliano.torromeo@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef TOUCHSCREEN_H -#define TOUCHSCREEN_H - -#include - -#include - -typedef struct { - uint16_t pressure; - uint16_t x; - uint16_t y; - uint16_t pad; - struct timeval stamp; -} TS_EVENT; - -class Touchscreen { -public: - Touchscreen(); - ~Touchscreen(); - - bool available() { - return false; - } - - bool poll(); - bool pressed(); - bool released(); - - bool handled(); - void setHandled(); - - bool inRect(int x, int y, int w, int h); - bool inRect(SDL_Rect r); - bool startedInRect(int x, int y, int w, int h); - bool startedInRect(SDL_Rect r); - - int getX() { return x; } - int getY() { return y; } - -private: - int ts_fd; - bool calibrated, _handled; - TS_EVENT event; - int calibX, calibY; - int x, y, startX, startY; - bool wasPressed; - - void calibrate(/*TS_EVENT event*/); -}; - -#endif diff --git a/src/wallpaperdialog.cpp b/src/wallpaperdialog.cpp index 2560f9c..4fd0365 100644 --- a/src/wallpaperdialog.cpp +++ b/src/wallpaperdialog.cpp @@ -32,9 +32,8 @@ using namespace std; -WallpaperDialog::WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts_) +WallpaperDialog::WallpaperDialog(GMenu2X& gmenu2x) : Dialog(gmenu2x) - , ts(ts_) { } @@ -63,8 +62,8 @@ bool WallpaperDialog::exec() uint i, selected = 0, firstElement = 0, iY; ButtonBox buttonbox; - buttonbox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"]))); - buttonbox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Exit"]))); + buttonbox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"]))); + buttonbox.add(unique_ptr(new IconButton(gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Exit"]))); unsigned int top, height; tie(top, height) = gmenu2x.getContentArea(); diff --git a/src/wallpaperdialog.h b/src/wallpaperdialog.h index 82225a8..6b6532c 100644 --- a/src/wallpaperdialog.h +++ b/src/wallpaperdialog.h @@ -25,14 +25,9 @@ #include -class Touchscreen; - class WallpaperDialog : protected Dialog { -private: - Touchscreen &ts; - public: - WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts); + WallpaperDialog(GMenu2X& gmenu2x); std::string wallpaper; bool exec();