/* * Copyright 2019-2020 PixlOne * * 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 3 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, see . * */ #ifndef LOGID_ACTIONS_H #define LOGID_ACTIONS_H #include "Device.h" #include #include #include namespace logid { enum class Action { None, Keypress, Gestures, CycleDPI, ChangeDPI, ToggleSmartshift, ToggleHiresScroll }; enum class Direction { None, Up, Down, Left, Right }; enum class GestureMode { NoPress, OnRelease, OnFewPixels, Axis }; class Device; class ButtonAction { public: virtual ~ButtonAction() = default; Action type; virtual ButtonAction* copy(Device* dev) = 0; virtual void press() = 0; virtual void release() = 0; // ButtonAction(const ButtonAction &a, Device* d) : type (a.type), device (d) {} // ButtonAction* create_instance(Device* d); protected: ButtonAction(Action a) : type (a) {}; Device* device; }; class NoAction : public ButtonAction { public: NoAction() : ButtonAction(Action::None) {} virtual NoAction* copy(Device* dev); virtual void press() {} virtual void release() {} }; class KeyAction : public ButtonAction { public: explicit KeyAction(std::vector k) : ButtonAction(Action::Keypress), keys (std::move(k)) {}; virtual KeyAction* copy(Device* dev); virtual void press(); virtual void release(); private: std::vector keys; }; class Gesture { public: struct axis_info { uint code; float multiplier; }; Gesture(ButtonAction* ba, GestureMode m, void* aux=nullptr); Gesture(const Gesture &g, Device* dev) : action (g.action->copy(dev)), mode (g.mode), per_pixel (g.per_pixel), axis (g.axis) { } ButtonAction* action; GestureMode mode; int per_pixel; int per_pixel_mod; axis_info axis; }; class GestureAction : public ButtonAction { public: GestureAction(std::map g) : ButtonAction(Action::Gestures), gestures (std::move(g)) {}; std::map gestures; virtual GestureAction* copy(Device* dev); virtual void press(); virtual void release(); void move(HIDPP20::IReprogControlsV4::Move m); private: bool held; int x = 0; int y = 0; }; class SmartshiftAction : public ButtonAction { public: SmartshiftAction() : ButtonAction(Action::ToggleSmartshift) {}; virtual SmartshiftAction* copy(Device* dev); virtual void press(); virtual void release() {} }; class HiresScrollAction : public ButtonAction { public: HiresScrollAction() : ButtonAction(Action::ToggleHiresScroll) {}; virtual HiresScrollAction* copy(Device* dev); virtual void press(); virtual void release() {} }; class CycleDPIAction : public ButtonAction { public: CycleDPIAction(std::vector d) : ButtonAction(Action::CycleDPI), dpis (d) {}; virtual CycleDPIAction* copy(Device* dev); virtual void press(); virtual void release() {} private: const std::vector dpis; }; class ChangeDPIAction : public ButtonAction { public: ChangeDPIAction(int i) : ButtonAction(Action::ChangeDPI), dpi_inc (i) {}; virtual ChangeDPIAction* copy(Device* dev); virtual void press(); virtual void release() {} private: int dpi_inc; }; } #endif //LOGID_ACTIONS_H