1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-05 04:51:53 +02:00

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.
This commit is contained in:
Nebuleon Fumika 2014-10-05 06:46:48 +00:00 committed by Maarten ter Huurne
parent 16aa3dd999
commit 2a2634b364
53 changed files with 115 additions and 586 deletions

View File

@ -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

View File

@ -40,7 +40,3 @@ bool Background::handleButtonPress(InputManager::Button button) {
return false;
}
}
bool Background::handleTouchscreen(Touchscreen&) {
return false;
}

View File

@ -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;

View File

@ -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<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/left.png")));
gmenu2x, "skin:imgs/buttons/left.png")));
buttonBox.add(unique_ptr<IconButton>(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<IconButton>(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<IconButton>(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<IconButton>(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<Uint16>(gmenu2x.resX - 9),
static_cast<Uint16>(gmenu2x.resY - topBarHeight - 25)
};
touchRect = (SDL_Rect) {
2,
static_cast<Sint16>(topBarHeight + 4),
static_cast<Uint16>(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();

View File

@ -30,12 +30,10 @@
#include <string>
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;

View File

@ -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();
}
}

View File

@ -16,7 +16,6 @@ public:
void clear();
void paint(Surface& s, int x, int y);
void handleTS();
private:
std::vector<std::unique_ptr<IconButton>> buttons;

View File

@ -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<int>(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;
}

View File

@ -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;

View File

@ -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);

View File

@ -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 = "");
};

View File

@ -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()) {

View File

@ -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();

View File

@ -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<MenuSetting>(new MenuSettingMultiString(
*this, ts, tr["Language"],
*this, tr["Language"],
tr["Set the language used by GMenu2X"],
&lang, &translations)));
sd.addSetting(unique_ptr<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(new MenuSettingString(
*this, ts, tr["Title"],
*this, tr["Title"],
tr["Link title"],
&linkTitle, diagTitle, diagIcon)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingString(
*this, ts, tr["Description"],
*this, tr["Description"],
tr["Link description"],
&linkDescription, diagTitle, diagIcon)));
sd.addSetting(unique_ptr<MenuSetting>(new MenuSettingMultiString(
*this, ts, tr["Section"],
*this, tr["Section"],
tr["The section this link belongs to"],
&newSection, &menu->getSections())));
sd.addSetting(unique_ptr<MenuSetting>(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<MenuSetting>(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<MenuSetting>(new MenuSettingDir(
*this, ts, tr["Selector Directory"],
*this, tr["Selector Directory"],
tr["Directory to scan for the selector"],
&linkSelDir)));
sd.addSetting(unique_ptr<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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<MenuSetting>(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()

View File

@ -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> 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

View File

@ -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;
}

View File

@ -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;

View File

@ -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);

View File

@ -10,29 +10,25 @@
class OffscreenSurface;
class Surface;
class Touchscreen;
class IconButton {
public:
typedef std::function<void(void)> 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;

View File

@ -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;

View File

@ -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();

View File

@ -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<IconButton>(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<IconButton>(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<IconButton>(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<IconButton>(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,

View File

@ -29,11 +29,10 @@
#include <vector>
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;

View File

@ -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:

View File

@ -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;

View File

@ -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;

View File

@ -72,10 +72,6 @@ public:
return true;
}
bool handleTouchscreen(Touchscreen&) override {
return true;
}
private:
LinkApp& app;
};

View File

@ -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
====================================*/

View File

@ -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<void(void)> 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);

View File

@ -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;

View File

@ -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);

View File

@ -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<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/accept.png",
gmenu2x, "skin:imgs/buttons/accept.png",
gmenu2x.tr["Switch"],
bind(&MenuSettingBool::toggle, this))));
}

View File

@ -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() {}

View File

@ -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<IconButton>(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<IconButton>(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());
}

View File

@ -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() {}

View File

@ -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<IconButton>(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<IconButton>(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());
}

View File

@ -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() {}

View File

@ -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());
}

View File

@ -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() {}

View File

@ -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<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/l.png",
gmenu2x, "skin:imgs/buttons/l.png",
"", actionDec)));
buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/left.png",
gmenu2x, "skin:imgs/buttons/left.png",
gmenu2x.tr["Decrease"], actionDec)));
buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/r.png",
gmenu2x, "skin:imgs/buttons/r.png",
"", actionInc)));
buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/right.png",
gmenu2x, "skin:imgs/buttons/right.png",
gmenu2x.tr["Increase"], actionInc)));
}

View File

@ -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() {}

View File

@ -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<string> *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<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/left.png", "",
gmenu2x, "skin:imgs/buttons/left.png", "",
bind(&MenuSettingMultiString::decSel, this))));
buttonBox.add(unique_ptr<IconButton>(new IconButton(
gmenu2x, ts, "skin:imgs/buttons/right.png",
gmenu2x, "skin:imgs/buttons/right.png",
gmenu2x.tr["Change value"],
bind(&MenuSettingMultiString::incSel, this))));
}

View File

@ -25,8 +25,6 @@
#include <vector>
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<std::string> *choices);
virtual ~MenuSettingMultiString() {};

View File

@ -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<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/l.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png", gmenu2x.tr["Decrease"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x.tr["Increase"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Confirm"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/l.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/left.png", gmenu2x.tr["Decrease"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/r.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/right.png", gmenu2x.tr["Increase"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Confirm"])));
} else {
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/right.png", gmenu2x.tr["Change color component"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Edit"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/left.png")));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/right.png", gmenu2x.tr["Change color component"])));
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Edit"])));
}
}

View File

@ -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();

View File

@ -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<IconButton>(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<IconButton>(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());
}

View File

@ -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 = "");

View File

@ -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<Sint16>(topBarHeight + 1),
static_cast<Uint16>(gmenu2x.resX - 9),
static_cast<Uint16>(gmenu2x.resY - topBarHeight - 25)
};
SDL_Rect touchRect = {
2,
static_cast<Sint16>(topBarHeight + 4),
static_cast<Uint16>(gmenu2x.resX - 12),
static_cast<Uint16>(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; i<settings.size() && i<firstElement+numRows; i++) {
iY = i-firstElement;
settings[i]->draw(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)) {

View File

@ -30,17 +30,15 @@
class InputManager;
class MenuSetting;
class Touchscreen;
class SettingsDialog : protected Dialog {
private:
InputManager &inputMgr;
Touchscreen &ts;
std::vector<std::unique_ptr<MenuSetting>> 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");

View File

@ -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 <fcntl.h>
#include <unistd.h>
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);
}

View File

@ -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 <SDL.h>
#include <stdint.h>
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

View File

@ -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<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"])));
buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Exit"])));
buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/accept.png", gmenu2x.tr["Select"])));
buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, "skin:imgs/buttons/cancel.png", gmenu2x.tr["Exit"])));
unsigned int top, height;
tie(top, height) = gmenu2x.getContentArea();

View File

@ -25,14 +25,9 @@
#include <string>
class Touchscreen;
class WallpaperDialog : protected Dialog {
private:
Touchscreen &ts;
public:
WallpaperDialog(GMenu2X& gmenu2x, Touchscreen &ts);
WallpaperDialog(GMenu2X& gmenu2x);
std::string wallpaper;
bool exec();