Change Details
src/Makefile.am | ||
---|---|---|
9 | 9 | menusettingstringbase.cpp \ |
10 | 10 | messagebox.cpp selector.cpp \ |
11 | 11 | settingsdialog.cpp surfacecollection.cpp surface.cpp \ |
12 | textdialog.cpp textmanualdialog.cpp touchscreen.cpp translator.cpp \ | |
12 | textdialog.cpp textmanualdialog.cpp translator.cpp \ | |
13 | 13 | utilities.cpp wallpaperdialog.cpp \ |
14 | 14 | browsedialog.cpp buttonbox.cpp dialog.cpp \ |
15 | 15 | imageio.cpp powersaver.cpp monitor.cpp mediamonitor.cpp clock.cpp \ |
... | ... | |
24 | 24 | menusettingstringbase.h \ |
25 | 25 | messagebox.h selector.h settingsdialog.h \ |
26 | 26 | surfacecollection.h surface.h textdialog.h textmanualdialog.h \ |
27 | touchscreen.h translator.h utilities.h wallpaperdialog.h \ | |
27 | translator.h utilities.h wallpaperdialog.h \ | |
28 | 28 | browsedialog.h buttonbox.h dialog.h \ |
29 | 29 | imageio.h powersaver.h monitor.h mediamonitor.h clock.h \ |
30 | 30 | layer.h helppopup.h contextmenu.h background.h battery.h |
src/background.cpp | ||
---|---|---|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | } |
43 | ||
44 | bool Background::handleTouchscreen(Touchscreen&) { | |
45 | return false; | |
46 | } |
src/background.h | ||
---|---|---|
21 | 21 | // Layer implementation: |
22 | 22 | virtual void paint(Surface& s); |
23 | 23 | virtual bool handleButtonPress(InputManager::Button button); |
24 | virtual bool handleTouchscreen(Touchscreen& ts); | |
25 | 24 | |
26 | 25 | private: |
27 | 26 | GMenu2X& gmenu2x; |
src/browsedialog.cpp | ||
---|---|---|
11 | 11 | using std::unique_ptr; |
12 | 12 | |
13 | 13 | BrowseDialog::BrowseDialog( |
14 | GMenu2X& gmenu2x, Touchscreen &ts_, | |
14 | GMenu2X& gmenu2x, | |
15 | 15 | const string &title, const string &subtitle) |
16 | 16 | : Dialog(gmenu2x) |
17 | , ts(ts_) | |
18 | 17 | , title(title) |
19 | 18 | , subtitle(subtitle) |
20 | , ts_pressed(false) | |
21 | 19 | { |
22 | 20 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
23 | gmenu2x, ts, "skin:imgs/buttons/left.png"))); | |
21 | gmenu2x, "skin:imgs/buttons/left.png"))); | |
24 | 22 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
25 | gmenu2x, ts, "skin:imgs/buttons/cancel.png", | |
23 | gmenu2x, "skin:imgs/buttons/cancel.png", | |
26 | 24 | gmenu2x.tr["Up one folder"], |
27 | 25 | bind(&BrowseDialog::directoryUp, this)))); |
28 | 26 | |
29 | 27 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
30 | gmenu2x, ts, "skin:imgs/buttons/accept.png", | |
28 | gmenu2x, "skin:imgs/buttons/accept.png", | |
31 | 29 | gmenu2x.tr["Select"], |
32 | 30 | bind(&BrowseDialog::directoryEnter, this)))); |
33 | 31 | |
34 | 32 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
35 | gmenu2x, ts, "skin:imgs/buttons/start.png", | |
33 | gmenu2x, "skin:imgs/buttons/start.png", | |
36 | 34 | gmenu2x.tr["Confirm"], |
37 | 35 | bind(&BrowseDialog::confirm, this)))); |
38 | 36 | |
39 | 37 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
40 | gmenu2x, ts, "skin:imgs/buttons/select.png", | |
38 | gmenu2x, "skin:imgs/buttons/select.png", | |
41 | 39 | gmenu2x.tr["Exit"], |
42 | 40 | bind(&BrowseDialog::quit, this)))); |
43 | 41 | |
... | ... | |
67 | 65 | static_cast<Uint16>(gmenu2x.resX - 9), |
68 | 66 | static_cast<Uint16>(gmenu2x.resY - topBarHeight - 25) |
69 | 67 | }; |
70 | touchRect = (SDL_Rect) { | |
71 | 2, | |
72 | static_cast<Sint16>(topBarHeight + 4), | |
73 | static_cast<Uint16>(gmenu2x.resX - 12), | |
74 | clipRect.h | |
75 | }; | |
76 | 68 | |
77 | 69 | selected = 0; |
78 | 70 | close = false; |
79 | 71 | while (!close) { |
80 | if (ts.available()) ts.poll(); | |
81 | ||
82 | 72 | paint(); |
83 | 73 | |
84 | 74 | handleInput(); |
... | ... | |
115 | 105 | void BrowseDialog::handleInput() |
116 | 106 | { |
117 | 107 | 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); | |
130 | 109 | |
131 | 110 | if (action == BrowseDialog::ACT_SELECT && fl[selected] == "..") { |
132 | 111 | action = BrowseDialog::ACT_GOUP; |
... | ... | |
174 | 153 | default: |
175 | 154 | break; |
176 | 155 | } |
177 | ||
178 | buttonBox.handleTS(); | |
179 | 156 | } |
180 | 157 | |
181 | 158 | void BrowseDialog::directoryUp() |
... | ... | |
274 | 251 | gmenu2x.font->write(s, fl[i], 24, offsetY + rowHeight / 2, |
275 | 252 | Font::HAlignLeft, Font::VAlignMiddle); |
276 | 253 | |
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 | ||
283 | 254 | offsetY += rowHeight; |
284 | 255 | } |
285 | 256 | s.clearClipRect(); |
src/browsedialog.h | ||
---|---|---|
30 | 30 | #include <string> |
31 | 31 | |
32 | 32 | class OffscreenSurface; |
33 | class Touchscreen; | |
34 | 33 | |
35 | 34 | class BrowseDialog : protected Dialog { |
36 | 35 | protected: |
37 | BrowseDialog( | |
38 | GMenu2X& gmenu2x, Touchscreen &ts, | |
36 | BrowseDialog(GMenu2X& gmenu2x, | |
39 | 37 | const std::string &title, const std::string &subtitle); |
40 | 38 | virtual ~BrowseDialog(); |
41 | 39 | |
... | ... | |
60 | 58 | ACT_CONFIRM, |
61 | 59 | }; |
62 | 60 | |
63 | Touchscreen &ts; | |
64 | 61 | bool close, result; |
65 | 62 | |
66 | 63 | std::string title; |
... | ... | |
68 | 65 | std::string path; |
69 | 66 | |
70 | 67 | SDL_Rect clipRect; |
71 | SDL_Rect touchRect; | |
72 | 68 | |
73 | 69 | unsigned int numRows; |
74 | 70 | unsigned int rowHeight; |
75 | 71 | |
76 | bool ts_pressed; | |
77 | ||
78 | 72 | OffscreenSurface *iconGoUp; |
79 | 73 | OffscreenSurface *iconFolder; |
80 | 74 | OffscreenSurface *iconFile; |
src/buttonbox.cpp | ||
---|---|---|
25 | 25 | x += button->getRect().w + 6; |
26 | 26 | } |
27 | 27 | } |
28 | ||
29 | void ButtonBox::handleTS() | |
30 | { | |
31 | for (auto& button : buttons) { | |
32 | button->handleTS(); | |
33 | } | |
34 | } |
src/buttonbox.h | ||
---|---|---|
16 | 16 | void clear(); |
17 | 17 | |
18 | 18 | void paint(Surface& s, int x, int y); |
19 | void handleTS(); | |
20 | 19 | |
21 | 20 | private: |
22 | 21 | std::vector<std::unique_ptr<IconButton>> buttons; |
src/contextmenu.cpp | ||
---|---|---|
157 | 157 | } |
158 | 158 | return true; |
159 | 159 | } |
160 | ||
161 | bool 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 | ||
---|---|---|
24 | 24 | virtual bool runAnimations(); |
25 | 25 | virtual void paint(Surface &s); |
26 | 26 | virtual bool handleButtonPress(InputManager::Button button); |
27 | virtual bool handleTouchscreen(Touchscreen &ts); | |
28 | 27 | |
29 | 28 | private: |
30 | 29 | struct MenuOption; |
src/dirdialog.cpp | ||
---|---|---|
24 | 24 | |
25 | 25 | using namespace std; |
26 | 26 | |
27 | DirDialog::DirDialog( | |
28 | GMenu2X& gmenu2x, Touchscreen &ts, | |
29 | const string &text, const string &dir) | |
30 | : BrowseDialog(gmenu2x, ts, "Directory Browser", text) | |
27 | DirDialog::DirDialog(GMenu2X& gmenu2x, const string &text, const string &dir) | |
28 | : BrowseDialog(gmenu2x, "Directory Browser", text) | |
31 | 29 | { |
32 | 30 | fl.setShowFiles(false); |
33 | 31 | setPath(dir); |
src/dirdialog.h | ||
---|---|---|
25 | 25 | |
26 | 26 | class DirDialog : public BrowseDialog { |
27 | 27 | public: |
28 | DirDialog( | |
29 | GMenu2X& gmenu2x, Touchscreen &ts, | |
28 | DirDialog(GMenu2X& gmenu2x, | |
30 | 29 | const std::string &text, const std::string &dir = ""); |
31 | 30 | }; |
32 | 31 |
src/filedialog.cpp | ||
---|---|---|
25 | 25 | using namespace std; |
26 | 26 | |
27 | 27 | FileDialog::FileDialog( |
28 | GMenu2X& gmenu2x, Touchscreen &ts, const string &text, | |
28 | GMenu2X& gmenu2x, const string &text, | |
29 | 29 | const string &filter, const string &file, const string &title) |
30 | : BrowseDialog(gmenu2x, ts, title, text) | |
30 | : BrowseDialog(gmenu2x, title, text) | |
31 | 31 | { |
32 | 32 | string path(CARD_ROOT); |
33 | 33 | if (!file.empty()) { |
src/filedialog.h | ||
---|---|---|
26 | 26 | class FileDialog : public BrowseDialog { |
27 | 27 | public: |
28 | 28 | FileDialog( |
29 | GMenu2X& gmenu2x, Touchscreen &ts, const std::string &text, | |
29 | GMenu2X& gmenu2x, const std::string &text, | |
30 | 30 | const std::string &filter="*", const std::string &file="", |
31 | 31 | const std::string &title = "File Dialog"); |
32 | 32 | bool exec(); |
src/gmenu2x.cpp | ||
---|---|---|
376 | 376 | |
377 | 377 | void GMenu2X::initMenu() { |
378 | 378 | //Menu structure handler |
379 | menu.reset(new Menu(*this, ts)); | |
379 | menu.reset(new Menu(*this)); | |
380 | 380 | |
381 | 381 | // Add action links in the applications section. |
382 | 382 | auto appIdx = menu->sectionNamed("applications"); |
... | ... | |
628 | 628 | break; |
629 | 629 | } |
630 | 630 | |
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 | ||
641 | 631 | // Handle other input events. |
642 | 632 | InputManager::Button button; |
643 | 633 | bool gotEvent; |
... | ... | |
656 | 646 | } |
657 | 647 | |
658 | 648 | void 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,"); | |
660 | 650 | if (fd.exec()) { |
661 | 651 | if (confInt["saveSelection"] && (confInt["section"]!=menu->selSectionIndex() || confInt["link"]!=menu->selLinkIndex())) |
662 | 652 | writeConfig(); |
... | ... | |
701 | 691 | encodings.push_back("NTSC"); |
702 | 692 | encodings.push_back("PAL"); |
703 | 693 | |
704 | SettingsDialog sd(*this, input, ts, tr["Settings"]); | |
694 | SettingsDialog sd(*this, input, tr["Settings"]); | |
705 | 695 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString( |
706 | *this, ts, tr["Language"], | |
696 | *this, tr["Language"], | |
707 | 697 | tr["Set the language used by GMenu2X"], |
708 | 698 | &lang, &translations))); |
709 | 699 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool( |
710 | *this, ts, tr["Save last selection"], | |
700 | *this, tr["Save last selection"], | |
711 | 701 | tr["Save the last selected link and section on exit"], |
712 | 702 | &confInt["saveSelection"]))); |
713 | 703 | #ifdef ENABLE_CPUFREQ |
714 | 704 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( |
715 | *this, ts, tr["Clock for GMenu2X"], | |
705 | *this, tr["Clock for GMenu2X"], | |
716 | 706 | tr["Set the cpu working frequency when running GMenu2X"], |
717 | 707 | &confInt["menuClock"], cpuFreqMin, cpuFreqSafeMax, cpuFreqMultiple))); |
718 | 708 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( |
719 | *this, ts, tr["Maximum overclock"], | |
709 | *this, tr["Maximum overclock"], | |
720 | 710 | tr["Set the maximum overclock for launching links"], |
721 | 711 | &confInt["maxClock"], cpuFreqMin, cpuFreqMax, cpuFreqMultiple))); |
722 | 712 | #endif |
723 | 713 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool( |
724 | *this, ts, tr["Output logs"], | |
714 | *this, tr["Output logs"], | |
725 | 715 | tr["Logs the output of the links. Use the Log Viewer to read them."], |
726 | 716 | &confInt["outputLogs"]))); |
727 | 717 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( |
728 | *this, ts, tr["Screen Timeout"], | |
718 | *this, tr["Screen Timeout"], | |
729 | 719 | tr["Set screen's backlight timeout in seconds"], |
730 | 720 | &confInt["backlightTimeout"], 0, 120))); |
731 | 721 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( |
732 | *this, ts, tr["Button repeat rate"], | |
722 | *this, tr["Button repeat rate"], | |
733 | 723 | tr["Set button repetitions per second"], |
734 | 724 | &confInt["buttonRepeatRate"], 0, 20))); |
735 | 725 | |
... | ... | |
761 | 751 | |
762 | 752 | string curSkin = confStr["skin"]; |
763 | 753 | |
764 | SettingsDialog sd(*this, input, ts, tr["Skin"]); | |
754 | SettingsDialog sd(*this, input, tr["Skin"]); | |
765 | 755 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString( |
766 | *this, ts, tr["Skin"], | |
756 | *this, tr["Skin"], | |
767 | 757 | tr["Set the skin used by GMenu2X"], |
768 | 758 | &confStr["skin"], &fl_sk.getDirectories()))); |
769 | 759 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( |
770 | *this, ts, tr["Top Bar"], | |
760 | *this, tr["Top Bar"], | |
771 | 761 | tr["Color of the top bar"], |
772 | 762 | &skinConfColors[COLOR_TOP_BAR_BG]))); |
773 | 763 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( |
774 | *this, ts, tr["Bottom Bar"], | |
764 | *this, tr["Bottom Bar"], | |
775 | 765 | tr["Color of the bottom bar"], |
776 | 766 | &skinConfColors[COLOR_BOTTOM_BAR_BG]))); |
777 | 767 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( |
778 | *this, ts, tr["Selection"], | |
768 | *this, tr["Selection"], | |
779 | 769 | tr["Color of the selection and other interface details"], |
780 | 770 | &skinConfColors[COLOR_SELECTION_BG]))); |
781 | 771 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( |
782 | *this, ts, tr["Message Box"], | |
772 | *this, tr["Message Box"], | |
783 | 773 | tr["Background color of the message box"], |
784 | 774 | &skinConfColors[COLOR_MESSAGE_BOX_BG]))); |
785 | 775 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( |
786 | *this, ts, tr["Message Box Border"], | |
776 | *this, tr["Message Box Border"], | |
787 | 777 | tr["Border color of the message box"], |
788 | 778 | &skinConfColors[COLOR_MESSAGE_BOX_BORDER]))); |
789 | 779 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingRGBA( |
790 | *this, ts, tr["Message Box Selection"], | |
780 | *this, tr["Message Box Selection"], | |
791 | 781 | tr["Color of the selection of the message box"], |
792 | 782 | &skinConfColors[COLOR_MESSAGE_BOX_SELECTION]))); |
793 | 783 | |
... | ... | |
888 | 878 | } |
889 | 879 | |
890 | 880 | void GMenu2X::changeWallpaper() { |
891 | WallpaperDialog wp(*this, ts); | |
881 | WallpaperDialog wp(*this); | |
892 | 882 | if (wp.exec() && confStr["wallpaper"] != wp.wallpaper) { |
893 | 883 | confStr["wallpaper"] = wp.wallpaper; |
894 | 884 | initBG(); |
... | ... | |
897 | 887 | } |
898 | 888 | |
899 | 889 | void 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,"); | |
901 | 891 | if (fd.exec()) |
902 | 892 | menu->addLink(fd.getPath(), fd.getFile()); |
903 | 893 | } |
... | ... | |
925 | 915 | string diagTitle = tr.translate("Edit $1",linkTitle.c_str(),NULL); |
926 | 916 | string diagIcon = linkApp->getIconPath(); |
927 | 917 | |
928 | SettingsDialog sd(*this, input, ts, diagTitle, diagIcon); | |
918 | SettingsDialog sd(*this, input, diagTitle, diagIcon); | |
929 | 919 | if (!linkApp->isOpk()) { |
930 | 920 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString( |
931 | *this, ts, tr["Title"], | |
921 | *this, tr["Title"], | |
932 | 922 | tr["Link title"], |
933 | 923 | &linkTitle, diagTitle, diagIcon))); |
934 | 924 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString( |
935 | *this, ts, tr["Description"], | |
925 | *this, tr["Description"], | |
936 | 926 | tr["Link description"], |
937 | 927 | &linkDescription, diagTitle, diagIcon))); |
938 | 928 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString( |
939 | *this, ts, tr["Section"], | |
929 | *this, tr["Section"], | |
940 | 930 | tr["The section this link belongs to"], |
941 | 931 | &newSection, &menu->getSections()))); |
942 | 932 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingImage( |
943 | *this, ts, tr["Icon"], | |
933 | *this, tr["Icon"], | |
944 | 934 | tr.translate("Select an icon for this link", linkTitle.c_str(), NULL), |
945 | 935 | &linkIcon, "png"))); |
946 | 936 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingFile( |
947 | *this, ts, tr["Manual"], | |
937 | *this, tr["Manual"], | |
948 | 938 | tr["Select a manual or README file"], |
949 | 939 | &linkManual, "man.png,txt"))); |
950 | 940 | } |
951 | 941 | if (!linkApp->isOpk() || !linkApp->getSelectorDir().empty()) { |
952 | 942 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingDir( |
953 | *this, ts, tr["Selector Directory"], | |
943 | *this, tr["Selector Directory"], | |
954 | 944 | tr["Directory to scan for the selector"], |
955 | 945 | &linkSelDir))); |
956 | 946 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool( |
957 | *this, ts, tr["Selector Browser"], | |
947 | *this, tr["Selector Browser"], | |
958 | 948 | tr["Allow the selector to change directory"], |
959 | 949 | &linkSelBrowser))); |
960 | 950 | } |
961 | 951 | #ifdef ENABLE_CPUFREQ |
962 | 952 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingInt( |
963 | *this, ts, tr["Clock frequency"], | |
953 | *this, tr["Clock frequency"], | |
964 | 954 | tr["CPU clock frequency for this link"], |
965 | 955 | &linkClock, cpuFreqMin, confInt["maxClock"], cpuFreqMultiple))); |
966 | 956 | #endif |
967 | 957 | if (!linkApp->isOpk()) { |
968 | 958 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString( |
969 | *this, ts, tr["Selector Filter"], | |
959 | *this, tr["Selector Filter"], | |
970 | 960 | tr["Selector filter (Separate values with a comma)"], |
971 | 961 | &linkSelFilter, diagTitle, diagIcon))); |
972 | 962 | sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingBool( |
973 | *this, ts, tr["Display Console"], | |
963 | *this, tr["Display Console"], | |
974 | 964 | tr["Must be enabled for console-based applications"], |
975 | 965 | &linkApp->consoleApp))); |
976 | 966 | } |
... | ... | |
1021 | 1011 | } |
1022 | 1012 | |
1023 | 1013 | void 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"]); | |
1025 | 1015 | if (id.exec()) { |
1026 | 1016 | // Look up section; create if it doesn't exist yet. |
1027 | 1017 | auto idx = menu->sectionNamed(id.getInput()); |
... | ... | |
1031 | 1021 | } |
1032 | 1022 | |
1033 | 1023 | void 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()); | |
1035 | 1025 | if (id.exec()) { |
1036 | 1026 | //only if a section with the same name does not exist & !samename |
1037 | 1027 | if (menu->selSection() != id.getInput() |
src/gmenu2x.h | ||
---|---|---|
24 | 24 | #include "contextmenu.h" |
25 | 25 | #include "surfacecollection.h" |
26 | 26 | #include "translator.h" |
27 | #include "touchscreen.h" | |
28 | 27 | #include "inputmanager.h" |
29 | 28 | #include "powersaver.h" |
30 | 29 | #include "surface.h" |
... | ... | |
70 | 69 | |
71 | 70 | class GMenu2X { |
72 | 71 | private: |
73 | Touchscreen ts; | |
74 | 72 | std::shared_ptr<Menu> menu; |
75 | 73 | #ifdef ENABLE_INOTIFY |
76 | 74 | MediaMonitor *monitor; |
... | ... | |
210 | 208 | |
211 | 209 | void drawTopBar(Surface& s); |
212 | 210 | void drawBottomBar(Surface& s); |
213 | ||
214 | Touchscreen &getTouchscreen() { return ts; } | |
215 | 211 | }; |
216 | 212 | |
217 | 213 | #endif // GMENU2X_H |
src/helppopup.cpp | ||
---|---|---|
36 | 36 | } |
37 | 37 | return true; |
38 | 38 | } |
39 | ||
40 | bool HelpPopup::handleTouchscreen(Touchscreen& ts) { | |
41 | if (ts.pressed()) { | |
42 | dismiss(); | |
43 | ts.setHandled(); | |
44 | } | |
45 | return true; | |
46 | } |
src/helppopup.h | ||
---|---|---|
19 | 19 | // Layer implementation: |
20 | 20 | virtual void paint(Surface& s); |
21 | 21 | virtual bool handleButtonPress(InputManager::Button button); |
22 | virtual bool handleTouchscreen(Touchscreen& ts); | |
23 | 22 | |
24 | 23 | private: |
25 | 24 | GMenu2X& gmenu2x; |
src/iconbutton.cpp | ||
---|---|---|
8 | 8 | |
9 | 9 | |
10 | 10 | IconButton::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) | |
13 | 13 | : gmenu2x(gmenu2x) |
14 | , ts(ts) | |
15 | 14 | , icon(icon) |
16 | 15 | , label(label) |
17 | 16 | , action(action) |
... | ... | |
52 | 51 | rect.h = h; |
53 | 52 | } |
54 | 53 | |
55 | bool IconButton::handleTS() { | |
56 | if (action && ts.released() && ts.inRect(rect)) { | |
57 | ts.setHandled(); | |
58 | action(); | |
59 | return true; | |
60 | } | |
61 | return false; | |
62 | } | |
63 | ||
64 | 54 | void IconButton::paint(Surface& s) { |
65 | 55 | if (iconSurface) { |
66 | 56 | iconSurface->blit(s, iconRect); |
src/iconbutton.h | ||
---|---|---|
10 | 10 | |
11 | 11 | class OffscreenSurface; |
12 | 12 | class Surface; |
13 | class Touchscreen; | |
14 | 13 | |
15 | 14 | |
16 | 15 | class IconButton { |
17 | 16 | public: |
18 | 17 | typedef std::function<void(void)> Action; |
19 | 18 | |
20 | IconButton(GMenu2X& gmenu2x, Touchscreen &ts, | |
19 | IconButton(GMenu2X& gmenu2x, | |
21 | 20 | const std::string &icon, const std::string &label = "", |
22 | 21 | Action action = nullptr); |
23 | 22 | |
24 | 23 | SDL_Rect getRect() { return rect; } |
25 | 24 | void setPosition(int x, int y); |
26 | 25 | |
27 | bool handleTS(); | |
28 | ||
29 | 26 | void paint(Surface& s); |
30 | 27 | |
31 | 28 | private: |
32 | 29 | void recalcRects(); |
33 | 30 | |
34 | 31 | GMenu2X& gmenu2x; |
35 | Touchscreen &ts; | |
36 | 32 | std::string icon, label; |
37 | 33 | Action action; |
38 | 34 |
src/imagedialog.cpp | ||
---|---|---|
34 | 34 | using namespace std; |
35 | 35 | |
36 | 36 | ImageDialog::ImageDialog( |
37 | GMenu2X& gmenu2x, Touchscreen &ts, const string &text, | |
37 | GMenu2X& gmenu2x, const string &text, | |
38 | 38 | const string &filter, const string &file) |
39 | : FileDialog(gmenu2x, ts, text, filter, file, "Image Browser") | |
39 | : FileDialog(gmenu2x, text, filter, file, "Image Browser") | |
40 | 40 | { |
41 | 41 | |
42 | 42 | string path; |
src/imagedialog.h | ||
---|---|---|
31 | 31 | SurfaceCollection previews; |
32 | 32 | public: |
33 | 33 | ImageDialog( |
34 | GMenu2X& gmenu2x, Touchscreen &ts, const std::string &text, | |
34 | GMenu2X& gmenu2x, const std::string &text, | |
35 | 35 | const std::string &filter = "", const std::string &file = ""); |
36 | 36 | virtual ~ImageDialog(); |
37 | 37 |
src/inputdialog.cpp | ||
---|---|---|
38 | 38 | } |
39 | 39 | |
40 | 40 | InputDialog::InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr_, |
41 | Touchscreen &ts_, const string &text, | |
41 | const string &text, | |
42 | 42 | const string &startvalue, const string &title, const string &icon) |
43 | 43 | : Dialog(gmenu2x) |
44 | 44 | , inputMgr(inputMgr_) |
45 | , ts(ts_) | |
46 | 45 | { |
47 | 46 | if (title.empty()) { |
48 | 47 | this->title = text; |
... | ... | |
97 | 96 | setKeyboard(0); |
98 | 97 | |
99 | 98 | buttonbox.add(unique_ptr<IconButton>(new IconButton( |
100 | gmenu2x, ts, "skin:imgs/buttons/l.png", | |
99 | gmenu2x, "skin:imgs/buttons/l.png", | |
101 | 100 | gmenu2x.tr["Backspace"], |
102 | 101 | bind(&InputDialog::backspace, this)))); |
103 | 102 | |
104 | 103 | buttonbox.add(unique_ptr<IconButton>(new IconButton( |
105 | gmenu2x, ts, "skin:imgs/buttons/r.png", | |
104 | gmenu2x, "skin:imgs/buttons/r.png", | |
106 | 105 | gmenu2x.tr["Space"], |
107 | 106 | bind(&InputDialog::space, this)))); |
108 | 107 | |
109 | 108 | buttonbox.add(unique_ptr<IconButton>(new IconButton( |
110 | gmenu2x, ts, "skin:imgs/buttons/accept.png", | |
109 | gmenu2x, "skin:imgs/buttons/accept.png", | |
111 | 110 | gmenu2x.tr["Confirm"], |
112 | 111 | bind(&InputDialog::confirm, this)))); |
113 | 112 | |
114 | 113 | buttonbox.add(unique_ptr<IconButton>(new IconButton( |
115 | gmenu2x, ts, "skin:imgs/buttons/cancel.png", | |
114 | gmenu2x, "skin:imgs/buttons/cancel.png", | |
116 | 115 | gmenu2x.tr["Change keys"], |
117 | 116 | bind(&InputDialog::changeKeys, this)))); |
118 | 117 | } |
... | ... | |
182 | 181 | gmenu2x.skinConfColors[COLOR_SELECTION_BG]); |
183 | 182 | } |
184 | 183 | |
185 | if (ts.available()) ts.poll(); | |
186 | 184 | drawVirtualKeyboard(); |
187 | 185 | s.flip(); |
188 | 186 | |
... | ... | |
306 | 304 | KEY_HEIGHT - 2 |
307 | 305 | }; |
308 | 306 | |
309 | //if ts on rect, change selection | |
310 | if (ts.available() && ts.pressed() && ts.inRect(re)) { | |
311 | selCol = xc; | |
312 | selRow = l; | |
313 | } | |
314 | ||
315 | 307 | s.rectangle(re, |
316 | 308 | gmenu2x.skinConfColors[COLOR_SELECTION_BG]); |
317 | 309 | gmenu2x.font->write(s, charX, |
... | ... | |
330 | 322 | KEY_HEIGHT - 1 |
331 | 323 | }; |
332 | 324 | 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 | } | |
337 | 325 | gmenu2x.font->write(s, gmenu2x.tr["Cancel"], |
338 | 326 | (int)(160 - kbLength * KEY_WIDTH / 4), |
339 | 327 | KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, |
... | ... | |
341 | 329 | |
342 | 330 | re.x = kbLeft + kbLength * KEY_WIDTH / 2 - 1; |
343 | 331 | 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 | } | |
348 | 332 | gmenu2x.font->write(s, gmenu2x.tr["OK"], |
349 | 333 | (int)(160 + kbLength * KEY_WIDTH / 4), |
350 | 334 | KB_TOP + kb->size() * KEY_HEIGHT + KEY_HEIGHT / 2, |
src/inputdialog.h | ||
---|---|---|
29 | 29 | #include <vector> |
30 | 30 | |
31 | 31 | class InputManager; |
32 | class Touchscreen; | |
33 | 32 | |
34 | 33 | class InputDialog : protected Dialog { |
35 | 34 | public: |
36 | InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr, Touchscreen &ts, | |
35 | InputDialog(GMenu2X& gmenu2x, InputManager &inputMgr, | |
37 | 36 | const std::string &text, const std::string &startvalue="", |
38 | 37 | const std::string &title="", const std::string &icon=""); |
39 | 38 | |
... | ... | |
50 | 49 | void setKeyboard(int); |
51 | 50 | |
52 | 51 | InputManager &inputMgr; |
53 | Touchscreen &ts; | |
54 | 52 | int selRow, selCol; |
55 | 53 | bool close, ok; |
56 | 54 | std::string title, text, icon; |
src/layer.h | ||
---|---|---|
7 | 7 | #include "inputmanager.h" |
8 | 8 | |
9 | 9 | class Surface; |
10 | class Touchscreen; | |
11 | 10 | |
12 | 11 | |
13 | 12 | /** |
... | ... | |
37 | 36 | */ |
38 | 37 | virtual bool handleButtonPress(InputManager::Button button) = 0; |
39 | 38 | |
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 | ||
47 | 39 | Status getStatus() { return status; } |
48 | 40 | |
49 | 41 | protected: |
src/link.cpp | ||
---|---|---|
34 | 34 | |
35 | 35 | Link::Link(GMenu2X& gmenu2x, Action action) |
36 | 36 | : gmenu2x(gmenu2x) |
37 | , ts(gmenu2x.getTouchscreen()) | |
38 | 37 | , action(action) |
39 | 38 | , lastTick(0) |
40 | 39 | { |
41 | // ts = gmenu2x.getTouchscreen(); | |
42 | 40 | rect.w = gmenu2x.skinConfInt["linkWidth"]; |
43 | 41 | rect.h = gmenu2x.skinConfInt["linkHeight"]; |
44 | 42 | edited = false; |
... | ... | |
49 | 47 | updateSurfaces(); |
50 | 48 | } |
51 | 49 | |
52 | bool Link::isPressed() { | |
53 | return ts.pressed() && ts.inRect(rect); | |
54 | } | |
55 | ||
56 | bool 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 | ||
69 | 50 | void Link::paint() { |
70 | 51 | Surface& s = *gmenu2x.s; |
71 | 52 |
src/link.h | ||
---|---|---|
28 | 28 | |
29 | 29 | class GMenu2X; |
30 | 30 | class OffscreenSurface; |
31 | class Touchscreen; | |
32 | 31 | |
33 | 32 | |
34 | 33 | /** |
... | ... | |
43 | 42 | Link(GMenu2X& gmenu2x, Action action); |
44 | 43 | virtual ~Link() {}; |
45 | 44 | |
46 | bool isPressed(); | |
47 | bool handleTS(); | |
48 | ||
49 | 45 | virtual void paint(); |
50 | 46 | void paintHover(); |
51 | 47 | |
... | ... | |
79 | 75 | private: |
80 | 76 | void recalcCoordinates(); |
81 | 77 | |
82 | Touchscreen &ts; | |
83 | 78 | Action action; |
84 | 79 | |
85 | 80 | SDL_Rect rect; |
src/linkapp.cpp | ||
---|---|---|
72 | 72 | return true; |
73 | 73 | } |
74 | 74 | |
75 | bool handleTouchscreen(Touchscreen&) override { | |
76 | return true; | |
77 | } | |
78 | ||
79 | 75 | private: |
80 | 76 | LinkApp& app; |
81 | 77 | }; |
src/menu.cpp | ||
---|---|---|
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | Menu::Menu(GMenu2X& gmenu2x, Touchscreen &ts) | |
71 | Menu::Menu(GMenu2X& gmenu2x) | |
72 | 72 | : gmenu2x(gmenu2x) |
73 | , ts(ts) | |
74 | , btnContextMenu(gmenu2x, ts, "skin:imgs/menu.png", "", | |
73 | , btnContextMenu(gmenu2x, "skin:imgs/menu.png", "", | |
75 | 74 | std::bind(&GMenu2X::showContextMenu, &gmenu2x)) |
76 | 75 | { |
77 | 76 | readSections(GMENU2X_SYSTEM_DIR "/sections"); |
... | ... | |
275 | 274 | sc.skinRes("imgs/manual.png")->blit( |
276 | 275 | s, gmenu2x.manualX, gmenu2x.bottomBarIconY); |
277 | 276 | } |
278 | ||
279 | if (ts.available()) { | |
280 | btnContextMenu.paint(s); | |
281 | } | |
282 | 277 | } |
283 | 278 | |
284 | 279 | bool Menu::handleButtonPress(InputManager::Button button) { |
... | ... | |
312 | 307 | } |
313 | 308 | } |
314 | 309 | |
315 | bool 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 | ||
352 | 310 | /*==================================== |
353 | 311 | SECTION MANAGEMENT |
354 | 312 | ====================================*/ |
src/menu.h | ||
---|---|---|
55 | 55 | }; |
56 | 56 | |
57 | 57 | GMenu2X& gmenu2x; |
58 | Touchscreen &ts; | |
59 | 58 | IconButton btnContextMenu; |
60 | 59 | int iSection, iLink; |
61 | 60 | uint iFirstDispRow; |
... | ... | |
109 | 108 | public: |
110 | 109 | typedef std::function<void(void)> Action; |
111 | 110 | |
112 | Menu(GMenu2X& gmenu2x, Touchscreen &ts); | |
111 | Menu(GMenu2X& gmenu2x); | |
113 | 112 | virtual ~Menu(); |
114 | 113 | |
115 | 114 | #ifdef HAVE_LIBOPK |
... | ... | |
152 | 151 | virtual bool runAnimations(); |
153 | 152 | virtual void paint(Surface &s); |
154 | 153 | virtual bool handleButtonPress(InputManager::Button button); |
155 | virtual bool handleTouchscreen(Touchscreen &ts); | |
156 | 154 | |
157 | 155 | bool linkChangeSection(uint linkIndex, uint oldSectionIndex, uint newSectionIndex); |
158 | 156 |
src/menusetting.cpp | ||
---|---|---|
44 | 44 | gmenu2x.font->write(s, name, 5, y, Font::HAlignLeft, Font::VAlignTop); |
45 | 45 | } |
46 | 46 | |
47 | void MenuSetting::handleTS(int /*valueX*/, int /*y*/, int /*h*/) | |
48 | { | |
49 | buttonBox.handleTS(); | |
50 | } | |
51 | ||
52 | 47 | void MenuSetting::drawSelected(int valueX, int y, int h) |
53 | 48 | { |
54 | 49 | Surface& s = *gmenu2x.s; |
src/menusetting.h | ||
---|---|---|
45 | 45 | virtual ~MenuSetting(); |
46 | 46 | |
47 | 47 | virtual void draw(int valueX, int y, int h); |
48 | virtual void handleTS(int valueX, int y, int h); | |
49 | 48 | |
50 | 49 | virtual bool handleButtonPress(InputManager::Button button) = 0; |
51 | 50 | virtual void drawSelected(int valueX, int y, int h); |
src/menusettingbool.cpp | ||
---|---|---|
32 | 32 | using std::unique_ptr; |
33 | 33 | |
34 | 34 | MenuSettingBool::MenuSettingBool( |
35 | GMenu2X& gmenu2x, Touchscreen &ts, | |
35 | GMenu2X& gmenu2x, | |
36 | 36 | const string &name, const string &description, int *value) |
37 | 37 | : MenuSetting(gmenu2x, name, description) |
38 | , ts(ts) | |
39 | 38 | { |
40 | 39 | _ivalue = value; |
41 | 40 | _value = NULL; |
... | ... | |
45 | 44 | } |
46 | 45 | |
47 | 46 | MenuSettingBool::MenuSettingBool( |
48 | GMenu2X& gmenu2x, Touchscreen &ts, | |
47 | GMenu2X& gmenu2x, | |
49 | 48 | const string &name, const string &description, bool *value) |
50 | 49 | : MenuSetting(gmenu2x, name, description) |
51 | , ts(ts) | |
52 | 50 | { |
53 | 51 | _value = value; |
54 | 52 | _ivalue = NULL; |
... | ... | |
60 | 58 | void MenuSettingBool::initButton() |
61 | 59 | { |
62 | 60 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
63 | gmenu2x, ts, "skin:imgs/buttons/accept.png", | |
61 | gmenu2x, "skin:imgs/buttons/accept.png", | |
64 | 62 | gmenu2x.tr["Switch"], |
65 | 63 | bind(&MenuSettingBool::toggle, this)))); |
66 | 64 | } |
src/menusettingbool.h | ||
---|---|---|
24 | 24 | #include "inputmanager.h" |
25 | 25 | |
26 | 26 | class GMenu2X; |
27 | class Touchscreen; | |
28 | 27 | |
29 | 28 | class MenuSettingBool : public MenuSetting { |
30 | 29 | private: |
31 | 30 | void initButton(); |
32 | 31 | void toggle(); |
33 | 32 | |
34 | Touchscreen &ts; | |
35 | 33 | bool originalValue; |
36 | 34 | bool *_value; |
37 | 35 | int *_ivalue; |
... | ... | |
39 | 37 | |
40 | 38 | public: |
41 | 39 | MenuSettingBool( |
42 | GMenu2X& gmenu2x, Touchscreen &ts, | |
40 | GMenu2X& gmenu2x, | |
43 | 41 | const std::string &name, const std::string &description, |
44 | 42 | bool *value); |
45 | 43 | MenuSettingBool( |
46 | GMenu2X& gmenu2x, Touchscreen &ts, | |
44 | GMenu2X& gmenu2x, | |
47 | 45 | const std::string &name, const std::string &description, |
48 | 46 | int *value); |
49 | 47 | virtual ~MenuSettingBool() {} |
src/menusettingdir.cpp | ||
---|---|---|
29 | 29 | using std::unique_ptr; |
30 | 30 | |
31 | 31 | MenuSettingDir::MenuSettingDir( |
32 | GMenu2X& gmenu2x, Touchscreen &ts_, | |
32 | GMenu2X& gmenu2x, | |
33 | 33 | const string &name, const string &description, string *value) |
34 | 34 | : MenuSettingStringBase(gmenu2x, name, description, value) |
35 | , ts(ts_) | |
36 | 35 | { |
37 | 36 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
38 | gmenu2x, ts, "skin:imgs/buttons/cancel.png", | |
37 | gmenu2x, "skin:imgs/buttons/cancel.png", | |
39 | 38 | gmenu2x.tr["Clear"], |
40 | 39 | bind(&MenuSettingDir::clear, this)))); |
41 | 40 | |
42 | 41 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
43 | gmenu2x, ts, "skin:imgs/buttons/accept.png", | |
42 | gmenu2x, "skin:imgs/buttons/accept.png", | |
44 | 43 | gmenu2x.tr["Select"], |
45 | 44 | bind(&MenuSettingDir::edit, this)))); |
46 | 45 | } |
47 | 46 | |
48 | 47 | void MenuSettingDir::edit() |
49 | 48 | { |
50 | DirDialog dd(gmenu2x, ts, description, value()); | |
49 | DirDialog dd(gmenu2x, description, value()); | |
51 | 50 | if (dd.exec()) setValue(dd.getPath()); |
52 | 51 | } |
src/menusettingdir.h | ||
---|---|---|
22 | 22 | |
23 | 23 | #include "menusettingstringbase.h" |
24 | 24 | |
25 | class Touchscreen; | |
26 | ||
27 | 25 | class MenuSettingDir : public MenuSettingStringBase { |
28 | private: | |
29 | Touchscreen &ts; | |
30 | ||
31 | 26 | protected: |
32 | 27 | virtual void edit(); |
33 | 28 | |
34 | 29 | public: |
35 | 30 | MenuSettingDir( |
36 | GMenu2X& gmenu2x, Touchscreen &ts, | |
31 | GMenu2X& gmenu2x, | |
37 | 32 | const std::string &name, const std::string &description, |
38 | 33 | std::string *value); |
39 | 34 | virtual ~MenuSettingDir() {} |
src/menusettingfile.cpp | ||
---|---|---|
29 | 29 | using std::unique_ptr; |
30 | 30 | |
31 | 31 | MenuSettingFile::MenuSettingFile( |
32 | GMenu2X& gmenu2x, Touchscreen &ts_, | |
32 | GMenu2X& gmenu2x, | |
33 | 33 | const string &name, const string &description, |
34 | 34 | string *value, const string &filter_) |
35 | 35 | : MenuSettingStringBase(gmenu2x, name, description, value) |
36 | , ts(ts_) | |
37 | 36 | , filter(filter_) |
38 | 37 | { |
39 | 38 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
40 | gmenu2x, ts, "skin:imgs/buttons/cancel.png", | |
39 | gmenu2x, "skin:imgs/buttons/cancel.png", | |
41 | 40 | gmenu2x.tr["Clear"], |
42 | 41 | bind(&MenuSettingFile::clear, this)))); |
43 | 42 | |
44 | 43 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
45 | gmenu2x, ts, "skin:imgs/buttons/accept.png", | |
44 | gmenu2x, "skin:imgs/buttons/accept.png", | |
46 | 45 | gmenu2x.tr["Select"], |
47 | 46 | bind(&MenuSettingFile::edit, this)))); |
48 | 47 | } |
49 | 48 | |
50 | 49 | void MenuSettingFile::edit() |
51 | 50 | { |
52 | FileDialog fd(gmenu2x, ts, description, filter, value()); | |
51 | FileDialog fd(gmenu2x, description, filter, value()); | |
53 | 52 | if (fd.exec()) { |
54 | 53 | setValue(fd.getPath() + "/" + fd.getFile()); |
55 | 54 | } |
src/menusettingfile.h | ||
---|---|---|
22 | 22 | |
23 | 23 | #include "menusettingstringbase.h" |
24 | 24 | |
25 | class Touchscreen; | |
26 | ||
27 | 25 | class MenuSettingFile : public MenuSettingStringBase { |
28 | 26 | protected: |
29 | 27 | virtual void edit(); |
30 | 28 | |
31 | Touchscreen &ts; | |
32 | 29 | std::string filter; |
33 | 30 | |
34 | 31 | public: |
35 | 32 | MenuSettingFile( |
36 | GMenu2X& gmenu2x, Touchscreen &ts, | |
33 | GMenu2X& gmenu2x, | |
37 | 34 | const std::string &name, const std::string &description, |
38 | 35 | std::string *value, const std::string &filter = ""); |
39 | 36 | virtual ~MenuSettingFile() {} |
src/menusettingimage.cpp | ||
---|---|---|
27 | 27 | using std::string; |
28 | 28 | |
29 | 29 | MenuSettingImage::MenuSettingImage( |
30 | GMenu2X& gmenu2x, Touchscreen &ts, | |
30 | GMenu2X& gmenu2x, | |
31 | 31 | const string &name, const string &description, |
32 | 32 | string *value, const string &filter) |
33 | : MenuSettingFile(gmenu2x, ts, name, description, value, filter) | |
33 | : MenuSettingFile(gmenu2x, name, description, value, filter) | |
34 | 34 | { |
35 | 35 | } |
36 | 36 | |
37 | 37 | void MenuSettingImage::edit() { |
38 | ImageDialog id(gmenu2x, ts, description, filter, value()); | |
38 | ImageDialog id(gmenu2x, description, filter, value()); | |
39 | 39 | if (id.exec()) setValue(id.getPath() + "/" + id.getFile()); |
40 | 40 | } |
41 | 41 |
src/menusettingimage.h | ||
---|---|---|
27 | 27 | virtual void edit(); |
28 | 28 | |
29 | 29 | public: |
30 | MenuSettingImage(GMenu2X& gmenu2x, Touchscreen &ts, | |
30 | MenuSettingImage(GMenu2X& gmenu2x, | |
31 | 31 | const std::string &name, const std::string &description, |
32 | 32 | std::string *value, const std::string &filter = ""); |
33 | 33 | virtual ~MenuSettingImage() {} |
src/menusettingint.cpp | ||
---|---|---|
33 | 33 | using std::unique_ptr; |
34 | 34 | |
35 | 35 | MenuSettingInt::MenuSettingInt( |
36 | GMenu2X& gmenu2x, Touchscreen &ts, | |
36 | GMenu2X& gmenu2x, | |
37 | 37 | const string &name, const string &description, |
38 | 38 | int *value, int min, int max, int increment) |
39 | 39 | : MenuSetting(gmenu2x, name, description) |
... | ... | |
50 | 50 | IconButton::Action actionDec = bind(&MenuSettingInt::dec, this); |
51 | 51 | |
52 | 52 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
53 | gmenu2x, ts, "skin:imgs/buttons/l.png", | |
53 | gmenu2x, "skin:imgs/buttons/l.png", | |
54 | 54 | "", actionDec))); |
55 | 55 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
56 | gmenu2x, ts, "skin:imgs/buttons/left.png", | |
56 | gmenu2x, "skin:imgs/buttons/left.png", | |
57 | 57 | gmenu2x.tr["Decrease"], actionDec))); |
58 | 58 | |
59 | 59 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
60 | gmenu2x, ts, "skin:imgs/buttons/r.png", | |
60 | gmenu2x, "skin:imgs/buttons/r.png", | |
61 | 61 | "", actionInc))); |
62 | 62 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
63 | gmenu2x, ts, "skin:imgs/buttons/right.png", | |
63 | gmenu2x, "skin:imgs/buttons/right.png", | |
64 | 64 | gmenu2x.tr["Increase"], actionInc))); |
65 | 65 | } |
66 | 66 |
src/menusettingint.h | ||
---|---|---|
23 | 23 | #include "menusetting.h" |
24 | 24 | #include "inputmanager.h" |
25 | 25 | |
26 | class Touchscreen; | |
27 | ||
28 | 26 | class MenuSettingInt : public MenuSetting { |
29 | 27 | private: |
30 | 28 | int originalValue; |
... | ... | |
38 | 36 | |
39 | 37 | public: |
40 | 38 | MenuSettingInt( |
41 | GMenu2X& gmenu2x, Touchscreen &ts, | |
39 | GMenu2X& gmenu2x, | |
42 | 40 | const std::string &name, const std::string &description, |
43 | 41 | int *value, int min, int max, int increment = 1); |
44 | 42 | virtual ~MenuSettingInt() {} |
src/menusettingmultistring.cpp | ||
---|---|---|
31 | 31 | using std::unique_ptr; |
32 | 32 | |
33 | 33 | MenuSettingMultiString::MenuSettingMultiString( |
34 | GMenu2X& gmenu2x, Touchscreen &ts, | |
34 | GMenu2X& gmenu2x, | |
35 | 35 | const string &name, const string &description, |
36 | 36 | string *value, const vector<string> *choices_) |
37 | 37 | : MenuSettingStringBase(gmenu2x, name, description, value) |
... | ... | |
40 | 40 | setSel(find(choices->begin(), choices->end(), *value) - choices->begin()); |
41 | 41 | |
42 | 42 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
43 | gmenu2x, ts, "skin:imgs/buttons/left.png", "", | |
43 | gmenu2x, "skin:imgs/buttons/left.png", "", | |
44 | 44 | bind(&MenuSettingMultiString::decSel, this)))); |
45 | 45 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
46 | gmenu2x, ts, "skin:imgs/buttons/right.png", | |
46 | gmenu2x, "skin:imgs/buttons/right.png", | |
47 | 47 | gmenu2x.tr["Change value"], |
48 | 48 | bind(&MenuSettingMultiString::incSel, this)))); |
49 | 49 | } |
src/menusettingmultistring.h | ||
---|---|---|
25 | 25 | |
26 | 26 | #include <vector> |
27 | 27 | |
28 | class Touchscreen; | |
29 | ||
30 | 28 | class MenuSettingMultiString : public MenuSettingStringBase { |
31 | 29 | private: |
32 | 30 | virtual void edit() { |
... | ... | |
42 | 40 | |
43 | 41 | public: |
44 | 42 | MenuSettingMultiString( |
45 | GMenu2X& gmenu2x, Touchscreen &ts, | |
43 | GMenu2X& gmenu2x, | |
46 | 44 | const std::string &name, const std::string &description, |
47 | 45 | std::string *value, const std::vector<std::string> *choices); |
48 | 46 | virtual ~MenuSettingMultiString() {}; |
src/menusettingrgba.cpp | ||
---|---|---|
34 | 34 | constexpr unsigned int COMPONENT_WIDTH = 28; |
35 | 35 | |
36 | 36 | MenuSettingRGBA::MenuSettingRGBA( |
37 | GMenu2X& gmenu2x, Touchscreen &ts_, | |
37 | GMenu2X& gmenu2x, | |
38 | 38 | const string &name, const string &description, RGBAColor *value) |
39 | 39 | : MenuSetting(gmenu2x, name, description) |
40 | , ts(ts_) | |
41 | 40 | { |
42 | 41 | edit = false; |
43 | 42 | |
... | ... | |
66 | 65 | font->write(s, strA, valueX + h + COMPONENT_WIDTH * 4 - 2, y, Font::HAlignRight, Font::VAlignTop); |
67 | 66 | } |
68 | 67 | |
69 | void 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 | ||
82 | 68 | bool MenuSettingRGBA::handleButtonPress(InputManager::Button button) |
83 | 69 | { |
84 | 70 | if (edit) { |
... | ... | |
230 | 216 | { |
231 | 217 | buttonBox.clear(); |
232 | 218 | 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"]))); | |
238 | 224 | } 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"]))); | |
242 | 228 | } |
243 | 229 | } |
src/menusettingrgba.h | ||
---|---|---|
26 | 26 | #include "inputmanager.h" |
27 | 27 | |
28 | 28 | class GMenu2X; |
29 | class Touchscreen; | |
30 | 29 | |
31 | 30 | class MenuSettingRGBA : public MenuSetting { |
32 | 31 | private: |
33 | Touchscreen &ts; | |
34 | 32 | unsigned short selPart; |
35 | 33 | std::string strR, strG, strB, strA; |
36 | 34 | RGBAColor originalValue; |
... | ... | |
47 | 45 | |
48 | 46 | public: |
49 | 47 | MenuSettingRGBA( |
50 | GMenu2X& gmenu2x, Touchscreen &ts, | |
48 | GMenu2X& gmenu2x, | |
51 | 49 | const std::string &name, const std::string &description, |
52 | 50 | RGBAColor *value); |
53 | 51 | virtual ~MenuSettingRGBA() {}; |
54 | 52 | |
55 | 53 | virtual void draw(int valueX, int y, int h); |
56 | virtual void handleTS(int valueX, int y, int h); | |
57 | 54 | virtual bool handleButtonPress(InputManager::Button button); |
58 | 55 | virtual void drawSelected(int valueX, int y, int h); |
59 | 56 | virtual bool edited(); |
src/menusettingstring.cpp | ||
---|---|---|
29 | 29 | using std::unique_ptr; |
30 | 30 | |
31 | 31 | MenuSettingString::MenuSettingString( |
32 | GMenu2X& gmenu2x, Touchscreen &ts_, | |
32 | GMenu2X& gmenu2x, | |
33 | 33 | const string &name, const string &description, string *value, |
34 | 34 | const string &diagTitle_, const string &diagIcon_) |
35 | 35 | : MenuSettingStringBase(gmenu2x, name, description, value) |
36 | , ts(ts_) | |
37 | 36 | , diagTitle(diagTitle_) |
38 | 37 | , diagIcon(diagIcon_) |
39 | 38 | { |
40 | 39 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
41 | gmenu2x, ts, "skin:imgs/buttons/cancel.png", | |
40 | gmenu2x, "skin:imgs/buttons/cancel.png", | |
42 | 41 | gmenu2x.tr["Clear"], |
43 | 42 | bind(&MenuSettingString::clear, this)))); |
44 | 43 | |
45 | 44 | buttonBox.add(unique_ptr<IconButton>(new IconButton( |
46 | gmenu2x, ts, "skin:imgs/buttons/accept.png", | |
45 | gmenu2x, "skin:imgs/buttons/accept.png", | |
47 | 46 | gmenu2x.tr["Edit"], |
48 | 47 | bind(&MenuSettingString::edit, this)))); |
49 | 48 | } |
... | ... | |
51 | 50 | void MenuSettingString::edit() |
52 | 51 | { |
53 | 52 | InputDialog id( |
54 | gmenu2x, gmenu2x.input, ts, | |
55 | description, value(), diagTitle, diagIcon); | |
53 | gmenu2x, gmenu2x.input, description, value(), diagTitle, diagIcon); | |
56 | 54 | if (id.exec()) setValue(id.getInput()); |
57 | 55 | } |
src/menusettingstring.h | ||
---|---|---|
22 | 22 | |
23 | 23 | #include "menusettingstringbase.h" |
24 | 24 | |
25 | class Touchscreen; | |
26 | ||
27 | 25 | class MenuSettingString : public MenuSettingStringBase { |
28 | private: | |
29 | Touchscreen &ts; | |
30 | ||
31 | 26 | protected: |
32 | 27 | virtual void edit(); |
33 | 28 | |
... | ... | |
35 | 30 | |
36 | 31 | public: |
37 | 32 | MenuSettingString( |
38 | GMenu2X& gmenu2x, Touchscreen &ts, const std::string &name, | |
33 | GMenu2X& gmenu2x, const std::string &name, | |
39 | 34 | const std::string &description, std::string *value, |
40 | 35 | const std::string &diagTitle = "", |
41 | 36 | const std::string &diagIcon = ""); |
src/settingsdialog.cpp | ||
---|---|---|
28 | 28 | using namespace std; |
29 | 29 | |
30 | 30 | SettingsDialog::SettingsDialog( |
31 | GMenu2X& gmenu2x, InputManager &inputMgr_, Touchscreen &ts_, | |
31 | GMenu2X& gmenu2x, InputManager &inputMgr_, | |
32 | 32 | const string &text_, const string &icon) |
33 | 33 | : Dialog(gmenu2x) |
34 | 34 | , inputMgr(inputMgr_) |
35 | , ts(ts_) | |
36 | 35 | , text(text_) |
37 | 36 | { |
38 | 37 | if (!icon.empty() && gmenu2x.sc[icon] != NULL) { |
... | ... | |
46 | 45 | OffscreenSurface bg(*gmenu2x.bg); |
47 | 46 | bg.convertToDisplayFormat(); |
48 | 47 | |
49 | bool close = false, ts_pressed = false; | |
48 | bool close = false; | |
50 | 49 | uint i, sel = 0, firstElement = 0; |
51 | 50 | |
52 | 51 | 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 | }; | |
65 | 52 | uint rowHeight = gmenu2x.font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1 |
66 | 53 | uint numRows = (gmenu2x.resY - topBarHeight - 20) / rowHeight; |
67 | 54 | |
... | ... | |
73 | 60 | while (!close) { |
74 | 61 | OutputSurface& s = *gmenu2x.s; |
75 | 62 | |
76 | if (ts.available()) ts.poll(); | |
77 | ||
78 | 63 | bg.blit(s, 0, 0); |
79 | 64 | |
80 | 65 | gmenu2x.drawTopBar(s); |
... | ... | |
93 | 78 | //selected option |
94 | 79 | settings[sel]->drawSelected(maxNameWidth + 15, iY, rowHeight); |
95 | 80 | |
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 | } | |
102 | 81 | for (i=firstElement; i<settings.size() && i<firstElement+numRows; i++) { |
103 | 82 | iY = i-firstElement; |
104 | 83 | 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 | } | |
112 | 84 | } |
113 | 85 | |
114 | 86 | gmenu2x.drawScrollBar(numRows, settings.size(), firstElement); |
... | ... | |
117 | 89 | writeSubTitle(s, settings[sel]->getDescription()); |
118 | 90 | |
119 | 91 | s.flip(); |
120 | settings[sel]->handleTS(maxNameWidth + 15, iY, rowHeight); | |
121 | 92 | |
122 | 93 | InputManager::Button button = inputMgr.waitForPressedButton(); |
123 | 94 | if (!settings[sel]->handleButtonPress(button)) { |
src/settingsdialog.h | ||
---|---|---|
30 | 30 | |
31 | 31 | class InputManager; |
32 | 32 | class MenuSetting; |
33 | class Touchscreen; | |
34 | 33 | |
35 | 34 | class SettingsDialog : protected Dialog { |
36 | 35 | private: |
37 | 36 | InputManager &inputMgr; |
38 | Touchscreen &ts; | |
39 | 37 | std::vector<std::unique_ptr<MenuSetting>> settings; |
40 | 38 | std::string text, icon; |
41 | 39 | |
42 | 40 | public: |
43 | SettingsDialog(GMenu2X& gmenu2x, InputManager &inputMgr, Touchscreen &ts, | |
41 | SettingsDialog(GMenu2X& gmenu2x, InputManager &inputMgr, | |
44 | 42 | const std::string &text, |
45 | 43 | const std::string &icon = "skin:sections/settings.png"); |
46 | 44 |
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 | ||
27 | Touchscreen::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 | ||
41 | Touchscreen::~Touchscreen() { | |
42 | if (ts_fd > 0) { | |
43 | close(ts_fd); | |
44 | } | |
45 | } | |
46 | ||
47 | void 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 | ||
55 | bool 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 | ||
76 | bool Touchscreen::handled() { | |
77 | return _handled; | |
78 | } | |
79 | ||
80 | void Touchscreen::setHandled() { | |
81 | wasPressed = false; | |
82 | _handled = true; | |
83 | } | |
84 | ||
85 | bool Touchscreen::pressed() { | |
86 | return !_handled && event.pressure > 0; | |
87 | } | |
88 | ||
89 | bool Touchscreen::released() { | |
90 | return !pressed() && wasPressed; | |
91 | } | |
92 | ||
93 | bool 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 | ||
98 | bool Touchscreen::inRect(SDL_Rect r) { | |
99 | return inRect(r.x, r.y, r.w, r.h); | |
100 | } | |
101 | ||
102 | bool 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 | ||
108 | bool 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 | ||
28 | typedef 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 | ||
36 | class Touchscreen { | |
37 | public: | |
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 | ||
60 | private: | |
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 | ||
---|---|---|
32 | 32 | |
33 | 33 | using namespace std; |
34 | 34 | |
35 | WallpaperDialog::WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts_) | |
35 | WallpaperDialog::WallpaperDialog(GMenu2X& gmenu2x) | |
36 | 36 | : Dialog(gmenu2x) |
37 | , ts(ts_) | |
38 | 37 | { |
39 | 38 | } |
40 | 39 | |
... | ... | |
63 | 62 | uint i, selected = 0, firstElement = 0, iY; |
64 | 63 | |
65 | 64 | 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"]))); | |
68 | 67 | |
69 | 68 | unsigned int top, height; |
70 | 69 | tie(top, height) = gmenu2x.getContentArea(); |
src/wallpaperdialog.h | ||
---|---|---|
25 | 25 | |
26 | 26 | #include <string> |
27 | 27 | |
28 | class Touchscreen; | |
29 | ||
30 | 28 | class WallpaperDialog : protected Dialog { |
31 | private: | |
32 | Touchscreen &ts; | |
33 | ||
34 | 29 | public: |
35 | WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts); | |
30 | WallpaperDialog(GMenu2X& gmenu2x); | |
36 | 31 | std::string wallpaper; |
37 | 32 | |
38 | 33 | bool exec(); |
Branches:
install_locations
master
opkrun
packages